/* ============================================================================
   Foundation design tokens — copied VERBATIM from
   packages/foundation/src/styles/tokens.css (:root LIGHT) so the console adopts
   the same WCAG-AA-verified palette without an @import (CSP-safe). Only the
   surface-generic tokens the console uses are copied.
   ========================================================================== */
:root {
  color-scheme: light;

  /* Brand */
  --brand-primary: #0066cc;
  --brand-primary-hover: #005bb8;
  --brand-primary-active: #004ea3;

  /* Surfaces */
  --bg-canvas: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-muted: #f1f5f9;
  --surface-card: #ffffff;
  --surface-raised: #ffffff;

  /* Text */
  --text-strong: #0f172a;
  --text-default: #1e293b;
  --text-muted: #475569;
  --text-subtle: #64748b;
  --text-on-brand: #ffffff;
  --text-link: #004ea3;
  --text-link-hover: #00397a;

  /* Borders */
  --border-subtle: #e2e8f0;
  --border-default: #cbd5e1;
  --border-interactive: #7d8da7;
  --border-strong: #475569;

  /* Semantic states */
  --success: #15803d;
  --success-bg: #f0fdf4;
  --success-text: #166534;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;

  /* Interaction */
  --focus-ring: #0066cc;
  --focus-ring-on-brand: #ffffff;
  --selected-bg: #eff6ff;
  --disabled-fill: #e2e8f0;
  --disabled-text: #94a3b8;

  /* Gradients (restrained, single-hue) — copied VERBATIM from foundation
     tokens.css. The CTA sheen is the primary button's brand fill; the brand-subtle
     wash is the on-brand auth-page backdrop. */
  --gradient-brand-subtle: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
  --gradient-cta-sheen: linear-gradient(180deg, #0a6fd4 0%, #0066cc 100%);

  /* Typography — the PLATFORM font. --font-sans leads with the self-hosted Tajawal
     web font (served from /assets/fonts/, @font-face below), matching the foundation
     contract exactly, then the same system fallback stack. --font-mono stays for
     machine tokens (<code>) so URLs/keys/base32 keep their monospace. */
  --font-sans: "Tajawal", system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;

  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  --letter-spacing-arabic: 0; /* NEVER track Arabic */

  /* Spacing (4px base) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 2.5rem;

  /* Layout / sizing */
  --tap-target-min: 44px;
  --container-max: 75rem;
  --control-height-sm: 2.25rem; /* 36px — compact/secondary controls */
  --control-height-md: var(--tap-target-min); /* 44px — primary actions */

  /* Radius */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;

  /* Shadow */
  --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.1), 0 2px 6px -2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 28px -6px rgba(15, 23, 42, 0.14), 0 6px 12px -6px rgba(15, 23, 42, 0.08);
  --shadow-brand: 0 8px 24px -6px rgba(0, 102, 204, 0.28);

  /* Motion */
  --duration-instant: 80ms;
  --duration-fast: 150ms;
  --duration-base: 220ms;
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);

  /* The sticky-chrome offset the section anchors clear (topbar height + breathing
     room). Used by scroll-padding so an anchor jump lands below the sticky bar. */
  --console-scroll-offset: 5rem;
}

