/* Layout: fixed sidebar + scrolling work area on desktop; top bar + drawer on phones.
   Kitchen-steel neutrals with a herb-green accent; numbers set in tabular figures. */
:root {
  --bg: #f3f5f4; --surface: #ffffff; --surface-2: #eaefec; --line: #d6ddd9;
  --fg: #17201c; --muted: #5a6962; --accent: #1b6a50; --accent-ink: #ffffff; --accent-soft: #dcebe3;
  --warn: #9a5806; --warn-soft: #fbedd6; --bad: #b0271f; --bad-soft: #f8dfdc; --good: #1b6a50;
  --shadow: 0 1px 2px rgba(20,30,25,.06), 0 6px 24px rgba(20,30,25,.06);
  --f-display: "Unbounded", "Segoe UI", system-ui, sans-serif;
  --f-body: "Onest", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101513; --surface: #161d1a; --surface-2: #1d2622; --line: #2b3631;
    --fg: #e5ece8; --muted: #97a69f; --accent: #5dbd94; --accent-ink: #0b1914; --accent-soft: #1b392d;
    --warn: #e8a64b; --warn-soft: #3a2b13; --bad: #f1867d; --bad-soft: #3d1d1a; --good: #5dbd94;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101513; --surface: #161d1a; --surface-2: #1d2622; --line: #2b3631;
  --fg: #e5ece8; --muted: #97a69f; --accent: #5dbd94; --accent-ink: #0b1914; --accent-soft: #1b392d;
  --warn: #e8a64b; --warn-soft: #3a2b13; --bad: #f1867d; --bad-soft: #3d1d1a; --good: #5dbd94;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.45 var(--f-body); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; text-wrap: balance; }
h1 { font: 600 1.35rem/1.2 var(--f-display); letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.mono { font-family: var(--f-mono); font-size: .85em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.label { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 248px minmax(0,1fr); min-height: 100%; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font: 700 .8rem var(--f-display); }
.brand b { font: 600 .95rem/1.1 var(--f-display); display: block; }
.brand span { font-size: .75rem; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav .label { padding: 10px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; color: var(--fg); text-decoration: none; font-size: .93rem; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav svg { width: 17px; height: 17px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 6px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 10px 24px; flex-wrap: wrap; }
.topbar .grow { flex: 1; }
.btn.menu-btn { display: none; }
.content { padding: 22px 24px 60px; display: flex; flex-direction: column; gap: 18px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 70ch; }
.demo-flag { font-size: .75rem; font-weight: 600; color: var(--warn); background: var(--warn-soft); padding: 3px 8px; border-radius: 99px; }

/* ---------- controls ---------- */
.btn { text-decoration: none; display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px;
  border-radius: 7px; cursor: pointer; font-weight: 550; font-size: .92rem; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], input:not([type]), select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 8px 10px; min-width: 0; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: .8rem; color: var(--muted); font-weight: 550; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.seg { flex-wrap: wrap; max-width: 100%; display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 7px 14px; cursor: pointer; font-weight: 550; font-size: .9rem; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: .9rem; cursor: pointer; }

/* ---------- surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.cols { display: grid; gap: 18px; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.stat b { font: 600 1.35rem/1.2 var(--f-body); font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th { text-align: left; font-size: .72rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 600;
  padding: 9px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: var(--surface-2); }
tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--line); }
th.num { text-align: right; }
td input, td select { padding: 6px 8px; }
td.name { min-width: 170px; }
td.w-qty { width: 110px; } td.w-price { width: 120px; } td.w-x { width: 40px; }
tr.cancelled td { color: var(--muted); text-decoration: line-through; }
.raw { font-size: .78rem; color: var(--muted); margin-top: 3px; }

/* ---------- chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.good { background: var(--accent-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10,16,13,.45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 10px; box-shadow: var(--shadow); width: min(760px, 100%); max-height: 90vh; overflow: auto;
  padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal > * { flex-shrink: 0; }
.modal.wide { width: min(1000px, 100%); }
.toast { position: fixed; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-weight: 550; max-width: calc(100% - 32px); }
.toast.err { background: var(--bad); color: #fff; }
.note { border-radius: 8px; padding: 10px 12px; font-size: .9rem; background: var(--surface-2); }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note.bad { background: var(--bad-soft); color: var(--bad); }
.note.good { background: var(--accent-soft); color: var(--good); }
.spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 3s; } }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login .panel { width: min(380px, 100%); }

/* ---------- chart ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--f-body); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 40; transform: translateX(-100%); transition: transform .2s;
    padding-top: calc(18px + env(safe-area-inset-top, 0px)); height: 100%; }
  .side.open { transform: none; box-shadow: var(--shadow); }
  .btn.menu-btn { display: inline-flex; }
  .hide-sm { display: none; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .cols { grid-template-columns: 1fr; }
  .scrim { position: fixed; inset: 0; z-index: 35; background: rgba(0,0,0,.35); }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }
