:root {
  color-scheme: dark;
  --bg: #0d0d0d; /* ChatGPT main page black */
  --panel: #171717; /* ChatGPT dark gray cards */
  --panel-soft: #212121; /* Highlight panels */
  --text: #ececec; /* Soft white text */
  --muted: #b4b4b4; /* Muted gray text */
  --line: #2f2f2f; /* ChatGPT dark border gray */
  --accent: #10a37f; /* ChatGPT signature green */
  --accent-dark: #0d8b6c; /* Dark green accent */
  --active-bg: rgba(16, 163, 127, 0.15); /* Soft ChatGPT green background overlay */
  --ok: #10a37f;
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.15); /* Soft glowing amber background */
  --warn-text: #fbbf24; /* High-contrast golden text */
  --bad: #ef4444;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f9f9f9; /* Clean light gray */
  --panel: #ffffff; /* Pure white cards */
  --panel-soft: #f4f4f4; /* Muted gray panels */
  --text: #0d0d0d; /* ChatGPT light mode deep dark black text */
  --muted: #676767; /* Muted gray text */
  --line: #e3e3e3; /* Light gray borders */
  --accent: #10a37f; /* ChatGPT signature green */
  --accent-dark: #0d8b6c;
  --active-bg: rgba(16, 163, 127, 0.08); /* Very soft green highlight overlay */
  --ok: #10a37f;
  --warn: #d97706;
  --warn-bg: #fff8ea; /* Classic light yellow */
  --warn-text: #5e3a00; /* Classic dark brown text */
  --bad: #dc2626;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0 auto;
  max-width: 428px; /* Strict iPhone 12 Pro Max CSS width */
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.15); /* Premium mobile app wrapper shadow */
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--panel); /* Dynamically reactive panel color */
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
  width: 100%;
  max-width: 428px;
  margin: 0 auto;
  left: 0;
  right: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.1;
}

h2 {
  font-size: 20px;
}

h3 {
  margin-bottom: 8px;
  font-size: 16px;
}

.layout {
  width: 100%;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 140px; /* Perfect side-by-side fit on a 390px-428px viewport */
  gap: 8px;
  align-items: stretch;
  margin-bottom: 8px;
}

.week-box,
.card,
.route-list,
.route-detail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.week-box {
  padding: 6px 10px;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.primary-button,
.icon-button,
.tab,
.route-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

.primary-button {
  padding: 0 10px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.primary-button:active {
  background: var(--accent-dark);
}

.icon-button {
  width: 42px;
  height: 42px;
  font-size: 20px;
}

.day-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px; /* Reduced gap to maximize horizontal space */
  margin-bottom: 12px;
}

.tab {
  min-height: 48px; /* Tighter vertical height */
  padding: 4px 2px;
  text-align: center; /* Center-aligned for elegant mobile tabs */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.tab strong {
  display: block;
  font-size: 11px; /* Scaled down for mobile */
  line-height: 1.2;
}

.tab span {
  display: block;
  color: var(--muted);
  font-size: 9px; /* Scaled down for mobile */
  line-height: 1.1;
  margin-top: 2px;
}

.tab.active {
  border-color: var(--accent);
  background: var(--active-bg);
}

.content {
  display: block; /* Strict mobile-first stacking */
  width: 100%;
}

.route-list {
  display: block;
  width: 100%;
  padding: 6px;
}

.route-detail {
  display: none; /* Hidden until driver selects a tour */
  width: 100%;
  padding: 8px;
}

/* Dynamic swap using body class added by app.js */
body.has-route-selected .route-list {
  display: none !important;
}

body.has-route-selected .route-detail {
  display: block !important;
}

/* Premium back to tour list button */
.back-to-list-button {
  display: block;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--active-bg);
  border: 1px solid var(--accent);
  color: var(--text);
  font-family: inherit;
  font-weight: 800;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}

.back-to-list-button:active {
  background: #d4e8ff;
}

.route-button {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 10px;
  text-align: left;
}

.route-button.active {
  border-color: var(--accent);
  background: var(--active-bg);
}

.route-button strong,
.route-button span {
  display: block;
}

.route-button span {
  color: var(--muted);
  font-size: 12px;
}

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

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  background: #e7f6ee;
  color: var(--ok);
}

.badge.warn {
  background: #fff3df;
  color: var(--warn);
}

.grid {
  display: grid;
  grid-template-columns: 1fr; /* Stack layout cards vertically by default for mobile-first */
  gap: 12px;
}

.card {
  padding: 12px;
}

.full {
  grid-column: 1 / -1;
}

.task,
.stop,
.load-row {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.task:first-child,
.stop:first-child,
.load-row:first-child {
  border-top: 0;
}

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

.sector {
  color: var(--ok);
  font-weight: 900;
}

.missing {
  color: var(--bad);
  font-weight: 900;
}

.body-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.body-meta span {
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.body-block {
  margin-top: 10px;
}

.body-block h4 {
  margin: 0 0 8px;
  font-size: 14px;
}

.body-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px; /* Tighter gap to maximize horizontal space */
}

.body-column {
  min-height: 120px; /* Compact mobile-first height */
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-soft); /* ChatGPT theme-reactive column background */
}

.body-column-head {
  padding: 4px 2px;
  background: var(--line); /* Theme-reactive header background */
  color: var(--text); /* Theme-reactive text color */
  font-weight: 900;
  text-align: center;
  font-size: 11px;
}

.body-column ol {
  margin: 0;
  padding: 6px 4px 8px 16px; /* Reduced left padding from 28px to 16px to maximize text space! */
}

.body-column li {
  min-height: auto;
  padding: 2px 0;
  border-bottom: 1px solid var(--line); /* Theme-reactive line border */
  font-size: 11px;
  overflow-wrap: anywhere;
  color: var(--text);
}

.body-column li.matched {
  color: var(--accent); /* High-contrast ChatGPT signature green for matched containers */
  font-weight: 900;
}

.body-notes {
  margin-top: 10px;
  padding: 10px;
  border-left: 4px solid var(--warn);
  border-radius: 6px;
  background: var(--warn-bg); /* Theme-reactive amber/yellow background */
  color: var(--warn-text); /* Theme-reactive amber/brown text */
  font-size: 13px;
  font-weight: 700;
}

.empty-state {
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
}

dialog {
  width: min(420px, calc(100% - 24px));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
}

.dialog-card {
  padding: 16px;
}

.dropzone {
  margin: 14px 0;
  padding: 28px 14px;
  border: 2px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

/* Feedback Dialog & Form Inputs */
.form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
}

.form-group label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 4px;
}

.dialog-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.secondary-button {
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.secondary-button:active {
  background: var(--line);
}

/* Interactive Warehouse Grid Map Styles */
.sector-cell {
  padding: 10px 2px;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--text);
  transition: all 0.3s ease;
  user-select: none;
}

.sector-cell-wide {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sector-cell.empty {
  opacity: 0.15;
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--muted);
  font-weight: 400;
}

.sector-cell.highlighted {
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 900;
  animation: pulse-glow 1.5s infinite ease-in-out;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

@keyframes pulse-glow {
  0% {
    background-color: rgba(16, 163, 127, 0.4);
    box-shadow: 0 0 4px var(--accent);
    transform: scale(1);
  }
  50% {
    background-color: rgba(16, 163, 127, 0.95);
    box-shadow: 0 0 14px var(--accent);
    transform: scale(1.04);
  }
  100% {
    background-color: rgba(16, 163, 127, 0.4);
    box-shadow: 0 0 4px var(--accent);
    transform: scale(1);
  }
}

