/* ─── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --card:     #21253a;
  --border:   #2e3350;
  --accent:   #5b7cf6;
  --accent2:  #38bdf8;
  --green:    #34d399;
  --yellow:   #fbbf24;
  --red:      #f87171;
  --text:     #e2e8f0;
  --muted:    #64748b;
  --radius:   12px;
  --font:     'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ─── Header ────────────────────────────────────────────────────────────── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header h1 { font-size: 1.15rem; font-weight: 700; flex: 1; min-width: 160px; }
.header h1 span { color: var(--accent); }

.header-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

select, button {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font);
  transition: background .15s, border-color .15s;
}
select:hover, button:hover { border-color: var(--accent); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.primary:hover { background: #4a6ee0; }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
  margin-right: 4px;
}
.status-dot.ok   { background: var(--green); }
.status-dot.err  { background: var(--red); }

/* ─── Route Chips ───────────────────────────────────────────────────────── */
.route-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.route-bar::-webkit-scrollbar { display: none; }

.chip {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.chip:hover  { border-color: var(--accent); color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.filter-group {
  display: flex;
  flex-direction: row;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.filter-sep {
  width: 1px;
  min-height: 20px;
  align-self: stretch;
  background: var(--border);
  margin: 0 12px;
  flex-shrink: 0;
}

.time-chip.active { background: #4caf82; border-color: #4caf82; }

/* ─── Tab Bar ───────────────────────────────────────────────────────────── */
.tab-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  gap: 0;
  overflow-x: auto;
}

.tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: all .15s;
  white-space: nowrap;
}
.tab:hover  { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ─── Main Content ──────────────────────────────────────────────────────── */
.content { padding: 24px; max-width: 1400px; margin: 0 auto; }

/* ─── Stat Cards ────────────────────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.card-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.card-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
}
.badge-depart { background: #1e3a5f; color: var(--accent2); }
.badge-arrive { background: #1a3a2b; color: var(--green); }

.card-value { font-size: 2rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.card-unit  { font-size: 12px; color: var(--muted); }

.card-stats {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.stat-item label { display: block; font-size: 10px; color: var(--muted); margin-bottom: 2px; }
.stat-item span  { font-size: 13px; font-weight: 600; }
.stat-best  { color: var(--green); }
.stat-worst { color: var(--red); }

/* ─── Section ───────────────────────────────────────────────────────────── */
.section { margin-bottom: 28px; }
.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 14px;
}

/* ─── Charts ────────────────────────────────────────────────────────────── */
.chart-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

canvas { display: block; width: 100%; }

/* ─── Tables ────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  padding: 10px 14px;
  background: var(--surface);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(91,124,246,.06); }
tbody td { padding: 9px 14px; vertical-align: middle; }

.td-route  { font-weight: 600; }
.td-road   { color: var(--accent2); font-size: 12px; }
.td-min    { color: var(--green); font-weight: 600; }
.td-max    { color: var(--red);   font-weight: 600; }
.td-avg    { font-weight: 600; }

.mini-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}

/* ─── Best Routes ───────────────────────────────────────────────────────── */
.best-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.best-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.best-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.best-card-day   { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.best-card-route { font-weight: 700; font-size: 1rem; }
.best-card-road  { color: var(--accent2); font-size: 12px; margin-top: 2px; }

.best-card-stats {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.alts { margin-top: 10px; }
.alt-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
}
.alt-row:last-child { border-bottom: none; }
.alt-row span { color: var(--text); }

/* ─── Spinner / empty ───────────────────────────────────────────────────── */
.loading, .empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-size: 15px;
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Schedule tags in Overview ─────────────────────────────────────────── */
.schedule-table { margin-top: 10px; font-size: 12px; color: var(--muted); }
.schedule-row   { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.schedule-tag {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
}

/* ─── Advisor Cards ─────────────────────────────────────────────────────── */
.advisor-card {
  border-left: 3px solid var(--accent);
}

.advisor-departure {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 10px 0 6px;
}

.advisor-leave-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.advisor-leave-time {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
}

.advisor-countdown {
  font-size: 13px;
  font-weight: 600;
  color: var(--green);
}
.advisor-countdown.urgent { color: var(--red); }
.advisor-countdown.muted  { color: var(--muted); }

.advisor-days {
  font-size: 11px;
  color: var(--muted);
  margin: 4px 0;
}

.advisor-stages {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 10px;
}

.advisor-stage {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: capitalize;
  letter-spacing: .02em;
}
.advisor-stage.fired   { background: rgba(52,211,153,.15); color: var(--green); }
.advisor-stage.pending { background: var(--card); color: var(--muted); border: 1px solid var(--border); }

.muted-text { color: var(--muted); }

/* ─── Quick Trip Split Button ───────────────────────────────────────────── */
.qt-split {
  position: relative;
  display: flex;
  align-items: stretch;
}

.quick-trip-btn {
  background: rgba(251,191,36,.12);
  border: 1px solid rgba(251,191,36,.35);
  border-right: none;
  color: var(--yellow);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px 0 0 999px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.quick-trip-btn:hover {
  background: rgba(251,191,36,.22);
  border-color: rgba(251,191,36,.6);
}

.qt-split-arrow {
  background: rgba(251,191,36,.12);
  border: 1px solid rgba(251,191,36,.35);
  color: var(--yellow);
  font-size: 11px;
  padding: 5px 8px;
  border-radius: 0 999px 999px 0;
  cursor: pointer;
  transition: all .15s;
  line-height: 1;
}
.qt-split-arrow:hover {
  background: rgba(251,191,36,.22);
  border-color: rgba(251,191,36,.6);
}

.qt-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 180px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  z-index: 200;
  overflow: hidden;
}

.qt-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background .1s;
  border-radius: 0;
  font-family: var(--font);
}
.qt-menu-item:hover {
  background: rgba(248,113,113,.1);
  color: var(--red);
  border-color: transparent;
}

.qt-delete-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  margin-left: 2px;
  transition: color .15s, background .15s;
}
.qt-delete-btn:hover {
  color: var(--red);
  background: rgba(248,113,113,.12);
  border-color: transparent;
}

/* ─── One-time Trip Badge & Card ────────────────────────────────────────── */
.badge-one-time {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: var(--yellow);
  background: rgba(251,191,36,.12);
  border: 1px solid rgba(251,191,36,.3);
  border-radius: 999px;
  padding: 1px 7px;
  vertical-align: middle;
  margin-left: 4px;
  letter-spacing: .03em;
}

.one-time-card {
  border-left-color: var(--yellow);
}

/* ─── Quick Trip Modal ──────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
}

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

.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); background: var(--card); border-color: transparent; }

.modal-body {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.modal-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.modal-req { color: var(--red); }

.modal-field input,
.modal-field select {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: var(--font);
}
.modal-field input:focus,
.modal-field select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Address picker inside the Quick Trip modal */
.modal-body .addr-wrap {
  position: relative;
  display: flex;
  gap: 4px;
  align-items: stretch;
}
.modal-body .addr-wrap input[type=text] {
  flex: 1;
  min-width: 0;
  width: auto;
}
.modal-body .addr-pick-btn {
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 0 10px;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font);
  line-height: 1;
  transition: border-color .15s, color .15s;
}
.modal-body .addr-pick-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}
.modal-body .addr-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 600;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.modal-body .addr-dropdown.open { display: block; }
.modal-body .addr-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.modal-body .addr-item:last-child { border-bottom: none; }
.modal-body .addr-item:hover { background: rgba(91,124,246,.12); color: var(--text); }
.modal-body .addr-empty {
  padding: 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.modal-footer {
  padding: 14px 20px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
}

.modal-error {
  flex: 1;
  font-size: 12px;
  color: var(--red);
  min-width: 0;
}

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .header  { padding: 10px 14px; }
  .content { padding: 14px; }
  .tab     { padding: 8px 12px; font-size: 12px; }
  .tab-bar { padding: 0 8px; }          /* more room for tabs on narrow screens */
  .header h1 { font-size: 1rem; min-width: 0; }

  /* Stack filter bar vertically on mobile */
  .route-bar {
    flex-direction: column;
    align-items: flex-start;
    overflow-x: visible;
    gap: 6px;
    padding: 10px 14px;
  }
  .filter-group {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .filter-sep {
    width: 100%;
    min-height: 0;
    height: 1px;
    margin: 2px 0;
  }
}
