:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #635bff;
    --primary-dark: #4f46e5;
    --danger-bg: #fef2f2;
    --danger-text: #991b1b;
    --success-bg: #ecfdf5;
    --success-text: #065f46;
    --soft: #eef2ff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px 1fr;
}

.sidebar {
    padding: 24px;
    background: #111827;
    color: #f9fafb;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 24px;
}

.brand-icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: var(--primary);
    font-weight: 700;
}

.brand span {
    display: block;
    color: #9ca3af;
    font-size: 13px;
    margin-top: 4px;
}

.side-nav {
    display: grid;
    gap: 8px;
    margin-bottom: 24px;
}

.side-nav a {
    display: block;
    color: #d1d5db;
    text-decoration: none;
    padding: 11px 12px;
    border-radius: 12px;
    border: 1px solid transparent;
}

.side-nav a:hover,
.side-nav a.active {
    color: #ffffff;
    background: rgba(255,255,255,.08);
    border-color: rgba(255,255,255,.12);
}

.notice,
.tip {
    border: 1px solid rgba(255,255,255,.12);
    background: rgba(255,255,255,.05);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
}

.notice p,
.tip p {
    color: #d1d5db;
    line-height: 1.5;
}

code {
    display: inline-block;
    padding: 3px 6px;
    border-radius: 7px;
    background: rgba(99,91,255,.12);
    color: #312e81;
    font-size: 13px;
}

.sidebar code {
    background: rgba(255,255,255,.12);
    color: #ffffff;
}

.content {
    padding: 32px;
    max-width: 1200px;
    width: 100%;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 24px;
}

h1,
h2 {
    margin: 0;
}

.topbar p {
    color: var(--muted);
    margin: 8px 0 0;
}

.topbar-link {
    text-decoration: none;
    color: var(--primary-dark);
    background: var(--soft);
    font-weight: 700;
    padding: 11px 14px;
    border-radius: 14px;
    white-space: nowrap;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 24px;
    box-shadow: 0 14px 34px rgba(15,23,42,.06);
    margin-bottom: 24px;
}

.soft-card {
    background: #f9fafb;
}

.soft-card p {
    line-height: 1.6;
    color: var(--muted);
}

.form-grid {
    display: grid;
    grid-template-columns: 1.2fr 1.4fr .5fr;
    gap: 18px;
}

.settings-form {
    grid-template-columns: 1fr 1.4fr;
}

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

.field.full,
.actions.full,
.checkbox-field.full {
    grid-column: 1 / -1;
}

label {
    font-weight: 700;
    font-size: 14px;
}

.checkbox-field {
    display: flex;
    gap: 8px;
    align-items: center;
    font-weight: 600;
    color: var(--text);
}

.checkbox-field input {
    width: auto;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 14px;
    font-size: 15px;
    color: var(--text);
    background: #fff;
}

textarea {
    resize: vertical;
    line-height: 1.5;
}

small {
    color: var(--muted);
}

.actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

button,
.secondary {
    border: 0;
    text-decoration: none;
    cursor: pointer;
    border-radius: 14px;
    padding: 12px 18px;
    font-weight: 700;
    font-size: 15px;
}

button {
    background: var(--primary);
    color: white;
}

button:hover {
    background: var(--primary-dark);
}

.secondary {
    background: var(--soft);
    color: var(--primary-dark);
}

.small-button {
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 13px;
}

.danger-button {
    background: #fee2e2;
    color: #991b1b;
}

.danger-button:hover {
    background: #fecaca;
}

.alert {
    border-radius: 16px;
    padding: 14px 16px;
    margin-bottom: 18px;
}

.alert.error {
    background: var(--danger-bg);
    color: var(--danger-text);
    border: 1px solid #fecaca;
}

