*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-bg: #0f0f0f;
    --color-surface: #1a1a1a;
    --color-surface-2: #222;
    --color-border: #2a2a2a;
    --color-text: #e0e0e0;
    --color-text-muted: #888;
    --color-accent: #7c6fe0;
    --color-accent-hover: #9a8ff0;
    --color-danger: #e05555;
    --color-danger-hover: #f06666;
    --color-heading: #fff;
    --radius: 8px;
}

[data-theme="light"] {
    --color-bg: #f5f5f5;
    --color-surface: #fff;
    --color-surface-2: #eee;
    --color-border: #ddd;
    --color-text: #1a1a1a;
    --color-text-muted: #666;
    --color-accent: #6c5ce7;
    --color-accent-hover: #5a4bd1;
    --color-danger: #e05555;
    --color-danger-hover: #f06666;
    --color-heading: #1a1a1a;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.site-footer {
    margin-top: auto;
    height: 40px;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}
.site-footer a {
    color: var(--color-text-muted);
}
.site-footer a:hover {
    color: var(--color-text);
}
.footer-sep {
    opacity: 0.4;
    user-select: none;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { color: var(--color-accent-hover); }

/* Header */
header {
    background-color: var(--color-surface);
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--color-border);
}

header nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.nav-logo {
    font-size: 1.2rem;
    font-weight: 600;
}

.nav-center {
    display: flex;
    gap: 2rem;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}
.nav-link {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    padding-bottom: 2px;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}
.nav-link:hover {
    color: var(--color-accent);
}
.nav-link--active {
    color: var(--color-accent);
    border-bottom-color: var(--color-accent);
}

.nav-right {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

/* Burger menu */
.nav-burger {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    flex-direction: column;
    gap: 5px;
}
.nav-burger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--color-text);
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
}
.nav--open .nav-burger span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.nav--open .nav-burger span:nth-child(2) {
    opacity: 0;
}
.nav--open .nav-burger span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.nav-user-dropdown-plan {
    display: none;
}

@media (max-width: 768px) {
    .nav-burger {
        display: flex;
    }
    header nav {
        flex-wrap: wrap;
    }
    .nav-right { gap: 0.75rem; }
    .nav-right > .nav-plan-badge {
        display: none !important;
    }
    .nav-user-dropdown-plan {
        display: block !important;
    }
    .nav-center {
        display: none;
        position: static;
        transform: none;
        width: 100%;
        flex-direction: column;
        gap: 0.5rem;
        padding: 1rem 0 0.5rem;
        order: 10;
    }
    .nav--open .nav-center {
        display: flex;
    }
}

/* Main */
main {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}

.btn-primary {
    background: var(--color-accent);
    color: #fff;
}
.btn-primary:hover {
    background: var(--color-accent-hover);
    color: #fff;
}
.btn-green {
    background: #22a85a;
    color: #fff;
}
.btn-green:hover {
    background: #1a8f4a;
    color: #fff;
}

.btn-secondary {
    background: var(--color-surface-2);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}
.btn-secondary:hover { background: var(--color-border); color: var(--color-heading); }

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

.btn-small { padding: 0.35rem 0.8rem; font-size: 0.8rem; }

/* Landing page */
main:has(.landing) {
    max-width: none;
    padding: 0;
}
.landing {
    overflow: hidden;
}
.landing-section {
    max-width: 1100px;
    margin: 0 auto;
    padding: 4rem 2rem;
}
.landing-section--accent {
    max-width: none;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
}
.landing-section--accent > * {
    max-width: 1100px;
    margin-left: auto;
    margin-right: auto;
}
.landing-section-label {
    text-align: center;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    margin-bottom: 1.25rem;
}
.landing-section-header {
    text-align: center;
    margin-bottom: 2.5rem;
}
.landing-section-header h2 {
    font-size: 1.8rem;
    color: var(--color-heading);
    margin-bottom: 0.5rem;
}
.landing-section-header p {
    color: var(--color-text-muted);
    font-size: 1.05rem;
}

/* Hero */
.hero {
    text-align: center;
    padding: 5rem 2rem 3rem;
    max-width: 800px;
    margin: 0 auto;
}
.hero-label {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-accent);
    background: rgba(124, 111, 224, 0.1);
    border: 1px solid rgba(124, 111, 224, 0.25);
    border-radius: 20px;
    padding: 0.3rem 0.9rem;
    margin-bottom: 1.5rem;
}
.hero h1 {
    font-size: 3.2rem;
    line-height: 1.15;
    color: var(--color-heading);
    margin-bottom: 1.25rem;
    letter-spacing: -0.02em;
}
.hero-tagline {
    font-size: 1.15rem;
    line-height: 1.7;
    color: var(--color-text-muted);
    max-width: 600px;
    margin: 0 auto 2rem;
}
.hero-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}
.hero-subtext {
    margin-top: 1rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}
.btn-lg {
    padding: 0.75rem 1.6rem;
    font-size: 1rem;
}

