/* =========================================================================
   FITOS SSOT DESIGN TOKENS HIERARCHY
   Tier 1: Primitives -> Tier 2: Semantic -> Tier 3: Components -> Tier 4: Dark Overrides
   ========================================================================= */

:root {
  /* Tier 1: Primitives — the calm palette (3.14.0): one light-blue accent and grays. Components never use these
     directly (gate #9 "raw-palette"); they use the semantic tokens below. */
  --color-sky-50: #F0F9FF;
  --color-sky-100: #E0F2FE;
  --color-sky-200: #BAE6FD;
  --color-sky-300: #7DD3FC;
  --color-sky-400: #38BDF8;
  --color-sky-500: #0EA5E9;
  --color-sky-600: #0284C7;
  --color-sky-700: #0369A1;
  --color-sky-800: #075985;
  --color-sky-900: #0C4A6E;

  --color-slate-50: #F8FAFC;
  --color-slate-100: #F1F5F9;
  --color-slate-200: #E2E8F0;
  --color-slate-300: #CBD5E1;
  --color-slate-400: #94A3B8;
  --color-slate-450: #7C8CA2; /* a field's boundary: 3:1 on white (WCAG 1.4.11, 4.8.14 C2) */
  --color-slate-500: #64748B;
  --color-slate-550: #5F6E84; /* muted text: 4.5:1 on every light surface (WCAG 1.4.3, 4.8.14 C2) */
  --color-slate-600: #475569;
  --color-slate-700: #334155;
  --color-slate-800: #1E293B;
  --color-slate-900: #0F172A;
  --color-slate-950: #0B1220;

  /* Status hues — only for small status badges, notices and destructive actions */
  --color-emerald-500: #10B981;
  --color-emerald-600: #059669;
  --color-emerald-700: #047857;
  --color-emerald-800: #065F46;
  --color-amber-500: #F59E0B;
  --color-rose-500: #EF4444;
  --color-rose-600: #DC2626;
  --color-rose-700: #B91C1C;

  /* Tier 2: Semantic Tokens */
  /* The accent: white text on it reads 4.5:1 (WCAG AA, 4.8.14 C2, D-481) */
  --primary: var(--color-sky-700);
  /* The FitOS logo (3.15.1): "Fit" ink, "OS" and the mark in the system accent */
  --logo-ink: var(--color-slate-800);
  --logo-accent: var(--color-sky-600);
  --logo-track: var(--color-sky-200);
  /* On a night surface (first load) in either theme */
  --logo-ink-inverse: var(--color-slate-50);
  --logo-accent-inverse: var(--color-sky-400);
  --logo-track-inverse: var(--color-slate-700);
  --primary-hover: var(--color-sky-800);
  --primary-subtle: var(--color-sky-50);
  /* Accent text on a light surface (links, selected tab, the chosen option) */
  --primary-text: var(--color-sky-700);
  --on-primary: #FFFFFF;
  --primary-alpha-10: rgba(2, 132, 199, 0.08);
  --primary-alpha-20: rgba(2, 132, 199, 0.18);
  --primary-alpha-30: rgba(2, 132, 199, 0.28);

  /* Overlays on the accent surface (e.g. the time chip on the dashboard strip) */
  --on-brand-faint: rgba(255, 255, 255, 0.07);
  --on-brand-subtle: rgba(255, 255, 255, 0.18);
  --on-brand-strong: rgba(255, 255, 255, 0.3);
  --on-brand-text-muted: rgba(255, 255, 255, 0.82);
  --on-brand-text: rgba(255, 255, 255, 0.95);
  /* Signature pad: the saved PNG is a legal record — always dark ink on white, in both themes */
  --signature-paper: #FFFFFF;
  --signature-ink: #0F172A;
  --overlay-scrim: rgba(0, 0, 0, 0.45);
  /* Dark surfaces that stay dark in both themes (sign-in backdrop, device frame) */
  --surface-night: var(--color-slate-900);

  --bg-page: var(--color-slate-50);
  --bg-surface: #FFFFFF;
  --bg-surface-subtle: var(--color-slate-100);

  --text-primary: var(--color-slate-900);
  --text-secondary: var(--color-slate-600);
  --text-muted: var(--color-slate-550);
  --text-inverse: #FFFFFF;

  --border-default: var(--color-slate-200);
  --border-subtle: var(--color-slate-100);

  --color-success: var(--color-emerald-700);
  --color-warning: var(--color-amber-500);
  --color-danger: var(--color-rose-600);
  --color-info: var(--color-sky-500);
  --color-danger-hover: var(--color-rose-700);
  --color-success-hover: var(--color-emerald-800);
  /* Short aliases */
  --success: var(--color-success);
  --danger: var(--color-danger);
  --warning: var(--color-warning);
  --info: var(--color-info);

  --success-bg: rgba(16, 185, 129, 0.12);
  --success-border: rgba(16, 185, 129, 0.25);
  --success-text: #065F46;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --danger-border: rgba(239, 68, 68, 0.25);
  --danger-text: #991B1B;
  --warning-bg: rgba(245, 158, 11, 0.12);
  --warning-border: rgba(245, 158, 11, 0.25);
  --warning-text: #92400E;
  --info-bg: rgba(14, 165, 233, 0.12);
  --info-border: rgba(14, 165, 233, 0.25);
  --info-text: #0369A1;

  /* Tier 2: Spacing scale — SSOT (3.14.0). Every gap, padding and margin uses a step. */
  --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;

  /* Tier 2: Typography Tokens — SSOT */
  --font-family-base: 'Assistant', 'Rubik', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Font Sizes */
  --font-size-2xs: 0.65rem;   /* ~10.5px: Micro captions, sub-labels, badge counts */
  --font-size-xs: 0.72rem;    /* ~11.5px: Metadata, timestamps, helper text, badges */
  --font-size-sm: 0.80rem;    /* ~12.8px: Secondary text, dense table cells, small tags */
  --font-size-base: 0.875rem; /* ~14px:   Standard body text, form inputs, buttons */
  --font-size-md: 0.95rem;    /* ~15.2px: Prominent body, tab labels, card titles */
  --font-size-lg: 1.1rem;     /* ~17.6px: Section sub-headings, medium numbers */
  --font-size-xl: 1.25rem;    /* ~20px:   Modal headers, card main headers */
  --font-size-2xl: 1.5rem;    /* ~24px:   Page headers, KPI hero numbers */
  --font-size-3xl: 2rem;      /* ~32px:   Hero statistics, large metrics */

  /* Font Weights */
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  --font-weight-extrabold: 800;
  --font-weight-black: 900;

  /* Line Heights */
  --line-height-none: 1;
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.75;

  /* Tier 2: Motion & Transition Tokens — SSOT */
  --transition-fast: 150ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-normal: 220ms cubic-bezier(0.16, 1, 0.3, 1);
  --transition-slow: 350ms cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-smooth: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Tier 3: Component Tokens */
  --btn-height-mobile: 44px;
  --touch-target-min: 44px;
  --input-font-size-touch: 16px; /* iOS Safari zooms into inputs below 16px */

  /* Device Safe Areas (notch / Dynamic Island / Android gesture bar) — requires viewport-fit=cover */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);

  /* App shell: side panel width, open and folded to icons (3.14.0) */
  --sidebar-w: 210px;
  /* The docked panel beside the screen (4.8.0, <DockPanel>) */
  --dock-w: 400px;
  --sidebar-w-collapsed: 60px;

  /* Mobile Portal Shell (Member + Instructor) */
  --portal-max-width: 640px; /* a phone fills it; a tablet gets one 640px column (4.8.18, D-498 decision 11) */
  --bottom-nav-height: 56px;
  /* <BottomActions> above the admin app's bottom bar (D-509): a 50px button and its slim padding */
  --bottom-actions-height: calc(50px + 2 * var(--space-2));
  --bottom-nav-icon: 22px;
  /* A list row's height (<ItemList> rows, the member app's rows) */
  --row-min-h: 44px;
  --bottom-nav-indicator-width: 28px;
  --bottom-nav-indicator-height: 3px;
  --radius-xs: 3px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --radius-device: 44px;
  --radius-device-inner: 34px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.12), 0 8px 10px -6px rgba(0, 0, 0, 0.08);
  --shadow-drawer: -4px 0 24px rgba(0, 0, 0, 0.25);
  --shadow-up: 0 -2px 12px rgba(0, 0, 0, 0.08);
  --shadow-2xl: 0 25px 60px rgba(0, 0, 0, 0.4);
  --shadow-brand: 0 6px 20px rgba(2, 132, 199, 0.25);
  --shadow-glow-success: 0 0 6px var(--color-success);

  /* Responsive 2-column form grid: 2 columns when there is room, 1 on phones */
  --grid-cols-2: repeat(auto-fit, minmax(min(100%, 220px), 1fr));

  /* Card Container Tokens — SSOT for all panels/cards across the app */
  --card-padding: 1rem 1.25rem;
  --card-padding-compact: 0.75rem 1rem;
  --card-margin-bottom: 1rem;
  --card-radius: var(--radius-md);

  /* KPI Card Tokens — SSOT for all metric cards across the app */
  --kpi-padding: 0.65rem 0.9rem;
  --kpi-gap: 0.75rem;
  --kpi-min-height: 62px;
  --kpi-icon-size: 1.15rem;
  --kpi-number-size: 1.35rem;
  --kpi-label-size: var(--font-size-xs);
  --kpi-sub-size: var(--font-size-2xs);

  /* Button Tokens — SSOT */
  --btn-height-sm: 30px;
  --btn-height-md: 36px;
  --btn-height-lg: 42px;
  --btn-padding-sm: 4px 10px;
  --btn-padding-md: 6px 14px;
  --btn-padding-lg: 8px 18px;
  --btn-radius: var(--radius-sm);
  --btn-font-size-sm: var(--font-size-sm);
  --btn-font-size-md: var(--font-size-base);
  --btn-font-size-lg: var(--font-size-md);

  /* Badge Tokens — SSOT */
  --badge-padding: 2px 8px;
  --badge-font-size: var(--font-size-2xs);
  --badge-radius: var(--radius-full);

  /* Form Input Tokens — SSOT */
  --input-height-sm: 32px;
  --input-height-md: 38px;
  --input-padding: 6px 12px;
  --input-radius: var(--radius-sm);
  --input-font-size: var(--font-size-base);
  --input-border: var(--color-slate-450); /* 3:1 on the field (WCAG 1.4.11) */
  --input-bg: var(--bg-surface);
  --input-focus-ring: 0 0 0 3px var(--primary-alpha-20);

  /* Tier 3: Modals & Dialogs */
  --modal-sm: 420px;
  --modal-md: 580px;
  --modal-lg: 840px;
  --modal-backdrop-bg: rgba(0, 0, 0, 0.55);
  --modal-backdrop-blur: 4px;
  --modal-header-padding: var(--space-4) var(--space-6);
  --modal-body-padding: var(--space-5) var(--space-6);
  --modal-footer-padding: var(--space-3) var(--space-6);
  --modal-radius: var(--radius-lg);
  /* How far a sheet is dragged down by its handle (set while dragging, 4.8.18) */
  --sheet-drag: 0px;
  /* A window with tabs or steps keeps one height whatever the tab shows (only the body scrolls) */
  --modal-fixed-h: min(44rem, 86dvh);

  /* Tier 3: Data Tables */
  --table-cell-padding: 0.65rem 0.85rem;
  --table-header-bg: var(--bg-surface-subtle);
  --table-header-color: var(--text-muted);
  --table-row-hover-bg: var(--bg-surface-subtle);
  /* List rows (<DataRow>): the accent (3.14.0: always the calm accent — no brand colours) */
  --row-accent: var(--primary);
  --row-accent-tint: color-mix(in srgb, var(--row-accent) 7%, var(--bg-surface));
  --row-accent-shadow: 0 2px 10px color-mix(in srgb, var(--row-accent) 28%, transparent);
  --table-border-color: var(--border-default);

  /* Tier 3: Toast Notifications */
  --toast-bg: var(--bg-surface);
  --toast-color: var(--text-primary);
  --toast-radius: var(--radius-md);
  --toast-shadow: var(--shadow-lg);
}