.alert.success {
    background: var(--success-bg);
    color: var(--success-text);
    border: 1px solid #a7f3d0;
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.section-title span {
    color: var(--muted);
    font-size: 14px;
}

.answer {
    line-height: 1.7;
    white-space: normal;
    background: #f9fafb;
    border: 1px solid var(--border);
    padding: 18px;
    border-radius: 16px;
}

.history-list {
    display: grid;
    gap: 14px;
}

.history-item {
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
    background: #fcfcfd;
}

.history-item p {
    line-height: 1.5;
}

.history-meta {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    color: var(--muted);
    font-size: 13px;
}

.history-meta strong {
    color: var(--text);
}

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

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

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

.models-table th,
.models-table td {
    border-bottom: 1px solid var(--border);
    padding: 12px;
    text-align: left;
    vertical-align: top;
}

.models-table th {
    font-size: 13px;
    color: var(--muted);
    background: #f9fafb;
}

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

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    background: #f3f4f6;
    color: #4b5563;
    font-size: 12px;
    font-weight: 700;
}

.success-badge {
    background: var(--success-bg);
    color: var(--success-text);
}

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-radius: 0 0 24px 24px;
    }

    .content {
        padding: 20px;
    }

    .topbar {
        flex-direction: column;
    }

    .form-grid,
    .settings-form {
        grid-template-columns: 1fr;
    }
}

.locked-badge {
    background: #eef2ff;
    color: #4338ca;
    margin-left: 0.4rem;
}

.muted-action {
    color: #64748b;
    font-size: 0.85rem;
    white-space: nowrap;
}

.auth-card {
    max-width: 720px;
}

.auth-form {
    grid-template-columns: 1fr;
}

.wrap-actions {
    flex-wrap: wrap;
}

.soft-card a {
    color: var(--primary-dark);
    font-weight: 700;
}

/* LGPD / privacidade */
.cookie-notice {
    position: fixed;
    left: 24px;
    right: 24px;
    bottom: 24px;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 18px;
    border-radius: 18px;
    background: #111827;
    color: #ffffff;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.28);
}

.cookie-notice[hidden] {
    display: none !important;
}

.cookie-notice p {
    margin: 4px 0 0;
    color: rgba(255, 255, 255, 0.84);
}

.cookie-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
}

.cookie-actions a {
    color: #bfdbfe;
    text-decoration: none;
    font-weight: 700;
}

.cookie-actions button {
    border: 0;
    border-radius: 999px;
    padding: 10px 16px;
    background: #ffffff;
    color: #111827;
    font-weight: 800;
    cursor: pointer;
}

.privacy-warning {
    border-left: 4px solid #2563eb;
}

.privacy-check a,
.privacy-policy a {
    font-weight: 700;
}

.privacy-policy ul {
    margin: 10px 0 0 20px;
    padding: 0;
}

.privacy-policy li {
    margin: 6px 0;
}

.danger-zone {
    border: 1px solid #fecaca;
    background: #fff7f7;
}

@media (max-width: 720px) {
    .cookie-notice {
        left: 12px;
        right: 12px;
        bottom: 12px;
        flex-direction: column;
        align-items: flex-start;
    }

    .cookie-actions {
        width: 100%;
        justify-content: space-between;
    }
}

.model-search-field {
    position: relative;
}

.autocomplete-panel {
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    top: calc(100% + 8px);
    max-height: 340px;
    overflow-y: auto;
    background: #ffffff;
    border: 1px solid #dfe5ef;
    border-radius: 16px;
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.18);
    padding: 8px;
}

.autocomplete-option {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto;
    gap: 4px 12px;
    align-items: center;
    text-align: left;
    color: #0f172a;
    background: transparent;
    border: 0;
    border-radius: 12px;
    padding: 10px 12px;
    cursor: pointer;
}

.autocomplete-option:hover,
.autocomplete-option:focus {
    background: #f3f6ff;
    outline: none;
}

.autocomplete-option strong {
    font-size: 14px;
}

.autocomplete-option code {
    justify-self: end;
    color: #4338ca;
    background: #eef2ff;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 12px;
}

.autocomplete-option span {
    grid-column: 1 / -1;
    color: #64748b;
    font-size: 12px;
}

.autocomplete-empty {
    padding: 12px;
    color: #64748b;
    font-size: 14px;
}

.paid-badge {
    background: #fff7ed;
    color: #c2410c;
    margin-left: 0.4rem;
}

/* v9 - Chat moderno */
.chat-body {
    overflow: hidden;
}

.chat-shell {
    min-height: 100vh;
}

.chat-content {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 0;
    width: 100%;
    min-width: 0;
    background: #f3f6fb;
}

.chat-history-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    border-right: 1px solid #dfe5ef;
    background: #ffffff;
    padding: 18px;
}

