/* The admin's stylesheet (T-274). Built ONLY from tokens.css, which is
   generated from the app's web/src/theme.css (see tokens.go). No raw colour,
   length or font here: tokens_test.go fails the build on one. The only literal
   lengths are media-query breakpoints, which cannot read a custom property.

   Vocabulary (shared with every lane's templates): ops-card, ops-section,
   ops-grid, ops-stack, ops-table (+ data-label cells), ops-form, ops-field,
   ops-hint, ops-confirm, btn-primary/-secondary/-danger, ops-badge + is-*,
   ops-empty, ops-error, ops-flash, ops-muted, ops-mono. */

:root {
  color-scheme: light; /* theme.css defines no dark variant; keep form controls on the light ramp */

  /* Inks derived from the semantic tokens. --error and --warning are tuned
     for the room's dark chrome; on a 10% tint of themselves they are too
     faint to read, so text on those tints is mixed toward --on-surface. */
  --ops-error-ink: color-mix(in srgb, var(--error) 62%, var(--on-surface));
  --ops-warning-ink: color-mix(in srgb, var(--warning) 50%, var(--on-surface));
  --ops-page: var(--surface-dim);
  --ops-gutter: var(--gap-lg); /* 16px side gutter at phone width (NFR-1) */
  --ops-label-col: var(--dt-col-max-tight);
  --ops-dot: var(--gap-sm);
}

@media (min-width: 720px) {
  :root { --ops-gutter: var(--pad-container); }
}

/* ---- base ---- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: var(--text-body-md);
  line-height: var(--line-body-md);
  color: var(--on-surface-variant);
  background: var(--ops-page);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { color: var(--on-surface); margin: 0; font-weight: 600; }
h1 { font-size: var(--text-headline-sm); line-height: var(--line-headline-sm); letter-spacing: var(--tracking-headline); }
h2 { font-size: var(--text-title-lg); line-height: var(--line-title-lg); letter-spacing: var(--tracking-title); }
h3 { font-size: var(--text-title-md); line-height: var(--line-title-md); letter-spacing: var(--tracking-title); }

@media (min-width: 720px) {
  h1 { font-size: var(--text-headline-md); line-height: var(--line-headline-md); }
}

p { margin: 0; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-sm); }

strong { color: var(--on-surface); font-weight: 600; }

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

.ops-header {
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
  background: var(--surface-translucent);
  backdrop-filter: var(--blur-md);
  -webkit-backdrop-filter: var(--blur-md);
  border-bottom: var(--border-width) solid var(--outline);
}

.ops-header-inner {
  max-width: var(--admin-content-width);
  margin: 0 auto;
  padding: var(--gap-md) var(--ops-gutter);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap-sm) var(--gap-xl);
}

.ops-brand {
  color: var(--on-surface);
  font-size: var(--text-title-md);
  line-height: var(--line-title-md);
  font-weight: 700;
  letter-spacing: var(--tracking-title);
}
.ops-brand:hover { text-decoration: none; }

.ops-nav {
  display: flex;
  align-items: center;
  gap: var(--gap-xs);
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
}

.ops-nav > a {
  color: var(--on-surface-variant);
  font-size: var(--text-label-md);
  line-height: var(--line-label-md);
  font-weight: 500;
  padding: var(--gap-sm) var(--gap-md);
  border-radius: var(--r-full);
  transition: color var(--t-fast), background var(--t-fast);
}
.ops-nav > a:hover { color: var(--on-surface); background: var(--surface-container-high); text-decoration: none; }
.ops-nav > a[aria-current="page"] { color: var(--on-primary-container); background: var(--primary-container); }

.ops-signout {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  min-width: 0;
}

.ops-whoami {
  font-size: var(--text-label-sm);
  line-height: var(--line-label-sm);
  color: var(--on-surface-muted);
  max-width: var(--admin-menu-width);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Phone: brand and Sign out share the first row, the nav takes the second. */
@media (max-width: 719px) {
  .ops-header-inner { gap: var(--gap-sm); }
  .ops-signout { order: 1; }
  .ops-nav { order: 2; flex-basis: 100%; margin-left: calc(-1 * var(--gap-md)); }
  .ops-whoami { display: none; }
}

/* ---- page frame ---- */

.ops-main {
  max-width: var(--admin-content-width);
  margin: 0 auto;
  padding: var(--gap-xl) var(--ops-gutter) var(--section);
}

.ops-page-head {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
  margin-bottom: var(--gap-xl);
}

.ops-subtitle { font-weight: 500; }

.ops-crumb {
  font-size: var(--text-label-sm);
  line-height: var(--line-label-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-eyebrow);
  text-transform: uppercase;
}

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

