/**
 * myFamily PWA - Main CSS Foundation
 *
 * A comprehensive CSS foundation for the myFamily Progressive Web App.
 * Mobile-first, accessible, and optimized for both light and dark themes.
 *
 * Table of Contents:
 * 1. CSS Custom Properties (Variables)
 * 2. CSS Reset/Normalize
 * 3. iOS-Specific Fixes
 * 4. Typography
 * 5. Layout Utilities
 * 6. Components
 * 7. Accessibility
 * 8. Utility Classes
 * 9. Offline Indicator
 * 10. Pull-to-Refresh Indicator
 */

/* ==========================================================================
   1. CSS CUSTOM PROPERTIES (VARIABLES)
   ========================================================================== */

:root {
  /* --------------------------------------------------------------------------
     Color Palette - Light Theme (Default)
     -------------------------------------------------------------------------- */
  --color-primary: #2563eb;           /* Blue - main brand color */
  --color-primary-hover: #1d4ed8;     /* Darker blue for hover states */
  --color-primary-light: #dbeafe;     /* Light blue for backgrounds */
  --color-secondary: #7c3aed;         /* Purple - accent color */
  --color-secondary-hover: #6d28d9;   /* Darker purple for hover states */
  --color-secondary-light: #ede9fe;   /* Light purple for backgrounds */

  --color-background: #f8fafc;        /* Page background */
  --color-surface: #ffffff;           /* Card/component backgrounds */
  --color-surface-elevated: #ffffff;  /* Elevated surfaces (modals, dropdowns) */

  --color-text: #0f172a;              /* Primary text color */
  --color-text-secondary: #475569;    /* Secondary/muted text */
  --color-text-tertiary: #94a3b8;     /* Placeholder text, disabled states */
  --color-text-inverse: #ffffff;      /* Text on dark backgrounds */

  --color-border: #e2e8f0;            /* Default border color */
  --color-border-focus: #2563eb;      /* Border color for focused elements */
  --color-divider: #f1f5f9;           /* Subtle dividers */

  /* Semantic Colors */
  --color-success: #16a34a;           /* Success states, confirmations */
  --color-success-light: #dcfce7;     /* Success backgrounds */
  --color-warning: #d97706;           /* Warnings, cautions */
  --color-warning-light: #fef3c7;     /* Warning backgrounds */
  --color-error: #dc2626;             /* Errors, destructive actions */
  --color-error-light: #fee2e2;       /* Error backgrounds */
  --color-info: #0891b2;              /* Informational states */
  --color-info-light: #cffafe;        /* Info backgrounds */

  /* --------------------------------------------------------------------------
     Spacing Scale
     Based on 4px base unit for consistent rhythm
     -------------------------------------------------------------------------- */
  --space-xs: 0.25rem;    /* 4px */
  --space-sm: 0.5rem;     /* 8px */
  --space-md: 1rem;       /* 16px */
  --space-lg: 1.5rem;     /* 24px */
  --space-xl: 2rem;       /* 32px */
  --space-2xl: 3rem;      /* 48px */
  --space-3xl: 4rem;      /* 64px */

  /* --------------------------------------------------------------------------
     Typography Scale
     Modular scale with 1.25 ratio for harmonious sizing
     -------------------------------------------------------------------------- */
  --font-size-xs: 0.75rem;    /* 12px */
  --font-size-sm: 0.875rem;   /* 14px */
  --font-size-base: 1rem;     /* 16px */
  --font-size-lg: 1.125rem;   /* 18px */
  --font-size-xl: 1.25rem;    /* 20px */
  --font-size-2xl: 1.5rem;    /* 24px */
  --font-size-3xl: 1.875rem;  /* 30px */
  --font-size-4xl: 2.25rem;   /* 36px */

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

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

  /* --------------------------------------------------------------------------
     Border Radius
     -------------------------------------------------------------------------- */
  --radius-sm: 0.25rem;   /* 4px - subtle rounding */
  --radius-md: 0.5rem;    /* 8px - default rounding */
  --radius-lg: 0.75rem;   /* 12px - pronounced rounding */
  --radius-xl: 1rem;      /* 16px - large rounding */
  --radius-2xl: 1.5rem;   /* 24px - extra large rounding */
  --radius-full: 9999px;  /* Fully rounded (pills, circles) */

  /* --------------------------------------------------------------------------
     Shadows
     -------------------------------------------------------------------------- */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);
  --shadow-inner: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);

  /* Colored Shadows for Elevated Elements */
  --shadow-primary: 0 4px 14px 0 rgb(37 99 235 / 0.25);
  --shadow-error: 0 4px 14px 0 rgb(220 38 38 / 0.25);

  /* --------------------------------------------------------------------------
     Transitions
     -------------------------------------------------------------------------- */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 350ms ease;
  --transition-bounce: 500ms cubic-bezier(0.68, -0.55, 0.265, 1.55);

  /* --------------------------------------------------------------------------
     Z-Index Scale
     -------------------------------------------------------------------------- */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-fixed: 300;
  --z-modal-backdrop: 400;
  --z-modal: 500;
  --z-popover: 600;
  --z-tooltip: 700;
  --z-toast: 800;
  --z-max: 9999;

  /* --------------------------------------------------------------------------
     Layout
     -------------------------------------------------------------------------- */
  --container-max-width: 1200px;
  --header-height: 56px;
  --bottom-nav-height: 64px;
  --fab-size: 56px;
  --fab-mini-size: 40px;

  /* --------------------------------------------------------------------------
     Safe Area Insets (iOS notch support)
     -------------------------------------------------------------------------- */
  --safe-area-inset-top: env(safe-area-inset-top, 0px);
  --safe-area-inset-right: env(safe-area-inset-right, 0px);
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-inset-left: env(safe-area-inset-left, 0px);
}

/* --------------------------------------------------------------------------
   Dark Theme - System Preference
   Automatically applied when user's system prefers dark mode
   -------------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --color-primary: #3b82f6;
    --color-primary-hover: #60a5fa;
    --color-primary-light: #1e3a5f;
    --color-secondary: #8b5cf6;
    --color-secondary-hover: #a78bfa;
    --color-secondary-light: #2e1f5e;

    --color-background: #0f172a;
    --color-surface: #1e293b;
    --color-surface-elevated: #334155;

    --color-text: #f1f5f9;
    --color-text-secondary: #94a3b8;
    --color-text-tertiary: #64748b;
    --color-text-inverse: #0f172a;

    --color-border: #334155;
    --color-border-focus: #3b82f6;
    --color-divider: #1e293b;

    --color-success: #22c55e;
    --color-success-light: #14532d;
    --color-warning: #f59e0b;
    --color-warning-light: #451a03;
    --color-error: #ef4444;
    --color-error-light: #450a0a;
    --color-info: #06b6d4;
    --color-info-light: #083344;

    /* Adjusted shadows for dark mode */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.3);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.5), 0 8px 10px -6px rgb(0 0 0 / 0.4);
    --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.6);
  }
}

