/* ============================================================
   "Vườn trong nhà" — design system theo phong cách cây sống
   Tông thiên nhiên: lá xanh làm điểm nhấn, bề mặt mềm, bo tròn,
   mỗi khối có biểu tượng minh hoạ riêng. Sáng & tối.
   ============================================================ */
:root {
  /* SF Pro trên thiết bị Apple (font hệ thống), Inter ở nơi khác */
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", "Segoe UI", system-ui, sans-serif;

  --bg: #edf3ef;
  --bg-glow: #d6ebff;
  --surface: #ffffff;
  --surface-2: #f2f7f3;
  --surface-3: #e7f0ea;
  --ink: #2b3b34;
  --ink-strong: #0f211a;
  --muted: #7f9289;
  --line: #e3ece6;

  --accent: #1f9d55;
  --accent-2: #3fc47c;
  --accent-ink: #ffffff;
  --accent-soft: #e2f4e9;
  --accent-glow: rgba(31, 157, 85, .28);

  --good: #16a34a;
  --warn: #d97706;
  --poor: #ea580c;
  --bad: #dc2626;

  /* màu từng chỉ số — dùng chung cho chip + biểu đồ */
  --c-pm25: #10b981;
  --c-temp: #f97316;
  --c-hum: #3b82f6;
  --c-fan: #8b5cf6;
  --c-filter: #84cc16;

  --radius: 26px;
  --radius-md: 18px;
  --radius-sm: 999px;
  --shadow-card: 0 1px 0 rgba(255, 255, 255, .7) inset, 0 18px 40px -18px rgba(28, 72, 48, .22), 0 4px 12px rgba(28, 72, 48, .05);
  --shadow-soft: 0 8px 20px -8px rgba(28, 72, 48, .18);
  --shadow-pill: 0 6px 16px -6px rgba(28, 72, 48, .22);
}

html[data-theme="dark"] {
  /* kiểu tối của Apple: nền gần đen trung tính, bề mặt xám sạch, chữ trắng rõ */
  --bg: #0b0b0c;
  --bg-glow: #0b0b0c;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --surface-3: #3a3a3c;
  --ink: #e5e5ea;
  --ink-strong: #ffffff;
  --muted: #98989f;
  --line: rgba(255, 255, 255, .08);

  --accent: #5aa97f;
  --accent-2: #74b994;
  --accent-ink: #0b1f15;
  --accent-soft: rgba(90, 169, 127, .14);
  --accent-glow: rgba(0, 0, 0, 0);

  --good: #5aa97f;
  --warn: #ff9f0a;
  --poor: #ff7a45;
  --bad: #ff453a;

  --c-pm25: #5cb894;
  --c-temp: #ff9f0a;
  --c-hum: #409cff;
  --c-fan: #bf5af2;
  --c-filter: #9fbf6e;

  --shadow-card: none;
  --shadow-soft: none;
  --shadow-pill: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  letter-spacing: -.011em;
  background:
    radial-gradient(1100px 460px at 50% -180px, var(--bg-glow), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s, color .25s;
}

button { touch-action: manipulation; font-family: inherit; }
input, select { font-family: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------------- header ---------------- */
header {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}
header {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px max(16px, calc((100vw - 1140px) / 2 + 16px));
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-logo {
  width: 40px; height: 40px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(140deg, var(--accent-2), var(--accent));
  box-shadow: 0 8px 18px -6px var(--accent-glow);
}
html[data-theme="dark"] .brand-logo { color: var(--accent-ink); }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.brand-text b { font-size: 16px; font-weight: 700; color: var(--ink-strong); white-space: nowrap; }
.brand-sub {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  font-size: 12px; color: var(--muted);
}
.brand-sub span { white-space: nowrap; }
.brand-sub #deviceInfo { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.brand-sub .sep { opacity: .6; }
.header-right { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: 0 0 auto; }

.icon-btn {
  width: 40px; height: 40px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  box-shadow: var(--shadow-pill);
  cursor: pointer;
  transition: transform .15s, color .15s, background .25s;
  flex: 0 0 auto;
}
.icon-btn:hover { color: var(--accent); transform: translateY(-1px); }
.icon-btn:disabled { opacity: .5; cursor: default; transform: none; }
.icon-btn.loading svg { animation: spin 1.6s linear infinite; }
html[data-theme="light"] .ico-sun { display: none; }
html[data-theme="dark"] .ico-moon { display: none; }

.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); display: inline-block; flex: 0 0 auto;
  position: relative;
}
.dot.ok { background: var(--good); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.dot.ok::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%;
  border: 2px solid var(--good); opacity: 0;
  animation: pulse 2.6s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(.5); opacity: .8; }
  70%, 100% { transform: scale(1.6); opacity: 0; }
}

main { max-width: 1140px; margin: 0 auto; padding: 18px 16px 8px; }

.banner {
  max-width: 1108px; margin: 14px auto 0; padding: 12px 16px;
  background: color-mix(in srgb, var(--warn) 12%, var(--surface));
  color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500;
}

/* ---------------- panels + section headers ---------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-top: 18px;
  padding: 22px;
  box-shadow: var(--shadow-card);
}
main > .panel:first-child { margin-top: 0; }
.sec-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; min-width: 0; }
.sec-ico {
  width: 40px; height: 40px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
}
.sec-title { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.sec-title h2 { margin: 0; font-size: 17px; font-weight: 700; color: var(--ink-strong); }
.sec-title p { margin: 0; font-size: 12.5px; color: var(--muted); font-weight: 400; }
.note { color: var(--muted); font-size: 12px; margin: 14px 0 0; line-height: 1.5; }

/* ---------------- buttons ---------------- */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 14px;
  padding: 9px 16px;
  font-size: 13.5px; font-weight: 600;
  cursor: pointer;
  min-height: 40px;
  box-shadow: var(--shadow-pill);
  transition: transform .15s, box-shadow .15s, color .15s, background .25s;
}
.btn:hover { color: var(--accent); transform: translateY(-1px); }
.btn.primary {
  border-color: transparent;
  background: linear-gradient(140deg, var(--accent-2), var(--accent));
  color: var(--accent-ink);
  box-shadow: 0 10px 22px -8px var(--accent-glow);
}
.btn.primary:hover { color: var(--accent-ink); box-shadow: 0 12px 26px -8px var(--accent-glow); }
.btn.small { padding: 7px 13px; font-size: 12.5px; min-height: 36px; border-radius: 12px; }
.btn:disabled { opacity: .45; cursor: default; transform: none; }

.loading { opacity: .72; pointer-events: none; }
.btn.loading::after, .seg.loading::after {
  content: ""; display: inline-block;
  width: 12px; height: 12px; margin-left: 8px;
  border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%;
  vertical-align: middle;
  animation: spin 1.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- segmented (dùng chung) ---------------- */
.segmented {
  display: flex; gap: 4px;
  background: var(--surface-3);
  padding: 4px;
  border-radius: 14px;
}
.seg {
  flex: 1 1 0; min-width: 0;
  border: none; background: transparent;
  border-radius: 11px;
  min-height: 36px;
  font-size: 13px; font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background .2s, color .2s, box-shadow .2s;
}
.seg:hover { color: var(--ink-strong); }
.seg.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow-pill);
}

