/* ===================================================================
   AL-SAYYIDA — Global design system
   -------------------------------------------------------------------
   Mobile-first. Phone layout is the base; the sidebar shell is layered
   on at >=1025px. Authored with CSS logical properties throughout so
   the Arabic (RTL) and English (LTR) directions share one rule set —
   avoid physical left/right in new components.

   Structure
     1. Design tokens            6. Tables (incl. mobile card mode)
     2. Reset & base             7. Forms
     3. App shell                8. Feedback: badges, modals, toasts
     4. Buttons                  9. Page-specific shared pieces
     5. Cards & stats           10. Accessibility & motion
   =================================================================== */

/* ── 1. Design tokens ───────────────────────────────────────────── */

/* --- Palettes -------------------------------------------------------
   Each theme declares only raw --l-* (light) and --d-* (dark) pairs. The
   light/dark resolution below maps them onto the real tokens exactly once,
   so adding a palette never means duplicating the mode logic.

   Selected via <html data-theme="..."> and <html data-mode="light|dark">;
   with no data-mode the OS preference decides.                           */

:root,
:root[data-theme="alsayyida"] {
  /* Al-Sayyida — warm tan, antique gold, soft ivory (original brand) */
  --l-primary: #c49a6c;
  --d-primary: #d2a876;
  --l-primary-dark: #a67c52;
  --d-primary-dark: #bb8e5c;
  --l-primary-light: #e6d5c3;
  --d-primary-light: #4a3c2d;
  --l-primary-50: #faf5ef;
  --d-primary-50: #2a241e;
  --l-secondary: #2c2c2c;
  --d-secondary: #16130f;
  --l-accent: #d4af37;
  --d-accent: #e0bc50;
  --l-accent-soft: #f2e4bd;
  --d-accent-soft: #3d3321;

  --l-bg-main: #fcfaf7;
  --d-bg-main: #1a1714;
  --l-bg-card: #ffffff;
  --d-bg-card: #221e1a;
  --l-bg-subtle: #f7f2ec;
  --d-bg-subtle: #2a251f;
  --l-border: #ece4da;
  --d-border: #363029;
  --l-border-strong: #ddd2c4;
  --d-border-strong: #473f36;
  --l-text-main: #2e2a26;
  --d-text-main: #f0ebe4;
  --l-text-muted: #857b70;
  --d-text-muted: #a89e92;
  --l-text-faint: #a89e93;
  --d-text-faint: #7d7469;

  --l-ring: rgba(196, 154, 108, 0.28);
  --d-ring: rgba(210, 168, 118, 0.38);
  --shadow-tint: 74, 58, 42;
}

:root[data-theme="sunnah"] {
  /* Healing Sunnah — deep teal/emerald, warm wood, clean white */
  --l-primary: #0f766e;
  --d-primary: #2dd4bf;
  --l-primary-dark: #115e59;
  --d-primary-dark: #14b8a6;
  --l-primary-light: #cbefe9;
  --d-primary-light: #134e4a;
  --l-primary-50: #f0fdfa;
  --d-primary-50: #112e2b;
  --l-secondary: #13302c;
  --d-secondary: #081a18;
  --l-accent: #a9815a;
  --d-accent: #d6b483;
  --l-accent-soft: #f0e3d4;
  --d-accent-soft: #33281d;

  --l-bg-main: #f8faf9;
  --d-bg-main: #0f1a18;
  --l-bg-card: #ffffff;
  --d-bg-card: #16231f;
  --l-bg-subtle: #eef5f3;
  --d-bg-subtle: #1c2b27;
  --l-border: #dce9e6;
  --d-border: #273a35;
  --l-border-strong: #c0d8d2;
  --d-border-strong: #364b45;
  --l-text-main: #162a26;
  --d-text-main: #e8f2ef;
  --l-text-muted: #5f7571;
  --d-text-muted: #94aba6;
  --l-text-faint: #8ba39e;
  --d-text-faint: #6b827d;

  --l-ring: rgba(15, 118, 110, 0.26);
  --d-ring: rgba(45, 212, 191, 0.32);
  --shadow-tint: 16, 54, 48;
}

:root[data-theme="clinical"] {
  /* Clinical Wellness — deep navy, mint, muted ruby accent */
  --l-primary: #17395e;
  --d-primary: #6aa5d8;
  --l-primary-dark: #0f2742;
  --d-primary-dark: #4f8cc2;
  --l-primary-light: #d6e4f0;
  --d-primary-light: #1d3a52;
  --l-primary-50: #f2f7fb;
  --d-primary-50: #142532;
  --l-secondary: #0d1b2a;
  --d-secondary: #060d14;
  --l-accent: #9b1c3d;
  --d-accent: #e0718f;
  --l-accent-soft: #f7e3e8;
  --d-accent-soft: #3a1b25;

  --l-bg-main: #f7fafc;
  --d-bg-main: #0e151c;
  --l-bg-card: #ffffff;
  --d-bg-card: #151e27;
  --l-bg-subtle: #edf3f8;
  --d-bg-subtle: #1b2630;
  --l-border: #dce7ef;
  --d-border: #26323d;
  --l-border-strong: #c0d2e0;
  --d-border-strong: #35434f;
  --l-text-main: #142029;
  --d-text-main: #e7eef4;
  --l-text-muted: #5a6b7b;
  --d-text-muted: #98aaba;
  --l-text-faint: #8899a8;
  --d-text-faint: #6d8193;

  --l-ring: rgba(23, 57, 94, 0.25);
  --d-ring: rgba(106, 165, 216, 0.34);
  --shadow-tint: 13, 27, 42;
}