.ops-card {
  background: var(--surface);
  color: var(--on-surface-variant);
  border: var(--border-width) solid var(--outline);
  border-radius: var(--r-lg);
  padding: var(--pad-card);
  box-shadow: var(--elev-1);
  min-width: 0;
}

@media (max-width: 719px) {
  .ops-card { padding: var(--gap-lg); border-radius: var(--r-md); }
}

.ops-section {
  display: flex;
  flex-direction: column;
  gap: var(--gap-lg);
  margin-bottom: var(--gap-xl);
}

/* A wide table must never widen the page: it scrolls inside its own card. */
.ops-section:has(> .ops-table) { overflow-x: auto; }

.ops-tinted { background: var(--primary-container-subtle); border-color: var(--primary-container); box-shadow: var(--elev-0); }

/* auto-fit, not a viewport query: correct at every container width (CLAUDE.md Gotchas). */
.ops-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--admin-card-min)), 1fr));
  gap: var(--gap-lg);
}
.ops-grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--shell-panel-w)), 1fr)); gap: var(--gap-xl); }
.ops-grid-2 > .ops-section { margin-bottom: 0; }
.ops-grid-2 + * { margin-top: var(--gap-xl); }

.ops-stack { display: flex; flex-direction: column; gap: var(--gap-sm); min-width: 0; }
.ops-tight { gap: var(--gap-xs); }

.ops-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-md); }

.ops-action {
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
  padding: var(--gap-lg);
  border: var(--border-width) solid var(--outline-variant);
  border-radius: var(--r-md);
  background: var(--surface-container);
  min-width: 0;
}
.ops-danger-zone { border-color: var(--error-container); background: var(--surface); }

.ops-group { display: flex; flex-direction: column; gap: var(--gap-sm); }
.ops-group + .ops-group { padding-top: var(--gap-lg); border-top: var(--border-width) solid var(--outline-variant); }

/* ---- text vocabulary ---- */

.ops-muted { color: var(--on-surface-muted); }
.ops-strong { font-weight: 600; }
.ops-hint { font-size: var(--text-body-sm); line-height: var(--line-body-sm); color: var(--on-surface-variant); }
.ops-nowrap { white-space: nowrap; }
.ops-wrap { overflow-wrap: anywhere; }
.ops-notes { white-space: pre-line; color: var(--on-surface); }

.ops-mono {
  font-family: var(--font-mono);
  font-size: var(--text-body-sm);
  line-height: var(--line-body-sm);
}

.ops-applink {
  font-size: var(--text-body-sm);
  line-height: var(--line-body-sm);
  overflow-wrap: anywhere;
}

.ops-command {
  margin: 0;
  padding: var(--gap-md) var(--gap-lg);
  background: var(--inverse-surface);
  color: var(--inverse-on-surface);
  border-radius: var(--r);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: all; /* one click selects the whole command for copying */
}

/* ---- states ---- */

.ops-flash, .ops-error, .ops-warning {
  padding: var(--gap-md) var(--gap-lg);
  border-radius: var(--r);
  font-size: var(--text-body-sm);
  line-height: var(--line-body-sm);
  font-weight: 500;
  overflow-wrap: anywhere;
}
.ops-main > .ops-flash, .ops-main > .ops-error { margin-bottom: var(--gap-xl); }
.ops-flash { background: var(--primary-container); color: var(--on-primary-container); }
.ops-error { background: var(--error-container); color: var(--ops-error-ink); }
.ops-warning { background: var(--warning-container); color: var(--ops-warning-ink); }
.ops-error-text { color: var(--ops-error-ink); font-size: var(--text-body-sm); line-height: var(--line-body-sm); overflow-wrap: anywhere; }

.ops-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap-sm);
  text-align: center;
  padding-block: var(--section);
  margin-bottom: var(--gap-xl);
  border-style: dashed;
  box-shadow: var(--elev-0);
}
.ops-empty p { max-width: var(--landing-copy-width); }
.ops-empty-inline { color: var(--on-surface-variant); }

.ops-problem { display: flex; flex-direction: column; gap: var(--gap-md); align-items: flex-start; }

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

.ops-badges { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap-xs); }

.ops-badge {
  display: inline-flex;
  align-items: center;
  font-size: var(--text-label-sm);
  line-height: var(--line-label-sm);
  font-weight: 600;
  padding: var(--gap-xs) var(--gap-md);
  border-radius: var(--r-full);
  border: var(--border-width) solid var(--primary-container);
  background: var(--primary-container-subtle);
  color: var(--on-primary-container);
  white-space: nowrap;
  vertical-align: middle;
}
a.ops-badge:hover { text-decoration: none; background: var(--primary-container); }