/* ---------------- điều khiển: ô chế độ ---------------- */
.mode-tiles {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px;
  background: none; padding: 0; border-radius: 0;
}
.mode-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  text-align: left;
  padding: 14px;
  min-height: 0;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  border: 1.5px solid transparent;
  color: var(--ink);
  transition: background .25s, border-color .25s, transform .15s, box-shadow .25s;
}
.mode-tile:hover { transform: translateY(-2px); color: var(--ink); }
.mode-tile .mt-ico {
  width: 40px; height: 40px; margin-bottom: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 13px;
  background: var(--surface);
  color: var(--muted);
  transition: background .25s, color .25s;
}
.mode-tile b { font-size: 14.5px; font-weight: 700; color: var(--ink-strong); }
.mode-tile small { font-size: 11.5px; color: var(--muted); font-weight: 400; }
.mode-tile.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 10px 24px -12px var(--accent-glow);
}
.mode-tile.active .mt-ico { background: var(--accent); color: var(--accent-ink); }
.mode-tile.active b { color: var(--accent); }
.mode-tile.loading::after { position: absolute; top: 14px; right: 14px; }
.mode-tile { position: relative; }

/* ---------------- điều khiển: tốc độ Favorite ---------------- */
.speed-card {
  margin-top: 14px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 16px 18px 12px;
}
.speed-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.speed-label { display: block; font-size: 12.5px; color: var(--muted); }
.speed-val { display: flex; align-items: baseline; gap: 5px; }
.speed-val b { font-size: 30px; line-height: 1.1; font-weight: 700; color: var(--ink-strong); }
.speed-val small { font-size: 13px; color: var(--muted); }

.leaf-range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 10px; margin: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent)) 0 / var(--fill, 50%) 100% no-repeat, var(--surface-3);
  outline: none; cursor: pointer;
}
.leaf-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--accent);
  box-shadow: 0 4px 10px -2px var(--accent-glow);
  transition: transform .15s;
}
.leaf-range::-webkit-slider-thumb:hover { transform: scale(1.12); }
.leaf-range::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--accent);
}
.leaf-range:focus-visible { box-shadow: 0 0 0 4px var(--accent-soft); }
.speed-scale { display: flex; justify-content: space-between; margin-top: 8px; font-size: 11px; color: var(--muted); }

/* ---------------- điều khiển: cài đặt khác ---------------- */
.advanced { margin-top: 14px; border-radius: var(--radius-md); border: 1px dashed var(--line); }
.advanced-toggle {
  width: 100%;
  display: flex; justify-content: space-between; align-items: center;
  background: transparent; border: none;
  padding: 12px 16px; min-height: 46px;
  font-size: 13.5px; font-weight: 600;
  color: var(--muted);
  cursor: pointer; border-radius: var(--radius-md);
}
.advanced-toggle:hover { color: var(--ink-strong); }
.chev { transition: transform .25s ease; color: var(--muted); flex: 0 0 auto; }
.advanced-toggle.open .chev, .panel-toggle.open .chev { transform: rotate(90deg); }
.advanced-content { display: none; padding: 0 12px 12px; }
.advanced-content.open { display: block; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.setting { background: var(--surface-2); border-radius: var(--radius-md); padding: 12px 14px; }
.setting-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; font-weight: 600; color: var(--ink); }
.set-ico {
  width: 28px; height: 28px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; background: var(--surface); color: var(--accent);
}

/* ---------------- biểu đồ ---------------- */
.range-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.presets {
  display: flex; gap: 2px; flex-wrap: wrap;
  background: var(--surface-3);
  padding: 4px; border-radius: 14px;
}
.presets .btn {
  border: none; background: transparent; box-shadow: none;
  border-radius: 11px; min-height: 34px; padding: 7px 13px;
  font-weight: 500; color: var(--muted);
}
.presets .btn:hover { color: var(--ink-strong); transform: none; }
.presets .btn.range.active { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: var(--shadow-pill); }
.custom-range { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.custom-range input, .table-filter input[type=date], .table-filter select {
  min-height: 38px; padding: 7px 10px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-2); color: var(--ink);
  font-size: 13px;
}
html[data-theme="dark"] input[type=date], html[data-theme="dark"] input[type=datetime-local] { color-scheme: dark; }

.metrics { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.metric-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1.5px solid transparent;
  cursor: pointer; user-select: none;
  transition: background .2s, color .2s, border-color .2s;
}
.metric-chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip-dot { width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--chip); transition: background .2s; }
.metric-chip:has(input:checked) {
  color: var(--ink-strong);
  background: color-mix(in srgb, var(--chip) 12%, var(--surface));
  border-color: color-mix(in srgb, var(--chip) 45%, transparent);
}
.metric-chip input:checked + .chip-dot { background: var(--chip); }
.metric-chip:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--accent-soft); }

.chart-wrap { background: var(--surface-2); border-radius: var(--radius-md); padding: 10px 6px 6px; }
.chart { width: 100%; height: 300px; }
.chart.tall { height: 360px; }

/* lõi lọc */
.filter-block {
  margin-top: 16px;
  display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 14px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 14px;
}
.filter-block .chart { height: 180px; }
.filter-sum { display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 12px; padding: 6px; }
.filter-ring {
  --p: 0;
  width: 92px; height: 92px; border-radius: 50%;
  display: grid; place-items: center;
  background:
    radial-gradient(closest-side, var(--surface-2) 74%, transparent 75%),
    conic-gradient(var(--ring, var(--c-filter)) calc(var(--p) * 1%), var(--surface-3) 0);
  transition: --p .8s;
}
.filter-ring span { font-size: 20px; font-weight: 700; color: var(--ink-strong); }
.filter-text { display: flex; flex-direction: column; gap: 2px; }
.filter-kicker { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.filter-kicker svg { color: var(--accent); }
.filter-text b { font-size: 15px; color: var(--ink-strong); }
.filter-days { font-size: 12.5px; color: var(--muted); }

/* ---------------- bảng ---------------- */
.panel-toggle {
  width: 100%;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: transparent; border: none; padding: 0; margin: 0;
  cursor: pointer; text-align: left; color: inherit;
}
.panel-toggle .sec-head { margin-bottom: 0; }
.panel-toggle:hover .chev { color: var(--accent); }
.panel-content { display: none; margin-top: 18px; }
.panel-content.open { display: block; }

.table-filter { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.table-filter label { display: flex; flex-direction: column; gap: 5px; font-size: 11.5px; color: var(--muted); font-weight: 500; }
.filter-hint { font-size: 11.5px; color: var(--muted); }
.table-tools { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; flex-wrap: wrap; font-size: 12.5px; }
.table-nav { display: flex; gap: 8px; }

.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th {
  position: sticky; top: 0;
  background: var(--surface-2);
  color: var(--muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .03em;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: var(--surface-2); }
td.num { font-variant-numeric: tabular-nums; }
#dataTable th:first-child, #dataTable td:first-child {
  position: sticky; left: 0; z-index: 1;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--line);
}
#dataTable thead th:first-child { background: var(--surface-2); z-index: 2; }
#dataTable tbody tr:hover td:first-child { background: var(--surface-2); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  background: var(--surface-3); color: var(--muted);
}
.pill.ok { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.pill.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.pill.off { background: var(--surface-3); color: var(--muted); }
.pill.mode { background: var(--accent-soft); color: var(--accent); }
.lvl-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; }
.empty-row td { text-align: center; color: var(--muted); padding: 22px; }

