:root {
  color-scheme: light;
  --bg: #eef3fb;
  --card: rgba(255, 255, 255, 0.94);
  --card-strong: #ffffff;
  --border: #d9e2f0;
  --text: #152238;
  --muted: #5b6c87;
  --accent: #2f6bff;
  --accent-soft: #edf3ff;
  --success: #1f995f;
  --warning: #cb7b08;
  --danger: #c03c4a;
  --shadow: 0 18px 40px rgba(19, 33, 56, 0.12);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, rgba(47, 107, 255, 0.12), transparent 28%), var(--bg);
}

button,
select,
input,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: relative;
  z-index: 1000;
  padding: 20px;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(246, 249, 255, 0.98) 100%);
  overflow-y: auto;
  backdrop-filter: blur(10px);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.sidebar-header h1 {
  margin: 6px 0 8px;
  font-size: 2rem;
  line-height: 1.02;
}

.eyebrow {
  margin: 0;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.subtle,
.hint,
.notes-card p,
.popup-muted,
.stat-label,
.cluster-note,
.category-cluster-name,
.nearby-meta {
  color: var(--muted);
}

.header-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.control-card {
  margin-top: 16px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.control-grid {
  display: grid;
  gap: 12px;
}

.label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.92rem;
  font-weight: 800;
}

#citySelect,
#travelModeSelect {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.section-row,
.stat,
.cluster-header,
.route-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.legend-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #3557a4;
  white-space: nowrap;
  border: 1px solid rgba(47, 107, 255, 0.08);
}

.app-state-pill[data-state="ready"] {
  background: rgba(31, 153, 95, 0.12);
  color: #146d42;
}

.app-state-pill[data-state="offline"] {
  background: rgba(203, 123, 8, 0.14);
  color: #8a5200;
}

.app-state-pill[data-state="offline-limited"] {
  background: rgba(192, 60, 74, 0.14);
  color: #8e2432;
}

.compact-actions,
.map-toolbar,
.route-grid,
.cluster-header-right,
.hours-filter-list {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.compact-actions button,
.toolbar-button,
.icon-button,
.secondary-button,
.filter-chip,
.map-route-button,
.route-toggle-inline,
.nearby-item {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  padding: 10px 14px;
  box-shadow: 0 8px 22px rgba(19, 33, 56, 0.08);
  text-decoration: none;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.compact-actions button:hover,
.toolbar-button:hover,
.icon-button:hover,
.secondary-button:hover,
.filter-chip:hover,
.map-route-button:hover,
.route-toggle-inline:hover,
.nearby-item:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.4rem;
  line-height: 1;
}

.filter-chip,
.route-toggle-inline,
.cluster-toggle,
.category-item,
.nearby-item {
  font-weight: 700;
}

.filter-chip.is-active,
.route-toggle-inline.is-active,
.toolbar-button.is-active,
.nearby-toggle-button.is-active,
.map-route-toggle-button.is-active,
.map-route-button.is-routing {
  background: var(--accent-soft);
  border-color: #7aa0ff;
  color: #2149aa;
}

.route-toggle-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}

.route-toggle-inline input {
  margin: 0;
}

.route-toggle-inline:has(input:checked) {
  background: var(--accent-soft);
  border-color: #7aa0ff;
  color: #2149aa;
}

.map-top-controls {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 900;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
}

.map-toolbar {
  pointer-events: auto;
  max-width: min(100%, 680px);
}

.map-route-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.map-route-button.is-disabled,
.route-travel-select:disabled {
  opacity: 0.6;
}

.map-route-toggle-button {
  min-width: 52px;
  font-weight: 900;
}

.category-list {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.category-cluster {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(251, 253, 255, 0.95);
  overflow: hidden;
}

.cluster-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.cluster-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}

.cluster-dot,
.category-swatch,
.nearby-swatch {
  border-radius: 999px;
}

.cluster-dot,
.nearby-swatch {
  width: 12px;
  height: 12px;
}

.cluster-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 999px;
  background: #f5f8ff;
  color: #365289;
  font-size: 0.82rem;
}

.cluster-items {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.category-item {
  display: grid;
  grid-template-columns: auto 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: #fff;
}

.category-item.is-disabled {
  opacity: 0.45;
}

.category-swatch {
  width: 14px;
  height: 14px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.8);
}

