/**
 * UNIFIED DESIGN TOKENS
 * Water Meter Monitoring System
 *
 * @version 1.0.0
 * @description Single source of truth for all design variables
 *
 * This file provides canonical values for:
 * - Status colors: operational green, warning amber, critical red, pending/idle grey.
 *   One set for admin and customer (2026-10, workstream K): the admin no longer overrides
 *   them. Brand/primary stays sky blue #0369A1 (buttons, links, logo, theme-color).
 *   Each status has: base (fills, borders, markers), -bg (solid tint), -border,
 *   -text (>= 4.5:1 on white and on its -bg) and -glyph (icon on a solid base fill).
 * - Typography
 * - Spacing (4px base grid)
 * - Border radius
 * - Shadows
 * - Transitions
 * - Z-index layers
 *
 * Import this file FIRST in all CSS stacks.
 *
 * Added 2026-10 (workstream G, additive: no existing token renamed or removed):
 * - --status-*-text      Status colours for TEXT and small glyphs. The base --status-* colours
 *                        (amber #f59e0b 2.2:1, red #ef4444 3.8:1 on white) are for fills,
 *                        borders and markers; text needs >= 4.5:1 (WCAG AA), which these give on
 *                        white, --bg-page and the matching --status-*-bg tint.
 * - --status-*-glyph     Icon colour drawn ON a solid --status-* fill (map markers, dots).
 * - --focus-ring-color / --focus-ring-width / --focus-ring-offset / --focus-ring
 *                        One keyboard focus indicator: `outline: var(--focus-ring)` plus
 *                        `outline-offset: var(--focus-ring-offset)`.
 * - --touch-target       Minimum hit area for anything tappable (44px, Apple HIG / WCAG 2.5.5).
 * - --icon-sm / --icon-md / --icon-lg   Icon sizes (16 / 20 / 24px).
 * - --z-skip-link        Above every other layer so the skip link is visible on focus.
 * - --text-muted is 2.6:1 on white: use it only for decoration (placeholders, dividers),
 *   never for information; use --text-secondary (4.8:1) for secondary text.
 */

