/* ============================================
   Delegatiq Design System
   Premium event operations — DM Sans + Playfair Display,
   deep indigo primary, amber accent, dark sidebar
   ============================================ */

/* UM7: Font @import moved to <link> tags in base.html for non-blocking loading */

/* --- CSS Variables --- */
:root {
  /* Primary brand — deeper indigo, more authoritative */
  --primary-50: #eef2ff;
  --primary-100: #e0e7ff;
  --primary-200: #c7d2fe;
  --primary-300: #a5b4fc;
  --primary-400: #818cf8;
  --primary-500: #6366f1;
  --primary-600: #4338ca;
  --primary-700: #3730a3;
  --primary-800: #312e81;
  --primary-900: #1e1b4b;
  --primary: var(--primary-600);
  --primary-hover: var(--primary-700);
  --primary-light: var(--primary-50);
  --primary-ghost: rgba(67, 56, 202, 0.08);
  --primary-ring: rgba(67, 56, 202, 0.25);

  /* Accent — warm amber for active states & highlights */
  --accent: #d97706;
  --accent-hover: #b45309;
  --accent-light: #fef3c7;
  --accent-ghost: rgba(217, 119, 6, 0.12);

  /* Sidebar & navigation — deep ink */
  --nav-bg: #0c0a1e;
  --nav-bg-hover: #1a1730;
  --nav-text: #94a3b8;
  --nav-text-active: #ffffff;
  --nav-accent: #d97706;
  --nav-border: rgba(255, 255, 255, 0.06);

  /* Neutral gray scale */
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;

  /* Content area — warm white instead of cold gray */
  --bg-page: #f7f7f5;
  --bg-card: #ffffff;
  --bg-card-hover: var(--gray-100);
  --bg-inset: var(--gray-100);

  /* Text */
  --text-primary: var(--gray-900);
  --text-secondary: var(--gray-600);
  --text-muted: var(--gray-500); /* UM2: Darkened from gray-400 (#94a3b8) to gray-500 (#64748b) for WCAG AA contrast (5.3:1) */
  --text-placeholder: var(--gray-300);
  --text-inverse: #ffffff;

  /* Borders */
  --border: var(--gray-200);
  --border-strong: var(--gray-300);

  /* Semantic */
  --success: #10b981;
  --success-bg: #ecfdf5;
  --success-text: #065f46;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-text: #92400e;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-text: #991b1b;
  --info: #3b82f6;
  --info-bg: #eff6ff;
  --info-text: #1e40af;

  /* Typography — DM Sans body + Playfair Display for headlines */
  --font-sans: 'DM Sans', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Layout dimensions */
  --sidebar-width: 260px;
  --sidebar-width-collapsed: 64px;
  --topbar-height: 56px;
  --max-content-width: 1320px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04), 0 0 0 1px var(--border);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms cubic-bezier(0.16, 1, 0.3, 1);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background: var(--bg-page);
}

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

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

img, svg { display: block; max-width: 100%; }

table { border-collapse: collapse; width: 100%; }

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
}

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

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

h1 {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  letter-spacing: -0.02em;
}
h2 {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  letter-spacing: -0.015em;
}
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-md); }
h6 { font-size: var(--text-base); font-weight: 500; }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-md { font-size: var(--text-md); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }

.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-primary-color { color: var(--primary); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }

.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.page-title {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.page-subtitle {
  font-size: var(--text-base);
  color: var(--text-secondary);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 36px;
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
  cursor: pointer;
}

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

.btn-primary {
  background: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger);
  color: var(--text-inverse);
  border-color: var(--danger);
}
.btn-danger:hover {
  background: #dc2626;
}

.btn-success {
  background: var(--success);
  color: var(--text-inverse);
  border-color: var(--success);
}

.btn-sm { height: 30px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.btn-lg { height: 44px; padding: 0 var(--space-6); font-size: var(--text-md); }

.btn-icon {
  width: 36px;
  padding: 0;
}
.btn-icon.btn-sm { width: 30px; }
.btn-icon.btn-lg { width: 44px; }

.btn svg { width: 16px; height: 16px; }

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

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

.card-header-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
}

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

