/* ============================================================================
   QATRA — Design Tokens & Global Style System (v2.0)
   Alkhidmat Foundation Emergency Blood Response Platform
   White Theme Only · Apple Design · Production-Grade
   ============================================================================ */

:root {
  color-scheme: light;

  /* Brand Palette */
  --primary-red: #C92A2A;
  --primary-red-hover: #B02020;
  --primary-red-dark: #821515;
  --primary-red-light: rgba(201, 42, 42, 0.08);
  --primary-red-subtle: rgba(201, 42, 42, 0.04);
  --secondary-crimson: #9B1C1C;

  /* Accent & Feedback Colors */
  --color-success: #34C759;
  --color-success-light: rgba(52, 199, 89, 0.1);
  --color-warning: #FF9500;
  --color-warning-light: rgba(255, 149, 0, 0.1);
  --color-danger: #FF3B30;
  --color-danger-light: rgba(255, 59, 48, 0.1);
  --color-info: #007AFF;
  --color-info-light: rgba(0, 122, 255, 0.1);

  /* Neutrals & Typography */
  --text-main: #1D1D1F;
  --text-muted: #6E6E73;
  --text-light: #86868B;
  --text-white: #FFFFFF;

  /* Backgrounds & Borders (Apple HIG Pure White & Canvas) */
  --bg-canvas: #F5F5F7;
  --bg-surface: #FFFFFF;
  --bg-subtle: #F5F5F7;
  --border-color: rgba(0, 0, 0, 0.06);
  --border-color-strong: rgba(0, 0, 0, 0.12);

  /* Shadows (Apple HIG Diffuse & Multi-layer) */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
  --shadow-lg: 0 4px 20px -2px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.02);
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.02);
  --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-elevated: 0 16px 40px -4px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.06);

  /* Radius & Transitions (Apple Continuous Squircles & Spring) */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;
  --radius-full: 9999px;
  --transition-fast: 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-normal: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out: cubic-bezier(0.0, 0.0, 0.2, 1);

  /* Spacing Units */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Font System — Apple SF Pro stack with optical sizing */
  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
  --tracking-display: -0.035em;
  --tracking-title: -0.025em;
  --tracking-heading: -0.015em;
  --tracking-body: -0.005em;
  --tracking-label: 0.01em;
  --tracking-caps: 0.06em;

  /* Glass Material Tokens */
  --glass-bg: rgba(255, 255, 255, 0.82);
  --glass-bg-heavy: rgba(255, 255, 255, 0.92);
  --glass-border: rgba(255, 255, 255, 0.6);
  --glass-border-subtle: rgba(0, 0, 0, 0.06);
  --glass-blur: blur(20px) saturate(180%);
  --glass-blur-heavy: blur(30px) saturate(200%);

  /* Dark canvas fallback */
  --bg-canvas-dark: #0f0f10;
  --bg-surface-dark: #1c1c1e;
  --bg-subtle-dark: #2c2c2e;
  --border-color-dark: rgba(255, 255, 255, 0.08);
  --glass-bg-dark: rgba(28, 28, 30, 0.80);
  --glass-border-dark: rgba(255, 255, 255, 0.12);
}

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

html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

body {
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-main);
  background-color: var(--bg-canvas);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================================
   Responsive Layout & Container System
   Small Mobile (<380px) | Large Mobile (380-640px) | Tablet (641-1024px) |
   Laptop & Desktop (1025-1440px) | Ultra-wide (>1440px)
   ============================================================================ */

.app-container {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  margin: 0 auto;
  min-height: 100vh;
  background-color: var(--bg-canvas);
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Tablet (641px - 1024px) */
@media (min-width: 641px) {
  .app-container {
    max-width: 900px;
    box-shadow: none;
  }
}

/* Laptop & Desktop (1025px - 1440px) */
@media (min-width: 1025px) {
  .app-container {
    max-width: 1240px;
    box-shadow: none;
  }
}

/* Large Desktop / Ultra-wide (>1440px) */
@media (min-width: 1441px) {
  .app-container {
    max-width: 1400px;
  }
}

/* Global Top Navigation Header (Responsive) */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: rgba(255, 255, 255, 0.82);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

@media (min-width: 768px) {
  .app-header {
    padding: 12px 28px;
  }
}

.app-header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--primary-red);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: -0.03em;
  flex-shrink: 0;
}

.app-header .brand-logo {
  height: 36px;
  width: auto;
  max-width: 44px;
  object-fit: contain;
  display: block;
}

/* Desktop Horizontal Navigation Bar */
.desktop-nav {
  display: none;
  align-items: center;
  gap: 4px;
  margin: 0 16px;
  flex-wrap: nowrap;
}