/* Provider strip */
.provider-strip {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 2rem;
}
.provider-strip-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text-muted);
    letter-spacing: 0.02em;
    opacity: 0.6;
    transition: opacity 0.2s;
}
.provider-logo {
    width: 24px;
    height: 24px;
    object-fit: contain;
}
.provider-strip-item:hover {
    opacity: 1;
}

/* Features grid */
.features-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
}
.feature-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
}
.feature-card--lg {
    padding: 1.75rem;
}
.feature-icon {
    font-size: 1.6rem;
    margin-bottom: 0.75rem;
    line-height: 1;
}
.feature-card h3 {
    color: var(--color-heading);
    margin-bottom: 0.5rem;
    font-size: 1rem;
}
.feature-card p {
    color: var(--color-text-muted);
    font-size: 0.88rem;
    line-height: 1.6;
}

/* Steps row */
.steps-row {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 1rem;
}
.step-block {
    flex: 1;
    max-width: 280px;
    text-align: center;
    padding: 1.5rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}
.step-block-number {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--color-accent);
    color: #fff;
    border-radius: 50%;
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 1rem;
}
.step-block h3 {
    color: var(--color-heading);
    font-size: 1rem;
    margin-bottom: 0.4rem;
}
.step-block p {
    color: var(--color-text-muted);
    font-size: 0.88rem;
    line-height: 1.5;
}
.step-block-arrow {
    color: var(--color-text-muted);
    font-size: 1.5rem;
    margin-top: 3rem;
    flex-shrink: 0;
}

/* Pricing teaser */
.pricing-teaser {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    max-width: 700px;
    margin: 0 auto;
}
.pricing-teaser-card {
    text-align: center;
    padding: 1.5rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: block;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.pricing-teaser-card:hover {
    border-color: var(--color-accent);
}
.pricing-teaser-card--featured {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 1px var(--color-accent);
}
.pricing-teaser-card h3 {
    color: var(--color-heading);
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}
.pricing-teaser-price {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-heading);
    margin-bottom: 0.4rem;
}
.pricing-teaser-price span {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--color-text-muted);
}
.pricing-teaser-card p {
    font-size: 0.82rem;
    color: var(--color-text-muted);
}

/* CTA */
.landing-cta {
    text-align: center;
    padding: 5rem 2rem;
}
.landing-cta h2 {
    font-size: 2rem;
    color: var(--color-heading);
    margin-bottom: 0.75rem;
}
.landing-cta p {
    color: var(--color-text-muted);
    font-size: 1.05rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 768px) {
    .hero h1 { font-size: 2rem; }
    .hero-actions { flex-direction: column; align-items: center; }
    .features-grid { grid-template-columns: 1fr; }
    .steps-row { flex-direction: column; align-items: center; }
    .step-block-arrow { transform: rotate(90deg); margin: 0; }
    .pricing-teaser { grid-template-columns: 1fr; max-width: 300px; }
}

/* Sections */
.section { margin-bottom: 3rem; }

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.section-header h2 { color: var(--color-heading); }

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.page-header h1 { color: var(--color-heading); }

.page-actions { display: flex; gap: 0.5rem; }

.page-description {
    color: var(--color-text-muted);
    margin: -1rem 0 2rem;
}

/* Cards */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.card {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: border-color 0.2s;
    color: var(--color-text);
}

.card:hover {
    border-color: var(--color-accent);
    color: var(--color-text);
}

.card h3 { color: var(--color-heading); margin-bottom: 0.4rem; }
.card p { font-size: 0.9rem; color: var(--color-text-muted); }

.card-provider {
    font-size: 0.75rem;
    color: var(--color-accent);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.4rem;
}

.card-grid--square {
    grid-template-columns: repeat(4, 1fr);
    align-content: start;
    align-items: start;
}

.card-grid--square > form {
    display: contents;
}

.model-card--square {
    position: relative;
    aspect-ratio: 1;
    align-self: start;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    align-items: flex-start;
    justify-content: center;
}

.model-card--square:has(.chat-card-cover-wrap) {
    padding: 0;
    justify-content: flex-end;
}
.model-card--square .chat-card-cover-wrap {
    position: absolute;
    inset: 0;
    flex: none;
}
.model-card--square .chat-card-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.model-card--square:has(.chat-card-cover-wrap) .chat-card-content {
    position: relative;
    z-index: 1;
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.75);
}
.model-card--square:has(.chat-card-cover-wrap) .chat-card-content h3,
.model-card--square:has(.chat-card-cover-wrap) .chat-card-content p,
.model-card--square:has(.chat-card-cover-wrap) .chat-card-content .card-meta {
    color: #000;
}

.model-card--square .card-provider {
    margin-bottom: 0.2rem;
}

.model-card--square h3 {
    margin-bottom: 0.3rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}

