/* 
  KAWAL DESIGN SYSTEM - "The Disciplined Anchor"
  Compliant with DESIGN.md specifications, Impeccable Typography Standard, & Full Dual-Theme (Dark/Light) Support
*/

:root {
  --font-family: 'DM Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Typographic Design Tokens */
  --text-xs: 0.75rem;     /* 12px - Micro-labels, Table headers, Badges */
  --text-sm: 0.8125rem;   /* 13px - Muted metadata, Sub-details */
  --text-base: 0.875rem;  /* 14px - Primary Body, Form inputs, Standard text */
  --text-md: 1rem;        /* 16px - Highlights, Card titles, Subheadings */
  --text-lg: 1.125rem;    /* 18px - Section Headings, Modal headers */
  --text-xl: 1.25rem;     /* 20px - Page Sub-banners, H3 */
  --text-2xl: 1.5rem;     /* 24px - Page Titles, H2 */
  --text-3xl: 2.25rem;    /* 36px - Main Hero Banner, H1 */

  /* Typographic Weights */
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --weight-extrabold: 800;

  /* Line Heights */
  --leading-tight: 1.2;
  --leading-normal: 1.5;
  --leading-relaxed: 1.6;

  /* Letter Spacing (Tracking) */
  --tracking-tight: -0.025em;
  --tracking-normal: 0em;
  --tracking-wide: 0.05em;

  /* Brand Accent Tokens */
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #818cf8;
  
  --sky: #0284c7;
  --sky-light: #38bdf8;
  
  --emerald: #16a34a;
  --emerald-light: #34d399;
  --emerald-bg: rgba(22, 163, 74, 0.12);
  
  --amber: #d97706;
  --amber-light: #fbbf24;
  --amber-bg: rgba(217, 119, 6, 0.12);
  
  --rose: #e11d48;
  --rose-light: #f87171;
  --rose-bg: rgba(225, 29, 72, 0.12);
  
  /* Geometry */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  
  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* Default Light Theme Tokens */
  --bg-main: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --border-hover: #cbd5e1;
  --border-focus: #4f46e5;
  --input-bg: #ffffff;
  --table-hover: rgba(15, 23, 42, 0.03);

  --emerald-bg: rgba(22, 163, 74, 0.1);
  --emerald-light: #15803d;

  --sky-light: #0284c7;

  --amber-bg: rgba(217, 119, 6, 0.1);
  --amber-light: #b45309;

  --rose-bg: rgba(225, 29, 72, 0.1);
  --rose-light: #be123c;
}

/* Dark Theme Tokens */
[data-theme="dark"] {
  --bg-main: #020617;
  --bg-surface: #0f172a;
  --bg-surface-elevated: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #1e293b;
  --border-hover: #334155;
  --border-focus: #4f46e5;
  --input-bg: #020617;
  --table-hover: rgba(255, 255, 255, 0.03);

  --emerald-bg: rgba(22, 163, 74, 0.12);
  --emerald-light: #34d399;

  --sky-light: #38bdf8;

  --amber-bg: rgba(217, 119, 6, 0.12);
  --amber-light: #fbbf24;

  --rose-bg: rgba(225, 29, 72, 0.12);
  --rose-light: #f87171;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: background-color 0.25s ease, color 0.25s ease;
}

a {
  color: var(--sky-light);
  text-decoration: none;
  transition: color 0.15s ease;
}

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

a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Standardized Headings */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-main);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}

h1 { font-size: clamp(1.5rem, 3vw, var(--text-3xl)); font-weight: var(--weight-extrabold); }
h2 { font-size: var(--text-2xl); font-weight: var(--weight-bold); }
h3 { font-size: var(--text-xl); font-weight: var(--weight-bold); }
h4 { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
h5 { font-size: var(--text-md); font-weight: var(--weight-semibold); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  padding: 8px 16px;
  min-height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  line-height: var(--leading-tight);
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
  color: #ffffff;
}

.btn-secondary {
  background-color: var(--bg-surface-elevated);
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-secondary:hover {
  background-color: var(--bg-surface);
  border-color: var(--border-hover);
}

.btn-emerald {
  background-color: var(--emerald);
  color: #ffffff;
}
.btn-emerald:hover {
  background-color: #15803d;
}

.btn-danger {
  background-color: var(--rose);
  color: #ffffff;
}
.btn-danger:hover {
  background-color: #be123c;
}

.btn-sm {
  padding: 4px 10px;
  min-height: 30px;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 12px 24px;
  min-height: 44px;
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}

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

.form-group label {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.form-control, select.form-control, textarea.form-control {
  width: 100%;
  padding: 8px 12px;
  min-height: 38px;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  color: var(--text-main);
  background-color: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.25s ease;
}

textarea.form-control {
  min-height: 80px;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}

/* Layout Containers */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-md);
}

.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: var(--space-md);
  margin-bottom: var(--space-md);
  border-bottom: 1px solid var(--border-color);
}

