:root {
    --bg: #f9fafb;
    --surface: #ffffff;
    --surface-strong: #f3f4f6;
    --text: #111827;
    --text-muted: #4b5563;
    --line: #e5e7eb;
    --line-strong: #d1d5db;
    --brand: #2563eb;
    --brand-strong: #1d4ed8;
    --brand-soft: #dbeafe;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --shadow: 0 20px 45px rgba(17, 24, 39, 0.08);
    --radius: 8px;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
}

* {
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a {
    color: inherit;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    width: min(1120px, calc(100% - 2rem));
    min-height: 4rem;
    margin: 0 auto;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text);
    font-size: 1.25rem;
    font-weight: 700;
    text-decoration: none;
}

.brand-icon {
    width: 1.55rem;
    height: 1.55rem;
    color: var(--brand);
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.header-nav {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1.35rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

.header-nav a {
    text-decoration: none;
    transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}

.header-nav a:hover {
    color: var(--text);
}

.nav-button {
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    padding: 0.45rem 0.8rem;
    color: var(--text);
    background: var(--surface);
}

.page-shell {
    flex: 1;
    width: min(1120px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 3rem 0 4rem;
}

.site-footer {
    border-top: 1px solid var(--line);
    background: #111827;
    color: #d1d5db;
}

.footer-inner {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-6);
    width: min(1120px, calc(100% - 2rem));
    margin: 0 auto;
    padding: var(--space-6) 0;
    font-size: 0.84rem;
}

.footer-inner strong {
    color: #ffffff;
}

.footer-inner p {
    margin: var(--space-1) 0 0;
    color: #9ca3af;
}

.footer-inner nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-4);
}

.footer-inner a:hover {
    color: #ffffff;
}

.portal-panel,
.auth-panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.auth-panel {
    max-width: 600px;
    margin: 2rem auto 0;
    padding: clamp(1.5rem, 4vw, 2.25rem);
}

.portal-panel {
    padding: clamp(1.25rem, 3vw, 2rem);
}

.portal-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: clamp(1.25rem, 3vw, 2rem);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.portal-card + .portal-card {
    margin-top: var(--space-5);
}

.section-heading,
.list-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.card-heading {
    margin-bottom: var(--space-5);
}

.card-heading > :last-child,
.card-intro {
    margin-bottom: 0;
}

.flow > * + * {
    margin-top: var(--space-5);
}

.portal-list {
    display: grid;
    margin-top: var(--space-5);
}

.list-row {
    border-top: 1px solid var(--line);
    padding: var(--space-5) 0;
}

.list-row:last-child {
    padding-bottom: 0;
}

.list-row h2,
.list-row h3,
.list-row p {
    margin-bottom: var(--space-1);
}

.inline-form {
    display: grid;
    gap: var(--space-3);
    margin: var(--space-4) 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-4);
}

.markdown-source {
    overflow-x: auto;
    white-space: pre-wrap;
    border-radius: var(--radius);
    padding: 1rem;
    background: var(--surface-strong);
}

.status-pill {
    border-radius: 999px;
    padding: 0.25rem 0.6rem;
    background: var(--surface-strong);
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.detail-list {
    display: grid;
    grid-template-columns: minmax(9rem, 0.25fr) minmax(0, 1fr);
    gap: var(--space-3) var(--space-5);
    margin: 0;
}

.detail-list dt {
    color: var(--text-muted);
    font-weight: 700;
}

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

.detail-list dd > :last-child {
    margin-bottom: 0;
}

.content-sections {
    display: grid;
    gap: var(--space-5);
}

.content-sections h2 {
    margin-bottom: var(--space-3);
}

.help-disclosure {
    margin: var(--space-5) 0;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    background: #eff6ff;
}

.help-disclosure summary {
    padding: var(--space-4);
    color: var(--brand-strong);
    font-weight: 700;
    cursor: pointer;
}

.help-disclosure summary:hover {
    background: rgba(219, 234, 254, 0.55);
}

.help-disclosure summary:focus-visible {
    border-radius: var(--radius);
    outline: 3px solid rgba(37, 99, 235, 0.25);
    outline-offset: 2px;
}

.help-disclosure[open] summary {
    border-bottom: 1px solid #bfdbfe;
}

.help-disclosure__content {
    padding: var(--space-5);
}

.help-disclosure__content > :first-child {
    margin-top: 0;
}

.help-disclosure__content > :last-child {
    margin-bottom: 0;
}

.example-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-5);
    margin: var(--space-5) 0;
}

