:root {
  --text: #172033;
  --muted: #5b6475;
  --line: #d9e0ea;
  --panel: rgba(255, 255, 255, 0.94);
  --accent: #0f766e;
  --accent-strong: #115e59;
  --shadow: 0 18px 48px rgba(23, 32, 51, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #eef3f8;
}

button,
input,
textarea {
  font: inherit;
}

.map-shell,
.admin-layout,
.admin-map-wrap {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.map-canvas,
#map {
  width: 100%;
  height: 100%;
  background: #dfe8f1;
}

.map-panel,
.admin-topbar {
  position: fixed;
  z-index: 800;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: var(--panel);
  border: 1px solid rgba(217, 224, 234, 0.82);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.map-panel {
  top: 18px;
  left: 18px;
  min-width: min(520px, calc(100vw - 36px));
  padding: 14px 16px;
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

.map-panel h1,
.admin-topbar h1 {
  font-size: 20px;
  line-height: 1.25;
}

.admin-link,
.secondary-link,
.primary-btn,
.secondary-btn {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  padding: 0 14px;
  border: 1px solid transparent;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.admin-link,
.primary-btn {
  color: #fff;
  background: var(--accent);
}

.admin-link:hover,
.primary-btn:hover {
  background: var(--accent-strong);
}

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

.secondary-link:hover,
.secondary-btn:hover {
  border-color: #aeb8c7;
}

.primary-btn:disabled,
.secondary-btn:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.loading,
.toast {
  position: fixed;
  z-index: 1200;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.loading {
  top: 50%;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  font-weight: 700;
}

.toast {
  bottom: 24px;
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 16px;
  background: rgba(17, 24, 39, 0.94);
  color: #fff;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.commune-label-icon {
  width: 0 !important;
  height: 0 !important;
  background: transparent !important;
  border: 0 !important;
  opacity: 1;
  pointer-events: none;
  transition: opacity 0.16s ease;
}

.commune-label {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  width: max-content;
  max-width: var(--label-max-width, 138px);
  transform: translate(-50%, -50%) scale(var(--label-scale, 1));
  transform-origin: center;
  padding: 1px 2px;
  color: #0756a3;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  font-family: "Times New Roman", Times, serif;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.96),
    0 -1px 0 rgba(255, 255, 255, 0.96),
    1px 0 0 rgba(255, 255, 255, 0.96),
    -1px 0 0 rgba(255, 255, 255, 0.96);
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
  user-select: none;
  pointer-events: none;
  transition: transform 0.16s ease;
}

.commune-label--compact {
  padding: 0 1px;
  font-size: 12px;
  line-height: 1.1;
}

.commune-label-icon.label-hidden {
  opacity: 0;
  visibility: hidden;
}

.leaflet-path {
  transition: fill-opacity 0.14s ease, stroke-width 0.14s ease, stroke 0.14s ease;
}

.leaflet-control-zoom,
.leaflet-control-attribution {
  border: 0 !important;
  border-radius: 8px !important;
  box-shadow: 0 8px 24px rgba(23, 32, 51, 0.16);
  overflow: hidden;
}

.modern-popup .leaflet-popup-content-wrapper {
  overflow: hidden;
  border: 1px solid rgba(203, 213, 225, 0.9);
  border-radius: 14px;
  box-shadow: 0 18px 46px rgba(23, 32, 51, 0.24);
}

.modern-popup .leaflet-popup-content {
  width: 330px !important;
  margin: 0;
}

.modern-popup .leaflet-popup-close-button {
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 30px;
  height: 30px;
  color: #475569;
  font-size: 22px;
  line-height: 28px;
  border-radius: 999px;
}

.modern-popup .leaflet-popup-close-button:hover {
  color: #0f172a;
  background: rgba(255, 255, 255, 0.82);
}

.popup-card {
  padding: 0;
}

.popup-profile__header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 86px;
  padding: 18px 46px 16px 18px;
  color: #fff;
  background: linear-gradient(135deg, #0f766e 0%, #115e59 100%);
}

.popup-profile__title-icon,
.popup-info-row__icon {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}

.popup-profile__title-icon {
  width: 42px;
  height: 42px;
  color: #fff;
  background: rgba(255, 255, 255, 0.17);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.popup-profile__title-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.popup-profile__title-copy {
  min-width: 0;
}

.popup-profile__eyebrow {
  display: block;
  margin-bottom: 3px;
  color: rgba(255, 255, 255, 0.76);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.popup-profile h3 {
  margin: 0;
  color: #fff;
  font-size: 21px;
  font-weight: 800;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.popup-profile__list {
  display: grid;
  gap: 0;
  padding: 6px 16px 10px;
  background: #fff;
}

.popup-info-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 11px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid #e8edf3;
}

.popup-info-row:last-child {
  border-bottom: 0;
}

.popup-info-row__icon {
  width: 36px;
  height: 36px;
  color: var(--accent-strong);
  background: #e9f6f4;
  border: 1px solid #cfe9e5;
}

.popup-info-row__icon svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.popup-info-row__content {
  min-width: 0;
}

.popup-info-row__label {
  display: block;
  margin-bottom: 3px;
  color: #64748b;
  font-size: 11px;
  font-weight: 750;
  line-height: 1.25;
}

.popup-info-row__value {
  display: block;
  color: #172033;
  font-size: 13.5px;
  font-weight: 650;
  line-height: 1.42;
  overflow-wrap: anywhere;
}

.popup-info-row__value--number {
  font-size: 15px;
  font-weight: 800;
}

@media (max-width: 720px) {
  .map-panel {
    top: 12px;
    left: 12px;
    min-width: calc(100vw - 24px);
    padding: 12px;
  }

  .map-panel h1,
  .admin-topbar h1 {
    font-size: 16px;
  }

  .admin-link,
  .secondary-link,
  .primary-btn,
  .secondary-btn {
    min-height: 36px;
    padding: 0 10px;
    font-size: 13px;
  }

  .commune-label {
    font-size: 12px;
    padding: 0 1px;
  }

  .commune-label--compact {
    font-size: 11px;
    padding: 0 1px;
  }

  .modern-popup .leaflet-popup-content {
    width: min(310px, calc(100vw - 48px)) !important;
  }

  .popup-profile__header {
    min-height: 78px;
    padding: 15px 42px 14px 15px;
  }

  .popup-profile h3 {
    font-size: 19px;
  }

  .popup-profile__list {
    padding-right: 14px;
    padding-left: 14px;
  }
}

/*
 * Nền dự phòng khi tile OSM chưa tải. Mặt nạ GeoJSON sẽ che phần ngoài
 * Lạng Sơn, còn đường và địa danh OSM chỉ lộ bên trong đường bao tỉnh.
 */
.leaflet-container {
  background: #e8edf2;
}

.context-label-icon {
  width: 0 !important;
  height: 0 !important;
  background: transparent !important;
  border: 0 !important;
}

.context-label {
  position: absolute;
  display: block;
  width: max-content;
  transform: translate(-50%, -50%);
  color: #687386;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0.055em;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
  opacity: 0.78;
  pointer-events: none;
  user-select: none;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.98),
    0 -1px 0 rgba(255, 255, 255, 0.98),
    1px 0 0 rgba(255, 255, 255, 0.98),
    -1px 0 0 rgba(255, 255, 255, 0.98),
    0 2px 5px rgba(255, 255, 255, 0.92);
}

.context-label--country {
  color: #778296;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0.04em;
}

@media (max-width: 720px) {
  .context-label {
    font-size: 12px;
  }

  .context-label--country {
    font-size: 10px;
  }
}


/* Giữ chữ và đường của nền OSM rõ dưới lớp màu xã/phường bán trong suốt. */
.leaflet-tile-pane {
  filter: saturate(0.9) contrast(0.98) brightness(1.02);
}

/* Mặt nạ và đường bao không nhận sự kiện chuột. */
.leaflet-outsideMask-pane,
.leaflet-provinceOutline-pane {
  pointer-events: none;
}

/* ===== Bố cục bản đồ hành chính cố định ===== */
.map-title-banner {
  position: fixed;
  z-index: 900;
  top: 16px;
  left: 50%;
  width: min(1040px, calc(100vw - 220px));
  transform: translateX(-50%);
  padding: 10px 22px 11px;
  text-align: center;
  pointer-events: none;
}

.map-title-banner::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  border-radius: 4px;
  background: rgba(238, 250, 250, 0.88);
  border-top: 3px solid rgba(0, 98, 112, 0.48);
  border-bottom: 1px solid rgba(0, 98, 112, 0.26);
  box-shadow: 0 7px 20px rgba(23, 50, 64, 0.11);
  backdrop-filter: blur(4px);
}

.map-title-banner h1 {
  margin: 0;
  color: #064fd5;
  font-family: "Times New Roman", Times, serif;
  font-size: clamp(22px, 2.15vw, 38px);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: 0.025em;
  text-transform: uppercase;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.98),
    0 2px 5px rgba(255, 255, 255, 0.88);
}

.map-admin-link {
  position: fixed;
  z-index: 920;
  top: 20px;
  right: 18px;
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  color: #fff;
  background: rgba(15, 118, 110, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 7px;
  box-shadow: 0 8px 22px rgba(23, 32, 51, 0.2);
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
  backdrop-filter: blur(5px);
}

.map-admin-link:hover {
  background: #115e59;
}

.province-summary {
  position: fixed;
  z-index: 880;
  bottom: 24px;
  left: 24px;
  width: min(310px, calc(100vw - 48px));
  padding: 7px;
  color: #053b52;
  background: rgba(225, 250, 247, 0.93);
  border: 3px solid #00677c;
  box-shadow:
    0 0 0 4px rgba(225, 250, 247, 0.82),
    0 0 0 6px #00677c,
    0 16px 38px rgba(20, 49, 64, 0.2);
  font-family: "Times New Roman", Times, serif;
  backdrop-filter: blur(5px);
}

.province-summary__heading {
  display: grid;
  gap: 1px;
  padding: 7px 8px 6px;
  border-bottom: 1px solid rgba(0, 103, 124, 0.34);
  text-align: center;
}

.province-summary__heading span {
  color: #125066;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.045em;
}

.province-summary__heading strong {
  color: #004f68;
  font-size: 21px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0.025em;
}

.province-summary__content {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px 7px 6px;
}

.province-summary__shape {
  display: flex;
  min-height: 126px;
  align-items: center;
  justify-content: center;
}

.province-summary__shape svg {
  width: 82px;
  height: 118px;
  overflow: visible;
  filter: drop-shadow(0 3px 3px rgba(0, 55, 72, 0.24));
}

.province-summary__shape-path {
  fill: #00687d;
  stroke: #004f65;
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
}

.province-summary__stats {
  display: grid;
  gap: 7px;
  margin: 0;
}

.province-summary__stats > div {
  min-width: 0;
}

.province-summary__stats dt {
  margin: 0 0 1px;
  color: #1d5d6d;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.1;
  text-transform: uppercase;
}

.province-summary__stats dd {
  margin: 0;
  color: #00475d;
  font-size: 15px;
  font-weight: 800;
  line-height: 1.08;
}

.province-summary__stats small {
  display: block;
  margin-top: 1px;
  color: #3a6875;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.15;
}

.province-summary__legal {
  font-size: 12px !important;
}

/* Nhãn các tỉnh/quốc gia xung quanh dùng cùng kiểu chữ bản đồ hành chính. */
.context-label,
.context-label--country {
  font-family: "Times New Roman", Times, serif;
  font-style: normal;
}

/* Đưa nút thu phóng xuống dưới tiêu đề để không chồng nội dung. */
.leaflet-top.leaflet-left {
  top: 78px;
}

@media (max-width: 900px) {
  .map-title-banner {
    top: 10px;
    width: calc(100vw - 116px);
    padding: 8px 12px;
  }

  .map-title-banner h1 {
    font-size: clamp(16px, 3.2vw, 24px);
  }

  .map-admin-link {
    top: 12px;
    right: 10px;
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
  }

  .province-summary {
    bottom: 14px;
    left: 14px;
    width: 270px;
  }

  .province-summary__content {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .province-summary__shape svg {
    width: 68px;
    height: 100px;
  }

  .province-summary__heading strong {
    font-size: 18px;
  }

  .province-summary__stats dd {
    font-size: 13px;
  }

  .leaflet-top.leaflet-left {
    top: 62px;
  }
}

@media (max-width: 560px) {
  .map-title-banner {
    left: 8px;
    width: calc(100vw - 94px);
    transform: none;
    padding: 7px 8px;
  }

  .map-title-banner h1 {
    font-size: 14px;
    line-height: 1.14;
  }

  .map-admin-link {
    width: 72px;
    padding: 0 6px;
  }

  .province-summary {
    bottom: 10px;
    left: 10px;
    width: min(245px, calc(100vw - 20px));
    border-width: 2px;
    box-shadow:
      0 0 0 3px rgba(225, 250, 247, 0.8),
      0 0 0 4px #00677c,
      0 10px 26px rgba(20, 49, 64, 0.2);
  }

  .province-summary__heading {
    padding: 5px 6px 4px;
  }

  .province-summary__heading span {
    font-size: 9px;
  }

  .province-summary__heading strong {
    font-size: 16px;
  }

  .province-summary__content {
    grid-template-columns: 60px minmax(0, 1fr);
    gap: 7px;
    padding: 5px;
  }

  .province-summary__shape {
    min-height: 88px;
  }

  .province-summary__shape svg {
    width: 56px;
    height: 82px;
  }

  .province-summary__stats {
    gap: 4px;
  }

  .province-summary__stats dt,
  .province-summary__stats small {
    font-size: 8px;
  }

  .province-summary__stats dd {
    font-size: 11px;
  }

  .province-summary__legal {
    font-size: 9px !important;
  }
}


/* ===== V4: phối màu hành chính + popup đa sắc + website ===== */
.modern-popup .leaflet-popup-content-wrapper {
  border: 1px solid rgba(127, 29, 29, 0.3);
  border-radius: 16px;
  box-shadow: 0 18px 48px rgba(69, 20, 20, 0.25);
  font-family: "Times New Roman", Times, serif;
}

.modern-popup .leaflet-popup-close-button {
  color: #fff7ed;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.modern-popup .leaflet-popup-close-button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.25);
}

.popup-profile,
.popup-profile__header,
.popup-profile__list,
.popup-info-row__label,
.popup-info-row__value {
  font-family: "Times New Roman", Times, serif;
}

.popup-profile__header {
  min-height: 90px;
  background: linear-gradient(135deg, #7f1d1d 0%, #b91c1c 54%, #c2410c 100%);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.16);
}

.popup-profile__title-icon {
  color: #fff7ed;
  background: rgba(255, 247, 237, 0.14);
  border-color: rgba(254, 215, 170, 0.38);
  box-shadow: 0 5px 16px rgba(69, 10, 10, 0.2);
}

.popup-profile__eyebrow {
  color: #ffedd5;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.075em;
}

.popup-profile h3 {
  font-family: "Times New Roman", Times, serif;
  color: #fff;
  font-size: 23px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.popup-profile__list {
  background: linear-gradient(180deg, #fffdf9 0%, #ffffff 100%);
}

.popup-info-row {
  border-bottom-color: #eee5df;
}

.popup-info-row__label {
  color: #6b5b55;
  font-size: 12px;
  font-weight: 700;
}

.popup-info-row__value {
  color: #1f2937;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.38;
}

.popup-info-row__value--number {
  font-size: 16px;
  font-weight: 700;
}

.popup-info-row__icon {
  border-width: 1px;
  box-shadow: 0 4px 12px rgba(31, 41, 55, 0.06);
}

.popup-info-row--history .popup-info-row__icon {
  color: #b45309;
  background: #fff7ed;
  border-color: #fed7aa;
}

.popup-info-row--area .popup-info-row__icon {
  color: #1d4ed8;
  background: #eff6ff;
  border-color: #bfdbfe;
}

.popup-info-row--population .popup-info-row__icon {
  color: #047857;
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.popup-info-row--website .popup-info-row__icon {
  color: #7c3aed;
  background: #f5f3ff;
  border-color: #ddd6fe;
}

.popup-info-row__website {
  color: #6d28d9;
  font-weight: 700;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.popup-info-row__website:hover {
  color: #991b1b;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.popup-info-row__empty {
  color: #9ca3af;
  font-style: italic;
  font-weight: 400;
}

/* Bảng thông tin chung: bo viền đỏ, nền ấm, số liệu đa sắc nhưng cùng độ bão hòa. */
.province-summary {
  color: #3f2c28;
  background: rgba(255, 251, 242, 0.95);
  border-color: #b91c1c;
  box-shadow:
    0 0 0 4px rgba(255, 247, 237, 0.9),
    0 0 0 6px #7f1d1d,
    0 16px 38px rgba(91, 33, 25, 0.22);
}

.province-summary__heading {
  border-bottom-color: rgba(185, 28, 28, 0.28);
  background: linear-gradient(180deg, rgba(255, 247, 237, 0.7), rgba(255, 251, 235, 0.25));
}

.province-summary__heading span {
  color: #b45309;
}

.province-summary__heading strong {
  color: #991b1b;
}

.province-summary__shape svg {
  filter: drop-shadow(0 3px 3px rgba(127, 29, 29, 0.22));
}

.province-summary__shape-path {
  fill: #b91c1c;
  stroke: #7f1d1d;
}

.province-summary__stats dt {
  color: #6b4c45;
}

.province-summary__stats dd {
  color: #3f2c28;
}

.province-summary__stats > div:nth-child(1) dt,
.province-summary__stats > div:nth-child(1) dd {
  color: #1d4ed8;
}

.province-summary__stats > div:nth-child(2) dt,
.province-summary__stats > div:nth-child(2) dd {
  color: #047857;
}

.province-summary__stats > div:nth-child(3) dt,
.province-summary__stats > div:nth-child(3) dd {
  color: #b45309;
}

.province-summary__stats > div:nth-child(4) dt,
.province-summary__stats > div:nth-child(4) dd {
  color: #7c3aed;
}

.province-summary__stats small {
  color: #78645d;
}

@media (max-width: 720px) {
  .popup-profile h3 {
    font-size: 20px;
  }
  .popup-info-row__label {
    font-size: 11.5px;
  }
  .popup-info-row__value,
  .popup-info-row__value--number {
    font-size: 14px;
  }
}

@media (max-width: 720px) {
  .popup-profile__header {
    min-height: 80px;
    padding: 15px 42px 13px 15px;
  }
}

@media (max-width: 560px) {
  .province-summary {
    border-width: 2px;
    box-shadow:
      0 0 0 3px rgba(255, 247, 237, 0.9),
      0 0 0 4px #7f1d1d,
      0 10px 26px rgba(91, 33, 25, 0.2);
  }
}