.ops-badge.is-running  { background: var(--primary-container); border-color: transparent; color: var(--on-primary-container); }
.ops-badge.is-stopped  { background: var(--secondary-container); border-color: transparent; color: var(--on-surface-variant); }
.ops-badge.is-failed   { background: var(--error-container); border-color: transparent; color: var(--ops-error-ink); }
.ops-badge.is-creating,
.ops-badge.is-deleting { background: var(--warning-container); border-color: transparent; color: var(--ops-warning-ink); }
.ops-badge.is-live     { background: var(--ops-error-ink); border-color: transparent; color: var(--on-error); text-transform: uppercase; letter-spacing: var(--tracking-eyebrow); }
.ops-badge.is-protected { background: var(--inverse-surface); border-color: transparent; color: var(--inverse-on-surface); }
.ops-badge.is-test     { background: var(--surface); border: var(--border-width) dashed var(--on-surface-muted); color: var(--on-surface-variant); }

/* Health: a dot and a word, so it reads without colour too. */
.ops-health { display: inline-flex; align-items: center; gap: var(--gap-sm); font-weight: 500; color: var(--on-surface); }
.ops-health::before {
  content: "";
  flex: none;
  width: var(--ops-dot);
  height: var(--ops-dot);
  border-radius: var(--r-full);
  background: var(--on-surface-muted);
}
.ops-health.is-ok::before { background: var(--primary); box-shadow: 0 0 0 var(--gap-xs) var(--primary-container); }
.ops-health.is-down { color: var(--ops-error-ink); }
.ops-health.is-down::before { background: var(--error); box-shadow: 0 0 0 var(--gap-xs) var(--error-container); }
.ops-health.is-unknown, .ops-health.is-idle { color: var(--on-surface-variant); }
.ops-health-error { display: block; margin-top: var(--gap-xs); color: var(--ops-error-ink); overflow-wrap: anywhere; }

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

.ops-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body-sm);
  line-height: var(--line-body-sm);
  color: var(--on-surface);
}

.ops-table th {
  text-align: left;
  font-size: var(--text-label-sm);
  line-height: var(--line-label-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-eyebrow);
  text-transform: uppercase;
  color: var(--on-surface-variant);
  padding: 0 var(--gap-md) var(--gap-md);
  border-bottom: var(--border-width) solid var(--outline);
  white-space: nowrap; /* headers are short on purpose; a clipped column NAME cannot be recovered */
}

.ops-table td {
  padding: var(--gap-md);
  border-bottom: var(--border-width) solid var(--outline-variant);
  vertical-align: top;
  overflow-wrap: anywhere;
}
.ops-table th:first-child, .ops-table td:first-child { padding-left: 0; }
.ops-table th:last-child, .ops-table td:last-child { padding-right: 0; }
.ops-table tbody tr:last-child td { border-bottom: none; }
.ops-table tr.ops-row-note td { padding-top: 0; }
.ops-table tr:has(+ tr.ops-row-note) td { border-bottom: none; }

