/* i2v Central admin UI. No external fonts or libraries: the page runs under a
   CSP that only allows files served by central itself. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e7eaef;
  --border: #dfe3e8;
  --border-strong: #c9ced6;
  --text: #16191d;
  --muted: #5b6573;
  --faint: #8a93a0;
  --accent: #2f5bea;
  --accent-hover: #2449c7;
  --accent-soft: #e8eefd;
  --on-accent: #ffffff;
  --green: #17794a;
  --green-soft: #e3f3ea;
  --amber: #93590a;
  --amber-soft: #fcf0da;
  --red: #b3261e;
  --red-soft: #fcebea;
  --grey-soft: #eceef1;
  --focus: 0 0 0 3px rgba(47, 91, 234, .28);
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1e232a;
    --surface-3: #262c35;
    --border: #2b323c;
    --border-strong: #3a424e;
    --text: #e7eaee;
    --muted: #a0a9b6;
    --faint: #737d8a;
    --accent: #6d8ff7;
    --accent-hover: #88a4fa;
    --accent-soft: #1d2744;
    --on-accent: #0b1020;
    --green: #4cc38a;
    --green-soft: #13301f;
    --amber: #e3a94f;
    --amber-soft: #33260f;
    --red: #f07b72;
    --red-soft: #3a1714;
    --grey-soft: #242a32;
    --focus: 0 0 0 3px rgba(109, 143, 247, .35);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.boot { padding: 48px; text-align: center; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  cursor: pointer; font-weight: 500; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, var(--border)); }
.btn.danger:hover:not(:disabled) { background: var(--red-soft); }
.btn.danger.solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 28px; padding: 0; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--muted); border-top-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- form fields ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label, .label { font-weight: 600; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12.5px; }
.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
}
.textarea { height: auto; min-height: 84px; padding: 8px 10px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input[readonly] { background: var(--surface-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.segmented button {
  border: 0; background: var(--surface); padding: 0 14px; height: 34px; cursor: pointer; font-weight: 500;
}
.segmented button + button { border-left: 1px solid var(--border-strong); }
.segmented button.on { background: var(--accent-soft); color: var(--accent); }
.form-error {
  background: var(--red-soft); color: var(--red); border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 13px;
}

/* ---------- sign-in ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 28px;
}
.auth-card h1 { font-size: 20px; margin: 14px 0 4px; }
.auth-card .lead { color: var(--muted); margin: 0 0 20px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px; background: var(--accent); display: grid; place-items: center;
}
.brand-mark::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--on-accent);
  box-shadow: inset 0 0 0 3px var(--accent), inset 0 0 0 6px var(--on-accent);
}

/* ---------- app shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1320px; margin: 0 auto; padding: 0 20px; height: 56px;
  display: flex; align-items: center; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand .brand-mark { width: 28px; height: 28px; border-radius: 7px; }
.brand .brand-mark::before { width: 11px; height: 11px; border-width: 2px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: none; height: 56px; padding: 0 12px; cursor: pointer; color: var(--muted);
  font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.tab .tag { margin-left: 6px; }
.usermenu { position: relative; }
.user-btn {
  display: flex; align-items: center; gap: 10px; border: 1px solid transparent; background: none;
  border-radius: var(--radius-sm); padding: 4px 8px; cursor: pointer; text-align: left;
}
.user-btn:hover { background: var(--surface-2); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; text-transform: uppercase;
}
.user-btn .who { line-height: 1.2; }
.user-btn .who small { display: block; color: var(--muted); font-size: 12px; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 6px; z-index: 30;
}
.dropdown button {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px;
  border-radius: var(--radius-sm); cursor: pointer;
}
.dropdown button:hover { background: var(--surface-2); }
.dropdown hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding-top: 8px; gap: 8px 12px; }
  .tabs { order: 3; width: 100%; }
  .tab { height: 44px; }
  .user-btn .who { display: none; }
}

main { max-width: 1320px; margin: 0 auto; padding: 24px 20px 64px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- stat cards ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.stat .k { color: var(--muted); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stat .v { font-size: 26px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 14px; color: var(--muted); font-weight: 500; }
.stat .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stat.good .v { color: var(--green); }
.stat.warn .v { color: var(--amber); }
.stat.bad .v { color: var(--red); }

/* ---------- quota banner ---------- */
.quota {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 16px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}
.quota .txt { min-width: 220px; }
.quota .txt strong { font-size: 15px; }
.quota .bar { flex: 1; min-width: 200px; }
.quota.full { border-color: color-mix(in srgb, var(--red) 45%, var(--border)); }

