* { box-sizing: border-box; }

html,
body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--color-page);
  color: var(--color-text);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

.map-service-shell {
  --topbar-height: 60px;
  display: grid;
  height: 100dvh;
  grid-template-rows: var(--topbar-height) minmax(0, 1fr);
}

.topbar {
  position: relative;
  z-index: 1000;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-footer);
}

.topbar-inner {
  display: grid;
  width: min(1380px, calc(100% - 40px));
  min-height: var(--topbar-height);
  margin-inline: auto;
  grid-template-columns: auto 1fr auto;
  gap: 20px;
  align-items: center;
}

.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--color-text);
  font-weight: 700;
  text-decoration: none;
}

.brand-logo { width: 66px; height: 44px; object-fit: contain; }
.brand-text { font-size: 1.2rem; white-space: nowrap; }
.main-nav { display: flex; gap: 20px; align-items: center; justify-content: center; }

.main-nav a {
  position: relative;
  color: var(--color-text-secondary);
  font-size: .82rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.main-nav a::after {
  position: absolute;
  right: 0;
  bottom: -9px;
  left: 0;
  height: 2px;
  background: var(--color-icon);
  content: "";
  opacity: 0;
  transform: scaleX(.4);
  transition: 160ms ease;
}

.main-nav a:hover,
.main-nav a[aria-current="page"] { color: var(--color-text); }
.main-nav a:hover::after,
.main-nav a[aria-current="page"]::after { opacity: 1; transform: scaleX(1); }

.topbar-actions { display: flex; gap: 8px; align-items: center; }
.icon-button,
.menu-button {
  display: inline-grid;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--color-border-soft);
  border-radius: 3px;
  background: var(--color-window);
  cursor: pointer;
  place-items: center;
}

.icon-button:hover,
.menu-button:hover { border-color: var(--color-icon); }
.menu-button { display: none; }
.theme-glyph { width: 15px; height: 15px; border: 2px solid var(--color-icon); border-radius: 50%; }

.map-workspace {
  display: grid;
  width: min(1380px, calc(100% - 40px));
  min-height: 0;
  margin: 20px auto;
  overflow: hidden;
  border: 1px solid var(--color-border-soft);
  border-radius: 12px;
  grid-template-columns: 350px minmax(0, 1fr);
  background: var(--color-canvas);
}

.map-sidebar {
  position: relative;
  z-index: 800;
  overflow: auto;
  padding: 18px;
  border-right: 1px solid var(--color-border);
  background: var(--color-footer);
}

.map-sidebar h1,
.map-sidebar h2 { margin: 0 0 5px; font-size: 16px; font-weight: 650; }
.section-accent-title {
  display: inline-flex;
  gap: 9px;
  align-items: center;
  margin: 0;
  color: var(--color-text-primary);
  font-size: clamp(1.25rem, 2vw, 1.55rem);
  font-weight: 700;
  letter-spacing: .04em;
  line-height: 1.25;
  text-transform: uppercase;
}

.section-accent-title::before {
  width: 26px;
  height: 2px;
  background: var(--color-accent);
  content: "";
}
.sidebar-intro { margin: 0 0 16px; color: var(--color-text-secondary); font-size: 12px; }
.field-label { display: block; margin-bottom: 5px; color: var(--color-text-secondary); font-size: 12px; font-weight: 600; }
.autocomplete,
.zone-combobox { position: relative; }
.autocomplete input,
.zone-combobox input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--color-border-soft);
  border-radius: 3px;
  background: var(--color-control);
}

.autocomplete input::placeholder,
.zone-combobox input::placeholder { color: var(--color-text-muted); }
.suggestions {
  position: absolute;
  z-index: 2000;
  top: calc(100% + 2px);
  right: 0;
  left: 0;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--color-border-soft);
  border-radius: 3px;
  background: var(--color-window);
  box-shadow: 0 12px 28px rgba(0, 0, 0, .28);
}

.suggestion {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-bottom: 1px solid var(--color-border-soft);
  background: transparent;
  cursor: pointer;
  line-height: 1.35;
  text-align: left;
}

.suggestion:last-child { border-bottom: 0; }
.suggestion:hover,
.suggestion.is-active { background: var(--color-selection); }
.suggestion-message { padding: 9px 10px; color: var(--color-text-secondary); font-size: 12px; }
.suggestion-message.is-error { color: var(--color-danger); }

.map-status {
  min-height: 18px;
  margin: 6px 0 0;
  color: var(--color-text-muted);
  font-size: 11px;
}

.map-status.is-error { color: var(--color-danger); }
.map-status.is-success { color: var(--color-success); }

.result-card {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--color-border-soft);
  border-radius: 5px;
  background: var(--color-window);
}

.result-card h3 { margin: 0 0 10px; font-size: 13px; font-weight: 650; }
.result-placeholder { margin: 0; color: var(--color-text-muted); font-size: 12px; }
.result-grid { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 7px 10px; margin: 0; }
.result-grid dt { color: var(--color-text-secondary); font-size: 12px; }
.result-grid dd { margin: 0; overflow-wrap: anywhere; font-size: 12px; font-weight: 650; }
.result-note { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--color-border-soft); color: var(--color-text-secondary); font-size: 11px; }
.result-note.is-warning { color: var(--color-warning); font-weight: 600; }

.data-note {
  margin: 16px 0 0;
  padding: 11px 0 0;
  border-top: 1px solid var(--color-border-soft);
  color: var(--color-text-muted);
  font-size: 11px;
}

