* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  color: #172033;
  background: #edf1f5;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

[v-cloak] {
  display: none;
}

.app-shell {
  height: 100vh;
  min-height: 620px;
  display: grid;
  grid-template-rows: 60px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.brand-block {
  min-width: 0;
}

.brand-block h1 {
  margin: 2px 0 0;
  font-size: 26px;
  line-height: 1.05;
  letter-spacing: 0;
  color: #0f172a;
}

.brand-kicker {
  display: block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  color: #0f766e;
  text-transform: uppercase;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 318px minmax(0, 1fr);
  gap: 10px;
}

.sidebar {
  min-width: 0;
  min-height: 0;
  display: grid;
  gap: 10px;
  align-content: start;
  overflow: auto;
  padding-right: 2px;
}

.panel {
  border: 1px solid #d5dde8;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  padding: 12px;
  box-shadow: 0 6px 18px rgba(22, 34, 51, 0.05);
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
}

.panel-heading span {
  font-size: 13px;
  font-weight: 800;
  color: #0f172a;
}

.panel-heading small {
  min-width: 0;
  overflow: hidden;
  color: #66758a;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mode-button {
  min-height: 56px;
  border: 1px solid #d7dee8;
  border-radius: 8px;
  background: #f8fafc;
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}

.mode-button:hover {
  border-color: #8fb2d8;
  background: #f2f7fb;
}

.mode-button.active {
  border-color: #2563eb;
  background: #eff6ff;
  color: #1d4ed8;
}

.mode-button span {
  font-weight: 800;
}

.mode-button small {
  min-width: 0;
  overflow: hidden;
  color: inherit;
  font-size: 12px;
  opacity: 0.76;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tone-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tone-button {
  height: 38px;
  border: 1px solid #d7dee8;
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
  font-weight: 800;
}

.tone-button:hover {
  border-color: #8fb2d8;
  background: #f2f7fb;
}

.tone-button.active {
  border-color: #0f766e;
  background: #ecfdf5;
  color: #0f766e;
}

.search-field input {
  width: 100%;
  height: 40px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0 12px;
  color: #0f172a;
  background: #fff;
}

.search-field input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.18);
  border-color: #2563eb;
}

.search-results {
  margin-top: 9px;
  max-height: 236px;
  overflow: auto;
  display: grid;
  gap: 6px;
}

.search-result {
  width: 100%;
  border: 1px solid #d7dee8;
  border-radius: 8px;
  background: #f8fafc;
  padding: 9px 10px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  cursor: pointer;
}

.search-result:hover {
  background: #eff6ff;
  border-color: #8fb2d8;
}

.search-result span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result small {
  color: #64748b;
  flex-shrink: 0;
}

.empty-state {
  padding: 7px 2px 2px;
  color: #64748b;
  font-size: 13px;
}

.empty-state.error {
  color: #b91c1c;
}

.data-panel {
  display: grid;
  gap: 10px;
}

.sidebar-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid #e5ebf2;
  border-bottom: 1px solid #e5ebf2;
}

.mini-stat {
  min-width: 0;
}

.mini-stat span {
  display: block;
  color: #64748b;
  font-size: 12px;
}

.mini-stat strong {
  display: block;
  margin-top: 2px;
  color: #0f172a;
  font-size: 19px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475569;
}

.status-chip.ready {
  background: #ecfdf5;
  color: #047857;
}

.status-chip.loading {
  background: #eff6ff;
  color: #1d4ed8;
}

.status-chip.empty,
.status-chip.idle {
  background: #f8fafc;
  color: #64748b;
}

.status-chip.warning {
  background: #fffbeb;
  color: #b45309;
}

.status-chip.error {
  background: #fef2f2;
  color: #b91c1c;
}

.admin-link {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 8px;
  padding: 0 11px;
  background: #0f766e;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
}

.admin-link:hover {
  background: #115e59;
}

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #cfd8e5;
  border-radius: 8px;
  background: #d9e3ee;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

#map {
  position: absolute;
  inset: 0;
}

.leaflet-container {
  overflow: hidden;
  touch-action: pan-x pan-y;
  font-family: inherit;
  background: #d9e3ee;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-container img {
  max-width: none;
}

.leaflet-basemap-pane {
  transition: filter 160ms ease, opacity 160ms ease;
}

.basemap-muted .leaflet-basemap-pane {
  filter: grayscale(100%) contrast(1.05) brightness(0.92);
  opacity: 0.86;
}

