/* CFAR Dispatch (hosted) — navy/teal, dense dispatch look.
   The Dispatch view is a CareWare-style Rides Calendar: one compact
   toolbar row, one slim totals line, then a time grid that fills the
   rest of the viewport with a frozen car/driver header. */

:root {
  --navy: #123a5f;
  --navy-dark: #0c2a46;
  --teal: #17808a;
  --teal-dark: #11616a;
  --ink: #1c2733;
  --muted: #5c6b7a;
  --line: #cfd8e0;
  --bg: #eef2f5;
  --panel: #ffffff;
  --cash: #fdf3b8;        /* yellow block: every program except Zetter / Bonnie Doon */
  --cash-edge: #d9c84f;
  --prog: #c9def2;        /* blue block: Zetter / Bonnie Doon */
  --prog-edge: #7fa8cf;
  --danger: #b3261e;
  --danger-bg: #fbe9e7;
  --ok: #1e7d32;
  --ok-bg: #e6f4ea;
  --axis-w: 56px;
  --hist-w: 240px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
}

.hidden { display: none !important; }

/* ---------- banner ---------- */
.banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 200;
  padding: 10px 44px 10px 16px;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  border-bottom: 2px solid transparent;
}
.banner.error   { background: var(--danger-bg); color: var(--danger); border-bottom-color: var(--danger); }
.banner.success { background: var(--ok-bg); color: var(--ok); border-bottom-color: var(--ok); }
.banner button {
  position: absolute; top: 4px; right: 8px;
  background: none; border: none; font-size: 18px; cursor: pointer; color: inherit;
}

/* ---------- buttons / inputs ---------- */
.btn {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
  white-space: nowrap;
}
.btn:hover { border-color: var(--teal); }
.btn-primary { background: var(--teal); border-color: var(--teal-dark); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-small { padding: 2px 8px; font-size: 12px; }
.btn-block { width: 100%; margin-top: 10px; padding: 9px 12px; }
.btn.danger { color: var(--danger); border-color: var(--danger); }

input, select, textarea {
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal); outline-offset: 0; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 8px 0; }
label input, label select, label textarea { display: block; width: 100%; margin-top: 3px; font-weight: 400; color: var(--ink); }

