/* ═══════════════════════════════════════════════════════
   VAISTO — uusi ulkoasu
   app.js pysyy koskemattomana: kaikki ID:t ja toiminnot
   säilytetty ennallaan.
════════════════════════════════════════════════════════ */

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  color: #1a1a1a;
  background: #f0f2f5;
}

/* ─── Layout: sidebar + map-area ──────────────────── */
body {
  display: flex;
  height: 100vh;
}

/* ─── VASEN PANEELI ────────────────────────────────── */
#sidebar {
  width: 220px;
  min-width: 220px;
  height: 100vh;
  background: #1c2333;
  color: #c8d0e0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  flex-shrink: 0;
}

/* Scrollbar paneelissa */
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }

/* Logo */
#sidebar-logo {
  padding: 14px 16px 12px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #7ec87e;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

/* ── Panel section ── */
.panel-section {
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

/* Section header / toggle */
.section-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: none;
  border: none;
  color: #e2e8f0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s;
}
.section-toggle:hover { background: rgba(255,255,255,0.05); }
.section-toggle .toggle-arrow {
  font-size: 12px;
  color: #6b7a99;
  transition: transform 0.2s;
  display: inline-block;
}
.section-toggle.open .toggle-arrow { transform: rotate(180deg); }

/* Section body (accordion) */
.section-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}
.section-body.open {
  max-height: 800px; /* riittää kaikelle sisällölle */
}

/* Sub-section label */
.subsection-label {
  padding: 10px 16px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #9db5c8;
  border-top: 1px solid rgba(255,255,255,0.18);
  margin-top: 2px;
}
.section-body > .subsection-label:first-child,
.subsection-label[style*="margin-top:0"] {
  border-top: none;
  margin-top: 0;
}

/* Button group */
.btn-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 8px 8px;
}

