:root {
  color-scheme: dark;
  --bg: #050607;
  --panel: #0b0d10;
  --panel-2: #111419;
  --panel-3: #171b20;
  --line: transparent;
  --line-strong: transparent;
  --text: #f6f7f9;
  --muted: #9299a6;
  --soft: #c6cbd3;
  --accent: #d7dbe0;
  --accent-2: #a8b0ba;
  --green: #32d583;
  --yellow: #fdb022;
  --red: #f97066;
  --blue: #53b1fd;
  --shadow: 0 22px 70px rgba(0,0,0,.48);
  --radius: 18px;
  --radius-sm: 12px;
  font-family: "Manrope", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.boot-screen {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  color: var(--muted);
}
.boot-screen h1 { margin: 0; color: var(--text); font-size: 24px; }
.boot-screen p { margin: 0; }
.boot-mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  animation: breathe 1.6s ease-in-out infinite;
}
.boot-mark img { width: 46px; height: 52px; object-fit: contain; display: block; }
@keyframes breathe { 50% { transform: scale(.96); opacity: .65; } }

.shell { min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  border-bottom: 0;
  background: rgba(5,6,7,.94);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 32px;
  height: 36px;
  display: grid;
  place-items: center;
}
.brand-mark img { width: 27px; height: 30px; object-fit: contain; display: block; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.user-chip {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  color: var(--soft);
  background: rgba(255,255,255,.025);
  font-size: 13px;
}
.user-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(50,213,131,.1); }

