/* The panel's base styles (step 0; B1 owns and refines them). Shared by every page: layout, nav,
   tables, forms, badges, banners and the one-column rules under 720 px (§5.10). No inline styles
   anywhere (CSP style-src 'self'): colours come from these classes. flows.css (B2) and
   monitor.css (B3) add their pages' own. */

:root {
  --bg: #f7f7f5;
  --fg: #1d1d1b;
  --dim: #6b6b66;
  --line: #d9d9d4;
  --card: #ffffff;
  --accent: #2458b3;
  --ok: #1f7a3a;
  --err: #b3261e;
  --warn-bg: #fff3cd;
  --warn-fg: #6b4e00;
  --staging: #f2a900;
  /* A carried lineage (D8): continued from a seed that failed its gate. 4.8:1 on --card. */
  --carry: #c05000;
  /* Text on a filled accent or danger button: at least 4.5:1 in both themes (§18.5) */
  --on-accent: #fff;
  --on-err: #fff;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --fg: #e8e8e3;
    --dim: #9a9a93;
    --line: #34342f;
    --card: #1f1f1d;
    --accent: #7aa7ff;
    --ok: #5cc27a;
    --err: #ff8a80;
    --warn-bg: #3d3210;
    --warn-fg: #ffd970;
    --carry: #ff9a3c;
    /* white on #7aa7ff is 2.4:1, on #ff8a80 2.3:1; the page's own dark is 7.6:1 and 7.9:1 */
    --on-accent: #161615;
    --on-err: #161615;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
code, pre, .mono { font-family: var(--mono); font-size: 0.92em; }
h1 { font-size: 1.4rem; margin: 0.6rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.4rem 0 0.6rem; }
.dim { color: var(--dim); }
.todo { color: var(--dim); font-style: italic; }

/* The instance band and banners */
.band { padding: 2px 16px; font-weight: 700; letter-spacing: 0.08em; font-size: 0.8rem; }
.band-staging { background: var(--staging); color: #1d1d1b; }
.band-development { background: var(--line); color: var(--fg); }
.banner { padding: 8px 16px; }
.banner.warn { background: var(--warn-bg); color: var(--warn-fg); }
.banner span + span::before { content: " · "; }

/* Header and navigation */
header.top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--card);
}
.brand { font-weight: 700; text-decoration: none; color: var(--fg); }
nav.bar { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
nav a { padding: 8px 10px; border-radius: 6px; text-decoration: none; color: var(--fg); min-height: 40px; display: inline-flex; align-items: center; }
nav a.active { background: var(--bg); color: var(--accent); font-weight: 600; }
details.menu { display: none; }
.who { display: flex; gap: 8px; align-items: center; margin-left: auto; }
form.inline { display: inline; }
button.link { background: none; border: 0; color: var(--accent); padding: 8px; min-height: 40px; cursor: pointer; font: inherit; }

main { padding: 12px 16px 48px; max-width: 1400px; margin: 0 auto; }
main.login { max-width: 420px; padding-top: 48px; }

/* Tables scroll inside their own box, never the page */
.table-box { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--dim); white-space: nowrap; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: 0 0 12px; }

/* Forms and actions */
label { display: block; margin: 0 0 10px; }
input, select, textarea, button {
  font: inherit; color: inherit; min-height: 40px; border-radius: 6px;
}
input, select, textarea { width: 100%; padding: 6px 8px; border: 1px solid var(--line); background: var(--bg); display: block; margin-top: 4px; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; display: inline; margin: 0 6px 0 0; }
button { padding: 6px 14px; border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); cursor: pointer; }
button.danger, form.danger button { border-color: var(--err); background: var(--err); color: var(--on-err); }
button.copy { min-height: 28px; padding: 2px 8px; margin-left: 6px; background: none; color: var(--accent); border-color: var(--line); font-size: 0.85em; }
form.action { display: inline-block; margin: 4px 8px 4px 0; vertical-align: top; }
form.action label { margin-bottom: 6px; }
/* An action's popup (ActionForm, §18.3): a native popover in the top layer, centred by the UA's
   [popover] rules, as wide as its sentence reads; its title, the confirm text, the typed name and
   the step-up code, Cancel and the real button. On a phone it sits near the top, above the
   on-screen keyboard the code field brings up. */
