/* Atlas dashboard.
 *
 * The palette and type are the approved proposal's: a warm burnt-orange accent against cool blue
 * greys, monospace for anything an operator reads as data. Semantic colour (ok / warn / bad) is a
 * separate axis from the accent so a running server and a primary button never compete.
 */

:root {
  --ground: #F5F7F9;
  --surface: #FFFFFF;
  --surface-2: #EDF1F4;
  --line: #D8DFE5;
  --line-soft: #E7ECF0;
  --ink: #131A21;
  --ink-2: #4A5765;
  --ink-3: #7B8794;
  --accent: #A85E28;
  --accent-soft: rgba(168, 94, 40, 0.10);
  --ok: #1F7A4D;
  --ok-soft: rgba(31, 122, 77, 0.12);
  --warn: #9A6B12;
  --warn-soft: rgba(154, 107, 18, 0.14);
  --bad: #B23A31;
  --bad-soft: rgba(178, 58, 49, 0.12);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 3px;
}

/* The OS preference, then the explicit toggle, which must win in both directions. Only the tokens
 * are redefined — no component is styled inside a media query, so there is one place a colour can
 * be wrong rather than three. */
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0E1116;
    --surface: #151A21;
    --surface-2: #1B222B;
    --line: #262F3A;
    --line-soft: #1F262F;
    --ink: #E4EAF0;
    --ink-2: #9AA7B4;
    --ink-3: #6B7784;
    --accent: #D08B4F;
    --accent-soft: rgba(208, 139, 79, 0.14);
    --ok: #3FB077;
    --ok-soft: rgba(63, 176, 119, 0.14);
    --warn: #D99A2B;
    --warn-soft: rgba(217, 154, 43, 0.14);
    --bad: #DD5C51;
    --bad-soft: rgba(221, 92, 81, 0.14);
  }
}

:root[data-theme="dark"] {
  --ground: #0E1116;
  --surface: #151A21;
  --surface-2: #1B222B;
  --line: #262F3A;
  --line-soft: #1F262F;
  --ink: #E4EAF0;
  --ink-2: #9AA7B4;
  --ink-3: #6B7784;
  --accent: #D08B4F;
  --accent-soft: rgba(208, 139, 79, 0.14);
  --ok: #3FB077;
  --ok-soft: rgba(63, 176, 119, 0.14);
  --warn: #D99A2B;
  --warn-soft: rgba(217, 154, 43, 0.14);
  --bad: #DD5C51;
  --bad-soft: rgba(221, 92, 81, 0.14);
}

