/* CDS Remote console. No external dependencies. */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #1c2330;
  --muted: #5f6b7a;
  --border: #dfe3e8;
  --input-bg: #ffffff;
  --input-border: #c9d0d8;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --accent-soft: #e6eefc;
  --ok: #16803c;
  --ok-soft: #e3f4e8;
  --warn: #9a6200;
  --warn-soft: #fbf0d9;
  --bad: #c0362c;
  --bad-soft: #fbe6e4;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
  --radius: 8px;
  --sidebar: #111827;
  --sidebar-text: #cbd2dc;
  --sidebar-active: #1f2a3c;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b;
    --panel: #161d27;
    --panel-2: #1c2531;
    --text: #e5e9ef;
    --muted: #93a0b0;
    --border: #2a3542;
    --input-bg: #0d1218;
    --input-border: #3b4859;
    --accent: #5b8def;
    --accent-text: #0b1220;
    --accent-soft: #1d2c47;
    --ok: #4cc07a;
    --ok-soft: #173325;
    --warn: #e0a83a;
    --warn-soft: #3a2e14;
    --bad: #f07167;
    --bad-soft: #3b1d1b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
    --sidebar: #0b1016;
    --sidebar-text: #aab4c2;
    --sidebar-active: #1a2330;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --panel: #161d27; --panel-2: #1c2531; --text: #e5e9ef; --muted: #93a0b0;
  --border: #2a3542; --input-bg: #0d1218; --input-border: #3b4859; --accent: #5b8def; --accent-text: #0b1220; --accent-soft: #1d2c47;
  --ok: #4cc07a; --ok-soft: #173325; --warn: #e0a83a; --warn-soft: #3a2e14; --bad: #f07167;
  --bad-soft: #3b1d1b; --sidebar: #0b1016; --sidebar-text: #aab4c2; --sidebar-active: #1a2330;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 16px 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; color: #fff; font-weight: 600; font-size: 15px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 700;
}
.nav { display: flex; flex-direction: column; padding: 4px 8px; gap: 1px; }
.nav a {
  color: var(--sidebar-text); padding: 8px 10px; border-radius: 6px; display: flex; gap: 10px; align-items: center;
}
.nav a:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav .sep { height: 1px; background: rgba(255, 255, 255, .08); margin: 8px 4px; }
.nav-ico { width: 18px; text-align: center; opacity: .85; }
.sidebar-foot { margin-top: auto; padding: 12px 16px; font-size: 11.5px; opacity: .75; }
.sidebar-foot a { color: inherit; text-decoration: underline; }

.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(--border);
  background: var(--panel); position: sticky; top: 0; z-index: 5;
}
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 20px 24px 40px; max-width: 1500px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.page-desc { color: var(--muted); margin: -8px 0 16px; max-width: 900px; }

.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.two { grid-template-columns: 1fr 1fr; }
.stat .num { font-size: 26px; font-weight: 600; margin-top: 4px; }
.stat .lbl { color: var(--muted); font-size: 12.5px; }

/* ---------- controls */
button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--panel); color: var(--text);
  padding: 7px 12px; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
button:hover { background: var(--panel-2); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
button.danger:hover { background: var(--bad-soft); }
button.link { border: none; background: none; padding: 2px 4px; color: var(--accent); }
button.small { padding: 4px 8px; font-size: 12.5px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--input-bg); border: 1px solid var(--input-border);
  border-radius: 6px; padding: 7px 10px; width: 100%; min-width: 0;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px;
}
input[type="checkbox"], input[type="radio"] { width: auto; }
.pw-wrap { position: relative; display: block; width: 100%; }
.pw-wrap > input { padding-right: 40px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  border: none; background: none; padding: 5px; border-radius: 5px; color: var(--muted); line-height: 0;
}
.pw-toggle:hover { color: var(--text); background: var(--panel-2); }
.pw-toggle svg { width: 18px; height: 18px; }
label.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-weight: 500; font-size: 13px; }
.field .help { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; max-width: 220px; }
.toolbar input[type="search"] { width: 280px; max-width: 100%; }
.content:focus { outline: none; }
.toolbar .spacer { flex: 1; }