/* ---------- auth ---------- */
.auth-view { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card {
  background: var(--panel);
  border-top: 6px solid var(--navy);
  border-radius: 6px;
  box-shadow: 0 4px 24px rgba(12, 42, 70, .18);
  padding: 28px 30px;
  width: 340px;
  max-width: 92vw;
}
.brand { font-weight: 700; color: var(--navy); letter-spacing: .2px; }
.brand-large { font-size: 24px; text-align: center; }
.brand-sub { text-align: center; color: var(--teal); font-weight: 600; margin: 2px 0 14px; }
.brand-sub-inline { color: var(--teal); font-weight: 600; }
.auth-note { text-align: center; color: var(--muted); font-size: 12px; }

/* ---------- app shell ---------- */
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#app-header {
  display: flex; align-items: center; gap: 18px; flex: none;
  background: var(--navy); color: #fff;
  padding: 8px 14px;
  z-index: 50;
}
#app-header .brand { color: #fff; font-size: 17px; }
#app-header .brand-sub-inline { color: #9fd8dd; }
#app-header nav { display: flex; gap: 6px; }
.nav-btn {
  background: transparent; border: 1px solid rgba(255,255,255,.35);
  color: #fff; border-radius: 4px; padding: 5px 12px; cursor: pointer; font-size: 13px;
}
.nav-btn:hover { border-color: #fff; }
.nav-btn.active { background: var(--teal); border-color: var(--teal); font-weight: 600; }
.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.badge {
  background: var(--teal); color: #fff; border-radius: 10px;
  padding: 1px 9px; font-size: 11px; font-weight: 700; text-transform: uppercase;
}
.badge.user { background: #63798c; }

/* ---------- toolbar / totals ---------- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; justify-content: space-between;
  padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
}
#view-board .toolbar { flex: none; }
.toolbar-group { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.board-toolbar .btn { padding: 5px 10px; font-size: 12.5px; }
.board-toolbar input[type="date"] { padding: 4px 6px; font-size: 12.5px; }
.board-toolbar select { padding: 4px 6px; font-size: 12.5px; }
#board-date-label { font-weight: 700; color: var(--navy); white-space: nowrap; font-size: 13.5px; }
.toggle { display: inline-flex; align-items: center; gap: 5px; margin: 0; color: var(--ink); font-size: 12.5px; font-weight: 400; }
.toggle input { width: auto; margin: 0; }
.toolbar-field { display: inline-flex; align-items: center; gap: 5px; margin: 0; font-size: 12.5px; }
.toolbar-field select { font-weight: 400; }
.totals-line {
  flex: none;
  padding: 4px 12px; font-size: 13px; font-weight: 600; color: var(--navy-dark);
  background: #dde8ee; border-bottom: 1px solid var(--line);
}

/* ---------- board layout ---------- */
#view-board { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#view-lists, #view-access { flex: 1; min-height: 0; overflow-y: auto; }
.board {
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  background: var(--panel);
  position: relative;
}
.board-empty { color: var(--muted); text-align: center; padding: 26px 0; font-size: 13px; }

/* Frozen header row: sticks to the top of the board's scroll area and
   uses the exact same flex layout as the grid body beneath it. */
.board-head {
  position: sticky; top: 0; z-index: 40;
  display: flex;
  background: var(--navy); color: #fff;
  border-bottom: 2px solid var(--navy-dark);
}
.bhead { padding: 5px 7px 6px; border-left: 1px solid rgba(255,255,255,.18); min-width: 0; }
.bhead-axis { flex: 0 0 var(--axis-w); border-left: none; background: var(--navy-dark); }
.colflex { flex: 1 1 0; min-width: 0; }
.colflex-hist { flex: 0 0 var(--hist-w); width: var(--hist-w); }
.col-title { font-weight: 700; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.col-revenue { font-size: 12px; color: #ffd75e; font-weight: 700; }
.col-driver { margin-top: 3px; }
.col-driver select { width: 100%; padding: 2px 4px; font-size: 11.5px; }
.col-stints { font-size: 10.5px; color: #cfe3ea; margin-top: 2px; line-height: 1.45; }

.grid-body { display: flex; align-items: stretch; }
.time-axis {
  flex: 0 0 var(--axis-w); position: relative;
  background: #f2f6f8; border-right: 1px solid var(--line);
}
.hour-label {
  position: absolute; right: 6px; transform: translateY(-50%);
  font-size: 10px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.grid-cols {
  flex: 1; position: relative; display: flex; min-width: 0;
  /* Hour + zoom-step grid lines are painted from inline background-size. */
  background-image:
    linear-gradient(to bottom, rgba(18, 58, 95, .30) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(18, 58, 95, .10) 1px, transparent 1px);
  background-repeat: repeat;
}
.car-col { position: relative; border-left: 1px solid var(--line); min-width: 0; }
.car-col:first-of-type { border-left: none; }
.car-col.drop-hint { background: rgba(23, 128, 138, .14); box-shadow: inset 0 0 0 2px var(--teal); }
.car-col.history { background: #fbfcfd; }
.history-list { position: absolute; inset: 0; overflow-y: auto; padding: 5px; }
.col-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 8px 0; }

/* Live red current-time line (Edmonton today only). */
.now-line {
  position: absolute; left: 0; right: 0; height: 0; z-index: 25;
  border-top: 2px solid #e53935;
  display: none; pointer-events: none;
}
.now-line::before {
  content: ""; position: absolute; left: 0; top: -5px;
  width: 8px; height: 8px; border-radius: 50%; background: #e53935;
}

/* ---------- ride blocks ---------- */
.ride-block {
  position: absolute;
  border: 1px solid var(--cash-edge);
  background: var(--cash);
  border-radius: 3px;
  padding: 2px 5px;
  cursor: grab;
  font-size: 11px;
  line-height: 1.3;
  overflow: hidden;
  z-index: 1;
}
.ride-block.prog { background: var(--prog); border-color: var(--prog-edge); }
.ride-block:hover { filter: brightness(.97); }
.ride-block .r-time { font-weight: 700; color: var(--navy-dark); font-size: 11px; }
.ride-block .r-name { font-weight: 700; font-size: 12.5px; }
.ride-block .r-route {
  color: #37434e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 10.5px;
}
.ride-block .r-price { font-weight: 600; font-size: 10.5px; }
.ride-block .r-status {
  font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; margin-left: 5px;
}
.ride-block.cancelled { outline: 3px solid var(--danger); outline-offset: -1px; }
.ride-block.cancelled .r-status { color: var(--danger); }
.ride-block.complete { outline: 3px solid var(--ok); outline-offset: -1px; }
.ride-block.complete .r-status { color: var(--ok); }
.ride-block.dragging { opacity: .45; cursor: grabbing; }
.ride-block.popped { z-index: 60; box-shadow: 0 0 0 2px var(--navy), 0 6px 18px rgba(12,42,70,.4); }
.hist-block {
  position: static; width: 100%; margin-bottom: 5px; cursor: pointer;
  font-size: 12px; padding: 5px 7px; height: auto;
}
.hist-block .r-route { white-space: normal; }

/* ---------- mobile car picker ---------- */
.mobile-picker-row {
  display: none; flex: none;
  padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
  align-items: center; gap: 8px;
}
.mobile-picker-row label { margin: 0; font-size: 12.5px; color: var(--ink); }
.mobile-picker-row select { flex: 1; }

/* ---------- popover ---------- */
.popover {
  position: fixed; z-index: 150;
  width: 350px; max-width: 94vw; max-height: 88vh; overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--navy);
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(12, 42, 70, .35);
  padding: 10px 12px 12px;
}
.pop-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.pop-head strong { color: var(--navy); }
.kv { display: grid; grid-template-columns: 78px 1fr; gap: 3px 8px; font-size: 12.5px; margin: 0 0 6px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; word-break: break-word; }
.pop-actions { border-top: 1px solid var(--line); padding-top: 4px; }
.pop-actions label { margin: 6px 0; }
.pop-actions .btn-block { margin-top: 8px; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 140;
  background: rgba(12, 42, 70, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 30px 10px; overflow-y: auto;
}
.modal {
  background: var(--panel); border-radius: 6px; width: 480px; max-width: 96vw;
  padding: 14px 18px 18px; box-shadow: 0 10px 36px rgba(0,0,0,.3);
  position: relative;
}
.form-row { display: flex; gap: 10px; }
.form-row label { flex: 1; min-width: 0; }
.quote-note { font-size: 12px; color: var(--teal-dark); min-height: 16px; }
.suggestions {
  border: 1px solid var(--line); border-radius: 4px; background: #fff;
  max-height: 180px; overflow-y: auto; margin-top: 2px;
  box-shadow: 0 6px 18px rgba(0,0,0,.15);
}
.suggestions div { padding: 6px 8px; cursor: pointer; font-size: 13px; font-weight: 400; color: var(--ink); }
.suggestions div:hover { background: #e8f2f4; }
.suggestions .s-prog { color: var(--muted); font-size: 11px; }

/* ---------- lists / tables ---------- */
.view-title { color: var(--navy); margin: 14px 12px 6px; }
.list-note { padding: 4px 12px; color: var(--muted); font-size: 12px; }
.list-tab.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.table-wrap { overflow-x: auto; margin: 6px 12px 20px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th {
  background: var(--navy); color: #fff; text-align: left;
  padding: 7px 9px; font-size: 12px; text-transform: uppercase; letter-spacing: .3px;
  position: sticky; top: 0;
}
td { padding: 6px 9px; border-top: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: #f2f7f9; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; padding: 6px 12px; align-items: center; }
.inline-form input[type="email"] { min-width: 260px; }

/* ---------- driver sheets (print only) ---------- */
#driver-sheets { display: none; }
@media print {
  body > *:not(#driver-sheets) { display: none !important; }
  #driver-sheets { display: block !important; color: #000; font-size: 12px; }
  #driver-sheets .sheet-head { font-size: 17px; font-weight: 700; margin-bottom: 12px; }
  #driver-sheets .sheet { page-break-inside: avoid; margin-bottom: 20px; }
  #driver-sheets h3 { margin: 0 0 2px; font-size: 14px; }
  #driver-sheets .sheet-sub { color: #444; margin-bottom: 6px; }
  #driver-sheets table { border-collapse: collapse; width: 100%; font-size: 12px; }
  #driver-sheets th {
    background: #ddd; color: #000; text-transform: none; letter-spacing: 0;
    position: static; padding: 4px 6px; border: 1px solid #999; text-align: left;
  }
  #driver-sheets td { padding: 4px 6px; border: 1px solid #999; }
  #driver-sheets .sheet-cancelled { opacity: .55; text-decoration: line-through; }
  #driver-sheets .sheet-none { color: #444; }
}

/* ---------- narrow screens: one car + bottom-sheet popover ---------- */
@media (max-width: 760px) {
  #app-header { flex-wrap: wrap; }
  .header-right { margin-left: 0; }
  .mobile-picker-row { display: flex; }
  .popover {
    left: 0 !important; right: 0; top: auto !important; bottom: 0;
    width: auto; max-width: none; max-height: 84vh;
    border-radius: 12px 12px 0 0; border-bottom: none;
    box-shadow: 0 -8px 30px rgba(12, 42, 70, .4);
  }
}