/* Tier 2 on a phone (4.8.18, D-496 / D-498): one type scale for every app at phone width — body 16, secondary 14,
   nothing under 12, a page title close to the text (22). Every screen reads these tokens, so it follows by itself;
   the desktop keeps the scale above. A list row is 52px high and the member / instructor bottom bar 64px. */
@media (max-width: 768px) {
  :root {
    --font-size-2xs: 0.75rem;     /* 12px */
    --font-size-xs: 0.78125rem;   /* 12.5px */
    --font-size-sm: 0.875rem;     /* 14px */
    --font-size-base: 1rem;       /* 16px */
    --font-size-md: 1.0625rem;    /* 17px */
    --font-size-lg: 1.1875rem;    /* 19px */
    --font-size-xl: 1.25rem;      /* 20px */
    --font-size-2xl: 1.375rem;    /* 22px */
    --font-size-3xl: 1.75rem;     /* 28px */
    --row-min-h: 52px;
    --bottom-nav-height: 64px;
    --bottom-nav-icon: 24px;
  }
}

/* Tier 4: Dark Mode Overrides — the same calm system: gray surfaces, the light-blue accent a step lighter */
[data-theme="dark"] {
  --bg-page: var(--color-slate-950);
  --bg-surface: var(--color-slate-900);
  --bg-surface-subtle: var(--color-slate-800);

  --text-primary: var(--color-slate-100);
  --text-secondary: var(--color-slate-300);
  --text-muted: var(--color-slate-400);

  --border-default: var(--color-slate-700);
  --border-subtle: var(--color-slate-800);
  --input-border: var(--color-slate-500);

  --primary: var(--color-sky-400);
  --logo-ink: var(--color-slate-50);
  --logo-accent: var(--color-sky-400);
  --logo-track: var(--color-slate-700);
  --primary-hover: var(--color-sky-300);
  --primary-subtle: rgba(56, 189, 248, 0.12);
  --primary-text: var(--color-sky-300);
  --on-primary: var(--color-slate-900);
  --primary-alpha-10: rgba(56, 189, 248, 0.08);
  --primary-alpha-20: rgba(56, 189, 248, 0.18);
  --primary-alpha-30: rgba(56, 189, 248, 0.28);
  --surface-night: var(--color-slate-950);

  --success-text: #6EE7B7;
  --danger-text: #FCA5A5;
  --warning-text: #FCD34D;
  --info-text: #7DD3FC;
}

