:root {
  --portal-bg: #f4f6fb;
  --portal-surface: #ffffff;
  --portal-border: #e6eaf2;
  --portal-text: #1b2430;
  --portal-muted: #5b6573;
  --portal-accent: #2563eb;
  --portal-accent-soft: #eff4ff;
  --portal-danger: #b42318;
  --portal-danger-border: #f0b8b4;
  --portal-radius: 14px;
  --portal-radius-sm: 8px;
  --portal-sidebar: 240px;
  --portal-sidebar-closed: 72px;
  --portal-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.04);
}

body.portal {
  margin: 0;
  max-width: none;
  font-family: Inter, system-ui, sans-serif;
  line-height: 1.45;
  color: var(--portal-text);
  background: var(--portal-bg);
}

body.portal *,
body.portal *::before,
body.portal *::after {
  box-sizing: border-box;
}

.portal-shell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

body.portal--campaign,
body.portal--app {
  height: 100vh;
  overflow: hidden;
}

.portal-sidebar {
  grid-column: 1;
  grid-row: 1 / span 2;
  width: var(--portal-sidebar);
  max-width: var(--portal-sidebar);
  min-width: 0;
  height: 100%;
  max-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--portal-surface);
  border-right: 1px solid var(--portal-border);
  padding: 0.85rem 0.85rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  transition: width 0.24s ease, max-width 0.24s ease;
}

html.portal-sidebar-collapsed .portal-sidebar {
  width: var(--portal-sidebar-closed);
  max-width: var(--portal-sidebar-closed);
}

.portal-sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  margin: 0;
  padding: 0.35rem 0.45rem;
  border: 0;
  border-radius: var(--portal-radius-sm);
  background: transparent;
  color: var(--portal-muted);
  cursor: pointer;
}

.portal-sidebar-toggle:hover {
  background: var(--portal-bg);
  color: var(--portal-text);
}

.portal-sidebar-toggle:focus-visible,
.portal-brand:focus-visible,
.portal-side-nav a:focus-visible {
  outline: 2px solid var(--portal-accent);
  outline-offset: 2px;
}

.portal-sidebar-toggle .portal-nav-icon {
  transition: transform 0.24s ease;
}

html.portal-sidebar-collapsed .portal-sidebar-toggle .portal-nav-icon {
  transform: rotate(180deg);
}

.portal-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--portal-text);
  text-decoration: none;
  padding: 0.35rem 0.7rem;
  border-radius: var(--portal-radius-sm);
  letter-spacing: -0.02em;
}

.portal-brand:hover {
  background: var(--portal-bg);
}

.portal-brand[aria-current="page"] {
  background: var(--portal-accent-soft);
  color: var(--portal-accent);
}

.portal-nav-icon.size-5 {
  flex: 0 0 1.25rem;
  width: 1.25rem;
  height: 1.25rem;
  display: block;
}

.portal-nav-icon.shrink-0 {
  flex-shrink: 0;
}

.portal-nav-label {
  overflow: hidden;
  white-space: nowrap;
  min-width: 0;
  max-width: 12rem;
  opacity: 1;
  transition: opacity 0.16s ease, max-width 0.24s ease;
}

html.portal-sidebar-collapsed .portal-sidebar .portal-nav-label {
  opacity: 0;
  max-width: 0;
  pointer-events: none;
}

.portal-side-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.portal-side-nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--portal-text);
  text-decoration: none;
  padding: 0.48rem 0.7rem;
  border-radius: var(--portal-radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
}

.portal-side-nav a:hover {
  background: var(--portal-bg);
}

.portal-side-nav a[aria-current="page"] {
  background: var(--portal-accent-soft);
  color: var(--portal-accent);
  font-weight: 600;
}

.portal-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  background: var(--portal-surface);
  border-bottom: 1px solid var(--portal-border);
}

.portal-shell .portal-topbar {
  grid-column: 2;
  grid-row: 1;
}

.portal-topbar-title {
  font-weight: 600;
  font-size: 0.98rem;
  color: var(--portal-text);
  text-decoration: none;
}

.portal-topbar .portal-brand {
  padding: 0;
}

.form-field--check label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.user-menu {
  position: relative;
  margin-left: auto;
}

.user-menu summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--portal-muted);
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--portal-border);
  border-radius: 999px;
  background: #fff;
}

.user-menu summary::-webkit-details-marker {
  display: none;
}

.user-menu-panel {
  position: absolute;
  right: 0;
  margin-top: 0.4rem;
  min-width: 11rem;
  background: #fff;
  border: 1px solid var(--portal-border);
  border-radius: 10px;
  box-shadow: var(--portal-shadow);
  padding: 0.35rem;
  z-index: 20;
}

