/* hub — the operator's console.
   Design: an instrument panel, not a brochure. Golos Text (Cyrillic-first UI face) for
   everything read, JetBrains Mono for paths, keys and aligned figures. Cool-tinted neutrals,
   one cobalt accent for "yours to act on", semantic colours (ok / warn / danger) kept apart
   from the accent. One rule for colours: every colour is a token from the blocks below and
   nothing else in this file or in a template names one (tests/test_theme.py checks). Light is
   the base, dark overrides the same tokens, so a new element built from tokens is right in
   both themes by construction. */

@import url("/static/fonts/fonts.css");

:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #171c24;
  --text-muted: #5b6573;
  --text-faint: #8b95a3;
  --border: #dfe4ea;
  --border-strong: #c3cbd5;
  --accent: #2b63d9;
  --accent-soft: #e3ecfb;
  --accent-2: #9db9ec;   /* a second, quieter accent: a segment inside a bar */
  --on-accent: #ffffff;
  --ok: #1e8f4e;
  --ok-soft: #dff5e7;
  --warn: #b8700f;
  --warn-soft: #fbefd6;
  --danger: #d33a3a;
  --danger-soft: #fbe3e3;
  --mine: #e9f0fd;
  --code-bg: #eaeef3;
  --focus: #8db2ff;
  --shadow: 0 1px 2px rgba(23, 28, 36, 0.06), 0 4px 12px rgba(23, 28, 36, 0.04);
  --nav-h: 58px;
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1319;
    --surface: #151b23;
    --surface-2: #1c242e;
    --text: #e7ebf0;
    --text-muted: #98a3b0;
    --text-faint: #6c7784;
    --border: #26303c;
    --border-strong: #3a4653;
    --accent: #7aa7ff;
    --accent-soft: #1a2a45;
    --accent-2: #3d5a8f;
    --on-accent: #0b1220;
    --ok: #4ccf7f;
    --ok-soft: #143222;
    --warn: #f0b545;
    --warn-soft: #3a2b0c;
    --danger: #f36a6a;
    --danger-soft: #3f1a1a;
    --mine: #172741;
    --code-bg: #0e1319;
    --focus: #3b82f6;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1319;
  --surface: #151b23;
  --surface-2: #1c242e;
  --text: #e7ebf0;
  --text-muted: #98a3b0;
  --text-faint: #6c7784;
  --border: #26303c;
  --border-strong: #3a4653;
  --accent: #7aa7ff;
  --accent-soft: #1a2a45;
  --accent-2: #3d5a8f;
  --on-accent: #0b1220;
  --ok: #4ccf7f;
  --ok-soft: #143222;
  --warn: #f0b545;
  --warn-soft: #3a2b0c;
  --danger: #f36a6a;
  --danger-soft: #3f1a1a;
  --mine: #172741;
  --code-bg: #0e1319;
  --focus: #3b82f6;
  --shadow: none;
}
/* ---- end of colour tokens: no colour literals below this line ---- */

* { box-sizing: border-box; }
/* Nothing may widen the page: a phone that scrolls sideways also loses the fixed nav
   below the fold (fixed boxes follow the layout viewport, not the visible one). */
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  font-feature-settings: "tnum" 0;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden; max-width: 100vw;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button, input, textarea, select { font: inherit; color: inherit; }
code, pre, .mono { font-family: var(--mono); }
.num, time, .cost, .metric .v { font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---- shell: top bar + content + bottom nav (phone) / sidebar (desktop) ---- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; align-items: center; gap: 8px;
  height: 54px; padding: 0 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .back { font-size: 22px; padding: 4px 10px 6px; margin-left: -10px; line-height: 1; border-radius: var(--radius-sm); }
.topbar .back:hover { background: var(--surface-2); text-decoration: none; }
.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.01em; }
.topbar .sub { color: var(--text-faint); font-weight: 400; font-size: 14px; font-family: var(--mono); }
.topbar form { margin: 0; }
.topbar .btn.small { padding: 6px 10px; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface); border-top: 1px solid var(--border);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-muted); font-size: 11px; font-weight: 500; letter-spacing: .01em; position: relative;
}
.nav a:hover { text-decoration: none; }
.nav a .ic { font-size: 19px; line-height: 1; }
.nav a.on { color: var(--accent); }
.nav a.off { opacity: .45; }
.badge {
  position: absolute; top: 5px; left: calc(50% + 4px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: var(--on-accent); font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums;
}

main { max-width: 780px; margin: 0 auto; padding: 14px 14px 28px; }

@media (min-width: 900px) {
  body { padding-bottom: 0; padding-left: 232px; }
  .nav {
    left: 0; right: auto; top: 0; bottom: 0; width: 232px; height: auto;
    flex-direction: column; justify-content: flex-start; padding: 14px 10px; gap: 2px;
    border-top: 0; border-right: 1px solid var(--border);
  }
  .nav a { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm); font-size: 14px; }
  .nav a .ic { font-size: 16px; width: 20px; text-align: center; }
  .nav a.on { background: var(--accent-soft); color: var(--accent); }
  .nav .badge { position: static; margin-left: auto; }
  .nav .brand { font-weight: 700; font-size: 15px; letter-spacing: .04em; text-transform: lowercase; padding: 6px 12px 18px; color: var(--text); }
  .topbar { padding: 0 24px; }
  main { padding: 22px 28px 48px; }
}
@media (max-width: 899px) { .nav .brand { display: none; } }

