/* ─── MediScan Web - Design Tokens ─── */
:root {
  --clr-primary: #0066ff;
  --clr-primary-hover: #0052cc;
  --clr-primary-soft: #e8f0ff;
  --clr-success: #10b981;
  --clr-success-soft: #d1fae5;
  --clr-danger: #ef4444;
  --clr-danger-soft: #fee2e2;
  --clr-warning: #f59e0b;
  --clr-warning-soft: #fef3c7;

  --clr-bg: #f5f7fb;
  --clr-surface: #ffffff;
  --clr-surface-hover: #f9fafb;
  --clr-border: #e5e7eb;
  --clr-text: #111827;
  --clr-text-muted: #6b7280;
  --clr-text-light: #9ca3af;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.12);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: 0.2s ease;
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--clr-bg);
  color: var(--clr-text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: 72px;
}
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ─── App Loading State ─── */
.app-loading {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 16px;
  background: var(--clr-bg);
}
.app-loading-status {
  font-size: 0.82rem;
  color: var(--clr-text-muted);
  margin-top: 4px;
}
.app-loading-icon { width: 40px; height: 40px; color: var(--clr-primary); }
.app-loading-text { font-size: 1.2rem; font-weight: 700; color: var(--clr-text); letter-spacing: -0.02em; }

/* ─── Login Screen ─── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e8f0ff 0%, #f5f7fb 50%, #d1fae5 100%);
  padding: 20px;
}
.login-container { width: 100%; max-width: 400px; }
.login-card {
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  padding: 40px 32px 32px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo svg {
  width: 48px; height: 48px;
  color: var(--clr-primary);
  margin-bottom: 8px;
}
.login-logo {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 20px;
}
.login-logo img {
  display: block;
  margin: 0 auto;
}
.login-title {
  font-size: 1.5rem; font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 2px;
}
.login-subtitle {
  font-size: 0.85rem; color: var(--clr-text-muted);
  margin-bottom: 28px;
}
.login-card form { text-align: left; }
.login-card .form-group { margin-bottom: 16px; }
.login-card .form-group label { font-size: 0.82rem; font-weight: 600; margin-bottom: 4px; display: block; }
.login-card .form-group input {
  width: 100%; padding: 11px 14px;
  border: 1px solid var(--clr-border); border-radius: var(--radius-sm);
  font-size: 0.92rem; transition: border-color var(--transition);
}
.login-card .form-group input:focus { outline: none; border-color: var(--clr-primary); box-shadow: 0 0 0 3px var(--clr-primary-soft); }
.login-error {
  background: var(--clr-danger-soft);
  color: var(--clr-danger);
  font-size: 0.82rem; font-weight: 600;
  padding: 10px 14px; border-radius: var(--radius-sm);
  margin-bottom: 14px;
}
.login-forgot {
  display: block;
  margin: 14px auto 0;
  background: none; border: none;
  color: var(--clr-primary);
  font-size: 0.8rem; font-weight: 600;
  cursor: pointer;
}
.login-forgot:hover { text-decoration: underline; }
.login-footer {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 24px; padding-top: 18px;
  border-top: 1px solid var(--clr-border);
  font-size: 0.7rem; color: var(--clr-text-muted);
}

/* ─── Topbar ─── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-facility {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--clr-primary);
  background: var(--clr-primary-soft);
  padding: 5px 12px;
  border-radius: 14px;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 6px;
}
.user-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--clr-text-muted);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--clr-border);
  background: var(--clr-surface);
  color: var(--clr-text-muted);
  transition: all var(--transition);
}
.btn-logout:hover { color: var(--clr-danger); border-color: var(--clr-danger); background: var(--clr-danger-soft); }
.topbar-popia-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--clr-success);
  background: var(--clr-success-soft);
  padding: 4px 10px;
  border-radius: 12px;
}
.logo-icon { width: 28px; height: 28px; color: var(--clr-primary); }
.logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
/* Logo image in topbar */
.topbar-logo {
  height: 36px;
  width: auto;
  display: block;
}
/* Logo image on splash/loading screen */
.app-loading-logo {
  width: 200px;
  max-width: 80vw;
  margin-bottom: 8px;
}
/* Live sync badge */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #059669;
  background: #d1fae5;
  padding: 4px 10px;
  border-radius: 12px;
  animation: livePulse 2.5s ease-in-out infinite;
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  animation: liveDot 1.4s ease-in-out infinite;
}
@keyframes liveDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.7); }
}
@keyframes livePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
  50%       { box-shadow: 0 0 0 3px rgba(16,185,129,0.2); }
}

