/* === DESIGN SYSTEM === */
:root {
  /* Extended color scale — auto-derived from whatever --primary Sonnet picks */
  --primary-50: color-mix(in srgb, var(--primary, #3b82f6) 8%, white);
  --primary-100: color-mix(in srgb, var(--primary, #3b82f6) 16%, white);
  --primary-200: color-mix(in srgb, var(--primary, #3b82f6) 30%, white);
  --primary-300: color-mix(in srgb, var(--primary, #3b82f6) 50%, white);
  --primary-400: color-mix(in srgb, var(--primary, #3b82f6) 75%, white);
  --primary-500: var(--primary, #3b82f6);
  --primary-600: color-mix(in srgb, var(--primary, #3b82f6) 90%, black);
  --primary-700: color-mix(in srgb, var(--primary, #3b82f6) 72%, black);
  --primary-800: color-mix(in srgb, var(--primary, #3b82f6) 56%, black);
  --primary-900: color-mix(in srgb, var(--primary, #3b82f6) 40%, black);

  /* Shadow system — layered multi-stop, not single-layer */
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 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);

  /* Spacing scale */
  --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;

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

  /* Transition tokens */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --duration-fast: 150ms;
  --duration-normal: 200ms;
  --duration-slow: 300ms;
}

/* Typography polish */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, h5, h6 { letter-spacing: -0.02em; line-height: 1.15; }
p, li, td, th { letter-spacing: -0.005em; }

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border, #e2e8f0); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light, #94a3b8); }

/* Selection color */
::selection { background: var(--primary-100, rgba(59,130,246,0.15)); color: var(--primary-900, #1e3a5f); }

/* Focus ring */
:focus-visible { outline: 2px solid var(--primary, #3b82f6); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--primary, #3b82f6);
  box-shadow: 0 0 0 3px var(--primary-100, rgba(59,130,246,0.12));
}

/* Dark mode shadow + transition */
body.dark {
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -2px rgba(0,0,0,0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.35), 0 4px 6px -4px rgba(0,0,0,0.2);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.4), 0 8px 10px -6px rgba(0,0,0,0.2);
}
body { transition: background-color var(--duration-normal, 200ms) ease, color var(--duration-normal, 200ms) ease; }
.sidebar, .card, .modal, nav, header, .stat-card, input, select, textarea, button, table, thead, th, td, .nav-btn {
  transition: background-color var(--duration-normal, 200ms) ease, color var(--duration-normal, 200ms) ease, border-color var(--duration-normal, 200ms) ease, box-shadow var(--duration-normal, 200ms) ease;
}

/* Smooth image rendering */
img { image-rendering: auto; }

/* Base link styling */
a { transition: color var(--duration-fast, 150ms) ease; }
/* === END DESIGN SYSTEM === */

/* === CLINT FORCED CSS FIXES APPLIED === */
html { scroll-padding-top: 90px; scroll-behavior: smooth; }
@media (max-width: 768px) { html { scroll-padding-top: 70px; } }
/* ===== RESET & VARIABLES ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #1e3a5f;
  --primary-dark: #152d4a;
  --primary-light: #2e5082;
  --primary-rgb: 30, 58, 95;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --secondary: #64748b;
  --background: #f1f5f9;
  --surface: #ffffff;
  --surface-raised: #f8fafc;
  --text: #0f172a;
  --text-light: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --success: #10b981;
  --success-bg: #d1fae5;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --error: #ef4444;
  --error-bg: #fee2e2;
  --critical: #7c3aed;
  --critical-bg: #ede9fe;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--background);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.025em; line-height: 1.15; }
h2 { font-size: 18px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
h3 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }

/* ===== DARK MODE ===== */
body.dark {
  --background: #0a1628;
  --surface: #0f2040;
  --surface-raised: #1a2d4a;
  --text: #f1f5f9;
  --text-light: #94a3b8;
  --text-muted: #64748b;
  --border: #1e3a5f;
  --border-strong: #2e5082;
}

/* ===== LAYOUT ===== */
#mainApp {
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--primary);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: fixed;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.15);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
}

.logo-text { display: flex; flex-direction: column; }
.logo-name { color: white; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
.logo-tagline { color: rgba(255,255,255,0.5); font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; }

.sidebar-section { padding: 12px 8px; }
.sidebar-section-label {
  color: rgba(255,255,255,0.35);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 4px 8px;
  margin-bottom: 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  width: 100%;
  background: none;
  border: none;
  border-radius: 6px;
  color: rgba(255,255,255,0.65);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms ease;
  text-align: left;
  margin-bottom: 1px;
  font-family: inherit;
}

.nav-btn i { font-size: 13px; width: 16px; text-align: center; flex-shrink: 0; }
.nav-btn span:not(.nav-badge) { flex: 1; }

.nav-btn:hover {
  background: rgba(255,255,255,0.1);
  color: white;
}

.nav-btn.active {
  background: rgba(255,255,255,0.18);
  color: white;
  font-weight: 600;
}

.nav-badge {
  background: rgba(255,255,255,0.2);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

/* ===== MAIN CONTENT ===== */
.main-content { margin-left: 240px;
  flex: 1;
  overflow-y: auto;
  min-width: 0;
}

.page { padding: 28px 32px; max-width: 1400px; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-sub {
  color: var(--text-light);
  font-size: 13px;
  margin-top: 3px;
}

.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ===== BUTTONS ===== */
button { cursor: pointer; font-family: inherit; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: all 150ms cubic-bezier(0.16,1,0.3,1);
  white-space: nowrap;
}

.btn-primary:hover { background: var(--primary-light); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: translateY(0) scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: all 150ms cubic-bezier(0.16,1,0.3,1);
  white-space: nowrap;
}

.btn-secondary:hover { border-color: var(--border-strong); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-secondary:active { transform: translateY(0) scale(0.98); }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: transparent;
  color: var(--text-light);
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: all 150ms ease;
}

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

.btn-icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-light);
  font-size: 12px;
  transition: all 150ms ease;
}

.btn-icon:hover { background: var(--border); color: var(--text); }
.btn-icon.btn-danger:hover { background: var(--error-bg); color: var(--error); border-color: var(--error); }

/* ===== STAT CARDS ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border-left: 3px solid var(--primary);
  transition: transform 200ms ease, box-shadow 200ms ease;
}

.stat-card:nth-child(2) { border-left-color: var(--accent); }
.stat-card:nth-child(3) { border-left-color: var(--success); }
.stat-card:nth-child(4) { border-left-color: var(--warning); }

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.stat-card .label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1;
}

.stat-card .stat-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ===== SECTION CARDS ===== */
.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

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

/* ===== CASES LIST ===== */
.case-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  transition: background 150ms ease;
  cursor: pointer;
}

.case-item:last-child { border-bottom: none; }
.case-item:hover { background: var(--surface-raised); }

.case-icon {
  width: 40px;
  height: 40px;
  background: var(--accent-light);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 16px;
  flex-shrink: 0;
}

.case-info { flex: 1; min-width: 0; }
.case-name { font-weight: 600; font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.case-meta { font-size: 12px; color: var(--text-light); margin-top: 2px; }

.case-actions { display: flex; gap: 6px; }

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-active { background: var(--success-bg); color: #059669; }
.badge-review { background: var(--warning-bg); color: #b45309; }
.badge-closed { background: var(--border); color: var(--text-light); }

/* Status badges for account settings */
.status-badge.active, .status-badge.pro { background: var(--success-bg); color: #059669; }
.status-badge.free { background: var(--border); color: var(--text-light); }
.status-badge.canceled { background: var(--error-bg); color: var(--error); }

/* ===== FILTER BAR ===== */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}

.search-wrap i {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 13px;
}

.search-wrap input {
  width: 100%;
  padding-left: 32px;
  min-height: 44px;
}

/* ===== INPUTS ===== */
input, select, textarea {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 150ms ease, box-shadow 150ms ease;
  outline: none;
}

textarea { height: auto; padding: 8px 12px; resize: vertical; }

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

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

/* ===== DOC TYPE TABS ===== */
.doc-type-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
}

.doc-tab {
  padding: 6px 14px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-light);
  transition: all 150ms ease;
  white-space: nowrap;
}

.doc-tab:hover { background: var(--border); color: var(--text); }
.doc-tab.active { background: var(--primary); color: white; font-weight: 600; }

/* ===== TIMELINE ===== */
.timeline-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  align-items: center;
}

.timeline-controls .search-wrap { flex: 2; min-width: 200px; }
.timeline-controls select { flex: 1; min-width: 160px; }
.timeline-controls input[type="date"] { flex: 0 0 150px; }

#timelineContainer {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.timeline-day-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0 8px;
  position: sticky;
  top: 0;
  background: var(--background);
  z-index: 2;
}

.timeline-day-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  white-space: nowrap;
}

.timeline-day-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.timeline-event {
  display: flex;
  gap: 16px;
  padding: 12px 0;
  position: relative;
}

.timeline-event::before {
  content: '';
  position: absolute;
  left: 19px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
  z-index: 0;
}

.timeline-event:first-of-type::before { top: 50%; }
.timeline-event:last-of-type::before { bottom: 50%; }

.tl-indicator {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
  position: relative;
  z-index: 1;
  background: var(--surface);
  transition: transform 150ms ease;
}

.tl-indicator.type-medication { background: #ede9fe; border-color: #7c3aed; color: #7c3aed; }
.tl-indicator.type-procedure { background: #fee2e2; border-color: #dc2626; color: #dc2626; }
.tl-indicator.type-vital_sign { background: #d1fae5; border-color: #059669; color: #059669; }
.tl-indicator.type-note { background: #dbeafe; border-color: #2563eb; color: #2563eb; }
.tl-indicator.type-diagnosis { background: #fef3c7; border-color: #d97706; color: #d97706; }
.tl-indicator.type-lab { background: #ecfdf5; border-color: #10b981; color: #10b981; }
.tl-indicator.type-imaging { background: #f0fdf4; border-color: #16a34a; color: #16a34a; }
.tl-indicator.type-intervention { background: #fff7ed; border-color: #ea580c; color: #ea580c; }
.tl-indicator.type-transport { background: #f0f9ff; border-color: #0284c7; color: #0284c7; }
.tl-indicator.type-other { background: var(--border); border-color: var(--border-strong); color: var(--text-muted); }

.tl-content {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 200ms ease, transform 200ms ease;
}

.tl-content:hover { box-shadow: var(--shadow-md); transform: translateX(2px); }

.tl-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.tl-title { font-weight: 600; font-size: 14px; color: var(--text); }
.tl-time {
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  flex-shrink: 0;
}

.tl-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }

.tl-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: var(--border);
  color: var(--text-light);
}

.tl-badge.source { background: var(--accent-light); color: var(--accent); }
.tl-badge.facility { background: var(--surface-raised); color: var(--text-light); border: 1px solid var(--border); }
.tl-badge.sig-critical { background: #ede9fe; color: #7c3aed; }
.tl-badge.sig-high { background: var(--error-bg); color: var(--error); }
.tl-badge.sig-medium { background: var(--warning-bg); color: #b45309; }

.tl-desc { font-size: 13px; color: var(--text-light); line-height: 1.5; }

.tl-excerpt {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--surface-raised);
  border-left: 3px solid var(--border-strong);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 12px;
  color: var(--text-light);
  font-style: italic;
  font-family: 'JetBrains Mono', monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.tl-flagged {
  border-left: 3px solid var(--error) !important;
}

.tl-flag-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  background: var(--error-bg);
  color: var(--error);
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.tl-actions { display: flex; gap: 4px; margin-top: 10px; }

/* ===== DOCUMENTS LIST ===== */
.doc-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  transition: box-shadow 200ms ease;
}

.doc-item:hover { box-shadow: var(--shadow-md); }

.doc-icon {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.doc-icon.type-deposition { background: #ede9fe; color: #7c3aed; }
.doc-icon.type-nursing_notes { background: #d1fae5; color: #059669; }
.doc-icon.type-physician_records { background: #dbeafe; color: #2563eb; }
.doc-icon.type-anesthesia { background: #fee2e2; color: #dc2626; }
.doc-icon.type-pharmacy { background: #fef3c7; color: #d97706; }
.doc-icon.type-emr { background: #ecfdf5; color: #059669; }
.doc-icon.type-imaging { background: #f0f9ff; color: #0284c7; }
.doc-icon.type-lab { background: #ecfdf5; color: #10b981; }
.doc-icon.type-other { background: var(--border); color: var(--text-light); }

.doc-info { flex: 1; min-width: 0; }
.doc-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { font-size: 12px; color: var(--text-light); margin-top: 2px; }

.doc-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.doc-status.pending { background: var(--warning-bg); color: #b45309; }
.doc-status.processing { background: var(--accent-light); color: var(--accent); }
.doc-status.completed { background: var(--success-bg); color: #059669; }
.doc-status.failed { background: var(--error-bg); color: var(--error); }

.doc-actions { display: flex; gap: 6px; }

/* ===== TABLES ===== */
.data-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

table { width: 100%; border-collapse: separate; border-spacing: 0; }

thead th {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
  background: var(--surface-raised);
}

thead th:first-child { border-radius: var(--radius) 0 0 0; }
thead th:last-child { border-radius: 0 var(--radius) 0 0; }

tbody td {
  padding: 11px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color 150ms ease; }
tbody tr:hover { background: rgba(var(--primary-rgb), 0.02); }

.empty-row {
  text-align: center;
  color: var(--text-muted);
  padding: 40px !important;
  font-size: 14px;
}

.empty-row i { margin-right: 8px; }

/* ===== MODALS ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
}

.modal-box {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 48px -12px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.2s cubic-bezier(0.16,1,0.3,1);
}

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

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h2 { font-size: 16px; display: flex; align-items: center; gap: 8px; }
.modal-header h2 i { color: var(--primary); }

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--border);
  border-radius: 6px;
  color: var(--text-light);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 150ms ease;
}

.modal-close:hover { background: var(--error-bg); color: var(--error); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ===== FORM ===== */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.form-group:last-child { margin-bottom: 0; }

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.required { color: var(--error); }

/* ===== FILE UPLOAD ===== */
.file-drop-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 200ms ease;
  color: var(--text-light);
}

.file-drop-zone:hover, .file-drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}

.file-drop-zone i { font-size: 32px; margin-bottom: 8px; display: block; }
.file-drop-zone p { font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.file-types { font-size: 12px; color: var(--text-muted); }

.file-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--success-bg);
  border: 1px solid var(--success);
  border-radius: var(--radius);
  margin-top: 8px;
  font-size: 13px;
  color: #059669;
}

.file-preview i { font-size: 16px; }
.file-preview span:nth-child(2) { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-preview span:nth-child(3) { color: #6ee7b7; font-size: 12px; }

.remove-file-btn {
  background: none;
  border: none;
  color: #059669;
  cursor: pointer;
  padding: 2px 4px;
  font-size: 14px;
  transition: color 150ms ease;
}

.remove-file-btn:hover { color: var(--error); }

.extract-option {
  padding: 12px;
  background: var(--accent-light);
  border-radius: var(--radius);
  margin-top: 8px;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  line-height: 1.4;
}

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

/* ===== NARRATIVE ===== */
.narrative-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.narrative-meta {
  display: flex;
  gap: 24px;
  padding: 14px 20px;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.narrative-meta-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-light);
}

.narrative-meta-item i { color: var(--primary); width: 14px; }

.narrative-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 40px;
  gap: 16px;
  color: var(--text-light);
}

.narrative-content {
  padding: 32px 40px;
  font-size: 14px;
  line-height: 1.8;
  color: var(--text);
}

.narrative-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'Inter', serif;
}

.narrative-section {
  margin-bottom: 24px;
}

.narrative-section h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ===== SPINNER ===== */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ===== EMPTY STATE ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
  color: var(--text-light);
}

.empty-state i {
  font-size: 40px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 13px;
  color: var(--text-light);
  max-width: 320px;
  margin-bottom: 20px;
  line-height: 1.5;
}

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--text);
  color: white;
  border-radius: var(--radius);
  box-shadow: 0 8px 16px rgba(0,0,0,0.15);
  min-width: 280px;
  max-width: 400px;
  animation: toastIn 0.3s cubic-bezier(0.16,1,0.3,1);
  font-size: 13px;
  font-weight: 500;
}

@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

.toast.success { background: #059669; }
.toast.error { background: var(--error); }
.toast.warning { background: #d97706; }
.toast.info { background: var(--accent); }
.toast i { font-size: 14px; }

/* ===== SETTINGS ===== */
.account-settings-section { display: flex; flex-direction: column; gap: 16px; }

.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.account-card h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.account-detail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.account-detail:last-of-type { border-bottom: none; }
.account-detail-label { font-size: 13px; color: var(--text-light); font-weight: 500; }
.account-detail-value { font-size: 13px; color: var(--text); font-weight: 500; }
.account-manage-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  margin-top: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: all 150ms ease;
}
.account-manage-btn:hover { background: var(--primary-light); }

.pref-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}

.pref-row:last-of-type { border-bottom: none; }
.pref-label { font-size: 14px; font-weight: 500; color: var(--text); }
.pref-desc { font-size: 12px; color: var(--text-light); margin-top: 2px; }

.theme-btns { display: flex; gap: 6px; }
.theme-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-light);
  font-size: 12px;
  font-weight: 500;
  transition: all 150ms ease;
}

.theme-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ===== DOC DETAIL ===== */
.doc-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.doc-detail-section h4 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.detail-row {
  display: flex;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--text-light); min-width: 110px; font-weight: 500; }
.detail-value { color: var(--text); flex: 1; word-break: break-all; }

.extracted-text-preview {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-light);
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

/* ===== PROGRESS PROCESSING ===== */
.processing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--accent-light);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 16px;
}

.processing-indicator .spinner {
  width: 16px;
  height: 16px;
  border-width: 2px;
  border-top-color: var(--accent);
  border-color: rgba(37,99,235,0.2);
  border-top-color: var(--accent);
}

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

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .sidebar { width: 200px; min-width: 200px; }
  .page { padding: 20px 20px; }
}

@media (max-width: 768px) {
  #mainApp { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; height: auto; position: relative; flex-direction: row; flex-wrap: wrap; }
  .main-content { overflow-y: unset; }
  .page { padding: 16px; }
  .form-row { grid-template-columns: 1fr; gap: 10px; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .timeline-controls { flex-direction: column; }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr; }
  .modal-box { max-width: 100%; }
}
.table-container { overflow-x: auto; }

/* System fix: force modal children visible — CSS animations unreliable */
.modal[style*="display: flex"] .modal-box,
.modal[style*="display: flex"] .modal-content,
.modal[style*="display: flex"] .modal-inner,
.modal[style*="display:flex"] .modal-box,
.modal[style*="display:flex"] .modal-content,
.modal[style*="display:flex"] .modal-inner {
  opacity: 1 !important;
  transform: none !important;
  animation: none !important;
}
/* System fix: modal body must scroll, never clip */
.modal-body { overflow-y: auto !important; max-height: 70vh !important; }
.modal-box { overflow: visible !important; }
.modal-box-wide { max-width: 700px !important; }

/* === CLINT NAV HEIGHT NORMALIZER === */
.sidebar [data-page], .sidebar-link, .sidebar > a, .sidebar > button, .sidebar nav a, .sidebar nav button,
nav.sidebar [data-page], aside [data-page], aside > a, aside > button,
[class*="sidebar"] [data-page], [class*="sidebar-item"], [class*="nav-item"] {
  display: flex !important; align-items: center !important; gap: 10px !important;
  white-space: nowrap !important; box-sizing: border-box !important;
  height: 40px !important; min-height: 40px !important; max-height: 40px !important;
  padding: 0 12px !important; line-height: 1 !important;
  overflow: hidden !important;
}
.sidebar [data-page] > svg, .sidebar-link > svg, .sidebar > a > svg, .sidebar > button > svg,
.sidebar [data-page] > img, .sidebar-link > img, .sidebar > a > img, .sidebar > button > img,
nav.sidebar svg, nav.sidebar img, aside [data-page] svg, aside [data-page] img,
[class*="sidebar"] svg, [class*="sidebar"] img,
[class*="nav-item"] svg, [class*="nav-item"] img {
  width: 18px !important; height: 18px !important; flex-shrink: 0 !important;
}
/* === END CLINT NAV HEIGHT NORMALIZER === */


/* === LEGAL LINKS === */
.legal-agree { display:flex; align-items:flex-start; gap:0.5rem; margin:0.75rem 0; font-size:0.8rem; color:#6b7280; }
.legal-agree input[type="checkbox"] { margin-top:0.2rem; accent-color:#667eea; }
.legal-agree a { color:#667eea; text-decoration:underline; cursor:pointer; }
.legal-agree a:hover { color:#4f46e5; }
/* === END LEGAL LINKS === */

/* === COMPONENT POLISH === */
/* Low-specificity defaults — Sonnet's more-specific selectors override these */

/* Buttons — micro-interactions */
button, .btn, [class*="btn-"] {
  transition: transform var(--duration-fast, 150ms) var(--ease-out, cubic-bezier(0.16,1,0.3,1)),
              box-shadow var(--duration-fast, 150ms) var(--ease-out, cubic-bezier(0.16,1,0.3,1)),
              background-color var(--duration-fast, 150ms) ease,
              border-color var(--duration-fast, 150ms) ease,
              color var(--duration-fast, 150ms) ease;
  cursor: pointer;
}
button:hover:not(:disabled), .btn:hover:not(:disabled) {
  transform: translateY(-1px);
}
button:active:not(:disabled), .btn:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}

/* Cards — hover lift */
.card, [class*="-card"], .stat-card, [class*="Card"] {
  transition: transform var(--duration-normal, 200ms) var(--ease-out, cubic-bezier(0.16,1,0.3,1)),
              box-shadow var(--duration-normal, 200ms) var(--ease-out, cubic-bezier(0.16,1,0.3,1)),
              border-color var(--duration-normal, 200ms) ease,
              background-color var(--duration-normal, 200ms) ease;
}
.card:hover, [class*="-card"]:hover, .stat-card:hover, [class*="Card"]:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg, 0 10px 15px -3px rgba(0,0,0,0.08));
}

/* Tables — polished headers and row hover */
table { border-collapse: separate; border-spacing: 0; width: 100%; }
thead th {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-light, #6b7280);
}
tbody tr { transition: background-color var(--duration-fast, 150ms) ease; }
tbody tr:hover { background-color: var(--primary-50, rgba(59,130,246,0.04)); }

/* Nav items — transition */
.nav-btn, .nav-item, [data-page] {
  transition: background-color var(--duration-fast, 150ms) ease,
              color var(--duration-fast, 150ms) ease;
}

/* Badges / Status pills */
.badge, .status-badge, [class*="badge"], .tag, .chip, .pill {
  font-size: 12px; font-weight: 500;
  letter-spacing: 0.01em;
  border-radius: var(--radius-full, 9999px);
  padding: 2px 10px;
  display: inline-flex; align-items: center;
}

/* Toast / notification — slide in animation */
.toast, .notification, [class*="toast"] {
  box-shadow: var(--shadow-xl, 0 20px 25px -5px rgba(0,0,0,0.1));
  border-radius: var(--radius-lg, 8px);
  animation: ds-slideIn var(--duration-slow, 300ms) var(--ease-out, cubic-bezier(0.16,1,0.3,1));
}
@keyframes ds-slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Form inputs — consistent sizing and focus */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
select, textarea {
  font-family: inherit;
  transition: border-color var(--duration-fast, 150ms) ease, box-shadow var(--duration-fast, 150ms) ease;
}

/* Modal backdrop */
.modal, [class*="modal-overlay"], .overlay {
  transition: opacity var(--duration-normal, 200ms) ease;
}

/* Empty states */
.empty-state, [class*="empty"], .no-data, .no-results { opacity: 0.7; }

/* Loading skeleton shimmer */
@keyframes ds-shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
.skeleton, [class*="skeleton"], .loading-placeholder {
  background: linear-gradient(90deg, var(--border, #e2e8f0) 25%, var(--background, #f8fafc) 50%, var(--border, #e2e8f0) 75%);
  background-size: 200% 100%;
  animation: ds-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-md, 6px);
}

/* Smooth page transitions */
.page, [class*="Page"], section[id$="Page"] {
  animation: ds-fadeIn var(--duration-slow, 300ms) ease;
}
@keyframes ds-fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
/* === END COMPONENT POLISH === */