:root {
  --bg: #0f1512;
  --panel: #161f1a;
  --border: #2a362f;
  --text: #e8efe9;
  --muted: #9db3a3;
  --accent: #f0b429;
  --accent-2: #2f9e5b;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  position: relative;
  display: flex;
  height: 100vh;
  width: 100vw;
}

#sidebar {
  width: 380px;
  min-width: 380px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 18px;
  overflow-y: auto;
  transition: width 0.25s ease, min-width 0.25s ease, padding 0.25s ease, border-color 0.25s ease;
}

#sidebar.collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border-right-color: transparent;
}

#sidebar-toggle {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 1000;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
#sidebar-toggle:hover { background: #1d2a22; }

#map {
  flex: 1;
  height: 100%;
}

h1 { font-size: 1.25rem; margin: 0 0 2px; }
.subtitle { color: var(--muted); font-size: 0.85rem; margin: 0 0 16px; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.tab-btn {
  flex: 1;
  padding: 8px 6px;
  background: #1d2a22;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.78rem;
}
.tab-btn.active { background: var(--accent-2); color: white; border-color: var(--accent-2); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 10px;
}

input, select {
  width: 100%;
  margin-top: 4px;
  padding: 7px 8px;
  background: #10170f + 0;
  background: #0d1310;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 5px;
  font-size: 0.85rem;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 12px;
  padding: 10px;
}
legend { font-size: 0.75rem; color: var(--accent); padding: 0 4px; }

.hint { font-size: 0.75rem; color: var(--muted); line-height: 1.4; }

button, .primary, .secondary {
  display: block;
  width: 100%;
  padding: 10px;
  border-radius: 6px;
  border: none;
  font-size: 0.85rem;
  cursor: pointer;
  margin-bottom: 10px;
  text-align: center;
  text-decoration: none;
}

.primary { background: var(--accent); color: #1a0d06; font-weight: 600; }
.secondary { background: #1d2a22; color: var(--text); border: 1px solid var(--border); }

.btn-row { display: flex; gap: 8px; }
.btn-row > button, .btn-row > a { width: auto; flex: 1; margin-bottom: 10px; }

#status {
  min-height: 20px;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 6px 0;
}
#status.error { color: #ff8a8a; }
#status.ok { color: var(--accent-2); }
.hint.error { color: #ff8a8a; }
.hint.ok { color: var(--accent-2); }

#results.hidden { display: none; }
#results { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 14px; }

.hidden { display: none !important; }
.crs-subfields { display: flex; gap: 10px; }
.crs-subfields label { flex: 1; }

#legend { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.legend-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  color: var(--muted);
}
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

#stats-table, #history-table { width: 100%; border-collapse: collapse; font-size: 0.75rem; margin-bottom: 12px; }
#stats-table th, #stats-table td, #history-table th, #history-table td { text-align: left; padding: 4px 2px; border-bottom: 1px solid var(--border); }

#history.hidden { display: none; }
#history { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 14px; }
#history h3 { font-size: 0.9rem; margin: 0 0 8px; }

.aoi-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  margin-bottom: 6px;
  font-size: 0.78rem;
  cursor: pointer;
}
.aoi-item.selected { border-color: var(--accent); background: #10201580; }
.aoi-item .aoi-name { font-weight: 600; }
.aoi-item .aoi-meta { color: var(--muted); font-size: 0.7rem; }

#zonal-section { margin-top: 14px; }
.zonal-scroll { overflow-x: auto; margin-top: 8px; margin-bottom: 8px; }
#zonal-table { border-collapse: collapse; font-size: 0.7rem; white-space: nowrap; }
#zonal-table th, #zonal-table td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--border); }
#zonal-table th { color: var(--accent-2); }

.scene-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px;
  margin-bottom: 6px;
  font-size: 0.72rem;
  cursor: pointer;
  color: var(--muted);
}
.scene-item.selected { border-color: var(--accent-2); color: var(--text); }
.scene-item img { width: 100%; border-radius: 4px; margin-bottom: 4px; display: block; }
.scene-download-link { display: block; position: relative; cursor: pointer; }
.scene-download-link:hover img { opacity: 0.75; }
.scene-download-badge {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 8px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 0.6rem;
  line-height: 1.3;
  padding: 2px 5px;
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scene-group-label { font-size: 0.72rem; color: var(--accent); margin: 8px 0 4px; }
.scene-downloads-all { margin-top: 4px; font-size: 0.68rem; }
.scene-downloads-all summary { cursor: pointer; color: var(--accent-2); user-select: none; }
.scene-downloads-all summary:hover { color: var(--accent); }
.scene-downloads-all ul { list-style: none; margin: 4px 0 0; padding: 0; max-height: 160px; overflow-y: auto; }
.scene-downloads-all li { padding: 2px 0; border-top: 1px dashed var(--border); }
.scene-downloads-all li:first-child { border-top: none; }
.scene-downloads-all a { color: var(--text); text-decoration: none; }
.scene-downloads-all a:hover { color: var(--accent-2); text-decoration: underline; }
.scene-downloads-all .file-size { color: var(--muted); }

.leaflet-container { background: #0d1310; }

#app-footer {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

.admin-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.68rem;
  opacity: 0.6;
}
.admin-link:hover { opacity: 1; text-decoration: underline; }

#auth-box {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 14px;
  font-size: 0.8rem;
}
#auth-box button { margin-bottom: 0; }
#auth-logged-out #login-form { margin-top: 10px; }
#auth-logged-out #login-form label { margin-bottom: 8px; }
#login-status { min-height: 16px; color: #ff8a8a; margin-top: 2px; }
#auth-logged-in p.hint { margin: 0 0 8px; }
#auth-logged-in .admin-link { opacity: 1; color: var(--accent); font-weight: 600; }

.aoi-item { position: relative; padding-right: 62px; }
.aoi-delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: auto;
  padding: 2px 8px;
  margin: 0;
  font-size: 0.68rem;
  background: transparent;
  border: 1px solid var(--border);
  color: #ff8a8a;
  border-radius: 4px;
}
.aoi-delete-btn:hover { background: #3a1a1a; border-color: #ff8a8a; }

.inline-check { display: flex; flex-direction: row; align-items: center; gap: 6px; font-weight: normal; }
.inline-check input[type="checkbox"] { width: auto; margin: 0; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.card-stat { border: 1px solid var(--border); border-radius: 6px; padding: 8px; background: #10170f; }
.card-stat .num { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.card-stat .lbl { font-size: 0.68rem; color: var(--muted); line-height: 1.3; }
.card-stat.warn .num { color: #ff9b6a; }
.card-stat.ok .num { color: #7fd6a0; }

.year-bar { display: flex; height: 10px; border-radius: 4px; overflow: hidden; margin: 4px 0 2px; }
.year-bar span { flex: 1; }
.year-bar-labels { display: flex; justify-content: space-between; font-size: 0.65rem; color: var(--muted); margin-bottom: 10px; }

.notice {
  border: 1px solid #5a4a1a;
  background: #221c0c;
  color: #e9d9a6;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.72rem;
  line-height: 1.45;
  margin-bottom: 12px;
}
.notice b { color: var(--accent); }

#year-table { width: 100%; border-collapse: collapse; font-size: 0.72rem; margin-bottom: 12px; }
#year-table th, #year-table td { text-align: right; padding: 3px 4px; border-bottom: 1px solid var(--border); }
#year-table th:first-child, #year-table td:first-child { text-align: left; }
#year-table .swatch { width: 9px; height: 9px; display: inline-block; border-radius: 2px; margin-right: 4px; }
#class-table { width: 100%; border-collapse: collapse; font-size: 0.72rem; margin-bottom: 12px; }
#class-table th, #class-table td { text-align: left; padding: 3px 4px; border-bottom: 1px solid var(--border); }
#class-table td.n, #class-table th.n { text-align: right; }
#class-table tr.forest td { color: #7fd6a0; }
.table-scroll { max-height: 260px; overflow-y: auto; }

/* ---------------------------------------------------------------------------
   Layar sempit (ponsel/tablet tegak): peta di atas, panel di bawah dan bisa digulir.
   Sebelumnya panel 380 px lebih lebar dari layar ponsel dan peta terdorong keluar layar (lebar 0).
   Tombol ☰ menciutkan panel sehingga peta memenuhi layar (untuk menggambar AOI). */
@media (max-width: 768px) {
  #app { flex-direction: column; height: 100vh; height: 100dvh; }
  #map { order: 1; flex: 0 0 42%; width: 100%; height: auto; min-height: 0; }
  #sidebar {
    order: 2; flex: 1 1 auto; width: 100%; min-width: 0; min-height: 0;
    border-right: none; border-top: 1px solid var(--border); padding: 14px;
  }
  #sidebar.collapsed { flex: 0 0 0; height: 0; padding: 0; border-top-color: transparent; }
  #app:has(#sidebar.collapsed) #map { flex: 1 1 auto; }
  #sidebar-toggle { top: 10px; left: auto; right: 10px; width: 42px; height: 42px; }   /* kanan atas: kiri atas dipakai kontrol zoom dan gambar */
  h1 { font-size: 1.1rem; }
  .cards { grid-template-columns: 1fr 1fr; }
  .btn-row { flex-wrap: wrap; }
  input, select, button { font-size: 16px; }   /* cegah zoom otomatis iOS saat fokus */
  .leaflet-draw-toolbar a { width: 34px; height: 34px; }
}
