/* ========================================================
   BEMS Executive Overview v4 — Main CSS
   ======================================================== */

/* Sarabun โหลดจากไฟล์ในเครื่อง — ไม่พึ่งอินเทอร์เน็ต (on-premise) */
@font-face { font-family: 'Sarabun'; font-weight: 400; font-style: normal; font-display: swap; src: url('../assets/fonts/sarabun-400.ttf') format('truetype'); }
@font-face { font-family: 'Sarabun'; font-weight: 600; font-style: normal; font-display: swap; src: url('../assets/fonts/sarabun-600.ttf') format('truetype'); }
@font-face { font-family: 'Sarabun'; font-weight: 700; font-style: normal; font-display: swap; src: url('../assets/fonts/sarabun-700.ttf') format('truetype'); }

/* Base Configuration */
html, body {
  font-family: 'Sarabun', system-ui, sans-serif;
}

.font-num {
  font-variant-numeric: tabular-nums;
  font-family: 'Sarabun', system-ui, sans-serif;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.35);
  border-radius: 8px;
}

.dark ::-webkit-scrollbar-thumb {
  background: rgba(60, 240, 255, 0.18);
}

/* Animations */
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.pulse {
  animation: pulse-dot 2s infinite;
}

@keyframes scan {
  0% { top: 0; }
  100% { top: 100%; }
}

.scanline {
  animation: scan 3.2s linear infinite;
}

/* Glows and Effects */
.glow-cyan {
  box-shadow: 0 0 16px rgba(60, 240, 255, 0.25);
}

.card {
  transition: border-color 0.2s, box-shadow 0.2s;
}

.nav-item.active {
  background: rgba(60, 240, 255, 0.1);
  color: #3CF0FF;
  border-color: rgba(60, 240, 255, 0.35);
}

.dark .nav-item.active {
  background: rgba(60, 240, 255, 0.12);
}

/* Toggle Track */
.toggle-track {
  width: 42px;
  height: 23px;
  border-radius: 999px;
  position: relative;
  transition: 0.2s;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-track::after {
  content: "";
  position: absolute;
  width: 17px;
  height: 17px;
  border-radius: 999px;
  top: 2px;
  left: 2px;
  transition: 0.2s;
  background: #94A3B8;
}

.toggle-track.on {
  background: rgba(57, 255, 158, 0.18);
}

.toggle-track.on::after {
  left: 21px;
  background: #39FF9E;
  box-shadow: 0 0 8px #39FF9E;
}

.toggle-track.off {
  background: rgba(148, 163, 184, 0.15);
}

/* Page Sections */
.page-section {
  display: none;
}

.page-section.active {
  display: block;
}

/* Chat Scroll */
.chat-scroll {
  scroll-behavior: smooth;
}

/* Sidebar Animation */
#sidebar {
  transition: transform 0.25s ease;
}

#sidebarOverlay {
  transition: opacity 0.2s ease;
}

/* Status Pills */
.pill-status {
  font-family: 'Sarabun', system-ui, sans-serif;
  font-size: 10px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid #E2E8F0;
  color: #64748B;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dark .pill-status {
  border-color: #1C2536;
  color: #8B96AC;
  background: rgba(255, 255, 255, 0.02);
}

.pill-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #39FF9E;
  box-shadow: 0 0 6px #39FF9E;
}

.pill-status.amber::before {
  background: #FFB020;
  box-shadow: 0 0 6px #FFB020;
}

/* Executive Design v4 */
.bems-hero {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(60, 240, 255, 0.22);
  border-radius: 16px;
  padding: 16px 18px;
  background: linear-gradient(120deg, rgba(8, 34, 52, 0.9), rgba(13, 18, 32, 0.72), rgba(57, 255, 158, 0.07));
}

.bems-hero:after {
  content: "";
  position: absolute;
  width: 230px;
  height: 230px;
  border-radius: 50%;
  right: -70px;
  top: -130px;
  background: radial-gradient(circle, rgba(60, 240, 255, 0.22), transparent 67%);
  pointer-events: none;
}

html:not(.dark) .bems-hero {
  background: linear-gradient(120deg, #edfaff, #fff, #effff7);
}

.bems-kpi {
  border-radius: 14px;
  padding: 14px;
  min-height: 108px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.2);
}

.bems-kpi small {
  display: block;
  color: #94A3B8;
  font-family: 'Sarabun', system-ui, sans-serif;
  font-size: 10px;
  letter-spacing: 0.06em;
}

.bems-kpi b {
  display: block;
  margin-top: 7px;
  font-family: 'Sarabun', system-ui, sans-serif;
  font-size: 24px;
}

.bems-kpi i {
  font-style: normal;
  font-size: 10px;
  color: #94A3B8;
}

.flow-node {
  border: 1px solid rgba(60, 240, 255, 0.25);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  min-width: 100px;
}

.flow-arrow {
  color: #3CF0FF;
  font-size: 22px;
  align-self: center;
}

.risk-good {
  box-shadow: inset 3px 0 #39FF9E;
}

.page-badge {
  font-family: 'Sarabun', system-ui, sans-serif;
  font-size: 10px;
  border: 1px solid rgba(60, 240, 255, 0.32);
  padding: 4px 8px;
  border-radius: 999px;
  color: #3CF0FF;
  background: rgba(60, 240, 255, 0.08);
}

/* Calm Executive Overview v4 */
:root {
  --ex-border: rgba(148, 163, 184, 0.16);
  --ex-panel: rgba(15, 23, 42, 0.72);
  --ex-muted: #94A3B8;
}

/* Light mode overrides for executive cards */
html:not(.dark) {
  --ex-border: rgba(148, 163, 184, 0.35);
  --ex-panel: #FFFFFF;
  --ex-muted: #64748B;
}

