/* Providence control panel.
 *
 * This is an operator readout for a sweep that runs for weeks. The data is
 * addresses, ports, version strings and counts, so the type work is about
 * scanning a column, not personality: identifiers and numbers get a monospace
 * column so they line up, everything else is the system UI font. No webfonts,
 * because the binary embeds these files and serves them with no external
 * requests: the panel has to open instantly on a LAN box that might have no
 * route to a CDN.
 *
 * Dark by default because the thing gets glanced at from a terminal at odd
 * hours, but that's a decision not a costume, so the light theme is a full
 * theme and the toggle is remembered.
 *
 * Colour budget: two greys for structure, one green accent for "alive", amber
 * and red held back for state that needs attention. Nothing glows, nothing is
 * glass, radii are small and only one surface gets to cast a shadow.
 *
 * Dial: ENERGY 2 / RHYTHM 3 / MOTION 1.
 *   ENERGY 2 because the data leads and the chrome stays quiet, but the
 *   counters strip should be readable across a room.
 *   RHYTHM 3 because the panes are genuinely different shapes: a dense table, a
 *   profile picker over a long form, a name search, a log tail, an account list.
 *   MOTION 1 because a panel that runs for weeks should sit still. Hover and
 *   focus states only; the one movement is a new row arriving.
 *
 * Picked by the agent: there's no DESIGN.md behind them yet, so this is a
 * considered default rather than the product owner's. The monospace data column
 * and the green "alive" vocabulary are the motif.
 */

:root {
  --bg:        #14171a;
  --panel:     #1b1f23;
  --panel-2:   #22272c;
  --border:    #2e353b;
  --control:   #767f87;
  --text:      #e6eaed;
  --text-dim:  #9aa4ad;
  --accent:    #5fb84e;
  --accent-ink:#0f1a0c;
  --warn:      #d9a441;
  --danger:    #e5685f;

  --r-sm: 2px;
  --r-md: 4px;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  color-scheme: dark;
}

[data-theme="light"] {
  --bg:        #f4f5f6;
  --panel:     #ffffff;
  --panel-2:   #eceef0;
  --border:    #d3d8dd;
  --control:   #6b7480;
  --text:      #1a1d20;
  --text-dim:  #5b656e;
  --accent:    #2f6f26;
  --accent-ink:#ffffff;
  --warn:      #8a5a00;
  --danger:    #b3261e;

  color-scheme: light;
}

* { box-sizing: border-box; }

/* the UA stylesheet hides [hidden] with display:none, but any rule that sets
 * display on the same element wins on specificity. Several sections here set
 * display, so the attribute gets re-asserted once instead of being remembered
 * at every call site */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

code, .mono, .num { font-family: var(--mono); font-size: .92em; }

.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;
}

/* focus is never removed, only replaced. 3:1 against every surface it lands on */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: var(--r-sm);
}

/* ---------------------------------------------------------------- controls */

.btn {
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--control);
  border-radius: var(--r-sm);
  padding: 6px 12px;
  cursor: pointer;
}
.btn:hover { border-color: var(--text-dim); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { border-color: var(--accent); filter: brightness(1.08); }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); border-color: var(--control); }
.btn-ghost[aria-pressed="true"] { color: var(--text); border-color: var(--control); background: var(--panel-2); }

.btn-sm { padding: 4px 9px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger); color: var(--bg); }

input[type="text"], input[type="password"], input[type="search"],
input[type="number"], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--control);
  border-radius: var(--r-sm);
  padding: 5px 8px;
  min-width: 0;
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }
input[type="number"].narrow { width: 8.5em; }
textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
select { cursor: pointer; }

#user-create input[type="text"] { min-width: 200px; }

.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text-dim); }
.check input { accent-color: var(--accent); }

.field { display: block; margin-bottom: 12px; }
.field-label { display: block; margin-bottom: 3px; font-size: 12px; color: var(--text-dim); }
.field input, .field textarea { width: 100%; }