/* --------------------------------------------------------------------------
   Dark Theme - Manual Toggle
   Applied when data-theme="dark" attribute is set on html/body
   -------------------------------------------------------------------------- */
[data-theme="dark"] {
  --color-primary: #3b82f6;
  --color-primary-hover: #60a5fa;
  --color-primary-light: #1e3a5f;
  --color-secondary: #8b5cf6;
  --color-secondary-hover: #a78bfa;
  --color-secondary-light: #2e1f5e;

  --color-background: #0f172a;
  --color-surface: #1e293b;
  --color-surface-elevated: #334155;

  --color-text: #f1f5f9;
  --color-text-secondary: #94a3b8;
  --color-text-tertiary: #64748b;
  --color-text-inverse: #0f172a;

  --color-border: #334155;
  --color-border-focus: #3b82f6;
  --color-divider: #1e293b;

  --color-success: #22c55e;
  --color-success-light: #14532d;
  --color-warning: #f59e0b;
  --color-warning-light: #451a03;
  --color-error: #ef4444;
  --color-error-light: #450a0a;
  --color-info: #06b6d4;
  --color-info-light: #083344;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.3);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.5), 0 8px 10px -6px rgb(0 0 0 / 0.4);
  --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.6);
}

/* ==========================================================================
   2. CSS RESET/NORMALIZE
   ========================================================================== */

/**
 * Box Sizing
 * Set border-box on all elements for predictable sizing
 */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/**
 * Remove Default Margins
 * Reset margins on common elements
 */
html,
body,
h1, h2, h3, h4, h5, h6,
p,
figure,
blockquote,
dl, dd,
ul, ol {
  margin: 0;
}

/**
 * Remove List Styles
 * Only on lists with role="list" to maintain accessibility
 */
ul[role="list"],
ol[role="list"] {
  list-style: none;
  padding: 0;
}

/**
 * Core Body Defaults
 */
html {
  /* Smooth scrolling for anchor links */
  scroll-behavior: smooth;

  /* Prevent text size adjustment on orientation change */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;

  /* Better font rendering on macOS/iOS */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--color-text);
  background-color: var(--color-background);

  /* Prevent horizontal overflow */
  overflow-x: hidden;
}

/**
 * Media Defaults
 * Make images and videos responsive by default
 */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/**
 * Inherit Fonts for Form Elements
 */
input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

/**
 * Text Wrapping
 * Prevent text overflow in headings and paragraphs
 */
h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

p {
  overflow-wrap: break-word;
  hyphens: auto;
}

/**
 * Remove Button Styles
 */
button {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

/**
 * Remove Anchor Underlines
 */
a {
  text-decoration: none;
  color: inherit;
}

/**
 * Table Defaults
 */
table {
  border-collapse: collapse;
  border-spacing: 0;
}

/* ==========================================================================
   3. iOS-SPECIFIC FIXES
   ========================================================================== */

/**
 * 100vh Fix for iOS
 * iOS Safari doesn't account for the address bar in 100vh
 * Using -webkit-fill-available as a fallback
 */
html {
  height: -webkit-fill-available;
}

body {
  min-height: 100vh;
  min-height: -webkit-fill-available;
}

/**
 * Safe Area Padding for Notched Devices
 * Applied to main content wrapper
 */
.safe-area-padding {
  padding-top: var(--safe-area-inset-top);
  padding-right: var(--safe-area-inset-right);
  padding-bottom: var(--safe-area-inset-bottom);
  padding-left: var(--safe-area-inset-left);
}

.safe-area-padding-horizontal {
  padding-left: var(--safe-area-inset-left);
  padding-right: var(--safe-area-inset-right);
}

.safe-area-padding-vertical {
  padding-top: var(--safe-area-inset-top);
  padding-bottom: var(--safe-area-inset-bottom);
}

/**
 * Touch Action Manipulation
 * Improves scrolling performance and prevents unwanted gestures
 */
.touch-manipulation {
  touch-action: manipulation;
}

/**
 * Prevent Pull-to-Refresh on Main Scroll Container
 * (Custom pull-to-refresh is implemented separately)
 */
.overscroll-contain {
  overscroll-behavior: contain;
}

/**
 * Momentum Scrolling for iOS
 */
.scroll-smooth {
  -webkit-overflow-scrolling: touch;
}

/**
 * Prevent Tap Highlight on iOS
 */
.no-tap-highlight {
  -webkit-tap-highlight-color: transparent;
}

/**
 * Disable User Selection (for UI elements)
 */
.no-select {
  -webkit-user-select: none;
  user-select: none;
}

/* ==========================================================================
   4. TYPOGRAPHY
   ========================================================================== */

/**
 * System Font Stack
 * Uses native fonts for better performance and platform consistency
 */
body {
  font-family:
    -apple-system,           /* iOS/macOS Safari */
    BlinkMacSystemFont,      /* macOS Chrome */
    'Segoe UI',              /* Windows */
    Roboto,                  /* Android */
    Oxygen,                  /* KDE */
    Ubuntu,                  /* Ubuntu */
    Cantarell,               /* GNOME */
    'Fira Sans',             /* Firefox OS */
    'Droid Sans',            /* Older Android */
    'Helvetica Neue',        /* macOS fallback */
    sans-serif;              /* Ultimate fallback */
}

/**
 * Heading Styles
 */
h1, .h1 {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  letter-spacing: -0.025em;
  color: var(--color-text);
}

h2, .h2 {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  letter-spacing: -0.02em;
  color: var(--color-text);
}

h3, .h3 {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  color: var(--color-text);
}

h4, .h4 {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-normal);
  color: var(--color-text);
}

h5, .h5 {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-normal);
  color: var(--color-text);
}

h6, .h6 {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-normal);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/**
 * Body Text Styles
 */
.text-body {
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--color-text);
}

.text-body-sm {
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  color: var(--color-text);
}

.text-sm {
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
}

