:root {
  color-scheme: light;
  --brand: #6d3bea;
  --brand-deep: #5124bd;
  --brand-soft: #f2eeff;
  --ink: #172033;
  --muted: #667085;
  --line: #e7eaf0;
  --line-strong: #d6dbe5;
  --canvas: #f5f7fb;
  --panel: #fff;
  --green: #177a55;
  --green-soft: #e8f7f0;
  --red: #b42318;
  --red-soft: #fff1ec;
  --amber: #9a6700;
  --amber-soft: #fff7e6;
  --radius-sm: 9px;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-lg: 0 16px 50px rgba(16, 24, 40, .08);
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 14px/1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 17px;
  background: linear-gradient(145deg, #263cff, #aa00d6 58%, #ee006a);
  color: #fff;
  font-size: 30px;
  font-weight: 800;
}
.brand-mark.small { width: 32px; height: 32px; border-radius: 10px; font-size: 16px; }

.eyebrow {
  margin: 0;
  color: var(--brand);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.copy { color: var(--muted); font-size: 13px; line-height: 1.55; }
.inline-error {
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 13px;
  font-weight: 600;
}
.alert {
  border: 1px solid #f1c3b8;
  border-radius: 10px;
  background: var(--red-soft);
  color: #963723;
  margin: 16px 0 0;
  padding: 10px 12px;
  font-size: 13px;
}

/* Gate */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  padding: 36px;
}
.gate-card h1 { margin: 20px 0 8px; font-size: 30px; letter-spacing: -.03em; }
.gate-card .copy { margin-bottom: 4px; }

/* Shell */
.shell { max-width: 1360px; margin: 0 auto; padding: 0 clamp(14px, 3vw, 34px) 56px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 700; letter-spacing: -.02em; }
.brand strong { color: var(--brand); }
.top-actions { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.who { color: var(--muted); }
.link { color: var(--brand-deep); text-decoration: none; font-weight: 650; }
.link:hover { text-decoration: underline; }

.tabs { display: flex; gap: 6px; margin: 18px 0; border-bottom: 1px solid var(--line); }
.tab {
  border: 0;
  background: transparent;
  padding: 10px 14px;
  border-radius: 10px 10px 0 0;
  color: var(--muted);
  font-weight: 650;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); background: #eef1f7; }
.tab.is-active { color: var(--brand-deep); border-bottom-color: var(--brand); background: var(--brand-soft); }

.main { display: grid; gap: 18px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
}
.stat span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.stat strong { display: block; margin-top: 6px; font-size: 28px; letter-spacing: -.03em; }
.stat small { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }

/* Toolbar and surface */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar .input { flex: 1 1 260px; }
.toolbar .select { flex: 0 0 170px; }
.surface {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.surface-head { display: flex; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.surface-head h2 { font-size: 16px; }
.surface-head .copy { margin-top: 4px; max-width: 640px; }
.empty { padding: 28px 18px; color: var(--muted); text-align: center; }

/* Table */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 10px 12px;
  text-align: left;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .05em;
  text-transform: uppercase;
  background: #fafbfd;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 13px; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #faf9ff; }
.table tbody tr.is-clickable { cursor: pointer; }
.table .num { text-align: right; }
.table .name { font-weight: 650; }
.table .sub { display: block; color: var(--muted); font-size: 12px; }
.table .row-actions { display: flex; justify-content: flex-end; gap: 8px; white-space: nowrap; }

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 11px;
  font-weight: 750;
  text-transform: capitalize;
}
.chip.is-suspended { background: var(--amber-soft); color: var(--amber); }
.chip.is-pending { background: var(--brand-soft); color: var(--brand-deep); }
.chip.is-muted { background: #eef1f7; color: var(--muted); }
.chip.is-internal { background: var(--brand-soft); color: var(--brand-deep); }

/* Buttons and inputs */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.button:disabled { opacity: .6; cursor: progress; }
.button-primary { background: var(--brand); color: #fff; }
.button-primary:hover { background: var(--brand-deep); }
.button-secondary { background: #fff; border-color: var(--line-strong); color: var(--ink); }
.button-secondary:hover { border-color: #bfc4d2; }
.button-quiet { background: transparent; color: var(--muted); border-color: transparent; }
.button-quiet:hover { color: var(--ink); background: #eef1f7; }
.button-danger { background: var(--red); color: #fff; }
.button-danger:hover { background: #8f1d13; }
.button-block { width: 100%; margin-top: 20px; min-height: 46px; font-size: 13px; }
.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.icon-button:hover { background: #eef1f7; color: var(--ink); }

.input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  padding: 8px 11px;
  font-size: 13px;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(109, 59, 234, .12); }
textarea.input { resize: vertical; }
.select { padding-right: 28px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.inline-form .input { flex: 1 1 220px; }
.inline-form .select { flex: 0 0 130px; }

.invite-box { padding: 14px 18px; border-bottom: 1px solid var(--line); background: #fbfaff; }
.copy-row { display: flex; gap: 8px; margin-top: 8px; }
.copy-row .input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* Modals */
.modal {
  width: min(620px, calc(100vw - 24px));
  border: 0;
  border-radius: 18px;
  padding: 0;
  box-shadow: var(--shadow-lg);
  background: transparent;
}
.modal::backdrop { background: rgba(23, 32, 51, .42); backdrop-filter: blur(2px); }
.modal-wide { width: min(1120px, calc(100vw - 24px)); }
.modal-card {
  background: var(--panel);
  border-radius: 18px;
  padding: 22px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.modal-head h2 { font-size: 21px; letter-spacing: -.02em; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-span { grid-column: 1 / -1; }
.field { display: grid; gap: 6px; font-size: 12px; font-weight: 700; color: #344054; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel h3 { font-size: 14px; margin-bottom: 10px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.panel-actions { display: flex; justify-content: flex-end; margin-top: 14px; }

.member-list { list-style: none; margin: 0 0 4px; padding: 0; display: grid; gap: 8px; }
.member-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; }
.member-id { min-width: 0; }
.member-id strong { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-id small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-controls { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.member-controls .select { min-height: 32px; width: auto; padding: 4px 26px 4px 8px; font-size: 12px; }
.mini { min-height: 30px; padding: 0 9px; font-size: 11px; }

.pending { display: grid; gap: 8px; margin-top: 12px; }
.pending-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 10px; border: 1px dashed var(--line-strong); border-radius: 10px; font-size: 12px; }

.danger-zone { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.danger-zone h3 { color: var(--red); }
.danger-zone .copy { margin: 6px 0 10px; }
.danger-form { display: flex; gap: 8px; flex-wrap: wrap; }
.danger-form .input { flex: 1 1 180px; }

/* Toasts */
.toast-region { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 60; }
.toast {
  min-width: 240px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 11px;
  background: #1d292a;
  color: #f4f7f6;
  box-shadow: 0 14px 34px rgba(16, 24, 40, .28);
  font-size: 13px;
}
.toast.is-error { background: #7a271a; }

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .who { display: none; }
  .table .hide-sm { display: none; }
}
