/* =========================================================================
   Land Purchase Suitability Study in Portugal — styles
   ========================================================================= */
:root {
  --green: #1a7a3c;
  --green-dark: #0f5a2a;
  --ink: #1f2933;
  --ink-soft: #52606d;
  --line: #e1e6eb;
  --bg: #f5f7f9;
  --panel-w: 320px;
  --header-h: 60px;
  --shadow: 0 2px 12px rgba(0,0,0,.12);
  --radius: 10px;
  --amber: #b7791f;
  font-synthesis: none;
}

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

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

/* ----------------------------- HEADER ----------------------------- */
#app-header {
  height: var(--header-h);
  background: linear-gradient(95deg, var(--green-dark), var(--green));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 1200;
}
.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-titles { min-width: 0; }
#app-title {
  font-size: 1.06rem;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#app-subtitle {
  font-size: .74rem;
  opacity: .9;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.35);
  color: #fff;
  padding: 8px 13px;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.header-btn:hover { background: rgba(255,255,255,.28); }
.header-btn.lang { min-width: 44px; justify-content: center; }
.info-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; color: var(--green-dark);
  font-style: italic; font-weight: 700; font-size: .8rem;
  font-family: Georgia, serif;
}

/* Hamburger */
.icon-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 38px; height: 38px;
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn span { display: block; height: 2px; width: 20px; background: #fff; margin: 0 auto; }

/* ----------------------------- BODY LAYOUT ----------------------------- */
#app-body {
  display: flex;
  height: calc(100% - var(--header-h));
}

/* ----------------------------- CONTROL PANEL ----------------------------- */
#control-panel {
  width: var(--panel-w);
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 4px 0 24px;
  z-index: 1100;
}
.panel-section { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.panel-section h2 {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
  margin-bottom: 12px;
  font-weight: 700;
}

/* View toggle */
.view-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}
.view-btn {
  flex: 1;
  padding: 8px 6px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  transition: all .15s;
}
.view-btn.active { background: var(--green); color: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.15); }