/* ─── Bottom Nav ─── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: var(--clr-surface);
  border-top: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--clr-text-light);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 8px 16px;
  transition: color var(--transition);
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--clr-primary); }
.nav-item:hover { color: var(--clr-primary); }

/* ─── Views ─── */
.view { display: none; animation: fadeIn 0.3s ease; }
.view.active { display: block; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Page container ─── */
.page-container {
  max-width: 680px;
  margin: 0 auto;
  padding: 32px 20px;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 20px;
  transition: all var(--transition);
}
.btn-icon { width: 18px; height: 18px; flex-shrink: 0; }
.btn-primary { background: var(--clr-primary); color: #fff; }
.btn-primary:hover { background: var(--clr-primary-hover); }
.btn-outline {
  background: transparent;
  border: 2px solid var(--clr-border);
  color: var(--clr-text);
}
.btn-outline:hover { border-color: var(--clr-primary); color: var(--clr-primary); }
.btn-ghost {
  background: transparent;
  color: var(--clr-text-muted);
  padding: 8px 14px;
}
.btn-ghost:hover { background: var(--clr-bg); color: var(--clr-text); }
.btn-lg {
  font-size: 1rem;
  padding: 14px 28px;
  border-radius: var(--radius-md);
}
.full-width { width: 100%; justify-content: center; }
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--clr-text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 20px;
  transition: color var(--transition);
}
.btn-back:hover { color: var(--clr-primary); }
.btn-back svg { width: 18px; height: 18px; }

/* ─── Home ─── */
.home-container {
  max-width: 680px;
  margin: 0 auto;
  padding: 32px 20px;
}
.home-hero {
  text-align: center;
  margin-bottom: 36px;
  padding-top: 16px;
}
.home-hero h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}
.home-hero p {
  color: var(--clr-text-muted);
  font-size: 0.95rem;
}
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.action-card {
  background: var(--clr-surface);
  border: 2px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 28px 20px;
  text-align: center;
  transition: all var(--transition);
}
.action-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.card-blue:hover { border-color: var(--clr-primary); }
.card-green:hover { border-color: var(--clr-success); }
.action-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
}
.action-icon svg { width: 26px; height: 26px; }
.card-blue .action-icon { background: var(--clr-primary-soft); color: var(--clr-primary); }
.card-green .action-icon { background: var(--clr-success-soft); color: var(--clr-success); }
.action-card h3 { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.action-card p { font-size: 0.82rem; color: var(--clr-text-muted); }

.section-title { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.02em; }
.section-desc { color: var(--clr-text-muted); margin-top: 2px; margin-bottom: 20px; font-size: 0.9rem; }

/* ─── Tabs ─── */
.tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--clr-border);
  margin-bottom: 20px;
}
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--clr-text-muted);
  transition: all var(--transition);
}
.tab.active { color: var(--clr-primary); border-bottom-color: var(--clr-primary); }
.tab:hover { color: var(--clr-text); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Search ─── */
.search-box {
  display: flex;
  align-items: center;
  background: var(--clr-surface);
  border: 2px solid var(--clr-border);
  border-radius: var(--radius-md);
  padding: 4px 4px 4px 16px;
  margin-bottom: 20px;
  transition: border-color var(--transition);
}
.search-box:focus-within { border-color: var(--clr-primary); }
.search-icon { width: 20px; height: 20px; color: var(--clr-text-light); flex-shrink: 0; }
.search-box input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 0.95rem;
  padding: 12px;
  background: transparent;
  color: var(--clr-text);
}
.search-box input::placeholder { color: var(--clr-text-light); }

/* ─── Results ─── */
.results-list { display: flex; flex-direction: column; gap: 8px; }
.result-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  padding: 14px;
  cursor: pointer;
  transition: all var(--transition);
}
.result-card:hover { border-color: var(--clr-primary); box-shadow: var(--shadow-sm); }
.result-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--clr-primary-soft); color: var(--clr-primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem; flex-shrink: 0;
}
.result-info { flex: 1; }
.result-name { font-weight: 600; font-size: 0.9rem; }
.result-meta { font-size: 0.78rem; color: var(--clr-text-muted); margin-top: 1px; }
.result-arrow { width: 18px; height: 18px; color: var(--clr-text-light); }
.no-results {
  text-align: center; padding: 36px 20px; color: var(--clr-text-muted);
}
.no-results svg { width: 44px; height: 44px; margin-bottom: 10px; color: var(--clr-text-light); }

/* ─── Fingerprint Scanner ─── */
.fp-scanner-area {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 16px; padding: 28px;
  background: var(--clr-surface); border: 2px solid var(--clr-border);
  border-radius: var(--radius-lg); margin-bottom: 20px;
}
.fp-visual { width: 120px; height: 150px; position: relative; }
#fp-svg { width: 100%; height: 100%; color: var(--clr-text-light); transition: color 0.5s; }
.fp-outline { stroke-width: 1.5; }
.fp-ridge { opacity: 0.5; }
.fp-scanline { stroke: var(--clr-primary); stroke-width: 2; opacity: 0; }
.fp-visual.scanning #fp-svg { color: var(--clr-primary); }
.fp-visual.scanning .fp-scanline { opacity: 1; animation: scanMove 1.5s ease-in-out infinite; }
.fp-visual.success #fp-svg { color: var(--clr-success); }
.fp-visual.fail #fp-svg { color: var(--clr-danger); }
@keyframes scanMove {
  0%   { transform: translateY(0); }
  50%  { transform: translateY(125px); }
  100% { transform: translateY(0); }
}
.fp-status { font-size: 0.85rem; color: var(--clr-text-muted); margin-top: 4px; }
.fp-hint { font-size: 0.78rem; color: var(--clr-text-light); }

/* ─── Fingerprint Enrollment (new patient) ─── */
.fp-enroll-section {
  padding: 20px;
  background: var(--clr-bg);
  border-radius: var(--radius-md);
  margin: 16px 0;
  grid-column: 1 / -1;
}
.fp-enroll-section h3 { font-size: 0.95rem; margin-bottom: 2px; }
.fp-enroll-section > p { font-size: 0.82rem; color: var(--clr-text-muted); margin-bottom: 12px; }
.fp-enroll-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.fp-enroll-buttons .btn { font-size: 0.82rem; padding: 8px 14px; }
.fp-enroll-status {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px; font-size: 0.85rem; color: var(--clr-text-muted);
}
.fp-mini-icon { width: 20px; height: 20px; flex-shrink: 0; }
.fp-thumb {
  display: block;
  width: 80px;
  height: auto;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  border: 1px solid var(--clr-border);
}
.scanner-error {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.82rem;
}
.scanner-error a {
  color: var(--clr-primary);
  text-decoration: underline;
}

/* ─── Forms: card + groups ─── */
.form-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-row {
  display: contents;
}
.form-group {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.form-group.full {
  grid-column: 1 / -1;
}
.form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--clr-text-muted);
  margin-bottom: 4px;
}
.form-group input,
.form-group select,
.form-group textarea {
  border: 1.5px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.9rem;
  color: var(--clr-text);
  background: var(--clr-surface);
  transition: border-color var(--transition);
  outline: none;
  width: 100%;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--clr-primary); }
.form-group textarea { resize: vertical; min-height: 60px; }
.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--clr-text-light); }

/* ─── Patient Detail ─── */
.patient-detail-card {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
}
.patient-header { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.patient-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--clr-primary-soft); color: var(--clr-primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.1rem;
}
.patient-name { font-size: 1.2rem; font-weight: 700; }
.patient-id-badge {
  font-size: 0.78rem; color: var(--clr-text-muted);
  background: var(--clr-bg); padding: 2px 10px;
  border-radius: 12px; display: inline-block; margin-top: 2px;
}
.patient-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.patient-field label {
  display: block; font-size: 0.72rem; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--clr-text-muted); margin-bottom: 1px; font-weight: 600;
}
.patient-field span { font-size: 0.9rem; }
.status-active {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--clr-success); font-weight: 600;
}
.status-active::before {
  content: ''; width: 7px; height: 7px; background: var(--clr-success); border-radius: 50%;
}
.status-inactive { color: var(--clr-text-light); }

