/* Hyperion design system — ONE stylesheet for every page, both presentation modes (Lite / Advanced) and both themes.
   Tokens first (light default, dark via html[data-theme="dark"]); components after; mode rules last (html[data-mode="lite"] hides .adv-only). */
:root {
  color-scheme: light;
  --bg: #f5f5f5; --card: #ffffff; --fg: #09090b; --text2: #27272a; --muted: #71717a; --muted2: #85858f;
  --border: #e4e4e7; --border2: #d4d4d8; --accent: #f4f4f5; --hover: #fafafa; --sidebar: #fafafa;
  --primary: #18181b; --primary-fg: #fafafa; --blue: #0062f5; --blue-2: #1760de; --blue-soft: #e6f0ff;
  --green: #16a34a; --green-soft: #dcfce7; --amber: #f59e0b; --orange: #ea580c; --red: #dc2626; --red-soft: #fee2e2;
  --ok-text: #16a34a; --danger-text: #dc2626; --warn-bg: #fffbeb; --warn-text: #92400e; --gray: #9ca3af; --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05); --overlay: rgba(0,0,0,.35);
  /* aliases used by the dashboard pages' inline CSS */
  --surface: var(--card); --text: var(--fg); --sky: var(--blue); --ok-bg: var(--green-soft); --bad-bg: var(--red-soft);
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #09090b; --card: #18181b; --fg: #fafafa; --text2: #e4e4e7; --muted: #a1a1aa; --muted2: #71717a;
  --border: #27272a; --border2: #3f3f46; --accent: #27272a; --hover: #1f1f23; --sidebar: #111113;
  --primary: #fafafa; --primary-fg: #18181b; --blue: #3b82f6; --blue-2: #60a5fa; --blue-soft: #172554;
  --green: #4ade80; --green-soft: #14532d; --amber: #fbbf24; --orange: #fb923c; --red: #f87171; --red-soft: #7f1d1d;
  --ok-text: #86efac; --danger-text: #fca5a5; --warn-bg: #422006; --warn-text: #fcd34d; --gray: #71717a; --shadow: 0 1px 2px rgba(0,0,0,.4); --overlay: rgba(0,0,0,.6);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: var(--fg); background: var(--bg); }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
img, canvas, svg { max-width: 100%; }

/* ============================ layout + components (was cloud/triton.css) ============================ */






/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 256px; flex: none; background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .logo { padding: 26px 0 22px; text-align: center; font-weight: 800; letter-spacing: .5px; color: var(--blue-2); font-size: 22px; }
.sidebar .logo img { height: 44px; width: auto; }
.nav { padding: 0 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a, .nav .grp { display: flex; align-items: center; gap: 12px; padding: 11px 10px; border-radius: 8px; font-size: 16px; color: var(--text2); cursor: pointer; }
.nav a:hover { background: var(--accent); }
.nav a.active { color: var(--blue); }
.nav a.active.top { box-shadow: inset 3px 0 0 var(--blue); border-radius: 0 8px 8px 0; }
.nav .sub { margin-left: 18px; padding-left: 8px; border-left: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.nav .sub a { font-size: 15px; padding: 10px 8px; }
.nav .sub a.active { background: var(--accent); color: var(--fg); }
.nav .spacer { flex: 1; }
.nav svg { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.nav .chev { margin-left: auto; width: 16px; height: 16px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 80px; display: flex; align-items: center; justify-content: space-between; padding: 0 24px 0 16px; border-bottom: 1px solid var(--border); background: var(--card); }
.crumbs { color: var(--muted); display: flex; align-items: center; gap: 10px; font-size: 14px; }
.crumbs .sep { color: var(--muted2); }
.crumbs .cur { color: var(--muted); } .crumbs a.link { color: var(--blue); }
.userbox { display: flex; align-items: center; gap: 12px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--border); display: grid; place-items: center; font-size: 13px; }
.userbox .who { font-size: 13px; line-height: 1.25; } .userbox .who small { display: block; color: var(--muted); font-size: 12px; }
.content { padding: 16px 24px 40px; flex: 1; }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; }
.footer a { text-decoration: underline; }

/* ---------- primitives ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px 20px; }
h2.title { font-size: 16px; margin: 0; font-weight: 700; } h2.title small { font-weight: 400; font-size: 13px; margin-left: 6px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; } .between { justify-content: space-between; }
.btn { border: 0; border-radius: 6px; height: 36px; padding: 0 16px; background: var(--primary); color: var(--primary-fg); font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.btn.icon { width: 36px; padding: 0; justify-content: center; } .btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.light { background: var(--accent); color: var(--fg); } .btn.danger { background: #fca5a5; color: var(--primary-fg); }
.input, select.input { height: 36px; border: 1px solid var(--border); border-radius: 6px; padding: 0 12px; background: var(--card); font: inherit; color: var(--fg); min-width: 0; }
.filters { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; margin: 20px 0; }
.filters .input { width: 100%; height: 36px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--gray); }
.dot.on { background: #22c55e; } .dot.warn { background: #f5b301; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.pill.on { background: var(--green-soft); color: var(--green); } .pill.off { background: var(--accent); color: var(--muted); }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-weight: 400; color: var(--muted); padding: 12px 8px; background: var(--accent); box-shadow: 0 2px 4px rgba(0,0,0,.06); position: sticky; top: 0; }
table.t td { padding: 14px 8px; border-bottom: 1px solid var(--border); }
table.t tbody tr:hover { background: var(--hover); }
.pager { display: flex; justify-content: flex-end; align-items: center; gap: 12px; padding: 16px 4px 4px; color: var(--muted); }
.pager .pg { border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; color: var(--fg); background: var(--card); }
.copy { color: var(--muted2); margin-left: 6px; cursor: pointer; vertical-align: middle; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--card); border-radius: 8px; padding: 4px; gap: 4px; flex: 1; }
.tabs a { text-align: center; padding: 10px 0; border-radius: 6px; color: var(--muted); font-weight: 600; font-size: 13px; }
.tabs a.active { background: var(--primary); color: var(--primary-fg); }
.switch { position: relative; width: 36px; height: 20px; border-radius: 10px; background: var(--border2); display: inline-block; flex: none; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--card); transition: .15s; }
.switch.on { background: var(--primary); } .switch.on::after { left: 18px; }

/* ---------- devices grid ---------- */
.dgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px 24px; }
.dcard { padding: 12px; }
.dcard .name { display: flex; justify-content: space-between; align-items: center; padding: 6px 0 14px; font-weight: 600; font-size: 15px; }
.dcard .meta { display: flex; align-items: center; gap: 10px; padding: 4px 0 14px; }
.dcard .meta img, .devimg { width: 28px; height: 28px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, var(--border2) 70%); flex: none; }
.dcard .meta .id { color: var(--muted); font-size: 13px; line-height: 1.35; flex: 1; }
.lastalert { background: var(--hover); border-radius: 6px; padding: 10px 12px; color: var(--muted2); display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.lastalert.has { background: var(--accent); color: var(--text2); } .lastalert small { display: block; }
.dcard .acts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.dcard .acts a { background: var(--accent); border-radius: 6px; text-align: center; padding: 14px 0 10px; color: var(--muted); font-size: 12px; }
.dcard .acts svg { display: block; margin: 0 auto 8px; width: 18px; height: 18px; stroke: var(--text2); fill: none; stroke-width: 1.6; }
.dcard .ov { background: var(--accent); border-radius: 6px; text-align: center; padding: 10px; display: flex; gap: 8px; justify-content: center; align-items: center; font-weight: 500; }

/* ---------- device page ---------- */
.devhead { display: flex; align-items: center; padding: 12px; gap: 0; margin-bottom: 8px; }
.devhead .cell { flex: 1; text-align: center; padding: 8px 14px; border-left: 1px solid var(--border); font-size: 13px; }
.devhead .cell:first-child { border: 0; flex: none; }
.devhead .cell small { display: block; color: var(--muted); margin-bottom: 8px; font-size: 13px; }
.devhead .cell b { font-weight: 600; }
.devhead .devimg { width: 90px; height: 90px; border-radius: 12px; }
.sumgrid { display: grid; grid-template-columns: 237px 1fr; gap: 16px; margin-top: 8px; }
.leftcol .seg { background: var(--primary); color: var(--primary-fg); border-radius: 8px; text-align: center; padding: 12px; font-weight: 600; font-size: 13px; margin-bottom: 16px; }
.leftcol .seg.alt { background: var(--card); color: var(--fg); margin-bottom: 16px; }
.blist { padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; max-height: 720px; overflow: auto; }
.brow { display: flex; justify-content: space-between; align-items: center; background: var(--accent); padding: 12px; border-radius: 8px; font-size: 14px; }
.brow .l { display: flex; align-items: center; gap: 8px; } .brow .v { font-weight: 600; }
.brow .v.alert { color: var(--red); }
.brow svg.bell { width: 14px; height: 14px; stroke: var(--blue); fill: none; stroke-width: 1.8; }
.tip-pop { white-space: pre-line; position: absolute; z-index: 90; max-width: 300px; background: var(--primary); color: var(--primary-fg); padding: 10px 12px; border-radius: 8px; font-size: 12.5px; line-height: 1.5; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-weight: 400; }
.i { cursor: pointer; width: 13px; height: 13px; border: 1px solid var(--muted2); border-radius: 50%; color: var(--muted2); font-size: 9px; display: inline-grid; place-items: center; font-style: normal; }
.toprow { display: grid; grid-template-columns: 1.6fr 1fr .5fr .5fr; gap: 12px; }
.panel { padding: 18px 20px; position: relative; }
.panel h3 { margin: 0 0 6px; font-size: 16px; font-weight: 700; } .panel .badge-r { position: absolute; right: 20px; top: 16px; font-weight: 700; font-size: 20px; }
.aqi-wrap { display: flex; align-items: center; gap: 20px; }
.ring { --p: 50; --c: #a3cf3a; width: 120px; height: 120px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--border) 0); position: relative; flex: none; }
.ring::before { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--card); }
.ring span { position: relative; width: 92px; height: 92px; border-radius: 50%; background: var(--c); color: #111; font-size: 26px; font-weight: 700; display: grid; place-items: center; }
.ring.sm { width: 68px; height: 68px; } .ring.sm::before { inset: 6px; background: var(--accent); } .ring.sm span { width: 52px; height: 52px; background: transparent; font-size: 16px; font-weight: 700; color: var(--fg); }
.mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.mini { background: var(--accent); border-radius: 8px; padding: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mini small { color: var(--text2); display: block; } .mini b { display: block; margin: 6px 0 4px; }
.good { color: var(--green); } .mod { color: var(--amber); } .bad { color: var(--red); }
.legend { display: flex; gap: 14px; font-size: 12px; margin-top: 12px; flex-wrap: wrap; } .legend i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 4px; }
.eq { display: flex; flex-direction: column; align-items: center; gap: 3px; margin-top: 18px; height: 300px; justify-content: flex-end; }
.eq i { display: block; width: 50px; height: 5px; background: var(--border); border-radius: 2px; } .eq i.on { background: #22c55e; } .eq i.on.hi { background: #f59e0b; } .eq i.on.vhi { background: #ef4444; }
.eqval { text-align: center; margin-top: 12px; font-size: 15px; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 12px; }
.tile { padding: 14px 16px; min-height: 100px; } .tile .h { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; } .tile .val { font-size: 36px; text-align: center; margin: 10px 0 0; } .tile .val small { font-size: 14px; vertical-align: top; }
.tile.wide { grid-row: span 2; display: flex; flex-direction: column; } .tile.wide .val { font-size: 22px; margin: auto; }
.tile.wide .cap { text-align: center; font-size: 13px; color: var(--text2); margin-bottom: auto; }
.sec { padding: 20px 24px; margin-bottom: 16px; } .sec h2 { margin: 0 0 20px; font-size: 16px; }
.chart-controls { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.lbl { font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.scroll { max-height: 460px; overflow: auto; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
@media (max-width: 1100px) { .dgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .toprow { grid-template-columns: repeat(2, minmax(0, 1fr)); } .sumgrid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 760px) {
  .dgrid { grid-template-columns: minmax(0, 1fr); } .filters { grid-template-columns: minmax(0, 1fr); } .tiles, .toprow, .chart-controls { grid-template-columns: minmax(0, 1fr); }
  .devhead { flex-wrap: wrap; } .content { padding: 12px; }
}

.modesw { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; font-size: 13px; line-height: 1; }
.modesw a, .modesw span { padding: 9px 14px; text-decoration: none; }
.modesw a { color: var(--muted); } .modesw a:hover { color: var(--fg); }
.modesw .on { background: var(--primary); color: var(--primary-fg); font-weight: 600; }

/* ============================ dashboard pages: tables, badges, incident cards, filters (was theme.css) ============================ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 0; border-radius: var(--radius); box-shadow: var(--shadow); background: var(--card); }
.table-wrap table { border-collapse: collapse; width: 100%; }
.table-wrap thead th { background: var(--accent); color: var(--muted); font-weight: 400; box-shadow: 0 2px 4px rgba(0,0,0,.05); }
.table-wrap th, .table-wrap td { border-bottom: 1px solid var(--border); }
.table-wrap tbody tr:hover { background: var(--hover); }
.badge { border-radius: 6px; font-weight: 600; padding: .15rem .55rem; }
.incident-card, .incidents-empty { border-radius: var(--radius); }
.incident-card { box-shadow: var(--shadow); }
select, input[type="search"], input[type="text"], input[type="date"], input[type="password"], input[type="email"], input[type="number"] { font: inherit; color: var(--fg); }
.filters select, .filters input[type="search"], .filters input[type="text"], .filters input[type="date"] { height: 36px; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--fg); padding: 0 12px; font: inherit; }
.filters button, .pager button { height: 36px; border: 1px solid var(--border); border-radius: 6px; background: var(--card); color: var(--fg); padding: 0 14px; font: inherit; cursor: pointer; }
.filters button:hover, .pager button:hover { background: var(--accent); }
a.pdf-btn { background: var(--primary); color: var(--primary-fg); border-radius: 6px; font-weight: 500; }
a.pdf-btn:hover { opacity: .85; }
.page-title { font-size: 18px; font-weight: 700; margin: 8px 0 16px; }

/* ============================ app shell: topbar controls, drawer, states, modes ============================ */
.topbar .actions { display: flex; align-items: center; gap: 10px; margin-left: auto; font-size: 13px; color: var(--muted); }
.topbar .actions .modesw { margin: 0; }
.topbar .actions .langsw { float: none !important; margin: 0 !important; }
#theme-toggle { float: none; margin: 0; cursor: pointer; font-size: 13px; line-height: 1; background: var(--card); color: var(--text2); border: 1px solid var(--border); border-radius: 999px; padding: 9px 12px; min-height: 36px; }
#theme-toggle:hover { border-color: var(--muted); }
.menu-btn { display: none; width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--fg); font-size: 20px; line-height: 1; align-items: center; justify-content: center; margin-right: 8px; }
.scrim { display: none; }
.userbox .who { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-pop { display: none; position: absolute; right: 0; top: 46px; background: var(--card); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.14); z-index: 30; min-width: 190px; }
.menu-pop a, .menu-pop button { display: block; width: 100%; text-align: left; padding: 12px 16px; background: none; border: 0; color: var(--fg); font: inherit; min-height: 44px; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--accent); }
.state { text-align: center; color: var(--muted); padding: 36px 12px; }
.state.error { color: var(--danger-text); }
.state .retry { margin-top: 12px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border2); border-top-color: var(--blue); border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; vertical-align: middle; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.content table { max-width: 100%; }
.content .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.content img, .content canvas { max-width: 100%; }

/* presentation modes: one app, one component set. Lite hides technical detail marked .adv-only */
html[data-mode="lite"] .adv-only { display: none !important; }
html:not([data-mode="lite"]) .lite-only { display: none !important; }

/* ============================ responsive: tablet <= 1100, drawer + phone <= 900 / 760 ============================ */
@media (max-width: 900px) {
  .sidebar { display: flex !important; position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%); transition: transform .2s; width: 280px; max-width: 86vw; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: var(--overlay); z-index: 55; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 12px; height: 64px; gap: 8px; }
  .topbar .crumbs { display: none; }
  .nav a, .nav .grp { min-height: 44px; }
}
@media (max-width: 900px) {
  .content .row { flex-wrap: wrap; }
  .content table.t, .content table.wide { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .content .filters, .content .chart-controls { min-width: 0; }
  .content select.input, .content .input { max-width: 100%; }
}
@media (max-width: 760px) {
  .topbar .actions { gap: 6px; }
  .topbar .actions .modesw a, .topbar .actions .modesw span { padding: 11px 12px; }
  .userbox .who { display: none; }
  #theme-toggle { padding: 0; width: 44px; height: 44px; font-size: 0; display: inline-grid; place-items: center; }
  #theme-toggle::before { content: attr(data-ico); font-size: 18px; line-height: 1; }
  .topbar .actions .langsw { white-space: nowrap; }
  .content { padding: 12px; }
  .btn, .input, select.input { min-height: 44px; }
  .btn.icon { min-width: 44px; }
  .filters { grid-template-columns: 1fr; }
  .tabs { grid-template-columns: repeat(2, 1fr); }
}

html[data-theme="dark"] .sidebar .logo img { background: #fff; border-radius: 8px; padding: 4px 10px; }
.topbar .actions .langsw { white-space: nowrap; }

.conn-banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 24px; background: var(--red-soft); color: var(--danger-text); border-bottom: 1px solid var(--red); font-size: 13px; font-weight: 600; }
.conn-banner[hidden] { display: none; }
.conn-banner .btn { height: 32px; }
@media (max-width: 760px) { .conn-banner { padding: 10px 12px; } }

dialog.dlg { border: 1px solid var(--border); border-radius: 12px; background: var(--card); color: var(--fg); padding: 22px; width: 460px; max-width: 94vw; box-shadow: 0 16px 48px rgba(0,0,0,.3); }
dialog.dlg::backdrop { background: var(--overlay); }
dialog.dlg .hint { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0 0 14px; }
dialog.dlg .err { color: var(--danger-text); font-size: 13px; min-height: 18px; margin-top: 8px; }
.lbl { font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.dot.warn { background: var(--amber); }

/* Device page: nothing may force the page wider than the window (found with real data: 2 px on phones, ~120 px at 1000-1100 px).
   Grid/flex children shrink instead of imposing their content width; the tab strip in the top bar shrinks and clips its labels. */
.main, .content, .sumgrid > *, .leftcol, .toprow > *, .panel, .tile, .card { min-width: 0; }
.topbar .crumbs { min-width: 0; flex: 1 1 0; overflow: hidden; }
.topbar .crumbs .tabs { min-width: 0; }
.topbar .crumbs .tabs a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 6px; padding-right: 6px; }
.topbar .actions, .topbar .userbox { flex: none; }
@media (max-width: 1100px) { .userbox .who { max-width: 120px; } .topbar .actions { gap: 6px; } }

.mini-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mini { min-width: 0; }
@media (max-width: 380px) { .mini-grid { grid-template-columns: minmax(0, 1fr); } }
