/* Lalu base styles. Mobile-first: wider layouts live in responsive.css. */

:root {
  /* Brand */
  --brand: #0f766e;
  --brand-strong: #0b5d57;
  --brand-ink: #08302e;
  --accent: #f59e0b;
  --on-brand: #ffffff;

  /* Route and markers */
  --route: #2563eb;
  --route-casing: #1e3a8a;
  --route-alt: #9aa9bb;
  --origin: #0f766e;
  --destination: #f59e0b;

  /* Surfaces and text */
  --bg: #eef3f2;
  --surface: #ffffff;
  --surface-2: #f2f6f5;
  --surface-hover: #e7efed;
  --text: #0f1f1e;
  --text-muted: #566664;
  --border: #d7e1df;
  --danger: #c2271d;
  --danger-bg: #fdecea;
  --focus: #2563eb;

  /* Shape and depth */
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow: 0 10px 30px rgba(8, 48, 46, 0.16), 0 2px 6px rgba(8, 48, 46, 0.08);
  --shadow-sm: 0 2px 8px rgba(8, 48, 46, 0.14);

  /* Type */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --fs-xs: clamp(0.72rem, 0.7rem + 0.1vw, 0.78rem);
  --fs-sm: clamp(0.82rem, 0.8rem + 0.12vw, 0.88rem);
  --fs-md: clamp(0.95rem, 0.92rem + 0.15vw, 1rem);
  --fs-lg: clamp(1.1rem, 1.05rem + 0.3vw, 1.25rem);
  --fs-xl: clamp(1.6rem, 1.4rem + 1vw, 2rem);

  /* Layout (panel/sheet heights are set by ui.js) */
  --gap: 12px;
  --touch: 44px;
  --panel-h: 132px;
  --sheet-h: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #14b8a6;
    --brand-strong: #2dd4bf;
    --brand-ink: #ccfbf1;
    --on-brand: #04201d;
    --route: #3b82f6;
    --route-casing: #1e3a8a;
    --origin: #14b8a6;

    --bg: #0c1a19;
    --surface: #132321;
    --surface-2: #1a2e2c;
    --surface-hover: #213936;
    --text: #e4efed;
    --text-muted: #9bb0ad;
    --border: #284340;
    --danger: #ff8a80;
    --danger-bg: #3a1714;
    --focus: #60a5fa;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);

    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
p,
ol,
ul,
dl,
dd {
  margin: 0;
  padding: 0;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Sidebar: search panel + route sheet ---------- */

.sidebar {
  display: contents;
}

.search-panel {
  position: fixed;
  z-index: 20;
  top: calc(var(--safe-top) + 8px);
  left: calc(var(--safe-left) + 8px);
  right: calc(var(--safe-right) + 8px);
  padding: 10px 10px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 2px 8px;
}

.brand__logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
}

.brand__name {
  font-size: var(--fs-lg);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--brand);
}

.brand__tag {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.lang-toggle {
  margin-left: auto;
  min-width: 40px;
  height: 30px;
  padding: 0 10px;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--brand);
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  transition: background-color 0.15s, border-color 0.15s;
}

.lang-toggle:hover {
  background: var(--surface-2);
  border-color: var(--brand);
}

.route-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.route-form__fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  min-width: 0;
}

.field {
  position: relative;
  display: flex;
  align-items: center;
  min-height: var(--touch);
  padding: 0 4px 0 12px;
  background: var(--surface-2);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, background-color 0.15s;
}

.field:focus-within {
  border-color: var(--brand);
  background: var(--surface);
}

.field__dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 10px;
  border-radius: 50%;
  flex: none;
}

.field__dot--origin {
  background: var(--surface);
  border: 3.5px solid var(--origin);
}

.field__dot--destination {
  background: var(--destination);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
}

.field__input {
  flex: 1;
  min-width: 0;
  height: var(--touch);
  padding: 0;
  font-size: 16px; /* 16px stops iOS zoom on focus */
  background: transparent;
  border: 0;
  outline: none;
  text-overflow: ellipsis;
}

