:root {
  --bg: #080d1a;
  --bg-sidebar: #0b1120;
  --bg-card: #101928;
  --bg-card-hover: #141f30;
  --bg-panel: #0b1120;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.13);
  --accent: #f59e0b;
  --accent-dim: rgba(245, 158, 11, 0.12);
  --accent-border: rgba(245, 158, 11, 0.35);
  --green: #10b981;
  --purple: #8b5cf6;
  --text: #eef2ff;
  --text-secondary: #7b93b8;
  --text-muted: #3d5473;
  --sidebar-w: 370px;
  --panel-w: 410px;
  --radius: 12px;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ─── Layout ─────────────────────────────────────────────── */

#app {
  display: flex;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

/* ─── Sidebar ─────────────────────────────────────────────── */

#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#sidebar-header {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(
    135deg,
    rgba(245, 158, 11, 0.06) 0%,
    transparent 60%
  );
  flex-shrink: 0;
}

.trip-icon {
  font-size: 34px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 8px rgba(245, 158, 11, 0.4));
}

#trip-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

#trip-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 3px;
}

#config-link {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 18px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}

#config-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
}

#trip-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.stat {
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border-right: 1px solid var(--border);
}

.stat:last-child {
  border-right: none;
}

.stat-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
}

#legs-container {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#legs-container::-webkit-scrollbar {
  width: 4px;
}
#legs-container::-webkit-scrollbar-track {
  background: transparent;
}
#legs-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ─── Leg cards ────────────────────────────────────────────── */

.leg-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px;
  margin-bottom: 10px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.18s ease, background 0.18s ease,
    border-color 0.18s ease;
}

.leg-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--c, var(--accent));
  border-radius: 3px 0 0 3px;
}

.leg-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
  transform: translateX(3px);
}

.leg-card.active {
  background: var(--bg-card-hover);
  border-color: var(--c, var(--accent));
  box-shadow: 0 0 0 1px var(--c, var(--accent)) inset,
    0 4px 20px rgba(0, 0, 0, 0.3);
  transform: translateX(3px);
}

/* card top row */
.leg-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 13px;
}

.leg-badge {
  display: flex;
  align-items: center;
  gap: 9px;
}

.leg-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--c, var(--accent));
  color: #000;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.leg-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

.leg-chips {
  display: flex;
  gap: 6px;
}

.chip {
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 7px;
}

/* route visualization */
.leg-route {
  display: flex;
  flex-direction: column;
}

.stop-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.stop-track {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: 10px;
  padding-top: 5px;
}

.stop-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stop-dot.origin {
  background: rgba(255, 255, 255, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.4);
}

.stop-dot.dest {
  background: var(--c, var(--accent));
  box-shadow: 0 0 6px var(--c, var(--accent));
}

.track-line {
  width: 2px;
  flex: 1;
  min-height: 20px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.1), var(--c, var(--accent)) 80%);
  margin: 4px 0;
  border-radius: 1px;
}

.stop-info {
  flex: 1;
  padding-bottom: 18px;
}

.stop-row:last-child .stop-info {
  padding-bottom: 0;
}

.stop-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
}

.stop-name.dest {
  font-weight: 700;
}

.stop-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.4;
}

/* card CTA */
.leg-cta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--c, var(--accent));
  opacity: 0.7;
  transition: opacity 0.15s;
}

.leg-card:hover .leg-cta {
  opacity: 1;
}

.cta-arrow {
  display: inline-block;
  transition: transform 0.25s ease;
  font-size: 14px;
}

.leg-card.expanded .cta-arrow {
  transform: rotate(180deg);
}

/* ─── Inline leg detail expand ─────────────────────────────── */

.leg-detail {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.42s cubic-bezier(0.4, 0, 0.2, 1);
}

.leg-card.expanded .leg-detail {
  max-height: 2400px;
}

.detail-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.detail-block:first-child {
  margin-top: 12px;
}

.detail-block-eyebrow {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.35);
  margin-bottom: 6px;
}

.detail-block-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.detail-hotel-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 5px;
}

.detail-hotel-stars {
  font-size: 13px;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.detail-stars-empty {
  color: rgba(255, 255, 255, 0.15);
}

.detail-hotel-address {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 10px;
}

.detail-hotel-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.7;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.hotel-img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 12px;
  display: block;
}

/* ─── Map ──────────────────────────────────────────────────── */

#map-container {
  flex: 1;
  position: relative;
  isolation: isolate; /* contain Leaflet's internal z-indexes so they don't escape into siblings */
}

#map {
  width: 100%;
  height: 100%;
}

#sidebar-toggle {
  display: none;
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 500;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

/* ─── Leaflet overrides ────────────────────────────────────── */

.leaflet-container {
  background: #f2efe9;
  font-family: inherit;
}

.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.85) !important;
  color: #666 !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: #444 !important;
}

.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  border-color: var(--border-strong) !important;
  color: var(--text) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-card-hover) !important;
}

