/* ============================================================
   RecreationBench — design system
   Direction: flat instrument dark. The chrome is a thin strip of
   surface colour; every remaining pixel belongs to the two
   desktops being compared. No gradients, no reveals, no
   stagecraft — a bright accent on one channel would bias a
   fidelity judgement, so both screens are framed identically.

   Two shells share this sheet:
     - body.app-shell  fixed viewport, never scrolls (the console)
     - plain body      normal document flow (the admin pages)
   ============================================================ */

@font-face {
  font-family: "Plex Mono";
  src: url("/mac/fonts/plexmono-400.woff2") format("woff2");
  font-weight: 400; font-display: swap; font-style: normal;
}
@font-face {
  font-family: "Plex Mono";
  src: url("/mac/fonts/plexmono-500.woff2") format("woff2");
  font-weight: 500; font-display: swap; font-style: normal;
}

:root {
  color-scheme: dark;

  /* surfaces */
  --bg: #0b0f14;
  --surface: #10151c;
  --surface-2: #151b23;
  --line: #29313b;
  --line-soft: #202934;

  /* type */
  --text: #e8edf4;
  --muted: #8995a4;

  /* accents */
  --blue: #6ea8ff;
  --green: #39d353;
  --red: #ff4038;
  --amber: #e3b341;

  /* the two comparison channels, held at similar luminance */
  --ch-a: #6ea8ff;
  --ch-b: #c792ea;

  /* radii */
  --r-sm: 7px;
  --r-md: 12px;
  --r-lg: 22px;
  --r-pill: 999px;

  /* faces */
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
          "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  /* spacing scale */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 72px;
  --s9: 112px;

  /* ---- legacy token names -------------------------------------------
     admin.html carries an inline <style> written against the previous
     palette, and older markup still says var(--steel) here and there.
     Pointing the old names at the new colours keeps those rules alive
     instead of leaving half a page in the retired gold scheme. */
  --void: var(--bg);
  --plate: var(--surface);
  --plate-hi: var(--surface-2);
  --engrave: var(--line);
  --porcelain: var(--text);
  --steel: var(--muted);
  --brass: var(--blue);
  --brass-lit: #8fbcff;
  --alarm: var(--red);
  --display: var(--sans);
  --body: var(--sans);
  --bevel: none;
  --lift: 0 16px 44px rgb(0 0 0 / 34%);
  --brushed: none;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* The console is a fixed-viewport app: the two desktops must fit the
   screen exactly, so this shell never scrolls. Admin pages leave it off
   and scroll normally. */
body.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

a { color: var(--blue); text-decoration: none; }
a:hover { color: #9cc4ff; }

button, input, select { font: inherit; }

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ============================================================
   TOP BAR
   Two columns: identity on the left, controls on the right.
   admin.html puts .brand + .right in here; the console puts
   .topbar-left + .topbar-right. Both land in the same slots.
   ============================================================ */
.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s5);
  padding: 10px var(--s5);
  background: #0d1218;
  border-bottom: 1px solid #252d36;
}
.topbar-left, .topbar-right { min-width: 0; }
.topbar-right, .topbar .right {
  display: flex; align-items: center; justify-content: flex-end;
  gap: var(--s4); flex-wrap: wrap;
  min-width: 0;
  font-size: 12px; color: var(--muted);
}
.topbar .right b, .topbar-right b {
  font-family: var(--mono); font-weight: 500; color: var(--text);
}

.brand-block { min-width: 0; }
.brand {
  display: flex; align-items: baseline; gap: 10px;
  white-space: nowrap;
  font-size: 17px; font-weight: 700; color: var(--text);
}
.brand h1 { margin: 0; font-size: 20px; line-height: 1.05; font-weight: 700; }
.brand span, .brand small {
  font-weight: 400; font-size: 12px; color: var(--muted);
}

/* ---------- the App / model pickers in the top bar ---------- */
.picker-bar { display: flex; align-items: center; gap: var(--s4); min-width: 0; flex-wrap: wrap; }
.picker-group { display: flex; align-items: center; gap: 10px; min-width: 0; }
.picker-label {
  flex: 0 0 auto;
  color: var(--muted); font-size: 11px; font-weight: 800;
  letter-spacing: .08em; text-transform: uppercase;
}
.picker-select, .pane-model-select, .lang-select, .sess-select {
  height: 32px;
  padding: 0 10px;
  border: 1px solid #303c49;
  border-radius: var(--r-sm);
  outline: none;
  background: #131a22;
  color: #dbe2eb;
  cursor: pointer;
  font-size: 12px;
}
.picker-select { min-width: 190px; }
.picker-select:focus, .pane-model-select:focus,
.lang-select:focus, .sess-select:focus {
  border-color: #5d94e8;
  box-shadow: 0 0 0 2px rgb(110 168 255 / 15%);
}
.picker-select:disabled, .pane-model-select:disabled, .sess-select:disabled {
  cursor: default; opacity: .45;
}
.lang-select { height: 28px; font-size: 12px; }

/* ============================================================
   STAGE — the two desktops
   ============================================================ */
