/* DispatchPal owner dashboard.
   Design intent: a tool a plumber checks one-handed in a truck between jobs.
   Jobsite palette -- deep slate, safety yellow, blueprint blue -- big tap
   targets, no decoration that slows reading. */

:root {
  --ink: #1b2430;          /* deep slate: text + header */
  --paper: #f6f7f5;        /* worksite-gray background */
  --card: #ffffff;
  --line: #d8dce1;
  --safety: #f5b400;       /* safety yellow: the one loud color */
  --blueprint: #1d5fbf;    /* links, actions */
  --ok: #1e7d43;
  --warn: #b34700;
  --danger: #b3261e;
  --muted: #5c6672;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* ---- Header ---- */
.topbar {
  background: var(--ink);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  border-bottom: 4px solid var(--safety);
  position: relative;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0.5px;
  color: #fff;
  text-decoration: none;
}
.brand-mark { width: 28px; height: 28px; }
.brand-accent { color: var(--safety); }
.topbar nav { display: flex; gap: 12px; flex-wrap: wrap; }
.topbar nav a {
  color: #cfd6de;
  text-decoration: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 1.05rem;
}
.topbar nav a:hover, .topbar nav a:focus-visible { background: #2a3543; color: #fff; }
.nav-admin-highlight { border: 2px solid var(--safety); color: #fff !important; }
.logout-form { display: flex; align-items: center; gap: 12px; }
.logout-form .who { color: #cfd6de; font-weight: 600; font-size: 0.85rem; }
.topbar .btn-quiet {
  color: #cfd6de;
  border-color: #3a4553;
  padding: 8px 14px;
  margin-top: 0;
  font-size: 0.85rem;
}
.topbar .btn-quiet:hover { background: #2a3543; color: #fff; }

/* Collapsible nav: a compact "Menu" toggle by default, so the header stays
   one row on a phone instead of three. Deliberately a hidden checkbox +
   label, NOT <details>/<summary> -- a closed <details>'s content isn't
   just display:none, browsers treat it as fundamentally unrendered (like
   <template>), which isn't reliably overridable with CSS alone across
   browsers. A checkbox's :checked state is ordinary CSS with no such
   special case, so forcing the panel open at wider viewports (below) just
   works everywhere. */
.nav-toggle-checkbox { display: none; }
.nav-menu-toggle {
  cursor: pointer;
  color: #cfd6de;
  font-weight: 700;
  padding: 8px 14px;
  border: 1px solid #3a4553;
  border-radius: 6px;
  user-select: none;
  margin-left: auto;
}
.nav-menu-toggle:hover { background: #2a3543; color: #fff; }
.nav-menu-panel {
  display: none;
  position: absolute;
  right: 20px;
  top: 62px;
  background: var(--ink);
  border: 1px solid #3a4553;
  border-radius: 8px;
  padding: 12px;
  flex-direction: column;
  gap: 8px;
  min-width: 220px;
  z-index: 20;
}
.nav-toggle-checkbox:checked ~ .nav-menu-panel { display: flex; }
.nav-menu-panel nav { display: flex; flex-direction: column; gap: 2px; }
/* JS relocates .logout-form into #nav-menu-panel on mobile (see base.html) --
   this only ever matches in that nested state, so the divider disappears
   automatically once JS moves it back out for desktop. */
.nav-menu-panel .logout-form { margin-top: 8px; padding-top: 8px; border-top: 1px solid #3a4553; }

@media (min-width: 760px) {
  .nav-menu-toggle { display: none; }
  /* Centered independently of the brand/logout widths on either side --
     absolute positioning takes it out of .topbar's flex flow entirely, so
     it doesn't compete for space with .logout-form's own margin-left:auto
     (below), which needs .topbar's real leftover flex space to push
     against. */
  .nav-menu-panel {
    display: flex;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    right: auto;
    background: none;
    border: none;
    padding: 0;
    border-radius: 0;
    gap: 24px;
    min-width: 0;
    z-index: auto;
  }
  .nav-menu-panel nav { flex-direction: row; gap: 4px; }
  .logout-form { margin-left: auto; }
}

main { max-width: 960px; margin: 0 auto; padding: 20px 16px 48px; }

.impersonate-banner {
  background: var(--safety);
  color: var(--ink);
  font-weight: 700;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  text-align: center;
}
.impersonate-banner form { margin: 0; }
.impersonate-banner .btn-quiet {
  margin-top: 0;
  border-color: var(--ink);
  color: var(--ink);
  background: rgba(255,255,255,0.3);
}
.impersonate-banner .btn-quiet:hover { background: rgba(255,255,255,0.5); }

/* ---- Admin tables ---- */
.tablewrap { overflow-x: auto; margin-bottom: 16px; }
table.admin {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
table.admin th, table.admin td { padding: 10px 14px; text-align: right; border-bottom: 1px solid var(--line); }
table.admin th:first-child, table.admin td:first-child { text-align: left; }
table.admin th {
  background: var(--paper);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
}
table.admin tr:last-child td { border-bottom: none; }
table.admin tr.total-row td { font-weight: 800; background: var(--paper); }

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 24px 0 32px;
}
.foot-links { display: block; margin-top: 6px; }
.foot-links a { color: var(--muted); }

/* ---- Stat strip ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin: 4px 0 24px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 5px solid var(--safety);
  border-radius: 8px;
  padding: 12px 14px;
  text-decoration: none;
  color: inherit;
  display: block;
  cursor: pointer;
}
.stat:hover, .stat:focus-visible {
  border-color: var(--blueprint);
  border-left-color: var(--blueprint);
}
.stat.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.stat.active span { color: #b8c2cd; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; }
.stat.alert { border-left-color: var(--danger); }
.stat.good  { border-left-color: var(--ok); }
.stat.active.alert, .stat.active.good { border-left-color: var(--safety); }

.filter-note { color: var(--muted); margin: 0; }
.filter-note a { color: var(--blueprint); }

/* ---- Toolbar with Hide-done toggle ---- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: -8px 0 16px;
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
}
.toggle:hover, .toggle:focus-visible { border-color: var(--blueprint); color: var(--ink); }
.toggle-track {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  flex-shrink: 0;
}
.toggle-dot {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.toggle.on { color: var(--ink); border-color: var(--ok); }
.toggle.on .toggle-track { background: var(--ok); }
.toggle.on .toggle-dot { left: 16px; }

/* ---- Sections & cards ---- */
h1 { font-size: 1.5rem; margin: 8px 0 16px; }
h2 { font-size: 1.1rem; margin: 28px 0 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
}

.settings-link {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-decoration: none;
  color: inherit;
}
.settings-link strong { font-size: 1.05rem; }
.settings-link:hover { border-color: var(--blueprint); }

/* ---- Call list ---- */
.call-row {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
  text-decoration: none;
  color: inherit;
}
.call-row:hover, .call-row:focus-visible { border-color: var(--blueprint); }
.call-row .who { font-weight: 700; }
.call-row .what { color: var(--muted); font-size: 0.92rem; margin-top: 2px; }
.call-row .meta { color: var(--muted); font-size: 0.8rem; margin-top: 6px; }

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 4px;
  padding: 2px 8px;
  margin-left: 8px;
  vertical-align: middle;
}
.badge.booked    { background: #e2f3e8; color: var(--ok); }
.badge.callback  { background: #fdf1e0; color: var(--warn); }
.badge.emergency { background: #fbe4e2; color: var(--danger); }
.badge.info      { background: #e8eef8; color: var(--blueprint); }
.badge.unreviewed{ background: var(--safety); color: var(--ink); }
.badge.done      { background: var(--ok); color: #fff; }

/* ---- Job status card: schedule/confirm state + all its actions in one place ---- */
.jobstate {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-left: 5px solid var(--warn);
}
.jobstate.done { border-left-color: var(--ok); background: #f2faf5; }
.jobstate.declined { border-left-color: var(--danger); background: #fbf2f1; }
.jobstate form { margin: 0; }
.jobstate .hint { color: var(--muted); font-size: 0.85rem; margin-left: 8px; }
.job-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.job-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.btn-done {
  background: var(--ok);
  margin-top: 0;
}
.btn-done:hover { background: #166335; }
.btn-quiet {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  margin-top: 0;
}
.btn-quiet:hover { background: #eef0ee; color: var(--ink); }
.btn-decline {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  margin-top: 0;
}
.btn-decline:hover { background: #fbe4e2; }

/* ---- Call detail: back button left, prev/next grouped on the right ---- */
.call-nav { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.call-nav-group { display: flex; gap: 8px; }
.call-nav-link {
  display: inline-block;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--ink);
  text-decoration: none;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
}
.call-nav-link:hover, .call-nav-link:focus-visible { border-color: var(--blueprint); color: var(--blueprint); }

/* ---- Admin sub-pages: back-links / sub-nav row -- same pill style as
   .call-nav-link so it reads as part of the app instead of default browser
   link styling, and wraps instead of overflowing the viewport on mobile. ---- */
.admin-links { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-links a {
  display: inline-block;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--ink);
  text-decoration: none;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  white-space: nowrap;
}
.admin-links a:hover, .admin-links a:focus-visible { border-color: var(--blueprint); color: var(--blueprint); }
.call-nav-link.disabled { color: var(--muted); opacity: 0.5; pointer-events: none; }

/* ---- Detail page ---- */
.kv { margin: 0 0 16px; }
.kv dt { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.kv dd { margin: 0 0 10px; font-weight: 600; }
.transcript {
  white-space: pre-wrap;
  background: #fbfcfa;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  font-size: 0.95rem;
  max-height: 420px;
  overflow-y: auto;
}

/* ---- Setup page tabs ---- */
.setup-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--line);
  flex-wrap: wrap;
}
.setup-tab {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  margin-top: 0;
  margin-bottom: -2px;
  padding: 10px 14px;
  font-size: 0.92rem;
}
.setup-tab:hover { background: transparent; color: var(--ink); }
.setup-tab.active { color: var(--ink); border-bottom-color: var(--blueprint); }

/* ---- Forms ---- */
form.stack label { display: block; font-weight: 700; margin: 14px 0 4px; }
form.stack .hint { font-weight: 400; color: var(--muted); font-size: 0.85rem; display: block; }
input[type=text], input[type=tel], input[type=email], input[type=password], select, textarea {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
textarea { min-height: 84px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 3px solid var(--safety);
  outline-offset: 1px;
}
.check { display: flex; align-items: center; gap: 10px; margin: 12px 0; font-weight: 600; }
.check input { width: 22px; height: 22px; }

button, .btn {
  display: inline-block;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 13px 22px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  margin-top: 18px;
}
button:hover { background: #2a3543; }

.rating { display: flex; gap: 8px; margin: 8px 0; }
.rating label {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 700;
}
.rating input { position: absolute; opacity: 0; }
.rating input:checked + span { color: var(--blueprint); }
.rating label:has(input:checked) { border-color: var(--blueprint); background: #e8eef8; }

/* ---- Prompt preview ---- */
pre.prompt {
  white-space: pre-wrap;
  background: var(--ink);
  color: #e8ecf1;
  border-radius: 8px;
  padding: 18px;
  font-size: 0.88rem;
  line-height: 1.55;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
  border: 2px dashed var(--line);
  border-radius: 10px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---- Next job hero ---- */
.next-job { margin: 0 0 20px; }
.next-job-label {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}
.next-job .feed-row { margin-bottom: 0; border-width: 2px; padding: 14px 16px; }

/* ---- Needs attention & upcoming feed ---- */
.feed { margin-bottom: 8px; }
.feed-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  color: inherit;
  text-decoration: none;
  margin-bottom: 8px;
}
.feed-row:last-child { margin-bottom: 0; }
.feed-row:hover, .feed-row:focus-visible { border-color: var(--blueprint); }
.feed-row.overdue-row { border-left-color: var(--danger); }
.feed-row.unconfirmed { border-left-color: var(--warn); }
.feed-row.confirmed { border-left-color: var(--ok); }
.feed-chip {
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 0.78rem;
  border-radius: 6px;
  padding: 6px 9px;
  white-space: nowrap;
  flex-shrink: 0;
}
.feed-chip.overdue { background: var(--danger); }
.feed-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.feed-title {
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.feed-desc {
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.feed-badge {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.feed-badge.unconfirmed { background: var(--warn); color: #fff; }
.feed-badge.confirmed { background: var(--ok); color: #fff; }
.feed-badge.conflict { background: var(--danger); color: #fff; }

.toggle-form { margin: 0; }
button.toggle { margin-top: 0; font-family: inherit; cursor: pointer; }

.savednote { border-left: 5px solid var(--ok); color: var(--ok); font-weight: 700; }
.errornote { border-left: 5px solid var(--danger); color: var(--danger); font-weight: 700; }

/* ---- Auth pages ---- */
.authwrap { max-width: 420px; margin: 40px auto; }
.authwrap h1 { text-align: center; }
.authwrap .foot-link { text-align: center; margin-top: 18px; color: var(--muted); }
.authwrap .foot-link a { color: var(--blueprint); font-weight: 700; text-decoration: none; }
.authwrap button { width: 100%; }

/* ---- Overdue + conflict flags ---- */
.clashwarn { border-left: 5px solid var(--danger); }
.clash-item { margin: 6px 0; }
.clash-item a { color: var(--blueprint); font-weight: 700; }

/* ---- SMS thread on a job ---- */
.msg-item { padding: 8px 0; border-bottom: 1px solid var(--line); }
.msg-item:last-child { border-bottom: none; }
.msg-meta { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 2px; }
.msg-item.in .msg-meta { color: var(--blueprint); }
.msg-body { font-size: 0.95rem; }