.map-layer-options {
  display: grid;
  margin: 16px 0 0;
  padding: 0;
  border: 0;
  gap: 8px;
}

.map-layer-options legend {
  margin-bottom: 8px;
  padding: 0;
  color: var(--color-text-secondary);
  font-size: 12px;
  font-weight: 600;
}

.map-layer-options label {
  display: flex;
  gap: 8px;
  align-items: center;
  cursor: pointer;
  font-size: 12px;
}

.map-layer-options input { accent-color: var(--color-icon); }

.road-zone-label.leaflet-tooltip {
  padding: 1px 4px;
  border: 0;
  background: rgba(255, 255, 255, .72);
  box-shadow: none;
  color: #20252e;
  font: 700 12px/1.2 "Segoe UI", Arial, sans-serif;
  pointer-events: none;
}

.road-zone-label.leaflet-tooltip::before { display: none; }

.freeze-depth-label {
  width: auto !important;
  height: auto !important;
  border: 0;
  background: transparent;
}

.freeze-depth-label span {
  display: block;
  padding: 0 2px;
  color: #111;
  font: 700 12px/1.2 "Segoe UI", Arial, sans-serif;
  text-shadow: 0 0 3px rgba(255, 255, 255, .95), 0 0 6px rgba(255, 255, 255, .95);
  white-space: nowrap;
}

.map-canvas { min-width: 0; min-height: 0; background: #dfe5ea; }
.map-canvas .leaflet-control-layers,
.map-canvas .maplibregl-ctrl-group,
.map-canvas .maplibregl-ctrl-attrib { color: #20252e; }
.map-canvas .leaflet-interactive:focus,
.map-canvas .leaflet-marker-icon:focus { outline: none; }
.map-canvas .maplibregl-ctrl-bottom-right { right: 0; bottom: 0; }

.map-service-main {
  display: grid;
  width: min(1380px, calc(100% - 40px));
  min-height: 0;
  margin: 20px auto;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.map-section-heading { min-width: 0; }
.map-section-heading .section-accent-title { margin: 0; }
.map-service-main .map-workspace { width: 100%; margin: 0; }

.map-workspace--compact {
  grid-template-columns: 1fr;
  grid-template-rows: auto minmax(0, 1fr);
}

.map-toolbar {
  display: grid;
  overflow: visible;
  padding: 12px 16px;
  border-right: 0;
  border-bottom: 1px solid var(--color-border);
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
  gap: 16px;
  align-items: center;
}

.map-toolbar .map-status { margin-top: 4px; }
.map-toolbar-search { position: relative; min-width: 0; }
.map-toolbar-search > .map-status {
  position: absolute;
  z-index: 1900;
  top: 100%;
  right: 0;
  left: 0;
  min-height: 0;
  margin: 2px 0 0;
  padding: 7px 10px;
  border: 1px solid var(--color-border-soft);
  border-radius: 3px;
  background: var(--color-window);
  box-shadow: 0 8px 20px rgba(0, 0, 0, .22);
}
.map-toolbar-zone { min-width: 0; }
.map-toolbar-result { min-width: 0; padding: 0 4px; }
.map-toolbar-result .result-grid { grid-template-columns: auto minmax(280px, 2fr) auto minmax(160px, .8fr); gap: 5px 10px; align-items: baseline; }
.map-toolbar-error { grid-column: 1 / -1; }

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #dfe5ea;
}

.map-stage .map-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-coordinate-readout {
  position: absolute;
  z-index: 10;
  bottom: 10px;
  left: 10px;
  padding: 6px 9px;
  border: 1px solid rgba(32, 37, 46, .28);
  border-radius: 4px;
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 1px 5px rgba(0, 0, 0, .18);
  color: #20252e;
  font: 600 11px/1.25 Consolas, "Courier New", monospace;
  pointer-events: none;
}

@media (max-width: 1060px) and (min-width: 801px) {
  .map-toolbar { grid-template-columns: minmax(260px, .9fr) minmax(420px, 1.5fr); }
}

@media (max-width: 1320px) {
  .main-nav {
    position: fixed;
    z-index: 1100;
    top: var(--topbar-height);
    right: 0;
    left: 0;
    display: none;
    flex-direction: column;
    gap: 0;
    padding: 12px 15px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-footer);
  }

  .main-nav.is-open { display: flex; }
  .main-nav a { width: 100%; padding: 12px 10px; border-bottom: 1px solid var(--color-border); }
  .main-nav a:last-child { border-bottom: 0; }
  .main-nav a::after { display: none; }
  .menu-button { display: inline-grid; }
}

@media (max-width: 800px) {
  body { overflow: auto; }
  .map-service-shell { --topbar-height: 68px; height: auto; min-height: 100dvh; grid-template-rows: var(--topbar-height) auto; }
  .topbar-inner { width: min(100% - 28px, 1380px); }
  .topbar-inner { grid-template-columns: 1fr auto; }
  .brand-text { font-size: 1.05rem; }
  .map-workspace { width: 100%; margin: 0; border: 0; border-radius: 0; grid-template-columns: 1fr; grid-template-rows: auto 62vh; }
  .map-service-main { width: 100%; margin: 0; gap: 10px; }
  .map-section-heading { padding: 16px 14px 0; }
  .map-toolbar { grid-template-columns: 1fr; }
  .map-toolbar-result { grid-column: auto; }
  .map-toolbar-result .result-grid { grid-template-columns: 100px minmax(0, 1fr); }
  .map-sidebar { max-height: none; border-right: 0; border-bottom: 1px solid var(--color-border); }
  .map-stage,
  .map-canvas { min-height: 440px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
