/* ============================================================
   Peta RT Bangka Barat — styles.css
   Mengikuti design.md sepenuhnya
   ============================================================ */

/* ── Design tokens ─────────────────────────────────────────── */
:root {
  --ink:        #17242B;
  --ink-muted:  #55646D;
  --paper:      #FFFFFF;
  --ground:     #EEF1F3;
  --line:       #D5DBDF;
  --rt:         #1F6F8B;
  --dusun:      #B5651D;
  --lahan:      #5E8C4A;
  --sorot:      #FFC400;
  --error:      #B42318;

  --r-input:    6px;
  --r-popup:    8px;
  --r-sheet:    14px;
  --tap:        44px;
  --panel-w:    360px;
}

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

html, body {
  height: 100%;
}

body {
  overflow: hidden;
  font: 16px/1.45 "Atkinson Hyperlegible Next", system-ui, sans-serif;
  color: var(--ink);
  background: var(--ground);
  -webkit-font-smoothing: antialiased;
}

/* ── App shell ──────────────────────────────────────────────── */
#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ── Map ────────────────────────────────────────────────────── */
#map {
  position: absolute;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  z-index: 0;
}

/* Loading overlay centred on map */
#mapLoading {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ground);
  font-size: 16px;
  color: var(--ink-muted);
  pointer-events: none;
  transition: opacity 0.2s;
}
#mapLoading.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ── Mobile header (mobile < 768px) ────────────────────────── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(48px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  padding-left: 16px;
  padding-right: 16px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  z-index: 400;  /* above sheet (300) and map controls (200) */
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(23,36,43,.08);
}

.mobile-filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  color: var(--ink);
  font: 600 14px/1 "Atkinson Hyperlegible Next", system-ui, sans-serif;
  cursor: pointer;
}
.mobile-filter-btn:hover { background: var(--line); }
.mobile-filter-btn:active { background: var(--line); }
.mobile-filter-btn:focus-visible { outline: 2px solid var(--rt); outline-offset: 1px; }

/* ── Side panel (desktop ≥ 768px) ───────────────────────────── */
.panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--panel-w);
  background: var(--paper);
  border-right: 1px solid var(--line);
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* rule from design.md §8 */
  min-width: 0;
  overflow-wrap: anywhere;
}

.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.app-title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}

/* ── Tabs ───────────────────────────────────────────────────── */
.tab-list {
  display: flex;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  height: 48px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font: 16px/1 "Atkinson Hyperlegible Next", system-ui, sans-serif;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 0 8px;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn.active,
.tab-btn[aria-selected="true"] {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--ink);
}

.tab-btn:focus-visible {
  outline: 2px solid var(--rt);
  outline-offset: -2px;
}

.tab-panel {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  overscroll-behavior: contain;
}

.tab-panel.hidden { display: none; }

/* ── Form fields ────────────────────────────────────────────── */
.field-group {
  margin-bottom: 12px;
}

.field-label {
  display: block;
  font-size: 14px;
  font-weight: 400;
  color: var(--ink-muted);
  margin-bottom: 4px;
  line-height: 1.4;
}

.field-select,
.field-input {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  background: var(--paper);
  font: 16px/1.45 "Atkinson Hyperlegible Next", system-ui, sans-serif;
  color: var(--ink);
  appearance: auto;
  -webkit-appearance: auto;
  overflow-wrap: anywhere;
}

.field-select:disabled {
  background: var(--ground);
  color: var(--ink-muted);
  cursor: not-allowed;
}

.field-select:focus,
.field-input:focus {
  outline: 2px solid var(--rt);
  outline-offset: 0;
  border-color: var(--rt);
}

.field-input[aria-invalid="true"] {
  border-color: var(--error);
}

.coord-input {
  font-variant-numeric: tabular-nums;
}

/* Coord row: side-by-side on ≥ 341px, stacked on ≤ 340px */
.coord-row {
  display: flex;
  gap: 8px;
}
.coord-row .field-group { flex: 1; min-width: 0; }

@media (max-width: 340px) {
  .coord-row { flex-direction: column; }
}

.field-hint {
  font-size: 14px;
  color: var(--ink-muted);
  margin-bottom: 12px;
  line-height: 1.4;
}

