:root {
  --bg: #0b1320; --bg-2: #0f1a2b; --panel: #131f33; --panel-2: #18263d; --line: #22324d; --line-2: #2c405f;
  --text: #dbe4f0; --muted: #8496b0; --faint: #5d6f8a;
  --accent: #2bb7a3; --accent-2: #1d8f80; --accent-soft: rgba(43, 183, 163, .12);
  --ok: #3fbf7f; --warn: #e0a83a; --bad: #e2635c; --info: #5b9be0; --violet: #9b8ae6;
  --radius: 8px; --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; } h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12px; } .mono { font-family: Consolas, monospace; font-size: 12px; }
.right { text-align: right; } .nowrap { white-space: nowrap; } .grow { flex: 1; min-width: 0; } .hidden { display: none !important; }
.pre { white-space: pre-wrap; word-break: break-word; }

#shell { display: flex; min-height: 100%; }
#sidebar { width: 216px; background: var(--bg-2); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { display: flex; gap: 10px; align-items: center; padding: 16px 14px 14px; border-bottom: 1px solid var(--line); }
.brand-mark { width: 30px; height: 30px; border-radius: 7px; background: var(--accent); color: #05221e; font-weight: 700; display: grid; place-items: center; }
.brand-name { font-weight: 600; font-size: 14px; } .brand-sub { font-size: 11px; color: var(--muted); }
#nav { padding: 8px; flex: 1; overflow-y: auto; }
#nav a { display: flex; justify-content: space-between; align-items: center; padding: 7px 10px; border-radius: 6px; color: var(--muted); font-size: 13.5px; }
#nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
#nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
#nav .count { font-size: 11px; background: var(--panel-2); border-radius: 10px; padding: 0 7px; color: var(--text); }
#nav .sep { height: 1px; background: var(--line); margin: 8px 4px; }
.mode-pill { margin: 10px; padding: 8px 10px; border-radius: 6px; font-size: 12px; border: 1px solid var(--line); cursor: pointer; }
.mode-pill.dry { color: var(--info); } .mode-pill.live { color: var(--warn); border-color: var(--warn); } .mode-pill.stop { color: var(--bad); border-color: var(--bad); }
.mode-pill b { display: block; font-size: 12.5px; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 12px; padding: 12px 22px; border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 5; }
#topbar h1 { font-size: 17px; flex: 1; }
#topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
#menu-btn { display: none; }
#view { padding: 18px 22px 60px; outline: none; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.panel > h2 { margin-bottom: 10px; display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.panel.flush { padding: 0; overflow: hidden; }
.panel.flush > h2 { padding: 12px 16px 0; }
.grid { display: grid; gap: 14px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.split { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); } .split-rev { grid-template-columns: 330px minmax(0, 1fr); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; cursor: pointer; display: block; color: inherit; }
.stat:hover { border-color: var(--line-2); text-decoration: none; }
.stat .n { font-size: 22px; font-weight: 600; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); }
.stat.attn .n { color: var(--warn); } .stat.bad .n { color: var(--bad); } .stat.good .n { color: var(--ok); }

button, .btn { font: inherit; border-radius: 6px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text); padding: 6px 12px; cursor: pointer; white-space: nowrap; }
button:hover:not(:disabled), .btn:hover { border-color: var(--accent-2); text-decoration: none; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #05221e; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #35c8b3; }
button.danger { border-color: #6d3330; color: #f0a39e; } button.danger:hover:not(:disabled) { border-color: var(--bad); }
button.warn { background: var(--warn); border-color: var(--warn); color: #2a1c00; font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); padding: 4px 8px; }
button.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--line); }
button.sm { padding: 3px 8px; font-size: 12px; }
.icon-btn { background: transparent; border: 0; font-size: 18px; color: var(--text); padding: 2px 8px; }

input, select, textarea { font: inherit; color: var(--text); background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 6px 9px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
textarea.email-body { min-height: 330px; font-size: 14px; }
label.f { display: block; }
label.f > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
label.f > small { display: block; font-size: 11.5px; color: var(--faint); margin-top: 3px; }
label.chk { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line-2); border-radius: 14px; padding: 3px 10px; font-size: 12.5px; cursor: pointer; color: var(--muted); background: transparent; user-select: none; }
.chip.on { background: var(--accent-soft); border-color: var(--accent-2); color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; color: var(--muted); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel); position: sticky; top: 0; }
th.sortable { cursor: pointer; } th.sortable:hover { color: var(--text); }
td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255, 255, 255, .025); }
tr.sel { background: var(--accent-soft); }
td.name { min-width: 170px; }
td.clip { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 26px 16px; text-align: center; color: var(--muted); }

.badge { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 10px; border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: rgba(63, 191, 127, .45); } .badge.warn { color: var(--warn); border-color: rgba(224, 168, 58, .45); }
.badge.bad { color: var(--bad); border-color: rgba(226, 99, 92, .5); } .badge.info { color: var(--info); border-color: rgba(91, 155, 224, .45); }
.badge.accent { color: var(--accent); border-color: var(--accent-2); } .badge.violet { color: var(--violet); border-color: rgba(155, 138, 230, .5); }
.score { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.score i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.score.hi i { background: var(--ok); } .score.mid i { background: var(--accent); } .score.low i { background: var(--warn); } .score.vlow i { background: var(--bad); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; background: var(--faint); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); } .dot.info { background: var(--info); }

