/**
 * DiabetCare — Design System Tokens
 * =====================================================
 * Single source of truth for the entire application.
 * Fonts loaded via <link> in base_head.html (non-blocking).
 * Import order: theme.css → app.css → mobile-ux.css → page.css
 * =====================================================
 */

:root {
    /* ─── Typography ────────────────────────────────────────────── */
    /* Syne: geometric display font for headings — distinctive, unforgettable */
    /* DM Sans: warm, readable body font — not Inter, not Roboto   */
    --font-display: 'Syne', system-ui, sans-serif;
    --font-sans:    'DM Sans', system-ui, -apple-system, sans-serif;

    --text-xs:   12px;
    --text-sm:   14px;
    --text-base: 15px;
    --text-md:   16px;
    --text-lg:   18px;
    --text-xl:   20px;
    --text-2xl:  24px;
    --text-3xl:  30px;
    --text-4xl:  36px;
    --text-5xl:  48px;

    --weight-regular:  400;
    --weight-medium:   500;
    --weight-semibold: 600;
    --weight-bold:     700;
    --weight-black:    800;

    --leading-tight:  1.2;
    --leading-snug:   1.35;
    --leading-normal: 1.6;

    /* ─── Brand Colors ──────────────────────────────────────────── */
    /* Health Teal — distinctive, health-positive, culturally warm  */
    --brand-primary: #00BFA5;
    --brand-deep:    #004D40;           /* darker teal for depth */
    --brand-light:   #64FFDA;           /* brighter mint for highlights */
    --brand-glow:    rgba(100, 255, 218, 0.15);  /* ambient glow for hero elements */
    --brand-amber:   #FFB300;
    --brand-red:     #EF5350;
    --brand-teal:    #00BFA5;   /* alias */

    /* ─── Accent Colors (breaks monotone teal) ─────────────────── */
    --accent-violet:      #7C3AED;           /* secondary accent for insights, AI features */
    --accent-violet-glow: rgba(124, 58, 237, 0.20);
    --accent-cyan:        #06B6D4;           /* tertiary — links, active states */
    --accent-warm:        #F59E0B;           /* warm amber for streaks, achievements, warnings */

    /* ─── Semantic Gradients ────────────────────────────────────── */
    --gradient-brand:   linear-gradient(135deg, #00BFA5, #004D40);
    --gradient-hero:    linear-gradient(135deg, #00BFA5 0%, #7C3AED 100%);  /* teal→violet for hero sections */
    --gradient-insight: linear-gradient(135deg, #7C3AED, #4F46E5);          /* AI insight cards */
    --gradient-score:   conic-gradient(from 220deg, #00BFA5, #64FFDA, #06B6D4, #7C3AED, #00BFA5); /* health score ring */
    --gradient-teal:    linear-gradient(135deg, #00BFA5, #26A69A);
    --gradient-green:   linear-gradient(135deg, #10b981, #059669);
    --gradient-success: linear-gradient(135deg, #00C853, #00E676);
    --gradient-warning: linear-gradient(135deg, #FFB300, #FFC107);
    --gradient-danger:  linear-gradient(135deg, #EF5350, #E53935);
    --gradient-amber:   linear-gradient(135deg, #FFB300, #FF8F00);

    /* ─── Glucose / Health Semantics ────────────────────────────── */
    --glucose-low:      #FF6D00;
    --glucose-target:   #00C853;
    --glucose-high:     #FFB300;
    --glucose-critical: #EF5350;

    /* Activity type colors */
    --activity-run:   #FF6B35;
    --activity-ride:  #00BFA5;
    --activity-swim:  #2196F3;
    --activity-other: #95A5A6;

    /* ─── Dark Surfaces (default — app is dark-first) ───────────── */
    --bg-body:          #050508;                    /* deeper black */
    --bg-surface:       rgba(16, 16, 26, 0.92);
    --bg-card:          rgba(15, 15, 25, 0.80);    /* more opaque, less washed out */
    --bg-card-elevated: rgba(25, 25, 42, 0.85);    /* hero/featured cards */
    --bg-card-hover:    rgba(35, 35, 55, 0.88);    /* richer hover state */
    --bg-subtle:        rgba(255, 255, 255, 0.04);
    --bg-hover:         rgba(0, 191, 165, 0.08);

    /* ─── Borders ────────────────────────────────────────────────── */
    --border-subtle:  rgba(255, 255, 255, 0.06);
    --border-default: rgba(255, 255, 255, 0.10);
    --border-strong:  rgba(255, 255, 255, 0.18);
    --border-brand:   rgba(0, 191, 165, 0.35);

    /* ─── Text ───────────────────────────────────────────────────── */
    --text-primary:   #F4F6F8;
    --text-secondary: #C8D0DA;
    --text-muted:     #8E9BAB;
    --text-faint:     #5C6B7A;
    --text-brand:     #4DD0C4;
    --text-green:     #34D399;
    --text-amber:     #FCD34D;
    --text-red:       #F87171;

    /* ─── Shadows & Glows ────────────────────────────────────────── */
    --shadow-sm:   0 2px 8px rgba(0, 0, 0, 0.32);
    --shadow-md:   0 8px 24px rgba(0, 0, 0, 0.48);
    --shadow-lg:   0 16px 48px rgba(0, 0, 0, 0.56);
    --shadow-xl:   0 24px 80px rgba(0, 0, 0, 0.64);
    --glow-brand:  0 0 24px rgba(0, 191, 165, 0.35);
    --glow-green:  0 0 20px rgba(16, 185, 129, 0.30);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.36);

    /* ─── Spacing (8px base) ─────────────────────────────────────── */
    --space-1:  4px;
    --space-2:  8px;
    --space-3:  12px;
    --space-4:  16px;
    --space-5:  20px;
    --space-6:  24px;
    --space-8:  32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;
    --space-20: 80px;

    /* ─── Border Radius ──────────────────────────────────────────── */
    --radius-sm:   6px;
    --radius-md:   10px;
    --radius-lg:   14px;
    --radius-xl:   20px;
    --radius-2xl:  28px;
    --radius-full: 9999px;

    /* ─── Motion ─────────────────────────────────────────────────── */
    --ease-out:    cubic-bezier(0, 0, 0.2, 1);
    --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --ease-in:     cubic-bezier(0.4, 0, 1, 1);

    /* ─── Layout ─────────────────────────────────────────────────── */
    --header-height:     64px;
    --bottom-nav-height: 64px;
    --container-sm:  720px;
    --container-md:  960px;
    --container-lg:  1200px;
    --container-xl:  1400px;

    /* ─── Z-Index Scale (named, never use magic numbers) ────────── */
    --z-below:    -1;
    --z-base:      0;
    --z-raised:   10;
    --z-floating: 50;
    --z-dropdown: 200;
    --z-sticky:   500;
    --z-nav:     1000;
    --z-overlay: 8000;
    --z-modal:   9000;
    --z-toast:   9999;
    --z-tooltip: 10000;

    /* ─── Legacy aliases (backward compat — do not use in new code) */
    --primary-brand:   var(--brand-primary);
    --primary-purple:  var(--brand-primary);
    --brand-purple:    var(--brand-primary);
    --deep-purple:     var(--brand-deep);
    --primary-medical: var(--brand-primary);
    --primary-red:     var(--brand-red);
    --primary-blue:    var(--brand-primary);
    --body-bg:         var(--bg-body);
    --card-bg:         var(--bg-card);
    --card-border:     var(--border-default);
    --gray-900: var(--text-primary);
    --gray-800: #E5E7EB;
    --gray-700: var(--text-secondary);
    --gray-600: var(--text-muted);
    --gray-500: var(--text-faint);
    --gray-400: #4B5563;
    --gray-300: #374151;
    --gray-200: #1F2937;
    --gray-100: #111827;
    --white:    #FFFFFF;
    --shadow-2xl: var(--shadow-xl);
    --bg-white:    rgba(255, 255, 255, 0.04);
    --bg-light:    rgba(255, 255, 255, 0.03);
    --bg-gradient: var(--gradient-brand);
    --healthcare-teal: var(--brand-primary);
    --gradient-primary: var(--gradient-brand);
    --glow-primary: var(--glow-brand);
    --section-bg: rgba(22, 22, 36, 0.75);

    /* ─── style.css aliases (CGM page) ─────────────────────────── */
    --primary-color:   var(--brand-primary);
    --secondary-color: var(--glucose-target);
    --danger-color:    var(--brand-red);
    --warning-color:   var(--brand-amber);
    --bg-color:        var(--bg-body);
    --border-color:    var(--border-default);
    --shadow:          var(--shadow-sm);
    --shadow-hover:    var(--shadow-md);
    --range-low:       var(--glucose-critical);
    --range-normal:    var(--glucose-target);
    --range-high:      var(--glucose-high);

    /* ─── discover.css aliases (Discover page) ─────────────────── */
    --primary-dark:    var(--brand-deep);
    --success-green:   #10b981;
    --warning-orange:  var(--accent-warm);
    --danger-red:      var(--brand-red);
    --neutral-gray:    var(--text-muted);
    --bg-primary:      var(--bg-card);
    --bg-secondary:    var(--bg-surface);
    --bg-tertiary:     var(--bg-subtle);
    --text-tertiary:   var(--text-faint);
    --border-light:    var(--border-subtle);
    --border-medium:   var(--border-default);
    --spacing-xs:      var(--space-2);
    --spacing-sm:      var(--space-3);
    --spacing-md:      var(--space-4);
    --spacing-lg:      var(--space-6);
    --spacing-xl:      var(--space-8);
}

/* ─── Light Mode Overrides ──────────────────────────────────────── */
/* Activated when OS prefers light AND user hasn't forced dark        */
@media (prefers-color-scheme: light) {
    html:not([data-theme="dark"]) {
        --bg-body:    #EEF2F7;
        --bg-surface: rgba(255, 255, 255, 0.96);
        --bg-card:    rgba(255, 255, 255, 0.92);
        --bg-subtle:  rgba(0, 0, 0, 0.04);
        --bg-hover:   rgba(0, 191, 165, 0.08);

        --border-subtle:  rgba(0, 0, 0, 0.07);
        --border-default: rgba(0, 0, 0, 0.11);
        --border-strong:  rgba(0, 0, 0, 0.18);
        --border-brand:   rgba(0, 191, 165, 0.40);

        --text-primary:   #111827;
        --text-secondary: #374151;
        --text-muted:     #6B7280;
        --text-faint:     #9CA3AF;
        --text-brand:     #007B6B;
        --text-green:     #059669;
        --text-amber:     #B45309;
        --text-red:       #DC2626;

        --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
        --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.12);
        --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.16);
        --shadow-xl: 0 24px 80px rgba(0, 0, 0, 0.20);

        --bg-body: #EEF2F7;
        --bg-card-elevated: rgba(255, 255, 255, 0.96);
        --bg-card-hover: rgba(245, 245, 250, 0.95);
        --section-bg: rgba(255, 255, 255, 0.92);
        --card-bg: rgba(255, 255, 255, 0.92);
        --bg-primary: rgba(255, 255, 255, 0.92);
        --bg-secondary: rgba(249, 250, 251, 0.96);
        --bg-tertiary: rgba(243, 244, 246, 0.90);
        --text-tertiary: #9CA3AF;
        --border-light: rgba(0, 0, 0, 0.07);
        --border-medium: rgba(0, 0, 0, 0.11);
        --gray-100: #F9FAFB;
        --gray-200: #F3F4F6;
        --gray-300: #E5E7EB;
        --gray-900: #111827;
        --gray-800: #1F2937;
        --gray-700: #374151;
        --gray-600: #6B7280;
    }
}

/* ─── Typography Polish ────────────────────────────────────────── */
/* Hero stat numbers — the biggest visual element on every page */
.stat-value-hero {
    font-family: var(--font-display);
    font-size: 56px;
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
    background: var(--gradient-hero);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Overline labels — small caps above section titles */
.overline {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent-violet);
}

/* ─── Global Reset & Base ──────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    font-weight: var(--weight-regular);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background-color: var(--bg-body);
    background-image:
        radial-gradient(ellipse at 10% 35%, rgba(0, 191, 165, 0.12) 0%, transparent 55%),
        radial-gradient(ellipse at 88% 18%, rgba(0, 121, 107, 0.10) 0%, transparent 55%),
        radial-gradient(ellipse at 50% 90%, rgba(0, 191, 165, 0.06) 0%, transparent 50%);
    background-attachment: fixed;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Display font for all headings */
h1, h2, h3, h4, h5, h6,
.section-title, .page-title, .card-title,
.stat-value, .brand-name {
    font-family: var(--font-display);
    letter-spacing: -0.02em;
}

/* App pages have top header + bottom nav padding */
body.app-page {
    padding-top: var(--header-height);
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
}

img {
    opacity: 0.97;
}

a {
    color: var(--text-brand);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ─── Performance: Backdrop-filter guard ────────────────────────── */
/* Disable GPU-heavy blur for reduced-motion users and low-power mode */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    /* Disable all backdrop blur — expensive on budget Android devices */
    .card, .glass-card, .top-header, .bottom-nav,
    .modal-backdrop, .modal-box, .toast,
    .user-dropdown, .info-tooltip {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }
}

/* Solid fallback for browsers without backdrop-filter support */
@supports not (backdrop-filter: blur(1px)) {
    .card, .glass-card {
        background: rgba(22, 22, 36, 0.97);
    }
    .top-header, .bottom-nav {
        background: rgba(9, 9, 15, 0.98);
    }
}
