:root {
  --bg: #f5f6f4;
  --panel: #ffffff;
  --ink: #1d2320;
  --ink-2: #4c5551;
  --ink-3: #7a837f;
  --line: #dde1de;
  --line-2: #eceeec;
  --accent: #0f6b5c;
  --accent-2: #e3f1ee;
  --warn: #a86400;
  --warn-bg: #fff4e0;
  --bad: #b3261e;
  --bad-bg: #fdecea;
  --good: #1e7b34;
  --good-bg: #e7f5ea;
  --sidebar: #17201d;
  --sidebar-ink: #c9d2ce;
  --radius: 6px;
  --font: "Segoe UI", system-ui, -apple-system, "Noto Sans", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "DejaVu Sans Mono", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 13.5px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.shell { display: grid; grid-template-columns: 216px 1fr; height: 100vh; }
.side { background: var(--sidebar); color: var(--sidebar-ink); display: flex; flex-direction: column; overflow-y: auto; }
.brand { padding: 14px 16px 10px; font-weight: 700; font-size: 16px; color: #fff; letter-spacing: .2px; }
.brand small { display: block; font-weight: 400; font-size: 11.5px; color: var(--sidebar-ink); opacity: .8; }
.firm-switch { margin: 0 12px 10px; }
.firm-switch select { width: 100%; background: #233029; color: #fff; border: 1px solid #344139; border-radius: 4px; padding: 4px 6px; }
.nav-group { padding: 8px 0 2px; }
.nav-group h4 { margin: 0; padding: 4px 16px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px; color: #8a9690; font-weight: 600; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 6px 16px; color: var(--sidebar-ink); text-decoration: none; border-left: 3px solid transparent; }
.nav a:hover { background: #1f2a26; color: #fff; }
.nav a.on { background: #22312b; color: #fff; border-left-color: #4fc3a8; }
.nav a kbd { font-size: 10px; opacity: .55; }
.side .me { margin-top: auto; padding: 12px 16px; font-size: 12px; border-top: 1px solid #26322d; }
.side .me button { background: none; border: 0; color: #9fb1aa; cursor: pointer; padding: 0; }
.main { overflow-y: auto; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.topbar .crumb { color: var(--ink-3); font-size: 12px; }
.topbar .spacer { flex: 1; }
.offline { background: var(--warn-bg); color: var(--warn); padding: 3px 10px; border-radius: 12px; font-size: 12px; }
.content { padding: 16px 20px 40px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.grow { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi b { display: block; font-size: 20px; margin-top: 2px; }
.kpi span { color: var(--ink-3); font-size: 12px; }
.btn { background: var(--panel); border: 1px solid #c6ccc8; border-radius: 4px; padding: 5px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #0c5a4d; }
.btn.danger { color: var(--bad); border-color: #e6b8b4; }
.btn.small { padding: 2px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn kbd { font-size: 10.5px; opacity: .7; margin-left: 4px; }
input[type=text], input[type=number], input[type=email], input[type=password], input[type=date], input:not([type]), select, textarea {
  border: 1px solid #c6ccc8; border-radius: 4px; padding: 5px 8px; background: #fff; min-width: 0;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid #8fd1c2; outline-offset: 0; border-color: var(--accent); }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
label.f > span { font-weight: 600; }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 14px; }
.form .wide { grid-column: 1 / -1; }
table.t { width: 100%; border-collapse: collapse; background: var(--panel); }
table.t th { text-align: left; font-size: 11.5px; color: var(--ink-2); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); background: #fafbfa; position: sticky; top: 0; }
table.t td { padding: 5px 8px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #f2f7f5; }
table.t tr.sel td { background: var(--accent-2); }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t td.c { text-align: center; }
.tbl-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 220px); background: var(--panel); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11.5px; background: #eef0ee; color: var(--ink-2); white-space: nowrap; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.acc { background: var(--accent-2); color: var(--accent); }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.conf { display: inline-block; width: 34px; height: 6px; background: #e4e7e5; border-radius: 3px; overflow: hidden; vertical-align: middle; }
.conf i { display: block; height: 100%; }
/* editable grid */
.eg { width: 100%; border-collapse: collapse; background: var(--panel); }
.eg th { font-size: 11.5px; color: var(--ink-2); text-align: left; padding: 6px; border-bottom: 1px solid var(--line); background: #fafbfa; position: sticky; top: 0; z-index: 1; }
.eg td { border-bottom: 1px solid var(--line-2); padding: 0; height: 30px; }
.eg td .cell { padding: 5px 6px; min-height: 30px; outline: none; white-space: pre-wrap; }
.eg td.n .cell { text-align: right; font-variant-numeric: tabular-nums; }
.eg td.active { box-shadow: inset 0 0 0 2px var(--accent); }
.eg td input { width: 100%; border: 0; border-radius: 0; padding: 5px 6px; height: 30px; outline: none; background: #fffef3; }
.eg tr.flag td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.eg tr.cat td { background: #f4f6f5; font-weight: 600; font-size: 12px; }
.picker { position: fixed; z-index: 30; background: #fff; border: 1px solid #b9c2bd; border-radius: 6px; box-shadow: 0 8px 28px rgba(0,0,0,.18); width: 620px; max-height: 340px; overflow: auto; }
.picker div { padding: 6px 10px; cursor: pointer; border-bottom: 1px solid var(--line-2); }
.picker div.on, .picker div:hover { background: var(--accent-2); }
.picker small { color: var(--ink-3); }
/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(20,28,25,.35); display: flex; align-items: flex-start; justify-content: center; padding-top: 6vh; z-index: 40; }
.modal { background: #fff; border-radius: 8px; width: min(900px, 94vw); max-height: 86vh; overflow: auto; box-shadow: 0 18px 50px rgba(0,0,0,.25); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; font-size: 15px; }
.modal .body { padding: 14px 16px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1f2a26; color: #fff; padding: 9px 14px; border-radius: 6px; max-width: 420px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.bad { background: var(--bad); }
.toast.good { background: var(--good); }
/* chat */
.chat { display: flex; flex-direction: column; height: 100%; }
.chat .log { flex: 1; overflow-y: auto; padding: 8px 0; display: flex; flex-direction: column; gap: 8px; min-height: 220px; max-height: 420px; }
.msg { padding: 8px 11px; border-radius: 8px; max-width: 85%; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.assistant { align-self: flex-start; background: #eef2f0; }
.chat form { display: flex; gap: 8px; }
.chat input { flex: 1; }
/* tick screen */
.ticks td.o { text-align: center; }
.ticks input[type=radio] { width: 18px; height: 18px; accent-color: var(--accent); }
.ticks td input[type=number] { width: 64px; }
/* login */
.login { max-width: 360px; margin: 12vh auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 26px; }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.empty { padding: 30px; text-align: center; color: var(--ink-3); }
.bar { height: 10px; background: var(--accent); border-radius: 2px; }
.chart-row { display: grid; grid-template-columns: 180px 1fr 110px; gap: 8px; align-items: center; font-size: 12px; margin: 3px 0; }
.chart-row .track { background: #edf0ee; border-radius: 2px; }
#map { height: 520px; border-radius: var(--radius); border: 1px solid var(--line); }
.drop { border: 2px dashed #b9c4bf; border-radius: 8px; padding: 22px; text-align: center; color: var(--ink-2); background: #fbfcfb; cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-2); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { background: none; border: 0; padding: 7px 12px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--ink-2); }
.tabs button.on { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }
.hint { font-size: 11.5px; color: var(--ink-3); }
.sticky-foot { position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); padding: 8px 12px; display: flex; gap: 16px; align-items: center; justify-content: flex-end; }
.totals b { font-size: 16px; }
@media print { .side, .topbar { display: none; } .shell { display: block; } }

/* charts (CSS only) */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 6px; }
.vbar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; min-width: 10px; }
.vbar i { display: block; width: 100%; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 1px; }
.vbar small { font-size: 9px; color: var(--ink-3); margin-top: 3px; writing-mode: vertical-rl; transform: rotate(180deg); }
.hbars { display: grid; gap: 4px; }
.hbar { display: grid; grid-template-columns: minmax(120px, 38%) 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.hbar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-transform: capitalize; }
.hbar div { background: var(--line-2); height: 10px; border-radius: 5px; overflow: hidden; }
.hbar i { display: block; height: 100%; background: var(--accent); }
.hbar b { font-weight: 600; font-variant-numeric: tabular-nums; }
table.t tr.bad td { background: #fdecea; }
details pre { white-space: pre-wrap; background: #f6f6f4; padding: 8px; border-radius: 6px; }

/* ---------- narrow screens: laptops, tablets, phones (browser use) ---------- */
.menu-btn { display: none; background: none; border: 1px solid var(--line); border-radius: 4px; padding: 3px 9px; font-size: 18px; line-height: 1; cursor: pointer; }
.nav-scrim { display: none; }
@media (max-width: 1100px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 50; transform: translateX(-100%); transition: transform .18s ease; }
  .shell.nav-open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .shell.nav-open .nav-scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 45; }
  .menu-btn { display: inline-block; }
  .topbar { flex-wrap: wrap; padding: 8px 12px; }
  .topbar #actions { width: 100%; }
  .content { padding: 12px 12px 40px; }
  .nav a kbd { display: none; }
}
@media (max-width: 760px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .modal-bg { padding-top: 0; }
  .modal { width: 100vw; max-height: 100vh; border-radius: 0; }
  .picker { width: calc(100vw - 16px); left: 8px !important; }
  .tbl-wrap { max-height: none; }
  table.t td, table.t th { padding: 6px 6px; }
  .topbar h1 { font-size: 15px; }
  .btn { padding: 7px 12px; }
  #map { height: 360px; }
  .login { margin: 6vh 12px; }
  .hbar { grid-template-columns: minmax(90px, 40%) 1fr auto; }
}
