.loading {
  text-align: center;
  margin-top: 30vh;
  color: var(--muted);
}
body.readonly .w {
  display: none !important;
}

/* ---------- header and tabs ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 1000;
}
.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 900;
  letter-spacing: 0.22em;
  font-size: 1.25rem;
}
.logo img { width: 30px; height: 30px; display: block; }
.company {
  color: var(--muted);
}
.work-status {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-left: auto;
  flex-wrap: wrap;
}
.work-pill {
  font-weight: 700;
  padding: 0.35em 0.8em;
  border-radius: 999px;
  background: var(--soft);
}
.work-pill.on {
  background: color-mix(in srgb, var(--ok) 20%, transparent);
  color: var(--ok);
}
.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  position: sticky;
  top: 57px;
  z-index: 999;
}
.tabs button {
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: none;
  padding: 0.7em 0.9em;
  white-space: nowrap;
  font-weight: 600;
  color: var(--muted);
}
.tabs button.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}
.tabs .badge {
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  padding: 0 0.45em;
  font-size: 0.75rem;
  margin-left: 0.3em;
}
main.page {
  padding: 1rem;
}

/* ---------- live tab ---------- */
.live {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 1rem;
  height: calc(100vh - 140px);
  min-height: 520px;
}
.live .map {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  min-height: 400px;
}
.live .side {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
@media (max-width: 900px) {
  .live {
    grid-template-columns: 1fr;
    height: auto;
  }
  .live .map {
    height: 55vh;
  }
}
.alert {
  border-left: 5px solid var(--warn);
}
.alert.danger {
  border-left-color: var(--danger);
}
.alert .row {
  margin-top: 0.5rem;
}
.crew-card {
  border-left: 6px solid var(--line);
}
.crew-card .status {
  margin-top: 0.25rem;
}
.progress {
  height: 6px;
  border-radius: 3px;
  background: var(--soft);
  overflow: hidden;
  margin-top: 0.4rem;
}
.progress > div {
  height: 100%;
  background: var(--ok);
}
.feed li {
  margin: 0.35rem 0;
}
.feed {
  padding-left: 1.1rem;
  margin: 0;
}
.legend {
  font-size: 0.85rem;
}

/* map markers */
.truck-icon {
  background: none;
  border: none;
}
.truck-label {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  white-space: nowrap;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
}
.stale-flag {
  background: var(--danger);
  color: #fff;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-weight: 700;
}
.map-overlay {
  background: var(--panel);
  color: var(--text);
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 260px;
}
.map-overlay ul {
  margin: 0.25rem 0 0;
  padding-left: 1rem;
}

/* ---------- routes board ---------- */
.toolbar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
}
.board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  align-items: start;
}
.route {
  border-top: 6px solid var(--line);
  padding: 0.75rem;
}
.route.drop-target {
  outline: 3px dashed var(--brand);
}
.route-head {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}
.route-head input {
  flex: 1;
  font-weight: 700;
  min-width: 120px;
}
.stop-list {
  list-style: none;
  margin: 0.6rem 0;
  padding: 0;
  min-height: 40px;
}
.stop-item {
  display: grid;
  grid-template-columns: 1.6rem minmax(0, 1fr);
  gap: 0.4rem;
  align-items: center;
  padding: 0.45rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0.35rem 0;
  background: var(--panel);
}
.stop-item[draggable='true'] {
  cursor: grab;
}
.stop-item.dragging {
  opacity: 0.4;
}
.stop-item.decision {
  border-color: var(--warn);
  border-width: 2px;
}
.stop-item .n {
  font-weight: 800;
  color: var(--muted);
  text-align: center;
}
.stop-item .nm {
  font-weight: 600;
}
.stop-item .ad {
  font-size: 0.8rem;
  color: var(--muted);
}
.stop-item .ctl {
  grid-column: 2;
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  align-items: center;
  min-width: 0;
}
.stop-item .ctl select {
  flex: 1 1 8rem;
  min-width: 0;
  max-width: 14rem;
}
.stop-item .ctl button,
.stop-item .ctl select {
  min-height: 32px;
  padding: 0.2em 0.45em;
  font-size: 0.85rem;
}
.add-stop {
  display: flex;
  gap: 0.4rem;
}
.add-stop select {
  flex: 1;
  min-width: 0;
}