.leaflet-label-pane {
  pointer-events: none;
}

.leaflet-control-zoom {
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.leaflet-control-zoom a {
  width: 34px;
  height: 34px;
  border: 0;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.96);
  line-height: 34px;
}

.leaflet-control-zoom a:hover {
  background: #eff6ff;
  color: #1d4ed8;
}

.leaflet-control-attribution,
.leaflet-control-scale-line {
  border-color: rgba(15, 23, 42, 0.16);
  background: rgba(255, 255, 255, 0.9);
  color: #334155;
}

.map-status,
.map-warning {
  position: absolute;
  z-index: 520;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  color: #0f172a;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.map-status {
  top: 12px;
  left: 12px;
  display: inline-flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 10px;
  pointer-events: none;
}

.map-warning {
  top: 56px;
  left: 12px;
  right: 12px;
  padding: 10px 12px;
  color: #b91c1c;
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 520;
  width: min(252px, calc(100% - 24px));
  padding: 10px 12px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
  pointer-events: none;
}

.legend-title {
  margin-bottom: 7px;
  color: #0f172a;
  font-size: 12px;
  font-weight: 800;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
  color: #334155;
  font-size: 12px;
}

.legend-line {
  width: 24px;
  height: 4px;
  border-radius: 999px;
  flex-shrink: 0;
}

.feature-popup {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 530;
  width: min(356px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 14px 16px 16px;
  border: 1px solid rgba(15, 23, 42, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.18);
}

.popup-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: #eef2f7;
  color: #334155;
  cursor: pointer;
  line-height: 1;
}

.popup-close:hover {
  background: #dbe4ef;
}

.popup-kind {
  color: #0f766e;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.feature-popup h2 {
  margin: 4px 0 12px;
  padding-right: 36px;
  color: #0f172a;
  font-size: 18px;
  line-height: 1.25;
}

.feature-popup dl {
  margin: 0;
  display: grid;
  gap: 8px;
}

.feature-popup dl > div {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding-top: 8px;
  border-top: 1px solid #e5ebf2;
}

.feature-popup dt {
  color: #64748b;
}

.feature-popup dd {
  margin: 0;
  min-width: 0;
  color: #0f172a;
  word-break: break-word;
}

.feature-popup a {
  color: #1d4ed8;
  text-decoration: none;
}

.feature-popup a:hover {
  text-decoration: underline;
}

.line-label-marker,
.station-label-marker,
.station-focus-label {
  pointer-events: none;
}

.line-label-marker span,
.station-label-marker span,
.station-focus-label span {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  max-width: 220px;
  overflow: hidden;
  color: #0f172a;
  font-weight: 700;
  line-height: 1.15;
  text-overflow: ellipsis;
  text-shadow:
    0 1px 0 #fff,
    1px 0 0 #fff,
    0 -1px 0 #fff,
    -1px 0 0 #fff;
  white-space: nowrap;
}

.line-label-marker span {
  bottom: -2px;
  color: #374151;
  font-size: 11px;
  font-style: italic;
  font-weight: 800;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.94),
    1px 0 0 rgba(255, 255, 255, 0.94),
    0 -1px 0 rgba(255, 255, 255, 0.94),
    -1px 0 0 rgba(255, 255, 255, 0.94);
}

.station-label-marker span {
  font-size: 11px;
}

.station-focus-label span {
  bottom: 14px;
  padding: 4px 7px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.14);
  font-size: 13px;
}

.boot-error {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 1000;
  padding: 10px 12px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  background: #fef2f2;
  color: #b91c1c;
  box-shadow: 0 12px 26px rgba(15, 23, 42, 0.16);
}

.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;
}

@media (max-width: 1100px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-rows: auto auto;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
    padding-right: 0;
  }

  .map-stage {
    min-height: 68vh;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 8px;
    gap: 8px;
  }

  .brand-block h1 {
    font-size: 22px;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .mode-grid {
    grid-template-columns: 1fr;
  }

  .map-stage {
    min-height: 62vh;
  }

  .map-status,
  .map-warning,
  .legend,
  .feature-popup {
    left: 8px;
    right: 8px;
    width: auto;
  }

  .map-status {
    top: 8px;
  }

  .map-warning {
    top: 52px;
  }

  .legend {
    bottom: 8px;
  }

  .feature-popup {
    bottom: 8px;
  }

  .feature-popup dl > div {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
