/* Predis Staging Deployer — dark, dense, deliberately a little futuristic.
 *
 * Design rules this file holds itself to (docs/design.md section 8.0):
 *
 *  - Status is never carried by colour alone. Every unit state pairs a colour
 *    with a glyph and a text label, so it survives colour-blindness and a
 *    screenshot pasted into Slack.
 *  - Status colours are a reserved set (running / warning / failed / inert) and
 *    are never reused as decoration. Decoration uses the cyan/violet accents.
 *  - All body ink clears WCGA AA against all three surfaces. --ink-dim is
 *    UI-level contrast only (~3.7:1) so it is restricted to borders, rules and
 *    icons — never small text.
 *  - Motion is ambient, never on a destructive path. The force-reset control is
 *    deliberately plain and slightly severe.
 *  - Everything animated is disabled under prefers-reduced-motion; colour and
 *    layout carry the same information without it.
 */

:root {
  /* Surfaces, dark → light */
  --bg: #07080c;
  --surface: #0e1118;
  --elevated: #151926;
  --sunken: #05060a;

  --border: #1c2130;
  --border-bright: #2a3145;

  /* Ink — all AA on every surface above except --ink-dim (UI only) */
  --ink: #e8eaf2;
  --ink-muted: #97a0b5;
  --ink-dim: #6b7488;

  /* Accents — decoration and focus only, never status */
  --cyan: #22d3ee;
  --violet: #8b7cf8;

  /* Reserved status palette. CVD-validated: worst adjacent pair ΔE 10.6
   * (protan), all ≥ 3:1 against every surface. */
  --running: #34d399;
  --warning: #fbbf24;
  --failed: #fb7185;
  --inert: #4b5262;

  --radius: 14px;
  --radius-sm: 8px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;

  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px -12px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* Ambient depth: one wide radial wash plus a very fine grid. Both are pure
 * decoration and sit behind everything at low opacity — they must never reduce
 * text contrast. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(70rem 40rem at 15% -10%, rgba(34, 211, 238, .07), transparent 60%),
    radial-gradient(60rem 35rem at 95% 0%, rgba(139, 124, 248, .07), transparent 60%);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .35;
  background-image:
    linear-gradient(rgba(255, 255, 255, .022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .022) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 50% 0%, #000 0%, transparent 75%);
}

.shell { position: relative; z-index: 1; max-width: 1600px; margin: 0 auto; padding: 22px 24px 140px; }

/* ------------------------------------------------------------------ header */

.top {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding-bottom: 18px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: baseline; gap: 10px; }

.brand h1 {
  margin: 0;
  font: 600 17px/1.2 var(--sans);
  letter-spacing: -.01em;
}

.brand .mark {
  font: 700 12px/1 var(--mono);
  letter-spacing: .16em;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--bg);
  background: linear-gradient(135deg, var(--cyan), var(--violet));
}

.brand .sub { color: var(--ink-muted); font-size: 12.5px; }

.top .spacer { flex: 1 1 auto; }

.who {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--ink-muted);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

.who .avatar {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font: 600 10px/1 var(--sans); color: var(--bg);
  background: linear-gradient(135deg, var(--cyan), var(--violet));
}

/* ------------------------------------------------------------ memory gauge */

/* A stat tile, not a chart: one measure against a known total, so the headline
 * is the number and the bar is secondary. 4px rounded fill anchored to the
 * track's start, 2px inset so fill and track never touch the same pixel. */
.gauge {
  min-width: 300px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.gauge .row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.gauge .label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-muted); }

.gauge .value { font: 600 20px/1 var(--mono); letter-spacing: -.02em; }
.gauge .value .unit { font-size: 12px; color: var(--ink-muted); font-weight: 400; margin-left: 2px; }
.gauge .of { font-size: 12px; color: var(--ink-muted); }

.gauge .track {
  position: relative;
  height: 8px;
  margin-top: 10px;
  border-radius: 999px;
  background: var(--sunken);
  border: 1px solid var(--border);
  overflow: hidden;
}

.gauge .fill {
  position: absolute; inset: 1px auto 1px 1px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  transition: width .5s cubic-bezier(.22, 1, .36, 1);
}

/* Pressure states reuse the reserved status colours and are always accompanied
 * by the numeric value, so the colour is a hint and not the message. */
.gauge.warn .fill { background: linear-gradient(90deg, var(--warning), var(--failed)); }
.gauge.crit .fill { background: linear-gradient(90deg, var(--failed), #e11d48); }

.gauge .foot { margin-top: 7px; font-size: 11.5px; color: var(--ink-muted); }

/* ------------------------------------------------------------------- grid */

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

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--surface), #0c0e15);
  box-shadow: var(--shadow);
  transition: border-color .18s, transform .18s;
}

.card:hover { border-color: var(--border-bright); }

/* A slot mid-deploy gets a travelling border highlight. Ambient only — it says
 * "busy", the step text says what is happening. */