/* ---------------- toast + footer ---------------- */
.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 60;
  max-width: 360px;
  padding: 12px 16px 12px 14px;
  border-radius: 16px;
  font-size: 13px; font-weight: 500;
  background: var(--surface); color: var(--ink-strong);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, .35);
}
.toast.ok { border-left-color: var(--good); }
.toast.err { border-left-color: var(--bad); }

footer {
  max-width: 760px; margin: 0 auto;
  display: flex; gap: 8px; justify-content: center; align-items: flex-start;
  text-align: center; color: var(--muted);
  font-size: 11.5px; line-height: 1.5;
  padding: 26px 16px 30px;
}
footer svg { color: var(--accent); flex: 0 0 auto; margin-top: 2px; }

/* ---------------- responsive ---------------- */
@media (max-width: 860px) {
  .filter-block { grid-template-columns: 1fr; }
  .filter-sum { flex-direction: row; align-items: center; }
}
@media (max-width: 700px) {
  header { padding: 9px 14px; }
  .brand-logo { width: 36px; height: 36px; border-radius: 12px; }
  .brand-text b { font-size: 15px; }
  .brand-sub { font-size: 11px; }
  .brand-sub #deviceInfo, .brand-sub .sep { display: none; }
  .icon-btn { width: 36px; height: 36px; border-radius: 12px; }

  main { padding: 12px 12px calc(10px + env(safe-area-inset-bottom)); }
  .banner { margin: 10px 12px 0; font-size: 12.5px; }
  .panel { padding: 15px; border-radius: 22px; margin-top: 12px; }
  .sec-head { gap: 10px; margin-bottom: 14px; }
  .sec-ico { width: 36px; height: 36px; border-radius: 12px; }
  .sec-title h2 { font-size: 15.5px; }
  .sec-title p { font-size: 11.5px; }

  .mode-tiles { gap: 8px; }
  .mode-tile { padding: 11px 10px; }
  .mode-tile .mt-ico { width: 34px; height: 34px; border-radius: 11px; margin-bottom: 6px; }
  .mode-tile b { font-size: 13.5px; }
  .mode-tile small { font-size: 10.5px; }
  .speed-card { padding: 14px 14px 10px; }
  .speed-val b { font-size: 26px; }
  .settings-grid { grid-template-columns: 1fr; gap: 10px; }
  .setting { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 10px 10px 12px; }
  .setting-head { margin: 0; min-width: 0; font-size: 12.5px; }
  .setting .segmented { flex: 0 0 54%; }
  .setting .seg { min-height: 34px; font-size: 12px; }
  .seg { min-height: 38px; }

  .range-bar { gap: 8px; }
  .presets { width: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .presets::-webkit-scrollbar { display: none; }
  .presets .btn { flex: 1 0 auto; padding: 7px 11px; font-size: 12px; white-space: nowrap; }
  .custom-range { width: 100%; }
  .custom-range label { flex: 1 1 45%; display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; }
  .custom-range input { width: 100%; }
  .custom-range #applyCustom { flex-basis: 100%; }
  .metrics { margin-left: 0; width: 100%; gap: 6px; }
  .metric-chip { padding: 6px 11px; font-size: 12px; }
  .chart-wrap { padding: 6px 2px 2px; border-radius: 14px; }
  .chart { height: 220px; }
  .chart.tall { height: 260px; }
  .filter-block { padding: 12px; border-radius: 14px; }
  .filter-block .chart { height: 160px; }
  .filter-ring { width: 76px; height: 76px; }
  .filter-ring span { font-size: 17px; }

  table { font-size: 12px; }
  th, td { padding: 8px 10px; }
  .table-filter { gap: 8px; }
  .table-filter label { flex: 1 1 45%; }
  .table-filter input[type=date], .table-filter select { width: 100%; }
  .table-filter .btn, .filter-hint { flex: 1 1 100%; }
  .table-tools { flex-direction: column; align-items: stretch; gap: 8px; }
  .table-nav { justify-content: space-between; }
  .table-nav .btn { flex: 1; }

  .toast { right: 12px; left: 12px; max-width: none; bottom: calc(12px + env(safe-area-inset-bottom)); }
  footer { padding: 18px 14px calc(22px + env(safe-area-inset-bottom)); font-size: 11px; }
}
@media (max-width: 360px) {
  .mode-tile small { display: none; }
  .presets .btn { font-size: 11.5px; }
}

/* ---------------- chuyển động ---------------- */
@keyframes riseIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
.panel { animation: riseIn .55s cubic-bezier(.22, .61, .36, 1) backwards; }
main .panel:nth-of-type(1) { animation-delay: .04s; }
main .panel:nth-of-type(2) { animation-delay: .12s; }
main .panel:nth-of-type(3) { animation-delay: .2s; }
main .panel:nth-of-type(4) { animation-delay: .28s; }
main .panel:nth-of-type(5) { animation-delay: .36s; }

.panel-content.open, .advanced-content.open { animation: contentIn .28s cubic-bezier(.22, .61, .36, 1); }
@keyframes contentIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.14); } 100% { transform: scale(1); } }

@keyframes flashRing {
  0% { box-shadow: var(--shadow-pill), 0 0 0 0 var(--accent-glow); }
  100% { box-shadow: var(--shadow-pill), 0 0 0 22px rgba(0, 0, 0, 0); }
}

@keyframes rowIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
tbody tr { animation: rowIn .3s ease backwards; }
tbody tr:nth-child(2) { animation-delay: .03s; }
tbody tr:nth-child(3) { animation-delay: .06s; }
tbody tr:nth-child(4) { animation-delay: .09s; }
tbody tr:nth-child(5) { animation-delay: .12s; }
tbody tr:nth-child(6) { animation-delay: .15s; }
tbody tr:nth-child(7) { animation-delay: .18s; }
tbody tr:nth-child(8) { animation-delay: .21s; }
tbody tr:nth-child(9) { animation-delay: .24s; }
tbody tr:nth-child(10) { animation-delay: .27s; }

.toast { animation: toastIn .32s cubic-bezier(.22, .61, .36, 1); }
.toast.hide { animation: toastOut .22s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(12px); } }

.panel, .setting, .speed-card, .segmented, .btn, header, .stat, .mode-tile, .metric-chip,
.table-wrap, thead th, .toast, .icon-btn {
  transition: background-color .25s ease, color .2s ease, border-color .25s ease, box-shadow .2s ease, transform .15s ease;
}

@media (prefers-reduced-motion: reduce) {
  /* Khi macOS bật "Reduce motion", Chrome báo prefers-reduced-motion: reduce.
     Rút duration còn .01ms mà để lặp vô hạn sẽ khiến quạt/refresh/mây/bụi quay hàng
     nghìn vòng mỗi giây → nhấp nháy, giật. Phải chạy đúng 1 vòng rồi dừng. */
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: .01ms !important;
  }
}