.field__input::placeholder {
  color: var(--text-muted);
}

.field__input::-webkit-search-cancel-button {
  display: none;
}

.field__spinner {
  display: none;
  width: 16px;
  height: 16px;
  margin: 0 6px;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.field.is-loading .field__spinner {
  display: inline-block;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: 50%;
  transition: background-color 0.15s, color 0.15s;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.field__gps {
  color: var(--brand);
}

.field__gps[aria-busy="true"] svg {
  animation: pulse 1s ease-in-out infinite;
}

.swap-btn {
  width: var(--touch);
  height: var(--touch);
  color: var(--text);
  background: var(--surface-2);
}

.swap-btn:active svg {
  transform: rotate(180deg);
}

.swap-btn svg {
  transition: transform 0.25s var(--ease);
}

/* ---------- Suggestions ---------- */

.suggestions {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: -2px;
  right: -2px;
  max-height: min(55vh, 360px);
  overflow-y: auto;
  list-style: none;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  overscroll-behavior: contain;
}

.suggestion {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 8px;
  min-height: var(--touch);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
}

.suggestion:hover,
.suggestion[aria-selected="true"] {
  background: var(--surface-hover);
}

.suggestion__icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: 50%;
}

.suggestion__icon svg {
  width: 16px;
  height: 16px;
}

.suggestion__text {
  min-width: 0;
}

.suggestion__name {
  display: block;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.suggestion__detail {
  display: block;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.suggestion--message {
  display: block;
  padding: 12px 8px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  cursor: default;
}

.suggestion--message:hover {
  background: none;
}

/* ---------- Route sheet ---------- */

.route-sheet {
  position: fixed;
  z-index: 15;
  left: calc(var(--safe-left));
  right: calc(var(--safe-right));
  bottom: 0;
  max-height: min(58vh, calc(100dvh - var(--panel-h) - 24px));
  display: flex;
  flex-direction: column;
  padding: 4px 16px calc(var(--safe-bottom) + 14px);
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
  animation: sheet-in 0.3s var(--ease);
}

.sheet-handle {
  display: grid;
  place-items: center;
  width: 100%;
  height: 22px;
  padding: 0;
  background: none;
  border: 0;
  flex: none;
}

.sheet-handle span {
  width: 40px;
  height: 5px;
  background: var(--border);
  border-radius: 999px;
}

.sheet-status,
.sheet-ready {
  display: none;
}

.route-sheet[data-state="loading"] .sheet-status--loading,
.route-sheet[data-state="error"] .sheet-status--error {
  display: flex;
}

.route-sheet[data-state="ready"] .sheet-ready {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sheet-status {
  align-items: center;
  gap: 12px;
  padding: 12px 0 8px;
  color: var(--text-muted);
}

.sheet-status--error {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.sheet-status__message {
  padding: 10px 12px;
  color: var(--danger);
  background: var(--danger-bg);
  border-radius: var(--radius-sm);
}

.summary {
  padding: 2px 0 10px;
}

.summary__time {
  font-size: var(--fs-xl);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--brand);
}

.summary__meta {
  margin-top: 4px;
  color: var(--text-muted);
}

.summary__meta #summary-distance,
.summary__meta #summary-eta {
  font-weight: 600;
  color: var(--text);
}

.summary__sep {
  margin: 0 4px;
}

.sheet-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0 -4px;
  padding: 0 4px 8px;
  transition: opacity 0.2s;
}

.route-sheet[data-collapsed="true"] .sheet-body {
  display: none;
}

.endpoints {
  /* On phones the search fields already show both places. */
  display: none;
  gap: 6px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}

.endpoints__row {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 8px;
  align-items: baseline;
}

.endpoints dt {
  display: flex;
  align-items: center;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.endpoints dt .field__dot {
  width: 10px;
  height: 10px;
  margin-right: 8px;
}

.endpoints dd {
  min-width: 0;
  font-size: var(--fs-sm);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.sheet-heading {
  margin: 14px 0 6px;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.alternatives {
  display: grid;
  gap: 6px;
  list-style: none;
}

.alt {
  display: grid;
  grid-template-columns: 6px 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 56px;
  padding: 10px 12px 10px 10px;
  text-align: left;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, background-color 0.15s;
}

.alt:hover {
  background: var(--surface-2);
}

.alt[aria-pressed="true"] {
  border-color: var(--route);
  background: color-mix(in srgb, var(--route) 8%, var(--surface));
}

.alt__bar {
  align-self: stretch;
  border-radius: 999px;
  background: var(--route-alt);
}

.alt[aria-pressed="true"] .alt__bar {
  background: var(--route);
}

.alt__main {
  min-width: 0;
}

.alt__time {
  display: block;
  font-weight: 700;
}

.alt__via {
  display: block;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.alt__side {
  display: grid;
  justify-items: end;
  gap: 2px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.alt__tag {
  padding: 1px 8px;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  border-radius: 999px;
}

.note {
  margin-top: 10px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 20px;
  font-weight: 700;
  border: 0;
  border-radius: 999px;
  transition: background-color 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  color: var(--on-brand);
  background: var(--brand);
}

.btn--primary:hover {
  background: var(--brand-strong);
}

.btn--primary svg {
  fill: currentColor;
  stroke: none;
}

.btn--ghost {
  color: var(--brand);
  background: var(--surface-2);
}

.btn {
  text-decoration: none;
}

.handoff {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
  flex: none;
}

.handoff .btn {
  padding: 0 14px;
  text-align: center;
}

.note--handoff {
  margin-top: 6px;
  flex: none;
}

/* ---------- Floating GPS button ---------- */

.fab {
  position: fixed;
  z-index: 12;
  right: calc(var(--safe-right) + 12px);
  bottom: calc(var(--sheet-h) + var(--safe-bottom) + 40px);
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  color: var(--brand);
  background: var(--surface);
  border: 0;
  border-radius: 50%;
  box-shadow: var(--shadow);
  transition: bottom 0.3s var(--ease), background-color 0.15s;
}

.fab:hover {
  background: var(--surface-2);
}

.fab[aria-busy="true"] svg {
  animation: pulse 1s ease-in-out infinite;
}

.fab.is-active svg {
  fill: currentColor;
}

/* ---------- Navigation banner (Phase 2) ---------- */

.nav-banner {
  position: fixed;
  z-index: 25;
  top: calc(var(--safe-top) + 8px);
  left: 8px;
  right: 8px;
  padding: 14px 16px;
  color: #fff;
  background: var(--brand-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Progress bar ---------- */

.progress {
  position: fixed;
  z-index: 40;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  overflow: hidden;
  background: color-mix(in srgb, var(--route) 20%, transparent);
}

.progress span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 40%;
  background: var(--route);
  animation: progress 1.1s var(--ease) infinite;
}

/* ---------- Toasts ---------- */

.toasts {
  position: fixed;
  z-index: 50;
  left: 50%;
  top: calc(var(--panel-h) + var(--safe-top) + 16px);
  display: grid;
  gap: 8px;
  width: min(440px, calc(100vw - 24px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  font-size: var(--fs-sm);
  color: var(--text);
  background: var(--surface);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: toast-in 0.25s var(--ease);
}

.toast--error {
  border-left-color: var(--danger);
}

.toast__close {
  margin-left: auto;
  width: 24px;
  height: 24px;
  padding: 0;
  color: var(--text-muted);
  background: none;
  border: 0;
}

.toast__close svg {
  width: 16px;
  height: 16px;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s, transform 0.2s;
}

/* ---------- Misc ---------- */

.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--route);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
}

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

@keyframes pulse {
  50% { opacity: 0.35; }
}

@keyframes progress {
  from { transform: translateX(-100%); }
  to { transform: translateX(260%); }
}

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
}

@keyframes toast-in {
  from { transform: translateY(-8px); opacity: 0; }
}