/* Dark token overrides — copied VERBATIM from
   packages/foundation/src/styles/themes.css ([data-theme="dark"]). Applied for an
   EXPLICIT cookie override (`[data-theme="dark"]`) AND for the OS preference when
   the operator set no theme cookie (`:root:not([data-theme])` under the media
   query). Light is the base; this is the only override block. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg-canvas: #0b1220;
    --bg-subtle: #111a2b;
    --bg-muted: #16213a;
    --surface-card: #19233c;
    --surface-raised: #1e2a45;
    --text-strong: #f1f5f9;
    --text-default: #e2e8f0;
    --text-muted: #a3b0c2;
    --text-subtle: #94a3b8;
    --text-on-brand: #ffffff;
    --text-link: #5aa9ff;
    --text-link-hover: #8cc2ff;
    --brand-primary-active: #7ab4ff;
    --border-subtle: #1f2a3d;
    --border-default: #2a3850;
    --border-interactive: #5b6a82;
    --border-strong: #8493a8;
    --success: #4ade80;
    --success-bg: color-mix(in oklab, #4ade80 14%, transparent);
    --success-text: #86efac;
    --danger: #f87171;
    --danger-bg: color-mix(in oklab, #f87171 14%, transparent);
    --selected-bg: color-mix(in oklab, #5aa9ff 16%, transparent);
    --focus-ring: #5aa9ff;
    --disabled-fill: #1f2a3d;
    --disabled-text: #64748b;
    --gradient-brand-subtle: linear-gradient(180deg, #0e1830 0%, #0b1322 100%);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.5), 0 1px 2px -1px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.55), 0 2px 6px -2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 28px -6px rgba(0, 0, 0, 0.6), 0 6px 12px -6px rgba(0, 0, 0, 0.45);
    --shadow-brand: 0 8px 24px -6px rgba(0, 102, 204, 0.5);
  }
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg-canvas: #0b1220;
  --bg-subtle: #111a2b;
  --bg-muted: #16213a;
  --surface-card: #19233c;
  --surface-raised: #1e2a45;
  --text-strong: #f1f5f9;
  --text-default: #e2e8f0;
  --text-muted: #a3b0c2;
  --text-subtle: #94a3b8;
  --text-on-brand: #ffffff;
  --text-link: #5aa9ff;
  --text-link-hover: #8cc2ff;
  --brand-primary-active: #7ab4ff;
  --border-subtle: #1f2a3d;
  --border-default: #2a3850;
  --border-interactive: #5b6a82;
  --border-strong: #8493a8;
  --success: #4ade80;
  --success-bg: color-mix(in oklab, #4ade80 14%, transparent);
  --success-text: #86efac;
  --danger: #f87171;
  --danger-bg: color-mix(in oklab, #f87171 14%, transparent);
  --selected-bg: color-mix(in oklab, #5aa9ff 16%, transparent);
  --focus-ring: #5aa9ff;
  --disabled-fill: #1f2a3d;
  --disabled-text: #64748b;
  --gradient-brand-subtle: linear-gradient(180deg, #0e1830 0%, #0b1322 100%);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.5), 0 1px 2px -1px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.55), 0 2px 6px -2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 28px -6px rgba(0, 0, 0, 0.6), 0 6px 12px -6px rgba(0, 0, 0, 0.45);
  --shadow-brand: 0 8px 24px -6px rgba(0, 102, 204, 0.5);
}

/* ============================================================================
   Self-hosted Tajawal — @font-face copied VERBATIM from
   packages/foundation/src/styles/fonts.css (same unicode-range split,
   font-display: swap), but pointing at the console's same-origin /assets/fonts/
   routes (the binary bakes the six woff2 in; the edge CSP already allows
   font-src 'self'). Three weights per subset (400/500/700); weight 600 resolves
   to the 700 face by design. Arabic + Latin subsets so a glyph run downloads only
   what it needs. THIS is the explicit "same font as the platform" requirement.
   ========================================================================== */
/* ---- Arabic subset ---- */
@font-face {
  font-family: "Tajawal";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/tajawal-arabic-400.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0898-08E1, U+08E3-08FF,
    U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: "Tajawal";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/assets/fonts/tajawal-arabic-500.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0898-08E1, U+08E3-08FF,
    U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: "Tajawal";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/assets/fonts/tajawal-arabic-700.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0898-08E1, U+08E3-08FF,
    U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFF;
}
/* ---- Latin subset (atomic LTR runs: brand EN, digits, machine tokens) ---- */
@font-face {
  font-family: "Tajawal";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/assets/fonts/tajawal-latin-400.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2074, U+20AC,
    U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Tajawal";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/assets/fonts/tajawal-latin-500.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2074, U+20AC,
    U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Tajawal";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/assets/fonts/tajawal-latin-700.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+2000-206F, U+2074, U+20AC,
    U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ============================================================================
   Base. Logical properties only so RTL/LTR both flow.
   ========================================================================== */
* { box-sizing: border-box; }
html { scroll-padding-top: var(--console-scroll-offset); }
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
body {
  font-family: var(--font-sans);
  margin: 0;
  padding: var(--space-5);
  line-height: 1.6;
  background-color: var(--bg-canvas);
  color: var(--text-default);
}
code { font-family: var(--font-mono); font-size: 0.9em; }
h1, h2 { color: var(--text-strong); text-wrap: balance; }

/* Shared focus ring for every interactive control (WCAG 2.4.7) — the AA-verified
   token, the same in both themes. */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Skip link — visually hidden until focused (keyboard accessibility). */
.skip-link {
  position: absolute;
  inset-inline-start: var(--space-4);
  inset-block-start: -3rem;
  z-index: 10;
  padding: var(--space-2) var(--space-4);
  background: var(--surface-card);
  color: var(--text-link);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: inset-block-start var(--duration-fast) var(--ease-standard);
}
.skip-link:focus-visible { inset-block-start: var(--space-4); }

a { color: var(--text-link); }
a:hover { color: var(--text-link-hover); }

/* ============================================================================
   Brand lockup (.c-logo) — replicated from apps/marketing primitives/Logo.{tsx,css}.
   The mark <img> is DECORATIVE (alt="") in every template; the page <h1>/<title>
   carries the accessible name. The wordmark is the platform's Arabic brand name
   "ويب تريندز" used platform-wide (NOT a heading, NOT new descriptive copy), so it
   is correct in both AR and EN chrome.
   ========================================================================== */
.c-logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-strong);
  font-weight: var(--font-weight-bold);
  line-height: 1;
}
.c-logo__mark {
  flex: none;
  /* width/height attributes reserve the box → no shift (CLS); the drop shadow
     lifts the gradient mark on any surface (same as the platform). */
  filter: drop-shadow(0 1px 2px rgba(15, 23, 42, 0.12));
}
.c-logo__word {
  font-size: 1.125rem;
  letter-spacing: var(--letter-spacing-arabic);
  white-space: nowrap;
}
/* Centered lockup above the auth-card heading (the polished entrance). */
.auth-logo { display: flex; justify-content: center; margin-block-end: var(--space-5); }

