:root {
  /* Surfaces — light editorial (PNM Now) */
  --bg: #eef2f7;          /* page / stage behind the map */
  --bg-2: #f4f6f9;
  --panel: #ffffff;       /* sidebar */
  --panel-2: #f5f7fa;     /* cards, inputs */
  --line: #e6e9ee;
  --line-2: #d7dde5;
  /* Text */
  --text: #111827;        /* PNM Now near-black */
  --muted: #6b7280;
  --faint: #9ca3af;
  /* Brand */
  --accent: #111827;      /* primary ink (buttons, active states) */
  --accent-ink: #ffffff;  /* text on the ink */
  --danger: #e11d48;
  /* Map */
  --ocean: #ffffff;       /* the map disk reads as white "paper" on the grey page */
  --land: #e4e9f0;
  --land-stroke: #cfd7e1;
  --grat: #eaeef4;
  /* System */
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 364px;
  --shadow: 0 16px 40px -16px rgba(17,24,39,0.22);
  --shadow-sm: 0 1px 3px rgba(17,24,39,0.08), 0 1px 2px rgba(17,24,39,0.04);
  --ring: 0 0 0 3px rgba(17,24,39,0.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-feature-settings: "cv02" 1, "cv11" 1, "ss01" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
.route-dist, .stat-row .v, .v { font-variant-numeric: tabular-nums; }

#app { display: flex; height: 100vh; width: 100vw; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 5;
}

.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 22px 16px;
  border-bottom: 1px solid var(--line);
}
.logo { display: flex; color: var(--text); }
.brand-text h1 {
  margin: 0; font-size: 21px; font-weight: 800; letter-spacing: -0.5px; line-height: 1;
}
.brand-text p {
  margin: 4px 0 0; font-size: 11.5px; color: var(--muted); font-weight: 500;
}
.brand-text .byline { color: var(--text); font-weight: 700; text-decoration: none; border-bottom: 1.5px solid var(--line-2); }
.brand-text .byline:hover { border-bottom-color: var(--text); }

/* ---------- Global add box (top of sidebar) ---------- */
.add-block { padding: 14px 16px 2px; }
.global-search {
  display: flex; align-items: center; gap: 9px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 0 11px; box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}
.global-search:focus-within { border-color: var(--text); box-shadow: var(--ring); }
.global-search .search-icon { color: var(--faint); flex: none; transition: color .15s; }
.global-search:focus-within .search-icon { color: var(--text); }
.global-input {
  flex: 1; background: none; border: none; outline: none; min-width: 0;
  color: var(--text); font-family: inherit; font-size: 14px; font-weight: 500; padding: 11px 0;
}
.global-input::placeholder { color: var(--faint); font-weight: 500; }

/* ---------- Inline add (suggestions dropdown shared) ---------- */
.suggestions {
  list-style: none; margin: 10px 0 2px; padding: 5px;
  background: var(--panel); border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
  max-height: 240px; overflow-y: auto;
}
.suggestions[hidden] { display: none; }
.suggestions li {
  display: flex; align-items: baseline; gap: 10px;
  padding: 8px 10px; border-radius: 6px; cursor: pointer; transition: background .1s;
}
.suggestions li.active, .suggestions li:hover { background: var(--panel-2); }
.sug-code { font-weight: 700; font-size: 13px; color: var(--text); min-width: 36px; letter-spacing: 0.3px; }
.sug-main { font-size: 13px; color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sug-sub { font-size: 11px; color: var(--muted); white-space: nowrap; }
.sug-empty { padding: 11px 10px; color: var(--muted); font-size: 13px; }

/* Inline stop input + "add" pill */
.stop-input {
  flex: 1 1 110px; min-width: 96px;
  background: var(--panel); border: 1px dashed var(--line-2); border-radius: 8px;
  color: var(--text); font-family: inherit; font-size: 13px; font-weight: 600; letter-spacing: 0.3px;
  padding: 5px 9px; outline: none; transition: border-color .14s, box-shadow .14s;
}
.stop-input::placeholder { color: var(--faint); font-weight: 500; letter-spacing: 0; }
.stop-input:focus { border-style: solid; border-color: var(--text); box-shadow: var(--ring); }
.add-stop {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 8px;
  background: transparent; border: 1px dashed var(--line-2); color: var(--muted);
  cursor: pointer; font-size: 16px; line-height: 1; font-family: inherit;
  transition: border-color .14s, color .14s;
}
.add-stop:hover { border-color: var(--text); color: var(--text); border-style: solid; }

/* "Add a route" button */
.add-route {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; margin-top: 2px; padding: 12px;
  background: transparent; border: 1px dashed var(--line-2); border-radius: var(--radius);
  color: var(--muted); font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.add-route:hover { border-color: var(--text); color: var(--text); background: var(--panel-2); }
.add-route .ar-plus { color: var(--text); font-size: 17px; line-height: 1; }

/* ---------- Routes ---------- */
.routes { flex: 1; overflow-y: auto; padding: 12px 16px 14px; }
.routes-bar { display: flex; justify-content: flex-end; padding: 0 2px 9px; }
.legs-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-family: inherit; font-size: 11.5px; font-weight: 600; padding: 3px 4px; border-radius: 6px;
  transition: color .14s;
}
.legs-toggle:hover { color: var(--text); }
.legs-toggle svg { opacity: 0.8; }

/* Per-leg mileage breakdown */
.leg-miles {
  margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--line);
  display: flex; flex-direction: column; gap: 5px;
}
.leg-mile-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 12px; }
.lm-pair { color: var(--muted); font-weight: 600; letter-spacing: 0.3px; }
.lm-right { display: inline-flex; align-items: baseline; white-space: nowrap; }
.lm-time { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.lm-time:not(:empty)::after { content: "·"; color: var(--faint); font-weight: 400; margin: 0 6px; }
.lm-dist { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.route-card {
  position: relative;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px 13px 16px;
  margin-bottom: 10px; cursor: default; overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: border-color .16s, box-shadow .16s;
}
.route-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--route-color, var(--text));
}
.route-card:hover { border-color: var(--line-2); }
.route-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.route-label { display: flex; align-items: center; gap: 8px; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.1px; font-weight: 700; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.route-meta { display: flex; align-items: center; gap: 8px; }
.route-dist { font-size: 12px; color: var(--muted); }
.route-del { background: none; border: none; color: var(--faint); cursor: pointer; font-size: 16px; padding: 1px 5px; line-height: 1; border-radius: 6px; transition: color .12s, background .12s; }
.route-del:hover { color: var(--danger); background: rgba(225,29,72,0.1); }

.legs { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.apt-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel-2); border: 1px solid var(--line-2);
  border-radius: 8px; padding: 5px 7px 5px 10px;
  font-size: 13px; font-weight: 700; letter-spacing: 0.3px;
  transition: border-color .12s;
}
.apt-chip:hover { border-color: var(--faint); }
.apt-chip .x { color: var(--faint); cursor: pointer; font-weight: 700; font-size: 13px; transition: color .12s; }
.apt-chip .x:hover { color: var(--danger); }
.leg-arrow { color: var(--faint); font-size: 11px; }

