:root {
  --bg: #f5f7fb; --panel: #ffffff; --panel2: #f1f5f9; --border: #e8ecf3; --border-strong: #dbe1ea;
  --text: #0f172a; --text2: #334155; --muted: #64748b; --muted2: #94a3b8;
  --accent: #2563eb; --accent-soft: #eaf1ff; --accent2: #7c3aed;
  --ok: #16a34a; --ok-soft: #dcfce7;
  --low: #2563eb; --low-soft: #dbeafe;
  --medium: #b45309; --medium-soft: #fef3c7;
  --high: #c2410c; --high-soft: #ffedd5;
  --critical: #dc2626; --critical-soft: #fee2e2;
  --info: #475569; --info-soft: #eef2f7;
  --sauter: #2f6fed; --honeywell: #e4002b; --schneider: #16a34a;
  --radius: 12px; --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.04), 0 1px 3px rgba(15,23,42,.05);
  --shadow: 0 4px 14px rgba(15,23,42,.06);
  --shadow-lg: 0 14px 38px rgba(15,23,42,.14);
}
/* dark theme (per-user preference) — overrides the neutral palette */
html[data-theme="dark"] {
  --bg: #0b1220; --panel: #131c2e; --panel2: #1b2740; --border: #243049; --border-strong: #30405e;
  --text: #e8eef7; --text2: #c3cee0; --muted: #94a3b8; --muted2: #6b7a93;
  --accent-soft: #16233c; --info-soft: #1b2740;
  --ok-soft: #13321e; --low-soft: #16243f; --medium-soft: #33270f; --high-soft: #3a2410; --critical-soft: #3a1717;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.35); --shadow: 0 4px 14px rgba(0,0,0,.4); --shadow-lg: 0 14px 38px rgba(0,0,0,.55);
}
html[data-theme="dark"] .topbar { background: rgba(13,20,34,.92); }
html[data-theme="dark"] select, html[data-theme="dark"] input { background: #0f1828; }
html[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #2d3a55; border-color: var(--bg); }
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text); touch-action: manipulation;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cdd5e1; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #b3bdcc; }

/* ── header ── */
header.top {
  display: flex; align-items: center; gap: 14px; padding: 12px 24px;
  border-bottom: 1px solid var(--border); background: rgba(255,255,255,.9); backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm); position: sticky; top: 0; z-index: 20;
}
.logo { font-weight: 800; font-size: 18px; letter-spacing: -.3px; }
.logo b { color: var(--accent); }
.logo small { color: var(--muted); font-weight: 500; font-size: 12px; margin-left: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted2); display: inline-block; margin-right: 6px; }
.status-dot.live { background: var(--ok); box-shadow: 0 0 0 3px rgba(22,163,74,.18); }
.spacer { flex: 1; }
.conn { color: var(--muted); font-size: 12px; }

