:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-soft: #fbfbfd;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: rgba(0, 0, 0, 0.1);
  --primary: #007aff;
  --primary-strong: #0066d6;
  --danger: #ff3b30;
  --warning: #ff9f0a;
  --success: #34c759;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.08);
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #101014;
    --surface: #1c1c1e;
    --surface-soft: #242426;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --border: rgba(255, 255, 255, 0.12);
    --primary: #0a84ff;
    --primary-strong: #409cff;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  letter-spacing: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 0 10px 18px;
}

.brand-title {
  font-size: 19px;
  font-weight: 700;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 13px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav a,
.nav button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  border: 0;
  border-radius: var(--radius);
  padding: 8px 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
}

.nav a:hover,
.nav button:hover,
.nav a.active {
  background: var(--surface-soft);
  color: var(--text);
}

.role-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--surface-soft);
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 12px;
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--muted);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted) 18%, transparent);
}

.dot.online {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 18%, transparent);
}

.dot.offline {
  background: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent);
}

.dot.warning {
  background: var(--warning);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warning) 18%, transparent);
}

.main {
  min-width: 0;
  padding: 28px clamp(18px, 4vw, 48px) 56px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.page-title {
  margin: 0;
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 750;
  letter-spacing: 0;
}

.page-kicker {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.actions form {
  margin: 0;
}

.table-actions {
  justify-content: flex-start;
}

.admin-access-actions {
  justify-content: flex-start;
}

.button,
button.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 13px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  font-weight: 600;
}

.button:hover,
button.button:hover {
  background: var(--primary-strong);
}

.button.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.button.secondary:hover {
  background: var(--surface-soft);
}

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

.button.warning {
  background: var(--warning);
  color: #1d1d1f;
}

.button:disabled,
button.button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.metrics {
  grid-template-columns: repeat(6, minmax(120px, 1fr));
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card-body {
  padding: 18px;
}

.metric-value {
  display: block;
  font-size: 30px;
  font-weight: 760;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.muted {
  color: var(--muted);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.message {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--surface);
}

.message.success {
  border-color: color-mix(in srgb, var(--success) 45%, var(--border));
}

.message.error {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--border));
}

.filters,
.form-panel {
  display: grid;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px;
  margin-bottom: 18px;
}

.filters {
  grid-template-columns: repeat(5, minmax(140px, 1fr));
}

.filters.compact {
  grid-template-columns: minmax(160px, 320px) minmax(120px, 1fr);
}

.filters .actions {
  justify-content: flex-start;
}

.filter-state {
  display: flex;
  align-items: center;
  min-height: 38px;
}

.form-panel p {
  margin: 0;
  display: grid;
  gap: 6px;
}

.form-panel label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.field-control {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--surface-soft);
  color: var(--text);
  outline: none;
}

.field-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}

textarea.field-control {
  min-height: 96px;
  resize: vertical;
}

.field-control:disabled,
.switch-input:disabled {
  opacity: 0.62;
  cursor: not-allowed;
}

.switch-input {
  width: 18px;
  height: 18px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  padding: 0;
}

.check-list {
  display: grid;
  gap: 8px;
  padding: 0;
  list-style: none;
}

.check-list label {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--text);
  font-weight: 500;
}

.helptext,
.errorlist {
  margin: 0;
  padding: 0;
  color: var(--muted);
  list-style: none;
  font-size: 13px;
}

.errorlist {
  color: var(--danger);
}

.detail-list {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 10px 16px;
}

.detail-list dt {
  color: var(--muted);
}

.detail-list dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.account-profile-form:not(.is-editing) .account-edit-field {
  display: none;
}

.account-profile-form.is-editing [data-account-status] {
  display: none;
}

.account-profile-form .field-control {
  background: color-mix(in srgb, var(--surface-soft) 82%, var(--surface));
}

.account-profile-form.is-editing .field-control {
  background: var(--surface-soft);
}

.account-edit-checkbox {
  align-items: center;
  color: var(--muted);
}

.account-profile-form.is-editing .account-edit-checkbox {
  color: var(--text);
}

.account-edit-actions {
  justify-content: flex-end;
}

.subscription {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.subscription .field-control {
  min-width: 0;
}

.subscription-url-code,
.subscription-link-code {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 36px), transparent 100%);
}

.qr-image {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fff;
  padding: 8px;
}

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

.progress {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
}

.progress.large {
  height: 12px;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.sync-strip {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface);
  color: var(--muted);
}

.activity-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--primary);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.86);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.click-row {
  cursor: pointer;
}

.click-row:hover td {
  background: var(--surface-soft);
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
}

.toggle-row label {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: var(--text);
}

.selection-panel {
  display: grid;
  gap: 12px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.selection-panel.is-disabled {
  opacity: 0.48;
}

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

.section-heading h2 {
  margin: 0;
}

.inbound-check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tag-choice-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.tag-choice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--surface-soft);
  color: var(--text);
}

.tag-choice input {
  width: 16px;
  height: 16px;
}

.check-card {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 500;
}

.plan-inbound-table table {
  min-width: 980px;
}

.selectable-row {
  cursor: pointer;
  transition: background 120ms ease, opacity 120ms ease;
}

.selectable-row.is-selected td {
  background: color-mix(in srgb, var(--success) 12%, var(--surface));
}

.selectable-row:has(.plan-inbound-input:checked) td {
  background: color-mix(in srgb, var(--success) 12%, var(--surface));
}

.selectable-row.is-unselected {
  opacity: 0.58;
}

.selectable-row:has(.plan-inbound-input:checked) {
  opacity: 1;
}

.selectable-row:hover td {
  background: color-mix(in srgb, var(--primary) 10%, var(--surface));
}

.selection-mark {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: color-mix(in srgb, var(--success) 14%, var(--surface-soft));
  border: 1px solid color-mix(in srgb, var(--success) 45%, var(--border));
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.is-unselected .selection-mark {
  background: var(--surface-soft);
  border-color: var(--border);
  color: var(--muted);
}

.selectable-row:has(.plan-inbound-input:checked) .selection-mark {
  background: color-mix(in srgb, var(--success) 14%, var(--surface-soft));
  border-color: color-mix(in srgb, var(--success) 45%, var(--border));
  color: var(--text);
}

.selection-on {
  display: none;
}

.selectable-row:has(.plan-inbound-input:checked) .selection-on {
  display: inline;
}

.selectable-row:has(.plan-inbound-input:checked) .selection-off {
  display: none;
}

details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface-soft);
}

summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
}

.login-brand-icon {
  display: block;
  margin-bottom: 10px;
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .grid.metrics,
  .grid.two,
  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .main {
    padding: 20px 14px 40px;
  }

  .topbar,
  .subscription,
  .status-row {
    grid-template-columns: 1fr;
    display: grid;
  }

  .actions {
    justify-content: flex-start;
  }

  .nav,
  .grid.metrics,
  .grid.two,
  .filters,
  .form-grid.two,
  .inbound-check-grid,
  .detail-list {
    grid-template-columns: 1fr;
  }
}
