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

/* Theme variables for the chat app (index.html) only - about/terms/privacy
   don't load script.js so they never get a data-theme attribute and keep
   their original light-only styling regardless of the setting below. */
:root {
    --bg-app: #ffffff;
    --bg-header: #2c2c2c;
    --text-header: #f5f5f5;
    --bg-panel: #f8f9fa;
    --border-panel: #e0e0e0;
    --bg-widget: #f5f5f5;
    --border-input: #cccccc;
    --bg-input: #ffffff;
    --bg-hover: #e8e8e8;
    --text-body: #333333;
    --text-secondary: #555555;
    --text-muted: #999999;
    --bg-bubble-user: #667eea;
    --text-bubble-user: #ffffff;
    --bg-bubble-assistant: #f0f0f5;
    --text-bubble-assistant: #333333;
    --accent: #667eea;
    --bg-modal: #ffffff;
    --bg-backdrop: rgba(0, 0, 0, 0.5);
    --danger: #d9534f;
    --danger-hover: #c9302c;
}

[data-theme="dark"] {
    --bg-app: #1c1c1e;
    --bg-header: #161616;
    --text-header: #f0f0f0;
    --bg-panel: #232326;
    --border-panel: #3a3a3d;
    --bg-widget: #28282b;
    --border-input: #46464a;
    --bg-input: #2a2a2d;
    --bg-hover: #333336;
    --text-body: #e8e8ea;
    --text-secondary: #c7c7ca;
    --text-muted: #9a9a9e;
    --bg-bubble-user: #667eea;
    --text-bubble-user: #ffffff;
    --bg-bubble-assistant: #2c2c30;
    --text-bubble-assistant: #e8e8ea;
    --accent: #8b98f0;
    --bg-modal: #242427;
    --bg-backdrop: rgba(0, 0, 0, 0.7);
    --danger: #e05a56;
    --danger-hover: #c9302c;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg-app: #1c1c1e;
        --bg-header: #161616;
        --text-header: #f0f0f0;
        --bg-panel: #232326;
        --border-panel: #3a3a3d;
        --bg-widget: #28282b;
        --border-input: #46464a;
        --bg-input: #2a2a2d;
        --bg-hover: #333336;
        --text-body: #e8e8ea;
        --text-secondary: #c7c7ca;
        --text-muted: #9a9a9e;
        --bg-bubble-user: #667eea;
        --text-bubble-user: #ffffff;
        --bg-bubble-assistant: #2c2c30;
        --text-bubble-assistant: #e8e8ea;
        --accent: #8b98f0;
        --bg-modal: #242427;
        --bg-backdrop: rgba(0, 0, 0, 0.7);
        --danger: #e05a56;
        --danger-hover: #c9302c;
    }
}

/* Named themes - opt-in only (not tied to prefers-color-scheme, since the
   OS only knows light/dark) but persisted the same way via data-theme. */
[data-theme="solarized"] {
    --bg-app: #fdf6e3;
    --bg-header: #073642;
    --text-header: #fdf6e3;
    --bg-panel: #eee8d5;
    --border-panel: #d3cbb7;
    --bg-widget: #eee8d5;
    --border-input: #cdc4ae;
    --bg-input: #fdf6e3;
    --bg-hover: #e4dcc5;
    --text-body: #073642;
    --text-secondary: #586e75;
    --text-muted: #93a1a1;
    --bg-bubble-user: #268bd2;
    --text-bubble-user: #fdf6e3;
    --bg-bubble-assistant: #eee8d5;
    --text-bubble-assistant: #073642;
    --accent: #cb4b16;
    --bg-modal: #fdf6e3;
    --bg-backdrop: rgba(7, 54, 66, 0.5);
    --danger: #dc322f;
    --danger-hover: #b91c1c;
}