.category-text,
.nearby-copy,
.tips-list {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.category-name,
.nearby-name {
  font-size: 0.94rem;
  font-weight: 700;
}

.category-count {
  min-width: 24px;
  text-align: right;
  font-weight: 800;
  color: var(--muted);
}

.route-card,
.nearby-card,
.stats-card {
  display: grid;
  gap: 12px;
}

.route-points {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.route-point-card {
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fbfdff;
  min-width: 0;
}

.route-point-card strong {
  display: block;
  font-size: 0.92rem;
  line-height: 1.35;
  word-break: break-word;
}

.route-point-label {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.nearby-empty {
  padding: 14px;
  border-radius: 16px;
  border: 1px dashed var(--border);
  color: var(--muted);
  background: #fbfdff;
}

.nearby-item {
  width: 100%;
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  text-align: left;
}

.nearby-chevron {
  font-size: 1.2rem;
  color: var(--muted);
}

.notes-card h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.tips-list p {
  margin: 0;
  line-height: 1.45;
}

.map-panel {
  position: relative;
  min-width: 0;
  isolation: isolate;
}

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

.leaflet-right .leaflet-control,
.leaflet-left .leaflet-control {
  margin-right: 16px;
}

.leaflet-top .leaflet-control {
  margin-top: 16px;
}

.leaflet-bottom .leaflet-control {
  margin-bottom: calc(16px + var(--safe-bottom));
}


.detail-panel {
  position: absolute;
  left: 50%;
  width: min(680px, calc(100% - 32px));
  bottom: calc(24px + var(--safe-bottom));
  z-index: 1200;
  pointer-events: none;
  opacity: 1;
  transform: translateX(-50%);
  transition: opacity 160ms ease, transform 160ms ease, top 160ms ease, bottom 160ms ease;
}

.detail-panel.is-hidden {
  opacity: 0;
  transform: translate(-50%, 12px);
}

.detail-card {
  position: relative;
  pointer-events: auto;
  width: 100%;
  margin: 0;
  padding: 16px 18px;
  border-radius: 22px;
  border: 1px solid rgba(217, 226, 240, 0.78);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 22px 44px rgba(19, 33, 56, 0.18);
  transition: opacity 140ms ease, transform 140ms ease;
}

.detail-panel:not(.is-hidden) .detail-card {
  opacity: 1;
  transform: translateY(0);
}

.detail-content {
  min-height: 68px;
  max-height: min(40vh, 380px);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-right: 6px;
}

.detail-close {
  float: right;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  padding: 0;
  margin-left: 12px;
}

.detail-topline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding-right: 44px;
}

.detail-swatch {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.detail-category {
  font-weight: 800;
}

.detail-cluster {
  font-size: 0.82rem;
  color: var(--muted);
  background: rgba(237, 243, 255, 0.92);
  border: 1px solid rgba(47, 107, 255, 0.08);
  border-radius: 999px;
  padding: 4px 8px;
}

.detail-title {
  margin: 0 0 6px;
  font-size: 1.22rem;
  line-height: 1.15;
}

.detail-address {
  margin-bottom: 8px;
}

.detail-description {
  margin: 10px 0 0;
  line-height: 1.48;
}

.detail-empty {
  color: var(--muted);
  line-height: 1.45;
}

.popup-card {
  max-width: 280px;
  line-height: 1.45;
}

.popup-card p {
  margin: 10px 0 0;
}

.popup-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.88rem;
}

.popup-chip {
  padding: 4px 8px;
  border-radius: 999px;
  background: #eff4ff;
}

.popup-route-hint {
  margin-top: 8px;
  font-size: 0.84rem;
}

.leaflet-tooltip.closing-hour-tooltip {
  background: rgba(15, 23, 42, 0.92);
  border: 0;
  color: #fff;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.25);
}

.leaflet-tooltip.closing-hour-tooltip::before {
  display: none;
}

.mobile-only {
  display: none;
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
  }

  .mobile-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: min(84vh, 780px);
    border-right: 0;
    border-top: 1px solid var(--border);
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -24px 42px rgba(19, 33, 56, 0.18);
    transform: translateY(calc(100% - 80px));
    transition: transform 180ms ease;
    padding-bottom: calc(20px + var(--safe-bottom));
  }

  body.sidebar-open .sidebar {
    transform: translateY(0);
  }

  .map-top-controls {
    top: 12px;
    left: 12px;
    right: 12px;
    gap: 8px;
  }

  .map-toolbar {
    gap: 8px;
    max-width: 100%;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, max-content));
    align-items: center;
  }

  .toolbar-button,
  .secondary-button,
  .compact-actions button,
  .filter-chip,
  .map-route-button,
  .route-toggle-inline {
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.97);
  }

  .map-route-button {
    min-width: 72px;
  }

  .map-route-toggle-button {
    min-width: 48px;
  }

  .control-grid,
  .route-points {
    grid-template-columns: 1fr;
  }

  body.sidebar-open .map-top-controls,
  body.sidebar-open .leaflet-control-container {
    opacity: 0.18;
    pointer-events: none;
  }

  .detail-panel {
    left: 12px;
    right: 12px;
    width: auto;
    bottom: calc(92px + var(--safe-bottom));
    transform: none;
  }

  .detail-panel.is-hidden {
    transform: translateY(12px);
  }

  body.sidebar-open .detail-panel {
    top: 72px;
    bottom: auto;
    z-index: 1205;
    opacity: 1;
    pointer-events: auto;
  }

  .detail-card {
    max-width: 100%;
    padding: 14px 14px 16px;
    border-radius: 20px;
  }

  .detail-content {
    max-height: min(34vh, 300px);
  }

  .detail-title {
    font-size: 1.05rem;
  }

  .leaflet-bottom .leaflet-control {
    margin-bottom: calc(156px + var(--safe-bottom));
  }
}

@media (max-width: 640px) {
  .sidebar {
    padding: 16px;
  }

  .map-toolbar {
    grid-template-columns: repeat(3, minmax(0, max-content));
  }

  .toolbar-button,
  .map-route-button {
    min-height: 44px;
  }

  .detail-card {
    padding: 12px 12px 14px;
    border-radius: 18px;
  }

  .detail-panel {
    left: 10px;
    right: 10px;
    bottom: calc(88px + var(--safe-bottom));
  }

  body.sidebar-open .detail-panel {
    top: 64px;
  }

  .detail-content {
    max-height: min(32vh, 250px);
  }

  .detail-topline {
    gap: 6px;
  }

  .cluster-header {
    align-items: flex-start;
  }

  .cluster-header-right {
    justify-content: flex-end;
  }
}
