/* Hazemon SiteAir – stylesheet */

/* ---------- tokens ---------- */
:root {
  --bg: #f3f5f8; --card: #fff; --text: #18212b; --muted: #687586; --line: #e4e8ee; --grid: #edf0f4;
  --accent: #5b4fe0; --s1: #0f9d8a; --s2: #2f6fdb; --s3: #c07a1a;
  --temp: #e0533d; --rh: #2f8fdb; --pres: #7a5bd6; --co: #6c7a89; --co2: #2e9e5b;
  --ok: #2e9e5b; --off: #c2412d; --tip: #18212b; --tipText: #fff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 14px; --gap: 14px;
  color-scheme: light;
}
/* โหมดมืด: ตามเครื่อง (ถ้าไม่ได้เลือก light) หรือเลือก dark เอง */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141a; --card: #171e26; --text: #e6ebf1; --muted: #8d99a8; --line: #26303b; --grid: #202933;
    --accent: #8f86ff; --s1: #2cc5ae; --s2: #5b95f0; --s3: #e0a24a;
    --temp: #f07a64; --rh: #5aaef0; --pres: #a68cf0; --co: #9aa7b5; --co2: #4cc681;
    --tip: #e6ebf1; --tipText: #0f141a; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141a; --card: #171e26; --text: #e6ebf1; --muted: #8d99a8; --line: #26303b; --grid: #202933;
  --accent: #8f86ff; --s1: #2cc5ae; --s2: #5b95f0; --s3: #e0a24a;
  --temp: #f07a64; --rh: #5aaef0; --pres: #a68cf0; --co: #9aa7b5; --co2: #4cc681;
  --tip: #e6ebf1; --tipText: #0f141a; --shadow: none; color-scheme: dark;
}

