:root {
  color-scheme: light;
  --navy: #10233f;
  --navy-2: #1a3458;
  --teal: #18a6a6;
  --purple: #8a5cf6;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #182132;
  --muted: #687386;
  --border: #dbe1e9;
  --danger: #b42318;
  --danger-bg: #fff0ee;
  --shadow: 0 12px 34px rgba(16, 35, 63, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
img { max-width: 100%; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 76px;
  padding: 12px max(18px, env(safe-area-inset-left));
  color: #fff;
  background: rgba(16, 35, 63, .97);
  border-bottom: 1px solid rgba(255,255,255,.12);
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand__mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--teal), #65d3c7);
  color: #fff;
  font-size: 23px;
  font-weight: 800;
}
.brand h1 { margin: 0; font-size: 18px; line-height: 1.15; }
.brand p { margin: 3px 0 0; color: #c9d5e5; font-size: 13px; }

.app-shell {
  width: min(1540px, calc(100% - 28px));
  margin: 18px auto 44px;
}

.control-panel,
.editor,
.visited-section,
.data-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.control-panel { padding: 16px; margin-bottom: 16px; }
.control-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) minmax(130px, .7fr) minmax(130px, .6fr) minmax(130px, .6fr);
  gap: 12px;
  align-items: end;
}

.field { display: block; min-width: 0; }
.field > span:first-child,
.photo-block__heading > span {
  display: block;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 700;
  color: #455167;
}

input[type="text"], input[type="search"], select, textarea {
  width: 100%;
  color: var(--text);
  background: #fff;
  border: 1px solid #cfd7e3;
  border-radius: 12px;
  outline: none;
}

input[type="text"], input[type="search"], select { min-height: 44px; padding: 9px 12px; }
textarea { padding: 12px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(138, 92, 246, .14); }

.metric {
  min-height: 65px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-soft);
}
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 6px; font-size: 18px; }

.deck-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-top: 14px;
  padding: 2px 0 4px;
  scrollbar-width: thin;
}
.deck-tab {
  flex: 0 0 auto;
  min-width: 44px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #fff;
  color: var(--navy);
  font-weight: 750;
}
.deck-tab:hover { border-color: var(--purple); }
.deck-tab.is-active { color: #fff; background: var(--navy); border-color: var(--navy); }
.deck-tab.has-zones::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 4px;
  border-radius: 50%;
  background: #46d4c5;
  vertical-align: 2px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 410px);
  gap: 16px;
  align-items: start;
}