.model-card--square > p {
    width: 100%;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.model-card--square .chat-card-content p {
    flex: 1;
    width: 100%;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.model-card--auto {
    background: var(--color-accent);
    border-color: var(--color-accent);
    align-items: center;
    text-align: center;
}
.model-card--auto h3,
.model-card--auto p,
.model-card--auto .card-meta {
    color: #fff;
}
.model-card--auto p {
    flex: 0;
}

.provider-logo {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    margin-bottom: 0.5rem;
}

.card-meta {
    display: inline-block;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* Card wrapper (for delete button positioning) */
.card-wrap {
    position: relative;
    aspect-ratio: 1;
}
.card-wrap > .card {
    width: 100%;
    height: 100%;
}
.card-delete-btn {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    z-index: 2;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: #e53e3e;
    color: #fff;
    font-size: 0.85rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
    padding: 0;
}
.card-wrap:hover .card-delete-btn,
.model-card--square:hover .card-delete-btn {
    opacity: 1;
}
.card-delete-btn:hover {
    background: #c53030;
}

/* Chat cards */
.chat-card--square {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
}
.chat-card--new {
    background: var(--color-accent);
    border-color: var(--color-accent);
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: pointer;
    width: 100%;
    font-family: inherit;
    font-size: inherit;
}
.chat-card--new h3 {
    color: #fff;
}
.chat-card-plus {
    font-size: 2.5rem;
    font-weight: 300;
    color: #fff;
    line-height: 1;
    margin-bottom: 0.3rem;
}
.chat-card-cover-wrap {
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.chat-card-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.chat-card-content {
    padding: 0.75rem 1rem;
    flex-shrink: 0;
    min-width: 0;
    overflow: hidden;
    width: 100%;
}
.chat-card-content h3 {
    font-size: 0.95rem;
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-card-content p {
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-card--square:not(.chat-card--new):not(:has(.chat-card-cover-wrap)) {
    justify-content: center;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--color-text-muted);
}

.empty-state p { margin-bottom: 1rem; }

/* Forms */
.form { max-width: 640px; }

.form-group {
    margin-bottom: 1.25rem;
    flex: 1;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    font-size: 0.9rem;
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--color-accent);
}

.form-group input[type="range"] {
    padding: 0;
    border: none;
    background: transparent;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
    justify-content: center;
}

.inline-form { display: inline; }

/* Detail layout */
.detail-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}

.detail-layout h2 {
    color: var(--color-heading);
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.detail-config .form { max-width: none; }

/* Playground */
.playground {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.playground-output {
    padding: 1rem;
    min-height: 200px;
    max-height: 500px;
    overflow-y: auto;
}

.playground-output pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.85rem;
    line-height: 1.5;
}

.playground-input {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface-2);
}

.playground-input textarea {
    flex: 1;
    padding: 0.5rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.9rem;
    resize: none;
}

.playground-input textarea:focus {
    outline: none;
    border-color: var(--color-accent);
}
.playground-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

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

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

/* Steps */
.steps-list { margin-bottom: 1.5rem; }

.step-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
}

.step-number {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-accent);
    color: #fff;
    border-radius: 50%;
    font-size: 0.8rem;
    font-weight: 600;
    flex-shrink: 0;
}

.step-info { flex: 1; }
.step-info strong { color: var(--color-heading); }

.step-model {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-left: 0.5rem;
}

.step-template {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

.add-step-form {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.add-step-form h3 {
    color: var(--color-heading);
    margin-bottom: 1rem;
    font-size: 0.95rem;
}

/* Agent Chain */
.agent-chain {
    margin-bottom: 0.75rem;
}
.agent-chain-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
}
.agent-chain-number {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-accent);
    color: #fff;
    border-radius: 50%;
    font-size: 0.8rem;
    font-weight: 600;
    flex-shrink: 0;
}
.agent-chain-name {
    font-weight: 600;
    color: var(--color-heading);
}
.agent-chain-arrow {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}
.agent-chain-remove {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 0.25rem;
}
.agent-chain-remove:hover {
    color: var(--color-danger);
}
.agent-chain-add {
    margin-top: 0.5rem;
}
.form-help {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-bottom: 0.75rem;
}

/* Step results */
.step-result {
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
    padding-bottom: 1rem;
}

.step-result:last-child { border-bottom: none; }

.step-result-header {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-accent);
    margin-bottom: 0.5rem;
}

/* Auth */
.auth-container {
    max-width: 400px;
    margin: 4rem auto;
    text-align: center;
}

.auth-container h1 {
    color: var(--color-heading);
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
}

.auth-form {
    max-width: none;
    text-align: left;
}

.auth-form .form-group input {
    font-size: 1rem;
    padding: 0.75rem 1rem;
}

.btn-full {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    margin-top: 0.5rem;
}

