/* ================================================================
   CareCost — Design System Tokens & Utilities
   Source of truth for all visual decisions.
   Adapted from shadcn/ui conventions for data-dense professional tools.
   ================================================================ */

/* ── Skip Link (accessibility) ── */
.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  z-index: 99999;
  padding: 8px 16px;
  background: var(--primary, #3B82F6);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 8px 0;
}
.skip-link:focus {
  left: 0;
  top: 0;
}

/* ── Color Tokens ── */
:root {
  /* Brand */
  --primary: #3B82F6;
  --primary-light: #DBEAFE;
  --primary-dark: #2563EB;
  --primary-darker: #1D4ED8;

  /* Semantic */
  --success: #16A34A;
  --success-light: #DCFCE7;
  --success-dark: #166534;

  --warning: #D97706;
  --warning-light: #FEF3C7;
  --warning-dark: #92400E;

  --danger: #DC2626;
  --danger-light: #FEE2E2;
  --danger-dark: #991B1B;

  --info: #2563EB;
  --info-light: #EFF6FF;
  --info-dark: #1E40AF;

  /* Accent (purple, indigo — special badges) */
  --accent-purple: #7C3AED;
  --accent-purple-light: #EDE9FE;
  --accent-purple-dark: #5B21B6;
  --accent-indigo: #4F46E5;
  --accent-indigo-light: #EEF2FF;
  --accent-indigo-dark: #4338CA;
  --accent-teal: #0D9488;
  --accent-teal-light: #D1FAE5;
  --accent-teal-dark: #065F46;

  /* Surfaces */
  --surface-0: #F8F9FB;
  --surface-1: #FFFFFF;
  --surface-2: #F3F4F6;

  /* Borders */
  --border: rgba(0,0,0,.08);
  --border-strong: rgba(0,0,0,.12);
  --border-focus: rgba(59,130,246,.4);

  /* Text hierarchy */
  --text-primary: #111827;
  --text-secondary: #4B5563;
  --text-tertiary: #6B7280;
  --text-muted: #9CA3AF;

  /* Legacy gray aliases (backward compat with existing JS-generated markup) */
  --gray-50: #F9FAFB; --gray-100: #F3F4F6; --gray-200: #E5E7EB; --gray-300: #D1D5DB;
  --gray-400: #9CA3AF; --gray-500: #6B7280; --gray-600: #4B5563; --gray-700: #374151;
  --gray-800: #1F2937; --gray-900: #111827;

  /* Dark surfaces (tooltips, output panels) */
  --surface-dark: #0F172A;
  --surface-tooltip: #1E293B;
  --text-on-dark: #F1F5F9;

  /* ── 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;
  --space-12: 48px;

  /* ── Typography Scale ── */
  --text-2xs: 10px;
  --text-xs: 11px;
  --text-sm: 12px;
  --text-base: 13px;
  --text-md: 14px;
  --text-lg: 16px;
  --text-xl: 18px;
  --text-2xl: 22px;

  /* ── Border Radius ── */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-pill: 9999px;

  /* ── Shadows ── */
  --shadow: 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.08);
}


/* ================================================================
   Alert Component — 4 semantic variants
   Usage: <div class="alert alert-info">...</div>
   ================================================================ */

.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  line-height: 1.5;
  margin-bottom: var(--space-2);
  border: 1px solid;
}
.alert strong { font-weight: 600; }
.alert a { font-weight: 500; text-decoration: underline; }

.alert-info {
  background: var(--info-light);
  color: var(--info-dark);
  border-color: #BFDBFE;
}
.alert-info a { color: var(--info-dark); }

.alert-success {
  background: var(--success-light);
  color: var(--success-dark);
  border-color: #BBF7D0;
}
.alert-success a { color: var(--success-dark); }

.alert-warning {
  background: var(--warning-light);
  color: var(--warning-dark);
  border-color: #FDE68A;
}
.alert-warning a { color: var(--warning-dark); }

.alert-danger {
  background: var(--danger-light);
  color: var(--danger-dark);
  border-color: #FCA5A5;
}
.alert-danger a { color: var(--danger-dark); }


/* ================================================================
   Overlay / Modal Component
   Usage:
     <div class="overlay" id="myPanel">
       <div class="modal">
         <div class="modal-header">...</div>
         <div class="modal-body">...</div>
       </div>
     </div>
   ================================================================ */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.modal {
  background: var(--surface-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
  width: 100%;
  max-width: 560px;
}

.modal-sm { max-width: 420px; }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 900px; }

.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-header h2,
.modal-header h3 {
  font-family: 'Poppins', sans-serif;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

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

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  line-height: 1;
}
.modal-close:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}