html:not(.dark) .exec-hero,
html:not(.dark) .exec-shell {
  background: linear-gradient(110deg, #EDFAFF, #FFFFFF 52%, #EFFFF7);
}

html:not(.dark) .exec-hero:after,
html:not(.dark) .exec-shell:after {
  background: radial-gradient(circle, rgba(60, 240, 255, 0.12), transparent 68%);
}

html:not(.dark) .exec-card {
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

html:not(.dark) .flow-step {
  background: rgba(15, 23, 42, 0.03);
}

html:not(.dark) .health-row {
  border-bottom-color: rgba(15, 23, 42, 0.08);
}

html:not(.dark) .config-input {
  background: #FFFFFF;
  color: #1E293B;
}

html:not(.dark) .sensor-map {
  background: linear-gradient(90deg, rgba(60, 240, 255, 0.08) 1px, transparent 1px), linear-gradient(rgba(60, 240, 255, 0.08) 1px, transparent 1px), rgba(241, 245, 249, 0.7);
  background-size: 42px 42px;
}

.exec-shell {
  padding: 22px 24px;
  border: 1px solid var(--ex-border);
  border-radius: 18px;
  background: linear-gradient(110deg, rgba(8, 32, 49, 0.82), rgba(15, 23, 42, 0.76) 52%, rgba(24, 46, 55, 0.58));
  position: relative;
  overflow: hidden;
}

.exec-shell:after {
  content: '';
  position: absolute;
  width: 310px;
  height: 310px;
  border-radius: 50%;
  right: -120px;
  top: -190px;
  background: radial-gradient(circle, rgba(60, 240, 255, 0.17), transparent 68%);
}

.exec-hero {
  padding: 22px 24px;
  border: 1px solid var(--ex-border);
  border-radius: 18px;
  background: linear-gradient(110deg, rgba(8, 32, 49, 0.82), rgba(15, 23, 42, 0.76) 52%, rgba(24, 46, 55, 0.58));
  position: relative;
  overflow: hidden;
}

.exec-hero:after {
  content: '';
  position: absolute;
  width: 310px;
  height: 310px;
  border-radius: 50%;
  right: -120px;
  top: -190px;
  background: radial-gradient(circle, rgba(60, 240, 255, 0.17), transparent 68%);
  pointer-events: none;
}

.exec-card {
  padding: 17px;
  border: 1px solid var(--ex-border);
  background: var(--ex-panel);
  border-radius: 15px;
  box-shadow: 0 10px 35px rgba(0, 0, 0, 0.1);
}

.exec-label {
  font-family: 'Sarabun', system-ui, sans-serif;
  color: var(--ex-muted);
  letter-spacing: 0.07em;
  font-size: 10px;
}

.exec-value {
  font-family: 'Sarabun', system-ui, sans-serif;
  font-weight: 700;
  font-size: 29px;
  line-height: 1.1;
  margin-top: 7px;
}

.exec-sub {
  font-size: 11px;
  color: var(--ex-muted);
  margin-top: 8px;
}

.exec-grid4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.exec-grid3 {
  display: grid;
  grid-template-columns: 1.2fr 0.95fr 0.95fr;
  gap: 14px;
}

.exec-grid2 {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 14px;
}

.flow-box {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  gap: 7px;
  margin-top: 16px;
}

.flow-step {
  padding: 10px 7px;
  border-radius: 11px;
  text-align: center;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--ex-border);
  font-family: 'Sarabun', system-ui, sans-serif;
  font-size: 10px;
}

.flow-step b {
  display: block;
  margin-top: 4px;
  font-size: 12px;
}

.flow-link {
  height: 2px;
  background: linear-gradient(90deg, #FBBF24, #3CF0FF);
  position: relative;
}

.flow-link:after {
  content: '›';
  position: absolute;
  right: -1px;
  top: -11px;
  color: #3CF0FF;
  font-size: 18px;
}

.soft-btn {
  border: 1px solid rgba(60, 240, 255, 0.28);
  background: rgba(60, 240, 255, 0.09);
  color: #3CF0FF;
  border-radius: 9px;
  padding: 8px 10px;
  font: 11px 'Sarabun', system-ui, sans-serif;
  cursor: pointer;
  transition: 0.2s;
}

.soft-btn:hover {
  background: rgba(60, 240, 255, 0.18);
}

.health-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 11px;
}

.health-row:last-child {
  border-bottom: none;
}

.health-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #39FF9E;
  display: inline-block;
  margin-right: 6px;
}

.mini-heat {
  position: relative;
  height: 160px;
  border-radius: 12px;
  overflow: hidden;
  background: radial-gradient(circle at center, rgba(255, 59, 92, 0.1), transparent 80%);
  border: 1px solid rgba(60, 240, 255, 0.2);
}

.heat-orb {
  position: absolute;
  filter: blur(18px);
}

.chart-area {
  height: 240px;
  position: relative;
}

/* Responsive */
@media (max-width: 1280px) {
  .exec-grid4 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .exec-grid3 {
    grid-template-columns: 1fr;
  }
  
  .exec-grid2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .exec-grid4 {
    grid-template-columns: 1fr;
  }
}

/* Config Input */
.config-input {
  margin-left: 8px;
  width: 80px;
  padding: 6px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(60, 240, 255, 0.2);
  color: #D7DEEC;
  font: 11px 'Sarabun', system-ui, sans-serif;
}

.config-input:focus {
  outline: none;
  border-color: rgba(60, 240, 255, 0.5);
}

/* Sensor Pin */
.sensor-pin {
  position: absolute;
  padding: 6px 10px;
  border-radius: 12px;
  background: #3CF0FF;
  color: #00121A;
  font: 9px 'Sarabun', system-ui, sans-serif;
  border: none;
  cursor: pointer;
  font-weight: bold;
  box-shadow: 0 4px 12px rgba(60, 240, 255, 0.3);
  transition: all 0.2s;
}

.sensor-pin:hover {
  box-shadow: 0 6px 16px rgba(60, 240, 255, 0.5);
}

.sensor-pin.offline {
  background: rgb(151, 151, 151);
  box-shadow: none;
  opacity: 0.75;
}

.sensor-map {
  position: relative;
  min-height: 360px;
  border: 1px solid rgba(60, 240, 255, 0.2);
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(60, 240, 255, 0.06) 1px, transparent 1px), linear-gradient(rgba(60, 240, 255, 0.06) 1px, transparent 1px), rgba(15, 23, 42, 0.35);
  background-size: 42px 42px;
}

