:root {
  --bg: #f4f5fa; --panel: #ffffff; --ink: #1c1836; --muted: #6b6f85; --line: #e4e6f0;
  --brand: #3b4cdb; --brand-ink: #ffffff; --brand-soft: #eceefc;
  --ok: #157a46; --ok-soft: #e3f5ea; --warn: #9a6200; --warn-soft: #fdf1d9; --bad: #b3261e; --bad-soft: #fbe5e3;
  --side: #14122b; --side-ink: #c9cbe6;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0e1f; --panel: #1a1833; --ink: #eceaff; --muted: #9a9cbc; --line: #2c2a4d;
    --brand: #6f7dff; --brand-ink: #0f0e1f; --brand-soft: #262a5c;
    --ok: #55d08c; --ok-soft: #123a27; --warn: #f0b95a; --warn-soft: #3d2f10; --bad: #ff8f86; --bad-soft: #4a1c19;
    --side: #0a0918;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; color: #fff; font-weight: 700; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: #3b4cdb; display: grid; place-items: center; font-size: 14px; }
.brand small { display: block; font-weight: 400; color: var(--side-ink); font-size: 11px; }
.side a.nav { display: block; padding: 9px 12px; border-radius: 8px; color: var(--side-ink); text-decoration: none; }
.side a.nav:hover { background: rgba(255,255,255,.07); }
.side a.nav.on { background: #3b4cdb; color: #fff; }
.side .grow { flex: 1; }
.side button.link { background: none; border: 0; color: var(--side-ink); text-align: left; padding: 9px 12px; cursor: pointer; border-radius: 8px; font: inherit; }
.side button.link:hover { background: rgba(255,255,255,.07); }
main.content { padding: 24px 28px 60px; min-width: 0; max-width: 1280px; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card.narrow { max-width: 460px; margin: 12vh auto; }
.grid { display: grid; gap: 14px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .n { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.kpi .l { color: var(--muted); font-size: 12px; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 9px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-weight: 600; margin-bottom: 4px; }
label.f > small { display: block; color: var(--muted); margin-top: 3px; font-size: 12px; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--ink); }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; }
textarea { min-height: 84px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-weight: 600; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { width: auto; }
.row input, .row select { min-width: 140px; }
.formgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 0 20px; }
.formgrid .wide { grid-column: 1 / -1; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs button { background: none; border: 0; padding: 9px 14px; cursor: pointer; font: inherit; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
th.s { cursor: pointer; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--brand-soft); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.gray { background: var(--line); color: var(--muted); }

.banner { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; background: var(--warn-soft); color: var(--warn); border: 1px solid transparent; }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }

.bars .b { display: grid; grid-template-columns: 110px 1fr 40px; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; }
.bars .track { background: var(--line); border-radius: 6px; height: 10px; overflow: hidden; }
.bars .fill { background: var(--brand); height: 100%; border-radius: 6px; }
.daily { display: flex; align-items: flex-end; gap: 3px; height: 110px; padding-top: 6px; }
.daily .col { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.daily .col.zero { background: var(--line); }

pre.log { background: #0d0c1c; color: #d7d9f5; padding: 14px; border-radius: 10px; max-height: 480px; overflow: auto; font: 12px/1.55 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
iframe.preview { width: 100%; height: 760px; border: 1px solid var(--line); border-radius: 10px; background: #eef0f7; }
.dialog-back { position: fixed; inset: 0; background: rgba(10,9,24,.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.dialog { background: var(--panel); border-radius: 14px; padding: 22px; width: min(560px, 100%); max-height: 90vh; overflow: auto; }
.dialog.wide { width: min(900px, 100%); }
.dl { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; font-size: 13px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }

#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: 420px; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); color: #fff; }

body.plain { display: block; }
body.plain .card.narrow h1 { margin-bottom: 12px; }
form.login { display: grid; gap: 4px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side .grow { display: none; }
  .brand { padding-bottom: 4px; width: 100%; }
  main.content { padding: 16px 14px 60px; }
}