.chat-history-header {
    display: flex;
    margin-bottom: 14px;
}

.new-chat-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 44px;
    padding: 0 16px;
    border-radius: 14px;
    background: #6554ff;
    color: #fff;
    font-weight: 800;
    text-decoration: none;
    box-shadow: 0 14px 28px rgba(101, 84, 255, 0.22);
}

.conversation-search-note {
    margin: 4px 0 10px;
    color: #64748b;
    font-size: 13px;
    font-weight: 700;
}

.conversation-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: auto;
    padding-right: 4px;
}

.conversation-item {
    display: block;
    padding: 12px 12px;
    border: 1px solid transparent;
    border-radius: 14px;
    color: #0f172a;
    text-decoration: none;
    background: #f8fafc;
}

.conversation-item:hover,
.conversation-item.active {
    border-color: #cfd8ff;
    background: #eef2ff;
}

.conversation-title {
    display: block;
    font-weight: 800;
    line-height: 1.25;
}

.conversation-item small {
    display: block;
    margin-top: 5px;
    color: #64748b;
    font-size: 12px;
    word-break: break-all;
}

.conversation-empty {
    margin: 12px 0;
    color: #64748b;
    font-size: 14px;
}

.chat-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    padding: 20px 24px;
}

.chat-topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 14px;
}

.chat-topbar h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.15;
    letter-spacing: -0.045em;
    color: #0f172a;
}

.chat-topbar p {
    margin: 5px 0 0;
    color: #64748b;
}

.chat-topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.danger-ghost {
    border: 0;
    border-radius: 12px;
    padding: 11px 14px;
    background: #fee2e2;
    color: #991b1b;
    font-weight: 800;
    cursor: pointer;
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 20px 6px 20px 0;
}

.welcome-panel {
    width: min(760px, 100%);
    margin: 8vh auto 0;
    padding: 34px;
    border: 1px solid #e2e8f0;
    border-radius: 28px;
    background: #fff;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
    text-align: center;
}

.welcome-badge {
    display: inline-flex;
    padding: 7px 12px;
    border-radius: 999px;
    background: #eef2ff;
    color: #4f46e5;
    font-weight: 900;
    font-size: 13px;
}

.welcome-panel h2 {
    margin: 16px 0 8px;
    color: #0f172a;
    font-size: clamp(30px, 4vw, 48px);
    letter-spacing: -0.06em;
}

.welcome-panel p {
    margin: 0 auto 22px;
    max-width: 560px;
    color: #64748b;
    line-height: 1.6;
}

.quick-prompts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.quick-prompts button {
    border: 1px solid #dfe5ef;
    border-radius: 16px;
    background: #f8fafc;
    color: #334155;
    padding: 14px;
    font-weight: 800;
    cursor: pointer;
    text-align: left;
}

.quick-prompts button:hover {
    border-color: #c7d2fe;
    background: #eef2ff;
    color: #3730a3;
}

.message-row {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 12px;
    width: min(960px, 100%);
    margin: 0 auto 18px;
}

.message-row.user {
    grid-template-columns: minmax(0, 1fr) 44px;
}

.message-row.user .message-avatar {
    grid-column: 2;
    grid-row: 1;
    background: #111827;
}

.message-row.user .message-bubble {
    grid-column: 1;
    grid-row: 1;
    background: #eef2ff;
    border-color: #cfd8ff;
}

.message-avatar {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 15px;
    background: #6554ff;
    color: #fff;
    font-weight: 900;
    font-size: 12px;
}

.message-bubble {
    min-width: 0;
    border: 1px solid #e2e8f0;
    border-radius: 22px;
    background: #fff;
    padding: 16px 18px;
    box-shadow: 0 12px 36px rgba(15, 23, 42, 0.06);
}

.message-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 10px;
    color: #64748b;
    font-size: 12px;
}

.message-meta strong {
    color: #0f172a;
    font-size: 13px;
}

.message-text {
    color: #182235;
    line-height: 1.68;
    white-space: normal;
    overflow-wrap: anywhere;
}

.message-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.message-actions button {
    border: 0;
    border-radius: 10px;
    padding: 8px 10px;
    background: #f1f5f9;
    color: #334155;
    cursor: pointer;
    font-weight: 800;
}

