:root {
  /* --app-zoom mirrors the Font Size setting (0.8–1.5); the viewport units are
     pre-divided by it so `zoom` on <body> does not inflate vh/vw-based sizes. */
  --app-zoom: 1;
  --vh: calc(1vh / var(--app-zoom));
  --dvh: calc(1dvh / var(--app-zoom));
  --vw: calc(1vw / var(--app-zoom));

  /* Photo-scrim colour intensity, driven by the admin "Colour intensity"
     slider (pharmacy_settings.hero_vibrancy, 50 = as designed). */
  --hero-sat: 1.1;
  --hero-bright: 1.075;

  /* Tile-photo transparency, driven by the admin "Photo transparency" slider
     (pharmacy_settings.tile_image_opacity, 60 = soft default, 100 = full photo). */
  --tile-img-op: 0.6;

  /* Native form controls (checkbox, radio, range, date picker, progress) take
     their tint from `accent-color`, which INHERITS — so declaring it once on
     :root themes every control app-wide and tracks the active brand. Without
     it the OS supplies its own accent (Android Material-You painted ours
     green on the owner's phone), which reads as an off-brand UI. */
  accent-color: var(--primary);

  /* Govind Diagnostics brand palette: orange primary + health-green accent on a warm wash.
     Light is the product default; [data-theme="dark"] is the refined night mode. */
  --bg: #FFF8F0;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(255,165,0,0.10), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(255,140,0,0.08), transparent 55%);
  --surface: #FFFFFF;
  --surface-hover: #FFFDF8;
  --surface-active: #FFF3E0;
  /* Brand fills carry WHITE text (buttons, chips, active tabs). Orange-600 clears 4.5:1 with white. */
  --primary: #FF6B35;
  --primary-dark: #E05A1A;
  --primary-glow: rgba(255,107,53,0.34);
  --primary-surface: rgba(255,107,53,0.14);
  --accent: #047857;
  --accent-surface: rgba(4,120,87,0.10);
  /* Text colour used ON TOP of brand-coloured fills (buttons, active chips,
     hero blocks). White on the deep teal/indigo/ocean fills; the vivid orange
     brand re-defines it to a warm near-black because white on #FFA500 fails
     legibility badly. Everything that paints white-on-brand reads this token. */
  --on-brand: #FFFFFF;
  --on-brand-soft: rgba(255,255,255,0.90);
  --on-brand-muted: rgba(255,255,255,0.74);
  --text: #0E2E2A;
  --text-secondary: rgba(14,46,42,0.74);
  --text-muted: rgba(14,46,42,0.55);
  --border: rgba(15,118,110,0.16);
  --border-strong: rgba(15,118,110,0.30);
  /* Semantic colours are used both as small text (badges, stock/status lines,
     prices, inline warnings) and as solid fills with white text. The original
     mid-tone values (#DC2626 / #059669 / #0891B2) only reached ~3.3–4.0:1 as
     text on white and on their own pale *-surface badge backgrounds — the
     "same-colour-on-same-colour" legibility problem. These deeper 700-shades
     clear WCAG AA (≥4.5:1) as text while white-on-solid only improves. Dark
     mode redefines them lighter below; brand themes inherit these. */
  --error: #B91C1C;
  --error-surface: rgba(185,28,28,0.10);
  --warning: #92400E;
  --warning-surface: rgba(146,64,14,0.12);
  --success: #047857;
  --success-surface: rgba(4,120,87,0.12);
  --info: #0E7490;
  --info-surface: rgba(14,116,144,0.12);

  /* Semantic text aliases. Several components reference --text-primary and
     --text-error, which were never defined — an undefined var() makes the whole
     color declaration invalid, so the text silently inherited its parent colour
     (e.g. error messages rendering dark-teal instead of red, selected chips and
     help links picking up whatever colour was around them). Aliasing them to the
     themed tokens keeps them correct in light, dark and every brand theme. */
  --text-primary: var(--text);
  --text-error: var(--error);
  --text-success: var(--success);
  --text-warning: var(--warning);
  --text-info: var(--info);
  /* Several components reference --danger (rejection borders, confirm modals).
     It was never defined, so `var(--danger, #FF5A5F)` silently fell back to a
     cold red that ignores the active brand. Alias it to the themed error. */
  --danger: var(--error);

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --radius-full: 100px;

  /* Soft, layered elevation (calm clinical depth, not heavy black shadows). */
  --shadow-sm: 0 1px 2px rgba(16,24,40,0.06), 0 1px 3px rgba(16,24,40,0.08);
  --shadow-md: 0 4px 6px -1px rgba(16,24,40,0.07), 0 10px 20px -6px rgba(88,88,76,0.14);
  --shadow-lg: 0 12px 24px -8px rgba(88,88,76,0.18), 0 24px 48px -12px rgba(16,24,40,0.14);
  --shadow-glow: 0 8px 24px var(--primary-glow);

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);

  --font-display: 'Lexend', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Source Sans 3', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  --font-xs: 12px;
  --font-sm: 14px;
  --font-md: 16px;
  --font-lg: 18px;
  --font-xl: 20px;
  --font-2xl: 24px;
  --font-3xl: 28px;
  --font-4xl: 32px;
  --font-5xl: 36px;

  --z-base: 1;
  --z-dropdown: 100;
  /* Fixed chrome (tab bar / sidebar) must sit BELOW modals, or it covers the
     sheet's bottom action button on phones. */
  --z-nav: 150;
  --z-modal: 200;
  --z-toast: 300;
}

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

