:root {
  --bg: #eef2ff;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --danger: #dc2626;
  --success: #059669;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: #111827;
  color: #fff;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-sub {
  opacity: 0.86;
  font-size: 13px;
}

.topbar-link {
  color: #fff;
  text-decoration: none;
  background: #374151;
  padding: 6px 10px;
  border-radius: 8px;
}

.dashboard-wrap {
  max-width: 1400px;
  margin: 16px auto;
  padding: 0 12px 24px;
  display: grid;
  gap: 14px;
}

.panel {
  background: var(--card);
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 14px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.04);
}

.kpi-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.kpi {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px;
}

.kpi label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.kpi strong {
  font-size: 22px;
}

.kpi small {
  display: block;
  color: #475569;
  margin-top: 6px;
}

h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.two-col,
.split-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 10px;
  align-items: center;
}

.form-grid label,
.field-inline label,
.subs-form label {
  font-size: 13px;
  color: #374151;
}

input,
select,
button {
  width: 100%;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  padding: 8px 10px;
  color: #111827;
  background: #fff;
}

button {
  background: var(--primary);
  border: none;
  color: #fff;
  cursor: pointer;
}

button.small {
  width: auto;
  min-width: 58px;
  padding: 6px 8px;
  font-size: 12px;
}

button.danger {
  background: var(--danger);
}


button.primary {
  background: var(--primary);
  color: #fff;
  border: none;
}

.modal-mask {
  position: fixed;
  z-index: 1200;
  inset: 0;
  display: none;
  background: rgba(15, 23, 42, 0.46);
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal-mask.show {
  display: flex;
}

.confirm-modal {
  width: min(480px, 90vw);
  background: #fff;
  border-radius: 10px;
  padding: 16px;
  border: 1px solid #e5e7eb;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.2);
}

.confirm-body {
  margin-bottom: 14px;
  color: #0f172a;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.ui-feedback {
  position: fixed;
  z-index: 1300;
  top: 14px;
  right: 14px;
  max-width: min(380px, calc(100vw - 28px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  opacity: 0;
  transform: translateY(-10px);
  color: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.2);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.toast.hide {
  opacity: 0;
  transform: translateY(-6px);
}

.toast-error {
  background: var(--danger);
}

.toast-success {
  background: var(--success);
}

.toast-info {
  background: #2563eb;
}

button.ghost {
  background: #f1f5f9;
  color: #0f172a;
  border: 1px solid var(--line);
  width: auto;
}

form {
  margin: 0;
}

.inline,
.actions-row {
  display: inline-block;
}

.inline form,
.inline {
  display: inline;
}

.actions-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.note,
.hint,
.muted {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.code-inline {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 6px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  max-height: 320px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 720px;
}

table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  text-align: left;
  font-weight: 600;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid #eef2ff;
  vertical-align: top;
}

.pill {
  display: inline-block;
  border-radius: 9999px;
  padding: 2px 8px;
  font-size: 12px;
  color: #fff;
}

.pill-on {
  background: #059669;
}

.pill-off {
  background: #ef4444;
}

.cell-small {
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.webhook-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.inline-btn {
  width: auto;
  min-width: 0;
  background: #e2e8f0;
  color: #0f172a;
  border: 1px solid #d1d5db;
  font-size: 12px;
  padding: 4px 8px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.subs-form {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(320px, 1fr);
  gap: 10px;
  align-items: start;
  margin-bottom: 10px;
}

.field-inline {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-direction: column;
  align-items: flex-start;
}

.field-inline.wide {
  grid-row: span 2;
}

.field-inline select {
  margin-top: 0;
}

.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.checkbox-line input[type="checkbox"] {
  width: 14px;
  height: 14px;
}

#expire-at:disabled {
  background: #f3f4f6;
  color: #94a3b8;
  cursor: not-allowed;
}

.auth-card {
  max-width: 360px;
  margin: 80px auto;
  background: var(--card);
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
}

.auth-card h1 {
  margin: 0 0 10px;
  font-size: 20px;
}

.auth-card .field {
  margin-bottom: 10px;
}

.auth-card .error {
  margin-top: 10px;
  color: var(--danger);
}

@media (max-width: 1100px) {
  .two-col,
  .split-grid,
  .kpi-bar {
    grid-template-columns: 1fr;
  }

  .subs-form {
    grid-template-columns: 1fr;
  }

  .field-inline {
    width: 100%;
  }
}


.modal-wide {
  width: min(860px, 94vw);
  max-height: 88vh;
  overflow: auto;
}

.form-actions-span {
  grid-column: 1 / -1;
}

.log-modal {
  width: min(980px, 94vw);
}

.log-pre {
  max-height: 62vh;
  overflow: auto;
  margin: 10px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #0f172a;
  color: #dbeafe;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.member-edit-btn,
.node-edit-btn {
  margin-right: 4px;
  margin-bottom: 4px;
}

td .inline,
td .inline button,
td > button.small {
  margin: 0 4px 4px 0;
}

.cell-small[title] {
  cursor: help;
}

#edit-member-expire:disabled,
#expire-at:disabled {
  background: #f3f4f6;
  color: #94a3b8;
  cursor: not-allowed;
}

@media (max-width: 680px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  .confirm-actions,
  .actions-row {
    flex-wrap: wrap;
  }
}


/* v9: sidebar admin layout */
body {
  background: #eef2f7;
}

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #0f172a;
  color: #e5e7eb;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.side-brand {
  padding: 4px 6px 14px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}

.side-brand strong {
  display: block;
  color: #fff;
  font-size: 17px;
  margin-bottom: 5px;
}

.side-brand small {
  color: #94a3b8;
}

.side-nav {
  display: grid;
  gap: 6px;
}

.side-nav a,
.side-logout {
  color: #cbd5e1;
  text-decoration: none;
  border-radius: 10px;
  padding: 10px 12px;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}

.side-nav a:hover,
.side-logout:hover {
  background: rgba(148, 163, 184, .14);
  color: #fff;
}

.side-nav a.active {
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  box-shadow: 0 10px 22px rgba(37, 99, 235, .28);
}

.side-logout {
  margin-top: auto;
  display: block;
  background: rgba(239, 68, 68, .12);
  color: #fecaca;
}

.admin-main {
  min-width: 0;
  padding: 22px;
  display: grid;
  align-content: start;
  gap: 16px;
}

.admin-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.05);
}

.admin-top h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.admin-top p {
  margin: 0;
  color: var(--muted);
}

.top-status {
  white-space: nowrap;
  color: #1e3a8a;
  background: #dbeafe;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 13px;
}

.admin-card {
  border-radius: 14px;
  padding: 18px;
}

.admin-kpis {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
}

.quick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.quick-grid a {
  display: block;
  text-decoration: none;
  color: #0f172a;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px;
  font-weight: 600;
}

.quick-grid a:hover {
  border-color: #93c5fd;
  background: #eff6ff;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.create-drawer {
  border: 1px solid #dbe3ef;
  background: #f8fafc;
  border-radius: 12px;
  margin: 12px 0 14px;
  overflow: hidden;
}

.create-drawer summary {
  cursor: pointer;
  padding: 12px 14px;
  font-weight: 700;
  color: #0f172a;
}

.drawer-form {
  padding: 0 14px 14px;
  max-width: 760px;
}

.admin-table {
  max-height: calc(100vh - 260px);
  background: #fff;
}

.admin-table table {
  min-width: 920px;
}

.admin-main .table-wrap {
  border-radius: 12px;
}

@media (max-width: 860px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
  }
  .side-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .side-logout {
    margin-top: 0;
  }
  .admin-main {
    padding: 12px;
  }
  .admin-top {
    flex-direction: column;
  }
  .top-status {
    white-space: normal;
  }
}