/* custom markers */
.map-marker {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: #000;
  border: 3px solid rgba(0, 0, 0, 0.6);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.7), 0 0 0 2px rgba(255,255,255,0.08);
  cursor: pointer;
  transition: transform 0.15s;
}

.map-marker:hover {
  transform: scale(1.12);
}

.map-marker.origin {
  width: 24px;
  height: 24px;
  background: rgba(255, 255, 255, 0.18);
  border: 2px solid rgba(255, 255, 255, 0.5);
  font-size: 10px;
  color: #fff;
}

.map-marker.charging {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid;
  font-size: 10px;
  font-weight: 900;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

.map-marker.place {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: #fff;
  border: 2px solid;
  font-size: 11px;
  font-weight: 900;
  box-shadow: 0 1px 7px rgba(0, 0, 0, 0.38);
}

/* Leaflet popup */
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: 10px !important;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.6) !important;
  color: var(--text) !important;
  font-family: inherit !important;
  font-size: 13px !important;
  padding: 0 !important;
}

.leaflet-popup-content {
  margin: 12px 14px !important;
}

.leaflet-popup-content strong {
  font-size: 14px;
  font-weight: 700;
  display: block;
  margin-bottom: 2px;
}

.leaflet-popup-content span {
  font-size: 12px;
  color: var(--text-secondary);
}

.leaflet-popup-tip {
  background: var(--bg-card) !important;
}

.leaflet-popup-tip-container {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4));
}

/* ─── Detail panel ─────────────────────────────────────────── */

#detail-panel {
  /* flex item — sits beside the map, no z-index battle with Leaflet */
  flex-shrink: 0;
  width: var(--panel-w);
  overflow: hidden;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: -6px 0 40px rgba(0, 0, 0, 0.4);
}

#detail-panel.panel-hidden {
  width: 0;
  border-left: none;
  box-shadow: none;
}

/* inner wrapper keeps full width so content doesn't reflow during animation */
#detail-inner {
  width: var(--panel-w);
  min-width: var(--panel-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#detail-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#close-panel {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  transition: all 0.15s;
}

#close-panel:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

#detail-leg-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

#detail-leg-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--panel-color, var(--accent));
  color: #000;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

#detail-leg-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

#detail-route-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
  margin-bottom: 4px;
}

#detail-route-meta {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  gap: 12px;
}

#detail-content {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#detail-content::-webkit-scrollbar {
  width: 4px;
}
#detail-content::-webkit-scrollbar-track {
  background: transparent;
}
#detail-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.detail-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 13px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.section-icon {
  font-size: 14px;
}

/* ── Hotel hero (magazine style) ────────────────────────────── */

.detail-section.section-flush {
  padding: 0;
  overflow: hidden;
}

.hotel-hero-head {
  padding: 18px 18px 16px;
  border-bottom: 1px solid var(--border);
}

.hotel-section-eyebrow {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.4);
  margin-bottom: 10px;
}

.hotel-hero-name {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 10px;
}

.hotel-star-row {
  display: flex;
  align-items: center;
  gap: 0;
}

.hotel-star {
  font-size: 14px;
  letter-spacing: 1px;
}

.hotel-star.filled {
  color: var(--accent);
}

.hotel-star.empty {
  color: rgba(255, 255, 255, 0.15);
}

.hotel-category {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-left: 10px;
  padding-left: 10px;
  border-left: 1px solid rgba(255, 255, 255, 0.15);
}

.hotel-hero-body {
  padding: 14px 18px 16px;
  background: var(--bg-card);
}

.hotel-address-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.hotel-hero-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 0;
}

/* ── Via tags ───────────────────────────────────────────────── */

.via-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.via-tag {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Restaurant cards (orb style) ───────────────────────────── */

.resto-card {
  display: flex;
  gap: 13px;
  align-items: flex-start;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}

.resto-card:first-child {
  padding-top: 0;
}

.resto-card:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.resto-orb {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: -1px;
}

.resto-body {
  flex: 1;
  min-width: 0;
}

.resto-top-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.resto-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.resto-price {
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
  letter-spacing: 0.5px;
}

.resto-type {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 7px;
}

.resto-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ── Sightseeing list ───────────────────────────────────────── */

.sight-item {
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.sight-item:first-child {
  padding-top: 0;
}

.sight-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.sight-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}

.sight-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.sight-type-tag {
  font-size: 10px;
  font-weight: 600;
  border-radius: 4px;
  padding: 2px 8px;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.3px;
}

.sight-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ─── Loading ──────────────────────────────────────────────── */

#loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 999;
  transition: opacity 0.5s ease;
}

#loading.done {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

#loading p {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ─── Mobile ───────────────────────────────────────────────── */

@media (max-width: 768px) {
  #sidebar {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 20;
    transform: translateX(-102%);
    box-shadow: 4px 0 40px rgba(0, 0, 0, 0.5);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #detail-panel:not(.panel-hidden) {
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    z-index: 25;
  }

  #detail-inner {
    width: 100%;
    min-width: 100%;
  }
}
