/* ══════════════════════════════════════════════
   Plottier SIG — Dark GIS Theme
══════════════════════════════════════════════ */

:root {
  --bg:       #0d1117;
  --bg2:      #161b22;
  --bg3:      #21262d;
  --border:   #30363d;
  --text:     #c9d1d9;
  --text2:    #8b949e;
  --blue:     #58a6ff;
  --green:    #3fb950;
  --orange:   #d29922;
  --red:      #f85149;
  --header-h: 52px;
  --sidebar-w: 320px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%; width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  overflow: hidden;
}

/* ── Loading Overlay ─────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s, visibility 0.5s;
}
#loading-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.loading-content {
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}
.loading-logo { font-size: 56px; animation: pulse 1.5s ease-in-out infinite; }
.loading-content h2 {
  font-size: 22px; font-weight: 700; letter-spacing: 3px; color: var(--text);
}
.loading-bar-container {
  width: 260px; height: 4px;
  background: var(--bg3); border-radius: 2px; overflow: hidden;
}
.loading-bar {
  height: 100%; width: 0;
  background: linear-gradient(90deg, var(--blue), #1565c0);
  border-radius: 2px;
  transition: width 0.4s ease;
}
#loading-status { color: var(--text2); font-size: 12px; }

@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* ── Header ─────────────────────────────────── */
.app-header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 12px;
  z-index: 200;
  gap: 12px;
}

.logo {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.logo-icon { font-size: 20px; }
.logo-text {
  font-size: 13px; letter-spacing: 2px;
  color: var(--text2); text-transform: uppercase;
}
.logo-text strong { color: var(--text); }

.module-nav {
  display: flex; gap: 2px; flex: 1; justify-content: center;
}
.nav-btn {
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 6px;
  color: var(--text2); font-size: 13px;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}
.nav-btn:hover  { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: #1f3d7a; color: var(--blue); }
.nav-icon { font-size: 15px; }

.header-right { flex-shrink: 0; }

.btn-3d {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 16px; border-radius: 6px;
  background: linear-gradient(135deg, #1565c0, #0d47a1);
  border: 1px solid #1976d2;
  color: #fff; font-size: 12px; font-weight: 700;
  cursor: pointer; letter-spacing: 1px;
  transition: all 0.2s;
}
.btn-3d:hover { background: linear-gradient(135deg, #1976d2, #1565c0); transform: translateY(-1px); }
.btn-3d.active {
  background: linear-gradient(135deg, #e65100, #bf360c);
  border-color: #f4511e;
}
.btn-3d-icon { font-size: 16px; }

/* ── Layout ─────────────────────────────────── */
.main-container {
  position: fixed;
  top: var(--header-h); left: 0; right: 0; bottom: 0;
  display: flex;
}

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width 0.3s, min-width 0.3s;
  position: relative;
  z-index: 100;
}
#sidebar.collapsed { width: 0; min-width: 0; }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

#sidebar-toggle {
  position: absolute; right: -14px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 40px;
  background: var(--bg3); border: 1px solid var(--border);
  border-left: none; border-radius: 0 4px 4px 0;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--text2); font-size: 10px; z-index: 101;
}

.module-panel {
  display: none; flex-direction: column; height: 100%; overflow-y: auto;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.module-panel.active { display: flex; }
.module-panel::-webkit-scrollbar { width: 4px; }
.module-panel::-webkit-scrollbar-track { background: transparent; }
.module-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.panel-title {
  font-size: 13px; font-weight: 600; color: var(--text);
  letter-spacing: 0.5px; margin-bottom: 12px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
  text-transform: uppercase;
}

/* ── Map ─────────────────────────────────────── */
#map {
  flex: 1; height: 100%;
}
.maplibregl-canvas { outline: none; }

/* ── Info Box ────────────────────────────────── */
.info-box {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 12px;
  color: var(--text2); font-size: 12px; line-height: 1.5;
  text-align: center;
}
.info-box::before { content: '↖ '; font-size: 16px; }

/* ── Parcel Info Card ────────────────────────── */
.info-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 12px; margin-bottom: 10px;
}
.info-card h4 { font-size: 12px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.info-card p  { color: var(--text2); font-size: 11px; margin-bottom: 6px; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 10px; font-weight: 600; color: #fff; margin-bottom: 4px;
}

.parcel-flags {
  display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap;
}
.flag {
  font-size: 10px; padding: 2px 6px; border-radius: 3px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text2);
}
.flag.yes { border-color: var(--green); color: var(--green); }

/* ── Metrics Grid ────────────────────────────── */
.metrics-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 6px; margin-bottom: 10px;
}
.metric {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.metric-label { font-size: 10px; color: var(--text2); }
.metric-value { font-size: 16px; font-weight: 700; color: var(--blue); }
.metric-unit  { font-size: 10px; color: var(--text2); }

/* ── Results Box ─────────────────────────────── */
.results-box {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 12px; margin-bottom: 10px;
}
.results-box h5 { font-size: 11px; color: var(--text2); margin-bottom: 8px; text-transform: uppercase; }
.result-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 4px 0; border-bottom: 1px solid var(--border); font-size: 11px;
  gap: 8px;
}
.result-row:last-child { border-bottom: none; }
.result-row span { color: var(--text2); flex: 1; }
.result-row strong { color: var(--green); white-space: nowrap; }

canvas#vol-chart { width: 100%; margin: 8px 0; }

/* ── Normativa Editor ────────────────────────── */
.norm-editor {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 12px;
}
.norm-editor h5 { font-size: 11px; color: var(--text2); margin-bottom: 8px; text-transform: uppercase; }
.norm-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 8px;
}
.norm-row label { font-size: 11px; color: var(--text2); white-space: nowrap; min-width: 110px; }
input[type=range] {
  flex: 1; accent-color: var(--blue); cursor: pointer;
  background: transparent;
}

