/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --header-h:   44px;
  --options-w:  260px;
  --info-w:     340px;
  --border:     #ccc;
  --bg-panel:   #f7f8fa;
  --bg-header:  #1a3a1f;
  --accent:     #2d6a37;
  --red-hi:     #c80000;
  --font:       'Segoe UI', system-ui, sans-serif;
}

html, body { height: 100%; overflow: hidden; font-family: var(--font); font-size: 14px; }

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  height: var(--header-h);
  background: var(--bg-header);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  font-size: 15px;
  font-weight: 500;
  flex-shrink: 0;
  z-index: 1000;
  position: relative;
}
header .logo {
  background: #fff;
  color: var(--bg-header);
  font-weight: 700;
  font-size: 13px;
  padding: 2px 7px;
  border-radius: 3px;
  letter-spacing: 1px;
}
header .subtitle {
  margin-left: auto;
  font-size: 13px;
  opacity: 0.75;
  font-style: italic;
}

/* ── Workspace (3-panel) ─────────────────────────────────────────────────── */
.workspace {
  display: flex;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

.panel { display: flex; flex-direction: column; }

/* Left panel */
.panel-options {
  width: var(--options-w);
  min-width: var(--options-w);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

/* Scrollable middle section — legend stays pinned below this */
.options-scroll {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* Map panel */
.panel-map { flex: 1; position: relative; }

/* Right panel */
.panel-info {
  width: var(--info-w);
  min-width: var(--info-w);
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

/* ── Panel title bar ─────────────────────────────────────────────────────── */
.panel-title {
  padding: 10px 14px 8px;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #444;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* Info panel title bar (title + save button side by side) */
.panel-title-bar {
  display: flex;
  align-items: center;
  padding: 7px 8px 7px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 6px;
}
.panel-title-text {
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #444;
  flex: 1;
}
.save-pdf-btn {
  flex-shrink: 0;
  padding: 3px 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.3px;
  white-space: nowrap;
  transition: background 0.15s;
}
.save-pdf-btn:hover { background: #1e4d28; }
.save-pdf-btn:disabled { background: #888; cursor: default; }
.save-pdf-btn.hidden { display: none; }

/* ── Section headers (Models / Layers) ──────────────────────────────────── */
.section-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: #fff;
  background: var(--accent);
  padding: 4px 12px;
  flex-shrink: 0;
}
.section-header-layers {
  border-top: 1px solid var(--border);
}

/* ── Model list ──────────────────────────────────────────────────────────── */
.model-list {
  flex-shrink: 0;
  max-height: 32vh;
  overflow-y: auto;
  padding: 3px 0 4px;
  border-bottom: 1px solid var(--border);
}
.model-item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 5px 12px;
  cursor: pointer;
  transition: background 0.1s;
  line-height: 1.3;
}
.model-item:hover  { background: #e8ede9; }
.model-item.selected { background: #d0e4d4; }
.model-item input[type=radio] { accent-color: var(--accent); flex-shrink: 0; margin-top: 3px; }
.model-text { display: flex; flex-direction: column; }
.model-name { font-size: 13px; font-weight: 600; color: #222; }
.model-desc { font-size: 11px; color: #777; margin-top: 1px; }

/* ── Layer search ────────────────────────────────────────────────────────── */
.layer-search-wrap {
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
}
#layer-search {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid #bbb;
  border-radius: 4px;
  font-size: 13px;
  outline: none;
  min-width: 0;
}
#layer-search:focus { border-color: var(--accent); }
#layer-search-clear {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: none;
  background: #ccc;
  color: #555;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
}
#layer-search-clear:hover { background: #aaa; color: #222; }
#layer-search-clear.visible { display: flex; }

/* ── Layer list ──────────────────────────────────────────────────────────── */
.layer-list {
  flex: 1;
  overflow-y: auto;
  min-height: 60px;
  padding: 4px 0 8px;
}
.layer-group-header {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
  padding: 8px 12px 3px;
}
.layer-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.1s;
  line-height: 1.3;
}
.layer-item:hover { background: #e8ede9; }
.layer-item.selected { background: #d0e4d4; }
.layer-item input[type=radio] { accent-color: var(--accent); flex-shrink: 0; }
.layer-name { font-size: 13px; color: #222; }
.layer-multiplier {
  margin-left: auto;
  font-size: 11px;
  color: #999;
  white-space: nowrap;
}

/* ── Legend ──────────────────────────────────────────────────────────────── */
.legend {
  border-top: 1px solid var(--border);
  padding: 10px 14px 12px;
  flex-shrink: 0;
}
.legend-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 5px;
}
.legend-bar {
  height: 12px;
  border-radius: 3px;
  background: linear-gradient(to right, #ffffff, #c80000);
  border: 1px solid #ccc;
  margin-bottom: 3px;
}
.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #666;
  margin-bottom: 8px;
}
.legend-items { display: flex; flex-direction: column; gap: 4px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12px; color: #555; }
.swatch {
  display: inline-block;
  width: 18px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}
.swatch-conserved {
  background: repeating-linear-gradient(
    45deg,
    rgba(34,170,68,0.15),
    rgba(34,170,68,0.15) 3px,
    rgba(34,170,68,0.5) 3px,
    rgba(34,170,68,0.5) 5px
  );
  border: 1.5px solid #22aa44;
}
.swatch-nodata { background: #dddddd; border: 1px solid #bbb; }

/* ── Parcel info panel ───────────────────────────────────────────────────── */
.info-placeholder {
  padding: 20px 14px;
  color: #888;
  font-style: italic;
  font-size: 13px;
}

#info-content { flex: 1; overflow-y: auto; }

.parcel-meta {
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.parcel-meta h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #1a1a1a;
}
.parcel-meta .meta-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 2px 0; }
.parcel-meta .meta-kv { color: #555; }
.parcel-meta .meta-kv strong { color: #222; }

.conserved-badge {
  display: inline-block;
  background: #22aa44;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-top: 4px;
}

.scores-section { padding: 8px 0 12px; }

.scores-cat-header {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #888;
  padding: 6px 14px 3px;
}

.score-row {
  display: grid;
  grid-template-columns: 16px 1fr 52px;
  gap: 4px;
  align-items: center;
  padding: 5px 14px 5px 10px;
  border-bottom: 1px solid #eee;
  font-size: 12px;
  cursor: default;
}
.score-row:hover { background: #f0f4f1; }
.score-layer-name { font-weight: 500; color: #222; }
.score-label { color: #555; font-size: 11px; margin-top: 1px; }
.score-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 12px;
  align-self: center;
  color: #fff;
  min-width: 44px;
}

/* ── Info icon ───────────────────────────────────────────────────────────── */
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid #bbb;
  color: #999;
  font-size: 9px;
  font-style: italic;
  font-weight: 700;
  font-family: Georgia, serif;
  cursor: default;
  flex-shrink: 0;
  line-height: 1;
  user-select: none;
}
.info-icon:hover { color: var(--accent); border-color: var(--accent); }

/* ── Custom floating tooltip ─────────────────────────────────────────────── */
.cpa-info-tip {
  position: fixed;
  z-index: 99999;
  background: #1e2b20;
  color: #e8ede9;
  border-radius: 6px;
  padding: 8px 11px;
  font-size: 12px;
  max-width: 230px;
  line-height: 1.5;
  pointer-events: none;
  box-shadow: 0 3px 10px rgba(0,0,0,0.35);
  display: none;
}
.cpa-info-tip.visible { display: block; }
.tip-section {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid rgba(255,255,255,0.15);
}

/* ── Loading overlay ─────────────────────────────────────────────────────── */
#loading {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  font-size: 15px;
  color: #444;
  gap: 10px;
}
#loading.hidden { display: none; }
.spinner {
  width: 22px; height: 22px;
  border: 3px solid #ccc;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Leaflet overrides ───────────────────────────────────────────────────── */
.leaflet-container { font-family: var(--font); }
.leaflet-popup-content-wrapper { border-radius: 6px; }
.leaflet-popup-content { margin: 8px 12px; font-size: 13px; }
