:root {
  color-scheme: light dark;
  --page: #f9f9f7; --surface: #fcfcfb; --text: #0b0b0b; --text-secondary: #52514e; --muted: #898781;
  --grid: #e1e0d9; --border: rgba(11, 11, 11, 0.10); --critical: #d03b3b;
  --temp-color: #eb6834; --hum-color: #2a78d6;
  /* 공기질 측정값 색 — dataviz 기준 팔레트에서 온도(주황)·습도(파랑)가 쓰지 않은 칸. 빨강은 경고색과 헷갈려 쓰지 않는다 */
  --pm25-color: #6250d6; --pm10-color: #1baf7a; --pm1-color: #e87ba4; --voc-color: #eda100; --no2-color: #008300;
  --comfort: rgba(137, 135, 129, 0.10);
  --humidifier: rgba(56, 189, 248, 0.28);
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d; --surface: #1a1a19; --text: #ffffff; --text-secondary: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --border: rgba(255, 255, 255, 0.10);
    --temp-color: #d95926; --hum-color: #3987e5;
    --pm25-color: #9085e9; --pm10-color: #199e70; --pm1-color: #d55181; --voc-color: #c98500; --no2-color: #008300;
    --comfort: rgba(137, 135, 129, 0.16);
    --humidifier: rgba(56, 189, 248, 0.34);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--page); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
main { max-width: 720px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 12px 24px; }

#login { display: grid; gap: 10px; margin-top: 18vh; }
#login h1 { font-size: 22px; margin: 0 0 8px; }
#login input, #login button { font: inherit; padding: 12px; border-radius: 10px; border: 1px solid var(--border); }
#login input { background: var(--surface); color: var(--text); }
#login button { background: var(--text); color: var(--page); font-weight: 700; border: 0; }
#login-msg { color: var(--critical); min-height: 1.4em; margin: 0; }
#login .hint { margin: 0; color: var(--text-secondary); font-size: 13px; }

.alert { background: var(--critical); color: #fff; border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-weight: 700; }

.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.card[aria-pressed="true"] { outline: 2px solid var(--text); } /* 선택한 방 */
.card:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; } /* 키보드 포커스 — 선택 표시보다 한 칸 바깥 */
.card .name, .card .vals { display: block; }
.card .name { color: var(--text-secondary); font-size: 13px; }
.card .temp { font-size: 22px; font-weight: 700; }
.card .hum { font-size: 15px; color: var(--text-secondary); margin-left: 8px; }
.card.off .vals { color: var(--muted); font-size: 15px; padding-top: 4px; }
.card.old .vals { opacity: .55; } /* 이 방만 보고가 끊김 — 옛 숫자 */
.card .age { display: block; color: var(--muted); font-size: 12px; }
.cards.stale { opacity: .55; } /* 경고 중에는 값이 오래된 것 */
/* 공기질 카드 — 첫 줄 PM2.5 숫자 + 등급 글자(색 없음 — 상태 색은 경고 배너 전용), 둘째 줄 공기청정기 상태 */
.card .pm { font-size: 22px; font-weight: 700; }
.card .grade { font-size: 15px; color: var(--text-secondary); margin-left: 8px; }
.card .sub { display: block; font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.card.off .pm { font-size: 15px; font-weight: 400; }
#air-now-error { margin: 0 0 8px; }

.ranges { display: flex; gap: 6px; margin: 14px 0 8px; }
.ranges button {
  flex: 1; padding: 8px 0; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-secondary); font: inherit;
}
.ranges button[aria-pressed="true"] { color: var(--text); font-weight: 700; border-color: var(--text-secondary); }

.chart { margin: 0 0 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 6px 8px; transition: opacity .15s; }
.chart.loading { opacity: .5; }
figcaption { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--text-secondary); padding: 0 6px 4px; word-break: keep-all; }
.chart-error { margin: 0; padding: 0 6px 6px; font-size: 12px; color: var(--critical); }

/* 끊김 구간 범례 — 그래프 안 라벨은 좁은 구간(7일 이상)에서 생략되므로 캡션 옆에 늘 보이게 둔다 */
.outage-chip { display: inline-flex; align-items: center; gap: 5px; flex: none; font-size: 12px; white-space: nowrap; }
.outage-chip .swatch {
  width: 16px; height: 12px; border: 1px solid var(--grid);
  background: repeating-linear-gradient(-45deg, var(--muted) 0 1px, transparent 1px 4px); /* 그래프 빗금과 같은 "/" 방향 */
}

