/* Layout: left rail; the overview is a grid of project cards, a project is a dotted canvas
   of service boxes joined by wires; details open in a right drawer. Dark first. */
:root {
  --paper: #13111c;
  --surface: #1b1926;
  --raised: #221f2f;
  --ink: #ece9f5;
  --muted: #9b96ad;
  --line: #2d2a3b;
  --line-strong: #3d3950;
  --dotgrid: #2a2738;
  --signal: #8b5cf6;
  --signal-ink: #ffffff;
  --signal-soft: #2b2145;
  --ok: #3fbf7f;
  --ok-soft: #173326;
  --warn: #e2a33b;
  --warn-soft: #3a2c12;
  --bad: #f06a5e;
  --bad-soft: #3d1c1a;
  --code: #100e18;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 30px rgba(0, 0, 0, .25);
  --text: "Inter", -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r: 12px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --paper: #f5f4f8; --surface: #ffffff; --raised: #faf9fc; --ink: #1d1a29; --muted: #6a6580; --line: #e3e0ea; --line-strong: #cfcadb; --dotgrid: #dedbe6;
    --signal: #7140e0; --signal-ink: #ffffff; --signal-soft: #eee8fc;
    --ok: #1e8a54; --ok-soft: #e1f2e9; --warn: #a86a0b; --warn-soft: #f8ecd8; --bad: #c2362f; --bad-soft: #f9e2e0;
    --code: #f3f1f7; --shadow: 0 1px 2px rgba(29, 26, 41, .06), 0 8px 24px rgba(29, 26, 41, .07); color-scheme: light;
  }
}
:root[data-theme="light"] {
  --paper: #f5f4f8; --surface: #ffffff; --raised: #faf9fc; --ink: #1d1a29; --muted: #6a6580; --line: #e3e0ea; --line-strong: #cfcadb; --dotgrid: #dedbe6;
  --signal: #7140e0; --signal-ink: #ffffff; --signal-soft: #eee8fc;
  --ok: #1e8a54; --ok-soft: #e1f2e9; --warn: #a86a0b; --warn-soft: #f8ecd8; --bad: #c2362f; --bad-soft: #f9e2e0;
  --code: #f3f1f7; --shadow: 0 1px 2px rgba(29, 26, 41, .06), 0 8px 24px rgba(29, 26, 41, .07); color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 14.5px/1.5 var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--signal); }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
h1, h2, h3 { font-weight: 600; margin: 0; text-wrap: balance; letter-spacing: -.015em; }
h1 { font-size: 30px; line-height: 1.15; font-weight: 500; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }

.shell { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100%; }
.rail { background: var(--paper); border-right: 1px solid var(--line); padding: 22px 12px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; padding: 0 10px; letter-spacing: -.02em; }
.rail-group { display: flex; flex-direction: column; gap: 2px; }
.rail-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 10px 6px; color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.rail-add { font-size: 12px; text-decoration: none; text-transform: none; letter-spacing: 0; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
.nav-item:hover { background: var(--surface); }
.nav-item.active { background: var(--signal-soft); color: var(--ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); flex: none; display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.dot.run { background: var(--signal); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

main { padding: 32px max(32px, env(safe-area-inset-right, 0px)) 64px max(32px, env(safe-area-inset-left, 0px)); width: 100%; min-width: 0; display: flex; flex-direction: column; gap: 28px; }
.page-head { display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: flex-end; justify-content: space-between; }
.page-head .sub { margin-top: 6px; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.title-input { font-size: 22px; font-weight: 500; padding: 4px 10px; width: min(360px, 100%); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
section { display: flex; flex-direction: column; gap: 12px; }
.section-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }

button, .btn { font: inherit; font-weight: 500; font-size: 14px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); padding: 7px 14px; border-radius: 8px; cursor: pointer; line-height: 1.3; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--muted); }
button.primary, .btn.primary { background: var(--signal); color: var(--signal-ink); border-color: var(--signal); }
button.primary:hover, .btn.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; border-color: transparent; color: var(--signal); padding-inline: 8px; }
button.ghost:hover { background: var(--signal-soft); }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select { font: inherit; font-size: 14px; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px; min-width: 0; }
textarea { width: 100%; min-height: 340px; background: var(--code); font-family: var(--mono); font-size: 13px; line-height: 1.55; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; padding: 2px; background: var(--surface); }
.seg button { border: 0; padding: 5px 12px; border-radius: 6px; background: transparent; }
.seg button.on { background: var(--raised); box-shadow: inset 0 0 0 1px var(--line-strong); }

.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico.sm { width: 13px; height: 13px; }
.dotted { background-color: var(--code); background-image: radial-gradient(var(--dotgrid) 1px, transparent 1px); background-size: 16px 16px; }

/* Overview: one card per project */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); gap: 18px; }
.card { display: flex; flex-direction: column; gap: 14px; padding: 18px 12px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); color: var(--ink); text-decoration: none; transition: border-color .15s, transform .15s; }
.card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.card-head { display: flex; align-items: baseline; gap: 10px; padding: 0 8px; min-width: 0; }
.card-head h2 { font-size: 16px; }
.card-repo { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-canvas { position: relative; min-height: 210px; border-radius: 10px; border: 1px solid var(--line); display: grid; place-items: center; padding: 20px 16px 44px; background-color: var(--code); background-image: radial-gradient(var(--dotgrid) 1px, transparent 1px); background-size: 16px 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; max-width: 290px; }
.chip { width: 54px; height: 54px; border-radius: 12px; display: grid; place-items: center; background: var(--raised); border: 1px solid var(--line-strong); color: var(--ink); position: relative; }
.chip .ico { width: 24px; height: 24px; }
.chip::after { content: ""; position: absolute; right: -3px; top: -3px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--code); background: var(--line-strong); }
.chip.ok::after { background: var(--ok); } .chip.bad::after { background: var(--bad); }
.chip.bad { border-color: color-mix(in srgb, var(--bad) 55%, var(--line-strong)); }
.card-foot { position: relative; margin-top: -46px; padding: 0 14px 12px; display: flex; align-items: center; gap: 8px; font-size: 13.5px; }

