/* ===== APP SHELL ===== */
.app-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ===== NAV ===== */
.app-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--bg-elevated);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--fg);
}

.brand-icon { font-size: 1.3rem; }

.app-nav-tagline {
  font-size: 0.8rem;
  color: var(--fg-muted);
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* ===== APP SHELL LAYOUT ===== */
.app-shell {
  display: grid;
  grid-template-columns: 400px 1fr;
  min-height: calc(100vh - 56px);
  flex: 1;
}

/* ===== PANELS ===== */
.panel {
  padding: 24px;
  overflow-y: auto;
}

.panel-input {
  background: var(--bg-elevated);
  border-right: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-results {
  background: var(--bg);
}

/* ===== PANEL HEADER ===== */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  font-size: 1.1rem;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
}

.stop-count {
  font-size: 0.8rem;
  color: var(--fg-muted);
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 500;
}

/* ===== START LOCATION ===== */
.start-location {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 0.78rem;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--fg-muted);
  text-transform: uppercase;
}

.field-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s;
}

.field-input:focus {
  border-color: rgba(59, 245, 142, 0.4);
}

.field-input::placeholder {
  color: var(--fg-muted);
  opacity: 0.6;
}

/* ===== STOP ROW ===== */
.stop-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stop-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius);
  padding: 12px;
  transition: border-color 0.15s;
}

.stop-row:focus-within {
  border-color: rgba(59, 245, 142, 0.25);
}

.stop-number {
  width: 28px;
  height: 28px;
  min-width: 28px;
  background: var(--accent-dim);
  border: 1px solid rgba(59, 245, 142, 0.25);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 2px;
}

.stop-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.stop-time-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.field-time {
  width: 100px;
  flex-shrink: 0;
  font-size: 0.82rem;
  padding: 7px 8px;
}

.time-dash {
  color: var(--fg-muted);
  font-size: 0.85rem;
}

.stop-notes {
  flex: 1;
  min-width: 0;
  font-size: 0.82rem;
  padding: 7px 8px;
}

.stop-remove {
  background: none;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
  flex-shrink: 0;
}

.stop-remove:hover {
  color: var(--warning);
  background: var(--warning-dim);
}

/* ===== BUTTONS ===== */
.btn-add-stop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  background: none;
  border: 1px dashed rgba(255,255,255,0.15);
  border-radius: var(--radius);
  color: var(--fg-muted);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-add-stop:hover {
  border-color: rgba(59, 245, 142, 0.4);
  color: var(--accent);
}

.btn-optimize {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #0a0c10;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-optimize:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-optimize:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.input-hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--fg-muted);
  margin-top: -8px;
}

.input-hint.hint-ready {
  color: var(--accent);
}

/* ===== RESULTS STATES ===== */
.results-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: 48px;
  text-align: center;
  gap: 16px;
}

.empty-icon { font-size: 3rem; }

.results-empty h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.2rem;
  color: var(--fg);
}

.results-empty p {
  font-size: 0.95rem;
  color: var(--fg-muted);
  max-width: 380px;
  line-height: 1.65;
}

.results-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 20px;
  color: var(--fg-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(59, 245, 142, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

.results-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 8px 0;
}

/* ===== SAVINGS BAR ===== */
.savings-bar {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--accent-dim);
  border: 1px solid rgba(59, 245, 142, 0.2);
  border-radius: var(--radius);
  padding: 16px 0;
}

.saving-item {
  flex: 1;
  text-align: center;
}

.saving-value {
  display: block;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}

.saving-label {
  display: block;
  font-size: 0.78rem;
  color: var(--fg-muted);
  margin-top: 2px;
}

.saving-divider {
  width: 1px;
  height: 40px;
  background: rgba(59, 245, 142, 0.15);
}

/* ===== ROUTE SUMMARY ===== */
.route-summary {
  font-size: 0.92rem;
  color: var(--fg-muted);
  line-height: 1.65;
  padding: 16px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.05);
}

/* ===== MAP ===== */
.map-container {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.06);
}

#routeMap {
  height: 280px;
  width: 100%;
  background: var(--bg-card);
}

/* Override Leaflet tile colors for dark mode */
.leaflet-tile-pane { filter: brightness(0.85) invert(1) contrast(1.1) hue-rotate(200deg) saturate(0.6) brightness(0.7); }