/* 습도 그래프 아래 범례 — 가습기 켜짐 띠 */
.hum-legend { display: flex; align-items: center; gap: 5px; margin: 0; padding: 4px 6px 0; font-size: 12px; white-space: nowrap; }
.hum-legend .swatch { width: 16px; height: 12px; border: 1px solid var(--grid); background: var(--humidifier); }

.summary { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; margin-top: 6px; }
.summary th { color: var(--muted); font-weight: 500; text-align: right; padding: 3px 6px; }
.summary td { text-align: right; padding: 3px 6px; border-top: 1px solid var(--grid); }
.summary th:first-child, .summary td:first-child { text-align: left; }
#ap-cycle th, #ap-cycle td, #ap-onoff th, #ap-onoff td { word-break: keep-all; } /* 가전 표: 한글 단어 중간에서 꺾지 않고 띄어쓰기에서만 */
.summary caption { caption-side: bottom; text-align: left; color: var(--muted); font-size: 12px; padding: 4px 6px 0; } /* 최저·최고의 기준 */

.uplot { font-family: inherit; }

/* 그래프 위 값 말풍선 — 값이 굵은 잉크색으로 먼저, 시각은 아래 작은 글씨. 계열 색은 값 앞 12×2px 짧은 선으로만 */
.tip {
  position: absolute; top: 0; left: 0; pointer-events: none; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); font-variant-numeric: tabular-nums; line-height: 1.3;
}
.tip .v, .tip .t { display: block; }
.tip .v { font-size: 15px; font-weight: 700; color: var(--text); }
.tip .v::before { content: ""; display: inline-block; width: 12px; height: 2px; margin-right: 6px; vertical-align: middle; background: var(--line); }
.tip .t { font-size: 12px; color: var(--text-secondary); }
.foot { color: var(--muted); font-size: 12px; text-align: center; }

/* 탭 — 화면 맨 위. 고른 탭은 잉크색 바탕 */
.tabs { display: flex; gap: 6px; margin-bottom: 10px; overflow-x: auto; }
.tabs button {
  flex: 1 0 auto; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-secondary); font: inherit; font-weight: 600;
}
.tabs button[aria-pressed="true"] { background: var(--text); color: var(--page); border-color: var(--text); }

/* 가전 기록 탭 */
.panel { margin: 0 0 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.panel h2 { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 2px 0 6px; }
.panel .summary + h2 { margin-top: 14px; }
.note { margin: 6px 0 0; font-size: 12px; color: var(--muted); }

.now-list { list-style: none; margin: 0; padding: 0; }
.now-list li { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 7px 0; border-top: 1px solid var(--grid); }
.now-list li:first-child { border-top: 0; }
.now-list .name { color: var(--text-secondary); white-space: nowrap; }
.now-list .val { text-align: right; font-variant-numeric: tabular-nums; }
.now-list li.running .val { font-weight: 700; }
.now-list li.off .val { color: var(--muted); }

.ap-history { font-size: 15px; font-weight: 700; margin: 18px 0 8px; } /* 아래 칩은 이력만 거른다 */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.chips button {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-secondary); font: inherit; font-size: 14px;
}
.chips button[aria-pressed="true"] { color: var(--text); font-weight: 700; border-color: var(--text-secondary); }

