/* nudo dashboard.
 *
 * Hand-written rather than a Tailwind build, so there is no CSS build step and
 * the whole stylesheet is one embedded file. Light and dark both come from
 * `light-dark()` against `color-scheme`, so the OS preference is honoured
 * without a toggle or a flash of the wrong theme. */

:root {
  color-scheme: light dark;

  --bg: light-dark(#f7f8fa, #0e1013);
  --surface: light-dark(#ffffff, #171a1f);
  --surface-2: light-dark(#f1f3f6, #1e2228);
  --border: light-dark(#e2e6ec, #282d35);
  --border-strong: light-dark(#cbd2dc, #3a414c);
  --text: light-dark(#141922, #e8ecf1);
  --muted: light-dark(#5b6673, #98a2b0);
  --faint: light-dark(#8a94a2, #6d7684);

  --accent: light-dark(#2563eb, #5b8cff);
  --accent-soft: light-dark(#e8efff, #1b2740);
  --success: light-dark(#0f7a3d, #46c97e);
  --success-soft: light-dark(#e4f6ea, #16301f);
  --warning: light-dark(#8a5a00, #e0a83a);
  --warning-soft: light-dark(#fdf3e0, #33260f);
  --danger: light-dark(#b3261e, #f2736a);
  --danger-soft: light-dark(#fdeceb, #331a19);

  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
h4 { font-size: 13px; }
p { margin: 0; }
code, pre, .mono { font-family: var(--mono); }

/* ---- layout ---- */

.shell { display: flex; min-height: 100vh; }

.rail {
  flex: 0 0 208px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  padding: 4px 8px 16px;
  font-weight: 650;
  font-size: 16px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand .tag { font-size: 11px; color: var(--faint); font-weight: 500; }
/* The running version, on its own line under the name. */
.brand .version {
  flex-basis: 100%;
  font-size: 11px;
  font-weight: 500;
  color: var(--faint);
  font-family: var(--mono);
}

.rail a.nav {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 500;
}
.rail a.nav:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.rail a.nav.active { background: var(--accent-soft); color: var(--accent); }
.rail .nav-icon { width: 15px; text-align: center; opacity: .85; flex: 0 0 auto; }
.rail .spacer { flex: 1; }
.rail .rail-foot {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--faint);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar .titles { min-width: 0; }
.topbar .subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }
.topbar .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.content { padding: 24px; flex: 1; min-width: 0; }
.content > * + * { margin-top: 20px; }

/* Stacked cards need the same gap wherever they sit.
 *
 * The rule above only reaches direct children of `.content`, so pages that
 * wrap their cards — the service form puts six inside one `<form>`, settings
 * nests them under `.split > div` — rendered them butted together with no
 * space at all. Spacing the cards themselves rather than the wrapper means it
 * holds however deeply they are nested, and does not depend on each page
 * remembering to ask for it.
 *
 * Adjacent-sibling selectors, so the first card in a section is untouched and
 * does not push itself away from the heading above it. */
.card + .card,
.card + .grid,
.grid + .card,
.card + .callout,
.callout + .card,
.card + .table-scroll,
.table-scroll + .card { margin-top: 20px; }

/* ---- tabs ---- */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 0 24px;
  overflow-x: auto;
}
.tabs a {
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* A vertical sub-menu within a configuration screen. */
.split { display: grid; grid-template-columns: 190px 1fr; gap: 24px; align-items: start; }
@media (max-width: 800px) { .split { grid-template-columns: 1fr; } }
.submenu { display: flex; flex-direction: column; gap: 2px; }
.submenu a {
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 500;
}
.submenu a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.submenu a.active { background: var(--surface-2); color: var(--text); }

/* ---- cards ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card.pad-0 { padding: 0; overflow: hidden; }
.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.card-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.card-body { padding: 16px; }
.card-note { color: var(--muted); font-size: 13px; margin-top: 4px; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

/* A whole card that is a link. */
.tile {
  position: relative;
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: inherit;
}
.tile:hover { border-color: var(--border-strong); text-decoration: none; }
.tile.alert { border-color: var(--danger); }
.tile .tile-title { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.tile .tile-meta { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.tile .tile-meta .mono { font-size: 12px; }

/* Aggregate counts across the top of the dashboard. */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .stat-value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }
.stat.is-bad .stat-value { color: var(--danger); }

/* ---- badges ---- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 20px;
  padding: 0 7px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--muted);
  vertical-align: middle;
}
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }

/* The flag that changes how every other operation behaves. */
.badge.hot {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger);
}

/* ---- buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { padding: 3px 8px; font-size: 12px; }

/* ---- tables ---- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 16px; vertical-align: middle; }
thead th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--faint);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr + tr td { border-top: 1px solid var(--border); }
tbody tr:hover { background: var(--surface-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

/* ---- forms ---- */

.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-weight: 550; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; }
.fields { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="search"], select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; min-height: 90px; }
.check { display: flex; align-items: flex-start; gap: 8px; }
.check input { margin-top: 3px; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 16px; }

/* Rotating a secret: a disclosure rather than a modal, so it needs no
 * JavaScript and degrades to a plain visible form. The summary is styled as a
 * button and loses its default triangle; the panel floats over the row so a
 * table with several secrets does not reflow when one is opened. */
.rotate { position: relative; display: inline-block; }
.rotate > summary { list-style: none; cursor: pointer; user-select: none; }
.rotate > summary::-webkit-details-marker { display: none; }
.rotate > form {
  position: absolute;
  right: 0;
  z-index: 20;
  width: 320px;
  margin-top: 6px;
  padding: 14px;
  text-align: left;
  white-space: normal;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgb(0 0 0 / .18);
}
.rotate > form .form-actions { margin-top: 12px; }

/* ---- callouts ---- */

.callout {
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 6px;
  padding: 10px 14px;
  background: var(--surface);
  font-size: 13px;
}
.callout.warn { border-left-color: var(--warning); background: var(--warning-soft); }
.callout.bad { border-left-color: var(--danger); background: var(--danger-soft); }
.callout.info { border-left-color: var(--accent); background: var(--accent-soft); }
.callout strong { display: block; margin-bottom: 2px; }
.callout p { margin-top: 4px; color: var(--muted); }
.callout .form-actions { margin-top: 10px; padding-top: 0; border-top: none; }

/* The update and support banners sit above the page content rather than inside
   a card, so they need the margin a card would have given them. */
.update-banner,
.support-banner { margin: 16px 24px 0; }

/* "Maybe next time" is not the action being encouraged, so it reads as a link
   rather than competing with the buttons beside it. */
.btn.quiet {
  background: none;
  border-color: transparent;
  color: var(--muted);
}
.btn.quiet:hover { color: var(--text); background: var(--surface-2); }

/* Release notes come from the manifest, so they are ordinary prose. */
.card-body ul { margin: 6px 0 6px 18px; }
.card-body li { margin: 2px 0; }

/* Commands meant to be copied. Scrolls rather than wrapping: a wrapped shell
   line is one that gets pasted wrong. */
pre.code {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  background: light-dark(#12151a, #08090b);
  color: #d6dbe3;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 10px 0;
  overflow-x: auto;
  white-space: pre;
}
.card-body code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ---- the first-run checklist ---- */

.steps { list-style: none; display: flex; flex-direction: column; gap: 14px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; }
.steps p { margin: 2px 0 8px; max-width: 62ch; }

/* The number, or a tick once the step is done. */
.step-mark {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}
.steps li.done .step-mark {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}
.steps li.current .step-mark {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* A finished step stays readable but stops competing for attention with the
   one actually being asked for. */
.steps li.done strong { color: var(--muted); font-weight: 500; }
.steps li.done p { display: none; }
.steps li.current strong { color: var(--text); }

/* An empty state should carry the next action, not just say "none". */
.empty { text-align: center; padding: 36px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }

/* ---- logs and unit files ---- */

.logs {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  background: light-dark(#12151a, #08090b);
  color: #d6dbe3;
  border-radius: var(--radius);
  padding: 12px 14px;
  overflow: auto;
  max-height: 62vh;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.logs.tall { max-height: none; height: calc(100vh - 260px); }
.logs .line { display: flex; gap: 10px; }
.logs .at { color: #6d7684; flex: 0 0 auto; }
.logs .msg { min-width: 0; }
.logs .line.err .msg { color: #f2736a; }
.logs .line.warn .msg { color: #e0a83a; }
.logs .line.cmd .msg { color: #8fb3ff; font-weight: 600; }
.logs .placeholder { color: #6d7684; }

pre.unit {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  overflow: auto;
  margin: 0;
}

/* ---- terminal ---- */

.term-wrap {
  background: #000;
  border-radius: var(--radius);
  padding: 8px;
  height: calc(100vh - 240px);
  min-height: 320px;
}
#terminal { width: 100%; height: 100%; }
.term-status { color: var(--muted); font-size: 12.5px; margin-top: 8px; }

/* ---- auth ---- */

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card { width: 100%; max-width: 380px; }
.auth-card .brand { justify-content: center; padding-bottom: 8px; }
.auth-card > * + * { margin-top: 14px; }

/* ---- misc ---- */

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.sep { color: var(--border-strong); }

/* ---------------------------------------------------------------------------
   The update dialog
   ---------------------------------------------------------------------------

   Driven by `:target` rather than by script: the actions inside it navigate,
   and one of them restarts the process serving the page. A dialog that only
   exists in JavaScript state would close itself at exactly the moment it has
   something to say.
*/
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  place-items: center;
  padding: 24px;
}
.modal:target { display: grid; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: light-dark(rgb(15 20 28 / 45%), rgb(0 0 0 / 60%));
}
.modal-backdrop:hover { text-decoration: none; }

.modal-card {
  position: relative;
  width: min(620px, 100%);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 18px 48px light-dark(rgb(15 20 28 / 18%), rgb(0 0 0 / 55%));
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0 0 2px; font-size: 17px; }
.modal-head p { margin: 0; }

.modal-close {
  flex: 0 0 auto;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-body .release-notes p { margin: 0 0 8px; max-width: 62ch; }
.modal-body .release-notes ul { margin: 0 0 10px; padding-left: 20px; }
.modal-body .release-notes li { margin: 2px 0; }

.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}
/* Close and Skip sit left, the primary action right: the consequential button
   is where the eye finishes, and is never the one hit by accident. */
.modal-foot-actions { display: flex; align-items: center; gap: 8px; }
.modal-foot-actions form { margin: 0; }
.modal-foot-actions form:last-child { margin-left: auto; }

/* The named steps of an upgrade in progress. */
.upgrade-steps { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.upgrade-step { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.upgrade-step .step-mark { margin-top: 0; }
.upgrade-step.done { color: var(--muted); }
.upgrade-step.done .step-mark {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}
.upgrade-step.current { color: var(--text); font-weight: 550; }
.upgrade-step.current .step-mark {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* The step being worked spins. Same 22px circle the numbers occupy, so the
   list does not reflow as the current step advances: the ring is the border,
   with one side coloured to give the rotation something to show.

   The track is `--border-strong` rather than `--accent-soft`: the soft accent
   is a hair off white in light mode, which left the ring invisible and the
   moving arc reading as a stray mark. */
.upgrade-step.current .step-mark.spinner {
  background: none;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Someone who asked not to be moved gets a pulse instead of a rotation —
   still alive, without the spin. */
@media (prefers-reduced-motion: reduce) {
  .upgrade-step.current .step-mark.spinner {
    animation: pulse 1.4s ease-in-out infinite;
  }
  @keyframes pulse {
    50% { opacity: 0.35; }
  }
}

@media (max-width: 720px) {
  .shell { flex-direction: column; }
  .rail {
    flex: none;
    height: auto;
    position: static;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    align-items: center;
  }
  .rail .brand { padding: 0 12px 0 4px; }
  .rail .rail-foot, .rail .spacer { display: none; }
  .content, .topbar { padding: 16px; }
  .tabs { padding: 0 16px; }
}
