:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #162033;
  --muted: #64748b;
  --line: #dce3ec;
  --line-soft: #edf1f6;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eaf1ff;
  --visited: #2563eb;
  --visited-2: #14b8a6;
  --todo: #eef2f7;
  --green: #059669;
  --red: #dc2626;
  --shadow: 0 18px 50px rgba(15, 23, 42, .08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body,
#map {
  width: 100%;
  height: 100%;
}

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

button,
input {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  width: 100%;
  height: 100vh;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  background: linear-gradient(180deg, #f7f9fc 0%, #eef3f9 100%);
}

.side-panel,
.map-panel {
  min-width: 0;
  min-height: 0;
}

.side-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: 16px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, .92);
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #111827;
  color: #fff;
  font-weight: 800;
}

.brand-title {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
}

.brand-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.stats-panel {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.progress-ring {
  position: relative;
  width: 112px;
  height: 112px;
}

.progress-ring svg {
  width: 112px;
  height: 112px;
  transform: rotate(-90deg);
}

.ring-track,
.ring-value {
  fill: none;
  stroke-width: 10;
}

.ring-track {
  stroke: #e7edf5;
}

.ring-value {
  stroke: var(--visited);
  stroke-linecap: round;
  stroke-dasharray: 307.88;
  stroke-dashoffset: 307.88;
  transition: stroke-dashoffset .35s ease;
}

.progress-ring > div {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
}

.progress-ring strong {
  font-size: 30px;
  line-height: 1;
}

.progress-ring span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.stat-grid {
  display: grid;
  gap: 10px;
}

.stat-grid div {
  min-height: 48px;
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.stat-grid span {
  color: var(--muted);
  font-size: 12px;
}

.stat-grid strong {
  font-size: 20px;
}

.controls {
  display: grid;
  gap: 10px;
}

.search-box input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
}

.search-box input:focus {
  border-color: rgba(37, 99, 235, .55);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}

.segments {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.segments button {
  height: 32px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segments button.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 750;
}

.province-section {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.section-head {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
}

.section-head strong {
  color: var(--text);
}

.province-list {
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.province-button {
  width: 100%;
  min-height: 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  padding: 0 9px 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.province-button:hover {
  background: var(--surface-soft);
}

.province-button.active {
  border-color: rgba(37, 99, 235, .18);
  background: linear-gradient(90deg, rgba(37, 99, 235, .12), rgba(20, 184, 166, .08));
}

.province-button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.province-button i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #cbd5e1;
}

.province-button.active i {
  background: var(--visited);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
}

.empty-list {
  height: 160px;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
}

.side-actions,
.map-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.side-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: #111827;
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}

.button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.button.ghost {
  border-color: rgba(220, 38, 38, .18);
  background: #fff;
  color: var(--red);
}

.map-panel {
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
}

.map-topbar {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .78);
  backdrop-filter: blur(16px);
}

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 850;
}

.map-topbar h1 {
  margin: 2px 0 0;
  font-size: 22px;
  line-height: 1.15;
}

.sync-state {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.sync-state i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.map-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 22% 18%, rgba(37, 99, 235, .09), transparent 28%),
    radial-gradient(circle at 82% 78%, rgba(20, 184, 166, .1), transparent 32%),
    linear-gradient(180deg, #f8fbff 0%, #eef3f8 100%);
}

.map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.label-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}

.map-label {
  position: absolute;
  min-height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  border: 1px solid rgba(148, 163, 184, .32);
  border-radius: 5px;
  background: rgba(255, 255, 255, .82);
  box-shadow: 0 8px 22px rgba(15, 23, 42, .08);
  color: #1f2937;
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
  transform: translate(-50%, -50%);
}

.map-label.active {
  border-color: rgba(29, 78, 216, .5);
  background: rgba(37, 99, 235, .96);
  box-shadow: 0 10px 26px rgba(37, 99, 235, .22);
  color: #fff;
}

.map-empty {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  color: var(--muted);
  pointer-events: none;
}

.map-empty.hidden {
  display: none;
}

.map-empty strong {
  color: var(--text);
}

.map-tooltip {
  display: grid;
  gap: 4px;
  min-width: 118px;
}

.map-tooltip strong {
  font-size: 14px;
}

.map-tooltip span {
  color: var(--muted);
  font-size: 12px;
}

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

  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
  }

  .side-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .province-section {
    max-height: 360px;
  }

  .map-panel {
    min-height: 680px;
  }
}

@media (max-width: 620px) {
  .side-panel {
    padding: 12px;
  }

  .stats-panel {
    grid-template-columns: 1fr;
  }

  .progress-ring {
    justify-self: center;
  }

  .side-actions,
  .segments {
    grid-template-columns: 1fr;
  }

  .map-topbar {
    align-items: flex-start;
    flex-direction: column;
    height: auto;
    min-height: 96px;
    padding: 14px;
  }

  .map-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .sync-state,
  .map-actions .button {
    width: 100%;
  }
}