/* ============================================================
   Living Environment Tree — một cảnh duy nhất gộp 3 chỉ số
   PM2.5  -> màu tán lá, bụi, mù, khẩu trang, lá rụng
   Nhiệt  -> bầu trời, mặt trời, sóng nhiệt, mồ hôi, tuyết, khăn
   Độ ẩm  -> màu đất, đất nứt, tán rũ, giọt sương, sương mù, mưa
   ============================================================ */
.hero {
  padding: 18px;
  /* bảng màu mặc định (trước khi có dữ liệu) */
  --sky-top: #c4e2ff; --sky-bot: #eef7ff;
  --leaf-1: #9cf0b6; --leaf-2: #5ad38a; --leaf-3: #2f9e5f;
  --ground: #9bd49a;
  --trunk: #8a5a33;
  --face: #1f3b2a;
  --dust: rgba(150, 130, 95, .55);
  --haze-color: #b9a07a;
  --haze: 0;
  --sun-core: #fcd34d; --sun-glow: rgba(252, 211, 77, .55);
  --sun-scale: 1; --sun-opacity: .9;
  --canopy-filter: none; --droop: 0px; --squash: 1;
}
html[data-theme="dark"] .hero {
  --sky-top: #0f1d36; --sky-bot: #1a2c4a;
  --ground: #27472f;
  --trunk: #6b4a2e;
  --haze-color: #6b5640;
  --sun-opacity: .75;
}

/* ---- dòng trên: tâm trạng + nút nguồn ---- */
.hero-top {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.mood { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mood-kicker { font-size: 12px; color: var(--muted); }
.mood-title { font-size: 22px; line-height: 1.2; color: var(--ink-strong); transition: color .6s ease; }
.mood-msg { font-size: 13px; color: var(--ink); line-height: 1.4; }

.power-pill {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 9px;
  border: none; cursor: pointer;
  padding: 8px 14px 8px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  box-shadow: var(--shadow-pill);
  transition: background .3s ease, color .3s ease, transform .15s ease, box-shadow .2s ease;
  position: relative;
}
.power-pill:hover { transform: translateY(-1px); }
.power-pill:active { transform: scale(.97); }
.power-pill .fan-ico {
  width: 30px; height: 30px; padding: 5px;
  border-radius: 50%;
  background: var(--surface);
  fill: currentColor;
  flex: 0 0 auto;
}
.power-pill .pp-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.power-pill .pp-text b { font-size: 14px; color: inherit; }
.power-pill .pp-text small { font-size: 11px; color: var(--muted); }
.power-pill.is-on { color: var(--good); background: color-mix(in srgb, var(--good) 12%, var(--surface)); }
.power-pill.is-on::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  animation: breathe 3.6s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
  50% { box-shadow: 0 0 0 5px rgba(22, 163, 74, .14); }
}
.fan-ico .fan-blades { transform-box: view-box; transform-origin: 50% 50%; }
.fan-ico.spin .fan-blades { animation: spin 3.2s linear infinite; }
.power-pill.flash { animation: flashRing .7s ease-out; }

/* ---- thân: cảnh + ô chỉ số ---- */
.hero-body {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(220px, 1fr);
  gap: 16px;
  align-items: stretch;
}
.scene {
  position: relative;
  height: 330px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--sky-bot);
  isolation: isolate;
}
.scene-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; transform: translateZ(0); will-change: transform; }

.stats { display: grid; grid-template-rows: repeat(3, 1fr); gap: 12px; }
.stat {
  background: var(--surface-2);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  min-width: 0;
}
.stat-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.stat-label svg { color: var(--accent); flex: 0 0 auto; }
.stat-val { display: flex; align-items: baseline; gap: 4px; }
.stat-val b { font-size: 28px; line-height: 1.1; color: var(--ink-strong); transition: color .6s ease; display: inline-block; }
.stat-val b.bump { animation: bump .5s cubic-bezier(.22, .61, .36, 1); }
.stat-val .unit { font-size: 12px; color: var(--muted); }
.stat-bar {
  position: relative; height: 6px; border-radius: 999px;
  background: var(--line); margin: 4px 0 2px;
}
.stat-bar i {
  position: absolute; top: 50%; left: 0;
  width: 12px; height: 12px; margin: -6px 0 0 -6px;
  border-radius: 50%;
  border: 2.5px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
  opacity: 0;
  transition: left .8s cubic-bezier(.22, .61, .36, 1), background .6s ease, opacity .4s;
}
.stat-bar.has i { opacity: 1; }
.stat-status { font-size: 12px; font-weight: 600; color: var(--muted); transition: color .6s ease; }

/* Số đo ngoài trời (trạm quan trắc thật) */
/* viên thuốc nhỏ ở góc phải hàng nhãn: không làm ô cao thêm */
.stat-label { white-space: nowrap; }
.stat-out {
  margin-left: auto; display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 8px; margin: -4px 0; line-height: 1.3; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 11.5px; color: var(--muted); cursor: default;
}
.stat-out b { color: var(--ink-strong); font-weight: 600; }
.stat-out .arrow { font-weight: 700; font-size: 10px; }
.stat-out .arrow.up { color: var(--warn); }
.stat-out .arrow.down { color: var(--accent); }
@media (max-width: 520px) {
  .stat-out .out-word { display: none; }
  .stat-out { padding: 1px 6px; font-size: 10.5px; gap: 2px; }
  .stat-label { gap: 4px; }
  .stat-label svg { display: none; } /* nhường chỗ cho viên số ngoài trời */
}

/* dòng địa điểm của số liệu ngoài trời */
.outdoor-note { margin: 10px 2px 0; font-size: 11.5px; color: var(--muted); }
.outdoor-aqi { color: var(--aqi-color, var(--muted)); font-weight: 600; }
.outdoor-aqi b { font-weight: 700; }

/* ---------------- SVG scene: lớp nền ---------------- */
.sky-top { stop-color: var(--sky-top); transition: stop-color 1s ease; }
.sky-bot { stop-color: var(--sky-bot); transition: stop-color 1s ease; }
.sun-glow-in { stop-color: var(--sun-glow); }
.sun-glow-out { stop-color: var(--sun-glow); stop-opacity: 0; }

.sun {
  opacity: var(--sun-opacity);
  transform-box: view-box; transform-origin: 372px 54px;
  transform: scale(var(--sun-scale));
  transition: opacity 1s ease, transform 1s ease;
}
.sun-core { fill: var(--sun-core); transition: fill 1s ease; }
.sun-rays path { stroke: var(--sun-core); stroke-width: 3.5; stroke-linecap: round; fill: none; }
.sun-rays { transform-box: view-box; transform-origin: 372px 54px; animation: spin 40s linear infinite; }
.sun-halo { animation: sunPulse 5s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes sunPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }

.cloud circle, .cloud rect { fill: #ffffff; }
html[data-theme="dark"] .cloud circle, html[data-theme="dark"] .cloud rect { fill: #2c3a55; }
.cloud-soft { opacity: .85; animation: cloudDrift 26s ease-in-out infinite alternate; }
@keyframes cloudDrift { from { transform: translateX(-14px); } to { transform: translateX(26px); } }

.ground { fill: var(--ground); transition: fill 1s ease; }
.ground-front { fill: color-mix(in srgb, var(--ground) 82%, #000); transition: fill 1s ease; }
.tree-shadow { fill: rgba(0, 0, 0, .14); }
.grass path { stroke: color-mix(in srgb, var(--ground) 60%, #14532d); stroke-width: 2; stroke-linecap: round; fill: none; transition: opacity .8s; }
.cracks path { stroke: #8a6a3e; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; fill: none; opacity: 0; transition: opacity .8s ease; }
.fallen path { fill: #c99a3b; opacity: 0; transition: opacity .8s ease; }

/* ---------------- cây ---------------- */
.trunk { fill: var(--trunk); }
.branch { stroke: var(--trunk); stroke-width: 5; stroke-linecap: round; fill: none; }
.tree {
  transform-box: view-box; transform-origin: 240px 216px;
  animation: treeSway 7s ease-in-out infinite;
}
@keyframes treeSway { 0%, 100% { transform: rotate(-.9deg); } 50% { transform: rotate(.9deg); } }

.canopy {
  transform-box: view-box; transform-origin: 240px 150px;
  transform: translateY(var(--droop)) scaleY(var(--squash));
  /* "none" khi trung tính: một filter rỗng vẫn buộc vẽ lại tán lá qua pass riêng ở MỖI khung hình
     khi cây đang đung đưa → tụt FPS, giật trên màn hình lớn/retina. */
  filter: var(--canopy-filter, none);
  transition: transform 1.2s cubic-bezier(.22, .61, .36, 1), filter 1s ease;
}
.canopy-shade circle { fill: var(--leaf-3); transition: fill 1s ease; }
.canopy-main circle { fill: var(--leaf-2); transition: fill 1s ease; }
.canopy-light ellipse { fill: var(--leaf-1); opacity: .75; transition: fill 1s ease; }

/* mặt */
.eyes-open circle { fill: var(--face); }
.eyes-open .glint { fill: #fff; }
.eyes-open { transform-box: fill-box; transform-origin: center; animation: blink 4.6s infinite; }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
.eyes-happy path, .brows path, .mouth { stroke: var(--face); stroke-width: 2.6; stroke-linecap: round; fill: none; }
.mouth-big { fill: var(--face); stroke-linejoin: round; }
.cheek { fill: #f59e9e; opacity: 0; transition: opacity .5s; }
.eyes-happy, .brows, .mouth, .mask, .sweat, .scarf, .eyes-open { transition: opacity .45s ease; }
.eyes-happy, .brows, .mouth, .mask, .sweat, .scarf { opacity: 0; }

/* chưa có dữ liệu: mặt bình thản */
.hero:not(.has-data) .mouth-flat { opacity: 1; }
/* 0 tuyệt vời: cười tít mắt, má hồng */
.mood-0 .eyes-open { opacity: 0; }
.mood-0 .eyes-happy, .mood-0 .mouth-big, .mood-0 .cheek { opacity: 1; }
/* 1 dễ chịu: mỉm cười */
.mood-1 .mouth-smile { opacity: 1; }
.mood-1 .cheek { opacity: .6; }
/* 2 tạm ổn: miệng thẳng */
.mood-2 .mouth-flat { opacity: 1; }
/* 3 không tốt / 4 nguy hại: lo lắng, buồn */
.mood-3 .mouth-frown, .mood-3 .brows,
.mood-4 .mouth-frown, .mood-4 .brows { opacity: 1; }
.mood-4 .tree { animation-duration: 4.2s; }

/* ---------------- PM2.5 ---------------- */
.pm-1 { --leaf-1: #a7f3c0; --leaf-2: #4ade80; --leaf-3: #1f9d55; }
.pm-2 { --leaf-1: #b4f0c8; --leaf-2: #5ad38a; --leaf-3: #2f9e5f; }
.pm-3 { --leaf-1: #dcedac; --leaf-2: #a9cf62; --leaf-3: #78a043; --dust: rgba(160, 135, 95, .55); --haze: .07; }
.pm-4 { --leaf-1: #efe0a0; --leaf-2: #cdb04a; --leaf-3: #9d8233; --dust: rgba(170, 115, 60, .65); --haze: .17; }
.pm-5 { --leaf-1: #d3c9a6; --leaf-2: #9c9068; --leaf-3: #6f664a; --dust: rgba(120, 85, 60, .75); --haze: .3; }
.haze { fill: var(--haze-color); opacity: var(--haze); transition: opacity 1.2s ease; pointer-events: none; }
.dust circle { fill: var(--dust); opacity: 0; transition: opacity .8s; }
.dust circle.visible { opacity: 1; animation: dustFloat 8s ease-in-out infinite; }
@keyframes dustFloat {
  0%   { transform: translate(0, 0); opacity: 0; }
  20%  { opacity: 1; }
  50%  { transform: translate(10px, -10px); }
  80%  { opacity: .8; }
  100% { transform: translate(20px, 4px); opacity: 0; }
}
.pm-5 .dust circle.visible { animation-name: dustChaos; }
@keyframes dustChaos {
  0%   { transform: translate(0, 0); opacity: 0; }
  15%  { opacity: 1; }
  35%  { transform: translate(-9px, -12px); }
  60%  { transform: translate(11px, -4px); }
  85%  { opacity: .9; }
  100% { transform: translate(-6px, 10px); opacity: 0; }
}
.pm-4 .mask, .pm-5 .mask { opacity: 1; }
.pm-4 .mouth, .pm-5 .mouth { opacity: 0 !important; }
.mask-body { fill: #f8fafc; stroke: #cbd5e1; stroke-width: 1.2; }
.mask-strap { stroke: #e2e8f0; stroke-width: 1.6; fill: none; stroke-linecap: round; }
.mask-pleat { stroke: #cbd5e1; stroke-width: 1.2; fill: none; stroke-linecap: round; }
.pm-4 .fallen path, .pm-5 .fallen path { opacity: .9; }

/* lá rơi (bụi rất cao hoặc quá khô) */
.falling-leaf { opacity: 0; transform-box: fill-box; transform-origin: center; }
.falling-leaf path { fill: #c99a3b; }
.pm-5 .falling-leaf, .hum-1 .falling-leaf { animation: leafFall 6s ease-in infinite; }
.pm-5 .falling-leaf.fl2, .hum-1 .falling-leaf.fl2 { animation-delay: -3s; }
@keyframes leafFall {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
  10%  { opacity: 1; }
  50%  { transform: translate(-14px, 46px) rotate(-60deg); }
  90%  { opacity: 1; }
  100% { transform: translate(8px, 92px) rotate(40deg); opacity: 0; }
}

/* ---------------- Nhiệt độ ---------------- */
.temp-1 { --sky-top: #d9e5f2; --sky-bot: #f5f8fc; --sun-opacity: 0; --sun-scale: .7; }
.temp-2 { --sky-top: #cde0f6; --sky-bot: #eef5fc; --sun-opacity: .55; --sun-scale: .85; --sun-core: #fde68a; --sun-glow: rgba(253, 230, 138, .45); }
.temp-3 { --sky-top: #bde0ff; --sky-bot: #eaf6ff; --sun-opacity: .9; --sun-scale: 1; }
.temp-4 { --sky-top: #ffdcb0; --sky-bot: #fff3e3; --sun-opacity: 1; --sun-scale: 1.12; --sun-core: #fb923c; --sun-glow: rgba(251, 146, 60, .55); }
.temp-5 { --sky-top: #ffb896; --sky-bot: #ffe6d6; --sun-opacity: 1; --sun-scale: 1.3; --sun-core: #ef4444; --sun-glow: rgba(239, 68, 68, .55); }
html[data-theme="dark"] .hero.temp-1 { --sky-top: #1b2433; --sky-bot: #28344a; --sun-opacity: 0; }
html[data-theme="dark"] .hero.temp-2 { --sky-top: #12213b; --sky-bot: #1c2f50; --sun-opacity: .5; }
html[data-theme="dark"] .hero.temp-3 { --sky-top: #0f1d36; --sky-bot: #1a2c4a; --sun-opacity: .7; }
html[data-theme="dark"] .hero.temp-4 { --sky-top: #2b1d1a; --sky-bot: #3b2a24; --sun-opacity: .95; }
html[data-theme="dark"] .hero.temp-5 { --sky-top: #3b1614; --sky-bot: #4d211c; --sun-opacity: 1; }

.heat path { stroke: #f97316; stroke-width: 2.4; fill: none; stroke-linecap: round; opacity: 0; }
.temp-4 .heat path { animation: heatRise 2.8s ease-in-out infinite; }
.temp-5 .heat path { stroke: #ef4444; animation: heatRise 2.4s ease-in-out infinite; }
.heat path:nth-child(2) { animation-delay: .6s; }
.heat path:nth-child(3) { animation-delay: 1.2s; }
@keyframes heatRise {
  0% { transform: translateY(0); opacity: 0; }
  35% { opacity: .75; }
  100% { transform: translateY(-34px); opacity: 0; }
}
.sweat { fill: #7cc4ff; }
.temp-4 .sweat.s1, .temp-5 .sweat { opacity: 1; animation: sweatDrip 2.4s ease-in infinite; }
.temp-5 .sweat.s2 { animation-delay: -1.1s; }
@keyframes sweatDrip {
  0%, 30% { transform: translateY(0); }
  100% { transform: translateY(9px); }
}

/* lạnh: tuyết rơi, tuyết phủ tán, khăn quàng, run */
.frost-cap ellipse { fill: #f8fbff; opacity: 0; transition: opacity 1s ease; }
.temp-1 .frost-cap ellipse { opacity: .95; }
.temp-1 .scarf { opacity: 1; }
.scarf-band, .scarf-tail { fill: #ef4444; }
.scarf-stripe { stroke: #fecaca; stroke-width: 1.6; stroke-linecap: round; fill: none; }
.temp-1 .tree { animation: shiver .7s ease-in-out infinite; }
@keyframes shiver {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-.6px); }
  75% { transform: translateX(.6px); }
}
.snow circle { fill: #ffffff; opacity: 0; }
html[data-theme="light"] .snow circle { stroke: #c7d7ea; stroke-width: .6; }
.snow circle.visible { animation: snowFall 8s linear infinite; }
@keyframes snowFall {
  0% { transform: translate(0, 0); opacity: 0; }
  10% { opacity: 1; }
  50% { transform: translate(8px, 130px); }
  100% { transform: translate(-4px, 270px); opacity: .2; }
}

/* ---------------- Độ ẩm ---------------- */
.hum-1 { --ground: #e2c58e; }
.hum-2 { --ground: #c9cf8a; }
.hum-3 { --ground: #9bd49a; }
.hum-4 { --ground: #7cc596; }
.hum-5 { --ground: #5fb592; --sun-opacity: .35; }
html[data-theme="dark"] .hero.hum-1 { --ground: #5a4426; }
html[data-theme="dark"] .hero.hum-2 { --ground: #444f2a; }
html[data-theme="dark"] .hero.hum-3 { --ground: #27472f; }
html[data-theme="dark"] .hero.hum-4 { --ground: #21493a; }
html[data-theme="dark"] .hero.hum-5 { --ground: #1d4645; --sun-opacity: .3; }
.hum-1 .cracks path { opacity: .85; }
.hum-2 .cracks path { opacity: .35; }
.hum-1 .grass path { opacity: .35; }
.hum-1 .fallen path { opacity: .9; }

.dew circle { fill: #8fd0ff; stroke: #fff; stroke-width: .8; opacity: 0; transition: opacity .8s ease; transform-box: fill-box; transform-origin: 50% 0; }
.hum-4 .dew circle { opacity: .85; }
.hum-5 .dew circle { opacity: 1; animation: dewSwell 3.6s ease-in-out infinite; }
@keyframes dewSwell { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.25); } }

.fog ellipse { fill: #ffffff; }
html[data-theme="dark"] .fog ellipse { fill: #a9bdd8; }
.fog { opacity: 0; transition: opacity 1.2s ease; }
.hum-4 .fog { opacity: .45; }
.hum-5 .fog { opacity: .8; animation: fogDrift 9s ease-in-out infinite alternate; }
@keyframes fogDrift { from { transform: translateX(-12px); } to { transform: translateX(12px); } }

.rain-cloud { opacity: 0; transition: opacity 1s ease; }
.rc-body circle, .rc-body rect { fill: #9fb2c8; }
html[data-theme="dark"] .rc-body circle, html[data-theme="dark"] .rc-body rect { fill: #4a5a75; }
.rain path { stroke: #60a5fa; stroke-width: 2; stroke-linecap: round; opacity: 0; }
.hum-5 .rain-cloud { opacity: 1; }
.hum-5 .rain path { animation: rainFall 1.9s linear infinite; }
.rain path:nth-child(2) { animation-delay: .48s; }
.rain path:nth-child(3) { animation-delay: .95s; }
.rain path:nth-child(4) { animation-delay: 1.43s; }
@keyframes rainFall {
  0% { transform: translateY(-4px); opacity: 0; }
  30% { opacity: .9; }
  100% { transform: translateY(26px); opacity: 0; }
}

/* lạnh luôn giấu mặt trời, kể cả khi đang mưa */
html[data-theme] .hero.temp-1 { --sun-opacity: 0; }

/* ---------------- bướm: chỉ khi mọi thứ tuyệt vời ---------------- */
.butterfly { opacity: 0; transition: opacity 1s ease; }
.mood-0 .butterfly { opacity: 1; animation: bfPath 12s ease-in-out infinite; }
@keyframes bfPath {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(40px, -26px); }
  50%  { transform: translate(-6px, -48px); }
  75%  { transform: translate(-34px, -14px); }
  100% { transform: translate(0, 0); }
}
.wing { fill: #f9a8d4; transform-box: fill-box; }
.wing.wl { transform-origin: 100% 50%; }
.wing.wr { transform-origin: 0% 50%; fill: #fbcfe8; }
.mood-0 .wing { animation: flap .55s ease-in-out infinite alternate; }
@keyframes flap { from { transform: scaleX(1); } to { transform: scaleX(.25); } }
.bf-core { stroke: #6b4a2e; stroke-width: 1.8; stroke-linecap: round; }

/* ---------------- responsive ---------------- */
@media (max-width: 860px) {
  .hero-body { grid-template-columns: 1fr; }
  .stats { grid-template-rows: none; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
}
@media (max-width: 700px) {
  .hero { padding: 14px; }
  .hero-top { margin-bottom: 12px; }
  .mood-title { font-size: 19px; }
  .mood-msg { font-size: 12.5px; }
  .power-pill { padding: 6px 12px 6px 7px; gap: 7px; }
  .power-pill .fan-ico { width: 28px; height: 28px; }
  .scene { height: 240px; border-radius: 16px; }
  .stat { padding: 10px 11px; border-radius: 14px; gap: 3px; }
  .stat-label { font-size: 11px; gap: 5px; }
  .stat-val b { font-size: 23px; }
  .stat-val .unit { font-size: 10.5px; }
  .stat-status { font-size: 11px; }
}
@media (max-width: 360px) {
  .stats { gap: 7px; }
  .stat { padding: 9px 8px; }
  .stat-val { flex-direction: column; gap: 0; }
  .stat-val b { font-size: 21px; }
}

/* ============================================================
   Chế độ tối: giảm độ chói — nút chính và điểm nhấn dùng nền mờ,
   số liệu dùng màu chữ trung tính (màu trạng thái chỉ ở nhãn + vạch),
   cảnh cây hạ bão hoà nhẹ cho hợp nền than chì.
   ============================================================ */
html[data-theme="dark"] .btn.primary {
  background: color-mix(in srgb, var(--accent) 20%, var(--surface-2));
  color: var(--accent-2);
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
  box-shadow: none;
}
html[data-theme="dark"] .btn.primary:hover { color: var(--ink-strong); }
html[data-theme="dark"] .brand-logo {
  background: var(--surface-3);
  color: var(--accent);
  box-shadow: none;
}
html[data-theme="dark"] .mode-tile.active {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow: none;
}
html[data-theme="dark"] .mode-tile.active .mt-ico { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); color: var(--accent-2); }
html[data-theme="dark"] .leaf-range {
  background: linear-gradient(var(--accent), var(--accent)) 0 / var(--fill, 50%) 100% no-repeat, var(--surface-3);
}
html[data-theme="dark"] .stat-val b { color: var(--ink-strong) !important; }
html[data-theme="dark"] .power-pill.is-on { background: color-mix(in srgb, var(--good) 10%, var(--surface-2)); }
html[data-theme="dark"] .power-pill.is-on::after { animation: none; }

/* ============================================================
   Tinh giản: bỏ các chi tiết trang trí thừa
   (nền phát sáng, nút gradient, bóng màu, ô icon, hiệu ứng xuất hiện lần lượt)
   ============================================================ */
body { background: var(--bg); }
.brand-text b { font-size: 17px; letter-spacing: -.01em; }

/* nút chính: màu đặc, không gradient, không quầng sáng */
.btn.primary,
.btn.primary:hover { background: var(--accent); box-shadow: none; }
html[data-theme="dark"] .btn.primary,
html[data-theme="dark"] .btn.primary:hover { background: color-mix(in srgb, var(--accent) 20%, var(--surface-2)); }
.btn, .icon-btn { box-shadow: none; }
.btn:hover, .icon-btn:hover { transform: none; }

/* tiêu đề khối chỉ còn chữ */
.sec-head { gap: 0; }

/* ô chế độ: icon trơn, không khung vuông; không nhấc lên khi rê chuột */
.mode-tile .mt-ico,
.mode-tile.active .mt-ico,
html[data-theme="dark"] .mode-tile.active .mt-ico { width: auto; height: auto; background: none; border-radius: 0; color: var(--muted); }
.mode-tile.active .mt-ico,
html[data-theme="dark"] .mode-tile.active .mt-ico { color: var(--accent); }
.mode-tile:hover { transform: none; }
.mode-tile.active { box-shadow: none; }

/* bỏ hiệu ứng "thở", vòng xung, và xuất hiện lần lượt */
.power-pill.is-on::after { animation: none; }
.power-pill:hover { transform: none; }
.dot.ok::after { display: none; }
.panel { animation: none; }
tbody tr { animation: none; }

/* bóng thẻ nhẹ hơn */
.panel { box-shadow: 0 1px 2px rgba(28, 40, 34, .05); }
html[data-theme="dark"] .panel { box-shadow: none; }
.power-pill { box-shadow: none; }

/* Font kiểu Apple: chữ lớn dùng khoảng chữ chặt hơn (giống SF Pro Display) */
.mood-title, .stat-val b, .speed-val b, .filter-ring span, .brand-text b { letter-spacing: -.025em; }
.sec-title h2, .mode-tile b { letter-spacing: -.018em; }

/* tán cây ở chế độ tối: xanh lá trầm hơn, bớt rực */
html[data-theme="dark"] .hero.pm-1 { --leaf-1: #8fcfa6; --leaf-2: #4fae7a; --leaf-3: #2b7d52; }
html[data-theme="dark"] .hero.pm-2 { --leaf-1: #98cfaa; --leaf-2: #59b081; --leaf-3: #33815a; }
html[data-theme="dark"] .hero:not([class*="pm-"]) { --leaf-1: #98cfaa; --leaf-2: #59b081; --leaf-3: #33815a; }

/* ============================================================
   Lịch sử: mỗi chỉ số một biểu đồ nhỏ, xếp chồng, chung trục thời gian
   ============================================================ */
.hist-rows { padding: 4px 16px 8px; }
.hist-row { padding: 14px 0 2px; border-top: 1px solid var(--line); }
.hist-row:first-child { border-top: none; }
.hist-row[hidden] { display: none; }
.hist-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.hist-name { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); min-width: 74px; }
.hist-name i { width: 8px; height: 8px; border-radius: 50%; background: var(--sw); }
.hist-now b { font-size: 21px; font-weight: 650; letter-spacing: -.02em; color: var(--ink-strong); }
.hist-now small { margin-left: 3px; font-size: 11.5px; color: var(--muted); }
.hist-range { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hist-range b { font-weight: 600; color: var(--ink); }
.hist-chart { height: 112px; margin: 0 -4px; }
.hist-row.last .hist-chart { height: 168px; }
@media (max-width: 700px) {
  .hist-rows { padding: 2px 12px 6px; }
  .hist-row { padding-top: 12px; }
  .hist-name { min-width: 0; }
  .hist-now b { font-size: 19px; }
  .hist-range { font-size: 11.5px; }
  .hist-chart { height: 96px; }
  .hist-row.last .hist-chart { height: 122px; }
}

/* ============================================================
   Điều khiển xếp chồng:
   ┌──────────┬──────────┬──────────┐
   │  Sleep   │ Favorite │   Auto   │
   ├──────────┼──────────┴──────────┤
   │ Màn hình │    Bật / Tắt máy    │
   └──────────┴─────────────────────┘
   ============================================================ */
.control-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-areas:
    "msleep mfav  mauto"
    "mbright power power";
  gap: 12px;
}
.control-grid .mode-tiles { display: contents; }
.mode-tile[data-v="auto"] { grid-area: mauto; }
.mode-tile[data-v="sleep"] { grid-area: msleep; }
.mode-tile[data-v="favorite"] { grid-area: mfav; }

.power-tile {
  grid-area: power;
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 92px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  background: var(--surface-2);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background .25s, border-color .25s;
}
.power-tile:active { transform: scale(.985); }
.pt-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.power-tile .fan-ico {
  width: 46px; height: 46px; padding: 10px; flex: 0 0 auto;
  border-radius: 50%;
  background: var(--surface);
  fill: var(--muted);
  transition: fill .25s;
}
.pt-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.pt-text b { font-size: 22px; font-weight: 700; letter-spacing: -.02em; color: var(--ink-strong); }
.pt-text small { margin-top: 2px; font-size: 12px; color: var(--muted); }

/* công tắc kiểu iOS */
.pt-switch {
  position: relative; flex: 0 0 auto;
  width: 51px; height: 31px; border-radius: 999px;
  background: var(--surface-3);
  transition: background .25s ease;
}
.pt-knob {
  position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .25);
  transition: transform .25s cubic-bezier(.22, .61, .36, 1);
}
.power-tile.is-on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.power-tile.is-on .fan-ico { fill: var(--accent); }
.power-tile.is-on .pt-switch { background: var(--accent); }
.power-tile.is-on .pt-knob { transform: translateX(20px); }
.power-tile.loading { opacity: .65; }
.power-tile.flash { animation: flashRing .7s ease-out; }

@media (max-width: 700px) {
  .control-grid { gap: 8px; }
  .power-tile { min-height: 80px; padding: 12px; gap: 8px; }
  .pt-main { gap: 9px; }
  .power-tile .fan-ico { width: 38px; height: 38px; padding: 8px; }
  .pt-text b { font-size: 19px; }
  .pt-text small { font-size: 11px; }
  .pt-switch { width: 44px; height: 27px; }
  .pt-knob { width: 23px; height: 23px; }
  .power-tile.is-on .pt-knob { transform: translateX(17px); }
}

/* thanh tốc độ Favorite: ẩn trừ khi đang ở chế độ Favorite */
.speed-card[hidden] { display: none; }
.speed-card:not([hidden]) { animation: contentIn .28s cubic-bezier(.22, .61, .36, 1); }

/* ô độ sáng màn hình: chạm để xoay vòng Tắt → Sáng → Rất sáng */
.bright-tile {
  grid-area: mbright;
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 14px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background .25s, border-color .25s;
}
.bright-tile:active { transform: scale(.985); }
.bright-tile .mt-ico { display: inline-flex; margin-bottom: 8px; color: var(--muted); transition: color .25s; }
.bt-text { display: flex; flex-direction: column; line-height: 1.2; }
.bt-text b { font-size: 14.5px; font-weight: 700; color: var(--ink-strong); letter-spacing: -.018em; }
.bt-text small { font-size: 11.5px; color: var(--muted); }
.bt-dots { position: absolute; top: 16px; right: 14px; display: flex; gap: 4px; }
.bt-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--surface-3); transition: background .25s; }
.bt-rays-near, .bt-rays-far { transition: opacity .25s; }
/* mức 0: tắt — chỉ còn lõi, không tia */
.bright-tile.lvl-0 .bt-rays-near, .bright-tile.lvl-0 .bt-rays-far { opacity: 0; }
/* mức 1: sáng — tia gần */
.bright-tile.lvl-1 .bt-rays-far { opacity: 0; }
.bright-tile.lvl-1 .mt-ico, .bright-tile.lvl-2 .mt-ico { color: var(--accent); }
.bright-tile.lvl-1 .bt-dots i:nth-child(1),
.bright-tile.lvl-2 .bt-dots i { background: var(--accent); }
.bright-tile.loading { opacity: .65; }
@media (max-width: 700px) {
  .bright-tile { padding: 11px 10px; }
  .bt-dots { top: 13px; right: 10px; }
  .bt-text b { font-size: 13.5px; }
  .bt-text small { font-size: 10.5px; }
}

/* loading khi đang gửi lệnh */
.bright-tile.loading, .power-tile.loading { opacity: 1; }
.bright-tile.loading .bt-dots { opacity: 0; }
.bright-tile.loading::after,
.power-tile.loading .pt-main::after {
  content: "";
  position: absolute;
  box-sizing: border-box; /* phần tử giả không nhận box-sizing chung, phải đặt riêng để căn đúng tâm */
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 1.6s linear infinite;
}
/* ô Màn hình: vòng xoay thay chỗ 2 chấm ở góc phải */
.bright-tile.loading::after { top: 14px; right: 12px; width: 14px; height: 14px; }
.bright-tile.loading .bt-text b { animation: loadPulse 1s ease-in-out infinite; }
/* ô Bật/Tắt: vòng xoay nằm trong vòng tròn biểu tượng quạt, không đè công tắc */
.pt-main { position: relative; }
.power-tile .fan-ico .fan-blades, .power-tile .fan-ico circle { transition: opacity .2s; }
.power-tile.loading .fan-ico .fan-blades,
.power-tile.loading .fan-ico circle { opacity: 0; }
.power-tile.loading .pt-main::after { top: 50%; left: 23px; width: 20px; height: 20px; margin: -10px 0 0 -10px; }
.power-tile.loading .pt-text b { animation: loadPulse 1s ease-in-out infinite; }
@keyframes loadPulse { 50% { opacity: .45; } }
@media (max-width: 700px) {
  .bright-tile.loading::after { top: 11px; right: 9px; }
  .power-tile.loading .pt-main::after { left: 19px; width: 18px; height: 18px; margin: -9px 0 0 -9px; }
}

/* chữ trạng thái tổng nằm trong khung cây, góc trên bên trái */
.scene-caption {
  position: absolute; z-index: 1;
  top: 14px; left: 16px; right: 40%;
  pointer-events: none;
}
.scene-caption .mood-title { font-size: 24px; line-height: 1.15; }
.scene-caption .mood-msg { font-size: 13px; color: var(--ink); }
.scene-caption .mood-msg:empty { display: none; }
html[data-theme="light"] .scene-caption .mood-title,
html[data-theme="light"] .scene-caption .mood-msg { text-shadow: 0 1px 8px rgba(255, 255, 255, .7); }
html[data-theme="dark"] .scene-caption .mood-title,
html[data-theme="dark"] .scene-caption .mood-msg { text-shadow: 0 1px 8px rgba(0, 0, 0, .55); }
html[data-theme="dark"] .scene-caption .mood-msg { color: #e5e5ea; }
@media (max-width: 700px) {
  .scene-caption { top: 11px; left: 13px; right: 35%; }
  .scene-caption .mood-title { font-size: 20px; }
  .scene-caption .mood-msg { font-size: 12px; }
}