/* ---------- Empty state ---------- */
.empty { padding: 6px 4px 14px; color: var(--muted); }
.empty-title { font-size: 14px; color: var(--text); margin: 0 0 3px; font-weight: 700; }
.empty-sub { font-size: 12.5px; margin: 0 0 13px; line-height: 1.4; }
.examples { display: flex; flex-direction: column; gap: 8px; }
.chip-example {
  text-align: left; background: var(--panel); border: 1px solid var(--line-2);
  color: var(--text); border-radius: var(--radius-sm); padding: 10px 13px; font-size: 13px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: border-color .14s, transform .05s, background .14s;
}
.chip-example:hover { border-color: var(--text); background: var(--panel-2); }
.chip-example:active { transform: translateY(1px); }

/* ---------- Stats ---------- */
.stats { padding: 14px 18px 6px; border-top: 1px solid var(--line); }
.stat-row { display: flex; align-items: baseline; justify-content: space-between; padding: 5px 0; }
.stat-row .k { font-size: 12px; color: var(--muted); }
.stat-row .v { font-size: 14px; font-weight: 700; }
.stat-row.total { padding-bottom: 8px; }
.stat-row.total .k { color: var(--text); }
.stat-row.total .v { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; color: var(--text); }
.stat-sub { font-size: 11px; color: var(--faint); margin-top: 4px; display: flex; align-items: center; gap: 6px; }
.mini-spin {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  border: 1.5px solid var(--line-2); border-top-color: var(--text);
  display: inline-block; animation: spin .7s linear infinite;
}

/* ---------- Footer + Subscribe ---------- */
.side-footer { display: flex; flex-direction: column; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line); }
.promo {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 13px;
}
.promo-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.promo-text strong { font-size: 12.5px; font-weight: 800; letter-spacing: -0.2px; }
.promo-text span { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.footer-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.footer-legal { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 2px; font-size: 11px; }
.footer-legal a {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--faint); text-decoration: none; font-weight: 600; letter-spacing: 0.2px;
  padding: 4px 8px; border-radius: 7px; transition: color .14s, background .14s;
}
.footer-legal a:hover { color: var(--text); background: var(--panel-2); }
.footer-legal a svg { opacity: 0.65; transition: opacity .14s; }
.footer-legal a:hover svg { opacity: 1; }
.footer-legal .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--line-2); flex: none; }
.footer-copy { text-align: center; font-size: 10.5px; color: var(--faint); margin-top: 1px; letter-spacing: 0.2px; }

