:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --surface-2: #fafbfa;
  --surface-hover: #f3f7f4;
  --text: #1a1a1a;
  --muted: #666;
  --border: #e7e7e7;
  --input-bg: #ffffff;
  --accent: #2f6f4f;
  --danger: #b3261e;
  --shift-a: #2f8f5b;
  --shift-g: #3568b0;
  --shift-b: #b3771f;
  --shift-c: #5b3fa0;

  --th-grad-1: #ffe985;
  --th-grad-2: #ffd93d;
  --th-border: #e8c94a;
  --th-text: #4a3c00;

  --pill-bg: #eef2f0;
  --pill-border: #d7ded9;
  --chip-bg: #eef1f0;

  --alert-success-bg: #d8f5e0;
  --alert-success-text: #164a2c;
  --alert-error-bg: #fdd;

  --badge-locked-bg: #ffd8d8;
  --badge-open-bg: #d8f5e0;
  --stat-missing-bg: #fdecd2;
  --stat-missing-text: #7a4a05;

  --day-locked-bg: #f0f0f0;
  --nav-bg: #1f2a24;

  --shadow-1: 0 1px 2px rgba(20, 20, 20, 0.04), 0 1px 6px rgba(20, 20, 20, 0.03);

  /* Boarding-point color coding, cycled by the point's route order */
  --pt0-bg: #dbe6f5; --pt0-border: #b9cdea; --pt0-text: #1d3a66;
  --pt1-bg: #fde3cf; --pt1-border: #f0c98f; --pt1-text: #8a4b12;
  --pt2-bg: #d7f0e6; --pt2-border: #b3e0cc; --pt2-text: #14523a;
  --pt3-bg: #ece0fb; --pt3-border: #d5c0f0; --pt3-text: #4a2d7a;
}

:root[data-theme="dark"] {
  --bg: #14171a;
  --card: #1c2024;
  --surface-2: #20252a;
  --surface-hover: #262b30;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --border: #2c3238;
  --input-bg: #22262b;
  --accent: #45a578;
  --danger: #ff6b61;

  --th-grad-1: #7a5f12;
  --th-grad-2: #5f4a0d;
  --th-border: #4a3a0a;
  --th-text: #ffe9a8;

  --pill-bg: #262b30;
  --pill-border: #333941;
  --chip-bg: #262b30;

  --alert-success-bg: #14351f;
  --alert-success-text: #8fe3ac;
  --alert-error-bg: #3a1a1a;

  --badge-locked-bg: #3a1a1a;
  --badge-open-bg: #14351f;
  --stat-missing-bg: #3a2a10;
  --stat-missing-text: #f0b463;

  --day-locked-bg: #22262b;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 6px rgba(0, 0, 0, 0.25);

  --pt0-bg: #1e3350; --pt0-border: #2c4870; --pt0-text: #a9c6ef;
  --pt1-bg: #4a2f10; --pt1-border: #6b451a; --pt1-text: #f5c98a;
  --pt2-bg: #123a2b; --pt2-border: #1e5940; --pt2-text: #8fe0bb;
  --pt3-bg: #2e2050; --pt3-border: #453070; --pt3-text: #cbb0f0;
}

* { box-sizing: border-box; }

input, select, textarea, button {
  color: var(--text);
  background: var(--input-bg);
  font-family: inherit;
}

body {
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  transition: background-color 0.2s ease, color 0.2s ease;
}

nav {
  background: var(--nav-bg);
  color: #fff;
  padding: 10px 20px;
}

nav a { color: #fff; text-decoration: none; margin-right: 16px; font-size: 14px; transition: opacity 0.15s ease; }
nav a:hover { opacity: 0.75; text-decoration: underline; }
nav form { display: inline; }
nav .brand { font-weight: 700; }

.nav-toggle-checkbox { display: none; }
.nav-brand-row { display: flex; align-items: center; justify-content: space-between; }
.nav-brand-controls { display: flex; align-items: center; gap: 12px; }
.nav-toggle-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 28px;
  height: 28px;
  cursor: pointer;
}
.nav-toggle-btn span { display: block; width: 100%; height: 2px; background: #fff; border-radius: 2px; transition: transform 0.2s ease, opacity 0.2s ease; }

.nav-collapsible { display: flex; align-items: center; }
.nav-links-left, .nav-links-right { display: flex; align-items: center; flex-wrap: wrap; }
.nav-links-right { gap: 14px; }
.nav-username { margin-right: 0; }

/* Desktop: brand+links-left grouped on the left, links-right pinned to the far right */
@media (min-width: 821px) {
  nav { display: flex; align-items: center; }
  .nav-brand-row { margin-right: 24px; }
  .nav-collapsible { flex: 1; justify-content: space-between; }
}

/* Mobile: collapse everything but the brand + toggle behind a hamburger */
@media (max-width: 820px) {
  .nav-toggle-btn { display: flex; }
  .nav-collapsible {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    max-height: 0;
    overflow: hidden;
    margin-top: 0;
    transition: max-height 0.25s ease, margin-top 0.25s ease;
  }
  .nav-links-left, .nav-links-right { flex-direction: column; align-items: flex-start; gap: 10px; width: 100%; }
  #nav-toggle:checked ~ .nav-collapsible { max-height: 600px; margin-top: 14px; }
  #nav-toggle:checked ~ .nav-brand-row .nav-toggle-btn span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  #nav-toggle:checked ~ .nav-brand-row .nav-toggle-btn span:nth-child(2) { opacity: 0; }
  #nav-toggle:checked ~ .nav-brand-row .nav-toggle-btn span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
}

.container { max-width: 1100px; margin: 20px auto; padding: 0 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-1);
  transition: background-color 0.2s ease, border-color 0.2s ease;
  animation: fadeInUp 0.35s ease both;
}