.map-column {
  min-width: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.map-toolbar strong { display: block; }
.map-toolbar span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.toolbar-actions { display: flex; align-items: center; gap: 7px; }
.toolbar-actions output { min-width: 52px; text-align: center; color: var(--muted); font-size: 13px; }

.map-viewport {
  position: relative;
  min-height: 620px;
  max-height: 76vh;
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(#eef2f7 1px, transparent 1px),
    linear-gradient(90deg, #eef2f7 1px, transparent 1px),
    #fafbfd;
  background-size: 24px 24px;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y;
}

.map-stage {
  position: relative;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
}
.map-stage.is-selection-mode {
  cursor: crosshair;
  touch-action: none;
}
.selection-banner {
  position: absolute;
  z-index: 20;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 9px 13px;
  border: 1px solid color-mix(in srgb, var(--purple) 60%, #fff);
  border-radius: 999px;
  background: rgba(255,255,255,.96);
  color: var(--purple);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  box-shadow: 0 5px 18px rgba(16,35,63,.18);
  pointer-events: none;
}
.map-stage.is-selection-mode::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  border: 3px dashed color-mix(in srgb, var(--purple) 72%, #fff);
  border-radius: 8px;
  pointer-events: none;
}
.button--select.is-active {
  border-color: var(--purple);
  background: color-mix(in srgb, var(--purple) 13%, #fff);
  color: var(--purple);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--purple) 16%, transparent);
}
.map-stage > img {
  display: block;
  width: 100%;
  height: auto;
  filter: grayscale(1);
  border-radius: 8px;
  pointer-events: none;
}
.zone-layer, .draft-region { position: absolute; inset: 0; }
.zone-layer { pointer-events: none; }

.map-zone-reveal {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-repeat: no-repeat;
  background-position: 0 0;
  background-size: 100% 100%;
  pointer-events: none;
  filter: saturate(1.04) contrast(1.01);
}

.map-zone,
.draft-region {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 2px solid color-mix(in srgb, var(--zone-color, var(--purple)) 82%, #fff 18%);
  outline: 2px solid rgba(255,255,255,.94);
  background: color-mix(in srgb, var(--zone-color, var(--purple)) 12%, transparent);
  box-shadow: 0 3px 10px rgba(16,35,63,.20);
}
.map-zone {
  z-index: 2;
  display: grid;
  place-items: center;
  min-width: 26px;
  min-height: 26px;
  padding: 0;
  color: #fff;
  pointer-events: auto;
  cursor: pointer;
}
.map-zone:hover, .map-zone:focus-visible, .map-zone.is-selected {
  z-index: 5;
  outline-width: 4px;
  box-shadow: 0 0 0 5px rgba(255,255,255,.8), 0 5px 16px rgba(16,35,63,.35);
}
.map-zone[data-shape="circle"], .draft-region[data-shape="circle"] { border-radius: 999px; }
.map-zone[data-shape="rectangle"], .draft-region[data-shape="rectangle"] { border-radius: 9px; }
.map-zone__number {
  display: grid;
  place-items: center;
  min-width: 23px;
  height: 23px;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(16,35,63,.82);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  box-shadow: 0 2px 7px rgba(0,0,0,.22);
  pointer-events: none;
}
.draft-region {
  pointer-events: none;
  z-index: 18;
  border-width: 3px;
  border-style: dashed;
  background: color-mix(in srgb, var(--zone-color, var(--purple)) 26%, transparent);
  box-shadow:
    0 0 0 3px rgba(255,255,255,.92),
    0 5px 18px rgba(16,35,63,.28);
}
.map-zone {
  border-width: 3px;
  background: color-mix(in srgb, var(--zone-color, var(--purple)) 20%, transparent);
}

.map-help {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}
.legend-chip { display: inline-flex; align-items: center; gap: 6px; }
.legend-chip i { width: 14px; height: 14px; border-radius: 4px; border: 1px solid #9ba6b5; }
.legend-chip__gray { background: #d9dde3; }
.legend-chip__color { background: linear-gradient(135deg, #d9eef7 0 45%, #2bb8b1 45% 62%, #f1d29b 62%); }
.map-help__text { margin-left: auto; }

.editor {
  position: sticky;
  top: 94px;
  overflow: hidden;
}
.editor__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}
.editor h2, .section-heading h2, .data-panel h2 { margin: 4px 0 0; font-size: 20px; }
.eyebrow { color: var(--teal); font-size: 11px; font-weight: 850; letter-spacing: .09em; text-transform: uppercase; }

.empty-state {
  padding: 34px 24px 40px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  border-radius: 18px;
  transition: background .18s ease, box-shadow .18s ease, transform .18s ease;
}
.empty-state:hover,
.empty-state:focus-visible {
  background: rgba(255,255,255,.46);
  box-shadow: inset 0 0 0 2px rgba(67,196,194,.16);
  transform: translateY(-1px);
  outline: none;
}
.empty-state__icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin: 0 auto 13px;
  border-radius: 50%;
  background: #edf7f7;
  color: var(--teal);
  font-size: 28px;
}
.empty-state p { margin: 0; line-height: 1.55; }

.editor-form { display: grid; gap: 15px; padding: 18px; }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.color-control {
  display: flex !important;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: 0 !important;
  padding: 6px 10px;
  border: 1px solid #cfd7e3;
  border-radius: 12px;
}
.color-control input { width: 48px; height: 30px; padding: 0; border: 0; background: transparent; }
.color-control output { color: var(--muted); font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
input[type="range"] { width: 100%; accent-color: var(--purple); }

.photo-block { min-width: 0; }
.photo-block__heading { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.photo-block__heading small { color: var(--muted); font-size: 11px; text-align: right; }
.photo-picker {
  width: 100%;
  min-height: 68px;
  padding: 12px 14px;
  color: var(--navy);
  background: #f7fbfb;
  border: 1.5px dashed #77bebe;
  border-radius: 13px;
  text-align: left;
}
.photo-picker strong, .photo-picker span { display: block; }
.photo-picker span { margin-top: 4px; color: var(--muted); font-size: 12px; }
.photo-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 8px; margin-top: 10px; }
.photo-item { position: relative; overflow: hidden; aspect-ratio: 1; border: 1px solid var(--border); border-radius: 10px; background: #eef1f5; }
.photo-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-item__file {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 6px;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
  word-break: break-all;
}
.photo-item button {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  padding: 0;
  color: #fff;
  background: rgba(16,35,63,.85);
  border: 0;
  border-radius: 50%;
}
.helper-text { min-height: 16px; margin: 7px 0 0; color: var(--muted); font-size: 12px; }

.editor-actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.button {
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-weight: 750;
}
.button--small { min-height: 36px; padding: 7px 10px; font-size: 12px; }
.button--primary { color: #fff; background: var(--navy); }
.button--primary:hover { background: var(--navy-2); }
.button--ghost { color: var(--navy); background: #fff; border-color: #cdd6e3; }
.topbar .button--ghost { color: #fff; background: transparent; border-color: rgba(255,255,255,.35); }
.button--danger { color: var(--danger); background: var(--danger-bg); border-color: #f4c7c2; }
.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--navy);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 20px;
}
.status { min-height: 18px; margin: 0; color: var(--muted); font-size: 12px; }
.status.is-error { color: var(--danger); }
.status.is-success { color: #137a55; }

.visited-section { margin-top: 16px; padding: 18px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.search-field { width: min(310px, 100%); }
.visited-list { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; }
.zone-card { min-width: 0; }
.zone-card__open {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 88px;
  padding: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 13px;
  text-align: left;
}
.zone-card__open:hover { border-color: #aebacc; background: #fff; }
.zone-card__swatch { flex: 0 0 auto; width: 11px; align-self: stretch; border-radius: 8px; background: var(--swatch); }
.zone-card__body { min-width: 0; display: grid; gap: 4px; }
.zone-card__title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zone-card__note { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.zone-card__meta { color: #7c8798; font-size: 11px; }
.zone-card__arrow { margin-left: auto; color: #94a0b0; font-size: 24px; }
.empty-list { margin: 24px 0 12px; color: var(--muted); text-align: center; }

.data-panel {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 20px;
  align-items: center;
  margin-top: 16px;
  padding: 18px;
}
.data-panel p { max-width: 800px; margin: 8px 0 0; color: var(--muted); line-height: 1.5; }
.data-panel__actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.data-panel > .status { grid-column: 1 / -1; }

.footer {
  padding: 0 18px calc(24px + env(safe-area-inset-bottom));
  color: #7b8696;
  font-size: 11px;
  text-align: center;
}
.footer p { max-width: 1000px; margin: 0 auto; }

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

@media (max-width: 1080px) {
  .workspace { grid-template-columns: minmax(0,1fr) 350px; }
  .visited-list { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 860px) {
  .control-grid { grid-template-columns: 1fr 1fr; }
  .workspace { grid-template-columns: 1fr; }
  .editor { position: static; }
  .map-viewport { min-height: 540px; max-height: 72vh; }
  .map-help__text { width: 100%; margin-left: 0; }
  .data-panel { grid-template-columns: 1fr; }
  .data-panel__actions { justify-content: flex-start; }
}

@media (max-width: 580px) {
  .topbar { min-height: 66px; }
  .brand__mark { width: 37px; height: 37px; }
  .brand h1 { font-size: 16px; }
  .brand p { display: none; }
  .app-shell { width: min(100% - 16px, 1540px); margin-top: 8px; }
  .control-panel { padding: 12px; }
  .control-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .control-grid .field:first-child { grid-column: 1 / -1; }
  .metric { min-height: 60px; }
  .map-toolbar { align-items: flex-start; padding: 12px; }
  .toolbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .toolbar-actions .button { display: none; }
  .map-viewport { min-height: 500px; padding: 10px; }
  .map-help { padding: 10px 12px; }
  .editor__header, .editor-form, .visited-section, .data-panel { padding: 14px; }
  .two-columns { grid-template-columns: 1fr; }
  .editor-actions { grid-template-columns: 1fr; }
  .photo-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .section-heading { align-items: stretch; flex-direction: column; }
  .search-field { width: 100%; }
  .visited-list { grid-template-columns: 1fr; }
  .data-panel__actions { display: grid; grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}

  
/* Чистые интерактивные зоны */
.map-zone {
  z-index: 2;
  display: block;
  min-width: 18px;
  min-height: 18px;
  padding: 0;
  border-width: 1px;
  border-color: color-mix(in srgb, var(--zone-color, var(--purple)) 28%, transparent);
  outline: 0;
  background: transparent;
  color: transparent;
  pointer-events: auto;
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, background .18s ease, box-shadow .18s ease, opacity .18s ease;
}

.map-zone:hover,
.map-zone:focus-visible {
  z-index: 25;
  border-width: 2px;
  border-color: color-mix(in srgb, var(--zone-color, var(--purple)) 92%, #fff 8%);
  outline: 2px solid rgba(255,255,255,.82);
  background: color-mix(in srgb, var(--zone-color, var(--purple)) 14%, transparent);
  transform: translate(-50%, -50%) scale(1.018);
  box-shadow:
    0 0 0 3px rgba(255,255,255,.72),
    0 0 20px color-mix(in srgb, var(--zone-color, var(--purple)) 66%, transparent);
  animation: zone-soft-glow 1.15s ease-in-out infinite alternate;
}

.map-zone.is-selected {
  z-index: 24;
  border-width: 2px;
  border-color: color-mix(in srgb, var(--zone-color, var(--purple)) 88%, #fff 12%);
  outline: 2px solid rgba(255,255,255,.74);
  background: color-mix(in srgb, var(--zone-color, var(--purple)) 10%, transparent);
  box-shadow:
    0 0 0 3px rgba(255,255,255,.62),
    0 0 15px color-mix(in srgb, var(--zone-color, var(--purple)) 50%, transparent);
}

.map-zone.is-search-match {
  z-index: 26;
  border-width: 3px;
  border-color: #ffbe2e;
  background: rgba(255,190,46,.20);
  box-shadow: 0 0 0 4px rgba(255,255,255,.78), 0 0 25px rgba(255,190,46,.9);
  animation: search-pulse 1s ease-in-out infinite alternate;
}

.map-zone.is-search-muted { opacity: .18; }

@keyframes zone-soft-glow {
  from { box-shadow: 0 0 0 3px rgba(255,255,255,.72), 0 0 11px color-mix(in srgb, var(--zone-color, var(--purple)) 46%, transparent); }
  to { box-shadow: 0 0 0 4px rgba(255,255,255,.82), 0 0 23px color-mix(in srgb, var(--zone-color, var(--purple)) 75%, transparent); }
}

@keyframes search-pulse {
  from { box-shadow: 0 0 0 4px rgba(255,255,255,.76), 0 0 14px rgba(255,190,46,.64); }
  to { box-shadow: 0 0 0 6px rgba(255,255,255,.88), 0 0 30px rgba(255,190,46,1); }
}

.map-zone__number { display: none !important; }

.map-zone[data-shape="polygon"],
.draft-region[data-shape="polygon"] {
  border-radius: 0;
}

.polygon-draft {
  position: absolute;
  inset: 0;
  z-index: 19;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.polygon-draft polygon,
.polygon-draft polyline {
  fill: color-mix(in srgb, var(--polygon-color, var(--purple)) 24%, transparent);
  stroke: var(--polygon-color, var(--purple));
  stroke-width: .65;
  stroke-dasharray: 1.7 1.1;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 0 3px rgba(255,255,255,.95));
}

.polygon-draft circle {
  fill: #fff;
  stroke: var(--polygon-color, var(--purple));
  stroke-width: .55;
  vector-effect: non-scaling-stroke;
}

.map-stage.is-polygon-mode {
  cursor: crosshair;
  touch-action: none;
}

.map-stage.is-polygon-mode .map-zone { pointer-events: none; }

.deck-tab.search-hit {
  border-color: #ffbe2e;
  background: rgba(255,190,46,.18);
  box-shadow: inset 0 0 0 2px rgba(255,190,46,.48);
}

.deck-tab.search-hit::after {
  content: attr(data-search-count);
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  margin-left: 4px;
  padding: 0 4px;
  border-radius: 999px;
  background: #ffbe2e;
  color: #202020;
  font-size: 10px;
  font-weight: 850;
}

@media (prefers-reduced-motion: reduce) {
  .map-zone:hover,
  .map-zone:focus-visible,
  .map-zone.is-search-match {
    animation: none;
  }
}


.draw-shape-control select {
  min-height: 36px;
  max-width: 170px;
  padding: 7px 30px 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
}

@media (max-width: 760px) {
  .toolbar-actions .button--select,
  .toolbar-actions #undoPolygonPoint,
  .toolbar-actions #finishPolygon {
    display: inline-flex;
  }

  .draw-shape-control {
    display: block;
    width: 100%;
  }

  .draw-shape-control select {
    width: 100%;
    max-width: none;
  }
}


/* =========================================================
   ROYAL FESTIVE UI + MAP-FIRST RESPONSIVE LAYOUT
   ========================================================= */

:root {
  --royal-blue: #0067b9;
  --royal-deep: #061d49;
  --royal-ocean: #00a9ce;
  --royal-aqua: #16c7bd;
  --royal-sun: #ffd23f;
  --royal-coral: #ff6b5d;
  --royal-pink: #e94f9d;
  --royal-violet: #7357e8;
  --bg: #eef6fc;
  --surface-soft: #f4f9fd;
  --border: #cfe1ef;
  --shadow: 0 18px 44px rgba(4, 44, 91, .12);
  --radius: 22px;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 5% 3%, rgba(0,169,206,.15), transparent 26rem),
    radial-gradient(circle at 96% 12%, rgba(255,210,63,.18), transparent 22rem),
    linear-gradient(180deg, #f7fbff 0%, #eef6fc 48%, #f8fbfd 100%);
}

.topbar {
  min-height: 68px;
  overflow: hidden;
  background:
    linear-gradient(105deg, #041b45 0%, #005baa 48%, #00a4c7 100%);
  border-bottom: 0;
  box-shadow: 0 8px 24px rgba(4, 32, 74, .18);
}

.topbar::before,
.topbar::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  pointer-events: none;
}

.topbar::before {
  width: 230px;
  height: 230px;
  right: 7%;
  top: -170px;
  border: 18px solid rgba(255,210,63,.28);
  transform: rotate(-18deg);
}

.topbar::after {
  width: 86px;
  height: 86px;
  right: 2%;
  bottom: -52px;
  background: rgba(255,107,93,.38);
  box-shadow:
    -110px -28px 0 -28px rgba(255,210,63,.72),
    -210px 20px 0 -18px rgba(233,79,157,.48);
}

.brand { position: relative; z-index: 2; }

.brand__mark {
  background:
    linear-gradient(145deg, var(--royal-sun), var(--royal-coral) 54%, var(--royal-pink));
  color: var(--royal-deep);
  box-shadow:
    0 7px 18px rgba(0,0,0,.2),
    inset 0 1px 0 rgba(255,255,255,.72);
}

.brand h1 { letter-spacing: -.02em; }
.brand p { color: rgba(255,255,255,.8); }

.app-shell {
  width: min(1720px, calc(100% - 24px));
  margin: 12px auto 38px;
}

.control-panel,
.map-column,
.editor,
.visited-section,
.data-panel {
  border-color: rgba(89, 152, 196, .25);
  box-shadow: var(--shadow);
}

.control-panel {
  padding: 13px 15px 11px;
  background:
    linear-gradient(110deg, rgba(255,255,255,.98), rgba(241,249,255,.98));
}

.metric {
  position: relative;
  overflow: hidden;
  min-height: 58px;
  background: linear-gradient(145deg, #f4fbff, #fffaf0);
}

.metric::after {
  content: "";
  position: absolute;
  width: 38px;
  height: 38px;
  right: -13px;
  bottom: -14px;
  border-radius: 50%;
  background: var(--royal-sun);
  opacity: .38;
}

.deck-tab {
  border-color: #c4dceb;
  background: #fff;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.deck-tab:hover {
  border-color: var(--royal-ocean);
  transform: translateY(-1px);
}

.deck-tab.is-active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--royal-blue), var(--royal-ocean));
  box-shadow: 0 7px 16px rgba(0,103,185,.23);
}

.deck-tab.has-zones::after { background: var(--royal-sun); }

.workspace {
  position: relative;
  grid-template-columns: minmax(0, 1fr) minmax(330px, 390px);
  gap: 14px;
}

.map-column {
  border-radius: 24px;
  background: #fff;
}

.map-toolbar {
  position: sticky;
  top: 68px;
  z-index: 32;
  min-height: 68px;
  padding: 11px 14px;
  background:
    linear-gradient(100deg, rgba(255,255,255,.98), rgba(239,249,255,.98));
  backdrop-filter: blur(14px);
}

.map-toolbar strong {
  color: var(--royal-deep);
  font-size: 17px;
}

.toolbar-actions {
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.draw-shape-control select,
.toolbar-actions select {
  border-color: #bdd8e8;
  background: #fff;
}

.button,
.icon-button {
  min-height: 42px;
  border-radius: 13px;
}

.button--primary {
  color: var(--royal-deep);
  background: linear-gradient(135deg, var(--royal-sun), #ffb93f);
  border-color: rgba(158,102,0,.08);
  box-shadow: 0 7px 18px rgba(255,185,63,.25);
}

.button--primary:hover {
  color: var(--royal-deep);
  background: linear-gradient(135deg, #ffdc60, var(--royal-sun));
}

.button--select {
  color: #fff;
  background: linear-gradient(135deg, var(--royal-blue), var(--royal-ocean));
  border-color: transparent;
}

.button--select:hover {
  color: #fff;
  background: linear-gradient(135deg, #00579c, #0094b8);
}

.button--select.is-active {
  color: var(--royal-deep);
  background: linear-gradient(135deg, var(--royal-sun), #ffb93f);
  border-color: transparent;
  box-shadow: 0 0 0 4px rgba(255,210,63,.22);
}

.icon-button {
  color: var(--royal-blue);
  border-color: #c7ddea;
  background: #fff;
}

.map-viewport {
  height: calc(100dvh - 248px);
  min-height: 610px;
  max-height: none;
  padding: 12px;
  background:
    linear-gradient(rgba(16,103,171,.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(16,103,171,.055) 1px, transparent 1px),
    linear-gradient(145deg, #fbfdff, #f2f8fc);
  background-size: 24px 24px;
  scrollbar-color: #8bbbd5 transparent;
}

.map-help {
  min-height: 48px;
  background: linear-gradient(90deg, #f9fcff, #fffdf5);
}

.legend-chip i { border-color: #8eaec1; }

.editor {
  top: 82px;
  max-height: calc(100dvh - 96px);
  overflow-y: auto;
  scrollbar-width: thin;
  border-radius: 24px;
  background:
    linear-gradient(180deg, #fff 0%, #fbfdff 100%);
}

.editor__header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(14px);
}

.eyebrow { color: var(--royal-ocean); }

.empty-state__icon {
  color: var(--royal-deep);
  background:
    linear-gradient(145deg, var(--royal-sun), #ffb84a);
  box-shadow: 0 9px 20px rgba(255,190,55,.28);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--royal-ocean);
  box-shadow: 0 0 0 4px rgba(0,169,206,.13);
}

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

.photo-picker {
  color: var(--royal-deep);
  border-color: var(--royal-aqua);
  background: linear-gradient(145deg, #efffff, #f5fbff);
}

.visited-section {
  background:
    linear-gradient(145deg, rgba(255,255,255,.99), rgba(247,252,255,.99));
}

.zone-card__open:hover {
  border-color: var(--royal-ocean);
  box-shadow: 0 8px 20px rgba(0,103,185,.08);
}

@media (min-width: 1181px) {
  .editor {
    position: sticky;
    transform: none !important;
  }
}

/* Laptop: map takes the full width; editor becomes a right drawer. */
@media (max-width: 1180px) and (min-width: 761px) {
  .app-shell { width: min(100% - 18px, 1500px); }

  .workspace { display: block; }

  .map-viewport {
    height: calc(100dvh - 230px);
    min-height: 590px;
  }

  .editor {
    position: fixed;
    z-index: 80;
    top: 82px;
    right: 10px;
    width: min(390px, calc(100vw - 20px));
    max-height: calc(100dvh - 94px);
    transform: translateX(calc(100% + 28px));
    transition: transform .24s ease;
    box-shadow: 0 24px 70px rgba(4,37,79,.28);
  }

  .editor.is-open { transform: translateX(0); }
}

/* Mobile: nearly full-screen map + bottom-sheet editor. */
@media (max-width: 760px) {
  body { padding-bottom: 72px; }

  .topbar {
    min-height: 58px;
    padding-block: 8px;
  }

  .brand__mark {
    width: 39px;
    height: 39px;
    border-radius: 12px;
  }

  .brand h1 { font-size: 15px; }

  .app-shell {
    width: 100%;
    margin: 0;
  }

  .control-panel {
    margin: 0;
    padding: 9px 9px 7px;
    border-inline: 0;
    border-radius: 0;
    box-shadow: 0 7px 20px rgba(4,44,91,.08);
  }

  .control-grid {
    grid-template-columns: minmax(0, 1.35fr) minmax(92px, .65fr);
    gap: 8px;
  }

  .control-grid .field:first-child { grid-column: auto; }

  .control-grid .metric { display: none; }

  .field > span:first-child { margin-bottom: 4px; font-size: 11px; }

  input[type="text"],
  input[type="search"],
  select {
    min-height: 42px;
  }

  .deck-tabs {
    margin-top: 8px;
    padding-bottom: 2px;
  }

  .deck-tab {
    min-width: 42px;
    height: 36px;
  }

  .workspace { display: block; }

  .map-column {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .map-toolbar {
    top: 58px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    min-height: 58px;
    padding: 8px 9px;
    border-top: 1px solid rgba(95,151,188,.18);
  }

  .map-toolbar > div:first-child span { display: none; }

  .toolbar-actions {
    display: grid;
    grid-template-columns: minmax(115px, 1fr) 42px 42px;
    gap: 6px;
    width: min(100%, 290px);
  }

  .draw-shape-control {
    grid-column: 1 / 2;
    width: auto;
  }

  .draw-shape-control select {
    min-height: 42px;
    width: 100%;
    max-width: none;
  }

  #drawArea,
  #fitMap,
  #zoomValue {
    display: none !important;
  }

  #undoPolygonPoint,
  #finishPolygon {
    grid-column: 1 / -1;
    width: 100%;
  }

  #zoomOut { grid-column: 2; grid-row: 1; }
  #zoomIn { grid-column: 3; grid-row: 1; }

  .icon-button { width: 42px; height: 42px; }

  .map-viewport {
    height: calc(100dvh - 206px);
    min-height: 470px;
    max-height: none;
    padding: 5px;
    overscroll-behavior: contain;
  }

  .map-help {
    display: none;
  }

  .selection-banner {
    position: fixed;
    top: auto;
    left: 50%;
    bottom: calc(84px + env(safe-area-inset-bottom));
    z-index: 120;
    max-width: calc(100vw - 24px);
    font-size: 11px;
  }

  .editor {
    position: fixed;
    z-index: 100;
    left: 7px;
    right: 7px;
    bottom: calc(6px + env(safe-area-inset-bottom));
    top: auto;
    width: auto;
    max-height: min(78dvh, 690px);
    overflow: hidden;
    border-radius: 24px 24px 18px 18px;
    transform: translateY(calc(100% - 68px));
    transition: transform .26s cubic-bezier(.2,.8,.2,1);
    box-shadow: 0 -20px 55px rgba(4,37,79,.28);
  }

  .editor::before {
    content: "";
    position: absolute;
    z-index: 8;
    left: 50%;
    top: 7px;
    width: 42px;
    height: 5px;
    border-radius: 999px;
    background: #c6d5df;
    transform: translateX(-50%);
  }

  .editor.is-open { transform: translateY(0); }

  .editor__header {
    min-height: 68px;
    padding: 20px 14px 10px;
    align-items: center;
  }

  .editor h2 { font-size: 17px; }

  .editor-form {
    max-height: calc(min(78dvh, 690px) - 68px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 13px 13px calc(22px + env(safe-area-inset-bottom));
  }

  .empty-state {
    max-height: calc(min(78dvh, 690px) - 68px);
    overflow-y: auto;
    padding: 25px 18px 34px;
  }

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

  .photo-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  .editor-actions {
    position: sticky;
    bottom: 0;
    z-index: 4;
    padding-top: 8px;
    background: linear-gradient(180deg, rgba(255,255,255,0), #fff 22%);
  }

  .visited-section,
  .data-panel {
    margin: 10px 8px 0;
    border-radius: 18px;
  }

  .visited-section { padding: 13px; }
  .data-panel { padding: 13px; }
}

@media (max-width: 420px) {
  .control-grid {
    grid-template-columns: minmax(0, 1fr) 88px;
  }

  .toolbar-actions {
    width: min(100%, 252px);
    grid-template-columns: minmax(105px, 1fr) 40px 40px;
  }

  .map-toolbar strong { font-size: 15px; }

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

  .photo-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .editor,
  .deck-tab,
  .button,
  .map-zone {
    transition: none !important;
  }
}
