/* ================================================================
   MediCal v10 — Responsive CSS (Mobile-first + Desktop)
================================================================ */

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

:root {
  --bg:          #0d1117;
  --bg2:         #161b22;
  --bg3:         #1c2230;
  --border:      #2a3244;
  --border2:     #3d4f6b;
  --accent:      #3b82f6;
  --accent-glow: #3b82f620;
  --accent2:     #06b6d4;
  --text:        #e6edf3;
  --text2:       #8b97ac;
  --text3:       #4d5d73;
  --success:     #22c55e;
  --warning:     #f59e0b;
  --danger:      #ef4444;
  --purple:      #a855f7;
  --radius:      10px;
  --radius-lg:   16px;
  --shadow:      0 4px 24px #00000040;
  --shadow-lg:   0 8px 48px #00000060;
  --sidebar-w:   240px;
  --topbar-h:    64px;
  --mobile-topbar-h: 52px;
  --bottom-nav-h:    60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: 'DM Sans', sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ================================================================
   iOS / iPhone optimizations
   - 300ms tap delay elimination
   - Scroll momentum
   - Prevent accidental pull-to-refresh
   - Tap highlight reset
================================================================ */
*, *::before, *::after {
  -webkit-tap-highlight-color: transparent;  /* remove blue flash on tap */
  touch-action: manipulation;                /* eliminate 300ms tap delay */
}
html {
  overscroll-behavior: none;                 /* prevent pull-to-refresh */
  -webkit-text-size-adjust: 100%;            /* prevent iOS auto-scaling */
}
.detail-body, .modal-form, .patients-table-wrap, .list-scroll {
  -webkit-overflow-scrolling: touch;         /* momentum scrolling in iOS */
  overscroll-behavior: contain;
}

/* iOS Safari: prevent auto-zoom on input focus (requires font-size ≥ 16px) */
@media (max-width: 768px) {
  input[type="text"], input[type="email"], input[type="tel"],
  input[type="number"], input[type="date"], input[type="time"],
  input[type="password"], input[type="search"],
  select, textarea {
    font-size: 16px !important;  /* prevents iOS Safari zoom on focus */
  }
}


html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ── Mobile top bar ──────────────────────────────────────────── */
.mobile-topbar {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--mobile-topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  align-items: center; justify-content: space-between;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0);
}
.mobile-logo {
  font-family: 'DM Serif Display';
  font-size: 18px;
  color: var(--text);
  position: absolute;
  left: 50%; transform: translateX(-50%);
}
.mobile-menu-btn {
  width: 40px; height: 40px; background: none; border: none;
  cursor: pointer; display: flex; flex-direction: column;
  justify-content: center; gap: 5px; padding: 8px;
}
.mobile-menu-btn span {
  display: block; height: 2px; background: var(--text);
  border-radius: 2px; transition: all .2s;
}
.mobile-action-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); border: none;
  color: #fff; font-size: 24px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .2s;
}
.mobile-action-btn:active { background: #2563eb; }

/* ── Sidebar overlay (mobile) ─────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 299;
  background: #000000a0;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 300;
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto;
  transition: transform .3s cubic-bezier(.4, 0, .2, 1);
}
.sidebar-inner { display: flex; flex-direction: column; height: 100%; padding: 16px 0; }
.logo {
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
}
.logo-icon  { font-size: 20px; color: var(--accent2); }
.logo-text  { font-family: 'DM Serif Display'; font-size: 18px; flex: 1; }
.sidebar-close {
  display: none;
  background: none; border: none; color: var(--text2);
  font-size: 18px; cursor: pointer; padding: 4px;
}

.sidebar-nav {
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px 8px;
}
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius);
  background: none; border: none; color: var(--text2);
  font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all .15s; text-align: left; width: 100%;
}
.nav-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; flex-shrink: 0; }
.nav-btn:hover  { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: var(--accent-glow); color: var(--accent); }

/* ── Mini calendar ───────────────────────────────────────────── */
.mini-calendar {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin: 6px 0;
}
.mini-cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.mini-cal-title  { font-size: 12px; font-weight: 600; color: var(--text); }
.mini-cal-nav    { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 14px; padding: 2px 6px; }
.mini-cal-nav:hover { color: var(--accent); }
.mini-cal-grid   { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.mini-day-label  { font-size: 9px; color: var(--text3); text-align: center; padding: 2px 0; font-weight: 600; }
.mini-day        { font-size: 10px; text-align: center; padding: 3px 2px; border-radius: 5px; cursor: pointer; color: var(--text2); transition: all .1s; }
.mini-day:hover  { background: var(--bg3); color: var(--text); }
.mini-day.today  { background: var(--accent); color: #fff; font-weight: 700; }
.mini-day.selected { background: var(--accent-glow); color: var(--accent); }
.mini-day.has-events::after { content:''; display:block; width:3px; height:3px; background:var(--accent2); border-radius:50%; margin:1px auto 0; }
.mini-day.other-month { opacity:.3; }

/* ── Nurse legend ─────────────────────────────────────────────── */
.nurse-legend       { padding: 10px 16px; }
.nurse-legend-title { font-size: 9px; font-weight: 700; color: var(--text3); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; }
.nurse-legend-list  { display: flex; flex-direction: column; gap: 4px; }
.nurse-legend-item  { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--text2); }
.nurse-dot          { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.nurse-tag          { font-size: 9px; padding: 1px 4px; border-radius: 3px; background: var(--bg3); color: var(--text3); }

/* ── Stats ───────────────────────────────────────────────────── */
.sidebar-stats { display: flex; gap: 8px; padding: 12px 16px; margin-top: auto; }
.stat-card { flex: 1; background: var(--bg3); border-radius: var(--radius); padding: 10px 8px; text-align: center; border: 1px solid var(--border); }
.stat-num  { display: block; font-size: 20px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat-label{ font-size: 10px; color: var(--text2); }

/* ── Main layout ─────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  height: 100vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* ── Desktop top bar ─────────────────────────────────────────── */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: var(--topbar-h);
  background: var(--bg2); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.top-left  { display: flex; align-items: center; gap: 10px; }
.top-right { display: flex; align-items: center; gap: 10px; }
.current-title { font-family: 'DM Serif Display'; font-size: 22px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; font-size: 16px;
  display: flex; align-items: center; justify-content: center; transition: all .2s;
}
.icon-btn:hover { background: var(--accent); border-color: var(--accent); }
.today-btn {
  padding: 6px 12px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); font-size: 13px; cursor: pointer; transition: all .2s;
}
.today-btn:hover { color: var(--text); }
.view-toggle { display: flex; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.vt-btn { padding: 6px 12px; font-size: 12px; font-weight: 500; background: none; border: none; color: var(--text2); cursor: pointer; transition: all .15s; }
.vt-btn.active { background: var(--accent); color: #fff; }
.add-btn {
  padding: 8px 16px; border-radius: 8px;
  background: var(--accent); border: none; color: #fff;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: all .2s;
  white-space: nowrap;
}
.add-btn:hover { background: #2563eb; }

/* ── Mobile calendar nav ─────────────────────────────────────── */
.mobile-cal-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--bg2);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.mobile-cal-title { font-family: 'DM Serif Display'; font-size: 18px; }

/* ── Weekdays header ─────────────────────────────────────────── */
.weekdays-header {
  display: grid; grid-template-columns: repeat(7, 1fr);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0; background: var(--bg2);
}
.weekday-label { text-align: center; padding: 8px 0; font-size: 11px; font-weight: 600; color: var(--text3); letter-spacing: .5px; text-transform: uppercase; }
.weekday-label.weekend { color: var(--accent2); opacity: .7; }

/* ── Calendar grid ───────────────────────────────────────────── */
#calendarView { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.calendar-grid {
  flex: 1; display: grid; grid-template-columns: repeat(7, 1fr);
  padding: 0 16px 12px; gap: 4px; overflow-y: auto;
}
/* Week and Day views need a single-column grid */
.calendar-grid.week-mode,
.calendar-grid.day-mode {
  display: block;
  padding: 0;
  overflow: hidden;
}
.day-cell {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px; min-height: 90px; cursor: pointer;
  transition: border-color .2s; display: flex; flex-direction: column; gap: 3px; overflow: hidden;
}
.day-cell:hover { border-color: var(--border2); }
.day-cell.today { border-color: var(--accent); background: var(--accent-glow); }
.day-cell.other-month { opacity: .3; }
.day-number {
  font-size: 12px; font-weight: 600; color: var(--text2);
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%; flex-shrink: 0;
}
.day-cell.today .day-number { background: var(--accent); color: #fff; }
.day-events { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.event-pill {
  padding: 2px 6px 2px 8px; border-radius: 4px;
  font-size: 10px; font-weight: 500; line-height: 1.35;
  cursor: pointer; transition: filter .15s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-left-width: 3px; border-left-style: solid;
}
.event-pill:hover { filter: brightness(1.15); }
.more-events { font-size: 9px; color: var(--accent); font-weight: 600; padding: 2px 4px; }

/* Week / Day views */
.time-slot { height: 60px; display: flex; align-items: flex-start; padding: 4px 8px; font-size: 10px; color: var(--text3); font-family: 'JetBrains Mono'; border-bottom: 1px solid var(--border); }
.week-day-header { text-align: center; padding: 6px 2px; border-bottom: 1px solid var(--border); font-size: 11px; font-weight: 600; color: var(--text2); position: sticky; top: 0; background: var(--bg2); }
.week-day-header.today { color: var(--accent); }
.week-slot { height: 60px; border-bottom: 1px solid var(--border); cursor: pointer; }
.week-slot:hover { background: var(--accent-glow); }
.week-event { position: absolute; left: 2px; right: 2px; border-radius: 5px; padding: 2px 5px; font-size: 10px; font-weight: 500; cursor: pointer; overflow: hidden; z-index: 2; border-left-width: 3px; border-left-style: solid; }
.day-view-grid { flex: 1; display: grid; grid-template-columns: 60px 1fr; overflow-y: auto; }
.day-slot { height: 60px; border-bottom: 1px solid var(--border); cursor: pointer; }
.day-slot:hover { background: var(--accent-glow); }
.day-event-block { position: absolute; left: 8px; right: 8px; border-radius: 8px; padding: 6px 10px; cursor: pointer; z-index: 2; border-left-width: 4px; border-left-style: solid; }
.ev-title { font-size: 12px; font-weight: 600; }
.ev-sub   { font-size: 10px; opacity: .8; margin-top: 2px; }

/* ── Section header ──────────────────────────────────────────── */
.section-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 10px; flex-shrink: 0; }
.section-title  { font-family: 'DM Serif Display'; font-size: 20px; color: var(--text); }
.section-actions { display: flex; gap: 8px; align-items: center; }
.compact-select { padding: 6px 10px; border-radius: 8px; background: var(--bg3); border: 1px solid var(--border); color: var(--text); font-size: 13px; outline: none; cursor: pointer; }

/* ── List view ───────────────────────────────────────────────── */
#listView { flex: 1; overflow-y: auto; padding: 0; display: none; flex-direction: column; }
.list-header { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px; flex-shrink: 0; }
.filter-row  { display: flex; gap: 8px; }
.search-box  { width: 100%; padding: 10px 14px; border-radius: var(--radius); background: var(--bg2); border: 1px solid var(--border); color: var(--text); font-size: 14px; outline: none; transition: border-color .2s; }
.search-box:focus { border-color: var(--accent); }
.cat-filter  { flex: 1; padding: 8px 10px; border-radius: var(--radius); background: var(--bg2); border: 1px solid var(--border); color: var(--text2); font-size: 12px; outline: none; cursor: pointer; }
.appointment-list { display: flex; flex-direction: column; gap: 2px; padding: 6px 16px 80px; overflow-y: auto; }

/* ── Appointment row (desktop) — dense single-line ──────────── */
.appt-row {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; display: grid;
  grid-template-columns: 100px 180px 1fr 80px 1fr 90px;
  gap: 8px; align-items: center; cursor: pointer; transition: border-color .2s;
  border-left-width: 3px; border-left-style: solid;
  min-height: 0;
}
.appt-row:hover { background: var(--bg3); border-color: var(--border2) !important; }

/* ── Appointment card (mobile) ───────────────────────────────── */
.appt-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px; cursor: pointer; transition: border-color .2s;
  border-left-width: 4px; border-left-style: solid;
  display: flex; flex-direction: column; gap: 8px;
}
.appt-card:hover { border-color: var(--border2) !important; }
.appt-card-top { display: flex; justify-content: space-between; align-items: flex-start; }
.appt-card-name { font-size: 15px; font-weight: 600; color: var(--text); }
.appt-card-time { font-family: 'JetBrains Mono'; font-size: 12px; color: var(--accent2); }
.appt-card-meta { font-size: 12px; color: var(--text2); display: flex; flex-wrap: wrap; gap: 6px; }
.appt-card-footer { display: flex; justify-content: space-between; align-items: center; }

.appt-date    { font-family: 'JetBrains Mono'; font-size: 11px; color: var(--accent2); }
.appt-patient { font-weight: 600; color: var(--text); font-size: 13px; }
.appt-meta    { font-size: 11px; color: var(--text2); }
.appt-account { font-family: 'JetBrains Mono'; font-size: 10px; color: var(--text3); }
.appt-badge   { padding: 3px 8px; border-radius: 20px; font-size: 10px; font-weight: 600; }

/* ── Lab badge ───────────────────────────────────────────────── */
.lab-badge     { display: inline-flex; align-items: center; gap: 3px; padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: 700; letter-spacing: .3px; }
.lab-LDC1      { background: #1e3050; color: #7dd3fc; border: 1px solid #3b82f640; }
.lab-LDC2      { background: #2d1a3b; color: #c4b5fd; border: 1px solid #a855f740; }
.lab-LDC3      { background: #2d1a10; color: #fdba74; border: 1px solid #f9731640; }
.lab-LDC4      { background: #1a2d20; color: #6ee7b7; border: 1px solid #22c55e40; }

/* Status badges */
.status-programada { background: #1e3a5f; color: #60a5fa; }
.status-confirmada { background: #1a3b2e; color: #4ade80; }
.status-completada { background: #2a2a2a; color: #8b97ac; }
.status-cancelada  { background: #3b1515; color: #f87171; }
.status-no_show    { background: #2d1818; color: #fca5a5; }

/* ── Patients view ───────────────────────────────────────────── */
#patientsView { flex: 1; overflow-y: auto; display: none; flex-direction: column; }
.patients-table-wrap { flex: 1; overflow-x: auto; padding: 0 16px 80px; }
.patients-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.patients-table thead tr { background: var(--bg3); border-bottom: 2px solid var(--border2); }
.patients-table th { padding: 8px 12px; text-align: left; font-size: 10px; font-weight: 700; color: var(--text3); letter-spacing: .8px; text-transform: uppercase; white-space: nowrap; }
.patients-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text2); vertical-align: middle; }
.patients-table tbody tr { transition: background .15s; cursor: pointer; }
.patients-table tbody tr:hover td { background: var(--bg3); }
.td-account { font-family: 'JetBrains Mono'; font-size: 10px; color: var(--accent2); }
.td-name    { font-weight: 600; color: var(--text); }

/* Patient cards (mobile) */
.patient-cards { display: flex; flex-direction: column; gap: 10px; padding: 0 16px 80px; overflow-y: auto; }
.patient-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px; display: flex; flex-direction: column; gap: 8px;
}
.patient-card-header { display: flex; justify-content: space-between; align-items: flex-start; }
.patient-card-name { font-size: 15px; font-weight: 600; color: var(--text); }
.patient-card-account { font-family: 'JetBrains Mono'; font-size: 11px; color: var(--accent2); }
.patient-card-meta { font-size: 12px; color: var(--text2); display: flex; flex-wrap: wrap; gap: 8px; }
.patient-card-actions { display: flex; gap: 8px; padding-top: 4px; }
.pt-action-btns { display: flex; gap: 6px; }
.pt-btn { padding: 5px 10px; border-radius: 6px; font-size: 11px; font-weight: 500; cursor: pointer; border: 1px solid var(--border); background: var(--bg3); color: var(--text2); transition: all .15s; }
.pt-btn:hover { border-color: var(--accent); color: var(--accent); }
.pt-btn-schedule { padding: 5px 10px; border-radius: 6px; font-size: 11px; font-weight: 600; cursor: pointer; border: 1px solid var(--accent); background: var(--accent-glow); color: var(--accent); transition: all .15s; }
.pt-btn-schedule:hover { background: var(--accent); color: #fff; }

/* ── Nurses view ─────────────────────────────────────────────── */
#nursesView   { flex: 1; overflow-y: auto; display: none; flex-direction: column; padding-bottom: 80px; }
.nurses-grid  { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; padding: 0 16px; }
.nurse-card   { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; display: flex; flex-direction: column; gap: 8px; transition: border-color .2s; border-left-width: 4px; border-left-style: solid; }
.nurse-card:hover { border-color: var(--border2) !important; }
.nurse-card-header { display: flex; align-items: center; justify-content: space-between; }
.nurse-card-name   { font-size: 14px; font-weight: 600; color: var(--text); }
.nurse-card-type   { font-size: 9px; font-weight: 700; padding: 3px 7px; border-radius: 20px; text-transform: uppercase; letter-spacing: .5px; }
.type-enfermera    { background: #1a3b2e; color: #4ade80; }
.type-recogido     { background: #2d1a14; color: #fb923c; }
.nurse-card-color  { display: flex; align-items: center; gap: 8px; }
.nurse-color-swatch{ width: 24px; height: 24px; border-radius: 6px; border: 2px solid #ffffff20; }
.nurse-color-hex   { font-family: 'JetBrains Mono'; font-size: 11px; color: var(--text3); }
.nurse-card-actions{ display: flex; gap: 6px; }

/* ── Dashboard ───────────────────────────────────────────────── */
#dashboardView { flex: 1; overflow-y: auto; display: none; flex-direction: column; padding: 0 16px 80px; gap: 0; }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; padding-top: 4px; }
.kpi-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; position: relative; overflow: hidden; }
.kpi-card::before { content:''; position:absolute; top:0; left:0; right:0; height:3px; background:var(--kpi-color, var(--accent)); }
.kpi-icon  { font-size: 18px; }
.kpi-num   { font-size: 28px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 11px; color: var(--text2); }
.charts-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-bottom: 14px; }
.chart-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chart-card.chart-wide { grid-column: span 2; }
.chart-title { font-size: 12px; font-weight: 600; color: var(--text2); }

/* ── Export panel ────────────────────────────────────────────── */
.export-panel-backdrop { position: fixed; inset: 0; z-index: 60; background: transparent; display: none; }
.export-panel-backdrop.open { display: block; }
.export-panel { position: fixed; right: -420px; top: 0; bottom: 0; z-index: 65; width: 400px; background: var(--bg2); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; transition: right .3s cubic-bezier(.4,0,.2,1); }
.export-panel.open { right: 0; }
.export-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.export-header h3 { font-size: 15px; font-weight: 700; }
.export-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.export-preview { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-height: 80px; }
.preview-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.preview-row:last-child { border-bottom: none; }
.preview-nurse-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

/* ── Modal ───────────────────────────────────────────────────── */
/* ── Modal — DESKTOP: centered dialog ────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: #00000088; backdrop-filter: blur(4px);
  display: flex; align-items: center;       /* desktop: centered */
  justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
  padding: 20px;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-lg);          /* desktop: fully rounded */
  width: 100%; max-width: 680px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(.98);
  transition: transform .25s cubic-bezier(.4,0,.2,1), opacity .2s;
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.modal-wide { max-width: 860px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg2); z-index: 5;
}
/* No drag handle on desktop */
.modal-header::before { display: none; }
.modal-header h2 { font-family: 'DM Serif Display'; font-size: 20px; }
.close-btn { width: 32px; height: 32px; border-radius: 8px; background: var(--bg3); border: 1px solid var(--border); color: var(--text2); cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; transition: all .2s; }
.close-btn:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.modal-form { padding: 16px 20px; }
.form-grid  { display: flex; flex-direction: column; gap: 16px; }
.form-section-title { font-size: 11px; font-weight: 700; color: var(--accent2); letter-spacing: 1px; text-transform: uppercase; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.form-row   { display: flex; flex-wrap: wrap; gap: 10px; }
.form-group { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 120px; }
.form-group.full { flex: 1 1 100%; min-width: 0; }
.form-group-sm   { flex: 0 0 72px; min-width: 72px; }
.fg-05 { flex: 0 1 64px !important; min-width: 54px; }
.fg-1  { flex: 1 !important; }
.fg-2  { flex: 2 !important; }
label  { font-size: 11px; font-weight: 500; color: var(--text2); }
.req   { color: var(--danger); }

input, select, textarea {
  padding: 10px 12px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); font-size: 14px; font-family: inherit;
  outline: none; transition: border-color .2s; width: 100%;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--text3); }
textarea { resize: vertical; }
select { cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b97ac' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.field-hint { font-size: 10px; color: var(--text3); }

/* ── Maps row ────────────────────────────────────────────────── */
.maps-row { display: flex; gap: 8px; align-items: center; }
.btn-icon-sm { padding: 10px 14px; border-radius: 8px; background: var(--bg3); border: 1px solid var(--border); color: var(--text2); font-size: 16px; cursor: pointer; transition: all .2s; flex-shrink: 0; }
.btn-icon-sm:hover { border-color: var(--accent); color: var(--accent); }

/* ── Nurse selector ──────────────────────────────────────────── */
.nurse-select-wrap { position: relative; }
.nurse-select-indicator { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 10px; height: 10px; border-radius: 50%; pointer-events: none; transition: background .2s; }
.nurse-select-wrap select { padding-left: 28px; }

/* ── Lab destination ─────────────────────────────────────────── */
.lab-dest-group { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.lab-dest-btn { padding: 10px 4px; border-radius: 8px; border: 2px solid var(--border); background: var(--bg3); color: var(--text2); font-size: 13px; font-weight: 600; cursor: pointer; transition: all .2s; text-align: center; }
.lab-dest-btn:hover          { border-color: var(--border2); color: var(--text); }
.lab-dest-btn.active-ldc1    { background: #1e3050; border-color: #3b82f6; color: #7dd3fc; }
.lab-dest-btn.active-ldc2    { background: #2d1a3b; border-color: #a855f7; color: #c4b5fd; }
.lab-dest-btn.active-ldc3    { background: #2d1a10; border-color: #f97316; color: #fdba74; }
.lab-dest-btn.active-ldc4    { background: #1a2d20; border-color: #22c55e; color: #6ee7b7; }

/* ── Lab tags ────────────────────────────────────────────────── */
.lab-input-wrap { display: flex; gap: 8px; }
.lab-add-btn { padding: 10px 14px; border-radius: 8px; background: var(--accent); border: none; color: #fff; font-size: 18px; cursor: pointer; flex-shrink: 0; }
.lab-tags    { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.lab-tag     { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 20px; background: #1e3a5f; color: #60a5fa; font-size: 11px; font-weight: 500; }
.lab-tag-remove { background: none; border: none; color: inherit; cursor: pointer; font-size: 12px; opacity: .6; line-height: 1; padding: 0; }
.lab-tag-remove:hover { opacity: 1; }

/* ── Save patient checkbox ───────────────────────────────────── */
.save-patient-check { display: inline-flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 8px; background: var(--bg3); border: 1px solid var(--border); color: var(--text2); font-size: 12px; font-weight: 500; cursor: pointer; transition: all .2s; width: 100%; user-select: none; }
.save-patient-check:hover { border-color: var(--success); color: var(--success); }
.save-patient-check input[type=checkbox] { display: none; }
.check-indicator { width: 16px; height: 16px; border-radius: 4px; flex-shrink: 0; border: 2px solid var(--border2); background: var(--bg); display: flex; align-items: center; justify-content: center; transition: all .15s; }
.save-patient-check input:checked + .check-indicator { background: var(--success); border-color: var(--success); }
.save-patient-check input:checked + .check-indicator::after { content: '✓'; font-size: 10px; color: #fff; font-weight: 700; }

/* ── New patient demog ───────────────────────────────────────── */
#newPatientDemog { background: var(--bg3); border: 1px solid #1a3b2e; border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; animation: slideDown .2s ease; }
@keyframes slideDown { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:translateY(0); } }
.demog-section-mini { font-size: 10px; font-weight: 700; color: var(--success); letter-spacing: .8px; text-transform: uppercase; padding: 6px 0 2px; border-bottom: 1px solid #1a3b2e; }

/* ── Past date warning ───────────────────────────────────────── */
.past-date-warn { font-size: 11px; color: var(--danger); display: none; margin-top: 3px; }

/* ── Form actions ────────────────────────────────────────────── */
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 16px; border-top: 1px solid var(--border); margin-top: 4px; padding-bottom: env(safe-area-inset-bottom, 0px); }
.btn-primary   { padding: 11px 20px; border-radius: 8px; background: var(--accent); border: none; color: #fff; font-size: 14px; font-weight: 600; cursor: pointer; transition: background .2s; flex: 1; }
.btn-primary:hover { background: #2563eb; }
.btn-secondary { padding: 11px 16px; border-radius: 8px; background: var(--bg3); border: 1px solid var(--border); color: var(--text2); font-size: 14px; cursor: pointer; transition: all .2s; }
.btn-secondary:hover { color: var(--text); border-color: var(--border2); }
.btn-danger    { padding: 11px 14px; border-radius: 8px; background: #3b1515; border: 1px solid var(--danger); color: var(--danger); font-size: 14px; cursor: pointer; transition: all .2s; }
.btn-danger:hover { background: var(--danger); color: #fff; }

/* ── Detail panel ────────────────────────────────────────────── */
.detail-backdrop { position: fixed; inset: 0; z-index: 50; background: transparent; display: none; }
.detail-backdrop.open { display: block; }
.detail-panel {
  position: fixed; right: -420px; top: 0; bottom: 0; z-index: 55;
  width: 400px; max-width: 100vw;
  background: var(--bg2); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transition: right .3s cubic-bezier(.4,0,.2,1); overflow-y: auto;
}
.detail-panel.open { right: 0; }
.detail-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; flex-shrink: 0; }
.detail-category-badge { padding: 4px 12px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.detail-body { flex: 1; padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.detail-section { display: flex; flex-direction: column; gap: 8px; }
.detail-section-title { font-size: 10px; font-weight: 700; color: var(--accent2); letter-spacing: 1px; text-transform: uppercase; border-bottom: 1px solid var(--border); padding-bottom: 5px; }
.detail-row   { display: flex; flex-direction: column; gap: 2px; }
.detail-label { font-size: 10px; color: var(--text3); font-weight: 500; }
.detail-value { font-size: 13px; color: var(--text); }
.detail-value.mono { font-family: 'JetBrains Mono'; font-size: 12px; color: var(--accent2); }
.detail-nurse-pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 8px; font-size: 12px; font-weight: 600; }
.detail-actions { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); flex-shrink: 0; padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
.detail-actions .btn-primary, .detail-actions .btn-secondary { flex: 1; text-align: center; }
.map-btn { padding: 8px 12px; border-radius: 8px; background: var(--bg3); border: 1px solid var(--border); color: var(--text2); font-size: 12px; cursor: pointer; transition: all .2s; width: 100%; text-align: center; display: block; }
.map-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Mobile bottom nav ───────────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  background: var(--bg2); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-nav-inner {
  display: flex; align-items: center; justify-content: space-around;
  height: var(--bottom-nav-h);
}
.bnav-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; flex: 1; height: 100%;
  background: none; border: none; color: var(--text3);
  font-size: 10px; font-weight: 500; cursor: pointer;
  transition: color .2s; -webkit-tap-highlight-color: transparent;
  min-width: 0;
}
.bnav-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.bnav-btn.active { color: var(--accent); }
.bnav-btn.bnav-add {
  background: var(--accent); border-radius: 50%;
  width: 48px; height: 48px; flex: 0 0 48px;
  color: #fff; margin: 0 8px; box-shadow: 0 4px 16px var(--accent-glow);
}
.bnav-btn.bnav-add svg { width: 26px; height: 26px; stroke-width: 2.5; }
.bnav-btn span { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 56px; }

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 48px 24px; color: var(--text3); text-align: center; }
.empty-icon  { font-size: 36px; opacity: .4; }
.empty-state p { font-size: 13px; }

/* ── Misc helpers ────────────────────────────────────────────── */
.desktop-only { display: block; }
.mobile-only  { display: none; }
.gender-m { color: #60a5fa; }
.gender-f { color: #f472b6; }
.gender-o { color: var(--text3); }

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ================================================================
   TABLET  (≤ 1024px)
================================================================ */
@media (max-width: 1024px) {
  :root { --sidebar-w: 200px; }
  .chart-card.chart-wide { grid-column: span 1; }
}

/* ================================================================
   MOBILE  (≤ 768px)  — full responsive overhaul
================================================================ */
@media (max-width: 768px) {
  /* Show mobile chrome, hide desktop chrome */
  .mobile-topbar  { display: flex; }
  .bottom-nav     { display: flex; flex-direction: column; }

  /* Sidebar becomes a drawer */
  .sidebar {
    transform: translateX(-110%);
    width: 280px;
    padding-top: env(safe-area-inset-top, 0);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open   { transform: translateX(0); }
  .sidebar-close  { display: block; }

  /* Main fills full width */
  .main {
    margin-left: 0;
    padding-top: var(--mobile-topbar-h);
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
    height: 100dvh;
  }

  /* Hide desktop top bar */
  .top-bar { display: none !important; }
  /* Mobile cal nav: shown by JS via .cal-active class on body, not always */
  body.cal-active .mobile-cal-nav { display: flex !important; }
  .mobile-cal-nav { display: none !important; }

  /* Calendar adjustments */
  .weekdays-header { padding: 0 8px; }
  .calendar-grid   { padding: 0 8px 8px; gap: 3px; }
  .day-cell        { min-height: 66px; padding: 4px; }
  .day-number      { width: 22px; height: 22px; font-size: 11px; }
  .event-pill      { font-size: 9px; padding: 2px 5px 2px 6px; }

  /* List uses cards on mobile */
  .appt-row { display: none !important; }

  /* Sections */
  #listView      { padding: 0; }
  #patientsView  { padding: 0; }
  #dashboardView { padding: 0 12px 80px; }
  #nursesView    { padding: 0 0 80px; }

  /* Patient table → cards */
  .desktop-only { display: none !important; }
  .mobile-only  { display: block !important; }

  /* Modal becomes a full bottom sheet on mobile */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 95dvh; max-width: 100%;
    transform: translateY(40px);
  }
  .modal-overlay.open .modal { transform: translateY(0); }
  .modal-wide { max-width: 100%; }
  /* Drag handle on mobile */
  .modal-header::before {
    display: block;
    content: '';
    position: absolute;
    top: 8px; left: 50%; transform: translateX(-50%);
    width: 36px; height: 4px; border-radius: 2px;
    background: var(--border2);
  }

  /* Form rows stack on mobile */
  .form-row { flex-direction: column; }
  .form-group { min-width: 0; }
  .fg-05, .fg-1, .fg-2 { flex: 1 !important; }
  /* Keep these narrow */
  .form-group-sm { flex: 0 0 72px !important; }

  /* Lab buttons 2x2 on mobile */
  .lab-dest-group { grid-template-columns: 1fr 1fr; }

  /* Export panel full screen on mobile */
  .export-panel { width: 100%; right: -100%; }
  .export-panel.open { right: 0; }

  /* Detail panel full screen on mobile */
  .detail-panel { width: 100%; right: -100%; }
  .detail-panel.open { right: 0; }
  /* On mobile the bottom nav (60px) overlays the action buttons — push them up */
  .detail-panel .detail-actions {
    padding-bottom: calc(var(--bottom-nav-h) + 14px + env(safe-area-inset-bottom, 0px));
  }

  /* KPIs 2 per row on mobile */
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .kpi-num { font-size: 22px; }

  /* Charts single column */
  .charts-row { grid-template-columns: 1fr; }
  .chart-card.chart-wide { grid-column: span 1; }

  /* Nurses grid */
  .nurses-grid { grid-template-columns: 1fr; }

  /* Appointment list header */
  .list-header { padding: 10px 12px; }
  .appointment-list { padding: 0 12px 80px; gap: 10px; }

  /* Patient cards */
  .patient-cards { padding: 0 12px 80px; }

  /* Section header */
  .section-header { padding: 12px 16px 8px; }
  .section-title  { font-size: 18px; }
}

/* ================================================================
   SMALL MOBILE  (≤ 390px)
================================================================ */
@media (max-width: 390px) {
  .kpi-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi-num { font-size: 20px; }
  .lab-dest-btn { font-size: 11px; padding: 9px 2px; }
}

/* ===== v11 ADDITIONS ===== */
.sidebar-divider { height:1px; background:var(--border); margin:8px 12px; }
.nav-btn-sm { font-size:12px; padding:7px 12px; opacity:.8; }
.nav-btn-sm:hover { opacity:1; }

/* List date filters */
.filter-row input[type=date].cat-filter { color:var(--text); }

/* Project table */
.proj-num-badge { font-family:'JetBrains Mono'; font-size:12px; font-weight:700; color:var(--accent2); padding:2px 8px; background:var(--bg3); border-radius:6px; }

/* ===== v11 FIXES ===== */

/* Print button */
.list-top-row { display: flex; gap: 8px; align-items: center; }
.btn-print {
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: all .2s; flex-shrink: 0;
}
.btn-print:hover { border-color: var(--accent); color: var(--accent); }

/* Patient filter bar */
.patients-filter-bar {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 16px 10px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* Desktop form improvements */
@media (min-width: 769px) {
  /* Form rows stay horizontal on desktop */
  .form-row { flex-direction: row !important; }
  .fg-05 { flex: 0 1 72px !important; min-width: 64px; }
  .fg-1  { flex: 1 !important; }
  .fg-2  { flex: 2 !important; }
  .form-group-sm { flex: 0 0 80px !important; }

  /* Lab buttons stay in 1 row */
  .lab-dest-group { grid-template-columns: repeat(4, 1fr) !important; }
}

/* Print styles */
@media print {
  .sidebar, .top-bar, .mobile-topbar, .bottom-nav,
  .list-header, .detail-panel, .modal-overlay,
  .export-panel, .export-panel-backdrop { display: none !important; }

  .main { margin-left: 0 !important; }
  #listView { display: block !important; overflow: visible !important; }
  .appointment-list { overflow: visible !important; }

  .appt-row {
    display: grid !important;
    border: 1px solid #ddd !important;
    border-left: 4px solid #000 !important;
    break-inside: avoid;
    margin-bottom: 4px;
    background: white !important;
    color: black !important;
  }
  .appt-patient, .appt-date, .appt-meta, .appt-account { color: black !important; }
  .appt-badge { border: 1px solid #ccc !important; color: black !important; background: #f5f5f5 !important; }
  .lab-badge { border: 1px solid #ccc !important; color: black !important; background: #f5f5f5 !important; }
  .appt-card { display: none !important; }

  /* Print header added by JS */
  #printHeader { display: block !important; margin-bottom: 12px; font-family: sans-serif; }
}
#printHeader { display: none; }

/* ================================================================
   DEFINITIVE LAYOUT FIXES
================================================================ */

/* All section views must stack vertically */
#calendarView, #listView, #patientsView,
#nursesView, #projectsView {
  flex-direction: column !important;
  overflow-y: auto;
}

/* Projects view full-width layout */
#projectsView {
  flex: 1;
  overflow-y: auto;
}
#projectsView .patients-table-wrap {
  flex: 1;
  overflow-x: auto;
  padding: 0 16px 80px;
}

/* Week/Day view: override grid so content fills full width */
.calendar-grid.week-mode,
.calendar-grid.day-mode {
  display: block !important;
  padding: 0 !important;
  overflow: hidden !important;
  height: 100%;
}
.calendar-grid.week-mode > div,
.calendar-grid.day-mode > div {
  height: 100%;
}

/* ================================================================
   LAB PICKER + HOY BUTTON
================================================================ */

/* Hoy button */
.btn-today-list {
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--accent-glow); border: 1px solid var(--accent);
  color: var(--accent); font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: all .2s; flex-shrink: 0;
}
.btn-today-list:hover  { background: var(--accent); color: #fff; }
.btn-today-list.active { background: var(--accent); color: #fff; }

/* Lab picker wrapper */
.lab-picker-wrap { position: relative; }

.lab-picker-search-row {
  display: flex; gap: 8px; align-items: center;
}
.lab-picker-search {
  flex: 1; padding: 10px 12px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); font-size: 13px; font-family: inherit;
  outline: none; transition: border-color .2s;
}
.lab-picker-search:focus { border-color: var(--accent); }

.lab-picker-toggle {
  padding: 10px 14px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: all .2s; flex-shrink: 0;
}
.lab-picker-toggle:hover { border-color: var(--accent2); color: var(--accent2); }

/* Dropdown panel — relative inside the modal, not fixed */
.lab-picker-panel {
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--radius);
  overflow: hidden;
  max-height: 320px; display: flex; flex-direction: column;
  margin-top: 6px;
  width: 100%;
}

.lab-picker-cats {
  flex: 1; overflow-y: auto; padding: 8px;
}

/* Category group */
.lab-cat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px 4px;
  font-size: 10px; font-weight: 700; color: var(--accent2);
  letter-spacing: .8px; text-transform: uppercase;
  cursor: pointer; border-radius: 6px; transition: background .15s;
  position: sticky; top: 0; background: var(--bg2); z-index: 1;
}
.lab-cat-header:hover { background: var(--bg3); }
.lab-cat-body { display: flex; flex-wrap: wrap; gap: 5px; padding: 4px 6px 8px; border-bottom: 1px solid var(--border); }
.lab-cat-body.hidden { display: none; }

/* Individual lab chip */
.lab-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 20px; cursor: pointer;
  border: 1.5px solid var(--border); background: var(--bg3);
  font-size: 11px; font-weight: 700; color: var(--text2);
  transition: all .15s; font-family: 'JetBrains Mono', monospace;
  user-select: none;
}
.lab-chip:hover   { border-color: var(--accent2); color: var(--accent2); background: #011520; }
.lab-chip.selected { border-color: var(--accent); background: var(--accent-glow); color: var(--accent); }
.lab-chip .lab-chip-name { font-family:'DM Sans',sans-serif; font-size:10px; font-weight:400; color:inherit; opacity:.8; }

/* Footer */
.lab-picker-footer {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--border); background: var(--bg2);
  flex-shrink: 0;
}

/* Lab code badge in tags */
.lab-tag { font-family: 'JetBrains Mono', monospace; font-size: 11px; }
.lab-tag-name { font-family: 'DM Sans', sans-serif; font-size: 10px; opacity: .8; }

/* Lab tests table code cell */
.td-code { font-family: 'JetBrains Mono'; font-size: 12px; font-weight: 700; color: var(--accent2); }
.cat-badge {
  padding: 2px 8px; border-radius: 20px; font-size: 10px; font-weight: 600;
  background: var(--bg3); border: 1px solid var(--border); color: var(--text2);
}

/* ================================================================
   FIX: Lab Tests view layout + Mobile modal buttons + Notes
================================================================ */

/* Lab Tests view — needs explicit flex column with proper height */
#labtestsView {
  flex: 1;
  overflow: hidden;
  display: none;
  flex-direction: column !important;
  min-height: 0;
}
#labtestsView .patients-filter-bar,
#labtestsView .section-header { flex-shrink: 0; }
#labtestsView .patients-table-wrap,
#labtestsView .patient-cards { flex: 1; overflow-y: auto; }

/* All other section views need the same fix */
#projectsView { flex: 1; overflow: hidden; display: none; flex-direction: column !important; min-height: 0; }
#projectsView .section-header,
#projectsView .list-header { flex-shrink: 0; }
#projectsView .patients-table-wrap,
#projectsView .patient-cards { flex: 1; overflow-y: auto; }

#patientsView { flex: 1; overflow: hidden; display: none; flex-direction: column !important; min-height: 0; }
#patientsView .section-header,
#patientsView .patients-filter-bar { flex-shrink: 0; }
#patientsView .patients-table-wrap,
#patientsView .patient-cards { flex: 1; overflow-y: auto; }

#nursesView { flex: 1; overflow: hidden; display: none; flex-direction: column !important; min-height: 0; }
#nursesView .section-header { flex-shrink: 0; }
#nursesView .nurses-grid { flex: 1; overflow-y: auto; }

#listView { flex: 1; overflow: hidden; display: none; flex-direction: column !important; min-height: 0; }
#listView .list-header { flex-shrink: 0; }
#listView .appointment-list { flex: 1; overflow-y: auto; }

/* Mobile: form-actions must clear bottom nav */
@media (max-width: 768px) {
  .form-actions {
    padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + 8px) !important;
    position: sticky;
    bottom: 0;
    background: var(--bg2);
    z-index: 5;
    border-top: 1px solid var(--border);
    margin-top: 0;
  }
  /* Lab tests padding on mobile */
  #labtestsView .patient-cards { padding-bottom: calc(var(--bottom-nav-h) + 20px); }
  #projectsView .patient-cards { padding-bottom: calc(var(--bottom-nav-h) + 20px); }
}

/* Patient notes textarea */
.patient-notes-field { min-height: 80px; resize: vertical; }

/* Patient notes */
.patient-notes-list { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow-y: auto; }
.patient-note-item {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; display: flex; flex-direction: column; gap: 4px;
}
.patient-note-text  { font-size: 13px; color: var(--text); white-space: pre-wrap; }
.patient-note-meta  { font-size: 10px; color: var(--text3); display: flex; justify-content: space-between; }
.patient-note-del   { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 12px; }
.patient-note-del:hover { color: var(--danger); }

/* Lista citas — labs badge row */
.appt-labs-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.appt-lab-code {
  padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: 700;
  background: var(--bg3); border: 1px solid var(--border2);
  color: var(--accent2); font-family: 'JetBrains Mono', monospace;
}

/* ── List desktop column header ─────────────────────────────── */
.appt-list-header {
  display: grid;
  grid-template-columns: 100px 180px 1fr 80px 1fr 90px;
  gap: 8px;
  padding: 6px 12px 6px 16px;
  font-size: 10px; font-weight: 700; color: var(--text3);
  text-transform: uppercase; letter-spacing: .6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg2);
}

/* Patient modal tabs */
.pat-tab-btn {
  padding: 6px 14px; border-radius: 6px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); background: var(--bg3); color: var(--text2);
  cursor: pointer; transition: all .15s;
}
.pat-tab-btn.active {
  background: var(--accent-glow); border-color: var(--accent); color: var(--accent);
}
.pat-tab-btn:hover:not(.active) { border-color: var(--border2); }

/* Patient history items */
.pat-hist-item {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  border-left: 3px solid var(--border2);
  display: flex; flex-direction: column; gap: 4px;
}
.pat-hist-date   { font-family:'JetBrains Mono'; font-size:11px; font-weight:700; color:var(--accent2); }
.pat-hist-nurse  { font-size:11px; color:var(--text2); }
.pat-hist-labs   { display:flex; flex-wrap:wrap; gap:3px; margin-top:2px; }
.pat-hist-status { font-size:10px; font-weight:600; }

/* ================================================================
   v12 NEW FEATURES
================================================================ */

/* Fasting toggle switch */
.fasting-toggle { position:relative; display:inline-block; width:44px; height:24px; cursor:pointer; }
.fasting-toggle input { opacity:0; width:0; height:0; }
.fasting-slider { position:absolute; inset:0; border-radius:34px; background:var(--bg3); border:1px solid var(--border); transition:.3s; }
.fasting-slider::before { content:''; position:absolute; width:18px; height:18px; left:2px; bottom:2px; background:var(--text3); border-radius:50%; transition:.3s; }
.fasting-toggle input:checked + .fasting-slider { background:var(--warning); border-color:var(--warning); }
.fasting-toggle input:checked + .fasting-slider::before { transform:translateX(20px); background:#fff; }

/* Fasting badge in list */
.fasting-badge { padding:2px 7px; border-radius:20px; font-size:10px; font-weight:700; background:#92400e22; border:1px solid #92400e66; color:#f59e0b; }

/* Appointment change reason */
#changeReasonWrap { background:var(--bg3); border:1px solid var(--warning); border-radius:8px; padding:10px 12px; margin-top:4px; }

/* Appointment history items */
.appt-hist-change {
  display:flex; flex-direction:column; gap:2px;
  padding:7px 10px; border-radius:6px;
  background:var(--bg3); border-left:3px solid var(--accent2);
  font-size:11px;
}
.appt-hist-change-field { font-weight:700; color:var(--accent2); font-family:'JetBrains Mono'; }
.appt-hist-change-values { color:var(--text2); }
.appt-hist-change-meta { color:var(--text3); font-size:10px; }

/* Quick status select in list */
.quick-status-sel {
  padding:3px 6px; border-radius:20px; font-size:10px; font-weight:600;
  border:1px solid var(--border); background:var(--bg3); color:var(--text2);
  cursor:pointer; outline:none; appearance:none; -webkit-appearance:none;
  padding-right:18px;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238b97ac'/%3E%3C/svg%3E");
  background-repeat:no-repeat; background-position:right 5px center;
}
.quick-status-sel:focus { border-color:var(--accent); }

/* Global search overlay */
.gsearch-overlay {
  position:fixed; inset:0; z-index:500;
  background:#000000bb; backdrop-filter:blur(6px);
  display:none; align-items:flex-start; justify-content:center;
  padding-top:10vh;
}
.gsearch-overlay.open { display:flex; }
.gsearch-box {
  background:var(--bg2); border:1px solid var(--border2);
  border-radius:var(--radius-lg); width:min(640px,94vw);
  box-shadow:0 24px 80px #0009;
  display:flex; flex-direction:column; overflow:hidden;
  max-height:80vh;
}
.gsearch-input-row {
  display:flex; align-items:center; gap:10px;
  padding:14px 16px; border-bottom:1px solid var(--border);
}
.gsearch-input {
  flex:1; background:none; border:none; outline:none;
  font-size:16px; color:var(--text); font-family:inherit;
}
.gsearch-results { overflow-y:auto; flex:1; padding:8px; max-height:60vh; }
.gsearch-hint { color:var(--text3); font-size:12px; padding:16px; text-align:center; }
.gsearch-section-title { font-size:10px; font-weight:700; color:var(--text3); letter-spacing:.8px; text-transform:uppercase; padding:8px 8px 4px; }
.gsearch-item {
  display:flex; align-items:center; gap:10px; padding:9px 10px; border-radius:8px;
  cursor:pointer; transition:background .15s; color:var(--text);
}
.gsearch-item:hover { background:var(--bg3); }
.gsearch-item-icon { font-size:14px; flex-shrink:0; width:24px; text-align:center; }
.gsearch-item-main { flex:1; overflow:hidden; }
.gsearch-item-name { font-weight:600; font-size:13px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.gsearch-item-sub  { font-size:11px; color:var(--text2); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.gsearch-empty { color:var(--text3); font-size:12px; padding:24px; text-align:center; }

/* Same address checkbox */
.same-addr-label {
  display: inline-flex; align-items: center; gap: 5px;
  margin-left: 10px; font-size: 12px; font-weight: 500;
  color: var(--accent2); cursor: pointer; vertical-align: middle;
}
.same-addr-label input[type="checkbox"] { cursor: pointer; width: 14px; height: 14px; }
#physicalAddrFields.locked input { opacity: .45; pointer-events: none; background: var(--bg3); }

/* ================================================================
   v13 — Visits & Audit views
================================================================ */
#visitsView, #auditView {
  flex: 1; overflow: hidden; display: none;
  flex-direction: column !important; min-height: 0;
}
#visitsView .section-header,
#visitsView .patients-filter-bar,
#auditView .section-header,
#auditView .patients-filter-bar { flex-shrink: 0; }
#visitsView .patients-table-wrap,
#visitsView .patient-cards,
#auditView .patients-table-wrap,
#auditView .patient-cards { flex: 1; overflow-y: auto; }
#auditPager { flex-shrink: 0; }

/* Audit action badges */
.audit-insert { color: #22c55e; font-weight: 700; }
.audit-update { color: #58a6ff; font-weight: 700; }
.audit-delete { color: #f85149; font-weight: 700; }

/* Visit result status */
.vr-pendiente { color: #e3b341; font-weight: 700; }
.vr-recibido  { color: #22c55e; font-weight: 700; }
.vr-rechazado { color: #f85149; font-weight: 700; }

/* Export modal overlay already uses .modal-overlay */
#exportModalOverlay .modal { max-width: 520px; }

/* ================================================================
   v14 — Auth: role-based visibility
================================================================ */
/* Hidden by JS when role restrictions apply */
.auth-admin-only   { display: none !important; }
.auth-recepcion-up { display: none !important; }
.auth-carrero-only { display: none !important; }

/* Shown after JS applies role class to body */
body.role-admin    .auth-admin-only    { display: revert !important; }
body.role-admin    .auth-recepcion-up  { display: revert !important; }
body.role-recepcion .auth-recepcion-up { display: revert !important; }
body.role-carrero  .auth-carrero-only  { display: revert !important; }

/* ================================================================
   v15 — Same-address improved visuals
================================================================ */
.same-addr-label {
  cursor: pointer; font-size: 12px; font-weight: 600;
  color: var(--text3); display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 8px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--bg3); transition: all .2s;
}
.same-addr-label:hover { color: var(--accent); border-color: var(--accent); }
.same-addr-label input[type="checkbox"] { display: none; }
/* When checked — highlight the label */
.same-addr-label:has(input:checked) {
  color: var(--accent2); border-color: var(--accent2);
  background: #22c55e18; font-weight: 700;
}
.same-addr-label::before { content: '☐'; font-size: 14px; }
.same-addr-label:has(input:checked)::before { content: '☑'; }

#physicalAddrFields.locked input,
#physicalAddrFields2.locked input {
  opacity: .4; pointer-events: none; background: var(--bg3);
  border-style: dashed;
}

/* Ayuna row in LABs section */
.fasting-row-banner {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 14px; margin-bottom: 6px;
  transition: border-color .2s, background .2s;
}
.fasting-row-banner:has(input:checked) {
  border-color: var(--warning); background: #f59e0b12;
}

/* ================================================================
   v15 — Personal view tabs
================================================================ */
.personal-tab {
  padding: 10px 18px; font-size: 13px; font-weight: 600;
  background: none; border: none; border-bottom: 3px solid transparent;
  color: var(--text3); cursor: pointer; transition: all .2s;
  margin-bottom: -2px;
}
.personal-tab:hover  { color: var(--text); }
.personal-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
#tab-nurses-pane, #tab-users-pane {
  display: flex; flex-direction: column; flex: 1; overflow: hidden; min-height: 0;
}
