:root {
  --bg: #0e1116; --bg-elev: #161b22; --bg-elev2: #1c232d; --border: #2a323d;
  --text: #e6edf3; --muted: #8b95a1; --accent: #2dd4bf; --gold: #e0b24c; --danger: #f2545b;
  --radius: 14px; --shadow: 0 8px 30px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden; }

/* topbar */
#topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 12px 22px; background: linear-gradient(180deg, var(--bg-elev), var(--bg)); border-bottom: 1px solid var(--border); z-index: 500; position: relative; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand .globe { font-size: 30px; filter: drop-shadow(0 2px 6px rgba(45,212,191,.4)); }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .3px; }
.brand .tagline { margin: 0; color: var(--muted); font-size: 12px; }
.userbar { display: flex; gap: 6px; background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 12px; padding: 4px; }
.ubtn { background: none; border: none; color: var(--muted); font-size: 13.5px; font-weight: 600; padding: 7px 13px; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.ubtn:hover { color: var(--text); }
.ubtn.active { background: var(--bg-elev); color: var(--text); box-shadow: inset 0 0 0 1.5px var(--uc, var(--accent)); }
.stats { display: flex; gap: 10px; flex-wrap: wrap; }
@media (max-width: 1200px) { .brand .tagline { display: none; } }
.stat { background: var(--bg-elev2); border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 14px; min-width: 78px; text-align: center; }
.stat .num { font-size: 21px; font-weight: 700; color: var(--accent); line-height: 1.1; }
.stat .num.gold { color: var(--gold); }
.stat .lbl { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* layout */
#app { display: flex; height: calc(100vh - 61px); }
#map-wrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; background: #0b1622; }

/* Leaflet dark tweaks */
.leaflet-container { background: #0b1622; font: inherit; }
.leaflet-bar a, .leaflet-control-zoom a { background: var(--bg-elev2); color: var(--text); border-color: var(--border); }
.leaflet-bar a:hover { background: #24303c; }
.leaflet-control-attribution { background: rgba(14,17,22,.8) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-tooltip.lft { background: rgba(20,26,34,.96); border: 1px solid var(--border); color: var(--text); box-shadow: var(--shadow); font-size: 12.5px; }
.leaflet-tooltip.lft::before { display: none; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--bg-elev); color: var(--text); border: 1px solid var(--border); }
.leaflet-popup-content { margin: 12px 14px; }
.leaflet-popup-close-button { color: var(--muted) !important; }

/* home marker (divIcon) */
.home-div { display: flex; flex-direction: column; align-items: center; transform: translate(-50%, -100%); white-space: nowrap; pointer-events: auto; cursor: pointer; }
.home-div .hp { font-size: 18px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.home-div .hl { font-size: 10px; font-weight: 700; color: var(--gold); margin-top: -2px;
  text-shadow: 0 0 3px #081521, 0 0 3px #081521, 0 0 2px #081521; }

/* photo button + drop hint + legend */
#map-tools { position: absolute; top: 14px; right: 14px; z-index: 500; display: flex; gap: 8px; }
#photo-btn, #addhome-btn { background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 13px; font-size: 13.5px; font-weight: 600; cursor: pointer; box-shadow: var(--shadow); }
#photo-btn:hover, #addhome-btn:hover { border-color: var(--accent); }
#addhome-btn.active { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 0 1.5px var(--gold); }
#addescala-btn.active { border-color: #8f83e0; color: #b3aaf0; box-shadow: 0 0 0 1.5px #8f83e0; }
.layover-div { transform: translate(-50%, -50%); font-size: 13px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.7)); cursor: pointer; }
.esc-box { margin: 4px 0 12px; }
.esc-row { display: flex; align-items: center; gap: 10px; padding: 9px 11px; margin-bottom: 6px;
  background: linear-gradient(90deg, rgba(124,111,214,.15), transparent); border: 1px solid rgba(143,131,224,.4); border-radius: 10px; }
.esc-t { flex: 1; font-weight: 600; color: #b3aaf0; }
.addhome-banner { position: absolute; top: 62px; left: 50%; transform: translateX(-50%); z-index: 500;
  background: rgba(224,178,76,.15); border: 1px solid var(--gold); color: var(--gold); font-weight: 600;
  padding: 8px 16px; border-radius: 999px; box-shadow: var(--shadow); font-size: 13.5px; }
.home-add-pop .hap-t { font-weight: 700; margin-bottom: 8px; color: var(--gold); }
.home-add-pop .hap-in { width: 100%; margin-bottom: 8px; background: var(--bg-elev2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: 8px 10px; font-size: 15px; }
.home-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; opacity: .5; align-self: center; padding: 0 2px; }
.home-del:hover { color: var(--danger); opacity: 1; }
.drop-hint { position: absolute; inset: 0; z-index: 600; display: flex; align-items: center; justify-content: center;
  background: rgba(45,212,191,.12); border: 3px dashed var(--accent); font-size: 26px; font-weight: 700; color: var(--accent); }
.legend { position: absolute; bottom: 22px; left: 12px; z-index: 500; background: rgba(14,17,22,.88);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; font-size: 11.5px; color: var(--muted); }
.legend .l-title { color: var(--text); font-weight: 600; margin-bottom: 5px; }
.legend .row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.legend .sw { width: 22px; height: 11px; border-radius: 3px; }
.legend .sw.dot { width: 11px; height: 11px; border-radius: 50%; }

/* panel + tabs */
.panel { width: 372px; flex: 0 0 372px; background: var(--bg-elev); border-left: 1px solid var(--border); display: flex; flex-direction: column; }
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab { flex: 1; background: none; border: none; color: var(--muted); padding: 13px 6px; font-size: 13px; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-body { flex: 1; overflow-y: auto; padding: 16px; }

.panel-empty { color: var(--text); margin-top: 40px; text-align: center; }
.muted { color: var(--muted); }
.panel-empty p { margin: 8px 0; }

/* list rows (Países / Ciudades) */
.list-head { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.lrow { display: flex; align-items: center; gap: 11px; padding: 9px 8px; border-radius: 9px; cursor: pointer; }
.lrow:hover { background: var(--bg-elev2); }
.lflag { font-size: 20px; width: 24px; text-align: center; flex: 0 0 auto; }
.lbody { flex: 1; min-width: 0; }
.lname { font-weight: 600; }
.lsub { font-size: 12px; color: var(--muted); }

/* country / city detail */
.pc-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.pc-flag { font-size: 32px; }
.pc-title h2 { margin: 0; font-size: 21px; }
.pc-title .pc-cont { color: var(--muted); font-size: 12.5px; }
.pc-metrics { display: flex; gap: 10px; margin: 14px 0 16px; }
.pc-metric { flex: 1; background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; text-align: center; }
.pc-metric .n { font-size: 20px; font-weight: 700; color: var(--accent); }
.pc-metric .l { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.sec-h { margin: 14px 0 8px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

.homes-box { margin: 4px 0 12px; }
.home-row { display: flex; align-items: flex-start; gap: 10px; padding: 9px 11px; margin-bottom: 6px;
  background: linear-gradient(90deg, rgba(224,178,76,.12), transparent); border: 1px solid rgba(224,178,76,.3); border-radius: 10px; }
.home-ico { font-size: 17px; }
.home-city { font-weight: 700; color: var(--gold); }
.home-note { font-size: 12px; color: var(--muted); }

.city-mini { display: flex; flex-direction: column; }
.cm-row { display: flex; justify-content: space-between; gap: 10px; padding: 8px 4px; border-top: 1px solid var(--border); cursor: pointer; }
.cm-row:hover { background: var(--bg-elev2); }
.cm-name { font-weight: 500; }
.cm-n { color: var(--muted); font-size: 12.5px; }

.btn { background: var(--accent); color: #06231f; border: none; border-radius: 8px; padding: 10px 14px; font-weight: 700; cursor: pointer; width: 100%; margin-top: 8px; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid rgba(45,212,191,.4); }

/* photo report modal */
.photo-report { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.6); padding: 20px; }
.pr-card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); width: min(560px,100%); max-height: 80vh; overflow-y: auto; box-shadow: var(--shadow); }
.pr-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.pr-head h2 { margin: 0; font-size: 18px; }
.pr-close { background: none; border: none; color: var(--muted); font-size: 22px; cursor: pointer; }
.pr-body { padding: 8px 20px 20px; }
.pr-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.pr-row:first-child { border-top: none; }
.pr-flag { font-size: 26px; } .pr-info { flex: 1; } .pr-info .pr-c { font-weight: 700; } .pr-info .pr-d { color: var(--muted); font-size: 12.5px; }
.pr-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.pr-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.pr-foot .btn { margin-top: 0; }

@media (max-width: 820px) {
  #app { flex-direction: column; }
  .panel { width: 100%; flex: 1 1 auto; border-left: none; border-top: 1px solid var(--border); }
  #map-wrap { flex: 0 0 52vh; }
  .stats { display: none; }
}
