:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}
.nav a:hover { color: var(--accent); }
.nav .logout { margin-left: auto; color: var(--danger); }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 0.75rem; }

.muted { color: var(--muted); font-size: 0.9rem; }
.warn {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid var(--warn);
  padding: 0.75rem 1rem;
  border-radius: 8px;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.flash-ok { background: rgba(34, 197, 94, 0.15); border: 1px solid var(--ok); }
.flash-error { background: rgba(239, 68, 68, 0.15); border: 1px solid var(--danger); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.card .num { font-size: 2rem; font-weight: 700; color: var(--accent); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.steps { padding-left: 1.25rem; }
.steps li { margin-bottom: 0.5rem; }
.steps a { color: var(--accent); }

.login-card {
  max-width: 380px;
  margin: 4rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
}

.form-panel label {
  display: block;
  margin: 0.75rem 0 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}
.form-panel input,
.form-panel textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.form-panel button,
.login-card button {
  margin-top: 1.25rem;
  padding: 0.65rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
}
.form-panel button:hover,
.login-card button:hover { background: var(--accent-hover); }

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}
th, td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
th { color: var(--muted); font-weight: 500; }
code {
  background: var(--bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
.btn-danger { background: var(--danger); color: #fff; border: none; border-radius: 6px; cursor: pointer; }
.btn-secondary {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  background: var(--border);
  color: var(--text);
  border-radius: 6px;
  text-decoration: none;
}
.btn-secondary:hover { background: var(--accent); color: #fff; }
.btn-link { margin-left: 0.75rem; color: var(--muted); text-decoration: none; }
.btn-link:hover { color: var(--accent); }
.inline { display: inline; }
.actions { white-space: nowrap; }
.actions .inline { margin-left: 0.35rem; }
.form-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 1rem; }

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}
.check-card {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.check-card:has(input:checked) {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.1);
}
.ch-name { font-weight: 600; }
.ch-id { font-size: 0.8rem; color: var(--muted); }

.bind-user { margin-bottom: 1.5rem; }

/* --- 订阅绑定：折叠 + 清晰勾选 --- */
.bind-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
}
.bind-toolbar-actions { display: flex; gap: 0.5rem; }
.bind-user-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
}
.bind-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.bind-pill:hover { border-color: var(--accent); }
.bind-pill.is-active {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.15);
}
.bind-pill-count {
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--surface);
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
}
.bind-pill.is-active .bind-pill-count { color: var(--accent); }

.bind-accordions { display: flex; flex-direction: column; gap: 0.65rem; }
.bind-accordion {
  margin: 0;
  padding: 0;
  overflow: hidden;
}
.bind-accordion[open] { border-color: rgba(59, 130, 246, 0.35); }
.bind-summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.bind-summary::-webkit-details-marker { display: none; }
.bind-summary::marker { display: none; }
.bind-summary-main {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 4.5rem;
}
.bind-alias { font-weight: 700; font-size: 1.05rem; }
.bind-chat { font-size: 0.78rem; }
.bind-summary-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 1;
  min-width: 0;
}
.bind-tag {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  white-space: nowrap;
}
.bind-tag-channel {
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.25);
}
.bind-tag-webhook {
  background: rgba(34, 197, 94, 0.12);
  color: #86efac;
  border: 1px solid rgba(34, 197, 94, 0.25);
}
.bind-tag-empty {
  background: rgba(139, 156, 179, 0.1);
  color: var(--muted);
  border: 1px dashed var(--border);
}
.bind-chevron {
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.2s;
  flex-shrink: 0;
  margin-left: 0.25rem;
}
.bind-accordion[open] > .bind-summary .bind-chevron {
  transform: rotate(-135deg);
  margin-top: 0.25rem;
}
.bind-body {
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--border);
}
.bind-body-flush { padding: 0.75rem 1rem 1rem; }
.bind-list-panel { margin-top: 1.25rem; }
.bind-summary-simple .bind-alias { font-size: 1rem; }

.bind-section { margin-top: 1rem; }
.bind-section:first-child { margin-top: 0.75rem; }
.bind-section-head {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}
.bind-section-head h3 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text);
}
.bind-form-footer {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.subscribe-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.subscribe-list-compact .subscribe-row { padding: 0.65rem 0.85rem; }

.subscribe-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  padding: 0.75rem 0.85rem;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.subscribe-row.is-on {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.08);
  box-shadow: inset 3px 0 0 var(--accent);
}
.wh-row.is-on {
  border-color: var(--ok);
  background: rgba(34, 197, 94, 0.08);
  box-shadow: inset 3px 0 0 var(--ok);
}

.subscribe-toggle {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  cursor: pointer;
  margin: 0;
}
.subscribe-toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.toggle-box {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.1rem;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  position: relative;
  transition: border-color 0.15s, background 0.15s;
}
.subscribe-toggle input:checked + .toggle-box {
  border-color: var(--accent);
  background: var(--accent);
}
.wh-row input:checked + .toggle-box {
  border-color: var(--ok);
  background: var(--ok);
}
.subscribe-toggle input:checked + .toggle-box::after {
  content: "";
  position: absolute;
  left: 0.32rem;
  top: 0.08rem;
  width: 0.35rem;
  height: 0.65rem;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.toggle-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.mailbox-scope {
  margin-top: 0.65rem;
  margin-left: 1.9rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
  font-size: 0.85rem;
  transition: opacity 0.2s;
}
.mailbox-scope.is-disabled {
  opacity: 0.4;
  pointer-events: none;
}
.scope-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 0.4rem;
}
.scope-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}
.scope-chip,
.mb-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--surface);
}
.scope-chip:has(input:checked),
.mb-chip:has(input:checked) {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(59, 130, 246, 0.12);
}
.mailbox-picks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}
.btn-primary:hover { background: var(--accent-hover); }

.channel-item {
  cursor: default;
  gap: 0.5rem;
}
.channel-head {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  cursor: pointer;
}
.mailbox-scope {
  margin-top: 0.35rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
  font-size: 0.85rem;
}
.scope-label {
  display: block;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.scope-opt {
  display: block;
  margin: 0.2rem 0;
  cursor: pointer;
}
.mailbox-picks {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.mb-opt {
  cursor: pointer;
  color: var(--muted);
}
.mb-opt:has(input:checked) { color: var(--text); }
.bind-user h3 { font-size: 1rem; margin: 1.25rem 0 0.5rem; color: var(--muted); }
.url-cell { word-break: break-all; font-size: 0.8rem; }
.small { font-size: 0.8rem; }
