*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #eef2f7;
  --surface:     #ffffff;
  --border:      #dde3ec;
  --primary:     #2563eb;
  --primary-end: #7c3aed;
  --primary-h:   #1d4ed8;
  --danger:      #dc2626;
  --success:     #059669;
  --warn-bg:     #fffbeb;
  --warn-bd:     #f59e0b;
  --text:        #0f172a;
  --muted:       #64748b;
  --header-h:    56px;
  --tab-h:       44px;
  --radius:      8px;
  --shadow-sm:   0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.06);
  --shadow-md:   0 4px 16px rgba(15,23,42,.10), 0 2px 6px rgba(15,23,42,.08);
  --grad-primary: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  --grad-header:  linear-gradient(135deg, #0f172a 0%, #1e3a5f 60%, #2e1065 100%);
  --font-base:   14px;
}

[data-theme="dark"] {
  --bg:       #0f172a;
  --surface:  #1e293b;
  --border:   #334155;
  --text:     #f1f5f9;
  --muted:    #94a3b8;
  --warn-bg:  #451a03;
  --warn-bd:  #d97706;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,.5), 0 2px 6px rgba(0,0,0,.4);
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: var(--font-base, 14px);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--grad-header);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 12px;
  box-shadow: 0 2px 12px rgba(15,23,42,.25);
}

.app-header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: .03em;
  background: var(--grad-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.app-header-brand span { -webkit-text-fill-color: #fff; background: none; }

.app-header-left { display: flex; align-items: center; gap: 14px; }

.back-link {
  color: #94a3b8;
  text-decoration: none;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color .15s;
}
.back-link:hover { color: #fff; }

.patient-name {
  font-weight: 700;
  font-size: 15px;
  color: #f1f5f9;
}

.btn-ghost {
  background: transparent;
  border: 1px solid rgba(255,255,255,.25);
  color: #e2e8f0;
  padding: 5px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, border-color .15s;
}
.btn-ghost:hover {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.4);
  color: #fff;
}

/* Header on trips page */
.trips-header-title {
  font-size: 17px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: .02em;
}

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  height: var(--tab-h);
  gap: 2px;
  padding: 0 8px;
  box-shadow: var(--shadow-sm);
}

.tab {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 100%;
  text-decoration: none;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  border-radius: 4px 4px 0 0;
  transition: color .15s, background .15s;
}
.tab:hover { color: var(--text); background: rgba(37,99,235,.06); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: rgba(37,99,235,.06);
  font-weight: 600;
}
/* ── Save banner ─────────────────────────────────────────────────────────── */
.save-banner {
  background: linear-gradient(90deg, #d1fae5 0%, #a7f3d0 100%);
  color: var(--success);
  text-align: center;
  padding: 9px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid #6ee7b7;
  letter-spacing: .01em;
}

/* ── Alert ───────────────────────────────────────────────────────────────── */
.alert-warn {
  background: var(--warn-bg);
  border: 1px solid var(--warn-bd);
  border-left: 4px solid var(--warn-bd);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 16px;
  font-weight: 600;
  font-size: 13px;
  color: #92400e;
}

.save-ok {
  color: var(--success);
  font-weight: 700;
  margin-left: 10px;
  font-size: 13px;
}

/* ── Page content ────────────────────────────────────────────────────────── */
.section-content {
  max-width: 1100px;
  margin: 0 auto;
  overflow-x: hidden;   /* swipe viewport — panels live here */
}

/* ── Swipe track ─────────────────────────────────────────────────────────── */
#swipe-track {
  display: flex;
  /* transition injected by JS — none at load to prevent flash */
}
.swipe-panel {
  min-width: 100%;
  padding: 24px 20px 48px;
  box-sizing: border-box;
}

.page-content {
  max-width: 1000px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  padding: 20px 24px;
}

/* ── Forms ───────────────────────────────────────────────────────────────── */
.pcr-form { display: flex; flex-direction: column; gap: 20px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.form-grid label input,
.form-grid label select,
.form-grid label textarea {
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  padding: 8px 11px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  width: 100%;
  text-transform: none;
  letter-spacing: 0;
  transition: border-color .15s, box-shadow .15s;
}
.form-grid label textarea { resize: vertical; }

.form-grid label input:focus,
.form-grid label select:focus,
.form-grid label textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.14);
}

fieldset {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
legend {
  font-weight: 800;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 0 8px;
  color: var(--text);
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-end) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.inline-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
}

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