:root[data-theme="spa"] {
  /* Luxury Spa — muted plum, rose gold, off-white */
  --l-primary: #7a5b86;
  --d-primary: #b98fc9;
  --l-primary-dark: #5e4468;
  --d-primary-dark: #a074b0;
  --l-primary-light: #ebe0f0;
  --d-primary-light: #3d2d45;
  --l-primary-50: #faf6fb;
  --d-primary-50: #241b28;
  --l-secondary: #2b1f31;
  --d-secondary: #130d16;
  --l-accent: #b76e79;
  --d-accent: #d99aa4;
  --l-accent-soft: #f6e4e6;
  --d-accent-soft: #3a2429;

  --l-bg-main: #fdfbfd;
  --d-bg-main: #17121a;
  --l-bg-card: #ffffff;
  --d-bg-card: #1f1823;
  --l-bg-subtle: #f6f0f7;
  --d-bg-subtle: #271f2b;
  --l-border: #ebe2ed;
  --d-border: #332a38;
  --l-border-strong: #d7c8db;
  --d-border-strong: #453a4b;
  --l-text-main: #2b2430;
  --d-text-main: #f0e9f2;
  --l-text-muted: #786c7d;
  --d-text-muted: #ab9db0;
  --l-text-faint: #a496a8;
  --d-text-faint: #7d7182;

  --l-ring: rgba(122, 91, 134, 0.26);
  --d-ring: rgba(185, 143, 201, 0.34);
  --shadow-tint: 54, 38, 60;
}

/* --- Light/dark resolution (written once for every palette) ---------- */

:root {
  color-scheme: light;

  --primary: var(--l-primary);
  --primary-dark: var(--l-primary-dark);
  --primary-light: var(--l-primary-light);
  --primary-50: var(--l-primary-50);
  --secondary: var(--l-secondary);
  --accent: var(--l-accent);
  --accent-soft: var(--l-accent-soft);

  --bg-main: var(--l-bg-main);
  --bg-card: var(--l-bg-card);
  --bg-subtle: var(--l-bg-subtle);
  --border: var(--l-border);
  --border-strong: var(--l-border-strong);
  --text-main: var(--l-text-main);
  --text-muted: var(--l-text-muted);
  --text-faint: var(--l-text-faint);

  --success: #3f9c54;
  --success-bg: #e9f6ec;
  --warning: #e08a1e;
  --warning-bg: #fdf3e3;
  --error: #d64545;
  --error-bg: #fdecec;
  --info: #3a7ca5;
  --info-bg: #eaf3f8;

  --shadow-sm: 0 1px 2px rgba(var(--shadow-tint), 0.05);
  --shadow-md: 0 4px 14px rgba(var(--shadow-tint), 0.09);
  --shadow-lg: 0 12px 32px rgba(var(--shadow-tint), 0.13);
  --shadow-xl: 0 20px 48px rgba(var(--shadow-tint), 0.18);
  --ring: 0 0 0 3px var(--l-ring);

  /* Categorical tints — role chips, alert cards. Palette-independent, but
     they still need a dark variant or they glow white in dark mode. */
  --tint-violet: #f0e6ff;
  --tint-violet-fg: #5b3b8c;
  --tint-blue: #e6f4ff;
  --tint-blue-fg: #1b5e8c;
  --tint-amber: #fffde7;
  --tint-amber-fg: #7a5d00;
  --tint-rose: #ffcdd2;
  --tint-rose-fg: #9b1c2e;
}

/* Dark tokens, shared by the OS preference and the explicit override. */
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    color-scheme: dark;

    --primary: var(--d-primary);
    --primary-dark: var(--d-primary-dark);
    --primary-light: var(--d-primary-light);
    --primary-50: var(--d-primary-50);
    --secondary: var(--d-secondary);
    --accent: var(--d-accent);
    --accent-soft: var(--d-accent-soft);

    --bg-main: var(--d-bg-main);
    --bg-card: var(--d-bg-card);
    --bg-subtle: var(--d-bg-subtle);
    --border: var(--d-border);
    --border-strong: var(--d-border-strong);
    --text-main: var(--d-text-main);
    --text-muted: var(--d-text-muted);
    --text-faint: var(--d-text-faint);

    --success: #5cc072;
    --success-bg: #1d2f22;
    --warning: #f0a53c;
    --warning-bg: #332717;
    --error: #f06a6a;
    --error-bg: #351e1e;
    --info: #63a9d0;
    --info-bg: #1b2a33;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.6);
    --ring: 0 0 0 3px var(--d-ring);

    --tint-violet: #2e2340;
    --tint-violet-fg: #c9aef0;
    --tint-blue: #16293a;
    --tint-blue-fg: #8fc6ec;
    --tint-amber: #302a12;
    --tint-amber-fg: #e2c766;
    --tint-rose: #3a1d22;
    --tint-rose-fg: #f0a0a9;
  }
}

