:root {
  --bg: #f6f7f9; --panel: #ffffff; --panel-2: #f1f3f6; --text: #16191d; --muted: #5f6b7a; --line: #e2e6eb;
  --accent: #1d4ed8; --accent-ink: #ffffff;
  --ok: #15803d; --ok-bg: #e7f6ec; --warn: #b45309; --warn-bg: #fdf3e2; --crit: #b91c1c; --crit-bg: #fdecec;
  --nodata: #6b7280; --nodata-bg: #eef0f3; --planned: #9aa3ae;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --panel: #171b21; --panel-2: #1e232b; --text: #e7ebf0; --muted: #98a3b1; --line: #2a313b;
    --accent: #93b4ff; --accent-ink: #0f1216;
    --ok: #4ade80; --ok-bg: #11291a; --warn: #fbbf24; --warn-bg: #2d2410; --crit: #f87171; --crit-bg: #321617;
    --nodata: #9ca3af; --nodata-bg: #22272f; --planned: #5d6673;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: inherit; }
.muted { color: var(--muted); }
.error { color: var(--crit); min-height: 1.4em; margin: 0; }
[hidden] { display: none !important; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: .2px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-block; position: relative; }
.logo::after { content: ""; position: absolute; inset: 6px 4px; border-bottom: 2px solid var(--accent-ink); border-left: 2px solid var(--accent-ink); transform: skew(-20deg); }

.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 9px; font-size: 13px; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-card label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.login-card input { font: inherit; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a { text-decoration: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 550; }
.tabs a:hover { background: var(--panel-2); color: var(--text); }
.tabs a.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.freshness { font-size: 13px; color: var(--muted); }
.banner { margin: 12px 20px 0; padding: 10px 14px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); border: 1px solid currentColor; }
.view { padding: 20px; max-width: 1280px; margin: 0 auto; }
.foot { text-align: center; font-size: 12px; padding: 20px 16px 28px; }
h2 { font-size: 18px; margin: 26px 0 10px; font-weight: 650; }
h2:first-child { margin-top: 0; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 13px; color: var(--muted); }
.tile .value { font-size: 28px; font-weight: 700; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.tile.ok .value { color: var(--ok); } .tile.warn .value { color: var(--warn); } .tile.crit .value { color: var(--crit); }

/* Pills */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); background: var(--ok-bg); }
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.crit { color: var(--crit); background: var(--crit-bg); }
.pill.nodata { color: var(--nodata); background: var(--nodata-bg); }
.pill.planned { color: var(--planned); background: transparent; border: 1px dashed var(--planned); }
.pill.planned::before { display: none; }

/* Tables */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; background: var(--panel-2); }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--panel-2); }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.group-row td { background: var(--panel-2); font-weight: 650; font-size: 13px; }
.params { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.params b { color: var(--text); font-weight: 600; }
.detail td { background: var(--panel-2); }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* Sites */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: grid; gap: 8px; }
.card .title { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 650; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13.5px; }
.kv span:nth-child(odd) { color: var(--muted); }

/* Flows */
.flow-picker { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.flow-picker .btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.flow-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.flow-head h2 { margin: 0; }
.flow-canvas { position: relative; overflow-x: auto; padding: 8px 4px 16px; }
.flow-grid { position: relative; display: grid; gap: 22px 46px; align-items: center; min-width: max-content; }
.lane-label { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; padding-right: 8px; white-space: nowrap; }
.step { position: relative; z-index: 1; width: 168px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--nodata); border-radius: 9px; padding: 9px 11px; box-shadow: var(--shadow); font-size: 13.5px; }
.step.ok { border-left-color: var(--ok); } .step.warn { border-left-color: var(--warn); } .step.crit { border-left-color: var(--crit); }
.step.planned { border-style: dashed; border-left-style: solid; border-left-color: var(--planned); opacity: .75; }
.step .name { font-weight: 650; line-height: 1.25; }
.step .meta { margin-top: 5px; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; color: var(--muted); font-size: 12.5px; }
.step .count { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.step .stuck { color: var(--warn); font-weight: 600; }
svg.edges { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
svg.edges path { fill: none; stroke: var(--muted); stroke-width: 1.4; opacity: .7; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 6px; }

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; gap: 10px; }
  .view { padding: 16px; }
  .top-right { margin-left: 0; width: 100%; justify-content: space-between; }
  .tile .value { font-size: 24px; }
}

.version { font-size: 12px; margin: 0; text-align: center; }
.version-badge { font-size: 12px; font-family: var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px; }