/* Chrome on Android force-darkens any page that does not signal dark-mode
   support, muddying the designed light UI (orange tiles read red, everything
   dim). When the OS is dark, declare dual support so Chrome leaves the page
   alone; the app's own Light/Dark/System choice still wins via [data-theme]. */
@media (prefers-color-scheme: dark) {
  :root { color-scheme: light dark; }
}

/* ===== Brand themes (light) =====
   Every brand palette follows the exact gold-standard structure of the orange theme:
   vivid primary, deep gradient anchor, matching warm/cool tinted canvas, tuned
   hover/active surfaces, tinted typography, glowing borders and layered shadows. */

/* Orange — product benchmark */
[data-brand="orange"] {
  --bg: #FFF7ED;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(255,165,0,0.16), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(255,140,0,0.12), transparent 55%);
  --surface-hover: #FFFBF5;
  --surface-active: #FFEDD5;
  --primary: #FFA500;
  --primary-dark: #E08900;
  --primary-glow: rgba(255,165,0,0.34);
  --primary-surface: rgba(255,165,0,0.14);
  --accent: #FFC24D;
  --accent-surface: rgba(255,194,77,0.16);
  --on-brand: #331A00;
  --on-brand-soft: rgba(51,26,0,0.86);
  --on-brand-muted: rgba(51,26,0,0.66);
  --text: #431407;
  --text-secondary: rgba(67,20,7,0.74);
  --text-muted: rgba(67,20,7,0.55);
  --border: rgba(224,137,0,0.22);
  --border-strong: rgba(224,137,0,0.40);
  --shadow-md: 0 4px 6px -1px rgba(16,24,40,0.07), 0 10px 20px -6px rgba(255,165,0,0.20);
  --shadow-lg: 0 12px 24px -8px rgba(255,165,0,0.26), 0 24px 48px -12px rgba(16,24,40,0.14);
}

/* Emerald — Teal & Medical Green */
[data-brand="emerald"] {
  --bg: #F0FDF4;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(13,148,136,0.16), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(16,185,129,0.12), transparent 55%);
  --surface-hover: #F6FEF9;
  --surface-active: #DCFCE7;
  --primary: #0D9488;
  --primary-dark: #0F766E;
  --primary-glow: rgba(13,148,136,0.34);
  --primary-surface: rgba(13,148,136,0.14);
  --accent: #10B981;
  --accent-surface: rgba(16,185,129,0.16);
  --on-brand: #FFFFFF;
  --on-brand-soft: rgba(255,255,255,0.92);
  --on-brand-muted: rgba(255,255,255,0.76);
  --text: #064E3B;
  --text-secondary: rgba(6,78,59,0.74);
  --text-muted: rgba(6,78,59,0.55);
  --border: rgba(13,148,136,0.22);
  --border-strong: rgba(13,148,136,0.40);
  --shadow-md: 0 4px 6px -1px rgba(16,24,40,0.07), 0 10px 20px -6px rgba(13,148,136,0.20);
  --shadow-lg: 0 12px 24px -8px rgba(13,148,136,0.26), 0 24px 48px -12px rgba(16,24,40,0.14);
}

