/**
 * KirCACS - Klinik Dashboard Stylesheet
 * Version: 3.0.0 - Opryddet & Organiseret
 * 
 * Indholdsfortegnelse:
 * 1. CSS Variables
 * 2. Reset & Base
 * 3. Typography & Links
 * 4. Form Elements
 * 5. Buttons
 * 6. Login Screen
 * 7. App Layout (Header, Main, Tabs)
 * 8. Filter Bar & Controls
 * 9. Multi-Select Dropdown
 * 10. Filter Hierarchy (Drag & Drop)
 * 11. Dashboard Cards (Admin)
 * 12. KPI Cards (Stats)
 * 13. Charts
 * 14. Tables (Data & Comparison)
 * 15. Drilldown Popover
 * 16. Modal
 * 17. Status Badges & Indicators
 * 18. Loading & Empty States
 * 19. Pagination
 * 20. Utility Classes
 * 21. Animations
 * 22. Responsive
 */

/* ========================================
   1. CSS Variables
   ======================================== */
:root {
  /* Backgrounds */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-hover: #e2e8f0;
  --bg-active: #dbeafe;
  
  /* Text */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  
  /* Accents */
  --accent-primary: #2563eb;
  --accent-primary-hover: #1d4ed8;
  --accent-success: #059669;
  --accent-success-light: #d1fae5;
  --accent-warning: #d97706;
  --accent-warning-light: #fef3c7;
  --accent-danger: #dc2626;
  --accent-danger-light: #fee2e2;
  --accent-info: #0284c7;
  --accent-info-light: #e0f2fe;
  
  /* Chart colors */
  --chart-year-1: #2563eb;
  --chart-year-2: #059669;
  --chart-year-3: #d97706;
  --chart-year-4: #7c3aed;
  --chart-year-5: #db2777;
  
  /* YoY colors */
  --yoy-positive: #059669;
  --yoy-negative: #dc2626;
  --yoy-neutral: #64748b;
  --yoy-new: #2563eb;
  
  /* UI */
  --border-color: #e2e8f0;
  --border-focus: #2563eb;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  
  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  
  /* Typography */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Consolas', 'Liberation Mono', monospace;
  
  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 200ms ease;
}

/* ========================================
   2. Reset & Base
   ======================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ========================================
   3. Typography & Links
   ======================================== */
h1, h2, h3, h4, h5, h6 {
  line-height: 1.3;
}

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

a:hover {
  text-decoration: underline;
}

/* ========================================
   4. Form Elements
   ======================================== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.form-group label,
.filter-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"],
input[type="password"],
input[type="date"],
select,
.filter-input,
.filter-select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input:focus,
select:focus,
.filter-input:focus,
.filter-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-size: 0.9rem;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-primary);
}

/* ========================================
   5. Buttons
   ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 10px 16px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-primary-hover);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

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

.btn-small {
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.8rem;
}

.btn-small svg {
  vertical-align: middle;
  margin-right: 4px;
}

.btn-full {
  width: 100%;
}

.btn svg {
  flex-shrink: 0;
}

.btn-success {
  background: var(--accent-success);
  color: white;
  border-color: var(--accent-success);
}

.btn-success:hover:not(:disabled) {
  background: var(--accent-success);
  border-color: var(--accent-success);
  filter: brightness(0.9);
}

.btn-success:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Match count badges in buttons */
.match-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-full);
}

.btn-primary .match-count {
  background: rgba(255, 255, 255, 0.25);
}

.match-count-name {
  background: var(--accent-success);
  color: white;
}

.btn-primary .match-count-name {
  background: var(--accent-success);
}

.match-count-zero {
  background: var(--accent-danger-light);
  color: var(--accent-danger);
}

.btn-primary .match-count-zero {
  background: rgba(239, 68, 68, 0.3);
  color: white;
}

/* ========================================
   6. Login Screen
   ======================================== */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 50%, #f0fdf4 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  box-shadow: var(--shadow-lg);
}

.login-header {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.login-logo {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--accent-primary) 0%, #1d4ed8 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.25rem;
  color: white;
  margin: 0 auto var(--space-md);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.3);
}

.login-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-xs);
  color: var(--text-primary);
}