[data-theme="midnight"] {
    --bg-app: #16121f;
    --bg-header: #0e0b16;
    --text-header: #f0eaff;
    --bg-panel: #1f1a2e;
    --border-panel: #372f4d;
    --bg-widget: #241d35;
    --border-input: #453a5e;
    --bg-input: #241d35;
    --bg-hover: #2e2545;
    --text-body: #ece6fa;
    --text-secondary: #c3b8e0;
    --text-muted: #9084b3;
    --bg-bubble-user: #a78bfa;
    --text-bubble-user: #16121f;
    --bg-bubble-assistant: #241d35;
    --text-bubble-assistant: #ece6fa;
    --accent: #a78bfa;
    --bg-modal: #1f1a2e;
    --bg-backdrop: rgba(0, 0, 0, 0.75);
    --danger: #f87171;
    --danger-hover: #ef4444;
}

[data-theme="forest"] {
    --bg-app: #0f1e17;
    --bg-header: #0a1611;
    --text-header: #eafff2;
    --bg-panel: #16281f;
    --border-panel: #2b4536;
    --bg-widget: #1c3226;
    --border-input: #35533f;
    --bg-input: #1c3226;
    --bg-hover: #24402f;
    --text-body: #e3f5e9;
    --text-secondary: #b7d9c3;
    --text-muted: #82a690;
    --bg-bubble-user: #34d399;
    --text-bubble-user: #0a1611;
    --bg-bubble-assistant: #1c3226;
    --text-bubble-assistant: #e3f5e9;
    --accent: #34d399;
    --bg-modal: #16281f;
    --bg-backdrop: rgba(0, 0, 0, 0.75);
    --danger: #f87171;
    --danger-hover: #ef4444;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-panel);
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px;
    color: var(--text-body);
    overflow-x: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--bg-app);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Header */
.header {
    background: var(--bg-header);
    color: var(--text-header);
    padding: 30px 20px;
    text-align: center;
    border-bottom: 1px solid #ddd;
}

.header-content h1 {
    font-size: 2.5em;
    margin-bottom: 8px;
    font-weight: 700;
}

.header-content p {
    font-size: 1.1em;
    opacity: 0.95;
}

.classic-nav {
    margin-top: 10px;
}

.classic-nav a {
    color: var(--text-header);
    font-size: 0.9em;
    opacity: 0.85;
}

.classic-nav a:hover {
    opacity: 1;
    text-decoration: underline;
}

/* Main Content */
.main {
    flex: 1;
    padding: 40px;
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 40px;
}

.section {
    background: var(--bg-panel);
    border-radius: 12px;
    padding: 25px;
}

.section h2 {
    font-size: 1.5em;
    color: var(--text-body);
    margin-bottom: 10px;
}

.section h3 {
    color: var(--text-secondary);
    margin-bottom: 15px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.95em;
    margin-bottom: 20px;
}

/* Traits Section */
.traits-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.btn-collapse {
    background: none;
    border: 1px solid var(--border-input);
    border-radius: 6px;
    width: 28px;
    height: 28px;
    line-height: 1;
    font-size: 1em;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-collapse:hover {
    background: var(--bg-hover);
    border-color: #999;
}

.favorites-bar {
    display: none;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.favorites-empty {
    color: var(--text-muted);
    font-size: 0.9em;
    font-style: italic;
}

.traits-list {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.trait-badge {
    background: var(--bg-widget);
    border: 1px solid var(--border-input);
    border-radius: 6px;
    padding: 10px 14px;
    cursor: grab;
    user-select: none;
    transition: all 0.2s ease;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
    touch-action: manipulation;
}

.trait-badge:hover {
    background: var(--bg-hover);
    border-color: #999;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

.trait-badge.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.trait-emoji {
    font-size: 1.2em;
}

.trait-favorite-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1em;
    color: #bbb;
    padding: 0;
    line-height: 1;
}

.trait-favorite-btn:hover {
    color: #f5a623;
}

.trait-favorite-btn.active {
    color: #f5a623;
}

.loading {
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
}

/* Builder Section */
.builder-section {
    grid-column: 2;
}

.builder-content {
    background: var(--bg-app);
    border-radius: 12px;
    padding: 25px;
    border: 2px solid var(--border-panel);
}

.agent-info {
    margin-bottom: 25px;
}

.agent-info h2 {
    margin-bottom: 15px;
}

.agent-name-group {
    display: flex;
    gap: 10px;
}

.agent-name-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--border-input);
    border-radius: 4px;
    font-size: 1em;
    background: var(--bg-input);
    color: var(--text-body);
    transition: border-color 0.2s;
}

.agent-name-input:focus {
    outline: none;
    border-color: #666;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
}

.past-agents-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
}