/* Admin forms */
.small { font-size: 12px; }
.pad { padding: 16px; display: grid; gap: 12px; }
.form-row { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: end; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-row label, .form-grid label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input, select, textarea { font: inherit; font-size: 14px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; }
textarea { font-family: var(--mono); font-size: 12.5px; width: 100%; }
table.edit input[type=number] { width: 6.5em; } table.edit input[type=text], table.edit input:not([type]) { min-width: 8em; }
table.edit textarea { min-width: 14em; }
input[type=checkbox] { width: 18px; height: 18px; }
.toast { position: fixed; bottom: 20px; right: 20px; z-index: 20; background: var(--ok-bg); color: var(--ok); border: 1px solid currentColor; padding: 10px 14px; border-radius: 9px; box-shadow: var(--shadow); max-width: min(460px, calc(100vw - 32px)); }
.toast.bad { background: var(--crit-bg); color: var(--crit); }

/* ── Shell: sidebar + main (DES Hub Console structure) ── */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--text); padding: 0 16px 14px; text-decoration: none; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.sidebar-brand .version-badge { font-weight: 400; }
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.nav-group { margin-top: 12px; }
.nav-heading { font-size: 10.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 6px 10px 3px; }
.nav-item { display: block; padding: 6px 10px; border-radius: 6px; font-size: 13.5px; font-weight: 500; color: var(--muted); text-decoration: none; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.nav-active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.sidebar-foot { padding: 12px 16px 0; border-top: 1px solid var(--line); margin-top: 12px; color: var(--muted); font-size: 11px; display: grid; gap: 8px; }
.main { min-width: 0; padding: 14px 24px 0; }
.main .view { padding: 0; max-width: 1280px; margin: 0; }
.topline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.tabs .tabs-label { font-size: 12px; color: var(--muted); padding: 3px 8px 3px 10px; }
.tabs button { background: none; border: 0; border-left: 1px solid var(--line); color: var(--muted); font: inherit; font-size: 12px; padding: 4px 11px; cursor: pointer; }
.tabs button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.main .banner { margin: 0 0 12px; }
h1 { font-size: 22px; margin: 4px 0 4px; }
.lede { color: var(--muted); margin: 0 0 18px; }

/* Cards (Overview) */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; border-top: 3px solid var(--line); box-shadow: var(--shadow); display: block; }
.card.tone-ok { border-top-color: var(--ok); } .card.tone-warn { border-top-color: var(--warn); } .card.tone-bad { border-top-color: var(--crit); }
.card header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.card h2 { font-size: 15px; margin: 0; } .card h2 a { color: var(--text); text-decoration: none; } .card h2 a:hover { text-decoration: underline; }
.card footer { margin-top: 12px; padding-top: 8px; border-top: 1px dashed var(--line); color: var(--muted); font-size: 12px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--crit); }
.stats { display: flex; gap: 14px 22px; flex-wrap: wrap; }
.stat-value { font-size: 22px; font-weight: 650; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value.ok { color: var(--ok); } .stat-value.warn { color: var(--warn); } .stat-value.bad { color: var(--crit); }
.hbar { display: grid; grid-template-columns: 130px 1fr; gap: 10px; align-items: center; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.progress { position: relative; background: var(--panel-2); border-radius: 6px; height: 16px; overflow: hidden; }
.progress div { height: 100%; border-radius: 6px; background: var(--accent); opacity: .85; }
.progress div.ok { background: var(--ok); } .progress div.warn { background: var(--warn); } .progress div.bad { background: var(--crit); }
.progress span { position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 16px; font-weight: 600; color: var(--text); }
.mini-list { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 12.5px; }
.mini-list span { display: inline-flex; align-items: center; gap: 6px; }
.issue-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; font-size: 13px; }
table.compact td { padding: 4px 8px 4px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin: 0 0 14px; }
.section > h2 { font-size: 15px; margin: 0 0 6px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.note { color: var(--muted); margin: 0 0 10px; font-size: 13px; }
.doc { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px 26px; }
.doc h2 { font-size: 16px; margin: 20px 0 8px; } .doc h2:first-child { margin-top: 0; }
.doc table { margin: 8px 0; } .doc code { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.stuck { color: var(--warn); font-weight: 600; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-brand { padding: 0; border: 0; margin: 0; }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; gap: 4px; padding: 0; }
  .nav-group { margin: 0; display: contents; }
  .nav-heading, .sidebar-foot div { display: none; }
  .sidebar-foot { border: 0; margin: 0; padding: 0; }
  .main { padding: 12px 16px 0; }
  .cards-grid { grid-template-columns: 1fr; }
}
