:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #1b2420;
  --muted: #66716c;
  --line: #e1e4df;
  --brand: #0f5c4d;
  --brand-2: #e8f1ee;
  --accent: #d9822b;
  --danger: #b3261e;
  --ok: #1d7a3a;
  --warn-bg: #fff4e0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--brand); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: #12302a; color: #d8e6e1; padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: #fff; padding: 4px 8px 14px; }
.brand i { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: inline-block; }
.side a { display: block; color: inherit; text-decoration: none; padding: 9px 12px; border-radius: 8px; margin: 1px 0; }
.side a:hover { background: rgba(255,255,255,.07); }
.side a.on { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.side .who { border-top: 1px solid rgba(255,255,255,.12); margin-top: 12px; padding: 12px 12px 0; font-size: 12px; color: #a9c2ba; }
.side .who button { margin-top: 8px; }
.main { padding: 18px 22px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mobilebar { display: none; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 14px; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.row > .fit { flex: 0 0 auto; }

/* ---------- Forms ---------- */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
input, select, textarea {
  width: 100%; font: inherit; color: inherit; padding: 8px 10px; border: 1px solid #cfd5cf; border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15,92,77,.25); border-color: var(--brand); }
input[type=checkbox] { width: auto; }
.field { margin-bottom: 10px; }
button, .btn {
  font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  background: var(--brand); color: #fff; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.ghost, .btn.ghost { background: #fff; color: var(--ink); border-color: #cfd5cf; }
button.danger { background: var(--danger); }
button.small { padding: 4px 9px; font-size: 12px; }
button.link { background: none; color: var(--brand); padding: 0; border: 0; font-weight: 500; }
.seg { display: inline-flex; border: 1px solid #cfd5cf; border-radius: 8px; overflow: hidden; }
.seg button { background: #fff; color: var(--ink); border-radius: 0; border: 0; border-right: 1px solid #cfd5cf; font-weight: 500; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--brand); color: #fff; }

/* ---------- Tables ---------- */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbf9; position: sticky; top: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #f6f9f7; }
tr.cancelled td { text-decoration: line-through; color: #999; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
td input { padding: 5px 7px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--brand-2); color: var(--brand); }
.pill.warn { background: var(--warn-bg); color: #9a5a00; }
.pill.bad { background: #fde8e7; color: var(--danger); }
.pill.grey { background: #eceeeb; color: var(--muted); }
.low td { background: #fff8ec; }
.empty { padding: 26px; text-align: center; color: var(--muted); }

/* ---------- Billing ---------- */
.bill { display: grid; grid-template-columns: 1fr 320px; gap: 14px; align-items: start; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 24px; font-weight: 800; border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 8px; }
.ac { position: relative; }
.ac-list { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid #cfd5cf; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 320px; overflow-y: auto; margin-top: 2px; }
.ac-list div { padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.ac-list div.on, .ac-list div:hover { background: var(--brand-2); }
.ac-list small { color: var(--muted); }

/* ---------- Bars ---------- */
.bars { display: flex; gap: 8px; align-items: flex-end; height: 140px; padding-top: 6px; }
.bars .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; height: 100%; font-size: 11px; color: var(--muted); }
.bars .stack { width: 100%; max-width: 46px; display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; }
.bars .r { background: var(--brand); }
.bars .l { background: var(--accent); }
.legend span { display: inline-flex; align-items: center; gap: 5px; margin-right: 12px; font-size: 12px; color: var(--muted); }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* ---------- Modal + toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,25,20,.45); display: flex; align-items: flex-start; justify-content: center; z-index: 50; padding: 30px 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 980px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head button { background: none; color: var(--muted); font-size: 22px; padding: 0 6px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 80; }
#toast div { background: #1b2420; color: #fff; padding: 10px 16px; border-radius: 8px; margin-top: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 90vw; }
#toast div.err { background: var(--danger); }

.login { max-width: 360px; margin: 10vh auto; }
.login .brand { color: var(--ink); padding: 0 0 16px; font-size: 22px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; color: var(--muted); border-radius: 0; border-bottom: 2px solid transparent; font-weight: 600; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.note { background: var(--warn-bg); border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 10px; }

/* ---------- Phone ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 60; transform: translateX(-105%); transition: transform .18s; height: 100%; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .mobilebar { display: flex; align-items: center; gap: 10px; background: #12302a; color: #fff; padding: 10px 14px; position: sticky; top: 0; z-index: 40; }
  .mobilebar button { background: none; font-size: 20px; padding: 0 4px; }
  .main { padding: 14px 12px 70px; }
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .g2 { grid-template-columns: 1fr; }
  .bill { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .kpi .v { font-size: 18px; }
  input, select { font-size: 16px; } /* stop iOS zoom */
}
@media print { .side, .mobilebar, .topbar .actions, button { display: none !important; } .shell { display: block; } }