.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--bg-inset);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.card-interactive {
  transition: all var(--transition-base);
  cursor: pointer;
}
.card-interactive:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* --- Stat Cards --- */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5) var(--space-6);
  box-shadow: var(--shadow-sm);
  position: relative;
}

.stat-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.stat-card-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-card-icon svg {
  width: 20px;
  height: 20px;
}
.stat-card-icon.primary { background: var(--primary-light); color: var(--primary); }
.stat-card-icon.success { background: var(--success-bg); color: var(--success); }
.stat-card-icon.warning { background: var(--warning-bg); color: var(--warning); }
.stat-card-icon.danger { background: var(--danger-bg); color: var(--danger); }
.stat-card-icon.info { background: var(--info-bg); color: var(--info); }

.stat-value {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: var(--space-1);
}

.stat-label {
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-change {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
}
.stat-change svg { width: 12px; height: 12px; }
.stat-change.up { background: var(--success-bg); color: var(--success-text); }
.stat-change.down { background: var(--danger-bg); color: var(--danger-text); }

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  white-space: nowrap;
  border-left: 2px solid transparent;
}

.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge-invited { background: #dbeafe; color: #1e3a8a; border-left-color: #3b82f6; }
.badge-invited::before { background: #3b82f6; }

.badge-confirmed { background: #bbf7d0; color: #14532d; border-left-color: #16a34a; }
.badge-confirmed::before { background: #16a34a; }

.badge-registered { background: #d1fae5; color: #065f46; border-left-color: #10b981; }
.badge-registered::before { background: #10b981; }

.badge-attended { background: #e0f2fe; color: #0c4a6e; border-left-color: #0ea5e9; }
.badge-attended::before { background: #0ea5e9; }

.badge-declined { background: #fee2e2; color: #7f1d1d; border-left-color: #ef4444; }
.badge-declined::before { background: #ef4444; }

.badge-no-show { background: #fef9c3; color: #713f12; border-left-color: #eab308; }
.badge-no-show::before { background: #eab308; }

.badge-nominated { background: #ede9fe; color: #4c1d95; border-left-color: #8b5cf6; }
.badge-nominated::before { background: #8b5cf6; }

.badge-pending { background: #fef3c7; color: #78350f; border-left-color: #f59e0b; }
.badge-pending::before { background: #f59e0b; }

.badge-active { background: #bbf7d0; color: #14532d; border-left-color: #16a34a; }
.badge-active::before { background: #16a34a; }

.badge-draft { background: var(--bg-inset); color: var(--text-muted); border-left-color: var(--border-strong); }
.badge-draft::before { background: var(--text-muted); }

.badge-error { background: #fee2e2; color: #7f1d1d; border-left-color: #ef4444; }
.badge-error::before { background: #ef4444; }

/* --- Form Inputs --- */
.form-group {
  margin-bottom: var(--space-5);
}

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

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-3);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

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

.form-input::placeholder { color: var(--text-placeholder); }

.form-textarea {
  height: auto;
  min-height: 80px;
  padding: var(--space-3);
  resize: vertical;
}

.form-input-lg {
  height: 44px;
  font-size: var(--text-md);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--danger);
  margin-top: var(--space-1);
}

.form-input.error { border-color: var(--danger); }
.form-input.error:focus { box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2); }

/* --- Tooltips --- */
[data-tip] {
  position: relative;
  cursor: help;
}
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px;
  font-size: var(--text-xs);
  font-weight: 400;
  line-height: 1.4;
  color: #fff;
  background: var(--gray-800);
  border-radius: var(--radius-md);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: 100;
  max-width: 280px;
  white-space: normal;
  text-align: center;
}
[data-tip]::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--gray-800);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: 100;
}
[data-tip]:hover::after,
[data-tip]:hover::before,
[data-tip]:focus::after,
[data-tip]:focus::before {
  opacity: 1;
}
/* Bottom position */
[data-tip-pos="bottom"]::after {
  bottom: auto;
  top: calc(100% + 6px);
}
[data-tip-pos="bottom"]::before {
  bottom: auto;
  top: calc(100% + 2px);
  border-top-color: transparent;
  border-bottom-color: var(--gray-800);
}
/* Info icon for label tooltips */
.tip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: var(--radius-full);
  background: var(--gray-200);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  margin-left: 4px;
  vertical-align: middle;
  cursor: help;
}

/* --- Data Tables --- */
.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.table-search {
  position: relative;
}

.table-search input {
  height: 34px;
  width: 240px;
  padding: 0 var(--space-3) 0 var(--space-8);
  font-size: var(--text-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-inset);
}

.table-search input:focus {
  background: var(--bg-card);
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-ring);
}

.table-search svg {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

.data-table {
  width: 100%;
  font-size: var(--text-sm);
}

.data-table thead {
  background: var(--bg-inset);
  border-bottom: 1px solid var(--border);
}

.data-table th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: 500;
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  user-select: none;
}

.data-table th.sortable {
  cursor: pointer;
}
.data-table th.sortable:hover {
  color: var(--text-primary);
}

.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

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

.data-table tbody tr:nth-child(even) {
  background: #fafaf9;
}

.data-table tbody tr:hover {
  background: var(--primary-ghost);
  cursor: pointer;
}

.data-table tbody tr:hover td:first-child {
  border-left: 2px solid var(--primary);
  padding-left: calc(var(--space-4) - 2px);
}

.data-table .col-actions {
  text-align: right;
  white-space: nowrap;
}

/* --- Avatars --- */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  color: var(--primary);
  font-size: var(--text-sm);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.avatar-sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--text-md); }

.avatar-group {
  display: flex;
}
.avatar-group .avatar {
  border: 2px solid var(--bg-card);
  margin-left: -8px;
}
.avatar-group .avatar:first-child { margin-left: 0; }

/* --- Alerts --- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
}
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert-info { background: var(--info-bg); color: var(--info-text); }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); }
.alert-danger { background: var(--danger-bg); color: var(--danger-text); }

/* --- Tabs --- */
.tab-group {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 0;
  margin-bottom: var(--space-6);
}

.tab-item {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  background: none;
}

.tab-item:hover { color: var(--text-primary); }
.tab-item.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* --- Dropdowns --- */
.dropdown { position: relative; }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1) 0;
  z-index: 100;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  transition: all var(--transition-fast);
}

.dropdown-menu.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  width: 100%;
  text-align: left;
  transition: background var(--transition-fast);
}
.dropdown-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}
.dropdown-item svg { width: 14px; height: 14px; }

.dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-1) 0;
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
}

.empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-4);
  color: var(--text-muted);
  opacity: 0.5;
}

.empty-title {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.empty-desc {
  font-size: var(--text-sm);
  color: var(--text-muted);
  max-width: 360px;
  margin: 0 auto var(--space-5);
}

/* --- Progress Bar --- */
.progress-bar {
  height: 6px;
  background: var(--bg-inset);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--primary);
  transition: width var(--transition-slow);
}
.progress-fill.success { background: var(--success); }
.progress-fill.warning { background: var(--warning); }
.progress-fill.danger { background: var(--danger); }

/* --- Skeleton Loaders --- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-inset) 25%, var(--bg-card-hover) 50%, var(--bg-inset) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

.skeleton-text {
  height: 14px;
  margin-bottom: var(--space-2);
}
.skeleton-text:last-child { width: 60%; }

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

.skeleton-card {
  height: 120px;
  border-radius: var(--radius-lg);
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* --- Page Animation --- */
.page-content {
  animation: pageIn 0.3s ease-out;
}

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

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Chart Container --- */
.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.chart-card-title {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}

.chart-container {
  position: relative;
  height: 260px;
}

/* --- Activity Feed --- */
.activity-feed {
  display: flex;
  flex-direction: column;
}

.activity-item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}
.activity-dot.checkin { background: var(--success); }
.activity-dot.confirm { background: var(--info); }
.activity-dot.decline { background: var(--danger); }
.activity-dot.message { background: var(--warning); }

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

.activity-time {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 2px;
}

/* --- Responsive Grid --- */
@media (max-width: 1024px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}

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

/* --- Toggle Switch --- */
.toggle {
  position: relative;
  display: inline-flex;
  width: 44px;
  height: 24px;
  background: var(--gray-300);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition-fast);
  border: none;
  padding: 0;
  flex-shrink: 0;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition-fast);
  box-shadow: var(--shadow-sm);
}
.toggle.on { background: var(--primary); }
.toggle.on::after { transform: translateX(20px); }
.toggle:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* --- Modal / Dialog --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  transform: scale(0.95) translateY(8px);
  transition: transform var(--transition-base);
}
.modal-overlay.open .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
}
.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: all var(--transition-fast);
}
.modal-close:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}
.modal-close svg { width: 18px; height: 18px; }

