:root {
  --brand: #0f6cbd;
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fb; --border: #e2e5ea; --grid: #eceef2;
  --text: #14171c; --text-2: #4b5360; --text-3: #6b7380;
  --good: #1f7a3d; --warn: #a35f00; --bad: #b3261e;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111315; --surface: #1a1c1f; --surface-2: #202327; --border: #2c3036; --grid: #272a2f;
    --text: #f2f3f5; --text-2: #c3c7ce; --text-3: #9aa1ab;
    --good: #5dc283; --warn: #e0a24a; --bad: #f08a83;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 1.5rem; margin: 0; } h1:focus { outline: none; } h2 { font-size: 1.15rem; margin: 0 0 .75rem; } h3 { font-size: 1rem; margin: 0 0 .5rem; }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
.muted { color: var(--text-3); } .small { font-size: .85rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.mono { font-family: ui-monospace, Consolas, monospace; }

/* layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; font-size: 1.1rem; }
.brand img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; }
.brand .logo { width: 34px; height: 34px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand); }
.nav .sec { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 14px 12px 4px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .spacer { flex: 1; }
.content { padding: 20px; max-width: 1280px; width: 100%; margin: 0 auto; }
.menu-btn { display: none; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .grow { flex: 1; }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
  .menu-btn { display: inline-flex; }
  .content { padding: 14px; }
  .hide-sm { display: none !important; }
}

/* controls */
button, .btn { white-space: nowrap; font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px; min-height: 38px; }
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--brand); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
button.ghost { border-color: transparent; background: transparent; }
button.sm { padding: 4px 10px; min-height: 30px; font-size: .88rem; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 38px; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input[type=checkbox] { width: auto; min-height: auto; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--text-2); font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; font-size: .95rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.form-grid .span2 { grid-column: span 2; } .form-grid .full { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .row.end { justify-content: flex-end; } .row .grow { flex: 1; min-width: 160px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* cards & tables */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; } .g2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); } .g3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { color: var(--text-3); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.55rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: .82rem; margin-top: 2px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tr.clickable { cursor: pointer; } tr.clickable:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, transparent); background: color-mix(in srgb, var(--good) 10%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.badge.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 35%, transparent); background: color-mix(in srgb, var(--bad) 10%, transparent); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 10px 14px; color: var(--text-2); }
.tabs button.active { border-bottom-color: var(--brand); color: var(--brand); font-weight: 600; }
.empty { text-align: center; color: var(--text-3); padding: 28px 12px; }
.alert { padding: 10px 14px; border-radius: 8px; background: color-mix(in srgb, var(--bad) 10%, transparent); color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); }
.alert.info { background: color-mix(in srgb, var(--brand) 10%, transparent); color: var(--text); border-color: color-mix(in srgb, var(--brand) 35%, transparent); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding-top: 10px; }

/* modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; width: min(720px, 100%); max-height: 92vh; overflow-y: auto; padding: 20px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.modal.wide { width: min(980px, 100%); }
.modal h2 { margin-bottom: 14px; }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); }
.toast.err { background: var(--bad); color: #fff; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); }
.login-card .brand { justify-content: center; font-size: 1.4rem; padding-bottom: 6px; }

/* pos */
.pos { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .pos { grid-template-columns: 1fr; } }
.item-card { display: flex; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; align-items: center; }
.item-card:hover { border-color: var(--brand); }
.item-card img, .thumb { width: 52px; height: 52px; border-radius: 6px; object-fit: cover; background: var(--surface-2); flex: none; }
.cart-line { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.totals div { display: flex; justify-content: space-between; padding: 2px 0; } .totals .grand { font-size: 1.25rem; font-weight: 700; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; } .photos .ph { position: relative; } .photos img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; }
.photos .ph button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; min-height: 0; padding: 0; justify-content: center; border-radius: 50%; }

/* charts (marks are thin, grid is recessive, text uses text tokens) */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; } .chart .axis-text { fill: var(--text-3); font-size: 11px; }
.chart .tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 8px; padding: 6px 10px; font-size: .82rem; transform: translate(-50%, -110%); white-space: nowrap; z-index: 5; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; color: var(--text-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: minmax(80px, 34%) 1fr auto; gap: 10px; align-items: center; padding: 5px 0; font-size: .9rem; }
.hbar .track { height: 10px; background: var(--grid); border-radius: 0 4px 4px 0; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; } .donut-wrap svg { width: 150px; flex: none; }
.toggle-link { font-size: .82rem; color: var(--text-3); cursor: pointer; background: none; border: none; padding: 0; min-height: 0; text-decoration: underline; }

@media print {
  .sidebar, .topbar, .no-print, .toasts { display: none !important; }
  .app { display: block; } .content { padding: 0; } body { background: #fff; }
}