.text-caption {
  font-size: var(--font-size-xs);
  line-height: var(--line-height-normal);
  color: var(--color-text-secondary);
}

.text-lead {
  font-size: var(--font-size-lg);
  line-height: var(--line-height-relaxed);
  color: var(--color-text-secondary);
}

/**
 * Link Styles
 */
a:not([class]) {
  color: var(--color-primary);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color var(--transition-fast);
}

a:not([class]):hover {
  color: var(--color-primary-hover);
}

.link {
  color: var(--color-primary);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color var(--transition-fast);
  cursor: pointer;
}

.link:hover {
  color: var(--color-primary-hover);
}

.link--secondary {
  color: var(--color-text-secondary);
}

.link--secondary:hover {
  color: var(--color-text);
}

/* ==========================================================================
   5. LAYOUT UTILITIES
   ========================================================================== */

/**
 * Container
 * Centered content wrapper with responsive padding
 */
.container {
  width: 100%;
  max-width: var(--container-max-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-md);
  padding-right: var(--space-md);
}

.container--narrow {
  max-width: 640px;
}

.container--wide {
  max-width: 1400px;
}

/**
 * Page Layout
 * Accounts for fixed header and bottom navigation
 */
.page {
  min-height: 100vh;
  min-height: -webkit-fill-available;
  padding-top: var(--header-height);
  padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-inset-bottom));
}

.page--no-header {
  padding-top: 0;
}

.page--no-nav {
  padding-bottom: var(--safe-area-inset-bottom);
}

/**
 * Flexbox Utilities
 */
.flex {
  display: flex;
}

.inline-flex {
  display: inline-flex;
}

.flex-col {
  flex-direction: column;
}

.flex-row {
  flex-direction: row;
}

.flex-wrap {
  flex-wrap: wrap;
}

.flex-nowrap {
  flex-wrap: nowrap;
}

/* Alignment */
.items-start {
  align-items: flex-start;
}

.items-center {
  align-items: center;
}

.items-end {
  align-items: flex-end;
}

.items-stretch {
  align-items: stretch;
}

.items-baseline {
  align-items: baseline;
}

/* Justify */
.justify-start {
  justify-content: flex-start;
}

.justify-center {
  justify-content: center;
}

.justify-end {
  justify-content: flex-end;
}

.justify-between {
  justify-content: space-between;
}

.justify-around {
  justify-content: space-around;
}

.justify-evenly {
  justify-content: space-evenly;
}

/* Flex Children */
.flex-1 {
  flex: 1 1 0%;
}

.flex-auto {
  flex: 1 1 auto;
}

.flex-none {
  flex: none;
}

.flex-grow {
  flex-grow: 1;
}

.flex-shrink-0 {
  flex-shrink: 0;
}

/* Gap Utilities */
.gap-xs {
  gap: var(--space-xs);
}

.gap-sm {
  gap: var(--space-sm);
}

.gap-md {
  gap: var(--space-md);
}

.gap-lg {
  gap: var(--space-lg);
}

.gap-xl {
  gap: var(--space-xl);
}

/**
 * Grid Utilities
 */
.grid {
  display: grid;
}

.grid-cols-1 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}

.grid-cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* Responsive Grid (auto-fit) */
.grid-auto-fit {
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.grid-auto-fill {
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

/* ==========================================================================
   6. COMPONENTS
   ========================================================================== */

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

/**
 * Base Button Styles
 * All buttons share these foundational styles
 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);

  min-height: 44px;  /* Minimum touch target size */
  min-width: 44px;
  padding: var(--space-sm) var(--space-lg);

  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  line-height: 1;
  text-align: center;
  white-space: nowrap;

  border: 2px solid transparent;
  border-radius: var(--radius-md);

  cursor: pointer;
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);

  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

/**
 * Button Variants
 */

/* Primary Button - Main call to action */
.btn--primary {
  background-color: var(--color-primary);
  color: var(--color-text-inverse);
}

.btn--primary:hover:not(:disabled) {
  background-color: var(--color-primary-hover);
  box-shadow: var(--shadow-primary);
}

.btn--primary:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* Secondary Button - Secondary actions */
.btn--secondary {
  background-color: var(--color-secondary);
  color: var(--color-text-inverse);
}

.btn--secondary:hover:not(:disabled) {
  background-color: var(--color-secondary-hover);
}

/* Outline Button - Tertiary actions */
.btn--outline {
  background-color: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}

.btn--outline:hover:not(:disabled) {
  background-color: var(--color-surface);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* Ghost Button - Minimal emphasis */
.btn--ghost {
  background-color: transparent;
  color: var(--color-text);
}

.btn--ghost:hover:not(:disabled) {
  background-color: var(--color-divider);
}

/* Danger Button - Destructive actions */
.btn--danger {
  background-color: var(--color-error);
  color: var(--color-text-inverse);
}

.btn--danger:hover:not(:disabled) {
  background-color: #b91c1c;
  box-shadow: var(--shadow-error);
}

/**
 * Button Sizes
 */
.btn--sm {
  min-height: 36px;
  padding: var(--space-xs) var(--space-md);
  font-size: var(--font-size-sm);
}

.btn--lg {
  min-height: 52px;
  padding: var(--space-md) var(--space-xl);
  font-size: var(--font-size-lg);
}

/**
 * Button with Icon Only
 */
.btn--icon {
  padding: var(--space-sm);
  border-radius: var(--radius-full);
}

.btn--icon.btn--sm {
  padding: var(--space-xs);
  min-height: 36px;
  min-width: 36px;
}

.btn--icon.btn--lg {
  padding: var(--space-md);
  min-height: 56px;
  min-width: 56px;
}

/**
 * Full Width Button
 */
.btn--block {
  width: 100%;
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */

.card {
  background-color: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card--elevated {
  box-shadow: var(--shadow-md);
}

.card--interactive {
  cursor: pointer;
  transition:
    box-shadow var(--transition-normal),
    transform var(--transition-normal);
}

.card--interactive:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.card--interactive:active {
  transform: translateY(0);
}

.card--bordered {
  box-shadow: none;
  border: 1px solid var(--color-border);
}

.card__header {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-divider);
}

.card__body {
  padding: var(--space-lg);
}

.card__footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-divider);
  background-color: var(--color-background);
}

/* --------------------------------------------------------------------------
   Form Inputs
   -------------------------------------------------------------------------- */

/**
 * Form Group - Container for label + input
 */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

/**
 * Form Label
 */
.form-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
}