/* ─── Medical Forms Grid ─── */
.forms-section {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
}
.forms-section h3 { font-size: 1rem; margin-bottom: 2px; }
.forms-grid { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }

/* ─── Department Groups ─── */
.dept-group {
  border: 1.5px solid var(--clr-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.dept-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 16px;
  background: var(--clr-bg);
  border: none;
  border-bottom: 1px solid var(--clr-border);
  cursor: pointer;
  transition: background var(--transition);
}
.dept-header:hover { background: var(--clr-surface-hover); }
.dept-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dept-chevron {
  width: 18px; height: 18px;
  color: var(--clr-text-muted);
  transition: transform 0.2s ease;
}
.dept-group.collapsed .dept-chevron { transform: rotate(-90deg); }
.dept-group.collapsed .dept-forms { display: none; }
.dept-group.collapsed .dept-header { border-bottom: none; }
.dept-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--dept-color, var(--clr-text));
}
.dept-counter {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--clr-text-muted);
  background: var(--clr-surface);
  padding: 2px 10px;
  border-radius: 12px;
}
.dept-forms {
  display: flex;
  flex-direction: column;
}
.form-tile {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--clr-border);
  overflow: hidden;
  transition: all var(--transition);
  background: var(--clr-surface);
}
.form-tile:last-child { border-bottom: none; }
.form-tile:hover { background: var(--clr-surface-hover); }
.form-tile-main {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  flex: 1;
}
.form-tile-icon {
  width: 36px; height: 36px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--clr-primary-soft); color: var(--clr-primary);
  border-radius: var(--radius-sm);
}
.form-tile-icon svg { width: 20px; height: 20px; }
.form-tile.completed .form-tile-icon {
  background: var(--clr-success-soft); color: var(--clr-success);
}
.form-tile-info { flex: 1; }
.form-tile-title { font-weight: 600; font-size: 0.9rem; }
.form-tile-desc { font-size: 0.78rem; color: var(--clr-text-muted); }
.form-tile-badge {
  font-size: 0.72rem; font-weight: 700; padding: 3px 10px;
  border-radius: 12px; flex-shrink: 0; text-transform: uppercase;
  letter-spacing: 0.02em;
}
.badge-done { background: var(--clr-success-soft); color: #065f46; }
.badge-new { background: var(--clr-primary-soft); color: var(--clr-primary); }

/* ─── PDF Button on form tile ─── */
.btn-pdf {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-top: 1px solid var(--clr-border);
  background: var(--clr-bg);
  color: var(--clr-primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-pdf svg { width: 16px; height: 16px; }
.btn-pdf:hover { background: var(--clr-primary-soft); }

/* ─── Form Header ─── */
.form-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 20px;
}
.form-header-icon {
  width: 44px; height: 44px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--clr-primary-soft); color: var(--clr-primary);
  border-radius: var(--radius-md);
}
.form-header-icon svg { width: 24px; height: 24px; }

/* ─── Pre-fill Banner ─── */
.prefill-banner {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--clr-primary-soft);
  color: var(--clr-primary);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
}

/* ─── Form actions ─── */
.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  padding-top: 8px;
}

/* ─── Verify / Biometric Section ─── */
.verify-section {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 20px;
}
.verify-section h3 { font-size: 1rem; margin-bottom: 8px; }
.biometric-status { margin-bottom: 12px; }
.bio-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 500;
}
.bio-linked { color: var(--clr-success); }
.bio-none { color: var(--clr-text-muted); }
.bio-cred-list { margin: 8px 0; }
.bio-cred-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--clr-text-muted);
  background: var(--clr-surface);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
}
.bio-cred-device { font-weight: 500; color: var(--clr-text); }
.bio-replace-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.btn-warning { color: #b45309; border-color: #d97706; }
.btn-warning:hover { background: #fef3c7; }
.btn-sm { font-size: 0.78rem; padding: 6px 10px; }
.biometric-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.biometric-actions .btn { font-size: 0.82rem; padding: 8px 14px; }
.verify-result {
  margin-top: 14px; padding: 12px 14px;
  border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 600;
}
.verify-result.pass { background: var(--clr-success-soft); color: #065f46; }
.verify-result.fail { background: var(--clr-danger-soft); color: #991b1b; }

/* ─── Encounters ─── */
.encounters-section {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
}
.encounters-section h3 { font-size: 1rem; margin-bottom: 12px; }
.encounters-list { display: flex; flex-direction: column; gap: 6px; }
.encounter-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: var(--clr-bg);
  border-radius: var(--radius-sm); font-size: 0.82rem;
}
.encounter-type { font-weight: 600; text-transform: capitalize; }
.encounter-method {
  font-size: 0.72rem; padding: 2px 8px; border-radius: 10px;
  background: var(--clr-primary-soft); color: var(--clr-primary);
}
.encounter-date { color: var(--clr-text-muted); font-size: 0.78rem; }
.no-encounters { font-size: 0.82rem; color: var(--clr-text-muted); text-align: center; padding: 14px; }

/* ─── POPIA Consent Banner ─── */
.popia-banner {
  position: fixed;
  bottom: 64px;
  left: 0;
  right: 0;
  z-index: 200;
  background: var(--clr-surface);
  border-top: 2px solid var(--clr-primary);
  padding: 20px;
  box-shadow: 0 -4px 20px rgba(0,0,0,.15);
  display: flex;
  justify-content: center;
}
.popia-banner-content {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  max-width: 680px;
  width: 100%;
}
.popia-icon { width: 32px; height: 32px; color: var(--clr-primary); flex-shrink: 0; margin-top: 2px; }
.popia-banner-content strong { display: block; font-size: 0.95rem; margin-bottom: 4px; }
.popia-banner-content p { font-size: 0.78rem; color: var(--clr-text-muted); line-height: 1.5; margin-bottom: 8px; }
.popia-banner-content .btn { flex-shrink: 0; align-self: flex-end; }

/* ─── PDF Preview Modal ─── */
.pdf-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,.6);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(4px);
}
.pdf-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--clr-surface);
  border-bottom: 1px solid var(--clr-border);
}
.pdf-modal-header h3 { font-size: 1rem; font-weight: 600; }
.pdf-modal-actions { display: flex; align-items: center; gap: 8px; }
.pdf-iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: #f5f5f5;
}
.pdf-preview-container {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.pdf-fallback {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--clr-bg);
  text-align: center;
  padding: 40px 20px;
}
.pdf-fallback p { font-size: 1rem; font-weight: 600; color: var(--clr-text); }
.pdf-fallback-hint { font-size: 0.85rem; font-weight: 400; color: var(--clr-text-muted); }