/* ---- primitives ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin: 10px 0; box-shadow: var(--shadow);
}
.card.attention { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.card.danger { border-color: var(--danger); }
.card.mine { background: var(--mine); border-color: transparent; margin-left: 28px; box-shadow: none; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 500; line-height: 1; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ok { border-color: var(--ok); color: var(--ok); }
.btn.ok:hover { background: var(--ok-soft); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--surface-2); color: var(--text-muted); white-space: nowrap;
}
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
a.chip:hover { text-decoration: none; filter: brightness(.96); }

.field {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
}
.field:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

.meta { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; color: var(--text-muted); font-size: 13px; }
.meta time { color: var(--text-faint); font-family: var(--mono); font-size: 12px; }
.empty { color: var(--text-muted); text-align: center; padding: 32px 0; }
.error { color: var(--danger); text-align: center; }
.section-title { margin: 22px 2px 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); }
.section-title.first { margin-top: 0; }

/* ---- items (feed and chat) ---- */
.item .head { display: flex; gap: 12px; align-items: flex-start; }
.item .icon {
  flex: 0 0 34px; width: 34px; height: 34px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); font-size: 17px; line-height: 1;
}
.item.attention .icon { background: var(--accent-soft); }
.item.danger .icon { background: var(--danger-soft); }
.item.mine .icon { background: var(--surface); }
.item .title { font-weight: 600; flex: 1; min-width: 0; overflow-wrap: anywhere; padding-top: 6px; line-height: 1.35; }
.item .title a { font-weight: 600; }
.item .note { color: var(--text-muted); font-style: italic; margin: 6px 0 0 46px; }
.item .meta { margin: 6px 0 0 46px; }
.item .body { margin: 10px 0 0 46px; }
.item .actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0 46px; }
.item .actions form { display: flex; gap: 6px; margin: 0; }
.item .actions form.text { flex: 1 1 100%; }
.item .actions form.text .field { flex: 1; }
@media (max-width: 480px) {
  .item .note, .item .meta, .item .body, .item .actions { margin-left: 0; }
}

/* ---- rich text ---- */
.md { overflow-wrap: anywhere; max-width: 68ch; }
.md p { margin: 0 0 8px; }
.md p:last-child, .md ul:last-child, .md ol:last-child { margin-bottom: 0; }
.md h3, .md h4, .md h5 { margin: 14px 0 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); }
.md ul, .md ol { margin: 0 0 8px; padding-left: 20px; }
.md li { margin: 3px 0; }
.md code { background: var(--code-bg); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; overflow-wrap: anywhere; }
.md pre { background: var(--code-bg); border: 1px solid var(--border); padding: 10px 12px; border-radius: var(--radius-sm); overflow-x: auto; margin: 6px 0 8px; font-size: 12.5px; line-height: 1.5; }
.md pre code { background: none; padding: 0; white-space: pre; }
.md a { overflow-wrap: anywhere; }
.md table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 13px; margin: 6px 0 8px; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; }
.md img { max-width: 100%; height: auto; }
.md b { font-weight: 600; }

/* ---- processes ---- */
.proc { display: block; color: inherit; position: relative; padding-left: 20px; }
.proc::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 2px; background: var(--border-strong); }
.proc.waiting_approve::before, .proc.waiting_answer::before { background: var(--accent); }
.proc.running::before { background: var(--ok); }
.proc.failed::before { background: var(--danger); }
.proc.paused::before { background: var(--warn); }
.proc:hover { text-decoration: none; border-color: var(--border-strong); }
.proc .line1 { display: flex; gap: 8px; align-items: baseline; }
.proc .key { font-weight: 700; font-family: var(--mono); font-size: 14px; }
.proc .num { color: var(--text-faint); font-size: 12px; font-family: var(--mono); }
.proc .cost { margin-left: auto; color: var(--text-muted); font-size: 13px; font-family: var(--mono); }
.proc .summary { margin: 3px 0 8px; color: var(--text); line-height: 1.4; }

