/* ---------------------------------------------------------------------------
   Shared styling for the login flow and dashboard.
   Light/dark aware via prefers-color-scheme; no external assets or fonts.
   --------------------------------------------------------------------------- */

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-alt: #f0f3f8;
  --border: #dde3ed;
  --text: #16202e;
  --text-muted: #5d6b80;
  --accent: #1f5fb5;
  --accent-hover: #17498c;
  --success: #17794a;
  --success-bg: #e6f6ee;
  --warning: #8a5a06;
  --warning-bg: #fdf3e0;
  --danger: #b0243a;
  --danger-bg: #fdeaed;
  --radius: 10px;
  /* Used by nested surfaces — cards inside cards, list rows, tiles. It was referenced
     in several rules but never defined, so every one of them fell back to square
     corners. */
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 26, 40, 0.06), 0 8px 24px rgba(16, 26, 40, 0.08);
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151d;
    --surface: #182029;
    --surface-alt: #1f2833;
    --border: #2c3846;
    --text: #e6ecf3;
    --text-muted: #9aa8b9;
    --accent: #5b9cf0;
    --accent-hover: #7cb0f5;
    --success: #58d29a;
    --success-bg: #132a20;
    --warning: #e0b062;
    --warning-bg: #2c2416;
    --danger: #f28b9b;
    --danger-bg: #2e1a1e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

.page { max-width: 1040px; margin: 0 auto; padding: 28px 20px 64px; }

/* --- Header --------------------------------------------------------------- */

.masthead {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 18px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.masthead h1 { font-size: 1.3rem; margin: 0; letter-spacing: -0.01em; }
.masthead .sub { color: var(--text-muted); font-size: 0.85rem; margin-top: 2px; }

/* --- Cards ---------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}
.card h2 { font-size: 1.02rem; margin: 0 0 4px; }
.card .hint { color: var(--text-muted); font-size: 0.86rem; margin: 0 0 16px; }
.card[hidden] { display: none; }

/* --- Stepper -------------------------------------------------------------- */

.stepper { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.step {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.82rem;
}
.step .dot {
  width: 20px; height: 20px; flex: 0 0 20px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 0.72rem; font-weight: 600;
}
.step.active { border-color: var(--accent); color: var(--accent); }
.step.active .dot { background: var(--accent); color: #fff; }
.step.done { border-color: var(--success); color: var(--success); }
.step.done .dot { background: var(--success); color: #fff; }

/* --- Forms ---------------------------------------------------------------- */

label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }

/*
  Matched by exclusion rather than by listing types. The old rule named text, password
  and url, which silently left every `type="email"` box at the browser's default width —
  so the email field sat half-size next to a full-width mobile field on the same row, in
  the add-user, edit-user and profile forms alike. Opting out the few types that must
  not stretch is the version that stays correct when a new input type appears.
*/
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="submit"]):not([type="button"]),
select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}
input:disabled { opacity: 0.6; cursor: not-allowed; }

.code-input {
  font-family: var(--mono);
  font-size: 1.25rem;
  letter-spacing: 0.32em;
  text-align: center;
}

.field-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.field-row > div { flex: 1 1 200px; }

/* --- Buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem; font-weight: 600; font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.btn:hover:not(:disabled) { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
.btn.secondary:hover:not(:disabled) { background: var(--border); }
.btn.danger { background: var(--danger); }
.btn.danger:hover:not(:disabled) { filter: brightness(1.08); }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* --- Status banners ------------------------------------------------------- */

.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 0.88rem;
  margin-bottom: 16px;
}
.banner[hidden] { display: none; }
.banner.info { background: var(--surface-alt); border-color: var(--border); color: var(--text-muted); }
.banner.success { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.banner.warning { background: var(--warning-bg); border-color: var(--warning); color: var(--warning); }
.banner.error { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }

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

/*
 * The portal's reports have an open-ended column count, so the table scrolls inside its
 * own box. Without this the page itself scrolls sideways and the sidebar drifts off.
 */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  white-space: nowrap;
}
.data-table[hidden] { display: none; }

