:root {
    --bg: #fafafa;
    --surface: #ffffff;
    --surface-muted: #f4f4f5;
    --text: #18181b;
    --text-muted: #71717a;
    --border: #e4e4e7;
    --border-subtle: #f0f0f2;
    --accent: #18181b;
    --accent-hover: #3f3f46;
    --success-bg: #f0fdf4;
    --success-text: #166534;
    --success-border: #bbf7d0;
    --error-bg: #fef2f2;
    --error-text: #991b1b;
    --error-border: #fecaca;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --max-width: 720px;
    --max-width-wide: 960px;
    --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
}

a {
    color: var(--text);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--text-muted);
}

.layout {
    padding: 2rem 1.25rem 3rem;
}

.page {
    max-width: var(--max-width);
    margin: 0 auto;
}

.page--wide {
    max-width: var(--max-width-wide);
}

.page--full {
    max-width: none;
    width: 100%;
    margin: 0;
}

.page--full nav[data-testid="admin-nav"] {
    max-width: none;
}

.page--full .table-wrap {
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    padding: 0 1.25rem;
    overflow-x: auto;
    box-sizing: border-box;
}

.page--full .models-table {
    width: 100%;
}

.page-header {
    margin-bottom: 1.75rem;
}

.page-header h1 {
    margin: 0 0 0.25rem;
}

.page-subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9375rem;
}

nav[data-testid="main-nav"] {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-subtle);
}

.nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    max-width: var(--max-width-wide);
    margin: 0 auto;
    padding: 0.875rem 1.25rem;
}

.nav-brand {
    font-weight: 600;
    font-size: 0.9375rem;
    letter-spacing: -0.01em;
}

.nav-links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 1rem;
    font-size: 0.875rem;
}

.nav-links span {
    color: var(--text-muted);
}

nav[data-testid="admin-nav"] {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    max-width: var(--max-width-wide);
    margin: 0 auto 1.5rem;
    padding: 0.25rem;
    background: var(--surface-muted);
    border-radius: var(--radius);
}

nav[data-testid="admin-nav"] a {
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    color: var(--text-muted);
    transition: background 0.15s ease, color 0.15s ease;
}

nav[data-testid="admin-nav"] a:hover {
    background: var(--surface);
    color: var(--text);
}

h1 {
    font-size: 1.375rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.3;
}

