/* Davis Vascular Map CRM — brand blue/red on white; restrained accents. */
:root {
  --blue: #204797; --blue-dark: #1D4189; --red: #C2242A; --amber: #D98E04; --teal: #0D74A5;
  --text: #333; --muted: #6b7280; --line: #e3e7ef; --bg: #f4f6fa; --card: #fff;
  --danger: #b91c1c; --warn-bg: #fff7e6; --ok-bg: #eefbf1;
  --header-h: 60px; --phone-nav-h: 60px; --radius: 10px;
  --font: "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body { font-family: var(--font); color: var(--text); background: var(--bg); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; overflow-x: hidden; }
a { color: var(--blue); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; color: var(--blue-dark); }
h2 { font-size: 1.1rem; margin: 1rem 0 .5rem; color: var(--blue-dark); }
p { margin: .4rem 0; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .warn { color: var(--amber); font-weight: 600; }
img { max-width: 100%; height: auto; }

/* Header and navigation */
.app-header { height: var(--header-h); background: var(--card); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 16px; position: sticky; top: 0; z-index: 20; }
.brand img { height: 40px; width: auto; display: block; }
.prototype-tag { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--red); border: 1px solid var(--red); border-radius: 4px; padding: 2px 6px; }
.nav-desktop { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.nav-desktop a { text-decoration: none; color: var(--blue-dark); padding: 8px 12px; border-radius: 8px; font-weight: 600; }
.nav-desktop a.active, .nav-desktop a:hover { background: #e8eef9; }
.account-menu { position: relative; }
.account-menu summary { list-style: none; cursor: pointer; padding: 8px 12px; border-radius: 8px; font-weight: 600; color: var(--blue-dark); }
.account-menu summary::-webkit-details-marker { display: none; }
.account-menu .menu { position: absolute; right: 0; top: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px; min-width: 200px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.nav-phone { display: none; }
@media (max-width: 767px) {
  .nav-desktop { display: none; }
  .brand img { height: 32px; }
  .nav-phone { display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--phone-nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line); z-index: 20; }
  .nav-phone a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: .75rem; font-weight: 600; }
  .nav-phone a.active { color: var(--blue); }
  .nav-phone .glyph { font-size: 1.2rem; line-height: 1; }
  main.container { padding-bottom: calc(var(--phone-nav-h) + 24px); }
}
.offline-banner { background: var(--amber); color: #fff; text-align: center; padding: 6px 12px; font-weight: 600; }

/* Layout */
.container { max-width: 960px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card.narrow { max-width: 680px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.breadcrumb { margin-bottom: 8px; font-size: .9rem; }
.flashes { max-width: 960px; margin: 12px auto 0; padding: 0 16px; }
.flash { padding: 10px 12px; border-radius: 8px; margin-bottom: 8px; border: 1px solid var(--line); background: var(--card); }
.flash-success { background: var(--ok-bg); border-color: #b7e4c7; } .flash-error { background: #fdecec; border-color: #f5b5b5; } .flash-warning { background: var(--warn-bg); border-color: #f3d79b; }
.flash ul { margin: 0; padding-left: 18px; }

/* Buttons and forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 8px; padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 40px; line-height: 1.2; }
.btn-primary { background: var(--blue); color: #fff; } .btn-primary:hover { background: var(--blue-dark); }
.btn-secondary { background: #fff; color: var(--blue-dark); border-color: #c5cfe6; } .btn-secondary:hover { background: #eef2fb; }
.btn-danger { background: #fff; color: var(--danger); border-color: #f0b4b4; }
.btn-link { background: none; color: var(--blue); padding: 6px 8px; min-height: 32px; }
.btn-block { width: 100%; } .btn-lg { padding: 14px 18px; font-size: 1.05rem; } .btn.small { padding: 6px 10px; min-height: 32px; font-size: .85rem; }
.btn-icon { width: 40px; padding: 0; background: #fff; border-color: #c5cfe6; color: var(--blue-dark); }
.btn:disabled { opacity: .45; cursor: default; }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
input, select, textarea { font: inherit; padding: 9px 10px; border: 1px solid #c9d1e0; border-radius: 8px; width: 100%; background: #fff; color: var(--text); min-height: 40px; }
textarea { min-height: 64px; resize: vertical; }
label { display: block; font-size: .9rem; font-weight: 600; color: #3b4252; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
.form-stack { display: grid; gap: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } .form-grid .span-2 { grid-column: 1 / -1; }
.form-inline { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; } .form-inline label { flex: 1 1 180px; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }
fieldset { border: 0; padding: 0; margin: 0; } legend { font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
.radio-row { display: flex; align-items: center; gap: 8px; font-weight: 500; padding: 4px 0; } .radio-row input { width: auto; min-height: 0; margin: 0; }
.check-row { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; } .check-row input { width: auto; min-height: 0; margin-top: 4px; }
.indent { padding-left: 24px; display: grid; gap: 8px; }
.form-error { color: var(--danger); background: #fdecec; border: 1px solid #f5b5b5; border-radius: 8px; padding: 8px 10px; margin: 8px 0; }
.panel { background: #f8faff; border: 1px solid #dbe3f5; border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.danger-zone { margin-top: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Badges, chips */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #eef1f7; color: #3b4252; vertical-align: middle; }
.badge-demo { background: #fff1d6; color: #8a5a00; border: 1px dashed #d9a441; letter-spacing: .03em; }
.badge-warn { background: var(--warn-bg); color: #8a5a00; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; border: 1px solid transparent; box-sizing: content-box; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid #c9d1e0; background: #fff; color: #3b4252; border-radius: 999px; padding: 5px 10px; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; min-height: 32px; }
.chip[aria-pressed="true"], .chip-toggle:has(input:checked) { background: var(--blue); color: #fff; border-color: var(--blue); }
.chip-static { cursor: default; background: #f1f4fa; border-color: transparent; padding: 2px 8px; min-height: 0; font-weight: 500; }
.chip-toggle input { width: auto; min-height: 0; margin: 0; position: absolute; opacity: 0; }
.chip-toggle { position: relative; }
.icon { flex: none; }
.davis-swatch { width: 10px; height: 10px; background: var(--blue); transform: rotate(45deg); display: inline-block; border: 1.5px solid #fff; outline: 1px solid var(--blue); }

/* Explore */
.filters-drawer > summary { display: none; }
.filters-drawer > .controls-row { margin-top: 6px; }
@media (max-width: 767px) {
  .filters-drawer > summary { display: list-item; cursor: pointer; font-weight: 700; color: var(--blue-dark); padding: 4px 0; }
}
body.page-explore { height: 100%; overflow: hidden; }
main.explore { display: flex; flex-direction: column; height: calc(100% - var(--header-h)); }
.explore-controls { background: var(--card); border-bottom: 1px solid var(--line); padding: 8px 16px; display: grid; gap: 6px; }
.controls-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#search { max-width: 320px; flex: 1 1 200px; }
.explore-body { flex: 1; display: grid; grid-template-columns: 400px 1fr; min-height: 0; }
.list-pane { overflow-y: auto; border-right: 1px solid var(--line); background: var(--card); }
.map-pane { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }
.map-missing { position: absolute; left: 12px; right: 12px; top: 12px; background: #fdecec; border: 1px solid #f5b5b5; border-radius: 8px; padding: 10px; z-index: 5; }
.clinic-list { list-style: none; margin: 0; padding: 0; }
.clinic-card { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.clinic-card:hover { background: #f6f8fd; } .clinic-card.selected { background: #e8eef9; box-shadow: inset 4px 0 0 var(--blue); }
.clinic-card-body { min-width: 0; flex: 1; }
.clinic-name { font-weight: 700; color: var(--blue-dark); text-decoration: none; word-break: break-word; }
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; } .card-actions { display: flex; gap: 4px; margin-top: 2px; margin-left: -8px; }
.pin-dot { width: 26px; height: 26px; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; flex: none; margin-top: 2px; border: 1.5px solid transparent; box-sizing: border-box; }
.empty-state { padding: 24px 16px; text-align: center; }
.view-toggle { display: none; }
.legend { position: absolute; left: 12px; bottom: 12px; background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: .8rem; z-index: 5; max-width: 260px; }
.legend summary { cursor: pointer; font-weight: 700; color: var(--blue-dark); }
.legend-section { display: grid; gap: 3px; padding: 6px 0; border-top: 1px solid var(--line); } .legend-row { display: flex; align-items: center; gap: 6px; }
.pin-sample { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1.5px solid transparent; box-sizing: content-box; } .pin-sample.selected { outline: 3px solid #111; outline-offset: 1px; }
.davis-sample { width: 14px; height: 14px; background: var(--blue); transform: rotate(45deg); display: inline-flex; align-items: center; justify-content: center; color: #fff; border: 1.5px solid #fff; outline: 1.5px solid var(--blue-dark); margin: 0 2px; }
.davis-sample svg { transform: rotate(-45deg); }
.legend-note { padding-top: 6px; border-top: 1px solid var(--line); }
.pin { background: none; border: 0; padding: 0; cursor: pointer; width: 30px; height: 40px; position: relative; display: block; }
.pin-head { position: absolute; left: 0; top: 0; width: 30px; height: 30px; border-radius: 50%; background: var(--pin-color); color: var(--pin-ink, #fff); display: flex; align-items: center; justify-content: center; border: 2px solid var(--pin-edge, #fff); box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.pin-tail { position: absolute; left: 50%; bottom: 2px; width: 0; height: 0; margin-left: -6px; border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 10px solid var(--pin-color); }
.pin.selected .pin-head { outline: 3px solid #111; outline-offset: 1px; transform: scale(1.1); z-index: 2; }
.pin:hover .pin-head, .pin:focus-visible .pin-head { outline: 2px solid #111; outline-offset: 1px; }
.davis-marker { background: none; border: 0; padding: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.davis-shape { width: 24px; height: 24px; background: var(--blue); transform: rotate(45deg); border: 2px solid #fff; outline: 2px solid var(--blue-dark); display: flex; align-items: center; justify-content: center; color: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.davis-shape svg { transform: rotate(-45deg); }
.davis-label { font-size: .7rem; font-weight: 700; color: var(--blue-dark); background: rgba(255,255,255,.9); padding: 0 4px; border-radius: 4px; white-space: nowrap; }
.mapboxgl-popup-content { font-family: var(--font); padding: 12px 14px; border-radius: 10px; }
.popup .popup-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; } .popup .eyebrow { font-size: .7rem; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.dialog { border: 0; border-radius: 12px; padding: 20px; width: min(420px, 92vw); box-shadow: 0 16px 48px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(10,20,40,.45); }
.dialog h2 { margin-top: 0; } .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.radio-list { display: grid; gap: 2px; max-height: 40vh; overflow-y: auto; }
.toast { position: fixed; left: 50%; bottom: calc(var(--phone-nav-h) + 16px); transform: translateX(-50%); background: #1f2937; color: #fff; padding: 10px 14px; border-radius: 8px; z-index: 50; max-width: 92vw; }
.toast a { color: #cfe0ff; }
@media (min-width: 768px) { .toast { bottom: 24px; } }
@media (max-width: 767px) {
  .explore-body { grid-template-columns: 1fr; }
  .explore-body.view-list .map-pane { display: none; }
  .explore-body.view-map .list-pane { display: none; }
  .list-pane { border-right: 0; padding-bottom: calc(var(--phone-nav-h) + 8px); }
  .map-pane { padding-bottom: 0; }
  .legend { bottom: calc(var(--phone-nav-h) + 12px); max-width: 200px; } .legend[open] .legend-section:nth-of-type(2) { display: none; }
  .view-toggle { display: flex; background: var(--card); border-bottom: 1px solid var(--line); }
  .view-toggle button { flex: 1; border: 0; background: none; font: inherit; font-weight: 700; padding: 10px; color: var(--muted); border-bottom: 3px solid transparent; }
  .view-toggle button[aria-selected="true"] { color: var(--blue); border-bottom-color: var(--blue); }
  .explore-controls { padding: 8px 12px; } #search { max-width: none; }
  main.explore { height: calc(100% - var(--header-h)); }
}

/* Clinic detail */
.detail-header h1 { display: inline; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
.facts { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 12px 0; }
.facts dt { font-weight: 700; color: #3b4252; } .facts dd { margin: 0; word-break: break-word; }
@media (max-width: 600px) { .facts { grid-template-columns: 1fr; gap: 2px; } .facts dd { margin-bottom: 8px; } }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.timeline-item { position: relative; padding: 0 0 14px 16px; }
.timeline-item::before { content: ""; position: absolute; left: -7px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--blue); border: 2px solid #fff; }
.timeline-item.kind-stop_outcome::before { background: var(--teal); } .timeline-item.kind-relationship_change::before { background: var(--amber); } .timeline-item.kind-listing_edit::before { background: #9aa3b5; }
.timeline-note { margin: 2px 0; white-space: pre-wrap; }

/* Plans */
.plan-cards { list-style: none; margin: 0; padding: 0; } .plan-title { text-decoration: none; } .plan-title h2 { margin: 0 0 4px; }
.progress { margin: 10px 0; } .progress-bar { height: 10px; background: #e5e9f2; border-radius: 999px; overflow: hidden; } .progress-fill { height: 100%; background: var(--blue); transition: width .3s; }
.progress-text { font-size: .9rem; margin-top: 4px; }
.stop-list { list-style: none; margin: 0; padding: 0; }
.stop { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.stop-main { display: flex; gap: 10px; min-width: 0; flex: 1; } .stop .name { font-weight: 700; text-decoration: none; color: var(--blue-dark); }
.pos { width: 28px; height: 28px; border-radius: 50%; background: var(--blue); color: #fff; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.status-visited .pos { background: #2f855a; } .status-skipped .pos { background: #9aa3b5; }
.stop-actions { display: flex; gap: 4px; align-items: flex-start; flex: none; } .btn-remove { color: var(--danger); }
.stop-note-row { display: flex; gap: 4px; align-items: center; margin-top: 6px; max-width: 460px; } .stop-note-input { min-height: 34px; padding: 5px 8px; font-size: .9rem; }
.stop-status { font-weight: 600; }

/* Run (phone execution) */
.run-head { margin-bottom: 12px; }
.next-stop { border: 2px solid var(--blue); }
.eyebrow { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--red); font-weight: 700; }
.next-stop h2 { margin: 4px 0; font-size: 1.3rem; } .next-stop h2 a { text-decoration: none; }
address { font-style: normal; margin: 6px 0; font-size: 1.05rem; }
.arrival { background: var(--warn-bg); padding: 8px 10px; border-radius: 8px; }
.context-list { padding-left: 18px; margin: 6px 0; } .context summary { cursor: pointer; font-weight: 600; color: var(--blue-dark); }
.outcome-form { margin-top: 12px; } .outcome-buttons { display: flex; gap: 8px; flex-wrap: wrap; } .outcome-buttons .btn-lg { flex: 1 1 140px; }
.run-stops { list-style: none; margin: 0; padding: 0; }
.run-stop { display: flex; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: center; }
.run-stop-main { display: flex; gap: 10px; align-items: center; min-width: 0; } .run-stop .name { font-weight: 600; }
.run-stop.is-next { background: #f3f6fd; margin: 0 -8px; padding: 10px 8px; border-radius: 8px; }
.run-stop.status-visited .name, .run-stop.status-skipped .name { color: var(--muted); }
.finished { background: var(--ok-bg); }

/* Login */
.login-main { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px 24px; width: min(420px, 100%); box-shadow: 0 12px 36px rgba(32,71,151,.08); }
.login-logo { width: 100%; max-width: 320px; display: block; margin: 0 auto 16px; }
.login-card h1 { text-align: center; } .login-card p { text-align: center; }

/* Print view */
.print-page { background: #fff; padding: 24px; max-width: 760px; margin: 0 auto; font-size: 13px; }
.print-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.print-logo { height: 44px; width: auto; }
.print-head { border-bottom: 2px solid var(--blue); padding-bottom: 8px; margin-bottom: 12px; }
.print-stops { padding-left: 22px; } .print-stops li { margin-bottom: 10px; break-inside: avoid; }
.print-name { font-weight: 700; font-size: 14px; } .print-demo { color: #8a5a00; font-weight: 400; } .print-status { color: var(--muted); }
.print-note { font-style: italic; } .print-foot { margin-top: 20px; color: var(--muted); font-size: 11px; }
@media print {
  .no-print, .app-header, .nav-phone, .flashes, .offline-banner { display: none !important; }
  body { background: #fff; } .print-page { padding: 0; max-width: none; }
  a { color: inherit; text-decoration: none; }
}