/* Phone: each row becomes a card, each cell a "label: value" line. */
@media (max-width: 719px) {
  .ops-section:has(> .ops-table) { overflow-x: visible; }
  .ops-table, .ops-table tbody, .ops-table tr, .ops-table td { display: block; width: 100%; }
  .ops-table thead {
    position: absolute;
    width: var(--border-width);
    height: var(--border-width);
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .ops-table tr {
    padding: var(--gap-md) 0;
    border-bottom: var(--border-width) solid var(--outline);
  }
  .ops-table tbody tr:last-child { border-bottom: none; padding-bottom: 0; }
  .ops-table tbody tr:first-child { padding-top: 0; }
  .ops-table tr:has(+ tr.ops-row-note) { border-bottom: none; padding-bottom: 0; }
  /* Block + an absolutely placed label, not a grid: a cell's content is often
     several inline children (a link and a badge, a label and its error), and
     a grid would make each one its own item and push some under the label. */
  .ops-table td,
  .ops-table td:first-child,
  .ops-table td:last-child {
    position: relative;
    padding: var(--gap-xs) 0 var(--gap-xs) calc(var(--ops-label-col) + var(--gap-md));
    border: none;
  }
  .ops-table td::before {
    content: attr(data-label);
    position: absolute;
    left: 0;
    top: var(--gap-xs);
    width: var(--ops-label-col);
    font-family: var(--font); /* a mono cell's label stays in the UI face */
    font-size: var(--text-label-sm);
    line-height: var(--line-body-sm);
    font-weight: 600;
    color: var(--on-surface-muted);
  }
}

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

.ops-form { display: flex; flex-direction: column; gap: var(--gap-lg); min-width: 0; }

.ops-field { display: flex; flex-direction: column; gap: var(--gap-xs); min-width: 0; }
.ops-field > label {
  font-size: var(--text-label-md);
  line-height: var(--line-label-md);
  font-weight: 500;
  color: var(--on-surface);
}

.ops-field input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.ops-field select,
.ops-field textarea {
  width: 100%;
  min-height: var(--input-height);
  padding: var(--gap-sm) var(--gap-md);
  font-family: var(--font);
  font-size: var(--text-body-md); /* 16px: below it iOS zooms the page on focus */
  line-height: var(--line-body-md);
  color: var(--on-surface);
  background: var(--surface);
  border: var(--border-width) solid var(--outline);
  border-radius: var(--r);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.ops-field input::placeholder { color: var(--on-surface-muted); }
.ops-field input:focus, .ops-field select:focus, .ops-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

/* A typed-name confirmation: the field is the last thing between a click and lost data. */
.ops-confirm input:not([type="hidden"]) { font-family: var(--font-mono); border-color: var(--on-surface-muted); }
.ops-confirm > label { font-weight: 500; }

.ops-inline-form { flex-direction: row; flex-wrap: wrap; align-items: flex-end; gap: var(--gap-sm); }
.ops-inline-form .ops-field { flex: 1 1 var(--dt-col-identity); }
.ops-inline-form .ops-field > label { font-size: var(--text-label-sm); line-height: var(--line-label-sm); color: var(--on-surface-variant); }

/* ---- buttons: on the classes, never the bare element (CLAUDE.md Gotchas) ---- */

.btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-sm);
  min-height: var(--control-height);
  padding: var(--gap-sm) var(--gap-xl);
  font-family: var(--font);
  font-size: var(--text-label-md);
  line-height: var(--line-label-md);
  font-weight: 500;
  border: var(--border-width) solid transparent;
  border-radius: var(--r-full);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: box-shadow var(--t-fast), background var(--t-fast), color var(--t-fast);
}
.btn-primary:hover, .btn-secondary:hover, .btn-danger:hover { text-decoration: none; }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { box-shadow: var(--elev-3); }

.btn-secondary { background: var(--surface); color: var(--on-surface); border-color: var(--outline); }
.btn-secondary:hover { background: var(--surface-container-high); }

.btn-danger { background: var(--ops-error-ink); color: var(--on-error); }
.btn-danger:hover { box-shadow: var(--elev-4); }

.btn-primary:disabled, .btn-secondary:disabled, .btn-danger:disabled { opacity: var(--disabled-opacity); cursor: not-allowed; box-shadow: none; }

/* ---- page parts ---- */

.ops-facts { display: flex; flex-direction: column; gap: var(--gap-sm); margin: 0; }
.ops-facts > div {
  display: grid;
  grid-template-columns: var(--dt-col-identity) minmax(0, 1fr);
  gap: var(--gap-md);
}
.ops-facts dt { font-size: var(--text-label-md); line-height: var(--line-body-md); font-weight: 500; color: var(--on-surface-variant); }
.ops-facts dd { margin: 0; color: var(--on-surface); min-width: 0; }
.ops-facts dd.ops-mono { line-height: var(--line-body-md); } /* level with its label, which is on the body line */

@media (max-width: 719px) {
  .ops-facts > div { grid-template-columns: minmax(0, 1fr); gap: 0; }
}

.ops-changelog { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.ops-changelog li {
  display: flex;
  align-items: baseline;
  gap: var(--gap-md);
  padding: var(--gap-sm) 0;
  border-bottom: var(--border-width) solid var(--outline-variant);
  color: var(--on-surface);
  overflow-wrap: anywhere;
  min-width: 0;
}
.ops-changelog li:last-child { border-bottom: none; }
.ops-sha {
  flex: none;
  padding: 0 var(--gap-sm);
  border-radius: var(--r-full);
  background: var(--surface-container-high);
  color: var(--on-surface-variant);
}

.ops-log summary { cursor: pointer; color: var(--primary); font-weight: 500; }
.ops-log pre {
  margin: var(--gap-sm) 0 0;
  padding: var(--gap-md);
  max-height: var(--admin-panel-height);
  overflow: auto;
  background: var(--surface-container);
  border: var(--border-width) solid var(--outline-variant);
  border-radius: var(--r);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ops-tiles {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--admin-card-min)), 1fr));
  gap: var(--gap-lg);
}
.ops-tile { display: flex; flex-direction: column; justify-content: space-between; gap: var(--gap-lg); }
.ops-tile .btn-primary { overflow-wrap: anywhere; }

.ops-pager { display: flex; align-items: center; justify-content: center; gap: var(--gap-lg); }
