:root {
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --ink: #1b2040;
  --ink-2: #565c7a;
  --line: #e1e4f0;
  --brand: #2b3a8c;
  --brand-ink: #ffffff;
  --brand-soft: #e6e9f8;
  --accent: #ff7a59;
  --ok: #217a4b;      --ok-bg: #e0f3e8;
  --warn: #9a6200;    --warn-bg: #fdf0d3;
  --danger: #b4302a;  --danger-bg: #fbe3e1;
  --info: #255f99;    --info-bg: #e1edf9;
  --muted: #676d86;   --muted-bg: #eceef5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(27, 32, 64, .06), 0 4px 16px rgba(27, 32, 64, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12142a; --surface: #1a1d38; --surface-2: #20244a; --ink: #e7e9f6; --ink-2: #a5aac8; --line: #2e3360;
    --brand: #8c9cff; --brand-ink: #0f1124; --brand-soft: #262c5c;
    --ok: #74c999; --ok-bg: #1d3a2c; --warn: #f0c46a; --warn-bg: #3a3020; --danger: #f08a78; --danger-bg: #42231f;
    --info: #86bfe8; --info-bg: #1e3242; --muted: #a5aac8; --muted-bg: #262a4c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 10px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; font-size: 18px; text-decoration: none; color: var(--ink); }
.brand img { width: 30px; height: 30px; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--ink-2); letter-spacing: .04em; text-transform: uppercase; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); padding: 12px 10px 4px; }
.nav a { display: block; padding: 7px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.side .me { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }
.side .me strong { color: var(--ink); display: block; }
.main { padding: 24px 28px 48px; min-width: 0; }

/* ---------- common */
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .spacer { flex: 1; }
.crumb { font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }
.crumb a { color: var(--ink-2); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px 18px; }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--muted-bg); color: var(--muted); }
.tone-ok { background: var(--ok-bg); color: var(--ok); }
.tone-warn { background: var(--warn-bg); color: var(--warn); }
.tone-danger { background: var(--danger-bg); color: var(--danger); }
.tone-info { background: var(--info-bg); color: var(--info); }
.tone-muted { background: var(--muted-bg); color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--ink-2); }
.hint { color: var(--ink-2); font-size: 12px; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
.grid td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid tbody tr.link { cursor: pointer; }
.grid tbody tr.link:hover td { background: var(--surface-2); }
.grid th.sortable { cursor: pointer; user-select: none; }
.grid th.sortable:hover { color: var(--ink); }
.grid tr.tone-warn td, .grid tr.tone-danger td { background: none; color: inherit; }
.grid tr.tone-warn td:first-child { box-shadow: inset 3px 0 var(--warn); }
.grid tr.tone-danger td:first-child { box-shadow: inset 3px 0 var(--danger); }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); color: var(--ink-2); font-size: 13px; }

