:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1e222b; --line: #2a2f3a;
  --text: #e6e8ec; --muted: #8b93a3; --accent: #0a84ff; --ok: #30d158; --bad: #ff453a; --warn: #ff9f0a;
  --radius: 10px; --topbar: 52px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
h4 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); font-weight: 600; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
code.select { user-select: all; word-break: break-all; }
.muted { color: var(--muted); } .sm { font-size: 12px; }
.ok-text { color: var(--ok); } .bad-text { color: var(--bad); }
.wrap { white-space: normal; word-break: break-word; text-align: right; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- layout */
.topbar { height: var(--topbar); display: flex; align-items: center; gap: 24px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 16px; }
.brand.big { font-size: 24px; justify-content: center; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 3px rgba(255,69,58,.25); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { color: var(--muted); padding: 6px 12px; border-radius: 8px; }
.topbar nav a:hover { color: var(--text); background: var(--panel2); }
.topbar nav a.active { color: var(--text); background: var(--panel2); }
.who { display: flex; align-items: center; gap: 10px; }
.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid > .card { margin-bottom: 0; }

/* --- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { border-color: #3a4150; background: #252a35; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
input, select, textarea { width: 100%; background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 8px 10px; font: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=range] { padding: 0; }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); font-size: 14px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 13px; }
.switch-label { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; margin: 0; cursor: pointer; }
.row input, .row select { width: auto; flex: 1; min-width: 140px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--panel2); border: 1px solid var(--line); text-transform: uppercase; letter-spacing: .03em; }
.badge.admin { color: var(--warn); } .badge.operator { color: var(--accent); }
.badge.ok { color: var(--ok); } .badge.bad { color: var(--bad); }
.state { font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: .04em; color: var(--muted); }
.state.running { color: var(--ok); } .state.paused { color: var(--warn); } .state.stopped, .state.error { color: var(--bad); }
.alert { padding: 10px 12px; border-radius: 8px; margin: 8px 0; border: 1px solid; }
.alert.error { border-color: rgba(255,69,58,.4); background: rgba(255,69,58,.1); color: #ffb4ae; }
.alert.ok { border-color: rgba(48,209,88,.4); background: rgba(48,209,88,.08); }
.toast { position: fixed; right: 16px; bottom: 16px; padding: 10px 16px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line); z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.4); max-width: 420px; }
.toast.ok { border-color: var(--ok); } .toast.error { border-color: var(--bad); } .toast.warn { border-color: var(--warn); }
.table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.table th, .table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.table tr.revoked td { opacity: .5; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

/* --- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; padding: 28px; }
.login-card p { text-align: center; margin: 4px 0 20px; }

/* --- home */
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 32px; font-weight: 700; margin: 4px 0; }
.stat .sub { color: var(--muted); font-size: 12px; }
.meter { height: 6px; border-radius: 3px; background: var(--panel2); overflow: hidden; margin: 6px 0; }
.meter span { display: block; height: 100%; background: linear-gradient(90deg, var(--ok), var(--warn), var(--bad)); background-size: 300px 100%; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }

/* --- settings */
.subnav { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 16px; position: sticky; top: var(--topbar); background: var(--bg); padding: 8px 0; z-index: 5; }
.subnav a { padding: 4px 10px; border-radius: 6px; color: var(--muted); font-size: 13px; }
.subnav a:hover { background: var(--panel2); color: var(--text); }
.services { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.service { background: var(--panel2); border-radius: 8px; padding: 12px; display: grid; gap: 8px; }
section[id], form[id] { scroll-margin-top: calc(var(--topbar) + 56px); }

/* --- alarm workspace */
.workspace { height: calc(100vh - var(--topbar)); display: flex; flex-direction: column; }
.tabs { display: flex; align-items: center; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); background: var(--panel); }
.tab { background: none; border: 0; color: var(--muted); padding: 10px 14px; cursor: pointer; font: inherit; font-weight: 600; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-color: var(--accent); }
.tabs-right { margin-left: auto; display: flex; align-items: center; gap: 14px; padding-bottom: 6px; }
.pill { background: var(--panel2); border-radius: 99px; padding: 0 7px; font-size: 11px; margin-left: 4px; }
.pill.hot { background: var(--bad); color: #fff; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 2s infinite; }
.live-dot.off { background: var(--bad); animation: none; }
@keyframes pulse { 50% { opacity: .35; } }
.tab-panel { flex: 1; min-height: 0; }
.tab-panel[hidden] { display: none !important; }

.triage { display: grid; grid-template-columns: 300px 1fr; }
.feed { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.feed-head { display: flex; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.feed-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.feed-item { display: grid; grid-template-columns: 72px 1fr 16px; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); cursor: pointer; border-left: 3px solid transparent; align-items: center; }
.feed-item:hover { background: var(--panel2); }
.feed-item.sel { background: #1f2a3d; border-left-color: var(--accent); }
.feed-item.hp .fi-label { color: var(--bad); }
.feed-item img { width: 72px; height: 48px; object-fit: cover; border-radius: 4px; background: #000; }
.fi-body { min-width: 0; }
.fi-top { display: flex; justify-content: space-between; }
.fi-label { font-weight: 600; text-transform: capitalize; }
.feed-item.v-true .fi-verdict { color: var(--ok); } .feed-item.v-false .fi-verdict { color: var(--bad); }
.feed-item.v-true, .feed-item.v-false { opacity: .65; }
.feed-item.v-none .fi-verdict::after { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.actionbar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.btn.verdict { padding: 10px 22px; font-size: 16px; font-weight: 700; flex-direction: column; gap: 0; line-height: 1.2; min-width: 150px; }
.btn.verdict small { font-weight: 400; font-size: 11px; opacity: .85; }
.btn.verdict.true { background: rgba(48,209,88,.15); border-color: var(--ok); color: var(--ok); }
.btn.verdict.false { background: rgba(255,69,58,.15); border-color: var(--bad); color: var(--bad); }
.btn.verdict.true:hover:not(:disabled), .btn.verdict.true.chosen { background: var(--ok); color: #fff; }
.btn.verdict.false:hover:not(:disabled), .btn.verdict.false.chosen { background: var(--bad); color: #fff; }
.actionbar-info { flex: 1; min-width: 200px; }
.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: #08090b; padding: 12px; overflow: hidden; }
.stage-empty { color: var(--muted); }
.imgwrap { position: relative; display: inline-block; cursor: zoom-in; max-width: 100%; max-height: 100%; line-height: 0; }
.imgwrap img { max-width: 100%; max-height: calc(100vh - var(--topbar) - 250px); display: block; }
.boxes { position: absolute; inset: 0; pointer-events: none; }
.boxes[hidden] { display: none; }
.bbox { position: absolute; border: calc(2px / var(--s, 1)) solid var(--c); box-shadow: 0 0 0 calc(1px / var(--s, 1)) rgba(0,0,0,.6); }
.bbox span { position: absolute; left: -2px; bottom: 100%; background: var(--c); color: #fff; font: 600 calc(11px / var(--s, 1)) / 1.3 system-ui, sans-serif; padding: 0 calc(4px / var(--s, 1)); white-space: nowrap; border-radius: 2px 2px 0 0; }
.details { border-top: 1px solid var(--line); padding: 10px 12px; max-height: 150px; overflow: auto; }
.det-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.chip { display: inline-flex; gap: 4px; align-items: center; padding: 3px 10px; margin: 2px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: inherit; font-size: 12px; cursor: pointer; text-transform: capitalize; }
.chip.on { border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 22%, transparent); }

/* lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.94); z-index: 50; display: flex; flex-direction: column; }
.lightbox[hidden], .modal[hidden] { display: none; }
.lb-tools { display: flex; gap: 8px; padding: 10px; justify-content: center; align-items: center; }
.lb-canvas { flex: 1; overflow: hidden; display: flex; align-items: center; justify-content: center; cursor: grab; touch-action: none; }
.lb-canvas:active { cursor: grabbing; }
.lb-content { position: relative; line-height: 0; transform-origin: center center; will-change: transform; }
.lb-content img { max-width: 96vw; max-height: calc(100vh - 100px); user-select: none; -webkit-user-drag: none; }
.lb-hint { text-align: center; padding: 6px; }

/* learning */
.learning { overflow-y: auto; padding: 16px; }
.learn-top { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.learn-filters { display: flex; flex-direction: column; gap: 10px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { background: var(--panel2); color: var(--muted); border: 0; padding: 6px 12px; font: inherit; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--accent); color: #fff; }
.export { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.hints textarea { margin-bottom: 8px; }
.learn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.learn-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; }
.learn-card:hover { border-color: var(--accent); }
.lc-img img { width: 100%; height: 140px; object-fit: cover; display: block; background: #000; }
.lc-body { padding: 10px; display: grid; gap: 3px; }
.pager { display: flex; gap: 4px; justify-content: center; margin: 16px 0; flex-wrap: wrap; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); width: min(1100px, 100%); max-height: 100%; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.ed-body { display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; padding: 16px; }
.ed-img { position: relative; line-height: 0; align-self: start; }
.ed-img img { width: 100%; border-radius: 6px; }

@media (max-width: 900px) {
  .triage { grid-template-columns: 1fr; grid-template-rows: 200px 1fr; }
  .feed { border-right: 0; border-bottom: 1px solid var(--line); }
  .learn-top, .ed-body { grid-template-columns: 1fr; }
  .topbar { gap: 8px; overflow-x: auto; }
  .who span:not(.badge) { display: none; }
  .tabs-right .switch-label { display: none; }
  .imgwrap img { max-height: 50vh; }
}