@media (max-width: 640px) {
  .sensor-pin {
    max-width: 42%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* AI Plan */
.ai-plan {
  border-left: 3px solid #3CF0FF;
  background: rgba(60, 240, 255, 0.06);
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

/* ========================================================
   Accessibility, motion, print — เพิ่มโดยพอร์ตจากไฟล์อ้างอิง
   ======================================================== */

/* โฟกัสที่มองเห็นได้ชัดสำหรับคีย์บอร์ด */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid #3CF0FF;
  outline-offset: 2px;
  border-radius: 6px;
}

/* เคารพการตั้งค่า "ลดการเคลื่อนไหว" ของผู้ใช้ (ไฟล์อ้างอิงวิ่ง pulse/scanline ไม่หยุด) */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* skip link ไปยังเนื้อหาหลัก */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: #3CF0FF;
  color: #00121A;
  padding: 8px 14px;
  font: 12px 'Sarabun', system-ui, sans-serif;
  border-radius: 0 0 8px 0;
}

.skip-link:focus {
  left: 0;
}

/* ปุ่มสลับภาษา */
.lang-toggle {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid #E2E8F0;
  font: 600 11px 'Sarabun', system-ui, sans-serif;
  color: #64748B;
  transition: color 0.2s, border-color 0.2s;
}

.dark .lang-toggle {
  border-color: #1C2536;
  color: #8B96AC;
}

.lang-toggle:hover {
  color: #3CF0FF;
  border-color: rgba(60, 240, 255, 0.4);
}

/* ข้อความสำรองเมื่อโหลด Chart.js ไม่ได้ */
.chart-fallback {
  display: none;
  height: 100%;
  align-items: center;
  justify-content: center;
  text-align: center;
  font: 11px 'Sarabun', system-ui, sans-serif;
  color: #94A3B8;
  padding: 16px;
}

.chart-offline .chart-fallback {
  display: flex;
}

.chart-offline canvas {
  display: none;
}

/* หน้า Overview เวอร์ชัน Executive: จำกัดความกว้างให้อ่านสบาย */
#page-overview {
  max-width: 1540px;
  margin: 0 auto;
}

/* AI decision chip ในสายโซ่การตัดสินใจ */
.decision-chip {
  padding: 4px 8px;
  border-radius: 6px;
  font: 10px 'Sarabun', system-ui, sans-serif;
  white-space: nowrap;
}

@media print {
  #sidebar,
  #sidebarOverlay,
  header,
  #globalAiForm,
  .md\:hidden,
  #aiChatToggle,
  #aiChatPanel,
  .fixed {
    display: none !important;
  }

  main {
    padding: 0 !important;
  }

  .exec-card,
  .card,
  .bems-hero,
  .exec-hero {
    break-inside: avoid;
    box-shadow: none !important;
  }
}

.metric-formula {
  font-family: 'Sarabun', system-ui, sans-serif;
  font-size: 10px;
  color: #94A3B8;
  display: block;
  margin: 8px 0;
}

/* ============================================================
   AUTH MODAL
============================================================ */
.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.auth-modal.hidden { display: none; }
.auth-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 16, 0.6);
  backdrop-filter: blur(2px);
}
.auth-modal__panel {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: #fff;
  border: 1px solid #E2E8F0;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}
.dark .auth-modal__panel {
  background: #0D1220;
  border-color: #1C2536;
}
.auth-modal__x {
  position: absolute;
  top: 12px;
  right: 12px;
  color: #94A3B8;
  transition: color 0.15s;
}
.auth-modal__x:hover { color: #06B6D4; }
.auth-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #64748B;
  margin-bottom: 4px;
}
.dark .auth-label { color: #8B96AC; }
.auth-input {
  width: 100%;
  border: 1px solid #E2E8F0;
  border-radius: 10px;
  background: #F8FAFC;
  padding: 9px 12px;
  font-size: 13px;
  color: #334155;
  outline: none;
  transition: border-color 0.15s;
}
.auth-input:focus { border-color: rgba(6, 182, 212, 0.6); }
.dark .auth-input {
  background: #0B0F19;
  border-color: #1C2536;
  color: #D7DEEC;
}

/* ========================================================
   ADMIN-DASHBOARD SKIN — เพิ่มทับสไตล์เดิม (สว่าง / อุ่น / มืด)
   เลเยอร์นี้ปรับสี ฟอนต์ และการ์ด โดยไม่ลบองค์ประกอบเดิม
   ======================================================== */
:root,
html:not(.dark):not(.warm) {
  --bx-accent: rgb(67, 121, 238);
  --bx-page:   rgb(238, 242, 248);
  --bx-text:   rgb(32, 34, 36);
  --bx-muted:  rgba(32, 34, 36, 0.6);
  --bx-card:   #ffffff;
  --bx-border: #DDE3EC;
  --bx-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.06);
  --bx-headbar: #F4F6FA;
  --bx-ok:   rgb(4, 120, 87);
  --bx-warn: rgb(180, 83, 9);
  --bx-off:  rgb(151, 151, 151);
}
html.warm {
  --bx-accent: rgb(196, 120, 50);
  --bx-page:   rgb(250, 243, 234);
  --bx-text:   rgb(68, 52, 38);
  --bx-muted:  rgba(68, 52, 38, 0.55);
  --bx-card:   rgb(255, 250, 243);
  --bx-border: rgb(233, 220, 201);
  --bx-shadow: 6px 6px 40px rgba(120, 80, 30, 0.07);
  --bx-headbar: rgb(248, 239, 226);
  --bx-ok:   rgb(4, 120, 87);
  --bx-warn: rgb(176, 88, 0);
  --bx-off:  rgb(150, 138, 122);
}
html.dark {
  --bx-accent: rgb(92, 142, 247);
  --bx-page:   rgb(18, 24, 36);
  --bx-text:   rgb(234, 238, 245);
  --bx-muted:  rgba(234, 238, 245, 0.6);
  --bx-card:   rgb(30, 39, 55);
  --bx-border: rgb(46, 58, 78);
  --bx-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  --bx-headbar: rgb(36, 46, 64);
  --bx-ok:   rgb(24, 205, 175);
  --bx-warn: rgb(255, 149, 0);
  --bx-off:  rgb(151, 151, 151);
}

html, body {
  font-family: 'Sarabun', system-ui, sans-serif;
}
body {
  background: var(--bx-page) !important;
  color: var(--bx-text) !important;
  transition: background .25s ease, color .25s ease;
}
h1, h2, h3, h4,
.font-display {
  font-family: 'Sarabun', system-ui, sans-serif !important;
  font-weight: 800;
}

/* ---- ข้อความ: หลัก / รอง ---- */
.text-slate-900, .text-slate-800, .text-slate-700,
.text-slate-600, .text-slate-300, .text-white {
  color: var(--bx-text) !important;
}
.text-slate-500, .text-slate-400 {
  color: var(--bx-muted) !important;
}

/* ---- Accent (แทนที่นีออน cyan เดิม) ---- */
.text-cyan-500, .text-cyan-400,
.dark .text-cyan-500, .dark .text-cyan-400,
.text-violet-400, .text-violet-500 {
  color: var(--bx-accent) !important;
}
.bg-cyan-500, .bg-cyan-400 { background-color: var(--bx-accent) !important; }
.bg-cyan-500\/10, .bg-cyan-400\/10, .bg-violet-400\/10 {
  background-color: color-mix(in srgb, var(--bx-accent) 12%, transparent) !important;
}
.hover\:text-cyan-500:hover { color: var(--bx-accent) !important; }

/* ---- สถานะ: เขียว = ปกติ, ส้ม = แจ้งเตือน ---- */
.text-emerald-400, .text-\[\#39FF9E\] { color: var(--bx-ok) !important; }
.text-amber-400,  .text-\[\#FFB020\] { color: var(--bx-warn) !important; }
.bg-emerald-400\/10 { background-color: color-mix(in srgb, var(--bx-ok) 14%, transparent) !important; }
.bg-amber-400\/10   { background-color: color-mix(in srgb, var(--bx-warn) 16%, transparent) !important; }

/* ---- Layout: sidebar / header / main ---- */
#sidebar {
  background: var(--bx-card) !important;
  border-color: var(--bx-border) !important;
  width: 240px !important;
}
#sidebar .border-b,
#sidebar .border-t { border-color: var(--bx-border) !important; }

header.sticky {
  height: 70px !important;
  background: var(--bx-card) !important;
  border-color: var(--bx-border) !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}
header .border,
header .border-slate-200 { border-color: var(--bx-border) !important; }
#globalAiForm { top: 70px !important; }

main#mainContent { padding: 32px !important; }
#page-overview,
.page-section { max-width: 1200px !important; margin: 0 auto; }
#page-overview.active {
  display: flex !important;
  flex-direction: column;
  gap: 20px;
}
#page-overview.active > * + * { margin-top: 0 !important; }
@media (max-width: 640px) {
  main#mainContent { padding: 18px !important; }
}

/* ---- Nav ---- */
.nav-item { font-family: 'Sarabun', system-ui, sans-serif; }
.nav-item.active,
.dark .nav-item.active {
  background: color-mix(in srgb, var(--bx-accent) 12%, transparent) !important;
  color: var(--bx-accent) !important;
  border-color: transparent !important;
}

/* ---- Card style ร่วม: radius 14, border 1px, shadow ตามธีม ---- */
.exec-card, .card, .exec-hero, .exec-shell, .bems-hero,
.auth-modal__panel, #aiChatPanel {
  background: var(--bx-card) !important;
  border: 1px solid var(--bx-border) !important;
  border-radius: 14px !important;
  box-shadow: var(--bx-shadow) !important;
}
.exec-card, .card { padding: 26px !important; }
.exec-hero, .exec-shell, .bems-hero { padding: 14px 22px !important; }
.exec-hero:after, .exec-shell:after, .bems-hero:after { display: none !important; }

