:root {
  --bg: #0f1f1a;
  --panel: rgba(255,255,255,0.94);
  --panel-dark: rgba(16,37,29,0.94);
  --text: #1b2a25;
  --muted: #66756f;
  --line: rgba(20,50,38,0.12);
  --green: #1f7a4c;
  --green-2: #36a96f;
  --green-soft: #e8f6ee;
  --yellow: #eebf45;
  --orange: #e36f3c;
  --red: #c83232;
  --violet: #6741d9;
  --shadow: 0 18px 60px rgba(0,0,0,0.18);
  --radius: 18px;
  --topbar-height: 68px;
  --timeline-height: 58px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); overflow: hidden; }
button, input, select { font: inherit; }
a { color: inherit; }
.noscript { padding: 16px; background: #fff6d6; color: #432; }

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: grid;
  grid-template-columns: 344px 1fr 376px;
  grid-template-rows: var(--topbar-height) 1fr var(--timeline-height);
  grid-template-areas:
    "topbar topbar topbar"
    "left map right"
    "timeline timeline timeline";
}

.topbar {
  grid-area: topbar;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-width: 0;
  padding: 10px 16px;
  background: linear-gradient(90deg, #10251d 0%, #173a2b 58%, #213f35 100%);
  color: #fff;
  box-shadow: 0 8px 28px rgba(0,0,0,.18);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { width: 46px; height: 46px; flex: 0 0 auto; }
.brand-title { font-size: 1.24rem; font-weight: 800; letter-spacing: .01em; white-space: nowrap; }
.brand-subtitle { color: #cfe8db; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }

.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.top-link, .lang-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.08);
  color: #fff;
  border-radius: 999px;
  padding: 0 12px;
  text-decoration: none;
  cursor: pointer;
  transition: .18s ease;
}
.top-link:hover, .lang-link:hover { background: rgba(255,255,255,.18); transform: translateY(-1px); }
.lang-switch { display: inline-flex; gap: 4px; padding: 3px; border-radius: 999px; background: rgba(255,255,255,.12); }
.lang-link { min-height: 30px; padding: 0 10px; border: 0; font-weight: 700; }
.lang-link.active { background: #fff; color: #173a2b; }
.mobile-menu-button { display: none; }

.left-panel, .right-panel {
  z-index: 20;
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  backdrop-filter: blur(18px);
}
.left-panel { grid-area: left; border-right: 1px solid var(--line); padding: 16px; }
.right-panel { grid-area: right; border-left: 1px solid var(--line); }

.map-area { grid-area: map; position: relative; min-width: 0; min-height: 0; }
.map { position: absolute; inset: 0; }
.map-status {
  position: absolute;
  left: 16px;
  bottom: 76px;
  z-index: 10;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(16,37,29,.9);
  color: #fff;
  font-size: .86rem;
  box-shadow: var(--shadow);
}
.map-status.hidden { display: none; }

.panel-section { border-bottom: 1px solid var(--line); padding: 0 0 16px 0; margin-bottom: 16px; }
.panel-section:last-child { border-bottom: 0; margin-bottom: 0; }
.section-heading, .section-label {
  display: block;
  margin-bottom: 10px;
  font-size: .82rem;
  line-height: 1.1;
  color: #234438;
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 800;
}

.search-box { display: flex; align-items: center; gap: 6px; }
.search-box input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid rgba(25,67,48,.18);
  background: #fff;
  border-radius: 12px;
  padding: 0 12px;
  outline: 0;
}
.search-box input:focus, select:focus { border-color: var(--green-2); box-shadow: 0 0 0 4px rgba(54,169,111,.13); }
.search-box button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  background: #edf4ef;
  color: #285141;
  cursor: pointer;
  font-size: 1.25rem;
}
.search-results { margin-top: 8px; display: grid; gap: 6px; }
.search-item {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 9px 10px;
  cursor: pointer;
}
.search-item:hover { border-color: var(--green-2); background: var(--green-soft); }
.search-item-title { font-weight: 800; }
.search-item-meta { color: var(--muted); font-size: .84rem; margin-top: 2px; }

.scenario-list { display: grid; gap: 8px; }
.scenario-button {
  width: 100%;
  border: 1px solid rgba(31,122,76,.16);
  background: #fff;
  color: #173a2b;
  border-radius: 14px;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  transition: .18s ease;
}
.scenario-button:hover, .scenario-button.active { background: var(--green-soft); border-color: var(--green-2); }
.scenario-title { display: block; font-weight: 800; }
.scenario-desc { display: block; margin-top: 4px; font-size: .82rem; color: var(--muted); }