.auth-switch {
    margin-top: 1.5rem;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.form-errors {
    background: rgba(224, 85, 85, 0.1);
    border: 1px solid var(--color-danger);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.form-errors .error {
    font-size: 0.85rem;
    margin: 0.25rem 0;
}

/* Nav user menu */
.nav-user-menu {
    position: relative;
}
.nav-user-btn {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    padding: 0;
}
.nav-user-btn:hover {
    color: var(--color-text);
}
.nav-user-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 0.5rem);
    min-width: 160px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 200;
    overflow: hidden;
}
.nav-user-dropdown--open {
    display: block;
}
.nav-user-dropdown-item {
    display: block;
    padding: 0.6rem 1rem;
    font-size: 0.85rem;
    color: var(--color-text);
    text-decoration: none;
    transition: background 0.15s;
}
.nav-user-dropdown-item:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
}
.nav-user-dropdown-item--danger {
    color: var(--color-danger);
    border-top: 1px solid var(--color-border);
}
.nav-user-dropdown-item--danger:hover {
    background: rgba(224, 85, 85, 0.1);
    color: var(--color-danger);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #34d399;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

/* Dashboard */
.dashboard-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.dashboard-header h1 {
    color: var(--color-heading);
    font-size: 1.8rem;
}

.dashboard-subtitle {
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

.dashboard-actions {
    display: flex;
    gap: 0.75rem;
}

.dashboard-stats {
    display: flex;
    gap: 1rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    min-width: 140px;
}

.stat-number {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-heading);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.empty-state-inline {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--color-text-muted);
}

/* Theme toggle */
.theme-toggle {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-size: 1rem;
    line-height: 1;
    color: var(--color-text-muted);
    transition: border-color 0.2s;
}

.theme-toggle:hover {
    border-color: var(--color-accent);
}

.theme-icon--light { display: inline; }
.theme-icon--dark { display: none; }

[data-theme="light"] .theme-icon--light { display: none; }
[data-theme="light"] .theme-icon--dark { display: inline; }

/* Compare */
.compare-model-grid {
    margin-bottom: 2rem;
}

.compare-select-card {
    position: relative;
    cursor: pointer;
}

.compare-select-card .compare-checkbox {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.compare-check {
    position: absolute;
    bottom: 0.75rem;
    right: 0.75rem;
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-border);
    border-radius: 4px;
    transition: all 0.2s;
}

.compare-select-card--selected .compare-check {
    background: var(--color-accent);
    border-color: var(--color-accent);
}

.compare-select-card--selected .compare-check::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 1px;
    width: 6px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.compare-select-card--selected {
    border-color: var(--color-accent);
}

.compare-select-card--disabled {
    opacity: 0.4;
    pointer-events: none;
}

.compare-prompt {
    display: flex;
    gap: 0.75rem;
    align-items: stretch;
    margin-bottom: 2rem;
}

.compare-prompt textarea {
    flex: 1;
}

.compare-prompt .btn {
    align-self: stretch;
    white-space: nowrap;
}

.compare-prompt textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
}

.compare-prompt textarea:focus {
    outline: none;
    border-color: var(--color-accent);
}

.compare-results {
    display: grid;
    gap: 1rem;
}

.compare-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.compare-card-header {
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-accent);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-2);
}

.compare-card-body {
    padding: 1rem;
    max-height: 500px;
    overflow-y: auto;
}

.compare-card-body pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.85rem;
    line-height: 1.5;
}

.markdown-body {
    font-size: 0.9rem;
    line-height: 1.6;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    color: var(--color-heading);
    margin: 1rem 0 0.5rem;
}
.markdown-body h1:first-child, .markdown-body h2:first-child,
.markdown-body h3:first-child {
    margin-top: 0;
}
.markdown-body p { margin-bottom: 0.75rem; color: var(--color-text); }
.markdown-body ul, .markdown-body ol {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}
.markdown-body li { margin-bottom: 0.25rem; }
.markdown-body code {
    background: var(--color-surface-2);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85em;
}
.markdown-body pre {
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin: 0.75rem 0;
    overflow-x: auto;
}
.markdown-body pre code {
    background: none;
    padding: 0;
}
.markdown-body blockquote {
    border-left: 3px solid var(--color-accent);
    margin: 0.75rem 0;
    padding: 0.25rem 0.75rem;
    color: var(--color-text-muted);
}
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
}
.markdown-body th, .markdown-body td {
    border: 1px solid var(--color-border);
    padding: 0.4rem 0.75rem;
    text-align: left;
}
.markdown-body th {
    background: var(--color-surface-2);
    color: var(--color-heading);
}
.markdown-body strong { color: var(--color-heading); }
.markdown-body a {
    color: var(--color-accent);
    text-decoration: underline;
}
.markdown-body a:hover {
    color: var(--color-accent-hover);
}
.markdown-body img {
    max-width: 360px;
    max-height: 360px;
    border-radius: var(--radius);
    object-fit: contain;
}

/* References */
.ref-link {
    color: var(--color-accent);
    text-decoration: none;
    font-size: 0.8em;
    vertical-align: super;
}
.ref-link:hover {
    text-decoration: underline;
}
.references-section {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
}
.references-section h4 {
    margin-bottom: 0.5rem;
    color: var(--color-heading);
}
.references-section ol {
    padding-left: 1.5rem;
    margin: 0;
}
.references-section li {
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
    word-break: break-all;
}
.references-section a {
    color: var(--color-accent);
    text-decoration: underline;
}
.references-section a:hover {
    color: var(--color-accent-hover);
}

