/* Agents dashboard. No JavaScript; everything served from this VPS. */
:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --fg: #17191c; --muted: #646a73;
  --border: #e1e4e8; --border-strong: #c9ced6; --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --accent: #2f5bd3; --accent-fg: #ffffff;
  --pos: #18794e; --pos-bg: #e6f4ec; --pos-border: #8fd1ad;
  --neg: #b42318; --neg-bg: #fdecea; --neg-border: #f2a59d;
  --amber: #8a5a00; --amber-bg: #fff5d9; --amber-border: #f1c95c;
  --off: #8b9098; --off-bg: #eef0f3;
  --paper-bg: #fff5d9; --paper-fg: #7a4f00; --live-bg: #b42318; --live-fg: #ffffff;
  --s1: #2f5bd3; --s2: #d0660f; --s3: #7c4ddb; --s4: #18794e;
  --radius: 10px; --gap: 16px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214; --surface: #1a1c1f; --surface-2: #222529; --fg: #eceef1; --muted: #9aa1ab;
    --border: #2c3036; --border-strong: #3a3f46; --shadow: none;
    --accent: #7ea2ff; --accent-fg: #0d1117;
    --pos: #5fd394; --pos-bg: #13291d; --pos-border: #2b6b47;
    --neg: #ff8c80; --neg-bg: #33191a; --neg-border: #7a3530;
    --amber: #f3c35c; --amber-bg: #2e2510; --amber-border: #6b5520;
    --off: #6f7680; --off-bg: #1e2023;
    --paper-bg: #2e2510; --paper-fg: #f3c35c; --live-bg: #b42318; --live-fg: #ffffff;
    --s1: #7ea2ff; --s2: #f29a4a; --s3: #b69bff; --s4: #5fd394;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-variant-numeric: tabular-nums; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: .01em; }
h3 { font-size: 13px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .mono { font-family: var(--mono); font-size: 13px; }
.pos { color: var(--pos); } .neg { color: var(--neg); }

/* banner + top bar */
.mode { text-align: center; font-weight: 700; letter-spacing: .08em; padding: 8px 16px; font-size: 13px; }
.mode.paper { background: var(--paper-bg); color: var(--paper-fg); border-bottom: 1px solid var(--amber-border); }
.mode.live { background: var(--live-bg); color: var(--live-fg); }
.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; color: var(--fg); margin-right: auto; }
.topbar .status { font-size: 13px; color: var(--muted); }
.dot-ok, .dot-bad { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot-ok { background: var(--pos); } .dot-bad { background: var(--neg); }

main { max-width: 1320px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* messages */
.flash, .alert { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 10px; border: 1px solid; }
.flash.ok { background: var(--pos-bg); color: var(--pos); border-color: var(--pos-border); }
.flash.bad, .alert { background: var(--neg-bg); color: var(--neg); border-color: var(--neg-border); }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: var(--gap); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 22px; font-weight: 650; margin-top: 4px; letter-spacing: -.01em; white-space: nowrap; }
.stat .sub { font-size: 12px; color: var(--muted); }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: var(--gap); align-items: start; }
.stack { display: grid; gap: var(--gap); }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--gap); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

/* control room */
.control { border-color: var(--border-strong); }
.control h2 { display: flex; align-items: center; gap: 8px; }
.control section + section { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-top: 1px solid var(--border); font-size: 14px; }
.list li:first-child { border-top: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* buttons / forms */
button, .btn { font: inherit; font-size: 14px; font-weight: 600; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--fg); }
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: .45; cursor: not-allowed; }
.btn-go { background: var(--pos); border-color: var(--pos); color: #fff; }
.btn-go:hover:not(:disabled) { background: var(--pos); filter: brightness(1.08); }
.btn-danger { border-color: var(--neg); color: var(--neg); }
.btn-kill { width: 100%; background: var(--neg); border-color: var(--neg); color: #fff; padding: 10px; letter-spacing: .04em; }
.btn-kill:hover:not(:disabled) { background: var(--neg); filter: brightness(1.08); }
.btn-small { padding: 4px 10px; font-size: 13px; }
.btn-link { border: 0; background: none; color: var(--muted); padding: 0; font-weight: 400; }
form.inline { display: inline; }
input { font: inherit; font-size: 14px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--fg); min-width: 0; }
input:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
details > summary { cursor: pointer; color: var(--muted); font-size: 14px; }
details[open] > summary { margin-bottom: 10px; }

/* pills */
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid; }
.pill.ready { color: var(--pos); background: var(--pos-bg); border-color: var(--pos-border); }
.pill.switched { color: var(--amber); background: var(--amber-bg); border-color: var(--amber-border); }
.pill.off { color: var(--off); background: var(--off-bg); border-color: var(--border); }
.pill.normal { color: var(--muted); background: var(--surface-2); border-color: var(--border); }

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
th.l, td.l { text-align: left; } td.wrap { white-space: normal; min-width: 220px; }
tr:last-child td { border-bottom: 0; }

