/*
 * DamageBrief — the app's theme over vendored Bootstrap 5 (dark) and its shell: the desktop sidebar, the phone top bar
 * and bottom navigation, the content column. The component layer (page headers, cards, chips, stacked tables, the
 * analysis stepper, skeletons, toasts…) is components.css, loaded right after this file. The brand palette and the
 * Inter font faces live in brand.css (loaded first). No inline styles anywhere in the app (strict CSP).
 *
 * CONTRAST (WCAG 2.2 AA, measured on every view by test/test_helpers/ui_quality.rb#assert_contrast_aa in the system
 * lane's ui_*_test.rb): every text colour below meets 4.5:1 on the
 * surfaces it is used on. Two choices follow from that and are deliberate: filled primary buttons use blue-600 (white
 * on blue-500 is 4.0:1, under the minimum), and "faint" text is slate-400 (slate-500 is 3.6:1 on the page).
 */

:root {
  --mono: var(--db-font-mono);

  /* surfaces and lines */
  --ui-page: var(--db-slate-900);
  --ui-surface: var(--db-slate-850);
  --ui-surface-2: var(--db-slate-800);
  --ui-surface-sunken: var(--db-slate-950);
  --ui-border: var(--db-slate-700);
  --ui-border-strong: #39414d;
  --ui-border-soft: rgba(255, 255, 255, .06);

  /* text */
  --ui-text: var(--db-slate-200);
  --ui-text-strong: var(--db-slate-100);
  --ui-text-muted: #a9b2be;
  --ui-text-faint: var(--db-slate-400);

  /* actions */
  --ui-primary: var(--db-blue-600);
  --ui-primary-hover: #2a63bc;
  --ui-primary-active: #2558a8;
  --ui-primary-soft: rgba(63, 127, 214, .16);
  --ui-primary-text: var(--db-blue-300);
  --ui-focus: var(--db-blue-300);

  /* shape and depth */
  --ui-radius-sm: 8px;
  --ui-radius: 12px;
  --ui-radius-lg: 16px;
  --ui-shadow: 0 1px 2px rgba(0, 0, 0, .28), 0 10px 30px rgba(0, 0, 0, .18);
  --ui-shadow-lg: 0 18px 50px rgba(0, 0, 0, .4);

  /* the shell */
  --sidebar-w: 252px;
  --topbar-h: 56px;
  --bottom-nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --touch: 44px;
}

/* ---- 1. Bootstrap's dark theme, read from the brand tokens ---- */
[data-bs-theme="dark"] {
  --bs-body-bg: var(--ui-page);              /* soft charcoal, not pure black */
  --bs-body-color: var(--ui-text);           /* off-white — pure white on near-black strains the eye */
  --bs-emphasis-color: var(--ui-text-strong);
  --bs-secondary-bg: var(--ui-surface);
  --bs-tertiary-bg: var(--ui-surface-2);
  --bs-border-color: var(--ui-border);
  --bs-border-color-translucent: var(--ui-border-soft);
  --bs-secondary-color: var(--ui-text-muted);
  --bs-tertiary-color: var(--ui-text-faint);
  --bs-heading-color: var(--ui-text-strong);

  --bs-link-color: var(--db-blue-400);
  --bs-link-hover-color: var(--db-blue-300);
  --bs-link-color-rgb: 91, 155, 255;
  --bs-link-hover-color-rgb: 130, 180, 255;

  --bs-primary: var(--db-blue-600);
  --bs-primary-rgb: 47, 111, 208;
  --bs-success-rgb: 76, 175, 99;
  --bs-danger-rgb: 226, 98, 90;
  --bs-warning-rgb: 201, 156, 67;
  --bs-info-rgb: 91, 155, 255;
  --bs-secondary-rgb: 120, 132, 148;

  /* the subtle/emphasis trio drives the status chips and the alerts — every emphasis colour ≥ 4.5:1 on its subtle bg */
  --bs-primary-bg-subtle: #14264a;   --bs-primary-border-subtle: #234479;   --bs-primary-text-emphasis: #9cc3ff;
  --bs-success-bg-subtle: #16301f;   --bs-success-border-subtle: #24533a;   --bs-success-text-emphasis: #7fd096;
  --bs-danger-bg-subtle: #341a1b;    --bs-danger-border-subtle: #6a3131;    --bs-danger-text-emphasis: #f0a19a;
  --bs-warning-bg-subtle: #312a16;   --bs-warning-border-subtle: #5e4b22;   --bs-warning-text-emphasis: #e2be6d;
  --bs-info-bg-subtle: #142838;      --bs-info-border-subtle: #27507a;      --bs-info-text-emphasis: #93c2f6;
  --bs-secondary-bg-subtle: #232a33; --bs-secondary-border-subtle: #39414d; --bs-secondary-text-emphasis: #b3bcc8;

  --bs-card-bg: var(--ui-surface);
  --bs-card-cap-bg: transparent;
  --bs-card-border-color: var(--ui-border);
  --bs-border-radius: var(--ui-radius-sm);
  --bs-border-radius-lg: var(--ui-radius);

  --bs-body-font-family: var(--db-font-sans);
  --bs-body-font-size: 1rem;
  --bs-body-font-weight: 400;
  --bs-body-line-height: 1.55;

  --bs-focus-ring-color: rgba(130, 180, 255, .55);
  --bs-focus-ring-width: 3px;
  color-scheme: dark;
}