/* Tier 5: High contrast (4.8.18, D-486) — "ניגודיות גבוהה" in "התאמות תצוגה", over light or dark: text and borders
   at full strength, the accent a step deeper (lighter in dark), every boundary seen. The person's own choice. */
[data-contrast="high"] {
  --bg-page: #FFFFFF;
  --bg-surface: #FFFFFF;
  --bg-surface-subtle: var(--color-slate-100);
  --text-primary: #000000;
  --text-secondary: var(--color-slate-900);
  --text-muted: var(--color-slate-800);
  --border-default: var(--color-slate-700);
  --border-subtle: var(--color-slate-500);
  --input-border: var(--color-slate-800);
  --primary: var(--color-sky-900);
  --primary-hover: var(--color-slate-900);
  --primary-text: var(--color-sky-900);
  --success-text: #064E3B;
  --danger-text: #7F1D1D;
  --warning-text: #78350F;
  --info-text: var(--color-sky-900);
}
[data-theme="dark"][data-contrast="high"] {
  --bg-page: #000000;
  --bg-surface: #000000;
  --bg-surface-subtle: var(--color-slate-900);
  --text-primary: #FFFFFF;
  --text-secondary: var(--color-slate-50);
  --text-muted: var(--color-slate-200);
  --border-default: var(--color-slate-300);
  --border-subtle: var(--color-slate-500);
  --input-border: var(--color-slate-200);
  --primary: var(--color-sky-300);
  --primary-hover: var(--color-sky-200);
  --primary-text: var(--color-sky-200);
  --on-primary: #000000;
  --success-text: #A7F3D0;
  --danger-text: #FECACA;
  --warning-text: #FDE68A;
  --info-text: var(--color-sky-200);
}
