:root {
  --ground: #EEF2F1;
  --surface: #FFFFFF;
  --ink: #142624;
  --muted: #586664;
  --line: #D5DDDB;
  --accent: #0E5E6F;
  --accent-dark: #0A4653;
  --accent-soft: #DCEBEE;
  --pine: #0C3B40;        /* แผงซ้ายหน้า login */
  --pine-ink: #E4EFED;
  --pine-muted: #9DBAB6;
  --pine-line: rgba(228, 239, 237, 0.16);
  --amber: #F2B544;       /* ค่าเกินเกณฑ์ บนพื้นเข้ม */
  --warn-bg: #FDF0D5;
  --warn-ink: #5C2805;
  --ok-bg: #E3F2EF;
  --ok-ink: #0B5D55;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans Thai", system-ui, sans-serif;
  color: var(--ink);
  background: var(--ground);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-dark); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 21px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; }
.brand img { display: block; height: 36px; width: auto; }

/* =========================================================
   หน้า login / สมัคร / ลืมรหัสผ่าน
   ========================================================= */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }

/* ---- แผงซ้าย: ตัวอย่างหน้าจอเซนเซอร์ ---- */
.auth-side {
  background: var(--pine);
  color: var(--pine-ink);
  padding: 56px clamp(32px, 5vw, 72px);
  display: flex; flex-direction: column; justify-content: space-between; gap: 40px;
}
.side-copy .brand { color: #FFFFFF; gap: 16px; font-size: 44px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 40px; }
.side-copy .brand img { height: 64px; }
.side-title { margin: 0; font-size: clamp(26px, 2.4vw, 32px); line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; }
.side-sub { margin: 12px 0 0; max-width: 36ch; color: var(--pine-muted); font-size: 15px; }
.side-foot { margin: 0; font-size: 13px; color: var(--pine-muted); }

/* ตัวอย่างหน้าจอจากเซนเซอร์ วางเรียงกัน */
.readouts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; max-width: 560px; }
.readout {
  display: flex; flex-direction: column;
  border: 1px solid var(--pine-line);
  border-radius: 16px;
  padding: 18px 18px 14px;
  background: rgba(255, 255, 255, 0.04);
}
.readout-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; color: var(--pine-muted); }
.live { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.live i { width: 7px; height: 7px; border-radius: 50%; background: #5FD0B8; }
.readout-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; margin: 14px 0 6px; }
.readout-grid b { display: block; font-size: 30px; line-height: 1; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.readout-grid small { display: block; margin-top: 5px; font-size: 12px; color: var(--pine-muted); }
.readout-grid .warn b, .readout-grid .warn small { color: var(--amber); }
.spark { display: block; width: 100%; height: 48px; margin-top: auto; }
.spark polyline { fill: none; stroke: #7FD6C4; stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke;
  stroke-dasharray: 600; stroke-dashoffset: 600; animation: draw 1.6s ease-out 0.2s forwards; }
.spark .limit { stroke: var(--amber); stroke-width: 1; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; opacity: 0.7; }
.readout-cap { margin: 4px 0 0; font-size: 12px; color: var(--pine-muted); }
@keyframes draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .spark polyline { animation: none; stroke-dashoffset: 0; } }

/* ---- ฝั่งฟอร์ม ---- */
.auth-main {
  background: var(--ground);
  display: grid; grid-template-rows: auto 1fr auto; justify-items: center; gap: 24px;
  padding: 28px clamp(20px, 4vw, 48px);
}
.auth-top { justify-self: end; min-height: 40px; display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }
.top-link {
  display: inline-flex; align-items: center; min-height: 40px; padding: 8px 16px;
  border: 1px solid #C3CFCC; border-radius: 10px; background: var(--surface);
  color: var(--ink); font-weight: 600; text-decoration: none;
}
.top-link:hover { border-color: var(--accent); color: var(--accent); }
.auth-box {
  align-self: center; width: 100%; max-width: 460px;
  background: var(--surface);
  border: 1px solid #DFE6E4; border-radius: 18px;
  padding: 40px 40px 36px;
  box-shadow: 0 24px 60px -36px rgba(12, 59, 64, 0.45);
}
.auth-foot { margin: 0; font-size: 13px; color: var(--muted); }
.mobile-only { display: none; }
.auth-box .brand { margin-bottom: 32px; gap: 14px; font-size: 36px; letter-spacing: -0.02em; }
.auth-box .brand img { height: 52px; }
.auth-box h1 { margin: 0; font-size: 30px; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; }
.lead { margin: 6px 0 28px; color: var(--muted); font-size: 15px; }

form { display: flex; flex-direction: column; gap: 18px; }
label { display: flex; flex-direction: column; gap: 7px; font-size: 14px; font-weight: 500; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.label-row a { font-weight: 400; font-size: 13px; }
.opt { font-weight: 400; font-size: 13px; color: var(--muted); }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.hint { margin: -8px 0 0; font-size: 13px; color: var(--muted); }

input {
  font: inherit; font-size: 16px; font-weight: 400; padding: 12px 14px; min-height: 48px;
  border: 1px solid var(--line); border-radius: 10px; background: #FAFCFB; color: var(--ink);
  transition: border-color .15s, background-color .15s;
}
input:hover { border-color: #B9C4C2; }
input:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px rgba(14, 94, 111, 0.15); }

.btn {
  font: inherit; font-size: 17px; font-weight: 600; min-height: 52px; padding: 11px 18px; margin-top: 4px;
  border: 0; border-radius: 10px; background: var(--accent); color: #FFFFFF; cursor: pointer;
}
.btn:hover { background: var(--accent-dark); }
.btn-ghost { margin: 0; background: transparent; color: var(--ink); border: 1px solid var(--line); min-height: 40px; font-size: 14px; font-weight: 500; }
.btn-ghost:hover { background: var(--ground); }

.switch { margin: 28px 0 0; padding-top: 22px; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }

.msg { padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.msg ul { margin: 0; padding-left: 18px; }
.msg-error { background: var(--warn-bg); color: var(--warn-ink); }
.msg-ok { background: var(--ok-bg); color: var(--ok-ink); }

/* มือถือ / จอแคบ: ซ่อนแผงซ้าย ให้ฟอร์มเต็มจอ */
@media (max-width: 1180px) { .readouts { grid-template-columns: minmax(0, 1fr); max-width: 300px; } .readout:nth-child(2) { display: none; } }
@media (max-width: 880px) {
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-side { display: none; }
  .auth-main { padding: 16px 16px 24px; gap: 16px; }
  .auth-box { align-self: start; padding: 28px 22px; }
  .mobile-only { display: block; }
}
@media (max-width: 420px) { .pair { grid-template-columns: minmax(0, 1fr); } }

/* =========================================================
   dashboard (ชั่วคราว)
   ========================================================= */
.topbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.who small { display: block; color: var(--muted); font-size: 12px; }
.who form { display: block; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 600; display: flex; align-items: center; justify-content: center; }
.page { max-width: 960px; margin: 0 auto; padding: 32px 16px; }
.page h1 { margin: 0 0 4px; font-size: 28px; font-weight: 600; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--ink); color: #FFFFFF; vertical-align: middle; }
.empty { margin-top: 24px; background: var(--surface); border: 1px dashed #C9D0CE; border-radius: 14px; padding: 40px 24px; text-align: center; color: var(--muted); }
.empty h2 { margin: 0 0 6px; color: var(--ink); font-size: 18px; }

/* =========================================================
   dashboard: การ์ดอุปกรณ์ + กราฟ
   ========================================================= */
.page { max-width: 1180px; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px 16px; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.btn-back {
  display: inline-flex; align-items: center; gap: 10px; min-height: 48px; padding: 10px 20px 10px 16px; margin-bottom: 20px;
  border: 1px solid #C3CFCC; border-radius: 12px; background: var(--surface);
  color: var(--ink); font-size: 16px; font-weight: 600; text-decoration: none;
  box-shadow: 0 1px 2px rgba(20, 38, 36, 0.06);
}
.btn-back span { font-size: 20px; line-height: 1; color: var(--accent); }
.btn-back:hover { border-color: var(--accent); color: var(--accent); }
.conn-error { margin: 12px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-ink); font-size: 14px; }
.who-name { line-height: 1.35; }
.plan { color: #7FE0CB; font-weight: 500; }
.sub { margin: 0; color: var(--muted); font-size: 14px; }

/* ---- แถบบนสีเข้ม ---- */
.topbar-dark { background: var(--pine); border-bottom: 0; color: var(--pine-ink); padding: 16px 28px; }
.topbar-dark .brand { color: #FFFFFF; gap: 14px; font-size: 30px; letter-spacing: -0.02em; }
.topbar-dark .brand img { height: 48px; }
.topbar-dark .who small { color: var(--pine-muted); }
.topbar-dark .avatar { background: rgba(255, 255, 255, 0.12); color: #FFFFFF; }
.topbar-dark .btn-ghost { color: var(--pine-ink); border-color: var(--pine-line); }
.topbar-dark .btn-ghost:hover { background: rgba(255, 255, 255, 0.08); }

/* ---- การ์ดอุปกรณ์: แบบเดียวกับตัวอย่างหน้าจอในหน้า login ---- */
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.device.readout { background: var(--pine); color: var(--pine-ink); border-color: transparent; padding: 20px 20px 14px; }
/* หน้า login ซ่อนการ์ดที่ 2 บนจอแคบ — หน้านี้ต้องแสดงทุกเครื่อง */
.devices .readout:nth-child(n) { display: flex; }
.device .readout-head { font-size: 14px; }
.device .readout-head { align-items: flex-start; }
.device-title { display: flex; flex-direction: column; min-width: 0; }
.loc-text, .loc-edit { color: #FFFFFF; font-weight: 600; font-size: 18px; line-height: 1.3; }
.loc-edit {
  display: inline-flex; align-self: flex-start; align-items: center; gap: 8px; max-width: 100%; text-align: left;
  font-family: inherit; background: none; border: 0; padding: 2px 6px; margin: -2px -6px; border-radius: 8px; cursor: text;
}
.loc-edit svg { width: 14px; height: 14px; flex: none; fill: var(--pine-muted); opacity: 0.7; }
.loc-edit:hover { background: rgba(255, 255, 255, 0.08); }
.loc-edit:hover svg { opacity: 1; fill: #7FE0CB; }
.loc-edit.is-empty { color: #7FE0CB; font-weight: 500; font-size: 16px; }
.loc-input {
  font: inherit; font-size: 17px; font-weight: 600; width: 100%; min-height: 38px; padding: 4px 10px; margin: -4px 0 0;
  color: #FFFFFF; background: rgba(255, 255, 255, 0.08); border: 1px solid #5FD0B8; border-radius: 8px;
}
.loc-input:focus { outline: none; box-shadow: 0 0 0 3px rgba(95, 208, 184, 0.3); background: rgba(255, 255, 255, 0.12); }
.loc-input::placeholder { color: var(--pine-muted); font-weight: 400; }
.device-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 4px; font-size: 13px; color: var(--pine-muted); }
.device-title { flex: 1; }
.live.off { color: var(--pine-muted); } .live.off i { background: #6E8784; }
.device .readout-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 14px 0 10px; }
.device .readout-grid b { font-size: 30px; }
.spark-empty { height: 48px; }
.device .spark polyline { animation: none; stroke-dashoffset: 0; }
.device-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 10px 0 0; padding-top: 12px; border-top: 1px solid var(--pine-line); font-size: 12px; color: var(--pine-muted); }
.btn-chart {
  display: inline-flex; align-items: center; min-height: 36px; padding: 6px 14px; border-radius: 9px; white-space: nowrap;
  background: #5FD0B8; color: var(--pine); font-size: 14px; font-weight: 600; text-decoration: none;
}
.btn-chart:hover { background: #7FE0CB; color: var(--pine); }

.iaq { align-self: flex-start; display: inline-flex; align-items: baseline; gap: 8px; margin-top: 12px; padding: 4px 12px 5px; border-radius: 999px; font-size: 13px; }
.iaq span { font-weight: 600; letter-spacing: 0.04em; opacity: 0.85; }
.iaq b { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.iaq em { font-style: normal; font-weight: 500; }
.iaq-1 { background: rgba(95, 208, 184, 0.16); color: #7FE0CB; }
.iaq-2 { background: rgba(242, 214, 90, 0.16); color: #F2D65A; }
.iaq-3 { background: rgba(242, 181, 68, 0.18); color: var(--amber); }
.iaq-4 { background: rgba(255, 128, 112, 0.18); color: #FF9A8C; }

/* ---- กราฟ: 1 ค่า = 1 กราฟ ---- */
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(440px, 1fr)); gap: 16px; }
.chart-card { margin: 0; background: var(--surface); border: 1px solid #E3E9E7; border-radius: 16px; padding: 18px 18px 10px; min-width: 0; box-shadow: 0 1px 2px rgba(20, 38, 36, 0.04), 0 8px 24px -18px rgba(12, 59, 64, 0.25); }
.chart-card figcaption { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 6px 18px; margin-bottom: 10px; padding-bottom: 12px; border-bottom: 1px solid #EEF2F1; }
.chart-title { font-weight: 600; font-size: 16px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.lg { display: inline-flex; align-items: baseline; gap: 6px; font-size: 13px; color: var(--muted); }
.lg b { font-size: 18px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.lg small { font-size: 12px; }
.lg i, .tip-row i { display: inline-block; width: 18px; border-top: 2.5px solid; transform: translateY(-3px); }
.lg i.dashed, .tip-row i.dashed { border-top-style: dashed; }
.lg i.dotted { border-top-style: dotted; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: #E2E9E7; border-radius: 10px; }
.seg button {
  font: inherit; font-size: 13px; font-weight: 500; min-height: 32px; padding: 4px 12px;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer;
}
.seg button:hover:not(:disabled) { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(20, 38, 36, 0.12); }
.seg button:disabled { cursor: not-allowed; opacity: 0.6; }
.pro { font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); }

.chart-wrap { position: relative; min-height: 240px; }
.chart-wrap svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.chart-msg { margin: 0; padding: 60px 0; text-align: center; color: var(--muted); font-size: 14px; }
.grid line { stroke: #EEF2F1; }
.baseline, .axis-x line { stroke: #C9D3D1; }
.area { stroke: none; }
.end-halo { opacity: 0.18; }
.end { stroke: var(--surface); stroke-width: 2; }
.zone { opacity: 0.9; }
.zone-label { font-size: 11px; font-weight: 500; fill: #6E7C7A; }
.axis-y text { font-size: 12px; fill: #6E7C7A; text-anchor: end; font-variant-numeric: tabular-nums; }
.axis-x text { font-size: 12px; fill: #6E7C7A; font-variant-numeric: tabular-nums; }
.chart-wrap .line { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart-wrap .band { opacity: 0.12; }
.axis-r text { text-anchor: start; }
.axis-unit { font-size: 11px; fill: var(--muted); }
.chart-wrap .limit line { stroke: #D9822B; stroke-width: 1.25; stroke-dasharray: 5 5; }
.chart-wrap .limit text { font-size: 11px; font-weight: 600; fill: #9A4A0B; paint-order: stroke; stroke: var(--surface); stroke-width: 4px; }
.chart-wrap .hit { fill: transparent; cursor: crosshair; }
.chart-wrap .hover .xhair { stroke: #9AA7A5; stroke-width: 1; }
.chart-wrap .hover circle { stroke: var(--surface); stroke-width: 2; }
.tip {
  position: absolute; z-index: 2; transform: translate(-50%, calc(-100% - 12px)); pointer-events: none;
  background: var(--ink); color: #FFFFFF; border-radius: 8px; padding: 6px 10px; font-size: 12px; white-space: nowrap;
  display: flex; flex-direction: column; gap: 1px;
}
.tip[hidden] { display: none; }
.tip-time { color: #C9D6D4; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row b { margin-left: auto; padding-left: 12px; font-size: 13px; font-weight: 600; }
.tip-row i { transform: none; width: 14px; }
.tip > span:not(.tip-row):not(.tip-time) { color: #C9D6D4; }
.chart-note { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

@media (max-width: 560px) {
  .topbar-dark { padding: 12px 16px; }
  .topbar-dark .brand { font-size: 24px; }
  .topbar-dark .brand img { height: 40px; }
  .devices, .charts { grid-template-columns: minmax(0, 1fr); }
  .who-name { font-size: 13px; }
  .device .readout-grid b { font-size: 26px; }
}

/* ---- หน้ากราฟ: แถบเลือกเครื่อง + ช่วงเวลา (ตรึงไว้ด้านบนเมื่อเลื่อน) ---- */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dev-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px 16px;
  margin: 0 -16px; padding: 10px 16px; background: rgba(238, 242, 241, 0.94); backdrop-filter: blur(8px);
}
.dev-bar.is-stuck { box-shadow: 0 8px 16px -14px rgba(12, 59, 64, 0.5); border-bottom: 1px solid #DCE4E2; }
.dev-pick { position: relative; min-width: 0; max-width: 100%; }
.dev-pick::after {
  content: ""; position: absolute; right: 14px; top: 50%; width: 9px; height: 9px; margin-top: -7px;
  border-right: 2.5px solid var(--accent); border-bottom: 2.5px solid var(--accent); transform: rotate(45deg); pointer-events: none;
}
.dev-pick select {
  appearance: none; -webkit-appearance: none; max-width: 100%;
  font: inherit; font-size: 26px; font-weight: 600; letter-spacing: -0.01em; color: var(--ink);
  padding: 6px 44px 6px 14px; min-height: 52px; border: 1px solid #C9D3D1; border-radius: 12px; background: var(--surface);
  cursor: pointer; text-overflow: ellipsis;
}
.dev-pick select:hover { border-color: var(--accent); }
.dev-pick select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14, 94, 111, 0.15); }
.dev-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin: 8px 0 20px; font-size: 14px; color: var(--muted); }
.dev-meta em { font-style: normal; color: #8A9896; }
.live-dot { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.live-dot i { width: 8px; height: 8px; border-radius: 50%; }
.live-dot.on { color: var(--ok-ink); } .live-dot.on i { background: #1A9A84; }
.live-dot.off i { background: #A3AEAC; }


@media (max-width: 560px) {
  .btn-back { margin-bottom: 12px; }
  .dev-pick, .dev-pick select { width: 100%; }
  .dev-pick select { font-size: 20px; min-height: 46px; }
  .dev-bar .seg { width: 100%; justify-content: space-between; }
  .dev-bar .seg button { flex: 1; padding: 4px 6px; }
}

/* ---- เพิ่มอุปกรณ์ / นำออก ---- */
.btn-add {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 18px;
  border-radius: 11px; background: var(--accent); color: #FFFFFF; font-size: 15px; font-weight: 600; text-decoration: none;
}
.btn-add span { font-size: 20px; line-height: 1; }
.btn-add:hover { background: var(--accent-dark); color: #FFFFFF; }
.empty p { margin: 0 auto 18px; max-width: 44ch; }
.added { margin-bottom: 16px; }

.page-narrow { max-width: 620px; }
.add-box { background: var(--surface); border: 1px solid #DFE6E4; border-radius: 18px; padding: 32px; box-shadow: 0 24px 60px -36px rgba(12, 59, 64, 0.45); }
.add-box h1 { margin: 0; font-size: 28px; }
.add-box input[name=serial], .add-box input[name=claim] { font-family: ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: 0.06em; text-transform: uppercase; }
.qr-summary { display: flex; align-items: baseline; gap: 12px; padding: 14px 16px; border-radius: 12px; background: var(--accent-soft); }
.qr-summary span { font-size: 14px; color: var(--muted); }
.qr-summary b { font-size: 22px; letter-spacing: 0.04em; font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.sticker { display: flex; align-items: center; gap: 16px; margin: 28px 0 0; padding: 16px; border: 1px dashed #C3CFCC; border-radius: 12px; }
.sticker-qr {
  flex: none; width: 64px; height: 64px; border-radius: 6px;
  background:
    conic-gradient(from 90deg at 3px 3px, #142624 25%, transparent 0) 0 0 / 16px 16px,
    repeating-linear-gradient(90deg, #142624 0 4px, transparent 4px 9px),
    #FFFFFF;
  border: 4px solid #142624; opacity: 0.85;
}
.sticker figcaption { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--muted); }
.sticker figcaption b { color: var(--ink); font-size: 14px; }
.sticker code { font-size: 13px; color: var(--ink); }

.danger { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px 24px; margin-top: 40px; padding: 18px 20px; border: 1px solid #EBCFCB; border-radius: 14px; background: #FFF8F7; }
.danger h2 { margin: 0 0 2px; font-size: 15px; }
.danger p { margin: 0; max-width: 60ch; font-size: 13px; color: var(--muted); }
.btn-danger { font: inherit; font-size: 14px; font-weight: 600; min-height: 40px; padding: 6px 16px; border-radius: 10px; border: 1px solid #D9A39C; background: #FFFFFF; color: #9B1C1C; cursor: pointer; }
.btn-danger:hover { background: #FBE6E4; }
@media (max-width: 560px) { .add-box { padding: 22px 18px; } .page-head .btn-add { width: 100%; justify-content: center; } }

/* การ์ดเปล่า "เพิ่มอุปกรณ์" ต่อท้ายการ์ดเครื่อง */
.add-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 240px;
  padding: 24px; border: 2px dashed #B9C8C5; border-radius: 16px; text-align: center; text-decoration: none; color: var(--muted);
  transition: border-color .15s, background-color .15s, color .15s;
}
.add-tile:hover { border-color: var(--accent); background: rgba(14, 94, 111, 0.05); color: var(--accent); }
.add-plus { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--accent); color: #FFFFFF; font-size: 30px; line-height: 1; margin-bottom: 6px; }
.add-tile b { font-size: 17px; color: var(--ink); }
.add-tile small { font-size: 13px; max-width: 26ch; }
@media (max-width: 560px) { .add-tile { min-height: 0; flex-direction: row; justify-content: flex-start; text-align: left; gap: 14px; padding: 16px 18px; }
  .add-plus { margin: 0; width: 44px; height: 44px; flex: none; } .add-tile small { display: none; } }

/* ปุ่มสแกน + หน้าจอกล้อง */
.btn-scan {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 56px; margin-top: 20px;
  font: inherit; font-size: 17px; font-weight: 600; color: #FFFFFF; background: var(--pine); border: 0; border-radius: 12px; cursor: pointer;
}
.btn-scan:hover { background: #0A3236; }
.btn-scan svg { width: 24px; height: 24px; fill: none; stroke: #5FD0B8; stroke-width: 2; stroke-linecap: round; }
.or { display: flex; align-items: center; gap: 12px; margin: 22px 0 18px; font-size: 13px; color: var(--muted); }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.scanner { position: fixed; inset: 0; z-index: 100; background: #000; display: flex; align-items: center; justify-content: center; }
.scanner[hidden] { display: none; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: relative; width: min(70vw, 300px); aspect-ratio: 1; border-radius: 20px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.55); outline: 3px solid #5FD0B8; outline-offset: -3px; }
.scan-status { position: absolute; left: 16px; right: 16px; bottom: calc(110px + env(safe-area-inset-bottom)); margin: 0; text-align: center; color: #FFFFFF; font-size: 16px; }
.scan-close { position: absolute; left: 50%; bottom: calc(36px + env(safe-area-inset-bottom)); transform: translateX(-50%); min-width: 140px; min-height: 48px; font: inherit; font-size: 16px; font-weight: 600; color: var(--ink); background: #FFFFFF; border: 0; border-radius: 999px; cursor: pointer; }
body.no-scroll { overflow: hidden; }

/* ---- การ์ดแบบวงกลม IAQ (หน้าภาพรวม) ---- */
.card2 {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid #E3E9E7; border-radius: 20px; overflow: hidden;
  box-shadow: 0 1px 2px rgba(20, 38, 36, 0.04), 0 12px 32px -22px rgba(12, 59, 64, 0.35);
  --c1: #6FC064; --c2: #F2C744; --c3: #F2954A; --c4: #E5675C;
}
.card2-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px 0 14px; }
.card2 .loc-edit, .card2 .loc-text {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0; margin: 0; padding: 4px 8px 4px 4px; border-radius: 8px;
  font: inherit; font-size: 17px; font-weight: 600; color: var(--ink); background: none; border: 0; text-align: left;
}
.card2 .loc-edit { cursor: text; }
.card2 .loc-edit span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card2 .loc-edit:hover { background: var(--ground); }
.card2 .loc-edit.is-empty { color: var(--accent); font-weight: 500; }
.card2 .pin { width: 18px; height: 18px; flex: none; fill: var(--accent); margin: 0; }
.card2 .pen { width: 13px; height: 13px; flex: none; fill: #9AA7A5; }
.card2 .loc-edit:hover .pen { fill: var(--accent); }
.card2 .loc-input { color: var(--ink); background: #FAFCFB; border-color: var(--accent); margin: 0; font-size: 16px; }
.card2 .loc-input:focus { box-shadow: 0 0 0 3px rgba(14, 94, 111, 0.15); background: #FFFFFF; }
.card2 .loc-input::placeholder { color: #9AA7A5; }
.card2 .status { flex: none; display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; }
.card2 .status i { width: 8px; height: 8px; border-radius: 50%; }
.card2 .status.on { color: var(--ok-ink); } .card2 .status.on i { background: #1A9A84; box-shadow: 0 0 0 3px rgba(26, 154, 132, 0.18); }
.card2 .status.off { color: var(--muted); } .card2 .status.off i { background: #A3AEAC; }

.hero { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 12px 12px 0; padding: 18px 12px; border-radius: 16px; }
.hero-l1 { background: #EEF7EA; } .hero-l2 { background: #FDF8E4; } .hero-l3 { background: #FDF0E4; } .hero-l4 { background: #FCEAE8; }
.hero-off { background: #F1F4F3; } .hero-none { background: #EEF4F5; }
.ring {
  position: relative; flex: none; width: 124px; height: 124px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: #1D2B29;
  box-shadow: 0 0 0 9px rgba(255, 255, 255, 0.65);
}
.ring-l1 { background: var(--c1); } .ring-l2 { background: var(--c2); } .ring-l3 { background: var(--c3); } .ring-l4 { background: var(--c4); }
.ring-off { background: #C9D1CF; color: #4F5D5B; } .ring-none { background: #CFE3E6; }
.ring .face { width: 44px; height: 31px; margin: -4px 0 2px; }
.ring .face circle { fill: #2E3B39; } .ring .face path { stroke: #2E3B39; }
.ring b { font-size: 34px; line-height: 1; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.ring span { font-size: 12px; font-weight: 600; letter-spacing: 0.08em; margin-top: 2px; }
.hero-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.side-v span { display: block; font-size: 13px; color: var(--muted); }
.side-v b { font-size: 28px; line-height: 1.1; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.side-v small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.hero-caption { display: flex; flex-direction: column; align-items: center; gap: 0; margin: 10px 16px 0; text-align: center; }
.hero-caption b { font-size: 16px; font-weight: 600; }
.hero-caption span { font-size: 12px; color: var(--muted); }

.tiles2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 14px 14px 0; }
.tile2 { position: relative; padding: 10px 12px 10px 14px; border: 1px solid #E3E9E7; border-radius: 12px; overflow: hidden; }
.tile2::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: #D5DDDB; }
.tile2.t1::before { background: var(--c1); } .tile2.t2::before { background: var(--c2); }
.tile2.t3::before { background: var(--c3); } .tile2.t4::before { background: var(--c4); }
.tile2-label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); }
.tile2 b { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile2 small { margin-left: 4px; font-size: 12px; color: var(--muted); }
.tile2 em { position: absolute; top: 10px; right: 10px; font-style: normal; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: #EEF2F1; color: var(--muted); }
.tile2.t3 em { background: #FDE6D3; color: #8A3B00; } .tile2.t4 em { background: #FBE0DE; color: #9B1C1C; }

.card2-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: auto; padding: 14px 14px 14px 16px; font-size: 12px; color: var(--muted); }
.card2 .btn-chart { background: var(--accent); color: #FFFFFF; }
.card2 .btn-chart:hover { background: var(--accent-dark); color: #FFFFFF; }
.card2-foot { border-top: 1px solid #EEF2F1; margin-top: 14px; }
.devices { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); align-items: stretch; }
@media (max-width: 560px) { .ring { width: 112px; height: 112px; } .ring b { font-size: 34px; } .hero { gap: 18px; } }

/* ฝุ่น 5 ระดับ แบบกรมควบคุมมลพิษ */
.tile2.a1::before { background: #3BB3E3; } .tile2.a2::before { background: #6FC064; } .tile2.a3::before { background: #F2C744; }
.tile2.a4::before { background: #F2954A; } .tile2.a5::before { background: #E5675C; }
.tile2.a1 em { background: #E2F4FB; color: #0B5A78; } .tile2.a2 em { background: #E8F5E4; color: #2F6B27; }
.tile2.a3 em { background: #FCF4D6; color: #6B4E00; } .tile2.a4 em { background: #FDE6D3; color: #8A3B00; } .tile2.a5 em { background: #FBE0DE; color: #9B1C1C; }
.tile2 em { max-width: 58%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.std-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 24px; font-size: 13px; color: var(--muted); }
.std-link:hover { color: var(--accent); }

/* หน้าเกณฑ์ที่ใช้ */
.std h1 { margin: 0 0 6px; font-size: 26px; }
.std section { margin-top: 18px; padding: 20px 22px; background: var(--surface); border: 1px solid #E3E9E7; border-radius: 16px; }
.std h2 { margin: 0 0 4px; font-size: 18px; }
.std p { margin: 6px 0; font-size: 14px; color: var(--muted); }
.std .note { padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-ink); font-size: 13px; }
.std table { width: 100%; margin-top: 10px; border-collapse: collapse; font-size: 14px; }
.std th, .std td { padding: 8px 10px; text-align: left; border-top: 1px solid #EEF2F1; }
.std th { font-size: 12px; font-weight: 600; color: var(--muted); border-top: 0; }
.std td:first-child { width: 14px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; }
.std .src { font-size: 12px; }


/* ---- นำเครื่องออกจากบัญชีจากหน้าภาพรวม ---- */
.foot-actions { display: inline-flex; align-items: center; gap: 8px; flex: none; }
.card-remove {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 36px;
  border: 1px solid transparent; border-radius: 9px; background: transparent; color: #8A9694; cursor: pointer;
}
.card-remove svg { width: 18px; height: 18px; }
.card-remove:hover { color: #9B1C1C; background: #FBECEA; border-color: #EBCFCB; }

.confirm {
  width: min(440px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 16px;
  color: var(--ink); background: var(--surface); box-shadow: 0 30px 80px -30px rgba(12, 59, 64, 0.55);
}
.confirm::backdrop { background: rgba(12, 32, 34, 0.45); }
.confirm form { display: block; padding: 24px 24px 20px; }
.confirm h2 { margin: 0 0 14px; font-size: 20px; font-weight: 600; }
.confirm p { margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.rm-device { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 10px; background: var(--ground); }
.rm-device b { font-size: 16px; color: var(--ink); }
.rm-device span { font-size: 13px; }
.confirm .rm-error { padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-ink); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.btn-plain, .btn-danger-solid {
  font: inherit; font-size: 15px; font-weight: 600; min-height: 44px; padding: 8px 18px; border-radius: 10px; cursor: pointer;
}
.btn-plain { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.btn-plain:hover { background: var(--ground); }
.btn-danger-solid { border: 0; background: #B42318; color: #FFFFFF; }
.btn-danger-solid:hover { background: #912018; }
.btn-danger-solid:disabled { opacity: 0.7; cursor: progress; }
#notice { margin-top: 12px; }
@media (max-width: 420px) { .confirm-actions { flex-direction: column-reverse; } .confirm-actions button { width: 100%; } }


/* ---- นำออกแบบกันพลาด: รหัสผ่าน / เลิกทำ / กู้คืน ---- */
.confirm .rm-pw { margin: 14px 0 0; color: var(--ink); }
.confirm .rm-pw input { margin: 0; }
.confirm p b { color: var(--ink); font-weight: 600; }
.notice {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  margin-top: 12px; padding: 10px 10px 10px 16px; border-radius: 12px;
  background: var(--ink); color: #FFFFFF; font-size: 15px;
}
.notice[hidden] { display: none; }
.notice-undo {
  font: inherit; font-size: 15px; font-weight: 600; min-height: 40px; padding: 6px 16px; border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.35); background: transparent; color: #8FE3D0; cursor: pointer;
}
.notice-undo:hover { background: rgba(255, 255, 255, 0.1); }
.notice-undo[hidden] { display: none; }
.removed { margin-top: 28px; }
.removed[hidden] { display: none; }
.removed h2 { margin: 0 0 10px; font-size: 15px; font-weight: 600; color: var(--muted); }
.removed ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-width: 640px; }
.removed li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 10px 10px 16px; border: 1px dashed #C3CFCC; border-radius: 12px; background: rgba(255, 255, 255, 0.6);
}
.rm-what { display: flex; flex-direction: column; min-width: 0; }
.rm-what b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rm-what small { font-size: 13px; color: var(--muted); }
.btn-restore { flex: none; min-height: 40px; font-size: 14px; }