.notice { border: 1px solid var(--line-2); border-left: 3px solid var(--info); background: var(--bg-2); border-radius: 6px; padding: 9px 12px; margin-bottom: 12px; font-size: 13px; }
.notice.warn { border-left-color: var(--warn); } .notice.bad { border-left-color: var(--bad); } .notice.ok { border-left-color: var(--ok); }
.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 5px 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.origin { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; padding: 0 5px; border-radius: 3px; margin-left: 6px; vertical-align: 1px; }
.origin.fact { background: rgba(63, 191, 127, .14); color: var(--ok); } .origin.ai { background: rgba(155, 138, 230, .16); color: var(--violet); }
.origin.owner { background: rgba(91, 155, 224, .16); color: var(--info); } .origin.unv { background: rgba(224, 168, 58, .14); color: var(--warn); }
.bar { height: 6px; background: var(--bg-2); border-radius: 3px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.breakdown { display: grid; grid-template-columns: 150px 60px minmax(0, 1fr); gap: 4px 10px; align-items: center; font-size: 13px; }
.breakdown .why { grid-column: 1 / -1; color: var(--muted); font-size: 12px; margin: -2px 0 6px; }
.progress { height: 8px; background: var(--bg-2); border-radius: 4px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); transition: width .3s; }
.steps { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.steps li { display: flex; gap: 8px; padding: 3px 0; } .steps li .muted { font-size: 12px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--line); } .list li:last-child { border-bottom: 0; }
.item { padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.item:hover { background: rgba(255, 255, 255, .03); } .item.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.item .t { font-weight: 600; } .item .s { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; border-radius: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 7px 12px; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }

.kanban { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px; align-items: flex-start; }
.kcol { flex: 0 0 218px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); }
.kcol h4 { font-size: 12px; padding: 9px 10px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kcards { padding: 8px; display: grid; gap: 8px; max-height: 62vh; overflow-y: auto; }
.kcard { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 8px 9px; font-size: 12.5px; }
.kcard .t { font-weight: 600; font-size: 13px; display: block; color: var(--text); }
.kcard select { margin-top: 6px; padding: 2px 6px; font-size: 12px; }

#modal-root:empty { display: none; }
.overlay { position: fixed; inset: 0; background: rgba(4, 9, 17, .72); display: grid; place-items: start center; padding: 6vh 14px 14px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px; width: min(640px, 100%); box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.modal.wide { width: min(900px, 100%); }
.modal header { padding: 13px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { font-size: 15px; }
.modal .body { padding: 14px 16px; max-height: 70vh; overflow-y: auto; }
.modal footer { padding: 11px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 80; max-width: min(420px, 92vw); }
.toast { background: var(--panel-2); border: 1px solid var(--line-2); border-left: 3px solid var(--accent); border-radius: 6px; padding: 9px 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); font-size: 13px; }
.toast.error { border-left-color: var(--bad); } .toast.warn { border-left-color: var(--warn); }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 30px; text-align: center; color: var(--muted); }
.banner-live { background: rgba(224, 168, 58, .1); border: 1px solid var(--warn); color: var(--warn); border-radius: 6px; padding: 9px 12px; margin-bottom: 12px; font-weight: 600; }
.banner-dry { background: rgba(91, 155, 224, .08); border: 1px solid rgba(91, 155, 224, .5); color: var(--info); border-radius: 6px; padding: 9px 12px; margin-bottom: 12px; }
pre.log { background: var(--bg-2); border: 1px solid var(--line); border-radius: 6px; padding: 10px; font: 12px/1.5 Consolas, monospace; max-height: 60vh; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0; }

@media (max-width: 980px) {
  .cols-2, .cols-3, .split, .split-rev { grid-template-columns: minmax(0, 1fr); }
  #sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  #shell.nav-open #sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .55); }
  #menu-btn { display: block; }
  #view { padding: 14px 12px 60px; } #topbar { padding: 10px 12px; }
  .kv { grid-template-columns: 110px minmax(0, 1fr); }
  .breakdown { grid-template-columns: 120px 50px minmax(0, 1fr); }
  button, .btn { padding: 8px 12px; } button.sm { padding: 5px 9px; }
  textarea.email-body { min-height: 260px; }
}
@media (max-width: 980px) {
  #topbar { flex-wrap: wrap; position: static; }
  #topbar h1 { flex: 1 1 60%; }
  #topbar-actions { flex: 1 1 100%; }
}

.big-actions { margin-bottom: 14px; }
button.big { font-size: 15px; padding: 11px 20px; font-weight: 600; }
button.big.attn { border-color: var(--warn); color: var(--warn); }
.flow { display: flex; align-items: stretch; gap: 6px; margin-bottom: 14px; overflow-x: auto; padding-bottom: 4px; }
.flow .arrow { align-self: center; color: var(--faint); font-size: 18px; }
.flow-step { flex: 1 1 0; min-width: 118px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 11px; color: inherit; display: block; }
.flow-step:hover { border-color: var(--accent-2); text-decoration: none; }
.flow-step.on { border-color: var(--warn); }
.flow-step .n { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.flow-step.on .n { color: var(--warn); }
.flow-step .t { font-weight: 600; font-size: 13px; } .flow-step .s { font-size: 11.5px; color: var(--muted); }

.next-step { border-color: var(--accent-2); background: linear-gradient(0deg, var(--accent-soft), var(--accent-soft)), var(--panel); }
.next-step .next-text { font-size: 16px; margin-top: 4px; }
.guide-step h2 { justify-content: space-between; }
.guide-n { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #05221e; font-weight: 700; margin-right: 9px; font-size: 13px; }
.guide-step ul, .panel ul { margin: 0; padding-left: 20px; } .guide-step li { margin: 4px 0; }