.exec-label, .exec-sub { color: var(--bx-muted) !important; font-family: 'Sarabun', system-ui, sans-serif; }
.exec-value {
  font-family: 'Sarabun', system-ui, sans-serif !important;
  font-weight: 800 !important;
  font-size: 28px !important;
}

/* ---- ปุ่ม / badge ---- */
.soft-btn {
  border: 1px solid color-mix(in srgb, var(--bx-accent) 30%, transparent) !important;
  background: color-mix(in srgb, var(--bx-accent) 10%, transparent) !important;
  color: var(--bx-accent) !important;
  border-radius: 10px !important;
  font-family: 'Sarabun', system-ui, sans-serif !important;
  font-weight: 700;
}
.soft-btn:hover { background: color-mix(in srgb, var(--bx-accent) 18%, transparent) !important; }
.page-badge {
  border-color: color-mix(in srgb, var(--bx-accent) 32%, transparent) !important;
  color: var(--bx-accent) !important;
  background: color-mix(in srgb, var(--bx-accent) 8%, transparent) !important;
  font-family: 'Sarabun', system-ui, sans-serif !important;
  font-weight: 800;
}

/* ---- Pills เดิม ---- */
.pill-status {
  border-color: var(--bx-border) !important;
  color: var(--bx-muted) !important;
  background: transparent !important;
}
.pill-status::before { background: var(--bx-ok) !important; box-shadow: none !important; }
.pill-status.amber::before { background: var(--bx-warn) !important; }

/* ---- การ์ดตารางอุปกรณ์ (หน้า Overview) ---- */
.equip-card { padding: 0 !important; overflow: hidden; }
.equip-headbar {
  background: var(--bx-headbar);
  padding: 20px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--bx-border);
}
.equip-scroll { overflow-x: auto; }
.equip-table { width: 100%; border-collapse: collapse; font-family: 'Sarabun', system-ui, sans-serif; }
.equip-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--bx-muted);
  background: var(--bx-headbar);
  padding: 12px 26px;
  white-space: nowrap;
}
.equip-table td {
  padding: 14px 26px;
  font-size: 13px;
  font-weight: 700;
  color: var(--bx-text);
  border-top: 1px solid var(--bx-border);
  white-space: nowrap;
}
.equip-table tbody tr:hover { background: color-mix(in srgb, var(--bx-text) 4%, transparent); }

.equip-cat { font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 7px; }
.equip-cat.hvac   { color: var(--bx-accent); background: color-mix(in srgb, var(--bx-accent) 12%, transparent); }
.equip-cat.light  { color: var(--bx-warn);   background: color-mix(in srgb, var(--bx-warn) 14%, transparent); }
.equip-cat.plug   { color: var(--bx-ok);     background: color-mix(in srgb, var(--bx-ok) 14%, transparent); }
.equip-cat.sensor { color: #8a5cf6;          background: rgba(138, 92, 246, 0.14); }

.equip-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 800; line-height: 1; }
.equip-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.equip-pill.ok   { color: var(--bx-ok);   background: color-mix(in srgb, var(--bx-ok) 14%, transparent); }
.equip-pill.warn { color: var(--bx-warn); background: color-mix(in srgb, var(--bx-warn) 16%, transparent); }
.equip-pill.off  { color: var(--bx-off);  background: color-mix(in srgb, var(--bx-off) 18%, transparent); }

