/* Base layout for the renderer demo page. External stylesheet because the
   Day-1 CSP (default-src 'self') forbids inline styles. */

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2027;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent: #ff385c;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #555;
  overflow: hidden;
  font: 14px/1.4 system-ui, sans-serif;
  color: #eee;
}

canvas#c {
  display: block;
  width: 100%;
  height: 100%;
  /* Prevent iOS Safari double-tap zooming the canvas (Risk #14). */
  touch-action: none;
}

/* Visually hidden but exposed to assistive tech (aria-live still fires). */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.renderer-error {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #222;
  color: #f66;
  padding: 2em;
  text-align: center;
}

/* Detail block for fatal overlays. <pre> keeps driver newlines intact
   (shader infoLogs are multi-line); overflow-wrap handles long single-word
   error strings so they don't blow past the viewport. */
.renderer-error-detail {
  white-space: pre-wrap;
  max-width: 90vw;
  overflow-wrap: anywhere;
}

/* Tile attribution. Bottom-right, ≥11 px per CARTO/OSM legibility guidance,
   white-on-translucent-black so it reads against both light Voyager tiles
   and dark city-night skins planned later. */
.attribution {
  position: fixed;
  right: 0;
  bottom: 0;
  padding: 2px 6px;
  background: #0009;
  color: #fff;
  font-size: 11px;
  line-height: 1.3;
  z-index: 10;
}
.attribution a {
  color: #fff;
  text-decoration: underline;
}
.attribution a:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Cards (info + tracking). Shared shell — content differs per card. */
.card {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  z-index: 1000;
}

/* Info card — top-left, shown on line/station selection. */
.card--info {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 320px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 16px 18px 14px;
}
.card--info.hidden { display: none; }

.info-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 4px;
}
.info-subtitle {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 10px;
}
.popup-cta {
  margin: 8px 0 0;
  font-size: 13px;
}
.popup-cta a {
  color: var(--primary);
  text-decoration: none;
  border-bottom: 1px dashed var(--primary);
  transition: border-color 0.12s;
}
.popup-cta a:hover { border-bottom-color: var(--primary-hover); color: var(--primary-hover); }

/* Tracking card — top-right, shown while a vehicle is tracked. */
.card--tracking {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 240px;
  padding: 14px 16px 12px;
}
.card--tracking.hidden { display: none; }
.tracking-title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.tracking-status {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--muted);
}
.info-dwell {
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 500;
}

/* Pin card — shown when the user drops a map pin. Sits below the tracking
   card on the right rail, outside the card-stack because it's a peer of
   info/tracking cards (one-per-instance overlays), not a stackable. */
.card--pin {
  position: absolute;
  top: 16px;
  right: 360px;
  width: 220px;
  padding: 12px 14px 10px;
}
.card--pin.hidden { display: none; }
.pin-title {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.pin-nearest {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

/* ---------------------------------------------------------------------------
   Sidebar + search stack (right rail). Ported from legacy public/styles.css,
   simplified: no ad-slots, no SPA overlay, no legend-inline.

   The card-stack wraps the always-visible search card on top and the
   collapsible sidebar card below. Collapsed sidebar is a 48px gear bubble
   (right-aligned via align-self:flex-end); expanded it fills the stack
   width and becomes a full settings card. Toggle handled by
   ui/sidebar.ts::attachSidebarHandlers flipping .sidebar--collapsed +
   .collapsed on sidebar-body.
   --------------------------------------------------------------------------- */

.card-stack {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 32px);
  z-index: 1000;
}

.card--search {
  flex-shrink: 0;
  padding: 10px 12px;
  position: relative;
  z-index: 2;
}
.card--search input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  outline: none;
  color: var(--text);
  box-sizing: border-box;
}
.card--search input[type="text"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.search { position: relative; }

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 7px;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.12);
  z-index: 30;
  display: none;
}
.search-results.active { display: block; }

.search-result {
  padding: 9px 11px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  line-height: 1.35;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover,
.search-result.kbd-active { background: #eef3ff; }
.search-result .primary {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.search-result .secondary {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.search-empty {
  padding: 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.status {
  font-size: 10px;
  color: var(--muted);
  text-align: right;
  line-height: 1.3;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  margin-top: 4px;
}
.status:empty { display: none; }
.status.error { color: #b91c1c; }
.status.ok    { color: #047857; }

.card--sidebar {
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  transition: width 0.3s ease, border-radius 0.3s ease;
}
.card--sidebar.sidebar--collapsed {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  align-self: flex-end;
  overflow: hidden;
}

.sidebar-toggle {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
}
.sidebar-toggle:hover { background: #f8f9fc; }
.sidebar-toggle:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}
.sidebar-toggle__gear {
  flex-shrink: 0;
  color: var(--muted);
  transition: color 0.2s;
}
.sidebar-toggle:hover .sidebar-toggle__gear { color: var(--text); }

.sidebar--collapsed .sidebar-toggle {
  width: 48px;
  height: 48px;
  justify-content: center;
  border-radius: 50%;
}
.sidebar--collapsed .sidebar-toggle__title,
.sidebar--collapsed .sidebar-toggle__close { display: none; }

.card--sidebar:not(.sidebar--collapsed) .sidebar-toggle {
  width: 100%;
  padding: 13px 18px;
  gap: 10px;
  border-radius: 14px 14px 0 0;
}
.sidebar-toggle__title {
  flex: 1;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
  letter-spacing: -0.01em;
}
.sidebar-toggle__close {
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  padding: 0 2px;
}
.sidebar-toggle__close:hover { color: var(--text); }

.card-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 18px 14px;
  max-height: 100vh;
  opacity: 1;
  transition: max-height 0.28s ease, padding 0.22s ease, opacity 0.22s ease;
}
.card-body.collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}

.panel { margin: 14px 0; }
.panel:first-of-type { margin-top: 4px; }
.panel h2 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  cursor: pointer;
  font-size: 13px;
  user-select: none;
}
.toggle input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--primary);
}
.toggle--inline { gap: 6px; }

.input-num {
  width: 48px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 12px;
  font-family: inherit;
  text-align: center;
  outline: none;
}
.input-num:focus { border-color: var(--primary); }

.btn {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.btn--primary {
  background: var(--primary);
  color: white;
}
.btn--primary:hover { background: var(--primary-hover); }
.btn--primary.active { background: var(--accent); }

.help-text {
  font-size: 11px;
  color: var(--muted);
  margin: 6px 0 0;
  line-height: 1.4;
}

.pass-btn {
  display: block;
  padding: 10px 12px;
  margin: 6px 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.15s;
}
.pass-btn:hover {
  border-color: var(--primary);
  background: #f8fbff;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
}
.pass-btn__title { font-size: 13px; font-weight: 600; }
.pass-btn__sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.affiliate-note {
  font-size: 9px;
  color: var(--muted);
  margin: 8px 0 0;
  text-align: center;
  font-style: italic;
  letter-spacing: 0.02em;
}
