/* ClearRoute owner hub. Deep water navy + clear aqua, per DESIGN.md.
   Dark is the default look; light theme ships too (rule 10) and follows
   the system setting until the owner picks one. */

:root,
[data-theme="dark"] {
  --bg: #071c2c;
  --bg-raise: #0b2940;
  --bg-card: #0d2f49;
  --bg-inset: #092238;
  --line: #1b4565;
  --text: #f2f8fc;
  --text-dim: #b8d2e2;
  --accent: #22c3e6;
  --accent-ink: #04222f;
  --green: #35c759;
  --amber: #ffb02e;
  --red: #ff5a4e;
  --red-bg: #3d1420;
  --chip-bg: #123c5c;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
  --bg: #eef6fa;
  --bg-raise: #ffffff;
  --bg-card: #ffffff;
  --bg-inset: #e3eff6;
  --line: #c3d9e6;
  --text: #0a2436;
  --text-dim: #3d5a6e;
  --accent: #0b93b8;
  --accent-ink: #ffffff;
  --green: #1d9e46;
  --amber: #b97a08;
  --red: #d92c20;
  --red-bg: #fdecea;
  --chip-bg: #dceef7;
  --shadow: 0 6px 24px rgba(10, 50, 80, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
}

h1 { font-size: 26px; margin: 0 0 4px; }
h2 { font-size: 20px; margin: 28px 0 12px; }
h3 { font-size: 17px; margin: 0 0 8px; }
p { margin: 0 0 10px; }

.muted { color: var(--text-dim); }
.small { font-size: 13px; }

/* ---------- buttons, fields ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--bg-raise);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 15px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.btn-block { width: 100%; padding: 13px 16px; font-size: 16px; }
.btn-quiet { background: transparent; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 5px; }
.field input, .search-input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  color: var(--text);
  font-size: 16px;
}

/* ---------- auth ---------- */
[hidden] { display: none !important; }

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 30px 28px;
  width: 100%;
  max-width: 400px;
}
.auth-sub { color: var(--text-dim); margin-bottom: 20px; }
.auth-note { color: var(--text-dim); font-size: 13px; margin-top: 16px; }
.auth-error {
  background: var(--red-bg);
  color: var(--red);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 14px;
}

/* ---------- shell ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-raise);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { font-size: 20px; font-weight: 800; letter-spacing: 0.2px; display: flex; align-items: center; gap: 9px; }
.brand-big { font-size: 26px; margin-bottom: 8px; }
.brand-mark {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(34, 195, 230, 0.25);
  display: inline-block;
}
.company-name { color: var(--text-dim); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.updated-at { color: var(--text-dim); font-size: 13px; }

.mainnav {
  display: flex;
  gap: 8px;
  padding: 12px 20px 0;
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
}
.nav-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 10px;
  cursor: pointer;
}
.nav-btn.active { background: var(--bg-card); color: var(--text); border-color: var(--line); }

.main { max-width: 1180px; margin: 0 auto; padding: 18px 20px 60px; width: 100%; }

/* ---------- cards, stats ---------- */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 16px 0 6px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
}
.stat-label { color: var(--text-dim); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; }
.stat-value { font-size: 30px; font-weight: 800; margin-top: 2px; }
.stat-sub { color: var(--text-dim); font-size: 13px; }
.stat-card.alert .stat-value { color: var(--red); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 14px;
}

/* ---------- alerts, issues ---------- */
.alert-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-left: 5px solid var(--red);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
}
.alert-card:hover { border-color: var(--accent); border-left-color: var(--red); }
.alert-title { font-weight: 700; }
.alert-problem { color: var(--red); font-weight: 600; }
.issue-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-left: 5px solid var(--amber);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
}

/* ---------- routes and stops ---------- */
.route-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.route-tech { font-size: 18px; font-weight: 800; }
.ring-wrap { position: relative; width: 58px; height: 58px; flex: none; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-track { stroke: var(--line); }
.ring-fill { stroke: var(--green); }
.ring-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; text-align: center;
}
.stop-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
}
.stop-row:hover { border-color: var(--accent); }
.stop-seq {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--chip-bg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; flex: none;
}
.stop-main { flex: 1; min-width: 0; }
.stop-name { font-weight: 700; }
.stop-addr { color: var(--text-dim); font-size: 13px; }

.chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--chip-bg);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.chip-done { background: var(--green); color: #06280f; }
.chip-progress { background: var(--accent); color: var(--accent-ink); }
.chip-skipped { background: var(--amber); color: #2e1f00; }
.chip-overdue, .chip-alert { background: var(--red); color: #fff; }
.chip-paid { background: var(--green); color: #06280f; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--text-dim); font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; }
td.num, th.num { text-align: right; }
tr.row-bad td { background: rgba(255, 90, 78, 0.08); }
.reading-bad { color: var(--red); font-weight: 700; }

/* ---------- customers ---------- */
.pool-block { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.pool-title { font-weight: 700; }
.equip-line { color: var(--text-dim); font-size: 14px; }
.search-row { margin: 6px 0 16px; }

/* ---------- map ---------- */
#map { height: 68vh; min-height: 380px; border-radius: 14px; border: 1px solid var(--line); z-index: 0; }
.pin-num {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.45);
}
.pin-num.done { background: var(--green); color: #06280f; }
.pin-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.45);
}
.pin-tech {
  min-width: 34px; height: 34px; border-radius: 50%;
  background: #0b2940; color: #fff;
  border: 3px solid var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.5);
  padding: 0 4px;
}
.leaflet-popup-content { font-size: 14px; line-height: 1.4; }

/* ---------- visit detail ---------- */
.back-btn { margin-bottom: 14px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.check-line { display: flex; gap: 9px; align-items: baseline; padding: 4px 0; }
.check-box { font-weight: 800; }
.check-done { color: var(--green); }
.check-todo { color: var(--text-dim); }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.photo-grid figure { margin: 0; }
.photo-grid img { width: 100%; height: 140px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
.photo-grid figcaption { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

.empty {
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 26px;
  text-align: center;
  color: var(--text-dim);
}
.loading { color: var(--text-dim); padding: 30px 0; text-align: center; }

@media (max-width: 640px) {
  .stat-value { font-size: 24px; }
  .mainnav { overflow-x: auto; }
}

/* ---------- batch 2: forms, modal, board ---------- */
.field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0 14px;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  margin: 8px 0;
  cursor: pointer;
}
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.btn-small { padding: 5px 11px; font-size: 13px; border-radius: 8px; }
.btn-danger { border-color: var(--red); color: var(--red); background: transparent; }
.inline-actions { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.notice {
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 12px 0;
  font-weight: 600;
}
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 28px 0 12px; }
.search-flex { display: flex; gap: 10px; }
.search-flex .search-input { flex: 1; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-dim { opacity: 0.62; }
.chip-partial { background: var(--amber); color: #2e1f00; }
.chip-voided { background: transparent; border: 1px solid var(--line); color: var(--text-dim); }

/* quick create */
.create-wrap { position: relative; }
.create-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 230px;
  padding: 6px;
  z-index: 60;
}
.create-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.create-menu button:hover:not(:disabled) { background: var(--bg-inset); }
.create-menu button:disabled { color: var(--text-dim); cursor: default; font-weight: 400; }

/* modal editors */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 12, 20, 0.66);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 28px 14px;
  z-index: 100;
}
.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px 24px 20px;
  width: 100%;
  max-width: 860px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 20px;
  flex-wrap: wrap;
}
.pool-form {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  margin: 14px 0;
  background: var(--bg-inset);
}

/* invoice lines */
.line-table input, .line-table select { font-size: 14px; }
.mini-input, .mini-select {
  padding: 8px 9px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  color: var(--text);
  font-size: 14px;
}
.mini-input.grow { width: 100%; min-width: 130px; }
.mini-input.num-in { width: 96px; text-align: right; }
.invoice-total { text-align: right; font-size: 19px; font-weight: 800; margin-top: 12px; }
.pay-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pay-row input {
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  color: var(--text);
  font-size: 15px;
  width: 170px;
}

/* schedule board */
/* The Schedule view breaks out of the 1180px container the other views
   use, so the week board gets the full window width. :has() scopes this
   to the schedule markup only; other views keep the narrow container. */
.main:has(> .board-wrap) { max-width: none; }
.board-wrap { position: relative; padding: 0 54px; }
.board {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  padding-bottom: 8px;
}
.board-col {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  min-height: 120px;
  min-width: 0;
}
.board-today { border-color: var(--accent); }
.board-day { font-weight: 800; margin-bottom: 8px; }
.board-tech { font-weight: 700; font-size: 14px; margin: 10px 0 6px; color: var(--accent); }
.stop-chip {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  margin-bottom: 8px;
  min-width: 0;
}
.stop-chip-head { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 4px; }
.stop-chip-head .stop-seq { flex: none; }
.stop-chip-head .stop-name { flex: 1; min-width: 0; overflow-wrap: break-word; }
.stop-chip-head .chip { flex: none; margin-top: 2px; }
/* Day select + Move share the first line; the tech select (long names)
   gets a full-width line of its own so nothing truncates into mush. */
.move-row { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.move-row .mini-select { min-width: 0; font-size: 12px; padding: 5px 4px; }
.move-row select[data-move-day] { flex: 1 1 0; }
.move-row select[data-move-tech] { flex: 1 1 100%; order: 3; }
.move-row .btn-small { flex: 0 0 auto; }

/* week navigation arrows: round buttons centered on the board edges.
   The wrap's side padding keeps the day columns clear of them. */
.board-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 28px;
  line-height: 1;
  padding: 0 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
}
.board-arrow:hover { border-color: var(--accent); color: var(--accent); }
.board-arrow-prev { left: 0; }
.board-arrow-next { right: 0; }

@media (max-width: 900px) {
  /* Small screens: columns keep a usable minimum and the board scrolls
     sideways inside the wrap instead of crushing the cards. */
  .board { grid-template-columns: repeat(7, minmax(150px, 1fr)); overflow-x: auto; }
  .board-wrap { padding: 0 48px; }
  .board-arrow { width: 38px; height: 38px; font-size: 24px; }
}