/* ============================================================================
   Button system (.c-btn) — replicated from packages/foundation/src/styles/button.css
   so the console's actions FEEL like the platform: a single dominant brand-fill
   primary (CTA sheen + hover lift + brand shadow) and a bordered-surface secondary.
   Radius --radius-sm, semibold, foundation transitions/easing, >= the 44px tap
   target. The lift/shadow is suppressed under prefers-reduced-motion.
   ========================================================================== */
.c-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height-md);
  padding-inline: var(--space-5);
  font: inherit;
  font-weight: var(--font-weight-semibold);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition:
    background-color var(--duration-fast) var(--ease-standard),
    border-color var(--duration-fast) var(--ease-standard),
    color var(--duration-fast) var(--ease-standard),
    box-shadow var(--duration-base) var(--ease-standard),
    transform var(--duration-instant) var(--ease-standard);
}
/* Primary — the dominant action: brand fill + CTA sheen + hover lift + brand shadow.
   The opaque gradient paints over background-color, so the interaction feedback is
   the lift + shadow (matches the foundation rationale). */
.c-btn--primary {
  background-color: var(--brand-primary);
  background-image: var(--gradient-cta-sheen);
  color: var(--text-on-brand);
}
@media (prefers-reduced-motion: no-preference) {
  .c-btn--primary:hover { box-shadow: var(--shadow-brand); transform: translateY(-1px); }
  .c-btn--primary:active { transform: translateY(0); box-shadow: none; }
}
/* Reduced-motion: keep the affordance via shadow only, never a transform. */
@media (prefers-reduced-motion: reduce) {
  .c-btn--primary:hover { box-shadow: var(--shadow-brand); }
}
/* Secondary — subordinate, bordered surface (e.g. "Sign out"). */
.c-btn--secondary {
  background-color: var(--surface-card);
  border-color: var(--border-interactive);
  color: var(--text-strong);
}
.c-btn--secondary:hover { border-color: var(--border-strong); background-color: var(--bg-subtle); }
.c-btn--secondary:active { background-color: var(--bg-muted); }
.c-btn--full { width: 100%; }
.c-btn:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
/* On a brand fill, switch the ring to white for separation (foundation pattern). */
.c-btn--primary:focus-visible {
  outline-color: var(--focus-ring-on-brand);
  box-shadow: 0 0 0 4px color-mix(in oklab, var(--brand-primary) 35%, transparent);
}
.c-btn[disabled], .c-btn[aria-disabled="true"] {
  background-color: var(--disabled-fill);
  background-image: none;
  border-color: transparent;
  color: var(--disabled-text);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}
@media (forced-colors: active) {
  .c-btn[disabled], .c-btn[aria-disabled="true"] { color: GrayText; border-color: GrayText; }
}

/* ============================================================================
   Display-preference bar (language segmented control + theme toggle). Shared by
   every page (auth card + settings topbar).
   ========================================================================== */