.past-agents-label {
    color: var(--text-secondary);
    font-size: 0.9em;
    white-space: nowrap;
}

.past-agents-select {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--border-input);
    border-radius: 4px;
    font-size: 16px;
    background: var(--bg-input);
    color: var(--text-body);
}

.btn-icon {
    background: none;
    border: 1px solid var(--border-input);
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 0.9em;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    display: inline-block;
    text-decoration: none;
}

.btn-icon:hover {
    background: #fde8e8;
    border-color: #e57373;
    color: #c62828;
}

.past-agents-select:focus {
    outline: none;
    border-color: #666;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
}

.trait-search-input {
    width: 100%;
    padding: 8px 12px;
    margin-bottom: 15px;
    border: 1px solid var(--border-input);
    border-radius: 4px;
    font-size: 16px;
    background: var(--bg-input);
    color: var(--text-body);
    transition: border-color 0.2s;
}

.trait-search-input:focus {
    outline: none;
    border-color: #666;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
}

/* Drop Zone */
.drop-zone {
    background: var(--bg-widget);
    border: 2px dashed #bbb;
    border-radius: 8px;
    padding: 30px;
    text-align: center;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    margin-bottom: 25px;
    position: relative;
}

.drop-zone.drag-over {
    background: var(--bg-hover);
    border-color: #888;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.drop-zone.drag-over .drop-zone-placeholder {
    color: var(--text-body);
    opacity: 1;
}

.drop-zone-placeholder {
    pointer-events: none;
}

.drop-zone-icon {
    font-size: 3em;
    margin-bottom: 10px;
}

.drop-zone-text {
    font-size: 1.2em;
    font-weight: 500;
    color: var(--accent);
    margin-bottom: 5px;
}

.drop-zone-subtext {
    font-size: 0.9em;
    color: var(--text-muted);
}

.agent-traits {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
    margin-top: 15px;
}

.agent-trait {
    background: var(--bg-widget);
    border: 1px solid #999;
    border-radius: 6px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    color: var(--text-secondary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    animation: slideIn 0.3s ease;
    font-size: 0.9em;
    max-width: 100%;
}

.agent-trait .trait-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.trait-intensity-slider {
    width: 70px;
    accent-color: #667eea;
    cursor: pointer;
}

.trait-intensity-value {
    font-size: 0.85em;
    color: var(--text-muted);
    min-width: 32px;
    text-align: right;
}

.agent-trait .trait-remove {
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 4px;
    width: 20px;
    height: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1em;
    transition: all 0.2s;
    padding: 0;
}

.agent-trait .trait-remove:hover {
    background: var(--danger-hover);
    transform: scale(1.1);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.agent-summary {
    background: var(--bg-widget);
    border-left: 3px solid #666;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 25px;
}

.agent-summary h3 {
    color: var(--text-body);
    margin-bottom: 8px;
    font-size: 0.95em;
}

.agent-summary p {
    color: var(--text-secondary);
    line-height: 1.6;
    font-size: 0.9em;
}

/* Prompt Section */
.prompt-section {
    background: var(--bg-app);
    border-radius: 12px;
    padding: 25px;
    border: 2px solid var(--border-panel);
    margin-top: 25px;
}

.prompt-section h2 {
    margin-bottom: 15px;
}

.prompt-input-group {
    margin-bottom: 15px;
}

.prompt-input {
    width: 100%;
    border: 1px solid var(--border-input);
    border-radius: 4px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 1em;
    resize: vertical;
    background: var(--bg-input);
    color: var(--text-body);
    transition: border-color 0.2s;
}

.prompt-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
}

.prompt-suggestion {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.prompt-suggestion-label {
    font-size: 0.85em;
    color: var(--text-muted);
    white-space: nowrap;
}

.suggestion-chip {
    background: var(--bg-widget);
    border: 1px solid var(--border-input);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 0.85em;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    animation: slideIn 0.3s ease;
}

.suggestion-chip:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text-body);
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: #555;
    color: white;
}

