:root {
  --bg: #f2efe8;
  --bg-deep: #eee8dc;
  --panel: rgba(255, 252, 246, 0.94);
  --panel-strong: rgba(255, 252, 246, 0.98);
  --panel-border: rgba(31, 41, 55, 0.12);
  --ink: #18212f;
  --muted: #5a6474;
  --accent: #c06a2f;
  --accent-2: #204f6e;
  --shadow: 0 14px 40px rgba(24, 33, 47, 0.12);
  --radius: 18px;
  --transition: 180ms ease;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(circle at 12% 12%, rgba(192, 106, 47, 0.1), transparent 38%),
    radial-gradient(circle at 86% 10%, rgba(32, 79, 110, 0.12), transparent 44%),
    linear-gradient(180deg, #f5f1e9 0%, var(--bg-deep) 100%);
  color: var(--ink);
  font-family: "Avenir Next", "IBM Plex Sans", "Segoe UI", sans-serif;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

code {
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: rgba(24, 33, 47, 0.05);
  border-radius: 7px;
  padding: 2px 5px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(340px, 420px) 1fr;
  gap: 16px;
  height: 100dvh;
  padding: 16px;
}

.sidebar,
.map-shell {
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 26px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  overflow: hidden;
  min-height: 0;
}

.sidebar-header {
  position: sticky;
  top: 0;
  z-index: 7;
  padding: 22px 22px 18px;
  border-bottom: 1px solid rgba(24, 33, 47, 0.08);
  background:
    linear-gradient(180deg, rgba(255, 252, 246, 0.98), rgba(255, 252, 246, 0.92)),
    radial-gradient(circle at 16% 12%, rgba(192, 106, 47, 0.08), transparent 34%);
  backdrop-filter: blur(12px);
}

.brand-mark {
  display: block;
  width: auto;
  height: 18px;
  margin-bottom: 12px;
  opacity: 0.96;
}

.eyebrow,
.panel-kicker,
.detail-label {
  display: block;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
}

h1,
h2 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
}

h1 {
  font-size: clamp(2rem, 3vw, 2.6rem);
  line-height: 1;
}

h2 {
  font-size: 1.35rem;
  line-height: 1.05;
}

.subhead,
.support-copy {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.95rem;
}

.sidebar-body {
  display: grid;
  gap: 14px;
  padding: 18px;
  overflow: auto;
  align-content: start;
  min-height: 0;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.sidebar-body::-webkit-scrollbar {
  width: 10px;
}

.sidebar-body::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-body::-webkit-scrollbar-thumb {
  background: rgba(24, 33, 47, 0.14);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.panel {
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(24, 33, 47, 0.08);
  border-radius: 18px;
  padding: 16px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 8px 20px rgba(24, 33, 47, 0.04);
}

.panel-search {
  background: rgba(255, 255, 255, 0.62);
}

.panel-browse {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.74), rgba(255, 255, 255, 0.58)),
    radial-gradient(circle at 12% 12%, rgba(32, 79, 110, 0.05), transparent 40%);
}

.panel-browse .panel-title-row {
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
}

.panel-browse .view-toggle {
  width: 100%;
}

.panel-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.search-form {
  margin-top: 14px;
}

.search-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

.search-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

input,
select {
  width: 100%;
  border: 1px solid rgba(24, 33, 47, 0.14);
  border-radius: 14px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
select:focus {
  outline: none;
  border-color: rgba(32, 79, 110, 0.55);
  box-shadow: 0 0 0 3px rgba(32, 79, 110, 0.12);
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, rgba(24, 33, 47, 0.55) 50%),
    linear-gradient(135deg, rgba(24, 33, 47, 0.55) 50%, transparent 50%);
  background-position:
    calc(100% - 22px) calc(50% - 3px),
    calc(100% - 16px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 42px;
}

button {
  border: 1px solid rgba(24, 33, 47, 0.14);
  border-radius: 999px;
  padding: 11px 14px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  cursor: pointer;
  transition:
    transform var(--transition),
    box-shadow var(--transition),
    background var(--transition),
    border-color var(--transition);
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(24, 33, 47, 0.08);
}

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

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.primary-button {
  background: linear-gradient(180deg, #265f83, #204f6e);
  color: white;
  border-color: rgba(32, 79, 110, 0.7);
  font-weight: 700;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.82);
  font-weight: 700;
}

.status-pill,
.territory-pill {
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.status-pill {
  background: rgba(24, 33, 47, 0.08);
  color: var(--muted);
}

.status-idle {
  background: rgba(24, 33, 47, 0.08);
  color: var(--muted);
}

.status-found {
  background: rgba(32, 82, 58, 0.12);
  color: #20523a;
}

.status-invalid,
.status-not-found {
  background: rgba(141, 31, 31, 0.1);
  color: #8d1f1f;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  font-size: 0.82rem;
  font-weight: 700;
}

.filter-chip.active {
  border-color: rgba(32, 79, 110, 0.35);
  background: rgba(32, 79, 110, 0.08);
}

.chip-swatch {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  border: 1px solid rgba(24, 33, 47, 0.16);
  flex: 0 0 auto;
}

.chip-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  border-radius: 999px;
  padding: 0 7px;
  background: rgba(24, 33, 47, 0.06);
  font-size: 0.75rem;
}

.territory-chip-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.territory-chip-row .filter-chip {
  width: 100%;
  min-height: 52px;
  justify-content: space-between;
  padding: 12px 14px;
  border-color: rgba(32, 79, 110, 0.25);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.subterritory-control {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.browse-select {
  font-weight: 700;
}

.browse-hint {
  margin-top: 0;
  font-size: 0.9rem;
}

.view-toggle {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  background: rgba(24, 33, 47, 0.05);
  border-radius: 999px;
  padding: 3px;
}

.view-toggle button {
  border: none;
  background: transparent;
  box-shadow: none;
  padding: 8px 11px;
  font-size: 0.78rem;
  font-weight: 800;
}

.view-toggle button.active {
  background: white;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

#visibleSummary {
  margin-top: 14px;
  line-height: 1.5;
}

.result-card {
  display: grid;
  gap: 14px;
}

.result-empty {
  min-height: 150px;
  align-content: center;
}

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

.result-grid strong {
  display: block;
  margin-top: 5px;
  font-size: 1rem;
}

.territory-pill {
  color: white;
  max-width: max-content;
}

.map-shell {
  position: relative;
  border-radius: 26px;
  overflow: hidden;
  border: 1px solid rgba(24, 33, 47, 0.1);
  box-shadow: var(--shadow);
  background:
    radial-gradient(circle at 25% 15%, rgba(32, 79, 110, 0.12), transparent 35%),
    radial-gradient(circle at 80% 80%, rgba(192, 106, 47, 0.14), transparent 45%),
    #e9edf1;
  height: 100%;
  min-height: 0;
}

.map-canvas {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.leaflet-bottom.leaflet-right {
  margin-bottom: 16px;
  margin-right: 16px;
}

.leaflet-control-zoom {
  border: 1px solid rgba(24, 33, 47, 0.12) !important;
  border-radius: 14px !important;
  overflow: hidden;
  box-shadow: 0 10px 24px rgba(24, 33, 47, 0.14);
}

.leaflet-control-zoom a {
  width: 38px !important;
  height: 38px !important;
  line-height: 38px !important;
  color: var(--ink) !important;
  background: rgba(255, 255, 255, 0.94) !important;
}

.leaflet-control-attribution {
  font-size: 10px;
}

.leaflet-interactive {
  cursor: pointer;
}

.territory-tooltip {
  background: rgba(24, 33, 47, 0.88);
  border: none;
  color: white;
  border-radius: 10px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  padding: 6px 8px;
  font-size: 0.74rem;
  font-weight: 700;
}

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

  .app-shell {
    grid-template-columns: 1fr;
    padding: 12px;
    height: auto;
    min-height: 100dvh;
  }

  .sidebar {
    border-radius: 22px;
  }

  .sidebar-body {
    padding: 14px;
  }

  .map-shell {
    min-height: 72vh;
    overflow: visible;
    height: auto;
  }

  .map-canvas {
    min-height: 72vh;
    height: 72vh;
  }

  .sidebar-header {
    padding: 18px 18px 16px;
  }

  .brand-mark {
    height: 16px;
    margin-bottom: 10px;
  }
}

@media (max-width: 640px) {
  .sidebar-body {
    gap: 12px;
  }

  .search-input-row {
    grid-template-columns: 1fr;
  }

  .panel-actions button,
  .search-input-row button,
  .filter-chip {
    width: 100%;
    justify-content: center;
  }

  .territory-chip-row {
    grid-template-columns: 1fr;
  }

  .territory-chip-row .filter-chip {
    justify-content: space-between;
  }

  .view-toggle {
    width: 100%;
  }

  .panel-title-row {
    flex-direction: column;
    align-items: stretch;
  }

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

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