.citations {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--color-border);
    font-size: 0.8rem;
}
.citations strong {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}
.citations ol {
    padding-left: 1.25rem;
    margin: 0;
}
.citations li {
    margin-bottom: 0.2rem;
    color: var(--color-text-muted);
}
.citations a {
    color: var(--color-accent);
    text-decoration: none;
    word-break: break-all;
}
.citations a:hover {
    text-decoration: underline;
}

.compare-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.compare-top-bar .page-description {
    margin: 0;
}

.saved-dropdown {
    position: relative;
}
.saved-dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 0.25rem;
    min-width: 240px;
    max-height: 300px;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 100;
}
.saved-dropdown-menu--open {
    display: block;
}
.saved-dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
}
.saved-dropdown-item:last-child {
    border-bottom: none;
}
.saved-dropdown-name {
    flex: 1;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.saved-dropdown-name:hover {
    color: var(--color-accent);
}
.saved-dropdown-delete {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0 0.25rem;
    line-height: 1;
    flex-shrink: 0;
}
.saved-dropdown-delete:hover {
    color: var(--color-danger);
}

.compare-card-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--color-border);
    text-align: right;
}

.compare-save-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 1rem;
}
.compare-save-input {
    flex: 1;
    padding: 0.5rem 0.8rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.9rem;
}
.compare-save-input:focus {
    outline: none;
    border-color: var(--color-accent);
}

.compare-saved-prompt {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
    color: var(--color-text);
    font-size: 0.9rem;
}
.compare-saved-prompt strong {
    color: var(--color-heading);
}

/* ---- Chat ---- */
main:has(.chat-layout) {
    max-width: none;
    padding: 0;
}
.chat-layout {
    display: flex;
    gap: 0;
    height: calc(100vh - 64px);
}

/* Sidebar */
.chat-sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-sidebar-config {
    padding: 1rem;
    flex: 1;
    overflow-y: auto;
}
.chat-title-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.chat-description-row {
    margin-bottom: 1rem;
}
.chat-description-input {
    width: 100%;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
    resize: vertical;
    min-height: 2.5rem;
}
.chat-description-input:focus {
    outline: none;
    border-color: var(--color-accent);
}
.chat-title-input {
    flex: 1;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-heading);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.4rem 0.6rem;
}
.chat-title-input:focus {
    outline: none;
    border-color: var(--color-accent);
}
.chat-sidebar-section {
    margin-bottom: 1rem;
}
.chat-sidebar-section h4 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    margin-bottom: 0.4rem;
}
.chat-config-select {
    width: 100%;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.82rem;
    padding: 0.35rem 0.5rem;
    cursor: pointer;
}
.chat-config-select:focus {
    outline: none;
    border-color: var(--color-accent);
}
.chat-config-select:disabled {
    opacity: 0.5;
    cursor: default;
}

.chat-selected-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.4rem;
}
.chat-selected-tag {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    color: var(--color-text);
}
.chat-selected-tag button {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0;
}
.chat-selected-tag button:hover {
    color: var(--color-danger);
}


/* Sidebar bottom actions */
.chat-sidebar-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--color-border);
    flex-shrink: 0;
}
.chat-sidebar-action-btn {
    flex: 1;
    text-align: center;
}