.data-table th,
.data-table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.data-table tbody tr:hover { background: var(--surface-alt); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* --- Loading -------------------------------------------------------------- */

.spinner {
  width: 15px; height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* --- CAPTCHA -------------------------------------------------------------- */

.captcha-box {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  padding: 14px;
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
}
/*
 * The portal serves a small, noisy JPEG (~130x40). It is upscaled here so it can be
 * read accurately first time — a misread costs a full login attempt, and the portal
 * locks the account after a few failures.
 */
.captcha-box img {
  width: 270px;
  max-width: 100%;
  height: auto;
  background: #fff;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  image-rendering: pixelated;
  cursor: zoom-in;
  transition: width 0.15s ease;
}
.captcha-box img.zoomed { width: 420px; cursor: zoom-out; }

/* --- Session detail grid -------------------------------------------------- */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.detail {
  background: var(--surface);
  padding: 14px 16px;
}
.detail dt {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.detail dd {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  word-break: break-word;
}
.detail dd.mono { font-family: var(--mono); font-weight: 500; font-size: 0.82rem; }

/* --- Login history -------------------------------------------------------- */

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.history-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  font-size: 0.88rem;
}
.history-list li + li { border-top: 1px solid var(--border); }
.history-list .mono { font-family: var(--mono); font-size: 0.82rem; }
.history-list .hist-user { color: var(--text-muted); font-weight: 500; }

/* --- Status pill ---------------------------------------------------------- */

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem; font-weight: 600;
}
.pill.ok { background: var(--success-bg); color: var(--success); }
.pill.bad { background: var(--danger-bg); color: var(--danger); }

/* --- Portal stat cards ---------------------------------------------------- */

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

.stat {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 18px 18px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  border-left: 5px solid var(--stat-accent, var(--accent));
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Bootstrap context colours from the portal, remapped to this palette. */
.stat[data-colour="success"] { --stat-accent: #1f9d5c; }
.stat[data-colour="info"]    { --stat-accent: #2a8fbd; }
.stat[data-colour="danger"]  { --stat-accent: #cf3049; }
.stat[data-colour="warning"] { --stat-accent: #d59412; }
.stat[data-colour="gray"]    { --stat-accent: #6b7889; }
.stat[data-colour="purple"]  { --stat-accent: #7a52c9; }
.stat[data-colour="orange"]  { --stat-accent: #c2691a; }
.stat[data-colour="teal"]    { --stat-accent: #12857f; }

.stat .stat-icon {
  position: absolute;
  right: 12px;
  bottom: 8px;
  font-size: 2.6rem;
  line-height: 1;
  opacity: 0.13;
  pointer-events: none;
}

.stat .stat-value {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--stat-accent);
  word-break: break-word;
}
.stat .stat-value .unit { font-size: 0.92rem; font-weight: 600; opacity: 0.85; }

.stat .stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

.stat .stat-link {
  margin-top: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--stat-accent);
  text-decoration: none;
}
.stat .stat-link:hover { text-decoration: underline; }

/* --- Portal notices ------------------------------------------------------- */

.notice-list { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; }
.notice {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-alt);
  border-left: 3px solid var(--notice-accent, var(--border));
  font-size: 0.84rem;
  line-height: 1.5;
}
.notice[data-colour="green"] { --notice-accent: #1f9d5c; }
.notice[data-colour="red"]   { --notice-accent: #cf3049; }
.notice[data-colour="blue"]  { --notice-accent: #2a8fbd; }
.notice a { color: var(--accent); }

/* --- Account strip -------------------------------------------------------- */

.account-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  padding: 12px 16px;
  margin-bottom: 18px;
  border-radius: var(--radius);
  background: var(--surface-alt);
  border: 1px solid var(--border);
}
.account-strip .who { font-weight: 700; font-size: 1rem; }
.account-strip .uid { font-family: var(--mono); font-size: 0.84rem; color: var(--text-muted); }
.account-strip .role {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

/* --- Output panel --------------------------------------------------------- */

.output {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.output[hidden] { display: none; }
.output header {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 9px 14px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  font-size: 0.83rem; font-weight: 600;
}
.output pre {
  margin: 0;
  padding: 14px;
  max-height: 420px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.55;
  white-space: pre;
  background: var(--surface);
}

/* Wide content scrolls inside its own container, never the page. */
.scroll-x { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; font-size: 0.82rem; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
td.mono { font-family: var(--mono); font-size: 0.76rem; word-break: break-all; }

/* --- Browser preview ------------------------------------------------------ */

details.preview { margin-top: 16px; }
details.preview summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 0;
}
details.preview img {
  width: 100%;
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.footnote { color: var(--text-muted); font-size: 0.79rem; margin-top: 22px; }
.footnote code { font-family: var(--mono); font-size: 0.95em; }

/* ---------------------------------------------------------------------------
   Sidebar shell (dashboard only — the login page keeps the plain centred page)
   --------------------------------------------------------------------------- */

:root { --sidebar-w: 248px; --topbar-h: 52px; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 30;
}

/* The sidebar is fixed, so the content column is inset rather than floated beside it. */
body.has-sidebar .page { margin-left: var(--sidebar-w); max-width: 1040px; }

/* --- Brand ---------------------------------------------------------------- */

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark {
  flex: 0 0 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem; font-weight: 800; letter-spacing: 0.04em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 0.92rem; }
.brand-text small { color: var(--text-muted); font-size: 0.72rem; }

/* --- Logged-in PSA ID card ------------------------------------------------ */

.side-id {
  display: flex; flex-direction: column; gap: 3px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-alt);
}
.side-id-label {
  font-size: 0.67rem; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-muted);
}
.side-id-value { font-size: 0.85rem; font-weight: 600; word-break: break-all; }
.side-id-state { font-size: 0.72rem; color: var(--text-muted); }
.side-id-state.ok  { color: var(--success); }
.side-id-state.bad { color: var(--danger); }

/* --- Nav ------------------------------------------------------------------ */

.side-nav { display: flex; flex-direction: column; gap: 3px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface-alt); }
.nav-item.is-active { background: var(--accent); color: #fff; font-weight: 600; }
.nav-item.is-active .nav-icon { filter: grayscale(1) brightness(3); }
.nav-item.danger { color: var(--danger); margin-top: 6px; }
.nav-item.danger:hover { background: var(--danger-bg); }
.nav-item:disabled { opacity: 0.55; cursor: default; }
.nav-icon { flex: 0 0 18px; font-size: 0.95rem; text-align: center; }

/*
 * Menu names stay on one line.
 *
 * The label sits in a flex row beside the icon and, on two items, a status badge. A flex
 * child may shrink below its content width, so "UTI Login Manage" next to an "action
 * needed" badge was being squeezed narrow enough to wrap onto three lines — which made
 * that one item three times the height of its neighbours and broke the rhythm of the list.
 *
 * The label refuses to wrap and refuses to shrink; the badge yields instead, since a
 * clipped badge still reads while a wrapped menu name looks broken.
 */
.nav-label {
  flex: 0 1 auto;
  white-space: nowrap;
}

.nav-item { overflow: hidden; }

/* --- Footer --------------------------------------------------------------- */

.side-foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--border); }
.side-keepalive { font-size: 0.71rem; color: var(--text-muted); line-height: 1.4; display: block; }

/* --- View switching ------------------------------------------------------- */

.view[hidden] { display: none; }

/* --- Mobile top bar ------------------------------------------------------- */

.topbar { display: none; }
.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 11px;
  font-size: 1rem;
  cursor: pointer;
}

@media (max-width: 900px) {
  .topbar {
    position: fixed; inset: 0 0 auto 0; height: var(--topbar-h);
    display: flex; align-items: center; gap: 12px;
    padding: 0 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 40;
  }
  .topbar-title { font-weight: 700; font-size: 0.92rem; margin-right: auto; }

  /* Off-canvas: slide in over the content instead of squeezing it. */
  .sidebar { transform: translateX(-100%); transition: transform 0.18s ease; box-shadow: var(--shadow); }
  .sidebar.is-open { transform: translateX(0); }

  body.has-sidebar .page { margin-left: 0; padding-top: calc(var(--topbar-h) + 20px); }

  .scrim { position: fixed; inset: 0; background: rgba(8, 12, 18, 0.45); z-index: 25; }
  .scrim[hidden] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* ========================================================================== */
/* Console sign-in page                                                       */
/* ========================================================================== */

.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 24px; }

.auth-shell { width: 100%; max-width: 420px; }

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  justify-content: center;
}
.auth-brand strong { display: block; font-size: 1.05rem; letter-spacing: -0.01em; }
.auth-brand small { display: block; font-size: 0.76rem; color: var(--text-muted); }

.auth-card h1 { font-size: 1.3rem; margin-bottom: 6px; }
.auth-card { padding: 26px 24px; }
.auth-foot { text-align: center; margin-top: 16px; }

/* ========================================================================== */
/* Sidebar additions                                                          */
/* ========================================================================== */

.nav-heading {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 14px 10px 4px;
  font-weight: 600;
}

/* Views with nothing to show until the portal session exists. Dimmed rather than
   disabled: they still open, and the empty state explains why. */
.nav-item.is-muted .nav-label { opacity: 0.55; }

.nav-badge {
  margin-left: auto;
  /* Shrinks before the label does, and clips rather than pushing the name around. */
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.62rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--warning-bg);
  color: var(--warning);
  white-space: nowrap;
}
.nav-badge[hidden] { display: none; }

.nav-item.is-active .nav-badge { background: rgba(255, 255, 255, 0.22); color: #fff; }

.side-user {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  word-break: break-all;
}

/* ========================================================================== */
/* Console user list                                                          */
/* ========================================================================== */

.user-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }

.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}

.user-name { font-weight: 600; font-size: 0.86rem; }
.user-meta { font-size: 0.73rem; color: var(--text-muted); }
.user-actions { margin-left: auto; display: flex; gap: 8px; }
.user-actions .btn { padding: 5px 11px; font-size: 0.76rem; }
.user-contact { font-size: 0.75rem; color: var(--text-muted); font-family: var(--mono, monospace); }

/* ========================================================================== */
/* Sidebar balance readout                                                    */
/* ========================================================================== */

.side-balance {
  margin: 10px 8px 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-balance-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
}

.side-balance-value {
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.side-balance-time { font-size: 0.66rem; color: var(--text-muted); }

.side-refresh {
  margin-left: auto;
  border: 0;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.82rem;
  line-height: 1;
  padding: 2px;
  border-radius: 4px;
}
.side-refresh:hover { color: var(--accent); background: var(--border); }

/* Spun only while a refresh is in flight, so the icon doubles as the progress cue. */
.side-refresh.is-spinning { animation: side-refresh-spin 0.8s linear infinite; }

@keyframes side-refresh-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .side-refresh.is-spinning { animation: none; opacity: 0.5; }
}


/* ========================================================================== */
/* Home: status hero                                                          */
/* ========================================================================== */

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  padding: 22px 24px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--text-muted);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-main { display: flex; align-items: center; gap: 16px; min-width: 0; }

.hero-title { font-size: 1.12rem; font-weight: 650; letter-spacing: -0.01em; }
.hero-sub { font-size: 0.84rem; color: var(--text-muted); margin-top: 3px; }

/* The dot carries the state at a glance, before any text is read. */
.hero-dot {
  flex: 0 0 12px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
}

.hero[data-state='on']    { border-left-color: var(--success); }
.hero[data-state='stale'] { border-left-color: var(--warning); }
.hero[data-state='off']   { border-left-color: var(--danger); }

.hero[data-state='on'] .hero-dot    { background: var(--success); }
.hero[data-state='stale'] .hero-dot { background: var(--warning); }
.hero[data-state='off'] .hero-dot   { background: var(--danger); }

/* A live connection is the only state worth animating; a pulsing red dot on a broken
   one just adds urgency to something the operator already cannot miss. */
.hero[data-state='on'] .hero-dot {
  box-shadow: 0 0 0 0 var(--success-bg);
  animation: hero-pulse 2.4s ease-out infinite;
}

@keyframes hero-pulse {
  70%  { box-shadow: 0 0 0 9px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.hero-actions .btn[hidden] { display: none; }

/* ========================================================================== */
/* Home: fact row                                                             */
/* ========================================================================== */

.fact-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.fact-row[hidden] { display: none; }

.fact {
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.fact-label {
  display: block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.fact-value { font-size: 0.92rem; font-weight: 600; }

/* ========================================================================== */
/* Home: task tiles                                                           */
/* ========================================================================== */

.task-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.task {
  display: block;
  text-align: left;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  cursor: pointer;
  transition: border-color 0.14s ease, transform 0.14s ease, box-shadow 0.14s ease;
}

.task:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

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

.task-icon { display: block; font-size: 1.25rem; margin-bottom: 8px; }
.task-name { display: block; font-weight: 650; font-size: 0.9rem; margin-bottom: 4px; }
.task-desc { display: block; font-size: 0.77rem; color: var(--text-muted); line-height: 1.45; }

/* ========================================================================== */
/* Home: technical details                                                    */
/* ========================================================================== */

.tech {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 18px;
}

.tech > summary {
  cursor: pointer;
  padding: 15px 20px;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  border-radius: var(--radius);
}
.tech > summary::-webkit-details-marker { display: none; }
.tech > summary:hover { background: var(--surface-alt); }
.tech > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* A rotating caret, drawn rather than typed so it does not depend on a glyph. */
.tech > summary::before {
  content: '';
  width: 0;
  height: 0;
  border-left: 5px solid var(--text-muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
  align-self: center;
}
.tech[open] > summary::before { transform: rotate(90deg); }

.tech-title { font-weight: 650; font-size: 0.92rem; }
.tech-hint { font-size: 0.76rem; color: var(--text-muted); }

.tech-body { padding: 4px 20px 20px; border-top: 1px solid var(--border); }
.tech-body h3 { font-size: 0.88rem; font-weight: 650; margin-top: 18px; }

@media (prefers-reduced-motion: reduce) {
  .hero[data-state='on'] .hero-dot { animation: none; }
  .task, .tech > summary::before { transition: none; }
  .task:hover { transform: none; }
}


/* ========================================================================== */
/* Dark sidebar                                                               */
/* ========================================================================== */

/*
  The sidebar redefines the palette variables on itself rather than overriding each
  child rule. Every descendant already resolves --surface / --text / --border, so they
  all follow automatically, and a rule added to the sidebar later inherits the dark
  treatment for free instead of quietly rendering light-on-light.

  The values sit between the dark theme's page background (#10151d) and its card surface
  (#182029). That gap is what keeps the panel legible when the whole UI is dark: matching
  either one would let the sidebar merge into the page or into the cards beside it.
*/
.sidebar {
  --surface: #151c26;
  --surface-alt: #1e2733;
  --border: #2b3543;
  --text: #e8eef6;
  --text-muted: #94a3b6;

  /* Accents lifted for contrast: the light theme's #1f5fb5 accent and #b0243a danger
     are tuned for white behind them and fail WCAG AA on this background. */
  --accent: #4f93ea;
  --accent-hover: #6ba5ef;
  --success: #5ad39c;
  --danger: #f2879a;
  --danger-bg: #33191f;
  --warning: #e3b268;
  --warning-bg: #33291a;

  background: var(--surface);
  border-right-color: #0d131b;
  color: var(--text);
}

/* The divider above the footer would otherwise use the light border it inherited. */
.sidebar .side-foot { border-top-color: var(--border); }

/*
  Hover needs to read as *lighter* here, not darker. --surface-alt sits above --surface
  on this panel, which is the opposite of the light theme where it sits below.
*/
.sidebar .nav-item:hover { background: var(--surface-alt); }

/* Keep the brand tile readable: it is white-on-accent, and the accent moved. */
.sidebar .brand-mark { background: var(--accent); color: #0e141c; }

/*
  The active item is a solid accent block. Its icon is an emoji, so it cannot be
  recoloured — the existing brightness filter washes it to near-white, which works on
  the accent fill in both themes.
*/
.sidebar .nav-item.is-active { background: var(--accent); color: #0e141c; font-weight: 650; }
.sidebar .nav-item.is-active .nav-icon { filter: grayscale(1) brightness(0.25); }
.sidebar .nav-item.is-active .nav-badge { background: rgba(0, 0, 0, 0.22); color: #0e141c; }

/* Sign out stays red but must not vibrate against the dark panel. */
.sidebar .nav-item.danger { color: var(--danger); }
.sidebar .nav-item.danger:hover { background: var(--danger-bg); }

@media (prefers-color-scheme: dark) {
  /* Against an already-dark page, lean on the border rather than a colour step to
     separate the panel — the two backgrounds are close enough to blur otherwise. */
  .sidebar { border-right-color: #000; }
}


/* Inline role switcher in the console account list. Sized down from the global input
   rule, which is built for full-width form fields and would dominate the row. */
.role-select {
  width: auto;
  min-width: 92px;
  padding: 4px 8px;
  font-size: 0.78rem;
  font-weight: 600;
}
.role-select:disabled { opacity: 0.6; }


/* ========================================================================== */
/* The `hidden` attribute must always win                                     */
/* ========================================================================== */

/*
  The user-agent rule for [hidden] is `display: none`, but any author rule that sets an
  explicit `display` beats it — so `.nav-item { display: flex }` left elements on screen
  after `element.hidden = true`, which is how admin-only menu items stayed visible for
  ordinary users despite the attribute being set correctly.

  Several components had already grown their own `.thing[hidden] { display: none }`
  patch. This replaces that whack-a-mole with one rule. `!important` is deliberate: the
  whole point is to outrank component display rules regardless of source order, and an
  element carrying `hidden` has no business being rendered whatever else is asked for.
*/
[hidden] { display: none !important; }


/* Inline account editor, revealed under the user list by a row's Edit button. */
.user-editor {
  margin-top: 16px;
  padding: 18px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}
.user-editor h3 { font-size: 0.9rem; font-weight: 650; margin: 0 0 14px; }


/* Heading row with an action pinned to the right, used by the session details panel. */
.tech-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.tech-head .btn { padding: 6px 13px; font-size: 0.79rem; flex: 0 0 auto; }
.tech-head .hint { margin-bottom: 12px; }

/*
  The output panel header gained a second button. `space-between` alone would strand
  Copy in the middle of the bar; pushing the title's right margin out keeps the buttons
  grouped together on the right where they belong.
*/
.output header > :first-child { margin-right: auto; }


/* ========================================================================== */
/* API access                                                                 */
/* ========================================================================== */

/*
  The one-time key reveal. Deliberately loud: this is the only moment the key exists
  outside the hash, and a panel that looked like every other row would get scrolled past.
*/
.key-reveal {
  margin-top: 16px;
  padding: 18px;
  border: 2px solid var(--warning);
  border-radius: var(--radius-sm);
  background: var(--warning-bg);
}
.key-reveal h3 { font-size: 0.92rem; font-weight: 700; margin: 0 0 6px; color: var(--warning); }

.key-box {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.key-box code {
  flex: 1 1 320px;
  font-size: 0.86rem;
  word-break: break-all;
  user-select: all;   /* one click selects the whole key */
}

/* Audit table. Scrolls inside its own container so the page never scrolls sideways. */
.log-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; min-width: 720px; }
.log-table th {
  text-align: left;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.log-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.log-table tr:last-child td { border-bottom: 0; }
.log-table .pill { padding: 1px 8px; font-size: 0.68rem; }


/* ========================================================================== */
/* Company branding                                                           */
/* ========================================================================== */

/* Constrained rather than sized: uploads arrive at any aspect ratio, and the sidebar
   row must not grow to fit a tall one. */
.brand-logo {
  flex: 0 0 auto;
  max-width: 38px;
  max-height: 38px;
  object-fit: contain;
  border-radius: 7px;
  background: #fff;   /* transparent PNGs need a backing on the dark sidebar */
  padding: 3px;
}

.logo-row { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.logo-row > div:last-child { flex: 1 1 260px; }

.logo-preview {
  flex: 0 0 auto;
  width: 132px;
  height: 92px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  overflow: hidden;
}
.logo-preview img { max-width: 118px; max-height: 78px; object-fit: contain; }
.logo-empty { font-size: 0.76rem; color: var(--text-muted); }

/* ========================================================================== */
/* Notification preference toggles                                            */
/* ========================================================================== */

.toggle-list { list-style: none; display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.toggle-list li {
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}
.toggle-list label {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 4px;
  font-size: 0.88rem;
}
.toggle-list input[type="checkbox"] { width: auto; flex: 0 0 auto; }

.toggle-desc {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
  padding-left: 25px;
}

/* Sits inline inside a sentence, so it must not stretch like a form field. */
.inline-number {
  width: 72px !important;
  padding: 3px 7px !important;
  font-size: 0.78rem !important;
  display: inline-block;
}

/* ========================================================================== */
/* Alert feed                                                                 */
/* ========================================================================== */

.alert-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.alert-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--text-muted);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.alert-row[data-severity="error"]   { border-left-color: var(--danger); }
.alert-row[data-severity="warning"] { border-left-color: var(--warning); }
.alert-row[data-severity="info"]    { border-left-color: var(--accent); }

/* Unread ones are tinted, so a glance separates new from already-seen. */
.alert-row.is-unread { background: var(--surface-alt); }
.alert-row.is-unread .alert-title { font-weight: 700; }

.alert-icon { flex: 0 0 auto; font-size: 1rem; line-height: 1.4; }
.alert-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.alert-title { font-size: 0.88rem; font-weight: 600; }
.alert-body { font-size: 0.81rem; color: var(--text-muted); line-height: 1.5; }
.alert-meta { font-size: 0.71rem; color: var(--text-muted); }


/* Per-value Copy buttons in the cookie jar and CSRF panels. */
.value-cell {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

/* The cookie values are long unbroken hex strings; let them wrap so the button is not
   pushed off the right edge of the table. */
.value-text { flex: 1 1 auto; word-break: break-all; min-width: 0; }

.value-copy {
  flex: 0 0 auto;
  padding: 2px 9px !important;
  font-size: 0.7rem !important;
  line-height: 1.6;
  /* Keeps the button beside the first line of a wrapped value rather than centred
     against a three-line block. */
  align-self: flex-start;
}

