/* ============================================================
   KPI Office — Huawei FusionSolar Dashboard — shared stylesheet
   Linked by: index.html, alarms.html, inverters.html, reports.html,
              settings.html, login.html, admin-users.html, qrcode.html
   ============================================================ */

body, .page-body { background:#f3f5f9; font-size:16px; }
body { zoom: 0.75; }

/* Cards */
.card { border:0; border-radius:16px; box-shadow:0 4px 18px rgba(40,60,90,.07); transition:transform .2s, box-shadow .2s; }
.card:hover { transform:translateY(-2px); box-shadow:0 8px 24px rgba(40,60,90,.12); }
.card-header { border-bottom:0; padding-bottom:0; }
.card-title { font-weight:700; font-size:1.25rem; }

/* Typography */
.h1 { font-size:3.2rem; }
.h2 { font-size:2.8rem; }
.h3 { font-size:2.1rem; }
.card-body .h3 { font-weight:700; }
.text-muted.small, .small, small { font-size:1rem; }
.apexcharts-datalabel-value { font-size:26px !important; }

/* Sidebar */
.navbar-vertical { background:#fff !important; border-right:1px solid #eef0f5; }
.navbar-vertical .nav-link-title { font-size:1.05rem; }
.navbar-brand { font-size:1.35rem; }
.sidebar-logo-img { width:100%; height:auto; display:block; }
.navbar-vertical .nav-item.active { position:relative; }
.navbar-vertical .nav-item.active::before { content:""; position:absolute; left:0; top:6px; bottom:6px; width:3px; background:#206bc4; border-radius:0 3px 3px 0; }
.navbar-vertical .nav-item.active .nav-link { color:#206bc4 !important; font-weight:600; background:#eef3fb; border-radius:10px; }
.navbar-vertical .nav-link { color:#6c7a92; padding:10px 14px; border-radius:10px; margin:2px 6px; }
.navbar-vertical .nav-link:hover { background:#f5f7fb; }
.navbar-vertical .navbar-collapse { display:flex !important; flex-direction:column; height:100%; }
.sidebar-footer { border-top:1px solid #eef0f5; padding-bottom:12px; }

/* Gauge / KPI */
.gauge-card { text-align:center; }
.gauge-card .gauge-title { color:#6c7a92; font-size:13px; font-weight:500; }
.gauge-card .gauge-value { font-size:1.8rem; font-weight:700; color:#2c3e50; margin-top:-60px; }
.gauge-card .gauge-sub { color:#6c7a92; font-size:12px; }
.legend-dot { width:10px; height:10px; border-radius:50%; display:inline-block; margin-right:6px; }

/* ===== Neumorphic 3D ring gauges (ported from Power Energy dashboard.html's
   .ngauge component — plain CSS + inline SVG stroke-dasharray, no charting lib).
   Scaled to 150px (reference used 200px); SVG geometry is viewBox-relative so
   only the outer px-based sizing (puck size, inset, font sizes) was rescaled. */
.ngauge { position:relative; width:150px; height:150px; margin:0 auto; border-radius:50%; overflow:hidden;
  background:linear-gradient(145deg,#eef1f5,#ccd4de);
  box-shadow:0 6px 15px rgba(0,0,0,.15), inset 0 -4px 7px rgba(0,0,0,.12);
  display:flex; align-items:center; justify-content:center; flex-shrink:0; }
html.dark .ngauge { background:linear-gradient(145deg,#333d49,#181e26); box-shadow:0 6px 15px rgba(0,0,0,.5), inset 0 -4px 7px rgba(0,0,0,.5); }
.ngauge svg { position:absolute; inset:7px; width:calc(100% - 14px); height:calc(100% - 14px); transform:rotate(126deg); overflow:visible; }
.ngshadow { fill:none; stroke:rgba(0,0,0,.18); stroke-width:14; stroke-linecap:round; filter:blur(1.6px); }
html.dark .ngshadow { stroke:rgba(0,0,0,.55); }
.ngtrack { fill:none; stroke:#c2cad6; stroke-width:9; stroke-linecap:round; }
html.dark .ngtrack { stroke:#4b5562; }
.ngfill { fill:none; stroke-width:9; stroke-linecap:round; transition:stroke-dasharray .5s, stroke .3s; }
.nghole { position:relative; width:66%; height:66%; border-radius:50%;
  background:linear-gradient(145deg,#fcfdff,#dbe1ea);
  box-shadow:0 4px 10px rgba(0,0,0,.12), inset 0 2px 3px rgba(255,255,255,.7), inset 0 -3px 5px rgba(0,0,0,.1);
  display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; line-height:1.1; }
html.dark .nghole { background:linear-gradient(145deg,#3a4450,#1b222b); box-shadow:0 4px 10px rgba(0,0,0,.5), inset 0 2px 3px rgba(255,255,255,.10), inset 0 -3px 5px rgba(0,0,0,.45); }
.nghole .ngv { font-size:20px; font-weight:800; font-family:'JetBrains Mono','Consolas',monospace; line-height:1; text-shadow:0 0 8px currentColor; }
.nghole .ngu { font-size:9px; color:#6c7a92; font-weight:600; margin-top:3px; }
html.dark .nghole .ngu { color:#8aa0b5; }

/* Weather card */
.weather-card { background:linear-gradient(135deg,#4fc3f7 0%,#1976d2 100%); color:#fff; }
.weather-card .display-5 { font-weight:300; color:#fff; font-size:2.6rem; }
.weather-card i { opacity:.9; }
.weather-middle { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.weather-left { flex:1; }
.weather-center { flex:0 0 auto; text-align:center; min-width:96px; }
.big-icon { width:64px; height:64px; margin:0 auto; filter:drop-shadow(0 6px 14px rgba(0,0,0,0.15)); font-size:48px; line-height:1; overflow:hidden; }
.big-icon img { width:100%; height:100%; object-fit:contain; }
.weather-stats { display:grid; grid-template-columns:1fr 1fr; gap:10px 12px; margin:12px 0 6px; padding:12px 0; border-top:1px solid rgba(255,255,255,0.2); border-bottom:1px solid rgba(255,255,255,0.2); }
.weather-stats > div { display:flex; align-items:center; gap:8px; font-size:1rem; opacity:.95; }
.weather-stats i { font-size:22px !important; opacity:.9; }
.weather-stats span { flex:1; opacity:.78; font-size:1rem; }
.weather-stats b { font-weight:700; color:#fff; font-size:1.05rem; }

/* Hourly weather strip */
.hourly-strip { display:grid; grid-template-columns:repeat(7, 1fr); gap:6px 4px; padding:10px 0 4px; border-top:1px solid rgba(255,255,255,0.2); margin-top:10px; }
.hour-cell { text-align:center; padding:6px 2px; border-radius:8px; font-size:12px; color:#fff; opacity:0.92; }
.hour-cell.now { background:rgba(255,255,255,0.22); font-weight:700; opacity:1; box-shadow:0 0 0 1px rgba(255,255,255,0.35) inset; }
.hour-cell .hour-icon { width:28px; height:28px; display:block; margin:3px auto; object-fit:contain; font-size:20px; }
.hour-cell .hour-time { font-weight:600; font-size:0.75rem; }
.hour-cell .hour-temp { font-weight:700; font-size:0.95rem; margin-top:3px; }

/* AI Forecast card hourly strip — same grid idea as .hourly-strip but tuned for a
   normal light card background instead of the weather card's dark-blue one. */
.fc-hourly { display:flex; gap:10px; overflow-x:auto; padding:10px 2px 4px; border-top:1px solid #eef0f5; margin-top:6px; }
.fc-hour-cell { flex:0 0 auto; min-width:52px; text-align:center; font-size:12px; color:#6c7a92; }
.fc-hour-cell .fc-hour-time { font-weight:600; font-size:0.75rem; }
.fc-hour-cell .fc-hour-cloud { font-weight:700; font-size:0.95rem; color:#206bc4; margin-top:2px; }
html.dark .fc-hourly { border-top-color: var(--color-border); }
html.dark .fc-hour-cell { color: var(--color-text-muted); }
html.dark .fc-hour-cell .fc-hour-cloud { color: var(--color-primary-600); }

/* 7-day forecast row (weather-radar page) — same idea as .fc-hourly but one cell per day */
.fc-daily { display:flex; gap:10px; overflow-x:auto; padding:6px 2px; }
.fc-day-cell { flex:1 1 0; min-width:80px; text-align:center; padding:10px 6px; border-radius:10px; }
.fc-day-cell.today { background:#eef4ff; }
.fc-day-cell .fc-day-name { font-weight:600; font-size:0.8rem; color:#6c7a92; }
.fc-day-cell .fc-day-icon { width:40px; height:40px; margin:6px auto; display:block; object-fit:contain; }
.fc-day-cell .fc-day-temps { font-size:0.85rem; }
.fc-day-cell .fc-day-temps .max { font-weight:700; }
.fc-day-cell .fc-day-temps .min { color:#6c7a92; margin-left:4px; }
.fc-day-cell .fc-day-rain { font-size:0.72rem; color:#206bc4; margin-top:2px; }
html.dark .fc-day-cell.today { background: var(--color-surface-muted); }
html.dark .fc-day-cell .fc-day-name, html.dark .fc-day-cell .fc-day-temps .min { color: var(--color-text-muted); }
html.dark .fc-day-cell .fc-day-rain { color: var(--color-primary-600); }

/* Rain radar map (weather-radar page) — tall/portrait aspect + vertical legend
   gutter beside it, mirroring the Thai Met Dept radar-app reference layout.
   Height is 100% of the card body (which itself stretches via .card.h-100 to
   match the taller sidebar column) rather than a fixed px, so the map always
   reaches the bottom of its card instead of leaving blank space below it. */
#section-radar .card-body { height:100%; }
#radarMap { height:100%; min-height:480px; min-width:0; border-radius:16px; overflow:hidden; background:#dde3ea; }
.scroll-anchor { scroll-margin-top:90px; }
.radar-legend-vertical { display:flex; align-items:stretch; gap:6px; width:64px; flex:0 0 auto; padding:4px 0; }
.rlv-ticks { display:flex; flex-direction:column; justify-content:space-between; font-size:11px; color:#6c7a92; text-align:right; }
.radar-legend-vertical-bar { width:12px; border-radius:6px;
  background:linear-gradient(to bottom,#d6339a,#e5433a,#f2994a,#f5d327,#7cc94c,#39a8a0,#63b8e0,#bfe3f5); }
html.dark .rlv-ticks { color: var(--color-text-muted); }

/* Solid current-conditions circle (weather-radar page only; dashboard's compact
   weather-card keeps the .weather-middle/.big-icon layout above, shared across pages) */
.weather-circle-solid { flex:0 0 auto; width:88px; height:88px; border-radius:50%;
  background:#0d47a1; box-shadow:0 4px 10px rgba(0,0,0,.2); display:flex; align-items:center; justify-content:center; }
.weather-circle-solid span { font-size:1.7rem; font-weight:700; color:#fff; }
.weather-mini-icon { width:32px; height:32px; filter:drop-shadow(0 2px 6px rgba(0,0,0,.15)); }
.weather-mini-icon img { width:100%; height:100%; object-fit:contain; }

/* Rain-nearby mini radar (weather-radar page) */
#rainNearbyMap { height:180px; border-radius:8px; overflow:hidden; background:#dde3ea; }
.ring-label { font-size:10px; font-weight:600; color:#6c7a92; background:rgba(255,255,255,.85);
  padding:0 4px; border-radius:3px; white-space:nowrap; text-align:center; }
html.dark .ring-label { background:rgba(30,36,50,.85); color:var(--color-text-muted); }

/* Monthly tiles (dashboard) */
.monthly-card { border-radius:12px; padding:14px; text-align:center; color:#fff; }
.monthly-card.m1 { background:linear-gradient(135deg,#ffb74d,#fb8c00); }
.monthly-card.m2 { background:linear-gradient(135deg,#64b5f6,#1976d2); }
.monthly-card.m3 { background:linear-gradient(135deg,#81c784,#388e3c); }
.monthly-card.m4 { background:linear-gradient(135deg,#ba68c8,#7b1fa2); }
.monthly-card i { font-size:24px; opacity:.9; }
.monthly-card .h3 { color:#fff; font-weight:700; margin:4px 0; }
.monthly-card small { opacity:.9; }

/* Status dots */
.status-dot { width:8px; height:8px; border-radius:50%; display:inline-block; margin-right:6px; vertical-align:middle; }
.status-online { background:#2fb344; box-shadow:0 0 6px #2fb344; }
.status-offline { background:#d63939; }
.status-warning { background:#f59f00; }

/* Table */
.card-table thead th { background:#fafbfd; color:#6c7a92; font-weight:600; font-size:12px; text-transform:uppercase; letter-spacing:.4px; }
.card-table tbody td { vertical-align:middle; }

/* Tabs */
.tab-group { display:inline-flex; background:#f3f5f9; border-radius:999px; padding:3px; }
.tab-btn { border:0; background:transparent; padding:6px 14px; border-radius:999px; font-size:13px; font-weight:500; color:#6c7a92; cursor:pointer; }
.tab-btn.active { background:#206bc4; color:#fff; box-shadow:0 2px 6px rgba(32,107,196,.3); }

/* Report data table — sortable headers + pagination (plant-report.html) */
#reportTable th.sortable { cursor:pointer; user-select:none; white-space:nowrap; }
#reportTable th.sortable:hover { color:#206bc4; }
#reportTable th.sortable .sort-arrow { display:inline-block; width:12px; opacity:.3; font-size:11px; }
#reportTable th.sortable.sort-asc .sort-arrow,
#reportTable th.sortable.sort-desc .sort-arrow { opacity:1; color:#206bc4; }
#reportTable td.num, #reportTable th.num { text-align:right; font-variant-numeric:tabular-nums; }
#pageControls .btn { min-width:38px; }
html.dark #reportTable th.sortable:hover { color: var(--color-primary); }
html.dark #reportTable th.sortable.sort-asc .sort-arrow,
html.dark #reportTable th.sortable.sort-desc .sort-arrow { color: var(--color-primary); }

/* Nav controls */
.nav-ctl { display:inline-flex; align-items:center; gap:8px; font-size:13px; }
.nav-ctl .btn { padding:2px 10px; }

/* Date-picker label (click → opens native date picker) */
.date-picker-wrap { position:relative; display:inline-block; }
.hidden-date-input { position:absolute; inset:0; width:100%; height:100%; opacity:0; border:0; padding:0; cursor:pointer; z-index:2; }
.date-label-clickable { display:inline-flex; align-items:center; padding:4px 12px; border-radius:6px; background:#eef3fb; color:#206bc4; font-weight:600; transition:background .15s; pointer-events:none; }
.date-picker-wrap:hover .date-label-clickable { background:#dbe7f7; }

/* Summary box */
.summary-box { background:#f8fafc; border-radius:12px; padding:12px 14px; }
.summary-box .h3 { margin-bottom:0; }
.row > [class*="col-"] > .summary-box { height:100%; }

/* Progress bars */
.dual-progress { display:flex; height:6px; border-radius:3px; overflow:hidden; background:#eef0f5; margin-bottom:4px; }
.dual-progress .dp-fill { height:100%; transition:width .4s ease; }
.single-progress { height:6px; border-radius:3px; background:#eef0f5; overflow:hidden; margin-bottom:4px; }
.single-progress .sp-fill { height:100%; transition:width .4s ease; }

.text-orange { color:#fd7e14; }

/* 8-column row (Bootstrap 5 native: 1..6 only) */
.row-cols-md-8 > * { flex: 0 0 auto; width: 50%; }
@media (min-width: 768px) { .row-cols-md-8 > * { width: 12.5%; } }

.kpi-mini-card { min-height: 160px; overflow:hidden; }
.kpi-mini-card .card-body { display:flex; flex-direction:column; justify-content:center; padding:10px 6px; }
.kpi-mini-card .h2 { margin: 10px 0 6px !important; line-height: 1.1; white-space:nowrap; }
.kpi-mini-card .small { font-size:0.85rem; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

/* ====== Inverter grid (inverters page) ====== */
.inv-filter-bar { background:#fff; border-radius:14px; box-shadow:0 2px 10px rgba(40,60,90,.05); padding:12px 16px; display:flex; flex-wrap:wrap; gap:10px; align-items:center; }
.inv-filter-bar .form-select, .inv-filter-bar .form-control { height:38px; }

.dev-grid { display:grid; grid-template-columns:repeat(3, 1fr); gap:18px; }
@media (max-width: 1400px) { .dev-grid { grid-template-columns:repeat(2, 1fr); } }
@media (max-width: 700px) { .dev-grid { grid-template-columns:1fr; } }

.dev-card { background:#fff; border-radius:12px; box-shadow:0 2px 10px rgba(40,60,90,.06); padding:18px 20px; border:1px solid #eef0f5; border-top:3px solid #94a3b8; transition:transform .15s, box-shadow .15s; }
.dev-card:hover { transform:translateY(-1px); box-shadow:0 6px 20px rgba(40,60,90,.12); }
.dev-card.s-online  { border-top-color:#22c55e; }
.dev-card.s-alarm   { border-top-color:#f97316; }
.dev-card.s-fault   { border-top-color:#ef4444; }
.dev-card.s-offline { border-top-color:#94a3b8; opacity:.85; }

.dev-card .dev-head { display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:6px; }
.dev-card .dev-name { font-size:16px; font-weight:700; color:#1a2332; line-height:1.3; }
.dev-card .dev-sn { font-size:12px; color:#6c7a92; display:flex; align-items:center; gap:5px; margin-bottom:12px; }
.dev-card .dev-badge { display:inline-flex; align-items:center; gap:5px; padding:3px 10px; border-radius:20px; font-size:12px; font-weight:700; margin-bottom:8px; white-space:nowrap; }
.dev-card .dev-badge.s-online  { background:rgba(34,197,94,.15);  color:#15803d; }
.dev-card .dev-badge.s-alarm   { background:rgba(249,115,22,.15); color:#c2410c; }
.dev-card .dev-badge.s-fault   { background:rgba(239,68,68,.15);  color:#b91c1c; }
.dev-card .dev-badge.s-offline { background:rgba(148,163,184,.2); color:#475569; }

.dev-metrics { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-bottom:12px; }
.dev-metric { background:#f5f7fa; border-radius:8px; padding:10px 12px; }
.dev-metric .label { font-size:11px; color:#6c7a92; margin-bottom:4px; line-height:1.3; }
.dev-metric .value { font-size:22px; font-weight:800; color:#1a2332; line-height:1.15; }
.dev-metric .unit  { font-size:12px; color:#6c7a92; font-weight:500; margin-left:3px; }

.dev-fault-info { padding:8px 10px; background:rgba(239,68,68,.08); border-left:3px solid #ef4444; border-radius:6px; font-size:12px; line-height:1.4; }
.dev-fault-info.alarm { background:rgba(249,115,22,.08); border-left-color:#f97316; }
.dev-fault-info .fault-name { font-weight:700; color:#b91c1c; font-size:13px; }
.dev-fault-info.alarm .fault-name { color:#c2410c; }
.dev-fault-info .fault-time { color:#6c7a92; font-size:11px; margin-top:3px; }

.dev-type-icon { font-size:16px; opacity:.7; }

/* Gauge-meter device cards (Inverter / Power Sensor) — ported from the
   sibling Power Energy project's meters.html (identical Tabler/vanilla-JS
   stack). Stripe/RUN-IDLE colors are driven by real device status here
   (green/amber/red/gray via the --c custom property set inline per card),
   not an arbitrary per-line color like the reference — these are 5
   identical inverters, not 6 distinct factory lines, so status is the
   meaningful signal. Light-mode colors match .dev-card/.dev-metric's
   existing palette; dark mode follows this file's established convention
   of hardcoded light defaults + an html.dark override block using the
   existing --color-* tokens (those tokens are only ever defined inside
   html.dark, not at :root — see the html.dark block below line ~309). */
.mc { background:#fff; border:1px solid #eef0f5; border-radius:20px; padding:24px 24px 20px;
  box-shadow:0 4px 18px rgba(40,60,90,.07); position:relative; overflow:hidden; transition:transform .15s, box-shadow .15s; }
.mc:hover { transform:translateY(-1px); box-shadow:0 6px 20px rgba(40,60,90,.12); }
.mc::before { content:""; position:absolute; left:0; top:0; bottom:0; width:6px; background:var(--c,#94a3b8); }
.mc-head { display:flex; align-items:center; gap:13px; margin-bottom:20px; }
.mc-head .ico { width:48px; height:48px; border-radius:13px; display:flex; align-items:center; justify-content:center;
  background:color-mix(in srgb, var(--c,#94a3b8) 18%, transparent); color:var(--c,#94a3b8); font-size:26px; flex-shrink:0; }
.mc-head .nm { font-weight:700; font-size:21px; line-height:1.2; color:#1a2332; }
.mc-head .sub { font-size:14px; color:#94a3b8; }
.mc-head .st { margin-left:auto; font-size:13px; font-weight:700; padding:5px 13px; border-radius:999px; letter-spacing:.5px; white-space:nowrap; }
.mc-head .st.run { background:rgba(34,197,94,.16); color:#16a34a; }
.mc-head .st.idle { background:rgba(148,163,184,.18); color:#64748b; }
.mc-main { display:flex; align-items:center; gap:22px; margin-bottom:20px; }
.mc .speedo { position:relative; width:210px; height:210px; flex:0 0 auto; }
.mc-read { flex:1; min-width:0; }
.mc .kwh-box { background:#f5f7fa; border:1px solid #eef0f5; border-radius:14px; padding:14px 17px; margin-bottom:15px; }
.mc .kwh-box .l { font-size:13px; color:#94a3b8; text-transform:uppercase; letter-spacing:.4px; }
.mc .kwh-box .v { font-size:34px; font-weight:700; color:var(--c,#206bc4); }
.mc .kwh-box .v small { font-size:15px; color:#94a3b8; font-weight:400; }
.mc .kwh-box .sub2 { font-size:13px; color:#6c7a92; margin-top:5px; }
.mc .rd-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px 18px; }
.mc .rd .l { font-size:13px; color:#94a3b8; text-transform:uppercase; letter-spacing:.4px; }
.mc .rd .v { font-size:24px; font-weight:600; color:#1a2332; }
.mc .rd .v small { font-size:13px; color:#94a3b8; font-weight:400; }
.mc .ph-wrap { border-top:1px dashed #eef0f5; padding-top:15px; }
.mc .ph-title { font-size:13px; font-weight:700; color:#94a3b8; text-transform:uppercase; letter-spacing:.5px; margin-bottom:11px; }
.mc .phases { display:grid; grid-template-columns:repeat(3,1fr); gap:11px; }
.mc .ph { text-align:center; background:#f5f7fa; border-radius:11px; padding:13px 8px; }
.mc .ph .pl { font-size:12px; color:#94a3b8; font-weight:800; letter-spacing:.3px; }
.mc .ph .pv { font-size:21px; font-weight:700; color:#1a2332; }
.mc .ph .pv small { font-size:12px; color:#94a3b8; font-weight:400; }
.mc .ph .pa { font-size:18px; color:#6c7a92; margin-top:3px; }

html.dark .mc { background:var(--color-surface) !important; border-color:var(--color-border) !important; box-shadow:0 4px 18px rgba(0,0,0,.45); }
html.dark .mc:hover { box-shadow:0 8px 24px rgba(0,0,0,.6); }
html.dark .mc-head .nm { color:var(--color-text); }
html.dark .mc-head .sub { color:var(--color-text-subtle); }
html.dark .mc .kwh-box { background:var(--color-surface-muted); border-color:var(--color-border-soft); }
html.dark .mc .kwh-box .l, html.dark .mc .kwh-box .v small, html.dark .mc .kwh-box .sub2 { color:var(--color-text-subtle); }
html.dark .mc .rd .l { color:var(--color-text-subtle); }
html.dark .mc .rd .v { color:var(--color-text); }
html.dark .mc .rd .v small { color:var(--color-text-subtle); }
html.dark .mc .ph-wrap { border-top-color:var(--color-border); }
html.dark .mc .ph-title { color:var(--color-text-subtle); }
html.dark .mc .ph { background:var(--color-surface-muted); }
html.dark .mc .ph .pl, html.dark .mc .ph .pv small { color:var(--color-text-subtle); }
html.dark .mc .ph .pv { color:var(--color-text); }
html.dark .mc .ph .pa { color:var(--color-text-muted); }

/* Custom Chart.js legend (DOM, not canvas-drawn) — click to toggle a line.
   Used where the chart runs with events:[] for the zoom-immune hover fix,
   which also blocks clicks on Chart.js's own canvas-drawn legend. */
.chart-legend-custom { display:flex; flex-wrap:wrap; justify-content:center; gap:14px; margin-bottom:8px; }
.chart-legend-item { display:inline-flex; align-items:center; gap:6px; font-size:11px; color:#6c7a92; cursor:pointer; user-select:none; }
.chart-legend-item:hover { color:#1a2332; }
.chart-legend-item.is-hidden { opacity:.4; text-decoration:line-through; }
.chart-legend-dot { width:10px; height:10px; border-radius:50%; flex-shrink:0; }
html.dark .chart-legend-item { color: var(--color-text-muted); }
html.dark .chart-legend-item:hover { color: var(--color-text); }

/* Fullscreen panel */
.panel-card.fs-active { position:fixed; inset:16px; z-index:1050; margin:0 !important; }
.panel-card.fs-active .card-body { height:100%; overflow:auto; }
body.fs-lock { overflow:hidden; }
.fs-backdrop { position:fixed; inset:0; background:rgba(0,0,0,.3); z-index:1040; }

/* Toggle switch (reports page) */
.toggle-switch { position:relative; display:inline-block; width:46px; height:24px; flex-shrink:0; }
.toggle-switch input { opacity:0; width:0; height:0; }
.toggle-switch .slider { position:absolute; cursor:pointer; inset:0; background:#cbd5e1; border-radius:24px; transition:.25s; }
.toggle-switch .slider:before { position:absolute; content:""; height:18px; width:18px; left:3px; bottom:3px; background:#fff; border-radius:50%; transition:.25s; box-shadow:0 2px 4px rgba(0,0,0,.15); }
.toggle-switch input:checked + .slider { background:#22c55e; }
.toggle-switch input:checked + .slider:before { transform:translateX(22px); }
.toggle-switch input:disabled + .slider { opacity:.5; cursor:not-allowed; }

/* Report channel cards */
.channel-card { border-top:3px solid transparent; }
.channel-card.channel-line      { border-top-color:#06c755; }
.channel-card.channel-telegram  { border-top-color:#2ca5e0; }
.channel-card.channel-email     { border-top-color:#ea4335; }

/* Alarms page — bar-list for top symptoms */
.bar-list .bar-row { display:grid; grid-template-columns:1fr auto; gap:6px 12px; align-items:center; padding:6px 0; border-bottom:1px solid #eef0f5; }
.bar-list .bar-row:last-child { border-bottom:0; }
.bar-list .bar-name { font-size:0.95rem; color:#1a2332; font-weight:500; }
.bar-list .bar-count { font-weight:700; color:#ef4444; }
.bar-list .bar-meter { grid-column:1 / -1; height:6px; background:#eef0f5; border-radius:3px; overflow:hidden; }
.bar-list .bar-meter > div { height:100%; background:linear-gradient(90deg,#f87171,#ef4444); border-radius:3px; }

/* Energy flow diagram (dashboard performance card) */
.flow-container { position:relative; width:90%; margin:0 auto; background:#fff; border-radius:14px; padding:10px; box-shadow:0 2px 10px rgba(40,60,90,.08); }
.flow-img { width:100%; height:auto; object-fit:contain; display:block; border-radius:8px; }

/* Glowing dot that travels the loop — only shown while producing */
.flow-dot {
  position:absolute; width:14px; height:14px; border-radius:50%;
  background:radial-gradient(circle, #fff 20%, #f59e0b 70%);
  box-shadow:0 0 12px #f59e0b, 0 0 4px #fff inset;
  transform:translate(-50%, -50%); pointer-events:none; display:none; z-index:2;
}
.flow-container.producing .flow-dot { display:block; }

/* Grid-side dot — separate color/path, always on (grid-tied system, always
   connected regardless of PV output; no real-time meter to gate it on/off) */
.flow-dot-grid {
  position:absolute; width:14px; height:14px; border-radius:50%;
  background:radial-gradient(circle, #fff 20%, #206bc4 70%);
  box-shadow:0 0 12px #206bc4, 0 0 4px #fff inset;
  transform:translate(-50%, -50%); pointer-events:none; z-index:2;
}

/* Small pencil icon, top-right, appears on hover — links to the path editor */
.flow-edit-link {
  position:absolute; top:4px; right:4px; width:30px; height:30px;
  display:flex; align-items:center; justify-content:center;
  background:rgba(255,255,255,0.7); border-radius:50%; color:#6c7a92;
  opacity:0; transition:opacity .2s; text-decoration:none; z-index:3;
}
.flow-container:hover .flow-edit-link { opacity:1; }
.flow-edit-link:hover { background:#206bc4; color:#fff; }
html.dark .flow-edit-link { background: rgba(30,41,59,.75); color: var(--color-text); }
html.dark .flow-edit-link:hover { background: var(--color-primary); color: #fff; }

/* Revenue readout — overlaid on an empty area of the artwork */
.flow-revenue {
  position:absolute; left:42%; bottom:2%;
  transform:translateX(-50%); z-index:3;
  white-space:nowrap; pointer-events:none; text-align:center;
}
.flow-revenue-label { font-size:0.9rem; color:#6c7a92; line-height:1.1; margin-bottom:2px; }
.flow-revenue-value { font-size:1.85rem; font-weight:700; color:#22c55e; line-height:1.1; }

/* Per-node power readouts (PV output / load consumption / grid power) —
   overlaid near each icon in the artwork, eyeballed against plant-solar.png. */
.flow-power {
  position:absolute; z-index:3; text-align:center;
  white-space:nowrap; pointer-events:none; transform:translateX(-50%);
}
.flow-power-value { font-size:1rem; font-weight:700; color:#1a2332; line-height:1.15; }
.flow-power-unit { font-size:0.7rem; font-weight:500; color:#6c7a92; }
.flow-power-label { font-size:0.68rem; color:#6c7a92; line-height:1.1; margin-top:1px; }
.flow-power-pv   { left:68%; top:1%; }
.flow-power-load { left:9%;  top:37%; }
.flow-power-grid { left:78%; top:44%; }
html.dark .flow-power-value { color: var(--color-text); }
html.dark .flow-power-unit, html.dark .flow-power-label { color: var(--color-text-muted); }

/* ============================================================
   Night mode (dark theme) — toggle via html.dark class. Runtime in js/theme.js.
   ============================================================ */

.theme-toggle {
  position: relative; width: 52px; height: 30px;
  border: 1px solid #e2e8f0; background: #f8fafc; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: space-between; padding: 0 7px;
  transition: background-color .22s ease, border-color .22s ease;
  vertical-align: middle; flex-shrink: 0;
}
.theme-toggle i { font-size: 14px; transition: opacity .22s, color .22s; z-index: 1; }
.theme-toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px;
  background: linear-gradient(135deg,#fff,#e2e8f0); border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  transition: transform .22s cubic-bezier(.2,.8,.3,1), background .22s;
}
.theme-toggle .theme-icon-moon { opacity: .35; color: #6c7a92; }
.theme-toggle .theme-icon-sun  { opacity: 1;   color: #f59e0b; }
html.dark .theme-toggle { background: #1f2937; border-color: #374151; }
html.dark .theme-toggle::after { transform: translateX(22px); background: linear-gradient(135deg, #334155, #0f172a); }
html.dark .theme-toggle .theme-icon-sun  { opacity: .35; color: #93a4c0; }
html.dark .theme-toggle .theme-icon-moon { opacity: 1;   color: #a5b4fc; }
.theme-toggle-fixed { position: fixed; top: 14px; right: 14px; z-index: 9999; }

html.dark {
  --color-bg: #0b1020; --color-surface: #121a2e; --color-surface-muted: #0f172a;
  --color-surface-alt: #1e293b; --color-border: #243049; --color-border-soft: #1e293b;
  --color-text: #e6edf7; --color-text-muted: #93a4c0; --color-text-subtle: #64748b;
  --color-primary: #3b82f6; --color-primary-600: #60a5fa;
  color-scheme: dark;
}

html.dark, html.dark body { background: var(--color-bg); }
html.dark body, html.dark .page, html.dark .page-body, html.dark .page-wrapper { background: var(--color-bg) !important; color: var(--color-text); }

html.dark .card, html.dark .dev-card, html.dark .inv-filter-bar, html.dark .login-card {
  background: var(--color-surface) !important; border-color: var(--color-border) !important;
  color: var(--color-text); box-shadow: 0 4px 18px rgba(0,0,0,.45);
}
html.dark .card:hover, html.dark .dev-card:hover { box-shadow: 0 8px 24px rgba(0,0,0,.6); }

html.dark .navbar-vertical { background: var(--color-surface) !important; border-right-color: var(--color-border) !important; }
html.dark .navbar-vertical .nav-link { color: var(--color-text-muted); }
html.dark .navbar-vertical .nav-link:hover { background: var(--color-surface-alt); color: var(--color-text); }
html.dark .navbar-vertical .nav-item.active .nav-link { background: rgba(59,130,246,.15) !important; color: var(--color-primary-600) !important; }
html.dark .navbar-vertical .nav-item.active::before { background: var(--color-primary-600); }
html.dark .navbar-brand, html.dark .navbar-brand .text-dark, html.dark .navbar-brand span { color: var(--color-text) !important; }
html.dark .sidebar-footer { border-top-color: var(--color-border); }

html.dark header.navbar-light { background: var(--color-surface) !important; border-bottom: 1px solid var(--color-border); }
html.dark .navbar-light .navbar-nav .nav-link, html.dark .navbar-light .nav-link { color: var(--color-text); }
html.dark .nav-user-name { color: var(--color-text); }
html.dark .nav-user-role { color: var(--color-text-muted) !important; }
html.dark .dropdown-menu { background: var(--color-surface); border-color: var(--color-border); color: var(--color-text); box-shadow: 0 10px 30px rgba(0,0,0,.5); }
html.dark .dropdown-item { color: var(--color-text); }
html.dark .dropdown-item:hover, html.dark .dropdown-item:focus { background: var(--color-surface-alt); color: var(--color-text); }
html.dark .dropdown-divider { border-top-color: var(--color-border); }

html.dark .page-header, html.dark .page-title,
html.dark h1, html.dark h2, html.dark h3, html.dark h4, html.dark h5,
html.dark .h1, html.dark .h2, html.dark .h3, html.dark .h4, html.dark .h5 { color: var(--color-text); }
html.dark .page-pretitle { color: var(--color-text-muted); }
html.dark .text-muted, html.dark .card-subtitle, html.dark .small, html.dark small { color: var(--color-text-muted) !important; }
html.dark .card-title { color: var(--color-text); }
html.dark .text-dark { color: var(--color-text) !important; }

html.dark .gauge-card .gauge-value { color: var(--color-text); }
html.dark .gauge-card .gauge-title, html.dark .gauge-card .gauge-sub { color: var(--color-text-muted); }

html.dark .summary-box { background: var(--color-surface-muted) !important; color: var(--color-text); }
html.dark .dual-progress, html.dark .single-progress { background: var(--color-surface-alt); }

html.dark .tab-group { background: var(--color-surface-muted); }
html.dark .tab-btn { color: var(--color-text-muted); }
html.dark .tab-btn.active { background: var(--color-primary); color: #fff; box-shadow: 0 2px 6px rgba(59,130,246,.35); }

html.dark .date-label-clickable { background: rgba(59,130,246,.18); color: var(--color-primary-600); }
html.dark .date-picker-wrap:hover .date-label-clickable { background: rgba(59,130,246,.28); }

html.dark table { color: var(--color-text); }
html.dark .card-table thead th { background: var(--color-surface-muted); color: var(--color-text-muted); border-bottom-color: var(--color-border); }
html.dark .table { --tblr-table-bg: transparent; --tblr-table-color: var(--color-text); color: var(--color-text); }
html.dark .table > :not(caption) > * > * { background-color: transparent !important; color: var(--color-text); border-bottom-color: var(--color-border-soft); }
html.dark .table-hover > tbody > tr:hover > * { background-color: var(--color-surface-alt) !important; color: var(--color-text) !important; }

html.dark .form-control, html.dark .form-select { background: var(--color-surface-muted); border-color: var(--color-border); color: var(--color-text); }
html.dark .form-control:focus, html.dark .form-select:focus { background: var(--color-surface-muted); border-color: var(--color-primary); color: var(--color-text); box-shadow: 0 0 0 3px rgba(59,130,246,.25); }
html.dark .form-control::placeholder { color: var(--color-text-subtle); }
html.dark .form-label { color: var(--color-text); }
html.dark .input-group-text { background: var(--color-surface-alt); border-color: var(--color-border); color: var(--color-text-muted); }

html.dark .btn-light { background: var(--color-surface-muted); color: var(--color-text); border-color: var(--color-border); }
html.dark .btn-light:hover { background: var(--color-surface-alt); color: var(--color-text); }
html.dark .btn-outline-secondary { color: var(--color-text-muted); border-color: var(--color-border); }
html.dark .btn-outline-secondary:hover { background: var(--color-surface-alt); color: var(--color-text); border-color: var(--color-border); }
html.dark .btn-link { color: var(--color-primary-600); }

html.dark .dev-card .dev-name { color: var(--color-text); }
html.dark .dev-card .dev-sn { color: var(--color-text-muted); }
html.dark .dev-metric { background: var(--color-surface-muted); }
html.dark .dev-metric .label { color: var(--color-text-muted); }
html.dark .dev-metric .value { color: var(--color-text); }
html.dark .dev-metric .unit  { color: var(--color-text-muted); }
html.dark .dev-fault-info { background: rgba(239,68,68,.12); }
html.dark .dev-fault-info.alarm { background: rgba(249,115,22,.12); }

html.dark .bar-list .bar-row { border-bottom-color: var(--color-border-soft); }
html.dark .bar-list .bar-name { color: var(--color-text); }
html.dark .bar-list .bar-meter { background: var(--color-surface-alt); }

html.dark .channel-card { background: var(--color-surface) !important; }
html.dark .flow-container { background: transparent; box-shadow: none; }
html.dark .flow-revenue-label { color: var(--color-text-muted); }
html.dark .weather-card { background: linear-gradient(135deg,#1565c0 0%, #0b2545 100%); }
html.dark .toggle-switch .slider { background: var(--color-surface-alt); }
html.dark .toggle-switch .slider:before { background: #e6edf7; }

html.dark .badge.bg-green-lt  { background: rgba(34,197,94,.18) !important;  color: #86efac !important; }
html.dark .badge.bg-red-lt    { background: rgba(239,68,68,.18) !important;  color: #fca5a5 !important; }
html.dark .badge.bg-orange-lt { background: rgba(249,115,22,.18) !important; color: #fdba74 !important; }
html.dark .badge.bg-yellow-lt { background: rgba(245,158,11,.18) !important; color: #fcd34d !important; }
html.dark .badge.bg-blue-lt   { background: rgba(59,130,246,.18) !important; color: #93c5fd !important; }

html.dark .apexcharts-tooltip, html.dark .apexcharts-tooltip.apexcharts-theme-light {
  background: var(--color-surface) !important; border: 1px solid var(--color-border) !important;
  color: var(--color-text) !important; box-shadow: 0 6px 18px rgba(0,0,0,.6) !important;
}
html.dark .apexcharts-tooltip-title { background: var(--color-surface-muted) !important; border-bottom-color: var(--color-border) !important; color: var(--color-text) !important; }
html.dark .apexcharts-xaxistooltip, html.dark .apexcharts-yaxistooltip { background: var(--color-surface) !important; border-color: var(--color-border) !important; color: var(--color-text) !important; }
html.dark .apexcharts-xaxis-label, html.dark .apexcharts-yaxis-label, html.dark .apexcharts-text tspan { fill: var(--color-text-muted) !important; }
html.dark .apexcharts-datalabel-value { fill: var(--color-text) !important; }
html.dark .apexcharts-gridline, html.dark .apexcharts-grid line { stroke: var(--color-border-soft) !important; }
html.dark .apexcharts-legend-text { color: var(--color-text-muted) !important; }

html.dark ::-webkit-scrollbar { width: 10px; height: 10px; }
html.dark ::-webkit-scrollbar-track { background: var(--color-bg); }
html.dark ::-webkit-scrollbar-thumb { background: var(--color-surface-alt); border-radius: 5px; }
html.dark ::-webkit-scrollbar-thumb:hover { background: var(--color-border); }

html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after {
  transition: background-color .25s ease, color .25s ease, border-color .25s ease, fill .25s ease, stroke .25s ease !important;
}

/* Print (window.print(), used by alarms.html's "Export PDF") — hide chrome that
   isn't part of the report itself: sidebar nav, toolbar controls, AI chat FAB/panel.
   Without this, the sidebar's reserved width steals horizontal space from the
   printed page, which pushes Bootstrap's row-cols-md-* grids below their column
   breakpoint and collapses KPI cards to a single stacked column. */
@media print {
  .navbar-vertical, .inv-filter-bar, #gemini-chat-fab, #gemini-chat-panel { display: none !important; }
  .page-wrapper { margin-left: 0 !important; }
  .row-cols-md-2 > * { width: 50% !important; }
  .row-cols-md-3 > * { width: 33.3333% !important; }
  .row-cols-md-4 > * { width: 25% !important; }
}