h2 {
    margin: 0 0 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

section,
.card {
    margin: 0 0 0.75rem;
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

section p:last-child,
.card p:last-child {
    margin-bottom: 0;
}

section ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

section li {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.9375rem;
}

section li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

section li:first-child {
    padding-top: 0;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.stat {
    padding: 1rem 1.125rem;
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.stat-label {
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.stat-note {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.progress-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.progress-bar {
    flex: 1;
    height: 6px;
    background: var(--surface-muted);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 999px;
    transition: width 0.3s ease;
}

.progress-label {
    min-width: 2.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    text-align: right;
}

progress {
    display: none;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 999px;
    background: var(--surface-muted);
    color: var(--text-muted);
}

.badge--active {
    background: var(--success-bg);
    color: var(--success-text);
}

.badge--inactive {
    background: var(--surface-muted);
    color: var(--text-muted);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0 0;
    font-size: 0.875rem;
}

th,
td {
    padding: 0.625rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
}

th {
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: transparent;
    border-bottom: 1px solid var(--border);
}

tr:last-child td {
    border-bottom: none;
}

form {
    margin: 0;
}

form[data-testid="logout-form"] {
    display: inline;
}

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 360px;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.form-field label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text);
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: flex-end;
    margin-top: 0.75rem;
}

.form-row label {
    font-size: 0.8125rem;
    font-weight: 500;
}

input,
select {
    font: inherit;
    font-size: 0.9375rem;
    padding: 0.5rem 0.75rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.08);
}

input[type="number"],
input[type="text"]:not([type="email"]):not([type="password"]) {
    max-width: 12rem;
}

button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    cursor: pointer;
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    transition: background 0.15s ease;
}

button:hover,
.btn:hover {
    background: var(--accent-hover);
}

button.btn-ghost,
.btn-ghost {
    padding: 0.375rem 0.75rem;
    color: var(--text-muted);
    background: transparent;
}

button.btn-ghost:hover,
.btn-ghost:hover {
    color: var(--text);
    background: var(--surface-muted);
}

button:disabled,
.btn:disabled {
    cursor: not-allowed;
    opacity: 0.45;
    background: var(--text-muted);
}

button:disabled:hover,
.btn:disabled:hover {
    background: var(--text-muted);
}

.text-link {
    display: inline-block;
    margin-top: 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.text-link:hover {
    color: var(--text);
}

[role="alert"],
[data-testid="form-error"] {
    max-width: var(--max-width-wide);
    margin: 0 auto 1rem;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-radius: var(--radius-sm);
    color: var(--error-text);
}

[role="status"],
[data-testid="flash-success"] {
    max-width: var(--max-width-wide);
    margin: 0 auto 1rem;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    border-radius: var(--radius-sm);
    color: var(--success-text);
}

.layout > [role="alert"],
.layout > [role="status"],
.layout > [data-testid="flash-success"],
.layout > [data-testid="flash-error"] {
    max-width: var(--max-width);
}

code {
    padding: 0.15rem 0.4rem;
    font-size: 0.8125rem;
    background: var(--surface-muted);
    border-radius: 4px;
    word-break: break-all;
}

pre {
    margin: 0.75rem 0;
    padding: 1rem;
    background: var(--surface-muted);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-size: 0.8125rem;
    line-height: 1.5;
}

pre code {
    padding: 0;
    background: none;
    border-radius: 0;
    word-break: normal;
    white-space: pre;
}

h3 {
    margin: 1rem 0 0.5rem;
    font-size: 0.9375rem;
    font-weight: 600;
}

.api-key-reveal {
    margin: 0.75rem 0;
    padding: 0.75rem;
    background: var(--surface-muted);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.api-key-reveal p {
    margin: 0;
}

.copy-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.btn-copy {
    flex-shrink: 0;
    font-size: 0.8125rem;
    padding: 0.35rem 0.75rem;
}

.auth-card {
    max-width: 360px;
    margin: 0 auto;
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.auth-card h1 {
    margin: 0 0 1.5rem;
}

.auth-card > p {
    margin: 1.25rem 0 0;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: center;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.pagination a {
    color: var(--text);
}

.admin-summary {
    margin: 0;
    padding: 0;
    list-style: none;
}

.admin-summary li {
    display: flex;
    justify-content: space-between;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.9375rem;
}

.admin-summary li:last-child {
    border-bottom: none;
}

.log-entry {
    margin-bottom: 0.75rem;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    font-size: 0.8125rem;
}

.section-spaced {
    margin-top: 1.5rem;
}

.payment-section {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-subtle);
}

.payment-section .form-row {
    margin-top: 0;
}

.table-wrap {
    padding: 0;
    overflow: hidden;
}

.form-field--grow {
    flex: 1;
    min-width: 160px;
}

.models-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.75rem 0;
}

.models-toolbar__reset {
    margin-top: 0;
}

.models-table th a {
    color: inherit;
    text-decoration: none;
}

.models-table th a:hover {
    color: var(--text-muted);
}

.models-table__filters td {
    padding-top: 0.375rem;
    padding-bottom: 0.75rem;
    vertical-align: top;
}

.models-table__filters input,
.models-table__filters select {
    width: 100%;
    min-width: 0;
    max-width: none;
    font-size: 0.8125rem;
    padding: 0.375rem 0.5rem;
}

.models-price-filters {
    display: flex;
    gap: 0.375rem;
}

.landing-hero {
    max-width: 520px;
    margin: 3rem auto 0;
    padding: 2.5rem 2rem;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.landing-hero h1 {
    margin: 0 0 0.75rem;
    font-size: 2rem;
    letter-spacing: -0.03em;
}

.landing-lead {
    margin: 0 0 2rem;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1.65;
}

.landing-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
}

.btn-lg {
    min-width: 11rem;
    padding: 0.75rem 1.25rem;
    font-size: 0.9375rem;
}

.btn-secondary {
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    color: var(--text);
    background: var(--surface-muted);
}

.btn[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.45;
    background: var(--text-muted);
}

.landing-note {
    margin: 1.5rem 0 0;
    font-size: 0.875rem;
    color: var(--text-muted);
}

@media (max-width: 560px) {
    .stat-grid {
        grid-template-columns: 1fr;
    }

    .nav-inner {
        flex-direction: column;
        align-items: flex-start;
    }

    .landing-hero {
        margin-top: 1.5rem;
        padding: 2rem 1.25rem;
    }

    .landing-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-lg {
        width: 100%;
    }
}