.login-header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.login-error {
  background: var(--accent-danger-light);
  border: 1px solid var(--accent-danger);
  color: var(--accent-danger);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  text-align: center;
}

/* ========================================
   7. App Layout
   ======================================== */
.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent-primary) 0%, #1d4ed8 100%);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  color: white;
}

.app-header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Tabs */
.main-tabs {
  display: flex;
  gap: var(--space-xs);
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.tab-btn.active {
  color: var(--accent-primary);
  background: var(--bg-active);
}

.tab-btn svg {
  opacity: 0.7;
}

.tab-btn.active svg {
  opacity: 1;
}

.logout-btn {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.logout-btn:hover {
  color: var(--accent-danger);
  background: var(--accent-danger-light);
}

/* Main Content */
.app-main {
  flex: 1;
  padding: var(--space-lg);
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 200ms ease;
}

/* ========================================
   8. Filter Bar & Controls
   ======================================== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-lg);
}

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

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

.filter-separator {
  color: var(--text-muted);
}

.filter-input,
.filter-select {
  min-width: 140px;
}

.filter-bar-secondary {
  margin-top: calc(-1 * var(--space-sm));
  padding-top: var(--space-sm);
  border-top: 1px dashed var(--border-color);
}

.filter-group-spacer {
  flex: 1;
}

.filter-bar .btn svg {
  margin-right: var(--space-xs);
}

.filter-bar .multi-select-wrapper {
  min-width: 140px;
}

.filter-bar .multi-select-trigger {
  width: 100%;
}

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

/* Chart Controls */
.chart-controls {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-md);
}

.ytd-toggle-label {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.ytd-toggle-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-primary);
}

.ytd-info {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: auto;
}

/* ========================================
   9. Multi-Select Dropdown
   ======================================== */
.multi-select-wrapper {
  position: relative;
}

.multi-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  min-width: 160px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.multi-select-trigger:hover {
  border-color: var(--text-muted);
}

.multi-select-trigger:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.multi-select-trigger svg {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform var(--transition-fast);
}

.multi-select-wrapper.open .multi-select-trigger svg {
  transform: rotate(180deg);
}

.multi-select-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  min-width: 220px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: none;
}

.multi-select-wrapper.open .multi-select-dropdown {
  display: block;
}

.multi-select-option {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  font-size: 0.85rem;
}

.multi-select-option:hover {
  background: var(--bg-hover);
}

.multi-select-option.selected {
  background: var(--bg-active);
}

.multi-select-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-primary);
  flex-shrink: 0;
}

.multi-select-option span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.multi-select-divider {
  height: 1px;
  background: var(--border-color);
  margin: var(--space-xs) 0;
}


/* ========================================
   10. Filter Hierarchy (Drag & Drop)
   ======================================== */
.filter-hierarchy-bar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  min-height: 44px;
}

.filter-hierarchy-label {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  white-space: nowrap;
}

.filter-hierarchy-label svg {
  opacity: 0.6;
}

.filter-hierarchy-list {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
  flex: 1;
}

