/* ==========================================================================
   IMEI-Tool - design layer
   --------------------------------------------------------------------------
   Owns the visual language of the whole panel. Bootstrap stays underneath as
   a grid and utility scaffold only; everything you actually see - type,
   colour, elevation, materials, motion - is defined here.

   Informed by Apple's interface design talks. The parts that apply to a
   form-driven panel are: instant response to input, translucent materials for
   chrome, size-specific typography, and honouring the accessibility media
   queries. Gesture physics (1:1 dragging, velocity hand-off) is deliberately
   absent - there is nothing here to drag, and faking it would be noise.

   Structure:
     1. Tokens          6. Forms
     2. Typography      7. Tables
     3. Chrome          8. Badges & alerts
     4. Surfaces        9. Utilities
     5. Controls       10. Accessibility overrides
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------
   One palette, two themes. Every colour below is referenced by role, never by
   hue, so the dark theme is a token swap rather than a second stylesheet. */

:root {
  /* Accent - the blue from the logo, so the product has ONE blue and not a
     brand colour fighting a UI colour. Sampled from wordmark.webp: #2c5bff. */
  --t-accent:        #2c5bff;
  --t-accent-hover:  #1f47d6;
  --t-accent-soft:   rgba(44, 91, 255, 0.10);
  --t-accent-ring:   rgba(44, 91, 255, 0.30);
  --t-on-accent:     #ffffff;

  /* Semantic */
  --t-good:        #1a7f37;
  --t-good-soft:   rgba(26, 127, 55, 0.11);
  --t-bad:         #c72c3b;
  --t-bad-soft:    rgba(199, 44, 59, 0.10);
  --t-warn:        #a86300;
  --t-warn-soft:   rgba(168, 99, 0, 0.12);

  /* Neutrals - very slightly cool, so the accent stays the only real colour */
  --t-bg:          #f5f5f7;
  --t-surface:     #ffffff;
  --t-surface-2:   #fafafc;
  --t-text:        #1d1d1f;
  --t-text-2:      #56565b;
  --t-text-3:      #86868b;
  --t-line:        rgba(0, 0, 0, 0.09);
  --t-line-strong: rgba(0, 0, 0, 0.16);

  /* Translucent chrome (§ materials). Two weights: heavier for structural
     regions, lighter for floating elements. Never stack one on the other. */
  --t-chrome:      rgba(255, 255, 255, 0.72);
  --t-chrome-line: rgba(255, 255, 255, 0.55);

  /* Elevation - layered and shallow. A big shadow reads as a cheap sticker;
     real depth comes from a tight contact shadow plus a wide soft one. */
  --t-shadow-1: 0 1px 2px rgba(0,0,0,.05), 0 1px 1px rgba(0,0,0,.03);
  --t-shadow-2: 0 2px 6px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.05);
  --t-shadow-3: 0 4px 12px rgba(0,0,0,.09), 0 24px 48px rgba(0,0,0,.09);

  /* Geometry */
  --t-r-sm: 7px;
  --t-r-md: 11px;
  --t-r-lg: 16px;
  --t-r-pill: 980px;

  /* Motion. Critically damped by default - no overshoot on things the user
     did not physically throw. The "spring" curve adds a whisper of settle for
     elements that appear. */
  --t-fast:   120ms;
  --t-base:   220ms;
  --t-slow:   340ms;
  --t-ease:   cubic-bezier(0.32, 0.72, 0, 1);
  --t-spring: cubic-bezier(0.34, 1.18, 0.64, 1);
}

[data-bs-theme="dark"] {
  /* Lifted on black: the raw brand blue is too dense against a dark surface
     to stay legible as text. Same hue, more light. */
  --t-accent:        #6a8dff;
  --t-accent-hover:  #8aa5ff;
  --t-accent-soft:   rgba(106, 141, 255, 0.16);
  --t-accent-ring:   rgba(106, 141, 255, 0.38);

  --t-good:        #4ade80;
  --t-good-soft:   rgba(74, 222, 128, 0.14);
  --t-bad:         #ff6b6b;
  --t-bad-soft:    rgba(255, 107, 107, 0.14);
  --t-warn:        #fbbf24;
  --t-warn-soft:   rgba(251, 191, 36, 0.14);

  --t-bg:          #000000;
  --t-surface:     #1c1c1e;
  --t-surface-2:   #232325;
  --t-text:        #f5f5f7;
  --t-text-2:      #aeaeb2;
  --t-text-3:      #8e8e93;
  --t-line:        rgba(255, 255, 255, 0.11);
  --t-line-strong: rgba(255, 255, 255, 0.20);

  --t-chrome:      rgba(28, 28, 30, 0.72);
  --t-chrome-line: rgba(255, 255, 255, 0.10);

  --t-shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --t-shadow-2: 0 2px 8px rgba(0,0,0,.45), 0 12px 32px rgba(0,0,0,.35);
  --t-shadow-3: 0 4px 16px rgba(0,0,0,.55), 0 28px 56px rgba(0,0,0,.45);
}

