:root {
  --bg: #fbfaf7;
  --card: rgba(251, 250, 247, 0.97);
  --ink: #1d1c1a;
  --ink2: #53514c;
  --muted: #8a877f;
  --line: #e4e1d8;
  --accent: #8c4a22;
  --accent-soft: #f3e7dc;
  --shadow: 0 2px 10px rgba(30, 25, 20, 0.16), 0 0 0 1px rgba(30, 25, 20, 0.06);
  --font: "Noto Sans Thai", "Leelawadee UI", "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; font-family: var(--font); color: var(--ink); background: #e9e6df; }
#map { position: absolute; inset: 0; }
button { font: inherit; cursor: pointer; }

/* ---------- panel ---------- */
#panel {
  position: absolute; top: 12px; left: 12px; width: 330px; max-height: calc(100% - 24px);
  display: flex; flex-direction: column; background: var(--card); border-radius: 10px; box-shadow: var(--shadow);
  z-index: 3; overflow: hidden;
}
.brand { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; padding: 14px 14px 8px; }
.brand h1 { margin: 0; font: italic 600 22px/1.1 Georgia, "Times New Roman", serif; letter-spacing: 0.2px; color: var(--ink); }
.brand .sub { margin: 4px 0 0; font-size: 12.5px; color: var(--ink2); }
.brand-tools { display: flex; gap: 6px; align-items: center; }
.lang { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.lang button { border: 0; background: transparent; padding: 3px 8px; font-size: 12px; color: var(--ink2); }
.lang button.on { background: var(--accent); color: #fff; }
button.icon { border: 1px solid var(--line); background: #fff; border-radius: 6px; width: 28px; height: 26px; font-size: 14px; color: var(--ink2); padding: 0; }
.search { position: relative; padding: 0 14px 10px; }
#q { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; font: inherit; font-size: 13.5px; background: #fff; }
#q:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
#results { position: absolute; left: 14px; right: 14px; top: 38px; margin: 0; padding: 4px 0; list-style: none; background: #fff;
  border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 320px; overflow: auto; z-index: 5; }
#results li { padding: 6px 10px; font-size: 13px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#results li:hover, #results li.sel { background: var(--accent-soft); }
#results li small { color: var(--muted); white-space: nowrap; }
#panel-body { overflow-y: auto; padding: 0 14px 10px; }
#panel.collapsed #panel-body, #panel.collapsed .search { display: none; }
section { border-top: 1px solid var(--line); padding: 10px 0 8px; }
section h2 { margin: 0 0 6px; font-size: 11.5px; font-weight: 600; letter-spacing: 0.6px; text-transform: uppercase; color: var(--muted); }
label.check, label.radio { display: flex; align-items: center; gap: 7px; font-size: 13.5px; padding: 3px 0; cursor: pointer; color: var(--ink); }
label input { accent-color: var(--accent); margin: 0; }
.slider { display: grid; grid-template-columns: 1fr 120px auto; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink2); padding: 4px 0; }
.slider input { width: 120px; accent-color: var(--accent); }
.slider output { font-size: 12px; color: var(--muted); min-width: 34px; }
#exag-row { opacity: 0.45; pointer-events: none; }
#exag-row.on { opacity: 1; pointer-events: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; margin: 2px 0 6px; }
.seg button { border: 0; background: #fff; padding: 4px 12px; font-size: 13px; color: var(--ink2); }
.seg button.on { background: var(--accent); color: #fff; }
.hint { margin: 4px 0 6px; font-size: 12px; color: var(--muted); line-height: 1.45; }
.key { display: inline-block; width: 18px; height: 12px; flex: 0 0 18px; border-radius: 2px; background-size: contain; background-repeat: no-repeat; background-position: center; }
.key-fault { height: 3px; background: #b0122b; border-radius: 1px; }
.key-dmr { height: 2px; background: #e8331c; }
.key-sheet { border: 1.5px solid #2a5d8f; background: transparent; }
.key-sheet2 { border: 1.5px dashed #5b3a8c; background: transparent; }
.key-prov { border: 1.5px solid #8c4a22; background: transparent; }
#legend, #legend-extra { list-style: none; margin: 0; padding: 0; }
#legend li { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 8px; padding: 3px 4px; border-radius: 5px; cursor: pointer; font-size: 13px; }
#legend li:hover { background: #f1eee7; }
#legend li.on { background: var(--accent-soft); outline: 1px solid #e2c9b3; }
#legend li.dim { opacity: 0.45; }
#legend li small, #legend-extra li small { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.sw { width: 22px; height: 14px; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12); }
#legend-extra li { display: grid; grid-template-columns: 22px 1fr; align-items: center; gap: 8px; padding: 3px 4px; font-size: 12.5px; color: var(--ink2); }
footer { border-top: 1px solid var(--line); padding: 8px 0 2px; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
footer a { color: var(--accent); }

/* ---------- info panel ---------- */
#info {
  position: absolute; top: 12px; right: 56px; width: 370px; max-height: calc(100% - 64px); overflow-y: auto;
  background: var(--card); border-radius: 10px; box-shadow: var(--shadow); z-index: 3; padding: 12px 14px 10px;
}
#info-close { position: sticky; float: right; top: 0; }
#info h3 { margin: 0 0 4px; font-size: 15.5px; line-height: 1.3; }
.loc { font-size: 12px; color: var(--muted); margin: 0 30px 8px 0; }
.unit { border-top: 1px solid var(--line); padding: 9px 0 8px; }
.unit:first-of-type { border-top: 0; }
.unit-head { display: flex; gap: 10px; align-items: flex-start; }
.chip { flex: 0 0 auto; min-width: 46px; padding: 3px 6px; border-radius: 4px; font: 600 13px/1.2 "Segoe UI", system-ui, sans-serif; text-align: center;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15); color: #1d1c1a; }
.unit .scale-tag { font-size: 11px; letter-spacing: 0.4px; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
dl { display: grid; grid-template-columns: 92px 1fr; gap: 3px 10px; margin: 8px 0 0; font-size: 13px; }
dt { color: var(--muted); }
dd { margin: 0; line-height: 1.45; }
.src { margin-top: 6px; font-size: 12px; color: var(--ink2); line-height: 1.45; }
.warn { color: #8a5a00; }
.links { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.links a { font-size: 12.5px; color: var(--accent); text-decoration: none; border: 1px solid #e2c9b3; padding: 2px 8px; border-radius: 12px; background: #fff; }
.links a:hover { background: var(--accent-soft); }
.sec2 { opacity: 0.92; }
.feat { border-top: 1px dashed var(--line); padding: 8px 0; font-size: 13px; }
.feat b { font-weight: 600; }

/* ---------- status ---------- */
#status { position: absolute; left: 50%; transform: translateX(-50%); top: 12px; z-index: 2; display: flex; gap: 12px;
  background: rgba(251,250,247,0.92); border-radius: 14px; padding: 4px 12px; font-size: 12px; color: var(--ink2); box-shadow: var(--shadow); white-space: nowrap; }
#st-show { color: var(--accent); }
.maplibregl-ctrl-bottom-left { margin-left: 4px; }
.maplibregl-ctrl-attrib { font-size: 10.5px; }

/* ---------- actions, explore ---------- */
button.action { display: flex; align-items: center; gap: 8px; width: 100%; margin: 8px 0 2px; padding: 6px 10px; border: 1px solid #e2c9b3;
  border-radius: 7px; background: #fff; color: var(--accent); font-size: 13.5px; text-align: left; }
button.action:hover, button.action.on { background: var(--accent-soft); }
.xs-icon { font-weight: 700; font-size: 15px; }
#explore { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
#explore li button { width: 100%; text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 5px 7px; font-size: 12.5px; color: var(--ink); line-height: 1.25; }
#explore li button:hover { background: var(--accent-soft); border-color: #e2c9b3; }
.tour { font-size: 13.5px; line-height: 1.55; color: var(--ink); }
.tour h3 { margin: 0 30px 6px 0; }

/* ---------- cross-section panel ---------- */
#xsec { position: absolute; left: 354px; right: 56px; bottom: 34px; height: 300px; background: var(--card); border-radius: 10px; box-shadow: var(--shadow);
  z-index: 4; display: flex; flex-direction: column; padding: 8px 12px 6px; }
#xsec header { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
#xs-meta { color: var(--muted); font-size: 12px; }
.xs-tools { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.seg.small { margin: 0; }
.seg.small button { padding: 2px 9px; font-size: 12px; }
.seg button:disabled { color: #c9c5bc; cursor: not-allowed; }
button.mini { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 2px 9px; font-size: 12px; color: var(--ink2); }
#xs-plot { flex: 1; position: relative; min-height: 0; }
#xs-plot svg { width: 100%; height: 100%; display: block; font-family: var(--font); }
#xs-note { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.4; }
#xs-tip { position: absolute; pointer-events: none; background: rgba(29,28,26,0.88); color: #fff; font-size: 12px; padding: 5px 8px; border-radius: 6px; white-space: nowrap; transform: translate(10px, -50%); line-height: 1.45; }
body.xsec-open #info { max-height: calc(100% - 64px - 310px); }
#toast { position: absolute; top: 52px; left: 50%; transform: translateX(-50%); z-index: 6; background: rgba(29,28,26,0.9); color: #fff; padding: 7px 14px; border-radius: 16px; font-size: 13px; }

@media (max-width: 760px) {
  #xsec { left: 12px; right: 12px; bottom: 12px; height: 260px; }
  #explore { grid-template-columns: 1fr; }
  #panel { width: calc(100% - 24px); max-height: 46%; }
  #info { left: 12px; right: 12px; width: auto; top: auto; bottom: 44px; max-height: 50%; }
  #status { display: none; }
}
