:root {
  --bg: #f4f3ee; --panel: #ffffff; --ink: #1c2a30; --muted: #5f6d72; --faint: #8a9599;
  --line: #e4e2da; --line-strong: #cfccc2; --accent: #0e6e64; --accent-soft: #e6f2ef; --accent-ink: #ffffff;
  --side: #17262b; --side-ink: #c9d6d3; --side-active: #24393f;
  --ok: #1b8a4b; --ok-soft: #e7f5ec; --warn: #a86400; --warn-soft: #fdf3e2; --bad: #b42318; --bad-soft: #fdecea;
  --dr: #1c2a30; --cr: #8a4b0f; --radius: 12px;
  --shadow: 0 1px 2px rgba(28, 42, 48, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.faint { color: var(--faint); font-size: 12px; }
.hide { display: none !important; }
.boot { padding: 40px; color: var(--muted); }

/* layout */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; color: #fff; font-weight: 700; font-size: 16px; }
.brand .mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; font-size: 12px; letter-spacing: -.3px; }
.side select { width: 100%; background: var(--side-active); color: #fff; border: 1px solid #33494f; border-radius: 8px; padding: 8px 10px; font: inherit; margin-bottom: 12px; }
.side nav a { display: flex; align-items: center; gap: 10px; color: var(--side-ink); padding: 8px 10px; border-radius: 8px; font-weight: 500; }
.side nav a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.side nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 #5cc2b1; }
.side .sep { height: 1px; background: #2c4046; margin: 12px 4px; }
.side .grow { flex: 1; }
.side .me { font-size: 12px; color: #8fa4a0; padding: 8px 10px; }
.side .me button { background: none; border: 0; color: #c9d6d3; padding: 0; cursor: pointer; font: inherit; text-decoration: underline; }
.ico { width: 16px; height: 16px; flex: none; opacity: .85; }
.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 18px 28px 0; flex-wrap: wrap; }
.top h1 { font-size: 22px; margin: 0; letter-spacing: -.2px; }
.top .spacer { flex: 1; }
.content { padding: 18px 28px 48px; }
.syncpill { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); padding: 5px 10px; border-radius: 999px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #bbb; display: inline-block; flex: none; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }
.dot.spin { background: var(--accent); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .3; } to { opacity: 1; } }

/* mobile */
.mbar { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 30; transform: translateX(-102%); transition: transform .2s; height: 100%; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .mbar { display: flex; align-items: center; gap: 10px; background: var(--side); color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 20; }
  .mbar button { background: none; border: 0; color: #fff; font-size: 22px; padding: 0 4px; cursor: pointer; }
  .top { padding: 14px 16px 0; } .content { padding: 14px 16px 40px; }
}

/* components */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel > .ph { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel > .ph h3 { margin: 0; font-size: 15px; }
.panel > .pb { padding: 16px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 14px; }
@media (max-width: 860px) {
  .panel > table, .pb table, .grid table { display: block; overflow-x: auto; }
  .totals { flex-wrap: wrap; gap: 6px 18px; }
  td:first-child { white-space: nowrap; }
  .kpi .v { font-size: 19px; }
}
.kpi { padding: 14px 16px; }
.kpi .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi .v { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.kpi .d { font-size: 12px; color: var(--faint); }
.two { grid-template-columns: 1.6fr 1fr; }
@media (max-width: 1100px) { .two { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: #faf9f6; position: sticky; top: 0; }
tbody tr:hover { background: #fbfaf7; }
tr.click { cursor: pointer; }
tr.group td { background: #f6f5f0; font-weight: 600; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line-strong); background: #faf9f6; }
.tablewrap { overflow: auto; max-height: calc(100vh - 230px); border-radius: 0 0 var(--radius) var(--radius); }
.cancel td { color: var(--faint); text-decoration: line-through; }
.drcr { font-size: 11px; color: var(--faint); margin-left: 4px; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: #eeece5; color: var(--muted); }
.tag.ok { background: var(--ok-soft); color: var(--ok); } .tag.bad { background: var(--bad-soft); color: var(--bad); } .tag.warn { background: var(--warn-soft); color: var(--warn); } .tag.acc { background: var(--accent-soft); color: var(--accent); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #0e6e6433; border-color: var(--accent); }
.filters input[type=search] { flex: 1; min-width: 180px; }
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field input, .field select, .field textarea { width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }

.btn { font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; cursor: pointer; background: var(--accent); color: var(--accent-ink); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: var(--panel); color: var(--ink); border-color: var(--line-strong); }
.btn.danger { background: var(--panel); color: var(--bad); border-color: #ebc0bb; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.link { background: none; border: 0; color: var(--accent); padding: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 12px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 12px 12px 10px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-color: var(--accent); }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h3 { color: var(--ink); margin: 0 0 6px; }
.note { background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; font-size: 13px; }
.note.warn { background: var(--warn-soft); } .note.bad { background: var(--bad-soft); }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: s; position: relative; padding: 0 0 18px 44px; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: -2px; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; }
.steps li.done::before { content: "✓"; background: var(--ok); color: #fff; }
.steps b { display: block; }
.code { font: 600 26px/1.2 Consolas, "Courier New", monospace; letter-spacing: 3px; background: #f6f5f0; border: 1px dashed var(--line-strong); padding: 12px 16px; border-radius: 10px; text-align: center; }
.copy { display: flex; gap: 8px; } .copy input { flex: 1; font-family: Consolas, monospace; }

/* lines editor */
.lines th, .lines td { padding: 6px 6px; border: 0; background: none; }
.lines td input, .lines td select { width: 100%; }
.lines .x { background: none; border: 0; color: var(--faint); font-size: 18px; cursor: pointer; padding: 4px 8px; }
.totals { display: flex; justify-content: flex-end; gap: 28px; padding: 10px 6px; font-variant-numeric: tabular-nums; }
.totals b { font-size: 16px; }

/* bar chart */
.chart { width: 100%; height: 220px; }
.chart text { font-size: 11px; fill: var(--faint); font-family: inherit; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .panel { width: 100%; max-width: 400px; padding: 28px; }
.auth h1 { margin: 12px 0 4px; font-size: 22px; }
.auth .btn { width: 100%; justify-content: center; margin-top: 6px; padding: 10px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(23, 38, 43, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-box { background: var(--panel); border-radius: 14px; width: 100%; max-width: 720px; max-height: 90vh; overflow: auto; position: relative; padding: 22px; }
.modal-box h2 { margin: 0 0 12px; font-size: 18px; }
.modal-x { position: absolute; right: 12px; top: 8px; background: none; border: 0; font-size: 26px; color: var(--faint); cursor: pointer; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--side); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 60; box-shadow: 0 6px 24px rgba(0,0,0,.2); max-width: 90vw; }
.toast.bad { background: var(--bad); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; font-size: 13px; margin-bottom: 14px; }
.kv div:nth-child(odd) { color: var(--muted); }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin-bottom: 10px; font-size: 13px; }
.bar-row .bar { grid-column: 1 / -1; height: 6px; background: #eeece5; border-radius: 3px; overflow: hidden; }
.bar-row .bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.progress { height: 6px; background: #eeece5; border-radius: 3px; overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