.pref-bar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.lang-switch {
  display: inline-flex;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: var(--bg-subtle);
}
.lang-switch .seg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3rem;
  min-height: var(--tap-target-min);
  padding-inline: var(--space-3);
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
}
.lang-switch .seg-active {
  background: var(--brand-primary);
  color: var(--text-on-brand);
}
.lang-switch .seg-active:hover { color: var(--text-on-brand); background: var(--brand-primary-hover); }
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--tap-target-min);
  min-height: var(--tap-target-min);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  background: var(--bg-subtle);
  color: var(--text-strong);
  text-decoration: none;
  font-size: 1.1rem;
  line-height: 1;
}
.theme-toggle:hover { background: var(--bg-muted); color: var(--text-strong); border-color: var(--border-interactive); }
/* Hover states + tasteful colour transitions on the pref controls (motion-gated). */
.lang-switch .seg:hover { color: var(--text-strong); background: var(--bg-muted); }
@media (prefers-reduced-motion: no-preference) {
  .lang-switch .seg, .theme-toggle {
    transition: background-color var(--duration-fast) var(--ease-standard),
                color var(--duration-fast) var(--ease-standard),
                border-color var(--duration-fast) var(--ease-standard);
  }
}

/* ============================================================================
   Auth-page card (login / bootstrap / mfa) — a polished, intentional entrance:
   the card is vertically centered on an on-brand subtle gradient (no bare form
   floating at the top), carries the brand lockup, and lifts on a comfortable
   surface card with a soft large shadow.
   ========================================================================== */
.auth-body {
  display: grid;
  place-items: center;
  min-block-size: 100dvh;
  padding-block: var(--space-6);
  background: var(--gradient-brand-subtle);
}
.card {
  width: 100%;
  max-width: 26rem;
  padding: var(--space-7) var(--space-6);
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.auth-card .pref-bar { justify-content: flex-end; margin-block-end: var(--space-5); }
.card h1 { margin-block-start: 0; font-size: 1.4rem; text-align: center; }
.card p { color: var(--text-muted); }
.card label { display: block; margin-block-start: var(--space-4); font-weight: 600; color: var(--text-strong); }
.card input, .card select {
  width: 100%;
  min-height: var(--tap-target-min);
  padding: var(--space-2) var(--space-3);
  margin-block-start: var(--space-1);
  font: inherit;
  background: var(--bg-canvas);
  color: var(--text-default);
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-sm);
}
@media (prefers-reduced-motion: no-preference) {
  .card input, .card select {
    transition: border-color var(--duration-fast) var(--ease-standard),
                box-shadow var(--duration-fast) var(--ease-standard);
  }
}
.card .c-btn { margin-block-start: var(--space-5); }
/* Bidi-isolate every token code cell: under the Arabic-RTL base direction an
   overflow wrap could reorder an LTR machine token's neutrals; the isolate is
   belt-and-suspenders with the dir="ltr" attribute on the cell. overflow-wrap:
   anywhere (W3C i18n guidance, preferred over word-break: break-all) only breaks
   the long otpauth URI / base32 key when it would otherwise overflow the narrow
   RTL card, and does not force breaks when the token already fits. */
.card code { overflow-wrap: anywhere; color: var(--text-strong); unicode-bidi: isolate; }
.error { color: var(--danger); font-weight: 600; }
.notice { color: var(--success-text); font-weight: 600; }
/* First-run step indicator (1/2 → 2/2): a small, muted, centered eyebrow above the
   setup heading so the owner always knows where they are in the two-step flow. */
.c-step { text-align: center; font-size: 0.8rem; font-weight: 600; letter-spacing: 0.04em; color: var(--text-muted); margin-block-end: var(--space-2); }
/* The "restart setup" affordance on the confirm screen: a secondary action that
   takes the owner back to a fresh STEP 1 to get a new key (used when enrollment
   could not be confirmed). Spaced from the primary confirm button above it. */
.c-restart { margin-block-start: var(--space-4); }