/* Explicit user choice. Must come after the media query to outrank it. */
:root[data-mode="dark"] {
  color-scheme: dark;

  --primary: var(--d-primary);
  --primary-dark: var(--d-primary-dark);
  --primary-light: var(--d-primary-light);
  --primary-50: var(--d-primary-50);
  --secondary: var(--d-secondary);
  --accent: var(--d-accent);
  --accent-soft: var(--d-accent-soft);

  --bg-main: var(--d-bg-main);
  --bg-card: var(--d-bg-card);
  --bg-subtle: var(--d-bg-subtle);
  --border: var(--d-border);
  --border-strong: var(--d-border-strong);
  --text-main: var(--d-text-main);
  --text-muted: var(--d-text-muted);
  --text-faint: var(--d-text-faint);

  --success: #5cc072;
  --success-bg: #1d2f22;
  --warning: #f0a53c;
  --warning-bg: #332717;
  --error: #f06a6a;
  --error-bg: #351e1e;
  --info: #63a9d0;
  --info-bg: #1b2a33;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.6);
  --ring: 0 0 0 3px var(--d-ring);

  --tint-violet: #2e2340;
  --tint-violet-fg: #c9aef0;
  --tint-blue: #16293a;
  --tint-blue-fg: #8fc6ec;
  --tint-amber: #302a12;
  --tint-amber-fg: #e2c766;
  --tint-rose: #3a1d22;
  --tint-rose-fg: #f0a0a9;
}

:root[data-mode="light"] {
  color-scheme: light;
}

:root {
  /* Radii */
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --radius-pill: 999px;

  /* Elevation — warm-tinted so shadows sit in the palette */
  --shadow-sm: 0 1px 2px rgba(74, 58, 42, 0.05);
  --shadow-md: 0 4px 14px rgba(74, 58, 42, 0.09);
  --shadow-lg: 0 12px 32px rgba(74, 58, 42, 0.13);
  --shadow-xl: 0 20px 48px rgba(74, 58, 42, 0.18);
  --ring: 0 0 0 3px rgba(196, 154, 108, 0.28);

  /* Type scale */
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-base: 0.9375rem;
  --fs-md: 1.0625rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 1.875rem;
  --font-ar: "Tajawal", "Inter", "Segoe UI", Tahoma, sans-serif;

  /* Spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;

  /* Shell metrics */
  --sidebar-w: 268px;
  --appbar-h: 58px;
  --bottomnav-h: 62px;
  --tap: 44px; /* minimum touch target */

  /* Safe areas (notch / home indicator) */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-start: env(safe-area-inset-left, 0px);
  --safe-end: env(safe-area-inset-right, 0px);

  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: all 0.15s ease;
}

/* Dark mode. Only tokens change — no component needs a dark variant. */
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #d2a876;
    --primary-dark: #bb8e5c;
    --primary-light: #4a3c2d;
    --primary-50: #2a241e;
    --secondary: #16130f;
    --accent: #e0bc50;
    --accent-soft: #3d3321;

    --bg-main: #1a1714;
    --bg-card: #221e1a;
    --bg-subtle: #2a251f;
    --border: #363029;
    --border-strong: #473f36;
    --text-main: #f0ebe4;
    --text-muted: #a89e92;
    --text-faint: #7d7469;

    --success-bg: #1d2f22;
    --warning-bg: #332717;
    --error-bg: #351e1e;
    --info-bg: #1b2a33;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 48px rgba(0, 0, 0, 0.6);
  }
}

/* ── 2. Reset & base ────────────────────────────────────────────── */

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

html {
  -webkit-text-size-adjust: 100%; /* stop iOS rotation text inflation */
}