.btn-primary:hover {
    background: #333;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.btn-success {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 100%;
}

.btn-success:hover:not(:disabled) {
    background: #333;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.btn-success:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Output Section */
.output-section {
    background: var(--bg-app);
    border-radius: 12px;
    padding: 25px;
    border: 2px solid var(--border-panel);
    margin-top: 25px;
    animation: slideIn 0.3s ease;
}

.output-section h2 {
    margin-bottom: 20px;
}

.output-comparison {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 15px;
    margin-bottom: 25px;
    align-items: stretch;
}

.output-box {
    background: var(--bg-panel);
    border-radius: 4px;
    padding: 15px;
    border-left: 3px solid #999;
}

.output-box.original {
    border-left-color: #888;
}

.output-box.modified {
    border-left-color: #666;
}

.output-box h3 {
    font-size: 0.95em;
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-weight: 600;
}

.output-box p {
    color: var(--text-body);
    line-height: 1.6;
    font-size: 0.95em;
}

.output-arrow {
    display: flex;
    align-items: center;
    font-size: 2em;
    color: var(--accent);
    font-weight: bold;
}

.output-traits {
    background: var(--bg-widget);
    border-left: 3px solid #666;
    padding: 15px;
    border-radius: 4px;
}

.output-traits h4 {
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-size: 0.95em;
}

.traits-display {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.trait-display {
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

/* Footer */
.footer {
    background: var(--bg-panel);
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    border-top: 1px solid var(--border-panel);
}

.footer-links {
    margin-top: 8px;
    font-size: 0.9em;
}

.footer-links a {
    color: var(--accent);
    text-decoration: none;
}

.footer-links a:hover {
    text-decoration: underline;
}

/* Legal pages */
.legal-main {
    display: block;
    padding: 40px;
}

.legal-section {
    max-width: 800px;
    margin: 0 auto;
    line-height: 1.6;
}

.legal-section h2 {
    margin-top: 25px;
    margin-bottom: 10px;
    color: var(--text-body);
    font-size: 1.2em;
}

.legal-section p {
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.legal-section a {
    color: var(--accent);
}

/* Traits guide page - wider than .legal-section since it's a grid of many
   short cards, not a column of paragraphs. */
.traits-guide-section {
    max-width: 1100px;
    margin: 0 auto;
    line-height: 1.6;
}

.traits-guide-section a {
    color: var(--accent);
}

.traits-guide-intro {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.traits-filter-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-input);
    border-radius: 10px;
    font-family: inherit;
    font-size: 1em;
    background: var(--bg-input);
    color: var(--text-body);
    margin-bottom: 6px;
    transition: border-color 0.2s;
}

.traits-filter-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.15);
}

.traits-filter-count {
    color: var(--text-muted);
    font-size: 0.85em;
    margin-bottom: 16px;
    min-height: 1.2em;
}

.traits-guide-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
}

.trait-guide-card {
    background: var(--bg-widget);
    border: 1px solid var(--border-panel);
    border-radius: 12px;
    padding: 14px 16px;
}

.trait-guide-name {
    font-weight: 700;
    color: var(--text-body);
    margin-bottom: 4px;
}

.trait-guide-description {
    color: var(--text-secondary);
    font-size: 0.9em;
    line-height: 1.4;
}

.traits-guide-empty {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 30px 0;
}

/* Responsive */
@media (max-width: 900px) {
    .main {
        grid-template-columns: 1fr;
    }

    /* On a single column, show the agent builder before the (long) traits
       list so mobile users reach "Create Agent" without scrolling past
       every trait badge first. */
    .builder-section {
        grid-column: 1;
        order: 1;
    }

    .traits-section {
        order: 2;
    }

    .output-comparison {
        grid-template-columns: 1fr;
    }

    .output-arrow {
        transform: rotate(90deg);
        justify-self: center;
    }

    .header-content h1 {
        font-size: 1.8em;
    }
}

