@font-face {
  font-family: "Noto Sans Thai";
  src: url("./fonts/NotoSansThai.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;
  font-family: "Noto Sans Thai", system-ui, sans-serif;
  color: #e9efed;
  background: #0e1213;
  --muted: #a2b0ad;
  --line: #293330;
  --green: #7de5b6;
  --tint: #20372e;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; }
button, select, input { font: inherit; }
button, select { cursor: pointer; }
select:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
.symbols { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 222px;
  padding: 34px 18px 22px;
  background: #121718;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 1;
}
.brand { display: flex; align-items: center; gap: 11px; margin: 0 8px 42px; font-size: 19px; font-weight: 750; letter-spacing: -.7px; line-height: 1.05; width: max-content; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; color: #9cf8c6; background: #192523; border-radius: 11px; }
.brand-mark .icon { width: 19px; height: 19px; }
.brand-accent { color: var(--green); }
.brand small { display: block; color: var(--muted); margin-top: 6px; font-size: 8px; font-weight: 750; letter-spacing: 1.8px; }
.sidebar nav { display: grid; gap: 6px; }
.nav-link { min-height: 46px; display: flex; align-items: center; gap: 11px; color: var(--muted); padding: 0 12px; border-radius: 9px; font-size: 14px; font-weight: 600; }
.nav-link:hover { background: #1c2622; }
.nav-link.active { background: var(--tint); color: #8ce9bd; }
.nav-link .icon { width: 18px; height: 18px; }
.source { display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); margin-top: auto; padding: 10px; border-radius: 10px; font-size: 12px; }
.source small { display: block; color: var(--muted); margin-top: 2px; }
.source-icon { width: 31px; height: 31px; border-radius: 7px; background: #1c2924; display: grid; place-items: center; color: var(--green); }
.source-icon .icon { width: 16px; height: 16px; }
.source .dot { margin-left: auto; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #9ba5a4; flex: none; }
.dot[data-tone="on"], .connection[data-tone="on"] .dot { background: #25ad74; }
.dot[data-tone="warn"], .connection[data-tone="warn"] .dot { background: #c2842c; }

main { margin-left: 222px; max-width: 1550px; padding: 37px clamp(22px, 3.1vw, 54px) 20px; }
section { scroll-margin-top: 20px; }
.page-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 23px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(29px, 3.2vw, 43px); font-weight: 750; letter-spacing: -.025em; line-height: 1.2; }
.page-header p { margin-top: 5px; color: var(--muted); font-size: 14px; }
.header-controls { display: flex; align-items: center; gap: 10px; }
.connection { display: inline-flex; align-items: center; gap: 7px; min-height: 35px; padding: 0 10px; border-radius: 6px; white-space: nowrap; font-size: 12px; font-weight: 650; color: var(--muted); background: #232e2a; }
.connection[data-tone="on"] { color: #9aecc6; background: #203b2e; }
.connection[data-tone="warn"] { color: #f1c379; background: #3a2e1c; }
.device-select { position: relative; display: flex; align-items: center; min-width: 0; color: var(--muted); }
.device-select .icon { position: absolute; left: 10px; pointer-events: none; width: 16px; height: 16px; }
.device-select .chevron { right: 9px; left: auto; }
.device-select select { appearance: none; min-height: 39px; max-width: 215px; padding: 0 28px 0 32px; background: #24372e; color: #e9efed; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-weight: 650; text-overflow: ellipsis; }

.hero { position: relative; min-height: 276px; isolation: isolate; display: flex; align-items: center; overflow: hidden; border-radius: 15px; background: #151819; color: #f6f9f8; }
.hero::before { content: ""; position: absolute; inset: 0 0 0 27%; z-index: -2; background: url("./house.webp") center 53% / cover no-repeat; }
.hero::after { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(90deg, #151819 24%, #151819 30%, #15181900 60%), linear-gradient(0deg, #15181946, transparent 38%); }
.hero-content { padding: 34px 40px; width: min(100%, 440px); }
.eyebrow { display: flex; align-items: center; gap: 7px; color: #9ceec4; font-weight: 650; font-size: 15px; }
.eyebrow .icon { width: 17px; height: 17px; }
.hero-reading { display: flex; align-items: baseline; gap: 10px; margin: 10px 0 16px; font-variant-numeric: tabular-nums; }
.hero-reading strong { font-size: clamp(50px, 7.7vw, 104px); font-weight: 650; line-height: .98; letter-spacing: -.085em; }
.hero-reading span { font-size: clamp(21px, 3.2vw, 42px); color: #aabbb7; font-weight: 400; }
.hero-device { color: #d4dfdc; font-size: 13px; font-weight: 550; display: flex; align-items: center; gap: 8px; overflow-wrap: anywhere; }
.hero-device .dot[data-tone="on"] { box-shadow: 0 0 13px #65dba8; }
.notice { margin-top: 12px; padding: 10px 14px; border: 1px solid #69502c; background: #30281b; border-radius: 8px; color: #f1cd91; font-size: 13px; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; margin-top: 15px; }
.metric, .panel { background: #181f20; border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.metric { padding: 14px 16px 16px; }
.metric-icon { display: inline-grid; place-items: center; height: 33px; width: 33px; color: var(--green); border-radius: 8px; background: var(--tint); flex: none; }
.metric-icon .icon { width: 17px; height: 17px; }
.metric h2 { color: var(--muted); font-size: 12px; font-weight: 650; margin: 10px 0 3px; }
.metric p { line-height: 1.25; white-space: nowrap; }
.metric strong, .bill-total strong { font-size: clamp(22px, 2.3vw, 32px); font-weight: 680; letter-spacing: -.06em; font-variant-numeric: tabular-nums; }
.metric p span, .bill-total span { color: var(--muted); font-size: 13px; font-weight: 550; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 2.35fr) minmax(230px, 1fr); gap: 15px; margin-top: 15px; }
.panel { padding: 19px 20px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.panel-heading h2 { font-size: 20px; font-weight: 750; letter-spacing: -.015em; line-height: 1.2; }
.panel-heading p, .chart-caption { color: var(--muted); font-size: 12px; margin-top: 5px; line-height: 1.5; }
.segments { display: flex; padding: 3px; gap: 2px; border-radius: 8px; background: #111a17; }
.segments button, .chart-toolbar button { color: var(--muted); font-size: 12px; font-weight: 650; border: 1px solid transparent; border-radius: 6px; white-space: nowrap; background: transparent; transition: background .14s; }
.segments button { padding: 4px 8px; }
.segments button:hover, .chart-toolbar button:hover { background: var(--tint); }
.segments button[aria-pressed="true"] { color: #a0f3ce; background: #24372e; border-color: #3a5348; box-shadow: 0 1px 3px #2035310c; }
.chart-toolbar { display: flex; gap: 5px; margin-top: 13px; }
.chart-toolbar button { padding: 3px 8px; }
.chart-toolbar button[aria-pressed="true"] { color: #8ce9bd; background: var(--tint); }
.plot { position: relative; width: 100%; height: 170px; margin-top: 3px; }
#chart { width: 100%; height: 100%; display: block; overflow: visible; }
.chart-message { position: absolute; inset: 16px 0 21px 36px; display: grid; place-items: center; background: #151e1b; color: var(--muted); font-size: 13px; border-radius: 6px; text-align: center; padding: 8px; }
.axis-label { font-size: 10px; fill: #a2b0ad; }
.grid-line { stroke: #293831; }
.chart-line { stroke: #73dfad; stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: #73dfad; }
.hover-line { stroke: #79b89d; stroke-dasharray: 3 3; }
.hover-dot { fill: #73dfad; stroke: #181f20; stroke-width: 2; }
.tooltip { position: absolute; top: 3px; z-index: 1; pointer-events: none; background: #172420; color: white; border-radius: 6px; padding: 5px 8px; font-size: 11px; white-space: nowrap; }
.chart-stats { border-top: 1px solid var(--line); padding-top: 9px; display: flex; gap: 14px; color: var(--muted); font-size: 12px; }
.chart-stats strong { color: #e9efed; font-weight: 700; }
.chart-zone { margin-left: auto; }
.bill-total { margin: 19px 0 17px; font-variant-numeric: tabular-nums; }
.bill-total strong { font-size: clamp(32px, 3.4vw, 46px); }
.bill-fields { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 9px; font-size: 13px; }
.bill-fields label { font-weight: 650; }
.bill-fields label span { display: block; color: var(--muted); font-size: 11px; font-weight: 400; }
.bill-fields input, .bill-fields select { color: #e9efed; background: #111a17; width: 73px; height: 33px; padding: 0 7px; border-radius: 6px; border: 1px solid var(--line); font-size: 13px; }
.bill-note { color: var(--muted); margin-top: 15px; border-top: 1px solid var(--line); padding-top: 12px; font-size: 11px; }

.devices-panel { margin-top: 15px; }
.device-list { list-style: none; padding: 0; margin: 13px 0 0; font-size: 13px; color: var(--muted); }
.device-list li + li { border-top: 1px solid var(--line); }
.device-row { width: 100%; display: flex; align-items: center; text-align: left; gap: 9px; background: #181f20; border: 0; color: #e9efed; padding: 9px 6px; border-radius: 7px; }
.device-row:hover, .device-row[aria-pressed="true"] { background: #20372e; }
.device-row strong { overflow-wrap: anywhere; min-width: 0; }
.device-row small { color: var(--muted); }
.device-row .device-watts { margin-left: auto; font-weight: 650; white-space: nowrap; }
footer { display: flex; align-items: center; gap: 6px; margin: 13px 1px 0; color: var(--muted); font-size: 11px; }
footer .icon { width: 13px; height: 13px; }

@media (max-width: 1050px) {
  .sidebar { width: 185px; padding-inline: 12px; }
  main { margin-left: 185px; }
  .detail-grid { grid-template-columns: minmax(0, 1.8fr) minmax(220px, 1fr); }
  .panel { padding-inline: 15px; }
}
@media (max-width: 810px) {
  .sidebar { position: static; width: auto; padding: 11px 17px; border-right: 0; border-bottom: 1px solid var(--line); flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
  .sidebar nav { display: flex; gap: 3px; }
  .brand { margin: 0; font-size: 17px; }
  .brand-mark { width: 32px; height: 32px; }
  .source { display: none; }
  .nav-link { min-height: 36px; padding-inline: 8px; font-size: 12px; gap: 5px; }
  .nav-link .icon { width: 15px; height: 15px; }
  main { margin-left: 0; padding: 23px 16px 17px; }
}
@media (max-width: 580px) {
  .sidebar { flex-wrap: wrap; }
  .sidebar nav { width: 100%; }
  .nav-link { flex: 1; justify-content: center; }
  .page-header { flex-wrap: wrap; margin-bottom: 15px; gap: 11px; }
  .header-controls { width: 100%; justify-content: space-between; }
  .device-select select { max-width: min(190px, 100%); min-width: 0; }
  .hero { min-height: 273px; align-items: end; }
  .hero::before { inset: 0; background-position: center 38%; background-size: cover; }
  .hero::after { background: linear-gradient(0deg, #151819 1%, #151819ed 15%, #15181958 56%, transparent 100%); }
  .hero-content { padding: 104px 19px 20px; }
  .hero-reading { margin: 5px 0 8px; }
  .hero-reading strong { font-size: 59px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 9px; }
  .metric { padding: 11px; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); gap: 9px; margin-top: 9px; }
  .devices-panel { margin-top: 9px; }
  .plot { height: 177px; }
  .segments button { padding-inline: 5px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
