:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #f59e0b;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary); text-decoration: none; }

/* ---------- NAVBAR ---------- */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.navbar .logo {
  font-weight: 800;
  font-size: 22px;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.navbar nav a {
  margin-left: 20px;
  font-weight: 600;
  color: var(--text);
}
.navbar nav a.btn-primary { color: #fff; }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-block;
  padding: 12px 22px;
  border-radius: 10px;
  border: none;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: transform .1s ease, opacity .2s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- HERO ---------- */
.hero {
  padding: 80px 32px;
  text-align: center;
  background: linear-gradient(135deg, #eff6ff, #f5f7fb);
}
.hero h1 { font-size: 42px; margin-bottom: 12px; }
.hero p { color: var(--muted); font-size: 18px; max-width: 560px; margin: 0 auto 32px; }

.role-cards {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 40px 32px;
}
.role-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 240px;
  text-align: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.04);
}
.role-card .emoji { font-size: 40px; }
.role-card h3 { margin: 12px 0 6px; }
.role-card p { color: var(--muted); font-size: 14px; margin-bottom: 16px; }

/* ---------- AUTH FORMS ---------- */
.auth-wrap {
  min-height: calc(100vh - 66px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 4px 20px rgba(0,0,0,.05);
}
.card h2 { margin-top: 0; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}
.role-select {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}
.role-option {
  flex: 1 1 30%;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
.role-option.active { border-color: var(--primary); background: #eff6ff; color: var(--primary); }
.hidden { display: none !important; }
.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }
.muted-link { text-align: center; margin-top: 16px; font-size: 14px; color: var(--muted); }

/* ---------- DASHBOARD ---------- */
.dash-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: calc(100vh - 66px);
}
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--card);
  padding: 20px;
  overflow-y: auto;
}
.sidebar h3 { margin-top: 0; }
#map { width: 100%; height: 100%; }

.status-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 18px;
}
.switch {
  position: relative;
  width: 46px;
  height: 26px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #cbd5e1; border-radius: 26px; transition: .2s;
}
.slider:before {
  content: ""; position: absolute; height: 20px; width: 20px;
  left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: .2s;
}
input:checked + .slider { background: var(--success); }
input:checked + .slider:before { transform: translateX(20px); }