/* Cover Image */
.chat-cover-preview {
    border-radius: var(--radius);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    overflow: hidden;
    min-height: 60px;
    max-width: 240px;
    max-height: 240px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: var(--radius);
}
.chat-cover-empty {
    color: var(--color-text-muted);
    font-size: 0.8rem;
}
.chat-cover-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    min-width: 0;
}
.chat-cover-btn {
    flex: 1;
    min-width: 0;
    text-align: center;
    cursor: pointer;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-cover-generate {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.5rem;
    min-width: 0;
}
.chat-cover-prompt-input {
    flex: 1 1 100%;
    min-width: 0;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    padding: 0.35rem 0.5rem;
    font-size: 0.8rem;
}
.chat-cover-generate .btn {
    flex: 1 1 100%;
}
.chat-cover-prompt-input:focus {
    outline: none;
    border-color: var(--color-accent);
}

/* Main area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.chat-conversation {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.chat-empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    font-size: 0.95rem;
}
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}
.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

/* Messages */
.chat-msg {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    line-height: 1.5;
}
.chat-msg--user {
    align-self: flex-end;
    background: var(--color-accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg--user .markdown-body,
.chat-msg--user .markdown-body p,
.chat-msg--user .markdown-body strong {
    color: #fff;
}
.chat-msg--assistant {
    align-self: flex-start;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 4px;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}
.chat-msg--assistant::-webkit-scrollbar {
    height: 6px;
}
.chat-msg--assistant::-webkit-scrollbar-track {
    background: transparent;
}
.chat-msg--assistant::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}
.chat-msg-model {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    margin-bottom: 0.3rem;
}
.chat-msg-body {
    font-size: 0.9rem;
}
.chat-msg-body .markdown-body p:last-child {
    margin-bottom: 0;
}

/* Message actions */
.chat-msg {
    position: relative;
}
.chat-msg-actions {
    display: none;
    gap: 0.2rem;
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
}
.chat-msg:hover .chat-msg-actions {
    display: flex;
}
.chat-msg-actions button {
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-muted);
    padding: 0.25rem;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}
.chat-msg-actions button:hover {
    color: var(--color-accent);
    background: var(--color-surface);
}
.chat-msg--user .chat-msg-actions button {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.7);
}
.chat-msg--user .chat-msg-actions button:hover {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

/* Input bar */
.chat-input-bar {
    padding: 0.75rem 1.5rem 1rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.chat-input-model-row {
    display: flex;
}
.chat-active-model-select {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.82rem;
    padding: 0.35rem 0.6rem;
    cursor: pointer;
}
.chat-active-model-select:focus {
    outline: none;
    border-color: var(--color-accent);
}
/* Attachments */
.chat-attachments {
    display: none;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0 0 0.25rem;
}
.chat-attachment-tag {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    padding: 0.2rem 0.6rem;
    font-size: 0.78rem;
    color: var(--color-text);
    max-width: 220px;
}
.chat-attachment-icon {
    flex-shrink: 0;
    font-size: 0.85rem;
}
.chat-attachment-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-attachment-tag button {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
}
.chat-attachment-tag button:hover {
    color: var(--color-danger);
}
.chat-attach-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 0.4rem;
    border-radius: var(--radius);
    transition: color 0.15s;
    flex-shrink: 0;
}
.chat-attach-btn:hover {
    color: var(--color-accent);
}

.chat-input-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}
.chat-input-row textarea {
    flex: 1;
    padding: 0.6rem 0.8rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.9rem;
    resize: none;
    max-height: 150px;
}
.chat-input-row textarea:focus {
    outline: none;
    border-color: var(--color-accent);
}

/* Responsive */
@media (max-width: 768px) {
    .chat-layout {
        flex-direction: column;
        height: auto;
    }
    .chat-sidebar {
        width: 100%;
        min-width: unset;
        max-height: 300px;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }
    .detail-layout {
        grid-template-columns: 1fr;
    }
    .hero h1 { font-size: 2rem; }
    .hero-actions { flex-direction: column; align-items: center; }
    .form-row { flex-direction: column; gap: 0; }
    .dashboard-header { flex-direction: column; gap: 1rem; }
    .dashboard-stats { flex-direction: column; }
    .compare-prompt { flex-direction: column; }
    .card-grid--square { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .model-card--square .chat-card-content p {
        -webkit-line-clamp: 2;
        flex: 0;
    }
}

/* Settings */
main:has(.settings-layout) {
    max-width: none;
}
.settings-layout {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}
.settings-section {
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1.5rem;
}
.settings-section h2 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}
.form-success {
    background: #d1fae5;
    color: #065f46;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}
[data-theme="dark"] .form-success {
    background: #064e3b;
    color: #6ee7b7;
}

/* Usage */
.usage-filters {
    margin-bottom: 1.25rem;
}
.usage-filter-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: wrap;
}
.usage-filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}
.usage-filter-group > label:first-child {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.usage-filter-group select,
.usage-filter-group input[type="date"] {
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 0.85rem;
    height: 34px;
}
.usage-dropdown {
    position: relative;
}
.usage-dropdown-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 0.85rem;
    cursor: pointer;
    height: 34px;
    min-width: 150px;
    text-align: left;
}
.usage-dropdown-toggle svg {
    flex-shrink: 0;
    transition: transform 0.15s;
}
.usage-dropdown.open .usage-dropdown-toggle svg {
    transform: rotate(180deg);
}
.usage-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    min-width: 100%;
    max-height: 200px;
    overflow-y: auto;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    margin-top: 4px;
    padding: 0.25rem 0;
    z-index: 20;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.usage-dropdown.open .usage-dropdown-menu {
    display: block;
}
.usage-checkbox {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.6rem;
    font-size: 0.85rem;
    font-weight: 400;
    cursor: pointer;
    white-space: nowrap;
}
.usage-checkbox:hover {
    background: var(--color-border);
}
.usage-checkbox input[type="checkbox"] {
    margin: 0;
    flex-shrink: 0;
}
.usage-filter-actions {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}
.usage-filter-actions .btn {
    height: 34px;
    padding: 0 0.75rem;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
}
.usage-summary {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}
.usage-stat {
    flex: 1;
    min-width: 120px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}
