/* ===================================================================== base */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 400 14px/1.45 var(--font-sans);
  color: var(--ink);
  background: var(--bg-app);
  display: flex; flex-direction: column;
  overflow: hidden;                         /* page never scrolls; panels scroll inside */
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--agree-2); color: var(--ink); }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-strong); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--accent); }
.mono, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
[hidden] { display: none !important; }
.only-mobile, .only-tablet { display: none !important; }
svg { width: 20px; height: 20px; flex: none; }

/* thin themed scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-control) transparent; }

/* ================================================================== buttons */
.btn {
  height: 36px; padding: 0 14px; border-radius: var(--r-8);
  font-size: 13px; font-weight: 600; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-dark { background: var(--ink); color: #FFF; border: 1px solid var(--ink); }
.btn-dark:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-outline { background: var(--surface); border: 1px solid var(--border-control); color: var(--ink); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent-strong); }
.icon-btn {
  width: 44px; height: 44px; border-radius: var(--r-8); border: 1px solid var(--border-control);
  background: var(--surface); display: inline-flex; align-items: center; justify-content: center;
}

/* =================================================================== header */
.top {
  flex: none;
  display: flex; flex-wrap: wrap; align-items: center; gap: 16px 28px;
  padding: 12px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: relative; z-index: 1100;
}
.brand h1 { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.25; letter-spacing: -.01em; }
.brand .sub { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  padding: 8px 12px; border-radius: var(--r-8); font-size: 14px; color: var(--text-2);
  text-decoration: none; min-height: 36px; display: inline-flex; align-items: center;
}
.tab:hover { background: var(--segment-bg); color: var(--ink); }
.tab[aria-current="page"] { background: var(--nav-active-bg); color: var(--accent-strong); font-weight: 600; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ===================================================================== main */
main { flex: 1; min-height: 0; position: relative; }
.view { height: 100%; }
.view-map { display: flex; min-height: 0; }
.view-page { overflow-y: auto; }

/* =============================================================== left panel */
.left-panel {
  width: 296px; flex: none;
  display: flex; flex-direction: column; gap: 22px;
  padding: 20px; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
}
.sec { display: flex; flex-direction: column; gap: 8px; }
.sec-label {
  margin: 0; font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted);
}
.sec-text { margin: 0; font-size: 13px; color: var(--text-2); }

/* threshold radiogroup */
.threshold { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.threshold button {
  height: 44px; border: 0; border-radius: var(--r-6);
  font: 700 15px/1 var(--font-mono); font-variant-numeric: tabular-nums;
}
.threshold button[data-k="1"] { background: var(--agree-1); color: var(--ink); }
.threshold button[data-k="2"] { background: var(--agree-2); color: var(--ink); }
.threshold button[data-k="3"] { background: var(--agree-3); color: #FFF; }
.threshold button[data-k="4"] { background: var(--agree-4); color: #FFF; }
.threshold button[data-k="5"] { background: var(--agree-5); color: #FFF; }
.threshold button[aria-checked="true"] { box-shadow: var(--sh-threshold); position: relative; z-index: 1; }
.thr-ends { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); }

/* KPI block */
.kpi { background: var(--surface-tint); border-radius: var(--r-10); padding: 16px; }
.kpi-label { font-size: 13px; color: var(--text-2); }
.kpi-big { font: 600 34px/1.1 var(--font-mono); font-variant-numeric: tabular-nums; margin: 4px 0 12px; letter-spacing: -.02em; }
.kpi-big small { font: 400 15px var(--font-sans); color: var(--text-muted); margin-left: 4px; letter-spacing: 0; }
.kpi-grid { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 13px; margin: 0; }
.kpi-grid dt { color: var(--text-2); }
.kpi-grid dd { margin: 0; text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 500; }
.kpi-note { margin: 12px 0 0; font-size: 12px; line-height: 1.5; color: var(--text-muted); }

/* segmented control */
.segment { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px;
  background: var(--segment-bg); padding: 3px; border-radius: var(--r-8); }
.segment button { height: 36px; border: 0; border-radius: var(--r-6); background: transparent; font-size: 13px; color: var(--text-2); }
.segment button[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--sh-control); }
.segment button:disabled { opacity: .45; cursor: not-allowed; }

/* layers */
.layers, .radar { display: flex; flex-direction: column; gap: 2px; }
.radar { border: 0; padding: 0; margin: 8px 0 0; }
.radar legend { padding: 0; margin-bottom: 2px; }
.layer { display: flex; align-items: center; gap: 10px; min-height: 36px; font-size: 14px; cursor: pointer; }
.layer input[type="checkbox"], .layer input[type="radio"] { width: 16px; height: 16px; margin: 0; flex: none; }
.layer-sub { padding-left: 26px; font-size: 13px; color: var(--text-2); }
.layer-sub input { flex: 1; min-width: 0; }
.sw { flex: none; display: inline-block; }
.sw-flood { width: 22px; height: 12px; border-radius: 2px; background: linear-gradient(90deg, var(--agree-1), var(--agree-5)); }
.sw-perm { width: 22px; height: 12px; border-radius: 2px; background: var(--permanent-water); }
.sw-road { width: 22px; height: 4px; border-radius: 2px; background: var(--exposed-road); }
.sw-prio { width: 14px; height: 14px; border-radius: 50%; background: var(--ink); margin: 0 4px; }
.sw-val { width: 10px; height: 10px; border: 2px solid var(--ink); transform: rotate(45deg); margin: 0 6px; }

.disclaimer { margin: auto 0 0; font-size: 12px; line-height: 1.5; color: var(--text-muted); }

/* ====================================================================== map */
.map-wrap { flex: 1; min-width: 0; position: relative; background: var(--map-placeholder); }
#map { position: absolute; inset: 0; background: var(--map-placeholder); font-family: var(--font-sans); }
.leaflet-container { font: 12px/1.4 var(--font-sans); }
.leaflet-bar { border: 0 !important; box-shadow: var(--sh-control) !important; border-radius: var(--r-8) !important; }
.leaflet-bar a {
  width: 44px !important; height: 44px !important; line-height: 44px !important;
  font-size: 20px !important; color: var(--ink) !important;
}
.leaflet-bar a:first-child { border-radius: var(--r-8) var(--r-8) 0 0 !important; }
.leaflet-bar a:last-child { border-radius: 0 0 var(--r-8) var(--r-8) !important; }
.leaflet-control-zoom { margin: 16px 0 0 16px !important; }
.leaflet-control-scale { margin: 0 16px 16px 0 !important; }
.leaflet-control-scale-line {
  background: var(--overlay-light) !important; border-color: var(--ink) !important;
  color: var(--ink); font: 12px var(--font-mono); font-variant-numeric: tabular-nums;
}
.leaflet-control-attribution { font-size: 11px; background: var(--overlay-light) !important; }

.img-tag {
  position: absolute; top: 16px; z-index: 900; pointer-events: none;
  background: var(--overlay-dark); color: #FFF; font-size: 13px; font-weight: 500;
  padding: 6px 10px; border-radius: var(--r-6);
}
.tag-before { left: 76px; }
.tag-after { right: 16px; }

.swipe-line {
  position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; z-index: 850;
  background: #FFF; box-shadow: 0 0 0 1px rgba(20, 32, 43, .45);
  pointer-events: none;
}
.swipe-handle {
  position: absolute; top: 50%; left: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px;
  border-radius: 50%; border: 0; background: #FFF; color: var(--ink); box-shadow: var(--sh-handle);
  display: flex; align-items: center; justify-content: center;
  cursor: ew-resize; pointer-events: auto; touch-action: none;
}
.swipe-handle svg { width: 18px; height: 18px; }

.map-bottom {
  position: absolute; left: 16px; right: 140px; bottom: 16px; z-index: 900;
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 8px;
  pointer-events: none;
}
.map-bottom > * { pointer-events: auto; }
.legend {
  background: var(--overlay-light); border-radius: var(--r-8); padding: 8px 10px;
  font-size: 12px; box-shadow: var(--sh-control);
}
.legend-title { font-weight: 600; margin-bottom: 4px; }
.legend-bars { display: flex; gap: 2px; }
.legend-bars i { width: 28px; height: 10px; display: block; }
.legend-ends { display: flex; justify-content: space-between; color: var(--text-2); font-family: var(--font-mono); }
.swipe-range {
  background: var(--overlay-light); border-radius: var(--r-8); padding: 6px 12px; box-shadow: var(--sh-control);
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink); margin: 0 auto;
}
.swipe-range input { width: 220px; }

.pix-tip {
  position: absolute; z-index: 950; pointer-events: none; min-width: 200px;
  background: var(--surface); border-radius: var(--r-8); box-shadow: var(--sh-tooltip);
  padding: 8px 10px; font-size: 13px; line-height: 1.45;
}
.pix-tip b { display: block; font-size: 12px; color: var(--text-muted); font-weight: 600; }

/* priority markers */
.pm {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid #FFF;
  display: flex; align-items: center; justify-content: center;
  color: #FFF; font: 700 14px/1 var(--font-mono); box-shadow: var(--sh-control);
  transition: box-shadow .15s ease-out, transform .15s ease-out;
}
.pm.t-road { background: var(--exposed-road); }
.pm.t-settlement_edge { background: var(--ink); }
.pm.t-cropland { background: var(--field); }
.pm.is-selected { box-shadow: var(--sh-selected); }
.pm.is-hover { transform: scale(1.12); }
.vm { width: 12px; height: 12px; transform: rotate(45deg); border: 2px solid var(--ink); }

/* ============================================================== right panel */
.right-panel {
  width: 344px; flex: none;
  display: flex; flex-direction: column; gap: 14px; padding: 20px;
  overflow-y: auto; background: var(--surface); border-left: 1px solid var(--border);
}
.rp-head { display: flex; align-items: baseline; gap: 12px; }
.rp-head h2 { margin: 0; font-size: 17px; font-weight: 700; }
.rp-head .mono { margin-left: auto; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 32px; padding: 0 12px; border-radius: var(--r-16); font-size: 13px;
  background: var(--surface); border: 1px solid var(--border-control); color: var(--ink);
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #FFF; }

.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.card { border: 1px solid var(--divider); border-radius: var(--r-10); background: var(--surface); }
.card.is-selected { background: var(--surface-tint); border-color: var(--accent); }
.card.is-checked .card-title { color: var(--text-muted); }
.card-main { display: flex; align-items: flex-start; gap: 10px; padding: 12px; }
.card-btn {
  flex: 1; min-width: 0; display: flex; gap: 10px; align-items: flex-start; text-align: left;
  border: 0; background: transparent; padding: 0;
}
.num-dot {
  width: 26px; height: 26px; border-radius: 50%; flex: none; color: #FFF;
  display: flex; align-items: center; justify-content: center; font: 700 12px/1 var(--font-mono);
}
.num-dot.t-road { background: var(--exposed-road); }
.num-dot.t-settlement_edge { background: var(--ink); }
.num-dot.t-cropland { background: var(--field); }
.card-title { display: block; font-size: 14px; font-weight: 600; line-height: 1.3; }
.card-sub { display: block; font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.card-check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); min-height: 26px; cursor: pointer; white-space: nowrap; }
.card-check input { width: 16px; height: 16px; margin: 0; }
.card-detail { padding: 0 12px 12px 48px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.conf { font-size: 12px; font-weight: 600; }
.conf-high { color: var(--val-tp); }
.conf-medium { color: var(--accent); }
.conf-uncertain { color: var(--val-unc); }
.segs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.seg {
  width: 100%; display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px;
  min-height: 32px; padding: 2px 6px; border: 0; border-radius: var(--r-6); background: transparent; text-align: left;
}
.seg:hover { background: var(--segment-bg); }
.seg-bar { height: 6px; border-radius: 3px; background: var(--exposed-road); }
.seg-rank { font: 600 12px var(--font-mono); color: var(--text-muted); }
.seg-km { font: 500 13px var(--font-mono); font-variant-numeric: tabular-nums; }
.chip-img { width: 100%; border-radius: var(--r-6); border: 1px solid var(--divider); display: block; }
.rp-actions { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: auto; padding-top: 6px; }
.rp-actions .btn { height: 40px; }

/* ==================================================================== pages */
.page { max-width: 880px; margin: 0 auto; padding: 28px 24px 64px; }
.page-wide { max-width: 1180px; }
.page h2 { font-size: 22px; margin: 0 0 12px; letter-spacing: -.01em; }
.page h3 { font-size: 16px; margin: 32px 0 8px; }
.page p, .page li { max-width: 75ch; line-height: 1.6; }
.page table { border-collapse: collapse; width: 100%; font-size: 13px; background: var(--surface); }
.page th, .page td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--divider); vertical-align: top; }
.page th { font-weight: 600; color: var(--text-2); background: var(--surface-tint); }
.page td.n, .page th.n { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; border: 1px solid var(--divider); border-radius: var(--r-8); }
.counts { display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid var(--divider); border-radius: var(--r-10); background: var(--surface); margin: 16px 0 20px; }
.counts div { padding: 12px 14px; border-left: 1px solid var(--divider); }
.counts div:first-child { border-left: 0; }
.counts span { display: block; font-size: 12px; color: var(--text-muted); }
.counts b { font: 600 26px var(--font-mono); }
.dl { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dl a {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; text-decoration: none; color: var(--ink);
  border: 1px solid var(--divider); border-radius: var(--r-10); background: var(--surface);
}
.dl a:hover { border-color: var(--accent); }
.dl a span { font-size: 13px; color: var(--text-muted); }
.dl a b { font: 600 13px var(--font-mono); }

/* =================================================== tablet 768–1023px */
@media (max-width: 1023px) {
  .only-tablet { display: inline-flex !important; }
  .left-panel { width: 260px; padding: 16px; }
  .right-panel {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 1200; width: min(360px, 92vw);
    transform: translateX(100%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
    box-shadow: var(--sh-tooltip);
  }
  .right-panel.is-open { transform: none; }
  .rp-head .icon-btn { margin-left: 4px; }
  .map-bottom { right: 120px; }
  .swipe-range input { width: 140px; }
}

/* =================================================== mobile <768px (variant C) */
@media (max-width: 767px) {
  .top { display: none; }
  .only-mobile { display: flex !important; }
  .only-tablet, .no-mobile, .desk-only-sec { display: none !important; }

  /* layers become a full-screen sheet */
  .left-panel {
    position: fixed; inset: 0; z-index: 1300; width: auto; border: 0;
    transform: translateY(100%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
  }
  .left-panel.is-open { transform: none; }
  .sheet-head { align-items: center; justify-content: space-between; }
  .sheet-head h2 { margin: 0; font-size: 17px; }
  .mobile-nav { gap: 8px; flex-wrap: wrap; }
  .mobile-nav a { padding: 10px 12px; border: 1px solid var(--border-control); border-radius: var(--r-8); text-decoration: none; min-height: 44px; }

  .right-panel { position: static; width: auto; transform: none; border: 0; padding: 0; overflow: visible; box-shadow: none; }

  .m-title {
    position: absolute; top: 16px; left: 16px; right: 80px; z-index: 900;
    flex-direction: column; background: var(--surface); border-radius: 12px; box-shadow: var(--sh-control);
    padding: 10px 14px;
  }
  .m-title strong { font-size: 15px; font-weight: 700; }
  .m-title span { font-size: 12px; color: var(--text-muted); }
  .m-layers {
    position: absolute; top: 16px; right: 16px; z-index: 900; width: 48px; height: 48px;
    border-radius: var(--r-8); border: 0; background: var(--surface); box-shadow: var(--sh-control);
    align-items: center; justify-content: center;
  }
  .leaflet-control-zoom { display: none; }
  .img-tag { top: 84px; }
  .tag-before { left: 16px; }
  .map-bottom { bottom: calc(var(--sheet-peek, 230px) + 12px); right: 16px; }
  .leaflet-bottom { bottom: var(--sheet-peek, 230px); }

  .sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
    height: 85vh; flex-direction: column;
    background: var(--surface); border-radius: var(--r-20) var(--r-20) 0 0; box-shadow: var(--sh-sheet);
    transform: translateY(calc(85vh - var(--sheet-peek, 230px)));
    transition: transform .25s cubic-bezier(.2, .8, .2, 1);
  }
  .sheet.is-open { transform: none; }
  .sheet.is-dragging { transition: none; }
  .sheet-grip { flex: none; height: 28px; border: 0; background: transparent; display: flex; align-items: center; justify-content: center; touch-action: none; }
  .sheet-grip span { width: 40px; height: 5px; border-radius: 3px; background: var(--border-control); }
  .sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 16px 24px; display: flex; flex-direction: column; gap: 12px; }
  .m-kpi { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
  .m-kpi .kpi-big { font-size: 30px; margin: 0; }
  .m-kpi .kpi-label { font-size: 12px; }
  .m-kpi dl { margin: 0; font-size: 12px; text-align: right; }
  .m-kpi dd { margin: 0 0 2px; font: 500 13px var(--font-mono); }
  .m-kpi dt { color: var(--text-muted); }
  .sheet .threshold button { border-radius: var(--r-8); }
  .m-pixel { margin: 0; font-size: 13px; }
  .card-main { min-height: 48px; }
  .counts { grid-template-columns: repeat(2, 1fr); }
  .counts div:nth-child(odd) { border-left: 0; }
  .dl { grid-template-columns: 1fr; }
  .page { padding: 20px 16px 48px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* highlighted table row (headline map) */
tr.hl td { background: var(--surface-tint); font-weight: 600; }

/* AI (Random Forest) probability layer */
.sw-ml { width: 22px; height: 12px; border-radius: 2px; background: linear-gradient(90deg, var(--ml-low), var(--ml-high)); }
.legend-bars i.ml-ramp { width: 148px; background: linear-gradient(90deg, var(--ml-low), var(--ml-high)); }

/* check your own points */
.checker-row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin: 12px 0; }
.checker-row select { font: inherit; padding: 4px 6px; border: 1px solid var(--border-control); border-radius: var(--r-6); background: var(--surface); }
.um { width: 14px; height: 14px; border: 2px solid #fff; border-radius: 3px; box-shadow: var(--sh-control); transform: rotate(45deg); }