/* ── Two-column layout ───────────────────────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }

/* ── Assessment groups ───────────────────────────────────────────────────── */
.assess-group { margin-bottom: 4px; }

.check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 24px;
  padding-top: 10px;
}

.num-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
}
.num-field input {
  width: 66px;
  padding: 5px 8px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.num-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.14);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--grad-primary);
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  align-self: flex-start;
  letter-spacing: .02em;
  box-shadow: 0 2px 8px rgba(37,99,235,.30);
  transition: opacity .15s, transform .1s, box-shadow .15s;
}
.btn-primary:hover {
  opacity: .92;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(37,99,235,.36);
}
.btn-primary:active { transform: translateY(0); opacity: 1; }

.btn-delete {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s, border-color .15s;
}
.btn-delete:hover {
  background: #fef2f2;
  border-color: var(--danger);
  color: var(--danger);
}

.form-actions { display: flex; align-items: center; gap: 12px; margin-top: 4px; }

/* ── Log tables ──────────────────────────────────────────────────────────── */
.log-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.log-table th {
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 700;
  color: var(--muted);
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1.5px solid var(--border);
}
.log-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 14px;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: 0;
}
.log-table td:first-child,
.log-table td:nth-child(2),
.log-table td:last-child {
  max-width: none;
  white-space: nowrap;
  width: 1%;
}
.log-table tbody tr:hover { background: rgba(37,99,235,.03); }
.log-table tr:last-child td { border-bottom: none; }

/* ── Dropoff checklist ───────────────────────────────────────────────────── */
.dropoff-items {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 28px;
  padding-top: 10px;
}

.dropoff-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reveal-field label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.reveal-field label input {
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  width: 180px;
  text-transform: none;
  letter-spacing: 0;
  transition: border-color .15s, box-shadow .15s;
}

.reveal-field label input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.14);
}

.vitals-scroll { overflow-x: auto; }
.vitals-table  { min-width: 900px; }