.card.busy {
  border-color: transparent;
  background:
    linear-gradient(180deg, var(--surface), #0c0e15) padding-box,
    linear-gradient(115deg, var(--cyan), var(--violet), var(--cyan)) border-box;
  background-size: auto, 300% 100%;
  animation: sweep 3.5s linear infinite;
}

@keyframes sweep {
  from { background-position: 0 0, 0% 50%; }
  to   { background-position: 0 0, 300% 50%; }
}

.card-head { display: flex; align-items: flex-start; gap: 11px; }

.slotno {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 11px;
  border: 1px solid var(--border-bright);
  background: var(--elevated);
  font: 600 18px/1 var(--mono);
  letter-spacing: -.03em;
}

.card.busy .slotno { border-color: var(--cyan); color: var(--cyan); }

.hosts { min-width: 0; flex: 1 1 auto; }

.hosts a {
  display: block;
  font: 500 13px/1.45 var(--mono);
  color: var(--ink);
  text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hosts a:hover { color: var(--cyan); text-decoration: underline; }
.hosts .brain { color: var(--ink-muted); font-size: 12px; }

/* --------------------------------------------------------------- meta rows */

.meta { display: grid; gap: 7px; }

.mrow { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; min-width: 0; }
.mrow .k { flex: 0 0 26px; color: var(--ink-dim); font: 600 10px/1.6 var(--mono); letter-spacing: .08em; }
.mrow .v {
  font-family: var(--mono);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.mrow .sha { color: var(--ink-muted); font-size: 11.5px; }

.tag {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 6px;
  border-radius: 5px;
  font: 600 10px/1.7 var(--mono);
  letter-spacing: .05em;
  border: 1px solid;
}
.tag.dirty { color: var(--warning); border-color: rgba(251, 191, 36, .4); background: rgba(251, 191, 36, .1); }
.tag.err { color: var(--failed); border-color: rgba(251, 113, 133, .4); background: rgba(251, 113, 133, .1); }
.tag.detached { color: var(--ink-muted); border-color: var(--border-bright); }

/* ------------------------------------------------------------------- units */

.units { display: grid; gap: 4px; }

.unit {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 7px;
  border-radius: 6px;
  background: var(--sunken);
  border: 1px solid transparent;
  font-size: 12px;
}

.unit .glyph { flex: 0 0 auto; width: 13px; text-align: center; font: 700 11px/1 var(--mono); }
.unit .name { flex: 1 1 auto; font-family: var(--mono); font-size: 11.5px; color: var(--ink-muted);
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unit .mem { flex: 0 0 auto; font: 500 11px/1 var(--mono); color: var(--ink-muted); }
.unit .state { flex: 0 0 auto; font: 600 9.5px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; }

.unit.active { border-color: rgba(52, 211, 153, .22); }
.unit.active .glyph, .unit.active .state { color: var(--running); }
.unit.active .name { color: var(--ink); }

.unit.inactive .glyph, .unit.inactive .state { color: var(--inert); }

.unit.failed { border-color: rgba(251, 113, 133, .3); background: rgba(251, 113, 133, .06); }
.unit.failed .glyph, .unit.failed .state { color: var(--failed); }

.unit.unknown .glyph, .unit.unknown .state { color: var(--warning); }

/* The pulse marks "currently running" without needing a second colour. It is
 * the only animated status cue, and it is redundant with the glyph and label. */
.unit.active .glyph { animation: pulse 2.4s ease-in-out infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* ----------------------------------------------------------------- footers */

.lastby {
  font-size: 11.5px;
  color: var(--ink-muted);
  padding-top: 9px;
  border-top: 1px dashed var(--border);
}
.lastby b { color: var(--ink); font-weight: 600; }
.lastby .bad { color: var(--failed); }

.actions { display: flex; gap: 7px; flex-wrap: wrap; }

.btn {
  appearance: none;
  font: 600 12px/1 var(--sans);
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-bright);
  background: var(--elevated);
  color: var(--ink);
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.btn:hover:not(:disabled) { border-color: var(--cyan); color: var(--cyan); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn.primary {
  border-color: transparent;
  color: var(--bg);
  background: linear-gradient(135deg, var(--cyan), var(--violet));
}
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); color: var(--bg); }

.btn.ghost { background: transparent; }

/* Destructive controls stay plain: no gradient, no glow, no animation. */
.btn.danger { border-color: rgba(251, 113, 133, .45); color: var(--failed); background: transparent; }
.btn.danger:hover:not(:disabled) { background: rgba(251, 113, 133, .12); border-color: var(--failed); color: var(--failed); }

.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ------------------------------------------------------------------ dialog */

dialog {
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  width: min(560px, calc(100vw - 32px));
  box-shadow: 0 24px 70px -20px rgba(0, 0, 0, .9);
}
dialog::backdrop { background: rgba(3, 4, 8, .74); backdrop-filter: blur(3px); }

.dlg-head { padding: 16px 18px 0; }
.dlg-head h2 { margin: 0 0 3px; font-size: 15px; }
.dlg-head p { margin: 0; font-size: 12.5px; color: var(--ink-muted); }
.dlg-body { padding: 16px 18px; display: grid; gap: 14px; }
.dlg-foot {
  padding: 13px 18px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
  background: var(--sunken);
  border-radius: 0 0 var(--radius) var(--radius);
}

.field { display: grid; gap: 5px; }
.field > label { font: 600 10.5px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-muted); }
.field .hint { font-size: 11.5px; color: var(--ink-muted); }

select, input[type="text"] {
  appearance: none;
  width: 100%;
  font: 13px/1.3 var(--mono);
  padding: 9px 10px;
  color: var(--ink);
  background: var(--sunken);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
}
select:focus, input:focus { outline: 2px solid var(--cyan); outline-offset: -1px; border-color: var(--cyan); }

.check { display: flex; gap: 9px; align-items: flex-start; font-size: 12.5px; }
.check input { margin: 2px 0 0; accent-color: var(--cyan); }
.check .t { color: var(--ink); font-weight: 600; }
.check .d { color: var(--ink-muted); font-size: 11.5px; }

.notice {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  border: 1px solid;
}
.notice.warn { color: var(--warning); border-color: rgba(251, 191, 36, .35); background: rgba(251, 191, 36, .08); }
.notice.bad { color: var(--failed); border-color: rgba(251, 113, 133, .35); background: rgba(251, 113, 133, .08); }
.notice.info { color: var(--ink-muted); border-color: var(--border-bright); background: var(--sunken); }
.notice b { display: block; margin-bottom: 3px; color: inherit; }
.notice ul { margin: 6px 0 0; padding-left: 18px; font-family: var(--mono); font-size: 11.5px; }

/* -------------------------------------------------------------- log drawer */

.drawer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  max-height: 62vh;
  display: flex; flex-direction: column;
  background: var(--sunken);
  border-top: 1px solid var(--border-bright);
  box-shadow: 0 -18px 50px -20px rgba(0, 0, 0, .95);
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.22, 1, .36, 1);
}
.drawer.open { transform: translateY(0); }

.drawer-head {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.drawer-head .title { font: 600 13px/1 var(--sans); }
.drawer-head .step { font: 12px/1 var(--mono); color: var(--cyan); }
.drawer-head .spacer { flex: 1 1 auto; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font: 600 10px/1.6 var(--mono); letter-spacing: .09em; text-transform: uppercase;
  border: 1px solid;
}
.pill.queued { color: var(--ink-muted); border-color: var(--border-bright); }
.pill.running { color: var(--cyan); border-color: rgba(34, 211, 238, .4); background: rgba(34, 211, 238, .1); }
.pill.succeeded { color: var(--running); border-color: rgba(52, 211, 153, .4); background: rgba(52, 211, 153, .1); }
.pill.failed { color: var(--failed); border-color: rgba(251, 113, 133, .4); background: rgba(251, 113, 133, .1); }

.log {
  flex: 1 1 auto;
  overflow: auto;
  margin: 0;
  padding: 12px 14px 20px;
  font: 12px/1.65 var(--mono);
  color: #c7cddd;
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: thin;
}
.log .l-step { color: var(--cyan); font-weight: 600; }
.log .l-cmd { color: var(--violet); }
.log .l-ok { color: var(--running); }
.log .l-warn { color: var(--warning); }
.log .l-bad { color: var(--failed); }
.log .l-dim { color: var(--ink-dim); }

/* Terminal cursor, only while a job is live. */
.log .cursor::after {
  content: "▊";
  color: var(--cyan);
  animation: blink 1.1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.empty { padding: 60px 20px; text-align: center; color: var(--ink-muted); }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 8px; max-width: 400px; }
.toast {
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-bright);
  background: var(--elevated);
  font-size: 12.5px;
  box-shadow: var(--shadow);
  animation: rise .22s ease-out;
}
.toast.bad { border-color: rgba(251, 113, 133, .5); color: var(--failed); }
.toast.good { border-color: rgba(52, 211, 153, .5); color: var(--running); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.skeleton {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(100deg, var(--surface) 30%, var(--elevated) 50%, var(--surface) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.4s linear infinite;
  height: 232px;
}
@keyframes shimmer { to { background-position: -220% 0; } }

/* ------------------------------------------------------- reduced motion */

/* Drop every animation and transition. All state remains readable from colour,
 * glyph and text, none of which depended on movement. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .drawer { transition: none; }
  .log .cursor::after { animation: none; visibility: visible; }
}

@media (max-width: 700px) {
  .shell { padding: 16px 14px 130px; }
  .grid { grid-template-columns: 1fr; }
  .gauge { min-width: 0; width: 100%; }
}
