:root {
  --bg: #f3f6f8;
  --panel: #ffffff;
  --border: #d7dfe5;
  --text: #1f2a37;
  --muted: #607385;
  --accent: #156f8b;
  --accent-soft: #e8f4f7;
  --bakery: #c87d1d;
  --restaurant: #d3434d;
  --camping: #238257;
  --water: #2a78d1;
  --hotel: #6f59c9;
  --toilets: #6a7482;
  --left: #1f8f66;
  --right: #2a78d1;
}

* {
  box-sizing: border-box;
}

.panel,
input[type="file"],
button,
.status,
#map,
.summary,
.interval-group,
.road-item,
.meta-pill,
.mobile-tab-btn,
#roadbook::-webkit-scrollbar-thumb,
.btn-spinner {
  border-radius: 0 !important;
}

.leaflet-bar,
.leaflet-bar a,
.leaflet-control-layers,
.leaflet-control-layers-expanded,
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  border-radius: 0 !important;
}

.panel,
input[type="file"],
.status,
#map,
.summary,
.interval-group,
.road-item,
.meta-pill,
.mobile-tab-btn {
  border-width: 1px !important;
}

.leaflet-bar,
.leaflet-bar a,
.leaflet-control-layers {
  border-width: 1px !important;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  color: var(--text);
  font-family: "Manrope", "Avenir Next", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 92% 8%, #e3edf3 0%, transparent 35%),
    radial-gradient(circle at 5% 95%, #e9f2f6 0%, transparent 30%),
    var(--bg);
}

.layout {
  display: grid;
  grid-template-columns: 310px minmax(520px, 1fr) 390px;
  gap: 0.95rem;
  height: 100vh;
  padding: 0.95rem;
  overflow: hidden;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0.9rem;
  box-shadow: 0 8px 24px rgba(23, 37, 50, 0.06);
  min-height: 0;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  overflow-y: auto;
}

label {
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #203344;
}

input[type="file"],
input[type="range"] {
  width: 100%;
}

input[type="file"] {
  border: 1px dashed #bed0dc;
  border-radius: 12px;
  padding: 0.45rem;
  background: #f8fbfc;
  color: #3c5162;
}

input[type="range"] {
  accent-color: var(--accent);
}

button {
  margin-top: 0.2rem;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0.74rem 0.9rem;
  font-weight: 800;
  font-size: 0.9rem;
  font-family: "Manrope", "Avenir Next", "Segoe UI", sans-serif;
  color: #fff;
  background: linear-gradient(135deg, #106b85, #2f8da8);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

button:hover {
  filter: brightness(0.98);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(16, 107, 133, 0.25);
}

.export-row {
  display: flex;
  gap: 0.5rem;
}

.export-row button {
  flex: 1;
}

button.secondary {
  color: #24465a;
  background: #e7f0f5;
  box-shadow: inset 0 0 0 1px #cddde6;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button.loading:disabled {
  opacity: 1;
  cursor: progress;
}

.btn-label {
  display: inline-flex;
  align-items: center;
}

.btn-spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px !important;
  border: 1px solid rgba(36, 70, 90, 0.25);
  border-top-color: #1f5f79;
  display: none;
  flex: 0 0 14px;
  animation: spin 0.8s linear infinite;
}

button.loading .btn-spinner {
  display: inline-block;
}

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

.status {
  margin: 0;
  padding: 0.55rem 0.62rem;
  border-radius: 10px;
  background: #eef4f7;
  border: 1px solid #d5e3eb;
  color: #335364;
  font-size: 0.84rem;
}

.status.status-success {
  background: #dff3dc;
  border-color: #9fcd99;
  color: #000000;
}

.legend h2 {
  margin: 0.25rem 0;
  font-size: 0.95rem;
  font-weight: 800;
}

.legend ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.legend li {
  color: var(--muted);
  font-size: 0.87rem;
}

.cat-option {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: 600;
}

.cat-option input {
  margin: 0;
}

.cat-icon {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cat-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: 14px;
  border: 1px solid #d4dee6;
}

.locate-control .locate-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  color: #255268;
  font-size: 16px;
  font-weight: 800;
  text-decoration: none;
}

.locate-control .locate-btn:hover {
  background: #eef6fa;
  color: #13445a;
}

.map-panel {
  display: flex;
  min-height: 0;
}

.mobile-tabbar {
  display: none;
}

.roadbook-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.roadbook-panel h2 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
}