/* Govind — Premium Botanical Olive with Warm Amber Accent */
[data-brand="govind"] {
  --bg: #F5F6F0;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(74,85,56,0.16), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(245,131,32,0.12), transparent 55%);
  --surface-hover: #FAFBF7;
  --surface-active: #E7EADF;
  --primary: #4A5538;
  --primary-dark: #363E28;
  --primary-glow: rgba(74,85,56,0.34);
  --primary-surface: rgba(74,85,56,0.14);
  --accent: #F58320;
  --accent-surface: rgba(245,131,32,0.16);
  --on-brand: #FFFFFF;
  --on-brand-soft: rgba(255,255,255,0.92);
  --on-brand-muted: rgba(255,255,255,0.76);
  --text: #1F2417;
  --text-secondary: rgba(31,36,23,0.74);
  --text-muted: rgba(31,36,23,0.55);
  --border: rgba(74,85,56,0.22);
  --border-strong: rgba(74,85,56,0.40);
  --shadow-md: 0 4px 6px -1px rgba(16,24,40,0.07), 0 10px 20px -6px rgba(74,85,56,0.20);
  --shadow-lg: 0 12px 24px -8px rgba(74,85,56,0.26), 0 24px 48px -12px rgba(16,24,40,0.14);
}

/* Indigo — Royal Tech & Modern Clinical */
[data-brand="indigo"] {
  --bg: #EEF2FF;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(79,70,229,0.16), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(124,58,237,0.12), transparent 55%);
  --surface-hover: #F8FAFF;
  --surface-active: #E0E7FF;
  --primary: #4F46E5;
  --primary-dark: #4338CA;
  --primary-glow: rgba(79,70,229,0.34);
  --primary-surface: rgba(79,70,229,0.14);
  --accent: #7C3AED;
  --accent-surface: rgba(124,58,237,0.16);
  --on-brand: #FFFFFF;
  --on-brand-soft: rgba(255,255,255,0.92);
  --on-brand-muted: rgba(255,255,255,0.76);
  --text: #1E1B4B;
  --text-secondary: rgba(30,27,75,0.74);
  --text-muted: rgba(30,27,75,0.55);
  --border: rgba(79,70,229,0.22);
  --border-strong: rgba(79,70,229,0.40);
  --shadow-md: 0 4px 6px -1px rgba(16,24,40,0.07), 0 10px 20px -6px rgba(79,70,229,0.20);
  --shadow-lg: 0 12px 24px -8px rgba(79,70,229,0.26), 0 24px 48px -12px rgba(16,24,40,0.14);
}

/* Ocean — Azure & Sky Blue */
[data-brand="ocean"] {
  --bg: #F0F9FF;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(2,132,199,0.16), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(6,182,212,0.12), transparent 55%);
  --surface-hover: #F7FCFF;
  --surface-active: #E0F2FE;
  --primary: #0284C7;
  --primary-dark: #0369A1;
  --primary-glow: rgba(2,132,199,0.34);
  --primary-surface: rgba(2,132,199,0.14);
  --accent: #06B6D4;
  --accent-surface: rgba(6,182,212,0.16);
  --on-brand: #FFFFFF;
  --on-brand-soft: rgba(255,255,255,0.92);
  --on-brand-muted: rgba(255,255,255,0.76);
  --text: #082F49;
  --text-secondary: rgba(8,47,73,0.74);
  --text-muted: rgba(8,47,73,0.55);
  --border: rgba(2,132,199,0.22);
  --border-strong: rgba(2,132,199,0.40);
  --shadow-md: 0 4px 6px -1px rgba(16,24,40,0.07), 0 10px 20px -6px rgba(2,132,199,0.20);
  --shadow-lg: 0 12px 24px -8px rgba(2,132,199,0.26), 0 24px 48px -12px rgba(16,24,40,0.14);
}

