:root {
  --bg: #f4f6f9; --panel: #ffffff; --panel-2: #f8fafc; --border: #e3e8ef; --text: #0f172a; --muted: #64748b; --faint: #94a3b8;
  --accent: #2563eb; --accent-2: #1d4ed8; --accent-soft: #e8efff;
  --ok: #15803d; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fdf3e2; --crit: #c81e1e; --crit-soft: #fdeaea; --info: #0e7490; --info-soft: #e3f5f8;
  --side: #0b1220; --side-2: #131c2e; --side-text: #c7d2e3; --side-muted: #7c8aa3;
  --term: #0b1020; --term-text: #d6e2ff;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .04);
  --radius: 10px; --mono: ui-monospace, SFMono-Regular, Consolas, "Cascadia Code", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0f1a; --panel: #111827; --panel-2: #0f1624; --border: #1f2a3c; --text: #e5ebf5; --muted: #93a1b8; --faint: #64748b;
    --accent: #4f8cff; --accent-2: #3b7bff; --accent-soft: #15233f;
    --ok: #4ade80; --ok-soft: #10261a; --warn: #fbbf24; --warn-soft: #2a2010; --crit: #f87171; --crit-soft: #2c1414; --info: #22d3ee; --info-soft: #0d2730;
    --side: #070b14; --side-2: #0f1626; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0f1a; --panel: #111827; --panel-2: #0f1624; --border: #1f2a3c; --text: #e5ebf5; --muted: #93a1b8; --faint: #64748b;
  --accent: #4f8cff; --accent-2: #3b7bff; --accent-soft: #15233f;
  --ok: #4ade80; --ok-soft: #10261a; --warn: #fbbf24; --warn-soft: #2a2010; --crit: #f87171; --crit-soft: #2c1414; --info: #22d3ee; --info-soft: #0d2730;
  --side: #070b14; --side-2: #0f1626; --shadow: 0 1px 2px rgba(0,0,0,.4); 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: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
code { overflow-wrap: anywhere; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } .g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g4, .g5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) { .g2, .g3, .g4, .g5 { grid-template-columns: 1fr; } }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 6px 10px 16px; color: #fff; font-weight: 700; font-size: 15px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #2563eb, #0ea5e9); display: grid; place-items: center; }
.brand small { display: block; font-weight: 500; color: var(--side-muted); font-size: 11px; }
.nav-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted); padding: 14px 10px 6px; }
.nav a { display: flex; gap: 10px; align-items: center; padding: 7px 10px; border-radius: 7px; color: var(--side-text); font-size: 13.5px; }
.nav a:hover { background: var(--side-2); text-decoration: none; color: #fff; }
.nav a.active { background: #1c2a45; color: #fff; }
.nav a svg { width: 17px; height: 17px; opacity: .85; flex: none; }
.nav .count { margin-left: auto; background: var(--crit); color: #fff; font-size: 11px; border-radius: 10px; padding: 0 7px; font-weight: 600; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 24px; border-bottom: 1px solid var(--border); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.top .search { flex: 1; max-width: 420px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.live.on i { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.content { padding: 22px 24px 60px; max-width: 1500px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.menu-btn { display: none; }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 20; width: 250px; left: -260px; transition: left .2s; }
  .app.nav-open .side { left: 0; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .top { padding: 0 16px; gap: 8px; }
}
@media (max-width: 640px) {
  .top .who, .top .live span { display: none; }
  .top .search { max-width: none; }
  .content { padding: 12px; }
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .facts { grid-template-columns: 110px minmax(0, 1fr); }
  .page-head > .row { width: 100%; }
}

/* ---------- surfaces ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-b { padding: 16px; min-width: 0; }
.card-b.flush { padding: 0; overflow-x: auto; }
/* Grid and flex children may shrink below their content width instead of overflowing. */
.grid > *, .stack > * { min-width: 0; }
.kpi { padding: 16px; }
.kpi .label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.crit .value { color: var(--crit); } .kpi.ok .value { color: var(--ok); } .kpi.warn .value { color: var(--warn); }
.facts { display: grid; grid-template-columns: 150px 1fr; gap: 7px 14px; font-size: 13px; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; overflow-wrap: anywhere; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--info-soft); color: var(--text); border: 1px solid transparent; font-size: 13px; }
.notice.warn { background: var(--warn-soft); } .notice.crit { background: var(--crit-soft); }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 9px 12px; border-bottom: 1px solid var(--border); background: var(--panel-2); white-space: nowrap; position: sticky; top: 0; }
td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--panel-2); }
tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-title { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 12px; }
.scroll-y { max-height: 460px; overflow-y: auto; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 13px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font: inherit; font-weight: 550; font-size: 13px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--faint); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--crit); }
.btn.danger.solid { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12.5px; }
.btn svg { width: 15px; height: 15px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; height: 34px; min-width: 0; }
textarea { padding: 8px 10px; height: auto; min-height: 90px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type="checkbox"] { height: auto; width: 15px; height: 15px; accent-color: var(--accent); }
label.field { display: grid; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 550; }
label.field > input, label.field > select, label.field > textarea { color: var(--text); font-weight: 400; }
.form { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; cursor: pointer; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.crit { background: var(--crit-soft); color: var(--crit); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--faint); }
.dot.online { background: var(--ok); } .dot.offline { background: var(--faint); } .dot.pending { background: var(--warn); }
.plat { display: inline-flex; align-items: center; gap: 7px; }
.plat svg { width: 16px; height: 16px; flex: none; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 13px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

.bar { height: 8px; background: var(--panel-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.warn > i { background: var(--warn); } .bar.crit > i { background: var(--crit); } .bar.ok > i { background: var(--ok); }
.meter { display: grid; grid-template-columns: 72px 1fr 52px; gap: 10px; align-items: center; font-size: 12.5px; }
.donut { width: 110px; height: 110px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.donut > div { width: 78px; height: 78px; border-radius: 50%; background: var(--panel); display: grid; place-items: center; font-weight: 700; font-size: 20px; }
.legend { display: grid; gap: 6px; font-size: 13px; }
.legend span i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; vertical-align: -1px; }

.terminal { background: var(--term); color: var(--term-text); border-radius: 8px; padding: 12px 14px; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-word; max-height: 460px; overflow-y: auto; min-height: 220px; }
.terminal .cmd { color: #7dd3fc; } .terminal .err { color: #fca5a5; } .terminal .dim { color: #64748b; }
.term-input { display: flex; gap: 8px; margin-top: 8px; }
.term-input input { flex: 1; font-family: var(--mono); }
.terminal.term-live { min-height: 320px; max-height: 520px; cursor: text; }
.term-line { display: flex; align-items: baseline; margin: 0; }
.term-prompt { color: #86efac; white-space: pre; flex: none; max-width: 60%; overflow: hidden; text-overflow: ellipsis; }
.term-line input { flex: 1; min-width: 40px; background: transparent; border: 0; outline: 0; box-shadow: none; padding: 0; margin: 0; color: var(--term-text); font: inherit; caret-color: #86efac; }
.term-line input::placeholder { color: #475569; }
pre.out { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; max-height: 420px; overflow: auto; margin: 0; }

/* Remote control viewer */
.rc-toolbar { gap: 8px; }
.rc-toolbar select { height: 28px; font-size: 12.5px; }
.rc-view { position: relative; background: #0b0f17; border-radius: 8px; min-height: 360px; display: grid; place-items: center; overflow: hidden; outline: none; user-select: none; }
.rc-view.on { cursor: default; }
.rc-view.on:focus { box-shadow: 0 0 0 2px var(--accent); }
.rc-view.viewonly { cursor: not-allowed; }
.rc-view img, .rc-view canvas { display: block; width: 100%; height: auto; image-rendering: auto; }
.rc-view canvas[hidden] { display: none; }
.rc-view:fullscreen { background: #000; border-radius: 0; }
.rc-view:fullscreen img { width: auto; height: auto; max-width: 100vw; max-height: 100vh; }
.rc-overlay { display: grid; gap: 8px; place-items: center; text-align: center; color: #94a3b8; padding: 40px 20px; }
.rc-overlay .small { color: #64748b; }
.rc-big svg { width: 54px; height: 54px; color: #334155; }
.rc-big { font-size: 40px; color: #f59e0b; }
.ticket-grid { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
@media (max-width: 1000px) { .ticket-grid { grid-template-columns: 1fr; } }
.ticket-thread { display: grid; gap: 10px; }
.tmsg { padding: 10px 12px; border-radius: 10px; background: #f1f5f9; white-space: pre-wrap; }
.tmsg.tech { background: #dbeafe; } .tmsg.internal { background: #fef9c3; border: 1px dashed #ca8a04; } .tmsg.system { background: transparent; color: #64748b; font-size: 12px; padding: 2px 12px; }
.kb-art > summary { cursor: pointer; list-style: none; }
.chat-log { max-height: 280px; overflow-y: auto; display: grid; gap: 8px; }
.chat-msg { padding: 8px 12px; border-radius: 10px; background: var(--bg-2, #f1f5f9); max-width: 80%; white-space: pre-wrap; }
.chat-msg.tech { justify-self: end; background: #dbeafe; } .chat-msg.user { justify-self: start; }
.chat-meta { font-size: 11px; color: #64748b; margin-bottom: 2px; }
.screen-wall { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.screen-tile { display: grid; gap: 6px; padding: 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 10px; background: var(--card, #fff); color: inherit; text-decoration: none; }
.screen-img { aspect-ratio: 16 / 10; background: #0b1220; border-radius: 6px; display: grid; place-items: center; overflow: hidden; }
.screen-img img { width: 100%; height: 100%; object-fit: contain; }
.card.stat .stat-n { font-size: 26px; font-weight: 700; margin-top: 4px; }
.text-crit { color: var(--crit); } .text-warn { color: var(--warn, #d97706); }
.rc-err { max-width: min(720px, 100%); max-height: 220px; overflow: auto; text-align: left; white-space: pre-wrap; word-break: break-word; background: #0b1220; color: #fca5a5; border: 1px solid #7f1d1d; border-radius: 8px; padding: 10px 12px; font-size: 12px; margin: 0; }
.rc-spinner { width: 34px; height: 34px; border: 3px solid #1e293b; border-top-color: var(--accent); border-radius: 50%; animation: rc-spin 0.9s linear infinite; }
@keyframes rc-spin { to { transform: rotate(360deg); } }
.rc-menu { position: relative; }
.rc-menu-list { position: absolute; right: 0; top: 32px; z-index: 10; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 4px; display: grid; min-width: 180px; }
.rc-menu-list .btn { justify-content: flex-start; }

.screen { position: relative; background: #000; border-radius: 8px; overflow: hidden; min-height: 240px; display: grid; place-items: center; color: #94a3b8; }
.screen img { display: block; width: 100%; height: auto; cursor: crosshair; }
.screen .overlay { position: absolute; top: 10px; left: 10px; }

/* ---------- modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; width: min(620px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.35); border: 1px solid var(--border); }
.modal.wide { width: min(940px, 100%); }
.modal-h { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.modal-b { padding: 18px; overflow-y: auto; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--side); color: #fff; padding: 10px 14px; border-radius: 9px; font-size: 13px; box-shadow: 0 8px 30px rgba(0,0,0,.25); max-width: 380px; border-left: 3px solid var(--accent); }
.toast.err { border-left-color: var(--crit); } .toast.ok { border-left-color: var(--ok); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 20% -10%, rgba(37,99,235,.18), transparent), var(--bg); }
.auth .card { width: min(400px, 100%); padding: 28px; }
.auth .brand { color: var(--text); padding: 0 0 18px; }

.bulkbar { position: sticky; top: 64px; z-index: 4; background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 10px; padding: 8px 12px; margin-bottom: 12px; }
.policy-cat { border: 1px solid var(--border); border-radius: 10px; }
.policy-cat h3 { padding: 10px 14px; background: var(--panel-2); border-bottom: 1px solid var(--border); border-radius: 10px 10px 0 0; font-size: 13px; }
.policy-row { display: grid; grid-template-columns: 1fr 220px; gap: 12px; padding: 10px 14px; align-items: center; border-bottom: 1px solid var(--border); }
.policy-row:last-child { border-bottom: 0; }
@media (max-width: 700px) { .policy-row { grid-template-columns: 1fr; } }
.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.chip { font-size: 10.5px; padding: 1px 6px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.crumbs { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; font-size: 13px; }
.qr { background: #fff; padding: 12px; display: inline-block; border-radius: 8px; }
/* Commands wrap inside their card; the Copy button always copies the full text. */
.copy { display: flex; gap: 8px; align-items: flex-start; min-width: 0; }
.copy code { flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-all; line-height: 1.5; max-height: 12em; overflow-y: auto; }
.copy .btn { flex: none; }

/* Password fields: show/hide toggle */
.pw-wrap { position: relative; display: block; min-width: 0; }
.pw-wrap > input { width: 100%; padding-right: 38px; }
.pw-eye { position: absolute; right: 3px; top: 50%; transform: translateY(-50%); width: 30px; height: 28px; display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 6px; }
.pw-eye:hover { color: var(--text); background: var(--panel-2); }
.pw-eye svg { width: 17px; height: 17px; }

.remote-grid { grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr); }
.policy-grid { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
@media (max-width: 1000px) { .remote-grid, .policy-grid { grid-template-columns: minmax(0, 1fr); } }

.btn.warn-soft { background: var(--warn-soft); border-color: transparent; color: var(--warn); }

.rc-ripple { position: absolute; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%; border: 2px solid var(--accent); pointer-events: none; animation: rcRip .6s ease-out forwards; z-index: 5; }
@keyframes rcRip { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