h1 { font-size: 22px; margin-top: 0; }
h2 { font-size: 18px; }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 10px 0 0;
  border: 1px solid var(--border);
  border-radius: 10px;
}
table { border-collapse: collapse; width: 100%; margin: 0; }
th, td { padding: 12px 14px; text-align: center; font-size: 14px; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); }
th:last-child, td:last-child { border-right: none; }

.roster-table { table-layout: fixed; min-width: 1000px; }
.roster-table th:nth-child(1), .roster-table td:nth-child(1) { width: 10%; }
.roster-table th:nth-child(2), .roster-table td:nth-child(2) { width: 8%; }
.roster-table th:nth-child(3), .roster-table td:nth-child(3) { width: 15%; }
.roster-table th:nth-child(4), .roster-table td:nth-child(4) { width: 34%; }
.roster-table th:nth-child(5), .roster-table td:nth-child(5) { width: 10%; }
.roster-table th:nth-child(6), .roster-table td:nth-child(6) { width: 8%; }
.roster-table th:nth-child(7), .roster-table td:nth-child(7) { width: 15%; }
th {
  background: linear-gradient(180deg, var(--th-grad-1), var(--th-grad-2));
  color: var(--th-text);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid var(--th-border);
  overflow: hidden;
  text-overflow: ellipsis;
}
.roster-table th { white-space: normal; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) { background: var(--surface-2); }
tbody tr { transition: background-color 0.15s ease; }
tbody tr:hover { background: var(--surface-hover); }

.pickup-time, .drop-time { font-weight: 700; font-size: 15px; }

.shift-badge {
  display: inline-block;
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.3px;
  padding: 2px 9px;
  border-radius: 999px;
  margin-top: 3px;
}
.shift-badge.code-A { background: var(--shift-a); }
.shift-badge.code-G { background: var(--shift-g); }
.shift-badge.code-B { background: var(--shift-b); }
.shift-badge.code-C { background: var(--shift-c); }

.count-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
}

.point-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: var(--chip-bg);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 12px;
  margin: 3px 0;
}
.point-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.point-chip b { font-weight: 700; flex-shrink: 0; }

.stat-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  animation: fadeIn 0.4s ease both;
}
.stat-pill.selected { background: var(--alert-success-bg); color: var(--alert-success-text); }
.stat-pill.missing { background: var(--stat-missing-bg); color: var(--stat-missing-text); }

.live-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin-top: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  color: var(--muted);
  font-size: 12.5px;
}
.live-badge b { color: var(--text); font-weight: 700; }
.live-sep { opacity: 0.5; }
.live-dot {
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent);
  animation: livePulse 1.6s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

.day-card {
  display: flex; justify-content: space-between; align-items: center; padding: 12px;
  border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; flex-wrap: wrap; gap: 10px;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.day-card.locked { opacity: 0.6; background: var(--day-locked-bg); }
.day-date { font-weight: 600; min-width: 180px; }
.trip-type-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.trip-radio { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); cursor: pointer; }
.trip-radio input { cursor: pointer; }
.shift-options { display: flex; gap: 8px; flex-wrap: wrap; }
.shift-btn {
  border: 1px solid var(--border); border-radius: 20px; padding: 6px 14px; cursor: pointer;
  background: var(--card); font-size: 13px; color: var(--text);
  transition: transform 0.12s ease, background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.shift-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--shadow-1); }
.shift-btn:active:not(:disabled) { transform: translateY(0); }
.shift-btn.selected { background: var(--accent); color: #fff; border-color: var(--accent); animation: pop 0.25s ease; }
.shift-btn:disabled { cursor: not-allowed; opacity: 0.55; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 12px; background: var(--chip-bg); }
.badge.locked { background: var(--badge-locked-bg); color: var(--danger); }
.badge.open { background: var(--badge-open-bg); color: var(--accent); }

.btn {
  display: inline-block; background: var(--accent); color: #fff; border: none; padding: 8px 16px;
  border-radius: 6px; cursor: pointer; font-size: 14px; text-decoration: none;
  transition: transform 0.12s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}
.btn.secondary { background: #555; }
.btn.danger { background: var(--danger); }
.btn:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: var(--shadow-1); }
.btn:active { transform: translateY(0); }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 14px; animation: slideDown 0.25s ease both; }
.alert.success { background: var(--alert-success-bg); color: var(--alert-success-text); }
.alert.error { background: var(--alert-error-bg); color: var(--danger); }