.provider-card, .request-card, .trip-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  background: #fff;
}
.provider-card .name, .request-card .name { font-weight: 700; }
.provider-card .meta, .request-card .meta { font-size: 13px; color: var(--muted); margin: 4px 0 10px; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--primary);
  margin-left: 6px;
  text-transform: uppercase;
}
.badge-pending { background: #fffbeb; color: var(--warn); }
.badge-accepted { background: #f0fdf4; color: var(--success); }

.empty-state { color: var(--muted); font-size: 14px; text-align: center; padding: 30px 10px; }

.provider-details, .patient-details {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 10px 0;
}
.provider-details .line, .patient-details .line {
  font-size: 13px;
  padding: 3px 0;
}
.provider-details .line b, .patient-details .line b {
  color: var(--muted);
  font-weight: 600;
  margin-right: 6px;
}

.route-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
}
.route-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.route-dot.from { background: var(--primary); }
.route-dot.to { background: var(--danger); }
.route-lines { flex: 1; }
.route-lines .line { font-size: 13px; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.route-lines .line:last-child { border-bottom: none; }
.route-lines .line b { color: var(--muted); font-weight: 600; margin-right: 6px; }

.top-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 24px; background: var(--card); border-bottom: 1px solid var(--border);
}
.top-bar .user-chip { font-weight: 700; }
.top-bar .user-chip .role-tag {
  font-size: 11px; background: #eff6ff; color: var(--primary);
  padding: 2px 8px; border-radius: 999px; margin-left: 8px; text-transform: capitalize;
}

/* ---------- ADMIN DASHBOARD ---------- */
.admin-wrap { padding: 24px 32px; max-width: 1400px; margin: 0 auto; }

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  padding: 12px 18px;
  border: none;
  background: none;
  font-weight: 700;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.stat-card .value { font-size: 28px; font-weight: 800; color: var(--primary); }
.stat-card .label { font-size: 13px; color: var(--muted); margin-top: 4px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar select, .toolbar input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.toolbar input { flex: 1; min-width: 200px; }

.data-table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th {
  text-align: left; padding: 12px 14px; background: #f8fafc;
  color: var(--muted); font-weight: 700; white-space: nowrap; border-bottom: 1px solid var(--border);
}
table.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data-table tr:last-child td { border-bottom: none; }

.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; }
.tag-role-patient { background: #eff6ff; color: #2563eb; }
.tag-role-doctor { background: #f0fdf4; color: #16a34a; }
.tag-role-nurse { background: #fdf4ff; color: #a21caf; }
.tag-role-admin { background: #fff7ed; color: #c2410c; }
.tag-ok { background: #f0fdf4; color: #16a34a; }
.tag-banned { background: #fef2f2; color: #dc2626; }
.tag-restricted { background: #fffbeb; color: #f59e0b; }
.tag-unverified { background: #f3f4f6; color: #6b7280; }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions .btn { padding: 6px 10px; font-size: 12px; }

.detail-toggle { cursor: pointer; color: var(--primary); font-size: 12px; font-weight: 700; }
.detail-row td { background: #f8fafc; font-size: 12px; }

#adminMap { width: 100%; height: 560px; border-radius: var(--radius); border: 1px solid var(--border); }

/* ---------- LIVE TRACKING BAR ---------- */
.tracking-bar {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.tracking-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}
.tracking-track {
  position: relative;
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  margin: 4px 0 10px;
}
.tracking-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--success), #4ade80);
  border-radius: 999px;
  transition: width 0.6s ease;
}
.tracking-icon {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px;
  transition: left 0.6s ease;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.25));
}
.tracking-status {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.tracking-status.arrived { color: var(--success); }
.tracking-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.location-permission-card {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  text-align: center;
}
.location-permission-card p { font-size: 13px; color: var(--muted); margin: 6px 0 12px; }

/* ---------- CHAT ---------- */
.chat-box {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin: 14px 0;
  background: #fff;
}
.chat-header { background: #f8fafc; padding: 10px 14px; font-weight: 700; font-size: 13px; border-bottom: 1px solid var(--border); }
.chat-messages {
  height: 200px;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg { max-width: 78%; }
.chat-msg.mine { align-self: flex-end; text-align: right; }
.chat-msg.theirs { align-self: flex-start; }
.chat-bubble {
  display: inline-block;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.4;
  word-break: break-word;
}
.chat-msg.mine .chat-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.theirs .chat-bubble { background: #f1f5f9; color: var(--text); border-bottom-left-radius: 4px; }
.chat-time { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.chat-input-row { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat-input-row input {
  flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: 20px; font-size: 13.5px;
}
.chat-input-row button { padding: 9px 16px; font-size: 13px; border-radius: 20px; }

/* ---------- HISTORY ---------- */
.history-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  font-size: 13px;
}
.history-item .hi-top { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 4px; }
.history-item .hi-meta { color: var(--muted); font-size: 12px; }

/* ---------- FIND COVER (provider searching another provider) ---------- */
.cover-search {
  background: #fdf4ff;
  border: 1px solid #f3d9fb;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 18px;
}
.cover-search h4 { margin: 0 0 8px; font-size: 14px; }
.cover-search select { width: 100%; margin-bottom: 8px; }

.tag-role-pharmacist { background: #fff7ed; color: #c2410c; }
.tag-role-labtech { background: #ecfeff; color: #0e7490; }

.role-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.role-tabs button {
  flex: 1; padding: 9px; border-radius: 8px; border: 1px solid var(--border);
  background: #fff; font-weight: 700; font-size: 12.5px; cursor: pointer; color: var(--muted);
}
.role-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

@media (max-width: 860px) {
  .dash-layout { grid-template-columns: 1fr; grid-template-rows: 45vh 1fr; }
}

/* ===================================================================
   DARK MODE — purely additive. Nothing above this line is touched.
   Activated by setting <html data-theme="dark">, toggled from the new
   Settings tab and persisted in localStorage (a UI preference, kept
   separate from the sessionStorage-based auth session).
=================================================================== */
html[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-dark: #60a5fa;
  --success: #22c55e;
  --danger: #f87171;
  --warn: #fbbf24;
  --bg: #0f172a;
  --card: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
}
html[data-theme="dark"] body { background: var(--bg); color: var(--text); }
html[data-theme="dark"] .navbar,
html[data-theme="dark"] .top-bar,
html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .card,
html[data-theme="dark"] .data-table-wrap,
html[data-theme="dark"] .provider-card,
html[data-theme="dark"] .request-card,
html[data-theme="dark"] .trip-card,
html[data-theme="dark"] .history-item,
html[data-theme="dark"] .chat-box,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .chat-header {
  background: var(--card);
  border-color: var(--border);
  color: var(--text);
}
html[data-theme="dark"] .status-toggle,
html[data-theme="dark"] .route-bar,
html[data-theme="dark"] .tracking-bar,
html[data-theme="dark"] table.data-table th,
html[data-theme="dark"] .detail-row td,
html[data-theme="dark"] .chat-msg.theirs .chat-bubble {
  background: #16213a;
  border-color: var(--border);
  color: var(--text);
}
html[data-theme="dark"] .field input,
html[data-theme="dark"] .field select,
html[data-theme="dark"] .field textarea,
html[data-theme="dark"] .toolbar input,
html[data-theme="dark"] .toolbar select,
html[data-theme="dark"] .cover-search select,
html[data-theme="dark"] .chat-input-row input {
  background: #16213a;
  border-color: var(--border);
  color: var(--text);
}
html[data-theme="dark"] table.data-table td { border-color: var(--border); }
html[data-theme="dark"] .location-permission-card { background: #16213a; border-color: var(--border); }
html[data-theme="dark"] .cover-search { background: #241a2e; border-color: #3d2a4d; }
html[data-theme="dark"] .provider-details,
html[data-theme="dark"] .patient-details { background: #16213a; border-color: var(--border); }
html[data-theme="dark"] .tab-btn { color: var(--muted); }
html[data-theme="dark"] .role-option { border-color: var(--border); color: var(--text); }
html[data-theme="dark"] .role-option.active { background: #16213a; }

/* ---------- MEDICAL RECORDS (additive only) ---------- */
.records-box {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin: 14px 0;
  background: #fff;
}
.records-list { max-height: 260px; overflow-y: auto; padding: 12px 14px; }
.record-section { font-size: 12.5px; margin-top: 6px; line-height: 1.5; }
.record-section ul { margin: 2px 0 0 18px; padding: 0; }
.records-form { padding: 12px 14px; border-top: 1px solid var(--border); }
.records-form .field { margin-bottom: 10px; }
.records-form textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; font-family: inherit; resize: vertical;
}

html[data-theme="dark"] .records-box,
html[data-theme="dark"] .record-section { background: var(--card); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .records-form { border-color: var(--border); }
html[data-theme="dark"] .records-form textarea { background: #16213a; border-color: var(--border); color: var(--text); }