/* ---------- table */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; font-size: 12.5px; color: var(--muted); background: var(--panel-2); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--panel-2); }
td.actions { white-space: nowrap; text-align: right; }
td.wrap { max-width: 340px; overflow-wrap: anywhere; }
td.os { min-width: 150px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 10px 2px; color: var(--muted); }
.pager select { width: auto; }

/* ---------- badges */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
}
.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.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.dot.on { background: var(--ok); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border); font-size: 12.5px;
}
.chip button { border: none; background: none; padding: 0 2px; color: var(--muted); }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid var(--border); }

/* ---------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  border: none; background: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 9px 14px; color: var(--muted);
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 500; }

/* ---------- modal / drawer */
.overlay {
  position: fixed; inset: 0; background: rgba(10, 14, 20, .45); z-index: 50; display: flex;
  align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  width: 100%; max-width: 560px; display: flex; flex-direction: column;
}
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); gap: 10px; }
.modal-head h2 { margin: 0; flex: 1; }
.modal-body { padding: 16px 18px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border); }
.picker { border: 1px solid var(--border); border-radius: 6px; max-height: 240px; overflow-y: auto; padding: 6px; }
.picker label { display: flex; gap: 8px; padding: 4px 6px; border-radius: 4px; align-items: center; }
.picker label:hover { background: var(--panel-2); }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 6px;
  box-shadow: var(--shadow); padding: 10px 14px; max-width: 380px;
}
.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }
.notice { padding: 10px 12px; border-radius: 6px; background: var(--accent-soft); margin-bottom: 12px; }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); }
.secret {
  font-family: var(--mono); background: var(--panel-2); padding: 10px; border-radius: 6px; overflow-wrap: anywhere;
  border: 1px dashed var(--border); user-select: all;
}

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login-title { font-size: 16px; margin: 0 0 8px; }
.login-foot { text-align: center; margin-top: 12px; }
.login .brand { color: var(--text); padding: 0 0 16px; justify-content: center; font-size: 18px; }

/* ---------- shell: icon buttons, table tools, theme toggle, collapsible sidebar, QR */
.ico { display: inline-flex; line-height: 0; }
.ico svg { width: 18px; height: 18px; }
button.icon-btn { padding: 6px; line-height: 0; color: var(--muted); }
button.icon-btn:hover { color: var(--text); }
button.icon-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.table-tools { display: inline-flex; gap: 4px; align-items: center; }
.icon-btn.spin svg { animation: cds-spin .8s linear infinite; }
@keyframes cds-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .icon-btn.spin svg { animation: none; } }
.col-chooser { position: relative; }
.col-menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 200px; max-height: 360px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px; display: flex; flex-direction: column;
}
.col-menu label.check { padding: 5px 8px; border-radius: 4px; white-space: nowrap; }
.col-menu label.check:hover { background: var(--panel-2); }
.col-menu-head { color: var(--muted); font-size: 12px; padding: 4px 8px 6px; }
.col-menu-foot { border-top: 1px solid var(--border); margin-top: 4px; padding: 4px 4px 0; text-align: right; }
.table-wrap.dense th, .table-wrap.dense td { padding: 4px 10px; }
.login-wrap { position: relative; }
.login-corner { position: absolute; top: 16px; right: 16px; }

/* collapsed sidebar (desktop only; mobile keeps the slide-in menu) */
@media (min-width: 901px) {
  .app.nav-collapsed { grid-template-columns: 60px 1fr; }
  .nav-collapsed .brand { justify-content: center; padding: 18px 0; }
  .nav-collapsed .brand-name, .nav-collapsed .nav-label, .nav-collapsed .sidebar-foot { display: none; }
  .nav-collapsed .nav a { justify-content: center; padding: 9px 0; }
  .nav-collapsed .nav-ico { width: auto; font-size: 16px; }
}

/* dashboard: Config & QR code */
.qr-box { display: inline-block; background: #fff; padding: 8px; border-radius: 8px; border: 1px solid var(--border); line-height: 0; }
.qr-box svg { display: block; max-width: 100%; height: auto; }
.cfg-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 12px; }