/* ============================================================================
   Settings page — topbar.
   ========================================================================== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  border-block-end: 1px solid var(--border-subtle);
  padding-block-end: var(--space-4);
  margin-block-end: var(--space-5);
  max-width: var(--container-max);
  margin-inline: auto;
}
/* Topbar brand cluster — the platform lockup beside the page heading. */
.topbar-brand { display: flex; align-items: center; gap: var(--space-4); min-width: 0; }
.topbar h1 { margin: 0; font-size: 1.5rem; }
.topbar-actions { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.console-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.console-nav-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-height-sm);
  padding-inline: var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
}
.console-nav-link:hover {
  color: var(--text-link);
  border-color: var(--border-interactive);
  background: var(--bg-subtle);
}
.console-nav-link-active {
  color: var(--text-link);
  border-color: var(--brand-primary);
  background: var(--selected-bg);
}
.inline { display: flex; align-items: center; gap: var(--space-3); margin: 0; flex-wrap: wrap; }
.who { color: var(--text-muted); font-size: 0.9rem; }

/* ============================================================================
   Settings page — responsive layout shell (sticky nav + main).
   ========================================================================== */
.settings-shell { max-width: var(--container-max); margin-inline: auto; }

.section-nav { margin-block-end: var(--space-5); }
.section-nav-title {
  margin: 0 0 var(--space-2);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-subtle);
}
.section-nav-list { list-style: none; margin: 0; padding: 0; }
.section-nav-link {
  display: flex;
  align-items: center;
  min-height: var(--tap-target-min);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-muted);
  font-weight: 500;
  border-inline-start: 3px solid transparent;
}
.section-nav-link:hover { background: var(--bg-subtle); color: var(--text-strong); }
.section-nav-link[aria-current="true"] {
  background: var(--selected-bg);
  color: var(--text-link);
  border-inline-start-color: var(--brand-primary);
  font-weight: 600;
}
@media (prefers-reduced-motion: no-preference) {
  .section-nav-link {
    transition: background-color var(--duration-fast) var(--ease-standard),
                color var(--duration-fast) var(--ease-standard),
                border-color var(--duration-fast) var(--ease-standard);
  }
}

.settings-main { min-width: 0; }
.page-intro { color: var(--text-muted); margin-block: 0 var(--space-5); max-width: 60ch; }
.flash { padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); font-weight: 600; margin-block: 0 var(--space-5); }
.flash-notice { color: var(--success-text); border: 1px solid var(--success); background: var(--success-bg); }
.flash-error { color: var(--danger); border: 1px solid var(--danger); background: var(--danger-bg); }

.settings-section {
  margin-block-end: var(--space-6);
  padding: var(--space-5);
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  scroll-margin-top: var(--console-scroll-offset);
}
.section-title { margin: 0 0 var(--space-1); font-size: 1.25rem; }
.section-desc { margin: 0 0 var(--space-4); color: var(--text-muted); font-size: 0.95rem; max-width: 70ch; }

.setting-list { display: flex; flex-direction: column; gap: var(--space-4); }
.setting-item {
  display: grid;
  grid-template-columns: minmax(14rem, 1fr) minmax(16rem, 1.2fr);
  gap: var(--space-4) var(--space-5);
  align-items: start;
  padding-block: var(--space-4);
  border-block-start: 1px solid var(--border-subtle);
}
.setting-item:first-child { border-block-start: none; padding-block-start: 0; }

.setting-meta { min-width: 0; }
.setting-label { display: block; font-weight: 600; margin-block-end: var(--space-1); color: var(--text-strong); }
.setting-desc { margin: 0 0 var(--space-2); color: var(--text-muted); font-size: 0.9rem; }
.setting-key { margin: 0; font-size: 0.8rem; color: var(--text-subtle); }
/* Bidi-isolate the dotted-key code cell (belt-and-suspenders with dir="ltr"). */
.setting-key code { color: var(--text-muted); unicode-bidi: isolate; }

.setting-control { min-width: 0; }
.control-form { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; margin: 0; }
.control-form input, .control-form select, .control-form textarea {
  flex: 1 1 12rem;
  min-width: 0;
  min-height: var(--tap-target-min);
  font: inherit;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-interactive);
  border-radius: var(--radius-sm);
  background: var(--bg-canvas);
  color: var(--text-default);
}
.control-form textarea { flex-basis: 100%; resize: vertical; line-height: 1.6; }
.control-form .c-btn { flex: 0 0 auto; }
@media (prefers-reduced-motion: no-preference) {
  .control-form input, .control-form select, .control-form textarea {
    transition: border-color var(--duration-fast) var(--ease-standard),
                box-shadow var(--duration-fast) var(--ease-standard);
  }
}