.popup { width: max-content; min-width: min(20em, calc(100vw - 32px)); max-width: min(34em, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg);
  box-shadow: 0 10px 32px rgb(0 0 0 / 0.3); }
.popup::backdrop { background: rgb(0 0 0 / 0.35); }
.popup h2 { margin: 0 0 8px; font-size: 1.1rem; }
.popup p { margin: 0 0 10px; }
.popup label.stepup input { max-width: 12em; }
.popup-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 4px; }
form .popup-buttons button.cancel { background: none; color: var(--accent); border-color: var(--line); }
.login-form button { width: 100%; }

/* InfoTip (§18.3): an ⓘ whose explanation shows on hover, keyboard focus and a tap (a tap focuses
   the button), by CSS alone. panel.js places it beside the icon inside the viewport; on a phone it
   is a sheet at the foot of the screen (the 720 px rules below). */
.infotip { display: inline-block; }
.infotip > button.info { min-width: 24px; min-height: 24px; padding: 0 3px; border: 0; background: none; color: var(--dim); font: inherit; line-height: 1; cursor: help; }
.infotip > .tip { display: none; position: fixed; z-index: 30; width: max-content; max-width: min(28rem, calc(100vw - 32px)); max-height: calc(100vh - 16px); overflow: auto;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--fg); box-shadow: 0 6px 20px rgb(0 0 0 / 0.25);
  font-size: 0.85rem; font-weight: normal; line-height: 1.4; text-align: left; white-space: pre-wrap; }
.infotip:hover > .tip, .infotip:focus-within > .tip { display: block; }
.status { margin: 6px 0; }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