main.stage {
  position: relative;
  min-height: 0;
  padding: var(--s4) var(--s5) var(--s3);
  overflow: hidden;
  background: radial-gradient(circle at 50% 10%, #131a23 0, var(--bg) 46%);
}
.desktop-stage { width: 100%; height: 100%; min-height: 0; overflow: hidden; }
.viewer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(14px, 2vw, 32px);
  align-items: stretch;
  width: 100%; height: 100%; min-height: 0;
}

.app-slot {
  display: grid;
  grid-template-rows: 34px minmax(0, 1fr);
  min-width: 0; min-height: 0;
  overflow: hidden;
}
.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s3);
  min-width: 0;
  padding: 0 4px 9px;
}
.pane-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.pane-label {
  overflow: hidden;
  color: var(--text); font-size: 14px; font-weight: 600;
  text-overflow: ellipsis; white-space: nowrap;
}
.pane-meta {
  overflow: hidden;
  color: var(--muted); font-size: 11px;
  text-overflow: ellipsis; white-space: nowrap;
}
.pane-model-select { width: min(220px, 46%); }

/* A slot is live only once its own container reports running: the dot is
   the honest per-screen signal, not the session's overall status. */
.live-dot {
  display: inline-block;
  width: 10px; height: 10px; flex: 0 0 10px;
  border-radius: 50%;
  background: #485463;
  box-shadow: 0 0 0 4px rgb(72 84 99 / 12%);
}
.app-slot.is-live .live-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgb(57 211 83 / 12%);
}
.app-slot.is-failed .live-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgb(255 64 56 / 12%);
}

.slot-frame {
  position: relative;
  min-width: 0; min-height: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-lg);
  background: #020406;
  box-shadow: 0 16px 44px rgb(0 0 0 / 34%), inset 0 0 0 1px rgb(255 255 255 / 2%);
  contain: layout paint size;
}
/* noVNC mounts its canvas in here and sizes it to the box */
.screen { position: absolute; inset: 0; overflow: hidden; }
.screen canvas { display: block; }

.placeholder, .empty-state {
  height: 100%;
  display: grid; place-items: center;
  padding: var(--s5);
  color: var(--muted); font-size: 13px; text-align: center;
}
.empty-state {
  border: 1px dashed #35414e;
  border-radius: var(--r-lg);
  background: var(--surface);
}
.empty-state .es-title { color: var(--text); font-size: 15px; font-weight: 650; }
.empty-state .es-body { max-width: 46ch; margin-top: var(--s2); line-height: 1.6; }

/* Status float, top-left inside a frame. Hidden once the screen is live so
   nothing sits on top of the desktop being judged. */
.slot-status {
  position: absolute; left: 14px; top: 14px; z-index: 2;
  max-width: calc(100% - 28px);
  padding: 7px 10px;
  border: 1px solid rgb(255 255 255 / 10%);
  border-radius: var(--r-sm);
  background: rgb(12 17 23 / 86%);
  color: var(--text);
  font-size: 12px; line-height: 1.35;
  opacity: 0; pointer-events: none;
  transition: opacity .15s ease;
}
.app-slot:not(.is-live) .slot-status { opacity: 1; }
.slot-status:empty { opacity: 0; }

/* Full cover while a session is being torn down and rebuilt: the old
   desktop is gone and the new one is not up, so the frame must not look
   interactive. */
.switch-mask {
  position: absolute; inset: 0; z-index: 3;
  display: grid; place-items: center;
  padding: var(--s5);
  border-radius: var(--r-lg);
  background: rgb(0 0 0 / 94%);
  color: var(--text);
  font-size: 15px; font-weight: 700; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .15s ease;
}
.app-slot.is-switching .switch-mask { opacity: 1; }

/* ============================================================
   ACTION BAR (console footer)
   ============================================================ */
.appbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s4); flex-wrap: wrap;
  min-height: 46px;
  padding: 6px var(--s5);
  background: #0d1218;
  border-top: 1px solid #252d36;
  font-size: 12px; color: var(--muted);
}
.appbar .tools { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.appbar .facts { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; min-width: 0; }
.appbar .facts b { font-family: var(--mono); font-weight: 500; color: var(--text); }

/* ---------- run metadata rows (console + admin) ---------- */
.run-meta {
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4);
  font-size: 12px; color: var(--muted);
}
.run-meta span { white-space: nowrap; }
.run-meta b { font-family: var(--mono); font-weight: 500; color: var(--text); }