.user-menu-panel a {
  display: block;
  padding: 0.45rem 0.65rem;
  border-radius: 6px;
  color: var(--portal-text);
  text-decoration: none;
  font-size: 0.875rem;
}

.user-menu-panel a:hover {
  background: var(--portal-bg);
}

.portal-body {
  min-width: 0;
}

.portal-shell .portal-body {
  grid-column: 2;
  grid-row: 2;
  min-height: 0;
  overflow-y: auto;
}

.portal-main {
  padding: 1.5rem 1.5rem 2.5rem;
  max-width: 72rem;
}

body.portal--login .portal-main {
  max-width: none;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.messages {
  list-style: none;
  margin: 0;
  padding: 1rem 1.5rem 0;
}

.messages li {
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--portal-border);
  background: #fff;
  margin-bottom: 0.5rem;
}

.messages .error,
.blockers,
.field-error {
  color: var(--portal-danger);
}

.messages .error {
  border-color: var(--portal-danger-border);
  background: #fff8f7;
}

.messages .success {
  color: #147a3f;
  border-color: #c8e6c9;
  background: #f3fbf6;
}

.blockers {
  margin: 0;
  padding-left: 1.1rem;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.page-head > div:first-child {
  min-width: 0;
  flex: 1 1 18rem;
}

.page-head .actions {
  flex: 0 0 auto;
  margin: 0.85rem 0 0;
}

.overview-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.85rem;
}

.overview-meta .host {
  color: var(--portal-muted);
  font-size: 0.9rem;
  word-break: break-word;
}

.overview-meta code {
  font-size: 0.85em;
}

.page-head h1,
.portal h1 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
  letter-spacing: -0.03em;
}

.lede,
.hint,
.muted {
  color: var(--portal-muted);
  margin: 0;
}

.hint {
  font-size: 0.85rem;
}

.card {
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-radius: var(--portal-radius);
  box-shadow: var(--portal-shadow);
  padding: 1.15rem 1.25rem;
}

.card + .card,
.card-grid + .card,
.metric-grid + .card,
.section-block + .section-block {
  margin-top: 1rem;
}

.card h2,
.section-block h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.card-question {
  font-size: 1.05rem;
  margin: 0 0 0.9rem;
}

.card-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 840px) {
  .card-grid--2 {
    grid-template-columns: 1.4fr 1fr;
  }
  .card-grid--3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: 0.75rem;
}

.metric-tile {
  background: var(--portal-surface);
  border: 1px solid var(--portal-border);
  border-radius: var(--portal-radius);
  box-shadow: var(--portal-shadow);
  padding: 0.9rem 1rem;
}

.metric-tile .label {
  display: block;
  color: var(--portal-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-tile .value {
  display: block;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-top: 0.2rem;
}

.metric-tile .sub {
  display: block;
  color: var(--portal-muted);
  font-size: 0.8rem;
  margin-top: 0.15rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.4;
}

.status-pill--draft,
.status-pill--ended,
.status-pill--not_connected {
  background: #eef1f6;
  color: var(--portal-muted);
}

.status-pill--live,
.status-pill--verified,
.status-pill--confirmed {
  background: #e8f8ee;
  color: #147a3f;
}

.status-pill--paused,
.status-pill--pending_dns,
.status-pill--pending,
.status-pill--pending_review {
  background: #fff4e0;
  color: #9a6700;
}

.status-pill--launched {
  background: #e7efff;
  color: var(--portal-accent);
}

.status-pill--failed,
.status-pill--rejected,
.status-pill--suppressed,
.status-pill--unsubscribed {
  background: #fde8e8;
  color: var(--portal-danger);
}

.status-pill--qualified {
  background: #e8f8ee;
  color: #147a3f;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 1rem 0;
}

.actions-quiet {
  margin-top: 0.75rem;
}

.btn,
.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.875rem;
  line-height: 1.2;
  border-radius: var(--portal-radius-sm);
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid var(--portal-border);
  background: #fff;
  color: var(--portal-text);
}

.btn-primary,
button.btn-primary,
a.btn-primary,
a.button.btn-primary {
  background: var(--portal-accent);
  border-color: var(--portal-accent);
  color: #fff;
}

.btn-danger,
button.btn-danger {
  background: #fff;
  color: var(--portal-danger);
  border-color: var(--portal-danger-border);
}

.btn-quiet,
button.btn-quiet {
  background: transparent;
  color: var(--portal-muted);
  border-color: transparent;
}

.btn-block,
button.btn-block {
  width: 100%;
}

button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

form.inline {
  display: inline;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin-bottom: 1rem;
}

.chip,
a.chip,
.insert-placeholder {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--portal-border);
  background: #fff;
  color: var(--portal-text);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 550;
  text-decoration: none;
  cursor: pointer;
}