@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    .header {
        padding: 20px 15px;
    }

    .main {
        padding: 20px;
        gap: 20px;
    }

    .section, .builder-content {
        padding: 15px;
    }

    .agent-name-group {
        flex-direction: column;
    }

    .agent-name-input {
        width: 100%;
    }

    .past-agents-group {
        flex-wrap: wrap;
    }

    .past-agents-select {
        flex-basis: 100%;
    }

    .traits-list {
        gap: 8px;
    }

    .trait-badge {
        flex: 0 1 calc(50% - 4px);
        min-width: 0;
    }

    .trait-badge span:nth-child(2) {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .btn-collapse, .btn-icon {
        min-height: 36px;
        min-width: 36px;
    }

    .drop-zone {
        padding: 20px;
        min-height: 150px;
    }

    .output-comparison {
        gap: 10px;
    }
}

@media (max-width: 400px) {
    .header-content h1 {
        font-size: 1.4em;
    }

    .header-content p {
        font-size: 0.95em;
    }

    .trait-badge {
        flex: 0 1 100%;
    }
}

/* Animation for drag feedback */
@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 0, 0, 0.1);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(0, 0, 0, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0);
    }
}

.drop-zone.drag-over {
    animation: pulse 0.6s;
}

/* ==========================================================================
   Chat UI (index.html)
   ========================================================================== */

.app {
    max-width: 1400px;
    margin: 0 auto;
    background: var(--bg-app);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

.app-header {
    background: var(--bg-header);
    color: var(--text-header);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid #ddd;
    position: relative;
}

.app-header h1 {
    font-size: 1.4em;
    white-space: nowrap;
}

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

.header-actions .btn-icon {
    background: #3a3a3a;
    border-color: #555;
    color: #f5f5f5;
}

.header-actions .btn-icon:hover {
    background: #4a4a4a;
    border-color: #777;
    color: #fff;
}

.chat-list-wrap {
    position: relative;
}

.chat-list-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 280px;
    max-height: 400px;
    background: var(--bg-modal);
    border: 1px solid var(--border-panel);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    padding: 10px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-list-items {
    overflow-y: auto;
    max-height: 320px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-list-empty {
    color: var(--text-muted);
    font-size: 0.9em;
    font-style: italic;
    padding: 8px 4px;
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 6px;
}

.chat-list-item.active {
    background: var(--bg-hover);
}

.chat-list-item-label {
    flex: 1;
    min-width: 0;
    text-align: left;
    background: none;
    border: none;
    padding: 8px;
    color: var(--text-body);
    font-size: 0.9em;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-radius: 6px;
}

.chat-list-item-label:hover {
    background: var(--bg-hover);
}

.chat-list-item-delete {
    background: none;
    border: none;
    padding: 6px;
    cursor: pointer;
    font-size: 0.95em;
    border-radius: 6px;
    flex-shrink: 0;
}

.chat-list-item-delete:hover {
    background: #fde8e8;
}

.chat-list-hint {
    color: var(--text-muted);
    font-size: 0.75em;
    padding: 4px;
    border-top: 1px solid var(--border-panel);
    padding-top: 8px;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

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

.app-main {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* Chat column */
.chat-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    padding: 20px 24px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 12px;
}

.chat-empty-state {
    margin: auto;
    text-align: center;
    color: var(--text-muted);
}

.chat-empty-icon {
    font-size: 2.5em;
    margin-bottom: 8px;
}

.chat-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    animation: slideIn 0.2s ease;
}

.chat-bubble-user {
    align-self: flex-end;
    background: var(--bg-bubble-user);
    color: var(--text-bubble-user);
    border-bottom-right-radius: 4px;
}

.chat-bubble-assistant {
    align-self: flex-start;
    background: var(--bg-bubble-assistant);
    color: var(--text-bubble-assistant);
    border-bottom-left-radius: 4px;
}

.chat-bubble-typing {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
}

.typing-dots {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

.typing-label {
    font-size: 0.85em;
    color: var(--text-muted);
    font-style: italic;
}

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Chat input */
.chat-input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    border-top: 1px solid var(--border-panel);
    padding-top: 14px;
}

.chat-input-row .attach-btn {
    flex-shrink: 0;
}

.chat-input-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
}

.chat-input {
    width: 100%;
    resize: none;
    max-height: 160px;
    padding: 12px 14px;
    border: 1px solid var(--border-input);
    border-radius: 10px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 1em;
    background: var(--bg-input);
    color: var(--text-body);
    transition: border-color 0.2s;
}

.chat-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.15);
}