/* Project tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin-top: -10px; }
.tabs a { padding: 10px 14px; color: var(--muted); text-decoration: none; font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--ink); border-bottom-color: var(--signal); }
.usage-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); gap: 16px; }
.meter-bar.share { margin-top: 0; min-width: 80px; }
.server-card { padding: 18px; gap: 16px; }
.server-card .card-head { padding: 0; }
.card-foot-row { display: flex; align-items: center; gap: 8px; font-size: 13.5px; flex-wrap: wrap; }
.meters.single { grid-template-columns: 1fr; gap: 18px; }
.nowrap { white-space: nowrap; flex-wrap: nowrap; }
details.old summary { padding: 6px 0; }
.meter-bar.share span { background: var(--signal); }

/* Logs tab */
.log-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.log-tools .grow { min-width: 200px; }
.check { gap: 6px; color: var(--muted); cursor: pointer; }
.logview { background: var(--code); border: 1px solid var(--line); border-radius: var(--r); height: min(68vh, 900px); overflow: auto; padding: 6px 0; font-size: 12.5px; }
.logline { display: grid; grid-template-columns: 74px 110px 46px minmax(0, 1fr); gap: 10px; padding: 2px 14px; cursor: pointer; align-items: baseline; }
.logline:hover { background: var(--surface); }
.log-ts { color: var(--muted); }
.log-node { color: var(--signal); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.log-lvl { font-size: 11.5px; font-weight: 600; text-transform: uppercase; color: var(--muted); }
.log-lvl.warn { color: var(--warn); } .log-lvl.error, .log-lvl.fatal { color: var(--bad); }
.logline.error, .logline.fatal { background: color-mix(in srgb, var(--bad) 8%, transparent); }
.log-msg { white-space: pre-wrap; overflow-wrap: anywhere; }
.log-full { display: none; grid-column: 1 / -1; margin: 4px 0 6px; padding: 8px 10px; background: var(--surface); border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.logline.open .log-full { display: block; }
@media (max-width: 700px) { .logline { grid-template-columns: 64px minmax(0, 1fr); } .log-node, .log-lvl { display: none; } }

/* Project canvas */
.canvas { position: relative; border: 1px solid var(--line); border-radius: var(--r); padding: 44px 36px; min-height: 280px; overflow-x: auto; background-color: var(--code); background-image: radial-gradient(var(--dotgrid) 1px, transparent 1px); background-size: 18px 18px; }
.stage { position: relative; width: max-content; min-width: 100%; }
.cols { position: relative; z-index: 1; display: flex; gap: 96px; justify-content: center; align-items: center; }
.col { display: flex; flex-direction: column; gap: 34px; }
.wires { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; overflow: visible; }
.wires path.wire { fill: none; stroke-width: 1.6; pointer-events: stroke; }
.wire.live { stroke: var(--signal); stroke-dasharray: 6 5; animation: flow 1s linear infinite; }
.wire.code { stroke: var(--muted); stroke-dasharray: 2 5; opacity: .75; }
.arrow.live { fill: var(--signal); } .arrow.code { fill: var(--muted); }
@keyframes flow { to { stroke-dashoffset: -11; } }
.node { width: 214px; text-align: left; display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow); color: var(--ink); font-weight: 400; }
.node:hover { border-color: var(--muted); }
.node.sel { border-color: var(--signal); box-shadow: 0 0 0 3px var(--signal-soft), var(--shadow); }
.node.bad { border-color: color-mix(in srgb, var(--bad) 60%, var(--line-strong)); }
.node-head { display: flex; align-items: center; gap: 10px; }
.node-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-domain { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.node-foot { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.node.ok .node-foot > span:nth-child(2) { color: var(--ink); }
.node.bad .node-foot > span:nth-child(2) { color: var(--bad); }
.node.run .node-foot > span:nth-child(2) { color: var(--signal); }
.node-ver { margin-left: auto; }
.mini-track { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.mini-track i { height: 4px; border-radius: 2px; background: var(--line-strong); }
.mini-track i.done { background: var(--ok); } .mini-track i.active { background: var(--signal); animation: pulse 1.2s ease-in-out infinite; } .mini-track i.failed { background: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 13px; align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.lg { display: inline-block; width: 26px; height: 0; border-top: 2px dashed var(--signal); }
.lg.code { border-top: 2px dotted var(--muted); }

/* Deploy stations, shown in the service drawer */
.track { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.station { display: flex; flex-direction: column; gap: 6px; }
.bar { height: 6px; border-radius: 3px; background: var(--line-strong); }
.station.done .bar { background: var(--ok); }
.station.active .bar { background: var(--signal); animation: pulse 1.2s ease-in-out infinite; }
.station.failed .bar { background: var(--bad); }
.station-label { font-size: 12.5px; color: var(--muted); }
.station.active .station-label { color: var(--signal); font-weight: 600; }
.station.failed .station-label { color: var(--bad); font-weight: 600; }
.lane-error { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 8px 12px; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; max-height: 200px; overflow: auto; }
.facts { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 8px 16px; margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.banner { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-radius: 10px; background: var(--signal-soft); color: var(--ink); }
.banner.ok { background: var(--ok-soft); } .banner.bad { background: var(--bad-soft); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--raised); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.warn { background: var(--warn-soft); color: var(--warn); } .pill.bad { background: var(--bad-soft); color: var(--bad); } .pill.run { background: var(--signal-soft); color: var(--signal); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
thead th { border-top: 0; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.empty { padding: 22px; color: var(--muted); }

/* Servers */
.servers { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 16px; }
.server { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.server-load { display: flex; align-items: baseline; gap: 10px; }
.big { font-weight: 600; font-size: 34px; line-height: 1; letter-spacing: -.02em; }
.spark { width: 100%; height: 64px; display: block; }
.spark .area { fill: var(--signal-soft); }
.spark .line { fill: none; stroke: var(--signal); stroke-width: 2; }
.spark .cap { fill: var(--signal); }
.spark .grid { stroke: var(--line); stroke-width: 1; }
.meters { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.meter-top { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.meter-bar { height: 6px; background: var(--raised); border-radius: 3px; overflow: hidden; margin-top: 5px; }
.meter-bar span { display: block; height: 100%; background: var(--ok); }
.meter-bar span.warn { background: var(--warn); } .meter-bar span.bad { background: var(--bad); }

/* Env */
.env-tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.env-group td:first-child { font-family: var(--mono); font-size: 13px; }
.env-group-head td { background: var(--raised); font-size: 12.5px; font-weight: 600; color: var(--muted); }
.env-val { width: 100%; font-family: var(--mono); font-size: 13px; }
.env-scope { gap: 10px; }
.env-scope .section-head { align-items: center; }
.env-owner { min-width: 140px; }
.drawer .env-val { min-width: 220px; }
.drawer .env-group td { padding: 6px 10px; }
.env-help { max-width: 90ch; margin: 0; }

/* Drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(900px, 100vw); background: var(--surface); border-left: 1px solid var(--line-strong); box-shadow: -16px 0 40px rgba(0, 0, 0, .3); display: flex; flex-direction: column; z-index: 20; }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer-body { flex: 1; overflow: auto; padding: 18px; }
.log { margin: 0; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--code); border-radius: 8px; padding: 12px 14px; }

.confirm { border: 1px solid var(--warn); background: var(--warn-soft); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.form { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 10px 16px; align-items: center; }
.form label { color: var(--muted); font-size: 14px; }
.error { color: var(--bad); white-space: pre-wrap; }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: var(--paper); padding: 11px 16px; border-radius: 10px; max-width: 460px; z-index: 30; box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); color: #fff; }
details summary { cursor: pointer; font-weight: 600; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; gap: 8px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .canvas { padding: 24px 16px; }
  .stage { width: auto; }
  .cols { flex-direction: column; gap: 40px; }
  .form { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

.stack { display: flex; flex-direction: column; gap: 14px; }
.top-gap { margin-top: 12px; }
.w100 { width: 100%; }
.grow { flex: 1; min-width: 240px; }
.pad { padding: 18px; }
.spark-note { font-size: 12.5px; color: var(--muted); margin-top: -8px; }

/* Online login: same page frame, left-aligned like every other page. */
.form.login { max-width: 480px; }
body.logged-out .rail-group, body.logged-out .rail-logout { display: none; }
.rail-logout { margin-top: auto; align-self: flex-start; }