.field-error {
  display: block;
  margin-top: 4px;
  font-size: 14px;
  color: var(--error);
  line-height: 1.4;
}
.field-error[hidden] { display: none; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn-primary {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 0 16px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: var(--r-input);
  font: 600 16px/1 "Atkinson Hyperlegible Next", system-ui, sans-serif;
  cursor: pointer;
  margin-bottom: 8px;
}

.btn-primary:hover { background: #253540; }
.btn-primary:active { background: #0e171c; }
.btn-primary:focus-visible {
  outline: 2px solid var(--rt);
  outline-offset: 2px;
}

.btn-text {
  background: none;
  border: none;
  color: var(--ink-muted);
  font: 16px/1 "Atkinson Hyperlegible Next", system-ui, sans-serif;
  cursor: pointer;
  padding: 8px 0;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  margin-bottom: 16px;
}

.btn-text:hover { color: var(--ink); }
.btn-text:focus-visible {
  outline: 2px solid var(--rt);
  outline-offset: 2px;
}

/* ── Legend ─────────────────────────────────────────────────── */
.legend {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 4px;
  margin-bottom: 12px;
}

.legend-title {
  font-size: 14px;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

.legend-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  display: inline-block;
  width: 28px;
  height: 10px;
  border-radius: 1px;
  flex-shrink: 0;
}

.swatch-rt    { background: rgba(31,111,139,.18); border: 1.2px solid #1F6F8B; }
.swatch-dusun { background: rgba(181,101,29,.16); border: 2px solid #B5651D; }
/* dashed via repeating-linear-gradient */
.swatch-lahan {
  background: repeating-linear-gradient(90deg, #5E8C4A 0, #5E8C4A 4px, transparent 4px, transparent 7px);
  border-top: 1px solid #5E8C4A;
  border-bottom: 1px solid #5E8C4A;
  border-left: none; border-right: none;
  height: 10px;
}

/* ── Data note ──────────────────────────────────────────────── */
.data-note {
  font-size: 12px;
  color: var(--ink-muted);
  line-height: 1.3;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

/* ── PIP results ────────────────────────────────────────────── */
.pip-result {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.pip-result-title {
  font-size: 14px;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

.pip-item {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.pip-item:last-child { border-bottom: none; margin-bottom: 0; }

.pip-name {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.pip-sub {
  font-size: 16px;
  color: var(--ink-muted);
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.pip-meta {
  font-size: 14px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.pip-action {
  display: inline-block;
  margin-top: 6px;
  font-size: 14px;
  color: var(--rt);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  min-height: var(--tap);
  min-width: var(--tap);
  font-family: inherit;
}
.pip-action:hover { text-decoration: underline; }
.pip-action:focus-visible { outline: 2px solid var(--rt); outline-offset: 2px; }

.pip-outside {
  font-size: 16px;
  color: var(--ink);
  line-height: 1.45;
}

/* ── Map controls (top-right) ───────────────────────────────── */
.map-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ctrl-btn {
  width: var(--tap);
  height: var(--tap);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.ctrl-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.ctrl-btn:hover { background: var(--ground); }
.ctrl-btn:active { background: var(--line); }
.ctrl-btn:focus-visible {
  outline: 2px solid var(--rt);
  outline-offset: 1px;
}

.ctrl-sep {
  height: 1px;
  background: var(--line);
  margin: -2px 4px;
}

/* Basemap menu */
.basemap-menu {
  position: absolute;
  top: 12px;
  right: calc(var(--tap) + 20px);
  z-index: 200;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  overflow: hidden;
  min-width: 160px;
  box-shadow: 0 2px 8px rgba(23,36,43,.12);
}

.basemap-menu[hidden] { display: none; }

.basemap-opt {
  display: block;
  width: 100%;
  padding: 0 14px;
  min-height: var(--tap);
  background: none;
  border: none;
  text-align: left;
  font: 16px/1 "Atkinson Hyperlegible Next", system-ui, sans-serif;
  color: var(--ink-muted);
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.basemap-opt:last-child { border-bottom: none; }
.basemap-opt.active { color: var(--ink); font-weight: 600; }
.basemap-opt:hover { background: var(--ground); }
.basemap-opt:focus-visible { outline: 2px solid var(--rt); outline-offset: -2px; }

/* ── Leaflet popup override ─────────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: var(--paper);
  border-radius: var(--r-popup);
  box-shadow: 0 4px 16px rgba(23,36,43,.18);
  padding: 0;
  width: min(280px, calc(100vw - 32px));
}

.leaflet-popup-content {
  margin: 0;
  width: 100% !important;
}

.leaflet-popup-tip {
  background: var(--paper);
  box-shadow: none;
}

.leaflet-popup-close-button {
  width: 44px !important;
  height: 44px !important;
  font-size: 22px !important;
  line-height: 44px !important;
  color: var(--ink-muted) !important;
  right: 0 !important;
  top: 0 !important;
}

/* Custom popup inner */
.popup-inner {
  padding: 14px 16px 12px;
}

.popup-title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
  margin-right: 28px; /* avoid close btn */
  overflow-wrap: anywhere;
  margin-bottom: 10px;
}

.popup-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.popup-table tr + tr td { padding-top: 4px; }

.popup-table td.lbl {
  width: 88px;
  vertical-align: top;
  color: var(--ink-muted);
  padding-right: 8px;
  flex-shrink: 0;
}

.popup-table td.val {
  font-size: 16px;
  color: var(--ink);
  overflow-wrap: anywhere;
}

/* ── Tooltip (mouse-only devices) ───────────────────────────── */
@media (hover: hover) {
  .leaflet-tooltip {
    background: var(--ink);
    color: #fff;
    border: none;
    border-radius: 4px;
    font: 14px/1.4 "Atkinson Hyperlegible Next", system-ui, sans-serif;
    padding: 4px 8px;
    box-shadow: none;
    white-space: nowrap;
  }
  .leaflet-tooltip::before { border-top-color: var(--ink); }
}

/* ── Sheet backdrop (mobile) ────────────────────────────────── */
.sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 290;
  background: transparent;
  pointer-events: none;
}

/* ── Bottom sheet (mobile < 768px) ─────────────────────────── */
.sheet {
  display: none; /* hidden on desktop */
  position: fixed;
  /* Sheet slides in from bottom; top is controlled by JS via transform */
  top: 0;
  left: 0;
  right: 0;
  /* Height equals full viewport so JS translateY reveals only part of it */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--paper);
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  box-shadow: 0 -4px 24px rgba(23,36,43,.18);
  z-index: 300;  /* above map (0) and map controls (200), below header (400) */

  /* Safe area for home bar */
  padding-bottom: env(safe-area-inset-bottom);

  /* Design rule */
  min-width: 0;
  overflow-wrap: anywhere;

  /* JS will manage translate via CSS custom prop */
  transform: translateY(var(--sheet-ty, calc(100% - 64px)));
  will-change: transform;
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

.sheet-handle {
  display: flex;
  justify-content: center;
  padding: 10px 0 6px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.handle-bar {
  width: 36px;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
}

.sheet .tab-list {
  border-bottom: 1px solid var(--line);
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 16px 16px;
}

/* ── Responsive: show sheet / hide panel on mobile ──────────── */
@media (max-width: 767px) {
  .panel { display: none; }
  .sheet { display: flex; flex-direction: column; }
  .sheet-backdrop { display: block; }
  .mobile-header { display: flex; }

  /* Map must account for fixed mobile header */
  #map {
    top: calc(48px + env(safe-area-inset-top));
    height: calc(100vh - 48px - env(safe-area-inset-top));
    height: calc(100dvh - 48px - env(safe-area-inset-top));
  }

  /* map controls & basemap menu: position below mobile header */
  .map-controls {
    position: fixed;
    top: calc(48px + env(safe-area-inset-top) + 12px);
    right: 12px;
    z-index: 200;
  }
  .basemap-menu {
    position: fixed;
    top: calc(48px + env(safe-area-inset-top) + 12px);
    right: calc(var(--tap) + 20px);
    z-index: 200;
  }
}

/* ── Responsive: tablet gets narrower panel ─────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
  :root { --panel-w: 320px; }
  .mobile-header { display: none; }
}

/* ── Landscape phone (height < 500px) → side panel like tablet ─ */
@media (max-height: 499px) and (orientation: landscape) {
  .panel { display: flex; }
  .sheet { display: none; }
  .sheet-backdrop { display: none; }
  .mobile-header { display: none; }
  #map { top: 0; height: 100vh; height: 100dvh; }
  .map-controls { position: absolute; top: 12px; right: 12px; }
  .basemap-menu { position: absolute; top: 12px; right: calc(var(--tap) + 20px); }
  :root { --panel-w: 300px; }
}

/* ── Custom marker ─────────────────────────────────────────── */
.marker-pin {
  /* Rendered by JS as SVG divIcon */
}

/* ── Keyboard focus ring ────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--rt);
  outline-offset: 2px;
}