/* Hand the tokens to Bootstrap so its own components follow without having to
   restyle each one individually. */
:root, [data-bs-theme="dark"] {
  --bs-body-bg:      var(--t-bg);
  --bs-body-color:   var(--t-text);
  --bs-border-color: var(--t-line);
  --bs-emphasis-color: var(--t-text);
  --bs-secondary-color: var(--t-text-2);
  --bs-tertiary-color:  var(--t-text-3);
  --bs-link-color:   var(--t-accent);
  --bs-link-hover-color: var(--t-accent-hover);
  --bs-border-radius:    var(--t-r-md);
  --bs-border-radius-sm: var(--t-r-sm);
  --bs-border-radius-lg: var(--t-r-lg);
  --bs-primary: var(--t-accent);
  --bs-focus-ring-color: var(--t-accent-ring);
}


/* 2. Typography -----------------------------------------------------------
   The platform font ships optical sizing and tracking tables already; there
   is no reason to load a webfont and lose that. Tracking is size-specific:
   large text needs negative tracking or the letters drift apart, small text
   needs a touch of positive tracking to stay legible. A single letter-spacing
   value would be wrong at one end or the other. */

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               Roboto, Helvetica, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  letter-spacing: -0.003em;
  background: var(--t-bg);
  color: var(--t-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, .h1 { font-size: clamp(1.9rem, 3.6vw, 2.5rem); line-height: 1.08; letter-spacing: -0.021em; font-weight: 600; }
h2, .h2 { font-size: clamp(1.55rem, 2.8vw, 1.95rem); line-height: 1.14; letter-spacing: -0.018em; font-weight: 600; }
h3, .h3 { font-size: 1.45rem;  line-height: 1.2;  letter-spacing: -0.015em; font-weight: 600; }
h4, .h4 { font-size: 1.22rem;  line-height: 1.26; letter-spacing: -0.012em; font-weight: 600; }
h5, .h5 { font-size: 1.06rem;  line-height: 1.34; letter-spacing: -0.008em; font-weight: 600; }
h6, .h6 { font-size: 0.945rem; line-height: 1.4;  letter-spacing: -0.004em; font-weight: 600; }

/* Small text gets POSITIVE tracking - the opposite of headings. */
small, .small { font-size: 0.8175rem; letter-spacing: 0.005em; line-height: 1.5; }

/* Hierarchy through weight and colour, not size alone. */
.text-muted { color: var(--t-text-2) !important; }
.card-title { letter-spacing: -0.01em; }

code, pre, .font-monospace {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.875em;
  letter-spacing: 0;
  font-variant-ligatures: none;
}
/* Digits in tables and balances must not shimmy as they change. */
.font-monospace, td, .tabular { font-variant-numeric: tabular-nums; }

code {
  background: var(--t-accent-soft);
  color: var(--t-accent);
  padding: 0.12em 0.38em;
  border-radius: 5px;
}
pre {
  background: var(--t-surface-2);
  border: 1px solid var(--t-line);
  border-radius: var(--t-r-md);
  color: var(--t-text);
}
pre code { background: none; color: inherit; padding: 0; }

a { text-decoration-thickness: 1px; text-underline-offset: 2px; }


/* 3. Chrome ---------------------------------------------------------------
   A fixed sidebar for navigation, and a slim translucent bar that carries
   only the two things worth glancing at from anywhere: the credit balance and
   whether anything is new. Everything else lives in the sidebar, where a
   growing list of destinations has room to grow. */

.app-shell { display: flex; min-height: 100svh; }

/* -- Sidebar ------------------------------------------------------------- */

.app-side {
  flex: 0 0 15rem;
  width: 15rem;
  background: var(--t-surface);
  border-right: 1px solid var(--t-line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100svh;
  padding: 1.1rem 0.75rem 0.9rem;
}

.app-side__brand {
  display: block;
  padding: 0.25rem 0.6rem 1.15rem;
  transition: opacity var(--t-fast) var(--t-ease);
}
.app-side__brand:hover  { opacity: 0.75; }
.app-side__brand:active { opacity: 0.6; }

/* The logo is a background image on a labelled link, not an <img>: the theme
   swap has to follow OUR data-bs-theme (which the user can override), and a
   <picture media="prefers-color-scheme"> would ignore that override. */
.brand-mark {
  display: block;
  width: 7.1rem;
  height: 1.7rem;
  background: url("../img/wordmark.webp") no-repeat left center;
  background-size: contain;
}
[data-bs-theme="dark"] .brand-mark { background-image: url("../img/wordmark-dark.webp"); }

.brand-mark--lg { width: 9.2rem; height: 2.22rem; background-position: center; margin-inline: auto; }

.app-side__nav { display: flex; flex-direction: column; gap: 1px; }

.app-side__link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.52rem 0.65rem;
  border-radius: var(--t-r-sm);
  color: var(--t-text-2);
  text-decoration: none;
  font-size: 0.925rem;
  font-weight: 500;
  letter-spacing: -0.006em;
  transition: color var(--t-fast) var(--t-ease),
              background-color var(--t-fast) var(--t-ease);
}
.app-side__link:hover { color: var(--t-text); background: var(--t-line); }
.app-side__link:active { background: var(--t-line-strong); }

/* The current page is stated once, in colour and weight - no extra marker. */
.app-side__link[aria-current="page"] {
  background: var(--t-accent-soft);
  color: var(--t-accent);
  font-weight: 600;
}
.app-side__link svg { flex: 0 0 auto; opacity: 0.8; }
.app-side__link[aria-current="page"] svg { opacity: 1; }

.app-side__section {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--t-text-3);
  padding: 1.1rem 0.65rem 0.35rem;
}

