:root {
  --fern: #1E3B2C;
  --fern-2: #2A4D3A;
  --leaf: #3F7D45;
  --leaf-dark: #2F6235;
  --sprout: #E3EEDB;
  --soil: #8A5A3B;
  --paper: #F3F6F1;
  --card: #FFFFFF;
  --ink: #1A231D;
  --muted: #5F6E64;
  --line: #DCE3D8;
  --bad: #B3402F;
  --warn: #A86B12;
  --info: #2D6687;
  --radius: 10px;
  --font-ui: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: "Bricolage Grotesque", "Figtree", system-ui, sans-serif;
}

html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.2rem; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
a { color: var(--leaf-dark); }
:focus-visible { outline: 3px solid #8CC27F; outline-offset: 2px; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  background: var(--fern) !important;
  color: #DCE8DE;
  width: 248px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
@media (min-width: 992px) {
  .sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; }
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 18px 12px; padding-top: calc(20px + env(safe-area-inset-top, 0px)); }
.sidebar .brand { color: #fff; text-decoration: none; font-family: var(--font-head); font-size: 1.15rem; font-weight: 700; display: flex; gap: 8px; align-items: center; line-height: 1.2; }
.sidebar-nav { padding: 4px 10px; flex: 1; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px;
  color: #C9D9CD; text-decoration: none;
  padding: 9px 12px; border-radius: 8px; font-weight: 500;
}
.sidebar-nav a i { font-size: 1.05rem; opacity: .85; }
.sidebar-nav a:hover { background: var(--fern-2); color: #fff; }
.sidebar-nav a.active { background: #DCEBD2; color: var(--fern); }
.sidebar-nav hr { border-color: #3B5E4A; opacity: 1; margin: 10px 12px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-top: 1px solid #3B5E4A; padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
.sidebar-user div { flex: 1; min-width: 0; }
.sidebar-user strong { display: block; color: #fff; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user small { color: #9DB8A5; }
.sidebar-user a { color: #C9D9CD; font-size: 1.15rem; }

.topbar {
  position: sticky; top: 0; z-index: 1020;
  background: var(--fern); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top, 0px));
}
.topbar .brand { color: #fff; text-decoration: none; font-family: var(--font-head); font-weight: 700; }
.btn-icon { color: #fff; font-size: 1.4rem; padding: 4px 10px; border: 0; }
.btn-icon:hover { color: #DCEBD2; }

.content { flex: 1; min-width: 0; padding: 24px 28px 60px; max-width: 1400px; }
@media (max-width: 991px) { .content { padding: 16px 14px 80px; } }

/* ---------- Page bits ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.panel > h2:first-child { margin-top: 0; }
.panel-flush { padding: 0; overflow: hidden; }
.panel-title { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-title h2 { margin: 0; font-size: 1.05rem; }

.btn { border-radius: 8px; font-weight: 600; }
.btn-leaf { background: var(--leaf); border-color: var(--leaf); color: #fff; }
.btn-leaf:hover, .btn-leaf:focus { background: var(--leaf-dark); border-color: var(--leaf-dark); color: #fff; }
.btn-quiet { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn-quiet:hover { background: var(--sprout); border-color: #C6D8BC; }
.btn-danger-soft { background: #FBEAE7; color: var(--bad); border: 1px solid #F0CBC4; }
.btn-danger-soft:hover { background: var(--bad); color: #fff; }

.form-label { font-weight: 600; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.form-control, .form-select { border-color: var(--line); border-radius: 8px; }
.form-control:focus, .form-select:focus { border-color: var(--leaf); box-shadow: 0 0 0 3px rgba(63,125,69,.18); }
.form-text { color: var(--muted); }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { margin: 0; --bs-table-bg: transparent; }
.table thead th { font-size: .78rem; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--line); background: #F8FAF6; white-space: nowrap; }
.table td, .table th { padding: 10px 12px; vertical-align: middle; border-color: var(--line); }
.table tbody tr:hover { background: #F8FBF6; }
.table .row-muted td { color: var(--muted); text-decoration: line-through; }

/* Status pills */
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 700; }
.pill-ok { background: #E2F1DC; color: #2F6235; }
.pill-warn { background: #FBEFD8; color: var(--warn); }
.pill-bad { background: #FBE4E0; color: var(--bad); }
.pill-info { background: #DFEDF5; color: var(--info); }
.pill-muted { background: #ECEFEA; color: var(--muted); }

/* Dashboard */
.today { background: var(--fern); color: #fff; border-radius: var(--radius); padding: 22px 24px; margin-bottom: 18px; display: grid; grid-template-columns: 1.4fr repeat(3, 1fr); gap: 18px; align-items: end; }
.today .big { font-family: var(--font-head); font-size: 2.4rem; line-height: 1; font-weight: 700; font-variant-numeric: tabular-nums; }
.today .lbl { color: #A9C4B0; font-size: .85rem; margin-top: 6px; }
.today .mid { font-family: var(--font-head); font-size: 1.35rem; font-variant-numeric: tabular-nums; }
@media (max-width: 767px) { .today { grid-template-columns: 1fr 1fr; } .today > div:first-child { grid-column: 1 / -1; } }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 8px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.bars .bar span { display: block; width: 100%; max-width: 38px; background: var(--leaf); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar small { font-size: .7rem; color: var(--muted); margin-top: 4px; }

.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty-state h2 { color: var(--ink); }

/* POS */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .pos { grid-template-columns: 1fr; } }
.scan-box { display: flex; gap: 8px; position: relative; }
.scan-box input { font-size: 1.05rem; padding: 10px 14px; }
.suggest { position: absolute; top: 100%; left: 0; right: 0; z-index: 50; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(30,59,44,.12); max-height: 320px; overflow-y: auto; }
.suggest button { display: flex; justify-content: space-between; gap: 10px; width: 100%; text-align: left; border: 0; background: #fff; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.suggest button:hover, .suggest button.hl { background: var(--sprout); }
.suggest small { color: var(--muted); }
.lines td input { min-width: 70px; }
.lines .line-name { min-width: 160px; }
.lines .line-name small { display: block; color: var(--muted); }
.totals { width: 100%; }
.totals td { padding: 4px 0; }
.totals tr.grand td { font-family: var(--font-head); font-size: 1.5rem; font-weight: 700; border-top: 2px solid var(--ink); padding-top: 8px; }
.sticky-side { position: sticky; top: 16px; }
@media (max-width: 1100px) { .sticky-side { position: static; } }

#scanner { width: 100%; max-width: 420px; margin: 0 auto; }

/* Mobile card tables */
@media (max-width: 767px) {
  .table-cards thead { display: none; }
  .table-cards tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 4px; }
  .table-cards td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 10px; text-align: right; }
  .table-cards td::before { content: attr(data-label); font-weight: 600; color: var(--muted); text-align: left; }
  .table-cards td.num { white-space: normal; }
}

.pager { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 14px; color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.filters > * { flex: 0 1 auto; }
.filters .grow { flex: 1 1 200px; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.perm-grid fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.perm-grid legend { font-size: .95rem; font-weight: 700; float: none; width: auto; padding: 0 6px; margin: 0; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--fern); }
.login-card { background: #fff; border-radius: 14px; padding: 32px 28px; width: 100%; max-width: 380px; }
.login-card h1 { font-size: 1.5rem; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
