/* ==========================================================================
   Smart Traffic Signal Demo - Stylesheet
   CSE-ICB Interactive Educational Simulation
   Pure Vanilla CSS - No external dependencies or frameworks required
   ========================================================================== */

:root {
  --font-system: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  
  /* Color Palette */
  --bg-app: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-muted: #f8fafc;
  --bg-asphalt: #1e293b;
  
  --border-light: #e2e8f0;
  --border-subtle: #edf2f7;
  --border-dark: #334155;
  
  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverted: #f8fafc;
  
  /* Primary & Accent */
  --accent-primary: #0284c7;
  --accent-primary-hover: #0369a1;
  --accent-primary-light: #e0f2fe;
  
  /* Traffic Signals */
  --signal-red: #ef4444;
  --signal-red-glow: rgba(239, 68, 68, 0.45);
  --signal-yellow: #f59e0b;
  --signal-yellow-glow: rgba(245, 158, 11, 0.45);
  --signal-green: #10b981;
  --signal-green-glow: rgba(16, 185, 129, 0.45);
  
  /* Emergency Theme */
  --emergency-primary: #0284c7;
  --emergency-glow: rgba(2, 132, 199, 0.35);
  --emergency-badge: #dbeafe;
  --emergency-badge-text: #1e40af;
  
  /* Dimensions & Shadows */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
}

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

html, body {
  overflow-x: hidden;
  width: 100%;
}

body {
  font-family: var(--font-system);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Top App Header */
.app-header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
  width: 100%;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background-color: #0f172a;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 4px;
  flex-shrink: 0;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.4);
}

.brand-icon-light {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.brand-icon-light.red { background-color: var(--signal-red); box-shadow: 0 0 5px var(--signal-red); }
.brand-icon-light.yellow { background-color: var(--signal-yellow); box-shadow: 0 0 5px var(--signal-yellow); }
.brand-icon-light.green { background-color: var(--signal-green); box-shadow: 0 0 5px var(--signal-green); }

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-text p {
  font-size: 0.78rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  font-size: 0.68rem;
  font-weight: 600;
  background-color: var(--accent-primary-light);
  color: var(--accent-primary);
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Header Controls & Status Pill */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background-color: var(--bg-muted);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--signal-green);
  box-shadow: 0 0 6px var(--signal-green-glow);
  flex-shrink: 0;
}

.status-pill.emergency {
  background-color: #fef2f2;
  border-color: #fecaca;
  color: #991b1b;
}

.status-pill.emergency .status-dot {
  background-color: var(--signal-red);
  box-shadow: 0 0 8px var(--signal-red);
  animation: pulse-dot 1.2s infinite ease-in-out;
}

.status-pill.paused {
  background-color: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}
.status-pill.paused .status-dot {
  background-color: var(--signal-yellow);
  box-shadow: none;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

/* Common Button Styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background-color: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  min-height: 36px;
}

.btn:hover {
  background-color: var(--bg-muted);
  border-color: var(--border-medium);
}

.btn:active {
  transform: translateY(1px);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
  min-height: 28px;
}

.btn-primary {
  background-color: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--accent-primary-hover);
  border-color: var(--accent-primary-hover);
}

.btn-icon {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* Main Layout Grid */
.app-container {
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: minmax(0, 1.8fr) minmax(360px, 1.2fr);
  gap: 24px;
  align-items: start;
  flex: 1;
}

/* Simulation Section (Left) */
.simulation-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.canvas-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.canvas-header {
  padding: 10px 16px;
  background-color: var(--bg-muted);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.canvas-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.canvas-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0.3px;
}

.demand-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 12px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-light);
  font-size: 0.74rem;
  font-weight: 600;
}

.canvas-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Interactive View Mode / Zoom Toggle Button */
.view-toggle-btn {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-medium);
  color: var(--text-main);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 16px;
  transition: all 0.15s ease;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.view-toggle-btn:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background-color: var(--accent-primary-light);
}

.view-toggle-btn.active {
  background-color: var(--accent-primary-light);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.canvas-viewport {
  width: 100%;
  aspect-ratio: 1 / 1;
  position: relative;
  background-color: #0f172a;
}

#traffic-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Preemption Notification Banner inside Viewport */
.preemption-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  background-color: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  color: #ffffff;
  border: 1px solid #0284c7;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 16px rgba(2, 132, 199, 0.35);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  max-width: 90%;
  text-align: center;
}

