/* ============================================================
   WOOF-01 eCRF — design system
   Modernized visual layer only: every class name below is still
   the exact one the TS view files render (verified against a full
   grep inventory of *.ts + index.html before this rewrite) and
   every CSS custom property referenced inline from TS
   (--primary, --accent, --success, --warning, --danger,
   --text-muted, --border) keeps its name. No markup/behavior
   changed, only colors/spacing/shadows/radii/typography.
   ============================================================ */

:root {
  /* Brand */
  --primary: #2563eb;
  --primary-dark: #1e3a8a;
  --primary-light: #60a5fa;
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --accent: #0891b2;

  /* Semantic */
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --info: #2563eb;
  --info-bg: #eff6ff;

  /* Neutrals */
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --border: #e5e9f0;
  --border-strong: #cbd5e1;
  --hover: #f1f5f9;

  /* Spacing (8px rhythm) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Radius */
  --radius-sm: 7px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.06);
  --shadow-focus: 0 0 0 3px rgba(37, 99, 235, 0.16);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4, h5 { font-weight: 700; letter-spacing: -0.01em; }
::selection { background: var(--primary-100); color: var(--primary-dark); }

/* Slim modern scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
*::-webkit-scrollbar-track { background: transparent; }

/* === LOGIN PAGE === */
.login-bg {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 15% 15%, rgba(255,255,255,0.12), transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(255,255,255,0.10), transparent 45%),
    linear-gradient(135deg, #1e3a8a 0%, #2563eb 55%, #0891b2 100%);
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 40px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 {
  font-size: 26px;
  color: var(--primary-dark);
  font-weight: 800;
  letter-spacing: -0.02em;
}
.login-logo .sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 4px;
}
.login-card h2 {
  font-size: 19px;
  margin-bottom: 6px;
  color: var(--text);
}
.login-card p.intro {
  color: var(--text-muted);
  margin-bottom: 22px;
  font-size: 13px;
}
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--text);
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.form-group input:hover, .form-group select:hover, .form-group textarea:hover { border-color: var(--border-strong); }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-focus);
}
.form-group input:disabled, .form-group select:disabled, .form-group textarea:disabled {
  background: var(--surface-muted);
  color: var(--text-muted);
  cursor: not-allowed;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.1s var(--ease);
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: white; box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--hover); border-color: var(--border-strong); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-xs { padding: 4px 9px; font-size: 11px; border-radius: 6px; }
.btn-block { width: 100%; }