/* ================================================================
   Badge System — unified
   ================================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--text-2xs);
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.3px;
}
.badge-primary  { background: var(--primary-light);        color: var(--primary-dark); }
.badge-success  { background: var(--success-light);        color: var(--success-dark); }
.badge-warning  { background: var(--warning-light);        color: var(--warning-dark); }
.badge-danger   { background: var(--danger-light);         color: var(--danger-dark); }
.badge-info     { background: var(--info-light);           color: var(--info-dark); }
.badge-purple   { background: var(--accent-purple-light);  color: var(--accent-purple-dark); }
.badge-indigo   { background: var(--accent-indigo-light);  color: var(--accent-indigo-dark); }
.badge-teal     { background: var(--accent-teal-light);    color: var(--accent-teal-dark); }
.badge-neutral  { background: var(--surface-2);            color: var(--text-secondary); }

.badge-lg {
  padding: 4px 12px;
  font-size: var(--text-sm);
}


/* ================================================================
   Section Label — unified uppercase micro heading
   ================================================================ */

.section-label {
  font-family: 'Poppins', sans-serif;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}


/* ================================================================
   Spacing Utilities
   Naming: .{property}{side}-{scale}
   mt = margin-top, mb = margin-bottom, ml = margin-left, mr = margin-right
   pt = padding-top, pb = padding-bottom, p = padding
   ================================================================ */

/* Margin top */
.mt-0 { margin-top: 0; }
.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); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }

/* Margin bottom */
.mb-0 { margin-bottom: 0; }
.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); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

/* Margin left/right */
.ml-1 { margin-left: var(--space-1); }
.ml-2 { margin-left: var(--space-2); }
.ml-3 { margin-left: var(--space-3); }
.ml-4 { margin-left: var(--space-4); }
.mr-1 { margin-right: var(--space-1); }
.mr-2 { margin-right: var(--space-2); }
.mr-3 { margin-right: var(--space-3); }
.mr-4 { margin-right: var(--space-4); }

/* Padding */
.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-5 { padding: var(--space-5); }
.p-6 { padding: var(--space-6); }
.px-3 { padding-left: var(--space-3); padding-right: var(--space-3); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }
.py-3 { padding-top: var(--space-3); padding-bottom: var(--space-3); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }

/* Gap */
.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-6 { gap: var(--space-6); }


/* ================================================================
   Typography Utilities
   ================================================================ */

.text-2xs  { font-size: var(--text-2xs); }
.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); }

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

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

.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger  { color: var(--danger); }
.text-info    { color: var(--info); }

.font-mono { font-family: 'Inconsolata', monospace; }
.font-display { font-family: 'Poppins', sans-serif; }

.text-center { text-align: center; }
.text-right  { text-align: right; }
.uppercase   { text-transform: uppercase; }


/* ================================================================
   Layout Utilities
   ================================================================ */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.inline-flex { display: inline-flex; }

.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}


/* ================================================================
   Drawer Component — slide-in panel from edge of screen
   Usage: <div class="drawer drawer-right">...</div>
   ================================================================ */

.drawer {
  position: fixed;
  top: 56px;
  width: 380px;
  max-width: 100vw;
  height: calc(100vh - 56px);
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px rgba(0,0,0,.08);
  z-index: 500;
  display: flex;
  flex-direction: column;
}
.drawer-right { right: 0; }
.drawer-left { left: 0; border-left: none; border-right: 1px solid var(--border); box-shadow: 4px 0 24px rgba(0,0,0,.08); }

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

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--space-5);
}

.drawer-footer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  text-align: right;
}


/* ================================================================
   Button — ghost variant (transparent, hover reveals bg)
   ================================================================ */

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: none;
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.btn-danger-subtle {
  background: var(--danger-light);
  color: var(--danger);
  border: none;
}
.btn-danger-subtle:hover {
  background: var(--danger-light);
  color: var(--danger-dark);
}


/* ================================================================
   Accessibility — focus-visible for all interactive elements
   ================================================================ */

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

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