.app-side__foot { margin-top: auto; padding: 0.9rem 0.35rem 0; border-top: 1px solid var(--t-line); }

/* -- Top bar ------------------------------------------------------------- */

.app-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.app-bar {
  position: sticky;
  top: 0;
  z-index: 1020;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1.25rem;
  background: var(--t-chrome);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid transparent;
  transition: border-color var(--t-base) var(--t-ease),
              box-shadow var(--t-base) var(--t-ease);
}
/* Scroll edge: the separator exists only while content is actually beneath. */
.app-bar.is-scrolled {
  border-bottom-color: var(--t-line);
  box-shadow: 0 1px 12px rgba(0,0,0,.04);
}

.app-bar__balance {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
  padding: 0.32rem 0.75rem;
  border-radius: var(--t-r-pill);
  background: var(--t-accent-soft);
  color: var(--t-accent);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--t-fast) var(--t-ease), transform var(--t-fast) var(--t-ease);
}
.app-bar__balance:hover  { background: color-mix(in srgb, var(--t-accent) 18%, transparent); color: var(--t-accent); }
.app-bar__balance:active { transform: scale(0.97); }

/* Bell: an icon button with a dot. The dot says "something is new" without
   stating a number nobody needs at a glance - the count is on the page. */
.app-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: var(--t-r-sm);
  color: var(--t-text-2);
  text-decoration: none;
  transition: color var(--t-fast) var(--t-ease),
              background-color var(--t-fast) var(--t-ease),
              transform var(--t-fast) var(--t-ease);
}
.app-bell:hover  { color: var(--t-text); background: var(--t-line); }
.app-bell:active { transform: scale(0.94); }
.app-bell[aria-current="page"] { color: var(--t-accent); background: var(--t-accent-soft); }