/* ---------- Buttons / segmented ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--text);
  border-radius: var(--radius-sm); padding: 8px 13px; font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: inherit; transition: border-color .14s, background .14s, color .14s; box-shadow: var(--shadow-sm);
}
.btn:hover { border-color: var(--text); }
.btn.subtle { color: var(--muted); box-shadow: none; }
.btn.subtle:hover { color: var(--text); }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent); color: var(--accent-ink);
  border: 1px solid var(--accent); border-radius: var(--radius-sm);
  padding: 9px 16px; font-size: 13px; font-weight: 700; cursor: pointer; white-space: nowrap;
  font-family: inherit; text-decoration: none; transition: opacity .14s, transform .05s;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:active { transform: translateY(1px); }

.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 3px; gap: 2px; box-shadow: var(--shadow-sm); }
.seg button {
  border: none; background: none; color: var(--muted); cursor: pointer;
  padding: 6px 12px; font-size: 12.5px; font-weight: 700; border-radius: 6px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; font-family: inherit;
  transition: color .14s, background .14s;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--accent); color: var(--accent-ink); }
.view-toggle button { padding: 8px 11px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--panel);
  color: var(--text); cursor: pointer; font-size: 19px; line-height: 1;
  display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-sm);
  transition: border-color .14s, color .14s;
}
.icon-btn:hover { border-color: var(--text); }
.icon-btn.ghost { width: auto; height: auto; border: none; background: none; padding: 2px 4px; font-size: 18px; color: var(--faint); box-shadow: none; }
.icon-btn.ghost:hover { color: var(--text); }

/* ---------- Stage / map ---------- */
#stage {
  position: relative; flex: 1; height: 100%; overflow: hidden;
  background:
    radial-gradient(1200px 700px at 70% -12%, #ffffff 0%, transparent 55%),
    var(--bg);
}
#map { width: 100%; height: 100%; display: block; cursor: grab; }
#map:active { cursor: grabbing; }

.map-controls { position: absolute; z-index: 6; display: flex; gap: 8px; }
.map-controls.top-right { top: 18px; right: 18px; align-items: center; }
.map-controls.bottom-right { right: 18px; bottom: 18px; flex-direction: column; }

.loading {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line-2); color: var(--muted);
  padding: 8px 15px; border-radius: 22px; font-size: 12.5px; z-index: 7; box-shadow: var(--shadow-sm);
}
.loading::before {
  content: ""; width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid var(--line-2); border-top-color: var(--text); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading.hidden { opacity: 0; pointer-events: none; transition: opacity .45s; }

.tooltip {
  position: absolute; z-index: 20; pointer-events: none;
  background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 10px; padding: 9px 12px; box-shadow: var(--shadow);
  font-size: 12.5px; max-width: 250px; transform: translate(-50%, calc(-100% - 14px));
}
.tooltip .t-code { font-weight: 800; color: var(--text); margin-right: 6px; letter-spacing: 0.3px; }
.tooltip .t-name { color: var(--text); }
.tooltip .t-sub { color: var(--muted); font-size: 11.5px; margin-top: 3px; }

/* ---------- Map SVG element styles ---------- */
.sphere { fill: var(--ocean); }
.graticule { fill: none; stroke: var(--grat); stroke-width: 0.6; }
.land { fill: var(--land); stroke: var(--land-stroke); stroke-width: 0.6; }
.route-arc { fill: none; stroke-linecap: round; opacity: 0.95; transition: opacity .25s; }
.route-arc.dim { opacity: 0.16; }
.apt-dot { stroke: #ffffff; stroke-width: 1.5; cursor: pointer; }
.apt-halo { opacity: 0.18; pointer-events: none; }
.apt-label {
  fill: var(--text); font-size: 11px; font-weight: 700; letter-spacing: 0.3px;
  paint-order: stroke; stroke: #ffffff; stroke-width: 3.5px; stroke-linejoin: round; pointer-events: none;
}

/* ---------- Toast ---------- */
.toast {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 13px;
  padding: 10px 18px; border-radius: 22px; z-index: 40; opacity: 0;
  transition: opacity .25s, transform .25s; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  /* Map fixed on top; the whole sidebar scrolls as one unit beneath it. */
  #app { flex-direction: column-reverse; height: 100vh; height: 100dvh; }
  #stage { flex: none; height: 42vh; height: 42dvh; min-height: 250px; }
  #sidebar {
    width: 100%; min-width: 0; flex: 1 1 auto; height: auto; min-height: 0;
    border-right: none; border-top: 1px solid var(--line);
    overflow-y: auto; -webkit-overflow-scrolling: touch;
  }
  .routes { flex: none; overflow: visible; padding-bottom: 4px; }

  .brand { padding: 14px 16px 12px; }
  .add-block { padding: 14px 14px 2px; }
  .routes { padding: 12px 14px 4px; }
  .stats { padding: 14px 16px 6px; }
  .side-footer { padding: 13px 14px calc(14px + env(safe-area-inset-bottom)); }

  /* 16px inputs stop iOS from zooming the page on focus */
  .global-input, .stop-input { font-size: 16px; }
  .global-input { padding: 12px 0; }

  /* Bigger, comfier tap targets on the map */
  .icon-btn { width: 42px; height: 42px; border-radius: 11px; }
  .map-controls { gap: 9px; }
  .map-controls.top-right { top: 12px; right: 12px; }
  .map-controls.bottom-right { right: 12px; bottom: 12px; }
  .view-toggle button { padding: 9px 12px; }

  .legs-toggle { padding: 6px 6px; font-size: 12px; }
  .suggestions { max-height: 260px; }
}