body {
  font-family: var(--font-ar);
  background-color: var(--bg-main);
  color: var(--text-main);
  font-size: var(--fs-base);
  line-height: 1.6;
  min-height: 100dvh; /* dvh, so mobile browser chrome can't clip it */
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img,
svg {
  max-width: 100%;
  height: auto;
}

h1,
h2,
h3,
h4 {
  line-height: 1.3;
  font-weight: 700;
  color: var(--text-main);
}

a {
  color: var(--primary-dark);
}

/* Kill sticky :hover on touch screens — guarded throughout the file. */
@media (hover: none) {
  * {
    -webkit-tap-highlight-color: rgba(196, 154, 108, 0.18);
  }
}

/* ── 3. App shell ───────────────────────────────────────────────── */
/* Phone: fixed top app bar + off-canvas drawer + bottom tab bar.
   Desktop (>=1025px): persistent sidebar, no app bar, no tab bar.   */

/* --- Top app bar (phone/tablet only) --- */
.app-bar {
  position: fixed;
  top: 0;
  inset-inline: 0;
  z-index: 90;
  height: calc(var(--appbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  padding-inline: var(--sp-3);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  /* Opaque fallback first — browsers without color-mix() get a solid bar
     rather than a transparent one with unreadable text behind it. */
  background: var(--bg-card);
  background: color-mix(in srgb, var(--bg-card) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.app-bar-title {
  font-size: var(--fs-md);
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--accent);
  text-transform: uppercase;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Icon button — used in the app bar and as a generic compact control. */
.icon-btn {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-main);
  font-size: var(--fs-md);
  cursor: pointer;
  transition: var(--transition-fast);
}

.icon-btn:active {
  background: var(--bg-subtle);
  transform: scale(0.94);
}

@media (hover: hover) {
  .icon-btn:hover {
    background: var(--bg-subtle);
  }
}

/* Legacy hamburger: kept so existing markup works, restyled to sit in
   the app bar instead of floating over the page content. */
.menu-toggle {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--text-main);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--fs-md);
  cursor: pointer;
  position: fixed;
  top: calc(var(--safe-top) + 7px);
  inset-inline-start: var(--sp-3);
  z-index: 95;
  transition: var(--transition-fast);
}

.menu-toggle:active {
  background: var(--bg-subtle);
  transform: scale(0.94);
}

/* Once app.js relocates the hamburger into the app bar it becomes a normal
   flex child, so the title can sit beside it instead of underneath. */
.app-bar .menu-toggle {
  position: static;
  inset: auto;
  z-index: auto;
}

/* --- Sidebar / drawer --- */
.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  inset-inline-start: 0;
  z-index: 110;
  width: var(--sidebar-w);
  max-width: 86vw;
  padding: var(--sp-6) var(--sp-4);
  padding-top: calc(var(--sp-6) + var(--safe-top));
  padding-bottom: calc(var(--sp-4) + var(--safe-bottom));
  background: var(--secondary);
  color: #fff;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* Off-canvas by default (phone-first); slid in via .active */
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-xl);
}

[dir="rtl"] .sidebar {
  transform: translateX(100%);
}

.sidebar.active {
  transform: translateX(0);
}

.logo-area {
  margin-bottom: var(--sp-8);
  text-align: center;
}

.logo-text {
  font-size: var(--fs-lg);
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--accent);
  text-transform: uppercase;
}

.logo-area .brand-sub,
.logo-sub {
  display: block;
  margin-top: var(--sp-1);
  font-size: var(--fs-xs);
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.45);
}

.nav-links {
  list-style: none;
  flex-grow: 1;
}

.nav-item {
  margin-bottom: var(--sp-1);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap);
  padding: var(--sp-3) var(--sp-4);
  color: rgba(255, 255, 255, 0.72);
  text-decoration: none;
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: var(--transition-fast);
}

.nav-link i {
  font-size: var(--fs-md);
  width: 22px;
  text-align: center;
  flex: none;
}

.nav-link.active {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-md);
}

.nav-link:active {
  background: var(--primary-dark);
  color: #fff;
}

@media (hover: hover) {
  .nav-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
  }
  .nav-link.active:hover {
    background: var(--primary);
  }
}

/* Sign-out / footer area inside the drawer */
.sidebar-footer {
  margin-top: var(--sp-4);
  padding-top: var(--sp-4);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* --- Drawer scrim --- */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: 105;
  background: rgba(20, 14, 8, 0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.25s ease,
    visibility 0.25s ease;
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* --- Bottom tab bar (phones only) --- */
/* Primary navigation on phones: thumb-reachable, no drawer round-trip. */
.bottom-nav {
  position: fixed;
  bottom: 0;
  inset-inline: 0;
  z-index: 95;
  display: flex;
  align-items: stretch;
  height: calc(var(--bottomnav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-card);
  background: color-mix(in srgb, var(--bg-card) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
}

.bottom-nav-item {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--sp-1) 2px;
  text-decoration: none;
  color: var(--text-faint);
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 1.1;
  transition: var(--transition-fast);
  position: relative;
}

.bottom-nav-item i {
  font-size: 1.1875rem;
}

.bottom-nav-item span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bottom-nav-item.active {
  color: var(--primary-dark);
}

/* Small pill above the active tab's icon */
.bottom-nav-item.active::before {
  content: "";
  position: absolute;
  top: 0;
  width: 26px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--primary);
}

.bottom-nav-item:active {
  transform: scale(0.92);
}

/* --- Main content --- */
.main-content {
  flex-grow: 1;
  min-width: 0;
  padding: var(--sp-4);
  /* Clear the fixed app bar above and the tab bar below. */
  padding-top: calc(var(--appbar-h) + var(--safe-top) + var(--sp-4));
  padding-bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + var(--sp-6));
  padding-inline-start: calc(var(--sp-4) + var(--safe-start));
  padding-inline-end: calc(var(--sp-4) + var(--safe-end));
}

/* --- Page header --- */
.header {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

.welcome-msg h1 {
  font-size: var(--fs-xl);
  font-weight: 800;
  letter-spacing: -0.3px;
}

.welcome-msg p {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.header-actions .btn {
  flex: 1 1 auto;
  justify-content: center;
}

/* --- Desktop shell: swap drawer for a persistent sidebar --- */
@media (min-width: 1025px) {
  body {
    display: flex;
  }

  .sidebar {
    transform: none;
    box-shadow: none;
  }

  [dir="rtl"] .sidebar {
    transform: none;
  }

  .main-content {
    margin-inline-start: var(--sidebar-w);
    padding: var(--sp-8);
  }

  /* No app bar, no tab bar, no hamburger, no scrim on desktop. */
  .app-bar,
  .bottom-nav,
  .menu-toggle,
  .sidebar-overlay {
    display: none !important;
  }

  .header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--sp-8);
  }

  .header-actions .btn {
    flex: none;
  }

  .welcome-msg h1 {
    font-size: var(--fs-2xl);
  }
}

/* Tablets keep the drawer but drop the bottom bar (plenty of width). */
@media (min-width: 769px) and (max-width: 1024px) {
  .bottom-nav {
    display: none;
  }

  .main-content {
    padding-bottom: calc(var(--sp-8) + var(--safe-bottom));
  }
}

/* ── 4. Buttons ─────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: var(--sp-3) var(--sp-5);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-main);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition-fast);
  -webkit-user-select: none;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-outline {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-main);
}

.btn-ghost {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.btn-danger {
  background: var(--error);
  color: #fff;
}

.btn-success {
  background: var(--success);
  color: #fff;
}

/* Compact variant — still 36px tall, above the accidental-tap floor. */
.btn-sm {
  min-height: 36px;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-sm);
  border-radius: var(--radius-sm);
}