:root {
    /* ================================================
       STATUS COLORS - CANONICAL
       ================================================
       The ONLY status colours, for every view (admin, customer, map markers, cluster
       icons, legends, chips, KPI tiles). Operational is GREEN; the brand blue
       (--primary) is for buttons, links and the brand, never for a status.
       ================================================ */

    --status-operational: #16a34a;            /* green-600: fills, borders, markers (3.3:1, graphics) */
    --status-operational-bg: #dcfce7;
    --status-operational-border: #86efac;

    --status-warning: #f59e0b;
    --status-warning-bg: #fef3c7;
    --status-warning-border: #fcd34d;

    --status-critical: #ef4444;
    --status-critical-bg: #fee2e2;
    --status-critical-border: #fca5a5;

    --status-pending: #64748b;
    --status-pending-bg: #f1f5f9;
    --status-pending-border: #94a3b8;

    /* Text-safe status colours (>= 4.5:1 on white, --bg-page and the -bg tint;
       checked by meters/tests/test_customer_portal.py::TestDesignTokens):
       operational #15803d 5.0 / 4.8 / 4.6, warning #92400e 7.1 / 6.8 / 6.4,
       critical #b91c1c 6.5 / 6.2 / 5.3, pending #475569 7.6 / 7.2 / 6.9 */
    --status-operational-text: #15803d;
    --status-warning-text: #92400e;
    --status-critical-text: #b91c1c;
    --status-pending-text: #475569;

    /* Glyph colour on a solid status fill (markers, filled badges) */
    --status-operational-glyph: #ffffff;
    --status-warning-glyph: #451a03;
    --status-critical-glyph: #ffffff;
    --status-pending-glyph: #ffffff;

    /* ================================================
       PRIMARY BRAND PALETTE
       ================================================ */

    --primary: #0369A1;
    --primary-hover: #0284C7;
    --primary-light: #DBEAFE;
    --primary-dark: #075985;

    --secondary: #3b82f6;
    --secondary-hover: #2563eb;
    --secondary-light: #dbeafe;

    --accent: #0ea5e9;
    --accent-bright: #38bdf8;

    /* ================================================
       SEMANTIC COLORS
       ================================================ */

    --success: var(--status-operational);
    --success-bg: var(--status-operational-bg);
    --success-border: var(--status-operational-border);

    --warning: var(--status-warning);
    --warning-bg: var(--status-warning-bg);
    --warning-border: var(--status-warning-border);

    --danger: var(--status-critical);
    --danger-bg: var(--status-critical-bg);
    --danger-border: var(--status-critical-border);

    --info: #3b82f6;
    --info-bg: #dbeafe;
    --info-border: #93c5fd;

    --neutral: var(--status-pending);
    --neutral-bg: var(--status-pending-bg);

    /* ================================================
       GRAY SCALE
       ================================================ */

    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* ================================================
       TEXT COLORS
       ================================================ */

    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    /* ================================================
       BACKGROUND COLORS
       ================================================ */

    --bg-page: #f8fafc;
    --bg-card: #ffffff;
    --bg-hover: #f1f5f9;
    --bg-active: #e2e8f0;

    /* ================================================
       BORDER COLORS
       ================================================ */

    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --border-dark: #cbd5e1;

    /* ================================================
       TYPOGRAPHY - CANONICAL
       ================================================ */

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'IBM Plex Mono', 'SF Mono', Monaco, 'Cascadia Code', monospace;
    --font-sans: var(--font-family);

    /* Font Sizes */
    --text-xs: 0.75rem;     /* 12px */
    --text-sm: 0.875rem;    /* 14px */
    --text-base: 1rem;      /* 16px */
    --text-lg: 1.125rem;    /* 18px */
    --text-xl: 1.25rem;     /* 20px */
    --text-2xl: 1.5rem;     /* 24px */
    --text-3xl: 1.875rem;   /* 30px */
    --text-4xl: 2.25rem;    /* 36px */

    /* Font Weights */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    /* Line Heights */
    --leading-tight: 1.25;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;

    /* ================================================
       SPACING - 4px BASE GRID (Canonical)
       ================================================ */

    --space-0: 0;
    --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;

    /* ================================================
       BORDER RADIUS - CANONICAL
       ================================================ */

    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-2xl: 20px;
    --radius-full: 9999px;

    /* ================================================
       SHADOWS
       ================================================ */

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow: var(--shadow-sm);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* Component-specific shadows */
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-card-hover: 0 4px 12px rgba(0, 0, 0, 0.1);

    /* ================================================
       TRANSITIONS - CANONICAL
       ================================================ */

    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-normal: 200ms ease;
    --transition-slow: 300ms ease;
    --transition-slower: 500ms ease;

    /* Animation duration for JS modules */
    --animation-duration: 300ms;

    /* ================================================
       FOCUS, TOUCH, ICONS (accessibility)
       ================================================ */

    --focus-ring-color: var(--primary);
    --focus-ring-width: 3px;
    --focus-ring-offset: 2px;
    --focus-ring: var(--focus-ring-width) solid var(--focus-ring-color);
    --touch-target: 44px;
    --icon-sm: 16px;
    --icon-md: 20px;
    --icon-lg: 24px;

    /* ================================================
       Z-INDEX LAYERS
       ================================================ */

    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-modal-backdrop: 900;
    --z-modal: 1000;
    --z-popover: 1100;
    --z-tooltip: 1200;
    --z-toast: 1300;
    --z-skip-link: 1400;

    /* ================================================
       LAYOUT
       ================================================ */

    --container-max: 1400px;
    --sidebar-width: 280px;
    --header-height: 64px;

    /* Grid Gaps */
    --grid-gap-sm: var(--space-3);
    --grid-gap-md: var(--space-4);
    --grid-gap-lg: var(--space-6);

    /* ================================================
       TABLE TOKENS - CANONICAL
       ================================================ */

    /* Table structure */
    --table-border-radius: var(--radius-lg);
    --table-border-color: var(--border-light);
    --table-border-width: 1px;

    /* Table header */
    --table-header-bg: var(--gray-50);
    --table-header-bg-hover: var(--gray-100);
    --table-header-color: var(--text-secondary);
    --table-header-font-size: 11px;
    --table-header-font-weight: var(--font-semibold);
    --table-header-padding: var(--space-3) var(--space-4);
    --table-header-letter-spacing: 0.05em;

    /* Table body */
    --table-cell-font-size: 13px;
    --table-cell-padding: var(--space-3) var(--space-4);
    --table-cell-color: var(--text-primary);
    --table-row-border-color: var(--border-light);
    --table-row-hover-bg: var(--bg-hover);
    --table-row-stripe-bg: var(--gray-50);

    /* Table card wrapper */
    --table-card-bg: var(--bg-card);
    --table-card-shadow: var(--shadow-card);
    --table-card-header-padding: var(--space-4) var(--space-5);

    /* Table pagination */
    --table-pagination-bg: var(--gray-50);
    --table-pagination-padding: var(--space-3) var(--space-4);

    /* Safe Areas (for mobile) */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
}

/* ================================================
   DARK MODE OVERRIDES
   ================================================ */

@media (prefers-color-scheme: dark) {
    :root.dark-mode {
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-muted: #64748b;

        --bg-page: #0f172a;
        --bg-card: #1e293b;
        --bg-hover: #334155;
        --bg-active: #475569;

        --border: #334155;
        --border-light: #1e293b;
        --border-dark: #475569;

        --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
        --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
    }
}

/* ================================================
   CSS BREAKPOINTS (Reference)

   Use these consistent values in all @media queries:

   --breakpoint-sm:  640px   (Mobile landscape)
   --breakpoint-md:  768px   (Tablet portrait)
   --breakpoint-lg:  1024px  (Tablet landscape / Desktop)
   --breakpoint-xl:  1280px  (Wide desktop)

   Usage:
   - Mobile-first: @media (min-width: 768px) { }
   - Desktop-first: @media (max-width: 767px) { }
   ================================================ */