/* charts */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .ref { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--surface); stroke-width: 1.5; }
.chart .s1 { stroke: var(--s1); } .chart .s2 { stroke: var(--s2); } .chart .s3 { stroke: var(--s3); } .chart .s4 { stroke: var(--s4); }
.chart circle.s1 { fill: var(--s1); } .chart circle.s2 { fill: var(--s2); } .chart circle.s3 { fill: var(--s3); } .chart circle.s4 { fill: var(--s4); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 8px; }
.sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.sw.s1 { background: var(--s1); } .sw.s2 { background: var(--s2); } .sw.s3 { background: var(--s3); } .sw.s4 { background: var(--s4); }
.chart-empty { padding: 32px 0; text-align: center; }

/* family tree (desktop: top-down org chart) */
.tree-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 4px 0 8px; }
.tree { display: flex; justify-content: center; min-width: min-content; }
.tree ul { display: flex; justify-content: center; margin: 0; padding: 22px 0 0; position: relative; list-style: none; }
.tree > ul { padding-top: 0; }
.tree li { position: relative; padding: 22px 8px 0; display: flex; flex-direction: column; align-items: center; }
.tree > ul > li { padding-top: 0; }
.tree li::before, .tree li::after { content: ""; position: absolute; top: 0; right: 50%; width: 50%; height: 22px;
  border-top: 2px solid var(--border-strong); }
.tree li::after { right: auto; left: 50%; border-left: 2px solid var(--border-strong); }
.tree li:only-child::before, .tree li:only-child::after { display: none; }
.tree li:only-child { padding-top: 0; }
.tree li:first-child::before, .tree li:last-child::after { border: 0 none; }
.tree li:last-child::before { border-right: 2px solid var(--border-strong); border-radius: 0 8px 0 0; }
.tree li:first-child::after { border-radius: 8px 0 0 0; }
.tree ul ul::before { content: ""; position: absolute; top: 0; left: 50%; height: 22px; border-left: 2px solid var(--border-strong); }
.tree > ul > li::before, .tree > ul > li::after { display: none; }

.node { width: 210px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow); text-align: left; position: relative; }
.node a.node-link { display: block; padding: 12px 14px 10px; color: var(--fg); text-decoration: none; border-radius: var(--radius); }
.node a.node-link:hover { background: var(--surface-2); }
.node .name { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.node .bal { font-size: 20px; font-weight: 650; margin-top: 2px; }
.node .strat { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node .pl { font-size: 13px; }
.node .actions { padding: 0 14px 12px; }
.node .actions button { width: 100%; }
.node.ready { border-color: var(--pos-border); background: var(--pos-bg); box-shadow: 0 0 0 2px var(--pos-border); }
.node.switched { border-color: var(--amber-border); background: var(--amber-bg); }
.node.off { border-style: dashed; background: var(--off-bg); }
.node.off a.node-link, .node.off .bal { color: var(--off); }
.tree-key { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.tree-key span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px;
  border: 1px solid var(--border-strong); background: var(--surface); vertical-align: -1px; }
.tree-key .k-ready::before { background: var(--pos-bg); border-color: var(--pos-border); }
.tree-key .k-switched::before { background: var(--amber-bg); border-color: var(--amber-border); }
.tree-key .k-off::before { background: var(--off-bg); border-style: dashed; }

/* agent page */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border-strong); }
.timeline li.current::before { background: var(--accent); border-color: var(--accent); }
.notes { font-family: var(--mono); font-size: 13px; white-space: pre-wrap; word-break: break-word; max-height: 520px;
  overflow-y: auto; background: var(--surface-2); border-radius: 8px; padding: 14px; margin: 0; }
.family a { font-weight: 600; }

/* login */
.login { max-width: 380px; margin: 12vh auto 0; }
.login input { width: 100%; margin-bottom: 12px; }
.login button { width: 100%; }

/* responsive */
@media (max-width: 1080px) { .layout { grid-template-columns: 1fr; } }
@media (max-width: 720px) {
  main { padding: 16px; } .topbar { padding: 10px 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat .value { font-size: 18px; }
  .card { padding: 14px; }
  h1 { font-size: 19px; }
  /* tree becomes an indented list */
  .tree { display: block; }
  .tree ul { display: block; padding: 0 0 0 18px; }
  .tree > ul { padding-left: 0; }
  .tree li { display: block; padding: 10px 0 0 16px; }
  .tree > ul > li { padding-left: 0; }
  .tree li::before, .tree li:last-child::before { border: 0; border-top: 2px solid var(--border-strong); border-radius: 0;
    top: 34px; left: 0; right: auto; width: 14px; height: 0; display: block; }
  .tree li::after, .tree li:first-child::after { border: 0; border-left: 2px solid var(--border-strong); border-radius: 0;
    top: 0; left: 0; width: 0; height: 100%; display: block; }
  .tree li:last-child::after { height: 35px; }
  .tree li:only-child::before, .tree li:only-child::after { display: block; }
  .tree li:only-child { padding-top: 10px; }
  .tree ul ul::before { display: none; }
  .tree > ul > li::before, .tree > ul > li::after { display: none; }
  .node { width: 100%; }
}
.mt { margin-top: 10px; } .mt-sm { margin-top: 6px; }