.form-label--required::after {
  content: ' *';
  color: var(--color-error);
}

/**
 * Base Input Styles
 */
.input,
.select,
.textarea {
  width: 100%;
  min-height: 44px;
  padding: var(--space-sm) var(--space-md);

  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--color-text);

  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);

  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--color-text-tertiary);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--color-text-tertiary);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  background-color: var(--color-divider);
  cursor: not-allowed;
  opacity: 0.6;
}

/**
 * Input States
 */
.input--error,
.select--error,
.textarea--error {
  border-color: var(--color-error);
}

.input--error:focus,
.select--error:focus,
.textarea--error:focus {
  box-shadow: 0 0 0 3px var(--color-error-light);
}

.input--success,
.select--success {
  border-color: var(--color-success);
}

/**
 * Textarea
 */
.textarea {
  min-height: 100px;
  resize: vertical;
}

/**
 * Select
 */
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-sm) center;
  background-size: 20px;
  padding-right: var(--space-2xl);
  cursor: pointer;
}

/**
 * Checkbox and Radio
 */
.checkbox,
.radio {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  min-height: 44px;
}

.checkbox__input,
.radio__input {
  /* Hide native input but keep it accessible */
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.checkbox__box,
.radio__box {
  display: flex;
  align-items: center;
  justify-content: center;

  width: 24px;
  height: 24px;
  flex-shrink: 0;

  background-color: var(--color-surface);
  border: 2px solid var(--color-border);
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast);
}

.checkbox__box {
  border-radius: var(--radius-sm);
}

.radio__box {
  border-radius: var(--radius-full);
}

/* Hover state */
.checkbox:hover .checkbox__box,
.radio:hover .radio__box {
  border-color: var(--color-primary);
}

/* Checked state */
.checkbox__input:checked + .checkbox__box,
.radio__input:checked + .radio__box {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
}

/* Checkmark icon */
.checkbox__input:checked + .checkbox__box::after {
  content: '';
  width: 6px;
  height: 10px;
  border: solid var(--color-text-inverse);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  margin-bottom: 2px;
}

/* Radio dot */
.radio__input:checked + .radio__box::after {
  content: '';
  width: 8px;
  height: 8px;
  background-color: var(--color-text-inverse);
  border-radius: var(--radius-full);
}

/* Focus state */
.checkbox__input:focus-visible + .checkbox__box,
.radio__input:focus-visible + .radio__box {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

.checkbox__label,
.radio__label {
  font-size: var(--font-size-base);
  color: var(--color-text);
  user-select: none;
}

/**
 * Form Helper Text
 */
.form-helper {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.form-error {
  font-size: var(--font-size-xs);
  color: var(--color-error);
}

/* --------------------------------------------------------------------------
   Bottom Navigation Bar
   -------------------------------------------------------------------------- */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;

  display: flex;
  align-items: stretch;
  justify-content: space-around;

  height: var(--bottom-nav-height);
  padding-bottom: var(--safe-area-inset-bottom);

  background-color: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1);

  z-index: var(--z-fixed);
}

.bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);

  flex: 1;
  min-width: 64px;
  max-width: 168px;
  padding: var(--space-xs) var(--space-sm);

  color: var(--color-text-secondary);
  text-decoration: none;

  transition: color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}

.bottom-nav__item:hover {
  color: var(--color-primary);
}

.bottom-nav__item--active {
  color: var(--color-primary);
}

.bottom-nav__icon {
  width: 24px;
  height: 24px;
}

.bottom-nav__label {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  line-height: 1;
}

/* --------------------------------------------------------------------------
   Floating Action Button (FAB)
   -------------------------------------------------------------------------- */

.fab {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + var(--space-md) + var(--safe-area-inset-bottom));
  right: var(--space-md);

  display: flex;
  align-items: center;
  justify-content: center;

  width: var(--fab-size);
  height: var(--fab-size);

  background-color: var(--color-primary);
  color: var(--color-text-inverse);

  border: none;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg), var(--shadow-primary);

  cursor: pointer;
  z-index: var(--z-fixed);

  transition:
    background-color var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);

  -webkit-tap-highlight-color: transparent;
}

.fab:hover {
  background-color: var(--color-primary-hover);
  transform: scale(1.05);
}

.fab:active {
  transform: scale(0.95);
}

.fab:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

.fab__icon {
  width: 24px;
  height: 24px;
}

/* Mini FAB */
.fab--mini {
  width: var(--fab-mini-size);
  height: var(--fab-mini-size);
}

.fab--mini .fab__icon {
  width: 20px;
  height: 20px;
}

/* Extended FAB with label */
.fab--extended {
  width: auto;
  padding: 0 var(--space-lg);
  gap: var(--space-sm);
  border-radius: var(--radius-xl);
}

/* FAB Menu (expandable) */
.fab-menu {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + var(--space-md) + var(--safe-area-inset-bottom));
  right: var(--space-md);

  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: var(--space-md);

  z-index: var(--z-fixed);
}

.fab-menu__items {
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-sm);

  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition:
    opacity var(--transition-normal),
    visibility var(--transition-normal),
    transform var(--transition-normal);
}

.fab-menu--open .fab-menu__items {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.fab-menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.fab-menu__label {
  padding: var(--space-xs) var(--space-sm);

  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;

  background-color: var(--color-surface);
  color: var(--color-text);

  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}

/* Rotate main FAB icon when menu is open */
.fab-menu--open .fab-menu__trigger .fab__icon {
  transform: rotate(45deg);
}

/* --------------------------------------------------------------------------
   Toast Notifications
   -------------------------------------------------------------------------- */

.toast-container {
  position: fixed;
  top: var(--space-md);
  left: var(--space-md);
  right: var(--space-md);

  display: flex;
  flex-direction: column;
  gap: var(--space-sm);

  z-index: var(--z-toast);
  pointer-events: none;
}

/* Bottom position for toasts (above bottom nav) */
.toast-container--bottom {
  top: auto;
  bottom: calc(var(--bottom-nav-height) + var(--space-md) + var(--safe-area-inset-bottom));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);

  max-width: 500px;
  margin: 0 auto;
  padding: var(--space-md);

  background-color: var(--color-surface-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);

  pointer-events: auto;

  animation: toast-enter var(--transition-normal) ease-out;
}

@keyframes toast-enter {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.toast--exiting {
  animation: toast-exit var(--transition-fast) ease-in forwards;
}

@keyframes toast-exit {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-20px);
  }
}