.usage-stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
}
.usage-stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}
.usage-table-title {
    font-size: 0.95rem;
    margin: 1.25rem 0 0.5rem;
}
.table-wrap {
    overflow-x: auto;
}
.usage-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.usage-table th,
.usage-table td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}
.usage-table th {
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.usage-table td:not(:first-child),
.usage-table th:not(:first-child) {
    text-align: right;
}

/* Pricing */
.pricing-page {
    max-width: 1000px;
    margin: 0 auto;
}
.pricing-header {
    text-align: center;
    margin-bottom: 2.5rem;
}
.pricing-header h1 {
    color: var(--color-heading);
    font-size: 2rem;
    margin-bottom: 0.5rem;
}
.pricing-subtitle {
    color: var(--color-text-muted);
    font-size: 1.1rem;
}
.pricing-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    align-items: start;
}
.pricing-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    position: relative;
    display: flex;
    flex-direction: column;
}
.pricing-card--featured {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 1px var(--color-accent);
}
.pricing-card--current {
    border-color: #34d399;
}
.pricing-card-badge {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-accent);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.2rem 0.75rem;
    border-radius: 20px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.pricing-card-header {
    margin-bottom: 1.25rem;
}
.pricing-card-header h2 {
    color: var(--color-heading);
    font-size: 1.15rem;
    margin-bottom: 0.5rem;
}
.pricing-amount {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-heading);
}
.pricing-period {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}
.pricing-features {
    list-style: none;
    margin-bottom: 1.5rem;
    flex: 1;
}
.pricing-features li {
    padding: 0.35rem 0;
    font-size: 0.85rem;
    padding-left: 1.5rem;
    position: relative;
}
.pricing-feature--included::before {
    content: "\2713";
    position: absolute;
    left: 0;
    color: #34d399;
    font-weight: 600;
}
.pricing-feature--excluded {
    color: var(--color-text-muted);
    text-decoration: line-through;
    opacity: 0.5;
}
.pricing-feature--excluded::before {
    content: "\2717";
    position: absolute;
    left: 0;
    color: var(--color-text-muted);
}
.pricing-current-badge {
    text-align: center;
    padding: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: #34d399;
    border: 1px solid #34d399;
    border-radius: var(--radius);
}
.pricing-checkout-btn {
    margin-top: auto;
}

/* Plan badge in nav */
.nav-plan-badge {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.45rem;
    border-radius: 20px;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    text-decoration: none;
    transition: opacity 0.2s;
}
.nav-plan-badge:hover {
    opacity: 0.8;
}
.nav-plan-badge--paid {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #fff;
}

/* Billing */
.billing-snapshot {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}
.billing-snapshot-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.billing-snapshot-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}
.billing-snapshot-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-heading);
}
.billing-details p {
    margin: 0.15rem 0;
    font-size: 0.9rem;
}
.billing-invoice-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.billing-invoice-table th {
    text-align: left;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
}
.billing-invoice-table td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
}
.billing-invoice-table tbody tr:last-child td {
    border-bottom: none;
}
.billing-invoice-status {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    text-transform: capitalize;
}
.billing-invoice-status--paid {
    background: #d1fae5;
    color: #065f46;
}
.billing-invoice-status--open {
    background: #fef3c7;
    color: #92400e;
}
.billing-invoice-status--uncollectible,
.billing-invoice-status--void {
    background: var(--color-surface-2);
    color: var(--color-text-muted);
}
@media (max-width: 600px) {
    .billing-snapshot {
        grid-template-columns: 1fr;
    }
}
.upgrade-lines {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: 1rem;
}
.upgrade-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.4rem 0;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--color-border);
}
.upgrade-line-amount--credit {
    color: #059669;
}
.upgrade-total {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.75rem 0;
    font-weight: 600;
    font-size: 1rem;
    border-top: 2px solid var(--color-border);
    margin-bottom: 1rem;
}
.upgrade-total-amount {
    font-size: 1.15rem;
}
.upgrade-note {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-bottom: 1rem;
}

.billing-cancel-note {
    font-size: 0.85rem;
    color: var(--color-danger, #ef4444);
    margin-top: 0.75rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1.5rem;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 0;
    line-height: 1;
}
.modal-close:hover {
    color: var(--color-text);
}

/* Team dashboard */
.team-members-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.team-member-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}
.team-member-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.team-member-name {
    font-weight: 600;
    color: var(--color-heading);
}
.team-member-role {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.15rem 0.45rem;
    border-radius: 20px;
    background: var(--color-surface-2);
    color: var(--color-text-muted);
}
.team-member-role--owner {
    background: var(--color-accent);
    color: #fff;
}
.team-member-role--editor {
    background: #2d7d46;
    color: #fff;
}

