:root {
  --brand: #3E8EDE;
  --brand-dark: #286eaf;
  --brand-soft: #eef5fc;
  --brand-rgb: 62, 142, 222;
  --ink: #17212b;
  --muted: #637381;
  --panel: #ffffff;
  --line: #d9e2ec;
  --soft: #f4f7fa;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--soft);
  font-family: "Segoe UI", Arial, sans-serif;
}

.app-header {
  height: 72px;
  z-index: 20;
  box-shadow: 0 1px 8px rgba(15, 23, 42, 0.08);
}

.app-header-inner {
  gap: 16px;
  min-width: 0;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  overflow: hidden;
}

.brand-logo-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding-right: 2px;
}

.brand-logo {
  width: auto;
  max-width: 92px;
  height: 38px;
  object-fit: contain;
}

.brand-logo-sdc {
  max-width: 185px;
  height: 48px;
}

.brand-logo-clear {
  max-width: 58px;
  height: 54px;
}

.brand-logo-unitar,
.brand-logo-unosat {
  max-width: 74px;
  height: 54px;
}

.brand-copy {
  min-width: 0;
  margin-left: 4px;
  line-height: 1.15;
  overflow: hidden;
}

.brand-divider {
  flex: 0 0 auto;
  width: 1px;
  height: 38px;
  background: var(--line);
}

.brand-title {
  color: var(--brand);
  font-size: 1.1rem;
  font-weight: 750;
  letter-spacing: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-primary {
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-dark);
  --bs-btn-hover-border-color: var(--brand-dark);
  --bs-btn-active-bg: var(--brand-dark);
  --bs-btn-active-border-color: var(--brand-dark);
  --bs-btn-disabled-bg: var(--brand);
  --bs-btn-disabled-border-color: var(--brand);
}

.text-primary {
  color: var(--brand) !important;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  margin-left: auto;
}

.sdc-filter-control {
  height: 31px;
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 0 9px;
  color: var(--muted);
  background: #fff;
  border: 1px solid #b9c3cc;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.sdc-filter-control:hover {
  color: var(--ink);
  background: var(--soft);
}

.sdc-filter-control.is-active {
  color: var(--brand-dark);
  background: var(--brand-soft);
  border-color: #a8cbed;
}

.sdc-filter-control .form-check-input {
  flex: 0 0 auto;
  margin: 0;
  cursor: pointer;
}

.sdc-filter-control .form-check-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.2);
}

.sdc-filter-control .form-check-input:checked {
  background-color: var(--brand);
  border-color: var(--brand);
}

.app-shell {
  position: relative;
  height: calc(100vh - 72px);
}

#map {
  width: 100%;
  height: 100%;
}

.profile-panel {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 9;
  width: min(460px, 100vw);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  transform: translateX(0);
  transition: transform 180ms ease;
}

.profile-panel.is-hidden {
  transform: translateX(100%);
}

.profile-sheet-toggle {
  display: none;
}

.profile-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  color: var(--brand-dark);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.profile-panel h1 {
  margin: 2px 0;
  font-size: 1.2rem;
  line-height: 1.25;
}

.profile-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin: 2px 0;
}