.card-header h3 {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.02em;
  line-height: var(--leading-tight);
}

.badge-emerald {
  background-color: var(--emerald-bg);
  color: var(--emerald-light);
  border: 1px solid rgba(22, 163, 74, 0.3);
}

.badge-amber {
  background-color: var(--amber-bg);
  color: var(--amber-light);
  border: 1px solid rgba(217, 119, 6, 0.3);
}

.badge-rose {
  background-color: var(--rose-bg);
  color: var(--rose-light);
  border: 1px solid rgba(225, 29, 72, 0.3);
}

.badge-sky {
  background-color: rgba(2, 132, 199, 0.1);
  color: var(--sky-light);
  border: 1px solid rgba(2, 132, 199, 0.3);
}

.badge-indigo {
  background-color: rgba(79, 70, 229, 0.1);
  color: var(--primary-light);
  border: 1px solid rgba(79, 70, 229, 0.3);
}

/* Tables (High-Density Data Grid) */
.table-responsive {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: var(--text-base);
}

.table th {
  background-color: var(--bg-surface-elevated);
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
  font-size: var(--text-base);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

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

/* Public & Admin Navigation Layout */
.app-header {
  height: 64px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.header-container-public {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-container-admin {
  width: 100%;
  padding: 0 var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--text-xl);
  font-weight: var(--weight-extrabold);
  color: var(--text-main);
  letter-spacing: var(--tracking-tight);
  line-height: 1;
}

.brand-logo span.tag {
  font-size: var(--text-xs);
  padding: 3px 6px;
  background-color: var(--primary);
  color: #fff;
  border-radius: var(--radius-sm);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  font-weight: var(--weight-bold);
  line-height: 1;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  list-style: none;
}

.nav-links a {
  color: var(--text-muted);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.nav-links a:hover, .nav-links a.active {
  color: var(--text-main);
  background-color: var(--bg-surface-elevated);
}

/* Theme Switcher Button */
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background-color: var(--bg-surface-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  min-height: 32px;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
  border-color: var(--border-hover);
}

/* Admin Dashboard Grid Layout */
.admin-layout {
  display: flex;
  min-height: calc(100vh - 64px);
}

.admin-sidebar {
  width: 240px;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  padding: var(--space-md);
  flex-shrink: 0;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.sidebar-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: var(--text-muted);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

.sidebar-menu a:hover, .sidebar-menu a.active {
  color: var(--text-main);
  background-color: var(--bg-surface-elevated);
}

.sidebar-menu a.active {
  border-left: 3px solid var(--primary);
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.admin-content {
  flex: 1;
  padding: var(--space-lg);
  background-color: var(--bg-main);
  overflow-y: auto;
  transition: background-color 0.25s ease;
}

/* Stats Cards Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.stat-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-md);
}

.stat-card .label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

.stat-card .value {
  font-size: 1.75rem;
  font-weight: var(--weight-bold);
  margin-top: 4px;
  color: var(--text-main);
  letter-spacing: var(--tracking-tight);
}

/* Autocomplete Dropdown styling */
.autocomplete-wrapper {
  position: relative;
}

.autocomplete-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  max-height: 220px;
  overflow-y: auto;
  z-index: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  display: none;
}

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  transition: background 0.15s ease;
  color: var(--text-main);
  font-size: var(--text-base);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item:hover {
  background-color: var(--primary);
  color: #fff;
}

/* Selected Team Member Tag Chips */
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--text-main);
}

.chip .remove-btn {
  cursor: pointer;
  color: var(--rose-light);
  font-weight: var(--weight-bold);
}

/* Radio & Checkbox Cards for Tracer Study */
.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-md);
  margin-top: var(--space-md);
}

.option-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.option-card:hover {
  border-color: var(--primary);
  background-color: var(--bg-surface-elevated);
}

.option-card input[type="radio"] {
  margin-top: 3px;
  accent-color: var(--primary);
}

.option-card.selected {
  border-color: var(--primary);
  background-color: rgba(79, 70, 229, 0.08);
}

/* Dynamic sub-section containers */
.tracer-section {
  display: none;
  animation: fadeIn 0.25s ease forwards;
}

.tracer-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Footer */
.app-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-color);
  padding: var(--space-md) 0;
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-xs);
  background-color: var(--bg-surface);
}

/* Responsive Breakpoints */
@media (max-width: 768px) {
  .admin-layout {
    flex-direction: column;
  }

  .admin-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 12px;
  }

  .sidebar-menu {
    flex-direction: row;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 4px;
  }

  .sidebar-menu li {
    white-space: nowrap;
  }

  .sidebar-menu a.active {
    border-left: none;
    border-bottom: 3px solid var(--primary);
    border-radius: var(--radius-md);
  }

  .header-container-public {
    flex-wrap: wrap;
    gap: 12px;
  }

  .nav-links {
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .admin-content {
    padding: var(--space-md);
  }
}

/* Responsive Grid Utilities for Stats & Analytics */
.responsive-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-md);
}

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

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

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