.bar { height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; }
.bar.warn > span { background: var(--amber); }
.bar.bad > span { background: var(--red); }
.bar.sm { height: 6px; }
.meter { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.meter .bar { flex: 1; min-width: 56px; }
.meter .n { font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 12.5px; color: var(--muted); }

/* ---------- toolbar ---------- */
.toolbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0; padding: 10px;
}
.search { position: relative; flex: 1; min-width: 220px; }
.search .input { padding-left: 34px; }
.search::before {
  content: ""; position: absolute; left: 12px; top: 50%; width: 11px; height: 11px; margin-top: -7px;
  border: 2px solid var(--faint); border-radius: 50%;
}
.search::after {
  content: ""; position: absolute; left: 23px; top: 50%; width: 2px; height: 6px; margin-top: 3px;
  background: var(--faint); transform: rotate(-45deg);
}
.toolbar .select { width: auto; min-width: 130px; }

/* ---------- tables ---------- */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-x: auto; box-shadow: var(--shadow);
}
.toolbar + .table-wrap { border-radius: 0 0 var(--radius) var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border); }
th {
  font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
  background: var(--surface-2); white-space: nowrap; position: sticky; top: 0;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
td.actions { text-align: right; white-space: nowrap; }
td.actions .btn + .btn { margin-left: 6px; }
.cell-title { font-weight: 600; }
.cell-title .tag { margin-left: 6px; }
.cell-sub { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 4px; }
.empty { text-align: center; padding: 44px 16px !important; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }
.pager {
  display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 10px 2px; color: var(--muted);
}

/* ---------- pills, dots, tags ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px; border-radius: 99px;
  font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--grey-soft); color: var(--muted);
}
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.blue { background: var(--accent-soft); color: var(--accent); }
.tag {
  display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 700;
  letter-spacing: .03em; background: var(--surface-3); color: var(--muted); vertical-align: 1px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); display: inline-block; flex: none; }
.dot.green { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.dot.red { background: var(--red); }
.dot.amber { background: var(--amber); }
.conn { display: flex; align-items: center; gap: 8px; }
.conn small { display: block; color: var(--muted); font-size: 12px; }
.copy {
  border: 0; background: none; padding: 2px 4px; border-radius: 4px; cursor: pointer; color: var(--faint);
  font-size: 11px; font-weight: 600;
}
.copy:hover { background: var(--surface-3); color: var(--text); }

/* ---------- cards / panels ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; min-width: 0;
}
.card h3 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card > p.muted { margin: 0 0 14px; }
.cards-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
@media (max-width: 520px) { .cards-2 { grid-template-columns: 1fr; } }
.notice {
  border-radius: var(--radius); padding: 12px 14px; background: var(--accent-soft); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); margin-bottom: 16px;
}
.notice.warn { background: var(--amber-soft); border-color: color-mix(in srgb, var(--amber) 30%, transparent); }
.notice.bad { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 30%, transparent); }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 520px) { .kv { grid-template-columns: 1fr; gap: 2px 0; } .kv dd { margin-bottom: 8px; } }
.section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  margin: 4px 0 10px;
}
.divider { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

/* ---------- response viewer (device tester) ---------- */
.response { margin-top: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.response-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); font-size: 12.5px;
}
.response pre, pre.code {
  margin: 0; padding: 10px 12px; max-height: 320px; overflow: auto; font-family: var(--mono); font-size: 12px;
  white-space: pre-wrap; word-break: break-all; background: var(--surface);
}
pre.code { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }

/* ---------- secrets ---------- */
.secret { display: flex; gap: 6px; align-items: stretch; }
.secret .input { font-family: var(--mono); font-size: 12.5px; }

/* ---------- modal ---------- */
.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 16px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 560px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border); animation: pop .14s ease-out;
}
.modal.wide { max-width: 760px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 0; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-head p { margin: 4px 0 0; color: var(--muted); }
.modal-body { padding: 16px 20px; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border);
  background: var(--surface-2); border-radius: 0 0 14px 14px; flex-wrap: wrap;
}

/* ---------- status chooser (relays) ---------- */
.choices { display: grid; gap: 8px; }
.choice {
  display: flex; gap: 12px; align-items: flex-start; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; background: var(--surface); text-align: left; cursor: pointer; width: 100%;
}
.choice:hover { border-color: var(--border-strong); background: var(--surface-2); }
.choice.on { border-color: var(--accent); background: var(--accent-soft); cursor: default; }
.choice strong { display: block; }
.choice span { color: var(--muted); font-size: 12.5px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); max-width: 380px; animation: pop .14s ease-out;
}
.toast.bad { background: var(--red); color: #fff; }
