:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #0f172a; --muted: #64748b; --line: #e5e7eb;
  --brand: #0f766e; --good: #15803d; --good-bg: #dcfce7; --warn: #b45309; --warn-bg: #fef3c7;
  --bad: #b91c1c; --bad-bg: #fee2e2; --info-bg: #e0f2fe; --info: #0369a1;
  --c-runs: #0f766e; --c-emails: #94a3b8;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --panel: #111827; --ink: #e5e7eb; --muted: #94a3b8; --line: #1f2937;
    --good: #4ade80; --good-bg: #14532d55; --warn: #fbbf24; --warn-bg: #78350f55;
    --bad: #f87171; --bad-bg: #7f1d1d55; --info-bg: #0c4a6e55; --info: #7dd3fc;
    --c-runs: #2dd4bf; --c-emails: #475569;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); display: flex; min-height: 100vh; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

/* sidebar */
.sidebar { width: 230px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line);
  padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 16px; display: flex; align-items: center; gap: 8px; }
.brand small { color: var(--muted); font-weight: 500; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
nav { flex: 1; }
nav > a, nav summary > a { display: block; padding: 7px 10px; border-radius: 7px; }
nav a.active { background: var(--info-bg); color: var(--info); font-weight: 600; }
nav a:hover { text-decoration: none; background: var(--bg); }
.nav-label { margin: 16px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
details summary { list-style: none; cursor: pointer; position: relative; }
details summary::-webkit-details-marker { display: none; }
details summary::after { content: "▸"; position: absolute; right: 10px; top: 7px; color: var(--muted); }
details[open] summary::after { content: "▾"; }
a.sub { display: block; padding: 5px 10px 5px 30px; color: var(--muted); border-radius: 7px; font-size: 13px; }
a.sub.active { color: var(--info); background: var(--info-bg); }
.swatch { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 8px; }
.swatch.big { width: 14px; height: 14px; }
.sync { font-size: 12px; color: var(--muted); padding: 10px; border-top: 1px solid var(--line); }

/* main */
main { flex: 1; min-width: 0; padding: 0 24px 40px; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 18px 0 10px; flex-wrap: wrap; }
.topbar h1 { font-size: 20px; margin: 0; flex: 1; display: flex; align-items: center; gap: 4px; }
.crumb { color: var(--muted); }
.burger { display: none; font-size: 22px; cursor: pointer; }
.periods { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.periods a { padding: 6px 12px; font-size: 13px; color: var(--muted); }
.periods a.on { background: var(--ink); color: var(--panel); }
.periods a:hover { text-decoration: none; }
section { margin-top: 22px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }

/* kpis */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; }
a.kpi:hover { text-decoration: none; border-color: var(--muted); }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi b { font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi b.txt { font-size: 15px; padding-top: 6px; font-weight: 600; }
.kpi small { color: var(--muted); font-size: 12px; }
.kpi.good b { color: var(--good); } .kpi.warn b { color: var(--warn); } .kpi.bad b { color: var(--bad); }
.kpi.sel { border-color: var(--ink); }

/* agent cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.card:hover { text-decoration: none; border-color: var(--accent); }
.card-head { display: flex; flex-direction: column; } .card-head b { font-size: 16px; }
.card-stats { display: flex; gap: 18px; }
.card-stats div { display: flex; flex-direction: column; } .card-stats b { font-size: 20px; } .card-stats span { font-size: 12px; color: var(--muted); }
.card-stats .bad b { color: var(--bad); }
.card-foot { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 8px; }

/* bars */
.bars { display: flex; gap: 6px; align-items: flex-end; height: 140px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 12px 6px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.bar .stack { flex: 1; width: 100%; max-width: 28px; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; }
.seg { border-radius: 3px 3px 0 0; } .seg.runs { background: var(--c-runs); border-radius: 0 0 2px 2px; } .seg.emails { background: var(--c-emails); }
.bar span { font-size: 11px; color: var(--muted); margin-top: 4px; }
.legend { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 8px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin: 0 4px 0 8px; }
.l-runs { background: var(--c-runs); } .l-emails { background: var(--c-emails); }

/* tables */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); }
tr:last-child td { border-bottom: 0; }
td a { color: var(--info); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; } .clip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: 12px; } .bad { color: var(--bad); }
.empty { color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: 10px; padding: 18px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; text-transform: capitalize; }
.badge.ok, .badge.accepted, .badge.inv-invoiced { background: var(--good-bg); color: var(--good); }
.badge.warning, .badge.pending, .badge.inv-partial, .badge.inv-not_invoiced { background: var(--warn-bg); color: var(--warn); }
.badge.error, .badge.void { background: var(--bad-bg); color: var(--bad); }
.badge.running { background: var(--info-bg); color: var(--info); }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 5px; background: var(--bg); border: 1px solid var(--line); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; }
.chip { padding: 4px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; }
.chip.sel { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.chip:hover { text-decoration: none; }

.alert { background: var(--bad-bg); color: var(--bad); border-radius: 10px; padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin-top: 8px; }
.alert a { text-decoration: underline; }
pre.log { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; overflow-x: auto; font-size: 12.5px; white-space: pre-wrap; }

/* mobile */
@media (max-width: 760px) {
  .sidebar { position: fixed; left: -260px; z-index: 10; transition: left .2s; box-shadow: 0 0 30px #0004; }
  #nav-toggle:checked ~ .sidebar { left: 0; }
  .burger { display: block; }
  main { padding: 0 16px 40px; }
  .periods { width: 100%; } .periods a { flex: 1; text-align: center; }
}

/* run-job buttons */
.btn { display: inline-block; padding: 7px 14px; border-radius: 8px; background: var(--brand); color: #fff; font-weight: 600;
  font-size: 13px; border: 0; cursor: pointer; text-align: center; }
.btn:hover { text-decoration: none; filter: brightness(1.1); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.big { padding: 12px 22px; font-size: 15px; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.card .btn { margin-top: auto; align-self: flex-start; }
.confirm { max-width: 640px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-top: 12px; }
.confirm h2 { font-size: 18px; text-transform: none; letter-spacing: 0; color: var(--ink); }
.confirm form { display: flex; gap: 10px; align-items: center; margin-top: 16px; }
.warn-box { background: var(--warn-bg); color: var(--warn); }
.badge.busy { background: var(--warn-bg); color: var(--warn); }
.card .badge { align-self: flex-start; }

/* dry runs */
.btn.dry { background: transparent; color: var(--info); border: 1.5px dashed var(--info); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: auto; }
.card .btn-row .btn { margin-top: 0; }
.info-box { background: var(--info-bg); color: var(--info); }
.badge.mode-dry { background: var(--info-bg); color: var(--info); border: 1px dashed var(--info); }
.badge.mode-live { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
.badge.unknown { background: var(--bg); color: var(--muted); }
.confirm.is-dry { border: 1.5px dashed var(--info); }

/* logo */
.brand { text-decoration: none; color: var(--ink); flex-wrap: wrap; }
.brand:hover { text-decoration: none; }
.brand { flex-direction: column; align-items: flex-start; gap: 4px; }
.brand .logo { width: 190px; max-width: 100%; height: auto; display: block; }
.brand:has(.logo) small { padding-left: 2px; letter-spacing: .08em; text-transform: uppercase; font-size: 11px; }

/* overview split panels */
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.panel h2 a { color: var(--muted); }
.kpis.two { grid-template-columns: 1fr 1fr; }
.panel .empty { margin: 0; }

/* people / drivers */
.people { display: grid; gap: 8px; margin-bottom: 14px; }
.person { display: grid; grid-template-columns: 34px 80px 1fr 40px; align-items: center; gap: 10px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.person:hover { text-decoration: none; border-color: var(--muted); }
.person.sel { border-color: var(--ink); }
.person b { font-size: 20px; text-align: right; font-variant-numeric: tabular-nums; }
.pbar { height: 12px; background: var(--bg); border-radius: 0 4px 4px 0; overflow: hidden; }
.pbar span { display: block; height: 100%; background: var(--brand); border-radius: 0 4px 4px 0; min-width: 2px; }
.people.mini { grid-template-columns: repeat(3, 1fr); margin: 0; }
.people.mini .person { grid-template-columns: 28px 1fr auto; padding: 6px 10px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--info-bg);
  color: var(--info); font-weight: 700; }
.avatar.sm { width: 22px; height: 22px; font-size: 11px; vertical-align: middle; }
.people.mini .avatar { width: 26px; height: 26px; font-size: 12px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

/* stock chart: current stock as % of 3-month target (axis 0-125%, target at 80% of width) */
.stockchart { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 14px; }
.stockchart.compact { border: 0; padding: 0; background: transparent; margin: 10px 0 6px; }
.sc-head, .sc-row { display: grid; grid-template-columns: minmax(180px, 2fr) 3fr 90px 60px; gap: 14px; align-items: center; }
.sc-head { font-size: 12px; color: var(--muted); padding: 8px 0 6px; border-bottom: 1px solid var(--line); }
.sc-axis { position: relative; height: 14px; }
.sc-axis i { position: absolute; font-style: normal; transform: translateX(-50%); white-space: nowrap; }
.sc-axis i:first-child { transform: none; }
.sc-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.sc-row:last-child { border-bottom: 0; }
.sc-row:hover { background: var(--bg); }
.sc-label { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: baseline; min-width: 0; }
.sc-label b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sc-label small { grid-column: 2; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sc-label .spill { grid-row: span 2; align-self: center; }
.sc-track { position: relative; height: 16px; border-radius: 0 4px 4px 0; background: var(--bg); }
.sc-track.t-urgent { background: var(--bad-bg); }
.sc-track.t-below { background: var(--warn-bg); }
.sc-track.t-ok { background: var(--good-bg); }
.sc-fill { position: absolute; left: 0; top: 2px; bottom: 2px; border-radius: 0 4px 4px 0; }
.f-urgent { background: var(--bad); } .f-below { background: var(--warn); } .f-ok { background: var(--good); } .f-nodata { background: var(--muted); }
.sc-target { position: absolute; left: 80%; top: -3px; bottom: -3px; width: 2px; background: var(--ink); border-radius: 1px; }
.sc-val { font-size: 13px; color: var(--muted); } .sc-val b { color: var(--ink); font-size: 14px; }
.sc-order b { color: var(--ink); }
.compact .sc-row { grid-template-columns: minmax(130px, 1.4fr) 2fr 70px; padding: 6px 0; }
.compact .sc-order { display: none; }
.spill { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.s-urgent { background: var(--bad-bg); color: var(--bad); } .s-below { background: var(--warn-bg); color: var(--warn); }
.s-ok { background: var(--good-bg); color: var(--good); } .s-nodata { background: var(--bg); color: var(--muted); }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin: 0 3px 0 8px; }
.key.k-target { width: 2px; height: 12px; background: var(--ink); }
.legend-line { margin-top: 10px; }
.report-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.report-bar form { display: flex; gap: 8px; align-items: center; }
select { font: inherit; padding: 5px 8px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
@media (max-width: 760px) {
  .sc-head { display: none; }
  .sc-row { grid-template-columns: 1fr 80px; row-gap: 6px; }
  .sc-track { grid-column: 1 / -1; grid-row: 2; }
  .sc-order { display: none; }
  .people.mini { grid-template-columns: 1fr; }
  .person { grid-template-columns: 30px 70px 1fr 34px; }
}
.split { align-items: start; }
.sc-label .spill { min-width: 104px; text-align: left; }
.compact .sc-label { grid-template-columns: 12px 1fr; }
.compact .sc-label .spill { min-width: 0; width: 10px; height: 10px; padding: 0; font-size: 0; border-radius: 3px; }
.compact .s-urgent { background: var(--bad); } .compact .s-below { background: var(--warn); } .compact .s-ok { background: var(--good); }
.alert.info-box, .alert.warn-box { display: block; line-height: 1.6; }

/* ---- logins, users, audit, controls ---- */
.auth-body { display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px 24px; flex: none; }
.auth-logo { width: 220px; max-width: 100%; display: block; }
.auth-sub { margin: 6px 0 18px; text-transform: uppercase; letter-spacing: .08em; }
.auth-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.auth-form label, .add-user label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input[type=email], input[type=password], input[type=text], input[type=date], input:not([type]), .add-user select {
  font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
input:focus, select:focus { outline: 2px solid var(--info); outline-offset: 1px; }
.auth-form .btn { margin-top: 6px; }
.add-user { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: end; max-width: none; }
form.inline { display: inline-flex; gap: 6px; margin: 0; }
code.temp { font-size: 15px; padding: 3px 8px; user-select: all; }
tr.muted td { opacity: .55; }

.me { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.me > a:first-child { display: flex; align-items: center; gap: 8px; min-width: 0; }
.me > a:first-child span:last-child { display: flex; flex-direction: column; min-width: 0; }
.me b { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me small { color: var(--muted); font-size: 11px; }
.me:hover a { text-decoration: none; }

.pause-banner { display: block; background: var(--bad-bg); color: var(--bad); border: 1px solid var(--bad); border-radius: 10px;
  padding: 10px 14px; margin: 4px 0 14px; }
.pause-banner:hover { text-decoration: none; filter: brightness(1.03); }
.btn.danger { background: var(--bad); }
.ctl-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 14px 0; }
.ctl { background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--accent, var(--ink)); border-radius: 10px;
  padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.ctl.is-paused { background: var(--bad-bg); border-color: var(--bad); }
.ctl-head { display: flex; justify-content: space-between; align-items: center; font-size: 16px; }
.ctl form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }
.ctl input { flex: 1; min-width: 120px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.badge.paused { background: var(--bad-bg); color: var(--bad); }
.badge.cat-auth { background: var(--info-bg); color: var(--info); }
.badge.cat-job { background: var(--warn-bg); color: var(--warn); }
.badge.cat-control { background: var(--bad-bg); color: var(--bad); }
.badge.cat-user { background: var(--good-bg); color: var(--good); }
.badge.cat-view, .badge.cat-system { background: var(--bg); color: var(--muted); }
