/* Global & Variables */
:root {
  --brand: #1D499B;
  --danger: #b91c1c;
  --bg: #f6f8fc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 10px 25px rgba(2, 6, 23, .08);
  --radius: 14px;
}

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* Layout */
.wrap {
  max-width: 1280px;
  margin: 28px auto;
  padding: 0 18px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.grid3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Typography */
h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -.3px;
}

.sub {
  color: var(--muted);
  margin-top: 6px;
  font-size: 13px;
}

.k {
  font-size: 12px;
  color: #334155;
  text-transform: uppercase;
  font-weight: 900;
  letter-spacing: .05em;
}

.v {
  margin-top: 6px;
  font-weight: 800;
}

.muted {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-top: 4px;
}

.mini {
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

a {
  color: var(--brand);
  text-decoration: none;
  font-weight: 700;
}

a:hover {
  text-decoration: underline;
}

/* Components */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  padding: 16px;
  margin-bottom: 14px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--brand);
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 1px 0 rgba(2, 6, 23, .03);
  display: inline-block;
  text-decoration: none;
}

.btn.primary {
  background: var(--brand);
  color: #fff;
  border-color: transparent;
}

.btn.small {
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 12px;
}

.btn.danger {
  color: var(--danger);
  border-color: var(--danger);
}

.btn.danger-solid {
  background-color: #dc2626;
  color: white;
  border: 0;
}

.btn:hover {
  filter: brightness(.98);
}

.btn:active {
  transform: translateY(1px);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff;
  font-weight: 800;
  font-size: 12px;
  color: #0f172a;
}

.alert {
  background: #fee2e2;
  color: var(--danger);
  padding: 10px;
  border-radius: 12px;
  margin-bottom: 12px;
  border: 1px solid rgba(185, 28, 28, .25);
  font-weight: 900;
}

/* Tables */
table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 12px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8fafc;
  font-size: 12px;
  color: #334155;
  text-transform: uppercase;
  letter-spacing: .05em;
}

td {
  font-size: 14px;
}

.manifest-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.manifest-table th {
  background: #f8fafc;
}

.manifest-table th,
.manifest-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.manifest-table td:last-child {
  text-align: right;
}

.manifest-scroll {
  margin-bottom: 14px;
  max-height: 240px;
  overflow-y: auto;
}

.manifest-table th {
  position: sticky;
  top: 0;
  z-index: 5;
}

/* Forms */
.field {
  margin: 10px 0;
}

label {
  display: block;
  font-weight: 900;
  font-size: 12px;
  color: #334155;
  margin-bottom: 6px;
}

input,
select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  background: #fff;
  box-sizing: border-box;
}

input:focus,
select:focus {
  border-color: rgba(29, 73, 155, .5);
  box-shadow: 0 0 0 3px rgba(29, 73, 155, .12);
}

/* The global input/select rule above (full-width, padded, rounded) isn't
   meant for checkboxes/radios — it hit the allocBasis radios, the case-size
   radios, and the manifest's checkbox column (stretching it into a
   full-width rounded box). These are the only checkbox/radio inputs in the
   app, so one global override here is safe rather than a local escape hatch
   per usage. */
input[type="checkbox"],
input[type="radio"] {
  width: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
}

.error-input {
  border-color: var(--danger);
  background: #fff5f5;
}

.error-text {
  color: var(--danger);
  font-size: 12px;
  margin-top: 6px;
  font-weight: 800;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}

.modal {
  width: min(920px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: #fbfdff;
}

.modal-title {
  font-weight: 900;
}

.x {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  padding: 8px 10px;
  cursor: pointer;
  font-weight: 900;
  color: #334155;
}

.modal-body {
  padding: 16px;
}

.hr-modal {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.modal-subtitle {
  font-weight: 900;
  margin: 14px 0 8px;
}

.modal-sm {
  width: 400px;
  max-width: 100%;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: #fbfdff;
}

/* Page-specific styles */

/* Login / Register Page */
.login-body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.login-container {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 400px;
}

.login-container h2 {
  margin-top: 0;
  color: #333;
  text-align: center;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: #666;
  font-weight: normal;
}

.form-group input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-sizing: border-box;
  font-size: 1rem;
}

.auth-footer {
  margin-top: 1rem;
  text-align: center;
  font-size: 0.9rem;
}

.login-container button {
  width: 100%;
  padding: 0.75rem;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s;
}

.login-container button:hover {
  background-color: #0056b3;
}

.error-msg, .success-msg {
  padding: 0.75rem;
  border-radius: 4px;
  margin-bottom: 1rem;
  display: none;
}

.error-msg {
  color: #dc3545;
  background-color: #f8d7da;
  border: 1px solid #f5c6cb;
}

.success-msg {
  color: #155724;
  background-color: #d4edda;
  border: 1px solid #c3e6cb;
}

/* TOTP Setup */
.totp-qr {
  text-align: center;
  margin-bottom: 16px;
}

.totp-qr img {
  width: 200px;
  height: 200px;
}

.totp-secret {
  background: #f4f4f5;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 12px;
  text-align: center;
  font-family: monospace;
  font-size: 18px;
  letter-spacing: 2px;
  margin-bottom: 8px;
  word-break: break-all;
}

.totp-instructions {
  text-align: left;
  margin-bottom: 20px;
  padding-left: 20px;
  line-height: 1.8;
  font-size: 14px;
}

.copy-btn {
  margin-bottom: 20px;
  font-size: 13px;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--brand);
  text-decoration: underline;
}