/* Badges: k-<kind> s-<state> */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 0.82em; background: var(--line); color: var(--fg); }
.badge.s-running, .badge.s-approved, .badge.s-leased, .badge.s-active { background: #d8ecff; color: #0b3f7a; }
.badge.s-finished, .badge.s-committed, .badge.s-done, .badge.s-used { background: #dff3e4; color: #145a2a; }
.badge.s-failed, .badge.s-revoked, .badge.s-rejected, .badge.s-poison { background: #fbe0de; color: #7a1610; }
.badge.s-paused, .badge.s-pending, .badge.s-draft, .badge.s-waiting, .badge.s-in-line { background: var(--warn-bg); color: var(--warn-fg); }

/* RunnerText's escaped characters */
.esc { font-family: var(--mono); font-size: 0.85em; background: var(--warn-bg); color: var(--warn-fg); border-radius: 3px; padding: 0 2px; }

/* Polled regions (panel.js) */
.poll.stale { opacity: 0.6; }
.poll.paused::after { content: "updates paused while you edit"; display: block; color: var(--dim); font-size: 0.8em; }
time + .local { color: var(--dim); }
.copyid code { word-break: break-all; }

/* B1's pages: Home, Fleet, Admin, Account */
nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: -4px 0 12px; border-bottom: 1px solid var(--line); }
nav.tabs a { border-radius: 6px 6px 0 0; }
.statusline { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 0 0 8px; }
.since { margin: 0 0 8px; }
.alarm-count { color: var(--err); }
.digest-group h2 { margin-top: 1rem; }
ul.digest, ul.history { list-style: none; padding: 0; margin: 0; }
ul.digest li, ul.history li { padding: 6px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
ul.digest li time { color: var(--dim); margin-right: 8px; }
ul.digest li.alarm { border-left: 3px solid var(--err); padding-left: 8px; }
.online { color: var(--ok); font-size: 0.85em; margin-left: 6px; }
.offline { color: var(--err); font-size: 0.85em; margin-left: 6px; }
.applicant { overflow-wrap: anywhere; }
table.fleet td { min-width: 120px; }
table.fleet td:first-child { min-width: 140px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
dl.facts dt { color: var(--dim); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
.card.secret { border-color: var(--accent); border-width: 2px; }
.code-once code { font-size: 1.15em; font-weight: 600; }
ol.codes { columns: 2; font-size: 1.05em; }
.uri { overflow-wrap: anywhere; font-size: 0.8em; }
form.filters { display: flex; flex-wrap: wrap; gap: 0 12px; align-items: flex-end; margin-bottom: 12px; }
form.filters label { min-width: 160px; flex: 1; }
form.filters button { margin-bottom: 10px; }
fieldset.scopes { border: 1px solid var(--line); border-radius: 6px; margin: 0 0 10px; padding: 6px 10px; }
fieldset.scopes label { margin: 4px 0; }
.runner-actions p { margin: 0 0 8px; overflow-wrap: anywhere; }
.badge.s-open, .badge.s-ok { background: #dff3e4; color: #145a2a; }
/* dim on --line was 3.8:1 (light) and 4.4:1 (dark): outlined instead, dim on the page (§18.5) */
.badge.s-expired, .badge.s-retired { background: none; color: var(--dim); box-shadow: inset 0 0 0 1px var(--line); }
.badge.s-refused { background: var(--warn-bg); color: var(--warn-fg); }

/* §18.5: inputs in the popup, the action menu, one runner list, the add buttons */
.popup fieldset.scopes { margin-bottom: 10px; }
.table-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; margin: 1rem 0 6px; }
.table-head h2 { margin: 0; }
.table-head form.action { margin: 0; text-align: right; }
.table-head form.action .popup { text-align: left; }
.table-head form.action > .status { margin: 2px 0 0; }
nav.states { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 10px; }
nav.states a { padding: 6px 10px; border: 1px solid var(--line); border-radius: 16px; text-decoration: none; min-height: 36px; display: inline-flex; align-items: center; gap: 6px; }
nav.states a .n { color: var(--dim); }
nav.states a.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
nav.states a.active .n { color: inherit; }
table.fleet td.acts, table.fleet th.acts { min-width: 0; position: sticky; right: 0; background: var(--card); box-shadow: inset 1px 0 0 var(--line); }
table.fleet td.acts form.action { display: block; margin: 0 0 6px; }
table.fleet tbody.earlier td { padding-top: 4px; padding-bottom: 4px; }
tbody.live.stale { opacity: 0.6; }
.actmenu { display: inline-block; }
button.menu-button { background: var(--card); color: var(--accent); border-color: var(--line); white-space: nowrap; }
.action-menu { min-width: 10em; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg); box-shadow: 0 6px 20px rgb(0 0 0 / 0.25); }
.action-menu form.action { display: block; margin: 0; }
.action-menu form.action > .status { margin: 2px 8px; }
.action-menu button.item { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--fg); border-radius: 4px; }
.action-menu button.item.danger { color: var(--err); }
.action-menu button.item:hover, .action-menu button.item:focus-visible { background: var(--bg); }
.action-menu:has(.popup:popover-open) { visibility: hidden; }
.action-menu .popup { visibility: visible; }

/* Phones: one column (§5.10) */
@media (max-width: 720px) {
  nav.bar { display: none; }
  details.menu { display: block; }
  details.menu > summary { padding: 8px 12px; min-height: 40px; cursor: pointer; list-style: none; border: 1px solid var(--line); border-radius: 6px; }
  details.menu nav { display: flex; flex-direction: column; padding: 6px 0; }
  header.top { gap: 8px; }
  .who { margin-left: 0; }
  main { padding: 10px 12px 40px; }
  form.action { display: block; }
  .popup { margin-top: 8vh; }
  .infotip > .tip { top: auto; right: 16px; bottom: 16px; left: 16px; width: auto; max-width: none; max-height: 50vh; }
  dl.facts { grid-template-columns: 1fr; }
  dl.facts dt { margin-top: 6px; }
  ol.codes { columns: 1; }
}