/* ---------- toolbar / filters */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px; border-bottom: 1px solid var(--line); }
.toolbar input[type=search] { flex: 1 1 220px; }
.input, .toolbar input, .toolbar select, .field input, .field select, .field textarea, .lines input, .lines select, dialog input, dialog select {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: var(--surface); min-width: 0;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* ---------- dashboard */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { display: block; text-decoration: none; color: inherit; padding: 14px 16px; }
.kpi:hover { border-color: var(--brand); }
.kpi .label { color: var(--ink-2); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.kpi.tone-warn, .kpi.tone-danger { background: var(--surface); }
.kpi.tone-warn .value { color: var(--warn); }
.kpi.tone-danger .value { color: var(--danger); }
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 14px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 16px 6px; }
.panel-head h2 { margin: 0; }

/* ---------- workspace */
.ws { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.ws.no-side { grid-template-columns: minmax(0, 1fr); }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.field .ro { padding: 7px 0; min-height: 34px; }
.field .err, .cell-err { color: var(--danger); font-size: 12px; }
.field.invalid input, .field.invalid select, .field.invalid textarea, td.invalid input, td.invalid select { border-color: var(--danger); }
.field.check { flex-direction: row; align-items: center; gap: 8px; padding-top: 18px; }
.field textarea { min-height: 70px; resize: vertical; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 8px; }
.lines td { padding: 6px 8px; }
.lines input, .lines select { width: 100%; }
.lines td:has(> select) { min-width: 230px; }
.lines .qty { width: 84px; }
.lines .money { width: 96px; }
.lines input[type=date] { width: 140px; }
.totals input { width: 110px; text-align: right; }
a.btn { text-decoration: none; display: inline-block; }
.grid td { white-space: normal; }
.grid td.num, .grid td.date { white-space: nowrap; }
.totals { padding: 14px 16px; position: sticky; top: 16px; }
.totals dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; }
.totals dt { color: var(--ink-2); }
.totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 18px; font-weight: 700; color: var(--ink); border-top: 1px solid var(--line); padding-top: 8px; }
.totals .est { margin-top: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.status-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login .brand { padding: 0 0 18px; }
.login form { display: grid; gap: 12px; }
.login .error { color: var(--danger); min-height: 20px; font-size: 13px; }
.login .demo { margin-top: 16px; font-size: 12px; color: var(--ink-2); border-top: 1px solid var(--line); padding-top: 12px; }

/* ---------- modal & toasts */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(760px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(20, 26, 23, .45); }
dialog .head { padding: 16px 20px; border-bottom: 1px solid var(--line); }
dialog .body { padding: 16px 20px; max-height: 65vh; overflow: auto; }
dialog .foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { white-space: pre-line; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); animation: in .18s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes in { from { transform: translateY(6px); opacity: 0; } }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 16px; }
  .brand { padding: 0 8px 0 0; }
  .nav-group { display: none; }
  .nav { display: contents; }
  .nav a { padding: 5px 8px; }
  .side .me { margin: 0 0 0 auto; border: 0; padding: 0; }
  .main { padding: 16px; }
  .ws { grid-template-columns: 1fr; }
  .panels { grid-template-columns: 1fr; }
  .totals { position: static; }
}
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------- Rumbo additions */
.kpi .sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-bottom: 16px; }
.chart .bar-row { display: grid; grid-template-columns: minmax(80px, 34%) 1fr auto; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.chart .bar { height: 10px; border-radius: 6px; background: var(--brand); min-width: 2px; }
.chart .track { background: var(--muted-bg); border-radius: 6px; overflow: hidden; }
.chart .val { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.card.pad, .grid-cards .card { padding: 16px; }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.card p.desc { margin: 0 0 12px; color: var(--ink-2); font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > select, .row > input { min-width: 0; }
.stack { display: grid; gap: 16px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--muted-bg); color: var(--muted); }
.tag.ok { background: var(--ok-bg); color: var(--ok); } .tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.pending { background: var(--warn-bg); color: var(--warn); } .tag.manual { background: var(--info-bg); color: var(--info); }
.punch-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 12px 0; }
.punch-buttons .btn { padding: 14px; font-size: 15px; justify-content: center; }
.clock { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.hello { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.big-number { font-size: 28px; font-weight: 700; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 12px; border-bottom: 2px solid transparent; cursor: pointer; color: var(--ink-2); }
.tabs button.active { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.org ul { list-style: none; margin: 0; padding-left: 22px; border-left: 1px dashed var(--line); }
.org > ul { padding-left: 0; border: 0; }
.org li { margin: 8px 0; }
.org .node { display: inline-block; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; box-shadow: var(--shadow); }
.org .node strong { display: block; }
.org .node .people { font-size: 12px; color: var(--ink-2); }
.result-errors { max-height: 260px; overflow: auto; }
textarea.csv { width: 100%; min-height: 90px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.notice { background: var(--info-bg); color: var(--info); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.notice.with-action { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.notice.with-action > span { flex: 1 1 320px; }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .main { padding: 16px; }
}
