:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --text: #22201c;
  --muted: #6b665c;
  --border: #e3dfd4;
  --accent: #8a5a2b;
  --accent-ink: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171614;
    --surface: #211f1c;
    --text: #ece8df;
    --muted: #a29c90;
    --border: #3a362f;
    --accent: #d39a5f;
    --accent-ink: #171614;
  }
}
:root[data-theme="dark"] {
  --bg: #171614; --surface: #211f1c; --text: #ece8df; --muted: #a29c90;
  --border: #3a362f; --accent: #d39a5f; --accent-ink: #171614;
}

* { box-sizing: border-box; }
body {
  margin: 0; padding: 0 16px 32px;
  background: var(--bg); color: var(--text);
  font: 15px/1.55 "IBM Plex Sans Thai", system-ui, sans-serif;
  max-width: 1400px; margin-inline: auto;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }
h3 { font-size: .95rem; margin: 16px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.top { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; padding: 20px 0 12px; }
.sub { margin: 4px 0 0; color: var(--muted); }
.downloads { display: flex; flex-wrap: wrap; gap: 8px; }
.downloads a {
  padding: 6px 12px; border-radius: 8px; text-decoration: none;
  background: var(--accent); color: var(--accent-ink); font-weight: 500;
}

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.stat b { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }

.layout { display: grid; grid-template-columns: 270px 1fr; gap: 14px; }
.filters { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.filters label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 10px; }
.filters select, .filters input, #q {
  display: block; width: 100%; margin-top: 3px; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit;
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
button {
  width: 100%; padding: 7px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; cursor: pointer;
}
.legend { list-style: none; padding: 0; margin: 0; font-size: .82rem; }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.25); }

#map { height: 640px; border-radius: 10px; border: 1px solid var(--border); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-top: 14px; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; }
#q { max-width: 320px; margin: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
td.num { font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--bg); }
footer { margin-top: 18px; }