/* ── app shell (sidebar layout) ── */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 244px; flex-shrink: 0; background: #0f1729; color: #cbd5e1; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 18px 20px; font-weight: 800; font-size: 18px; color: #fff; display: flex; align-items: center; gap: 11px; letter-spacing: -.3px; }
.brand .mark { width: 30px; height: 30px; flex: none; display: flex; align-items: center; justify-content: center; }
.brand .mark svg { width: 100%; height: 100%; display: block; border-radius: 8px; }
.brand-co { padding: 0 20px 14px 59px; margin-top: -12px; font-size: 12px; font-weight: 500; color: #93a1b8; letter-spacing: .2px; }
.side-nav { flex: 1; overflow-y: auto; padding: 6px 12px 12px; }
.side-nav::-webkit-scrollbar-thumb { background: #334155; border-color: #0f1729; }
.nav-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .7px; color: #5b6b85; font-weight: 700; padding: 16px 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 8px; color: #c2ccdb; font-size: 13.5px; font-weight: 500; cursor: pointer; margin-bottom: 2px; transition: background .12s, color .12s; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 600; box-shadow: 0 4px 12px rgba(37,99,235,.35); }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.nav-item.active svg { opacity: 1; }
/* Alarms & FDD — red to flag it as the alerts section */
.nav-item[data-tab="alarms"] { color: #f87171; }
.nav-item[data-tab="alarms"] svg { opacity: 1; }
.nav-item[data-tab="alarms"]:hover { color: #fca5a5; background: rgba(220,38,38,.14); }
.nav-item[data-tab="alarms"].active { background: var(--critical); color: #fff; box-shadow: 0 4px 12px rgba(220,38,38,.4); }
/* nested (expandable) nav items */
.nav-parent-head { display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 8px; color: #c2ccdb; font-size: 13.5px; font-weight: 500; cursor: pointer; margin-bottom: 2px; transition: background .12s, color .12s; }
.nav-parent-head:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-parent-head.active { color: #fff; }
.nav-parent-head svg:not(.nav-chev) { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.nav-chev { width: 15px; height: 15px; margin-left: auto; opacity: .6; transition: transform .15s; }
.nav-parent.expanded .nav-chev { transform: rotate(90deg); }
.nav-children { display: none; margin: 2px 0 4px 14px; padding-left: 9px; border-left: 1px solid rgba(255,255,255,.09); }
.nav-parent.expanded .nav-children { display: block; }
.nav-item.nav-child { padding: 7px 10px; font-size: 12.5px; color: #9aa7bd; gap: 8px; }
.nav-item.nav-child:hover { color: #fff; }
.nav-item.nav-child.active { background: var(--accent); color: #fff; box-shadow: none; }
.side-foot { padding: 13px 20px; font-size: 11.5px; color: #5b6b85; border-top: 1px solid rgba(255,255,255,.07); }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 13px 24px; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.page-title { font-size: 20px; font-weight: 800; letter-spacing: -.4px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border: 1px solid var(--border-strong); border-radius: 999px; font-size: 12.5px; font-weight: 600; color: var(--text2); cursor: pointer; transition: border-color .12s; }
.user-chip:hover { border-color: var(--accent); }
.user-chip .avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
.content { flex: 1; padding: 22px 24px 40px; }

/* ── KPI strip ── */
.kpis { display: grid; grid-template-columns: repeat(8, 1fr); gap: 12px; padding: 0 0 18px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm); transition: transform .12s, box-shadow .12s, border-color .12s; }
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--border-strong); }
.kpi .v { font-size: 24px; font-weight: 800; color: #0b1220; letter-spacing: -.5px; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; margin-top: 5px; }

/* ── nav ── */
nav.tabs { display: flex; gap: 2px; padding: 6px 16px 0; border-bottom: 1px solid var(--border); background: transparent; overflow-x: auto; }
nav.tabs button {
  background: none; border: none; color: var(--muted); padding: 11px 15px; cursor: pointer; white-space: nowrap;
  font-size: 13.5px; font-weight: 600; font-family: inherit; border-bottom: 2px solid transparent; border-radius: 8px 8px 0 0; transition: .12s;
}
nav.tabs button:hover { color: var(--text); background: var(--panel2); }
nav.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

main { padding: 20px 24px 40px; }
section.tab { display: none; animation: fade .2s ease; }
section.tab.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.grid2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.panel h3 { margin: 0 0 14px; font-size: 14px; font-weight: 700; letter-spacing: -.2px; }
.panel h3 small { color: var(--muted); font-weight: 500; }

/* ── site cards ── */
.sites { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.site-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); transition: transform .12s, box-shadow .12s, border-color .12s; }
.site-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }
.site-card .name { font-weight: 700; font-size: 15px; letter-spacing: -.2px; }
.site-card .addr { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.row { display: flex; justify-content: space-between; align-items: center; margin: 5px 0; font-size: 13px; }
.row .muted { color: var(--muted); }

/* ── badges / pills / severities ── */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; color: #fff; letter-spacing: .2px; }
.badge.sauter { background: var(--sauter); } .badge.honeywell { background: var(--honeywell); } .badge.schneider { background: var(--schneider); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 7px; font-size: 11px; font-weight: 600; border: 1px solid var(--border-strong); color: var(--muted); background: var(--panel2); }
.sev { padding: 2px 9px; border-radius: 7px; font-size: 11px; font-weight: 700; letter-spacing: .2px; }
.sev.low { background: var(--low-soft); color: #1d4ed8; }
.sev.medium { background: var(--medium-soft); color: var(--medium); }
.sev.high { background: var(--high-soft); color: var(--high); }
.sev.critical { background: var(--critical-soft); color: var(--critical); }
.sev.info { background: var(--info-soft); color: var(--info); }

/* ── live monitor: active-alerts panel ── */
#liveAlerts { max-height: 46vh; overflow-y: auto; }
.live-alert { border: 1px solid var(--border); border-left: 3px solid var(--medium); border-radius: 9px; padding: 10px 12px; margin-bottom: 9px; background: var(--panel2); }
.live-alert:last-child { margin-bottom: 0; }
.live-alert .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.live-alert.sev-border-critical { border-left-color: var(--critical); }
.live-alert.sev-border-high { border-left-color: var(--high); }
.live-alert.sev-border-medium { border-left-color: var(--medium); }
.live-alert.sev-border-low { border-left-color: var(--low); }
.live-alert.sev-border-info { border-left-color: var(--low); }

/* occupancy schedule editable cells */
.sched-cell { display: inline-flex; align-items: center; gap: 6px; }
.sched-cell input[type="number"] { width: 60px; padding: 5px 8px; text-align: center; }

/* settings hub cards + settings forms */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.settings-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; cursor: pointer; transition: transform .12s, box-shadow .12s, border-color .12s; box-shadow: var(--shadow-sm); }
.settings-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }
.sc-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.sc-icon svg { width: 20px; height: 20px; }
.sc-title { font-weight: 600; font-size: 14.5px; margin-bottom: 3px; }
.sc-desc { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.form-grid { display: grid; grid-template-columns: 270px 1fr; gap: 11px 18px; align-items: center; max-width: 660px; }
.form-grid label { color: var(--text2); font-size: 13px; }
.form-grid input, .form-grid select { width: 100%; max-width: 320px; }

/* OT transport chips (connectors) */
.tp { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text2); background: var(--panel2); white-space: nowrap; }
.tp-5g { color: #fff; background: linear-gradient(135deg, #2563eb, #7c3aed); border-color: transparent; box-shadow: 0 2px 6px rgba(124,58,237,.3); }
.tp-cell { color: #6d28d9; background: #ede9fe; border-color: #ddd6fe; }
.tp-wifi { color: #0d9488; background: #ccfbf1; border-color: #99f6e4; }
.tp-ser { color: #b45309; background: #fef3c7; border-color: #fde68a; }
.tp-eth { color: var(--muted); background: var(--panel2); }

/* ── tables ── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
tbody tr { transition: background .1s; }
tr:hover td { background: var(--panel2); }
.val { font-variant-numeric: tabular-nums; font-weight: 700; }
.flash { animation: flash .9s ease-out; }
@keyframes flash { from { background: rgba(37,99,235,.16); } to { background: transparent; } }
.mono { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace; font-size: 12px; color: var(--muted); }
.arrow { color: var(--accent2); margin: 0 6px; }

/* ── equipment tree ── */
.tree { max-height: 70vh; overflow: auto; }
.tree .site { font-weight: 700; margin: 12px 0 4px; font-size: 12px; color: var(--text2); text-transform: uppercase; letter-spacing: .4px; }
.tree .equip { padding: 7px 10px; border-radius: 8px; cursor: pointer; color: var(--text); display: flex; justify-content: space-between; align-items: center; transition: .1s; }
.tree .equip:hover { background: var(--panel2); }
.tree .equip.active { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.tree .equip .et { color: var(--muted); font-size: 11px; }
.tree .equip.active .et { color: #dbe7ff; }
.points-wrap { max-height: 70vh; overflow: auto; }

.tagchip { display: inline-block; background: var(--accent-soft); border: 1px solid #d7e3ff; color: #3257b0; border-radius: 6px; padding: 0 7px; font-size: 11px; margin: 1px; font-weight: 500; }
.controls { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }

/* ── form controls ── */
select, input { background: #fff; color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 7px 11px; font-size: 13px; font-family: inherit; transition: border-color .12s, box-shadow .12s; }
select:focus, input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
button.act { background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm); padding: 7px 13px; cursor: pointer; font-weight: 600; font-size: 12.5px; font-family: inherit; transition: filter .12s, transform .08s; }
button.act:hover { filter: brightness(1.07); }
button.act:active { transform: translateY(1px); }
a.act { text-decoration: none; display: inline-block; }
.empty { color: var(--muted); padding: 22px; text-align: center; }
canvas { max-height: 260px; }
.chart-fill { flex: 1; position: relative; min-height: 300px; }
.chart-fill canvas { max-height: none !important; height: 100% !important; }
.grade { font-weight: 800; font-size: 14px; padding: 1px 9px; border-radius: 7px; color: #fff; }
.grade.A { background: #16a34a; } .grade.B { background: #65a30d; } .grade.C { background: #d97706; } .grade.D { background: #ea580c; } .grade.F { background: #dc2626; }

/* ── header bell + search + popups ── */
.bell { position: relative; cursor: pointer; padding: 6px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel); transition: .12s; }
.bell:hover { color: var(--text); border-color: var(--accent); }
.bell-badge { background: var(--critical); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 10px; font-weight: 700; margin-left: 4px; }
.bell-badge.zero { background: var(--muted2); }
.notif-pop { position: absolute; top: 52px; right: 24px; width: 350px; max-height: 60vh; overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 8px; z-index: 40; }
.notif-item { padding: 9px; border-bottom: 1px solid var(--border); font-size: 13px; cursor: pointer; border-radius: 6px; }
.notif-item:hover { background: var(--panel2); }
.search-pop { position: absolute; top: 40px; left: 0; width: 100%; max-height: 62vh; overflow: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 40; }
.search-pop .grp { font-size: 10.5px; color: var(--muted2); text-transform: uppercase; letter-spacing: .5px; font-weight: 700; padding: 8px 8px 3px; }
.search-pop .res { padding: 8px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.search-pop .res:hover { background: var(--panel2); }

/* ── building diagram ── */
.diagram-flow { display: flex; align-items: stretch; gap: 14px; }
.diag-col { flex: 1; background: var(--panel2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.diag-col-h { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 12px; }
.diag-nodes { display: flex; flex-wrap: wrap; gap: 10px; }
.diag-node { position: relative; width: 124px; background: var(--panel); border: 1px solid var(--border); border-radius: 11px; padding: 14px 8px 11px; text-align: center; cursor: pointer; transition: transform .12s, box-shadow .12s, border-color .12s; box-shadow: var(--shadow-sm); }
.diag-node:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }
.diag-icon { width: 46px; height: 46px; margin: 0 auto 9px; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
.diag-icon svg { width: 24px; height: 24px; }
.diag-node.plant .diag-icon { background: #dbeafe; color: #1d4ed8; }
.diag-node.air .diag-icon { background: #ccfbf1; color: #0d9488; }
.diag-node.zones .diag-icon { background: #fef3c7; color: #b45309; }
.diag-node.meter .diag-icon { background: #ede9fe; color: #6d28d9; }
.diag-node.fire .diag-icon { background: #fee2e2; color: #dc2626; }
.diag-node.water .diag-icon { background: #e0f2fe; color: #0284c7; }
.diag-node.security .diag-icon { background: #e0e7ff; color: #4f46e5; }
.diag-node.power .diag-icon { background: #ffedd5; color: #ea580c; }
.diag-node.env .diag-icon { background: #dcfce7; color: #15803d; }
.diag-node.transport .diag-icon { background: #e2e8f0; color: #475569; }
.diag-name { font-size: 12.5px; font-weight: 600; line-height: 1.25; }
.diag-type { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; margin-top: 2px; }
.diag-alarm { position: absolute; top: 8px; right: 8px; background: var(--high); color: #fff; border-radius: 999px; min-width: 18px; height: 18px; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 5px; }
.diag-ok { position: absolute; top: 11px; right: 11px; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.diag-arrow { display: flex; align-items: center; color: var(--muted2); }
.diag-arrow svg { width: 24px; height: 24px; }
@media (max-width: 1000px) { .diagram-flow { flex-direction: column; } .diag-arrow { transform: rotate(90deg); align-self: center; } }

/* ── per-element schematic modal ── */
.modal.schem-modal { width: min(1300px, 96vw); height: 88vh; max-height: 88vh; display: flex; flex-direction: column; overflow: hidden; }
.schem-modal .modal-head { flex: 0 0 auto; }
.schem-modal .modal-foot { flex: 0 0 auto; }
.schem-modal .modal-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.schem-modal .modal-head h3 { font-size: 20px; }
.schem-modal .modal-head .et { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: capitalize; margin-left: 4px; }
.schem-meta { flex: 0 0 auto; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.schem-alarmbar { flex: 0 0 auto; }
.schem-canvas { flex: 1; min-height: 0; background: var(--panel2); background-image: radial-gradient(circle, var(--border-strong) 1px, transparent 1px); background-size: 24px 24px; border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; display: flex; align-items: center; justify-content: center; overflow: auto; }
.schem-canvas > .schem-grid { width: 100%; align-self: flex-start; }
.schem-svg { width: 100%; height: 100%; display: block; overflow: visible; }
.schem-svg .s-body { fill: var(--panel); stroke: var(--border-strong); stroke-width: 2.2; }
.schem-svg .s-line { fill: none; stroke: var(--muted2); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.schem-svg .s-cool { fill: rgba(37,99,235,.10); stroke: #2563eb; stroke-width: 1.8; }
.schem-svg .s-warm { fill: rgba(220,38,38,.10); stroke: #dc2626; stroke-width: 1.8; }
.schem-svg .s-water { fill: rgba(2,132,199,.14); stroke: #0284c7; stroke-width: 2.2; }
.schem-svg .s-cap { fill: var(--muted); font-size: 11.5px; font-weight: 600; letter-spacing: .5px; text-transform: uppercase; font-family: inherit; }
.schem-chip rect { fill: var(--panel); stroke: var(--border-strong); stroke-width: 1.4; filter: drop-shadow(0 2px 3px rgba(15,23,42,.10)); }
.schem-chip.alarm { cursor: help; }
.schem-dot { fill: var(--critical); stroke: #fff; stroke-width: 1.6; animation: schemPulse 1.3s ease-in-out infinite; }
@keyframes schemPulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
.schem-alarmbar { display: none; gap: 7px; flex-wrap: wrap; margin: 0 0 10px; }
.schem-alarm-pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 5px 12px; font-size: 12px; font-weight: 600; cursor: pointer; max-width: 100%; border: 1px solid; transition: filter .12s; }
.schem-alarm-pill:hover { filter: brightness(.94); }
.schem-alarm-pill .tx { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 360px; }
.schem-alarm-pill.sevp-critical { background: var(--critical-soft); color: var(--critical); border-color: var(--critical); }
.schem-alarm-pill.sevp-high { background: var(--high-soft); color: var(--high); border-color: var(--high); }
.schem-alarm-pill.sevp-medium { background: var(--medium-soft); color: var(--medium); border-color: var(--medium); }
.schem-alarm-pill.sevp-low, .schem-alarm-pill.sevp-info { background: var(--low-soft); color: var(--low); border-color: var(--low); }
.diag-node.has-alarm { border-color: var(--high); box-shadow: 0 0 0 1px var(--high), var(--shadow-sm); }
.schem-chip .sc-l { fill: var(--muted); font-size: 9.5px; font-weight: 600; letter-spacing: .35px; text-transform: uppercase; font-family: inherit; }
.schem-chip .sc-v { fill: var(--text); font-size: 14.5px; font-weight: 700; font-family: inherit; }
html[data-theme="dark"] .schem-chip rect { filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); }
.schem-chip.on rect { stroke: var(--ok); } .schem-chip.on .sc-v { fill: var(--ok); }
.schem-chip.alarm rect { stroke: var(--critical); fill: var(--critical-soft); } .schem-chip.alarm .sc-v { fill: var(--critical); }
.schem-chip.off .sc-v { fill: var(--muted); }
.schem-chip.na .sc-v, .schem-chip.na .sc-l { opacity: .42; }
.schem-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.schem-cell { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--panel); }
.schem-cell .sc-l { font-size: 11px; color: var(--muted); }
.schem-cell .sc-v { font-size: 15px; font-weight: 700; color: var(--text); margin-top: 2px; }
.schem-cell.on .sc-v { color: var(--ok); }
.schem-cell.alarm { border-color: var(--critical); } .schem-cell.alarm .sc-v { color: var(--critical); }

/* ── edge gateway installer panel ── */
.edge-block { margin: 12px 0; }
.edge-h { font-size: 12.5px; font-weight: 600; color: var(--text2); margin-bottom: 5px; }
.edge-cmd { display: flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.edge-cmd code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--text); overflow-x: auto; white-space: nowrap; flex: 1; }
.edge-cmd button, .edge-cmd a { flex: none; }
.diag-legend { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.diag-legend-h { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 9px; }
.diag-legend-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 7px 22px; font-size: 13px; color: var(--text); }
.diag-legend-grid > div { display: flex; align-items: center; }
.diag-legend-grid b { font-weight: 700; }

/* ── modal / popup ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 80; display: flex; align-items: center; justify-content: center; animation: fade .15s ease; }
.modal { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 430px; max-width: 92vw; max-height: 88vh; overflow: auto; animation: pop .16s ease; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.modal-x { cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; padding: 4px; }
.modal-x:hover { color: var(--text); }
.modal-body { padding: 14px 18px; }
.modal-body label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin: 11px 0 4px; }
.modal-body input, .modal-body select { width: 100%; }
.modal-msg { color: var(--critical); font-size: 12.5px; min-height: 16px; margin-top: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--border); }
button.act.ghost { background: var(--panel2); color: var(--text2); }
button.act.ghost:hover { background: var(--border); }

/* ── toasts ── */
.toast-wrap { position: fixed; bottom: 22px; right: 22px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg); transition: opacity .3s, transform .3s; max-width: 340px; }
.toast.error { background: var(--critical); } .toast.ok { background: var(--ok); }

/* ── responsive / mobile ─────────────────────────────────────────────── */
.menu-btn { display: none; align-items: center; justify-content: center; width: 38px; height: 38px; flex-shrink: 0; background: var(--panel2); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); color: var(--text2); cursor: pointer; padding: 0; }
.menu-btn svg { width: 20px; height: 20px; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(8, 13, 24, .55); z-index: 88; opacity: 0; transition: opacity .18s; }
.sidebar-overlay.show { display: block; opacity: 1; }
.sidebar .side-close { display: none; margin-left: auto; background: none; border: none; color: #93a1b8; font-size: 22px; line-height: 1; cursor: pointer; padding: 2px 6px; }
.bottom-nav { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 80; background: #0f1729; border-top: 1px solid rgba(255,255,255,.08); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
.bnav-item { display: flex; flex-direction: column; align-items: center; gap: 3px; flex: 1; max-width: 88px; padding: 6px 2px; border: none; background: none; color: #8b99b3; font-size: 10.5px; font-weight: 600; font-family: inherit; cursor: pointer; border-radius: 9px; position: relative; }
.bnav-item svg { width: 21px; height: 21px; }
.bnav-item.active { color: #fff; }
.bnav-item.active::after { content: ''; position: absolute; top: -6px; left: 22%; right: 22%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.bnav-badge { position: absolute; top: 1px; right: 16px; background: var(--critical); color: #fff; border-radius: 999px; min-width: 15px; height: 15px; font-size: 9.5px; font-weight: 700; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
.bnav-badge.zero { display: none; }
.topbar-search { position: relative; width: 330px; }
#installBtn { display: none; }

@media (max-width: 1280px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 1100px) { .grid2 { grid-template-columns: 1fr; } .chart-row3 { grid-template-columns: 1fr 1fr !important; } }

@media (max-width: 960px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; height: 100dvh; z-index: 90; width: min(290px, 84vw); transform: translateX(-103%); transition: transform .22s ease; box-shadow: none; }
  .sidebar.open { transform: none; box-shadow: 0 0 60px rgba(0,0,0,.45); }
  .sidebar .side-close { display: block; }
  .menu-btn { display: flex; }
  .bottom-nav { display: flex; }
  .topbar { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
  .topbar .spacer { display: none; }
  .topbar-search { order: 10; flex-basis: 100%; width: 100%; }
  .page-title { font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1 1 0; }
  .user-chip .uname { display: none; }
  .user-chip { padding: 4px; border: none; }
  .content { padding: 14px 12px calc(86px + env(safe-area-inset-bottom)); }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 9px; }
  .kpi { padding: 11px 13px; }
  .kpi .v { font-size: 19px; }
  .grid2, .chart-row3 { grid-template-columns: 1fr !important; gap: 12px; }
  .grid2 > *, .grid2 .panel, .chart-row3 > * { min-width: 0; max-width: 100%; }
  .panel { padding: 13px; border-radius: 10px; }
  .sites { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; gap: 4px 0; max-width: none; }
  .form-grid label { margin-top: 9px; }
  .form-grid input, .form-grid select { max-width: none; }
  /* tables scroll horizontally inside their panel instead of squishing */
  .points-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .points-wrap table { min-width: 640px; }
  #tab-explorer .points-wrap table { min-width: 840px; }
  #tab-admin-connectors .points-wrap table { min-width: 920px; }
  #tab-maint-schedule .points-wrap table { min-width: 760px; }

  /* ── Live Monitor: fit without horizontal scroll ── */
  .tree { max-height: 38vh; }
  .tree .equip { padding: 11px 10px; }
  #tab-live .points-wrap table { min-width: 0; }
  #tab-live .points-wrap th:nth-child(3), #tab-live .points-wrap td:nth-child(3) { display: none; } /* vendor name */
  #tab-live .points-wrap th, #tab-live .points-wrap td { padding: 9px 6px; }
  #tab-live .points-wrap td:first-child { word-break: break-word; }

  /* ── Alarms: card layout instead of a wide table ── */
  #tab-alarms .points-wrap:has(#alarmsBody) { overflow-x: visible; }
  #tab-alarms table:has(#alarmsBody) { min-width: 0; width: 100%; max-width: 100%; display: block; }
  #tab-alarms table:has(#alarmsBody) thead { display: none; }
  #alarmsBody { display: block; width: 100%; }
  #alarmsBody td { min-width: 0; overflow-wrap: anywhere; }
  #alarmsBody tr { display: grid; grid-template-columns: auto auto 1fr; gap: 5px 8px; align-items: center; padding: 12px 2px; border-bottom: 1px solid var(--border); }
  #alarmsBody tr:hover td { background: transparent; }
  #alarmsBody td { display: block; border: none; padding: 0; }
  #alarmsBody td:nth-child(1) { grid-row: 1; grid-column: 1; }                 /* severity */
  #alarmsBody td:nth-child(4) { grid-row: 1; grid-column: 2; }                 /* vendor */
  #alarmsBody td:nth-child(3) { grid-row: 1; grid-column: 3; text-align: right; color: var(--muted); font-size: 12px; } /* site */
  #alarmsBody td:nth-child(2) { grid-row: 2; grid-column: 1 / -1; line-height: 1.45; } /* finding */
  #alarmsBody td:nth-child(5) { grid-row: 3; grid-column: 1 / -1; display: flex; gap: 8px; } /* actions */
  #alarmsBody td.empty { grid-column: 1 / -1; text-align: center; }
  .panel > table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  th, td { padding: 10px 9px; }
  .tree { max-height: 44vh; }
  #liveAlerts { max-height: 38vh; }
  #map { height: 42vh !important; }
  .notif-pop { position: fixed; left: 10px; right: 10px; top: 58px; width: auto; max-height: 62vh; }
  .modal { width: 100%; max-width: calc(100vw - 20px); max-height: 90dvh; }
  .schem-modal { max-width: calc(100vw - 12px); }
  .schem-canvas { min-height: 0; padding: 10px 8px; }
  .toast-wrap { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
  /* touch targets */
  .nav-item, .nav-parent-head { padding: 12px 12px; font-size: 14.5px; }
  .nav-item.nav-child { padding: 10px 11px; font-size: 13.5px; }
  button.act { padding: 10px 15px; font-size: 13px; }
  select, input { padding: 10px 12px; font-size: 14px; }
  .bell { padding: 9px 12px; }
  .controls { gap: 7px; }
  .controls select, .controls input { flex: 1 1 140px; min-width: 0; }
  .diag-node { width: calc(50% - 5px); }
}
@media (max-width: 380px) { .kpis { grid-template-columns: 1fr 1fr; } .bnav-item { font-size: 9.5px; } }

@media (min-width: 961px) { .sidebar { transform: none !important; } }
@media print { .sidebar, .topbar, .bell, .notif-pop, .search-pop, #globalSearch { display: none !important; } section.tab { display: block !important; } .panel { break-inside: avoid; } .content { padding: 0 !important; } }