.app-bell__dot {
  position: absolute;
  top: 0.3rem;
  right: 0.32rem;
  min-width: 0.95rem;
  height: 0.95rem;
  padding: 0 0.22rem;
  border-radius: var(--t-r-pill);
  background: var(--t-bad);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 0.95rem;
  text-align: center;
  letter-spacing: 0;
  /* A ring in the bar's own colour lifts the dot off the icon beneath it. */
  box-shadow: 0 0 0 2px var(--t-chrome);
}
/* One announcement on arrival, then still. A looping pulse would nag. */
.app-bell__dot { animation: bell-pop 420ms var(--t-spring) both; }
@keyframes bell-pop {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.app-bar__user {
  color: var(--t-text-2);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-bar__user:hover { color: var(--t-text); }

.app-content { padding: 1.5rem 1.25rem 0; flex: 1 1 auto; }
.app-content > * { max-width: 78rem; margin-inline: auto; }

.app-footer {
  color: var(--t-text-3);
  font-size: 0.8125rem;
  letter-spacing: 0.005em;
  padding: 1.5rem 1.25rem 1.5rem;
}
.app-footer > * { max-width: 78rem; margin-inline: auto; }
.app-footer a { color: inherit; text-decoration: none; }
.app-footer a:hover { color: var(--t-text-2); }

/* -- Small screens: the sidebar becomes a drawer -------------------------- */

.app-burger { display: none; }

@media (max-width: 991.98px) {
  .app-side { display: none; }
  .app-burger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.15rem;
    height: 2.15rem;
    border: 0;
    border-radius: var(--t-r-sm);
    background: transparent;
    color: var(--t-text-2);
    transition: background-color var(--t-fast) var(--t-ease), transform var(--t-fast) var(--t-ease);
  }
  .app-burger:hover  { background: var(--t-line); color: var(--t-text); }
  .app-burger:active { transform: scale(0.94); }
  .app-content, .app-footer { padding-inline: 1rem; }
}

/* The drawer reuses the sidebar's own styles, so the two cannot drift. */
.offcanvas.app-drawer {
  width: 16rem;
  background: var(--t-surface);
  border-right: 1px solid var(--t-line);
}
.offcanvas.app-drawer .app-side {
  display: flex;
  position: static;
  height: auto;
  flex: 1 1 auto;
  width: auto;
  border-right: 0;
}

/* 4. Surfaces -------------------------------------------------------------
   Cards are the one container. Flat, hairline-bordered, with a shadow small
   enough that you notice the content instead of the box. */

.card {
  background: var(--t-surface);
  border: 1px solid var(--t-line);
  border-radius: var(--t-r-lg);
  box-shadow: var(--t-shadow-1);
}
/* Bootstrap's shadow utilities are redirected rather than fought. */
.card.shadow-sm { box-shadow: var(--t-shadow-1) !important; }
.card.shadow    { box-shadow: var(--t-shadow-2) !important; }
.card-body { padding: 1.35rem 1.45rem; }

/* Cards that are entirely clickable get a hint of lift - and press feedback,
   because anything that reacts to a click must react on the way down. */
.card-interactive {
  cursor: pointer;
  transition: transform var(--t-base) var(--t-ease),
              box-shadow var(--t-base) var(--t-ease);
}
.card-interactive:hover  { transform: translateY(-2px); box-shadow: var(--t-shadow-2); }
.card-interactive:active { transform: translateY(0) scale(0.994); transition-duration: var(--t-fast); }

/* A compact figure: label above, number below, no box of its own. */
.stat__label {
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--t-text-3);
}
.stat__value {
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

hr { border-color: var(--t-line); opacity: 1; }


/* 5. Controls -------------------------------------------------------------
   Response is the foundation: a control must acknowledge the press on the way
   DOWN, not when the click completes. Everything else is decoration. */

.btn {
  --bs-btn-border-radius: var(--t-r-sm);
  font-weight: 500;
  letter-spacing: -0.006em;
  padding: 0.5rem 1rem;
  border-radius: var(--t-r-sm);
  transition: background-color var(--t-fast) var(--t-ease),
              border-color var(--t-fast) var(--t-ease),
              color var(--t-fast) var(--t-ease),
              transform var(--t-fast) var(--t-ease),
              box-shadow var(--t-fast) var(--t-ease);
}
.btn:active { transform: scale(0.97); }
.btn:disabled, .btn.disabled { transform: none; opacity: 0.45; }
.btn-sm { padding: 0.3rem 0.68rem; font-size: 0.85rem; border-radius: 6px; }
.btn-lg { padding: 0.7rem 1.3rem; font-size: 1.0125rem; }

.btn-primary {
  --bs-btn-bg: var(--t-accent);
  --bs-btn-border-color: var(--t-accent);
  --bs-btn-hover-bg: var(--t-accent-hover);
  --bs-btn-hover-border-color: var(--t-accent-hover);
  --bs-btn-active-bg: var(--t-accent-hover);
  --bs-btn-active-border-color: var(--t-accent-hover);
  --bs-btn-color: var(--t-on-accent);
  --bs-btn-hover-color: var(--t-on-accent);
  --bs-btn-disabled-bg: var(--t-accent);
  --bs-btn-disabled-border-color: var(--t-accent);
  box-shadow: var(--t-shadow-1);
}

.btn-outline-primary {
  --bs-btn-color: var(--t-accent);
  --bs-btn-border-color: var(--t-line-strong);
  --bs-btn-hover-bg: var(--t-accent-soft);
  --bs-btn-hover-color: var(--t-accent);
  --bs-btn-hover-border-color: var(--t-accent);
  --bs-btn-active-bg: var(--t-accent-soft);
  --bs-btn-active-color: var(--t-accent);
  --bs-btn-active-border-color: var(--t-accent);
}

.btn-outline-secondary {
  --bs-btn-color: var(--t-text-2);
  --bs-btn-border-color: var(--t-line-strong);
  --bs-btn-hover-bg: var(--t-accent-soft);
  --bs-btn-hover-color: var(--t-text);
  --bs-btn-hover-border-color: var(--t-line-strong);
  --bs-btn-active-bg: var(--t-accent-soft);
  --bs-btn-active-color: var(--t-text);
  --bs-btn-active-border-color: var(--t-line-strong);
}

.btn-outline-danger {
  --bs-btn-color: var(--t-bad);
  --bs-btn-border-color: var(--t-line-strong);
  --bs-btn-hover-bg: var(--t-bad-soft);
  --bs-btn-hover-color: var(--t-bad);
  --bs-btn-hover-border-color: var(--t-bad);
  --bs-btn-active-bg: var(--t-bad-soft);
  --bs-btn-active-color: var(--t-bad);
  --bs-btn-active-border-color: var(--t-bad);
}

.btn-warning {
  --bs-btn-bg: var(--t-warn);
  --bs-btn-border-color: var(--t-warn);
  --bs-btn-color: #fff;
  --bs-btn-hover-color: #fff;
}

/* Keyboard focus is loud; mouse focus is silent. */
:focus-visible {
  outline: 3px solid var(--t-accent-ring);
  outline-offset: 2px;
  border-radius: var(--t-r-sm);
}
.btn:focus, .btn:focus-visible { box-shadow: none; }
.btn:focus-visible { outline: 3px solid var(--t-accent-ring); outline-offset: 2px; }


/* 6. Forms ----------------------------------------------------------------
   Inputs read as recessed surfaces; the accent appears only on focus, so the
   field the user is in is the only coloured thing on screen. */

.form-label {
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: -0.003em;
  color: var(--t-text-2);
  margin-bottom: 0.35rem;
}
.form-text { color: var(--t-text-3); font-size: 0.8125rem; letter-spacing: 0.004em; }

.form-control, .form-select {
  background: var(--t-surface-2);
  border: 1px solid var(--t-line-strong);
  border-radius: var(--t-r-sm);
  color: var(--t-text);
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
  transition: border-color var(--t-fast) var(--t-ease),
              box-shadow var(--t-fast) var(--t-ease),
              background-color var(--t-fast) var(--t-ease);
}
.form-control:hover:not(:focus), .form-select:hover:not(:focus) { border-color: var(--t-text-3); }
.form-control:focus, .form-select:focus {
  background: var(--t-surface);
  border-color: var(--t-accent);
  box-shadow: 0 0 0 3.5px var(--t-accent-ring);
  outline: none;
}
.form-control::placeholder { color: var(--t-text-3); }
.form-control-sm, .form-select-sm { padding: 0.3rem 0.55rem; font-size: 0.85rem; border-radius: 6px; }
textarea.form-control { line-height: 1.55; }

.form-check-input {
  border-color: var(--t-line-strong);
  transition: background-color var(--t-fast) var(--t-ease),
              border-color var(--t-fast) var(--t-ease);
}
.form-check-input:checked { background-color: var(--t-accent); border-color: var(--t-accent); }
.form-check-input:focus-visible { box-shadow: 0 0 0 3.5px var(--t-accent-ring); outline: none; }
.form-check-label { font-size: 0.925rem; }

.form-switch .form-check-input { width: 2.1em; height: 1.18em; }

.input-group > .form-control:focus { z-index: 3; }


/* 7. Tables ---------------------------------------------------------------
   Data tables carry the heavy lifting in this panel, so they get quiet lines,
   generous vertical rhythm and headers that recede. */

.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--t-text);
  --bs-table-border-color: var(--t-line);
  --bs-table-hover-bg: var(--t-accent-soft);
  --bs-table-hover-color: var(--t-text);
  margin-bottom: 0;
}
.table > thead th {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.035em;
  text-transform: uppercase;
  color: var(--t-text-3);
  border-bottom: 1px solid var(--t-line);
  padding: 0.55rem 0.6rem;
  white-space: nowrap;
}
.table > tbody td { padding: 0.72rem 0.6rem; border-color: var(--t-line); vertical-align: middle; }
.table > tbody tr:last-child td { border-bottom: 0; }
.table-hover > tbody > tr { transition: background-color var(--t-fast) var(--t-ease); }

