/* ============================================================
   AfriRescue CRM - Ambulance Dispatch Centre (SA)
   ============================================================ */
:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --ink: #0f172a;
  --ink-soft: #475569;
  --line: #e2e8f0;
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --accent: #e11d48;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 4px 14px rgba(15,23,42,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #eef2f7; color: var(--ink); font-size: 14px; line-height: 1.45;
}
.hidden { display: none !important; }
a { color: var(--primary); cursor: pointer; }
button { font-family: inherit; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid transparent; border-radius: 8px; padding: 8px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: .15s; white-space: nowrap; line-height: 1.2;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(.95); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { background: var(--panel-2); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-ok:hover { filter: brightness(.95); }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }
.btn .ic { font-style: normal; }

/* ---------------- Login ---------------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% 10%, #134e4a, var(--bg));
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 420px; background: var(--panel); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35); padding: 30px;
}
.login-logo { display: flex; gap: 14px; align-items: center; margin-bottom: 22px; }
.cross {
  width: 46px; height: 46px; border-radius: 10px; background: var(--accent);
  color: #fff; font-size: 30px; font-weight: 800; display: flex; align-items: center;
  justify-content: center; flex: none; line-height: 1;
}
.login-logo h1 { margin: 0; font-size: 22px; letter-spacing: .3px; }
.login-logo h1 span { color: var(--primary); }
.login-logo p { margin: 2px 0 0; color: var(--ink-soft); font-size: 12px; }
.login-form label { display: block; font-size: 12px; font-weight: 700; color: var(--ink-soft); margin: 12px 0 5px; }
.login-form select, .login-form input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; background: #fff; color: var(--ink);
}
.login-form button { margin-top: 18px; }
.login-hint { margin-top: 16px; font-size: 12px; color: var(--ink-soft); }
.welcome-choices { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.demo-role-list { display: flex; flex-direction: column; gap: 8px; }
.demo-role {
  display: block; width: 100%; text-align: left; padding: 12px 14px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
  font: inherit; transition: border-color .15s, background .15s;
}
.demo-role:hover, .demo-role:focus-visible { border-color: var(--primary); background: #f1f5f9; outline: none; }
.demo-role:disabled { opacity: .6; cursor: wait; }
.demo-role strong { display: block; font-size: 14px; }
.demo-role span { display: block; font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.login-form hr { border: none; border-top: 1px solid var(--line); margin: 20px 0 4px; }

/* ---------------- Shell layout ---------------- */
#shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex: none; background: var(--bg); color: #cbd5e1;
  display: flex; flex-direction: column; padding: 16px 12px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 18px; border-bottom: 1px solid #1e293b; }
.brand .cross { width: 38px; height: 38px; font-size: 24px; }
.brand .cross.has-logo { width: auto; min-width: 38px; max-width: 96px; padding: 3px; background: #fff; }
.brand .cross.has-logo img { max-height: 32px; max-width: 90px; object-fit: contain; display: block; }
.brand strong { display: block; color: #fff; font-size: 16px; }
.brand span { font-size: 11px; color: #94a3b8; }
.nav-section-label {
  font-size: 11px;
  text-transform: uppercase;
  color: #64748b;
  margin: 16px 0 4px 12px;
  font-weight: 700;
  letter-spacing: .05em;
}

.nav { flex: 1; margin-top: 14px; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: #cbd5e1; cursor: pointer; font-weight: 600; font-size: 13px; border: none;
  background: transparent; text-align: left; width: 100%;
}
.nav-item:hover { background: #1e293b; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .n-ic { width: 18px; text-align: center; font-style: normal; }
.nav-item .n-badge {
  margin-left: auto; background: var(--accent); color: #fff; font-size: 11px;
  border-radius: 20px; padding: 1px 8px; font-weight: 700;
}
.sidebar-footer { padding-top: 12px; border-top: 1px solid #1e293b; }
.clock { font-variant-numeric: tabular-nums; font-size: 12px; color: #94a3b8; text-align: center; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: #fff; border-bottom: 1px solid var(--line); padding: 14px 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar h2 { margin: 0; font-size: 19px; }
.topbar p { margin: 2px 0 0; color: var(--ink-soft); font-size: 12px; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.sync-badge { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: #e0f2fe; color: #0369a1; white-space: nowrap; }
.sync-badge.sync-offline { background: #ffedd5; color: #c2410c; }
.view { padding: 22px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ---------------- Cards / grids ---------------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px;
}
.card h3 { margin: 0 0 14px; font-size: 15px; }
.card h4 { margin: 0 0 10px; font-size: 13px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .4px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px;
}
.kpi .k-label { font-size: 12px; color: var(--ink-soft); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.kpi .k-value { font-size: 26px; font-weight: 800; margin-top: 4px; }
.kpi .k-sub { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.kpi .k-value.accent { color: var(--accent); }
.kpi .k-value.ok { color: var(--ok); }
.kpi .k-value.warn { color: var(--warn); }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--panel-2); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-soft); white-space: nowrap; }
tr:hover td { background: #f8fafc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.billing td.num { white-space: nowrap; }
.muted { color: var(--ink-soft); }
.small { font-size: 12px; }
.strong { font-weight: 700; }

/* ---------------- Badges ---------------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-red, .badge-LOGGED { background: #fee2e2; color: #b91c1c; }
.badge-orange, .badge-DISPATCHED, .badge-EN_ROUTE { background: #ffedd5; color: #c2410c; }
.badge-yellow, .badge-ON_SCENE, .badge-TRANSPORTING { background: #fef9c3; color: #a16207; }
.badge-green, .badge-AT_HOSPITAL, .badge-COMPLETED { background: #dcfce7; color: #15803d; }
.badge-blue, .badge-REVIEWED { background: #dbeafe; color: #1d4ed8; }
.badge-slate, .badge-CLOSED { background: #e2e8f0; color: #475569; }
.badge-CANCELLED { background: #f1f5f9; color: #64748b; }
.badge-gray { background: #e2e8f0; color: #475569; }
.badge-cyan { background: #ccfbf1; color: #0f766e; }
.badge-violet { background: #ede9fe; color: #6d28d9; }
.role-badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 800;
  background: #ccfbf1; color: #0f766e; text-transform: uppercase; letter-spacing: .5px;
}
.role-calltaker { background: #dcfce7; color: #15803d; }
.role-dispatcher { background: #ffedd5; color: #c2410c; }
.role-multidispatch { background: #fef9c3; color: #a16207; }
.role-crew { background: #dbeafe; color: #1d4ed8; }
.role-casemanager { background: #ede9fe; color: #6d28d9; }
.role-manager { background: #fee2e2; color: #b91c1c; }

/* ---------------- Forms ---------------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--ink-soft); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 13px; font-family: inherit; color: var(--ink); background: #fff;
}
.field textarea { resize: vertical; min-height: 60px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid #99f6e4; border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }

/* Compact data-entry table (RHT vital signs): a real table keeps each header cell
   locked above its field, and these rules give the bare <input>s inside it the same
   look as .field inputs elsewhere in the form. */
.vitals-tbl { table-layout: fixed; }
.vitals-tbl th, .vitals-tbl td { padding: 4px 5px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.vitals-tbl th { font-size: 11px; white-space: normal; }
.vitals-tbl th:first-child, .vitals-tbl td:first-child { width: 22%; }
.vitals-tbl th:last-child, .vitals-tbl td:last-child { width: 28px; padding-left: 2px; }
.vitals-tbl input {
  width: 100%; padding: 6px 7px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 12px; font-family: inherit; color: var(--ink); background: #fff;
}
.vitals-tbl input:focus { outline: 2px solid #99f6e4; border-color: var(--primary); }

/* ---------------- Call cards / timeline ---------------- */
.call-card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; background: #fff; box-shadow: var(--shadow); }
.call-card:hover { border-color: #a5f3fc; }
.call-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.call-head .ref { font-weight: 800; }
.call-title { font-weight: 700; font-size: 14px; margin-top: 8px; }
.call-meta { color: var(--ink-soft); font-size: 12px; margin-top: 4px; }
.call-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 26px; }
.timeline li:before { content: ''; position: absolute; left: 7px; top: 4px; bottom: -2px; width: 2px; background: var(--line); }
.timeline li:last-child:before { display: none; }
.timeline li .dot {
  position: absolute; left: 0; top: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--panel-2); border: 2px solid var(--primary); display: flex; align-items: center; justify-content: center;
}
.timeline li .dot::after { content: ''; width: 5px; height: 5px; border-radius: 50%; background: var(--primary); }
.timeline .t-status { font-weight: 700; font-size: 13px; }
.timeline .t-time { font-size: 11px; color: var(--ink-soft); }
.timeline .t-note { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

/* ---------------- Modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); display: flex;
  align-items: flex-start; justify-content: center; padding: 30px 16px; z-index: 100; overflow: auto;
}
.modal {
  background: #fff; border-radius: 14px; max-width: 860px; width: 100%;
  box-shadow: 0 30px 80px rgba(0,0,0,.4); margin-bottom: 30px;
}
.modal.wide { max-width: 1100px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--ink-soft); line-height: 1; }

/* ---------------- Toast ---------------- */
.toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.3); animation: slideup .2s ease; max-width: 360px;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
.toast.warn { background: var(--warn); }
.toast.update { display: flex; align-items: center; gap: 12px; }
@keyframes slideup { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------- Misc ---------------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab {
  padding: 7px 14px; border-radius: 20px; border: 1px solid var(--line); background: #fff;
  font-size: 12px; font-weight: 700; color: var(--ink-soft); cursor: pointer;
}
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: #fff; padding: 7px 12px; font-size: 12px; font-weight: 700; color: var(--ink-soft); cursor: pointer; }
.seg button.active { background: var(--primary); color: #fff; }
.empty { text-align: center; padding: 34px 10px; color: var(--ink-soft); }
.empty .big { font-size: 34px; }
.chart-bar { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding: 10px 4px 0; border-bottom: 1px solid var(--line); }
.chart-bar .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 5px; min-width: 0; }
.chart-bar .bar {
  width: 100%; max-width: 46px; background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  border-radius: 5px 5px 0 0; min-height: 2px; transition: height .3s;
}
.chart-bar .bar.alt { background: linear-gradient(180deg, var(--accent), #be123c); }
.chart-bar .bar-val { font-size: 10px; color: var(--ink-soft); font-weight: 700; white-space: nowrap; }
.chart-bar .bar-label { font-size: 10px; color: var(--ink-soft); margin-top: 4px; white-space: nowrap; }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filter-bar .field { margin: 0; min-width: 150px; }
.dl { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; font-size: 13px; }
.dl dt { color: var(--ink-soft); font-weight: 600; }
.dl dd { margin: 0; }
.invoice-box { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 20px; }
.invoice-head { display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.invoice-head h2 { margin: 0; color: var(--primary-dark); }
.invoice-meta { font-size: 12px; color: var(--ink-soft); }
.cost-plus-note { font-size: 11px; color: var(--warn); font-weight: 600; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.notice { background: #fefce8; border: 1px solid #fde68a; color: #854d0e; border-radius: 10px; padding: 10px 14px; font-size: 12px; margin-bottom: 14px; }
.ai-chip { background: linear-gradient(90deg, #ccfbf1, #ede9fe); border: 1px solid #99f6e4; color: #0f766e; border-radius: 20px; padding: 2px 10px; font-size: 11px; font-weight: 800; }

/* ---------------- Call taker questionnaire ---------------- */
.q-sec { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); border-bottom: 1px dashed var(--line); padding-bottom: 4px; margin: 12px 0 8px; }
.q-sec:first-child { margin-top: 0; }
.check-row { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; padding: 4px 0; cursor: pointer; }
.check-row input { margin-top: 3px; }

/* ---------------- AI recommendation / heatmap / messaging ---------------- */
.ai-rec { background: linear-gradient(90deg, #f0fdfa, #f5f3ff); border: 1px solid #99f6e4; border-radius: 10px; padding: 8px 12px; font-size: 12px; color: #134e4a; margin-bottom: 8px; }
.bar-track { height: 10px; border-radius: 6px; background: #e2e8f0; overflow: hidden; margin-top: 4px; }
.bar-fill { height: 100%; border-radius: 6px; background: linear-gradient(90deg, #f97316, #dc2626); }
.msg-log { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px; background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 12px; font-size: 13px; }
.msg.mine { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 3px; }
.msg.theirs { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.msg-from { font-size: 10px; font-weight: 800; opacity: .8; margin-bottom: 2px; }
.msg-t { font-size: 10px; opacity: .65; margin-top: 3px; text-align: right; }
.msg-form { display: flex; gap: 8px; align-items: center; }
.msg-form input { flex: 1; }

/* ---------------- Map pins / autocomplete ---------------- */
.unit-pin div { width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 10px; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.unit-pin div span { transform: rotate(45deg); }
.leaflet-container { z-index: 1; }
.autocomplete { position: relative; }
.ac-item { position: absolute; z-index: 50; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; cursor: pointer; font-size: 12px; box-shadow: var(--shadow); width: 100%; margin-top: 4px; }
.ac-item:hover { background: #f0fdfa; }

/* ---------------- Attachments / signature / PCR ---------------- */
.att { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 11px; font-weight: 700; background: #fff; cursor: pointer; max-width: 220px; }
.att:hover { border-color: #a5f3fc; }
.att img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.att-ic { font-size: 14px; }
.sig-wrap { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; background: #fff; }
.sig-wrap canvas { width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; cursor: crosshair; }

.notice.ok { background: #f0fdf4; border-color: #86efac; color: #166534; }
.notice.warn { background: #fff7ed; border-color: #fdba74; color: #9a3412; }
.role-badge { font-size: 11px; font-weight: 800; padding: 3px 10px; border-radius: 20px; }

@media (max-width: 820px) {
  .sidebar { width: 64px; padding: 12px 8px; }
  .brand div:last-child, .nav-item .n-label { display: none; }
  .sidebar-footer { display: none; }
  .view { padding: 14px; }
}
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; inset: 0; margin: 0; padding: 20px; }
  /* A printable modal (e.g. a day's log sheet) prints in full, not just its first screen. */
  .modal-backdrop { position: static; overflow: visible; padding: 0; background: none; }
  .modal { box-shadow: none; max-width: none; }
  body:has(.modal .print-area) #view { display: none; }   /* only the open modal prints, not the report behind it */
  .print-page { break-before: page; page-break-before: always; }
  .no-print { display: none; }
}