.text-muted-sm {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

/* Map View */
.map-body {
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

#info {
  position: absolute;
  top: 12px;
  left: 12px;
  display: none;
  background: rgba(255, 255, 255, .92);
  border-radius: 10px;
  padding: 10px 12px;
  font: 13px/1.3 system-ui, Arial, sans-serif;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .15);
  z-index: 2;
  pointer-events: auto;
  max-width: min(90vw, 320px);
}

#info .value {
  font-weight: 700;
}

@media (max-width: 640px) {
  #info {
    top: 8px;
    left: 8px;
    padding: 8px 10px;
    font-size: 12px;
  }
}

/* Utilities */
.mr-auto { margin-right: auto; }
.text-center { text-align: center; }

.flex { display: flex; }
.flex-between { justify-content: space-between; }
.items-center { align-items: center; }
.justify-end { justify-content: flex-end; }

.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-10 { gap: 10px; }
.gap-12 { gap: 12px; }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }

.mt-0 { margin-top: 0; }
.mt-4 { margin-top: 4px; }
.mb-4 { margin-bottom: 4px; }
.mb-6 { margin-bottom: 6px; }
.mb-10 { margin-bottom: 10px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }

.pt-12 { padding-top: 12px; }
.p-12 { padding: 12px; }

.border-top { border-top: 1px solid var(--border); }
.w-100 { width: 100%; }
.bold { font-weight: 900; }
.nowrap { white-space: nowrap; }
.text-13 { font-size: 13px; }

.map-container { position: relative; width: 100%; height: 360px; }
.map-iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }


.surplus { color: #1a7f37; font-weight: 600; }
.deficit { color: #c43a31; font-weight: 600; }
/* ---- Multi-stop routes -------------------------------------------------
   A route visits an ordered list of stops. The row order IS the drive order,
   so the number and the move controls carry real meaning here. */

.stop-list { display: flex; flex-direction: column; gap: 6px; }

.stop-row {
  display: grid;
  grid-template-columns: 24px 1fr auto auto auto;
  align-items: center;
  gap: 6px;
}

.stop-row .stop-num {
  width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  background: #e8eef6; color: #33475b;
}

.stop-row select { width: 100%; }
.stop-row .btn.small { padding: 2px 8px; line-height: 1.4; }
.stop-row .btn:disabled { opacity: .35; cursor: default; }

.stop-actions {
  display: flex; align-items: center; gap: 10px; margin-top: 8px;
}

.case-size-radios { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.case-size-option { display: flex; align-items: center; gap: 6px; font-weight: 700; cursor: pointer; }

.stop-listing { margin: 6px 0 0; padding-left: 20px; }
.stop-listing li { margin-bottom: 6px; }
.stop-listing li span { display: block; }

.leg-table { width: 100%; border-collapse: collapse; }
.leg-table td { padding: 4px 6px; border-bottom: 1px solid #eef1f5; }
.leg-table .num { text-align: right; white-space: nowrap; }
.leg-table .leg-total td { font-weight: 700; border-top: 2px solid #d8dee7; border-bottom: none; }

.mt-16 { margin-top: 16px; }

/* Post-delivery corrections: the "Corrected" pairing shown alongside an
   estimate, and the signed overage-cost readout (a credit when the run came
   in under estimate is just as real as a surcharge, so both get a color). */
.corrected-value { color: #33475b; font-weight: 700; }
.overage-pos { color: var(--danger); }
.overage-neg { color: #0f9d58; }

/* The est-vs-actual "components" line (Drive/Handling/Distance/Total) is a
   variable subset — each actual field is independently optional, so which
   spans render varies per route. A CSS-driven separator avoids needing
   Jinja to track "is this the first visible one": :first-child only counts
   ELEMENT children, so whichever .overage-part renders first never gets a
   leading " · ", and every one after it does, automatically. */
.overage-part:not(:first-child)::before { content: " · "; color: var(--muted); }

/* ---- Searchable selects -------------------------------------------------
   Every <select> gets a type-to-search combobox layered on top of it (see
   static/searchable-select.js). The original <select> is kept in the DOM —
   it's still the real submitting form control — but visually hidden via
   the standard "visually-hidden" technique (not display:none, so it stays
   reachable/predictable, just removed from the visual flow). */

select.ss-native-select {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}

.ss-wrap {
  position: relative;
}

.ss-input {
  /* Inherits width/padding/border/radius/background from the app's global
     `input, select` rule above — this is what gives it the same native
     look as every other field. */
  cursor: text;
  padding-right: 28px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.ss-input:disabled {
  background-color: #f1f5f9;
  color: var(--muted);
  cursor: not-allowed;
}

.ss-list {
  display: none;
  position: fixed; /* escapes .modal's overflow:hidden — see position() in
                       searchable-select.js, which sets top/left/width. */
  z-index: 999;
  max-height: 240px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 4px;
}

.ss-list.ss-open {
  display: block;
}

.ss-option {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ss-option.ss-active {
  background: #eef2ff;
}

.ss-option.ss-selected {
  font-weight: 800;
}

.ss-empty {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.ss-disabled .ss-input {
  background-color: #f1f5f9;
}
