/* Console chassis — shared by the CUSTOMER console at /company and the INTERNAL
   operator portal at /admin.
   ─────────────────────────────────────────────────────────────────────────────
   ADR-0028. These two pages were a fork: 92 CSS lines byte-identical, and the
   shared half was the chassis below. Phase 22 proved the fork does not work —
   Gates 1-3 fixed one file and the other received none of it, in a single phase,
   by one author, with the duplication known and written down at the time.

   THIS FILE CONTAINS NO LITERAL COLOUR. Every colour is a var(--token) that the
   consuming page must define in its own :root. That is the palette contract, and
   it is enforced by console-a11y.test.ts:

     * completeness  — every token read here is defined in both portals;
     * distinctness  — the identity tokens DIFFER between them, so the two can
                       never converge by accident. ADR-0018 §9 requires that a
                       customer never confuse the two, and a test is a stronger
                       guarantee than two people maintaining two files.

   Layout metrics are tokens too (--nav-width, --main-max, --stat-min,
   --dialog-max). They are not palette, but the two portals had drifted on them
   for no recorded reason and the operator portal genuinely wants wider tables;
   a token keeps one stylesheet without forcing one number.

   Cached at /assets/*, unlike the pages themselves which are no-store. Every
   reference to this file MUST be version-stamped, or new HTML renders against
   stale CSS. */

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

/* Author display rules beat the browser's [hidden] rule, so a flex or grid
   element stays visible after hidden=true. Every toggle on these pages relies
   on that attribute, so make it authoritative. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--ink);
}
a { color: var(--info); }
h2 { font-size: 18px; margin: 0 0 4px; }
h3 { font-size: 14px; margin: 24px 0 10px; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }

/* ── Focus ─────────────────────────────────────────────────────────────────
   One rule, every focusable thing (BACK-222). `:focus-visible` rather than
   `:focus` so a mouse click draws nothing and nobody reaches for `outline-none`
   to suppress it; `outline-offset: 2px` rather than inset, because an inset
   outline is clipped by the 8px corner radius on exactly the controls that
   matter. Matches app/globals.css:87 in the desktop app, deliberately. */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── Reduced motion ────────────────────────────────────────────────────────
   Both portals animate every toast — the one element that appears without
   being asked for. Mirrors app/globals.css:104. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Sign-in ─────────────────────────────────────────────────────────────── */
#signin { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
#signin-card {
  background: var(--card);
  border-radius: 14px;
  padding: 36px;
  width: 420px;
  max-width: 100%;
  box-shadow: var(--shadow-card);
}
#signin-card h1 { margin: 0 0 6px; font-size: 21px; }
#signin-card p { margin: 0 0 18px; font-size: 13px; color: var(--muted); line-height: 1.55; }

/* The identity bar at the top of the card. A gradient on one portal, a flat
   operator colour on the other — which is the fastest way to tell them apart. */
.mark { height: 6px; border-radius: 3px; background: var(--mark); margin-bottom: 22px; }

/* Federated sign-in. Buttons are full width and stacked so the providers read
   as equal choices rather than a primary and a fallback. */
.provider-buttons { display: flex; flex-direction: column; gap: 8px; }
.provider-buttons button { width: 100%; justify-content: center; font-weight: 600; }
.signin-divider { display: flex; align-items: center; gap: 10px; margin: 16px 0; font-size: 12px; color: var(--muted); }
.signin-divider::before, .signin-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.stacked-link { margin-top: 16px; }
.spaced { margin-top: 18px; }

/* ── Controls ────────────────────────────────────────────────────────────── */
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { border-color: var(--focus-ring); }

button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid transparent; padding: 9px 16px; }
.btn-primary { background: var(--accent); color: var(--accent-on); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .55; cursor: default; }
.btn-sec { background: var(--card); color: var(--ink); border-color: var(--control-line); }
.btn-sec:hover { background: var(--surface-raised); }
.btn-danger { background: var(--card); color: var(--bad); border-color: var(--control-line-danger); }
.btn-danger:hover { background: var(--bad-bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Shell ───────────────────────────────────────────────────────────────── */
#app { display: none; min-height: 100vh; }

header {
  background: var(--header-bg);
  color: var(--header-fg);
  border-bottom: 1px solid var(--header-line);
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 58px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--logo); flex: none; }
header .title { font-weight: 650; font-size: 15px; margin: 0; }
header .company { color: var(--header-muted); font-size: 13px; }
header .spacer { flex: 1; }
/* Deliberately quiet — these are working tools, not tutorials — but present on
   every page, because the seat model and the role separations are the two
   things nobody guesses correctly. */
header a.help-link { font-size: 12.5px; color: var(--header-muted); text-decoration: none; white-space: nowrap; }
header a.help-link:hover { color: var(--header-fg); text-decoration: underline; }
.whoami { text-align: right; font-size: 12px; color: var(--header-muted); line-height: 1.4; }
.whoami strong { display: block; color: var(--header-fg); font-size: 13px; }
header .btn-sec { background: var(--header-btn-bg); color: var(--header-btn-fg); border-color: var(--header-btn-line); }
header .btn-sec:hover { background: var(--header-btn-hover); }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 30;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 0 0 8px 0;
  font-size: 13px;
}
.skip-link:focus { left: 0; }