.example-list {
    display: grid;
    gap: var(--space-2);
    margin: 0;
    padding-left: 1.25rem;
}

.example-list code,
.source-summary code {
    overflow-wrap: anywhere;
}

.help-note {
    color: var(--text-muted);
    font-size: 0.92rem;
}

.source-list {
    margin-top: 0;
}

.source-summary h3 {
    font-size: 1rem;
}

.source-summary p {
    display: grid;
    grid-template-columns: 5rem minmax(0, 1fr);
    gap: var(--space-3);
}

.source-summary p span {
    color: var(--text-muted);
    font-size: 0.88rem;
    font-weight: 700;
}

.form-section {
    margin-top: var(--space-6);
    padding-top: var(--space-5);
    border-top: 1px solid var(--line);
}

.form-section h3,
.form-section p {
    margin-bottom: var(--space-1);
}

.portal-form {
    display: grid;
    gap: var(--space-4);
    margin-top: var(--space-5);
}

.portal-form > p,
.portal-form fieldset p {
    margin: 0;
}

.portal-form > p > label:first-child,
.portal-form fieldset p > label:first-child {
    display: block;
    margin-bottom: var(--space-2);
}

.portal-form .helptext {
    display: block;
    margin-top: var(--space-1);
    color: var(--text-muted);
    font-size: 0.86rem;
}

.portal-form input[type="checkbox"] {
    width: auto;
    margin-right: var(--space-2);
}

.portal-form > h2 {
    margin: var(--space-4) 0 0;
}

.settings-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(15rem, 0.55fr);
    align-items: start;
    gap: var(--space-5);
    padding: var(--space-5) 0;
    border-top: 1px solid var(--line);
}

.settings-row h3,
.settings-row p {
    margin-bottom: var(--space-1);
}

.confirm-form {
    display: grid;
    gap: var(--space-3);
}

.danger-zone {
    border-color: #fecaca;
}

.text-button {
    margin: 0;
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

.danger-text {
    color: #b91c1c;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    margin: 0 0 1rem;
    border-radius: 999px;
    padding: 0.4rem 0.75rem;
    background: var(--brand-soft);
    color: var(--brand-strong);
    font-size: 0.85rem;
    font-weight: 700;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0.75rem;
    color: var(--text);
    font-size: clamp(2rem, 4vw, 3rem);
    font-weight: 800;
    line-height: 1.08;
}

.portal-title h1,
.auth-panel h1,
.portal-panel h1 {
    font-size: clamp(1.8rem, 3vw, 2.5rem);
}

h2 {
    margin-bottom: 0.75rem;
    font-size: 1.35rem;
    line-height: 1.25;
}

h3 {
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.lead {
    max-width: 48rem;
    margin-bottom: 1.5rem;
    color: var(--text-muted);
    font-size: 1.08rem;
}

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

.button-row,
.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.actions form {
    display: inline-flex;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.55rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 0.55rem 1rem;
    background: var(--brand);
    color: #ffffff;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.button:hover {
    background: var(--brand-strong);
    transform: translateY(-1px);
}

.button.secondary {
    border-color: var(--line-strong);
    background: #ffffff;
    color: var(--text);
}

.button.secondary:hover {
    border-color: #9ca3af;
    background: #f9fafb;
}

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

.button.danger:hover {
    background: #b91c1c;
}

.button.small {
    min-height: 2.1rem;
    padding: 0.35rem 0.7rem;
    font-size: 0.9rem;
}

.portal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}

.metric-card,
.content-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.metric-card {
    padding: 1rem;
}

.metric-card span {
    display: block;
    margin-bottom: 0.25rem;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.metric-card strong {
    display: block;
    font-size: 1.45rem;
    line-height: 1.2;
}

.content-card {
    padding: 1.25rem;
    margin-top: 1rem;
}

.split-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.42fr);
    gap: 1rem;
}

