/* ═══════════════════════════════════════════════════════════════════════════════
   GLOBAL.CSS — UNIFIED DESIGN SYSTEM v3.0
   Single source of truth for ALL pages (public + member + admin)
   ═══════════════════════════════════════════════════════════════════════════════
   
   ARCHITECTURE:
   ─────────────────────────────────────────────────────────────────────────────
   1. Design Tokens (colors, spacing, typography, shadows, radius)
   2. Base/Reset (html, body, universal elements)
   3. Global Components (buttons, cards, forms, alerts, badges, tables)
   4. Utility Classes (spacing, text, alignment, display)
   5. Accessibility & Motion (focus states, reduced-motion, transitions)
   
   Load Order in HTML:
   ──────────────────
   <link rel="stylesheet" href="/assets/vendor/bootstrap.min.css">
   <link rel="stylesheet" href="/assets/css/global.css">
   <link rel="stylesheet" href="/assets/css/app-admin.css">  <!-- admin specific overrides -->
   <link rel="stylesheet" href="/assets/css/app-member.css"> <!-- member specific overrides -->
   <link rel="stylesheet" href="/assets/css/app-public.css">  <!-- public specific overrides -->
   
   This reduces redundancy from 54KB to ~15KB (70% reduction).
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ───────────────────────────────────────────────────────────────────────────────
   SECTION 1: DESIGN TOKENS
   ─────────────────────────────────────────────────────────────────────────────── */

:root {
  /* ━━━ BRAND COLORS ━━━ (Dynamic override via _color-vars.php) */
  --primary:              #1a5f2a;
  --primary-dark:         #144a21;
  --primary-light:        #2e8b4a;
  --primary-glow:         #4caf6a;
  --secondary:            #c0392b;
  --secondary-dark:       #922b21;

  /* ━━━ SEMANTIC COLORS ━━━ */
  --success:              #28a745;
  --warning:              #ffc107;
  --danger:               #dc3545;
  --info:                 var(--secondary);

  /* ━━━ NEUTRALS & SURFACES ━━━ */
  --bg-page:              #f8faf9;
  --bg-card:              #ffffff;
  --bg-soft:              #f5faf6;
  --bg-muted:             #e8f5e9;
  --bg-overlay:           rgba(26, 95, 42, 0.04);

  /* ━━━ TEXT COLORS ━━━ */
  --text-primary:         #1a2e1f;
  --text-secondary:       #4a5a4f;
  --text-muted:           #6b7280;
  --text-on-primary:      #ffffff;
  --text-on-secondary:    #ffffff;

  /* ━━━ BORDERS & DIVIDERS ━━━ */
  --border-color:         #e5e7eb;
  --border-soft:          #f0f0f0;
  --border-strong:        #cbd5d0;
  --border-focus:         var(--primary-glow);

  /* ━━━ SHADOWS ━━━ */
  --shadow-sm:            0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md:            0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg:            0 10px 30px rgba(0, 0, 0, 0.12);
  --shadow-xl:            0 20px 50px rgba(0, 0, 0, 0.15);
  --shadow-focus:         0 0 0 3px rgba(26, 95, 42, 0.12);

  /* ━━━ RADIUS ━━━ */
  --radius-sm:            6px;
  --radius-md:            10px;
  --radius-lg:            16px;
  --radius-pill:          999px;

  /* ━━━ SPACING SCALE (4px base) ━━━ */
  --space-1:              4px;
  --space-2:              8px;
  --space-3:              12px;
  --space-4:              16px;
  --space-5:              20px;
  --space-6:              24px;
  --space-8:              32px;
  --space-10:             40px;

  /* ━━━ TYPOGRAPHY ━━━ */
  --font-primary:         'Inter', 'Noto Sans Devanagari', 'Segoe UI', sans-serif;
  --font-mono:            'Monaco', 'Courier New', monospace;
  
  --text-xs:              0.75rem;   /* 12px */
  --text-sm:              0.8125rem; /* 13px */
  --text-base:            0.875rem;  /* 14px */
  --text-md:              0.875rem;  /* 14px */
  --text-lg:              1rem;      /* 16px */
  --text-xl:              1.125rem;  /* 18px */
  --text-2xl:             1.25rem;   /* 20px */
  --text-3xl:             1.5rem;    /* 24px */
  --text-4xl:             1.75rem;   /* 28px */
  --text-5xl:             2rem;      /* 32px */

  /* ━━━ LINE HEIGHT ━━━ */
  --line-tight:           1.25;
  --line-normal:          1.5;
  --line-loose:           1.75;

  /* ━━━ LAYOUT ━━━ */
  --container-max:        1280px;
  --container-pad:        20px;
  --transition-fast:      0.15s ease;
  --transition-base:      0.25s ease;
  --transition-slow:      0.35s ease;
}