/* ---- process page ---- */
.proc-head h2 { margin: 0 0 4px; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.proc-head h2 .num { color: var(--text-faint); font-weight: 400; font-size: 14px; font-family: var(--mono); }
.proc-head .summary { margin: 0 0 10px; color: var(--text-muted); line-height: 1.45; }
.chat { padding-bottom: 8px; }

.compose {
  position: fixed; left: 0; right: 0; z-index: 4;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-top: 1px solid var(--border);
}
.compose .inner { max-width: 780px; margin: 0 auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.compose textarea { min-height: 44px; max-height: 40vh; resize: none; line-height: 1.45; }
.compose .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.compose .row .spacer { flex: 1; }
.compose .hint { color: var(--text-faint); font-size: 12px; }
body.has-compose { padding-bottom: calc(var(--nav-h) + 150px + env(safe-area-inset-bottom, 0px)); }
@media (min-width: 900px) {
  .compose { left: 232px; bottom: 0; }
  .compose .inner { padding: 12px 28px; }
  body.has-compose { padding-bottom: 160px; }
}

/* ---- overview ---- */
/* Five tiles: the numbers are the point, so they sit on one line across the row —
   the label box is two lines tall whether the label needs them or not. */
.metrics { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.metric { display: grid; grid-template-rows: 2.5em auto auto; align-content: start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 11px; box-shadow: var(--shadow); min-width: 0; }
.metric .l { align-self: end; font-size: 11px; font-weight: 600; line-height: 1.25; text-transform: uppercase; letter-spacing: .08em; color: var(--text-faint); }
.metric .v { font-size: 30px; font-weight: 600; line-height: 1.1; margin-top: 6px; letter-spacing: -0.02em; white-space: nowrap; }
.metric .v .s { font-size: 14px; font-weight: 400; letter-spacing: 0; color: var(--text-muted); margin-left: 5px; }
.metric .s { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
@media (max-width: 719px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(5) { grid-column: 1 / -1; }
}
.metric.warn { border-color: var(--warn); }
.metric.warn .v { color: var(--warn); }
.stack { display: flex; gap: 2px; height: 12px; border-radius: 6px; overflow: hidden; }
.stack .seg { display: block; height: 100%; border-radius: 2px; }
.seg.accent, .legend i.accent { background: var(--accent); }
.seg.warn, .legend i.warn { background: var(--warn); }
.seg.danger, .legend i.danger { background: var(--danger); }
.seg.ok, .legend i.ok { background: var(--ok); }
.seg.plain, .legend i.plain { background: var(--border-strong); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-muted); margin: 8px 2px 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; margin-top: 4px; }
.line { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--border); color: inherit; }
.line:first-of-type { border-top: 0; }
a.line { margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: var(--radius-sm); }
a.line:hover { text-decoration: none; background: var(--surface-2); }
.line .grow { flex: 1; min-width: 0; }
.line .grow b { font-family: var(--mono); font-size: 14px; }
.line .num { color: var(--text-muted); font-size: 13px; white-space: nowrap; font-family: var(--mono); }
.sub { display: block; color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.warn-text { color: var(--warn); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot.danger { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.dot.idle { background: var(--border-strong); }
/* Gauges: one grid for the whole card, so every bar starts and ends on the same
   line and the numbers form a column. */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.section-head .section-title { flex: 1; }
.stamp { font-family: var(--mono); font-size: 11px; color: var(--text-faint); margin: 22px 2px 8px; white-space: nowrap; }
.gauges { display: grid; grid-template-columns: max-content minmax(0, 1fr) max-content; column-gap: 14px; row-gap: 12px; align-items: center; font-size: 13px; }
.gauges .k { font-weight: 500; }
.gauges .track { position: relative; display: flex; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.gauges .track::after { content: ""; position: absolute; left: 80%; top: 0; bottom: 0; width: 1px; background: var(--border-strong); }
.gauges .fill { display: block; height: 100%; background: var(--accent); flex: 0 0 auto; }
.gauges .fill:first-child { border-radius: 4px 0 0 4px; }
.gauges .fill:last-child { border-radius: 0 4px 4px 0; }
.gauges .fill:only-child { border-radius: 4px; }
.gauges .fill.hot { background: var(--warn); }
.gauges .fill.docker { background: var(--accent-2); }
.gauges .num { color: var(--text-muted); white-space: nowrap; font-family: var(--mono); font-size: 12px; text-align: right; }
.card .gauges + .sub { margin-top: 12px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 6px; }
.swatch.docker { background: var(--accent-2); }

/* ---- toast ---- */
#toast { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom, 0px)); z-index: 6; pointer-events: none; display: flex; justify-content: center; }
#toast .msg { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-sm); max-width: 520px; font-weight: 500; }
#toast .msg.bad { background: var(--danger); color: var(--on-accent); }
@media (min-width: 900px) { #toast { left: 232px; bottom: 24px; } }

/* ---- login ---- */
body.login { padding: 0; }
body.login main { text-align: center; padding-top: 22vh; max-width: 420px; }
body.login h1 { font-size: 30px; letter-spacing: .04em; margin-bottom: 22px; }
body.login .btn { font-size: 17px; height: 46px; padding: 0 34px; }
body.login .hint { margin-top: 16px; color: var(--text-muted); }