.composer-card {
    width: min(980px, 100%);
    margin: 0 auto;
    border: 1px solid #dfe5ef;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 14px 38px rgba(15, 23, 42, 0.08);
    padding: 10px;
}

.composer-controls {
    display: grid;
    grid-template-columns: 0.9fr 1.4fr 110px;
    gap: 8px;
    margin-bottom: 6px;
}

.composer-controls label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    font-weight: 900;
    color: #0f172a;
}

.composer-controls select,
.composer-controls input,
.composer-input textarea {
    width: 100%;
    border: 1px solid #dbe3ef;
    border-radius: 14px;
    background: #fff;
    color: #0f172a;
    font: inherit;
}

.composer-controls select,
.composer-controls input {
    min-height: 36px;
    padding: 0 10px;
    font-size: 13px;
}

.composer-input textarea {
    display: block;
    min-height: 52px;
    max-height: 150px;
    padding: 12px 14px;
    resize: none;
    overflow-y: auto;
    line-height: 1.45;
}

.model-warning,
.privacy-hint {
    margin: 5px 2px 7px;
    color: #64748b;
    font-size: 12px;
    line-height: 1.35;
}

.success-text {
    color: #047857;
}

.composer-message-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: stretch;
}

.composer-actions {
    display: flex;
    gap: 8px;
    align-items: stretch;
    margin-top: 0;
}

.composer-actions .btn-submit,
.composer-actions .secondary {
    min-height: 52px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    padding-left: 14px;
    padding-right: 14px;
}

.composer-actions .secondary {
    font-size: 14px;
}

.btn-submit[disabled],
.secondary.is-disabled {
    opacity: 0.75;
    cursor: not-allowed;
}