.page {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 34px 32px 64px;
}
.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}
.page-heading h1 { margin: 0 0 7px; font-size: clamp(26px, 3vw, 38px); letter-spacing: -.04em; }
.page-heading p { margin: 0; color: var(--muted); font-size: 14px; }
.heading-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 0;
  border-radius: 11px;
  background: var(--panel-2);
  cursor: pointer;
  transition: background .18s ease, transform .18s ease, opacity .18s ease;
  font-weight: 650;
  font-size: 13px;
}
.btn:hover { background: var(--panel-3); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #090a0c; }
.btn-primary:hover { background: #eef0f2; }
.btn-danger { color: #ffb4ad; border-color: rgba(249,112,102,.24); background: rgba(249,112,102,.08); }
.btn-danger:hover { background: rgba(249,112,102,.14); border-color: rgba(249,112,102,.4); }
.btn-ghost { background: transparent; }
.btn-icon { width: 40px; padding: 0; }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.overview-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 14px;
  margin-bottom: 26px;
}
.card {
  border: 0;
  border-radius: var(--radius);
  background: var(--panel);
}
.metric-card { min-height: 176px; padding: 20px; position: relative; overflow: hidden; }
.metric-card::after { display: none; }
.metric-label { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: none; letter-spacing: 0; }
.metric-value { margin-top: 26px; font-size: 31px; line-height: 1; letter-spacing: -.045em; font-weight: 750; }
.metric-sub { margin-top: 10px; color: var(--muted); font-size: 13px; }
.metric-row { display: flex; gap: 22px; margin-top: 18px; }
.metric-pair strong { display: block; font-size: 16px; }
.metric-pair span { color: var(--muted); font-size: 11px; }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 0;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .02em;
  white-space: nowrap;
}
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-live { color: var(--green); background: rgba(50,213,131,.08); border-color: rgba(50,213,131,.2); }
.status-waiting { color: var(--yellow); background: rgba(253,176,34,.08); border-color: rgba(253,176,34,.2); }
.status-error { color: var(--red); background: rgba(249,112,102,.08); border-color: rgba(249,112,102,.2); }
.status-disabled { color: var(--muted); }
.status-connecting { color: var(--blue); background: rgba(83,177,253,.08); border-color: rgba(83,177,253,.2); }
.capacity-track { height: 7px; margin-top: 20px; border-radius: 999px; background: rgba(255,255,255,.07); overflow: hidden; }
.capacity-fill { width: 0; height: 100%; border-radius: inherit; background: #89939f; transition: width .35s ease; }
.capacity-fill.warning { background: var(--red); }

.section-card { overflow: visible; }
.section-header {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 0;
}
.section-title { display: flex; align-items: baseline; gap: 10px; }
.section-title h2 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.section-title span { color: var(--muted); font-size: 12px; }
.table-head, .partner-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) minmax(170px, 1fr) 140px 110px 132px;
  align-items: center;
  gap: 18px;
}
.table-head {
  min-height: 42px;
  padding: 0 20px;
  color: #737b89;
  border-bottom: 0;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: none;
}
.partner-row {
  min-height: 84px;
  padding: 13px 20px;
  border-bottom: 0;
  transition: background .18s ease;
}
.partner-row:last-child { border-bottom: 0; }
.partner-row:hover { background: var(--panel-2); transform: translateX(2px); }
.partner-main { min-width: 0; display: flex; align-items: center; gap: 13px; }
.partner-avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: #cbd0d6;
  background: #15191e;
  font-size: 14px;
  font-weight: 800;
}
.partner-name { overflow: hidden; }
.partner-name strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.partner-name span { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.destination { min-width: 0; }
.destination strong, .destination span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.destination strong { color: var(--soft); font-size: 12px; font-weight: 600; }
.destination span { margin-top: 5px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.relay-metric strong { display: block; font-size: 13px; }
.relay-metric span { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.row-actions { display: flex; justify-content: flex-end; gap: 7px; }
.action-menu { position: relative; }
.menu-popover {
  position: fixed;
  z-index: 1000;
  width: 180px;
  padding: 6px;
  border: 0;
  border-radius: 12px;
  background: var(--panel-2);
  box-shadow: var(--shadow);
}
.menu-popover button { width: 100%; min-height: 36px; justify-content: flex-start; border: 0; background: transparent; border-radius: 8px; padding: 0 10px; color: var(--soft); cursor: pointer; text-align: left; font-size: 12px; }
.menu-popover button:hover { background: rgba(255,255,255,.06); color: white; }
.menu-popover button.danger { color: #ffb4ad; }
.empty-state { min-height: 310px; display: grid; place-content: center; justify-items: center; padding: 40px; text-align: center; }
.empty-icon { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 18px; color: var(--accent-2); background: rgba(139,92,246,.08); border: 1px solid rgba(139,92,246,.14); }
.empty-icon svg { width: 27px; height: 27px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.empty-state h3 { margin: 18px 0 8px; font-size: 17px; }
.empty-state p { max-width: 380px; margin: 0 0 18px; color: var(--muted); font-size: 13px; line-height: 1.55; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0,0,0,.66);
  backdrop-filter: blur(8px);
}
.modal {
  width: min(560px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
  border: 0;
  border-radius: 20px;
  background: #111318;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-wide { width: min(760px, 100%); }
.modal-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 22px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 22px; overflow: auto; }
.modal-footer { min-height: 72px; display: flex; align-items: center; justify-content: flex-end; gap: 9px; padding: 0 22px; border-top: 1px solid var(--line); }
.form-grid { display: grid; gap: 17px; }
.field { display: grid; gap: 8px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label { color: var(--soft); font-size: 12px; font-weight: 700; }
.field input {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border: 0;
  border-radius: 11px;
  background: #0c0e12;
  color: var(--text);
  transition: border-color .18s ease, background .18s ease;
}
.field input:hover { border-color: rgba(255,255,255,.24); }
.field input:focus { border-color: var(--accent); background: #0a0b0e; }
.field small { color: var(--muted); font-size: 11px; line-height: 1.45; }
.switch-row { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 14px; border: 0; border-radius: 12px; background: rgba(255,255,255,.02); }
.switch-copy strong { display: block; font-size: 12px; }
.switch-copy span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.switch { position: relative; width: 42px; height: 24px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #333842; cursor: pointer; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: white; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }

.secret-grid { display: grid; gap: 12px; }
.secret-item { display: grid; grid-template-columns: 120px minmax(0,1fr) 38px; align-items: center; gap: 10px; min-height: 48px; padding: 0 10px 0 14px; border: 0; border-radius: 12px; background: #0c0e12; }
.secret-item > span:first-child { color: var(--muted); font-size: 11px; }
.secret-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.profile-note { margin-top: 17px; padding: 14px; border: 1px solid rgba(83,177,253,.16); border-radius: 12px; background: rgba(83,177,253,.06); color: #c7e7ff; font-size: 12px; line-height: 1.55; }
.warning-note { margin-bottom: 17px; padding: 14px; border: 1px solid rgba(253,176,34,.18); border-radius: 12px; background: rgba(253,176,34,.07); color: #fbdca0; font-size: 12px; line-height: 1.5; }

.audit-list { display: grid; gap: 9px; }
.audit-item { display: grid; grid-template-columns: 132px 1fr auto; gap: 14px; align-items: center; min-height: 50px; padding: 10px 12px; border: 0; border-radius: 11px; background: rgba(255,255,255,.018); }
.audit-time { color: var(--muted); font-size: 10px; }
.audit-action { font-size: 12px; }
.audit-user { color: var(--muted); font-size: 10px; }
.log-box { margin-top: 12px; padding: 11px 13px; border: 0; border-radius: 10px; background: #090a0d; color: #aab2bf; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }

.toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 150; display: grid; gap: 9px; width: min(360px, calc(100vw - 40px)); }
.toast { padding: 13px 15px; border: 0; border-radius: 12px; background: #1a1d23; box-shadow: var(--shadow); color: var(--soft); font-size: 12px; animation: toast-in .2s ease-out; }
.toast.error { border-color: rgba(249,112,102,.35); color: #ffd0cb; }
.toast.success { border-color: rgba(50,213,131,.3); color: #b7f4d3; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.skeleton { position: relative; overflow: hidden; background: rgba(255,255,255,.045); border-radius: 8px; color: transparent !important; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.08), transparent); animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }

@media (max-width: 1060px) {
  .overview-grid { grid-template-columns: 1fr 1fr; }
  .overview-grid .metric-card:first-child { grid-column: 1 / -1; }
  .table-head { display: none; }
  .partner-row { grid-template-columns: minmax(0,1fr) auto; gap: 14px; }
  .partner-row > .destination, .partner-row > .relay-metric { display: none; }
  .partner-row > .status-cell { justify-self: end; }
  .row-actions { grid-column: 2; }
}
@media (max-width: 700px) {
  .topbar { height: 64px; padding: 0 16px; }
  .brand-copy span, .user-chip span { display: none; }
  .user-chip { width: 38px; justify-content: center; padding: 0; }
  .page { padding: 24px 16px 48px; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .heading-actions { justify-content: stretch; }
  .heading-actions .btn { flex: 1; }
  .overview-grid { grid-template-columns: 1fr; }
  .overview-grid .metric-card:first-child { grid-column: auto; }
  .metric-card { min-height: 154px; }
  .section-header { padding: 12px 14px; flex-wrap: wrap; }
  .partner-row { padding: 14px; min-height: 90px; }
  .partner-avatar { width: 38px; height: 38px; }
  .row-actions { grid-column: auto; }
  .status-cell { display: none; }
  .field-row { grid-template-columns: 1fr; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { width: 100%; max-height: 92vh; border-radius: 20px 20px 0 0; }
  .secret-item { grid-template-columns: 88px minmax(0,1fr) 38px; }
  .audit-item { grid-template-columns: 1fr auto; }
  .audit-time { grid-column: 1 / -1; }
}

.menu-portal { width: 180px; right: auto; }
.partner-row { position: relative; z-index: 1; }
.partner-row:hover { z-index: 2; }
.action-menu { position: relative; z-index: 3; }