.btn-block {
  width: 100%;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

@media (hover: hover) {
  .btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
  }
  .btn-outline:hover,
  .btn-ghost:hover {
    background: var(--primary-50);
    border-color: var(--primary-light);
  }
  .btn-danger:hover {
    filter: brightness(0.93);
  }
  .btn-success:hover {
    filter: brightness(0.93);
  }
}

/* ── 5. Cards & stats ───────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-sm);
}

.card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  font-size: var(--fs-md);
  font-weight: 700;
  margin-bottom: var(--sp-4);
}

.content-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
}

/* Two-up stat tiles on phones — denser than one-per-row, still legible. */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

.stat-card {
  position: relative;
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-sm);
  transition: var(--transition-fast);
}

/* Accent edge on the inline-start side — flips automatically for RTL. */
.stat-card::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: 4px;
  background: var(--primary);
}

.stat-title {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.3px;
  display: block;
}

.stat-value {
  font-size: var(--fs-xl);
  font-weight: 800;
  margin: var(--sp-1) 0 0;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}

.stat-sub {
  font-size: var(--fs-xs);
  color: var(--text-faint);
}

@media (min-width: 560px) {
  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: var(--sp-4);
  }
}

@media (min-width: 1025px) {
  .card {
    padding: var(--sp-6);
  }
  .content-grid {
    grid-template-columns: 2fr 1fr;
    gap: var(--sp-6);
  }
  .stat-card {
    padding: var(--sp-5);
  }
  .stat-value {
    font-size: var(--fs-2xl);
  }
}

@media (hover: hover) {
  .stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
  }
}

/* ── 6. Tables ──────────────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
}

.appointment-list,
.patient-table,
.log-table,
.users-table,
.settings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-base);
}

thead th {
  text-align: start;
  padding: var(--sp-3);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: var(--sp-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

@media (hover: hover) {
  tbody tr:hover {
    background: var(--primary-50);
  }
}

/* Wrappers the pages use around wide tables — scroll, don't overflow. */
.appointments-table-wrap,
.users-table-wrap,
.settings-table-wrap,
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* --- Mobile card mode -------------------------------------------------
   Tables tagged .responsive-table by app.js stop being tables below
   768px and become one card per row, each cell labelled from its <th>
   (app.js copies the header text into td[data-label]). Horizontal
   scrolling on a phone is the thing being eliminated here.            */

@media (max-width: 768px) {
  table.responsive-table,
  table.responsive-table tbody,
  table.responsive-table tr,
  table.responsive-table td {
    display: block;
    width: 100%;
  }

  table.responsive-table thead {
    display: none;
  }

  table.responsive-table tr {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-2) var(--sp-3);
    margin-bottom: var(--sp-3);
  }

  table.responsive-table tr:last-child {
    margin-bottom: 0;
  }

  table.responsive-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-2) 0;
    border-bottom: 1px dashed var(--border);
    text-align: start;
  }

  table.responsive-table td:last-child {
    border-bottom: none;
  }

  /* The label, lifted off the <th> */
  table.responsive-table td::before {
    content: attr(data-label);
    flex: none;
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  /* A cell with no label (action buttons) spans the full width. */
  table.responsive-table td[data-label=""]::before,
  table.responsive-table td:not([data-label])::before {
    display: none;
  }

  table.responsive-table td.cell-actions {
    justify-content: stretch;
    padding-top: var(--sp-3);
  }

  table.responsive-table td.cell-actions > * {
    flex: 1 1 auto;
  }

  /* An empty-state row must not be chopped into labelled cells. */
  table.responsive-table tr.empty-row td,
  table.responsive-table td[colspan] {
    justify-content: center;
    text-align: center;
    border-bottom: none;
  }

  table.responsive-table tr.empty-row td::before,
  table.responsive-table td[colspan]::before {
    display: none;
  }

  /* The wrappers no longer need to scroll once rows are cards. */
  .appointments-table-wrap,
  .users-table-wrap,
  .settings-table-wrap,
  .table-wrap {
    overflow-x: visible;
  }
}

/* ── 7. Forms ───────────────────────────────────────────────────── */

.form-card {
  max-width: 820px;
  margin-inline: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-md);
}