/* Coral — Energetic Vivid Coral & Warm Rose Glow */
[data-brand="coral"] {
  --bg: #FFF1F2;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(225,29,72,0.16), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(251,113,133,0.12), transparent 55%);
  --surface-hover: #FFF8F9;
  --surface-active: #FFE4E6;
  --primary: #E11D48;
  --primary-dark: #BE123C;
  --primary-glow: rgba(225,29,72,0.34);
  --primary-surface: rgba(225,29,72,0.14);
  --accent: #FB7185;
  --accent-surface: rgba(251,113,133,0.16);
  --on-brand: #FFFFFF;
  --on-brand-soft: rgba(255,255,255,0.92);
  --on-brand-muted: rgba(255,255,255,0.76);
  --text: #4C0519;
  --text-secondary: rgba(76,5,25,0.74);
  --text-muted: rgba(76,5,25,0.55);
  --border: rgba(225,29,72,0.22);
  --border-strong: rgba(225,29,72,0.40);
  --shadow-md: 0 4px 6px -1px rgba(16,24,40,0.07), 0 10px 20px -6px rgba(225,29,72,0.20);
  --shadow-lg: 0 12px 24px -8px rgba(225,29,72,0.26), 0 24px 48px -12px rgba(16,24,40,0.14);
  --success: #9F1239;
  --success-surface: rgba(159,18,57,0.12);
  --info: #BE123C;
  --info-surface: rgba(190,18,60,0.12);
  --warning: #881337;
  --warning-surface: rgba(136,19,55,0.12);
  --error: #881337;
  --error-surface: rgba(136,19,55,0.12);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #061411;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(45,212,191,0.10), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(8,145,178,0.08), transparent 55%);
  --surface: rgba(255,255,255,0.06);
  --surface-hover: rgba(255,255,255,0.09);
  --surface-active: rgba(255,255,255,0.13);
  --primary: #2DD4BF;
  --primary-dark: #14B8A6;
  --primary-glow: rgba(45,212,191,0.30);
  --primary-surface: rgba(45,212,191,0.12);
  --accent: #34D399;
  --accent-surface: rgba(52,211,153,0.12);
  /* Night-mode primaries are LIGHT tints, so brand fills carry dark type. */
  --on-brand: #06201B;
  --on-brand-soft: rgba(6,32,27,0.86);
  --on-brand-muted: rgba(6,32,27,0.66);
  --text: #E7F6F3;
  --text-secondary: rgba(231,246,243,0.74);
  --text-muted: rgba(231,246,243,0.55);
  --border: rgba(255,255,255,0.10);
  --border-strong: rgba(255,255,255,0.20);
  --error: #F87171;
  --error-surface: rgba(248,113,113,0.12);
  --warning: #FBBF24;
  --warning-surface: rgba(251,191,36,0.12);
  --success: #34D399;
  --success-surface: rgba(52,211,153,0.12);
  --info: #22D3EE;
  --info-surface: rgba(34,211,238,0.12);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4), 0 10px 20px -6px rgba(0,0,0,0.5);
  --shadow-lg: 0 12px 24px -8px rgba(0,0,0,0.55), 0 24px 48px -12px rgba(0,0,0,0.6);
  --shadow-glow: 0 8px 24px var(--primary-glow);
}

/* ===== Brand themes (dark) =====
   Re-tint the night palette per brand. These sit AFTER [data-theme="dark"] so
   they win when both attributes are present. */

/* Orange (dark) — the night orange deliberately stays ORANGE. Android Chrome
   force-dark used to shift the warm accent toward red; a true orange-400 primary
   on a warm (not black-red) base reads as orange, and color-scheme:dark plus the
   prefers-dark `color-scheme: light dark` opt-out stop Chrome recolouring it. */
