:root {
  --paper: #e8ecf1;
  --sheet: #ffffff;
  --sheet-2: #f5f7fa;
  --ink: #13203a;
  --ink-2: #4a5873;
  --ink-3: #7b879c;
  --line: #ccd4df;
  --line-2: #e1e6ed;
  --cobalt: #2b44e0;
  --cobalt-dark: #1f33b8;
  --cobalt-tint: #e6eafd;
  --live: #12805a;
  --amber: #b86e00;
  --fail: #c0322d;
  --idle: #9aa5b6;
  --tape: #0e1729;
  --tape-2: #16223a;
  --tape-ink: #c9d3e6;

  --display: 'Bricolage Grotesque', 'Avenir Next', system-ui, sans-serif;
  --ui: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --r-panel: 12px;
  --r-control: 7px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--cobalt); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -0.015em; }
h1 { font-size: 1.9rem; font-weight: 800; line-height: 1.1; }
h2 { font-size: 1.15rem; font-weight: 600; }
p { margin: 0; }
code, .mono { font-family: var(--mono); font-size: 0.86em; }
:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- top bar */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 22px;
  padding: 12px 28px;
  background: var(--ink);
  color: #e9eef6;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font: 800 1.1rem var(--display); letter-spacing: -0.02em; }
.brand:hover { text-decoration: none; }
.brand .dom { font-weight: 400; color: #8f9cb6; }
.top nav { display: flex; gap: 4px; }
.top nav a { color: #b9c3d6; padding: 6px 12px; border-radius: var(--r-control); font-weight: 500; }
.top nav a:hover { color: #fff; background: #1f2d4b; text-decoration: none; }
.top nav a.on { color: #fff; background: #24345a; }
.top .spacer { flex: 1; }
.sys { display: flex; gap: 16px; font-size: 0.8rem; color: #8f9cb6; }
.meter { display: flex; align-items: center; gap: 7px; }
.meter i { display: block; width: 46px; height: 5px; border-radius: 3px; background: #2a3a5c; overflow: hidden; }
.meter i b { display: block; height: 100%; background: #7d93c9; }
.meter.hot i b { background: #e2973b; }
.top .btn.ghost { color: #b9c3d6; border-color: transparent; background: transparent; }
.top .btn.ghost:hover { color: #fff; background: #1f2d4b; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 0.88rem var(--ui);
  padding: 8px 14px;
  border-radius: var(--r-control);
  border: 1px solid var(--line);
  background: var(--sheet);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none !important;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--cobalt); border-color: var(--cobalt); color: #fff; }
.btn.primary:hover { background: var(--cobalt-dark); border-color: var(--cobalt-dark); }
.btn.danger { color: var(--fail); }
.btn.danger:hover { border-color: var(--fail); }
.btn.danger-solid { background: var(--fail); border-color: var(--fail); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 0.82rem; }
.btn:disabled { opacity: 0.5; cursor: default; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--cobalt); cursor: pointer; }

/* ---------------------------------------------------------------- page */
.page { max-width: 1180px; margin: 0 auto; padding: 34px 28px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.lede { color: var(--ink-2); margin-top: 6px; max-width: 62ch; }
.back { display: inline-block; color: var(--ink-2); font-weight: 500; margin-bottom: 14px; }
.back::before { content: '‹ '; }

/* ---------------------------------------------------------------- lamps */
.lamp {
  width: 11px; height: 11px; border-radius: 50%; flex: none;
  background: var(--idle);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}
.s-live .lamp, .lamp.s-live { background: var(--live); box-shadow: 0 0 0 4px rgba(18, 128, 90, 0.16); }
.s-building .lamp, .lamp.s-building,
.s-queued .lamp, .lamp.s-queued { background: var(--amber); box-shadow: 0 0 0 4px rgba(184, 110, 0, 0.18); animation: pulse 1.2s ease-in-out infinite; }
.s-failed .lamp, .lamp.s-failed { background: var(--fail); box-shadow: 0 0 0 4px rgba(192, 50, 45, 0.15); }
.s-warn .lamp, .lamp.s-warn { background: var(--live); box-shadow: 0 0 0 3px var(--amber); }
.s-idle .lamp, .lamp.s-idle { background: transparent; box-shadow: inset 0 0 0 2px var(--idle); }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .lamp { animation: none !important; } }

.state { font-weight: 600; }
.s-live .state, .state.s-live { color: var(--live); }
.s-building .state, .s-queued .state, .state.s-building, .state.s-queued, .s-warn .state, .state.s-warn { color: var(--amber); }
.s-failed .state, .state.s-failed { color: var(--fail); }
.s-idle .state, .state.s-idle { color: var(--ink-3); }

/* ---------------------------------------------------------------- hostnames */
.host { font-family: var(--display); color: var(--ink); letter-spacing: -0.02em; overflow-wrap: anywhere; }
.host .sub { font-weight: 800; }
.host .dom { font-weight: 400; color: var(--ink-3); }
a.host:hover { text-decoration: none; }
a.host:hover .sub { color: var(--cobalt); }

/* ---------------------------------------------------------------- rack (site list) */
.rack { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; }
.row {
  display: grid;
  grid-template-columns: 14px minmax(0, 2.3fr) 118px minmax(0, 2fr) auto;
  align-items: center; gap: 20px;
  padding: 18px 22px;
  border-top: 1px solid var(--line-2);
  cursor: pointer;
}
.row:first-child { border-top: 0; }
.row:hover { background: var(--sheet-2); }
.row .host { font-size: 1.32rem; line-height: 1.15; display: block; }
.row-sub { color: var(--ink-2); font-size: 0.84rem; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.branch { color: var(--ink); font-weight: 500; }
.type-tag { font-size: 0.82rem; color: var(--ink-2); font-weight: 500; }
.row-deploy { min-width: 0; font-size: 0.86rem; }
.commit { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.when { color: var(--ink-3); font-size: 0.8rem; margin-top: 2px; }
.row-actions { display: flex; gap: 8px; }

.empty { text-align: center; padding: 64px 24px; }
.empty h2 { font-size: 1.4rem; font-weight: 800; }
.empty p { color: var(--ink-2); margin: 8px auto 22px; max-width: 46ch; }

/* ---------------------------------------------------------------- forms */
.panel { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-panel); padding: 26px 28px; }
.panel + .panel { margin-top: 18px; }
.panel > h2 { margin-bottom: 4px; }
.panel > .hint:first-of-type { margin-bottom: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 22px; margin-top: 18px; }
.form-grid .wide { grid-column: 1 / -1; }
.field label, .field .label { display: block; font-weight: 600; font-size: 0.87rem; margin-bottom: 6px; }
.hint { color: var(--ink-2); font-size: 0.82rem; margin-top: 5px; }
input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%;
  font: 0.93rem var(--ui);
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: var(--r-control);
  padding: 9px 11px;
}
textarea { font-family: var(--mono); font-size: 0.84rem; min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--cobalt); box-shadow: 0 0 0 3px var(--cobalt-tint); }
.affix { display: flex; align-items: stretch; }
.affix input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.affix span {
  display: flex; align-items: center; padding: 0 12px;
  border: 1px solid var(--line); border-left: 0;
  border-radius: 0 var(--r-control) var(--r-control) 0;
  background: var(--sheet-2); color: var(--ink-2); font-family: var(--display); white-space: nowrap;
}
.check { display: flex; gap: 9px; align-items: flex-start; font-size: 0.9rem; }
.check input { margin-top: 3px; accent-color: var(--cobalt); }

.types { display: flex; flex-wrap: wrap; gap: 8px; }
.types label {
  position: relative; display: flex; flex-direction: column; gap: 1px;
  padding: 10px 14px; min-width: 150px;
  border: 1px solid var(--line); border-radius: var(--r-control);
  cursor: pointer; font-weight: 600; font-size: 0.9rem;
}
.types label small { font-weight: 400; color: var(--ink-2); font-size: 0.78rem; }
.types input { position: absolute; opacity: 0; pointer-events: none; }
.types label:has(input:checked) { border-color: var(--cobalt); background: var(--cobalt-tint); box-shadow: inset 0 0 0 1px var(--cobalt); }
.types label:has(input:focus-visible) { outline: 2px solid var(--cobalt); outline-offset: 2px; }

details.more { margin-top: 22px; border-top: 1px solid var(--line-2); padding-top: 16px; }
details.more summary { cursor: pointer; font-weight: 600; color: var(--ink-2); }
details.more[open] summary { color: var(--ink); }

.form-foot { display: flex; gap: 10px; align-items: center; margin-top: 22px; }
.form-foot .msg { color: var(--ink-2); font-size: 0.85rem; }
form[data-type=static] .only-server { display: none; }
form:not([data-type=static]) .only-static { display: none; }

.detected { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.detected .lead { color: var(--ink-2); font-size: 0.86rem; margin-right: 4px; }
.pick { display: flex; flex-direction: column; align-items: flex-start; padding: 8px 12px; border: 1px dashed var(--ink-3); border-radius: var(--r-control); background: var(--sheet); cursor: pointer; font: 600 0.86rem var(--ui); color: var(--ink); }
.pick small { color: var(--ink-2); font-weight: 400; }
.pick.on { border-style: solid; border-color: var(--cobalt); background: var(--cobalt-tint); }

/* ---------------------------------------------------------------- app page */
.app-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.app-head .lamp { width: 16px; height: 16px; }
.app-head .host { font-size: clamp(2rem, 4.4vw, 3.3rem); line-height: 1.02; flex: 1; min-width: 0; }
.app-actions { display: flex; gap: 8px; }
.facts { display: flex; flex-wrap: wrap; gap: 10px 34px; margin: 18px 0 26px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.facts div { min-width: 0; }
.facts dt { font-size: 0.78rem; color: var(--ink-3); }
.facts dd { margin: 2px 0 0; font-weight: 500; }

.tabs { display: flex; gap: 2px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 9px 14px; color: var(--ink-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--cobalt); }

.deploys { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 18px; align-items: start; }
.dep-list { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; max-height: 640px; overflow-y: auto; }
.dep {
  display: grid; grid-template-columns: 10px minmax(0, 1fr); gap: 4px 12px; align-items: center;
  width: 100%; text-align: left; padding: 12px 16px;
  background: none; border: 0; border-top: 1px solid var(--line-2);
  font: inherit; color: inherit; cursor: pointer;
}
.dep:first-child { border-top: 0; }
.dep:hover { background: var(--sheet-2); }
.dep.on { background: var(--cobalt-tint); }
.dep .lamp { width: 9px; height: 9px; }
.dep .t { font-weight: 600; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dep .m { grid-column: 2; color: var(--ink-2); font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dep .sha { color: var(--ink); }

/* the tape: live build log */
.tape { background: var(--tape); border-radius: var(--r-panel); overflow: hidden; display: flex; flex-direction: column; min-height: 420px; }
.tape-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px; background: var(--tape-2); color: #e8eef9; font-size: 0.86rem; }
.tape-head .what { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tape-head .state { font-size: 0.82rem; }
.tape-head .state.s-live { color: #5fd3a2; }
.tape-head .state.s-failed { color: #ff8a84; }
.tape-head .state.s-building, .tape-head .state.s-queued { color: #f0b85a; }
.tape pre {
  margin: 0; padding: 16px 18px 24px; flex: 1;
  max-height: 600px; overflow: auto;
  color: var(--tape-ink); font: 0.78rem/1.6 var(--mono);
  white-space: pre-wrap; word-break: break-word;
}
.tape pre .cmd { color: #8fb0ff; }
.tape pre .ok { color: #5fd3a2; }
.tape pre .err { color: #ff8a84; }
.tape pre .stamp { color: #5d6c8a; }
.tape .nothing { color: #7484a3; }
.tape.light { background: var(--sheet); border: 1px solid var(--line); }
.tape.light pre { color: var(--ink); }

.runtime { display: grid; gap: 18px; }

/* env editor */
.env-table { width: 100%; border-collapse: collapse; }
.env-table td { padding: 5px 0; vertical-align: top; }
.env-table td:first-child { width: 34%; padding-right: 10px; }
.env-table td:last-child { width: 40px; text-align: right; }
.env-table input { font-family: var(--mono); font-size: 0.84rem; }
.x { background: none; border: 0; color: var(--ink-3); font-size: 1.2rem; cursor: pointer; padding: 6px 8px; border-radius: 6px; }
.x:hover { color: var(--fail); background: var(--sheet-2); }
.env-tools { display: flex; gap: 14px; margin-top: 10px; }

.danger-zone { border-color: #e6b9b7; }
.danger-zone h2 { color: var(--fail); }

/* settings */
.kv { display: flex; gap: 10px; align-items: center; }
.kv code { background: var(--sheet-2); border: 1px solid var(--line-2); padding: 7px 10px; border-radius: var(--r-control); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-line { display: flex; align-items: center; gap: 9px; font-weight: 500; }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.settings-grid .panel + .panel { margin-top: 0; }
.settings-grid .wide { grid-column: 1 / -1; }
.log-out { margin-top: 12px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .panel { width: min(400px, 100%); padding: 34px; }
.login .brand { color: var(--ink); font-size: 1.35rem; margin-bottom: 20px; }
.login p { color: var(--ink-2); margin-bottom: 18px; }
.login .btn { width: 100%; margin-top: 14px; padding: 11px; }
.warn-note { background: #fff4e0; border: 1px solid #f0cf96; color: #6d4300; padding: 10px 12px; border-radius: var(--r-control); font-size: 0.84rem; margin-bottom: 16px; }
.err-note { color: var(--fail); font-size: 0.86rem; margin-top: 10px; min-height: 1.2em; }

/* toasts */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: var(--r-control); font-size: 0.88rem; max-width: 380px; animation: rise 0.18s ease-out; }
.toast.error { background: var(--fail); }
@keyframes rise { from { transform: translateY(6px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .top { flex-wrap: wrap; gap: 10px 16px; padding: 12px 18px; }
  .sys { display: none; }
  .page { padding: 24px 16px 60px; }
  .row { grid-template-columns: 12px minmax(0, 1fr) auto; gap: 6px 14px; }
  .row .type-tag, .row .row-deploy { grid-column: 2 / -1; }
  .row-actions { grid-row: 1; grid-column: 3; }
  .deploys, .settings-grid, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .dep-list { max-height: 280px; }
  .page-head { flex-direction: column; align-items: flex-start; }
}