.btn-loading {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.btn-label[hidden],
.btn-loading[hidden] {
    display: none !important;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #ffffff;
    border-radius: 50%;
    display: inline-block;
    animation: iaStudioSpin 0.8s linear infinite;
}

@keyframes iaStudioSpin {
    to {
        transform: rotate(360deg);
    }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 1100px) {
    .composer-message-row {
        grid-template-columns: 1fr;
    }

    .composer-actions {
        justify-content: flex-start;
    }

    .chat-content {
        grid-template-columns: 240px minmax(0, 1fr);
    }

    .composer-controls {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 860px) {
    .composer-actions {
        flex-wrap: wrap;
    }

    .composer-actions .btn-submit,
    .composer-actions .secondary {
        min-height: 46px;
    }

    .chat-body {
        overflow: auto;
    }

    .chat-shell {
        display: block;
    }

    .chat-content {
        display: block;
    }

    .chat-history-panel,
    .chat-main {
        height: auto;
    }

    .chat-history-panel {
        border-right: 0;
        border-bottom: 1px solid #dfe5ef;
    }

    .conversation-list {
        max-height: 220px;
    }

    .chat-main {
        padding: 16px;
    }

    .quick-prompts {
        grid-template-columns: 1fr;
    }

    .message-row,
    .message-row.user {
        grid-template-columns: 1fr;
    }

    .message-row.user .message-avatar,
    .message-row.user .message-bubble {
        grid-column: auto;
        grid-row: auto;
    }

    .message-avatar {
        width: auto;
        height: auto;
        justify-content: start;
        padding: 8px 10px;
    }
}

.warning-text {
    color: #b45309;
}

.danger-text {
    color: #991b1b;
}

.message-meta .usage-pill {
    border-radius: 999px;
    background: #f8fafc;
    padding: 3px 8px;
    color: #475569;
}

.model-warning code {
    font-size: 11px;
    background: #f8fafc;
    border-radius: 6px;
    padding: 2px 5px;
}

/* v9.3 - Preferências do usuário */
.accent-roxo {
    --primary: #635bff;
    --primary-dark: #4f46e5;
    --soft: #eef2ff;
}

.accent-azul {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --soft: #dbeafe;
}

.accent-verde {
    --primary: #059669;
    --primary-dark: #047857;
    --soft: #d1fae5;
}

.accent-laranja {
    --primary: #ea580c;
    --primary-dark: #c2410c;
    --soft: #ffedd5;
}

.accent-rosa {
    --primary: #db2777;
    --primary-dark: #be185d;
    --soft: #fce7f3;
}

.theme-escuro {
    --bg: #0f172a;
    --panel: #111827;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: #263244;
    --danger-bg: #3f1111;
    --danger-text: #fecaca;
    --success-bg: #052e22;
    --success-text: #a7f3d0;
    background: var(--bg);
    color: var(--text);
}

.theme-escuro .chat-content,
.theme-escuro .chat-main {
    background: #0f172a;
}

.theme-escuro .chat-history-panel,
.theme-escuro .card,
.theme-escuro .message-bubble,
.theme-escuro .composer-card,
.theme-escuro .welcome-panel,
.theme-escuro .screen,
.theme-escuro .autocomplete-panel {
    background: #111827;
    border-color: #263244;
    color: #e5e7eb;
}

.theme-escuro .soft-card,
.theme-escuro .answer,
.theme-escuro .history-item,
.theme-escuro .models-table th,
.theme-escuro .conversation-item,
.theme-escuro input,
.theme-escuro select,
.theme-escuro textarea,
.theme-escuro .composer-controls select,
.theme-escuro .composer-controls input,
.theme-escuro .composer-input textarea {
    background: #0b1220;
    border-color: #263244;
    color: #e5e7eb;
}

.theme-escuro .conversation-item:hover,
.theme-escuro .conversation-item.active,
.theme-escuro .message-row.user .message-bubble,
.theme-escuro .quick-prompts button:hover {
    background: rgba(99, 91, 255, 0.16);
    border-color: rgba(147, 197, 253, 0.35);
}

.theme-escuro .chat-topbar h1,
.theme-escuro .message-meta strong,
.theme-escuro .message-text,
.theme-escuro .mini-title,
.theme-escuro .welcome-panel h2,
.theme-escuro .composer-controls label,
.theme-escuro h1,
.theme-escuro h2,
.theme-escuro label,
.theme-escuro .conversation-title {
    color: #f8fafc;
}

.theme-escuro .chat-topbar p,
.theme-escuro .welcome-panel p,
.theme-escuro .message-meta,
.theme-escuro small,
.theme-escuro .empty,
.theme-escuro .conversation-item small,
.theme-escuro .privacy-hint,
.theme-escuro .model-warning,
.theme-escuro .soft-card p,
.theme-escuro .section-title span {
    color: #94a3b8;
}

.theme-escuro code,
.theme-escuro .model-warning code {
    background: rgba(255, 255, 255, 0.08);
    color: #c4b5fd;
}

.theme-escuro .topbar-link,
.theme-escuro .secondary {
    background: rgba(255, 255, 255, 0.08);
    color: #e5e7eb;
}

.theme-escuro .danger-zone {
    background: #2b1111;
    border-color: #7f1d1d;
}

@media (prefers-color-scheme: dark) {
    .theme-automatico {
        --bg: #0f172a;
        --panel: #111827;
        --text: #e5e7eb;
        --muted: #94a3b8;
        --border: #263244;
        background: var(--bg);
        color: var(--text);
    }

    .theme-automatico .chat-content,
    .theme-automatico .chat-main {
        background: #0f172a;
    }

    .theme-automatico .chat-history-panel,
    .theme-automatico .card,
    .theme-automatico .message-bubble,
    .theme-automatico .composer-card,
    .theme-automatico .welcome-panel,
    .theme-automatico .autocomplete-panel {
        background: #111827;
        border-color: #263244;
        color: #e5e7eb;
    }

    .theme-automatico .soft-card,
    .theme-automatico input,
    .theme-automatico select,
    .theme-automatico textarea,
    .theme-automatico .conversation-item,
    .theme-automatico .composer-controls select,
    .theme-automatico .composer-controls input,
    .theme-automatico .composer-input textarea {
        background: #0b1220;
        border-color: #263244;
        color: #e5e7eb;
    }

    .theme-automatico .chat-topbar h1,
    .theme-automatico .message-meta strong,
    .theme-automatico .message-text,
    .theme-automatico h1,
    .theme-automatico h2,
    .theme-automatico label,
    .theme-automatico .conversation-title {
        color: #f8fafc;
    }

    .theme-automatico .chat-topbar p,
    .theme-automatico .welcome-panel p,
    .theme-automatico .message-meta,
    .theme-automatico small,
    .theme-automatico .empty,
    .theme-automatico .conversation-item small,
    .theme-automatico .privacy-hint,
    .theme-automatico .model-warning,
    .theme-automatico .soft-card p {
        color: #94a3b8;
    }
}

.preferences-form {
    align-items: start;
}

.preference-help {
    margin-top: -10px;
}

.preference-preview {
    justify-content: flex-start;
}

.mini-chat-preview {
    display: flex;
    gap: 10px;
    align-items: center;
    min-height: 48px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--bg);
}

.mini-avatar {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    font-weight: 900;
    font-size: 12px;
}

.mini-bubble {
    flex: 1;
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
}

.new-chat-button,
.message-avatar,
button,
.btn-submit,
.brand-icon {
    background: var(--primary);
}

.new-chat-button:hover,
button:hover,
.btn-submit:hover {
    background: var(--primary-dark);
}

.welcome-badge,
.conversation-item:hover,
.conversation-item.active,
.message-row.user .message-bubble {
    border-color: color-mix(in srgb, var(--primary) 28%, #ffffff);
}

.welcome-badge {
    background: var(--soft);
    color: var(--primary-dark);
}

.preference-subsection {
    background: color-mix(in srgb, var(--primary) 6%, #ffffff);
    border: 1px solid color-mix(in srgb, var(--primary) 18%, #e2e8f0);
    border-radius: 16px;
}

.preference-subsection h3 {
    margin: 0 0 8px;
    font-size: 18px;
    color: var(--text);
}

.preference-subsection p {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.privacy-routing-notice {
    border: 1px solid color-mix(in srgb, var(--primary) 22%, #dbeafe);
    background: color-mix(in srgb, var(--primary) 7%, #ffffff);
    color: var(--text);
}

.alert.warning {
    background: #fffbeb;
    border-color: #fbbf24;
    color: #92400e;
}

.changelog-summary p {
    line-height: 1.65;
}

.muted-line {
    color: var(--muted);
    font-size: 14px;
}

.changelog-list {
    display: grid;
    gap: 16px;
}

.changelog-item {
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--panel-soft, #f8fafc);
}

.changelog-item h3 {
    margin: 8px 0 10px;
    font-size: 20px;
    line-height: 1.25;
    color: var(--text);
}

.changelog-item p {
    margin: 0 0 12px;
    color: var(--muted);
    line-height: 1.6;
}

.changelog-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.inline-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 12px;
    border-radius: 12px;
    background: var(--soft);
    color: var(--primary-dark);
    font-weight: 800;
    text-decoration: none;
}

.inline-action:hover {
    background: var(--primary);
    color: #ffffff;
}

.theme-escuro .changelog-item {
    background: rgba(255, 255, 255, 0.04);
}

.theme-automatico .changelog-item {
    background: var(--panel-soft, #f8fafc);
}

@media (prefers-color-scheme: dark) {
    .theme-automatico .changelog-item {
        background: rgba(255, 255, 255, 0.04);
    }
}


/* Integrações OpenRouter */
.integrations-hero h2 {
    margin-bottom: 10px;
}

.pill-label {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary);
    font-size: 0.82rem;
    font-weight: 800;
}

.integration-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.integration-card {
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    background: var(--surface-soft);
}

.integration-card h3 {
    margin: 0 0 8px;
}

.integration-card p {
    margin: 0 0 12px;
    color: var(--muted);
    line-height: 1.55;
}

.integration-card ol {
    margin: 0;
    padding-left: 20px;
    color: var(--text);
}

.integration-card li + li {
    margin-top: 6px;
}

.simple-list {
    display: grid;
    gap: 14px;
}

.simple-list > div {
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.55);
}

.simple-list p {
    margin: 6px 0 0;
    color: var(--muted);
    line-height: 1.55;
}

.actions-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 18px;
}

@media (max-width: 900px) {
    .integration-grid {
        grid-template-columns: 1fr;
    }
}

.delete-all-conversations-form {
    margin: 0 0 12px;
}

.delete-all-conversations-button {
    width: 100%;
    border: 0;
    border-radius: 14px;
    padding: 10px 12px;
    background: #fff1f2;
    color: #b91c1c;
    cursor: pointer;
    font-weight: 800;
    text-align: center;
}

.delete-all-conversations-button:hover,
.delete-all-conversations-button:focus {
    background: #ffe4e6;
    outline: none;
}


.conversation-bulk-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin: 0 0 12px;
}

.export-all-conversations-button {
    display: block;
    width: 100%;
    border: 0;
    border-radius: 14px;
    padding: 10px 12px;
    background: #eef2ff;
    color: #4f46e5;
    cursor: pointer;
    font-weight: 800;
    text-align: center;
    text-decoration: none;
}

.export-all-conversations-button:hover,
.export-all-conversations-button:focus {
    background: #e0e7ff;
    outline: none;
}

.conversation-bulk-actions .delete-all-conversations-form {
    margin: 0;
}


/* v9.14 - Uso da IA */
.usage-panel {
    gap: 24px;
}

.usage-explainer p {
    margin-bottom: 8px;
}

.usage-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.usage-stat-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.06);
}

.usage-stat-card span {
    display: block;
    color: #64748b;
    font-size: 13px;
    font-weight: 800;
    margin-bottom: 8px;
}

.usage-stat-card strong {
    display: block;
    color: #0f172a;
    font-size: clamp(24px, 3vw, 34px);
    line-height: 1;
    letter-spacing: -0.05em;
}

.usage-stat-card small {
    display: block;
    color: #64748b;
    margin-top: 8px;
}

.usage-two-columns {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 18px;
}

.section-header-inline {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.section-header-inline h2 {
    margin: 0;
}

.section-header-inline span {
    color: #64748b;
    font-size: 14px;
}

.responsive-table {
    width: 100%;
    overflow-x: auto;
}

.usage-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 620px;
}

.usage-table th,
.usage-table td {
    border-bottom: 1px solid #e2e8f0;
    padding: 12px 10px;
    text-align: left;
    vertical-align: top;
}

.usage-table th {
    color: #475569;
    font-size: 13px;
    background: #f8fafc;
}

.usage-table td {
    color: #0f172a;
}

.usage-table code {
    display: inline-block;
    max-width: 220px;
    white-space: normal;
    word-break: break-word;
}

@media (max-width: 1100px) {
    .usage-summary-grid,
    .usage-two-columns {
        grid-template-columns: 1fr;
    }
}


/* v9.14.2 - Ajuste de espaçamento da página Uso da IA */
.usage-panel {
    padding: 28px 32px 48px !important;
    width: 100%;
    min-width: 0;
}

.usage-panel .page-header {
    margin-bottom: 22px;
}

.usage-panel .page-header h1 {
    margin-top: 0;
}

.usage-panel .card,
.usage-panel .usage-summary-grid,
.usage-panel .usage-two-columns {
    margin-bottom: 24px;
}

.usage-summary-grid {
    margin-top: 8px;
}

.usage-table {
    border-spacing: 0;
}

@media (max-width: 900px) {
    .usage-panel {
        padding: 22px 18px 36px !important;
    }
}


/* v9.15 - campos de economia OpenRouter */
.preferences-form input[type="number"] {
    width: 100%;
    border: 1px solid #dbe3ef;
    border-radius: 14px;
    padding: 13px 14px;
    font: inherit;
    color: #0f172a;
    background: #ffffff;
}

.preferences-form input[type="number"]:focus {
    border-color: #6d5dfc;
    box-shadow: 0 0 0 4px rgba(109, 93, 252, 0.12);
    outline: none;
}

.integration-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 22px;
    padding: 22px;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.06);
    margin-bottom: 18px;
}