/* live startup countdown, shown while a session boots */
.startup-timer {
  font-family: var(--mono); font-size: 12px;
  color: var(--blue); white-space: nowrap; cursor: help;
}
.startup-timer:empty { display: none; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  min-height: 34px;
  padding: 0 var(--s4);
  border: 1px solid var(--blue);
  border-radius: 9px;
  background: var(--blue);
  color: #08111f;
  font-size: 13px; font-weight: 700;
  cursor: pointer;
  transition: filter .15s ease, background-color .15s ease,
              color .15s ease, border-color .15s ease;
}
.btn:hover:not(:disabled) { filter: brightness(1.07); }
.btn.ghost {
  background: #141b23; color: var(--text);
  border-color: #303c49;
}
.btn.ghost:hover:not(:disabled) { border-color: #47576a; background: #18212b; filter: none; }
.btn.danger {
  background: transparent; color: var(--red);
  border-color: rgb(255 64 56 / 45%);
}
.btn.danger:hover:not(:disabled) { background: var(--red); color: #170908; filter: none; }
.btn.small { min-height: 30px; padding: 0 12px; font-size: 12px; }
.btn:disabled { cursor: default; opacity: .45; }

/* ---------- toast ---------- */
.toast {
  position: fixed; right: var(--s5); top: 62px; z-index: 99;
  max-width: 340px;
  padding: 10px var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: rgb(21 27 35 / 96%);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--lift);
}
.toast.err { border-color: rgb(255 64 56 / 50%); }
.toast + .toast { top: 112px; }

/* ============================================================
   DOCUMENT PAGES (admin)
   ============================================================ */
.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--s5) var(--s5) var(--s8);
}

.section-title {
  margin: var(--s6) 0 var(--s3);
  color: var(--muted);
  font-size: 11px; font-weight: 800;
  letter-spacing: .1em; text-transform: uppercase;
}
.section-title:first-child { margin-top: 0; }

.grid { display: grid; gap: var(--s3); }
.stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.card {
  padding: var(--s4) var(--s5);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
.stat .num { font-family: var(--mono); font-size: 26px; font-weight: 500; line-height: 1.2; }
.stat .lbl { margin-top: var(--s1); color: var(--muted); font-size: 12px; }
.small { font-size: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th {
  color: var(--muted); font-size: 11px; font-weight: 800;
  letter-spacing: .06em; text-transform: uppercase;
}
td.mono, th.mono, .mono { font-family: var(--mono); }
/* Browser ids: normally 20 chars, but the caller picks the string, so cap the
   column instead of letting one long id stretch the whole table. Full value in
   the cell's title. */
td.cid { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
.rowbtns { display: flex; gap: 6px; flex-wrap: wrap; }

.bar { height: 6px; background: var(--surface-2); border-radius: var(--r-pill); overflow: hidden; margin-top: 6px; }
.bar > div { height: 100%; background: var(--blue); border-radius: var(--r-pill); }
.bar > div.hot { background: var(--red); }

/* ---------- status pills ---------- */
.badge {
  display: inline-block;
  padding: 1px 9px;
  border: 1px solid currentColor;
  border-radius: var(--r-pill);
  font-family: var(--mono); font-size: 11px;
  white-space: nowrap;
}
.badge.running   { color: var(--green); }
.badge.creating  { color: var(--amber); }
.badge.failed    { color: var(--red); }
.badge.destroyed { color: var(--muted); }

/* ---------- forms ---------- */
.form-row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.form-row + .form-row { margin-top: var(--s3); }
.form-row > label {
  color: var(--muted); font-size: 11px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
}
.input {
  padding: 7px 10px;
  border: 1px solid #303c49;
  border-radius: var(--r-sm);
  background: #131a22;
  color: var(--text);
  font-size: 13px;
}
.input:focus { border-color: #5d94e8; outline: none; box-shadow: 0 0 0 2px rgb(110 168 255 / 15%); }
.input.num { width: 84px; }
/* one line of feedback per form, reserved so nothing jumps when it appears */
.form-msg { min-height: 17px; margin-top: var(--s2); font-size: 12px; color: var(--muted); }
.form-msg.err { color: var(--red); }
.form-msg.ok { color: var(--green); }

/* the sign-in gate: the only thing on the page until an admin is known */
.gate { max-width: 400px; margin: 10vh auto 0; }
.gate h2 { margin: 0 0 var(--s2); font-size: 18px; font-weight: 700; }
.gate .lbl { color: var(--muted); font-size: 12.5px; line-height: 1.6; }
.gate .form-row { margin-top: var(--s4); }
.gate .form-row > label { min-width: 82px; }
.gate .input { flex: 1; min-width: 0; }

/* ---------- empty state inside a card/table ---------- */
.empty {
  padding: var(--s6) var(--s4);
  border: 1px dashed #35414e;
  border-radius: var(--r-md);
  color: var(--muted); font-size: 13px; text-align: center;
}
td.empty, .empty[colspan] { border: none; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .topbar { gap: 10px var(--s4); padding: 10px var(--s4); }
  .topbar-right, .topbar .right { gap: 10px; }
  .picker-bar { gap: var(--s2); }
  .picker-group { gap: 5px; }
  .picker-select { min-width: 130px; }
  main.stage { padding: var(--s3) var(--s4) 10px; }
  .viewer-grid {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--s3);
  }
  .slot-frame, .switch-mask, .empty-state { border-radius: var(--r-md); }
  .appbar { padding: 6px var(--s4); }
}

@media (max-width: 560px) {
  .brand h1 { font-size: 17px; }
  .brand span, .brand small, .pane-meta { display: none; }
  .pane-model-select { width: min(150px, 52%); }
}

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