/* ── Add forms ───────────────────────────────────────────────────────────── */
.add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.add-form input,
.add-form textarea {
  padding: 8px 11px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.add-form input:focus,
.add-form textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.14);
  background: var(--surface);
}
.textarea-wrap {
  position: relative;
  flex: 1 1 300px;
  display: flex;
  flex-direction: column;
}
.textarea-wrap textarea {
  width: 100%;
  box-sizing: border-box;
}
.char-counter {
  position: absolute;
  bottom: 6px;
  right: 10px;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
  transition: color .15s;
}
.textarea-wrap textarea:focus ~ .char-counter { color: var(--text); }
.char-near-limit { color: #d97706 !important; }
.char-at-limit   { color: #dc2626 !important; }

.vitals-add-form { flex-direction: column; gap: 10px; align-items: stretch; }
.vitals-row-dt { display: flex; gap: 10px; flex-wrap: wrap; }
.vitals-row-fields { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.vitals-field-label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 10px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.vitals-row-dt .vitals-field-label input { width: 160px; }
.vitals-row-fields .vitals-field-label input { width: 72px; }

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--grad-header);
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 0;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(15,23,42,.4);
  overflow: hidden;
}

.login-card-header {
  background: var(--grad-primary);
  padding: 32px 32px 24px;
  text-align: center;
}

.login-card-header h1 {
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  letter-spacing: .01em;
}

.login-card-header p {
  color: rgba(255,255,255,.75);
  font-size: 13px;
  margin-top: 4px;
}

.login-card-body {
  padding: 28px 32px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-card-body label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.login-card-body input {
  font-size: 14px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.login-card-body input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.14);
}

.login-card-body button {
  width: 100%;
  padding: 11px;
  background: var(--grad-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(37,99,235,.30);
  transition: opacity .15s, transform .1s;
  margin-top: 4px;
}
.login-card-body button:hover { opacity: .9; transform: translateY(-1px); }
.login-card-body button:active { transform: translateY(0); }

.error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 8px 12px;
}

/* ── Search page ─────────────────────────────────────────────────────────── */
.search-form {
  margin-top: 8px;
}
.search-input-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.search-input {
  flex: 1;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.search-hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
.search-hint code {
  font-family: monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
}

/* ── Trips page filter bar ───────────────────────────────────────────────── */
.trips-filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.trips-filter-bar input,
.trips-filter-bar select {
  padding: 7px 11px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: border-color .15s;
}
.trips-filter-bar input:focus,
.trips-filter-bar select:focus {
  border-color: var(--primary);
}
.trips-filter-bar input[name="search"] {
  flex: 1;
  min-width: 160px;
}
.trips-filter-bar label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.trips-filter-clear {
  font-size: 12px;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.trips-filter-clear:hover {
  background: var(--border);
  color: var(--text);
}

/* ── Trips page ──────────────────────────────────────────────────────────── */
.trips-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.trips-page-header h2 {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
}

.trip-count {
  font-size: 13px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 12px;
  font-weight: 600;
}

.trip-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.trip-list a {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid #16a34a;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, transform .1s;
}

.trip-list a:hover {
  border-color: var(--primary);
  border-left-color: #16a34a;
  box-shadow: 0 4px 16px rgba(37,99,235,.12);
  transform: translateY(-1px);
}
.trip-closed a:hover {
  border-left-color: #94a3b8;
}

.trip-list a:active { transform: translateY(0); }

.trip-name {
  flex: 1;
  font-weight: 700;
  font-size: 15px;
}

.trip-id {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 8px;
  font-family: monospace;
  font-weight: 600;
}

.trip-date {
  font-size: 12px;
  color: var(--muted);
}

.trip-arrow {
  color: var(--border);
  font-size: 16px;
  transition: color .15s, transform .15s;
}
.trip-list a:hover .trip-arrow {
  color: var(--primary);
  transform: translateX(3px);
}

.trip-closed a {
  border-left-color: #94a3b8;
  background: var(--bg);
  opacity: .9;
}
.trip-pdf-icon {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: .02em;
  transition: color .15s;
}
.trip-list a:hover .trip-pdf-icon {
  color: var(--primary);
  transform: none;
}

.trip-status {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  letter-spacing: .03em;
  white-space: nowrap;
}
.status-active {
  background: #dcfce7;
  color: #15803d;
}
.status-closed {
  background: #f1f5f9;
  color: #64748b;
}
[data-theme="dark"] .status-active {
  background: rgba(22,163,74,.2);
  color: #4ade80;
}
[data-theme="dark"] .status-closed {
  background: rgba(148,163,184,.12);
  color: #94a3b8;
}

/* When a trip has a share row, square the bottom corners of the main link card */
.trip-list li:has(.trip-share) > a {
  border-radius: 10px 10px 0 0;
}

.trip-share {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 10px 10px;
  font-size: 12px;
  flex-wrap: wrap;
}

.trip-pin {
  color: var(--muted);
  white-space: nowrap;
}
.trip-pin strong {
  color: var(--text);
  font-family: monospace;
  font-size: 13px;
  letter-spacing: .12em;
}

.trip-copy-btn {
  padding: 3px 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.trip-copy-btn:hover { background: var(--primary-dark, #1d4ed8); }
.trip-copy-btn.copied { background: #16a34a; }

.trip-public-link {
  color: var(--muted);
  font-family: monospace;
  font-size: 11px;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.trip-public-link:hover { color: var(--primary); text-decoration: underline; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state p { font-size: 15px; }

/* ── Dark mode overrides ─────────────────────────────────────────────────── */
[data-theme="dark"] .log-table th {
  background: linear-gradient(180deg, #1e293b 0%, #172032 100%);
}
[data-theme="dark"] .error {
  background: #2d1010;
  border-color: #7f1d1d;
  color: #fca5a5;
}
[data-theme="dark"] .save-banner {
  background: linear-gradient(90deg, #064e3b 0%, #065f46 100%);
  border-bottom-color: #047857;
  color: #d1fae5;
}
[data-theme="dark"] .btn-delete:hover { background: #2d1010; border-color: #7f1d1d; }
[data-theme="dark"] .alert-warn { background: var(--warn-bg); border-color: var(--warn-bd); color: #fcd34d; }
[data-theme="dark"] .login-card { background: var(--surface); }
[data-theme="dark"] .login-card-body input,
[data-theme="dark"] .login-card-body select { background: var(--bg); color: var(--text); border-color: var(--border); }
[data-theme="dark"] .num-field input { background: var(--bg); color: var(--text); }
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea { color: var(--text); background-color: var(--surface); border-color: var(--border); }
[data-theme="dark"] .vitals-field-label input { background: var(--bg); }

/* ── Theme toggle button ─────────────────────────────────────────────────── */
.theme-toggle {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 6px;
  color: rgba(255,255,255,.85);
  padding: 4px 10px;
  font-size: 16px;
  cursor: pointer;
  transition: background .15s;
  line-height: 1;
}
.theme-toggle:hover { background: rgba(255,255,255,.15); }

/* ── Header menu dropdown ────────────────────────────────────────────────── */
.header-menu { position: relative; }

.header-menu-btn {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 6px;
  color: rgba(255,255,255,.85);
  padding: 4px 10px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background .15s;
}
.header-menu-btn:hover { background: rgba(255,255,255,.15); }

.header-menu-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 180px;
  z-index: 200;
  overflow: hidden;
}
.header-menu-dropdown.open { display: block; }

.header-menu-item {
  display: block;
  width: 100%;
  padding: 11px 16px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  transition: background .12s;
  white-space: nowrap;
}
.header-menu-item:hover { background: var(--bg); }
.header-menu-item + .header-menu-item { border-top: 1px solid var(--border); }

/* ── Settings page ───────────────────────────────────────────────────────── */
.settings-page { max-width: 560px; margin: 0 auto; padding: 32px 20px; }
.settings-page h2 { font-size: 20px; font-weight: 700; color: var(--text); margin: 0 0 28px; }
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin-bottom: 20px;
}
.settings-card h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin: 0 0 18px;
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; }
.settings-row label { font-size: 14px; font-weight: 500; color: var(--text); }
.settings-row .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.font-controls { display: flex; align-items: center; gap: 10px; }
.font-controls button {
  width: 32px; height: 32px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  display: flex; align-items: center; justify-content: center;
}
.font-controls button:hover { border-color: var(--primary); background: var(--surface); }
.font-size-display {
  min-width: 52px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
}
.theme-switch {
  display: flex;
  gap: 6px;
}
.theme-switch button {
  padding: 6px 16px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.theme-switch button.active {
  background: var(--grad-primary);
  border-color: transparent;
  color: #fff;
}

/* ── PIN change inline form ──────────────────────────────────────────────── */
.trip-pin-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.trip-change-pin-btn {
  padding: 2px 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.trip-change-pin-btn:hover { border-color: var(--primary); color: var(--primary); }

.pin-edit-form { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.pin-edit-input {
  width: 54px;
  padding: 2px 6px;
  font-size: 13px;
  font-family: monospace;
  letter-spacing: .12em;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
}
.pin-edit-input:focus { border-color: var(--primary); outline: none; }

.pin-save-btn {
  padding: 2px 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.pin-save-btn:disabled { opacity: .5; cursor: not-allowed; }

.pin-cancel-btn {
  padding: 2px 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
}

/* ── Mobile responsive ───────────────────────────────────────────────────── */
@media (max-width: 600px) {
  :root { --header-h: 50px; }

  /* Header: shrink padding, allow text overflow */
  .app-header { padding: 0 12px; gap: 8px; }
  .app-header-left { gap: 8px; min-width: 0; flex: 1; overflow: hidden; }
  .patient-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .back-link { font-size: 12px; white-space: nowrap; }
  /* Hide numeric trip_id badge on small screens */
  .app-header-left span[style*="background"] { display: none; }

  /* Tabs: horizontally scrollable */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    scrollbar-width: none;
    gap: 0;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 0 14px;
    font-size: 13px;
  }

  /* Forms: single column, full width */
  .form-grid { grid-template-columns: 1fr !important; gap: 12px; }
  .two-col { grid-template-columns: 1fr !important; }
  .pcr-form { padding: 16px; }
  .section-content { padding: 0 8px 80px; }

  /* Buttons */
  .btn-primary { width: 100%; }

  /* Dropoff items */
  .dropoff-items { gap: 12px; }

  /* Trip list */
  .trip-list li > a {
    padding: 12px 14px;
    gap: 6px;
  }
  .trip-name { font-size: 14px; }
  .trip-id { font-size: 11px; }
  .trip-date { font-size: 11px; }
  .trip-share { gap: 8px; padding: 8px 14px; }

  /* Medications / notes / vitals: stack add form vertically */
  .add-row {
    flex-direction: column;
    align-items: stretch;
  }
  .add-row input, .add-row select { width: 100%; }

  /* Vitals table: horizontal scroll */
  .vitals-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Page content padding */
  .page-content { padding: 16px 8px; }
  .trips-page-header { padding: 0; }
}

@media (max-width: 420px) {
  /* PIN boxes on lock screen */
  .pin-row input { width: 52px; height: 60px; font-size: 24px; }
}