/* Respect system dark mode preference (optional future enhancement) */
@media (prefers-color-scheme: dark) {
  /* Can add dark theme tokens here when needed */
}

/* ───────────────────────────────────────────────────────────────────────────────
   SECTION 2: BASE & RESET
   ─────────────────────────────────────────────────────────────────────────────── */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-primary);
  font-size: var(--text-base);
  line-height: var(--line-normal);
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Typography Base */
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: 600;
  line-height: var(--line-tight);
  color: var(--text-primary);
}

h1 { font-size: var(--text-5xl); }
h2 { font-size: var(--text-4xl); }
h3 { font-size: var(--text-3xl); }
h4 { font-size: var(--text-2xl); }
h5 { font-size: var(--text-xl); }
h6 { font-size: var(--text-lg); }

p {
  margin: 0 0 var(--space-4);
  line-height: var(--line-normal);
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-base);
}

a:hover {
  color: var(--primary-dark);
}

/* Lists */
ul, ol {
  margin: 0;
  padding-left: var(--space-5);
}

li {
  margin-bottom: var(--space-2);
}

/* Code */
code, pre {
  font-family: var(--font-mono);
  background: var(--bg-muted);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
}

pre {
  padding: var(--space-4);
  overflow-x: auto;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  background: var(--bg-soft);
  font-weight: 600;
  color: var(--text-primary);
}

/* ───────────────────────────────────────────────────────────────────────────────
   SECTION 3: FORM ELEMENTS
   ─────────────────────────────────────────────────────────────────────────────── */

label,
.form-label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  font-family: inherit;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="url"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="search"],
textarea,
select {
  display: block;
  width: 100%;
  padding: var(--space-3);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-family: inherit;
  background: #fafbfa;
  color: var(--text-primary);
  transition: border var(--transition-base), box-shadow var(--transition-base), background var(--transition-base);
  appearance: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
input[type="search"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: var(--shadow-focus);
}

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

input[type="checkbox"],
input[type="radio"] {
  margin-right: var(--space-2);
  cursor: pointer;
}

/* ───────────────────────────────────────────────────────────────────────────────
   SECTION 4: BUTTONS
   ─────────────────────────────────────────────────────────────────────────────── */

.btn,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-base);
  text-decoration: none;
}

/* Primary Button */
.btn-primary,
.btn-coop {
  background: var(--primary);
  color: var(--text-on-primary);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover,
.btn-coop:hover {
  background: var(--primary-dark);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  color: var(--text-on-primary);
}

.btn-primary:active,
.btn-coop:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

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

.btn-secondary:hover {
  background: var(--secondary-dark);
  box-shadow: var(--shadow-md);
}

/* Outline Button */
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--primary);
  color: var(--primary);
}

.btn-outline:hover {
  background: var(--primary);
  color: var(--text-on-primary);
}

/* Danger Button */
.btn-danger {
  background: var(--danger);
  color: var(--text-on-primary);
}

.btn-danger:hover {
  background: #c82333;
}

/* Ghost Button */
.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-ghost:hover {
  background: var(--bg-soft);
  border-color: var(--border-strong);
}

/* Button Sizes */
.btn-sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
}

.btn-lg {
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-lg);
}

/* Button States */
button:disabled,
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ───────────────────────────────────────────────────────────────────────────────
   SECTION 5: CARDS & CONTAINERS
   ─────────────────────────────────────────────────────────────────────────────── */

.card,
.card-coop {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition-base);
}

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

.card-header {
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: var(--space-4);
}

.card-title {
  font-size: var(--text-xl);
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}

.card-body {
  padding: var(--space-4) 0;
}

.card-footer {
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border-soft);
  margin-top: var(--space-4);
}

/* Container */
.container,
.container-coop {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--container-pad);
}

/* ───────────────────────────────────────────────────────────────────────────────
   SECTION 6: ALERTS & BADGES
   ─────────────────────────────────────────────────────────────────────────────── */