.chat-input-row .btn {
    padding: 12px 20px;
}

/* Rotating prompt suggestions: sits visually on top of the empty textarea
   like a fancier placeholder, hidden the moment there's real content or
   focus so it never fights with typing. */
.suggestion-overlay {
    position: absolute;
    left: 15px;
    right: 15px;
    top: 12px;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    text-align: left;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 1em;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-decoration: underline;
    text-decoration-style: dashed;
    text-decoration-color: var(--border-input);
    text-underline-offset: 3px;
}

.suggestion-overlay:hover {
    color: var(--text-secondary);
    text-decoration-style: solid;
    text-decoration-color: var(--text-secondary);
}

/* Attached image */
.image-preview-chip {
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    margin-bottom: 10px;
    background: var(--bg-widget);
    border: 1px solid var(--border-panel);
    border-radius: 10px;
    max-width: fit-content;
}

.image-preview-thumb {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 6px;
}

.image-preview-name {
    font-size: 0.85em;
    color: var(--text-secondary);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2em;
    line-height: 1;
    cursor: pointer;
    padding: 2px 4px;
}

.image-remove-btn:hover {
    color: var(--text-body);
}

.chat-image-bubble {
    align-self: flex-end;
    max-width: 220px;
    max-height: 220px;
    border-radius: 12px;
    object-fit: cover;
}

/* Each turn (user prompt + optional image + the arena round) is wrapped in
   one of these so they can be minimized together - see maybeCollapseTurn()
   in script.js. */
.chat-turn {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.arena-round-note {
    font-size: 0.8em;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 6px;
}

/* AI Arena: two-option rounds */
.arena-round {
    display: flex;
    flex-direction: column;
    align-self: stretch;
    max-width: 100%;
}

.arena-options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

@media (max-width: 700px) {
    .arena-options-grid {
        grid-template-columns: 1fr;
    }
}

.arena-option {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--border-panel);
    border-radius: 14px;
    background: var(--bg-panel);
    transition: border-color 0.2s ease, opacity 0.2s ease;
}

.arena-option-label {
    font-size: 0.8em;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.arena-option-body {
    max-width: 100%;
    align-self: stretch;
}

/* Auto-minimized past turns: every child (prompt bubble, image, arena round)
   is hidden and replaced by a single compact summary row, so old turns take
   up almost no space and the window doesn't keep growing turn after turn -
   see maybeCollapseTurn() in script.js. Scrolling up still reaches them;
   they're just visually collapsed, not removed. */
.chat-turn.is-collapsed > .chat-bubble,
.chat-turn.is-collapsed > .chat-image-bubble,
.chat-turn.is-collapsed > .arena-round {
    display: none;
}

.turn-summary {
    display: none;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-widget);
    border: 1px solid var(--border-input);
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 0.9em;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
}

.chat-turn.is-collapsed .turn-summary {
    display: flex;
}

.turn-summary:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text-body);
}

.turn-summary-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.turn-summary-chevron {
    flex-shrink: 0;
}

/* Markdown rendered inside a reply - see renderMarkdown() in script.js */
.arena-option-body p {
    margin: 0 0 10px;
}

.arena-option-body p:last-child {
    margin-bottom: 0;
}

.arena-option-body h1,
.arena-option-body h2,
.arena-option-body h3,
.arena-option-body h4,
.arena-option-body h5,
.arena-option-body h6 {
    margin: 12px 0 6px;
    line-height: 1.3;
}

.arena-option-body h1:first-child,
.arena-option-body h2:first-child,
.arena-option-body h3:first-child {
    margin-top: 0;
}

.arena-option-body ul {
    margin: 0 0 10px;
    padding-left: 22px;
}

.arena-option-body li {
    margin-bottom: 4px;
}

