:root {
  --bg: #0f1419;
  --panel: rgba(18, 24, 32, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #eef2f6;
  --muted: #93a0b0;
  --accent: #3d9cf0;
  --accent-strong: #1f7fd4;
  --start: #22c55e;
  --end: #ef4444;
  --route: #3d9cf0;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
}

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

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
}

button,
input {
  font: inherit;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
  min-height: 100dvh;
}

/* ── Top bar ─────────────────────────────────────────── */

.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px 20px;
  padding: 14px 18px;
  background: linear-gradient(180deg, #121820 0%, #10151c 100%);
  border-bottom: 1px solid var(--panel-border);
  z-index: 1000;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 180px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: white;
  background: linear-gradient(145deg, #3d9cf0, #2563eb);
  box-shadow: 0 8px 20px rgba(61, 156, 240, 0.3);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-text strong {
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-text span {
  font-size: 0.75rem;
  color: var(--muted);
}

.search-form {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  min-width: min(100%, 520px);
}

.search-fields {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
}

.field-wrap {
  flex: 1 1 200px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-label em {
  font-style: normal;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.8;
}

.pin {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.start-pin {
  background: var(--start);
}

.end-pin {
  background: var(--end);
}

.input-shell {
  position: relative;
}

.input-shell input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease,
    background 0.15s ease;
}

.input-shell input::placeholder {
  color: #6d7a8a;
}

.input-shell input:focus {
  border-color: rgba(61, 156, 240, 0.7);
  background: rgba(61, 156, 240, 0.08);
  box-shadow: 0 0 0 3px rgba(61, 156, 240, 0.18);
}

.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  max-height: 280px;
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: #151c25;
  box-shadow: var(--shadow);
  z-index: 1200;
}

.suggestions li {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1.35;
  color: var(--text);
}

.suggestions li:hover,
.suggestions li[aria-selected="true"] {
  background: rgba(61, 156, 240, 0.16);
}

.suggestions li small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.75rem;
}

.icon-btn,
.primary-btn,
.ghost-btn,
.export-btn,
.seg-btn,
.zoom-controls button {
  cursor: pointer;
  border: none;
  border-radius: 12px;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-bottom: 2px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.icon-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.primary-btn {
  height: 44px;
  padding: 0 18px;
  font-weight: 600;
  color: white;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  box-shadow: 0 8px 18px rgba(31, 127, 212, 0.28);
}

.primary-btn:hover {
  filter: brightness(1.06);
}

.primary-btn:active {
  transform: translateY(1px);
}

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

.map-stage {
  position: relative;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
  background: #1a2330;
}

.floating-panel {
  position: absolute;
  top: 16px;
  left: 16px;
  width: min(320px, calc(100% - 32px));
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.seg-btn {
  height: 36px;
  color: var(--muted);
  background: transparent;
  font-size: 0.88rem;
  font-weight: 500;
}

.seg-btn.is-active {
  color: white;
  background: rgba(61, 156, 240, 0.22);
  box-shadow: inset 0 0 0 1px rgba(61, 156, 240, 0.35);
}

.check-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
}

.check-row input {
  margin-top: 3px;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.check-row strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
}

.check-row small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stats > div {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats strong {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ghost-btn {
  height: 40px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-weight: 500;
}

.ghost-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.ghost-btn:disabled,
.export-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.export-btn {
  grid-column: 1 / -1;
  height: 44px;
  font-weight: 700;
  color: white;
  background: linear-gradient(180deg, #22c55e, #16a34a);
  box-shadow: 0 8px 18px rgba(34, 197, 94, 0.25);
}

.export-btn:hover:not(:disabled) {
  filter: brightness(1.05);
}

.zoom-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 500;
}

.zoom-controls button {
  width: 42px;
  height: 42px;
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.zoom-controls button:hover {
  background: #1a2330;
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  margin: 0;
  max-width: min(520px, calc(100% - 32px));
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 0.84rem;
  text-align: center;
  z-index: 500;
  pointer-events: none;
}

/* Leaflet overrides */

.leaflet-control-attribution {
  background: rgba(15, 20, 25, 0.75) !important;
  color: #9aa7b5 !important;
  font-size: 11px !important;
  border-radius: 8px 0 0 0 !important;
}

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

.leaflet-container {
  font-family: var(--font);
  background: #1a2330;
}

/* Custom markers */

.marker-bubble {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  border: 2px solid white;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.35);
  color: white;
  font-size: 12px;
  font-weight: 700;
}

.marker-bubble span {
  transform: rotate(45deg);
}

.marker-bubble.start {
  background: var(--start);
}

.marker-bubble.end {
  background: var(--end);
}

/* ── Export dialog ───────────────────────────────────── */

.export-dialog {
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 0;
  width: min(420px, calc(100vw - 32px));
  background: #151c25;
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.export-dialog::backdrop {
  background: rgba(6, 10, 16, 0.62);
  backdrop-filter: blur(4px);
}

.export-dialog-inner {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
}

.export-dialog-header h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.export-dialog-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.export-name-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.export-name-field input {
  height: 46px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease,
    background 0.15s ease;
}

.export-name-field input:focus {
  border-color: rgba(61, 156, 240, 0.7);
  background: rgba(61, 156, 240, 0.08);
  box-shadow: 0 0 0 3px rgba(61, 156, 240, 0.18);
}

.export-filename-preview {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.export-filename-preview code {
  color: #c5d4e4;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  word-break: break-all;
}

.export-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
}

.export-dialog-actions .export-btn {
  grid-column: auto;
  height: 44px;
}

.export-dialog-actions .ghost-btn {
  height: 44px;
}

@media (max-width: 720px) {
  .top-bar {
    padding: 12px;
  }

  .brand {
    width: 100%;
  }

  .swap-btn {
    display: none;
  }

  .floating-panel {
    top: auto;
    bottom: 64px;
    left: 12px;
    right: 12px;
    width: auto;
  }

  .hint {
    bottom: auto;
    top: 12px;
    left: 12px;
    right: 60px;
    transform: none;
    max-width: none;
    border-radius: 12px;
    text-align: left;
  }

  .zoom-controls {
    top: 12px;
    right: 12px;
  }
}
