:root {
  --bg: #f1f4f8;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #61708a;
  --line: #dde3ec;
  --brand: #14532d;
  --brand-soft: #dcfce7;
  --accent: #1d4ed8;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --ok: #15803d;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 26, 46, .08), 0 4px 14px rgba(16, 26, 46, .05);
}

* { box-sizing: border-box; }
/* Author `display` rules below outrank the UA stylesheet, so [hidden] needs teeth. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }

/* ---------- gate ---------- */
.gate {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: linear-gradient(160deg, #14532d, #0b3a1f 60%, #082a17);
  z-index: 50; padding: 20px;
}
.gate-card {
  background: #fff; padding: 30px 32px; border-radius: 14px; width: 100%; max-width: 380px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.gate-card h1 { font-size: 21px; color: var(--brand); }
.gate-card p { color: var(--muted); margin: 6px 0 18px; font-size: 13.5px; }
.gate-card input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 8px; font: inherit;
}
.gate-card button {
  width: 100%; margin-top: 12px; padding: 11px; border: 0; border-radius: 8px;
  background: var(--brand); color: #fff; font-weight: 600;
}
.gate-err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.side {
  background: #0f2a1c; color: #cfe6d8; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 11px; align-items: center; padding: 20px 18px 18px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 9px; background: #1f7a45; color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: 13px; letter-spacing: .04em; flex: none;
}
.brand-name { font-weight: 700; color: #fff; font-size: 14px; line-height: 1.2; }
.brand-sub { font-size: 11.5px; color: #7fb99a; margin-top: 2px; }

#nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 1px; flex: 1; overflow-y: auto; }
#nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border-radius: 7px; color: #b9d8c7; text-decoration: none;
  font-size: 13.5px; font-weight: 500;
}
#nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
#nav a.on { background: #1f7a45; color: #fff; }
.badge {
  background: #f59e0b; color: #4a2a00; border-radius: 20px; font-size: 11px;
  font-weight: 800; padding: 1px 7px; min-width: 20px; text-align: center;
}
#nav a.on .badge { background: #fff; color: #14532d; }
.side-foot { padding: 12px 18px 18px; border-top: 1px solid rgba(255, 255, 255, .08); }
.link { background: none; border: 0; color: #7fb99a; font-size: 12.5px; padding: 0; text-decoration: underline; }

/* ---------- main ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 16px 24px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
.topbar h2 { font-size: 18px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.view { padding: 20px 24px 60px; }

.warnings { margin: 14px 24px 0; display: flex; flex-direction: column; gap: 6px; }
.warn-item {
  background: var(--warn-soft); border-left: 4px solid var(--warn); color: #6b4708;
  padding: 9px 13px; border-radius: 0 7px 7px 0; font-size: 13px;
}

/* ---------- controls ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 500;
}
.btn:hover { background: #f6f8fb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #1a6b3a; }
.btn.danger { background: #fff; border-color: #e7b9b9; color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

select, input[type=text], input[type=date], input[type=email], input[type=tel],
input[type=number], textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; font: inherit;
  background: #fff; color: var(--ink); max-width: 100%;
}
textarea { resize: vertical; min-height: 66px; width: 100%; }
label.fld { display: block; margin-bottom: 12px; }
label.fld > span {
  display: block; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px;
}
label.fld > input, label.fld > select, label.fld > textarea { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 130px; }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.card .n { font-size: 26px; font-weight: 700; color: var(--brand); line-height: 1.1; }
.card .k {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin-top: 3px; font-weight: 600;
}
.card.alert .n { color: var(--warn); }
.card.clickable { cursor: pointer; }
.card.clickable:hover { border-color: #b8c4d6; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-top: 18px; overflow: hidden;
}
.panel-head {
  padding: 13px 16px; border-bottom: 1px solid var(--line); display: flex;
  align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.panel-head h3 { font-size: 15px; }
.panel-body { padding: 16px; }
.panel-body.flush { padding: 0; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  background: #f8fafc; font-weight: 700; position: sticky; top: 0;
}
tbody tr:hover { background: #f8fafc; }
tbody tr.click { cursor: pointer; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- pills ---------- */
.pill {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px;
  border-radius: 20px; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap;
}
.pill.new { background: #dbeafe; color: #1e40af; }
.pill.awaiting_photos { background: var(--warn-soft); color: var(--warn); }
.pill.approved, .pill.scheduled { background: var(--brand-soft); color: var(--brand); }
.pill.completed { background: #d1fae5; color: #065f46; }
.pill.en_route { background: #ede9fe; color: #5b21b6; }
.pill.cancelled, .pill.declined { background: #e2e8f0; color: #475569; }
.pill.needs_reschedule, .pill.not_home { background: var(--danger-soft); color: var(--danger); }
.pill.sent, .pill.dryrun { background: var(--brand-soft); color: var(--brand); }
.pill.skipped { background: #e2e8f0; color: #475569; }
.pill.failed { background: var(--danger-soft); color: var(--danger); }
.pill.ghost { background: #eef2f7; color: var(--muted); }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ---------- day schedule ---------- */
.truck-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.truck-col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.truck-head {
  padding: 12px 15px; border-bottom: 1px solid var(--line); display: flex;
  justify-content: space-between; align-items: center; gap: 10px;
}
.truck-head h4 { font-size: 14.5px; display: flex; align-items: center; }
.truck-meta { font-size: 12px; color: var(--muted); }
.stop-list { padding: 8px; display: flex; flex-direction: column; gap: 6px; min-height: 60px; }
.stop-item {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: #fff;
  display: flex; gap: 10px; cursor: grab;
}
.stop-item:hover { border-color: #b8c4d6; }
.stop-item.dragging { opacity: .4; }
.stop-item.over { border-color: var(--accent); border-style: dashed; }
.stop-item .seq {
  flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--brand);
  color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.stop-item.completed { opacity: .6; }
.stop-item.completed .seq { background: #94a3b8; }
.stop-main { flex: 1; min-width: 0; }
.stop-name { font-weight: 600; font-size: 13.5px; }
.stop-addr { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.stop-tags { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; align-items: center; }

/* ---------- map ---------- */
#mapCanvas { width: 100%; height: 62vh; min-height: 380px; border-radius: var(--radius); background: #e6ebf2; }
.map-missing { display: grid; place-items: center; height: 100%; text-align: center; padding: 30px; color: var(--muted); }

/* ---------- drawer ---------- */
.drawer { position: fixed; inset: 0; z-index: 40; }
.drawer-back { position: absolute; inset: 0; background: rgba(15, 25, 40, .45); }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 100%);
  background: var(--panel); box-shadow: -8px 0 30px rgba(0, 0, 0, .18);
  overflow-y: auto; padding: 22px 24px 50px;
}
.drawer-x {
  position: absolute; top: 12px; right: 16px; border: 0; background: none;
  font-size: 26px; line-height: 1; color: var(--muted);
}
.drawer h3 { font-size: 18px; margin-bottom: 3px; }
.drawer .sub { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 7px 12px; font-size: 13.5px; margin: 14px 0; }
.dl dt { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.dl dd { margin: 0; }
.section-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  font-weight: 700; margin: 22px 0 8px; padding-bottom: 5px; border-bottom: 1px solid var(--line);
}
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 7px; border: 1px solid var(--line); }
.preview-frame { width: 100%; height: 320px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #172033; color: #fff; padding: 11px 20px; border-radius: 24px;
  font-size: 13.5px; z-index: 60; box-shadow: 0 8px 26px rgba(0, 0, 0, .28); max-width: 90vw;
}
.toast.err { background: var(--danger); }

/* ---------- calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal .dow {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  font-weight: 700; text-align: center; padding: 5px 0;
}
.cal .day {
  background: #fff; border: 1px solid var(--line); border-radius: 8px; min-height: 88px;
  padding: 7px 8px; font-size: 12px;
}
.cal .day.pad { background: #f6f8fb; border-style: dashed; }
.cal .day.today { border-color: var(--brand); border-width: 2px; }
.cal .day .d { font-weight: 700; color: var(--muted); }
.cal .day .chip {
  display: block; margin-top: 4px; padding: 2px 6px; border-radius: 5px;
  background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: 11.5px;
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; }
  #nav { flex-direction: row; overflow-x: auto; flex: 1 1 100%; }
  .side-foot { border: 0; padding: 12px; }
  .dl { grid-template-columns: 1fr; gap: 2px 0; }
  .dl dd { margin-bottom: 8px; }
}

/* Driver link panel in the day view. */
.linkish {
  background: none; border: 0; padding: 0; font: inherit; font-size: 12px;
  color: var(--brand); text-decoration: underline; cursor: pointer;
}
.linkish:disabled { opacity: .5; cursor: wait; }
.driver-link {
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: #f8fafc;
}
.driver-link[hidden] { display: none; }
.driver-link input {
  width: 100%; font: inherit; font-size: 12px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.driver-link .row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.driver-link .hint { font-size: 11.5px; color: var(--muted); margin-top: 6px; }

/* Item picker and consent line in the manual pickup drawer. */
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.chips .chip {
  padding: 8px 13px; border: 1px solid var(--line); border-radius: 20px;
  background: #fff; font: inherit; font-size: 13.5px; color: var(--ink); cursor: pointer;
}
.chips .chip:hover { background: #f6f8fb; }
.chips .chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
label.consent { display: flex; gap: 9px; align-items: flex-start; margin-bottom: 14px; line-height: 1.45; }
label.consent input { margin-top: 3px; flex: none; }
label.consent em { display: block; font-style: normal; margin-top: 3px; }
#tWhen[hidden] { display: none; }

/* Photo approval gate on a request. */
fieldset.bare { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset.bare[disabled] { opacity: .45; }
.ok-item {
  padding: 10px 12px; margin-bottom: 16px; border-radius: 8px;
  background: var(--brand-soft); color: var(--brand);
  border-left: 4px solid var(--brand); font-size: 13.5px;
}
.ok-item .linkish { color: var(--brand); }

/* Adding photos is done on the phone the donor texted them to, so it gets a
   real tap target rather than a toolbar-sized button. */
#pAddBtn { width: 100%; min-height: 46px; font-weight: 600; margin-bottom: 6px; }

@media (max-width: 860px) {
  /* Eight columns will not fit a handset; let the table scroll on its own. */
  .panel-body.flush { overflow-x: auto; }
  .panel-body.flush table { min-width: 720px; }
  #topActions { flex-wrap: wrap; }
  #topActions input[type="search"] { flex: 1 1 100%; min-width: 0; }
}

/* Texted-in photos nobody has placed yet. */
.panel.warn { border-color: #e6cf92; }
.panel.warn .panel-head { background: var(--warn-soft); }
.panel.warn .panel-head h3 { color: #6b4708; }
.unfiled-row {
  display: flex; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line);
}
.unfiled-row:last-child { border-bottom: 0; padding-bottom: 0; }
.unfiled-meta { flex: 1; min-width: 0; }
.unfiled-hits { margin-top: 4px; }
.unfiled-q { min-width: 200px; }
@media (max-width: 860px) { .unfiled-row { flex-direction: column; } }

/* Month overview: every day is a place to book from. */
.cal .day { display: flex; flex-direction: column; }
.cal .day.past { background: #fafbfc; }
.cal .day.past .d { opacity: .55; }
.cal .dhead { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.cal .dadd {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  width: 22px; height: 22px; border-radius: 6px; line-height: 1; font-size: 15px;
  cursor: pointer; padding: 0; flex: none; opacity: 0; transition: opacity .12s;
}
.cal .day:hover .dadd, .cal .dadd:focus-visible { opacity: 1; }
.cal .dadd:hover { background: var(--brand); border-color: var(--brand); color: #fff; }
.cal .dbody {
  flex: 1; margin-top: 4px; cursor: pointer; border-radius: 6px;
  display: flex; flex-direction: column; gap: 3px;
}
.cal .dbody:hover { background: #f6f8fb; }
.cal .dbody:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.cal .dsum { font-size: 10.5px; color: var(--muted); margin-top: auto; }
.cal .dfree { font-size: 10.5px; color: #9aa7b8; margin-top: auto; }

/* Touch has no hover, so the add button is always visible - and a little
   larger, since a fingertip is not a mouse pointer. */
@media (hover: none) {
  .cal .dadd { opacity: 1; width: 26px; height: 26px; font-size: 17px; }
  .cal .day { padding: 6px 5px; }
}

/* Sign-in variants and the People screen. */
.gate-alt {
  background: none; border: 0; padding: 8px 0 0; width: 100%;
  color: var(--muted); font: inherit; font-size: 12.5px; text-decoration: underline; cursor: pointer;
}
.gate-alt:hover { color: var(--brand); }
.gate-card[hidden] { display: none; }
.whoami { margin-bottom: 8px; line-height: 1.3; }
.whoami-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.whoami-role { font-size: 11.5px; color: var(--muted); }
.whoami[hidden] { display: none; }
#nav a[hidden] { display: none; }
#view tr.off td { opacity: .55; }
.temp-pass {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 19px; letter-spacing: .04em; padding: 14px 16px; margin: 4px 0 12px;
  background: var(--brand-soft); color: var(--brand); border-radius: 9px;
  user-select: all; word-break: break-all; text-align: center;
}