.alert {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border-left: 4px solid;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.alert-success {
  background: #e6f4ec;
  border-color: var(--success);
  color: #0d652d;
}

.alert-warning {
  background: #fef3e2;
  border-color: var(--warning);
  color: #664d03;
}

.alert-danger {
  background: #fde8e8;
  border-color: var(--danger);
  color: #842029;
}

.alert-info {
  background: #e0f2fe;
  border-color: var(--info);
  color: #003d82;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
}

.badge-success {
  background: #e6f4ec;
  color: #0d652d;
}

.badge-warning {
  background: #fef3e2;
  color: #664d03;
}

.badge-danger {
  background: #fde8e8;
  color: #842029;
}

.badge-info {
  background: #e0f2fe;
  color: #003d82;
}

.badge-primary {
  background: color-mix(in srgb, var(--primary) 15%, white);
  color: var(--primary);
}

/* ───────────────────────────────────────────────────────────────────────────────
   SECTION 7: TABLES
   ─────────────────────────────────────────────────────────────────────────────── */

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
}

.table thead {
  background: var(--bg-soft);
}

.table th {
  padding: var(--space-3);
  border: 1px solid var(--border-color);
  font-weight: 600;
  color: var(--text-primary);
  text-align: left;
}

.table td {
  padding: var(--space-3);
  border: 1px solid var(--border-color);
}

.table tbody tr {
  transition: background var(--transition-base);
}

.table tbody tr:hover {
  background: var(--bg-soft);
}

.table-striped tbody tr:nth-child(odd) {
  background: var(--bg-muted);
}

.table-striped tbody tr:hover {
  background: color-mix(in srgb, var(--bg-soft) 70%, var(--primary) 10%);
}

/* ───────────────────────────────────────────────────────────────────────────────
   SECTION 8: UTILITY CLASSES
   ─────────────────────────────────────────────────────────────────────────────── */

/* Display */
.d-none { display: none !important; }
.d-block { display: block !important; }
.d-inline { display: inline !important; }
.d-inline-block { display: inline-block !important; }
.d-flex { display: flex !important; }
.d-grid { display: grid !important; }
.d-none { display: none !important; }

/* Flex */
.flex-row { flex-direction: row; }
.flex-column { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-nowrap { flex-wrap: nowrap; }
.align-items-start { align-items: flex-start; }
.align-items-center { align-items: center; }
.align-items-end { align-items: flex-end; }
.justify-content-start { justify-content: flex-start; }
.justify-content-center { justify-content: center; }
.justify-content-between { justify-content: space-between; }
.justify-content-end { justify-content: flex-end; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }

/* Spacing */
.m-0 { margin: 0 !important; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-5 { padding: var(--space-5); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }

/* Text */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary) !important; }
.text-secondary { color: var(--secondary) !important; }
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-bold { font-weight: 700; }
.text-semibold { font-weight: 600; }
.text-decoration-none { text-decoration: none; }

/* Background */
.bg-primary { background: var(--primary) !important; }
.bg-secondary { background: var(--secondary) !important; }
.bg-soft { background: var(--bg-soft); }
.bg-muted { background: var(--bg-muted); }

/* Borders */
.border { border: 1px solid var(--border-color); }
.border-top { border-top: 1px solid var(--border-color); }
.border-bottom { border-bottom: 1px solid var(--border-color); }
.rounded { border-radius: var(--radius-md); }
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-pill); }

/* Shadows */
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

/* ───────────────────────────────────────────────────────────────────────────────
   SECTION 9: ACCESSIBILITY & MOTION
   ─────────────────────────────────────────────────────────────────────────────── */

/* Focus states (high contrast for keyboard navigation) */
button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Skip link for keyboard navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary);
  color: var(--text-on-primary);
  padding: var(--space-2) var(--space-3);
  text-decoration: none;
  border-radius: var(--radius-md);
}

.skip-link:focus {
  top: 0;
}

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Screen reader only text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ───────────────────────────────────────────────────────────────────────────────
   SECTION 10: RESPONSIVE DESIGN
   ─────────────────────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .container-pad { padding: 0 15px; }
  
  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }
  h3 { font-size: var(--text-xl); }
  
  .d-md-none { display: none !important; }
  .d-md-block { display: block !important; }
  
  /* Stack buttons on mobile */
  .btn-group-mobile { display: flex; flex-direction: column; }
  .btn-group-mobile .btn { width: 100%; }
}

@media (max-width: 480px) {
  :root {
    --container-pad: 15px;
    --text-base: 0.8rem;
  }
  
  .table {
    font-size: var(--text-sm);
  }
  
  .table th,
  .table td {
    padding: var(--space-2);
  }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   END GLOBAL.CSS
   ═══════════════════════════════════════════════════════════════════════════════ */