.layout { display: grid; grid-template-columns: var(--nav-width) 1fr; align-items: start; }
nav { padding: 18px 12px; position: sticky; top: 58px; }
nav button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--ink-soft);
  font-size: 13.5px;
  margin-bottom: 2px;
}
nav button:hover:not(.active) { background: var(--nav-hover); }
nav button.active { background: var(--card); color: var(--accent-ink); font-weight: 600; box-shadow: var(--shadow-nav-active); }
nav button:disabled { opacity: .4; cursor: default; }
.nav-note { margin: 10px 12px 0; font-size: 12px; color: var(--muted); line-height: 1.45; }

/* max-width with no auto margin left the content pinned to the left edge next
   to the rail on a wide monitor. */
main { padding: 24px 28px 64px; max-width: var(--main-max); margin: 0 auto; width: 100%; min-width: 0; }
.page { display: none; }
.page.active { display: block; }

/* ── Cards, stats, tables ────────────────────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--stat-min), 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat .value { font-size: 25px; font-weight: 640; letter-spacing: -.01em; }
.stat.good .value { color: var(--ok); }
.stat.warn .value { color: var(--warn); }
.stat.bad .value { color: var(--bad); }

/* Tables scroll inside this wrapper rather than by becoming blocks themselves:
   `display: block` on a table drops the implicit table role in WebKit/Blink,
   so the mobile view loses row and column semantics (BACK-225). */
.table-wrap { overflow-x: auto; border-radius: 12px; }
table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
thead th {
  background: var(--surface-sunk);
  padding: 10px 14px;
  text-align: left;
  font-size: 11.5px;
  font-weight: 650;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--line);
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-hover); }
td.actions { text-align: right; white-space: nowrap; }
td.actions button { margin-left: 4px; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.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;
}

/* ── Badges and chips ────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 650; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.grey { background: var(--badge-grey-bg); color: var(--badge-grey-fg); }
.chip { display: inline-block; padding: 2px 8px; border-radius: 6px; background: var(--chip-bg); font-size: 11.5px; margin: 2px 3px 2px 0; }

/* ── Notices ─────────────────────────────────────────────────────────────── */
.notice { border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; font-size: 13px; line-height: 1.55; border: 1px solid; }
.notice.warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-ink); }
.notice.bad { background: var(--bad-bg); border-color: var(--bad-border); color: var(--bad-ink); }
.notice.info { background: var(--info-bg); border-color: var(--info-border); color: var(--info-ink); }
.notice ul { margin: 6px 0 0; padding-left: 18px; }

/* ── Toolbar and fields ──────────────────────────────────────────────────── */
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 190px; }
.toolbar .spacer { flex: 1; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* ── Dialog ──────────────────────────────────────────────────────────────── */
dialog {
  border: none;
  border-radius: 14px;
  padding: 0;
  max-width: var(--dialog-max);
  width: calc(100% - 32px);
  box-shadow: var(--shadow-dialog);
}
dialog::backdrop { background: var(--backdrop); }
.dlg-head { padding: 18px 20px 0; }
.dlg-head h3 { margin: 0 0 4px; font-size: 16px; }
.dlg-body { padding: 14px 20px; max-height: 62vh; overflow: auto; }
/* Outside .dlg-body on purpose: the body scrolls, and an error that scrolls out
   of view is the problem this element exists to solve (BACK-213). */
.dlg-msg { padding: 0 20px; }
.dlg-msg .notice { margin-bottom: 0; margin-top: 4px; }
.dlg-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--surface-hover);
  border-radius: 0 0 14px 14px;
}
.linkbox { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.linkbox input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }

/* ── Toasts ──────────────────────────────────────────────────────────────── */
#toasts { position: fixed; top: 14px; right: 14px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 11px 15px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  /* A fixed 380px plus gutters needs 408px, which overflows a 400px screen. */
  max-width: min(380px, calc(100vw - 28px));
  color: var(--accent-on);
  box-shadow: var(--shadow-toast);
  animation: slide .18s ease;
}
.toast.ok { background: var(--ok); }
.toast.bad { background: var(--bad); }
.toast.info { background: var(--accent); }
@keyframes slide { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }

/* ── Empty and loading ───────────────────────────────────────────────────── */
.empty { text-align: center; padding: 34px 16px; color: var(--muted); font-size: 13px; }
.spinner { text-align: center; padding: 40px; color: var(--muted); }

/* ── Expandable raw records (audit log) ──────────────────────────────────── */
details.raw { margin-top: 6px; }
details.raw summary { cursor: pointer; font-size: 12px; color: var(--muted); }
details.raw summary:hover { color: var(--info); }
details.raw pre {
  margin: 6px 0 0;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 11.5px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ── Breakpoints ─────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  nav {
    position: static;
    display: flex;
    overflow-x: auto;
    gap: 4px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--card);
  }
  nav button { width: auto; white-space: nowrap; }
  .nav-note { display: none; }
  main { padding: 18px 16px 48px; }
}

@media (max-width: 640px) {
  /* .row never stacked at any width, so two fields sat side by side at ~176px
     each on a phone — including inside dialogs. */
  .row { flex-direction: column; gap: 10px; }
  header { padding: 8px 16px; gap: 10px; }
  header .whoami { text-align: left; }
  .toolbar input, .toolbar select { min-width: 0; width: 100%; }
  .toolbar .spacer { display: none; }
  #signin { padding: 16px; }
  #signin-card { padding: 24px; }
}
