:root {
  --red: #b50920;
  --red-dark: #7d0718;
  --ink: #201d1d;
  --muted: #6d6663;
  --paper: #fffdf9;
  --canvas: #f3f1ed;
  --line: #ded8d1;
  --green: #18794e;
  --amber: #9a6700;
  --blue: #155b8f;
  --unknown: #68717b;
  --shadow: 0 18px 50px rgba(38, 25, 22, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body { min-height: 100vh; margin: 0; background: var(--canvas); }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.login-shell {
  min-height: 100vh;
  display: grid;
  align-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 90% 8%, rgba(181, 9, 32, .14), transparent 34%),
    linear-gradient(150deg, #f8f6f2 0%, #ece8e1 100%);
}

.login-card { width: min(100%, 540px); margin: 0 auto; padding: 34px; background: rgba(255, 253, 249, .94); border: 1px solid rgba(181, 9, 32, .12); border-radius: 28px; box-shadow: var(--shadow); }
.brand-mark { display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: 36px; border-radius: 17px; color: #fff; background: var(--red); font-weight: 900; font-size: 28px; box-shadow: 0 9px 24px rgba(181, 9, 32, .25); }
.brand-mark-wide { width: auto; min-width: 82px; padding: 0 13px; font-size: 19px; letter-spacing: .06em; }
.eyebrow { margin: 0 0 7px; color: var(--red); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.login-card h1 { margin: 0; font-size: clamp(42px, 11vw, 68px); line-height: .97; letter-spacing: -.055em; }
.login-copy { margin: 25px 0 30px; color: var(--muted); font-size: 18px; line-height: 1.55; }
.privacy-note { margin: 22px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }

.button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border: 1px solid transparent; border-radius: 12px; color: var(--ink); background: transparent; font-weight: 750; text-decoration: none; cursor: pointer; }
.button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid rgba(21, 91, 143, .32); outline-offset: 2px; }
.button-primary { color: #fff; background: var(--red); box-shadow: 0 8px 20px rgba(181, 9, 32, .19); }
.button-primary:hover { background: var(--red-dark); }
.button-secondary { border-color: var(--line); background: var(--paper); }
.button-quiet { min-height: 38px; padding: 8px 12px; color: var(--muted); border-color: var(--line); }
.button-wide { width: 100%; min-height: 54px; }
.button[disabled] { opacity: .55; cursor: wait; }

.topbar { position: sticky; z-index: 10; top: 0; display: flex; align-items: center; justify-content: space-between; min-height: 72px; padding: max(12px, env(safe-area-inset-top)) max(18px, calc((100vw - 1100px) / 2)) 12px; border-bottom: 1px solid rgba(222, 216, 209, .9); background: rgba(243, 241, 237, .90); backdrop-filter: blur(18px); }
.topbar strong { display: block; font-size: 15px; }
.topbar small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.topbar .eyebrow { margin-bottom: 2px; font-size: 10px; }
.app-shell { width: min(100%, 1100px); margin: 0 auto; padding: 28px 18px max(70px, env(safe-area-inset-bottom)); }
.app-nav { display: inline-flex; gap: 5px; padding: 5px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.65); }
.nav-button { min-height: 40px; padding: 8px 15px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; font-weight: 800; cursor: pointer; }
.nav-button.active { color: #fff; background: var(--ink); box-shadow: 0 5px 16px rgba(32,29,29,.16); }
.app-view[hidden] { display: none; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; padding: 18px 2px 26px; }
.hero h1 { margin: 0 0 7px; font-size: clamp(36px, 8vw, 58px); line-height: 1; letter-spacing: -.045em; }
.muted { margin: 0; color: var(--muted); }
.offline-banner { margin-bottom: 18px; padding: 13px 15px; border: 1px solid #ddbd63; border-radius: 12px; color: #664400; background: #fff5cf; font-size: 14px; }
.route-list { display: grid; gap: 20px; }
.route-card { overflow: hidden; border: 1px solid var(--line); border-radius: 22px; background: var(--paper); box-shadow: 0 8px 26px rgba(38, 25, 22, .055); }
.route-head { display: grid; grid-template-columns: 1fr auto; gap: 16px; padding: 22px; border-bottom: 1px solid var(--line); }
.route-head h2 { margin: 0 0 8px; font-size: 25px; line-height: 1.1; letter-spacing: -.025em; }
.route-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; color: var(--muted); font-size: 13px; }
.badge { align-self: start; padding: 6px 9px; border-radius: 999px; color: var(--blue); background: #e8f3fb; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.badge.completed { color: var(--green); background: #e5f5ec; }
.route-note { margin: 16px 22px 0; padding: 13px 15px; border-left: 3px solid var(--red); background: #f8f1f1; color: #534846; font-size: 14px; line-height: 1.5; }
.day { padding: 0 22px; }
.day + .day { border-top: 1px solid var(--line); }
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 0 14px; }
.day-head h3 { margin: 0; font-size: 17px; }
.maps-link { color: var(--blue); font-size: 13px; font-weight: 750; text-decoration: none; }
.stop-list { display: grid; gap: 12px; padding-bottom: 22px; }
.stop { border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.stop summary { display: grid; grid-template-columns: 38px 1fr auto; gap: 12px; align-items: center; min-height: 78px; padding: 13px; cursor: pointer; list-style: none; }
.stop summary::-webkit-details-marker { display: none; }
.stop-number { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; color: #fff; background: var(--ink); font-weight: 850; }
.stop-title { min-width: 0; }
.stop-title strong { display: block; overflow: hidden; margin-bottom: 4px; text-overflow: ellipsis; white-space: nowrap; }
.stop-title small { display: block; color: var(--muted); line-height: 1.35; }
.stop-chevron { color: var(--muted); font-size: 19px; transition: transform .18s ease; }
.stop[open] .stop-chevron { transform: rotate(180deg); }
.stop.completed { border-color: #a9d5ba; background: #f8fdf9; }
.stop.completed .stop-number { background: var(--green); }
.stop.follow_up { border-color: #e4c66e; }
.stop.follow_up .stop-number { background: var(--amber); }
.stop-body { padding: 0 14px 16px 64px; }
.contact-card { margin: 0 0 15px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.contact-card a { color: var(--blue); }
.latest-report { margin-bottom: 15px; padding: 10px 12px; border-radius: 10px; color: var(--green); background: #e9f6ee; font-size: 13px; }
.latest-report.pending { color: var(--amber); background: #fff4cc; }
.report-form { display: grid; gap: 13px; }
.field { display: grid; gap: 6px; }
.field label, .field-label { color: #4d4644; font-size: 12px; font-weight: 800; }
.field input, .field textarea, .field select { width: 100%; min-height: 45px; padding: 10px 12px; border: 1px solid #cbc3bb; border-radius: 10px; color: var(--ink); background: #fff; }
.field textarea { min-height: 92px; resize: vertical; }
.status-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.status-option { position: relative; }
.status-option input { position: absolute; opacity: 0; pointer-events: none; }
.status-option span { display: grid; min-height: 52px; place-items: center; padding: 7px; border: 1px solid #cbc3bb; border-radius: 10px; color: var(--muted); background: #fff; text-align: center; font-size: 12px; font-weight: 750; }
.status-option input:checked + span { border-color: var(--red); color: var(--red); background: #fff0f2; box-shadow: inset 0 0 0 1px var(--red); }
.photo-input { padding: 14px !important; border-style: dashed !important; background: #faf8f4 !important; }
.form-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 2px; }
.form-hint { color: var(--muted); font-size: 11px; line-height: 1.35; }
.empty-state { padding: 54px 24px; border: 1px dashed #c7bfb7; border-radius: 22px; background: rgba(255,255,255,.55); text-align: center; }
.empty-state span { display: grid; width: 52px; height: 52px; margin: 0 auto 16px; place-items: center; border-radius: 50%; color: #fff; background: var(--green); font-size: 24px; }
.empty-state h2 { margin: 0 0 8px; }
.empty-state p { margin: 0 auto; max-width: 520px; color: var(--muted); line-height: 1.5; }
.toast { position: fixed; z-index: 30; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); left: 18px; max-width: 520px; margin-left: auto; padding: 14px 16px; border-radius: 13px; color: #fff; background: #272323; box-shadow: var(--shadow); font-size: 14px; }
.toast.error { background: var(--red-dark); }

.status-hero { padding-bottom: 22px; }
.executive-card { overflow: hidden; margin-bottom: 20px; border: 1px solid var(--line); border-radius: 26px; color: #fff; background: #2e3439; box-shadow: var(--shadow); }
.executive-card.healthy { background: linear-gradient(135deg, #0e6843, #14865a); }
.executive-card.degraded { background: linear-gradient(135deg, #7b5100, #a86f00); }
.executive-card.critical { background: linear-gradient(135deg, #850d20, #b50920); }
.executive-card.unknown { background: linear-gradient(135deg, #414a52, #68717b); }
.executive-state { display: flex; align-items: center; gap: 22px; padding: 30px; }
.executive-state .eyebrow { color: rgba(255,255,255,.72); }
.executive-state h2 { margin: 0 0 7px; font-size: clamp(27px, 5vw, 42px); line-height: 1.05; letter-spacing: -.035em; }
.executive-state p:last-child { margin: 0; color: rgba(255,255,255,.78); }
.health-orb { display: grid; flex: 0 0 auto; width: 72px; height: 72px; place-items: center; border: 1px solid rgba(255,255,255,.26); border-radius: 50%; background: rgba(255,255,255,.13); }
.health-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 4px rgba(255,255,255,.16); }
.health-orb .health-dot { width: 25px; height: 25px; color: #fff; }
.metric-grid { display: grid; grid-template-columns: repeat(5, 1fr); border-top: 1px solid rgba(255,255,255,.18); background: rgba(0,0,0,.09); }
.metric-grid > div { display: grid; gap: 3px; padding: 18px 22px; border-right: 1px solid rgba(255,255,255,.15); }
.metric-grid > div:last-child { border-right: 0; }
.metric-grid strong { font-size: 27px; line-height: 1; }
.metric-grid span { color: rgba(255,255,255,.72); font-size: 11px; font-weight: 750; text-transform: uppercase; letter-spacing: .04em; }
.status-section { margin-bottom: 20px; padding: 22px; border: 1px solid var(--line); border-radius: 22px; background: var(--paper); box-shadow: 0 8px 26px rgba(38,25,22,.045); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.section-head h2 { margin: 0; font-size: 23px; letter-spacing: -.025em; }
.section-count { display: grid; min-width: 35px; height: 35px; place-items: center; border-radius: 99px; color: var(--muted); background: var(--canvas); font-weight: 800; }
.organization-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 11px; }
.organization-card { display: grid; gap: 9px; padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: #fff; }
.organization-card > div { display: flex; align-items: center; gap: 9px; }
.organization-card > span { color: var(--muted); font-size: 13px; }
.organization-card small { color: var(--muted); font-size: 11px; }
.organization-card.healthy .health-dot, .status-marker.healthy, .health-panel.healthy, .source-pill.healthy { color: var(--green); }
.organization-card.degraded .health-dot, .status-marker.degraded, .health-panel.degraded, .source-pill.degraded { color: var(--amber); }
.organization-card.critical .health-dot, .status-marker.critical, .health-panel.critical, .source-pill.critical { color: var(--red); }
.organization-card.unknown .health-dot, .status-marker.unknown, .health-panel.unknown, .source-pill.unknown { color: var(--unknown); }
.site-status-list { display: grid; gap: 8px; }
.site-status-row { display: grid; grid-template-columns: 30px minmax(170px,.8fr) minmax(260px,1.6fr) 20px; gap: 12px; align-items: center; width: 100%; padding: 14px; border: 1px solid var(--line); border-radius: 13px; color: var(--ink); background: #fff; text-align: left; cursor: pointer; }
.site-status-row:hover { border-color: #bbb1a8; box-shadow: 0 5px 16px rgba(38,25,22,.06); }
.status-marker { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 9px; background: currentColor; }
.status-marker .health-dot { width: 8px; height: 8px; color: #fff; }
.site-status-title, .site-status-copy { display: grid; min-width: 0; gap: 3px; }
.site-status-title small, .site-status-copy small { color: var(--muted); font-size: 11px; }
.site-status-copy strong { overflow: hidden; font-size: 13px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.row-chevron { color: var(--muted); font-size: 24px; }
.all-clear { display: flex; align-items: center; gap: 15px; padding: 18px; border-radius: 14px; background: #edf8f1; color: var(--green); }
.all-clear > span { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 50%; color: #fff; background: var(--green); }
.all-clear p { margin: 3px 0 0; color: #4b6757; font-size: 13px; }
.site-detail { margin-top: 16px; padding: 20px; border: 1px solid var(--line); border-radius: 15px; background: #faf8f4; }
.site-detail[hidden] { display: none; }
.detail-summary { margin: 0 0 16px; font-size: 17px; line-height: 1.5; }
.health-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.health-panel { display: flex; align-items: flex-start; gap: 12px; padding: 15px; border: 1px solid var(--line); border-radius: 13px; background: #fff; }
.health-panel .health-dot { margin-top: 5px; flex: 0 0 auto; }
.health-panel p { margin: 4px 0; color: var(--ink); font-size: 13px; line-height: 1.45; }
.health-panel small { color: var(--muted); }
.diagnostic-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(180px,1fr)); gap: 1px; overflow: hidden; margin: 14px 0 0; border: 1px solid var(--line); border-radius: 12px; background: var(--line); }
.diagnostic-grid > div { padding: 12px; background: #fff; }
.diagnostic-grid dt { color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.diagnostic-grid dd { margin: 4px 0 0; overflow-wrap: anywhere; font-size: 13px; }
.site-browser { padding: 0; }
.site-browser > summary { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; cursor: pointer; list-style: none; }
.site-browser > summary::-webkit-details-marker { display: none; }
.site-browser > summary strong { display: block; font-size: 19px; }
.site-browser-body { padding: 0 22px 22px; }
.status-filters { display: grid; grid-template-columns: 1fr 190px; gap: 9px; margin-bottom: 12px; }
.status-filters input, .status-filters select { min-height: 44px; padding: 9px 11px; border: 1px solid #cbc3bb; border-radius: 10px; background: #fff; }
.source-strip { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 5px 3px 15px; }
.source-pills { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.source-pill { display: flex; align-items: center; gap: 7px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 99px; background: var(--paper); font-size: 11px; }
.source-pill small { color: var(--muted); }
.source-pill .health-dot { width: 7px; height: 7px; }
.error-copy { color: var(--red); }
.dispatch-panel { border-color: rgba(21,91,143,.25); background: linear-gradient(145deg,#fffdf9,#f0f7fb); }
.dispatch-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 18px; }
.dispatch-actions .muted { flex: 1 1 220px; font-size: 12px; }
.candidate-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(260px,1fr)); gap: 12px; margin-top: 18px; }
.candidate-card { display: grid; gap: 13px; padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.candidate-card.critical { border-color: rgba(181,9,32,.38); }
.candidate-card.high { border-color: rgba(154,103,0,.38); }
.candidate-head { display: grid; grid-template-columns: 30px minmax(0,1fr) auto; gap: 10px; align-items: center; }
.candidate-head strong,.candidate-head small { display: block; }
.candidate-head small { overflow: hidden; margin-top: 3px; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.candidate-head b { color: var(--blue); font-size: 13px; white-space: nowrap; }
.candidate-card > p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.candidate-actions { display: flex; gap: 8px; }
.candidate-actions .button { flex: 1; }
.dispatch-reason { display: grid; gap: 4px; margin: 0 0 15px; padding: 12px 14px; border-left: 3px solid var(--blue); border-radius: 8px; background: #eef7fc; font-size: 13px; }
.dispatch-reason span,.detail-address { color: var(--muted); }
.detail-address { margin: -7px 0 13px; }

@media (max-width: 620px) {
  .login-card { padding: 28px 23px; border-radius: 22px; }
  .app-shell { padding-inline: 12px; }
  .topbar { padding-inline: 14px; }
  .app-nav { display: flex; position: sticky; z-index: 8; top: 80px; }
  .nav-button { flex: 1; }
  .hero { align-items: center; padding-inline: 5px; }
  .hero h1 { font-size: 40px; }
  .route-head { grid-template-columns: 1fr; padding: 18px; }
  .route-head .badge { justify-self: start; }
  .route-note { margin-inline: 18px; }
  .day { padding-inline: 12px; }
  .stop-body { padding-left: 13px; }
  .status-options { grid-template-columns: 1fr; }
  .status-option span { min-height: 44px; place-items: center start; padding-left: 13px; }
  .form-footer { align-items: stretch; flex-direction: column; }
  .form-footer .button { width: 100%; }
  .executive-state { align-items: flex-start; padding: 23px 19px; }
  .health-orb { width: 54px; height: 54px; }
  .health-orb .health-dot { width: 18px; height: 18px; }
  .metric-grid { grid-template-columns: repeat(2,1fr); }
  .metric-grid > div { border-bottom: 1px solid rgba(255,255,255,.15); }
  .metric-grid > div:first-child { grid-column: 1 / -1; }
  .status-section { padding: 17px 12px; }
  .site-status-row { grid-template-columns: 28px 1fr 18px; }
  .site-status-copy { grid-column: 2 / -1; padding-right: 16px; }
  .health-columns { grid-template-columns: 1fr; }
  .status-filters { grid-template-columns: 1fr; }
  .source-strip { align-items: flex-start; flex-direction: column; }
  .source-pills { justify-content: flex-start; }
  .dispatch-actions { align-items: stretch; flex-direction: column; }
  .dispatch-actions .button { width: 100%; }
  .candidate-actions { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