.lang { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang button { width: auto; border: 0; border-radius: 0; padding: 6px 10px; background: var(--surface); }
.lang button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.filters label.check { display: flex; gap: 6px; align-items: center; color: var(--text); }
.filters label.check input { width: auto; margin: 0; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }
.pop { border-collapse: collapse; margin: 6px 0; font-size: 12px; }
.pop td { padding: 1px 8px 1px 0; border: 0; white-space: normal; }
.pop td:first-child { color: #6b665c; }
.pop.depth th { font-size: 11px; font-weight: 600; text-align: right; padding: 1px 6px; color: #6b665c; }
.pop.depth th:first-child { text-align: left; }
.pop.depth td.num { text-align: right; padding: 1px 6px; color: inherit; }
.dates-help { margin: 0; padding-left: 18px; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  #map { height: 420px; }
}
.flags span { display: inline-block; margin: 1px 0; padding: 0 5px; border-radius: 4px; background: #f5e6c8; color: #6b4a12; font-size: 11px; }

.downloads a.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tabs button { width: auto; padding: 5px 12px; border-radius: 999px; }
.tabs button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.card-head { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.card h2 { font-size: 1rem; margin: 0; }
.card p { margin: 2px 0 8px; font-size: .88rem; }
.card dl { display: grid; grid-template-columns: 100px 1fr; gap: 4px 10px; margin: 0; font-size: .86rem; }
.card dt { color: var(--muted); }
.card dd { margin: 0; }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge-used { background: #d9f0d3; color: #1f5a1a; }
.badge-planned { background: #f5e6c8; color: #6b4a12; }
.badge-basemap { background: #e3e8f0; color: #2b3a55; }

/* ตรวจดินจากพิกัด */
.check-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 4px; }
.check-form button { width: auto; padding: 7px 12px; }
.check-form button[aria-pressed="true"], .check-form button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.check-form label { font-size: .85rem; color: var(--muted); }
.check-form input, .check-form select {
  display: block; margin-top: 3px; padding: 6px 8px; width: 150px; max-width: 100%;
  border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit;
}
.check-head { margin: 4px 0 10px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.check-grid .card { background: var(--bg); }
.check-grid h3 { margin: 0 0 6px; }
.check-grid h3 + h4, .check-grid h4 { font-size: .88rem; margin: 12px 0 4px; color: var(--muted); font-weight: 600; }
.check-grid .card > h3:not(:first-child) { margin-top: 16px; }
.check-grid p { margin: 2px 0 6px; font-size: .88rem; }
table.mini { font-size: .82rem; margin-bottom: 4px; }
table.mini th, table.mini td { padding: 3px 6px; }
table.mini td.num, table.mini th { text-align: right; }
table.mini th:first-child, table.mini td:first-child { text-align: left; }
.bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; margin: 4px 0 6px; border: 1px solid var(--border); }
.bar i { display: block; height: 100%; }
.dl-list { margin: 0 0 6px; padding-left: 18px; }
.dl-list li { margin: 2px 0; }
@media (max-width: 800px) {
  .check-grid { grid-template-columns: 1fr; }
  .check-form input, .check-form select { width: 130px; }
}
.check-grid { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.check-grid .card { min-width: 0; overflow-x: auto; }
.map-pick {
  width: auto; padding: 6px 10px; border: 2px solid rgba(0,0,0,.2); border-radius: 6px;
  background: #ffffff; color: #22201c; font: 500 13px/1.2 "IBM Plex Sans Thai", system-ui, sans-serif;
}
.map-pick[aria-pressed="true"] { background: #8a5a2b; color: #ffffff; }

/* ชั้นข้อมูล */
.layer { border-bottom: 1px solid var(--border); padding: 8px 0 6px; }
.layer label.check { flex-wrap: wrap; }
.layer .badge { margin-left: auto; }
.layer details { margin-top: 4px; }
.layer summary { cursor: pointer; font-size: .85rem; color: var(--accent); margin-bottom: 8px; }
.filters h2 + p { margin-top: 0; }

/* intro สำหรับผู้ใช้ทั่วไป */
.intro { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; margin-bottom: 14px; }
.intro .lead { font-size: 1.05rem; margin: 0 0 12px; max-width: 70ch; }
.steps { list-style: none; padding: 0; margin: 0 0 10px; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 12px; }
.steps li { display: flex; gap: 10px; align-items: flex-start; }
.steps p { margin: 2px 0 6px; font-size: .9rem; color: var(--muted); }
.num-badge {
  flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.cta {
  display: inline-block; padding: 6px 14px; border-radius: 8px; text-decoration: none;
  background: var(--accent); color: var(--accent-ink); font-weight: 500; font-size: .9rem;
}
.glossary { margin: 4px 0 8px; font-size: .9rem; }
.glossary summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.glossary dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 8px 0 0; }
.glossary dt { font-weight: 600; }
.glossary dd { margin: 0; color: var(--muted); }
.standards { border-top: 1px solid var(--border); padding-top: 10px; margin: 6px 0 8px; font-size: .9rem; }
.standards p { margin: 4px 0 8px; color: var(--muted); }
.standards dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0 0 6px; }
.standards dt { font-weight: 600; }
.standards dd { margin: 0; color: var(--muted); }
@media (max-width: 600px) {
  .standards dl, .glossary dl { grid-template-columns: 1fr; }
  .standards dd, .glossary dd { margin-bottom: 6px; }
}
.ramp { height: 10px; border-radius: 4px; border: 1px solid var(--border); }
.ramp-labels { display: flex; justify-content: space-between; font-size: .78rem; color: var(--muted); }
#raster-legend img { max-height: 160px; }
#raster-legend p { margin: 4px 0; font-size: .78rem; color: var(--muted); }
/* กลุ่มจุด: สีตามค่าที่เลือก */
.pt-cluster div {
  width: 100%; height: 100%; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid #ffffff; box-shadow: 0 0 0 1px rgba(0,0,0,.35);
}
.pt-cluster span {
  font: 600 12px/1 "IBM Plex Sans Thai", system-ui, sans-serif; color: #1b1b1b;
  background: rgba(255,255,255,.8); border-radius: 8px; padding: 2px 5px;
}

/* แผนที่ฐานสีเทาจาง ให้จุดข้อมูลและเส้นขอบเขตเด่น */
.basemap { filter: grayscale(1) contrast(.82) brightness(1.08); }
#map { background: #eceae6; }

/* คำอธิบายสีบนแผนที่ */
.map-legend {
  background: rgba(255,255,255,.94); color: #22201c; border-radius: 8px; padding: 8px 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.3); max-width: 260px; max-height: 60vh; overflow: auto;
  font: 13px/1.4 "IBM Plex Sans Thai", system-ui, sans-serif;
}
.map-legend summary { cursor: pointer; font-weight: 600; }
.map-legend section { margin-top: 8px; }
.map-legend section b { display: block; margin-bottom: 4px; }
.map-legend p { margin: 4px 0 0; font-size: 12px; color: #5c574e; }
.map-legend .ramp { height: 14px; border-color: #ccc; }
.map-legend .ramp-labels { color: #5c574e; font-size: 12px; }
.map-legend .sg-legend { display: block; max-height: 240px; }
.map-legend .legend.lc { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; font-size: 12px; }
@media (max-width: 800px) { .map-legend { max-width: 190px; max-height: 45vh; } }

/* แถบชั้นข้อมูลแบบกระชับ (สูงไม่เกินแผนที่) */
.filters { padding: 12px 14px; max-height: 640px; overflow: auto; }
.filters h2 { margin: 0; }
.filters h3 { margin: 10px 0 4px; }
.filters label { margin-bottom: 6px; }
.filters .info { font-size: .78rem; color: var(--muted); margin: 0 0 0 22px; line-height: 1.35; }
.filters > .info { margin: 2px 0 8px; }
.filters label.check { margin-bottom: 2px; }
.layer { padding: 6px 0; }
.layer label.check .badge { margin-left: auto; }
.layer details summary { margin: 4px 0 6px 22px; }
.row-label { display: flex !important; align-items: center; gap: 8px; }
.row-label > span { flex: none; }
.filters .row-label select, .filters .row-label input { margin-top: 0; flex: 1; min-width: 0; }
.layer-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.filters select.mini { width: auto; display: inline-block; margin: 0; padding: 2px 4px; font-size: .82rem; }
.grid2, .grid3 { display: grid; gap: 2px 8px; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: repeat(3, 1fr); }
.map-legend .legend { font-size: 12px; }
@media (max-width: 800px) { .filters { max-height: none; } }
.legend li.muted { display: block; }
.layer-row label.check { flex-wrap: nowrap; align-items: flex-start; }
.layer-row label.check input { margin-top: 4px; }
.map-legend { max-height: min(420px, 62vh); }
.row-label[hidden] { display: none !important; }
.dates-help ul { margin: 2px 0 4px; padding-left: 18px; }

/* โลโก้ KU และ SIS (พื้นขาวเสมอ ให้อ่านได้ในโหมดมืด) */
.brand { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.logos { display: inline-flex; align-items: center; gap: 12px; background: #ffffff; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--border); }
.logos img { height: 56px; width: auto; display: block; }
@media (max-width: 600px) { .logos img { height: 40px; } }

/* แบรนด์ SISoil (แบบเดียวกับ BURANA): โลโก้ระบบ + ชื่อ, โลโก้ KU/SIS ด้านขวา; จอแคบย้ายไปท้ายหน้า */
.brand-mark { flex: none; border-radius: 11px; display: block; }
.brand h1 { margin: 0; letter-spacing: .01em; }
.brand-th { font-weight: 500; font-size: .8em; color: var(--muted); margin-left: 4px; }
.downloads { align-items: center; }
.downloads .logos img { height: 40px; }
.foot-org { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.foot-org .logos img { height: 32px; }
footer p { margin: 4px 0 0; }
@media (max-width: 640px) {
  .downloads .logos { display: none; }
  .brand-mark { width: 40px; height: 40px; }
}