.profile-title-row h1 {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.profile-status-badge {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  padding: 3px 7px;
  border: 1px solid;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 750;
  line-height: 1.2;
  white-space: nowrap;
}

.profile-status-badge[hidden] {
  display: none;
}

.profile-status-badge.is-sdc {
  color: #0f5f78;
  background: #e1f4fb;
  border-color: #8ed3eb;
}

.profile-status-badge.is-other {
  color: #475569;
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.profile-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}

.summary-card {
  min-width: 0;
  padding: 10px 8px;
  text-align: center;
  background: var(--brand-soft);
  border: 1px solid #d5e6f7;
  border-radius: 8px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

.summary-card strong {
  display: block;
  margin-top: 2px;
  font-size: 1.05rem;
}

.compact-tabs {
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}

.compact-tabs .nav-link {
  border-radius: 0;
  color: var(--muted);
  font-weight: 600;
}

.compact-tabs .nav-link.active {
  color: var(--brand-dark);
}

.profile-content {
  min-height: 0;
  overflow-y: auto;
  padding: 12px 18px 18px;
}

.accordion-item {
  border-color: var(--line);
}

.accordion-button {
  padding: 10px 12px;
  font-size: 0.9rem;
  font-weight: 700;
}

.accordion-button:not(.collapsed) {
  color: var(--brand-dark);
  background: var(--brand-soft);
  box-shadow: none;
}

.detail-table {
  font-size: 0.82rem;
}

.detail-table td,
.detail-table th {
  padding: 7px 10px;
  vertical-align: middle;
}

.detail-table .detail-icon {
  width: 30px;
  padding-right: 4px;
  color: var(--muted);
  text-align: center;
}

.detail-table td:last-child,
.detail-table th:last-child,
.detail-table td[id],
.detail-table th:nth-last-child(-n + 2) {
  text-align: right;
  font-weight: 700;
  color: #1a3a5c;
  overflow-wrap: anywhere;
}

.chart-card {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.chart-title {
  padding: 10px 12px;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
}

.chart-frame {
  padding: 10px;
}

.chart-frame-small {
  height: 340px;
}

.chart-frame-large {
  height: 720px;
}

.about-modal-body {
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.55;
}

.about-logo-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding: 12px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.about-logo-strip img {
  width: 100%;
  max-height: 58px;
  object-fit: contain;
}

.about-logo-strip img:first-child {
  max-height: 48px;
}

.app-loader {
  position: fixed;
  inset: 72px 0 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(244, 247, 250, 0.72);
}

.app-loader-content {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 18px 22px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.14);
}

.app-loader-message {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

.app-loader[hidden] {
  display: none;
}

.map-empty-state {
  position: absolute;
  top: 18px;
  left: 50%;
  z-index: 8;
  width: min(390px, calc(100% - 140px));
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: 0 8px 26px rgba(15, 23, 42, 0.18);
  transform: translateX(-50%);
}

.map-empty-state[hidden] {
  display: none;
}

.map-empty-state > i {
  color: var(--muted);
  font-size: 1rem;
}

.map-empty-state strong,
.map-empty-state span {
  display: block;
}

.map-empty-state strong {
  font-size: 0.82rem;
}

.map-empty-state span {
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.7rem;
}

#errorAction {
  color: #7f1d1d;
  font-weight: 700;
}

.maplibregl-popup-content {
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
}

.village-hover-popup {
  pointer-events: none;
}

.village-hover-popup .maplibregl-popup-content {
  padding: 10px 11px;
  border: 1px solid rgba(15, 23, 42, 0.12);
}

.village-tooltip {
  min-width: 155px;
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

.village-tooltip-name {
  font-size: 0.84rem;
  font-weight: 750;
  line-height: 1.25;
}

.village-tooltip-location {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.72rem;
}

.village-tooltip-status {
  display: inline-block;
  margin-top: 7px;
  padding: 2px 6px;
  border: 1px solid;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 750;
}

.village-tooltip-status.is-sdc {
  color: #0f5f78;
  background: #e1f4fb;
  border-color: #8ed3eb;
}

.village-tooltip-status.is-other {
  color: #475569;
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.maplibregl-ctrl-group {
  border-radius: 8px;
  overflow: hidden;
}

.maplibregl-ctrl-home {
  display: grid;
  place-items: center;
  font-size: 14px;
}

.village-search {
  position: relative;
  clear: both;
  width: 30px;
  overflow: visible;
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

.village-search.is-expanded {
  /* Each MapLibre control is its own stacking context; lift the open search above the filter button below it */
  z-index: 3;
  width: min(310px, calc(100vw - 70px));
}

.village-search-toggle {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  color: #333;
  background: #fff;
  border: 0;
  border-radius: 4px;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
  font-size: 14px;
}

.village-search-toggle:hover {
  background: #f2f2f2;
}

.village-search.is-expanded .village-search-toggle {
  display: none;
}

.village-search-panel {
  position: relative;
  width: 100%;
}

.village-search-panel[hidden] {
  display: none;
}

.village-search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.2);
}

.village-search-box > i {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.82rem;
}

.village-search-input {
  width: 100%;
  height: 38px;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  font: inherit;
  font-size: 0.84rem;
}

.village-search-input::placeholder {
  color: var(--muted);
}

.village-search-close {
  width: 28px;
  height: 28px;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 4px;
}

.village-search-close:hover,
.village-search-close:focus {
  color: var(--ink);
  background: var(--soft);
  outline: 0;
}

.village-search-box:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.2);
}

.village-search-results {
  position: absolute;
  top: calc(100% + 5px);
  right: 0;
  left: 0;
  z-index: 2;
  max-height: min(380px, calc(100vh - 190px));
  overflow-y: auto;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2);
}