.secret-status { margin: 0 0 var(--space-2); color: var(--text-muted); font-size: 0.9rem; }
.badge { display: inline-block; padding: 0.1rem 0.6rem; border-radius: var(--radius-pill); font-size: 0.8rem; font-weight: 600; border: 1px solid currentColor; }
.badge-set { color: var(--success-text); }
.badge-unset { color: var(--text-subtle); }

/* ============================================================================
   Requests inbox.
   ========================================================================== */
.requests-main {
  display: block;
  max-width: var(--container-max);
}
.request-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-card);
  box-shadow: var(--shadow-sm);
}
.request-table {
  width: 100%;
  min-width: 58rem;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.request-table th,
.request-table td {
  padding: var(--space-3);
  border-block-end: 1px solid var(--border-subtle);
  text-align: start;
  vertical-align: top;
}
.request-table th {
  color: var(--text-muted);
  font-weight: 700;
  background: var(--bg-subtle);
}
.request-table tbody tr:last-child td { border-block-end: none; }
.request-number {
  color: var(--text-link);
  font-weight: 700;
  unicode-bidi: isolate;
}
.request-contact {
  display: grid;
  gap: var(--space-1);
  min-width: 12rem;
}
.request-contact a {
  color: var(--text-link);
  overflow-wrap: anywhere;
}
.request-status {
  display: inline-flex;
  align-items: center;
  min-height: 1.75rem;
  padding-inline: var(--space-2);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-weight: 700;
  white-space: nowrap;
}
.request-empty {
  padding-block: var(--space-7);
  color: var(--text-muted);
  text-align: center;
  font-weight: 700;
}
.pager {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-block-start: var(--space-4);
  flex-wrap: wrap;
}
.pager-current { color: var(--text-muted); font-weight: 700; }
.console-back-link {
  color: var(--text-link);
  font-weight: 700;
}
.request-detail {
  padding: var(--space-5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-card);
  box-shadow: var(--shadow-sm);
}
.request-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-block-end: var(--space-4);
}
.request-detail-list {
  display: grid;
  gap: var(--space-3);
  margin: 0 0 var(--space-5);
}
.request-detail-list div {
  display: grid;
  grid-template-columns: minmax(8rem, 0.25fr) minmax(0, 1fr);
  gap: var(--space-3);
  padding-block: var(--space-3);
  border-block-start: 1px solid var(--border-subtle);
}
.request-detail-list dt {
  color: var(--text-muted);
  font-weight: 700;
}
.request-detail-list dd {
  margin: 0;
  display: grid;
  gap: var(--space-1);
}
.request-message {
  padding: var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
}
.request-message h3 { margin-block: 0 var(--space-2); }
.request-message p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.8;
}

/* ============================================================================
   Responsive — DESKTOP (>=64rem): two-column shell, sticky sidebar nav. Logical
   properties put the sidebar on the RIGHT automatically under dir="rtl".
   ========================================================================== */
@media (min-width: 64rem) {
  .settings-shell {
    display: grid;
    grid-template-columns: 16rem minmax(0, 1fr);
    gap: var(--space-6);
    align-items: start;
  }
  .settings-shell.requests-main { display: block; }
  .section-nav {
    position: sticky;
    top: var(--console-scroll-offset);
    margin-block-end: 0;
    padding: var(--space-4);
    background: var(--bg-subtle);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
  }
}

/* TABLET / NARROW (<64rem): the nav becomes a sticky, horizontally-scrollable chip
   bar above the content. */
@media (max-width: 63.999rem) {
  .section-nav {
    position: sticky;
    top: 0;
    z-index: 5;
    padding-block: var(--space-2);
    background: var(--bg-canvas);
    border-block-end: 1px solid var(--border-subtle);
  }
  .section-nav-title { display: none; }
  .section-nav-list {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    padding-block-end: var(--space-1);
  }
  .section-nav-link {
    white-space: nowrap;
    border: 1px solid var(--border-default);
    border-inline-start: 1px solid var(--border-default);
    border-radius: var(--radius-pill);
  }
  .section-nav-link[aria-current="true"] { border-color: var(--brand-primary); }
}

/* MOBILE (<40rem): stack each setting's metadata above its control; tighten gutters. */
@media (max-width: 40rem) {
  body { padding: var(--space-4); }
  .setting-item { grid-template-columns: 1fr; gap: var(--space-3); }
  .topbar { gap: var(--space-3); }
  .control-form input, .control-form select { flex-basis: 100%; }
}