.toast__icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.toast__content {
  flex: 1;
  min-width: 0;
}

.toast__title {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  margin-bottom: var(--space-xs);
}

.toast__message {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.toast__close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;

  color: var(--color-text-tertiary);
  border-radius: var(--radius-full);

  transition:
    background-color var(--transition-fast),
    color var(--transition-fast);
}

.toast__close:hover {
  background-color: var(--color-divider);
  color: var(--color-text);
}

/* Toast Variants */
.toast--success {
  border-left: 4px solid var(--color-success);
}

.toast--success .toast__icon {
  color: var(--color-success);
}

.toast--warning {
  border-left: 4px solid var(--color-warning);
}

.toast--warning .toast__icon {
  color: var(--color-warning);
}

.toast--error {
  border-left: 4px solid var(--color-error);
}

.toast--error .toast__icon {
  color: var(--color-error);
}

.toast--info {
  border-left: 4px solid var(--color-info);
}

.toast--info .toast__icon {
  color: var(--color-info);
}

/* --------------------------------------------------------------------------
   Modal/Dialog
   -------------------------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;

  background-color: rgb(0 0 0 / 0.5);
  backdrop-filter: blur(4px);

  z-index: var(--z-modal-backdrop);

  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--transition-normal),
    visibility var(--transition-normal);
}

.modal-backdrop--visible {
  opacity: 1;
  visibility: visible;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);

  width: calc(100% - var(--space-xl));
  max-width: 500px;
  max-height: calc(100vh - var(--space-xl));

  background-color: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-2xl);

  overflow: hidden;
  z-index: var(--z-modal);

  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--transition-normal),
    visibility var(--transition-normal),
    transform var(--transition-normal);
}

.modal--visible {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

/* Full screen modal on mobile */
.modal--fullscreen {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border-radius: 0;
  transform: translate(-50%, -50%);
}

@media (max-width: 640px) {
  .modal--mobile-fullscreen {
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    border-radius: 0;
    transform: translate(-50%, -50%);
  }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);

  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-divider);
}

.modal__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

.modal__close {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;

  color: var(--color-text-tertiary);
  border-radius: var(--radius-full);

  transition:
    background-color var(--transition-fast),
    color var(--transition-fast);
}

.modal__close:hover {
  background-color: var(--color-divider);
  color: var(--color-text);
}

.modal__body {
  padding: var(--space-lg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm);

  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--color-divider);
}

/* --------------------------------------------------------------------------
   Loading Spinner
   -------------------------------------------------------------------------- */

.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;

  border: 3px solid var(--color-divider);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-full);

  animation: spinner-rotate 0.8s linear infinite;
}

@keyframes spinner-rotate {
  to {
    transform: rotate(360deg);
  }
}

/* Spinner Sizes */
.spinner--sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.spinner--lg {
  width: 40px;
  height: 40px;
  border-width: 4px;
}

.spinner--xl {
  width: 56px;
  height: 56px;
  border-width: 5px;
}

/* Loading Overlay */
.loading-overlay {
  position: absolute;
  inset: 0;

  display: flex;
  align-items: center;
  justify-content: center;

  background-color: rgb(255 255 255 / 0.8);
  z-index: var(--z-fixed);
}

[data-theme="dark"] .loading-overlay {
  background-color: rgb(15 23 42 / 0.8);
}

@media (prefers-color-scheme: dark) {
  .loading-overlay {
    background-color: rgb(15 23 42 / 0.8);
  }
}

/* ==========================================================================
   7. ACCESSIBILITY
   ========================================================================== */

/**
 * Focus Styles
 * Visible focus rings for keyboard navigation
 */
:focus {
  outline: none;
}

:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* High contrast focus for buttons and interactive elements */
.btn:focus-visible,
.card--interactive:focus-visible,
a:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/**
 * Skip Link
 * Allows keyboard users to skip to main content
 */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-md);

  padding: var(--space-sm) var(--space-md);

  background-color: var(--color-primary);
  color: var(--color-text-inverse);

  border-radius: var(--radius-md);
  z-index: var(--z-max);

  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: var(--space-md);
}

/**
 * Screen Reader Only
 * Visually hidden but accessible to screen readers
 */
.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;
}

.sr-only-focusable:focus {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/**
 * Reduced Motion Support
 * Respects user preference for reduced motion
 */
@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;
  }

  .spinner {
    animation: none;
    border-top-color: transparent;
  }
}

/**
 * Minimum Touch Target Sizes
 * Ensures 44x44px minimum for touch targets (WCAG 2.1 AAA)
 * Applied via classes for flexibility
 */
.touch-target {
  min-width: 44px;
  min-height: 44px;
}

.touch-target-lg {
  min-width: 48px;
  min-height: 48px;
}

/**
 * High Contrast Mode Support
 */
@media (prefers-contrast: more) {
  :root {
    --color-border: #000000;
    --color-text: #000000;
    --color-text-secondary: #000000;
  }

  .btn--primary,
  .btn--secondary {
    border: 2px solid currentColor;
  }

  .input,
  .select,
  .textarea {
    border-width: 2px;
  }
}

/* ==========================================================================
   8. UTILITY CLASSES
   ========================================================================== */

/**
 * Text Alignment
 */
.text-left {
  text-align: left;
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

/**
 * Display Utilities
 */
.hidden {
  display: none !important;
}

.block {
  display: block;
}

.inline-block {
  display: inline-block;
}

.inline {
  display: inline;
}

/* Responsive display utilities */
@media (max-width: 640px) {
  .hidden-mobile {
    display: none !important;
  }
}

@media (min-width: 641px) {
  .hidden-desktop {
    display: none !important;
  }
}

/**
 * Visibility
 */
.visible {
  visibility: visible;
}

.invisible {
  visibility: hidden;
}

/**
 * Spacing Utilities - Margin
 */
.m-0 { margin: 0; }
.m-xs { margin: var(--space-xs); }
.m-sm { margin: var(--space-sm); }
.m-md { margin: var(--space-md); }
.m-lg { margin: var(--space-lg); }
.m-xl { margin: var(--space-xl); }

.mt-0 { margin-top: 0; }
.mt-xs { margin-top: var(--space-xs); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }
.mt-2xl { margin-top: var(--space-2xl); }

.mb-0 { margin-bottom: 0; }
.mb-xs { margin-bottom: var(--space-xs); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }
.mb-2xl { margin-bottom: var(--space-2xl); }

.ml-0 { margin-left: 0; }
.ml-xs { margin-left: var(--space-xs); }
.ml-sm { margin-left: var(--space-sm); }
.ml-md { margin-left: var(--space-md); }
.ml-lg { margin-left: var(--space-lg); }
.ml-auto { margin-left: auto; }

.mr-0 { margin-right: 0; }
.mr-xs { margin-right: var(--space-xs); }
.mr-sm { margin-right: var(--space-sm); }
.mr-md { margin-right: var(--space-md); }
.mr-lg { margin-right: var(--space-lg); }
.mr-auto { margin-right: auto; }

.mx-auto { margin-left: auto; margin-right: auto; }

/**
 * Spacing Utilities - Padding
 */
.p-0 { padding: 0; }
.p-xs { padding: var(--space-xs); }
.p-sm { padding: var(--space-sm); }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }
.p-xl { padding: var(--space-xl); }