/* v9.16 - ajustes para documentação de recursos OpenRouter */
.integration-card strong {
    color: #312e81;
}

.model-capability-note {
    color: #64748b;
    font-size: 13px;
    margin-top: 6px;
}


/* v9.17 - Busca avançada de modelos */
.model-select-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: stretch;
}

.model-search-open {
    border: 0;
    border-radius: 14px;
    padding: 0 14px;
    background: #eef2ff;
    color: #4f46e5;
    font-weight: 900;
    cursor: pointer;
}

.model-search-open:hover,
.model-search-open:focus {
    background: #e0e7ff;
    outline: none;
}

.model-search-is-open {
    overflow: hidden;
}

.model-search-modal[hidden] {
    display: none;
}

.model-search-modal {
    position: fixed;
    inset: 0;
    z-index: 999;
    display: grid;
    place-items: center;
    padding: 24px;
}

.model-search-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.58);
    backdrop-filter: blur(4px);
}

.model-search-panel {
    position: relative;
    width: min(980px, 100%);
    max-height: min(820px, calc(100vh - 48px));
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    border-radius: 28px;
    background: #ffffff;
    box-shadow: 0 35px 90px rgba(15, 23, 42, 0.35);
    border: 1px solid #e2e8f0;
}

.model-search-header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 24px 26px 18px;
    border-bottom: 1px solid #e2e8f0;
}