.village-search-results[hidden] {
  display: none;
}

.village-search-result {
  width: 100%;
  display: grid;
  gap: 2px;
  padding: 9px 11px;
  color: var(--ink);
  text-align: left;
  background: #fff;
  border: 0;
  border-bottom: 1px solid var(--line);
}

.village-search-result:last-child {
  border-bottom: 0;
}

.village-search-result:hover,
.village-search-result:focus,
.village-search-result.is-active {
  background: var(--brand-soft);
  outline: 0;
}

.village-search-result-name {
  font-size: 0.84rem;
  font-weight: 700;
}

.village-search-result-lao {
  color: #334155;
  font-size: 0.78rem;
}

.village-search-result-location {
  color: var(--muted);
  font-size: 0.7rem;
}

.village-search-empty {
  padding: 13px 11px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.village-filter-control {
  position: relative;
  clear: both;
  width: 30px;
  overflow: visible;
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

.village-filter-control.is-expanded {
  width: min(310px, calc(100vw - 70px));
}

.village-filter-toggle {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  color: #333;
  background: #fff;
  border: 0;
  border-radius: 4px;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
  font-size: 14px;
}

.village-filter-toggle:hover {
  background: #f2f2f2;
}

.village-filter-control.is-expanded .village-filter-toggle {
  display: none;
}

.village-filter-panel {
  width: 100%;
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid rgba(15, 23, 42, 0.14);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.2);
}

.village-filter-panel[hidden] {
  display: none;
}

.village-filter-header,
.village-filter-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
}

.village-filter-header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff;
  border-bottom: 1px solid var(--line);
  font-size: 0.86rem;
}

.village-filter-close {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 4px;
}

.village-filter-close:hover,
.village-filter-close:focus {
  color: var(--ink);
  background: var(--soft);
  outline: 0;
}

.village-filter-fields {
  display: grid;
  gap: 9px;
  padding: 11px;
}

.village-filter-field {
  display: grid;
  gap: 4px;
  color: #334155;
  font-size: 0.72rem;
  font-weight: 700;
}

.village-filter-field select {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 28px 0 8px;
  color: var(--ink);
  background-color: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 500;
}

.village-filter-field select:focus {
  border-color: var(--brand);
  outline: 0;
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.18);
}

.village-filter-empty {
  margin: 0 11px 10px;
  padding: 9px;
  color: #991b1b;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 6px;
  font-size: 0.76rem;
  text-align: center;
}

.village-filter-empty[hidden] {
  display: none;
}

.village-filter-footer {
  position: sticky;
  bottom: 0;
  background: #fff;
  border-top: 1px solid var(--line);
}

.village-filter-count {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.village-filter-reset {
  padding: 4px 8px;
  color: var(--brand-dark);
  background: var(--brand-soft);
  border: 1px solid #c8def3;
  border-radius: 5px;
  font-size: 0.72rem;
  font-weight: 700;
}

.village-filter-reset:hover,
.village-filter-reset:focus {
  background: #dceafb;
  outline: 0;
}

.village-legend {
  min-width: 142px;
  padding: 9px 11px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.18);
  font-size: 0.75rem;
  line-height: 1.2;
}

.village-legend-title {
  margin-bottom: 7px;
  font-weight: 750;
}

.village-legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
}

.village-legend-item + .village-legend-item {
  margin-top: 5px;
}

.village-legend-swatch {
  width: 18px;
  height: 12px;
  flex: 0 0 auto;
  border: 2px solid;
  border-radius: 2px;
}

.village-legend-swatch.is-sdc {
  background: rgba(var(--brand-rgb), 0.35);
  border-color: var(--brand-dark);
}

.village-legend-swatch.is-other {
  background: rgba(148, 163, 184, 0.35);
  border-color: #64748b;
}

.village-legend-swatch.is-selected {
  background: rgba(245, 158, 11, 0.45);
  border-color: #f59e0b;
}