/* Custom map markers */
.map-marker {
  width: 32px;
  height: 32px;
  background: var(--bg-card);
  border: 2px solid var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.map-marker-start {
  background: var(--accent);
  color: #0a0c10;
  font-size: 1rem;
}

/* ===== ORDERED STOPS ===== */
.ordered-stops {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ordered-stop {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s;
}

.ordered-stop:hover {
  border-color: rgba(59, 245, 142, 0.2);
}

.ordered-stop-num {
  width: 26px;
  height: 26px;
  min-width: 26px;
  background: var(--accent-dim);
  border: 1px solid rgba(59, 245, 142, 0.3);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 1px;
}

.ordered-stop-info {
  flex: 1;
  min-width: 0;
}

.ordered-stop-address {
  font-size: 0.9rem;
  color: var(--fg);
  font-weight: 500;
}

.ordered-stop-eta {
  font-size: 0.8rem;
  color: var(--accent);
  margin-top: 3px;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
}

.ordered-stop-window,
.ordered-stop-notes {
  font-size: 0.78rem;
  color: var(--fg-muted);
  margin-top: 2px;
}

/* ===== ACTIONS ===== */
.results-actions {
  display: flex;
  gap: 12px;
  padding-top: 4px;
}

.btn-secondary {
  flex: 1;
  padding: 12px;
  background: var(--bg-elevated);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  color: var(--fg);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.btn-secondary:hover {
  border-color: rgba(255,255,255,0.2);
  background: var(--bg-card);
}

.btn-primary {
  flex: 2;
  padding: 12px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #0a0c10;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-primary:hover { opacity: 0.88; }

/* ===== SAVE ROUTE BUTTON ===== */
.btn-save-route {
  flex: 1.5;
  padding: 12px;
  background: rgba(59, 245, 142, 0.12);
  border: 1px solid rgba(59, 245, 142, 0.35);
  border-radius: var(--radius);
  color: var(--accent);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-save-route:hover {
  background: rgba(59, 245, 142, 0.2);
  border-color: rgba(59, 245, 142, 0.5);
}

/* ===== AUTH NAV ===== */
.app-nav-auth {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.btn-nav-login {
  padding: 7px 14px;
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-nav-login:hover {
  border-color: rgba(255,255,255,0.3);
  color: var(--fg);
}

.btn-nav-signup {
  padding: 7px 14px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #0a0c10;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-nav-signup:hover { opacity: 0.88; }

.nav-user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.82rem;
  color: var(--fg-muted);
}

.nav-user-name {
  color: var(--fg);
  font-weight: 600;
}

.btn-nav-logout {
  padding: 5px 10px;
  background: none;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.78rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.btn-nav-logout:hover {
  border-color: rgba(255,255,255,0.25);
  color: var(--fg);
}

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-box {
  background: var(--bg-elevated);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 32px;
  width: 100%;
  max-width: 420px;
  position: relative;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}

.modal-box-sm {
  max-width: 360px;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--fg-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}

.modal-close:hover {
  color: var(--fg);
  background: rgba(255,255,255,0.06);
}

.modal-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.modal-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 24px;
}

.modal-tab {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--fg-muted);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  margin-bottom: -1px;
}

.modal-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.78rem;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--fg-muted);
  text-transform: uppercase;
}

.form-error {
  font-size: 0.82rem;
  color: var(--warning);
  background: var(--warning-dim);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  margin: 0;
}

.btn-auth-submit {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #0a0c10;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 4px;
}

.btn-auth-submit:hover { opacity: 0.88; }
.btn-auth-submit:disabled { opacity: 0.4; cursor: not-allowed; }

.form-switch {
  text-align: center;
  font-size: 0.85rem;
  color: var(--fg-muted);
  margin: 0;
}

.form-switch a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.form-switch a:hover { text-decoration: underline; }

/* ===== SAVED ROUTES SECTION ===== */
.saved-routes-section {
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.saved-routes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.saved-routes-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-refresh-history {
  background: none;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s;
}

.btn-refresh-history:hover { color: var(--fg); }

.saved-routes-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.saved-route-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.saved-route-item:hover {
  border-color: rgba(59, 245, 142, 0.3);
  background: rgba(59, 245, 142, 0.04);
}

.saved-route-name {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.saved-route-meta {
  font-size: 0.75rem;
  color: var(--fg-muted);
  flex-shrink: 0;
}

.saved-routes-empty {
  font-size: 0.85rem;
  color: var(--fg-muted);
  text-align: center;
  padding: 16px 0;
  margin: 0;
}

/* ===== HIDDEN UTILITY ===== */
.hidden { display: none !important; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .panel-input {
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,0.06);
  }

  .panel {
    padding: 16px;
  }

  .app-nav-tagline { display: none; }

  #routeMap { height: 220px; }

  .stop-time-row {
    flex-wrap: wrap;
  }

  .field-time { width: 90px; }

  .savings-bar { gap: 0; }
  .saving-value { font-size: 1.5rem; }
}