.day { margin: 0 0 12px; }
.day h3 { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 0 0 4px; padding: 0 2px; }
.day ul { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.day li {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 8px 12px;
  border-top: 1px solid var(--grid); font-variant-numeric: tabular-nums;
}
.day li:first-child { border-top: 0; }
.day li .name { flex: 0 0 7em; color: var(--text-secondary); }
.day li .detail { margin-left: auto; color: var(--text-secondary); font-size: 14px; }
.day li.stopped .detail { color: var(--critical); }
.day li.outage { display: block; color: var(--critical); font-size: 13px; }
.empty { color: var(--muted); text-align: center; margin: 16px 0; }
.more {
  display: block; width: 100%; padding: 10px; margin: 4px 0 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}

/* 전기 탭 — 묶음 색: dataviz 기준 팔레트 1~5번 (라이트·다크 validate_palette.js 통과 2026-10-14).
   라이트의 청록·노랑·분홍은 대비 3:1 미만 → 막대마다 숫자를 잉크색 글자로 함께 쓴다 (relief 규칙) */
:root { --g-always: #2a78d6; --g-laundry: #eb6834; --g-kitchen: #1baf7a; --g-climate: #eda100; --g-other: #e87ba4; }
@media (prefers-color-scheme: dark) {
  :root { --g-always: #3987e5; --g-laundry: #d95926; --g-kitchen: #199e70; --g-climate: #c98500; --g-other: #d55181; }
}
.g-always { background: var(--g-always); }
.g-laundry { background: var(--g-laundry); }
.g-kitchen { background: var(--g-kitchen); }
.g-climate { background: var(--g-climate); }
.g-other { background: var(--g-other); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; flex: none; }

.en-stale { margin: 0 0 10px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary); font-size: 13px; }
.en-period { margin: 0; font-size: 13px; color: var(--text-secondary); }
.en-total { margin: 4px 0 0; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: pre-wrap; }

.en-rows { list-style: none; margin: 0; padding: 0; }
.en-rows li {
  display: grid; grid-template-columns: 6.2em minmax(0, 1fr) auto auto; align-items: center; gap: 2px 8px;
  padding: 6px 0; border-top: 1px solid var(--grid); font-size: 14px; font-variant-numeric: tabular-nums;
}
.en-rows.en-groups li { grid-template-columns: 7.4em minmax(0, 1fr) auto auto auto; }
.en-rows li:first-child { border-top: 0; }
.en-rows .name { display: flex; align-items: center; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.en-rows .num { text-align: right; white-space: nowrap; }
.en-rows .note-tag { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
/* 가로 막대 — 조각 사이 2px 배경색 간격, 끝 4px 둥글게 */
.hbar { display: flex; height: 10px; min-width: 0; }
.hbar .seg { display: block; height: 100%; box-sizing: border-box; }
.hbar .seg + .seg { border-left: 2px solid var(--surface); }
.hbar .seg:last-child { border-radius: 0 4px 4px 0; }

/* 시간대 — 24칸 세로 누적 막대, 칸마다 버튼 (아래부터 묶음 순서) */
.en-h2 { display: flex; justify-content: space-between; align-items: baseline; }
.axis-max { font-weight: 400; color: var(--muted); font-size: 12px; }
.en-hours { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 2px; height: 140px; border-bottom: 1px solid var(--grid); }
.en-hours .col {
  display: flex; flex-direction: column-reverse; height: 100%; padding: 0; margin: 0;
  border: 0; border-radius: 4px 4px 0 0; background: none; cursor: pointer; font: inherit;
}
.en-hours .col[aria-pressed="true"] { outline: 2px solid var(--text); outline-offset: 1px; }
.en-hours .seg { display: block; width: 100%; flex: none; box-sizing: border-box; }
.en-hours .seg + .seg { border-bottom: 2px solid var(--surface); }
.en-hours .seg:last-child { border-radius: 4px 4px 0 0; }
.en-axis { display: grid; grid-template-columns: repeat(24, minmax(0, 1fr)); font-size: 11px; color: var(--muted); margin-top: 3px; }
.en-axis span:nth-child(1) { grid-column: 1 / span 3; }
.en-axis span:nth-child(2) { grid-column: 7 / span 2; }
.en-axis span:nth-child(3) { grid-column: 13 / span 2; }
.en-axis span:nth-child(4) { grid-column: 19 / span 2; }
.en-axis span:nth-child(5) { grid-column: 23 / span 2; text-align: right; }
.en-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 8px 0 0; font-size: 12px; color: var(--text-secondary); }
.en-legend .item { display: inline-flex; align-items: center; }
.en-detail { margin: 8px 0 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
.en-detail p { margin: 0; }
.en-detail .title { font-weight: 700; }
.en-detail .items { margin-top: 2px; color: var(--text-secondary); }
.en-peak { margin: 10px 0 0; font-size: 14px; font-weight: 600; word-break: keep-all; }
#en-foot { word-break: keep-all; }

.apt-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.apt-amount { font-size: 1.5rem; font-weight: 700; margin: 6px 0; }

#apt-refresh { width: auto; flex: 0 0 auto; padding: 10px 14px; }
#tab-apartment .fr-heading > div { min-width: 0; }

.apt-toolbar, .apt-actions { display:flex; align-items:center; justify-content:space-between; gap:10px; }
.apt-actions { margin-top:18px; flex-wrap:wrap; }
.apt-actions .more { width:auto; margin:0; padding:10px 14px; }
.apt-dialog { width:min(440px, calc(100vw - 32px)); box-sizing:border-box; padding:20px; border:1px solid var(--border); border-radius:18px; background:var(--surface); color:var(--text); max-height:85vh; overflow:auto; }
.apt-dialog::backdrop { background:#0008; }
#apt-fields label { display:block; margin:14px 0 6px; }
#apt-fields input { box-sizing:border-box; width:100%; padding:12px; font:inherit; border:1px solid var(--border); border-radius:8px; background:var(--surface); color:var(--text); }
.apt-check { display:flex; gap:8px; margin:14px 0; font-size:14px; }
#apt-consent details { margin:12px 0; font-size:14px; }
#apt-review-text { white-space:pre-line; line-height:1.8; }
#apt-month { padding:8px; font:inherit; background:var(--surface); color:var(--text); border:1px solid var(--border); border-radius:8px; }
.apt-row button { margin:8px 8px 0 0; padding:8px 12px; font:inherit; border:1px solid var(--border); border-radius:8px; background:var(--surface); color:var(--text); }

.bill-heading { display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap; }
.bill-heading label { font-size:13px; color:var(--text-secondary); }
.bill-heading select { display:block; font:inherit; color:var(--text); background:var(--surface); border:1px solid var(--border); border-radius:8px; padding:8px; margin-top:4px; }
.bill-total { font-size:clamp(22px,6vw,30px);font-weight:700; margin:12px 0; }
.bill-paid { font-size:14px;font-weight:600; }
.bill-chart { display:flex; gap:4px; align-items:end; margin:16px 0 22px; min-height:112px; }
.bill-bar { flex:1; min-width:0; padding:0; border:0; background:transparent; color:var(--text-secondary); cursor:pointer; font:inherit; }
.bill-track { display:flex; height:88px; align-items:end; background:color-mix(in srgb,var(--text) 4%,transparent);border-radius:4px;overflow:hidden; }
.bill-fill { display:block; width:100%;background:var(--text-secondary);opacity:.5; min-height:0; }
.bill-bar[aria-pressed="true"] .bill-fill { opacity:1;background:var(--text); }
.bill-bar[aria-pressed="true"] .bill-tick { color:var(--text);font-weight:700; }
.bill-tick { display:block; margin-top:6px; font-size:10px; white-space:nowrap; }
.bill-table { width:100%; border-collapse:collapse; font-size:13px; margin-top:12px; }
.bill-table th,.bill-table td { padding:10px 3px; border-bottom:1px solid var(--border);text-align:right; }
.bill-table th:first-child,.bill-table td:first-child { text-align:left; }
.bill-table td:first-child { max-width:135px;overflow-wrap:anywhere; }
.bill-subitem { font-size:11px;color:var(--text-secondary); }
.bill-link { display:block; border:0; background:none; color:var(--text-secondary);padding:5px 0;font:inherit;font-size:11px;text-decoration:underline;cursor:pointer; }
.bill-metrics { display:flex;gap:6px;margin-top:18px; }
.bill-metrics button { padding:7px 14px; border:1px solid var(--border);border-radius:8px;background:var(--surface);color:var(--text);font:inherit; }
.bill-metrics button[aria-pressed="true"] { background:var(--text);color:var(--surface); }
#bill-detail summary { cursor:pointer;font-weight:600;font-size:14px; }

.news-link { font:inherit;font-size:13px;background:transparent;color:var(--text);border:1px solid var(--border);border-radius:8px;padding:8px 10px;cursor:pointer; }
.news-row { display:block;width:100%;text-align:left;font:inherit;background:transparent;color:var(--text);border:0;border-bottom:1px solid var(--border);padding:14px 0;cursor:pointer; }
.news-row strong { display:block;font-size:14px;line-height:1.6;overflow-wrap:anywhere; }
.news-row .note { display:block;margin:5px 0 0;font-size:12px; }
#news-dialog { box-sizing:border-box;width:min(660px,calc(100vw - 24px));max-height:88vh;padding:18px;border:1px solid var(--border);border-radius:18px;background:var(--surface);color:var(--text);overflow:auto; }
#news-dialog::backdrop {background:#0008;}
#news-title { font-size:18px;overflow-wrap:anywhere;line-height:1.5; }
#news-dialog .apt-toolbar { align-items:flex-start; }
#news-close {flex-shrink:0;}
#news-category {font:inherit;padding:8px;background:var(--surface);color:var(--text);border:1px solid var(--border);border-radius:8px;}
#news-body p {white-space:pre-wrap;overflow-wrap:anywhere;font-size:14px;line-height:1.8;}
#news-body img {display:block;max-width:100%;height:auto;margin:12px auto;}