/* ---- Settings Drawer ---- */
.settings-drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: 340px;
  max-width: 88vw;
  z-index: 71;
  transform: translateX(100%);
  transition: transform .25s ease;
  background: var(--bx-card);
  border-left: 1px solid var(--bx-border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  font-family: 'Sarabun', system-ui, sans-serif;
  color: var(--bx-text);
  overflow-y: auto;
}
.settings-drawer.open { transform: translateX(0); }
#settingsBackdrop.open { opacity: 1 !important; pointer-events: auto !important; }
.set-block { display: flex; flex-direction: column; gap: 10px; }
.set-h { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--bx-muted); }
.set-seg { display: flex; gap: 6px; padding: 5px; border: 1px solid var(--bx-border); border-radius: 10px; background: var(--bx-page); }
.set-seg button {
  flex: 1;
  padding: 8px 0;
  border: 0;
  border-radius: 7px;
  background: none;
  cursor: pointer;
  font: 800 12px 'Sarabun', system-ui, sans-serif;
  color: var(--bx-muted);
}
.set-seg button.active { background: var(--bx-accent); color: #fff; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; font-weight: 700; cursor: pointer; }
.set-switch { width: 18px; height: 18px; accent-color: var(--bx-accent); cursor: pointer; flex-shrink: 0; }

/* ---- ช่องค้นหา (topbar) ---- */
.topbar-search {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--bx-page);
  border: 1px solid var(--bx-border);
  border-radius: 10px;
  padding: 8px 13px;
  width: 320px;
  max-width: 34vw;
}
.topbar-search svg { width: 16px; height: 16px; color: var(--bx-muted); flex-shrink: 0; }
.topbar-search input {
  border: none; background: none; outline: none;
  font-family: 'Sarabun', system-ui, sans-serif; font-size: 13px; font-weight: 600;
  color: var(--bx-text); width: 100%;
}
.topbar-search input::placeholder { color: var(--bx-muted); }
@media (max-width: 640px) {
  .topbar-search { max-width: none; flex: 1; }
}

/* ---- แถวกราฟแนวโน้ม + สถานะระบบ: ให้สูงพอดีกันไม่มีที่ว่างเกิน ---- */
.exec-grid2 > .exec-card { display: flex; flex-direction: column; }
.exec-grid2 > .exec-card .chart-area { height: 220px; }
.exec-grid2 > .exec-card #ovHealthList {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
}

/* ---- ปุ่มสลับชนิดกราฟ (เส้น/แท่ง) ---- */
.chart-type-seg { display: flex; gap: 4px; padding: 3px; border: 1px solid var(--bx-border); border-radius: 8px; background: var(--bx-page); }
.chart-type-seg button {
  width: 30px; height: 26px; display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 6px; background: none; cursor: pointer; color: var(--bx-muted);
}
.chart-type-seg button.active { background: var(--bx-accent); color: #fff; }
.chart-type-seg svg { width: 14px; height: 14px; }
#ovMetricSeg button, #enMetricSeg button {
  width: auto;
  height: 26px;
  padding: 0 8px;
  font-family: 'Sarabun', system-ui, sans-serif;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
#ovRangeSeg, #enRangeSeg { flex-wrap: wrap; }
#ovRangeSeg button, #enRangeSeg button {
  width: auto;
  height: 26px;
  padding: 0 10px;
  font-family: 'Sarabun', system-ui, sans-serif;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

/* ---- ปุ่มเต็มแถวในแผงตั้งค่า (เช่น พิมพ์รายงาน) ---- */
.btn-block {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--bx-border);
  border-radius: 10px;
  background: var(--bx-page);
  color: var(--bx-text);
  font-family: 'Sarabun', system-ui, sans-serif;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
}
.btn-block:hover { border-color: var(--bx-accent); color: var(--bx-accent); }
.btn-block svg { flex-shrink: 0; }

/* ---- สถานะระบบ: จุด+ป้ายสีตามสถานะ (เขียว=ปกติ, ส้ม=แจ้งเตือน, เทา=ปิด) ---- */
.health-dot.ok   { background: var(--bx-ok)   !important; box-shadow: none !important; }
.health-dot.warn { background: var(--bx-warn) !important; box-shadow: none !important; }
.health-dot.off  { background: var(--bx-off)  !important; box-shadow: none !important; }
.health-status.ok   { color: var(--bx-ok)   !important; }
.health-status.warn { color: var(--bx-warn) !important; }
.health-status.off  { color: var(--bx-off)  !important; }