/* ------------------------------------------------------------------ login */

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 24px;
}
.login-logo { display: block; width: 88px; height: auto; margin: 0 auto 14px; }
.login-title { font-size: 20px; letter-spacing: -.01em; }
.login-sub { margin: 6px 0 20px; color: var(--text-dim); font-size: 13px; }
.login-error {
  margin: 0 0 12px;
  padding: 8px 10px;
  border: 1px solid var(--danger);
  border-radius: var(--r-sm);
  color: var(--danger);
  font-size: 13px;
}
.login-foot { margin: 14px 0 0; color: var(--text-dim); font-size: 12px; text-align: center; }

/* ------------------------------------------------------------------ shell */

.app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 600; letter-spacing: -.01em; }

.livestate { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; color: var(--text-dim); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); flex: none; }
/* a real state gets a real mark: green while the sweep is running */
.dot[data-state="running"] { background: var(--accent); }
.dot[data-state="stopped"] { background: var(--text-dim); }
.dot[data-state="down"]    { background: var(--danger); }

.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tab {
  font: inherit;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 5px 10px;
  cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab[aria-current="page"] { color: var(--text); background: var(--panel-2); border-color: var(--control); }

.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.who { font-size: 13px; color: var(--text-dim); }

.banner {
  margin: 0;
  padding: 8px 16px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.banner[data-kind="error"] { color: var(--danger); }

.pane { padding: 16px; flex: 1; min-width: 0; }
.pane-title { font-size: 15px; margin-bottom: 4px; }
.pane-sub { margin: 0 0 14px; color: var(--text-dim); font-size: 13px; max-width: 78ch; }
.hint { color: var(--text-dim); font-size: 13px; margin: 0 0 12px; max-width: 78ch; }

/* --------------------------------------------------------------- counters */

.counters {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--panel);
  margin-bottom: 12px;
  overflow: hidden;
}
.counter {
  padding: 8px 14px;
  border-right: 1px solid var(--border);
  min-width: 0;
}
.counter:last-child { border-right: 0; }
.counter-label { display: block; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.counter-value { display: block; font-family: var(--mono); font-size: 16px; margin-top: 1px; }
.counter-value[data-tone="good"] { color: var(--accent); }
.counter-value[data-tone="warn"] { color: var(--warn); }
.counter-value[data-tone="bad"]  { color: var(--danger); }

/* ---------------------------------------------------------------- toolbar */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.toolbar .grow { flex: 1 1 220px; }
.toolbar .spacer { flex: 1 1 auto; }

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

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--panel);
  overflow: auto;
  max-height: 62vh;
}
.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  padding: 7px 10px;
  white-space: nowrap;
}
.grid td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background: var(--panel-2); }
.grid tbody tr[data-clickable] { cursor: pointer; }
.grid .nowrap { white-space: nowrap; }
.grid .dim { color: var(--text-dim); }

.table-foot { display: flex; align-items: center; gap: 12px; padding: 8px 2px; color: var(--text-dim); font-size: 13px; }

/* MOTD colour codes, so a server's own formatting shows up as written.
 *
 * the game's palette is built for the game's dark chat box, so the raw values
 * don't work on a light background: §f is near-white and §b and §e are pale.
 * Both sets below are verified at 4.5:1 or better against the panel they land
 * on, and the hue is kept so a server that colours itself green still reads
 * green */
.motd {
  --mc0: #6b7378; --mc1: #4a6fbe; --mc2: #3f8f4a; --mc3: #3f9a9a;
  --mc4: #b04a4a; --mc5: #9a5bbe; --mc6: #c08a3e; --mc7: #9aa4ad;
  --mc8: #767f87; --mc9: #6f8fd0; --mca: #5fb84e; --mcb: #5fc9d6;
  --mcc: #e5685f; --mcd: #d07fd0; --mce: #d9c84a; --mcf: #e6eaed;
  display: inline;
}
[data-theme="light"] .motd {
  --mc0: #3a4045; --mc1: #2b4c8c; --mc2: #2c6b34; --mc3: #1f6b6b;
  --mc4: #9b2c2c; --mc5: #6f3d8f; --mc6: #7a5400; --mc7: #5b656e;
  --mc8: #4a5259; --mc9: #3457a8; --mca: #2f6f26; --mcb: #1f6f7a;
  --mcc: #b3261e; --mcd: #8f3f8f; --mce: #7a6400; --mcf: #1a1d20;
}
.motd .mc-bold { font-weight: 700; }
.motd .mc-italic { font-style: italic; }
.motd .mc-under { text-decoration: underline; }
.motd .mc-strike { text-decoration: line-through; }