form {
    margin: 0;
}

.form-grid {
    display: grid;
    gap: 0.9rem;
}

.field {
    display: grid;
    gap: 0.35rem;
}

.field input[type="checkbox"] {
    width: auto;
    justify-self: start;
}

.field .helptext {
    color: var(--text-muted);
    font-size: 0.86rem;
}

.field .helptext a {
    color: var(--brand-strong);
}

.legal-page {
    max-width: 880px;
    margin: 0 auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: clamp(1.5rem, 4vw, 3rem);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.legal-hero {
    padding-bottom: var(--space-5);
    border-bottom: 1px solid var(--line);
}

.legal-page section {
    padding-top: var(--space-6);
}

.legal-page section + section {
    margin-top: var(--space-5);
    border-top: 1px solid var(--line);
}

.legal-page li + li {
    margin-top: var(--space-2);
}

.legal-page a {
    color: var(--brand-strong);
}

.legal-summary {
    margin-top: var(--space-6);
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    padding: var(--space-5);
    background: #eff6ff;
}

.legal-summary > :last-child {
    margin-bottom: 0;
}

.legal-details {
    display: grid;
    grid-template-columns: minmax(9rem, 0.35fr) minmax(0, 1fr);
    gap: var(--space-3) var(--space-5);
    margin: 0;
}

.legal-details dt {
    color: var(--text-muted);
    font-weight: 700;
}

.legal-details dd {
    margin: 0;
}

.legal-table-wrap {
    overflow-x: auto;
    margin-bottom: var(--space-4);
}

.legal-table-wrap table {
    min-width: 680px;
}

label {
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    padding: 0.65rem 0.75rem;
    background: #ffffff;
    color: var(--text);
    font: inherit;
}

textarea {
    min-height: 9rem;
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 0.88rem;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--brand);
    outline: 3px solid rgba(37, 99, 235, 0.18);
}

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

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.8rem 0.75rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

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

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    background: var(--surface-strong);
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: capitalize;
}

.badge.active,
.badge.owner {
    background: var(--success-soft);
    color: #166534;
}

.badge.invited,
.badge.admin {
    background: var(--brand-soft);
    color: var(--brand-strong);
}

.messages {
    display: grid;
    gap: 0.65rem;
    margin-bottom: 1rem;
}

.message {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.75rem 0.9rem;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 8px 20px rgba(17, 24, 39, 0.05);
}

.message.success {
    border-color: #bbf7d0;
    background: var(--success-soft);
}

.message.error {
    border-color: #fecaca;
    background: var(--danger-soft);
}

.message.info {
    border-color: #bfdbfe;
    background: var(--brand-soft);
}

.token-box {
    margin-top: 1rem;
}

.empty-state {
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    padding: 1.5rem;
    background: #ffffff;
}

.empty-state.compact {
    margin: 0;
    padding: var(--space-4);
}

.marketing-fallback {
    width: min(720px, calc(100% - 2rem));
    margin: 5rem auto;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (max-width: 820px) {
    .header-inner,
    .portal-header {
        display: block;
    }

    .footer-inner {
        display: block;
    }

    .footer-inner nav {
        justify-content: flex-start;
        margin-top: var(--space-5);
    }

    .legal-details {
        grid-template-columns: 1fr;
        gap: var(--space-1);
    }

    .legal-details dd + dt {
        margin-top: var(--space-3);
    }

    .header-nav {
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 0.8rem;
        margin-top: 0.75rem;
        padding-bottom: 0.85rem;
    }

    .portal-header .actions {
        margin-top: 1.5rem;
    }

    .meta-grid,
    .split-grid,
    .example-grid,
    .settings-row {
        grid-template-columns: 1fr;
    }

    .section-heading {
        flex-wrap: wrap;
    }
}

@media (max-width: 560px) {
    .page-shell {
        width: min(100% - 1rem, 1120px);
        padding-top: 1.5rem;
    }

    .button,
    .button-row .button,
    .actions .button {
        width: 100%;
    }

    .detail-list,
    .source-summary p {
        grid-template-columns: 1fr;
        gap: var(--space-1);
    }

    .section-heading > .button {
        width: 100%;
    }
}
