@font-face { font-family: 'Plex Sans'; src: url('fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Plex Sans'; src: url('fonts/ibm-plex-sans-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Plex Sans'; src: url('fonts/ibm-plex-sans-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Plex Mono'; src: url('fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Plex Mono'; src: url('fonts/ibm-plex-mono-latin-500-normal.woff2') format('woff2'); font-weight: 500; font-display: swap; }

:root {
  --bg: #0d1014;
  --bg-2: #12161c;
  --panel: #161b22;
  --panel-2: #1c222b;
  --line: #262e39;
  --line-2: #323c4a;
  --text: #e3e8ef;
  --text-2: #a4afbd;
  --muted: #6d7888;
  --accent: #4fd1c5;
  --accent-ink: #062b28;
  --up: #3ddc84;
  --down: #ff5c5c;
  --warn: #ffb547;
  --info: #6aa8ff;
  --crit: #ff3d8b;
  --offsite: #7d8aa0;
  --radius: 10px;
  --sans: 'Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Plex Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-size: 0.92em; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.dim { color: var(--text-2); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 500; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); background: var(--panel-2);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap; line-height: 1.2; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--down); border-color: color-mix(in srgb, var(--down) 40%, var(--line-2)); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.icon { padding: 6px 8px; }
.btn svg { width: 16px; height: 16px; flex: none; }

label.field { display: grid; gap: 5px; font-size: 13px; color: var(--text-2); }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=url], select, textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
textarea { resize: vertical; min-height: 70px; }
.inputrow { display: flex; gap: 6px; }
.inputrow > input { flex: 1; min-width: 0; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--text); cursor: pointer; }
.hint { font-size: 12.5px; color: var(--muted); }
.error { color: var(--down); font-size: 13.5px; min-height: 1.2em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 2px; }
.seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg button { white-space: nowrap; border: 0; background: transparent; padding: 5px 11px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-size: 13.5px; }
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }

/* ---------- auth screens ---------- */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 500px at 50% -10%, #173033 0%, transparent 60%), var(--bg); }
.gate-card { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: grid; gap: 16px; }
.gate-card.wide { width: min(560px, 100%); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; }
.brand-mark { width: 28px; height: 28px; }
.steps { display: flex; gap: 6px; }
.steps span { height: 3px; flex: 1; border-radius: 2px; background: var(--line-2); }
.steps span.on { background: var(--accent); }
.qr { background: #fff; padding: 10px; border-radius: 10px; width: 200px; height: 200px; justify-self: center; }
.qr img { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.secret { font-family: var(--mono); font-size: 13px; background: var(--bg-2); padding: 8px 10px; border-radius: 8px; word-break: break-all; border: 1px solid var(--line); }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; font-family: var(--mono); background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; }
.warnbox { border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 8%, transparent);
  color: #ffd79a; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; }
.meter { height: 4px; border-radius: 2px; background: var(--line-2); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; transition: width 0.2s, background 0.2s; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100%; }
.side { background: var(--bg-2); border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { padding: 4px 8px 16px; }
.nav { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2); cursor: pointer; text-decoration: none; }
.nav:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav.on { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
button.nav { border: 0; background: transparent; width: 100%; text-align: left; font: inherit; }
.nav .count { margin-left: auto; }
.nav.sub { padding-left: 38px; font-size: 14px; }
.side-foot { margin-top: auto; display: grid; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.where { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--text-2); padding: 4px 10px; }
.where .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.where.home .dot { background: var(--up); }
.where.away .dot { background: var(--warn); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5; }
.topbar .search { max-width: 360px; }
.page { padding: 24px; display: grid; gap: 20px; align-content: start; max-width: 1400px; width: 100%; }
.pagehead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.count { min-width: 20px; padding: 0 6px; height: 20px; border-radius: 10px; background: var(--line-2); color: var(--text); font-size: 12px;
  display: inline-grid; place-items: center; font-weight: 600; font-family: var(--mono); }
.count.hot { background: var(--down); color: #fff; }
.count:empty { display: none; }

.lockchip { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--text-2); background: var(--panel); cursor: pointer; }
.lockchip svg { width: 14px; height: 14px; }
.lockchip.open { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, var(--line-2)); }

/* ---------- panels ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-body { padding: 16px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 4px; }
.stat b { font: 600 26px/1.1 var(--mono); }
.stat span { color: var(--muted); font-size: 13px; }
.stat.up b { color: var(--up); }
.stat.down b { color: var(--down); }
.stat.warnstat b { color: var(--warn); }
.stat.link { cursor: pointer; }
.stat.link:hover { border-color: var(--line-2); }

/* device tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.tile { color: inherit; text-decoration: none !important; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; cursor: pointer;
  position: relative; overflow: hidden; transition: border-color 0.15s, transform 0.15s; }
.tile:hover { border-color: var(--line-2); transform: translateY(-1px); }
.tile::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--muted); }
.tile.up::before { background: var(--up); }
.tile.down::before { background: var(--down); }
.tile.down { border-color: color-mix(in srgb, var(--down) 45%, var(--line)); background: linear-gradient(90deg, color-mix(in srgb, var(--down) 7%, var(--panel)), var(--panel)); }
.tile.offsite::before { background: var(--offsite); opacity: 0.5; }
.tile-top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tile-top svg.kind { width: 20px; height: 20px; color: var(--text-2); flex: none; }
.tile-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-host { font-family: var(--mono); font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-foot { display: flex; align-items: flex-end; gap: 10px; }
.tile-foot .lat { font: 500 13px var(--mono); color: var(--text-2); white-space: nowrap; }
.spark { flex: 1; height: 26px; display: block; }
.lamp { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; margin-left: auto; }
.lamp.up { background: var(--up); box-shadow: 0 0 0 3px color-mix(in srgb, var(--up) 18%, transparent); }
.lamp.down { background: var(--down); box-shadow: 0 0 0 3px color-mix(in srgb, var(--down) 22%, transparent); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--down) 0%, transparent); } }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--text-2); white-space: nowrap; }
.badge.offsite { color: var(--offsite); }
.badge svg { width: 12px; height: 12px; }
.section-title { display: flex; align-items: center; gap: 10px; }

/* device page */
.devhead { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.devhead .icon { width: 48px; height: 48px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); display: grid; place-items: center; }
.devhead .icon svg { width: 26px; height: 26px; color: var(--text-2); }
.statusline { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.chart { width: 100%; height: 190px; display: block; }
.chart .grid line { stroke: var(--line); }
.chart text { fill: var(--muted); font: 11px var(--mono); }
.chart .area { fill: color-mix(in srgb, var(--accent) 14%, transparent); }
.chart .lat { fill: none; stroke: var(--accent); stroke-width: 1.6; }
.chart .downband { fill: color-mix(in srgb, var(--down) 30%, transparent); }
.chart .cursor { stroke: var(--line-2); }
.chart .dot { fill: var(--accent); }
.charttip { font: 12.5px var(--mono); color: var(--text-2); min-height: 1.3em; }

.creds { display: grid; gap: 10px; }
.cred { border: 1px solid var(--line); background: var(--bg-2); border-radius: 10px; padding: 12px; display: grid; gap: 8px; }
.cred-head { display: flex; align-items: center; gap: 8px; }
.cred-head b { font-weight: 600; }
.credrow { display: grid; grid-template-columns: 82px 1fr auto; gap: 8px; align-items: center; font-size: 14px; }
.credrow .k { color: var(--muted); font-size: 13px; }
.credrow .v { font-family: var(--mono); font-size: 13.5px; overflow-wrap: anywhere; min-width: 0; }
.credrow .acts { display: flex; gap: 4px; }
.totp { font: 600 17px var(--mono); letter-spacing: 0.12em; color: var(--accent); }
.locked-box { border: 1px dashed var(--line-2); border-radius: 10px; padding: 18px; display: grid; gap: 10px; justify-items: start; color: var(--text-2); }

/* alarms */
.alarms-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; align-items: start; }
.lists { display: grid; gap: 2px; }
.lists .nav { padding: 7px 10px; }
.listtools { display: flex; gap: 6px; padding: 10px 4px 0; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.alarm { display: grid; grid-template-columns: 22px 6px minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.alarm:last-child { border-bottom: 0; }
.alarm.acked { opacity: 0.62; }
.alarm.selected { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.alarm input { margin-top: 3px; }
.sev { width: 6px; align-self: stretch; border-radius: 3px; background: var(--info); }
.sev.minor { background: var(--warn); }
.sev.major { background: var(--down); }
.sev.critical { background: var(--crit); }
.alarm-title { font-weight: 500; cursor: pointer; overflow-wrap: anywhere; }
.alarm-meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 3px; align-items: center; }
.alarm-detail { white-space: pre-wrap; font: 12.5px/1.5 var(--mono); color: var(--text-2); background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 8px; overflow-wrap: anywhere; }
.alarm-acts { display: flex; gap: 4px; align-items: center; }
.state { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; padding: 1px 7px; border-radius: 999px; border: 1px solid; }
.state.open { color: var(--down); border-color: color-mix(in srgb, var(--down) 50%, transparent); }
.state.cleared { color: var(--up); border-color: color-mix(in srgb, var(--up) 45%, transparent); }
.state.acked { color: var(--text-2); border-color: var(--line-2); }
.mini-alarms .alarm { grid-template-columns: 6px minmax(0, 1fr) auto; }

/* menus & dialogs */
.menu { position: fixed; z-index: 50; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 4px; min-width: 180px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45); display: grid; }
.menu button { text-align: left; border: 0; background: transparent; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--line); }
.menu .sep { height: 1px; background: var(--line-2); margin: 4px 2px; }
dialog { border: 1px solid var(--line-2); background: var(--panel); color: var(--text); border-radius: 14px; padding: 0; width: min(560px, calc(100% - 32px)); max-height: calc(100% - 32px); }
dialog::backdrop { background: rgba(5, 7, 10, 0.7); backdrop-filter: blur(2px); }
dialog form { display: grid; gap: 14px; padding: 20px; }
.dlg-head { display: flex; align-items: center; gap: 10px; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding-top: 4px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 14px; margin: 0; display: grid; gap: 12px; }
legend { padding: 0 6px; color: var(--text-2); font-size: 13px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12.5px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 16px;
  border-radius: 10px; z-index: 60; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); font-size: 14px; max-width: calc(100% - 32px); }
.toast.bad { border-color: color-mix(in srgb, var(--down) 60%, var(--line-2)); }

.mobilenav { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .topbar { padding: 10px 16px; }
  .page { padding: 16px 16px 90px; }
  .cols, .alarms-layout { grid-template-columns: 1fr; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2 { grid-template-columns: 1fr; }
  .mobilenav { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
    background: var(--bg-2); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .mobilenav a { display: grid; justify-items: center; gap: 2px; font-size: 11.5px; color: var(--text-2); padding: 4px; position: relative; text-decoration: none; }
  .mobilenav a.on { color: var(--accent); }
  .mobilenav svg { width: 22px; height: 22px; }
  .mobilenav .count { position: absolute; top: 0; left: calc(50% + 6px); height: 17px; min-width: 17px; font-size: 10.5px; }
  .lists { grid-auto-flow: column; grid-auto-columns: max-content; overflow-x: auto; }
  .listtools { padding-top: 6px; }
  .table .hide-sm { display: none; }
  .alarm { grid-template-columns: 22px 6px minmax(0, 1fr); }
  .alarm-acts { grid-column: 3; }
  .topbar .search { max-width: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.tile-text { min-width: 0; }