/* ---------- responsive */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 240px; z-index: 40; transform: translateX(-100%); transition: transform .15s; }
  .app.nav-open .sidebar { transform: none; }
  .menu-btn { display: inline-flex; }
  .collapse-btn { display: none; }
  .cfg-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .two { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .toolbar input[type="search"], .toolbar select { max-width: none; flex: 1 1 140px; }
  .hide-sm { display: none; }
}

/* ---------- users-devices */
.more-filters-btn.active { border-color: var(--accent); color: var(--accent); }
.more-filters { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); padding: 12px 12px 4px; margin-bottom: 12px; }
.more-filters-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0 12px; }
.more-filters-grid .field { margin-bottom: 8px; }
.more-filters .row { margin-bottom: 8px; }
.menu-pop {
  position: absolute; z-index: 60; min-width: 200px; display: flex; flex-direction: column; padding: 4px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.menu-pop button { border: none; background: none; text-align: left; justify-content: flex-start; padding: 7px 10px; border-radius: 6px; }
.menu-pop button:hover:not(:disabled), .menu-pop button:focus-visible { background: var(--panel-2); }
td.row-actions { width: 1%; white-space: nowrap; text-align: right; }
.dev-id { display: flex; align-items: center; white-space: nowrap; }
td.dev-info { min-width: 150px; max-width: 220px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-foot:has(> .row) { flex-wrap: wrap; }
.assign-devices .toolbar input[type="search"] { width: 220px; }
.tfa-steps { padding-left: 18px; }
.tfa-steps li { margin-bottom: 8px; }
/* ---------- logs-ab-strat */
.audit-filters {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 12px;
  margin-bottom: 12px; padding: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
}
.audit-filter { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
.audit-filter-btn { justify-content: flex-end; align-items: flex-start; }
.audit-raw { white-space: pre-wrap; font-size: 12px; margin: 0; }
th.num, td.num { text-align: right; white-space: nowrap; }
.ab-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.ab-head h2 { margin: 0; }
.ab-head .spacer { flex: 1; }
.ab-tagbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px; }
.ab-tagchip {
  --tag: var(--muted);
  display: inline-flex; align-items: center; border: 1px solid var(--border); border-left: 4px solid var(--tag);
  border-radius: 999px; background: var(--panel); overflow: hidden;
}
.ab-tagchip.on { background: var(--accent-soft); border-color: var(--accent); border-left-color: var(--tag); }
.ab-tagchip button { border: none; background: none; border-radius: 0; padding: 3px 8px; font-size: 12.5px; }
.ab-tagchip .ab-tagname { gap: 6px; }
.ab-tagchip .ab-tagx { padding: 3px 5px; color: var(--muted); }
.ab-tagchip .ab-tagx:hover { color: var(--text); }
.chip.ab-tag { border-left: 4px solid var(--tag, var(--border)); }
.devpicker .table-wrap { max-height: 55vh; overflow-y: auto; }
/* ---------- roles-account-settings */
.wizard-steps { display: flex; gap: 8px; margin-bottom: 14px; }
.wizard-steps span { flex: 1; padding: 6px 10px; border-radius: 6px; background: var(--panel-2); color: var(--muted); font-size: 13px; }
.wizard-steps span.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.role-types { display: grid; gap: 8px; }
.role-type { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; }
.role-type > span { display: flex; flex-direction: column; gap: 2px; }
.role-type.active { border-color: var(--accent); background: var(--accent-soft); }
.role-type input { margin-top: 3px; }
.role-scope { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; }
.role-scope h3 { margin: 0 0 8px; }
.perm-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 8px; }
.perm-head h3 { margin: 0; flex: 1; }
.perm-matrix th { width: 140px; vertical-align: top; text-align: left; white-space: nowrap; }
.perm-levels { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.perm-levels label.check { font-size: 13px; }
.session-list { display: flex; flex-direction: column; }
.session-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--border); }
.session-item:first-child { border-top: none; }
.session-main { flex: 1; min-width: 0; }
.session-main .badge { margin-left: 8px; }
.session-kv { margin: 6px 0 0; font-size: 13px; }
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.preset { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; text-align: left; }
@media (max-width: 700px) {
  .perm-matrix th { width: auto; white-space: normal; }
  .session-item { flex-direction: column; }
}