/* ------------------------------------------------------------------ chips */

.tag {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--control);
  border-radius: var(--r-sm);
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}
.tag[data-tone="good"] { color: var(--accent); border-color: var(--accent); }
.tag[data-tone="warn"] { color: var(--warn); border-color: var(--warn); }
.tag[data-tone="bad"]  { color: var(--danger); border-color: var(--danger); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }

/* --------------------------------------------------------------- presets */

.presets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}
.preset {
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.preset:hover { border-color: var(--control); }
.preset[aria-pressed="true"] { border-color: var(--accent); }
.preset-name { font-weight: 600; }
.preset-sum { color: var(--text-dim); font-size: 12.5px; }
.preset-count { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }

/* -------------------------------------------------------------- settings */

.settings { display: grid; gap: 18px; }
.group { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--panel); padding: 14px; }
.group-title { font-size: 13px; margin-bottom: 2px; }
.group-note { color: var(--text-dim); font-size: 12.5px; margin: 0 0 12px; }
.group-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.group-grid .wide { grid-column: 1 / -1; }
.row-label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 3px; }
.row-help { display: block; font-size: 11.5px; color: var(--text-dim); margin-top: 3px; }
.group-grid input[type="text"], .group-grid input[type="number"],
.group-grid select, .group-grid textarea { width: 100%; }
.group-grid label { min-width: 0; }

.sticky-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  margin-top: 16px;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.save-state { font-size: 13px; color: var(--text-dim); }
.save-state[data-tone="good"] { color: var(--accent); }
.save-state[data-tone="bad"] { color: var(--danger); }

/* ------------------------------------------------------------------ logs */

.logs {
  margin: 0;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  max-height: 68vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------------------------------------------------------------- detail */

/* the one surface allowed to float, since it genuinely sits above the table */
.detail {
  width: min(760px, 94vw);
  max-height: 88vh;
  padding: 0;
  border: 1px solid var(--control);
  border-radius: var(--r-md);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}
.detail::backdrop { background: rgba(0, 0, 0, .55); }
.detail-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
  position: sticky;
  top: 0;
}
.detail-head h2 { font-size: 15px; margin-right: auto; }
.detail-head-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.detail-body { padding: 16px; overflow: auto; max-height: calc(88vh - 56px); }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.fact-label { display: block; font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }
.fact-value { display: block; margin-top: 2px; }
.section-title { font-size: 13px; margin: 20px 0 8px; }
.section-title:first-child { margin-top: 0; }
.spark { display: block; width: 100%; height: 64px; }
.spark-note { font-size: 12px; color: var(--text-dim); margin: 6px 0 0; }
.raw {
  margin-top: 18px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 10px;
}
.raw summary { cursor: pointer; color: var(--text-dim); font-size: 13px; }
.raw pre { margin: 10px 0 0; overflow: auto; font-size: 12px; max-height: 40vh; }

.player-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.player-row:last-child { border-bottom: 0; }
.player-name { font-family: var(--mono); }
.player-meta { margin-left: auto; color: var(--text-dim); font-size: 12.5px; }

.sighting { display: flex; align-items: baseline; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.sighting:last-child { border-bottom: 0; }
.sighting-key { font-family: var(--mono); background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: inherit; text-align: left; }
.sighting-key:hover { text-decoration: underline; }
.sighting-meta { margin-left: auto; color: var(--text-dim); font-size: 12.5px; white-space: nowrap; }

/* ---------------------------------------------------------------- narrow */

@media (max-width: 860px) {
  .pane { padding: 12px; }
  .topbar { gap: 10px; padding: 10px 12px; }
  .topbar-right { margin-left: 0; width: 100%; }
  .table-wrap { max-height: none; }
  .counters { overflow-x: auto; }
  .counter { flex: none; }
  .detail { width: 100vw; max-width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; border: 0; }
  .detail-body { max-height: calc(100vh - 56px); }
  .toolbar .grow { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