.preemption-banner.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.banner-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #38bdf8;
  box-shadow: 0 0 8px #38bdf8;
  animation: pulse-beacon 0.8s infinite alternate ease-in-out;
  flex-shrink: 0;
}

@keyframes pulse-beacon {
  0% { transform: scale(0.9); opacity: 0.6; }
  100% { transform: scale(1.3); opacity: 1; }
}

/* Mobile Quick-Status Strip: Always visible under the viewport on mobile */
.mobile-quick-strip {
  display: none; /* hidden on desktop */
  background-color: #0f172a;
  border-top: 1px solid #334155;
  padding: 8px 14px;
  color: #f8fafc;
  font-size: 0.76rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-stat-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.quick-phase-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.quick-label {
  color: #94a3b8;
  font-size: 0.72rem;
  font-weight: 600;
}

.quick-phase-item strong {
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
}

.quick-metrics-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quick-badge {
  background-color: #1e293b;
  border: 1px solid #334155;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  color: #cbd5e1;
}

.quick-badge strong {
  color: #38bdf8;
  font-weight: 700;
}

/* Simulation Legend Bar */
.canvas-legend {
  padding: 10px 16px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-around;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}
.legend-swatch.sensor {
  border: 1.5px dashed #0284c7;
  background-color: rgba(2, 132, 199, 0.2);
}
.legend-swatch.ambulance {
  background-color: #ffffff;
  border: 1px solid #94a3b8;
  box-shadow: inset 0 0 0 2px #0284c7;
}
.legend-swatch.stopline {
  background-color: #ffffff;
  border: 1px solid #475569;
}

/* Right Dashboard Column */
.dashboard-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

/* Mobile Segmented Tab Switcher (Visible only on mobile <= 768px) */
.mobile-tabs-nav {
  display: none; /* hidden on desktop */
  background-color: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
  box-shadow: var(--shadow-sm);
}

.mobile-tab-btn {
  flex: 1;
  padding: 8px 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
  white-space: nowrap;
}

.mobile-tab-btn.active {
  background-color: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(2, 132, 199, 0.3);
}

/* Metrics Cards Row */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.metric-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-title {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.metric-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.metric-desc {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

/* Signal Phase Monitor Card */
.dashboard-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 12px 16px;
  background-color: var(--bg-muted);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2 {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-content {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Direction Phase Pairs */
.phase-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background-color: var(--bg-muted);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  gap: 10px;
}

.phase-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.phase-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
}

.phase-detail {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.phase-status-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
}

.phase-badge {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.phase-badge.green {
  background-color: #d1fae5;
  color: #065f46;
}
.phase-badge.yellow {
  background-color: #fef3c7;
  color: #92400e;
}
.phase-badge.red {
  background-color: #fee2e2;
  color: #991b1b;
}

.phase-timer {
  font-size: 0.92rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-main);
  min-width: 44px;
  text-align: right;
}

/* Mini Signal Head Visual */
.mini-signal-head {
  display: flex;
  gap: 3px;
  background-color: #0f172a;
  padding: 3px 5px;
  border-radius: 12px;
  align-items: center;
}
.mini-lamp {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  opacity: 0.2;
}
.mini-lamp.red { background-color: var(--signal-red); }
.mini-lamp.yellow { background-color: var(--signal-yellow); }
.mini-lamp.green { background-color: var(--signal-green); }

.mini-lamp.active {
  opacity: 1;
}
.mini-lamp.red.active { box-shadow: 0 0 6px var(--signal-red); }
.mini-lamp.yellow.active { box-shadow: 0 0 6px var(--signal-yellow); }
.mini-lamp.green.active { box-shadow: 0 0 6px var(--signal-green); }

/* Preemption Progress Pipeline */
.pipeline-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 0.78rem;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.step-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: var(--border-light);
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-item.active {
  background-color: #f0f9ff;
  border-color: #bae6fd;
  color: #0369a1;
  font-weight: 600;
}

.step-item.active .step-num {
  background-color: #0284c7;
  color: #ffffff;
  box-shadow: 0 0 6px rgba(2, 132, 199, 0.4);
}

.step-item.completed {
  color: var(--text-muted);
}
.step-item.completed .step-num {
  background-color: #10b981;
  color: #ffffff;
}

/* Event Log Card */
.log-container {
  height: 180px;
  overflow-y: auto;
  background-color: #0f172a;
  color: #e2e8f0;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.74rem;
  line-height: 1.6;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-entry {
  display: flex;
  align-items: baseline;
  gap: 8px;
  word-break: break-word;
}

.log-time {
  color: #64748b;
  flex-shrink: 0;
  font-weight: 600;
}

.log-tag {
  font-size: 0.65rem;
  padding: 1px 4px;
  border-radius: 3px;
  text-transform: uppercase;
  font-weight: 700;
  flex-shrink: 0;
}
.log-tag.info { background-color: #1e293b; color: #94a3b8; }
.log-tag.sensor { background-color: #0369a1; color: #e0f2fe; }
.log-tag.preempt { background-color: #991b1b; color: #fee2e2; }
.log-tag.recover { background-color: #065f46; color: #d1fae5; }
.log-tag.timing { background-color: #854d0e; color: #fef3c7; }

.log-msg {
  color: #f1f5f9;
}

/* Collapsible How It Works Section */
.accordion-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background-color: var(--bg-muted);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  text-align: left;
  transition: background-color 0.15s ease;
  min-height: 40px;
}

.accordion-toggle:hover {
  background-color: #e2e8f0;
}

.accordion-icon {
  width: 14px;
  height: 14px;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.accordion-toggle[aria-expanded="true"] .accordion-icon {
  transform: rotate(180deg);
}

.accordion-content {
  display: none;
  padding: 12px 14px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  font-size: 0.76rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.accordion-content.expanded {
  display: block;
}

.accordion-content ol {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.accordion-content strong {
  color: var(--text-main);
}

/* Footer Disclaimer */
.app-footer {
  text-align: center;
  padding: 14px 20px 24px;
  font-size: 0.74rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-light);
  margin-top: auto;
}

/* Settings Drawer & Backdrop */
.settings-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.settings-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  max-width: 100vw;
  height: 100%;
  background-color: var(--bg-surface);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.15);
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}

.settings-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  padding: 16px 20px;
  background-color: var(--bg-muted);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
}

.drawer-close-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  line-height: 1;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drawer-close-btn:hover {
  background-color: var(--border-light);
  color: var(--text-main);
}

.drawer-body {
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
}

.setting-val-display {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-primary);
  font-variant-numeric: tabular-nums;
}

.setting-controls {
  display: grid;
  grid-template-columns: 1fr 64px;
  gap: 12px;
  align-items: center;
}

input[type="range"] {
  accent-color: var(--accent-primary);
  height: 6px;
  cursor: pointer;
}

input[type="number"] {
  padding: 6px 8px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  background-color: var(--bg-surface);
  text-align: right;
  width: 100%;
  min-height: 36px;
}

input[type="number"]:focus {
  outline: 2px solid var(--accent-primary);
  border-color: transparent;
}

select {
  padding: 8px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-main);
  background-color: var(--bg-surface);
  cursor: pointer;
  min-height: 40px;
}

select:focus {
  outline: 2px solid var(--accent-primary);
  border-color: transparent;
}

.setting-hint {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.settings-notice {
  background-color: var(--bg-muted);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.74rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.settings-status-banner {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.76rem;
  font-weight: 600;
  display: none;
}
.settings-status-banner.applied {
  display: block;
  background-color: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}
.settings-status-banner.pending {
  display: block;
  background-color: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}
.settings-status-banner.error {
  display: block;
  background-color: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.drawer-footer {
  padding: 16px 20px;
  background-color: var(--bg-muted);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* Desktop defaults for mobile-only components */
.mobile-floating-actions {
  display: none;
}
.sheet-drag-handle-bar {
  display: none;
}
.sheet-peek-summary {
  display: none;
}
.sheet-expanded-header {
  display: none;
}
.bottom-sheet-backdrop {
  display: none;
}
.sheet-footer-disclaimer {
  display: none;
}
.sheet-scrollable-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}

/* Accessibility & Motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Responsive Media Queries - Mobile Optimization (Apple Maps & Google Maps Pattern) */
@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px;
  }
  
  .canvas-card {
    max-width: 760px;
    margin: 0 auto;
    width: 100%;
  }
}

/* Mobile presentation refresh. SVG coordinates remain unchanged by UI layout. */
:root { --sheet-peek-height: 68px; --header-bottom: 64px; --visual-height: 100dvh; --visual-top: 0px; }
[hidden] { display: none !important; }
.mobile-title, .sheet-peek-header, .sheet-toolbar { display: none; }
.dashboard-panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.sheet-scrollable-body, .drawer-body { min-height: 0; }
.sheet-scrollable-body { overflow-anchor: none; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #0284c7; outline-offset: 3px; }
.priority-summary { font-size: .84rem; color: #0369a1; padding: 12px; background: #f0f9ff; border-radius: 10px; }
.step-label { flex: 1; min-width: 0; }
.step-status { font-size: .68rem; white-space: nowrap; color: #64748b; }
.step-item.active .step-status { color: #0369a1; }
.log-actions { display: flex; gap: 6px; }
.log-actions .btn { min-height: 36px; }
.settings-drawer { visibility: hidden; transition: transform .25s ease, visibility .25s; }
.settings-drawer.open { visibility: visible; }
.drawer-header, .drawer-footer { flex-shrink: 0; }
.settings-form-intro { color: #64748b; font-size: .8rem; }
.setting-label label { flex: 1; min-width: 0; }
.setting-val-display { flex-shrink: 0; margin-left: 8px; }
.setting-error { color: #b91c1c; font-size: .8rem; }
input[aria-invalid="true"] { border-color: #dc2626; background: #fef2f2; }
.drawer-body .restore-section { border-top: 1px solid var(--border-light); padding-top: 18px; }
.restore-section p { font-size: .78rem; color: #64748b; margin-bottom: 10px; }
.drawer-footer { justify-content: flex-end; }
.drawer-footer .btn { min-height: 44px; }
.settings-notice { font-size: .78rem; }
.modal-open { overflow: hidden; }
@media (max-width: 768px) {
  html, body { height: 100%; width: 100%; overflow: hidden; }
  body { min-height: 100dvh; }
  .app-header {
    position: fixed; top: calc(10px + env(safe-area-inset-top, 0px));
    left: calc(12px + env(safe-area-inset-left, 0px)); right: calc(12px + env(safe-area-inset-right, 0px));
    z-index: 50; width: auto; min-height: 48px; padding: 8px 12px;
    border: 1px solid rgba(226,232,240,.85); border-radius: 16px;
    background: rgba(255,255,255,.96); box-shadow: 0 4px 18px rgba(15,23,42,.08);
    display: flex; align-items: center; justify-content: space-between; flex-wrap: nowrap; gap: 8px;
  }
  .brand-group { gap: 8px; min-width: 0; }
  .brand-icon { width: 26px; height: 30px; border-radius: 7px; padding: 3px; }
  .brand-icon-light { width: 5px; height: 5px; }
  .brand-text { min-width: 0; }
  .brand-text h1 { font-size: .92rem; line-height: 1.2; white-space: nowrap; }
  .app-header .brand-text .brand-subtitle, .desktop-title, .header-desktop-btn { display: none !important; }
  .mobile-title { display: inline; }
  .header-actions { flex-wrap: nowrap; flex-shrink: 0; gap: 0; }
  .status-pill { padding: 5px 8px; gap: 5px; font-size: .72rem; white-space: nowrap; border: 0; }
  .status-dot { width: 6px; height: 6px; }
  .app-container { position: absolute; inset: 0; height: 100dvh; width: 100%; display: block; padding: 0; margin: 0; overflow: hidden; }
  .simulation-section, .canvas-card, .canvas-viewport { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; }
  .canvas-card { max-width: none; border: 0; border-radius: 0; box-shadow: none; }
  .canvas-header, .canvas-legend, .mobile-quick-strip, .app-footer { display: none !important; }
  .canvas-viewport { aspect-ratio: auto; background: #e8f0e5; }
  #traffic-svg { width: 100%; height: 100%; display: block; }
  .preemption-banner {
    position: fixed; top: calc(var(--header-bottom) + 8px); left: 50%; z-index: 51;
    width: max-content; max-width: calc(100% - 32px); padding: 8px 12px;
    font-size: .75rem; line-height: 1.4; border-radius: 12px; gap: 7px;
    background: #0f172a; box-shadow: 0 4px 12px rgba(15,23,42,.15);
  }
  .mobile-floating-actions {
    display: flex; position: fixed; top: auto; right: calc(14px + env(safe-area-inset-right, 0px));
    bottom: calc(var(--sheet-peek-height) + 16px); z-index: 52; flex-direction: column; gap: 9px;
  }
  .map-fab {
    width: 46px; height: 46px; border-radius: 14px; border: 1px solid #e2e8f0;
    background: rgba(255,255,255,.97); box-shadow: 0 3px 10px rgba(15,23,42,.12);
    display: flex; align-items: center; justify-content: center; position: relative;
    cursor: pointer; color: #1e293b; -webkit-tap-highlight-color: transparent;
  }
  .map-fab:active { background: #e0f2fe; }
  .map-fab[aria-pressed="true"] { border-color: #7dd3fc; }
  .fab-icon { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
  #fab-zoom .fab-icon { transform: translateY(-4px); width: 18px; height: 18px; }
  .fab-zoom-tag { position: absolute; bottom: 4px; font-size: .62rem; font-weight: 700; line-height: 1; color: #0369a1; }
  .modal-open .mobile-floating-actions { visibility: hidden; pointer-events: none; }
  #dashboard-bottom-sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: flex; flex-direction: column; gap: 0;
    height: min(68dvh, calc(100dvh - env(safe-area-inset-top, 0px) - 20px)); max-height: none;
    padding: 0; overflow: hidden; background: #fff; border: 1px solid #e2e8f0; border-bottom: 0;
    border-radius: 22px 22px 0 0; box-shadow: 0 -6px 24px rgba(15,23,42,.10);
    transform: translateY(calc(100% - var(--sheet-peek-height))); transition: transform .28s cubic-bezier(.2,.75,.25,1);
  }
  #dashboard-bottom-sheet.expanded { transform: translateY(0); }
  .sheet-peek-header { display: block; flex-shrink: 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .expanded .sheet-peek-header { display: none; }
  .sheet-drag-handle-bar {
    display: flex; justify-content: center; align-items: center; width: 100%; height: 18px;
    background: transparent; border: 0; cursor: grab; touch-action: none; padding: 6px 0;
  }
  .sheet-handle-pill { width: 34px; height: 4px; border-radius: 4px; background: #cbd5e1; }
  .sheet-peek-summary {
    width: 100%; min-height: 48px; border: 0; background: transparent; display: flex;
    align-items: center; justify-content: space-between; gap: 8px; padding: 4px 16px 10px;
    color: #0f172a; text-align: left; cursor: pointer; font: inherit;
  }
  .peek-phases { display: flex; align-items: center; gap: 8px; min-width: 0; }
  .peek-phase-badge { display: inline-flex; align-items: center; gap: 5px; padding: 7px 8px; background: #f1f5f9; border-radius: 9px; white-space: nowrap; font-size: .76rem; }
  .peek-title { color: #64748b; font-weight: 600; }
  .peek-val { font-weight: 700; font-variant-numeric: tabular-nums; }
  .peek-details { display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0; color: #0369a1; font-size: .76rem; font-weight: 600; }
  .chevron-icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; }
  .sheet-toolbar { display: none; flex-shrink: 0; padding: 0 16px 12px; border-bottom: 1px solid #e2e8f0; background: #fff; }
  .expanded .sheet-toolbar { display: block; }
  .sheet-heading { display: flex; justify-content: space-between; align-items: center; margin: 0 0 10px; gap: 8px; }
  .sheet-heading h2 { font-size: 1rem; line-height: 1.3; }
  .sheet-subtitle { font-size: .72rem; line-height: 1.4; color: #64748b; }
  .sheet-collapse-btn { width: 44px; height: 44px; flex-shrink: 0; border: 0; background: #f1f5f9; border-radius: 12px; font-size: 1.4rem; cursor: pointer; color: #334155; }
  .mobile-tabs-nav { display: flex; width: 100%; padding: 3px; border: 0; box-shadow: none; background: #f1f5f9; gap: 4px; }
  .mobile-tab-btn { flex: 1 1 0; min-width: 0; min-height: 44px; font-size: .8rem; padding: 7px 4px; white-space: nowrap; }
  .sheet-scrollable-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px calc(18px + env(safe-area-inset-bottom, 0px)); gap: 14px; }
  #dashboard-bottom-sheet:not(.expanded) .sheet-scrollable-body { visibility: hidden; }
  .card-header { padding: 10px 12px; }
  .card-header h2 { font-size: .85rem; }
  .card-content { padding: 12px; gap: 10px; }
  .phase-group { display: grid; grid-template-columns: minmax(0, 1fr) auto; padding: 10px; gap: 8px; }
  .phase-name { font-size: .8rem; white-space: nowrap; }
  .phase-detail { display: none; }
  .phase-status-cluster { gap: 6px; min-width: 0; }
  .phase-status-cluster .mini-signal-head { display: none; }
  .phase-badge { font-size: .7rem; padding: 4px 6px; letter-spacing: 0; }
  .phase-timer { font-size: .8rem; min-width: 56px; }
  .metrics-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .metric-card { padding: 12px 8px; min-width: 0; gap: 7px; box-shadow: none; background: #f8fafc; }
  .metric-title { font-size: .63rem; letter-spacing: 0; text-transform: none; color: #64748b; }
  .metric-value { font-size: 1.35rem; }
  .metric-desc { display: none; }
  .step-item { padding: 9px 6px; gap: 8px; font-size: .8rem; }
  .log-container { height: auto; max-height: none; overflow: visible; font-size: .75rem; padding: 10px; }
  .log-entry { display: grid; grid-template-columns: auto 1fr; gap: 3px 8px; padding: 7px 0; border-bottom: 1px solid #334155; }
  .log-tag { justify-self: start; }
  .log-msg { grid-column: 1 / -1; overflow-wrap: anywhere; }
  .log-actions .btn { min-height: 44px; padding: 5px 8px; font-size: .72rem; }
  .accordion-toggle { min-height: 44px; font-size: .8rem; }
  .sheet-footer-disclaimer { display: block; font-size: .7rem; text-align: center; color: #64748b; padding: 4px 8px; }
  .bottom-sheet-backdrop { display: block; position: fixed; inset: 0; z-index: 58; opacity: 0; pointer-events: none; background: rgba(15,23,42,.22); transition: opacity .2s; }
  .bottom-sheet-backdrop.active { opacity: 1; pointer-events: auto; }
  .settings-drawer { width: 100%; max-width: none; top: var(--visual-top); height: var(--visual-height); border-radius: 0; }
  .drawer-header { padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; }
  .drawer-header h2 { font-size: 1rem; }
  .drawer-close-btn { width: 44px; height: 44px; color: #334155; background: #e2e8f0; }
  .drawer-body { padding: 16px; gap: 20px; overscroll-behavior: contain; }
  .setting-label { font-size: .86rem; }
  .setting-controls { grid-template-columns: minmax(0, 1fr) 80px; gap: 16px; }
  input[type="number"], select { min-height: 44px; font-size: 16px; }
  input[type="range"] { width: 100%; min-width: 0; height: 44px; }
  .setting-hint { font-size: .76rem; }
  .drawer-footer { display: grid; grid-template-columns: 1fr 1.5fr; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .drawer-footer .btn { width: 100%; font-size: .9rem; }
  .restore-section .btn { min-height: 44px; }
}
@media (max-width: 768px) and (max-height: 740px) {
  .mobile-floating-actions { display: grid; grid-template-columns: repeat(2, 46px); gap: 8px; }
}
@media (max-width: 768px) and (orientation: landscape) and (max-height: 500px) {
  .app-header { right: auto; max-width: calc(100% - 24px); }
  #dashboard-bottom-sheet { height: calc(100dvh - 12px - env(safe-area-inset-top, 0px)); }
  .preemption-banner { top: calc(var(--header-bottom) + 6px); }
  .sheet-toolbar { padding-bottom: 6px; }
  .sheet-heading { margin-bottom: 4px; }
  .drawer-header { padding-top: 6px; padding-bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  #dashboard-bottom-sheet, .settings-drawer, .preemption-banner, .bottom-sheet-backdrop { transition: none; }
  .banner-pulse, .status-dot { animation: none !important; }
}