@media (min-width: 1024px) {
  .desktop-nav {
    display: flex;
  }
}

.desktop-nav a {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 13px;
  border-radius: var(--radius-full);
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  letter-spacing: var(--tracking-body);
}

.desktop-nav a:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.65);
}

.desktop-nav a.active {
  color: var(--primary-red);
  background-color: #FFFFFF;
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08), 0 1px 1px rgba(0, 0, 0, 0.03);
}

.app-header .header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

/* Global Mobile Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 100%;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  padding: 8px 8px max(22px, env(safe-area-inset-bottom, 22px)) 8px;
  box-sizing: border-box;
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

/* Hide Bottom Nav on Desktop/Laptops where Top Nav is Active */
@media (min-width: 1024px) {
  .bottom-nav {
    display: none !important;
  }
}

.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  gap: 2px;
  transition: color var(--transition-fast);
  flex: 1;
  padding: 4px 0;
}

.bottom-nav a.active, .bottom-nav a:hover {
  color: var(--primary-red);
}

.bottom-nav .nav-icon {
  font-size: 18px;
}

/* Main Content Area (Adaptive Padding) */
.app-content {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  box-sizing: border-box;
  overflow-x: hidden;
  padding: var(--space-md);
  padding-bottom: 85px; /* offset for mobile bottom nav */
}

@media (min-width: 768px) {
  .app-content {
    padding: var(--space-lg);
    padding-bottom: 85px;
  }
}

@media (min-width: 1024px) {
  .app-content {
    padding: var(--space-xl) var(--space-lg);
    padding-bottom: 40px; /* No offset needed on desktop! */
  }
}

