:root {
  --bg: #111317; --rail: #0C0E11; --panel: #181B20; --panel2: #1F232A; --line: #2A2F37; --line2: #363C46;
  --ink: #ECE8E1; --soft: #AEB4BD; --mute: #7B838E;
  --teal: #26A68E; --copper: #D2763A; --bad: #E2706B; --good: #5DBB8A; --warn: #E0B04A;
  --r: 10px; --font: 'Golos Text', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 400 14.5px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
.num, td.n, .kpi .v { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

/* ---------- buttons, inputs ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line2); background: var(--panel2); border-radius: 8px; padding: 7px 13px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--mute); }
.btn.pri { background: var(--teal); border-color: var(--teal); color: #06140F; font-weight: 600; }
.btn.pri:hover { filter: brightness(1.08); }
.btn.danger { border-color: var(--bad); color: var(--bad); background: transparent; }
.btn.danger.sure { background: var(--bad); color: #1A0807; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--soft); }
.btn.ghost:hover { color: var(--ink); border-color: var(--line2); }
.btn:disabled { opacity: .45; cursor: default; }
input[type=text], input[type=number], input[type=search], select, textarea {
  background: #0E1013; border: 1px solid var(--line2); border-radius: 8px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); outline: none; }
textarea { resize: vertical; min-height: 60px; width: 100%; }

/* ---------- sign in ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; }
.login h1 { font-size: 26px; display: flex; align-items: center; gap: 10px; }
.login p { color: var(--soft); margin: 10px 0 22px; }
.login .btn { width: 100%; justify-content: center; padding: 11px; }
.login .st { min-height: 22px; margin-top: 14px; color: var(--mute); font-size: 13px; }
.login .st a { color: var(--teal); }
.mark { width: 26px; height: 26px; border-radius: 7px; background: conic-gradient(from 210deg, var(--teal), var(--copper), var(--teal)); position: relative; flex: none; }
.mark::after { content: ''; position: absolute; inset: 6px; border-radius: 3px; background: var(--rail); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.rail { background: var(--rail); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 2px 8px 16px; }
.rail .sec { color: var(--mute); font-size: 12px; padding: 10px 8px 4px; }
.rail a { white-space: nowrap; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--soft); text-decoration: none; font-weight: 500; }
.rail a:hover { background: var(--panel); color: var(--ink); }
.rail a.on { background: var(--panel2); color: var(--ink); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--mute); }
.dot.err { background: var(--bad); }
.rail .foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 8px; color: var(--mute); font-size: 12.5px; }
main { min-width: 0; padding: 22px 28px 60px; max-width: 1280px; }
.phead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.phead h1 { font-size: 24px; }
.phead .meta { color: var(--mute); font-size: 13px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 12px; color: var(--soft); cursor: pointer; font-weight: 500; white-space: nowrap; margin-bottom: -1px; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--teal); }

/* ---------- dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; margin-bottom: 18px; }
.kpi { background: var(--panel); padding: 14px 16px 15px; }
.kpi .v { font-size: 30px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }
.kpi .v small { font-size: 15px; color: var(--soft); font-weight: 500; margin-left: 3px; }
.kpi .l { color: var(--soft); font-size: 13px; margin-top: 4px; }
.kpi .h { color: var(--mute); font-size: 12px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; min-width: 0; }
.card h2 { font-size: 15.5px; }
.card .note { color: var(--mute); font-size: 12.5px; margin: 2px 0 10px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .ax { fill: var(--mute); font-size: 11px; font-family: var(--font); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart #xh { stroke: var(--mute); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .tip { position: absolute; pointer-events: none; background: #0B0D10; border: 1px solid var(--line2); border-radius: 7px; padding: 5px 9px; font-size: 12.5px; white-space: nowrap; transform: translate(-50%, -100%); margin-top: -10px; z-index: 2; }
.chart .tip b { font-variant-numeric: tabular-nums; }
.hbars { display: flex; flex-direction: column; gap: 7px; }
.hbar { display: grid; grid-template-columns: minmax(110px, 38%) 1fr 54px; align-items: center; gap: 10px; font-size: 13px; }
.hbar .lab { color: var(--soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .tr { height: 14px; background: #0E1013; border-radius: 0 4px 4px 0; }
.hbar .fi { height: 100%; border-radius: 0 4px 4px 0; background: var(--teal); }
.hbar .val { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--mute); padding: 10px 0; }

/* ---------- tables ---------- */
.tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.tools input { flex: 1; min-width: 200px; }
.tw { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--mute); font-weight: 500; font-size: 12.5px; background: var(--panel); position: sticky; top: 0; }
td.n, th.n { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: var(--panel2); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line2); color: var(--soft); font-size: 12px; }
.tcount { color: var(--mute); font-size: 12.5px; margin-top: 8px; }