/* Tables must not force a horizontal scrollbar on the whole page. */
.table-wrap { overflow-x: auto; margin-inline: -0.35rem; padding-inline: 0.35rem; }


/* 8. Badges & alerts ------------------------------------------------------ */

.badge {
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.006em;
  padding: 0.32em 0.62em;
  border-radius: 6px;
}
/* Tinted, not saturated: a status is information, not an alarm. */
.badge.text-bg-success   { background: var(--t-good-soft) !important; color: var(--t-good) !important; }
.badge.text-bg-danger    { background: var(--t-bad-soft) !important;  color: var(--t-bad) !important; }
.badge.text-bg-warning   { background: var(--t-warn-soft) !important; color: var(--t-warn) !important; }
.badge.text-bg-secondary { background: var(--t-line) !important;      color: var(--t-text-2) !important; }
.badge.text-bg-primary   { background: var(--t-accent-soft) !important; color: var(--t-accent) !important; }
.badge.text-bg-light     { background: var(--t-line) !important;      color: var(--t-text-2) !important; }
.badge.bg-success   { background: var(--t-good-soft) !important; color: var(--t-good) !important; }
.badge.bg-danger    { background: var(--t-bad) !important;       color: #fff !important; }
.badge.bg-warning   { background: var(--t-warn-soft) !important; color: var(--t-warn) !important; }
.badge.bg-secondary { background: var(--t-line) !important;      color: var(--t-text-2) !important; }
.badge.bg-primary   { background: var(--t-accent-soft) !important; color: var(--t-accent) !important; }

.alert {
  border-radius: var(--t-r-md);
  border: 1px solid var(--t-line);
  padding: 0.85rem 1rem;
  font-size: 0.925rem;
  box-shadow: var(--t-shadow-1);
}
.alert-success   { background: var(--t-good-soft); border-color: transparent; color: var(--t-good); }
.alert-danger    { background: var(--t-bad-soft);  border-color: transparent; color: var(--t-bad); }
.alert-warning   { background: var(--t-warn-soft); border-color: transparent; color: var(--t-warn); }
.alert-secondary,
.alert-light     { background: var(--t-surface-2); border-color: var(--t-line); color: var(--t-text-2); }
.alert a { color: inherit; font-weight: 500; }

/* Flash messages arrive rather than blink into place. */
.flash { animation: t-arrive var(--t-slow) var(--t-spring) both; }
@keyframes t-arrive {
  from { opacity: 0; transform: translateY(-6px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

.spinner-border { border-width: 0.16em; }
.progress { background: var(--t-line); border-radius: var(--t-r-pill); overflow: hidden; }
.progress-bar { background: var(--t-accent); }


/* 8b. Theme switch --------------------------------------------------------
   A segmented control, not a two-state toggle: "follow my device" is a real
   choice and must stay reachable. The selected segment is a raised pill that
   slides in front of the track, the way a physical selector would. */

.theme-switch,
.lang-switch {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  border-radius: var(--t-r-pill);
  background: var(--t-line);
  line-height: 1;
}
.theme-switch__opt,
.lang-switch__opt {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--t-text-3);
  font-size: 0.8rem;
  padding: 0.24rem 0.5rem;
  border-radius: var(--t-r-pill);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--t-ease),
              color var(--t-fast) var(--t-ease),
              transform var(--t-fast) var(--t-ease),
              box-shadow var(--t-fast) var(--t-ease);
}
.theme-switch__opt:hover,
.lang-switch__opt:hover { color: var(--t-text-2); }
.theme-switch__opt:active,
.lang-switch__opt:active { transform: scale(0.94); }
.theme-switch__opt[aria-pressed="true"],
.lang-switch__opt[aria-pressed="true"] {
  background: var(--t-surface);
  color: var(--t-text);
  box-shadow: var(--t-shadow-1);
}
.theme-switch__opt:focus-visible,
.lang-switch__opt:focus-visible { outline: 3px solid var(--t-accent-ring); outline-offset: 1px; }

@media (prefers-reduced-motion: reduce) {
  .theme-switch__opt:active,
  .lang-switch__opt:active { transform: none; }
}

/* The language switch is a real <form> (it works without JS and is
   remembered server-side), so it needs the form's default margin removed. */
.lang-switch { margin: 0; }
.lang-switch__opt { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em; }

/* 9. Utilities ------------------------------------------------------------ */

.bg-light      { background: var(--t-surface-2) !important; }
.border-top    { border-top: 1px solid var(--t-line) !important; }
.border-bottom { border-bottom: 1px solid var(--t-line) !important; }
.text-success  { color: var(--t-good) !important; }
.text-danger   { color: var(--t-bad) !important; }
.text-warning  { color: var(--t-warn) !important; }
.text-success-emphasis { color: var(--t-good) !important; }
.text-danger-emphasis  { color: var(--t-bad) !important; }
.text-warning-emphasis { color: var(--t-warn) !important; }

details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; color: var(--t-text-3); }
details[open] > summary::before { content: "▾ "; }

::selection { background: var(--t-accent-soft); color: var(--t-text); }

/* Anything scrollable keeps momentum and a thin, unobtrusive bar. */
* { scrollbar-width: thin; scrollbar-color: var(--t-line-strong) transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--t-line-strong); border-radius: var(--t-r-pill); }
::-webkit-scrollbar-track { background: transparent; }


