/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-green: #22c55e;
  --color-yellow: #eab308;
  --color-gray: #94a3b8;
  --color-red: #ef4444;
  --color-blue: #3b82f6;
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-border: #334155;
  --color-text: #f1f5f9;
  --color-muted: #94a3b8;
  --radius: 10px;
  --font: system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Map ──────────────────────────────────────────────────────────────────── */
#map {
  width: 100%;
  height: 50vh;
  min-height: 280px;
  background: #1e293b;
  position: relative;
  z-index: 0;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 20px;
  font-size: 1rem;
  font-family: var(--font);
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

button:active {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--color-blue);
  color: white;
}

.btn-success {
  background: var(--color-green);
  color: white;
}

.btn-danger {
  background: var(--color-red);
  color: white;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-warn {
  background: var(--color-yellow);
  color: #1c1917;
}

/* ── Layout Containers ────────────────────────────────────────────────────── */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

/* ── Offline / Status Banners ─────────────────────────────────────────────── */
#offline-banner {
  display: none;
  background: var(--color-red);
  color: white;
  text-align: center;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.95rem;
}

#offline-banner.visible {
  display: block;
}

.status-bar {
  padding: 8px 16px;
  font-size: 0.8rem;
  color: var(--color-muted);
  text-align: center;
  border-bottom: 1px solid var(--color-border);
}

/* ── Stop List ────────────────────────────────────────────────────────────── */
#stop-list {
  list-style: none;
  padding: 8px 0;
}

#stop-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.95rem;
}

#stop-list li:last-child {
  border-bottom: none;
}

.stop-name {
  font-weight: 500;
}

.stop-eta {
  font-size: 0.85rem;
  font-weight: 600;
  text-align: right;
  min-width: 70px;
}

.stop-completed .stop-name { color: var(--color-green); }
.stop-completed .stop-eta  { color: var(--color-green); }

.stop-next .stop-name { color: var(--color-yellow); font-weight: 700; }
.stop-next .stop-eta  { color: var(--color-yellow); }

.stop-future .stop-name { color: var(--color-muted); }
.stop-future .stop-eta  { color: var(--color-muted); }

/* ── Countdown View ───────────────────────────────────────────────────────── */
#countdown-view {
  display: none;
  text-align: center;
  padding: 48px 24px;
}

#countdown-view.visible {
  display: block;
}

.countdown-label {
  font-size: 1rem;
  color: var(--color-muted);
  margin-bottom: 8px;
}

.countdown-time {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 32px;
}

.countdown-clock {
  font-size: 3.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--color-yellow);
  letter-spacing: 0.05em;
}

.countdown-sublabel {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--color-muted);
}

/* ── Live View ────────────────────────────────────────────────────────────── */
#live-view {
  display: none;
}

#live-view.visible {
  display: block;
}

/* ── Driver Page ──────────────────────────────────────────────────────────── */
#driver-header {
  background: var(--color-surface);
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#driver-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
}

#start-btn {
  width: 100%;
  font-size: 1.2rem;
  min-height: 56px;
  margin-bottom: 0;
}

#next-stop-card {
  padding: 14px 16px;
}

#next-stop-card .label {
  font-size: 0.75rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

#next-stop-name {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--color-yellow);
}

#next-stop-eta {
  font-size: 0.9rem;
  color: var(--color-muted);
  margin-top: 2px;
}

.controls-row {
  display: flex;
  gap: 10px;
  padding: 10px 16px;
}

.controls-row button {
  flex: 1;
}

#wake-warning {
  background: #78350f;
  color: #fef3c7;
  text-align: center;
  padding: 8px 16px;
  font-size: 0.85rem;
  display: none;
}

#wake-warning.visible {
  display: block;
}

#driver-status {
  text-align: center;
  padding: 8px 16px;
  font-size: 0.8rem;
  color: var(--color-muted);
}

/* ── Admin Page ───────────────────────────────────────────────────────────── */
.admin-section {
  margin-bottom: 24px;
}

.admin-section h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.form-row {
  display: flex;
  gap: 8px;
}

input[type="text"],
input[type="datetime-local"],
select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 1rem;
  font-family: var(--font);
}

input[type="text"]:focus,
input[type="datetime-local"]:focus,
select:focus {
  outline: none;
  border-color: var(--color-blue);
}

input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
}

label {
  font-size: 0.85rem;
  color: var(--color-muted);
  font-weight: 500;
}

.admin-stop-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-stop-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.admin-stop-item .stop-index {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.admin-stop-item .stop-label {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-stop-item button {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.btn-icon {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  width: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 6px;
  font-size: 1rem;
}

.route-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.route-tab {
  flex: 1;
  min-height: 40px;
  font-size: 0.9rem;
}

.route-tab.active {
  background: var(--color-blue);
  color: white;
}

.schedule-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.schedule-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 0.9rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 9999;
  white-space: nowrap;
}

.toast.visible {
  opacity: 1;
}

/* ── QR Code ──────────────────────────────────────────────────────────────── */
#qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px;
}

#qr-container canvas {
  border-radius: 8px;
}

#qr-url {
  font-size: 0.75rem;
  color: var(--color-muted);
  word-break: break-all;
  text-align: center;
}

/* ── Rider Page Header ────────────────────────────────────────────────────── */
.rider-header {
  padding: 14px 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.rider-header h1 {
  font-size: 1.1rem;
  font-weight: 700;
}

#route-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--color-blue);
  color: white;
}

/* ── Center Button ────────────────────────────────────────────────────────── */
#center-btn {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 400;
  background: white;
  color: #1e293b;
  border: none;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  min-height: 36px;
}

#map-wrapper {
  position: relative;
}

/* ── No Stops / Empty State ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--color-muted);
  font-size: 0.9rem;
}

/* ── Scrollable Stop List ────────────────────────────────────────────────── */
#stop-list-wrapper {
  overflow-y: auto;
  max-height: calc(50vh - 48px);
}

/* ── Page Title / Admin Header ────────────────────────────────────────────── */
.page-header {
  padding: 14px 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.page-header h1 {
  font-size: 1.2rem;
  font-weight: 700;
}

.page-header p {
  font-size: 0.8rem;
  color: var(--color-muted);
  margin-top: 2px;
}