.filters-section select { margin-bottom: 10px; }
.filter-label { display: block; margin: 10px 0 5px 0; font-size: .84rem; color: var(--muted); font-weight: 700; }
.layer-groups { display: grid; gap: 10px; }
.layer-group { border: 1px solid var(--line); border-radius: 16px; background: #fff; overflow: hidden; }
.layer-group-title {
  padding: 10px 12px;
  background: #f5faf7;
  font-weight: 900;
  display: flex;
  justify-content: space-between;
  cursor: pointer;
}
.layer-group-body { padding: 8px 10px 10px 10px; display: grid; gap: 8px; }
.layer-toggle { display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 8px; }
.layer-toggle input { accent-color: var(--green); }
.layer-title { font-size: .92rem; }
.layer-badge { font-size: .68rem; padding: 2px 7px; border-radius: 999px; background: #edf4ef; color: #285141; text-transform: uppercase; }

.details-panel { padding: 18px; }
.empty-details {
  min-height: calc(100vh - var(--topbar-height) - var(--timeline-height) - 36px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
}
.empty-kicker { font-weight: 900; color: var(--green); text-transform: uppercase; letter-spacing: .08em; font-size: .82rem; }
.empty-title { font-size: 1.85rem; line-height: 1.1; font-weight: 900; color: #142b22; }
.empty-text { color: var(--muted); line-height: 1.55; }
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; margin: 14px 0; }
.stat-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.stat-value { font-size: 1.35rem; font-weight: 900; color: #142b22; }
.stat-label { margin-top: 3px; color: var(--muted); font-size: .78rem; }
.area-title { font-size: 1.55rem; font-weight: 900; line-height: 1.12; }
.area-meta { color: var(--muted); margin-top: 6px; line-height: 1.4; }
.impact-pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 10px; font-weight: 800; font-size: .8rem; margin-top: 12px; }
.impact-high { background: #ffe8e8; color: #9f1e1e; }
.impact-medium { background: #fff4d7; color: #8f5f00; }
.impact-low { background: #e7f6ee; color: #1c6d43; }
.details-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.action-button {
  min-height: 38px;
  border: 1px solid rgba(31,122,76,.18);
  background: #fff;
  border-radius: 999px;
  padding: 0 12px;
  cursor: pointer;
  color: #173a2b;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 750;
}
.action-button.primary { background: var(--green); color: #fff; border-color: var(--green); }
.timeline-list { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.timeline-row { display: grid; grid-template-columns: 72px 1fr; gap: 8px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.timeline-row:last-child { border-bottom: 0; }
.timeline-date { color: var(--muted); font-weight: 800; }

.legend {
  position: absolute;
  left: 16px;
  top: 16px;
  z-index: 12;
  min-width: 210px;
  max-width: 280px;
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(20,50,38,.12);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 12px;
  display: grid;
  gap: 8px;
}
.legend-title { font-weight: 900; color: #142b22; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: .84rem; color: #253c34; }
.legend-symbol { width: 20px; height: 12px; border-radius: 3px; border: 1px solid rgba(0,0,0,.16); flex: 0 0 auto; }
.legend-line { height: 0; border-top: 3px solid #222; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; }
.damage-gradient { background: linear-gradient(90deg, #f2d35b, #e36f3c, #c83232, #6741d9); }

.map-tooltip {
  position: absolute;
  z-index: 15;
  display: none;
  pointer-events: none;
  background: rgba(16,37,29,.94);
  color: #fff;
  padding: 8px 10px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: .84rem;
  max-width: 280px;
}

.timeline-bar {
  grid-area: timeline;
  z-index: 25;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  background: rgba(255,255,255,.96);
  border-top: 1px solid var(--line);
}
.timeline-label { font-weight: 900; color: #234438; }
#yearRange { accent-color: var(--green); }
.selected-year { font-weight: 900; color: #173a2b; background: var(--green-soft); border-radius: 999px; padding: 7px 12px; }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5,12,9,.55);
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-card {
  width: min(820px, 96vw);
  max-height: min(720px, 88vh);
  overflow: auto;
  border-radius: 24px;
  background: #fff;
  box-shadow: var(--shadow);
  padding: 24px;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: #edf4ef;
  cursor: pointer;
  font-size: 1.4rem;
}
.modal-content { line-height: 1.58; color: #344841; }
.modal-content ul { padding-left: 22px; }
.modal-content code { background: #f2f6f3; border-radius: 6px; padding: 2px 5px; }

.maplibregl-popup-content { border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); }
.maplibregl-ctrl-group { border-radius: 14px; overflow: hidden; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 318px 1fr; grid-template-areas: "topbar topbar" "left map" "timeline timeline"; }
  .right-panel {
    position: absolute;
    top: var(--topbar-height);
    right: 0;
    bottom: var(--timeline-height);
    width: 376px;
    transform: translateX(calc(100% - 18px));
    transition: transform .22s ease;
    box-shadow: var(--shadow);
  }
  .right-panel:hover, .right-panel.open { transform: translateX(0); }
}

@media (max-width: 860px) {
  body { overflow: hidden; }
  .app-shell { grid-template-columns: 1fr; grid-template-areas: "topbar" "map" "timeline"; }
  .top-actions { display: none; }
  .mobile-menu-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: 1px solid rgba(255,255,255,.2);
    color: #fff;
    background: rgba(255,255,255,.1);
    border-radius: 12px;
    font-size: 1.2rem;
  }
  .left-panel {
    position: fixed;
    top: var(--topbar-height);
    bottom: var(--timeline-height);
    left: 0;
    width: min(342px, 92vw);
    transform: translateX(-100%);
    transition: transform .24s ease;
    box-shadow: var(--shadow);
  }
  .left-panel.open { transform: translateX(0); }
  .right-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: var(--timeline-height);
    width: 100%;
    max-height: 46vh;
    transform: translateY(calc(100% - 28px));
    border-radius: 22px 22px 0 0;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
  .right-panel:hover, .right-panel.open { transform: translateY(0); }
  .legend { top: auto; left: 12px; bottom: 74px; min-width: 180px; max-width: calc(100vw - 24px); }
  .timeline-bar { grid-template-columns: 1fr auto; gap: 8px; }
  .timeline-label { display: none; }
  .brand-subtitle { display: none; }
  .brand-title { font-size: 1.05rem; }
  .brand-logo { width: 40px; height: 40px; }
  .modal-card { padding: 20px; }
}