.filter-hierarchy-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Hierarchy Chips */
.filter-hierarchy-chip {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: grab;
  user-select: none;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.filter-hierarchy-chip:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.filter-hierarchy-chip:active {
  cursor: grabbing;
}

.chip-handle {
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: grab;
}

.chip-handle:active {
  cursor: grabbing;
}

.chip-rank {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: var(--accent-primary);
  color: var(--text-inverse);
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
}

.chip-label {
  font-weight: 600;
  color: var(--text-primary);
}

.chip-role {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* SortableJS States */
.filter-chip-ghost {
  opacity: 0.4;
  background: var(--bg-active);
}

.filter-chip-chosen {
  box-shadow: var(--shadow-lg);
  transform: scale(1.05);
}

.filter-chip-drag {
  opacity: 0.9;
}

/* Rank Colors */
.filter-hierarchy-chip:nth-child(1) .chip-rank { background: #2563eb; }
.filter-hierarchy-chip:nth-child(2) .chip-rank { background: #059669; }
.filter-hierarchy-chip:nth-child(3) .chip-rank { background: #d97706; }
.filter-hierarchy-chip:nth-child(4) .chip-rank { background: #7c3aed; }
.filter-hierarchy-chip:nth-child(5) .chip-rank { background: #db2777; }

/* ========================================
   11. Dashboard Cards (Admin)
   ======================================== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.dash-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-lg);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  transition: all var(--transition-fast);
}

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

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

.dash-card-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dash-card-warning .dash-card-icon { background: var(--accent-warning-light); color: var(--accent-warning); }
.dash-card-danger .dash-card-icon { background: var(--accent-danger-light); color: var(--accent-danger); }
.dash-card-info .dash-card-icon { background: var(--accent-info-light); color: var(--accent-info); }
.dash-card-success .dash-card-icon { background: var(--accent-success-light); color: var(--accent-success); }

.dash-card-content {
  display: flex;
  flex-direction: column;
}

.dash-card-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
}

.dash-card-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ========================================
   12. KPI Cards (Stats)
   ======================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--space-md);
}

.kpi-card.expanded {
  grid-column: 1 / -1;
}

.kpi-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: all var(--transition-fast);
}

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

.kpi-card-header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-lg);
  cursor: pointer;
  transition: background var(--transition-fast);
  position: relative;
}

/* Compact collapsed card layout */
.kpi-card:not(.expanded) .kpi-card-header {
  flex-wrap: wrap;
  padding: var(--space-md);
  gap: var(--space-sm);
}

.kpi-card:not(.expanded) .kpi-header-left {
  gap: var(--space-sm);
  width: 100%;
}

.kpi-card:not(.expanded) .kpi-icon {
  width: 32px;
  height: 32px;
}

.kpi-card:not(.expanded) .kpi-icon svg {
  width: 16px;
  height: 16px;
}

.kpi-card:not(.expanded) .kpi-value {
  font-size: 1.4rem;
  width: 100%;
  padding-left: calc(32px + var(--space-sm));
}

.kpi-card:not(.expanded) .kpi-sub,
.kpi-card:not(.expanded) .kpi-filter-scope {
  display: none;
}

.kpi-card:not(.expanded) .kpi-expand-icon {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  opacity: 0.4;
}

.kpi-card:not(.expanded):hover .kpi-expand-icon {
  opacity: 1;
}

.kpi-card-header:hover {
  background: var(--bg-tertiary);
}

.kpi-card-header:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: -2px;
}

.kpi-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex: 1;
}

.kpi-icon {
  width: 44px;
  height: 44px;
  background: var(--bg-active);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-primary);
  flex-shrink: 0;
}

.kpi-title-wrap {
  display: flex;
  flex-direction: column;
}

.kpi-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.kpi-filter-scope {
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.6;
  letter-spacing: 0.02em;
}

/* Sparkline in collapsed KPI card */
.kpi-sparkline {
  display: none;
}

.kpi-card:not(.expanded) .kpi-sparkline {
  display: block;
  width: 100%;
  height: 28px;
  padding-left: calc(32px + var(--space-sm));
}

.kpi-sparkline svg {
  width: 100%;
  height: 100%;
}

.kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.kpi-expand-icon {
  color: var(--text-muted);
  transition: transform var(--transition-fast);
}

.kpi-card.expanded .kpi-expand-icon {
  transform: rotate(180deg);
}

/* KPI Expanded Content */
.kpi-card-expanded,
.kpi-card-body {
  display: none;
  padding: 0 var(--space-lg) var(--space-lg);
  border-top: 1px solid var(--border-color);
}

.kpi-card.expanded .kpi-card-expanded,
.kpi-card.expanded .kpi-card-body {
  display: block;
}


/* ========================================
   13. Charts
   ======================================== */
.chart-container {
  height: 350px;
  margin-bottom: var(--space-lg);
  position: relative;
}

.chart-container canvas {
  max-height: 350px;
}

/* ========================================
   14. Tables
   ======================================== */
/* Data Table (Admin) */
.table-container {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

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

.data-table th,
.data-table td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  background: var(--bg-tertiary);
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.data-table .mono {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* Column widths */
.col-date { width: 100px; }
.col-behandler { width: 180px; }
.col-patient { width: 200px; }
.col-debitor { width: 140px; }
.col-kode { width: 80px; }
.col-amount { width: 100px; text-align: right; }
.col-status { width: 120px; }
.col-actions { width: 100px; text-align: center; }

/* Comparison Table (Stats) */
.kpi-table-container,
.comparison-table-wrap {
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.comparison-table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.comparison-table th,
.comparison-table td {
  padding: var(--space-sm) var(--space-md);
  text-align: right;
  border-bottom: 1px solid var(--border-color);
}

.comparison-table th {
  background: var(--bg-tertiary);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.comparison-table th:first-child,
.comparison-table td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 2;
}

.comparison-table th:first-child {
  background: var(--bg-tertiary);
}

.comparison-table td:first-child {
  background: var(--bg-secondary);
}

.comparison-table th small {
  display: block;
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.75rem;
}

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

.comparison-table tfoot {
  font-weight: 600;
}

.comparison-table tfoot td {
  border-top: 2px solid var(--border-color);
  background: var(--bg-tertiary);
}

.comparison-table td.highlight {
  background: var(--bg-active);
}

/* Multi-level Table Headers */
.comparison-table th.header-multi {
  padding: var(--space-xs) var(--space-sm);
  text-align: center;
  min-width: 100px;
}

.comparison-table th.header-multi .header-primary {
  display: block;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-primary);
}

.comparison-table th.header-multi .header-secondary {
  display: block;
  font-weight: 500;
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.comparison-table th.header-multi .header-tertiary {
  display: block;
  font-weight: 400;
  font-size: 0.6rem;
  color: var(--accent-info);
  font-style: italic;
  margin-top: 1px;
}

.comparison-table th.header-multi .header-year {
  display: block;
  font-weight: 400;
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* YoY Styling */
.yoy {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  margin-top: 2px;
  margin-left: 4px;
}

.yoy-positive { color: var(--yoy-positive); }
.yoy-negative { color: var(--yoy-negative); }
.yoy-neutral { color: var(--yoy-neutral); }
.yoy-new { color: var(--yoy-new); font-weight: 600; }

/* ========================================
   15. Drilldown Popover
   ======================================== */
.cell-drilldown {
  cursor: pointer;
  position: relative;
  transition: background var(--transition-fast);
}

.cell-drilldown:hover {
  background: var(--bg-active);
}

.cell-drilldown.drilldown-active {
  background: var(--bg-active);
  box-shadow: inset 0 0 0 2px var(--accent-primary);
}

.drilldown-icon {
  display: inline-block;
  font-size: 0.6rem;
  color: var(--accent-primary);
  margin-left: 4px;
  vertical-align: middle;
  opacity: 0.6;
  transition: opacity var(--transition-fast);
}

.cell-drilldown:hover .drilldown-icon {
  opacity: 1;
}

.drilldown-popover-container {
  position: absolute;
  z-index: 1000;
}

.drilldown-popover {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 220px;
  max-width: 350px;
  animation: popoverFadeIn 0.15s ease;
}

.drilldown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.drilldown-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color var(--transition-fast);
}

.drilldown-close:hover {
  color: var(--text-primary);
}

.drilldown-body {
  padding: var(--space-sm);
  max-height: 300px;
  overflow-y: auto;
}

.drilldown-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.drilldown-row td {
  padding: var(--space-xs) var(--space-sm);
}

.drilldown-row.drilldown-group td {
  font-weight: 600;
  color: var(--text-secondary);
  padding-top: var(--space-sm);
  border-bottom: 1px solid var(--border-color);
}

.drilldown-label {
  color: var(--text-secondary);
  white-space: nowrap;
}

.drilldown-value {
  text-align: right;
  font-weight: 500;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.drilldown-row.indent-1 .drilldown-label { padding-left: var(--space-md); }
.drilldown-row.indent-2 .drilldown-label { padding-left: calc(var(--space-md) * 2); }
.drilldown-row.indent-3 .drilldown-label { padding-left: calc(var(--space-md) * 3); }

.drilldown-row:not(.drilldown-group):nth-child(even) {
  background: var(--bg-tertiary);
}

/* ========================================
   16. Modal
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 200ms ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: transform 200ms ease;
}

.modal-overlay.active .modal {
  transform: scale(1);
}

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

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border-color);
}

/* Match Modal */
.match-source,
.match-candidates {
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: var(--space-md);
}

.match-source h3,
.match-candidates h3 {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: var(--space-md);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.match-details {
  font-size: 0.9rem;
}

.match-details dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-xs) var(--space-md);
}

.match-details dt {
  color: var(--text-secondary);
}

.match-details dd {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.match-arrow {
  display: flex;
  justify-content: center;
  padding: var(--space-md) 0;
  color: var(--text-muted);
}

.candidates-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  max-height: 300px;
  overflow-y: auto;
}

.candidate-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.candidate-item:hover {
  border-color: var(--accent-primary);
}

.candidate-item.selected {
  border-color: var(--accent-primary);
  background: var(--bg-active);
}

.candidate-radio {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-color);
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.candidate-item.selected .candidate-radio {
  border-color: var(--accent-primary);
}

.candidate-item.selected .candidate-radio::after {
  content: '';
  width: 10px;
  height: 10px;
  background: var(--accent-primary);
  border-radius: 50%;
}

.candidate-info {
  flex: 1;
  font-size: 0.85rem;
}

.candidate-info strong {
  display: block;
  margin-bottom: 2px;
  color: var(--text-primary);
}

.candidate-info span {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* Candidate header with badges */
.candidate-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.candidate-header strong {
  margin-bottom: 0;
}

/* Match indicator badges */
.match-badges {
  display: inline-flex;
  gap: 4px;
}

.match-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  font-size: 0.65rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

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

.match-badge.match-behandler {
  background: var(--accent-primary-light, rgba(99, 102, 241, 0.15));
  color: var(--accent-primary);
}

/* Recommended candidate styling */
.candidate-item.candidate-recommended {
  border-color: var(--accent-success);
  background: rgba(16, 185, 129, 0.05);
}

.candidate-item.candidate-recommended::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent-success);
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.candidate-item {
  position: relative;
}

/* Candidate hash display */
.candidate-hash {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-tertiary);
  margin-top: 4px;
}

/* Hash code in modal */
.hash-code {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  word-break: break-all;
}

/* Candidate sections */
.candidate-section {
  margin-bottom: var(--space-md);
}

.candidate-section-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-xs) var(--space-sm);
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.candidate-section-header .section-hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

.candidate-section-historical {
  border-top: 1px dashed var(--border-color);
  padding-top: var(--space-md);
  margin-top: var(--space-md);
}

.candidate-section-historical .candidate-section-header {
  background: rgba(245, 158, 11, 0.1);
  border-left: 3px solid var(--accent-warning);
}

/* Historical candidate styling */
.candidate-item.candidate-historical {
  border-style: dashed;
  background: rgba(245, 158, 11, 0.03);
}

.candidate-item.candidate-historical:hover {
  border-color: var(--accent-warning);
}

.candidate-item.candidate-historical.selected {
  border-color: var(--accent-warning);
  background: rgba(245, 158, 11, 0.1);
}

/* Historical match badge */
.match-badge.match-hist {
  background: var(--accent-warning-light);
  color: var(--accent-warning);
}

/* Historical count badge in buttons */
.match-count.match-count-hist {
  background: var(--accent-warning);
  color: white;
}

/* Candidate meta info */
.candidate-meta {
  display: block;
  font-size: 0.7rem;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* ========================================
   17. Status Badges & Indicators
   ======================================== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 3px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: var(--radius-full);
}

.status-unmatched { background: var(--accent-warning-light); color: var(--accent-warning); }
.status-ambiguous { background: var(--accent-danger-light); color: var(--accent-danger); }
.status-matched { background: var(--accent-success-light); color: var(--accent-success); }

.partial-badge {
  display: inline-block;
  padding: 1px 6px;
  background: var(--accent-warning-light);
  color: var(--accent-warning);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  border-radius: var(--radius-sm);
  margin-left: var(--space-xs);
}

/* ========================================
   18. Loading & Empty States
   ======================================== */
.loading-row td {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--text-secondary);
}

.loading-row span {
  display: block;
  margin-top: var(--space-sm);
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

.empty-row td {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
}

/* ========================================
   19. Pagination
   ======================================== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  margin-top: var(--space-lg);
}

.pagination-info {
  font-size: 0.85rem;
  color: var(--text-secondary);
  min-width: 100px;
  text-align: center;
}

/* ========================================
   20. Utility Classes
   ======================================== */
.mono {
  font-family: var(--font-mono);
}

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

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

.text-muted {
  color: var(--text-muted);
}

/* ========================================
   21. Animations
   ======================================== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes popoverFadeIn {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========================================
   22. Responsive
   ======================================== */
@media (max-width: 1200px) {
  .filter-bar {
    flex-wrap: wrap;
  }
  
  .filter-group {
    min-width: 150px;
  }
}

@media (max-width: 1024px) {
  .app-header {
    flex-wrap: wrap;
    gap: var(--space-md);
  }
  
  .main-tabs {
    order: 3;
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
  }
  
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .filter-group {
    width: 100%;
  }
  
  .filter-input,
  .filter-select,
  .multi-select-trigger {
    width: 100%;
  }
  
  .table-container {
    overflow-x: auto;
  }
  
  .data-table {
    min-width: 800px;
  }
  
  .chart-container {
    height: 280px;
  }
  
  .chart-controls {
    flex-wrap: wrap;
  }
  
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .kpi-card.expanded .kpi-card-header {
    flex-wrap: wrap;
  }

  .kpi-card.expanded .kpi-value {
    order: 3;
    width: 100%;
    margin-top: var(--space-sm);
  }
  
  .filter-hierarchy-bar {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }
  
  .filter-hierarchy-list {
    width: 100%;
  }
  
  .filter-hierarchy-chip {
    flex: 0 0 auto;
  }
  
  .filter-bar-secondary {
    flex-direction: column;
    align-items: stretch;
  }
  
  .filter-group-spacer {
    display: none;
  }
  
  .filter-bar-secondary .btn {
    width: 100%;
    justify-content: center;
  }
}

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

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

  .app-main {
    padding: var(--space-md);
  }

  .modal {
    width: 95vw;
    max-height: 90vh;
    margin: 5vh auto;
  }

  .modal-wide {
    width: 95vw;
  }

  .date-range {
    flex-direction: column;
    align-items: stretch;
  }

  .date-range .filter-separator {
    display: none;
  }
}
/* ========================================
   Occupancy Rate KPI
   ======================================== */
.occ-high { color: #22c55e; }
.occ-mid  { color: #a16207; }
.occ-low  { color: #ef4444; }

/* Treatment per patient KPI — color coding */
.tpp-high { color: #22c55e; }
.tpp-mid  { color: #a16207; }
.tpp-low  { color: #ef4444; }

/* Toggle group — dimension switch */
.toggle-group {
  display: inline-flex;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.toggle-option {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: var(--space-xs) var(--space-md);
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  border-right: 1px solid var(--border-color);
  user-select: none;
}

.toggle-option:last-child {
  border-right: none;
}

.toggle-option input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.toggle-option:has(input:checked) {
  background: var(--accent-primary);
  color: var(--text-inverse, #fff);
  font-weight: 500;
}

.toggle-option:hover:not(:has(input:checked)) {
  background: var(--bg-hover);
}

/* Date Presets */
.date-presets {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.date-preset-btn {
  padding: 2px 8px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.date-preset-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.date-preset-btn.active {
  background: var(--accent-primary);
  color: var(--text-inverse, #fff);
  border-color: var(--accent-primary);
}

/* Per-card granularity override */
.filter-select-small {
  min-width: auto;
  width: auto;
  padding: 4px 8px;
  font-size: 0.75rem;
}

/* Sliding Toggle */
.sliding-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.sliding-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.sliding-toggle-track {
  position: relative;
  width: 36px;
  height: 20px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  transition: background 0.2s;
}

.sliding-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.sliding-toggle input:checked ~ .sliding-toggle-track {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.sliding-toggle input:checked ~ .sliding-toggle-track .sliding-toggle-thumb {
  transform: translateX(16px);
  background: var(--text-inverse, #fff);
}

.sliding-toggle-label::after {
  content: attr(data-off);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.sliding-toggle input:checked ~ .sliding-toggle-label::after {
  content: attr(data-on);
}