.model-search-header h2 {
    margin: 0 0 6px;
    font-size: 28px;
    letter-spacing: -0.04em;
}

.model-search-header p {
    margin: 0;
    color: #64748b;
}

.eyebrow-small {
    margin: 0 0 6px !important;
    color: #4f46e5 !important;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 900;
}

.model-search-close {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 14px;
    background: #f1f5f9;
    color: #0f172a;
    font-size: 28px;
    cursor: pointer;
}

.model-search-body {
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: 14px;
    padding: 18px 26px 24px;
}

.model-search-input-wrap {
    display: grid;
    gap: 8px;
    font-weight: 800;
}

.model-search-input-wrap input {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 18px;
    padding: 15px 16px;
    font: inherit;
}

.model-search-input-wrap input:focus {
    outline: none;
    border-color: #6d5dfc;
    box-shadow: 0 0 0 4px rgba(109, 93, 252, 0.12);
}

.model-filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.model-filter-row button {
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    padding: 9px 13px;
    background: #ffffff;
    color: #475569;
    cursor: pointer;
    font-weight: 800;
}

.model-filter-row button.active {
    background: #4f46e5;
    color: #ffffff;
    border-color: #4f46e5;
}

.model-search-results {
    overflow: auto;
    display: grid;
    gap: 8px;
    padding-right: 4px;
}