.modal-body {
  padding: var(--space-6);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--bg-inset);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* --- Toast Notifications --- */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 300;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-3);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-width: 320px;
  max-width: 420px;
  padding: var(--space-4);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toastIn var(--transition-slow) forwards;
}
.toast.removing {
  animation: toastOut var(--transition-base) forwards;
}

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 1px;
}

.toast-content { flex: 1; min-width: 0; }
.toast-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}
.toast-message {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: 2px;
}

.toast-close {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  flex-shrink: 0;
  transition: all var(--transition-fast);
}
.toast-close:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}
.toast-close svg { width: 14px; height: 14px; }

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-success .toast-icon { color: var(--success); }
.toast.toast-danger { border-left: 3px solid var(--danger); }
.toast.toast-danger .toast-icon { color: var(--danger); }
.toast.toast-warning { border-left: 3px solid var(--warning); }
.toast.toast-warning .toast-icon { color: var(--warning); }
.toast.toast-info { border-left: 3px solid var(--info); }
.toast.toast-info .toast-icon { color: var(--info); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(100%); }
}

/* --- Disabled States --- */
.btn:disabled,
.btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

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

/* --- Loading Spinner --- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.spinner-sm { width: 14px; height: 14px; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

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

/* --- Button Loading State --- */
.btn.loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  /* Inherit button's original color */
}
.btn-primary.loading::after { border-color: rgba(255,255,255,0.3); border-top-color: white; }
.btn-secondary.loading::after { border-color: var(--border); border-top-color: var(--text-secondary); }