.chip:hover,
.insert-placeholder:hover {
  border-color: #cdd5e4;
}

.chip--active,
a.chip[aria-current="page"] {
  background: var(--portal-accent-soft);
  border-color: #c9d7fb;
  color: var(--portal-accent);
}

.insert-placeholder {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--portal-border);
  border-radius: var(--portal-radius);
  background: #fff;
  box-shadow: var(--portal-shadow);
}

.portal table {
  border-collapse: collapse;
  width: 100%;
  background: #fff;
}

.portal th,
.portal td {
  border-bottom: 1px solid var(--portal-border);
  border-left: 0;
  border-right: 0;
  padding: 0.7rem 0.85rem;
  text-align: left;
  vertical-align: middle;
}

.portal thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--portal-muted);
  background: #fafbfe;
}

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

.portal tbody tr:hover td {
  background: #fafbfe;
}

.table-link {
  color: var(--portal-text);
  font-weight: 600;
  text-decoration: none;
  display: block;
  padding: 0.7rem 0.85rem;
  margin: -0.7rem -0.85rem;
}

.table-link:hover {
  color: var(--portal-accent);
}

.auth-card {
  width: min(26rem, 100%);
  background: #fff;
  border: 1px solid var(--portal-border);
  border-radius: 16px;
  box-shadow: var(--portal-shadow);
  padding: 1.75rem 1.6rem 1.5rem;
}

.auth-card .brand {
  font-weight: 700;
  margin: 0 0 0.35rem;
  letter-spacing: -0.03em;
}

.auth-card h1 {
  margin-bottom: 0.35rem;
}

.auth-card .lede {
  margin-bottom: 1.25rem;
}

.stack-form .form-field,
.portal form p {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0 0 0.9rem;
}

.radio-list {
  border: 0;
  padding: 0;
  margin: 0 0 1rem;
}
.radio-list legend {
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.radio-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.radio-list li {
  margin: 0.35rem 0;
}

.portal form p:has(input[type="checkbox"]) {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.portal label {
  font-weight: 550;
  font-size: 0.875rem;
}

.portal input[type="text"],
.portal input[type="email"],
.portal input[type="password"],
.portal input[type="url"],
.portal input[type="search"],
.portal input[type="number"],
.portal input[type="file"],
.portal select,
.portal textarea,
.full {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  color: var(--portal-text);
  border: 1px solid var(--portal-border);
  border-radius: var(--portal-radius-sm);
  padding: 0.55rem 0.7rem;
  background: #fff;
}

.portal textarea {
  min-height: 8rem;
  resize: vertical;
}

.color-input {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.color-swatch {
  width: 2.4rem;
  height: 2.15rem;
  padding: 0;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.hex-input {
  flex: 1;
}

.form-grid {
  display: grid;
  gap: 0 1rem;
}

@media (min-width: 720px) {
  .form-grid--2 {
    grid-template-columns: 1fr 1fr;
  }
}

.form-section {
  margin-bottom: 0.25rem;
}

.form-section h2 {
  margin-bottom: 0.85rem;
}

.field-error,
.errorlist {
  color: var(--portal-danger);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.85rem;
}

.meter {
  height: 0.45rem;
  background: #eef1f6;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.45rem;
}

.meter > span {
  display: block;
  height: 100%;
  background: var(--portal-accent);
  border-radius: inherit;
}

.milestone-row {
  margin-bottom: 0.85rem;
}

.milestone-row:last-child {
  margin-bottom: 0;
}

.sparkline {
  display: block;
  width: 100%;
  height: 2.4rem;
  margin-top: 0.65rem;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 0.2rem;
  height: 7.5rem;
  margin: 0.5rem 0 0.75rem;
}

.bar-chart__col {
  flex: 1;
  display: flex;
  align-items: flex-end;
  height: 100%;
}

.bar-chart__col span {
  display: block;
  width: 100%;
  min-height: 2px;
  background: #93b4fb;
  border-radius: 3px 3px 0 0;
}

.visits-chart {
  margin-top: 1rem;
}

.visits-chart__range {
  margin: 0 0 0.5rem;
  color: var(--portal-muted);
  font-size: 0.85rem;
}

.visits-chart__canvas {
  position: relative;
  height: 14rem;
}

.card .visits-chart {
  margin-top: 1.15rem;
}

.mechanic-grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 840px) {
  .mechanic-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.mechanic-card h3 {
  margin: 1rem 0 0.4rem;
  font-size: 0.95rem;
}

.mechanic-card .lede {
  margin-bottom: 0.85rem;
}

.mechanic-card details {
  margin-top: 0.65rem;
  border-top: 1px solid var(--portal-border);
  padding-top: 0.65rem;
}

.mechanic-card summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--portal-accent);
}

.rule-list,
.reward-list {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem;
}

.rule-list li,
.reward-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--portal-border);
  font-size: 0.9rem;
}