.arena-option-body code {
    background: var(--bg-widget);
    border: 1px solid var(--border-panel);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.arena-option-body pre {
    background: var(--bg-widget);
    border: 1px solid var(--border-panel);
    border-radius: 8px;
    padding: 10px 12px;
    margin: 0 0 10px;
    overflow-x: auto;
}

.arena-option-body pre code {
    background: none;
    border: none;
    padding: 0;
    white-space: pre;
}

.arena-vote-btn {
    align-self: flex-start;
}

.arena-option.is-winner {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.arena-option.is-winner .arena-option-label::after {
    content: ' · Winner';
    color: var(--accent);
    text-transform: none;
    letter-spacing: normal;
}

.arena-option.is-loser {
    opacity: 0.6;
}

.arena-option-traits {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.trait-chip {
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 0.8em;
    color: var(--text-secondary);
}

.trait-chip-empty {
    font-style: italic;
    color: var(--text-muted);
}

.app-footer {
    background: var(--bg-panel);
    padding: 14px;
    text-align: center;
    color: var(--text-muted);
    border-top: 1px solid var(--border-panel);
}

.app-footer .footer-links {
    font-size: 0.85em;
}

.app-footer .footer-links a {
    color: var(--accent);
    text-decoration: none;
}

.app-footer .footer-links a:hover {
    text-decoration: underline;
}

/* Chat UI responsive */
@media (max-width: 900px) {
    .chat-column {
        min-height: 60vh;
    }
}

@media (max-width: 600px) {
    body {
        padding: 0;
    }

    .app-header {
        flex-wrap: wrap;
        padding: 12px 16px;
        row-gap: 8px;
    }

    .app-header h1 {
        font-size: 1.2em;
    }

    .header-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .header-actions .btn-icon {
        padding: 6px 8px;
        font-size: 0.85em;
    }

    .chat-column {
        padding: 14px;
    }

    .chat-bubble {
        max-width: 88%;
    }
}

/* ==========================================================================
   Modals (settings, delete-all confirmation)
   ========================================================================== */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--bg-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

/* Short viewports (mobile landscape) - the backdrop's own padding plus a
   centered 90dvh box can still pinch the header/actions off-screen, so
   tighten things up rather than relying on scroll alone. */
@media (max-height: 480px) {
    .modal-backdrop {
        padding: 10px;
        align-items: flex-start;
    }

    .modal-box {
        max-height: 96vh;
        max-height: 96dvh;
        margin-top: 2vh;
    }

    .modal-header {
        padding: 10px 16px;
    }

    .modal-body {
        padding: 12px 16px;
    }

    .settings-section {
        margin-bottom: 14px;
    }

    .modal-actions {
        padding: 10px 16px;
    }
}

.modal-box {
    background: var(--bg-modal);
    color: var(--text-body);
    border-radius: 12px;
    max-width: 440px;
    width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
    animation: slideIn 0.2s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-panel);
    position: sticky;
    top: 0;
    background: var(--bg-modal);
    z-index: 1;
}

.modal-header h2 {
    font-size: 1.2em;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5em;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
}

.modal-close:hover {
    color: var(--text-body);
}

.modal-body {
    padding: 20px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border-panel);
    position: sticky;
    bottom: 0;
    background: var(--bg-modal);
}

.settings-section {
    margin-bottom: 22px;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section h3 {
    font-size: 1em;
    margin-bottom: 10px;
    color: var(--text-body);
}

.settings-hint {
    color: var(--text-muted);
    font-size: 0.9em;
    margin-bottom: 12px;
}

.theme-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.theme-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.95em;
}

.settings-select {
    width: 100%;
    padding: 8px 10px;
    margin-bottom: 8px;
    border: 1px solid var(--border-input);
    border-radius: 6px;
    font-size: 0.95em;
    background: var(--bg-input);
    color: var(--text-body);
}

/* ==========================================================================
   First-run guided tour
   ========================================================================== */

.tour-overlay {
    position: fixed;
    inset: 0;
    z-index: 1500;
    pointer-events: none;
}

.tour-spotlight {
    position: fixed;
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.72);
    transition: top 0.25s ease, left 0.25s ease, width 0.25s ease, height 0.25s ease;
    pointer-events: none;
}

.tour-tooltip {
    position: fixed;
    width: 300px;
    background: var(--bg-modal);
    color: var(--text-body);
    border-radius: 10px;
    padding: 16px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    pointer-events: auto;
    transition: top 0.25s ease, left 0.25s ease;
}