.pt-0 { padding-top: 0; }
.pt-xs { padding-top: var(--space-xs); }
.pt-sm { padding-top: var(--space-sm); }
.pt-md { padding-top: var(--space-md); }
.pt-lg { padding-top: var(--space-lg); }
.pt-xl { padding-top: var(--space-xl); }

.pb-0 { padding-bottom: 0; }
.pb-xs { padding-bottom: var(--space-xs); }
.pb-sm { padding-bottom: var(--space-sm); }
.pb-md { padding-bottom: var(--space-md); }
.pb-lg { padding-bottom: var(--space-lg); }
.pb-xl { padding-bottom: var(--space-xl); }

.pl-0 { padding-left: 0; }
.pl-xs { padding-left: var(--space-xs); }
.pl-sm { padding-left: var(--space-sm); }
.pl-md { padding-left: var(--space-md); }
.pl-lg { padding-left: var(--space-lg); }

.pr-0 { padding-right: 0; }
.pr-xs { padding-right: var(--space-xs); }
.pr-sm { padding-right: var(--space-sm); }
.pr-md { padding-right: var(--space-md); }
.pr-lg { padding-right: var(--space-lg); }

.px-md { padding-left: var(--space-md); padding-right: var(--space-md); }
.py-md { padding-top: var(--space-md); padding-bottom: var(--space-md); }
.px-lg { padding-left: var(--space-lg); padding-right: var(--space-lg); }
.py-lg { padding-top: var(--space-lg); padding-bottom: var(--space-lg); }

/**
 * Color Utilities
 */
.text-primary { color: var(--color-primary); }
.text-secondary { color: var(--color-text-secondary); }
.text-tertiary { color: var(--color-text-tertiary); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-error { color: var(--color-error); }
.text-info { color: var(--color-info); }

.bg-primary { background-color: var(--color-primary); }
.bg-primary-light { background-color: var(--color-primary-light); }
.bg-surface { background-color: var(--color-surface); }
.bg-background { background-color: var(--color-background); }
.bg-success-light { background-color: var(--color-success-light); }
.bg-warning-light { background-color: var(--color-warning-light); }
.bg-error-light { background-color: var(--color-error-light); }
.bg-info-light { background-color: var(--color-info-light); }

/**
 * Border Utilities
 */
.border { border: 1px solid var(--color-border); }
.border-0 { border: 0; }
.border-t { border-top: 1px solid var(--color-border); }
.border-b { border-bottom: 1px solid var(--color-border); }
.border-l { border-left: 1px solid var(--color-border); }
.border-r { border-right: 1px solid var(--color-border); }

.rounded-none { border-radius: 0; }
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-full { border-radius: var(--radius-full); }

/**
 * Shadow Utilities
 */
.shadow-none { box-shadow: none; }
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.shadow-xl { box-shadow: var(--shadow-xl); }

/**
 * Width/Height Utilities
 */
.w-full { width: 100%; }
.w-auto { width: auto; }
.max-w-sm { max-width: 400px; }
.h-full { height: 100%; }
.h-auto { height: auto; }
.min-h-screen { min-height: 100vh; min-height: -webkit-fill-available; }

/**
 * Overflow Utilities
 */
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.overflow-scroll { overflow: scroll; -webkit-overflow-scrolling: touch; }
.overflow-x-auto { overflow-x: auto; }
.overflow-y-auto { overflow-y: auto; -webkit-overflow-scrolling: touch; }

/**
 * Position Utilities
 */
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }

/**
 * Text Utilities
 */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.whitespace-nowrap { white-space: nowrap; }
.whitespace-normal { white-space: normal; }

.font-normal { font-weight: var(--font-weight-normal); }
.font-medium { font-weight: var(--font-weight-medium); }
.font-semibold { font-weight: var(--font-weight-semibold); }
.font-bold { font-weight: var(--font-weight-bold); }

.uppercase { text-transform: uppercase; }
.lowercase { text-transform: lowercase; }
.capitalize { text-transform: capitalize; }

/* ==========================================================================
   9. OFFLINE INDICATOR
   ========================================================================== */

/**
 * Offline Indicator Bar
 * Shows when the app is offline
 */
.offline-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;

  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);

  padding: var(--space-sm) var(--space-md);
  padding-top: calc(var(--space-sm) + var(--safe-area-inset-top));

  background-color: var(--color-warning);
  color: #000000;

  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);

  z-index: var(--z-toast);

  transform: translateY(-100%);
  transition: transform var(--transition-normal);
}

.offline-indicator--visible {
  transform: translateY(0);
}

.offline-indicator__icon {
  width: 16px;
  height: 16px;
}

/**
 * Offline Badge
 * Smaller indicator for specific components
 */
.offline-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);

  padding: var(--space-xs) var(--space-sm);

  background-color: var(--color-warning-light);
  color: var(--color-warning);

  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);

  border-radius: var(--radius-full);
}

/**
 * Offline Content Indicator
 * Shows cached/stale data warning
 */
.offline-content {
  position: relative;
}

.offline-content::before {
  content: '';
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);

  width: 8px;
  height: 8px;

  background-color: var(--color-warning);
  border-radius: var(--radius-full);
}

/* ==========================================================================
   10. PULL-TO-REFRESH INDICATOR
   ========================================================================== */

/**
 * Pull-to-Refresh Container
 * Wrapper that enables pull-to-refresh functionality
 */
.pull-to-refresh {
  position: relative;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/**
 * Pull-to-Refresh Indicator
 * The visual spinner/indicator shown during pull
 */
.pull-indicator {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);

  display: flex;
  align-items: center;
  justify-content: center;

  width: 40px;
  height: 40px;

  background-color: var(--color-surface);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-md);

  transition: transform var(--transition-normal);
  z-index: var(--z-sticky);
}