/* ---- ปุ่มแจ้งเตือน (topbar) ---- */
.notif-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px;
  background: var(--bx-warn);
  color: #fff;
  font-size: 10px; font-weight: 800;
  font-family: 'Sarabun', system-ui, sans-serif;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.notif-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 320px;
  max-width: 82vw;
  background: var(--bx-card);
  border: 1px solid var(--bx-border);
  border-radius: 14px;
  box-shadow: var(--bx-shadow), 0 12px 30px rgba(0, 0, 0, 0.12);
  z-index: 75;
  overflow: hidden;
  font-family: 'Sarabun', system-ui, sans-serif;
}
.notif-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: var(--bx-headbar);
  border-bottom: 1px solid var(--bx-border);
  font-size: 13px; font-weight: 800; color: var(--bx-text);
}
.notif-head button {
  border: none; background: none; cursor: pointer;
  font-size: 11px; font-weight: 700; color: var(--bx-accent);
}
.notif-list { max-height: 320px; overflow-y: auto; }
.notif-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--bx-border);
}
.notif-item:first-child { border-top: none; }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.notif-dot.ok { background: var(--bx-ok); }
.notif-dot.warn { background: var(--bx-warn); }
.notif-dot.crit { background: #FF3B5C; }
.notif-body p { font-size: 12.5px; font-weight: 700; color: var(--bx-text); margin: 0; }
.notif-body span { font-size: 11px; font-weight: 600; color: var(--bx-muted); }
.notif-empty { padding: 24px 16px; text-align: center; font-size: 12.5px; color: var(--bx-muted); }

/* ---- Mobile polish (ใช้งานจากมือถือผ่าน LAN) ---- */
html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: none; }
.settings-drawer { height: 100dvh; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
#sidebar { padding-bottom: env(safe-area-inset-bottom); }
header.sticky { padding-top: env(safe-area-inset-top); }
@media (max-width: 768px) {
  #mainContent { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  button, select, .config-input, #sidebarNav a { min-height: 40px; }
  input, select, textarea { font-size: 16px; } /* กัน iOS zoom เมื่อโฟกัสช่องกรอก */
  .config-input { width: 96px; }
  table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ---- Chat "thinking" indicator ---- */
.chat-thinking { animation: chat-thinking-pulse 1.1s ease-in-out infinite; }
@keyframes chat-thinking-pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }


/* ---- Polish: ระยะห่าง / การเคลื่อนไหว ---- */
.exec-card, .card { padding: 24px !important; transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease; }
main#mainContent { padding: 28px 32px !important; }
#page-overview.active { gap: 24px; }
.nav-item { border-radius: 10px; transition: background .2s ease, color .2s ease; }
.nav-item:not(.active):hover { background: color-mix(in srgb, var(--bx-text) 6%, transparent); }
.exec-label { letter-spacing: .02em; }
.equip-table td, .equip-table th { padding-left: 24px; padding-right: 24px; }
@media (max-width: 640px) {
  main#mainContent { padding: 16px !important; }
  .exec-card, .card { padding: 18px !important; }
  #page-overview.active { gap: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .exec-card, .card, .nav-item { transition: none; }
}

/* ---- กล่องสภาพอากาศ: ขาว/ปกติ → ส้ม → แดงเมื่อค่าสูงเกิน ---- */
.climate-box { border: 1px solid var(--bx-border); background: color-mix(in srgb, var(--bx-text) 6%, transparent); border-radius: 12px; padding: 12px 16px; min-width: 104px; color: var(--bx-text); transition: background .25s ease, border-color .25s ease, color .25s ease; }
.climate-box[data-level="warn"] { color: var(--bx-warn); border-color: var(--bx-warn); background: color-mix(in srgb, var(--bx-warn) 14%, transparent); }
.climate-box[data-level="bad"]  { color: #ff4d4f; border-color: #ff4d4f; background: color-mix(in srgb, #ff4d4f 14%, transparent); }

/* ================= Visual refresh ================= */
body {
  background-image:
    radial-gradient(900px 420px at 85% -80px, color-mix(in srgb, var(--bx-accent) 14%, transparent), transparent 70%),
    radial-gradient(700px 360px at -10% 0, color-mix(in srgb, var(--bx-ok) 8%, transparent), transparent 70%);
  background-repeat: no-repeat;
  background-attachment: fixed;
}

/* Hero */
.exec-hero {
  background: linear-gradient(120deg, color-mix(in srgb, var(--bx-accent) 16%, var(--bx-card)), var(--bx-card) 65%) !important;
  padding: 18px 24px !important;
}

/* Climate boxes */
.climate-box { position: relative; padding: 10px 16px 12px; }
.climate-box .exec-label { display: flex; align-items: center; gap: 6px; font-size: 11px; }
.climate-box .climate-ico { opacity: .85; flex: none; }
.climate-box .font-num { font-size: 20px; font-weight: 800; line-height: 1.2; }
.climate-box .font-num span { font-variant-numeric: tabular-nums; }
.climate-dot { width: 7px; height: 7px; border-radius: 50%; margin-left: auto; background: var(--bx-ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bx-ok) 22%, transparent); }
.climate-box[data-level="warn"] .climate-dot { background: var(--bx-warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bx-warn) 25%, transparent); }
.climate-box[data-level="bad"] .climate-dot { background: #ff4d4f; box-shadow: 0 0 0 3px color-mix(in srgb, #ff4d4f 25%, transparent); animation: climatePulse 1.4s ease-in-out infinite; }
@keyframes climatePulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, #ff4d4f 10%, transparent); } }

/* KPI cards */
.kpi { position: relative; overflow: hidden; padding-bottom: 14px !important; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--kpi-c, var(--bx-accent)); opacity: .9; }
.kpi-power { --kpi-c: var(--bx-accent); }
.kpi-cost  { --kpi-c: var(--bx-warn); }
.kpi-occ   { --kpi-c: var(--bx-ok); }
.kpi-perf  { --kpi-c: #8a5cf6; }
.kpi-ico { position: absolute; top: 18px; right: 18px; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: var(--kpi-c); background: color-mix(in srgb, var(--kpi-c) 14%, transparent); }
.kpi .exec-value { font-size: 32px !important; letter-spacing: -.01em; }
.kpi .exec-sub { margin-top: 6px; }
.spark { display: block; width: 100%; height: 28px; margin-top: 10px; overflow: visible; }
.spark polyline { fill: none; stroke: var(--kpi-c); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; opacity: .85; }

/* Sidebar / header */
.nav-item { position: relative; font-weight: 600; }
.nav-item.active::before { content: ""; position: absolute; left: -12px; top: 22%; bottom: 22%; width: 4px; border-radius: 0 4px 4px 0; background: var(--bx-accent); }
#sidebar nav { padding-left: 12px; padding-right: 12px; }
header.sticky { box-shadow: 0 1px 0 var(--bx-border), 0 6px 18px rgba(0, 0, 0, .06); }
header.sticky .ml-auto { gap: 10px; }
header.sticky button { border-radius: 10px; transition: border-color .2s ease, color .2s ease, background .2s ease; }
header.sticky button:hover { border-color: var(--bx-accent) !important; background: color-mix(in srgb, var(--bx-accent) 8%, transparent); }

/* Equipment table */
.equip-table tbody tr:nth-child(even) { background: color-mix(in srgb, var(--bx-text) 2.5%, transparent); }
.equip-table tbody tr { transition: background .15s ease; }
.equip-table tbody tr:hover { background: color-mix(in srgb, var(--bx-accent) 8%, transparent); }
.equip-pill { padding: 5px 12px; font-size: 12px; }
.equip-pill.ok::before { box-shadow: 0 0 0 3px color-mix(in srgb, var(--bx-ok) 25%, transparent); }

/* ---- Sidebar หุบได้ (จอใหญ่) ---- */
@media (min-width: 1024px) {
  #sidebar { transition: width .25s ease, border-color .25s ease; overflow: hidden; }
  #sidebar > * { min-width: 240px; }
  body.sb-collapsed #sidebar { width: 0 !important; border-right-width: 0 !important; }
}

/* ================= Critique fixes ================= */
/* ตัวเลข KPI ใช้สีเดียวกับแถบ/ไอคอนของการ์ดนั้น */
.kpi .exec-value, .kpi .exec-value * { color: var(--kpi-c) !important; }
html:not(.dark) .kpi-perf { --kpi-c: #6d3fd8; }

/* โหมดสว่าง: สีแดงเตือนให้เข้มพอ (contrast) */
html:not(.dark) .climate-box[data-level="bad"] { color: #c62828; border-color: #c62828; }
html:not(.dark) .climate-box[data-level="bad"] .climate-dot { background: #c62828; }

/* สถานะไม่พึ่งสีอย่างเดียว: เพิ่มข้อความกำกับ */
.climate-box[data-level="warn"] .exec-label::before,
.climate-box[data-level="bad"] .exec-label::before {
  order: 3; font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 999px;
  background: color-mix(in srgb, currentColor 16%, transparent);
}
.climate-box[data-level="warn"] .exec-label::before { content: "สูง"; }
.climate-box[data-level="bad"]  .exec-label::before { content: "สูงมาก"; }

/* ป้ายเล็กให้อ่านง่ายขึ้น */
.exec-label { font-size: 12px !important; }
.exec-sub { font-size: 12px; }

/* ปุ่มมุมขวาบน: เป้าสัมผัส ≥ 44px */
header.sticky .ml-auto > button,
header.sticky .ml-auto > .relative > button { min-width: 44px; min-height: 44px; }
.chart-type-seg button { min-height: 36px; }
@media (pointer: coarse) { .chart-type-seg button { min-height: 44px; min-width: 44px; } }

/* hero: ชื่อหลัก + ห้องเป็นบรรทัดรอง */
.hero-room { margin-top: 2px; }
#ovMetricSeg button, #enMetricSeg button { white-space: nowrap; flex: 0 0 auto; }
#enMetricSeg button { min-width: 44px; }


/* ========================================================
   Overview — "แผงมิเตอร์ไฟฟ้า"
   จุดเด่นเดียว: ค่ากำลังไฟขนาดใหญ่คู่กราฟ ส่วนอื่นเรียบและนิ่ง
   ใช้ตัวแปร --bx-* เดิม จึงรองรับธีมสว่าง/อบอุ่น/มืดอัตโนมัติ
   ======================================================== */
#page-overview .exec-hero {
  background: none !important;
  border: 0 !important;
  border-bottom: 1px solid var(--bx-border) !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  padding: 0 0 16px !important;
}
#page-overview #ovHeroTitle { font-size: 22px; font-weight: 700; line-height: 1.35; }
#page-overview .hero-room { margin-top: 2px; }
#page-overview .climate-box { background: none; border: 0; border-left: 2px solid var(--bx-border); border-radius: 0; padding: 0 0 0 12px; min-width: 0; }

#page-overview .ov-stage {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
}
#page-overview .ov-stage > .exec-card { transform: none !important; }

#page-overview .ov-meter {
  display: flex;
  flex-direction: column;
  border-left: 4px solid var(--bx-accent) !important;
  padding: 24px 24px 20px !important;
}
#page-overview .ov-reading {
  margin: 8px 0 4px;
  font-size: 84px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--bx-accent);
}
#page-overview .ov-reading small { font-size: 24px; font-weight: 600; margin-left: 6px; letter-spacing: 0; color: var(--bx-muted); }
#page-overview .ov-meter > .spark { width: 100%; height: 28px; margin-top: 12px; }
/* สเกลมิเตอร์: เลื่อนเข้าครั้งเดียวตอนเปิดหน้า */
#page-overview .ov-figures {
  margin: 14px 0 0;
  padding-top: 14px;
  background: repeating-linear-gradient(90deg, var(--bx-muted) 0 1px, transparent 1px 10px) top / 100% 7px no-repeat;
}
#page-overview .ov-figures::before {
  content: "";
  display: block;
  height: 0;
}