/* ---------- drawer ---------- */
.shade { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--bg); border-left: 1px solid var(--line); z-index: 21; overflow-y: auto; padding: 18px 20px 40px; }
.drawer .dh { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.drawer .dh div { flex: 1; }
.drawer h2 { font-size: 20px; }
.drawer .sub { color: var(--mute); font-size: 13px; }
.kv { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 6px 16px; font-size: 13.5px; }
.kv dt { color: var(--mute); }
.kv dd { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- forms (config, actions) ---------- */
.group { margin-bottom: 14px; }
.group > h2 { font-size: 15.5px; }
.field { display: grid; grid-template-columns: minmax(170px, 230px) 1fr; gap: 6px 18px; align-items: start; padding: 12px 0; border-top: 1px solid var(--line); }
.field:first-of-type { border-top: 0; }
.field .fl { font-weight: 500; padding-top: 6px; }
.field .fl small { display: block; color: var(--mute); font-weight: 400; font-size: 12px; }
.field .ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.field .ctl input[type=number] { width: 120px; }
.field .ctl input[type=text] { width: min(420px, 100%); }
.field .ctl .unit { color: var(--mute); }
.field .help { flex-basis: 100%; color: var(--mute); font-size: 12.5px; }
.field .diff { flex-basis: 100%; font-size: 12.5px; color: var(--warn); }
.field.changed { box-shadow: inset 3px 0 0 var(--warn); padding-left: 12px; margin-left: -12px; }
.field .def { color: var(--mute); font-size: 12px; }
.sw { position: relative; width: 42px; height: 24px; border-radius: 99px; background: var(--line2); border: 0; cursor: pointer; flex: none; }
.sw::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--soft); transition: transform .15s; }
.sw[aria-checked=true] { background: var(--teal); }
.sw[aria-checked=true]::after { transform: translateX(18px); background: #fff; }
.savebar { position: sticky; bottom: 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: rgba(17,19,23,.96); border-top: 1px solid var(--line); padding: 12px 0; margin-top: 8px; backdrop-filter: blur(4px); }
.savebar input { flex: 1; min-width: 200px; }
.savebar .cnt { color: var(--warn); font-size: 13px; }
.hist { display: flex; flex-direction: column; }
.hrow { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); align-items: start; }
.hrow:first-child { border-top: 0; }
.hrow .ver { font-weight: 600; font-variant-numeric: tabular-nums; }
.hrow .when { color: var(--mute); font-size: 12.5px; }
.hrow .ch { font-size: 13px; color: var(--soft); }
.hrow .ch b { color: var(--ink); font-weight: 500; }
.layout2 { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.acts { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.act h3 { font-size: 15px; margin-bottom: 4px; }
.act .confirm { color: var(--mute); font-size: 12.5px; margin-bottom: 8px; }
.act .field { grid-template-columns: 1fr; padding: 6px 0; border: 0; gap: 4px; }
.act .field .fl { padding: 0; font-size: 13px; }
.act .row { display: flex; gap: 8px; margin-top: 10px; }

/* ---------- confirm dialog ---------- */
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 40; background: rgba(0,0,0,.55); padding: 16px; }
.modal .box { width: 100%; max-width: 460px; background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; padding: 20px; }
.modal h2 { font-size: 17px; margin-bottom: 10px; }
.modal ul { margin: 0 0 14px; padding-left: 18px; color: var(--soft); max-height: 50vh; overflow: auto; }
.modal li b { color: var(--ink); font-weight: 500; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- journal ---------- */
.audit td { white-space: normal; vertical-align: top; }
.audit .ok { color: var(--good); }
.audit .no { color: var(--bad); }

.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: #0B0D10; border: 1px solid var(--line2); border-left: 3px solid var(--teal); border-radius: 8px; padding: 10px 16px; z-index: 50; max-width: calc(100% - 32px); box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.toast.bad { border-left-color: var(--bad); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); gap: 4px; }
  .rail .sec { display: none; }
  .brand { padding: 0 10px 0 2px; }
  .rail .foot { margin: 0 0 0 auto; flex-direction: row; padding: 0; }
  .rail .foot .who { display: none; }
  main { padding: 16px 16px 60px; }
  .charts { grid-template-columns: 1fr; }
  .layout2 { grid-template-columns: 1fr; }
  .field { grid-template-columns: 1fr; gap: 6px; }
  .field .fl { padding-top: 0; }
  .kpi .v { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) { .sw::after { transition: none; } }

/* server page (docs/47) */
.alert { padding: 11px 14px; border-radius: 10px; margin: 0 0 12px; font-weight: 500; border: 1px solid; }
.alert.bad { background: rgba(226,112,107,.12); border-color: rgba(226,112,107,.5); color: #F5C2BF; }
.alert.warn { background: rgba(224,176,74,.10); border-color: rgba(224,176,74,.45); color: #F1DCA8; }
.kpi.kwarn .v { color: var(--warn); } .kpi.kbad .v { color: var(--bad); }
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--panel); }
.seg button { border: 0; background: transparent; color: var(--soft); padding: 6px 12px; border-radius: 8px; font: inherit; cursor: pointer; }
.seg button.on { background: var(--teal); color: #06140F; font-weight: 600; }
#body > .card { margin-top: 14px; }
.dot.ok { background: var(--good); }
