:root {
  color-scheme: dark;
  --bg: #0b0e12; --surface: #131820; --surface-2: #1a212b; --line: #2a3340; --line-soft: #1f2732;
  --text: #eef1f5; --muted: #93a0b2; --accent: #e1b936; --accent-ink: #1a1500;
  --ok: #4cc38a; --warn: #f0b24a; --bad: #f0645a; --info: #5aa9f0;
  --radius: 12px; --shadow: 0 10px 30px rgba(0,0,0,.35);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3f5f8; --surface: #ffffff; --surface-2: #f0f3f7; --line: #d5dce6; --line-soft: #e6ebf2;
    --text: #151a22; --muted: #5d6b7e; --accent: #b98f0b; --accent-ink: #ffffff;
    --ok: #178a58; --warn: #a96b00; --bad: #c4372d; --info: #1e6fc0;
    --shadow: 0 10px 30px rgba(20,30,50,.12);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); min-height: 100vh; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.1rem; } h3 { font-size: .95rem; }
p { margin: 0; }
a { color: var(--info); }
code, .mono { font-family: var(--mono); font-size: .88em; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .hidden { display: none !important; }
.noscript { padding: 24px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 8px; }
.brand svg { width: 28px; height: 28px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .1em; padding: 12px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; display: grid; gap: 10px; }
.me { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; flex: none; }
.me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { padding: 28px clamp(16px, 3vw, 40px) 64px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.topbar { display: none; }

/* components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.grid { display: grid; gap: 14px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 16px; }
.grid.cards { grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat { padding: 16px; }
.stat .v { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; }
.stat .l { color: var(--muted); font-size: .85rem; }
.stat .s { color: var(--muted); font-size: .8rem; margin-top: 2px; }
button, .btn { font: inherit; font-weight: 600; min-height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; background: var(--accent); color: var(--accent-ink); display: inline-flex; align-items: center; gap: 7px; justify-content: center; text-decoration: none; }
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: not-allowed; filter: none; }
button.ghost { background: transparent; border-color: var(--line); color: var(--text); }
button.ghost:hover { background: var(--surface-2); }
button.danger { background: transparent; border-color: color-mix(in srgb, var(--bad) 55%, transparent); color: var(--bad); }
button.danger:hover { background: color-mix(in srgb, var(--bad) 14%, transparent); }
button.sm { min-height: 30px; padding: 0 10px; font-size: .85rem; }
button.icon { padding: 0; width: 34px; min-height: 34px; }
button svg { width: 16px; height: 16px; }
label { display: grid; gap: 6px; font-size: .85rem; color: var(--muted); font-weight: 500; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; min-height: 40px; padding: 8px 12px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.form { display: grid; gap: 14px; }
.form-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .9rem; }
.check input { width: 18px; min-height: 18px; accent-color: var(--accent); }
.error { color: var(--bad); font-size: .9rem; min-height: 1.2em; white-space: pre-wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.pill.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.pill.info { color: var(--info); border-color: color-mix(in srgb, var(--info) 40%, transparent); }
.pill.plain::before { display: none; }
.pill.ok.pulse::before { animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* device cards */
.device { display: grid; gap: 12px; }
.device-top { display: flex; gap: 12px; align-items: flex-start; }
.kind-ico { width: 42px; height: 42px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; flex: none; color: var(--accent); }
.kind-ico svg { width: 24px; height: 24px; }
.device h3 { overflow-wrap: anywhere; }
.device-meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .85rem; }
.device-meta dt { color: var(--muted); } .device-meta dd { margin: 0; overflow-wrap: anywhere; }
.device-actions { display: flex; gap: 6px; flex-wrap: wrap; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.device.soon { opacity: .75; border-style: dashed; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
th { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; background: var(--surface); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
td .row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input { max-width: 320px; } .toolbar select { width: auto; min-width: 150px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab { background: var(--surface); border: 1px solid var(--line); color: var(--muted); }
.tab[aria-selected="true"] { border-color: var(--accent); color: var(--text); background: var(--surface-2); }
.tab[disabled] { opacity: .6; }
.secret { font-family: var(--mono); background: var(--bg); border: 1px dashed var(--accent); border-radius: 8px; padding: 12px; overflow-wrap: anywhere; user-select: all; }
.notice { border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); border-radius: 10px; padding: 12px 14px; font-size: .9rem; }
.notice.info { border-color: color-mix(in srgb, var(--info) 45%, transparent); background: color-mix(in srgb, var(--info) 10%, transparent); }
.list { display: grid; gap: 0; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
.list-item:last-child { border-bottom: 0; }
.timeline { display: grid; gap: 10px; }
.event { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .88rem; }
.event time { color: var(--muted); font-family: var(--mono); font-size: .8rem; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(900px 500px at 20% -10%, color-mix(in srgb, var(--accent) 14%, transparent), transparent), var(--bg); }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 18px; }
.login-card .brand { padding: 0; font-size: 1.15rem; }

/* dialog + toast */
dialog { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(5,8,12,.6); backdrop-filter: blur(3px); }
.dlg { padding: 22px; display: grid; gap: 16px; max-height: calc(100vh - 60px); overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast { background: var(--surface-2); border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: 8px; padding: 11px 14px; box-shadow: var(--shadow); max-width: 380px; }
.toast.ok { border-left-color: var(--ok); } .toast.bad { border-left-color: var(--bad); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* mobile */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(280px, 85vw); height: 100vh; transform: translateX(-102%); transition: transform .2s; z-index: 30; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 20; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 25; }
  .main { padding-top: 20px; }
}

.qr { display: block; margin: 0 auto; width: 216px; height: 216px; max-width: 100%; border-radius: 10px; background: #fff; image-rendering: pixelated; }

dialog.wide { width: min(860px, calc(100vw - 24px)); }
.device.clickable { cursor: pointer; transition: border-color .15s, transform .15s; }
.device.clickable:hover { border-color: var(--accent); }
.route-card { display: grid; gap: 10px; }
svg.route { width: 100%; height: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.rt-box { fill: url(#rtg); stroke: var(--line); stroke-width: 1.2; }
.rt-box.ghost { fill: none; stroke-dasharray: 5 5; }
.rt-box.mid.on { stroke: var(--ok); }
.rt-title { fill: var(--text); font: 600 13px var(--font); }
.rt-text { fill: var(--text); font: 12px var(--font); }
.rt-dim { fill: var(--muted); font: 12px var(--font); }
.rt-mono { fill: var(--muted); font: 11px var(--mono); }
.rt-line { stroke: var(--line); stroke-width: 3; fill: none; stroke-linecap: round; }
.rt-line.active { stroke: var(--ok); stroke-width: 4; }
.rt-line.idle { stroke: var(--info); }
.rt-line.down { stroke: var(--bad); stroke-dasharray: 3 8; }
.rt-line.unknown { stroke-dasharray: 3 8; }
.rt-line.dotted { stroke-width: 1.5; stroke-dasharray: 2 6; }
.rt-dim.active { fill: var(--ok); } .rt-dim.down { fill: var(--bad); } .rt-dim.idle { fill: var(--info); }
.dot.ok { fill: var(--ok); } .dot.warn { fill: var(--warn); } .dot.off { fill: var(--muted); }
.iface-block { display: grid; gap: 6px; }
table.compact { min-width: 520px; } table.compact th, table.compact td { padding: 7px 10px; }

.rt-box.node { filter: drop-shadow(0 4px 10px rgba(0,0,0,.25)); }
.rt-flow { stroke-width: 4; fill: none; stroke-linecap: round; stroke-dasharray: 2 14; opacity: .9; animation: rt-dash 1s linear infinite; }
.rt-flow.active { stroke: #fff; stroke-opacity: .55; }
.rt-flow.idle { stroke: var(--info); stroke-opacity: .6; animation-duration: 2.4s; }
.rt-line.active { filter: url(#rtglow); }
.rt-line.ctl { stroke-dasharray: 2 7; animation: rt-dash 2.2s linear infinite; opacity: .7; }
.pkt { filter: url(#rtglow); }
.pkt.fwd { fill: var(--ok); } .pkt.back { fill: var(--info); r: 3; }
.dot-ring { fill: none; stroke: var(--ok); stroke-width: 2; transform-box: fill-box; transform-origin: center; animation: rt-ping 1.8s ease-out infinite; }
.rt-box.mid.on { animation: rt-glow 2.6s ease-in-out infinite; }
.rt-ico { fill: var(--accent); font: 14px var(--font); }
svg.route { animation: rt-in .4s ease-out; }
@keyframes rt-dash { to { stroke-dashoffset: -16; } }
@keyframes rt-ping { from { transform: scale(1); opacity: .9; } to { transform: scale(3); opacity: 0; } }
@keyframes rt-glow { 50% { stroke-width: 2.4; filter: drop-shadow(0 0 6px var(--ok)); } }
@keyframes rt-in { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .rt-flow, .rt-line.ctl, .dot-ring, .rt-box.mid.on, svg.route { animation: none; } }