/* ---------- tables ---------- */
.table-wrap {
  overflow-x: auto;
}
table {
  border-collapse: collapse;
  width: 100%;
  background: var(--panel);
}
th,
td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
tr.edited td:first-child {
  border-left: 4px solid var(--warn);
}
.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
@media (max-width: 900px) {
  .two-col {
    grid-template-columns: 1fr;
  }
}
.loc-map {
  height: 320px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  margin-top: 0.6rem;
}
.results {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0;
}
.results li button {
  width: 100%;
  text-align: left;
  margin: 0.2rem 0;
}
.code-big {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 0.3em;
}
.member-list {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0;
}
.member-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.2rem 0;
}
.history {
  font-size: 0.85rem;
  padding-left: 1rem;
}
.rec-list {
  list-style: none;
  padding: 0;
}
.rec-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0.4rem 0;
}
.rec-list li.best {
  border: 2px solid var(--ok);
}
.leaflet-container {
  font: inherit;
}

/* ---- Batch 2: passes, one-time stops, kebab menu, settings, photos ---- */
.passes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-top: 0.3rem;
}
.passes .field-box {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  padding: 0.1rem 0.4rem;
  background: var(--panel);
}
.passes .lbl {
  font-size: 0.75rem;
  color: var(--muted);
}
.passes .num {
  min-width: 1.2em;
  text-align: center;
}
.passes button.tick,
.passes button.lock {
  padding: 0.05rem 0.45rem;
  min-height: 0;
  line-height: 1.3;
}
.passes.met .field-box {
  background: color-mix(in srgb, var(--ok) 15%, var(--panel));
  border-color: var(--ok);
  color: var(--ok);
}
.passes.met .lbl {
  color: inherit;
}
.stop-item.finished {
  opacity: 0.6;
}
.stop-item.one-time {
  border-left: 3px dashed var(--warn);
}
.kebab {
  position: relative;
}
.kebab .menu {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 13rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
  padding: 0.25rem;
}
.kebab .menu.hidden {
  display: none;
}
.kebab .menu button {
  text-align: left;
  border: 0;
  background: transparent;
}
.kebab .menu button:hover,
.kebab .menu button:focus-visible {
  background: var(--soft);
}
dialog.modal.wide {
  width: min(46rem, 96vw);
}
.type-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.chip.big {
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.chip button.x {
  border: 0;
  background: transparent;
  padding: 0 0.2rem;
  min-height: 0;
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  gap: 0.6rem;
}
.photo-grid figure {
  margin: 0;
}
.photo-grid img {
  width: 100%;
  height: 10rem;
  object-fit: cover;
  border-radius: 0.4rem;
  border: 1px solid var(--line);
  display: block;
}

/* ---- Batch 3: notifications, locked/unlocked passes, settings spacing ---- */
.alert.warn {
  border-left-color: var(--warn);
}
.alert.info {
  border-left-color: var(--brand);
}
.notif-title {
  margin-top: 0.8rem;
}
button.bell {
  font-weight: 700;
  border-color: var(--warn);
  color: var(--warn);
}
/* Locked: the passes field is greyed out and its − / + can't be pressed. */
.passes.locked .field-box.pass-field {
  border-style: dashed;
}
.passes.locked:not(.met) .field-box.pass-field {
  opacity: 0.45;
  background: var(--soft);
}
.passes.locked .tick {
  visibility: hidden;
}
/* Unlocked: clearly highlighted while you edit. */
.passes.unlocked .field-box.pass-field {
  border: 2px solid var(--brand);
  background: color-mix(in srgb, var(--brand) 12%, var(--panel));
  opacity: 1;
}
.passes button.lock {
  font-size: 0.8rem;
  font-weight: 700;
}
.passes.unlocked button.lock {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
/* Space between the sections of the Routes & Service Settings window. */
dialog.modal.wide .modal-body h3 {
  margin-top: 2rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
}
dialog.modal.wide .modal-body h3:first-child {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

/* Traffic order suggestion */
.order-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.order-compare h3 { margin: 4px 0; font-size: 0.95rem; }
.order-list { margin: 0; padding-left: 1.6em; }
.order-list li { padding: 2px 0; }
.ok-text { color: var(--ok, #1b7f3b); font-weight: 600; }
.attribution { margin-top: 12px; }
input.num { width: 6em; }
@media (max-width: 560px) { .order-compare { grid-template-columns: 1fr; } }
.photo-row { align-items: flex-end; }
.photo-row .field { margin-bottom: 0; }

/* Latest activity: three kinds, each with its own color and tag */
:root { --feed-ack: #6a3fb5; --feed-office: #0b7285; }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) { --feed-ack: #b79cf2; --feed-office: #5cc8d8; } }
:root[data-theme='dark'] { --feed-ack: #b79cf2; --feed-office: #5cc8d8; }
.feed li.field { color: var(--text); }
.feed li.ack { color: var(--feed-ack); }
.feed li.office { color: var(--feed-office); }
.feed-tag { display: inline-block; min-width: 3.6em; text-align: center; font-weight: 700; font-size: 0.7em; text-transform: uppercase; letter-spacing: 0.05em; border: 1px solid currentColor; border-radius: 4px; padding: 0 0.3em; vertical-align: 0.1em; }
.feed-time { font-variant-numeric: tabular-nums; }
.feed-by { opacity: 0.8; }
.feed-scroll { max-height: 420px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 0.4rem 0.6rem; overscroll-behavior: contain; }
.feed-scroll .feed { list-style: none; padding: 0; }
.feed-scroll .feed li { padding: 0.25rem 0; border-bottom: 1px solid var(--line); margin: 0; }
.feed-scroll .feed li:last-child { border-bottom: 0; }
.feed-filters { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.5rem; }
.feed-filter { padding: 0.25em 0.7em; font-size: 0.85rem; border-radius: 999px; }
.feed-filter.ack { color: var(--feed-ack); }
.feed-filter.office { color: var(--feed-office); }
.feed-filter.active { color: var(--brand-text); background: var(--brand); border-color: var(--brand); }
.feed-filter.ack.active { background: var(--feed-ack); border-color: var(--feed-ack); }
.feed-filter.office.active { background: var(--feed-office); border-color: var(--feed-office); }
.ack-btn { margin-left: auto; }
.feed-more { text-align: center; border-bottom: 0 !important; }

/* ---------- Prep ---------- */
.work-pill.prep { background: color-mix(in srgb, var(--brand) 18%, transparent); color: var(--brand); }
.prep-card { border-left: 4px solid var(--brand); }
.end-summary h3 { margin: 0.9rem 0 0.3rem; font-size: 0.95rem; }
.end-summary h3:first-child { margin-top: 0; }
.end-list { margin: 0; padding-left: 1.2rem; }
.end-list li { margin: 0.2rem 0; }

/* ---------- Dark mode switch ---------- */
.theme-switch { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.25em 0.6em; border-radius: 999px; }
.theme-track { position: relative; width: 2.6em; height: 1.4em; border-radius: 999px; background: var(--soft); border: 1px solid var(--line); flex: none; transition: background 0.15s; }
.theme-knob { position: absolute; top: 50%; left: 0.1em; transform: translateY(-50%); border-radius: 50%; background: var(--panel); box-shadow: 0 1px 2px rgb(0 0 0 / 0.3); font-size: 0.75em; line-height: 1.2em; text-align: center; transition: left 0.15s; display: grid; place-items: center; width: 1.6em; height: 1.6em; }
.theme-switch.on .theme-track { background: var(--brand); border-color: var(--brand); }
.theme-switch.on .theme-knob { left: calc(100% - 1.7em); }
.theme-label { font-size: 0.85rem; }

/* Dark map: the vector map has its own dark style; the picture-tile fallback is inverted to match. */
:root[data-theme='dark'] .raster-map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.95) saturate(0.6); }
:root[data-theme='dark'] .leaflet-container { background: #1b1f24; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .raster-map .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.95) saturate(0.6); }
  :root:not([data-theme='light']) .leaflet-container { background: #1b1f24; }
}
:root[data-theme='dark'] { color-scheme: dark; }
:root[data-theme='light'] { color-scheme: light; }

/* ---- Collapsible route cards ---- */
.route-sub { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-top: 0.3rem; flex-wrap: wrap; }
.route-toggle { padding: 0.2em 0.7em; font-size: 0.85rem; border-radius: 999px; }
.route.collapsed .stop-list { margin: 0.4rem 0 0; }
.collapsed-note { margin-top: 0.35rem; }

/* ---- Account banners (trial, support visit) and the trial-ended screen ---- */
.account-banner { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; padding: 0.5rem 1rem; font-size: 0.92rem; }
.account-banner.hidden { display: none; }
.account-banner.trial { background: var(--banner-trial-bg); color: var(--banner-trial-text); }
.account-banner.trial.soon { background: var(--banner-soon-bg); color: var(--banner-soon-text); }
.account-banner.support { background: var(--banner-support-bg); color: var(--banner-support-text); }
.account-banner button { flex: none; }
.ended-card p { margin: 0 0 0.75rem; }
:root { --banner-trial-bg: #e7f0fb; --banner-trial-text: #0b2545; --banner-soon-bg: #fff1d6; --banner-soon-text: #5c3b00; --banner-support-bg: #efe6fb; --banner-support-text: #3d1f73; }
:root[data-theme='dark'] { --banner-trial-bg: #16283f; --banner-trial-text: #d6e6fa; --banner-soon-bg: #3d2c08; --banner-soon-text: #ffe2a8; --banner-support-bg: #2b1d45; --banner-support-text: #e3d4ff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) { --banner-trial-bg: #16283f; --banner-trial-text: #d6e6fa; --banner-soon-bg: #3d2c08; --banner-soon-text: #ffe2a8; --banner-support-bg: #2b1d45; --banner-support-text: #e3d4ff; }
}