.portal-body:has(.email-screen) {
  overflow: hidden;
}

.portal-main:has(.email-screen) {
  max-width: none;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.email-screen {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(22rem, 34rem) minmax(0, 1fr);
}

.email-editor {
  min-height: 0;
  overflow: auto;
  padding: 1.25rem 1.25rem 2rem;
}

.email-preview-pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1.25rem 1.25rem 1rem;
  background: var(--portal-surface);
  border-left: 1px solid var(--portal-border);
}

.email-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.email-preview-head h2 {
  margin: 0;
}

.email-preview-pane .email-not-sent {
  margin: 0;
}

.email-preview-pane .hint {
  margin: 0;
}

.email-preview {
  flex: 1;
  width: 100%;
  min-height: 0;
  height: 100%;
  border: 1px solid var(--portal-border);
  border-radius: 10px;
  background: #fff;
}

.email-upload {
  margin: 0 0 0.85rem;
  padding: 0.85rem;
  border: 1px dashed var(--portal-border);
  border-radius: 10px;
  background: var(--portal-bg);
}

.email-upload .form-field {
  margin-bottom: 0;
}

.email-upload-preview {
  display: block;
  max-width: 100%;
  max-height: 8rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--portal-border);
  border-radius: 8px;
  background: var(--portal-bg);
}

.email-upload input[type="file"] {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
}

.email-text-preview {
  white-space: pre-wrap;
  font-size: 0.9rem;
  background: #fafbfe;
  border: 1px solid var(--portal-border);
  border-radius: 10px;
  padding: 0.85rem;
  margin: 0;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-not_connected { background: #eef1f6; color: var(--portal-muted); }
.badge-pending_dns { background: #fff4e0; color: #9a6700; }
.badge-verified { background: #e8f8ee; color: #147a3f; }
.badge-failed { background: #fde8e8; color: var(--portal-danger); }

.dns-data { max-width: 28rem; word-break: break-all; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: end;
  margin-bottom: 1rem;
}

.toolbar .form-field,
.toolbar p {
  margin-bottom: 0;
}

.search-field {
  min-width: 14rem;
  flex: 1;
}

.builder {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.builder iframe {
  width: 100%;
  min-height: 32rem;
  background: #fff;
  border: 1px solid var(--portal-border);
  border-radius: 10px;
}

@media (max-width: 720px) {
  body.portal--campaign,
  body.portal--app {
    height: auto;
    overflow: auto;
  }
  .portal-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
    overflow: visible;
  }
  .portal-sidebar,
  html.portal-sidebar-collapsed .portal-sidebar {
    width: 100%;
    max-width: none;
    height: auto;
    max-height: none;
    overflow: visible;
    grid-column: 1;
    grid-row: auto;
    border-right: 0;
    border-bottom: 1px solid var(--portal-border);
    padding: 0.75rem;
  }
  .portal-sidebar-toggle {
    display: none;
  }
  html.portal-sidebar-collapsed .portal-sidebar .portal-nav-label {
    opacity: 1;
    max-width: none;
    pointer-events: auto;
  }
  .portal-side-nav {
    flex-direction: row;
    overflow-x: auto;
  }
  .portal-side-nav a {
    white-space: nowrap;
  }
  .portal-shell .portal-topbar,
  .portal-shell .portal-body {
    grid-column: 1;
    grid-row: auto;
    overflow: visible;
  }
  .builder {
    grid-template-columns: 1fr;
  }
  .portal-body:has(.email-screen),
  .portal-main:has(.email-screen) {
    height: auto;
    overflow: visible;
  }
  .email-screen {
    grid-template-columns: 1fr;
  }
  .email-preview-pane {
    min-height: 70vh;
    border-left: 0;
    border-top: 1px solid var(--portal-border);
  }
}

@media (prefers-reduced-motion: reduce) {
  .portal-sidebar,
  .portal-nav-label,
  .portal-sidebar-toggle .portal-nav-icon {
    transition: none;
  }
}
