:root{
  /* Theme tokens (overridden by .theme-day / .theme-night on <body>) */
  --bg:#0f1220; --panel:#171a2b; --ink:#e9edf1; --muted:#9aa3b2; --line:#262a40; --accent:#7cc4ff;
  --gap:12px; --panelW:380px;
  --tab-offset:72px;
}
/* All theme tokens are overridden by .theme-day/.theme-night; keep layout tokens (e.g., --gap, --panelW) here. */

/* =========================
   Light (Day) theme tokens
   ========================= */
body.theme-day{
  --bg:#f3f4f6;        /* page background */
  --panel:#ffffff;     /* sidebar panel */
  --card:#f9fafb;      /* section/card background (soft, not pure white) */
  --field:#ffffff;     /* input/button background */
  --ink:#0f172a;       /* primary text */
  --muted:#4b5563;     /* secondary text */
  --line:#e5e7eb;      /* borders */
  --accent:#2563eb;    /* primary accent */
}

/* =========================
   Dark (Night) theme tokens
   ========================= */
body.theme-night{
  --bg:#0f1220;
  --panel:#171a2b;
  --card:#11152a;
  --field:#0f1325;
  --ink:#e9edf1;
  --muted:#9aa3b2;
  --line:#262a40;
  --accent:#7cc4ff;
}

/* Base element resets & global transitions */
*{box-sizing:border-box}
html,body{height:100%;margin:0}
body{min-height:100dvh;background:var(--bg);color:var(--ink);font:16px/1.5 system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial;overflow:auto}
/* Lock page while password gate is active */
body.gated{ overflow:hidden; position:fixed; inset:0; width:100%; height:100dvh; overscroll-behavior:none; }
body, .card, .sidebar, #map, input, button { transition: background-color .35s ease, color .35s ease, border-color .35s ease; }