.error-box, .success-box, .info-box, .warning-box {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.error-box { background: var(--danger-bg); border-color: #fecaca; color: #991b1b; }
.success-box { background: var(--success-bg); border-color: #bbf7d0; color: #166534; }
.info-box { background: var(--info-bg); border-color: #bfdbfe; color: #1e40af; }
.warning-box { background: var(--warning-bg); border-color: #fde68a; color: #92400e; }

.text-link {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  text-decoration: underline;
  padding: 4px 0;
}

.security-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

/* === APP LAYOUT === */
/* Source used a ".app.active" convention (display:none until an "active"
   class was added). This port's JS instead uses a single ".hidden" utility
   class everywhere (index.html starts #app with class="app hidden", and
   main.ts's enterApp() only ever removes "hidden") - so .app must default to
   its visible (flex) layout directly, with the .hidden utility class (below,
   display:none !important) as the sole show/hide mechanism. */
.app { display: flex; flex-direction: column; min-height: 100vh; }

header.app-header {
  background: linear-gradient(120deg, var(--primary-dark), var(--primary));
  color: white;
  padding: 13px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  z-index: 2;
}
header.app-header h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
header.app-header .header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
}
.current-study {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.28);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 600;
}
.btn-switch-study {
  background: transparent;
  color: white;
  border: none;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  opacity: 0.85;
}
.btn-switch-study:hover { opacity: 1; }
.user-info { text-align: right; }
.user-info .name { font-weight: 600; }
.user-info .role { font-size: 11px; opacity: 0.85; }
.btn-logout {
  background: rgba(255,255,255,0.12);
  color: white;
  border: 1px solid rgba(255,255,255,0.28);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  transition: background-color 0.15s var(--ease);
}
.btn-logout:hover { background: rgba(255,255,255,0.22); }

/* === TABS === */
.maintabs {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 0 20px;
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-color: var(--primary) var(--hover);
  scrollbar-width: thin;
}
.maintabs::-webkit-scrollbar { height: 8px; }
.maintabs::-webkit-scrollbar-track { background: var(--hover); }
.maintabs::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 20px; }
.maintabs::-webkit-scrollbar-thumb:hover { background: var(--primary-dark); }
.maintab {
  background: transparent;
  border: none;
  padding: 14px 18px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s var(--ease), background-color 0.15s var(--ease);
  white-space: nowrap;
}
.maintab:hover { color: var(--text); background: var(--hover); }
.maintab.active { color: var(--primary); }

/* === MAIN LAYOUT === */
.main-layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}
.sidebar-header .count {
  background: var(--primary-100);
  color: var(--primary-dark);
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 20px;
  font-weight: 700;
}
.patient-list { padding: 6px; }
.patient-item {
  padding: 10px 12px;
  margin: 2px 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-sm);
  border-left: 3px solid transparent;
  transition: background-color 0.12s var(--ease);
}
.patient-item:hover { background: var(--hover); }
.patient-item.active { background: var(--primary-50); border-left-color: var(--primary); }
.patient-item .pid,
.patient-item-id { font-weight: 600; font-size: 13px; color: var(--text); }
.patient-item .pinfo,
.patient-item-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.patient-item .psite {
  font-size: 11px;
  color: var(--text-faint, var(--text-muted));
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.patient-item .pstudy {
  font-size: 11px;
  color: var(--primary, #2563eb);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}
.patient-item .pstatus {
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-top: 4px;
  padding: 2px 7px;
  border-radius: 20px;
  display: inline-block;
  align-self: flex-start;
}
.pstatus.active-st { background: var(--success-bg); color: #166534; }
.pstatus.screen-fail { background: var(--warning-bg); color: #92400e; }
.pstatus.completed { background: #e0e7ff; color: #3730a3; }
.pstatus.withdrawn { background: var(--danger-bg); color: #991b1b; }
.pstatus.screening { background: #f3e8ff; color: #6b21a8; }

#patientSearch {
  width: 100%;
  padding: 7px 10px;
  font-size: 12.5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  color: var(--text);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background-color 0.15s var(--ease);
}
#patientSearch:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: var(--shadow-focus);
}
#patientSearch::placeholder { color: var(--text-faint); }

.content { flex: 1; overflow-y: auto; padding: 24px 28px; min-width: 0; }

/* === HOME PAGE === */
.home-greeting { margin-bottom: 24px; }
.home-greeting h2 { font-size: 23px; font-weight: 800; letter-spacing: -0.02em; }
.home-greeting p { color: var(--text-muted); margin-top: 4px; font-size: 13.5px; }

.home-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  transition: box-shadow 0.15s var(--ease), transform 0.15s var(--ease);
}
.stat-card:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.stat-card .label {
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}
.stat-card .value {
  font-size: 27px;
  font-weight: 800;
  margin-top: 8px;
  color: var(--primary-dark);
  letter-spacing: -0.02em;
}
.home-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}
.home-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), border-color 0.15s var(--ease);
}
.home-card:hover {
  border-color: var(--primary-light);
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}
.home-card .icon { font-size: 28px; margin-bottom: 10px; }
.home-card h3 { font-size: 15.5px; margin-bottom: 4px; }
.home-card p { color: var(--text-muted); font-size: 12.5px; }

/* === FORMS / SECTIONS === */
.section {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}
.section-header {
  padding: 14px 20px;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.section-header:hover { background: var(--hover); }
.section-header .title { display: flex; align-items: center; gap: 8px; }
.section-header .toggle { color: var(--text-muted); transition: transform 0.2s var(--ease); }
.section.collapsed .toggle { transform: rotate(-90deg); }
.section.collapsed .section-body { display: none; }
.section-body { padding: 20px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.form-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.form-row > * { flex: 1; min-width: 150px; }

/* === TABLES === */
/* .tbl (admin views) and .data-table (clinical/safety/queries/audit views)
   share the same modern styling - .data-table was used throughout the app
   but had never actually been styled, a gap from the original port fixed
   as part of this redesign. */
table.tbl, table.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
table.tbl th, table.tbl td,
table.data-table th, table.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
table.tbl th, table.data-table th {
  background: var(--surface-muted);
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}
table.tbl tr:last-child td, table.data-table tr:last-child td { border-bottom: none; }
table.tbl tr:hover td, table.data-table tr:hover td { background: var(--surface-muted); }

/* Import preview's "Modifications détectées" tree: patient -> visit ->
   section, collapsible like a file explorer (native <details>, no JS). */
.change-tree { font-size: 13px; }
.tree-node { margin: 1px 0; }
.tree-node > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  list-style: none;
  user-select: none;
}
.tree-node > summary::-webkit-details-marker { display: none; }
.tree-node > summary::marker { content: ""; }
.tree-node > summary::before { content: "▸"; display: inline-block; width: 10px; color: var(--text-muted); transition: transform 0.15s; }
.tree-node[open] > summary::before { transform: rotate(90deg); }
.tree-node > summary:hover { background: var(--surface-muted); }
.tree-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
}
.tree-children { margin-left: 15px; padding-left: 12px; border-left: 1px dashed var(--border); margin-bottom: 2px; }
.tree-field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  flex-wrap: wrap;
}
.tree-field-row:hover { background: var(--surface-muted); }
.tree-field-approve { display: flex; align-items: center; cursor: pointer; }
.tree-field-approve input { cursor: pointer; }
.tree-field-row:has(.change-approve:not(:checked)) { opacity: 0.5; }
.tree-field-name { min-width: 170px; font-weight: 600; }
.tree-field-value { word-break: break-word; overflow-wrap: anywhere; }
.tree-field-db { color: var(--danger); text-decoration: line-through; opacity: 0.85; }
.tree-field-file { color: var(--success); font-weight: 600; }
.tree-field-arrow { color: var(--text-muted); }

.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab-btn {
  background: none;
  border: none;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s var(--ease);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal.large, .modal-large { max-width: 1200px; }
.modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--surface);
}
.modal-header h3 { font-size: 17px; }
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.modal-close:hover { background: var(--hover); color: var(--text); }
.modal-body { padding: 22px; }
.modal-footer {
  padding: 16px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  position: sticky;
  bottom: 0;
  background: var(--surface);
}