/* States */
.pull-indicator--pulling {
  transform: translateX(-50%) translateY(var(--pull-distance, 0px));
}

.pull-indicator--refreshing {
  transform: translateX(-50%) translateY(60px);
}

.pull-indicator__icon {
  width: 24px;
  height: 24px;
  color: var(--color-primary);

  transition: transform var(--transition-normal);
}

.pull-indicator--pulling .pull-indicator__icon {
  transform: rotate(calc(var(--pull-progress, 0) * 180deg));
}

.pull-indicator--refreshing .pull-indicator__icon {
  animation: spinner-rotate 0.8s linear infinite;
}

/**
 * Alternative: Loading Bar Style
 */
.pull-loading-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;

  background-color: var(--color-primary-light);
  z-index: var(--z-toast);

  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--transition-normal);
}

.pull-loading-bar--active {
  transform: scaleX(var(--pull-progress, 0));
}

.pull-loading-bar--refreshing {
  animation: loading-bar 1.5s ease-in-out infinite;
}

@keyframes loading-bar {
  0% {
    transform: scaleX(0);
    transform-origin: left;
  }
  50% {
    transform: scaleX(1);
    transform-origin: left;
  }
  50.01% {
    transform-origin: right;
  }
  100% {
    transform: scaleX(0);
    transform-origin: right;
  }
}

/* ==========================================================================
   ADDITIONAL COMPONENT STYLES
   ========================================================================== */

/**
 * Header/App Bar
 */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;

  display: flex;
  align-items: center;
  gap: var(--space-md);

  height: var(--header-height);
  padding: 0 var(--space-md);
  padding-top: var(--safe-area-inset-top);

  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);

  z-index: var(--z-sticky);
}

.header__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

.header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  margin-left: auto;
}

/**
 * Avatar
 */
.avatar {
  display: flex;
  align-items: center;
  justify-content: center;

  width: 40px;
  height: 40px;

  background-color: var(--color-primary-light);
  color: var(--color-primary);

  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);

  border-radius: var(--radius-full);
  overflow: hidden;
}

.avatar--sm {
  width: 32px;
  height: 32px;
  font-size: var(--font-size-sm);
}

.avatar--lg {
  width: 56px;
  height: 56px;
  font-size: var(--font-size-xl);
}

.avatar__image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/**
 * Badge/Chip
 */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);

  padding: var(--space-xs) var(--space-sm);

  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  line-height: 1;

  background-color: var(--color-divider);
  color: var(--color-text);

  border-radius: var(--radius-full);
}

.badge--primary {
  background-color: var(--color-primary-light);
  color: var(--color-primary);
}

.badge--success {
  background-color: var(--color-success-light);
  color: var(--color-success);
}

.badge--warning {
  background-color: var(--color-warning-light);
  color: var(--color-warning);
}

.badge--error {
  background-color: var(--color-error-light);
  color: var(--color-error);
}

/**
 * Divider
 */
.divider {
  height: 1px;
  background-color: var(--color-divider);
  border: none;
  margin: var(--space-md) 0;
}

.divider--thick {
  height: 8px;
  background-color: var(--color-background);
}

/**
 * Empty State
 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);

  padding: var(--space-2xl);
  text-align: center;
}

.empty-state__icon {
  width: 64px;
  height: 64px;
  color: var(--color-text-tertiary);
}

.empty-state__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

.empty-state__description {
  font-size: var(--font-size-base);
  color: var(--color-text-secondary);
  max-width: 280px;
}

/**
 * List Item
 */
.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);

  min-height: 56px;
  padding: var(--space-sm) var(--space-md);

  background-color: var(--color-surface);

  transition: background-color var(--transition-fast);
}

.list-item--interactive {
  cursor: pointer;
}

.list-item--interactive:hover {
  background-color: var(--color-divider);
}

.list-item--interactive:active {
  background-color: var(--color-primary-light);
}

.list-item__leading {
  flex-shrink: 0;
}

.list-item__content {
  flex: 1;
  min-width: 0;
}

.list-item__title {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
}

.list-item__subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.list-item__trailing {
  flex-shrink: 0;
  color: var(--color-text-tertiary);
}

/* ==========================================================================
   DOCUMENT VAULT STYLES
   ========================================================================== */

/**
 * Documents Page Layout
 */
.documents-page {
  padding: var(--space-md);
}

.documents-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.documents-header__title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  margin: 0;
}

.documents-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.documents-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

/**
 * Expiring Documents Warning
 */
.expiring-warning {
  background-color: var(--color-warning-light);
  border-color: var(--color-warning);
}

.expiring-warning__header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-bottom: 1px solid var(--color-warning);
}

.expiring-warning__icon {
  color: var(--color-warning);
}

.expiring-warning__icon svg {
  width: 20px;
  height: 20px;
}

.expiring-warning__title {
  flex: 1;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin: 0;
}

.expiring-warning__list {
  padding: var(--space-sm);
}

.expiring-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--transition-fast);
  text-align: left;
}

.expiring-item:hover {
  background-color: rgb(0 0 0 / 0.05);
}

.expiring-item__name {
  font-size: var(--font-size-sm);
  color: var(--color-text);
}

.expiring-item__date {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
}

.expiring-item--more {
  justify-content: center;
  color: var(--color-primary);
  font-weight: var(--font-weight-medium);
}

/**
 * Documents Search
 */
.documents-search {
  position: relative;
}

.documents-search__input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.documents-search__input-wrapper svg {
  position: absolute;
  left: var(--space-md);
  color: var(--color-text-tertiary);
  pointer-events: none;
}

.documents-search__input {
  padding-left: calc(var(--space-md) * 2 + 20px);
  padding-right: var(--space-2xl);
}

.documents-search__clear {
  position: absolute;
  right: var(--space-xs);
}

/**
 * Documents Filters
 */
.documents-filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.documents-filters__categories {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  overflow-x: auto;
  padding-bottom: var(--space-xs);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.documents-filters__categories::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-secondary);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.filter-chip:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.filter-chip--active {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-text-inverse);
}

.filter-chip__icon {
  font-size: 16px;
}

.documents-filters__archive {
  align-self: flex-start;
}

/**
 * Documents Grid
 */
.documents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
}

@media (max-width: 640px) {
  .documents-grid {
    grid-template-columns: 1fr;
  }
}

/**
 * Documents List
 */