/* v10: node create radio controls */
.radio-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.radio-grid-exchange {
  max-width: 720px;
}

.radio-grid-compact {
  max-width: 260px;
}

.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 0;
  cursor: pointer;
  user-select: none;
}

.radio-pill input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.radio-pill span {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #334155;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s ease;
}

.radio-pill:hover span {
  border-color: #93c5fd;
  background: #eff6ff;
}

.radio-pill input[type="radio"]:checked + span {
  border-color: #2563eb;
  background: #2563eb;
  color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, .22);
}

.radio-pill input[type="radio"]:focus-visible + span {
  outline: 2px solid #93c5fd;
  outline-offset: 2px;
}


/* v11: subscription dual-list binding */
.subscription-board {
  display: grid;
  grid-template-columns: minmax(280px, 0.85fr) minmax(420px, 1.4fr);
  gap: 14px;
  align-items: stretch;
  margin: 14px 0;
}

.bind-column {
  min-width: 0;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: #f8fafc;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.bind-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
}

.bind-head span {
  color: #64748b;
  background: #eef2ff;
  border: 1px solid #dbe3ff;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
}

.bind-list {
  padding: 10px;
  display: grid;
  gap: 8px;
  max-height: min(58vh, 520px);
  overflow: auto;
}

.bind-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  cursor: pointer;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
  padding: 11px;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}

.bind-row:hover {
  border-color: #93c5fd;
  background: #eff6ff;
}

.bind-row input {
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

.bind-row b {
  display: block;
  color: #0f172a;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.bind-row small {
  display: block;
  margin-top: 4px;
  color: #64748b;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.bind-row:has(input:checked) {
  border-color: #2563eb;
  background: #eff6ff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, .12);
}

.bind-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.bind-actions button {
  width: auto;
}

.empty-state {
  color: #64748b;
  background: #fff;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  padding: 14px;
}

@media (max-width: 980px) {
  .subscription-board {
    grid-template-columns: 1fr;
  }
}


/* v12: signal list filters */
.bind-head-with-filters {
  align-items: flex-start;
  gap: 12px;
}

.bind-head-with-filters > div:first-child {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: max-content;
}

.signal-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.signal-filters label {
  display: grid;
  gap: 4px;
  color: #64748b;
  font-size: 12px;
  font-weight: 600;
}

.signal-filters select {
  width: 150px;
  min-height: 34px;
  padding: 6px 28px 6px 10px;
  border-radius: 9px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #0f172a;
  font-size: 13px;
}

.node-bind-row.hidden-by-filter {
  display: none;
}

@media (max-width: 1120px) {
  .bind-head-with-filters {
    flex-direction: column;
  }
  .signal-filters {
    justify-content: flex-start;
    width: 100%;
  }
}


/* v13: one-member-one-row subscription summary */
.subscription-summary-table {
  margin-top: 14px;
  max-height: min(52vh, 520px);
}

.subscription-summary-table table {
  min-width: 860px;
}

.sub-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 28px;
  border-radius: 999px;
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 800;
}

.sub-detail-drawer summary {
  cursor: pointer;
  color: #1d4ed8;
  font-weight: 700;
}

.sub-detail-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  max-width: 780px;
}

.sub-detail-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  padding: 9px 10px;
}

.sub-detail-item > div {
  min-width: 0;
  overflow-wrap: anywhere;
}

.sub-detail-item form {
  flex: 0 0 auto;
}

@media (max-width: 760px) {
  .sub-detail-item {
    align-items: flex-start;
    flex-direction: column;
  }
}