.form-header {
  text-align: center;
  margin-bottom: var(--sp-6);
}

.form-header h2 {
  color: var(--primary-dark);
  font-size: var(--fs-lg);
  margin-bottom: var(--sp-1);
}

.form-header p {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.form-group label {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text-main);
}

/* 16px font-size is deliberate: anything smaller makes iOS Safari zoom
   the viewport on focus, which users then have to pinch back out. */
.form-control,
input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: var(--tap);
  padding: var(--sp-3) var(--sp-4);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-main);
  font-family: inherit;
  font-size: 16px;
  transition: var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
}

textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.6;
}

/* Native select needs its arrow back after appearance:none. */
select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% + 2px),
    calc(100% - 13px) calc(50% + 2px);
  background-size:
    5px 5px,
    5px 5px;
  background-repeat: no-repeat;
  padding-inline-end: var(--sp-8);
}

[dir="rtl"] select {
  background-position:
    18px calc(50% + 2px),
    13px calc(50% + 2px);
}

.form-control:focus,
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}

::placeholder {
  color: var(--text-faint);
}

/* Checkboxes & radios — enlarged for fingers */
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--sp-2);
  padding: var(--sp-3);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-4);
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--fs-base);
  transition: var(--transition-fast);
}

.checkbox-item:active {
  background: var(--primary-50);
}

.checkbox-item input[type="checkbox"],
.checkbox-item input[type="radio"] {
  width: 22px;
  height: 22px;
  min-height: 0;
  flex: none;
  accent-color: var(--primary);
  cursor: pointer;
}

.section-title {
  font-size: var(--fs-md);
  font-weight: 700;
  margin: var(--sp-6) 0 var(--sp-4);
  padding-bottom: var(--sp-2);
  border-bottom: 2px solid var(--primary-light);
}

.form-actions {
  display: flex;
  flex-direction: column-reverse;
  gap: var(--sp-3);
  margin-top: var(--sp-8);
}

.form-actions .btn {
  width: 100%;
}

/* Search box used on patients / appointments */
.search-box {
  position: relative;
}

.search-box i {
  position: absolute;
  inset-inline-start: var(--sp-4);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}

.search-box input {
  padding-inline-start: var(--sp-10);
}

@media (min-width: 769px) {
  .form-card {
    padding: var(--sp-10);
  }
  .form-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-6);
  }
  .form-header h2 {
    font-size: var(--fs-xl);
  }
  .form-actions {
    flex-direction: row;
    justify-content: space-between;
  }
  .form-actions .btn {
    width: auto;
  }
}

/* ── 8. Badges, modals, misc feedback ───────────────────────────── */

.status-badge,
.chip,
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  white-space: nowrap;
}

.status-confirmed,
.status-completed {
  background: var(--success-bg);
  color: var(--success);
}

.status-waiting,
.status-in-progress {
  background: var(--warning-bg);
  color: var(--warning);
}

.status-cancelled {
  background: var(--error-bg);
  color: var(--error);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.dot-free {
  background: var(--success);
  box-shadow: 0 0 0 3px var(--success-bg);
}

.dot-busy {
  background: var(--error);
  box-shadow: 0 0 0 3px var(--error-bg);
}

/* --- Modals: bottom sheet on phones, centred dialog on desktop --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  background: rgba(20, 14, 8, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.active,
.modal-overlay[style*="flex"] {
  display: flex;
}

.modal {
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-card);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--sp-5);
  padding-bottom: calc(var(--sp-5) + var(--safe-bottom));
  box-shadow: var(--shadow-xl);
  animation: sheet-up 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Grab handle, so the sheet reads as draggable/dismissable */
.modal::before {
  content: "";
  display: block;
  width: 38px;
  height: 4px;
  margin: 0 auto var(--sp-4);
  border-radius: var(--radius-pill);
  background: var(--border-strong);
}

@keyframes sheet-up {
  from {
    transform: translateY(14%);
    opacity: 0.6;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  font-size: var(--fs-md);
  font-weight: 700;
}

.modal-close {
  width: var(--tap);
  height: var(--tap);
  flex: none;
  display: grid;
  place-items: center;
  border: none;
  border-radius: var(--radius-md);
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: var(--fs-md);
  cursor: pointer;
}

.modal-actions {
  display: flex;
  flex-direction: column-reverse;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}

.modal-actions .btn {
  width: 100%;
}

@media (min-width: 769px) {
  .modal-overlay {
    align-items: center;
  }
  .modal {
    max-width: 520px;
    max-height: 86dvh;
    border-radius: var(--radius-xl);
    padding-bottom: var(--sp-5);
    animation: dialog-in 0.22s ease;
  }
  .modal::before {
    display: none;
  }
  .modal-actions {
    flex-direction: row;
    justify-content: flex-end;
  }
  .modal-actions .btn {
    width: auto;
  }
  @keyframes dialog-in {
    from {
      transform: scale(0.97);
      opacity: 0;
    }
    to {
      transform: scale(1);
      opacity: 1;
    }
  }
}

/* --- Tabs: horizontally scrollable, snapping, no visible scrollbar --- */
.tab-nav,
.settings-tabs {
  display: flex;
  gap: var(--sp-5);
  margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tab-nav::-webkit-scrollbar,
.settings-tabs::-webkit-scrollbar {
  display: none;
}

.tab-item,
.settings-tab {
  position: relative;
  flex: none;
  scroll-snap-align: start;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  padding: var(--sp-2) 0;
  font-weight: 700;
  font-size: var(--fs-base);
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  background: none;
  border: none;
  font-family: inherit;
}

.tab-item.active,
.settings-tab.active {
  color: var(--primary-dark);
}

.tab-item.active::after,
.settings-tab.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  inset-inline: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--primary);
}

/* --- Waiting room cards --- */
.waiting-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
}