.documents-list {
  display: flex;
  flex-direction: column;
  background-color: var(--color-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.documents-list .document-row:not(:last-child) {
  border-bottom: 1px solid var(--color-divider);
}

/**
 * Document Card (Grid View)
 */
.document-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.document-card--archived {
  opacity: 0.7;
}

.document-card__thumbnail {
  position: relative;
  height: 140px;
  background-color: var(--color-background);
  display: flex;
  align-items: center;
  justify-content: center;
}

.document-card__archived-badge {
  position: absolute;
  top: var(--space-sm);
  left: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-inverse);
  background-color: var(--color-text-tertiary);
  border-radius: var(--radius-sm);
}

.document-card__ocr-badge {
  position: absolute;
  bottom: var(--space-sm);
  right: var(--space-sm);
}

.document-card__content {
  padding: var(--space-md);
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.document-card__category {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.document-card__category .material-icons {
  font-size: 14px;
}

.document-card__name {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin: 0;
  line-height: var(--line-height-tight);
}

.document-card__description {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin: 0;
}

.document-card__meta {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  margin-top: auto;
}

.document-card__indicators {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-xs);
}

.indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
}

.indicator--ocr svg {
  width: 14px;
  height: 14px;
}

.indicator--versions {
  padding: 2px 6px;
  background-color: var(--color-divider);
  border-radius: var(--radius-sm);
  font-weight: var(--font-weight-medium);
}

/**
 * Document Row (List View)
 */
.document-row--archived {
  opacity: 0.7;
}

/**
 * Thumbnail
 */
.thumbnail {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--color-background);
  border-radius: var(--radius-md);
}

.thumbnail--small {
  width: 48px;
  height: 48px;
}

.thumbnail .material-icons {
  font-size: 32px;
  color: var(--color-text-tertiary);
}

.thumbnail--small .material-icons {
  font-size: 24px;
}

.thumbnail--image {
  background-color: var(--color-info-light);
}

.thumbnail--image .material-icons {
  color: var(--color-info);
}

.thumbnail--pdf {
  background-color: var(--color-error-light);
}

.thumbnail--pdf .material-icons {
  color: var(--color-error);
}

/**
 * Document Detail Page
 */
.document-detail {
  padding: var(--space-md);
}

.document-detail__header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.document-detail__title {
  flex: 1;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-detail__content {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

/**
 * Document Preview
 */
.doc-preview {
  padding: var(--space-lg);
}

.doc-preview__image {
  margin-bottom: var(--space-lg);
}

.preview {
  height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  background-color: var(--color-background);
  border-radius: var(--radius-lg);
}

.preview__icon {
  font-size: 48px;
  color: var(--color-text-tertiary);
}

.preview__label {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.preview--image {
  background-color: var(--color-info-light);
}

.preview--image .preview__icon {
  color: var(--color-info);
}

.preview--pdf {
  background-color: var(--color-error-light);
}

.preview--pdf .preview__icon {
  color: var(--color-error);
}

.doc-preview__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.doc-preview__actions .btn {
  flex: 1;
  min-width: 140px;
}

/**
 * Document Info
 */
.doc-info__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin: 0;
}

.doc-info__item {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.doc-info__item dt {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.doc-info__item dd {
  font-size: var(--font-size-base);
  color: var(--color-text);
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.doc-info__item dd .material-icons {
  font-size: 18px;
  color: var(--color-text-secondary);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

/**
 * OCR Section
 */
.doc-ocr__actions {
  display: flex;
  gap: var(--space-sm);
}

.ocr-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-xl);
  text-align: center;
  color: var(--color-text-secondary);
}

.ocr-text {
  max-height: 300px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.ocr-text__content {
  font-family: inherit;
  font-size: var(--font-size-sm);
  line-height: var(--line-height-relaxed);
  color: var(--color-text);
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.ocr-empty,
.ocr-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-lg);
  text-align: center;
  color: var(--color-text-secondary);
}

.ocr-error .material-icons {
  font-size: 32px;
}

/**
 * Version History
 */
.versions-list {
  padding: var(--space-md);
}

.version-item {
  display: flex;
  gap: var(--space-md);
}

.version-item__indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: var(--space-xs);
}

.version-item__dot {
  width: 12px;
  height: 12px;
  border-radius: var(--radius-full);
  background-color: var(--color-border);
  flex-shrink: 0;
}

.version-item--current .version-item__dot {
  background-color: var(--color-primary);
}

.version-item__line {
  width: 2px;
  flex: 1;
  background-color: var(--color-border);
  margin-top: var(--space-xs);
}

.version-item__content {
  flex: 1;
  padding-bottom: var(--space-lg);
}

.version-item__header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-xs);
}

.version-item__number {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text);
}

.version-item__meta {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.version-item__notes {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin: var(--space-sm) 0;
  font-style: italic;
}

.version-item__actions {
  margin-top: var(--space-sm);
}

/**
 * Upload Modal
 */
.upload-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.drop-zone {
  position: relative;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  text-align: center;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.drop-zone:hover,
.drop-zone--active {
  border-color: var(--color-primary);
  background-color: var(--color-primary-light);
}

.drop-zone__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
}

.drop-zone__content svg {
  color: var(--color-text-tertiary);
}

.drop-zone__text {
  font-size: var(--font-size-base);
  color: var(--color-text-secondary);
  margin: 0;
}

.drop-zone__hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  margin: 0;
}

.drop-zone__preview {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  background-color: var(--color-background);
  border-radius: var(--radius-md);
}

.file-preview__info {
  flex: 1;
  text-align: left;
}

.file-preview__name {
  display: block;
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-preview__size {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.upload-progress {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.upload-progress__status {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  text-align: center;
}

/**
 * Progress Bar
 */
.progress-bar {
  height: 8px;
  background-color: var(--color-divider);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  background-color: var(--color-primary);
  border-radius: var(--radius-full);
  transition: width var(--transition-normal);
}

/**
 * Document Options Menu
 */
.doc-options {
  display: flex;
  flex-direction: column;
}

.doc-option {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  color: var(--color-text);
  cursor: pointer;
  transition: background-color var(--transition-fast);
  text-align: left;
  width: 100%;
}

.doc-option:hover {
  background-color: var(--color-divider);
}

.doc-option svg {
  color: var(--color-text-secondary);
}

.doc-option--danger {
  color: var(--color-error);
}

.doc-option--danger svg {
  color: var(--color-error);
}

/* End of main.css */