.btn-recalc, .btn-zoom {
  width: 100%; padding: 7px; border-radius: 5px;
  border: 1px solid var(--blue); background: transparent;
  color: var(--blue); font-size: 12px; cursor: pointer;
  transition: background 0.2s;
  margin-top: 4px;
}
.btn-recalc:hover, .btn-zoom:hover { background: #1565c020; }

/* ── Section Headers ─────────────────────────── */
.filter-section, .stats-section, .market-stats, .chart-section {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
h5 {
  font-size: 11px; color: var(--text2);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 8px;
}

/* ── Toggles ─────────────────────────────────── */
.toggle-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0; cursor: pointer; font-size: 12px; color: var(--text2);
}
.toggle-row:hover { color: var(--text); }
.toggle-row input[type=checkbox] { accent-color: var(--blue); cursor: pointer; }
.tipo-dot {
  width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; display: inline-block;
}

/* ── Stats ───────────────────────────────────── */
.stat-row {
  display: flex; justify-content: space-between;
  padding: 4px 0; font-size: 12px;
  border-bottom: 1px solid var(--border);
}
.stat-row:last-child { border-bottom: none; }
.stat-row span { color: var(--text2); }
.stat-row strong { color: var(--text); }

.chart-section canvas, .market-stats canvas { max-height: 180px; }

/* ── Color Mode Select ───────────────────────── */
select {
  width: 100%; padding: 6px 8px; border-radius: 5px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); font-size: 12px; cursor: pointer;
  margin-bottom: 8px;
}
select:focus { outline: none; border-color: var(--blue); }

/* ── Properties Module ───────────────────────── */
.filter-section .filter-row {
  margin-bottom: 6px;
}
.filter-section input[type=number] {
  width: calc(50% - 10px); padding: 6px 8px; border-radius: 5px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); font-size: 12px;
}
.price-range {
  display: flex; align-items: center; gap: 6px;
}
.price-range span { color: var(--text2); }

.btn-filter {
  width: 100%; padding: 7px; border-radius: 5px;
  background: #1565c0; border: none;
  color: #fff; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background 0.2s;
}
.btn-filter:hover { background: #1976d2; }

#prop-count {
  font-size: 11px; color: var(--text2); text-align: right;
  display: block; margin-bottom: 6px;
}

.properties-list {
  display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto; flex: 1;
}

