* { box-sizing: border-box; }
/* System UI on TH gracefully falls back to Sarabun-class system fonts on
 * Linux/Android and SF Thai on macOS/iOS; nothing extra to ship. */
html, body { margin: 0; height: 100%; font-family: system-ui, -apple-system, "Segoe UI", "Sarabun", sans-serif; color: #1a1a1a; }
html[lang="th"] body { line-height: 1.55; }  /* Thai needs a touch more leading for tone marks */

.lang-toggle {
  display: inline-flex;
  gap: 0;
  margin-bottom: 10px;
  border: 1px solid #d6d6d6;
  border-radius: 4px;
  overflow: hidden;
}
.lang-toggle button {
  appearance: none;
  border: 0;
  background: #fff;
  color: #555;
  /* Thai glyphs need extra horizontal room — "ไทย" was clipping to "ไท" at
   * the previous 10 px right padding. Min-width keeps both pills the same
   * width regardless of language, so the toggle stays balanced. */
  padding: 5px 14px;
  min-width: 56px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  font-family: system-ui, -apple-system, "Segoe UI", "Sarabun", sans-serif;
  line-height: 1.4;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.lang-toggle button:hover { background: #f3f3f3; }
.lang-toggle button.active:hover { background: #1d827d; }
.lang-toggle button.active {
  background: #21918c;
  color: #fff;
}
.lang-toggle button + button { border-left: 1px solid #d6d6d6; }
.lang-toggle button.active + button,
.lang-toggle button + button.active { border-left-color: #21918c; }
#map { position: absolute; inset: 0 380px 0 0; }

#panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 380px;
  background: #fff;
  border-left: 1px solid #d6d6d6;
  box-shadow: -2px 0 8px rgba(0,0,0,0.04);
  overflow-y: auto;
  padding: 16px 18px;
  font-size: 14px;
  line-height: 1.4;
}
#panel header h1 { font-size: 16px; margin: 0 0 4px; }
#panel header p { margin: 0 0 14px; }
#panel h2 { font-size: 14px; font-weight: 600; margin: 8px 0 4px; }
#panel h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
  color: #555; margin: 16px 0 6px; font-weight: 600;
}
#panel footer { margin-top: 24px; font-size: 11px; }
.muted { color: #888; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

.controls {
  display: grid;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid #eee;
  border-bottom: 1px solid #eee;
}
.controls .row { display: flex; align-items: center; gap: 8px; }
.controls .row > span:first-child { min-width: 64px; color: #555; font-size: 12px; }
.controls input[type="range"] { flex: 1; }
.controls fieldset {
  border: none; padding: 0; margin: 0;
  display: grid; gap: 6px;
}
.controls legend { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: #555; padding: 0; margin-bottom: 4px; }

.score-line { display: flex; align-items: baseline; gap: 12px; margin: 8px 0 0; }
.score-val { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.score-feas {
  padding: 2px 8px; border-radius: 4px; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.4px; font-weight: 600;
}
.score-feas.ok { background: #d4edda; color: #1e6d36; }
.score-feas.no { background: #f8d7da; color: #842029; }

.bd { width: 100%; border-collapse: collapse; table-layout: fixed; }
/* Wider label column + smaller font on Thai keeps each label to ≤2 lines.
 * The previous 110 px col wrapped Thai labels into 3 lines because
 * "ความต้องการ EV" / "สถานีเต็มใกล้เคียง" don't fit in that width. */
.bd th {
  text-align: left; font-weight: 500;
  padding: 4px 6px 4px 0; font-size: 12px; width: 130px; color: #333;
  vertical-align: middle; line-height: 1.3;
  word-break: keep-all;  /* keep Thai/CJK words intact when wrapping */
}
html[lang="th"] .bd th { font-size: 11px; width: 140px; line-height: 1.35; }
.bd .bar { width: 100%; padding: 4px 6px; vertical-align: middle; }
.bd .bar-fill { height: 8px; border-radius: 2px; min-width: 1px; }
.bd .bar-fill.pos { background: #21918c; }
.bd .bar-fill.neg { background: #ee6055; }
.bd .num { width: 40px; text-align: right; font-size: 12px; padding: 4px 0; vertical-align: middle; }

/* Tooltip indicator — dotted underline so users know the label has more
 * detail on hover. Native title= attribute gives the actual tooltip; works
 * on desktop hover and mobile long-press, no extra JS or library. */
.has-tip {
  text-decoration: underline dotted #b0b0b0;
  text-underline-offset: 2px;
  cursor: help;
}

/* Four-up kW-bucket badges for the ≤3 km supply mix. Zero counts dim out so
 * the eye reads the gap immediately ("0 in the 100-119 band → that's the
 * supply-mix hole here"). 120+ kW gets the brand teal as a quiet highlight
 * since it's the band most often missing in the saturated cells. */
.kv .kw-segs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  width: 100%;
  max-width: 240px;
}
.kw-segs .seg {
  text-align: center;
  padding: 3px 2px 4px;
  border-radius: 4px;
  background: #f1f3f4;
  border: 1px solid transparent;
}
.kw-segs .seg-range {
  font-size: 9px;
  font-weight: 600;
  color: #777;
  letter-spacing: 0.2px;
  line-height: 1.1;
}
.kw-segs .seg-count {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #333;
  line-height: 1.1;
  margin-top: 1px;
}
.kw-segs .seg.zero { background: #f8f8f8; }
.kw-segs .seg.zero .seg-count { color: #c4c4c4; font-weight: 500; }
.kw-segs .seg.zero .seg-range { color: #b3b3b3; }
.kw-segs .seg.high {
  background: rgba(33, 145, 140, 0.12);
  border-color: rgba(33, 145, 140, 0.35);
}
.kw-segs .seg.high .seg-count { color: #21918c; }
.kw-segs .seg.high .seg-range { color: #21918c; }

/* Weekly usage heatmap (7 days × 24 hours). Each cell's intensity is the
 * busyness fraction relative to that station's own peak — set as the
 * --a CSS variable so a single class can render every shade. Brand teal
 * keeps it consistent with the score-bar palette. */
.hm {
  display: grid;
  grid-template-columns: 22px repeat(24, 1fr);
  gap: 1px;
  margin: 6px 0 2px;
  font-size: 9px;
}
.hm-day {
  font-size: 10px;
  font-weight: 500;
  color: #666;
  text-align: right;
  padding-right: 4px;
  align-self: center;
  height: 12px;
  line-height: 12px;
}
.hm-cell {
  height: 12px;
  background: rgba(33, 145, 140, var(--a, 0));
  border-radius: 1px;
  outline: 0.5px solid rgba(0, 0, 0, 0.04);
}
.hm-axis {
  display: grid;
  grid-template-columns: 22px repeat(24, 1fr);
  gap: 1px;
  font-size: 9px;
  color: #888;
  text-align: center;
  margin-bottom: 2px;
}
.hm-hour {
  line-height: 1.2;
}
.hm-note {
  font-size: 11px;
  margin: 4px 0 0;
  line-height: 1.35;
}

/* Inline info icon in section headings — tooltip-only by design, so the
 * caveat text stays one hover away without eating panel space. */
#panel h3.with-info { display: flex; align-items: center; gap: 6px; }
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #d6d6d6;
  color: #555;
  font-size: 9px;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  cursor: help;
  user-select: none;
  text-transform: none;
  letter-spacing: 0;
  transition: background 120ms, color 120ms;
}
.info-icon:hover { background: #21918c; color: #fff; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 0; }
.kv dt { color: #666; font-size: 12px; }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; font-size: 12px; }

@media (max-width: 720px) {
  #map { inset: 0 0 280px 0; }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: 280px; border-left: none; border-top: 1px solid #d6d6d6; }
}