.summary {
  margin: 0.55rem 0 0.7rem;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid #d6e5ed;
  background: #f3f9fc;
  color: #2d4e5f;
  font-size: 0.84rem;
}

#roadbook {
  margin: 0;
  flex: 1 1 auto;
  min-height: 0;
  display: block;
  overflow-y: auto;
  padding-right: 0.2rem;
}

#roadbook::-webkit-scrollbar {
  width: 8px;
}

#roadbook::-webkit-scrollbar-thumb {
  background: #c8d5df;
  border-radius: 999px;
}

.interval-group {
  border: 1px solid #d8e1e8;
  border-radius: 12px;
  background: #fbfdff;
  overflow: visible;
  margin-bottom: 0.85rem;
  height: auto;
}

.interval-group:last-child {
  margin-bottom: 0;
}

.interval-head {
  padding: 0.55rem 0.68rem;
  border-bottom: 1px solid #e0e8ee;
  font-weight: 800;
  font-size: 0.84rem;
  color: #26495d;
  background: #f3f8fb;
  letter-spacing: 0.01em;
}

.interval-list {
  list-style: none;
  margin: 0;
  padding: 0.45rem;
  display: grid;
  gap: 0.45rem;
}

.road-item {
  border: 1px solid #d7e0e7;
  border-radius: 11px;
  padding: 0.56rem 0.62rem;
  cursor: pointer;
  background: #ffffff;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}

.road-item:hover {
  border-color: #9bc2d8;
  transform: translateY(-1px);
}

.road-item.active {
  border-color: #217f99;
  box-shadow: 0 0 0 2px rgba(33, 127, 153, 0.18);
  background: #f3fbff;
}

.item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.28rem;
}

.item-title {
  display: inline-flex;
  align-items: center;
  gap: 0.36rem;
  font-weight: 800;
  font-size: 0.92rem;
  color: #1f3444;
}

.item-cat-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
  flex: 0 0 18px;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  color: #586c7d;
  font-size: 0.82rem;
}

.meta-pill {
  padding: 0.16rem 0.42rem;
  border-radius: 999px;
  background: #edf3f7;
  border: 1px solid #d7e2ea;
  font-weight: 700;
}

.side-chip {
  color: #fff;
  border: none;
  min-width: 28px;
  text-align: center;
  font-size: 0.95rem;
}

.side-chip.left {
  background: var(--left);
}

.side-chip.right {
  background: var(--right);
}

.interval-empty {
  color: var(--muted);
  font-size: 0.83rem;
  padding: 0.2rem 0.3rem;
}

.map-poi-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid #cdd8e0;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.map-poi-icon-img {
  width: 21px;
  height: 21px;
  object-fit: contain;
}

.map-poi-icon.active {
  transform: scale(1.08);
  box-shadow: 0 0 0 1px rgba(24, 112, 140, 0.28), 0 2px 8px rgba(0, 0, 0, 0.18);
}

@media (max-width: 1320px) {
  .layout {
    grid-template-columns: 300px minmax(0, 1fr);
    grid-template-areas:
      "controls map"
      "roadbook map";
  }

  .controls {
    grid-area: controls;
  }

  .map-panel {
    grid-area: map;
  }

  .roadbook-panel {
    grid-area: roadbook;
  }
}

@media (max-width: 1050px) {
  .layout {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-areas:
      "controls"
      "tabs"
      "content";
    gap: 0.75rem;
    overflow: visible;
  }

  .controls {
    grid-area: controls;
  }

  .mobile-tabbar {
    display: grid;
    grid-area: tabs;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
  }

  .mobile-tab-btn {
    margin: 0;
    border-radius: 999px;
    background: #eef3f7;
    color: #2b4f63;
    box-shadow: inset 0 0 0 1px #d4e1ea;
    font-size: 0.86rem;
  }

  .mobile-tab-btn.active {
    color: #ffffff;
    background: linear-gradient(135deg, #106b85, #2f8da8);
    box-shadow: 0 4px 12px rgba(16, 107, 133, 0.24);
  }

  #map {
    height: 62vh;
    min-height: 420px;
  }

  .map-panel {
    grid-area: content;
  }

  .roadbook-panel {
    grid-area: content;
    height: auto;
  }

  body[data-mobile-tab="map"] .roadbook-panel {
    display: none;
  }

  body[data-mobile-tab="roadbook"] .map-panel {
    display: none;
  }
}