.prop-card {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 7px; padding: 10px 12px; cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.prop-card:hover {
  border-color: var(--blue); background: #1f2937;
}
.prop-card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 5px;
}
.prop-badge {
  padding: 2px 7px; border-radius: 10px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.prop-badge.sale   { background: #c62828; color: #fff; }
.prop-badge.rent   { background: #1b5e20; color: #fff; }
.prop-source { font-size: 10px; color: var(--text2); }
.prop-title  { font-size: 12px; color: var(--text); margin-bottom: 5px; line-height: 1.3; }
.prop-meta   { display: flex; gap: 8px; font-size: 10px; color: var(--text2); margin-bottom: 4px; flex-wrap: wrap; }
.prop-price  { font-size: 13px; font-weight: 700; color: var(--green); }
.prop-address { font-size: 10px; color: var(--text2); margin-top: 3px; }

.no-results { text-align: center; color: var(--text2); padding: 20px; font-size: 12px; }
.load-more-note { text-align: center; color: var(--text2); font-size: 11px; padding: 8px; }

/* ── Map Info Bar ────────────────────────────── */
.map-info-bar {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0009; backdrop-filter: blur(4px);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 3px 10px; display: flex; gap: 16px;
  font-size: 10px; color: var(--text2); z-index: 150;
  pointer-events: none;
}

/* ── Legend ──────────────────────────────────── */
.legend {
  position: fixed; bottom: 50px; right: 16px;
  background: #000c; backdrop-filter: blur(8px);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; z-index: 150; min-width: 160px;
}
.legend h5 { margin-bottom: 6px; }
.legend-item {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; color: var(--text2); padding: 2px 0;
}
.legend-swatch {
  width: 12px; height: 12px; border-radius: 2px; flex-shrink: 0;
}
.legend-swatch.round { border-radius: 50%; }

/* ── Basemap Switcher ────────────────────────── */
#basemap-switcher {
  position: fixed;
  bottom: 110px; right: 16px;
  z-index: 160;
  display: flex; flex-direction: column; gap: 4px;
}

.bm-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: #000b; backdrop-filter: blur(6px);
  border: 2px solid var(--border);
  border-radius: 7px; padding: 4px;
  cursor: pointer; width: 62px;
  transition: border-color 0.2s, transform 0.15s;
}
.bm-btn:hover    { transform: translateY(-1px); border-color: #555; }
.bm-btn.active   { border-color: var(--blue); }

.bm-thumb {
  width: 54px; height: 36px;
  border-radius: 4px; display: block;
  background-size: cover; background-position: center;
}
.bm-dark      { background: linear-gradient(135deg, #1a1a2e 40%, #0d3460 100%); }
.bm-satellite { background:
    linear-gradient(135deg, #1a3a1a 0%, #2d5a2d 30%, #5a8a4a 60%, #8ab870 80%, #4a6a8a 100%);
}

.bm-label {
  font-size: 9px; color: var(--text); letter-spacing: 0.3px;
  font-weight: 600; text-transform: uppercase;
}

/* ── Popup ───────────────────────────────────── */
.maplibregl-popup-content { background: transparent !important; padding: 0 !important; box-shadow: none !important; }
.maplibregl-popup-tip { display: none; }

.listing-popup .popup-inner {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
  min-width: 200px;
}
.popup-badge { margin-bottom: 5px; display: inline-block; padding: 2px 7px; border-radius: 10px; font-size: 10px; font-weight: 700; }
.popup-badge.sale   { background: #c62828; color: #fff; }
.popup-badge.rent   { background: #1b5e20; color: #fff; }
.popup-title  { font-size: 12px; color: var(--text); margin: 5px 0; line-height: 1.3; }
.popup-detail { font-size: 12px; color: var(--text2); }
.popup-detail strong { color: var(--green); }
.popup-source { font-size: 10px; color: var(--text2); margin-top: 4px; }
.popup-link   { display: block; margin-top: 6px; font-size: 11px; color: var(--blue); text-decoration: none; }
.popup-link:hover { text-decoration: underline; }
.popup-detail-btn {
  margin-top: 8px; width: 100%; padding: 5px; border-radius: 4px;
  background: #1565c0; border: none; color: #fff; font-size: 11px; cursor: pointer;
}
.popup-detail-btn:hover { background: #1976d2; }

/* ── Modal ───────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: #000a; display: none;
  align-items: center; justify-content: center;
  z-index: 5000; padding: 20px;
}
.modal.open { display: flex; }

.modal-content {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; padding: 20px 24px;
  max-width: 500px; width: 100%; position: relative;
  max-height: 80vh; overflow-y: auto;
}
.modal-close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; color: var(--text2);
  font-size: 18px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-prop-title { font-size: 16px; font-weight: 600; color: var(--text); margin: 8px 0; }
.modal-price { font-size: 20px; font-weight: 700; color: var(--green); margin-bottom: 14px; }
.modal-price small { font-size: 13px; color: var(--text2); margin-left: 8px; }

.modal-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
.modal-table td { padding: 6px 4px; border-bottom: 1px solid var(--border); font-size: 12px; }
.modal-table td:first-child { color: var(--text2); width: 40%; }
.modal-table td:last-child  { color: var(--text); font-weight: 500; }

.modal-desc {
  font-size: 12px; color: var(--text2); line-height: 1.5;
  margin-bottom: 14px; max-height: 120px; overflow-y: auto;
}
.modal-link {
  display: inline-block; padding: 8px 16px; border-radius: 6px;
  background: #1565c0; color: #fff; text-decoration: none; font-size: 12px;
}
.modal-link:hover { background: #1976d2; }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 700px) {
  :root { --sidebar-w: 100vw; }
  .nav-label { display: none; }
  .btn-3d span:last-child { display: none; }
  #sidebar { position: absolute; top: 0; bottom: 0; z-index: 300; }
}