/* === TOAST NOTIFICATIONS === */
/* Replaces window.alert() across the app (see dom.ts's notify()) - stacked
   top-center, above the modal overlay (z-index 1000) so a validation error
   raised from within an open modal is still visible. */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(480px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  line-height: 1.4;
  border: 1px solid transparent;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}
.toast.toast-in { opacity: 1; transform: translateY(0); }
.toast.toast-out { opacity: 0; transform: translateY(-8px); }
.toast .toast-msg { flex: 1; word-break: break-word; }
.toast .toast-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  color: inherit;
  opacity: 0.55;
  padding: 0 2px;
}
.toast .toast-close:hover { opacity: 1; }
.toast-error { background: var(--danger-bg); color: var(--danger); border-color: rgba(220, 38, 38, 0.25); }
.toast-warning { background: var(--warning-bg); color: var(--warning); border-color: rgba(217, 119, 6, 0.25); }
.toast-success { background: var(--success-bg); color: var(--success); border-color: rgba(22, 163, 74, 0.25); }

/* === BADGES === */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-info { background: var(--info-bg); color: #1e40af; }
.badge-success { background: var(--success-bg); color: #166534; }
.badge-warning { background: var(--warning-bg); color: #92400e; }
.badge-danger { background: var(--danger-bg); color: #991b1b; }
.badge-neutral { background: var(--hover); color: #475569; }

/* === VISIT TABS === */
.visit-tabs {
  display: flex;
  gap: 5px;
  flex-wrap: nowrap;
  overflow-x: auto;
  margin-bottom: 20px;
  padding: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
}
.visit-tab {
  padding: 7px 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  flex-shrink: 0;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
  line-height: 1.2;
}
.visit-tab:hover { background: var(--hover); }
.visit-tab.active { background: var(--primary); color: white; border-color: var(--primary); }
.visit-tab .vk { font-weight: 700; font-size: 12px; }
.visit-tab .vlbl { font-size: 9px; opacity: 0.8; margin-top: 1px; }

/* === Header bar de visite === */
.visit-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.visit-header-title { display: flex; align-items: center; gap: 10px; flex: 1 1 auto; font-size: 14px; }
.visit-header-icon { font-size: 18px; }
.visit-header-label { color: var(--text); font-weight: 500; }
.visit-header-day {
  color: var(--text-muted);
  font-size: 11.5px;
  padding: 2px 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
}
.visit-header-date { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.visit-header-datelabel, .visit-header-icf {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
}
.visit-header-datelabel > span, .visit-header-icf > span { font-weight: 500; }

/* === Inputs date compacts === */
.input-date-compact {
  width: 150px;
  padding: 6px 9px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
}
.input-date-compact:disabled { background: var(--surface-muted); color: var(--text-muted); }

.section-tab[data-sid="cm"] .status-dot,
.section-tab[data-sid="ae"] .status-dot { display: none; }

/* === AUDIT TRAIL === */
.audit-entry {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 140px 100px 1fr 120px;
  gap: 12px;
  font-size: 12px;
  align-items: center;
}
.audit-entry .timestamp { color: var(--text-muted); font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.audit-entry .user { font-weight: 600; }
.audit-entry .action { color: var(--text); }
.audit-entry .scope { color: var(--text-muted); font-size: 11px; }
.audit-table { font-size: 12.5px; }

/* === EMPTY STATES === */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 44px; margin-bottom: 12px; opacity: 0.45; }
.empty-state h3 { font-size: 16px; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 13px; margin-bottom: 16px; }

.loading { padding: 40px 0; text-align: center; color: var(--text-muted); font-size: 13px; }
.view-header { margin-bottom: 18px; }
.view-header h2 { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.view-header .muted, .muted { color: var(--text-muted); }

/* === FILTERS === */
.filters-bar {
  background: var(--surface);
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
  box-shadow: var(--shadow-xs);
}
.filters-bar label { font-size: 12px; font-weight: 600; }
.filters-bar select, .filters-bar input {
  padding: 7px 10px;
  font-size: 13px;
  min-width: 140px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}
.filters-bar select:focus, .filters-bar input:focus { outline: none; border-color: var(--primary); box-shadow: var(--shadow-focus); }

/* === CHECKBOX/RADIO LABELS === */
.cbx {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  line-height: 1.4;
  margin: 0;
  padding: 4px 0;
}
.cbx input[type="checkbox"], .cbx input[type="radio"] {
  margin: 0; flex-shrink: 0; width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary);
}
.cbx-stack { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.cbx-inline { display: inline-flex; align-items: center; gap: 8px; margin-right: 16px; }

/* === VALIDATION === */
input.field-error, textarea.field-error, select.field-error {
  border: 1.5px solid var(--danger) !important;
  background: var(--danger-bg);
}
.field-hint { font-size: 11px; color: var(--text-muted); margin-top: 3px; font-style: italic; }
.field-warning {
  font-size: 12px;
  color: var(--danger);
  margin-top: 4px;
  padding: 7px 10px;
  background: var(--danger-bg);
  border-left: 3px solid var(--danger);
  border-radius: 6px;
}
.required-mark { color: var(--danger); margin-left: 2px; font-weight: bold; }

/* === ALERTS (PV / SAE) === */
.alert, .alert-pv, .alert-sae, .alert-info {
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin: 12px 0;
  font-size: 13px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1.5px solid transparent;
}
.alert-pv { background: var(--warning-bg); border-color: #f5c877; color: #78350f; }
.alert-pv .icon { font-size: 22px; flex-shrink: 0; }
.alert-pv strong { color: #b45309; }
.alert-sae { background: var(--danger-bg); border-color: #f3a1a1; color: #7f1d1d; display: block; }
.alert-info { background: var(--info-bg); border-color: #93c5fd; color: #1e40af; display: block; }

/* === CORQ === */
.corq-block { margin: 14px 0; padding: 14px; background: var(--surface-muted); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.corq-block h4 { font-size: 14px; color: var(--primary-dark); margin: 0 0 10px 0; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.corq-row { display: grid; grid-template-columns: 60px 1fr 110px; gap: 12px; align-items: center; padding: 9px 4px; border-bottom: 1px dashed var(--border); }
.corq-row:last-child { border-bottom: none; }
.corq-key { font-weight: 700; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; color: var(--primary-dark); min-width: 32px; text-align: center; }
.corq-row .corq-label { font-size: 13px; line-height: 1.4; }
.corq-row select { font-size: 13px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; }
.corq-inverse-tag, .corq-positive-tag { margin-left: 6px; font-size: 13px; cursor: help; }
.corq-positive-tag { color: var(--success); }
.corq-inverse-tag { color: var(--danger); }
.corq-total-badge { font-size: 12.5px; color: var(--text-muted); background: var(--surface); padding: 4px 11px; border-radius: 20px; border: 1px solid var(--border); }
.corq-vas { margin-top: 14px; padding: 14px; background: var(--info-bg); border: 1px solid #93c5fd; border-radius: var(--radius-sm); }
.corq-vas label { font-size: 13px; font-weight: 600; display: block; margin-bottom: 8px; }
.corq-vas .vas-controls { display: flex; align-items: center; gap: 12px; }
.corq-vas input[type="range"] { flex: 1; accent-color: var(--primary); }
.corq-vas .vas-value { font-weight: 700; font-size: 18px; color: var(--primary-dark); min-width: 70px; text-align: right; }

/* === Anatomic site picker === */
.site-picker { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; background: var(--surface-muted); max-height: 380px; overflow-y: auto; }
.site-picker h5 { font-size: 12px; font-weight: 700; color: var(--primary-dark); margin: 8px 0 4px 0; text-transform: uppercase; letter-spacing: 0.04em; }
.site-picker h5:first-child { margin-top: 0; }
.site-picker .site-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 14px; margin-bottom: 8px; }

/* === SECTION TABS === */
.section-tabs {
  display: flex;
  gap: 3px;
  margin: 14px 0 0 0;
  padding: 5px 5px 0 5px;
  background: var(--surface-muted);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  overflow-x: auto;
  flex-wrap: nowrap;
  scrollbar-color: var(--primary) var(--hover);
  scrollbar-width: thin;
}
.section-tabs::-webkit-scrollbar { height: 8px; }
.section-tabs::-webkit-scrollbar-track { background: var(--hover); }
.section-tabs::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 20px; }
.section-tabs::-webkit-scrollbar-thumb:hover { background: var(--primary-dark); }
.section-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--border);
  border: none;
  border-radius: 7px 7px 0 0;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
  flex-shrink: 0;
  position: relative;
}
.section-tab:hover { background: var(--border-strong); }
.section-tab.active { background: var(--primary); color: white; font-weight: 700; }
.section-tab .ico { font-size: 14px; }
.section-tab .lbl { font-size: 13px; }

.status-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  font-size: 9px;
  font-weight: 700;
  margin-left: 4px;
  border: 1.5px solid currentColor;
  background: white;
  color: var(--text-faint);
}
.section-tab.active .status-dot { background: white; }
.status-empty { color: var(--text-faint); background: var(--hover); }
.status-partial { color: #d97706; background: var(--warning-bg); }
.status-complete { color: #059669; background: var(--success-bg); }
.status-warning { color: var(--danger); background: var(--danger-bg); }

.section-pane { background: var(--surface); border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius-sm) var(--radius-sm); padding: 0; box-shadow: var(--shadow-xs); }
.section-pane > .section { border: none; margin-bottom: 0; box-shadow: none; }
.section-pane > .section > .section-header { border-bottom: 1px solid var(--border); border-radius: 0; }

.section-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--surface-muted);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.section-nav > * { flex: 0 1 auto; }
.section-nav > .btn-primary { margin-left: auto; }

/* === VISIT OVERVIEW === */
.visit-overview { background: var(--surface); border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius-sm) var(--radius-sm); padding: 24px; box-shadow: var(--shadow-xs); }
.overview-header { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.overview-progress { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
.overview-progress-bar { flex: 1; height: 9px; background: var(--border); border-radius: 20px; overflow: hidden; }
.overview-progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width 0.3s var(--ease); border-radius: 20px; }
.overview-progress-label { font-size: 13px; color: var(--text-muted); white-space: nowrap; }

.overview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.overview-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: 13px;
  transition: transform 0.12s var(--ease), box-shadow 0.15s var(--ease);
}
.overview-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.overview-card-icon { font-size: 22px; flex-shrink: 0; }
.overview-card-body { flex: 1; }
.overview-card-label { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.overview-card-status { font-size: 11px; opacity: 0.85; }

/* === CM grouped by visit === */
.cm-by-visit { margin: 12px 0; }
.cm-visit-group { margin: 8px 0; padding: 10px 12px; background: var(--surface-muted); border-left: 3px solid var(--primary-dark); border-radius: 6px; }
.cm-visit-group h5 { margin: 0 0 8px; color: var(--primary-dark); font-size: 13px; }
.cm-source-tag { display: inline-block; font-size: 10px; background: var(--hover); color: var(--text-muted); padding: 2px 7px; border-radius: 20px; margin-left: 6px; }

/* === HIDDEN === */
.hidden { display: none !important; }

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .sidebar { width: 220px; }
  .main-layout { flex-direction: column; }
  .home-stats { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 18px; }
}

/* === PRINT === */
@media print {
  .sidebar, .maintabs, header.app-header, .filters-bar { display: none !important; }
  .content { padding: 0; }
}