/* --- Required Field Indicator --- */
.form-label .required {
  color: var(--danger);
  margin-left: 2px;
}

/* --- Auto-fit Grid --- */
.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-6);
}

/* UL1: Dark Mode — prefers-color-scheme: dark */
@media (prefers-color-scheme: dark) {
  :root {
    --nav-bg: #020617;
    --nav-bg-hover: #0f172a;
    --bg-page: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #334155;
    --bg-inset: #0f172a;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #94a3b8;
    --text-placeholder: #475569;
    --border: #334155;
    --border-strong: #475569;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.2), 0 0 0 1px var(--border);
    --success-bg: #064e3b;
    --success-text: #6ee7b7;
    --warning-bg: #78350f;
    --warning-text: #fcd34d;
    --danger-bg: #7f1d1d;
    --danger-text: #fca5a5;
    --info-bg: #1e3a5f;
    --info-text: #93c5fd;
  }
  body, .app-layout { background: var(--bg-page); color: var(--text-primary); }
  .card, .stat-card, .table-container { background: var(--bg-card); border-color: var(--border); }
  .form-input, .form-select, .form-textarea { background: var(--bg-inset); color: var(--text-primary); border-color: var(--border); }
  .table th { background: var(--bg-inset); color: var(--text-secondary); }
  .table td { border-color: var(--border); }
  .modal-content { background: var(--bg-card); }
  .sidebar { background: var(--nav-bg); }
}

/* UL2: Print Styles */
@media print {
  body { background: white !important; color: black !important; font-size: 12pt; }
  .sidebar, .topbar, .nav, .btn, .modal, .toast,
  #toast, .skip-link, .pub-nav, .pub-footer,
  [role="navigation"], .no-print { display: none !important; }
  .app-layout { display: block !important; }
  .main-content { margin: 0 !important; padding: 0 !important; max-width: 100% !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; break-inside: avoid; }
  .table { font-size: 10pt; }
  .table th, .table td { padding: 4px 8px !important; }
  a { color: black !important; text-decoration: none !important; }
  a[href]::after { content: " (" attr(href) ")"; font-size: 9pt; color: #666; }
  a[href^="#"]::after, a[href^="javascript"]::after { content: ""; }
  .stat-card { border: 1px solid #ccc !important; padding: 8px !important; }
  canvas { max-height: 300px !important; }
}