.waiting-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--sp-3);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  transition: var(--transition-fast);
}

.waiting-card .btn {
  width: 100%;
}

.waiting-info h4 {
  font-size: var(--fs-base);
  margin-bottom: 2px;
}

.waiting-info span {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

@media (min-width: 560px) {
  .waiting-grid {
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  }
  .waiting-card {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .waiting-card .btn {
    width: auto;
  }
}

@media (hover: hover) {
  .waiting-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
  }
}

.pulse-timer {
  display: inline-block;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: var(--warning-bg);
  color: var(--warning);
  font-weight: 700;
  font-size: var(--fs-xs);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.06);
    opacity: 0.85;
  }
}

.specialist-status {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap);
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-2);
  font-size: var(--fs-base);
}

/* --- Reminders --- */
.reminder-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--primary-50);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-2);
}

.reminder-icon {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 50%;
}

.reminder-info h4 {
  font-size: var(--fs-sm);
  margin-bottom: 2px;
}

.reminder-info p {
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

/* --- Empty states --- */
.empty-state {
  text-align: center;
  padding: var(--sp-8) var(--sp-4);
  color: var(--text-muted);
}

.empty-state i {
  font-size: 2.25rem;
  color: var(--border-strong);
  margin-bottom: var(--sp-3);
  display: block;
}

/* --- Skeleton loading shimmer --- */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-subtle) 25%,
    var(--border) 37%,
    var(--bg-subtle) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: var(--radius-sm);
  color: transparent !important;
}

@keyframes shimmer {
  from {
    background-position: 100% 50%;
  }
  to {
    background-position: 0 50%;
  }
}

/* ── 9. Page-specific shared pieces ─────────────────────────────── */

.details-grid,
.treatment-container,
.session-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
}

@media (min-width: 1025px) {
  .details-grid {
    grid-template-columns: 1fr 2fr;
    gap: var(--sp-6);
  }
  .treatment-container,
  .session-layout {
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-6);
  }
}

/* Body maps (specialist / guest): stack on phones, side-by-side later */
.body-maps,
.maps-container,
.maps-row,
.mini-maps {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
  justify-content: center;
}

.map-wrapper,
.map-wrap,
.map-col {
  width: 100%;
  max-width: 280px;
}

.body-map-container {
  background: var(--bg-subtle);
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  min-height: 240px;
  display: grid;
  place-items: center;
  margin-bottom: var(--sp-5);
  color: var(--text-muted);
}

/* Floating language toggle. Lifted above the bottom tab bar on phones. */
.lang-toggle {
  position: fixed;
  inset-inline-start: var(--sp-4);
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + var(--sp-3));
  z-index: 96;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 40px;
  padding: var(--sp-2) var(--sp-4);
  background: var(--secondary);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: var(--transition-fast);
}

.lang-toggle i {
  font-size: var(--fs-base);
  color: var(--accent);
}

.lang-toggle:active {
  transform: scale(0.95);
}

@media (hover: hover) {
  .lang-toggle:hover {
    background: var(--primary);
  }
}

/* No bottom bar from tablet up — drop the toggle back to the corner. */
@media (min-width: 769px) {
  .lang-toggle {
    bottom: calc(var(--sp-5) + var(--safe-bottom));
  }
}

/* ── 9b. Appearance picker ──────────────────────────────────────── */
/* Floating control beside the language toggle. Each user's choice is saved
   to their own account, so a shared workstation still shows the right look
   per login.                                                              */

.theme-toggle {
  position: fixed;
  inset-inline-start: calc(var(--sp-4) + 92px);
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + var(--sp-3));
  z-index: 96;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 40px;
  padding: var(--sp-2) var(--sp-4);
  background: var(--secondary);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: var(--transition-fast);
}

.theme-toggle i {
  font-size: var(--fs-base);
  color: var(--accent);
}

.theme-toggle:active {
  transform: scale(0.95);
}

@media (hover: hover) {
  .theme-toggle:hover {
    background: var(--primary);
  }
}

@media (min-width: 769px) {
  .theme-toggle {
    bottom: calc(var(--sp-5) + var(--safe-bottom));
  }
}

/* --- Sheet --- */
.appearance-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(20, 14, 8, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.appearance-sheet-overlay.active {
  display: flex;
}

.appearance-sheet {
  width: 100%;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--bg-card);
  color: var(--text-main);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--sp-5);
  padding-bottom: calc(var(--sp-5) + var(--safe-bottom));
  box-shadow: var(--shadow-xl);
  animation: sheet-up 0.28s cubic-bezier(0.32, 0.72, 0, 1);
}