/* Workspace layout with sidebar */
main:has(.workspace-layout) {
    max-width: none;
}
.workspace-layout {
    display: flex;
    gap: 2rem;
    min-height: calc(100vh - 80px);
}
.workspace-sidebar {
    width: 220px;
    flex-shrink: 0;
    border-right: 1px solid var(--color-border);
    padding-right: 1.5rem;
}
.workspace-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border);
}
.workspace-sidebar-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.workspace-sidebar-edit {
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.workspace-sidebar-edit:hover {
    color: var(--color-text);
}
.workspace-sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.workspace-sidebar-link {
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    transition: background 0.15s, color 0.15s;
}
.workspace-sidebar-link:hover {
    background: var(--color-surface-2);
    color: var(--color-text);
}
.workspace-sidebar-link--active {
    background: var(--color-surface-2);
    color: var(--color-text);
    font-weight: 600;
}
.workspace-main {
    flex: 1;
    min-width: 0;
}
.workspace-main .card-grid--square {
    grid-template-columns: repeat(auto-fill, minmax(220px, 250px));
}
.move-to-workspace {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1.5rem;
}
.move-to-workspace__select {
    flex: 1;
    max-width: 360px;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.9rem;
}
@media (max-width: 768px) {
    .workspace-layout {
        flex-direction: column;
        gap: 1rem;
    }
    .workspace-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        padding-right: 0;
        padding-bottom: 1rem;
    }
    .workspace-sidebar-nav {
        flex-direction: row;
        gap: 0.5rem;
    }
}

.form-row {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
}
.form-group--grow {
    flex: 1;
}
.form-group--action {
    padding-bottom: 0;
}
.messages {
    margin-bottom: 1rem;
}
.alert--success {
    background: rgba(45, 125, 70, 0.15);
    border: 1px solid #2d7d46;
    color: #4ade80;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
}
.alert--error {
    background: rgba(224, 85, 85, 0.15);
    border: 1px solid var(--color-danger);
    color: var(--color-danger);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
}

@media (max-width: 768px) {
    .pricing-grid {
        grid-template-columns: 1fr;
        max-width: 360px;
        margin: 0 auto;
    }
    .form-row {
        flex-direction: column;
        align-items: stretch;
    }
}

/* ── Help button ─────────────────────────────────────────── */
.help-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1.5px solid var(--color-border);
    background: none;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    flex-shrink: 0;
}
.help-btn:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
    background: rgba(124, 111, 224, 0.08);
}

/* ── Help overlay ────────────────────────────────────────── */
.help-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 900;
    animation: help-fade-in 0.2s ease;
}
.help-overlay--open {
    display: block;
}
@keyframes help-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Help sidebar ────────────────────────────────────────── */
.help-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(480px, 100vw);
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    z-index: 901;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}
.help-sidebar--open {
    transform: translateX(0);
}

.help-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.help-sidebar-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-heading);
    margin: 0;
}
.help-sidebar-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius);
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}
.help-sidebar-close:hover {
    color: var(--color-text);
    background: var(--color-surface-2);
}

/* Table of contents */
.help-toc {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.help-toc-link {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: 20px;
    padding: 0.2rem 0.65rem;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
    white-space: nowrap;
}
.help-toc-link:hover {
    color: var(--color-accent);
    border-color: var(--color-accent);
    background: rgba(124, 111, 224, 0.08);
}

/* Scrollable body */
.help-sidebar-body {
    overflow-y: auto;
    flex: 1;
    padding: 1.5rem;
    scroll-behavior: smooth;
}

/* Sections */
.help-section {
    padding-bottom: 2rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--color-border);
}
.help-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}
.help-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-heading);
    margin-bottom: 0.6rem;
}
.help-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-heading);
    margin-top: 1.1rem;
    margin-bottom: 0.4rem;
}
.help-section p {
    font-size: 0.875rem;
    color: var(--color-text);
    line-height: 1.65;
    margin-bottom: 0.5rem;
}
.help-section a {
    color: var(--color-accent);
}
.help-section a:hover {
    color: var(--color-accent-hover);
}
.help-section code {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.8rem;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    padding: 0.1em 0.35em;
    color: var(--color-accent);
}
kbd {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.75rem;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 0.1em 0.4em;
    color: var(--color-text);
}

/* Ordered / unordered lists */
.help-steps,
.help-list {
    font-size: 0.875rem;
    color: var(--color-text);
    line-height: 1.65;
    padding-left: 1.4rem;
    margin-top: 0.4rem;
}
.help-steps li,
.help-list li {
    margin-bottom: 0.35rem;
}

/* FAQ */
.help-faq {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.help-faq dt {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-heading);
}
.help-faq dd {
    font-size: 0.875rem;
    color: var(--color-text);
    line-height: 1.65;
    margin-left: 0;
    margin-top: 0.25rem;
}

/* Media placeholders */
.help-placeholder {
    margin: 1rem 0;
    padding: 1rem 1.25rem;
    background: var(--color-surface-2);
    border: 1.5px dashed var(--color-border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    color: var(--color-text-muted);
    line-height: 1.5;
    font-style: italic;
}

/* Mobile adjustments */
@media (max-width: 480px) {
    .help-sidebar {
        width: 100vw;
    }
}

/* Impersonation banner */
.impersonation-banner {
    background: #7c3aed;
    color: #fff;
    text-align: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Admin user table */
.table-container {
    overflow-x: auto;
    margin-top: 1rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
}

.data-table th {
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-surface-2);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--color-surface-2); }