.tour-step-count {
    font-size: 0.8em;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.tour-tooltip h3 {
    font-size: 1.05em;
    margin-bottom: 6px;
}

.tour-tooltip p#tourBody {
    color: var(--text-secondary);
    font-size: 0.9em;
    line-height: 1.5;
    margin-bottom: 14px;
}

.tour-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.tour-actions .btn {
    padding: 8px 16px;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 8px 10px;
    cursor: pointer;
    font-size: 0.95em;
}

.btn-text:hover {
    color: var(--text-secondary);
    text-decoration: underline;
}

/* ==========================================================================
   Analytics page
   ========================================================================== */

.analytics-main {
    display: block;
    padding: 40px;
}

.analytics-main .section {
    max-width: 900px;
    margin: 0 auto;
}

.analytics-status {
    color: var(--text-secondary);
    padding: 20px 0;
}

.stat-tile-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin: 20px 0 30px;
}

.stat-tile {
    background: var(--bg-widget);
    border: 1px solid var(--border-panel);
    border-radius: 12px;
    padding: 16px;
    text-align: center;
}

.stat-tile-value {
    font-size: 1.6em;
    font-weight: 700;
    color: var(--text-body);
}

.stat-tile-label {
    font-size: 0.8em;
    color: var(--text-muted);
    margin-top: 4px;
}

.chart-card {
    background: var(--bg-widget);
    border: 1px solid var(--border-panel);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.chart-card h2 {
    font-size: 1.1em;
    color: var(--text-body);
    margin-bottom: 4px;
}

.chart-subtitle {
    color: var(--text-muted);
    font-size: 0.85em;
    margin-bottom: 16px;
}

.chart-empty {
    color: var(--text-muted);
    font-size: 0.9em;
    font-style: italic;
}

.chart-canvas-wrap {
    position: relative;
    height: 320px;
}

.chart-picker-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.85em;
    margin-bottom: 12px;
}

.chart-picker-label select {
    margin-left: 6px;
    padding: 6px 10px;
    border: 1px solid var(--border-input);
    border-radius: 4px;
    font-size: 0.95em;
    background: var(--bg-input);
    color: var(--text-body);
}

.bar-chart {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bar-row {
    display: grid;
    grid-template-columns: 110px 1fr 100px;
    align-items: center;
    gap: 10px;
}

.bar-row-label {
    color: var(--text-body);
    font-size: 0.9em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-track {
    background: var(--bg-panel);
    border: 1px solid var(--border-panel);
    border-radius: 6px;
    height: 14px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 6px;
}

.bar-row-value {
    color: var(--text-secondary);
    font-size: 0.85em;
    text-align: right;
}

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

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

.analytics-table th,
.analytics-table td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-panel);
    font-size: 0.9em;
}

.analytics-table th {
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75em;
    letter-spacing: 0.03em;
}

.analytics-table td {
    color: var(--text-body);
}

/* Pagination (charts + combo table, 7 items/page) */
.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 16px;
}

.pagination-controls:empty {
    margin-top: 0;
}

.pagination-btn {
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 0.85em;
    color: var(--text-body);
    cursor: pointer;
    transition: all 0.15s ease;
}

.pagination-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--accent);
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.pagination-label {
    font-size: 0.85em;
    color: var(--text-muted);
    min-width: 90px;
    text-align: center;
}

/* Skeleton loaders - shown by default in the HTML, replaced once /api/analytics resolves */
.skeleton-block {
    height: 14px;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--bg-panel) 25%, var(--bg-hover) 37%, var(--bg-panel) 63%);
    background-size: 400% 100%;
    animation: skeleton-shimmer 1.4s ease infinite;
}

@keyframes skeleton-shimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.stat-tile.skeleton-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.skeleton-stat-value {
    height: 26px;
    width: 55%;
}

.skeleton-stat-label {
    height: 11px;
    width: 75%;
}

.skeleton-cell {
    width: 70%;
}

@media (max-width: 600px) {
    .analytics-main {
        padding: 20px;
    }

    .bar-row {
        grid-template-columns: 90px 1fr 70px;
    }
}