.appearance-sheet::before {
  content: "";
  display: block;
  width: 38px;
  height: 4px;
  margin: 0 auto var(--sp-4);
  border-radius: var(--radius-pill);
  background: var(--border-strong);
}

@media (min-width: 769px) {
  .appearance-sheet-overlay {
    align-items: center;
  }
  .appearance-sheet {
    max-width: 460px;
    border-radius: var(--radius-xl);
    padding-bottom: var(--sp-5);
  }
  .appearance-sheet::before {
    display: none;
  }
}

.appearance-title {
  font-size: var(--fs-md);
  font-weight: 800;
  margin-bottom: var(--sp-1);
}

.appearance-label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: var(--sp-5) 0 var(--sp-3);
}

/* --- Palette swatches --- */
.theme-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--sp-3);
}

.theme-option {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap);
  padding: var(--sp-3);
  background: var(--bg-subtle);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: start;
  font-family: inherit;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text-main);
  transition: var(--transition-fast);
}

.theme-option[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--primary-50);
}

.theme-option:active {
  transform: scale(0.98);
}

/* Three dots previewing the palette, rendered from that theme's own tokens. */
.swatch {
  flex: none;
  display: inline-flex;
  gap: 3px;
}

.swatch span {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

/* --- Light / dark / auto --- */
.mode-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
}

.mode-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  min-height: 62px;
  padding: var(--sp-2);
  background: var(--bg-subtle);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-main);
  transition: var(--transition-fast);
}

.mode-option i {
  font-size: var(--fs-md);
  color: var(--text-muted);
}

.mode-option[aria-pressed="true"] {
  border-color: var(--primary);
  background: var(--primary-50);
}

.mode-option[aria-pressed="true"] i {
  color: var(--primary);
}

.appearance-status {
  margin-top: var(--sp-4);
  font-size: var(--fs-sm);
  min-height: 1.2em;
}

/* ── 10. Accessibility & motion ─────────────────────────────────── */

/* Visible focus for keyboard users only. */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.nav-link:focus-visible,
.bottom-nav-item:focus-visible {
  outline-color: var(--accent);
}

/* Screen-reader-only text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Lock background scroll while a drawer or sheet is open. */
body.no-scroll {
  overflow: hidden;
}

@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;
  }
}

/* ── 11. Overrides for page-level <style> blocks ────────────────────
   Each page carries its own inline <style>, which loads after this file
   and therefore wins at equal specificity. These rules are deliberately
   one step more specific (two classes, or class+element) so the mobile
   treatment lands without needing !important or edits in nine files.
   =================================================================== */

/* Pages toggle their modals with .open; keep .active working too. */
.modal-overlay.open,
.modal-overlay.active {
  display: flex;
}

@media (max-width: 768px) {
  /* Centred dialogs become bottom sheets: reachable by thumb, and they
     don't get shoved off-screen by the on-screen keyboard. */
  .modal-overlay.open,
  .modal-overlay.active {
    align-items: flex-end;
    padding: 0;
  }

  .modal-overlay .modal {
    max-width: none;
    width: 100%;
    max-height: 92dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: var(--sp-5);
    padding-bottom: calc(var(--sp-5) + var(--safe-bottom));
  }

  /* Stack modal buttons full-width — side-by-side they end up too narrow
     to hit reliably once there are three of them. */
  .modal .modal-actions {
    flex-direction: column-reverse;
    gap: var(--sp-2);
  }

  .modal .modal-actions .btn,
  .modal .modal-actions button {
    width: 100%;
    min-height: var(--tap);
  }

  /* Row action buttons: the pages set these as small as 4px/0.75rem,
     which is roughly a 24px target — half the accidental-tap floor. */
  .btn.btn-sm,
  .action-btns .btn,
  .action-btns button,
  td button,
  td .btn {
    min-height: 40px;
    padding: var(--sp-2) var(--sp-4);
    font-size: var(--fs-sm);
    border-radius: var(--radius-sm);
  }

  .action-btns {
    display: flex;
    gap: var(--sp-2);
    width: 100%;
  }

  .action-btns > * {
    flex: 1 1 auto;
  }

  /* Card-mode rows supply their own surface, so the wrapper must not add
     a second card border around the stack. */
  div.appointments-table-wrap,
  div.users-table-wrap,
  div.settings-table-wrap {
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }

  /* Toolbars stack rather than squeezing a search field and two selects
     onto one 360px line. */
  .toolbar,
  .search-container,
  .results-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
  }

  .toolbar > *,
  .search-container > * {
    width: 100%;
  }
}

/* Desktop: the page sets overflow:hidden on table wrappers, which clips a
   wide table instead of letting it scroll. */
@media (min-width: 769px) {
  div.appointments-table-wrap,
  div.users-table-wrap,
  div.settings-table-wrap {
    overflow-x: auto;
  }
}

@media print {
  .sidebar,
  .app-bar,
  .bottom-nav,
  .menu-toggle,
  .lang-toggle,
  .sidebar-overlay,
  .header-actions {
    display: none !important;
  }
  .main-content {
    margin: 0;
    padding: 0;
  }
  .card,
  .stat-card {
    box-shadow: none;
    border: 1px solid #ccc;
  }
}