/* 10. Accessibility overrides --------------------------------------------
   Three independent user signals, each handled on its own terms. Reduced
   motion is not "no feedback" - it is feedback without vestibular movement. */

@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;
  }
  /* Keep the press acknowledgement - just make it colour, not movement. */
  .btn:active, .card-interactive:active, .card-interactive:hover { transform: none; }
  .btn:active { filter: brightness(0.94); }
  .flash { animation: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .app-bar {
    background: var(--t-surface);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    border-bottom-color: var(--t-line);
  }
  /* The dot's ring must follow the now-solid bar, or it outlines in the
     translucent colour and reads as a halo. */
  .app-bell__dot { box-shadow: 0 0 0 2px var(--t-surface); }
}

@media (prefers-contrast: more) {
  :root {
    --t-line:        rgba(0, 0, 0, 0.32);
    --t-line-strong: rgba(0, 0, 0, 0.55);
    --t-text-2:      #333336;
    --t-text-3:      #55555a;
    --t-chrome:      #ffffff;
  }
  [data-bs-theme="dark"] {
    --t-line:        rgba(255, 255, 255, 0.34);
    --t-line-strong: rgba(255, 255, 255, 0.62);
    --t-text-2:      #e4e4e8;
    --t-text-3:      #c0c0c6;
    --t-chrome:      #1c1c1e;
  }
  .card, .form-control, .form-select { border-width: 1px; }
  .badge { outline: 1px solid currentColor; outline-offset: -1px; }
}

/* Phones: the chrome stays, the padding shrinks. */
@media (max-width: 575.98px) {
  .card-body { padding: 1.1rem; }
  .stat__value { font-size: 1.5rem; }
  h1, .h1 { font-size: 1.75rem; }
}

@media print {
  .app-side, .app-bar, .app-footer, .btn { display: none !important; }
  .app-shell { display: block; }
  .card { box-shadow: none; border-color: #ccc; }
}