/* Layer + basemap radios */
.layer-list, .basemap-list { display: flex; flex-direction: column; gap: 2px; }
.radio-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .87rem;
  transition: background .12s;
}
.radio-row:hover { background: var(--bg); }
.radio-row input { accent-color: var(--green); width: 16px; height: 16px; cursor: pointer; flex-shrink: 0; }
.radio-row.selected { background: #eaf5ee; font-weight: 600; }
.radio-row .swatch {
  width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0;
  border: 1px solid rgba(0,0,0,.15);
}

/* Opacity */
.opacity-label { display: block; font-size: .8rem; color: var(--ink-soft); font-weight: 600; }
.opacity-label input { width: 100%; margin-top: 10px; accent-color: var(--green); cursor: pointer; }

/* Legend */
.legend { font-size: .8rem; }
.legend-title { font-weight: 600; margin-bottom: 10px; color: var(--ink); }
.legend-bar {
  height: 16px;
  border-radius: 4px;
  background: linear-gradient(to right,
    #a50026, #d73027, #f46d43, #fdae61, #fee08b,
    #d9ef8b, #a6d96a, #66bd63, #1a9850, #006837);
  border: 1px solid rgba(0,0,0,.1);
}
.legend-scale { display: flex; justify-content: space-between; margin-top: 5px; color: var(--ink-soft); font-size: .72rem; }
.legend-nodata { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: var(--ink-soft); }
.legend-nodata .box {
  width: 14px; height: 14px; border-radius: 3px;
  background: repeating-linear-gradient(45deg,#d9dde1,#d9dde1 3px,#eef1f3 3px,#eef1f3 6px);
  border: 1px solid rgba(0,0,0,.12);
}
.legend-note { margin-top: 10px; font-size: .72rem; color: var(--ink-soft); font-style: italic; }

/* Disclaimer */
.disclaimer-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #e0e6ea;
}
.disclaimer-section h2 {
  font-size: .95rem;
  margin-bottom: 12px;
  color: #8b4513;
}
.disclaimer-text {
  font-size: .72rem;
  line-height: 1.5;
  color: #555;
  margin-bottom: 10px;
  text-align: justify;
}
.disclaimer-link {
  font-size: .75rem;
  margin: 0;
}
.disclaimer-link a {
  color: var(--green);
  text-decoration: none;
  font-weight: 600;
  transition: color .15s;
}
.disclaimer-link a:hover {
  color: #0d4a23;
  text-decoration: underline;
}

/* ----------------------------- MAP ----------------------------- */
#map-wrap { position: relative; flex: 1; min-width: 0; }
#map { width: 100%; height: 100%; background: #dfe6ea; }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(255,255,255,.7);
  backdrop-filter: blur(2px);
  z-index: 800;
  font-weight: 600;
  color: var(--ink-soft);
}
.spinner {
  width: 42px; height: 42px;
  border: 4px solid #cfd8dd;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* ----------------------------- POPUP ----------------------------- */
.leaflet-popup-content-wrapper { border-radius: 10px; box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 0; width: 280px !important; }
.muni-popup { font-size: .85rem; }
.muni-popup .pop-head {
  background: linear-gradient(95deg, var(--green-dark), var(--green));
  color: #fff;
  padding: 12px 14px;
  border-radius: 10px 10px 0 0;
}
.muni-popup .pop-name { font-size: 1.05rem; font-weight: 700; line-height: 1.2; }
.muni-popup .pop-sub { font-size: .76rem; opacity: .92; margin-top: 2px; }
.muni-popup .pop-score-big {
  display: flex; align-items: baseline; gap: 6px;
  margin-top: 8px;
}
.muni-popup .pop-score-big .val { font-size: 1.7rem; font-weight: 800; }
.muni-popup .pop-score-big .max { font-size: .8rem; opacity: .85; }
.muni-popup .pop-score-big .lbl { font-size: .72rem; opacity: .9; margin-left: auto; text-align: right; }
.muni-popup .pop-body { padding: 10px 14px 14px; }
.pop-bar-row { margin: 7px 0; }
.pop-bar-row .pb-top { display: flex; justify-content: space-between; font-size: .76rem; margin-bottom: 3px; }
.pop-bar-row .pb-top .pb-val { font-weight: 700; }
.pop-bar { height: 7px; border-radius: 4px; background: var(--line); overflow: hidden; }
.pop-bar > span { display: block; height: 100%; border-radius: 4px; }
.pop-meta { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: .78rem; color: var(--ink-soft); }
.pop-meta div { display: flex; justify-content: space-between; gap: 8px; margin: 3px 0; }
.pop-meta b { color: var(--ink); font-weight: 600; }
.pop-just {
  margin-top: 10px; padding: 8px 10px;
  background: #eaf5ee; border-left: 3px solid var(--green);
  border-radius: 4px; font-size: .78rem; color: var(--ink);
}
.pop-raster-hint { padding: 12px 14px; font-size: .82rem; color: var(--ink-soft); line-height: 1.45; }

/* ----------------------------- MODAL ----------------------------- */
.modal { position: fixed; inset: 0; z-index: 2000; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15,25,20,.55); backdrop-filter: blur(2px); }
.modal-box {
  position: relative;
  width: min(920px, 94vw);
  height: min(82vh, 760px);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 50px rgba(0,0,0,.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-close {
  position: absolute; top: 10px; right: 14px;
  background: transparent; border: none; font-size: 1.8rem; line-height: 1;
  color: var(--ink-soft); cursor: pointer; z-index: 3; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg); color: var(--ink); }
.modal-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 16px 18px 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.modal-tab {
  padding: 9px 14px;
  border: none;
  background: transparent;
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.modal-tab:hover { color: var(--green); }
.modal-tab.active { color: var(--green-dark); border-bottom-color: var(--green); background: #fff; }
.modal-content {
  padding: 24px 30px 40px;
  overflow-y: auto;
  line-height: 1.6;
  font-size: .92rem;
}
.modal-content h3 { color: var(--green-dark); font-size: 1.15rem; margin: 20px 0 10px; }
.modal-content h3:first-child { margin-top: 0; }
.modal-content h4 { color: var(--ink); font-size: 1rem; margin: 14px 0 6px; }
.modal-content p { margin: 8px 0; color: var(--ink); }
.modal-content ul, .modal-content ol { margin: 8px 0 8px 22px; }
.modal-content li { margin: 5px 0; }
.modal-content .info-note {
  background: #fff8e6; border-left: 4px solid var(--amber);
  padding: 10px 14px; border-radius: 6px; margin: 14px 0; font-size: .88rem;
}
.formula {
  background: #0f2417; color: #c6f6d5;
  padding: 12px 16px; border-radius: 8px; font-size: 1rem;
  text-align: center; margin: 12px 0; font-family: "SF Mono", Menlo, monospace;
}
.info-table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: .85rem; }
.info-table th, .info-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.info-table th { background: var(--bg); font-weight: 700; color: var(--ink); }
.info-table td.ok { color: var(--green); font-weight: 600; }
.info-table td.warn { color: var(--amber); font-weight: 600; }
.info-table .chip { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: middle; margin-right: 6px; }

/* ----------------------------- RESPONSIVE ----------------------------- */
@media (max-width: 820px) {
  :root { --header-h: 56px; }
  .icon-btn { display: flex; }
  #app-title { font-size: .92rem; white-space: normal; }
  #app-subtitle { display: none; }
  .header-btn .btn-text { display: none; }
  .header-btn { padding: 8px 11px; }

  #control-panel {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: 84vw; max-width: 330px;
    transform: translateX(-105%);
    transition: transform .25s ease;
    box-shadow: var(--shadow);
  }
  #control-panel.open { transform: translateX(0); }
  #app-body { position: relative; }

  .modal-content { padding: 18px 18px 36px; }
  .leaflet-popup-content { width: 240px !important; }
}

@media (max-width: 480px) {
  #app-title { font-size: .82rem; }
}

/* Panel scrim on mobile */
#panel-scrim {
  display: none;
  position: absolute; inset: 0;
  background: rgba(0,0,0,.35); z-index: 1050;
}
#panel-scrim.show { display: block; }