#page-overview .ov-fig {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-top: 1px solid var(--bx-border);
}
#page-overview .ov-fig:first-child { margin-top: 8px; }
#page-overview .ov-fig dt { margin: 0; }
#page-overview .ov-fig dd { margin: 0; }
#page-overview .ov-fig .exec-value { font-size: 22px !important; font-weight: 700 !important; font-variant-numeric: tabular-nums; color: var(--bx-text); }
#page-overview .ov-fig .exec-value small { font-size: 14px; font-weight: 600; color: var(--bx-muted); }
#page-overview .ov-fig .spark { display: none; }

#page-overview .ov-trend .chart-area { height: 300px; }

#page-overview .ov-health { padding: 14px 20px !important; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 28px; }
#page-overview .ov-health-head { display: flex; align-items: center; gap: 12px; }
#page-overview .ov-health #ovHealthList { display: flex; flex-wrap: wrap; gap: 8px 28px; flex: 1; }
#page-overview .ov-health .health-row { display: flex; align-items: center; gap: 8px; padding: 0; border: 0; }

@media (max-width: 900px) {
  #page-overview .ov-stage { grid-template-columns: minmax(0, 1fr); }
  #page-overview .ov-reading { font-size: 64px; }
  #page-overview .ov-trend .chart-area { height: 240px; }
}
@media (prefers-reduced-motion: no-preference) {
  #page-overview .ov-figures { animation: ov-scale-in .9s cubic-bezier(.2,.7,.2,1) both; }
}
@keyframes ov-scale-in { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }

/* ยกเลิกแถบสี .kpi เดิมในแผงมิเตอร์ (ใช้เส้นขอบซ้ายของ .ov-meter แทน) และลดสีให้เหลือสีเน้นเดียว */
#page-overview .ov-meter::before,
#page-overview .ov-fig::before { display: none; }
#page-overview .ov-fig { padding-bottom: 11px !important; }
#page-overview .ov-fig .exec-value,
#page-overview .ov-fig .exec-value * { color: var(--bx-text) !important; }
#page-overview .ov-fig .exec-value small { color: var(--bx-muted) !important; }
#page-overview .ov-meter .spark polyline { stroke: var(--bx-accent); }
#page-overview .ov-reading { font-size: clamp(56px, 6vw, 80px); }

