:root {
  --ink: #12241a;
  --muted: #5c6f64;
  --line: rgba(18, 36, 26, .10);
  --gold: #d4a017;
  --gold-2: #f0d060;
  --gold-deep: #9a7209;
  --green: #1b5e3b;
  --green-2: #0f3d28;
  --green-3: #247a4d;
  --cream: #f6f1e6;
  --card: #fffdf8;
  --star: #e0b422;
  --star-off: #d7d1c3;
  --shadow: 0 18px 50px rgba(15, 36, 26, .22);
  --font: "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
}
button, input { font-family: inherit; }
a { color: var(--green); }

#map {
  position: absolute; inset: 0;
  z-index: 1;
  background: #14261c;
}

.leaflet-control-zoom a {
  background: #fffdf8 !important;
  color: var(--green-2) !important;
  border-color: #ead9a8 !important;
}
.leaflet-control-layers {
  border: 0 !important;
  border-radius: 12px !important;
  overflow: hidden;
  box-shadow: var(--shadow) !important;
}

.xa-label {
  font-weight: 800; color: #fff; font-size: 11px;
  text-shadow: 0 0 3px #000, 0 1px 2px #000, 1px 0 2px #000, -1px 0 2px #000;
  white-space: nowrap; pointer-events: none;
}
.xa-label.has-sp { color: #fff4c2; font-size: 12px; }

.leaflet-div-icon.sp-div-icon,
.sp-div-icon,
.leaflet-div-icon.xa-cluster-icon,
.xa-cluster-icon {
  background: transparent !important;
  border: none !important;
}

.sp-pin {
  width: 56px; height: 66px;
  display: flex; flex-direction: column; align-items: center;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.35));
  cursor: pointer;
  transform: scale(var(--sp-scale, 1));
  transform-origin: 50% 100%;
  will-change: transform;
}
.sp-pin .thumb,
.xa-cluster .thumb {
  width: 52px; height: 52px; border-radius: 50%;
  border: 2.5px solid #fff;
  background: #1b5e3b center/cover no-repeat;
  box-sizing: border-box;
}
.sp-pin .thumb.empty,
.xa-cluster .thumb.empty {
  display: grid; place-items: center;
  color: #fff; font-size: 16px;
  background: linear-gradient(160deg, #2a8a56, #134e32);
}
.sp-pin .sao,
.xa-cluster .sao {
  margin-top: -8px;
  min-width: 28px; padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px; font-weight: 800; color: #3b2a04;
  background: linear-gradient(180deg, #f5d76e, #d4a017);
  border: 1.5px solid #fff;
  letter-spacing: .02em;
  text-align: center;
}
.sp-pin.sao5 .thumb, .xa-cluster.sao5 .thumb { box-shadow: 0 0 0 2px #d4a017; }
.sp-pin.sao4 .sao, .xa-cluster.sao4 .sao { background: linear-gradient(180deg, #93c5fd, #2563eb); color: #fff; }
.sp-pin.sao3 .sao, .xa-cluster.sao3 .sao { background: linear-gradient(180deg, #86efac, #16a34a); color: #fff; }

.xa-cluster {
  width: 64px; height: 74px;
  display: flex; flex-direction: column; align-items: center;
  filter: drop-shadow(0 8px 14px rgba(0,0,0,.4));
  cursor: pointer;
  position: relative;
  transform: scale(var(--sp-scale, 1));
  transform-origin: 50% 100%;
  will-change: transform;
}
.xa-cluster .thumb { width: 56px; height: 56px; }
.xa-cluster .badge {
  position: absolute; top: -4px; right: -2px;
  min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 999px;
  background: #dc2626; color: #fff;
  font-size: 11px; font-weight: 800;
  display: grid; place-items: center;
  border: 2px solid #fff;
}

.dock {
  position: absolute; z-index: 1100;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(400px, 38vw);
  height: 100%;
  max-height: none;
  display: flex; flex-direction: column;
  background: rgba(255, 253, 248, .96);
  border: 0;
  border-right: 1px solid rgba(212, 160, 23, .35);
  border-radius: 0;
  box-shadow: 8px 0 28px rgba(15, 36, 26, .16);
  backdrop-filter: blur(14px);
  overflow: hidden;
}
.dock-head {
  flex-shrink: 0;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--line);
}
.dock-title {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
}
.dock-head h2 {
  margin: 0 0 4px; font-size: .95rem; font-weight: 800; color: var(--green-2);
}
.btn-back {
  flex-shrink: 0;
  border: 1px solid #e6d7a8; background: #fff; color: var(--green-2);
  border-radius: 999px; padding: 4px 10px; font-size: .72rem; font-weight: 800;
  cursor: pointer;
}
.btn-back[hidden] { display: none !important; }
.dock-head p { margin: 0; font-size: .76rem; color: var(--muted); font-weight: 600; }
.search {
  width: 100%; margin-top: 10px;
  border: 1px solid #e6d7a8; border-radius: 11px;
  padding: 9px 12px; font-size: .88rem;
  background: #fff;
  outline: none;
}
.search:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212,160,23,.18); }
.xa-combo { position: relative; margin-top: 10px; }
.xa-combo .search { margin-top: 0; }
.xa-suggest {
  position: fixed;
  z-index: 1400;
  margin: 0; padding: 6px;
  list-style: none;
  max-height: min(260px, 40vh); overflow-y: auto;
  background: #fffdf8;
  border: 1px solid #ead9a8;
  border-radius: 12px;
  box-shadow: 0 12px 28px rgba(15, 36, 26, .18);
}
.xa-suggest[hidden] { display: none !important; }
.xa-suggest li {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 9px;
  font-size: .84rem; font-weight: 700; color: var(--ink);
  cursor: pointer;
}
.xa-suggest li:hover, .xa-suggest li.is-on { background: #fff6d8; }
.xa-suggest li .xa-has {
  flex-shrink: 0;
  font-size: .68rem; font-weight: 800; letter-spacing: .04em;
  color: #9a7209; background: #fff4c2;
  border-radius: 999px; padding: 2px 7px;
}
.xa-suggest .xa-empty {
  color: var(--muted); cursor: default; font-weight: 600;
}
.xa-suggest .xa-empty:hover { background: transparent; }
.filters {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px;
}
.chip {
  border: 1px solid #e6d7a8; background: #fff; color: var(--green-2);
  border-radius: 999px; padding: 5px 10px; font-size: .75rem; font-weight: 800;
  cursor: pointer;
}
.chip.is-on {
  background: var(--green); color: #fff; border-color: var(--green);
}
.chip.sao5.is-on { background: #9a7209; border-color: #9a7209; }
.chip.sao4.is-on { background: #1d4ed8; border-color: #1d4ed8; }
.chip.sao3.is-on { background: #15803d; border-color: #15803d; }
.legend {
  flex-shrink: 0;
  display: flex; flex-wrap: wrap; gap: 8px 12px;
  padding: 8px 14px; font-size: .72rem; font-weight: 700; color: var(--muted);
  border-bottom: 1px dashed #ead9a8;
}
.legend i {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 4px; vertical-align: -1px;
}
.lg-has { background: #d4a017; }
.lg-none { background: #94a3b8; }
.list {
  list-style: none; margin: 0; padding: 6px 8px 10px;
  overflow-y: auto; flex: 1; min-height: 0;
}
.list li {
  display: flex; gap: 10px; align-items: center;
  padding: 6px 8px; border-radius: 12px; cursor: pointer;
}
.list li:hover, .list li.is-active { background: #fff6d8; }
.list .ava {
  width: 46px; height: 46px; border-radius: 12px; flex-shrink: 0;
  object-fit: cover; background: #e8f5ee; border: 1px solid #ead9a8;
}
.list .ava.ph { display: grid; place-items: center; font-size: 18px; }
.list .meta { min-width: 0; flex: 1; }
.list .meta strong {
  display: block; font-size: .84rem; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list .sub {
  font-size: .72rem; color: var(--muted); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stars { color: var(--star); letter-spacing: 1px; font-weight: 800; font-size: .82rem; }
.stars .off { color: var(--star-off); }
.dock-count {
  flex-shrink: 0;
  padding: 8px 14px 10px; font-size: .72rem; color: var(--muted); font-weight: 700;
}

/* Popup Leaflet — danh sách SP của xã */
.leaflet-popup.xa-leaflet-popup .leaflet-popup-content-wrapper {
  padding: 0; border-radius: 18px; overflow: hidden;
  box-shadow: 0 22px 50px rgba(8, 20, 14, .35);
  border: 1px solid rgba(212, 160, 23, .35);
}
.leaflet-popup.xa-leaflet-popup .leaflet-popup-content {
  margin: 0; min-width: 280px; max-width: 340px; line-height: 1.4;
}
.leaflet-popup.xa-leaflet-popup .leaflet-popup-tip { background: #fffdf8; }
.leaflet-popup.xa-leaflet-popup .leaflet-popup-close-button {
  color: #fff4c2 !important;
  top: 8px; right: 8px;
  width: 22px; height: 22px;
  font-size: 18px; font-weight: 700;
}
.xa-pop { font-family: var(--font); background: #fffdf8; color: var(--ink); }
.xa-pop-head {
  padding: 12px 28px 12px 12px;
  background: linear-gradient(135deg, #1b5e3b, #0f3d28);
  color: #fff;
}
.xa-pop-title {
  display: flex;
  align-items: center;
  gap: 12px;
}
.xa-pop-logo {
  height: 40px;
  width: auto;
  max-width: 128px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
  background: linear-gradient(180deg, #fffefb, #fff4d0);
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid #f0d060;
}
.xa-pop-head h3 {
  margin: 0;
  flex: 1;
  min-width: 0;
  text-align: right;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.25;
}
.xa-pop-head p { margin: 6px 0 0; font-size: .75rem; opacity: .92; font-weight: 600; line-height: 1.5; }
.xa-pop-head .xa-pop-stars {
  color: #f5d76e;
  letter-spacing: .04em;
  font-size: .82rem;
}
.xa-pop-list { max-height: 320px; overflow-y: auto; padding: 8px; }
.xa-sp {
  width: 100%; display: flex; gap: 10px; align-items: center;
  text-align: left; border: 0; background: transparent;
  padding: 8px; border-radius: 12px; cursor: pointer;
  font-family: inherit;
}
.xa-sp:hover { background: #fff6d8; }
.xa-sp img, .xa-sp .ph {
  width: 52px; height: 52px; border-radius: 12px; flex-shrink: 0;
  object-fit: cover; background: #e8f5ee; border: 1px solid #ead9a8;
}
.xa-sp .ph { display: grid; place-items: center; color: var(--gold-deep); font-size: 18px; }
.xa-sp strong {
  display: block; font-size: .86rem; font-weight: 800; line-height: 1.25;
  color: var(--ink);
}
.xa-sp-stars { margin-top: 2px; font-size: .75rem; font-weight: 700; color: var(--muted); }
.xa-sp-stars em { font-style: normal; color: var(--gold-deep); margin-left: 4px; }

/* Modal chi tiết sản phẩm */
.modal-bg {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(6, 14, 10, .62);
  backdrop-filter: blur(8px);
  display: none; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.modal-bg.is-open { display: flex; }
.modal {
  width: min(560px, 100%);
  max-height: min(92vh, 860px);
  overflow: auto;
  background: var(--card);
  border-radius: 24px;
  box-shadow: 0 36px 90px rgba(0,0,0,.45);
  animation: pop .28s ease;
}
@keyframes pop {
  from { transform: translateY(18px) scale(.97); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.modal-hero {
  position: relative; height: 280px;
  background: #123528 center/cover no-repeat;
}
.modal-hero::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0; height: 88px;
  background: linear-gradient(transparent, var(--card));
  pointer-events: none;
}
.modal-hero.empty {
  background: linear-gradient(160deg, #1b5e3b, #0f3d28);
}
.modal-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 38px; height: 38px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.48); color: #fff;
  font-size: 22px; cursor: pointer; line-height: 1;
}
.modal-close:hover { background: rgba(0,0,0,.7); }
.modal-sao-float {
  position: absolute; left: 16px; right: 16px; bottom: 22px; z-index: 3;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}
.modal-sao-logo-plate {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 5px 10px;
  background: linear-gradient(180deg, #fffefb, #fff4d0);
  border: 1px solid #f0d060;
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(18, 36, 26, .22);
}
.modal-sao-logo-plate img {
  height: 44px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  display: block;
}
.modal-sao-text {
  margin-left: auto;
  text-align: right;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  white-space: nowrap;
  padding: 8px 14px;
  border-radius: 8px;
  background: linear-gradient(180deg, #fffefb, #fff4d0);
  border: 1px solid #f0d060;
  color: var(--gold-deep);
  box-shadow: 0 6px 16px rgba(18, 36, 26, .22);
}
.modal-sao-text .stars {
  font-size: 1.05rem;
  color: #d4a017;
  letter-spacing: .06em;
}
.modal-sao-text .sao-label {
  font-weight: 800;
  font-size: .92rem;
  color: var(--ink);
}
.modal-body { padding: 6px 22px 22px; }
.kicker {
  font-size: .72rem; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; color: var(--gold-deep); margin: 0 0 6px;
}
.modal-body h3 {
  margin: 0 0 8px; font-size: 1.42rem; line-height: 1.25; letter-spacing: -.02em;
}
.modal-xa {
  font-size: .88rem; font-weight: 700; color: var(--green);
  margin: 0 0 12px;
}
.desc {
  font-size: .94rem; line-height: 1.58; color: #33443b; margin: 0 0 14px;
}
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.pill {
  display: inline-flex; align-items: center;
  border-radius: 999px; padding: 4px 10px;
  font-size: .72rem; font-weight: 800;
  background: #eef7f1; color: var(--green-2);
}
.pill.warn { background: #fff7ed; color: #c2410c; }
.pill.ok { background: #ecfdf5; color: #047857; }
.specs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.spec {
  background: #f7f3ea; border-radius: 14px; padding: 10px 12px;
}
.spec .lbl {
  font-size: .68rem; font-weight: 800; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 4px;
}
.spec .val { font-size: .88rem; font-weight: 700; word-break: break-word; }
.modal-actions {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 999px; padding: 10px 16px; font-weight: 800; font-size: .88rem;
  border: 1px solid transparent; cursor: pointer; text-decoration: none !important;
}
.btn-gold {
  color: #3b2a04;
  background: linear-gradient(180deg, #f5d76e, #d4a017);
  box-shadow: 0 6px 16px rgba(212,160,23,.35);
}
.btn-zalo { background: #0068ff; color: #fff; }
.btn-ghost {
  background: #fff; color: var(--green-2); border-color: #e6d7a8;
}
.related { margin-top: 18px; }
.related h4 {
  margin: 0 0 8px; font-size: .78rem; font-weight: 800;
  letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.related-row {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px;
}
.rel-card {
  flex: 0 0 118px; border: 0; background: #fff; padding: 0;
  border-radius: 14px; overflow: hidden; cursor: pointer;
  border: 1px solid #ead9a8; text-align: left; font-family: inherit;
}
.rel-card img, .rel-card .ph {
  width: 100%; height: 78px; object-fit: cover; display: block;
  background: #e8f5ee;
}
.rel-card .ph { display: grid; place-items: center; height: 78px; }
.rel-card span {
  display: block; padding: 6px 8px 8px;
  font-size: .72rem; font-weight: 800; line-height: 1.25;
  color: var(--ink);
}

.toast {
  position: fixed; z-index: 1300; left: 50%; bottom: 18px;
  transform: translateX(-50%);
  background: rgba(18,36,26,.9); color: #fff;
  padding: 8px 14px; border-radius: 999px; font-size: .8rem; font-weight: 700;
  display: none;
}

@media (max-width: 820px) {
  .dock {
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; height: 46vh; max-height: 46vh;
    border-right: 0;
    border-top: 1px solid rgba(212, 160, 23, .35);
    border-radius: 16px 16px 0 0;
  }
  .modal-hero { height: 210px; }
  .specs { grid-template-columns: 1fr; }
}