/* Layout & sidebar */
.app{display:grid;grid-template-rows:auto 1fr;min-height:100dvh}
.tab-bar{grid-column:1 / -1;display:flex;gap:8px;padding:12px 16px;background:var(--panel);border-bottom:1px solid var(--line);align-items:center;min-height:var(--tab-offset)}
.tab-btn{width:auto;flex:0 0 auto;padding:10px 18px;border-radius:999px;border:1px solid var(--line);background:transparent;color:var(--ink);font-weight:600;margin-top:0}
.tab-btn.active{background:var(--accent);color:#fff;border-color:var(--accent)}
.theme-toggle{margin-left:auto;display:inline-flex;border:1px solid var(--line);border-radius:999px;overflow:hidden}
.theme-option{position:relative;display:flex;align-items:center}
.theme-option input{position:absolute;opacity:0;pointer-events:none}
.theme-option span{display:block;padding:6px 12px;font-size:12px;font-weight:600;text-transform:uppercase;letter-spacing:.05em;color:var(--muted);cursor:pointer;background:transparent;transition:background .2s,color .2s}
.theme-option input:checked + span{background:var(--accent);color:#fff}
.sidebar{padding:16px;background:var(--panel);border-bottom:1px solid var(--line)}
.header h1{margin:0 0 4px;font-size:20px}
.sub{margin:0;color:var(--muted);font-size:12px}

/* Cards, rows, and typographic tweaks */
.card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:12px;margin-top:12px}

/* Reduce extra top space for card titles */
.card h3{ margin: 0 0 8px; }
.row{display:flex;justify-content:space-between;align-items:center;gap:12px;margin:6px 0}
.row > :first-child{flex:1;min-width:0}
.row > :last-child{flex:none}
.total{font-weight:800}

.row.price-toggle{ margin-top: 14px; }

/* Form controls */
input,button{width:100%;padding:12px;border-radius:10px;border:1px solid var(--line);background:var(--field);color:var(--ink)}
button{border:0;background:var(--accent);color:#fff;font-weight:800;cursor:pointer;margin-top:8px}
.hint{color:var(--muted);font-size:12px;margin:6px 0 0}
.prep-hint{min-height:16px}
.job-meta .duration-field{display:flex;align-items:center;gap:8px;margin:8px 0 4px}
.job-meta .duration-field input{margin:0}
.job-meta .duration-field span{font-weight:600;color:var(--muted)}

/* Prevent iOS Safari zoom-on-focus by ensuring controls are >=16px text size */
html{ -webkit-text-size-adjust: 100%; }
input, select, textarea{ font-size:16px; }

/* Mono font for numeric readouts */
.mono{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;white-space:nowrap}

/* Map area */
.map{ min-height:45vh; position:relative; }
#map{ width:100%; height:100%; border-top:1px solid var(--line); }
#map{touch-action: pan-y;}
@media (max-width: 899px){
  .app{ display:block; min-height:auto; }
  .tab-bar{position:sticky;top:0;z-index:5}
  .map{ height:60vh; }
  #map{ height:100%; }
}

/* Responsive: put sidebar left of map on wide screens */
@media (min-width: 900px){
  body{overflow:hidden;}
  .app{
    grid-template-columns:var(--panelW) 1fr;
    grid-template-rows:auto minmax(0,1fr);
    min-height:100vh;
  }
  .sidebar{
    height:calc(100vh - var(--tab-offset));
    border-right:1px solid var(--line);
    border-bottom:0;
    overflow:auto;
    padding-right:8px;
  }
  .map{
    position:sticky;
    top:var(--tab-offset);
    height:calc(100vh - var(--tab-offset));
    min-height:0;
  }
  #map{
    height:100%;
  }
.schedule-panel{
  height:calc(100vh - var(--tab-offset));
  overflow:auto;
  padding-bottom:48px;
}
}

/* ===== iOS-like Emergency toggle ===== */
.toggle-card { display: flex; align-items: center; justify-content: space-between; }
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch .slider { position: relative; width: 52px; height: 32px; border-radius: 999px; background: #2a2f47; transition: background 200ms ease, box-shadow 200ms ease; box-shadow: inset 0 0 0 1px #0a0f1f; }
.switch.standard .slider { background: #2a2f47; } /* neutral for standard/off */
.switch.emergency .slider { background: #dc2626; } /* red for emergency/on */
.switch .slider::before { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform 200ms ease; box-shadow: 0 1px 2px rgba(0,0,0,.35); }
.switch.emergency .slider::before { transform: translateX(20px); }
.toggle-label { font-weight: 600; font-size: 14px; }

/* Show only ONE pricing card at a time (Emergency is hidden by default) */
#emergencyPricing { display: none; }

/* Red emphasis for long routes (≥100 mi or ≥2h) */
.mono.danger { color: #dc2626; }
/* Applied by updateThresholdAlert when miles ≥ ALERT_MILE_THRESHOLD or duration ≥ ALERT_DURATION_THRESHOLD_SEC */

/* ===== Copy icon next to Miles over 20 ===== */
.copy-wrap{display:inline-flex;align-items:center;gap:6px;white-space:nowrap}
/* Inline layout: places the copy icon immediately left of the numeric readout without breaking layout on narrow screens */
.icon-btn{display:inline-flex;align-items:center;justify-content:center;border:0;background:transparent;padding:0 2px;cursor:pointer;color:var(--muted);line-height:1}
.icon-btn:hover{color:var(--ink)}
.icon-btn:active{transform:scale(0.96)}
/* Make the SVG ignore text baselines so it truly centers within the flex button */
.icon-btn svg{width:16px;height:16px;display:block;transform:translateY(-4px)}

/* ===== Simple password gate overlay ===== */
#gateOverlay{position:fixed;inset:0;z-index:9999;background:#0a0c18;display:flex;align-items:center;justify-content:center;padding:20px}
.gate-card{width:min(480px, 92vw);background:var(--panel);border:1px solid var(--line);border-radius:14px;padding:18px;box-shadow:0 10px 30px rgba(0,0,0,.4)}
.gate-card h2{margin:0 0 6px;font-size:18px}
.gate-card p{margin:6px 0 14px;color:var(--muted);font-size:13px}
.gate-row{display:flex;flex-direction:column;gap:10px;align-items:stretch}
.gate-row input{flex:initial}
.gate-error{color:#dc2626;font-size:12px;min-height:16px;margin-top:8px}
.hidden{display:none !important}


/* Make the sidebar Map Controls Satellite toggle turn green when ON */
.map-controls .switch.emergency .slider { background: #16a34a; }

/* ===== Scheduling tab ===== */
.schedule-panel{grid-column:1 / -1;padding:16px 16px 32px;display:flex;justify-content:center;width:100%;box-sizing:border-box}
.schedule-panel[hidden]{display:none}
.schedule-stack{width:100%;max-width:1200px;display:flex;flex-direction:column;gap:12px;margin:0 auto}
.schedule-stack .card{width:100%}
.schedule-stack::after{
  content:"";
  display:block;
  height:32px;
  flex-shrink:0;
}
.sched-status{font-size:14px;color:var(--muted)}
.current-job-card{margin-bottom:12px}
.current-job{display:flex;justify-content:space-between;align-items:center;gap:20px;flex-wrap:wrap}
.current-job-fee{padding:12px 16px;border:1px solid var(--line);border-radius:12px;background:var(--card);min-width:220px}
.current-job-fee .fee-total{font-size:20px;font-weight:700;margin:4px 0}
.current-job-fee .fee-breakdown{margin:0;color:var(--muted);font-size:12px}
.current-job h2{margin:4px 0}
.refresh-btn{flex:0 0 auto;width:auto;padding:10px 18px}
.sched-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:18px;margin:16px 0;position:relative;min-height:240px}
.sched-grid.loading::before{content:"Loading schedule…";position:absolute;inset:0;background:rgba(10,15,30,.82);color:#fff;font-weight:600;font-size:16px;display:flex;align-items:center;justify-content:center;border-radius:18px;z-index:10}
.sched-grid.loading{pointer-events:none}
@media (min-width: 1200px){
  .sched-grid{grid-template-columns:repeat(4, minmax(250px,1fr))}
}
.sched-cell{border:1px solid var(--line);border-radius:18px;padding:26px 18px 18px;background:var(--card);display:flex;flex-direction:column;gap:12px;position:relative;transition:border-color .2s ease, box-shadow .2s ease, transform .2s ease;overflow:visible}
.sched-cell .sched-head{display:flex;justify-content:space-between;align-items:center;gap:8px}
.sched-cell .weekday{font-weight:700;font-size:16px;text-transform:uppercase;letter-spacing:.08em;color:var(--accent)}
.sched-cell .date-wrap{text-align:right}
.sched-cell .date-num{font-size:34px;font-weight:800;line-height:1}
.sched-cell .month-label{font-size:14px;color:var(--muted)}
.sched-cell .busy-wrap{display:flex;align-items:center;gap:8px;font-size:12px;text-transform:uppercase;letter-spacing:.1em;color:var(--muted)}
.sched-cell .busy-bar{height:10px;border-radius:999px;background:var(--line);overflow:hidden;flex:1}
.sched-cell .busy-bar span{display:block;height:100%;background:var(--accent);transition:width .3s}
.sched-cell .busy-bar span.maxed{background:#dc2626}
.sched-cell .sched-metrics{font-size:13px;color:var(--muted);display:flex;flex-direction:column;gap:4px}
.sched-cell .sched-badges{display:flex;flex-wrap:wrap;gap:6px}
.sched-cell .badge{padding:3px 10px;border-radius:999px;font-size:11px;font-weight:600;background:rgba(255,255,255,.08);border:1px solid var(--line);text-transform:uppercase;letter-spacing:.05em}
.sched-cell.blocked{border-color:#b91c1c;box-shadow:0 4px 14px rgba(185,28,28,.25)}
.sched-cell.is-top{border-color:var(--accent);box-shadow:0 6px 18px rgba(59,130,246,.35);transform:translateY(-3px)}
.sched-cell.is-top-one{border-color:#10b981;box-shadow:0 6px 18px rgba(16,185,129,.4)}
.sched-cell .hours-flag{font-weight:700}
.sched-cell .hours-flag.danger{color:#dc2626}
.sched-cell .target-badge{position:absolute;top:6px;right:16px;font-size:11px;text-transform:uppercase;letter-spacing:.08em;font-weight:700;padding:2px 10px;border-radius:999px;background:rgba(59,130,246,.15);color:var(--accent);box-shadow:0 4px 10px rgba(0,0,0,.2)}
.sched-cell.is-top-one .target-badge{background:rgba(16,185,129,.2);color:#059669}
.sched-cell.is-top-other .target-badge{background:rgba(59,130,246,.15);color:var(--accent)}
@media (max-width: 640px){
  .sched-grid{grid-template-columns:repeat(auto-fit,minmax(160px,1fr))}
}
.schedule-recs{margin-top:16px}
.sched-rec-list{margin:16px 0 0;padding-left:20px;display:flex;flex-direction:column;gap:10px}
.sched-rec-list{margin:16px 0 0;padding-left:20px;display:flex;flex-direction:column;gap:10px;position:relative;min-height:180px}
.sched-rec-list.loading{pointer-events:none}
.sched-rec-list.loading::before{content:"Loading schedule…";position:absolute;inset:0;background:rgba(10,15,30,.82);color:#fff;font-weight:600;font-size:16px;display:flex;align-items:center;justify-content:center;border-radius:12px;z-index:5}
.sched-rec-list.loading > *{opacity:0.2}
.sched-rec-item{padding:10px 12px;border:1px solid var(--line);border-radius:10px;background:var(--card)}
.sched-rec-item.additional{border-style:dashed}
.sched-rec-item.over-limit{border-style:dashed;border-color:var(--line)}
.sched-rec-item strong{display:block;font-size:16px}
.sched-rec-meta{margin:4px 0 0;font-size:13px;color:var(--muted)}
.sched-rec-detail{margin:4px 0 0;font-size:13px;display:flex;flex-wrap:wrap;gap:6px;align-items:center}
.sched-rec-detail span{white-space:nowrap}
.sched-rec-detail .delta{font-weight:700}
.sched-rec-detail .delta.negative{color:#10b981}
.sched-rec-detail .delta.positive{color:#f97316}
.sched-rec-detail .delta.positive.best{color:#10b981}
.sched-rec-detail .delta.danger{color:#dc2626}
.card-header-row{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:8px}
.card-header-row h2{margin:0}
.switch.weekend .slider{background:#2a2f47}
.switch.weekend input:checked + .slider{background:#10b981}
.switch.weekend input:checked + .slider::before{transform:translateX(20px)}
.pac-container{z-index:10000!important}
.sched-rec-detail .delta.best{color:#10b981}
.sched-rec-detail .limit-pill{
  padding:2px 8px;
  border-radius:999px;
  font-weight:600;
}
.sched-rec-detail .limit-pill{background:rgba(248,113,113,.15);color:#b91c1c}