.model-search-item {
    width: 100%;
    border: 1px solid #e2e8f0;
    border-radius: 18px;
    background: #ffffff;
    padding: 14px;
    cursor: pointer;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    text-align: left;
}

.model-search-item:hover,
.model-search-item.active {
    border-color: #6d5dfc;
    background: #f8f7ff;
}

.model-search-item strong,
.model-search-item code,
.model-search-item small {
    display: block;
}

.model-search-item strong {
    color: #0f172a;
    margin-bottom: 5px;
}

.model-search-item code {
    color: #4f46e5;
    word-break: break-word;
}

.model-search-item small {
    margin-top: 5px;
    color: #64748b;
}

.model-search-item em {
    justify-self: end;
    font-style: normal;
    font-size: 12px;
    font-weight: 900;
    color: #0f172a;
    background: #eef2ff;
    border-radius: 999px;
    padding: 6px 9px;
}

.model-search-empty {
    padding: 26px;
    border: 1px dashed #cbd5e1;
    border-radius: 18px;
    color: #64748b;
    text-align: center;
}

@media (max-width: 720px) {
    .model-search-modal {
        padding: 10px;
    }

    .model-search-panel {
        max-height: calc(100vh - 20px);
        border-radius: 22px;
    }

    .model-search-header,
    .model-search-body {
        padding-left: 18px;
        padding-right: 18px;
    }

    .model-select-row {
        grid-template-columns: 1fr;
    }
}


/* v9.18 - aceite obrigatório da política atualizada */
.alert.warning {
    background: #fff7ed;
    color: #9a3412;
    border: 1px solid #fed7aa;
}

.alert.warning a {
    color: #7c2d12;
    font-weight: 900;
}


/* v9.19 - privacidade por provedor OpenRouter */
.preferences-form input[type="number"] {
    width: 100%;
    border: 1px solid #dbe3ef;
    border-radius: 14px;
    padding: 13px 14px;
    font: inherit;
    color: #0f172a;
    background: #ffffff;
}

.preferences-form input[type="number"]:focus {
    border-color: #6d5dfc;
    box-shadow: 0 0 0 4px rgba(109, 93, 252, 0.12);
    outline: none;
}

.integration-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 22px;
    padding: 22px;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.06);
    margin-bottom: 18px;
}