/* ---- Overview ส่วนล่าง: ให้เข้ากับแผงมิเตอร์ ---- */
/* การไหลของพลังงาน: ค่าอ่านเรียงแถวเดียว คั่นด้วยเส้นแนวตั้ง */
#page-overview .flow-box {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0;
  margin-top: 18px;
}
#page-overview .flow-link { display: none; }
#page-overview .flow-step {
  background: none;
  border: 0;
  border-left: 1px solid var(--bx-border);
  border-radius: 0;
  padding: 2px 12px;
  text-align: left;
  font-size: 12px;
  color: var(--bx-muted) !important;
}
#page-overview .flow-step:first-child { border-left: 0; padding-left: 0; }
#page-overview .flow-step b {
  margin-top: 6px;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--bx-text);
}

/* คำแนะนำ AI: กล่องผลลัพธ์เป็นเส้นข้างเดียวกับแผงมิเตอร์ */
#page-overview #ovInsightExpect { font-size: 15px; font-weight: 700; }
#page-overview .exec-card .rounded-xl.bg-cyan-500\/10 {
  background: none !important;
  border-left: 4px solid var(--bx-accent);
  border-radius: 0 !important;
  padding: 2px 0 2px 12px !important;
}

/* ทะเบียนอุปกรณ์: ตัดช่องว่างซ้อนที่เกิดจาก padding ของ .exec-card */
#page-overview .equip-card { padding: 0 !important; }
#page-overview .equip-headbar { padding: 18px 24px; }

@media (max-width: 900px) {
  #page-overview .flow-box { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 14px; }
  #page-overview .flow-step:nth-child(odd) { border-left: 0; padding-left: 0; }
}

/* แอนิเมชันสเกล: เฉพาะแถบขีด ไม่ตัดตัวเลขในกล่องเดียวกัน */
#page-overview .ov-figures { background: none; animation: none !important; }
#page-overview .ov-figures::before {
  content: "";
  display: block;
  height: 7px;
  background: repeating-linear-gradient(90deg, var(--bx-muted) 0 1px, transparent 1px 10px);
}
@media (prefers-reduced-motion: no-preference) {
  #page-overview .ov-figures::before { animation: ov-scale-in .9s cubic-bezier(.2,.7,.2,1) both; }
}

/* นับเฉพาะ div (ข้าม <i class="flow-link"> ที่ซ่อนอยู่) เพื่อให้เส้นคั่นบนมือถือสม่ำเสมอ */
@media (max-width: 900px) {
  #page-overview .flow-step:nth-child(odd) { border-left: 1px solid var(--bx-border); padding-left: 12px; }
  #page-overview .flow-step:nth-of-type(odd) { border-left: 0; padding-left: 0; }
}

/* การ์ดการไหลของพลังงานไม่ต้องยืดเท่าการ์ดควบคุมด่วน (ตัดพื้นที่ว่าง) */
#page-overview .exec-grid2 { align-items: start; }

/* ---- สัดส่วนแหล่งไฟ (การ์ดการไหลของพลังงาน) ---- */
#page-overview .flow-mix { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--bx-border); }
#page-overview .flow-mix-title { font-size: 15px; font-weight: 600; color: var(--bx-text); margin: 0 0 10px; }
#page-overview .mix-bar { display: flex; height: 12px; gap: 2px; border-radius: 3px; overflow: hidden; background: color-mix(in srgb, var(--bx-text) 8%, transparent); }
#page-overview .mix-bar i { display: block; flex: 0 0 auto; min-width: 0; transition: flex-grow .6s ease; }
#page-overview .mix-bar .mix-solar { background: var(--bx-accent); }
#page-overview .mix-bar .mix-batt  { background: var(--bx-ok); }
#page-overview .mix-bar .mix-grid  { background: var(--bx-off); }
#page-overview .mix-legend { display: flex; flex-wrap: wrap; gap: 6px 24px; margin: 12px 0 0; padding: 0; list-style: none; font-size: 12px; color: var(--bx-muted); }
#page-overview .mix-legend li::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 2px; vertical-align: -1px; background: var(--c); }
#page-overview .mix-legend .mix-solar { --c: var(--bx-accent); }
#page-overview .mix-legend .mix-batt  { --c: var(--bx-ok); }
#page-overview .mix-legend .mix-grid  { --c: var(--bx-off); }
#page-overview .mix-legend b { color: var(--bx-text); font-variant-numeric: tabular-nums; margin-left: 4px; }
@media (prefers-reduced-motion: reduce) { #page-overview .mix-bar i { transition: none; } }

/* แจ้งเตือนที่ระฆัง: เห็นแล้ว = จาง */
.notif-item.seen { opacity: .55; }
.notif-item.seen .notif-dot { filter: grayscale(1); }

/* หน้าวิเคราะห์พลังงาน: ตัวเลข kW / kWh / kWh/วัน ต้องไม่ล้นช่อง */
#energyBreakdown .exec-grid4 > div { min-width: 0; }
#energyBreakdown .exec-value { font-size: clamp(18px, 2.2vw, 24px) !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#energyBreakdown .exec-value small { font-size: 0.55em; font-weight: 600; color: var(--bx-muted); }
#energyBreakdown .health-row { flex-wrap: wrap; gap: 2px 12px; }
#energyBreakdown .health-row > span:last-child { text-align: right; overflow-wrap: anywhere; }

/* ตารางการใช้ห้อง */
.sch-lunch { background: rgba(100, 116, 139, .25); }
.sch-empty { cursor: pointer; }
.sch-empty:hover { background: color-mix(in srgb, var(--bx-accent, #4379EE) 12%, transparent); }
.sch-item { background: color-mix(in srgb, var(--bx-accent, #4379EE) 14%, transparent); cursor: default; }
.sch-item[data-sch-edit] { cursor: pointer; }
.sch-item:hover { background: color-mix(in srgb, var(--bx-accent, #4379EE) 24%, transparent); }
.sch-warn { outline: 2px dashed #f5b400; outline-offset: -3px; }

/* เอาช่องค้นหาบนแถบบนออกทุกหน้า (เหมือนหน้า overview) */
.topbar-search { display: none !important; }