/* ---------- base / layout ---------- */
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 "Sarabun", "Noto Sans Thai", "Leelawadee UI", system-ui, sans-serif; background: var(--bg); color: var(--text); }
.wrap { max-width: 1280px; margin: auto; padding: 0 16px 32px; }
.grid { display: grid; gap: var(--gap); margin-top: var(--gap); }
.top { grid-template-columns: 1fr 1.15fr 1fr 1.25fr; margin-top: 0; }
.kpis { grid-template-columns: repeat(7, 1fr); }
.two { grid-template-columns: 1fr 1fr; }
.three { grid-template-columns: repeat(3, 1fr); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.wide { margin-top: var(--gap); }
.card h2 { font-size: 14px; margin: 0 0 2px; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.lab { font-size: 13px; color: var(--muted); }
.cardhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.err { background: #fdecea; color: #a1261b; padding: 10px 14px; border-radius: 10px; margin-bottom: var(--gap); }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 0 4px; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; padding: 14px 0 12px; position: sticky; top: 0; z-index: 5; background: var(--bg); }
header h1 { margin: 0; font-size: 20px; }
header .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.pill, .themebtn { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: 13px; font-weight: 600; }
.themebtn { cursor: pointer; }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill.on i { background: var(--ok); animation: pulse-ok 2s ease-out infinite; }
.pill.off i { background: var(--off); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: none; color: var(--text); padding: 6px 12px; cursor: pointer; font: inherit; font-size: 13px; }
.seg.sm button { padding: 4px 10px; font-size: 12px; }
.seg button.on { background: var(--text); color: var(--bg); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- big value tiles ---------- */
.val { font-size: 56px; font-weight: 700; line-height: 1.05; margin-top: 6px; font-variant-numeric: tabular-nums; }
.val small { font-size: 16px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.foot { margin-top: 8px; font-size: 13px; color: var(--muted); }
.up { color: var(--off); }
.down { color: var(--ok); }

/* live */
.livehead { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 10px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; letter-spacing: .04em; color: var(--off); }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--off); animation: pulse 1.6s ease-out infinite; }
#live { width: 100%; height: 120px; display: block; margin-top: 4px; }
.flash { animation: flash 1.2s ease-out; }

/* AQI */
.aqi { display: flex; flex-direction: column; }
.aqi .row { display: flex; align-items: center; gap: 14px; margin-top: 8px; }
.aqi img { width: 84px; height: 84px; flex: none; }
.aqi .num { font-size: 52px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.aqi .lvl { font-size: 15px; font-weight: 700; margin-top: 4px; }
.aqi .by { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stripe { height: 6px; border-radius: 3px; margin: 12px 0 10px; background: var(--grid); transition: background .4s; }
.subs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.subs div { border: 1px solid var(--line); border-radius: 8px; padding: 5px 7px; font-size: 11px; color: var(--muted); }
.subs b { display: block; font-size: 16px; color: var(--text); }
.subs div.main { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.subs i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--muted)); margin-right: 4px; }

/* 24h average tile */
.ma { color: #fff; border: 0; background: #8792a0; transition: background .4s; }
.ma .lab, .ma .val small, .ma .foot, .scale-lbl { color: rgba(255, 255, 255, .88); }
.ma .lvl { font-size: 18px; font-weight: 700; margin-top: 4px; }
.ma.ink, .ma.ink .lab, .ma.ink .foot, .ma.ink .val small, .ma.ink .scale-lbl, .ma.ink .scale b { color: #1a1a1a; }
.ma.ink .scale b::after { border-top-color: #1a1a1a; }
.scale { display: flex; gap: 3px; margin-top: 26px; position: relative; }
.scale span { flex: 1; height: 10px; border-radius: 3px; border: 1.5px solid rgba(255, 255, 255, .9); }
.scale b { position: absolute; bottom: 13px; transform: translateX(-50%); font-size: 11px; font-weight: 700; color: #fff; white-space: nowrap; transition: left .6s; }
.scale b::after { content: ""; display: block; margin: 1px auto 0; width: 0; border: 6px solid transparent; border-top-color: #fff; border-bottom: 0; }
.scale-lbl { display: flex; justify-content: space-between; font-size: 11px; margin-top: 4px; }

/* map */
.mapcard { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
#map { position: relative; flex: 1; min-height: 200px; overflow: hidden; background: var(--grid); }
#map img { position: absolute; width: 256px; height: 256px; user-select: none; -webkit-user-drag: none; }
#map .pin { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; margin: -22px 0 0 -11px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--off); border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .35); z-index: 1; }
#map .zoom { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 4px; z-index: 1; }
#map .zoom button { width: 30px; height: 30px; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 7px; cursor: pointer; font-size: 17px; line-height: 1; }
#map .attr { position: absolute; right: 0; bottom: 0; background: rgba(255, 255, 255, .85); color: #333; font-size: 10px; padding: 1px 5px; z-index: 1; }
#map .attr a { color: #333; }
.mapinfo { padding: 10px 14px; font-size: 13px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.mapinfo a { color: var(--accent); }

/* KPI cards */
.kpi { padding: 12px 14px; }
.kpi .n { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi .v small { font-size: 12px; color: var(--muted); font-weight: 400; }
.kpi .d { font-size: 11px; color: var(--muted); min-height: 14px; }
.kpi svg { width: 100%; height: 30px; display: block; margin-top: 4px; }
.kpi.na { opacity: .45; }

/* charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 3px; border-radius: 2px; background: var(--c); vertical-align: middle; margin-right: 5px; }
.tip { position: absolute; top: 6px; pointer-events: none; background: var(--tip); color: var(--tipText); font-size: 12px; padding: 6px 9px; border-radius: 8px; white-space: nowrap; display: none; z-index: 2; line-height: 1.5; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

/* table */
.tbl { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; }
td small { color: var(--muted); font-size: 11px; }
tr.na { opacity: .5; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; color: #1a1a1a; }
.cell { display: inline-block; min-width: 52px; padding: 2px 8px; border-radius: 6px; color: #1a1a1a; font-weight: 600; }

/* ---------- animations ---------- */
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--off) 60%, transparent); } 100% { box-shadow: 0 0 0 8px transparent; } }
@keyframes pulse-ok { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); } 100% { box-shadow: 0 0 0 7px transparent; } }
@keyframes flash { 0% { background: color-mix(in srgb, var(--accent) 22%, var(--card)); } 100% { background: var(--card); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .top { grid-template-columns: 1fr 1fr; }
  .mapcard { grid-column: 1 / -1; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .three { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 700px) {
  header { position: static; }
  .top, .two, .three { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .val { font-size: 46px; }
}