:root[data-theme="light"] {
  --ground: #F5F7F9;
  --surface: #FFFFFF;
  --surface-2: #EDF1F4;
  --line: #D8DFE5;
  --line-soft: #E7ECF0;
  --ink: #131A21;
  --ink-2: #4A5765;
  --ink-3: #7B8794;
  --accent: #A85E28;
  --accent-soft: rgba(168, 94, 40, 0.10);
  --ok: #1F7A4D;
  --ok-soft: rgba(31, 122, 77, 0.12);
  --warn: #9A6B12;
  --warn-soft: rgba(154, 107, 18, 0.14);
  --bad: #B23A31;
  --bad-soft: rgba(178, 58, 49, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

/* ---- Sign in ---- */

.signin {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.signin-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.wordmark {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}

.signin-card p {
  margin: 0;
  color: var(--ink-2);
  font-size: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.field input {
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 11px;
  font-size: 14px;
}

.field input:focus { border-color: var(--accent); }

.button {
  background: var(--accent);
  color: #FFFFFF;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.button:hover { filter: brightness(1.08); }
.button[disabled] { opacity: 0.55; cursor: default; filter: none; }

.button-quiet {
  background: transparent;
  color: var(--ink-2);
  border-color: var(--line);
}

.button-quiet:hover { background: var(--surface-2); filter: none; }

.button-danger { color: var(--bad); border-color: var(--line); background: transparent; }
.button-danger:hover { background: var(--bad-soft); filter: none; }

.button-small { padding: 4px 9px; font-size: 12px; }

/* Errors say what went wrong. Never an apology, never "something went wrong". */
.notice {
  margin: 0;
  padding: 9px 11px;
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--bad-soft);
  color: var(--bad);
  border: 1px solid transparent;
}

/* ---- Application chrome ---- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 24px;
  flex-wrap: wrap;
}

.topbar .wordmark { font-size: 16px; }

.nav {
  display: flex;
  gap: 2px;
  margin-right: auto;
}

.nav button {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 5px 11px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
}

.nav button:hover { background: var(--surface-2); }

.nav button[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

.topbar select {
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 8px;
  font-size: 13px;
  max-width: 220px;
}

.who {
  font-size: 13px;
  color: var(--ink-3);
  font-family: var(--mono);
}

.page {
  max-width: 1160px;
  margin: 0 auto;
  padding: 28px 24px 72px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.view-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.view-head h2 {
  margin: 0;
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 600;
}

/* Freshness is stated because everything on this page is a snapshot. A dashboard that looks live
 * and is four minutes stale is worse than one that admits its age. */
.freshness {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.04em;
}

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

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat dt {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0;
}

.stat dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* Tables are the point of this product. Wide ones scroll inside themselves so the page body never
 * scrolls sideways. */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

td.mono, th.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
td.right, th.right { text-align: right; }
.dim { color: var(--ink-3); }

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--ink-3);
  font-size: 14px;
}

/* State reads at a glance as shape and colour, not only as a word — the whole reason to scan a
 * list is to find the row that is not like the others. */
.pill {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  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-idle { background: var(--surface-2); color: var(--ink-3); }

/* A meter is only drawn when there is a measurement. Absent usage renders as an em dash, because
 * a bar at zero and a bar with no data look identical and mean opposite things. */
.meter {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 130px;
}

.meter-track {
  flex: 1;
  height: 5px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.meter-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.meter-fill.is-warn { background: var(--warn); }
.meter-fill.is-bad { background: var(--bad); }

.meter-value {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  min-width: 62px;
  text-align: right;
}

.unmeasured { color: var(--ink-3); font-family: var(--mono); }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---- inline editing ----
 *
 * Tables here are forms. The controls stay quiet until hovered or focused so a page of them reads
 * as data rather than as a wall of boxes, but they never hide the fact that they are editable. */

td select,
td input[type="text"],
td input[type="number"] {
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 3px 6px;
  font-size: 12px;
  max-width: 100%;
}

td input[type="number"] {
  width: 66px;
  font-family: var(--mono);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td select { font-size: 12px; }

td select:hover,
td input:hover { border-color: var(--ink-3); }

td select:focus,
td input:focus { border-color: var(--accent); }

.narrow { width: 1%; white-space: nowrap; }

/* A hint under a column heading, for the questions the heading alone cannot answer. */
.th-hint {
  display: block;
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: none;
  opacity: 0.7;
}

/* A group's name: one name, shown as the fixed identifier it is. */
.group-name {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  cursor: help;
}

/* ---- storage ---- */

.storage {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.storage-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.storage-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.storage-figure {
  margin-left: auto;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.storage .meter-track { height: 7px; }

.storage-note {
  margin: 0;
  font-size: 12px;
  color: var(--ink-3);
}

/* ---- creating things ---- */

.create-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.create-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}

.create-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.create-field > span {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.create-field input,
.create-field select {
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 9px;
  font-size: 13px;
}

.create-field input:focus,
.create-field select:focus { border-color: var(--accent); }

/* The consequence of a field, said where the decision is made rather than in documentation
   nobody opens. */
.create-field em {
  font-style: normal;
  font-size: 11px;
  color: var(--ink-3);
  line-height: 1.4;
}

.create-actions { display: flex; gap: 8px; }

.scale-pair {
  display: flex;
  align-items: center;
  gap: 6px;
}

.scale-pair span { font-size: 11px; }

.node-name { display: flex; align-items: center; gap: 6px; }
.node-name input { font-family: var(--mono); min-width: 140px; }

/* ---- Home ---- */

.split {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; }
}

.panel { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.panel-head {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.feed-state {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  text-transform: none;
}

.feed-state.is-live { color: var(--ok); }
.feed-state.is-down { color: var(--bad); }

/* The activity feed. Scrolls inside itself so a busy network never stretches the page. */
.feed {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-height: 560px;
  overflow-y: auto;
  font-size: 13px;
}

.feed li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.feed li:last-child { border-bottom: none; }

.feed .at {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.feed .who { font-weight: 500; }
.feed .what { color: var(--ink-2); min-width: 0; overflow-wrap: anywhere; }

/* Arrival, departure and movement are three different things and the eye should not have to read
   the sentence to tell them apart. */
.feed .mark {
  width: 3px;
  align-self: stretch;
  border-radius: 999px;
  flex-shrink: 0;
}

.feed .mark-ok { background: var(--ok); }
.feed .mark-warn { background: var(--warn); }
.feed .mark-bad { background: var(--bad); }
.feed .mark-idle { background: var(--ink-3); }

.feed-empty { padding: 24px 12px; text-align: center; color: var(--ink-3); }

/* ---- Console ---- */

.console-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 40;
}

.console-panel {
  width: min(1000px, 100%);
  height: min(680px, 85vh);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.console-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.console-head h2 {
  margin: 0;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
}

.console-target { font-size: 12px; color: var(--ink-3); }

/* Monospace, dense, and scrolling on its own. This is the one surface where a customer reads raw
   output, so line alignment is the whole readability story. */
.console-out {
  list-style: none;
  margin: 0;
  padding: 10px 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  background: var(--ground);
}

.console-out li {
  display: flex;
  gap: 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.console-out .at {
  color: var(--ink-3);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* stderr is where a crash arrives, so it must not look like ordinary output. */
.console-out .err { color: var(--bad); }
/* Lines Atlas wrote about the stream itself, not lines the server printed. */
.console-out .meta { color: var(--accent); font-style: italic; }
/* What the operator typed, echoed so the transcript reads as a conversation. */
.console-out .sent { color: var(--ok); }

.console-input {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
}

.console-input input {
  flex: 1;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 12px;
}

.console-input input:focus { border-color: var(--accent); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--ground);
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 50;
  max-width: min(90vw, 520px);
}

.toast.is-bad { background: var(--bad); color: #FFFFFF; }

@media (prefers-reduced-motion: no-preference) {
  .meter-fill { transition: width 400ms ease; }
}

@media (max-width: 620px) {
  .topbar { padding: 10px 14px; gap: 12px; }
  .page { padding: 20px 14px 56px; }
  .who { display: none; }
}