/* Universal Responsive Horizontal Scrolling Component Protection */
.filter-chips-scroll,
.category-pills,
.segmented-control-pills,
.audit-table-wrapper {
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#map-container,
#map,
#live-map,
.leaflet-container {
  max-width: 100vw !important;
  overflow: hidden !important;
}

/* Typography Helpers */
h1, h2, h3, h4 {
  color: var(--text-main);
  font-weight: 700;
  line-height: 1.25;
}

h1 { font-size: 24px; margin-bottom: var(--space-sm); }
h2 { font-size: 20px; margin-bottom: var(--space-sm); }
h3 { font-size: 17px; margin-bottom: var(--space-xs); }
p { color: var(--text-muted); margin-bottom: var(--space-sm); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s cubic-bezier(0.2, 0, 0, 1),
              background-color 0.2s ease,
              box-shadow 0.2s ease,
              opacity 0.2s ease;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: linear-gradient(180deg, #D32F2F 0%, #C92A2A 100%);
  color: #FFFFFF;
  box-shadow: 0 2px 10px rgba(201, 42, 42, 0.28), 0 1px 0 rgba(255, 255, 255, 0.2) inset;
  padding: 8px 18px;
  font-size: 13.5px;
}

.btn-primary:hover {
  background: linear-gradient(180deg, #DE3535 0%, #B02020 100%);
  box-shadow: 0 4px 16px rgba(201, 42, 42, 0.35), 0 1px 0 rgba(255, 255, 255, 0.2) inset;
}

.btn-secondary {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-main);
  border: 1px solid rgba(0, 0, 0, 0.04);
  box-shadow: none;
  padding: 8px 18px;
  font-size: 13.5px;
}

.btn-secondary:hover {
  background: rgba(0, 0, 0, 0.08);
}

.btn-outline {
  border: 1.5px solid var(--primary-red);
  background: transparent;
  color: var(--primary-red);
  padding: 7px 16px;
}

.btn-outline:hover {
  background: var(--primary-red-light);
}

.btn-success {
  background-color: var(--color-success);
  color: var(--text-white);
  box-shadow: 0 2px 8px rgba(52, 199, 89, 0.25);
  padding: 8px 18px;
  font-size: 13.5px;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 12.5px;
  border-radius: var(--radius-full);
  width: auto;
}

/* Cards & Surfaces (Apple Continuous Squircle & Pure White) */
.card {
  background-color: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.2s ease;
}

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

.card-highlight {
  border-color: rgba(201, 42, 42, 0.2);
  box-shadow: 0 4px 20px -2px rgba(201, 42, 42, 0.08), 0 1px 3px rgba(0, 0, 0, 0.02);
}

.card-success {
  border-color: rgba(52, 199, 89, 0.25);
}

.card-warning {
  border-color: rgba(255, 149, 0, 0.25);
}

/* Badges (Apple Pill Badges) */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-blood {
  background-color: var(--primary-red-light);
  color: var(--primary-red);
  font-size: 13.5px;
  font-weight: 700;
  padding: 4px 12px;
}

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

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

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

.badge-gray {
  background-color: rgba(0, 0, 0, 0.05);
  color: var(--text-muted);
}

/* Forms & Inputs (Apple Fields) */
.form-group {
  margin-bottom: var(--space-md);
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 12px 16px;
  font-size: 15px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: #FFFFFF;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
  -webkit-appearance: none;
  appearance: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary-red);
  box-shadow: 0 0 0 4px rgba(201, 42, 42, 0.14);
}

/* Progress Bars */
.progress-bar-container {
  width: 100%;
  height: 8px;
  background-color: var(--border-color);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin: var(--space-xs) 0;
}

.progress-bar-fill {
  height: 100%;
  background-color: var(--primary-red);
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

.progress-bar-fill.success {
  background-color: var(--color-success);
}

/* Global Toast Notifications */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}

.toast {
  padding: 12px 18px;
  background-color: var(--text-main);
  color: var(--text-white);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  opacity: 0;
  transform: translateY(-10px);
  animation: toast-in 0.3s forwards;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 320px;
}

.toast.toast-success { background-color: var(--color-success); }
.toast.toast-error { background-color: var(--color-danger); }
.toast.toast-warning { background-color: var(--color-warning); color: #fff; }

@keyframes toast-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px) saturate(160%);
  -webkit-backdrop-filter: blur(8px) saturate(160%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background-color: #FFFFFF;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: var(--radius-xl);
  max-width: 480px;
  width: 100%;
  padding: 32px 28px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(0, 0, 0, 0.06);
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease;
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* ============================================================================
   PWA Installation Banner & Badges (Mobile Chrome & Desktop)
   ============================================================================ */
.pwa-install-banner {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 480px;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 14px 18px;
  box-shadow: 0 12px 36px -4px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 9998;
  animation: slideUp 0.3s ease-out;
}

@media (min-width: 1024px) {
  .pwa-install-banner {
    bottom: 24px;
    right: 24px;
    left: auto;
    transform: none;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translate(-50%, 20px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.pwa-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pwa-banner-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  object-fit: contain;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.pwa-banner-text {
  display: flex;
  flex-direction: column;
}

.pwa-banner-text strong {
  font-size: 13.5px;
  color: var(--text-main);
}

.pwa-banner-text span {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.3;
}

.pwa-banner-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.pwa-install-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

/* ============================================================================
   Responsive Grid & Split Layout Utilities
   ============================================================================ */
.grid-responsive-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
}

@media (min-width: 641px) {
  .grid-responsive-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.grid-responsive-3 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
}

@media (min-width: 641px) {
  .grid-responsive-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .grid-responsive-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

.grid-responsive-4 {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
}

@media (min-width: 480px) {
  .grid-responsive-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .grid-responsive-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Desktop Split Screen Views (e.g. Map Sidebar + Map Canvas) */
.split-desktop {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

@media (min-width: 1024px) {
  .split-desktop {
    flex-direction: row;
    gap: var(--space-lg);
    align-items: flex-start;
  }

  .split-sidebar {
    width: 380px;
    flex-shrink: 0;
  }

  .split-main {
    flex: 1;
    min-width: 0;
  }
}

/* Visibility toggles */
.hide-on-desktop {
  display: block;
}

.hide-on-mobile {
  display: none;
}

@media (min-width: 1024px) {
  .hide-on-desktop {
    display: none !important;
  }
  .hide-on-mobile {
    display: block !important;
  }
}

/* Form Container Constraints for Desktop/Tablet */
.form-container-sm {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.form-container-md {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
}

.form-container-lg {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
}

/* Responsive Feed Stream Grid */
.feed-stream-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-md);
}

@media (min-width: 680px) {
  .feed-stream-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1200px) {
  .feed-stream-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.feed-stream-grid > .card[style*="text-align: center"] {
  grid-column: 1 / -1;
}

/* Mobile Fine-Tuning (<=640px) */
@media (max-width: 640px) {
  body {
    font-size: 14px;
  }

  h1 { font-size: 22px; }
  h2 { font-size: 19px; }
  h3 { font-size: 16px; }

  .app-content {
    padding: 14px 12px calc(85px + env(safe-area-inset-bottom, 22px)) 12px;
  }

  .card {
    padding: 14px 14px;
  }

  .table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 379px) {
  .app-content {
    padding: 10px 10px calc(85px + env(safe-area-inset-bottom, 22px)) 10px;
  }

  .btn {
    padding: 7px 10px;
    font-size: 12px;
  }

  .card {
    padding: 12px;
  }
}