/* ─── Admin Panel ─── */
.admin-section {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}
.admin-section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.admin-section-header h3 { font-size: 1rem; font-weight: 700; }
.admin-user-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--clr-border);
}
.admin-user-row:last-child { border-bottom: none; }
.admin-user-actions { display: flex; gap: 6px; flex-shrink: 0; }
.admin-user-name { font-weight: 600; font-size: 0.9rem; display: flex; align-items: center; gap: 8px; }
.admin-user-meta { font-size: 0.78rem; color: var(--clr-text-muted); margin-top: 2px; }
.btn-danger-outline {
  border: 1px solid #fca5a5; color: #dc2626; background: #fff;
  border-radius: var(--radius-sm); font-size: 0.78rem; padding: 4px 10px;
  font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.btn-danger-outline:hover { background: #fef2f2; border-color: #ef4444; }
.role-badge {
  display: inline-block;
  font-size: 0.65rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 8px; border-radius: 10px;
}
.role-admin { background: #fef3c7; color: #92400e; }
.role-staff { background: var(--clr-primary-soft); color: var(--clr-primary); }
.admin-facility-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--clr-border);
}
.admin-facility-row:last-child { border-bottom: none; }
.admin-facility-info { display: flex; flex-direction: column; gap: 2px; }
.admin-facility-name { font-weight: 600; font-size: 0.88rem; }
.admin-facility-city { font-size: 0.78rem; color: var(--clr-text-muted); }
.admin-empty { font-size: 0.85rem; color: var(--clr-text-muted); padding: 16px 0; }
.admin-error { font-size: 0.85rem; color: var(--clr-danger); }
.card-purple .action-icon { background: #f3e8ff; color: #7c3aed; }
.edit-user-email { font-size: 0.82rem; color: var(--clr-text-muted); margin-bottom: 14px; font-weight: 500; }

/* ─── Admin Modals ─── */
.admin-modal {
  position: fixed; inset: 0; z-index: 310;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
  padding: 20px;
}
.admin-modal-content {
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 440px;
  max-height: 90vh; overflow-y: auto;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.admin-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.admin-modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.admin-modal-content .form-group { margin-bottom: 14px; }
.admin-modal-content .form-group label { font-size: 0.82rem; font-weight: 600; margin-bottom: 4px; display: block; }
.admin-modal-content .form-group input,
.admin-modal-content .form-group select {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--clr-border); border-radius: var(--radius-sm);
  font-size: 0.9rem;
}
.admin-modal-content .form-group input:focus,
.admin-modal-content .form-group select:focus { outline: none; border-color: var(--clr-primary); }
}

/* ─── Toast (centred popup) ─── */
.toast {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  background: rgba(0,0,0,0.82); color: #fff;
  padding: 18px 36px; border-radius: 14px;
  font-size: 0.95rem; font-weight: 600; z-index: 9999;
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
  pointer-events: none; will-change: opacity, transform;
  max-width: 80vw; text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  opacity: 0; visibility: hidden;
}
.toast.visible { transform: translate(-50%, -50%) scale(1); opacity: 1; visibility: visible; }

/* ─── Spinner ─── */
.spinner {
  display: inline-block; width: 20px; height: 20px;
  border: 2.5px solid var(--clr-border); border-top-color: var(--clr-primary);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-state {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding: 32px; color: var(--clr-text-muted); font-size: 0.88rem;
}

/* ─── Confidence bar ─── */
.confidence-bar-wrap {
  width: 100%; height: 5px; background: var(--clr-border);
  border-radius: 3px; margin-top: 3px; overflow: hidden;
}
.confidence-bar { height: 100%; border-radius: 3px; transition: width 0.6s ease; }

/* ─── File Uploads Section ─── */
.uploads-section {
  background: var(--clr-surface);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
}
.uploads-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.uploads-header h3 { font-size: 1rem; margin-bottom: 2px; }
.uploads-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.upload-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--clr-text);
  transition: all var(--transition);
}
.upload-card:hover { border-color: var(--clr-primary); box-shadow: var(--shadow-sm); }
.upload-preview {
  width: 48px; height: 48px; flex-shrink: 0;
  border-radius: var(--radius-sm);
  background: var(--clr-bg);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.upload-thumb {
  width: 100%; height: 100%; object-fit: cover; border-radius: var(--radius-sm);
}
.upload-file-icon { width: 24px; height: 24px; color: var(--clr-text-muted); }
.upload-info { flex: 1; min-width: 0; }
.upload-name { font-weight: 600; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upload-meta { font-size: 0.75rem; color: var(--clr-text-muted); margin-top: 1px; }
.upload-desc { font-size: 0.78rem; color: var(--clr-text-muted); margin-top: 2px; }
.no-uploads { font-size: 0.82rem; color: var(--clr-text-muted); text-align: center; padding: 20px; }

/* ─── Upload Modal ─── */
.upload-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  padding: 20px;
}
.upload-modal-content {
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
}
.upload-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.upload-modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.upload-modal form { display: flex; flex-direction: column; gap: 14px; }
.upload-file-input {
  border: 2px dashed var(--clr-border) !important;
  border-radius: var(--radius-md) !important;
  padding: 20px 12px !important;
  cursor: pointer;
}
.upload-file-input:hover { border-color: var(--clr-primary) !important; }
.upload-progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.upload-progress-track {
  flex: 1;
  height: 8px;
  background: var(--clr-border);
  border-radius: 4px;
  overflow: hidden;
}
.upload-progress-bar {
  height: 100%;
  background: var(--clr-primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.upload-progress-text {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--clr-text-muted);
  min-width: 36px;
  text-align: right;
}

/* ─── Responsive ─── */

/* Touch-friendly tap targets */
@media (pointer: coarse) {
  .btn, .tab, .nav-item, .dept-header, .form-tile-main, .result-card, .upload-card {
    min-height: 44px;
  }
  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 16px; /* prevent iOS zoom on focus */
    padding: 12px 14px;
  }
}

/* Small phones */
@media (max-width: 560px) {
  .topbar { padding: 0 14px; height: 50px; }
  .logo-text { font-size: 1rem; }
  .topbar-popia-badge span { display: none; }
  .topbar-facility { font-size: 0.7rem; padding: 4px 8px; max-width: 110px; }
  .topbar-facility svg { display: none; }
  .legal-footer { bottom: 56px; font-size: 0.62rem; }
  .user-name { display: none; }
  .btn-logout { width: 28px; height: 28px; }

  .action-grid { grid-template-columns: 1fr; gap: 10px; }
  .action-card { padding: 20px 16px; }
  .action-card h3 { font-size: 0.92rem; }
  .action-icon { width: 44px; height: 44px; border-radius: 12px; }

  .patient-fields { grid-template-columns: 1fr; gap: 10px; }
  .patient-detail-card { padding: 16px; }
  .patient-avatar { width: 44px; height: 44px; font-size: 0.95rem; }
  .patient-name { font-size: 1.05rem; }

  .form-card { grid-template-columns: 1fr; padding: 16px; gap: 12px; }
  .home-container, .page-container { padding: 16px 12px; }
  .home-hero { margin-bottom: 24px; padding-top: 8px; }
  .home-hero h1 { font-size: 1.3rem; }
  .home-hero p { font-size: 0.85rem; }

  .section-title { font-size: 1.1rem; }
  .section-desc { font-size: 0.82rem; }

  .forms-section, .uploads-section, .verify-section, .encounters-section { padding: 16px; }
  .forms-section h3, .uploads-section h3, .verify-section h3 { font-size: 0.95rem; }

  .dept-header { padding: 10px 12px; }
  .dept-label { font-size: 0.82rem; }
  .form-tile-main { padding: 12px; }
  .form-tile-title { font-size: 0.85rem; }
  .form-tile-desc { font-size: 0.72rem; }
  .form-tile-icon { width: 32px; height: 32px; }
  .form-tile-icon svg { width: 18px; height: 18px; }

  .biometric-actions { flex-direction: column; }
  .biometric-actions .btn { width: 100%; justify-content: center; }

  .fp-enroll-buttons { flex-direction: column; }
  .fp-enroll-buttons .btn { width: 100%; justify-content: center; }
  .fp-enroll-section { padding: 14px; }

  .search-box { padding: 2px 2px 2px 12px; }
  .search-box input { padding: 10px 8px; }
  .search-box .btn { padding: 10px 14px; font-size: 0.82rem; }

  .tab { padding: 10px 12px; font-size: 0.82rem; }
  .fp-scanner-area { padding: 20px 14px; }
  .fp-visual { width: 100px; height: 125px; }
  .fp-hint { font-size: 0.72rem; }

  .uploads-header { flex-direction: column; gap: 8px; }
  .uploads-header .btn { width: 100%; justify-content: center; }
  .upload-card { padding: 10px 12px; gap: 10px; }
  .upload-preview { width: 40px; height: 40px; }
  .upload-name { font-size: 0.8rem; }

  .result-card { padding: 12px; gap: 10px; }
  .result-avatar { width: 38px; height: 38px; font-size: 0.82rem; }
  .result-name { font-size: 0.85rem; }

  .popia-banner { bottom: 56px; padding: 14px; }
  .popia-banner-content { flex-direction: column; gap: 10px; }
  .popia-banner-content .btn { align-self: stretch; }
  .popia-icon { width: 24px; height: 24px; }

  .bottom-nav { height: 56px; }
  .nav-item { padding: 6px 12px; }
  .nav-item svg { width: 20px; height: 20px; }
  .nav-item span { font-size: 0.65rem; }

  .pdf-modal-header { padding: 10px 14px; }
  .pdf-modal-header h3 { font-size: 0.85rem; }
  .pdf-modal-actions .btn { padding: 8px 12px; font-size: 0.8rem; }

  .upload-modal { padding: 10px; }
  .upload-modal-content { padding: 16px; }
  .upload-modal-header h3 { font-size: 1rem; }

  .prefill-banner { font-size: 0.78rem; padding: 8px 12px; }

  .toast { font-size: 0.82rem; padding: 14px 24px; }
  .btn-back { font-size: 0.82rem; margin-bottom: 14px; }
  .form-header { gap: 10px; }
  .form-header-icon { width: 38px; height: 38px; }
  .form-header-icon svg { width: 20px; height: 20px; }
}

/* Tablets in portrait */
@media (min-width: 561px) and (max-width: 768px) {
  .page-container, .home-container { max-width: 100%; padding: 24px 20px; }
  .action-grid { grid-template-columns: 1fr 1fr; }
  .biometric-actions { flex-wrap: wrap; }
  .uploads-header .btn { white-space: nowrap; }
}

/* ─── Role Selector (test mode) ─── */
.role-selector {
  display: flex; flex-direction: column; gap: 10px;
  margin-top: 20px;
}
.role-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; border-radius: var(--radius-md);
  border: 2px solid var(--clr-border); background: #fff;
  cursor: pointer; text-align: left; transition: all 0.2s;
}
.role-btn svg { width: 28px; height: 28px; flex-shrink: 0; }
.role-btn span { font-weight: 700; font-size: 1rem; display: block; }
.role-btn small { font-size: 0.78rem; color: var(--clr-text-muted); font-weight: 400; }
.role-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.role-btn-staff { border-color: #10b981; }
.role-btn-staff svg { stroke: #10b981; }
.role-btn-staff:hover { background: #ecfdf5; }

.role-btn-admin { border-color: #3b82f6; }
.role-btn-admin svg { stroke: #3b82f6; }
.role-btn-admin:hover { background: #eff6ff; }

.role-btn-super { border-color: #8b5cf6; }
.role-btn-super svg { stroke: #8b5cf6; }
.role-btn-super:hover { background: #f5f3ff; }

/* ─── Field Validation Hints ─── */
.field-hint {
  display: block; font-size: 0.78rem; margin-top: 4px;
  min-height: 1.2em; line-height: 1.3;
}
.hint-valid { color: #059669; }
.hint-error { color: #dc2626; }

/* ─── Admin Stats Counters ─── */
.admin-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 18px 12px; border-radius: var(--radius-md);
  background: #fff; border: 1px solid var(--clr-border);
  box-shadow: var(--shadow-sm);
}
.stat-card svg { width: 24px; height: 24px; }
.stat-value { font-size: 1.6rem; font-weight: 800; line-height: 1.2; }
.stat-label { font-size: 0.75rem; color: var(--clr-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-hospitals svg { stroke: #8b5cf6; }
.stat-hospitals .stat-value { color: #7c3aed; }
.stat-staff svg { stroke: #3b82f6; }
.stat-staff .stat-value { color: #2563eb; }
.stat-patients svg { stroke: #10b981; }
.stat-patients .stat-value { color: #059669; }

/* ─── Role Badges ─── */
.role-badge {
  display: inline-block; font-size: 0.7rem; font-weight: 700;
  padding: 2px 8px; border-radius: 10px; text-transform: uppercase;
  letter-spacing: 0.03em;
}
.role-badge.role-staff { background: #d1fae5; color: #065f46; }
.role-badge.role-admin { background: #dbeafe; color: #1e40af; }
.role-badge.role-super { background: #ede9fe; color: #5b21b6; }

/* ─── Terms Modal ─── */
.terms-modal-content { max-width: 640px; max-height: 85vh; display: flex; flex-direction: column; }
.terms-body {
  flex: 1; overflow-y: auto; padding: 0 24px 16px;
  font-size: 0.88rem; line-height: 1.65; color: var(--clr-text);
}
.terms-body h3 { margin-top: 18px; margin-bottom: 6px; font-size: 0.95rem; color: var(--clr-text); }
.terms-body ul { padding-left: 20px; margin: 6px 0; }
.terms-body li { margin-bottom: 4px; }
.terms-body p { margin: 6px 0; }
.terms-actions { padding: 12px 24px 16px; border-top: 1px solid var(--clr-border); }

/* ─── Legal Footer ─── */
.legal-footer {
  position: fixed;
  bottom: 64px; /* sits just above the bottom-nav (64px tall) */
  left: 0;
  right: 0;
  z-index: 99;
  text-align: center;
  padding: 0.3rem 1rem;
  font-size: 0.68rem;
  color: var(--clr-text-muted);
  border-top: 1px solid var(--clr-border);
  background: var(--clr-surface);
  line-height: 1.4;
}
.legal-footer a { color: var(--clr-text-muted); text-decoration: none; }
.legal-footer a:hover { color: var(--clr-primary); text-decoration: underline; }
.legal-footer span { margin: 0 0.3rem; }

/* no extra padding-bottom needed on bottom-nav; footer is above it */

/* ─── HMS Admin ─── */
.badge-info {
  display: inline-block; font-size: 0.72rem; font-weight: 600;
  padding: 2px 8px; border-radius: 4px;
  background: #e0f2fe; color: #0369a1;
  letter-spacing: 0.02em;
  margin-left: 0.5rem;
  vertical-align: middle;
}
.badge-success {
  display: inline-block; font-size: 0.72rem; font-weight: 600;
  padding: 2px 8px; border-radius: 4px;
  background: #d1fae5; color: #065f46;
}
.badge-neutral {
  display: inline-block; font-size: 0.72rem; font-weight: 600;
  padding: 2px 8px; border-radius: 4px;
  background: #f3f4f6; color: #6b7280;
}
.hms-status-line { font-size: 0.8rem; color: var(--clr-text-muted); }
.checkbox-group { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.4rem; }
.checkbox-group label { font-size: 0.9rem; display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }

/* Form history modal (appendable forms: vitals, progress notes, imaging) */
#form-history-modal { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); display: none; align-items: flex-start; justify-content: center; padding: 60px 20px; z-index: 1000; }
#form-history-modal.visible { display: flex; }
#form-history-modal .modal-card { background: #fff; border-radius: 12px; box-shadow: 0 18px 50px rgba(0,0,0,0.18); width: 100%; max-width: 760px; display: flex; flex-direction: column; max-height: 90vh; }
#form-history-modal .modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid #e5e7eb; }
#form-history-modal .modal-head h3 { margin: 0; font-size: 1.05rem; }
#form-history-modal .modal-close { background: transparent; border: 0; font-size: 1.6rem; line-height: 1; cursor: pointer; color: #6b7280; }
#form-history-modal .modal-body { padding: 16px 20px; }
.hist-card { border: 1px solid #e5e7eb; border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; background: #fafbfc; }
.hist-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px dashed #e5e7eb; }
.hist-head .hist-date { color: #6b7280; font-size: 0.82rem; }
.hist-row { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 0.88rem; }
.hist-row .hist-key { color: #374151; font-weight: 500; flex: 1; }
.hist-row .hist-val { color: #111827; text-align: right; max-width: 60%; word-break: break-word; }

/* ─────────── Patient self-fill bar (staff side) ─────────── */
.self-fill-bar { display:flex; align-items:center; justify-content:space-between; gap:16px; padding:14px 18px; margin:16px 0; background:linear-gradient(135deg,#eff6ff,#dbeafe); border:1px solid #bfdbfe; border-radius:12px; }
.self-fill-info { display:flex; flex-direction:column; gap:2px; }
.self-fill-info strong { color:#1e3a8a; font-size:0.95rem; }
.self-fill-info span { color:#475569; font-size:0.82rem; }
@media (max-width: 640px) { .self-fill-bar { flex-direction:column; align-items:stretch; } }

/* ─────────── Generic modal overlay (used by self-fill) ─────────── */
.modal-overlay { position:fixed; inset:0; background:rgba(15,23,42,0.55); display:flex; align-items:flex-start; justify-content:center; padding:60px 20px; z-index:1000; }
.modal-overlay .modal-card { background:#fff; border-radius:12px; box-shadow:0 18px 50px rgba(0,0,0,0.18); width:100%; max-width:560px; padding:18px 22px 22px; }
.modal-overlay .modal-head { display:flex; align-items:center; justify-content:space-between; padding:0 0 12px; border-bottom:1px solid #e5e7eb; margin-bottom:14px; }
.modal-overlay .modal-head h3 { margin:0; font-size:1.05rem; }
.modal-overlay .modal-close { background:transparent; border:0; font-size:1.6rem; line-height:1; cursor:pointer; color:#6b7280; }

/* Patient-captured signature display (on staff consent form view) */
.patient-sig-block { margin-top:18px; }
.patient-sig-block > label { display:block; font-weight:600; color:#0f172a; margin-bottom:8px; font-size:0.92rem; }
.patient-sig-meta { font-weight:400; color:#64748b; font-size:0.82rem; }
.patient-sig-frame { border:1px solid #e2e8f0; border-radius:10px; background:#fff; padding:12px; box-shadow:0 1px 2px rgba(15,23,42,0.04); }
.patient-sig-img { display:block; max-width:100%; max-height:220px; margin:0 auto; }
.patient-sig-caption { margin-top:8px; padding-top:8px; border-top:1px dashed #e2e8f0; font-size:0.8rem; color:#64748b; text-align:center; }

/* Medical Aid linked-member section */
.medaid-section { background:#fff; border:1px solid #e2e8f0; border-radius:12px; padding:20px; margin-top:18px; }
.medaid-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; }
.medaid-header h3 { margin:0; font-size:1rem; }
.medaid-details { display:grid; grid-template-columns:repeat(auto-fill, minmax(180px, 1fr)); gap:10px; }
.medaid-detail { display:flex; flex-direction:column; }
.medaid-detail label { font-size:0.75rem; text-transform:uppercase; letter-spacing:0.04em; color:#64748b; font-weight:600; margin-bottom:2px; }
.medaid-detail span { font-size:0.92rem; color:#0f172a; }
.medaid-linked-card { background:#eff6ff; border:1px solid #bfdbfe; border-radius:10px; padding:14px 16px; }
.medaid-linked-badge { font-size:0.75rem; font-weight:600; text-transform:uppercase; color:#2563eb; margin-bottom:6px; letter-spacing:0.04em; }
.medaid-linked-name { display:flex; align-items:center; gap:6px; cursor:pointer; font-size:0.95rem; color:#1e40af; margin-bottom:10px; }
.medaid-linked-name:hover { text-decoration:underline; }
.medaid-linked-orphan { background:#fef2f2; border-color:#fecaca; }
.medaid-unlink-btn { margin-top:10px; }
.medaid-empty { color:#64748b; font-size:0.88rem; margin:0; }
.medaid-dependants { margin-top:14px; padding-top:12px; border-top:1px solid #e2e8f0; }
.medaid-dependants-label { font-size:0.78rem; text-transform:uppercase; letter-spacing:0.04em; color:#64748b; font-weight:600; margin-bottom:8px; }
.medaid-dep-row { display:flex; align-items:center; justify-content:space-between; padding:8px 10px; border-radius:8px; cursor:pointer; transition:background 0.1s; }
.medaid-dep-row:hover { background:#f1f5f9; }
.medaid-dep-name { font-size:0.9rem; color:#0f172a; }

/* Inline contact edit/add buttons on patient detail view */
.inline-add-btn { background:#eff6ff; color:#2563eb; border:1px dashed #93c5fd; border-radius:6px; padding:4px 10px; font-size:0.82rem; font-weight:600; cursor:pointer; transition:all 0.15s; }
.inline-add-btn:hover { background:#dbeafe; border-style:solid; }
.inline-edit-btn { background:transparent; border:none; color:#94a3b8; cursor:pointer; font-size:0.85rem; padding:2px 6px; margin-left:4px; border-radius:4px; vertical-align:middle; }
.inline-edit-btn:hover { color:#2563eb; background:#eff6ff; }

/* Self-fill modal specifics */
.sf-channels { display:flex; flex-direction:column; gap:8px; margin:8px 0 16px; }
.sf-channels-label, .sf-section-label { font-size:0.78rem; text-transform:uppercase; letter-spacing:0.06em; color:#475569; font-weight:600; margin-bottom:4px; }
.sf-channel { display:flex; align-items:center; gap:10px; padding:10px 12px; border:1px solid #e5e7eb; border-radius:8px; cursor:pointer; font-size:0.92rem; }
.sf-channel:hover { border-color:#cbd5e1; background:#f8fafc; }
.sf-channel input[type=radio] { margin:0; }
.sf-channel-name { font-weight:600; color:#0f172a; min-width:54px; }
.sf-channel-target { color:#64748b; font-size:0.85rem; word-break:break-all; }
.sf-channel-disabled { opacity:0.5; cursor:not-allowed; }
.sf-channel-disabled:hover { background:transparent; border-color:#e5e7eb; }
.sf-opts { display:flex; flex-direction:column; gap:8px; margin:12px 0 18px; }
.sf-opt { display:flex; align-items:flex-start; gap:8px; font-size:0.92rem; cursor:pointer; padding:8px 10px; border:1px solid #e5e7eb; border-radius:8px; }
.sf-opt input { margin-top:3px; }
.sf-actions { display:flex; justify-content:flex-end; gap:10px; margin-top:8px; }
.sf-success { text-align:center; }
.sf-pin-card { background:linear-gradient(135deg,#fef3c7,#fde68a); border:1px solid #fbbf24; border-radius:12px; padding:16px; margin-bottom:14px; }
.sf-pin-label { font-size:0.85rem; color:#78350f; margin-bottom:8px; }
.sf-pin { font-family: 'SF Mono', Menlo, monospace; font-size:2.4rem; letter-spacing:0.4em; font-weight:700; color:#1e293b; padding-left:0.4em; /* offset for letter-spacing */ }
.sf-link-row { display:flex; gap:8px; margin:12px 0; align-items:stretch; }
.sf-link-row input { flex:1; min-width:0; padding:8px 10px; border:1px solid #d1d5db; border-radius:6px; font-size:0.8rem; font-family: 'SF Mono', Menlo, monospace; }
.sf-link-row .btn { flex-shrink:0; white-space:nowrap; }

/* ─────────── Patient self-fill portal (patient.html) ─────────── */
.patient-portal-body { margin:0; min-height:100vh; background:#f1f5f9; font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif; color:#0f172a; padding-bottom:env(safe-area-inset-bottom); }
.pp-header { background:#fff; border-bottom:1px solid #e2e8f0; padding:14px 18px; display:flex; align-items:center; gap:12px; }
.pp-logo { height:32px; }
.pp-tagline { color:#64748b; font-size:0.9rem; }
.pp-main { max-width:560px; margin:0 auto; padding:20px 16px 40px; }
.pp-footer { max-width:560px; margin:0 auto; padding:14px 18px 32px; font-size:0.78rem; color:#64748b; text-align:center; }
.pp-loading-block { text-align:center; padding:40px 0; color:#64748b; }
.pp-card { background:#fff; border-radius:14px; box-shadow:0 4px 18px rgba(15,23,42,0.06); padding:22px 20px; margin-bottom:16px; }
.pp-card h2 { margin:0 0 6px; font-size:1.25rem; color:#0f172a; }
.pp-sub { margin:0 0 18px; color:#475569; font-size:0.92rem; line-height:1.45; }
.pp-form { display:flex; flex-direction:column; gap:16px; }
.pp-field { display:flex; flex-direction:column; gap:6px; }
.pp-field-label, .pp-form label { font-size:0.92rem; color:#334155; font-weight:600; line-height:1.3; }
/* font-size:16px on inputs prevents iOS Safari auto-zoom on focus */
.pp-field-input,
.pp-form input, .pp-form select, .pp-form textarea {
  width:100%; box-sizing:border-box;
  padding:14px 14px; min-height:48px;
  border:1px solid #cbd5e1; border-radius:10px;
  font-size:16px; line-height:1.35;
  background:#fff; color:#0f172a; font-family:inherit;
  -webkit-appearance:none; appearance:none;
}
.pp-form textarea { min-height:96px; resize:vertical; }
.pp-form select { background-image:linear-gradient(45deg,transparent 50%,#475569 50%),linear-gradient(135deg,#475569 50%,transparent 50%); background-position:calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size:5px 5px,5px 5px; background-repeat:no-repeat; padding-right:36px; }
.pp-field-input:focus,
.pp-form input:focus, .pp-form select:focus, .pp-form textarea:focus {
  outline:none; border-color:#2563eb; box-shadow:0 0 0 3px rgba(37,99,235,0.18);
}
.pp-field-input:invalid:not(:placeholder-shown) { border-color:#f87171; }
.pp-pin-input { font-family:'SF Mono',Menlo,monospace; font-size:1.5rem; letter-spacing:0.4em; text-align:center; min-height:56px; }
.pp-required { color:#dc2626; }
/* Buttons - 48px min touch target */
.pp-btn { display:inline-block; padding:14px 20px; min-height:48px; border-radius:10px; border:0; font-size:1rem; font-weight:600; cursor:pointer; font-family:inherit; -webkit-tap-highlight-color:transparent; }
.pp-btn-block { display:block; width:100%; }
.pp-btn-primary { background:#2563eb; color:#fff; }
.pp-btn-primary:active { background:#1d4ed8; }
.pp-btn-primary:disabled { background:#94a3b8; cursor:not-allowed; }
.pp-btn-outline { background:#fff; color:#2563eb; border:1px solid #2563eb; }
.pp-btn-sm { padding:10px 14px; min-height:40px; font-size:0.9rem; }
/* Sticky submit bar on small screens - keeps Submit reachable above iOS bottom bar */
.pp-submit-bar { margin-top:8px; }
@media (max-width: 640px) {
  .pp-main { padding:14px 12px 120px; }
  .pp-card { padding:18px 16px; border-radius:12px; }
  .pp-card h2 { font-size:1.15rem; }
  .pp-submit-bar {
    position:sticky; bottom:0; left:0; right:0;
    padding:12px 0 calc(12px + env(safe-area-inset-bottom));
    background:linear-gradient(to top, #ffffff 70%, rgba(255,255,255,0));
    margin:8px -16px 0;
    padding-left:16px; padding-right:16px;
    z-index:5;
  }
}
.pp-err { color:#b91c1c; font-size:0.88rem; padding:8px 10px; background:#fef2f2; border:1px solid #fecaca; border-radius:6px; }
.pp-back { background:none; border:0; color:#2563eb; cursor:pointer; padding:0 0 12px; font-size:0.9rem; }
.pp-form-list { list-style:none; padding:0; margin:0; display:flex; flex-direction:column; gap:10px; }
.pp-form-row { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px 14px; border:1px solid #e2e8f0; border-radius:10px; background:#f8fafc; }
.pp-form-desc { font-size:0.78rem; color:#64748b; margin-top:2px; }
.pp-form-actions { display:flex; align-items:center; gap:8px; }
.pp-pill { display:inline-block; padding:3px 9px; border-radius:999px; font-size:0.74rem; background:#e2e8f0; color:#475569; font-weight:600; }
.pp-pill-done { background:#dcfce7; color:#166534; }
.pp-success-msg { margin-top:14px; padding:12px; background:#dcfce7; border-radius:8px; color:#166534; text-align:center; font-weight:600; }
.pp-sig-wrap { display:flex; flex-direction:column; gap:8px; }
.pp-sig-canvas { width:100%; height:200px; border:1px dashed #94a3b8; border-radius:8px; background:#fff; touch-action:none; }
.pp-success { text-align:center; padding:36px 20px; }
.pp-check { width:64px; height:64px; line-height:64px; margin:0 auto 14px; border-radius:50%; background:#dcfce7; color:#166534; font-size:2.2rem; font-weight:700; }
.pp-error { text-align:center; padding:36px 20px; border-top:4px solid #ef4444; }
.pp-error h2 { color:#b91c1c; }