[data-bs-theme="dark"] h1, [data-bs-theme="dark"] h2, [data-bs-theme="dark"] h3 { letter-spacing: -.015em; }
::selection { background: rgba(91, 155, 255, .35); color: #fff; }

/* Focus is always visible (WCAG 2.4.7 / 2.4.11): one ring, on everything the keyboard can reach. */
:focus-visible { outline: 2px solid var(--ui-focus); outline-offset: 2px; }
.btn:focus-visible, .form-control:focus, .form-select:focus, .form-check-input:focus, .btn-check:focus-visible + .btn {
  outline: 2px solid var(--ui-focus); outline-offset: 2px; box-shadow: none;
}
.form-control:focus, .form-select:focus { border-color: var(--db-blue-400); }

/* ---- 2. buttons: real touch targets, one radius, the primary as the only loud colour ---- */
[data-bs-theme="dark"] .btn {
  --bs-btn-font-weight: 600; --bs-btn-padding-y: .55rem; --bs-btn-padding-x: 1rem; --bs-btn-border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 42px;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}
[data-bs-theme="dark"] .btn-sm { --bs-btn-padding-y: .35rem; --bs-btn-padding-x: .75rem; --bs-btn-font-size: .875rem; --bs-btn-border-radius: 8px; min-height: 34px; }
[data-bs-theme="dark"] .btn-lg { --bs-btn-padding-y: .75rem; --bs-btn-padding-x: 1.35rem; --bs-btn-font-size: 1.0625rem; min-height: 50px; }
[data-bs-theme="dark"] .btn > .bi { font-size: 1.05em; line-height: 1; }
[data-bs-theme="dark"] .btn-primary {
  --bs-btn-bg: var(--ui-primary); --bs-btn-border-color: var(--ui-primary); --bs-btn-color: #fff;
  --bs-btn-hover-bg: var(--ui-primary-hover); --bs-btn-hover-border-color: var(--ui-primary-hover); --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: var(--ui-primary-active); --bs-btn-active-border-color: var(--ui-primary-active); --bs-btn-active-color: #fff;
  --bs-btn-disabled-bg: var(--ui-primary); --bs-btn-disabled-border-color: var(--ui-primary);
  box-shadow: 0 6px 18px rgba(47, 111, 208, .28);
}
[data-bs-theme="dark"] .btn-outline-secondary, [data-bs-theme="dark"] .btn-secondary {
  --bs-btn-color: var(--ui-text-strong); --bs-btn-border-color: var(--ui-border-strong); --bs-btn-bg: var(--ui-surface-2);
  --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #2c333e; --bs-btn-hover-border-color: #4a5462;
  --bs-btn-active-color: #fff; --bs-btn-active-bg: #2c333e; --bs-btn-active-border-color: #4a5462;
  --bs-btn-disabled-color: var(--ui-text-muted); --bs-btn-disabled-bg: var(--ui-surface-2);
}
[data-bs-theme="dark"] .btn-outline-danger {
  --bs-btn-color: var(--bs-danger-text-emphasis); --bs-btn-border-color: var(--bs-danger-border-subtle); --bs-btn-bg: transparent;
  --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #a23a33; --bs-btn-hover-border-color: #a23a33;
  --bs-btn-active-color: #fff; --bs-btn-active-bg: #8f322c; --bs-btn-active-border-color: #8f322c;
}
[data-bs-theme="dark"] .btn-danger {
  --bs-btn-bg: #b3403a; --bs-btn-border-color: #b3403a; --bs-btn-color: #fff;
  --bs-btn-hover-bg: #9d3731; --bs-btn-hover-border-color: #9d3731; --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: #8f322c; --bs-btn-active-border-color: #8f322c;
}
[data-bs-theme="dark"] .btn-ghost {
  --bs-btn-color: var(--ui-text-muted); --bs-btn-border-color: transparent; --bs-btn-bg: transparent;
  --bs-btn-hover-color: var(--ui-text-strong); --bs-btn-hover-bg: var(--ui-surface-2); --bs-btn-hover-border-color: transparent;
  --bs-btn-active-color: var(--ui-text-strong); --bs-btn-active-bg: var(--ui-surface-2);
}
.btn-icon { width: 42px; padding-left: 0 !important; padding-right: 0 !important; }
.btn-sm.btn-icon { width: 34px; }
/* coarse pointers (fingers): every button at least 44 px tall (WCAG 2.5.8 asks 24; thumbs need more) */
@media (pointer: coarse) {
  [data-bs-theme="dark"] .btn, [data-bs-theme="dark"] .btn-sm { min-height: var(--touch); }
  .btn-sm.btn-icon, .btn-icon { width: var(--touch); }
}

/* the fault choice: a neutral tile that turns solid primary when chosen */
[data-bs-theme="dark"] .fault-choice {
  --bs-btn-color: var(--ui-text-strong); --bs-btn-border-color: var(--ui-border-strong); --bs-btn-bg: var(--ui-surface-2);
  --bs-btn-hover-bg: #2c333e; --bs-btn-hover-color: #fff; --bs-btn-hover-border-color: #4a5462;
  --bs-btn-active-bg: var(--ui-primary); --bs-btn-active-border-color: var(--ui-primary); --bs-btn-active-color: #fff;
}

/* ---- 3. forms ---- */
[data-bs-theme="dark"] .form-control, [data-bs-theme="dark"] .form-select {
  --bs-border-radius: 10px; min-height: 44px; background-color: var(--ui-surface-sunken); border-color: var(--ui-border-strong);
  color: var(--ui-text-strong);
}
[data-bs-theme="dark"] .form-control-sm, [data-bs-theme="dark"] .form-select-sm { min-height: 36px; --bs-border-radius: 8px; }
[data-bs-theme="dark"] textarea.form-control { min-height: 88px; }
[data-bs-theme="dark"] .form-control::placeholder { color: var(--ui-text-faint); opacity: 1; }
[data-bs-theme="dark"] .form-control:disabled, [data-bs-theme="dark"] .form-select:disabled { background-color: var(--ui-surface-2); color: var(--ui-text-muted); }
/* Bootstrap floats a legend (for bordered fieldsets) and clears it on the NEXT element — a hidden input there leaves the
   float in place and squeezes the fieldset's content off the right edge. Our legends are plain labels. */
legend { float: none; }
.form-label { margin-bottom: .35rem; color: var(--ui-text-strong); font-size: .9375rem; font-weight: 600; }
.form-text { color: var(--ui-text-faint); font-size: .8125rem; }
[data-bs-theme="dark"] .form-check-input { width: 1.15em; height: 1.15em; margin-top: .2em; background-color: var(--ui-surface-sunken); border-color: #56606e; }
[data-bs-theme="dark"] .form-check-input:checked { background-color: var(--ui-primary); border-color: var(--ui-primary); }
/* A switch (form-switch, e.g. Admin → Clients' "Allow own AI keys") stays a switch: the square size above must not win. */
[data-bs-theme="dark"] .form-switch .form-check-input { width: 2.3em; border-radius: 2em; }
.form-check-label { cursor: pointer; }
[data-bs-theme="dark"] .input-group > .form-control { min-width: 0; }

/* ---- 4. tables ---- */
[data-bs-theme="dark"] .table {
  --bs-table-bg: transparent; --bs-table-color: var(--bs-body-color); --bs-table-border-color: var(--ui-border);
  --bs-table-hover-bg: rgba(255, 255, 255, .03); --bs-table-hover-color: var(--bs-body-color);
  --bs-table-striped-bg: rgba(255, 255, 255, .02);
}
[data-bs-theme="dark"] .table > :not(caption) > * > * { padding: .65rem .75rem; }
[data-bs-theme="dark"] .table thead th {
  border-bottom-color: var(--ui-border-strong); color: var(--ui-text-faint);
  font-size: .75rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap;
}
[data-bs-theme="dark"] .table-sm > :not(caption) > * > * { padding: .45rem .6rem; }
.table-responsive { scrollbar-width: thin; }

/* pagination in the theme's primary */
[data-bs-theme="dark"] .pagination {
  --bs-pagination-bg: var(--ui-surface-2); --bs-pagination-border-color: var(--ui-border); --bs-pagination-color: var(--ui-text);
  --bs-pagination-hover-bg: #2c333e; --bs-pagination-hover-color: #fff; --bs-pagination-hover-border-color: var(--ui-border-strong);
  --bs-pagination-active-bg: var(--ui-primary); --bs-pagination-active-border-color: var(--ui-primary);
  --bs-pagination-disabled-bg: var(--ui-surface); --bs-pagination-disabled-border-color: var(--ui-border);
  --bs-pagination-disabled-color: var(--ui-text-faint); --bs-pagination-padding-x: .85rem; --bs-pagination-padding-y: .45rem;
  flex-wrap: wrap; gap: 4px; margin: 0;
}
[data-bs-theme="dark"] .pagination .page-link { border-radius: 8px !important; min-width: 40px; text-align: center; }

/* ---- 5. the shell ---- */
/* `turbo_stream_from` adds a connection element with no UI; as an unknown inline element it would become a grid item
   (it once shoved the sidebar into the content column). Layout-inert wherever it is placed. */
turbo-cable-stream-source { display: none !important; }

body.app-body { min-height: 100vh; background: var(--ui-page); }
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.skip-link {
  position: fixed; left: 12px; top: -80px; z-index: 2000; padding: 10px 14px; border-radius: 10px;
  background: var(--ui-primary); color: #fff; font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: calc(12px + var(--safe-top)); color: #fff; }

/* the desktop sidebar (also the phone's menu sheet: the same partial inside an offcanvas) */
.sidebar {
  display: flex; flex-direction: column; gap: 4px; padding: 16px 12px 14px;
  background: var(--ui-surface-sunken); border-right: 1px solid var(--ui-border-soft);
}
/* Desktop: the full screen height, never scrolled as a whole — the brand and the foot (the user, Sign out) stay put and
   only the nav list scrolls, and only when the window is too short for it, with a thin dark scrollbar. A tighter rhythm
   than the phone's menu sheet: an admin's whole list fits the browser window of a 1366×768 screen (≈ 625 px tall);
   its items never shrink (a short window scrolls the list instead). The list's padding keeps the active item's left
   bar (::before at -12px) inside its scroll box. */
@media (min-width: 992px) {
  aside.sidebar { position: sticky; top: 0; align-self: start; height: 100vh; height: 100dvh; overflow: hidden; gap: 0; padding: 12px 12px 10px; }
  aside.sidebar > .brand, aside.sidebar > .sidebar-foot, aside.sidebar > nav > * { flex: none; }
  aside.sidebar > .brand { padding: 2px 10px 8px; }
  aside.sidebar .nav-section { margin: 6px 0 2px; }
  aside.sidebar .nav-item { min-height: 32px; padding: 5px 12px; }
  /* the foot on one row: the user, then Password & sessions and Sign out as icons (labels visually hidden — still their
     names; tooltips) */
  aside.sidebar > .sidebar-foot { display: flex; align-items: center; padding: 10px 0 0; gap: 4px; }
  /* two icons beside it: a smaller avatar and tighter padding keep a name like "Ada Admin" whole (the title has it all) */
  aside.sidebar > .sidebar-foot .sidebar-user { flex: 1 1 auto; gap: 8px; padding: 4px; }
  aside.sidebar > .sidebar-foot .avatar { width: 30px; height: 30px; font-size: .75rem; }
  aside.sidebar > .sidebar-foot form { flex: none; }
  aside.sidebar > .sidebar-foot .sidebar-signout, aside.sidebar > .sidebar-foot .sidebar-icon-btn {
    display: inline-grid; flex: none; place-items: center; width: 40px; height: 40px; padding: 0;
  }
  aside.sidebar > .sidebar-foot .sidebar-icon-btn.active { background: var(--ui-primary-soft); border-color: var(--db-blue-400); color: #dce9fb; }
  aside.sidebar > .sidebar-foot .sidebar-signout .btn-label, aside.sidebar > .sidebar-foot .sidebar-icon-btn .btn-label {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  aside.sidebar > nav {
    flex: 1 1 auto; min-height: 0; margin: 0 -12px; padding: 0 12px 4px; overflow-x: hidden; overflow-y: auto;
    overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--db-slate-700) transparent;
  }
}
/* A shorter desktop window (a 1366×768 screen leaves ≈ 625 px): an admin's list grew with Messages (Password &
   sessions is an icon in the foot), so the rhythm tightens once more — every item keeps its 32 px (one line, never
   squeezed); the space comes from the gaps, the section labels and the brand; below ~600 px the list scrolls as before. */
@media (min-width: 992px) and (max-height: 720px) {
  aside.sidebar nav { gap: 0; }
  aside.sidebar > .brand { padding-bottom: 4px; }
  aside.sidebar .nav-section { margin: 3px 0 0; line-height: 1.2; }
  aside.sidebar .nav-item { min-height: 32px; padding-block: 3px; line-height: 1.3; }
  aside.sidebar .nav-item > .bi { line-height: 1; }
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-size: 1.14rem; text-decoration: none;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section {
  margin: 16px 0 4px; padding: 0 12px; color: var(--ui-text-faint);
  font-size: .6875rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
}
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 7px 12px; border-radius: 10px;
  color: var(--ui-text-muted); font-size: .9375rem; font-weight: 500; text-decoration: none;
}
button.nav-item { width: 100%; border: 0; background: none; text-align: left; font-family: inherit; }
.nav-item > .bi { width: 1.25rem; font-size: 1.05rem; text-align: center; color: var(--ui-text-faint); }
.nav-item:hover { background: var(--ui-surface-2); color: var(--ui-text-strong); text-decoration: none; }
.nav-item:hover > .bi { color: var(--ui-text-strong); }
.nav-item.active { background: var(--ui-primary-soft); color: #dce9fb; font-weight: 600; }
.nav-item.active > .bi { color: var(--db-blue-300); }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--db-blue-400);
}
/* the account item: its name on one line (an ellipsis when long — the title has it whole), the balance under it */
.nav-item:has(.nav-balance) { display: grid; grid-template-columns: 1.25rem minmax(0, 1fr); column-gap: 10px; row-gap: 3px; }
.nav-item:has(.nav-balance) > .bi { grid-row: span 2; align-self: center; }
.nav-item .nav-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .nav-balance { justify-self: start; }
.sidebar-foot { margin-top: auto; padding: 14px 4px 2px; border-top: 1px solid var(--ui-border-soft); display: grid; gap: 10px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 6px 8px; border-radius: 10px; text-decoration: none; }
.sidebar-user:hover { background: var(--ui-surface-2); }
/* on Your data the user item is the current page (aria-current), lit like a nav item */
.sidebar-user.active { background: var(--ui-primary-soft); }
.sidebar-user.active .sidebar-user-mail { color: var(--ui-text-muted); }
.avatar {
  display: inline-grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%;
  background: var(--db-tile); color: #fff; font-size: .8125rem; font-weight: 700; letter-spacing: .02em;
}
.sidebar-user-text { display: grid; min-width: 0; line-height: 1.25; }
.sidebar-user-name { overflow: hidden; color: var(--ui-text-strong); font-size: .875rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-mail { overflow: hidden; color: var(--ui-text-faint); font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .btn { width: 100%; }

/* the content column: centred, readable width up to 1920 px screens */
.content { min-width: 0; display: flex; flex-direction: column; }
.content > main { flex: 1; width: 100%; max-width: 1360px; margin: 0 auto; padding: 24px 32px 32px; }
.content > main:focus { outline: none; }
.app-footer {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 18px;
  width: 100%; max-width: 1360px; margin: 0 auto; padding: 8px 32px 24px; color: var(--ui-text-faint); font-size: .8125rem;
}

/* ---- 6. phones and tablets: the top bar and the bottom navigation ---- */
.app-topbar, .bottom-nav { display: none; }
@media (max-width: 991.98px) {
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .app-topbar {
    position: sticky; top: 0; z-index: 1030; display: flex; align-items: center; gap: 6px;
    min-height: calc(var(--topbar-h) + var(--safe-top)); padding: var(--safe-top) 8px 0 8px;
    background: rgba(16, 19, 24, .9); backdrop-filter: saturate(150%) blur(12px);
    border-bottom: 1px solid var(--ui-border-soft);
  }
  .app-topbar .brand { display: inline-flex; align-items: center; gap: 8px; margin-left: 6px; font-size: 1.06rem; text-decoration: none; }
  .topbar-title {
    min-width: 0; margin: 0; overflow: hidden; color: var(--ui-text-strong);
    font-size: 1.0625rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap;
  }
  .topbar-back { flex: none; width: var(--touch) !important; min-height: var(--touch) !important; }
  .topbar-end { margin-left: auto; display: flex; align-items: center; gap: 4px; }

  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1035; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
    height: calc(var(--bottom-nav-h) + var(--safe-bottom)); padding: 6px 6px var(--safe-bottom);
    background: rgba(16, 19, 24, .94); backdrop-filter: saturate(150%) blur(12px); border-top: 1px solid var(--ui-border-soft);
  }
  .bottom-nav-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0;
    border: 0; border-radius: 12px; background: none; color: var(--ui-text-muted);
    font-size: .75rem; font-weight: 600; line-height: 1.1; text-decoration: none;
  }
  .bottom-nav-item > .bi {
    display: grid; place-items: center; width: 52px; height: 30px; border-radius: 15px; font-size: 1.25rem; line-height: 1;
    transition: background-color .15s, color .15s;
  }
  .bottom-nav-item > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bottom-nav-item:hover { color: var(--ui-text-strong); }
  .bottom-nav-item.active { color: #dce9fb; }
  .bottom-nav-item.active > .bi { background: var(--ui-primary-soft); color: var(--db-blue-300); }
  .bottom-nav-item.bottom-nav-primary > .bi { background: var(--ui-primary); color: #fff; box-shadow: 0 6px 18px rgba(47, 111, 208, .35); }
  .bottom-nav-item.bottom-nav-primary.active > .bi { background: var(--ui-primary-active); color: #fff; }

  /* nothing sits under the fixed bottom navigation */
  /* + 8px: the footer ends clear of the bottom navigation, not exactly on its edge — a page whose height has a fraction
     (measured: 1227.03 px, the case list with a ready case's PDF link) put the footer 0.03 px under the bar */
  .content { padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px); }
  .content > main { padding: 18px 20px 28px; }
  .app-footer { padding: 4px 20px 20px; }
  /* an anchor or a focused field is never hidden under the sticky top bar or the fixed bottom navigation */
  html { scroll-padding-top: calc(var(--topbar-h) + var(--safe-top) + 12px);
         scroll-padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 16px); }

  /* the menu sheet (the sidebar partial in a bottom offcanvas) */
  .offcanvas.menu-sheet {
    --bs-offcanvas-height: auto; --bs-offcanvas-bg: var(--ui-surface-sunken); --bs-offcanvas-border-color: var(--ui-border);
    max-height: 88dvh; border-radius: 20px 20px 0 0; padding-bottom: var(--safe-bottom); overflow-y: auto;
  }
  .menu-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 4px 0; }
  .menu-sheet-grip { display: block; width: 40px; height: 4px; margin: 0 auto 6px; border-radius: 2px; background: var(--ui-border-strong); }
  .menu-sheet .brand { display: none; } /* the top bar already shows it */
  /* who is signed in and Sign out first, on screen without scrolling the sheet (an administrator's menu is long) */
  .menu-sheet > .menu-sheet-grip, .menu-sheet > .menu-sheet-head { order: -2; }
  .menu-sheet > .sidebar-foot {
    order: -1; display: flex; align-items: center; gap: 10px; margin: 0 0 6px; padding: 4px 4px 12px;
    border-top: 0; border-bottom: 1px solid var(--ui-border-soft);
  }
  .menu-sheet > .sidebar-foot .sidebar-user { flex: 1 1 auto; min-width: 0; }
  .menu-sheet > .sidebar-foot form { flex: none; }
  .menu-sheet > .sidebar-foot .btn { width: auto; }
}
@media (max-width: 575.98px) {
  .content > main { padding: 14px 16px 24px; }
  .app-footer { padding: 4px 16px 18px; }
}

/* ---- 7. text helpers ---- */
.mono { font-family: var(--mono); font-size: .88em; }
/* A badge beside a monospace value (a case number on an erasure's confirm page) keeps the interface's own typeface —
   inside .mono it inherited the code font. */
.mono .badge { font-family: var(--db-font-sans); }
.faint { color: var(--ui-text-faint); }
.muted { color: var(--ui-text-muted); }
.empty { color: var(--ui-text-faint); font-style: italic; padding: 10px 0; }
.text-strong { color: var(--ui-text-strong); }
.num { font-variant-numeric: tabular-nums; }
/* The label column fits its labels but never takes more than 45 % (a long label wraps instead of squeezing the value);
   both columns may wrap, even inside a word (a long label, an e-mail address) — with max-content + 1fr a long label and
   an unbreakable value pushed the list past a phone's width (master 0.13.0). */
dl.kv { display: grid; grid-template-columns: fit-content(45%) minmax(0, 1fr); gap: 8px 20px; margin: 0; }
dl.kv dt { color: var(--ui-text-faint); font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; color: var(--ui-text-strong); }
@media (max-width: 359.98px) {
  dl.kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  dl.kv dd { margin-bottom: 8px; }
}
a { text-underline-offset: 2px; }

/* ---- 8. the sign-in page (no app shell): the logo above the card on a faint glow of the brand blue ---- */
/* the sign-in page fills the screen UNDER the cookie banner — not the screen plus the banner (a stray scrollbar) */
body.app-body:has(> .auth-page) { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.auth-page {
  flex: 1 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; padding: calc(32px + var(--safe-top)) 16px calc(28px + var(--safe-bottom));
  background: radial-gradient(60rem 28rem at 50% -6rem, rgba(36, 83, 166, .38), transparent 70%), var(--db-slate-900);
}
.auth-brand { display: inline-flex; align-items: center; gap: 12px; font-size: 1.6rem; text-decoration: none; }
.auth-card { width: 100%; max-width: 420px; border-radius: var(--ui-radius-lg); box-shadow: var(--ui-shadow-lg); }
.auth-card .card-body { padding: 28px; }
@media (max-width: 400px) { .auth-card .card-body { padding: 22px 18px; } }
.auth-title { margin: 0 0 4px; font-size: 1.375rem; font-weight: 700; }
.auth-back { display: inline-flex; align-items: center; gap: 6px; min-height: var(--touch); font-size: .9375rem; color: var(--ui-text-muted); text-decoration: none; }
.auth-back:hover { color: var(--ui-text-strong); }
.turnstile-box { min-height: 65px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}