/* ── Pohjakartta-napit ── */
.map-btn {
  background: transparent;
  border: none;
  color: #a8b8c8;
  padding: 7px 8px;
  border-radius: 6px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.map-btn:hover { background: rgba(255,255,255,0.07); color: #e2e8f0; }
.map-btn.active {
  background: rgba(126, 200, 126, 0.15);
  color: #7ec87e;
  font-weight: 600;
}

/* ── Toggle-napit (Näytä kartalla) — syaaninsininen ── */
.toggle-btn {
  background: transparent;
  border: none;
  color: #7ec8c8;
  padding: 7px 8px;
  border-radius: 6px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.toggle-btn:hover { background: rgba(126,200,200,0.1); color: #a8e0e0; }
.toggle-btn.active {
  background: rgba(126,200,200,0.15);
  color: #a8e0e0;
}

/* ── Sovellus-linkit — sininen ── */
.app-link-btn {
  background: transparent;
  border: none;
  color: #7da8d8;
  padding: 7px 8px;
  border-radius: 6px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.12s, color 0.12s;
}
.app-link-btn:hover { background: rgba(125,168,216,0.12); color: #a8c8ee; }

/* ── Työkalu-napit — oranssi/keltainen ── */
.tool-btn {
  background: transparent;
  border: none;
  color: #c8a86a;
  padding: 7px 8px;
  border-radius: 6px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.tool-btn:hover { background: rgba(200,168,106,0.1); color: #e0c080; }
.tool-btn.active {
  background: rgba(200,168,106,0.15);
  color: #e0c080;
}
.tool-btn.danger { color: #f87171; }
.tool-btn.danger:hover { background: rgba(248,113,113,0.1); color: #fca5a5; }

/* ── Mittaa-napit — violetin sävy ── */
.tool-btn[onclick*="mittaa"],
.tool-btn[onclick*="poistaMittaukset"] {
  color: #b09ad8;
}
.tool-btn[onclick*="mittaa"]:hover,
.tool-btn[onclick*="poistaMittaukset"]:hover {
  background: rgba(176,154,216,0.1);
  color: #cbbfea;
}

/* ── PeltoAnalyysi erikoisväri ── */
#lpisBtn { color: #f6d860; }
#lpisBtn:hover { background: rgba(246,216,96,0.1); color: #fde68a; }

/* ── Tulva / pohjavesi / maa-aines active-tila ── */
#tulvaBtn.active, #tulvaRaporttiBtn.active { color: #60a5fa; background: rgba(96,165,250,0.12); }
#pohjavesiBtn.active, #pohjavesiRaporttiBtn.active { color: #67e8f9; background: rgba(103,232,249,0.1); }
#maaAinesBtn.active, #maaAinesRaporttiBtn.active { color: #d1d5db; background: rgba(209,213,219,0.1); }

/* ─── KARTTA-ALUE ──────────────────────────────────── */
#map-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* ─── HAKUPALKKI KARTAN PÄÄLLÄ ─────────────────────── */
#map-toolbar {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 16px;
}

#search-bar {
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.1);
}

#tunnukset {
  border: none;
  outline: none;
  padding: 8px 12px;
  font-size: 13px;
  width: 450px;
  background: transparent;
  color: #1a1a1a;
}
#tunnukset::placeholder { color: #aaa; }

#haeBtn {
  background: #7ec87e;
  color: #1c2333;
  border: none;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
#haeBtn:hover { background: #6dba6d; }

/* Kamera-painike */
#kameraBtn {
  background: #1c2333;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
  height: 40px;
}
#kameraBtn:hover { background: #2d3a52; transform: translateY(-1px); }
#kameraBtn:active { transform: translateY(0); }

/* ─── KARTTA ────────────────────────────────────────── */
#karttaWrapper {
  position: relative;
  flex: 1;
  width: 100%;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}

/* ─── RAPORTTIPANEELI ───────────────────────────────── */
#raportti {
  position: absolute;
  top: 60px;
  left: 12px;
  width: 420px;
  max-width: 70vw;
  min-width: 300px;
  max-height: 65vh;
  overflow-y: auto;
  background: rgba(255,255,255,0.97);
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 12px;
  font-family: "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 6px 24px rgba(0,0,0,0.15);
  z-index: 2000;
  display: none;
}
#raportti div:first-child { font-weight: 700; margin-bottom: 6px; }


/* ─── KARTTA-LABELIT (säilytetty app.js:ää varten) ── */
.ktunnus-label .ktunnus-box {
  display: inline-block;
  font-size: 13px;
  font-weight: bold;
  background: white;
  border: 2px solid #333;
  border-radius: 6px;
  padding: 5px 9px;
  min-width: 160px;
  text-align: left;
  color: black;
  white-space: nowrap;
  box-shadow: 2px 2px 6px rgba(0,0,0,0.25);
  transform: scale(var(--label-scale, 1));
  transform-origin: center center;
  will-change: transform;
}

.ktunnus-box {
  transform: scale(var(--label-scale, 1)) !important;
  transform-origin: center center;
  display: inline-block;
}

.area-tooltip {
  background: white;
  border: 2px solid #000;
  color: #111;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 6px;
}

.area-label {
  background: white;
  border: 2px solid #000;
  border-radius: 6px;
  padding: 6px 10px;
  min-width: 70px;
  text-align: center;
  font-family: sans-serif;
  font-size: 14px;
  font-weight: bold;
  white-space: nowrap;
  box-shadow: 2px 2px 6px rgba(0,0,0,0.3);
}

.pelto-label {
  min-width: 160px;
  text-align: center;
  background: #ffeb3b;
  border: 2px solid #000;
  color: #000;
  font-weight: 700;
  white-space: nowrap;
  transform: scale(var(--label-scale, 1));
  transform-origin: center center;
  display: inline-block;
}

.raportti-summa {
  font-size: 15px;
  font-weight: 700;
  margin-top: 8px;
}

/* ─── Liukusäädin (säilytetty) ──────────────────────── */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 5px;
  background: linear-gradient(to right, #1976d2 50%, #ddd 50%);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: #fff;
  border: 2px solid #1976d2;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  transition: transform 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: #fff;
  border: 2px solid #1976d2;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

/* ─── PANEELIN ALAREUNA ─────────────────────────────── */
#sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#sidebar-footer a {
  font-size: 10px;
  color: #4a5568;
  text-decoration: none;
  line-height: 1.4;
  transition: color 0.12s;
}
#sidebar-footer a:hover { color: #7ec87e; }
#haku-konteksti {
  position: absolute;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctx-btn {
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  background: rgba(255,255,255,0.95);
}

/* Punainen kehys — rakennukset/tunnukset näkyvissä, voi poistaa */
.ctx-piilota {
  border: 1.5px solid #dc2626;
  color: #b91c1c;
}
.ctx-piilota:hover {
  background: rgba(220,38,38,0.06);
}

/* Vihreä kehys — piilotettu, voi palauttaa */
.ctx-nayta {
  border: 1.5px solid #16a34a;
  color: #15803d;
}
.ctx-nayta:hover {
  background: rgba(22,163,74,0.06);
}
/* Vanha #controls-div ei ole enää HTML:ssä, joten tätä
   ei tarvita. Jätetään tyhjänä varmuuden vuoksi. */
#controls { display: none !important; }