[data-theme="dark"][data-brand="orange"] {
  color-scheme: dark;
  --bg: #1A0E06;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(255,165,0,0.16), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(255,140,0,0.12), transparent 55%);
  --primary: #FFA500;
  --primary-dark: #E08900;
  --primary-glow: rgba(255,165,0,0.36);
  --primary-surface: rgba(255,165,0,0.16);
  --accent: #FFC24D;
  --accent-surface: rgba(255,194,77,0.16);
  --on-brand: #2A1500;
  --on-brand-soft: rgba(42,21,0,0.86);
  --on-brand-muted: rgba(42,21,0,0.66);
  --text: #FFF3E8;
  --text-secondary: rgba(255,243,232,0.74);
  --text-muted: rgba(255,243,232,0.55);
}

[data-theme="dark"][data-brand="emerald"] {
  color-scheme: dark;
  --bg: #041714;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(13,148,136,0.16), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(16,185,129,0.12), transparent 55%);
  --primary: #14B8A6;
  --primary-dark: #0D9488;
  --primary-glow: rgba(20,184,166,0.36);
  --primary-surface: rgba(20,184,166,0.16);
  --accent: #34D399;
  --accent-surface: rgba(52,211,153,0.16);
  --on-brand: #02251F;
  --on-brand-soft: rgba(2,37,31,0.86);
  --on-brand-muted: rgba(2,37,31,0.66);
  --text: #E6FBF7;
  --text-secondary: rgba(230,251,247,0.74);
  --text-muted: rgba(230,251,247,0.55);
}

[data-theme="dark"][data-brand="govind"] {
  color-scheme: dark;
  --bg: #14170F;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(163,177,138,0.14), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(245,131,32,0.12), transparent 55%);
  --primary: #A3B18A;
  --primary-dark: #829460;
  --primary-glow: rgba(163,177,138,0.34);
  --primary-surface: rgba(163,177,138,0.16);
  --accent: #F59A3C;
  --accent-surface: rgba(245,154,60,0.16);
  --on-brand: #14170F;
  --on-brand-soft: rgba(20,23,15,0.86);
  --on-brand-muted: rgba(20,23,15,0.66);
  --text: #F4F6F0;
  --text-secondary: rgba(244,246,240,0.74);
  --text-muted: rgba(244,246,240,0.55);
}

[data-theme="dark"][data-brand="indigo"] {
  --bg: #0A0A1C;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(129,140,248,0.12), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(167,139,250,0.10), transparent 55%);
  --primary: #818CF8;
  --primary-dark: #6366F1;
  --primary-glow: rgba(129,140,248,0.32);
  --primary-surface: rgba(129,140,248,0.14);
  --accent: #A78BFA;
  --accent-surface: rgba(167,139,250,0.14);
  --text: #ECEBFF;
  --text-secondary: rgba(236,235,255,0.74);
  --text-muted: rgba(236,235,255,0.55);
}

[data-theme="dark"][data-brand="ocean"] {
  --bg: #04101C;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(56,189,248,0.12), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(34,211,238,0.10), transparent 55%);
  --primary: #38BDF8;
  --primary-dark: #0EA5E9;
  --primary-glow: rgba(56,189,248,0.32);
  --primary-surface: rgba(56,189,248,0.14);
  --accent: #22D3EE;
  --accent-surface: rgba(34,211,238,0.14);
  --text: #E6F4FF;
  --text-secondary: rgba(230,244,255,0.74);
  --text-muted: rgba(230,244,255,0.55);
}

[data-theme="dark"][data-brand="coral"] {
  --bg: #170A0E;
  --bg-gradient: radial-gradient(1200px 600px at 100% -10%, rgba(251,113,133,0.12), transparent 60%),
                 radial-gradient(900px 500px at -10% 0%, rgba(251,113,133,0.10), transparent 55%);
  --primary: #FB7185;
  --primary-dark: #F43F5E;
  --primary-glow: rgba(251,113,133,0.32);
  --primary-surface: rgba(251,113,133,0.14);
  --accent: #FDA4AF;
  --accent-surface: rgba(253,164,175,0.14);
  --text: #FFECEF;
  --text-secondary: rgba(255,236,239,0.74);
  --text-muted: rgba(255,236,239,0.55);
}
