:root {
  color-scheme: dark;
  --bg: #06101d;
  --bg-deep: #030914;
  --surface: rgba(13, 27, 48, .92);
  --surface-soft: rgba(18, 35, 60, .72);
  --surface-strong: #142743;
  --line: rgba(150, 175, 215, .16);
  --line-strong: rgba(149, 126, 255, .34);
  --text: #f3f7ff;
  --muted: #8fa0ba;
  --violet: #917cff;
  --violet-strong: #755ce8;
  --cyan: #43d7dc;
  --green: #54d79d;
  --red: #ff748d;
  --shadow: 0 24px 80px rgba(0, 0, 0, .34);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg-deep); }
body { min-height: 100vh; margin: 0; color: var(--text); background: radial-gradient(circle at 14% 0%, rgba(70, 90, 150, .16), transparent 34%), linear-gradient(150deg, #071423 0%, #050d19 62%, #030913 100%); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.ambient { position: fixed; pointer-events: none; filter: blur(100px); opacity: .18; border-radius: 999px; }
.ambient-one { width: 420px; height: 420px; top: -180px; right: 4vw; background: var(--violet); }
.ambient-two { width: 360px; height: 360px; bottom: -180px; left: -100px; background: var(--cyan); }

.shell { position: relative; z-index: 1; width: min(1480px, calc(100% - 40px)); margin: 0 auto; padding: 26px 0 52px; }
.topbar { min-height: 72px; padding: 14px 18px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 18px; border: 1px solid var(--line); border-radius: 18px; background: rgba(10, 23, 41, .82); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.back-link { width: max-content; color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 700; }
.back-link:hover { color: var(--text); }
.topbar-title { text-align: center; }
.topbar-title h1 { margin: 3px 0 0; font-size: 22px; letter-spacing: -.04em; }
.eyebrow { display: block; color: var(--violet); font-size: 9px; font-weight: 800; letter-spacing: .22em; }
.account-actions { justify-self: end; display: flex; align-items: center; gap: 10px; }
.account-actions > span { max-width: 260px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }

.state-card { width: min(460px, 100%); margin: 12vh auto 0; padding: 34px; text-align: center; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.state-card h2 { margin: 9px 0 8px; font-size: 25px; letter-spacing: -.04em; }
.state-card p { margin: 0 auto 22px; max-width: 340px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.state-icon { width: 48px; height: 48px; margin: 0 auto 18px; display: grid; place-items: center; color: var(--text); border: 1px solid var(--line-strong); border-radius: 14px; background: linear-gradient(145deg, rgba(145, 124, 255, .24), rgba(67, 215, 220, .08)); font-size: 19px; font-weight: 800; }
.spinner { width: 34px; height: 34px; margin: 0 auto 18px; border: 3px solid rgba(255,255,255,.1); border-top-color: var(--violet); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.admin-view { margin-top: 22px; display: grid; gap: 18px; }
.summary-grid { display: grid; grid-template-columns: 170px 170px minmax(280px, 1fr); gap: 14px; }
.summary-card { min-height: 102px; padding: 18px; display: flex; flex-direction: column; justify-content: space-between; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 15px 44px rgba(0,0,0,.18); }
.summary-card span { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.summary-card strong { font-size: 28px; letter-spacing: -.05em; }
.summary-card-wide strong { color: var(--cyan); font-size: 16px; letter-spacing: -.02em; }
.panel { padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: 0 18px 52px rgba(0,0,0,.2); }
.panel-heading { margin-bottom: 18px; display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.panel-heading h2 { margin: 5px 0 0; font-size: 19px; letter-spacing: -.035em; }
.status-pill { padding: 6px 9px; color: var(--green); border: 1px solid rgba(84, 215, 157, .25); border-radius: 999px; background: rgba(84, 215, 157, .08); font-size: 9px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }

.permission-form { display: grid; grid-template-columns: minmax(240px, .8fr) minmax(560px, 2fr) auto; align-items: end; gap: 12px; }
.field { min-width: 0; display: grid; gap: 7px; }
.field > span { color: var(--muted); font-size: 10px; font-weight: 750; }
.field input { width: 100%; min-height: 44px; padding: 0 13px; color: var(--text); border: 1px solid var(--line); outline: 0; border-radius: 11px; background: rgba(5, 14, 27, .68); }
.field input:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(145, 124, 255, .12); }
.platform-picker { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)); gap: 8px; }
.platform-choice { min-width: 0; min-height: 62px; padding: 10px; display: flex; align-items: flex-start; gap: 8px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-soft); cursor: pointer; }
.platform-choice:hover, .platform-choice.is-selected { border-color: var(--line-strong); background: rgba(145, 124, 255, .1); }
.platform-choice input { width: 15px; height: 15px; margin: 2px 0 0; accent-color: var(--violet); }
.platform-choice strong, .platform-choice small { display: block; }
.platform-choice strong { font-size: 10px; line-height: 1.25; }
.platform-choice small { margin-top: 4px; color: var(--muted); font-size: 8px; line-height: 1.25; }

.button { min-height: 40px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; color: var(--text); border: 1px solid transparent; border-radius: 10px; background: none; cursor: pointer; text-decoration: none; font-size: 11px; font-weight: 800; }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button-primary { border-color: rgba(167, 148, 255, .38); background: linear-gradient(135deg, var(--violet), var(--violet-strong)); box-shadow: 0 12px 28px rgba(117, 92, 232, .25); }
.button-primary:hover:not(:disabled) { filter: brightness(1.08); }
.button-ghost { color: var(--muted); border-color: var(--line); background: rgba(255,255,255,.025); }
.button-ghost:hover:not(:disabled) { color: var(--text); border-color: var(--line-strong); }
.button-danger { color: var(--red); border-color: rgba(255, 116, 141, .22); background: rgba(255, 116, 141, .07); }
.button-wide { width: 100%; }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; }
.permission-table { min-width: 1040px; background: rgba(5, 14, 27, .42); }
.permission-row { min-height: 62px; padding: 10px 12px; display: grid; grid-template-columns: minmax(250px, 1.5fr) repeat(var(--platform-count), minmax(122px, 1fr)) 92px; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.permission-row:last-child { border-bottom: 0; }
.permission-row-header { min-height: 44px; color: var(--muted); background: rgba(20, 39, 67, .62); font-size: 8.5px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.permission-row-header > span:not(:first-child) { text-align: center; }
.user-cell { min-width: 0; }
.user-cell strong, .user-cell small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-cell strong { font-size: 11px; }
.user-cell small { margin-top: 4px; color: var(--muted); font-size: 9px; }
.permission-toggle { min-height: 36px; padding: 7px; display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--muted); border: 1px solid var(--line); border-radius: 9px; background: rgba(255,255,255,.025); cursor: pointer; font-size: 9px; font-weight: 800; }
.permission-toggle:has(input:checked) { color: var(--green); border-color: rgba(84, 215, 157, .25); background: rgba(84, 215, 157, .08); }
.permission-toggle:has(input:disabled) { cursor: default; opacity: .82; }
.permission-toggle input { width: 14px; height: 14px; margin: 0; accent-color: var(--green); }
.permission-row > .button { width: 100%; }

.notice { margin: 0 0 16px; padding: 11px 12px; border-radius: 10px; font-size: 11px; line-height: 1.45; }
.notice-error { color: #ffc1cc; border: 1px solid rgba(255, 116, 141, .25); background: rgba(255, 116, 141, .09); }
.toast { position: fixed; z-index: 20; right: 24px; bottom: 24px; max-width: 380px; padding: 13px 16px; color: var(--text); border: 1px solid var(--line-strong); border-radius: 12px; background: #14243d; box-shadow: var(--shadow); font-size: 11px; font-weight: 700; }
.toast.is-error { color: #ffd2da; border-color: rgba(255, 116, 141, .38); }

[hidden] { display: none !important; }

@media (max-width: 1200px) {
  .permission-form { grid-template-columns: 1fr; }
  .permission-form > .button { width: 100%; }
  .platform-picker { grid-template-columns: repeat(3, minmax(130px, 1fr)); }
}
@media (max-width: 720px) {
  .shell { width: min(100% - 22px, 1480px); padding-top: 12px; }
  .topbar { grid-template-columns: auto 1fr; }
  .topbar-title { text-align: left; }
  .account-actions { grid-column: 1 / -1; width: 100%; justify-content: space-between; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-card-wide { grid-column: 1 / -1; }
  .platform-picker { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
  .state-card { margin-top: 8vh; padding: 26px 20px; }
}

/* Larger dashboard-scale typography */
body { font-size: 15px; }
.back-link { font-size: 15px; }
.topbar-title h1 { font-size: 26px; }
.eyebrow { font-size: 11px; }
.account-actions > span { font-size: 13px; }
.state-card h2 { font-size: 29px; }
.state-card p { font-size: 15px; }
.summary-card span { font-size: 12px; }
.summary-card strong { font-size: 34px; }
.summary-card-wide strong { font-size: 18px; }
.panel-heading h2 { font-size: 22px; }
.field > span { font-size: 12px; }
.field input { min-height: 48px; font-size: 15px; }
.platform-choice strong { font-size: 12px; }
.platform-choice small { font-size: 10px; }
.button { min-height: 44px; font-size: 13px; }
.permission-row-header { font-size: 10px; }
.user-cell strong { font-size: 13px; }
.user-cell small { font-size: 10px; }
.permission-toggle { min-height: 40px; font-size: 11px; }

@media (max-width: 720px) {
  .topbar-title h1 { font-size: 23px; }
  .summary-card strong { font-size: 30px; }
  .summary-card-wide strong { font-size: 16px; }
}

/* Admin impersonation controls */
.button-secondary { color: var(--cyan); border-color: rgba(67, 215, 220, .28); background: rgba(67, 215, 220, .08); }
.button-secondary:hover:not(:disabled) { color: var(--text); border-color: rgba(67, 215, 220, .52); background: rgba(67, 215, 220, .14); }
.permission-table { min-width: 1180px; }
.permission-row { grid-template-columns: minmax(250px, 1.5fr) repeat(var(--platform-count), minmax(122px, 1fr)) 210px; }
.user-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.user-actions .button { width: 100%; padding-inline: 10px; white-space: nowrap; }

.impersonation-status { padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border: 1px solid rgba(67, 215, 220, .28); border-radius: 18px; background: linear-gradient(135deg, rgba(67, 215, 220, .1), rgba(145, 124, 255, .1)); box-shadow: 0 18px 52px rgba(0,0,0,.2); }
.impersonation-status strong, .impersonation-status small { display: block; }
.impersonation-status strong { margin-top: 6px; font-size: 18px; }
.impersonation-status small { margin-top: 5px; color: var(--muted); font-size: 13px; }
.impersonation-status-actions { display: flex; gap: 9px; }

.modal-backdrop { position: fixed; z-index: 30; inset: 0; padding: 24px; display: grid; place-items: center; background: rgba(2, 8, 16, .78); backdrop-filter: blur(12px); }
.modal-card { width: min(520px, 100%); padding: 26px; border: 1px solid var(--line-strong); border-radius: 20px; background: #0d1b30; box-shadow: var(--shadow); }
.modal-card h2 { margin: 7px 0 6px; font-size: 27px; letter-spacing: -.04em; }
.modal-card > p { margin: 0 0 18px; color: var(--cyan); font-size: 15px; font-weight: 750; }
.impersonation-platforms { display: grid; gap: 10px; }
.impersonation-platform-choice { min-height: 74px; padding: 14px; display: flex; align-items: flex-start; gap: 11px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-soft); cursor: pointer; }
.impersonation-platform-choice:hover, .impersonation-platform-choice.is-selected { border-color: var(--line-strong); background: rgba(145, 124, 255, .12); }
.impersonation-platform-choice input { width: 17px; height: 17px; margin: 3px 0 0; accent-color: var(--violet); }
.impersonation-platform-choice strong, .impersonation-platform-choice small { display: block; }
.impersonation-platform-choice strong { font-size: 15px; }
.impersonation-platform-choice small { margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.modal-actions { margin-top: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (max-width: 720px) {
  .impersonation-status { align-items: stretch; flex-direction: column; }
  .impersonation-status-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .modal-backdrop { padding: 12px; }
  .modal-card { padding: 20px; }
}

/* Domain assignment administration */
.field select { width: 100%; min-height: 48px; padding: 0 13px; color: var(--text); border: 1px solid var(--line); outline: 0; border-radius: 11px; background: rgba(5, 14, 27, .86); font-size: 15px; }
.field select:focus { border-color: var(--violet); box-shadow: 0 0 0 3px rgba(145, 124, 255, .12); }
.domain-panel-heading { align-items: center; }
.domain-summary { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.domain-summary span { padding: 8px 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.025); font-size: 12px; font-weight: 750; }
.domain-summary strong { color: var(--cyan); font-size: 14px; }
.domain-toolbar { margin-bottom: 16px; display: grid; grid-template-columns: minmax(280px, 1fr) minmax(230px, .55fr) auto; align-items: end; gap: 12px; }
.domain-table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; }
.domain-assignment-table { min-width: 980px; background: rgba(5, 14, 27, .42); }
.domain-row { min-height: 72px; padding: 11px 13px; display: grid; grid-template-columns: minmax(220px, 1.1fr) minmax(280px, 1.35fr) minmax(300px, 1.25fr) 110px; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.domain-row:last-child { border-bottom: 0; }
.domain-row-header { min-height: 46px; color: var(--muted); background: rgba(20, 39, 67, .62); font-size: 10px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.domain-cell strong, .domain-cell small, .domain-account-cell span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.domain-cell strong { font-size: 14px; }
.domain-cell small { margin-top: 5px; color: var(--muted); font-size: 11px; text-transform: capitalize; }
.domain-account-cell { min-width: 0; display: grid; gap: 4px; }
.domain-account-cell span { color: #cbd6eb; font-size: 12px; }
.domain-owner-cell { min-width: 0; display: grid; gap: 5px; }
.domain-owner-cell select { width: 100%; min-height: 42px; padding: 0 10px; color: var(--text); border: 1px solid var(--line); border-radius: 10px; background: #0b192c; font-size: 13px; }
.domain-owner-cell select:focus { outline: 0; border-color: var(--violet); }
.domain-conflict { color: var(--red); font-size: 11px; font-weight: 750; }
.domain-empty { padding: 34px; color: var(--muted); text-align: center; font-size: 14px; }

@media (max-width: 920px) {
  .domain-panel-heading { align-items: flex-start; flex-direction: column; }
  .domain-toolbar { grid-template-columns: 1fr; }
  .domain-toolbar .button { width: 100%; }
}

/* Persistent dashboard navigation */
.topbar {
  position: sticky;
  top: 12px;
  z-index: 18;
}
.back-link {
  min-height: 44px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  border: 1px solid rgba(67, 215, 220, .3);
  border-radius: 11px;
  background: rgba(67, 215, 220, .08);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .16);
  font-size: 14px;
  white-space: nowrap;
}
.back-link:hover {
  color: #fff;
  border-color: rgba(67, 215, 220, .58);
  background: rgba(67, 215, 220, .14);
}

@media (max-width: 720px) {
  .topbar { top: 6px; }
  .back-link { min-height: 42px; padding-inline: 13px; font-size: 13px; }
}

/* The every-platform switch on a member row. */
.all-platforms-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
  cursor: pointer;
}
.all-platforms-switch input { cursor: pointer; }
.all-platforms-switch span { opacity: 0.85; }
.permission-toggle input:disabled { cursor: not-allowed; }