@media (max-width: 720px) {
  .app-header {
    height: 60px;
  }

  .app-shell {
    height: calc(100vh - 60px);
  }

  .app-loader {
    inset: 60px 0 0;
  }

  .map-empty-state {
    top: 10px;
    width: calc(100% - 20px);
    grid-template-columns: auto minmax(0, 1fr);
  }

  .map-empty-state .btn {
    grid-column: 1 / -1;
    width: 100%;
  }

  .app-header-inner {
    display: flex;
    gap: 8px;
    padding-right: 8px;
    padding-left: 8px;
  }

  .app-brand {
    gap: 8px;
    width: 100%;
  }

  .brand-logo-strip,
  .brand-logo-clear,
  .brand-logo-unitar,
  .brand-logo-unosat,
  .brand-subtitle,
  .brand-divider {
    display: none;
  }

  .brand-copy {
    max-width: calc(100vw - 112px);
    margin-left: 0;
  }

  .brand-title {
    font-size: 1rem;
  }

  .app-actions {
    width: auto;
    justify-content: flex-end;
  }

  .app-actions .btn {
    min-width: 40px;
  }

  .sdc-filter-control {
    min-width: 65px;
    justify-content: center;
    padding: 0 6px;
    gap: 5px;
  }

  .sdc-filter-short {
    font-size: 0.68rem;
    font-weight: 750;
  }

  .profile-panel {
    top: auto;
    bottom: 0;
    width: 100vw;
    height: min(56vh, 560px);
    border-top: 1px solid var(--line);
    border-left: 0;
    border-radius: 14px 14px 0 0;
    transform: translateY(0);
    transition: height 200ms ease, transform 200ms ease;
  }

  .profile-panel.is-expanded {
    height: min(88vh, calc(100% - 8px));
  }

  .profile-panel.is-hidden {
    transform: translateY(100%);
  }

  .profile-sheet-toggle {
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 6px 12px 4px;
    color: var(--muted);
    background: #fff;
    border: 0;
    border-radius: 14px 14px 0 0;
  }

  .profile-sheet-toggle:focus-visible {
    outline: 3px solid rgba(var(--brand-rgb), 0.35);
    outline-offset: -3px;
  }

  .profile-sheet-toggle > i {
    font-size: 0.68rem;
    transition: transform 180ms ease;
  }

  .profile-sheet-toggle.is-expanded > i {
    transform: rotate(180deg);
  }

  .profile-sheet-grip {
    width: 38px;
    height: 4px;
    background: #b8c2cc;
    border-radius: 999px;
  }

  .profile-panel-header {
    min-width: 0;
    padding: 10px 14px 9px;
  }

  .profile-panel-header > div {
    min-width: 0;
  }

  #closePanel {
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
  }

  .compact-tabs .nav-link {
    min-height: 44px;
  }

  .accordion-button {
    min-height: 44px;
  }

  .detail-table td[id] {
    max-width: 48vw;
    overflow-wrap: anywhere;
  }

  .about-logo-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .village-legend {
    min-width: 0;
    padding: 7px 9px;
    font-size: 0.68rem;
  }

  .village-legend-title {
    margin-bottom: 5px;
  }

  .village-legend-item {
    gap: 5px;
  }

  .village-legend-item + .village-legend-item {
    margin-top: 4px;
  }

  .village-legend-swatch {
    width: 15px;
    height: 10px;
  }

  .village-search {
    width: 30px;
  }

  .village-search.is-expanded {
    width: min(260px, calc(100vw - 60px));
  }

  .village-search-input {
    height: 36px;
    font-size: 0.8rem;
  }

  .village-search-results {
    max-height: min(300px, calc(100vh - 160px));
  }

  .village-filter-control {
    width: 30px;
  }

  .village-filter-control.is-expanded {
    width: min(280px, calc(100vw - 60px));
  }

  .village-filter-panel {
    max-height: calc(100vh - 110px);
  }
}

@media (max-width: 720px) and (orientation: landscape) {
  .profile-panel {
    height: 64vh;
  }

  .profile-panel.is-expanded {
    height: calc(100% - 6px);
  }

  .profile-panel-header {
    padding-top: 7px;
    padding-bottom: 7px;
  }
}

@media (max-width: 420px) {
  .brand-copy {
    max-width: calc(100vw - 104px);
  }

  .brand-title {
    font-size: 0.92rem;
  }
}