.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 13px; margin-bottom: 4px; color: var(--muted); }
.form-row input, .form-row select {
  width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-row input:focus, .form-row select:focus, .inline-form input:focus, .inline-form select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 111, 79, 0.15);
}

.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input, .inline-form select { padding: 4px 6px; font-size: 13px; border: 1px solid var(--border); border-radius: 4px; }

.tabs { margin-bottom: 16px; }
.tabs a { margin-right: 14px; font-size: 14px; color: var(--accent); text-decoration: none; }
.tabs a.active { font-weight: 700; text-decoration: underline; }

.route-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.route-tab {
  display: inline-block;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.route-tab:hover { transform: translateY(-1px); }
.route-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

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

.name-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.name-pill-row { display: inline-flex; align-items: center; gap: 6px; }
.name-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  border-radius: 999px;
  padding: 4px 10px 4px 12px;
  font-size: 13px;
  white-space: nowrap;
}
.team-tag {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.trip-tag {
  background: var(--stat-missing-bg);
  color: var(--stat-missing-text);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.name-pill-row select { padding: 2px 4px; font-size: 12px; }

/* Boarding-point color coding -- applied to both the per-employee pill and the
   breakdown chip so the two visually match without needing a legend. */
.name-pill.pt-0, .point-chip.pt-0 { background: var(--pt0-bg); border-color: var(--pt0-border); color: var(--pt0-text); }
.name-pill.pt-1, .point-chip.pt-1 { background: var(--pt1-bg); border-color: var(--pt1-border); color: var(--pt1-text); }
.name-pill.pt-2, .point-chip.pt-2 { background: var(--pt2-bg); border-color: var(--pt2-border); color: var(--pt2-text); }
.name-pill.pt-3, .point-chip.pt-3 { background: var(--pt3-bg); border-color: var(--pt3-border); color: var(--pt3-text); }
.point-chip.pt-0, .point-chip.pt-1, .point-chip.pt-2, .point-chip.pt-3 { border: 1px solid transparent; }

.theme-toggle {
  position: relative;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background-color 0.15s ease, transform 0.15s ease;
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.16); transform: translateY(-1px); }
.theme-toggle svg { position: absolute; transition: opacity 0.3s ease, transform 0.4s ease; }
.theme-toggle .icon-sun { opacity: 1; transform: rotate(0deg) scale(1); }
.theme-toggle .icon-moon { opacity: 0; transform: rotate(-90deg) scale(0.6); }
:root[data-theme="dark"] .theme-toggle .icon-sun { opacity: 0; transform: rotate(90deg) scale(0.6); }
:root[data-theme="dark"] .theme-toggle .icon-moon { opacity: 1; transform: rotate(0deg) scale(1); }
.theme-toggle-standalone { position: fixed; top: 16px; right: 16px; z-index: 10; background: var(--card); border-color: var(--border); color: var(--text); box-shadow: var(--shadow-1); }
.theme-toggle-standalone:hover { background: var(--surface-hover); }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pop {
  0% { transform: scale(0.9); }
  60% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 480px) {
  .form-row input, .form-row select, .inline-form input, .inline-form select {
    font-size: 16px; /* prevents iOS Safari auto-zoom on focus */
  }
}

/* Mobile-only "Landscape View" toggle for the driver link -- rotates the
   roster card 90deg via CSS so a wide table is usable on a narrow phone
   screen without relying on the phone's own auto-rotate being enabled. */
.landscape-toggle-btn {
  display: none;
  margin: 0 auto 14px;
  gap: 6px;
}
.landscape-exit-btn {
  display: none;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 12px;
}

@media (max-width: 820px) {
  .landscape-toggle-btn { display: inline-flex; }
  body.landscape-mode .landscape-toggle-btn { display: none; }
}

/* The rotate hack only makes sense while the phone is still reporting a
   portrait viewport -- i.e. auto-rotate is locked. If auto-rotate is ON,
   physically turning the phone already makes the browser re-render
   natively in landscape; applying our own rotate on top of that would
   double-rotate the content. .physically-landscape (set via JS from
   matchMedia) marks that case so we back off and let it render normally. */
body.landscape-mode:not(.physically-landscape) {
  overflow: hidden;
}
body.landscape-mode:not(.physically-landscape) .landscape-target {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vh;
  height: 100vw;
  margin: 0;
  max-width: none;
  border-radius: 0;
  transform-origin: top left;
  transform: rotate(90deg) translateY(-100%);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1000;
  animation: none;
}
body.landscape-mode .landscape-exit-btn {
  display: inline-block;
  position: sticky;
  top: 0;
}

/* Sits outside .landscape-target so it never inherits the rotation -- stays
   upright and readable the instant landscape mode turns on, before the
   driver has actually turned their phone. */
.landscape-hint { display: none; }
body.landscape-mode.physically-landscape .landscape-hint,
body.landscape-mode.hint-dismissed .landscape-hint { display: none; }
body.landscape-mode .landscape-hint {
  display: block;
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-1);
  z-index: 1001;
  animation: fadeIn 0.3s ease both;
}