/* ── Fee Schedule Column Mapper Modal ── */
.fs-modal-overlay {
  position: fixed; inset: 0; z-index: 10000;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.fs-modal-overlay.active { opacity: 1; pointer-events: auto; }
.fs-modal {
  background: var(--surface-1); border-radius: var(--radius-lg, 12px);
  width: 95vw; max-width: 1100px; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 48px rgba(0,0,0,0.2);
}
.fs-modal-header {
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.fs-modal-header h2 { font-family: 'Poppins', sans-serif; font-size: 17px; font-weight: 600; }
.fs-modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.fs-modal-footer {
  padding: 16px 24px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
}

/* Column mapping controls */
.fs-map-row {
  display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.fs-map-field { display: flex; flex-direction: column; gap: 4px; }
.fs-map-field label { font-size: 12px; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.5px; }
.fs-map-field select { padding: 6px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm, 6px); font-size: 13px; min-width: 180px; }

/* Preview table */
.fs-preview-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 12px; }
.fs-preview-table th, .fs-preview-table td { padding: 6px 10px; border: 1px solid var(--gray-200); text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.fs-preview-table th { background: var(--gray-100); font-weight: 600; font-size: 12px; color: var(--text-tertiary); }
.fs-preview-table td.fs-col-highlight { background: var(--primary-light); }
.fs-preview-table th.fs-col-highlight { background: var(--primary); color: white; }

/* Header row toggle */
.fs-header-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.fs-header-toggle input[type="checkbox"] { margin: 0; }

/* Sheet tab selector */
.fs-sheet-selector { margin-bottom: 16px; }
.fs-sheet-selector label { font-size: 12px; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; margin-right: 8px; }
.fs-sheet-selector select { padding: 4px 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm, 6px); font-size: 13px; }

/* Facility/non-facility toggle */
.fs-facility-toggle { margin-bottom: 16px; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.fs-facility-toggle select { padding: 4px 8px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm, 6px); font-size: 13px; }

/* Review step */
.fs-review-summary { font-size: 14px; margin-bottom: 16px; padding: 12px; background: var(--info-light); border-radius: var(--radius-sm, 6px); color: var(--info-dark); }
.fs-review-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.fs-review-table th, .fs-review-table td { padding: 6px 10px; border-bottom: 1px solid var(--gray-200); text-align: left; }
.fs-review-table th { background: var(--gray-50); font-weight: 600; font-size: 12px; color: var(--text-tertiary); position: sticky; top: 0; }
.fs-review-table .fs-unmatched { opacity: 0.6; }
.fs-review-table .fs-warning { color: var(--warning-dark); font-size: 12px; }
.fs-skipped-section { margin-top: 16px; }
.fs-skipped-toggle { font-size: 13px; color: var(--text-tertiary); cursor: pointer; border: none; background: none; text-decoration: underline; padding: 0; }
.fs-skipped-list { font-size: 12px; color: var(--text-muted); margin-top: 8px; max-height: 120px; overflow-y: auto; }

/* Import unmatched checkbox */
.fs-import-unmatched { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-top: 12px; color: var(--text-secondary); }

/* Replace warning */
.fs-replace-warning { margin-top: 12px; padding: 10px; background: var(--warning-light); border-radius: var(--radius-sm, 6px); font-size: 13px; color: var(--warning-dark); }

/* ── Manual Entry Table ── */
.fs-manual-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.fs-manual-table th, .fs-manual-table td { padding: 6px 8px; border-bottom: 1px solid var(--gray-200); text-align: left; }
.fs-manual-table th { font-size: 12px; font-weight: 600; color: var(--text-tertiary); text-transform: uppercase; }
.fs-manual-table input { width: 100%; padding: 4px 6px; border: 1px solid var(--border); border-radius: var(--radius-sm, 4px); font-size: 13px; }
.fs-manual-table input:focus { border-color: var(--border-focus); outline: none; box-shadow: 0 0 0 2px rgba(59,130,246,0.15); }
.fs-manual-table input.fs-invalid { border-color: var(--danger); background: var(--danger-light); }
.fs-manual-table .fs-warning-cell { color: var(--warning-dark); font-size: 11px; }
.fs-manual-table .fs-delete-btn { border: none; background: none; color: var(--text-muted); cursor: pointer; font-size: 16px; padding: 2px 6px; }
.fs-manual-table .fs-delete-btn:hover { color: var(--danger); }
.fs-manual-actions { margin-top: 8px; display: flex; gap: 8px; align-items: center; }

/* Autocomplete dropdown */
.fs-autocomplete { position: relative; }
.fs-autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 100;
  background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: var(--radius-sm, 6px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1); max-height: 200px; overflow-y: auto;
  display: none;
}
.fs-autocomplete-list.active { display: block; }
.fs-autocomplete-item { padding: 6px 10px; font-size: 13px; cursor: pointer; }
.fs-autocomplete-item:hover { background: var(--primary-light); }
.fs-autocomplete-item .fs-ac-code { font-weight: 600; margin-right: 8px; }
.fs-autocomplete-item .fs-ac-name { color: var(--text-tertiary); }
