/* ============================================================
   Tokens — paleta inspirada no design SEED (navy + dourado)
   ============================================================ */
:root {
    --fundo: #f1f2f4;
    --card: #ffffff;
    --card-suave: #f7f8fa;
    --texto: #161d2e;
    --suave: #5d6878;
    --muito-suave: #8a94a3;
    --borda: #e2e5ea;
    --borda-forte: #cdd2da;

    --sidebar: #1a2236;
    --sidebar-texto: #c9d0dd;
    --sidebar-borda: rgba(255, 255, 255, .08);
    --acento: #d9a93f;
    --acento-fundo: #fbf3e2;

    --primaria: #1a2236;
    --primaria-hover: #2a3550;
    --primaria-texto: #ffffff;
    --foco: #d9a93f;

    --verde: #1f8a4c;
    --verde-fundo: #e7f4ec;
    --alerta: #a8620b;
    --alerta-fundo: #fdf3e1;
    --alerta-borda: #ecc98a;
    --perigo: #c62828;
    --perigo-fundo: #fdecec;
    --perigo-borda: #f3b4b4;
    --info: #1a5fb4;
    --info-fundo: #e8f1fd;
    --info-borda: #9cc1f2;

    --balao-usuario: #1a2236;
    --balao-usuario-texto: #ffffff;
    --sombra: 0 1px 2px rgba(16, 24, 40, .04);
    --avatar: #1a2236;
    --avatar-texto: #ffffff;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --fundo: #0f1420;
        --card: #171e2d;
        --card-suave: #1d2536;
        --texto: #e7eaf0;
        --suave: #a3adbd;
        --muito-suave: #7a8597;
        --borda: #283246;
        --borda-forte: #36425a;
        --sidebar: #0b101b;
        --acento-fundo: #3a2f16;
        --primaria: #d9a93f;
        --primaria-hover: #e6bb5c;
        --primaria-texto: #161d2e;
        --verde: #4cc283;
        --verde-fundo: #133222;
        --alerta: #f0b85a;
        --alerta-fundo: #33270f;
        --alerta-borda: #6b5220;
        --perigo: #f08080;
        --perigo-fundo: #3a1717;
        --perigo-borda: #6e2a2a;
        --info: #8ab8f5;
        --info-fundo: #14263f;
        --info-borda: #2c4d7a;
        --balao-usuario: #2a3550;
        --sombra: none;
        --avatar: #2f3b57;
        --avatar-texto: #e7eaf0;
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --fundo: #0f1420;
    --card: #171e2d;
    --card-suave: #1d2536;
    --texto: #e7eaf0;
    --suave: #a3adbd;
    --muito-suave: #7a8597;
    --borda: #283246;
    --borda-forte: #36425a;
    --sidebar: #0b101b;
    --acento-fundo: #3a2f16;
    --primaria: #d9a93f;
    --primaria-hover: #e6bb5c;
    --primaria-texto: #161d2e;
    --verde: #4cc283;
    --verde-fundo: #133222;
    --alerta: #f0b85a;
    --alerta-fundo: #33270f;
    --alerta-borda: #6b5220;
    --perigo: #f08080;
    --perigo-fundo: #3a1717;
    --perigo-borda: #6e2a2a;
    --info: #8ab8f5;
    --info-fundo: #14263f;
    --info-borda: #2c4d7a;
    --balao-usuario: #2a3550;
    --sombra: none;
    --avatar: #2f3b57;
    --avatar-texto: #e7eaf0;
    color-scheme: dark;
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; }

html, body { height: 100%; }
body {
    margin: 0;
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    background: var(--fundo);
    color: var(--texto);
    -webkit-font-smoothing: antialiased;
}
svg { width: 18px; height: 18px; flex-shrink: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }

/* ============================================================
   Estrutura: sidebar + principal
   ============================================================ */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 248px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-texto);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.ambiente {
    background: #c62828;
    color: #fff;
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    padding: 4px 0;
}
.marca {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 20px 18px;
    margin: 0 14px;
    border-bottom: 1px solid var(--sidebar-borda);
}
.marca-icone { width: 30px; height: 30px; color: var(--acento); }
.marca strong { display: block; color: #fff; font-size: 17px; font-weight: 800; letter-spacing: -.01em; }
.marca small { display: block; font-size: 11.5px; color: var(--sidebar-texto); opacity: .85; }

.menu { display: flex; flex-direction: column; gap: 2px; padding: 16px 14px; }
.menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 8px;
    border: 1px solid transparent;
    color: #e4e8f0;
    font-weight: 600;
    text-decoration: none;
    transition: background .15s;
}
.menu a:hover { background: rgba(255, 255, 255, .06); }
.menu a.ativo { color: var(--acento); border-color: var(--acento); }
.menu-secao {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px 2px 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: #8f9bb3;
}
.menu-secao::after { content: ""; flex: 1; height: 1px; background: var(--sidebar-borda); }

.sidebar-rodape {
    margin: auto 14px 0;
    padding: 16px 0 20px;
    border-top: 1px solid var(--sidebar-borda);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: #8f9bb3;
}
.sidebar-rodape code { letter-spacing: .04em; text-transform: none; }
.sidebar-fundo { display: none; }

.principal { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ============================================================
   Barra superior
   ============================================================ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 16px;
    height: 56px;
    padding: 0 20px;
    background: var(--card);
    border-bottom: 1px solid var(--borda);
}
.topbar-titulo { display: flex; flex-direction: column; min-width: 0; font-size: 12.5px; color: var(--suave); }
.topbar-titulo span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sobretitulo {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--suave);
}
.topbar-acoes { margin-left: auto; display: flex; align-items: center; gap: 14px; }

.icone-btn {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 0;
    background: none;
    color: var(--texto);
    cursor: pointer;
}
.icone-btn:hover { background: var(--card-suave); }
.icone-btn svg { width: 20px; height: 20px; }
.icone-btn .sol { display: none; }
:root[data-theme="dark"] .icone-btn .sol { display: block; }
:root[data-theme="dark"] .icone-btn .lua { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .icone-btn .sol { display: block; }
    :root:not([data-theme="light"]) .icone-btn .lua { display: none; }
}
.so-mobile { display: none; }

.usuario-topo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 14px;
    border-left: 1px solid var(--borda);
    line-height: 1.2;
}
.usuario-topo strong { display: block; font-size: 13px; }
.usuario-topo small { font-size: 11.5px; color: var(--suave); }

.avatar {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--avatar);
    color: var(--avatar-texto);
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}
.avatar.pequeno { width: 30px; height: 30px; font-size: 11px; }
.avatar.ia { background: var(--acento-fundo); color: var(--alerta); border: 1px solid var(--alerta-borda); }

/* ============================================================
   Conteúdo
   ============================================================ */
.conteudo { flex: 1; padding: 20px; display: flex; flex-direction: column; min-height: 0; }

.pagina-titulo {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.pagina-titulo h1 { margin: 0; font-size: 21px; font-weight: 800; letter-spacing: -.01em; }

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 16px;
    flex: 1;
    min-height: 0;
}

.card {
    background: var(--card);
    border: 1px solid var(--borda);
    border-radius: 10px;
    padding: 18px;
    box-shadow: var(--sombra);
}
.card-titulo {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}
.card h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}
.card h2 svg { color: var(--suave); }

/* ============================================================
   Botões
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 18px;
    border-radius: 999px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s;
}
.btn svg { width: 16px; height: 16px; }
.btn-primario { background: var(--primaria); color: var(--primaria-texto); border: 1px solid var(--primaria); }
.btn-primario:hover { background: var(--primaria-hover); }
.btn-contorno { background: var(--card); color: var(--texto); border: 1px solid var(--borda-forte); }
.btn-contorno:hover { background: var(--card-suave); border-color: var(--suave); }
.btn-pequeno { height: 32px; padding: 0 12px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: wait; }

/* ============================================================
   Chat
   ============================================================ */
.chat {
    display: flex;
    flex-direction: column;
    padding: 0;
    height: calc(100vh - 56px - 40px - 56px);
    height: calc(100dvh - 56px - 40px - 56px);
    min-height: 480px;
}

.mensagens {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overscroll-behavior: contain;
}
/* o estado vazio só aparece quando não há mensagens */
.mensagens .vazio:not(:only-child) { display: none; }

.vazio {
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
    color: var(--suave);
    padding: 24px;
}
.vazio strong { color: var(--texto); font-size: 18px; font-weight: 800; }
.vazio-icone {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    margin-bottom: 8px;
    border-radius: 50%;
    background: var(--acento-fundo);
    color: var(--alerta);
}
.vazio-icone svg { width: 28px; height: 28px; }

.par { display: flex; flex-direction: column; gap: 10px; }
.linha { display: flex; align-items: flex-end; gap: 10px; max-width: 82%; }
.linha.assistente { max-width: 90%; }
.linha.usuario { align-self: flex-end; }
.linha.assistente { align-self: flex-start; }

.balao {
    padding: 12px 15px;
    border-radius: 12px;
    line-height: 1.5;
    overflow-wrap: anywhere;
    min-width: 0;
}
.balao.usuario {
    white-space: pre-wrap;
    background: var(--balao-usuario);
    color: var(--balao-usuario-texto);
    border-bottom-right-radius: 3px;
}
.balao.assistente {
    background: var(--card-suave);
    border: 1px solid var(--borda);
    border-bottom-left-radius: 3px;
}
.balao.sem-info { background: var(--alerta-fundo); border-color: var(--alerta-borda); }
.balao.erro { background: var(--perigo-fundo); border-color: var(--perigo-borda); }
.balao .texto { white-space: normal; }

/* Markdown da resposta */
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p, .markdown ul, .markdown ol, .markdown pre, .markdown blockquote, .markdown table { margin: 0 0 10px; }
.markdown ul, .markdown ol { padding-left: 22px; }
.markdown li { margin: 3px 0; }
.markdown li > p { margin: 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 14px 0 6px; font-size: 15px; font-weight: 700; line-height: 1.3; }
.markdown h1 { font-size: 17px; }
.markdown h2 { font-size: 16px; }
.markdown strong { font-weight: 700; }
.markdown a { color: var(--info); text-decoration: underline; text-underline-offset: 2px; }
.markdown code {
    background: var(--card);
    border: 1px solid var(--borda);
    border-radius: 4px;
    padding: 1px 5px;
}
.markdown pre {
    background: var(--sidebar);
    color: #e4e8f0;
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    white-space: pre;
}
.markdown pre code { background: none; border: 0; padding: 0; color: inherit; font-size: 12.5px; }
.markdown blockquote {
    padding: 4px 12px;
    border-left: 3px solid var(--acento);
    color: var(--suave);
}
.markdown hr { border: 0; border-top: 1px solid var(--borda-forte); margin: 12px 0; }
.markdown table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; font-size: 13px; }
.markdown th, .markdown td { border: 1px solid var(--borda); padding: 6px 10px; text-align: left; }
.markdown th {
    background: var(--card);
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.balao .badge { margin-bottom: 8px; }

.fontes {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--borda-forte);
}
.rotulo, .stat-rotulo {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--suave);
}
.tag {
    display: inline-block;
    background: var(--card);
    border: 1px solid var(--borda-forte);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 12px;
    font-weight: 600;
}
.hora { font-size: 11.5px; color: var(--muito-suave); }

.balao-rodape {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}
.copiar {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 26px;
    padding: 0 8px;
    margin-left: -8px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--suave);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.copiar svg { width: 14px; height: 14px; }
.copiar:hover { background: var(--card); color: var(--texto); }
.copiar:focus-visible { outline: 2px solid var(--foco); outline-offset: 1px; }
.copiar.copiado { color: var(--verde); }

/* resposta em andamento (mostrada pelo navegador enquanto o servidor processa) */
.digitando { display: flex; align-items: center; gap: 10px; color: var(--suave); font-size: 13px; }
.pontos { display: inline-flex; gap: 4px; }
.pontos i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--acento);
    animation: pulsar 1.2s ease-in-out infinite;
}
.pontos i:nth-child(2) { animation-delay: .15s; }
.pontos i:nth-child(3) { animation-delay: .3s; }
@keyframes pulsar { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

@keyframes entrada { from { opacity: 0; transform: translateY(6px); } }
.mensagens.pronto .par { animation: entrada .2s ease-out; }
@media (prefers-reduced-motion: reduce) {
    .mensagens.pronto .par, .pontos i { animation: none; }
    .pontos i { opacity: .7; }
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 6px;
    border: 1px solid;
    font-size: 12px;
    font-weight: 700;
}
.badge.alerta { background: var(--alerta-fundo); color: var(--alerta); border-color: var(--alerta-borda); }
.badge.info { background: var(--info-fundo); color: var(--info); border-color: var(--info-borda); }
.badge.perigo { background: var(--perigo-fundo); color: var(--perigo); border-color: var(--perigo-borda); }

.chat-rodape { border-top: 1px solid var(--borda); padding: 14px 20px 12px; }
.chat-rodape .aviso { margin-bottom: 10px; }
.chat-rodape [hidden] { display: none; }
.form-chat { display: flex; flex-direction: column; gap: 6px; }

.campo-chat {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 5px 5px 5px 8px;
    border: 1px solid var(--borda-forte);
    border-radius: 14px;
    background: var(--card);
    transition: border-color .15s;
}
.campo-chat:focus-within { border-color: var(--foco); outline: 2px solid var(--foco); outline-offset: 1px; }
.campo-chat textarea {
    flex: 1;
    min-width: 0;
    height: auto;
    max-height: 160px;
    padding: 9px 4px;
    border: 0;
    border-radius: 0;
    background: transparent;
    line-height: 1.5;
    resize: none;
}
.campo-chat textarea:focus { outline: none; }
.digitando[hidden], .raciocinio[hidden], .texto[hidden] { display: none; }
.texto.streaming { white-space: pre-wrap; overflow-wrap: anywhere; }
.raciocinio { margin-bottom: 10px; font-size: 12.5px; color: var(--suave); }
.raciocinio summary { cursor: pointer; font-weight: 700; user-select: none; }
.raciocinio-texto {
    margin-top: 6px;
    padding: 8px 10px;
    max-height: 220px;
    overflow-y: auto;
    border-left: 3px solid var(--borda-forte);
    background: var(--card-suave);
    border-radius: 0 8px 8px 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.5;
}
.btn-thinking {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 40px;
    padding: 0 12px;
    border: 0;
    border-radius: 10px;
    background: none;
    font-size: 13px;
    font-weight: 700;
    color: var(--suave);
    cursor: pointer;
    flex-shrink: 0;
}
.btn-thinking:hover:not(:disabled) { background: var(--card-suave); }
.btn-thinking[aria-pressed="true"] { color: var(--foco); background: var(--card-suave); }
.btn-thinking:disabled { opacity: .4; cursor: not-allowed; }
.btn-thinking:focus-visible { outline: 2px solid var(--foco); outline-offset: 1px; }
.btn-thinking svg { width: 18px; height: 18px; }
.btn-enviar { width: 40px; height: 40px; padding: 0; justify-content: center; border-radius: 10px; flex-shrink: 0; }
.btn-enviar svg { width: 18px; height: 18px; }

.chat-dicas {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    min-height: 16px;
    padding: 0 4px;
    font-size: 11.5px;
    color: var(--muito-suave);
}
.chat-dicas kbd {
    padding: 0 5px;
    border: 1px solid var(--borda-forte);
    border-radius: 4px;
    background: var(--card-suave);
    font: inherit;
    font-size: 11px;
}
.contador.limite { color: var(--perigo); font-weight: 600; }
@media (hover: none) { .atalhos { display: none; } }

/* sem mensagens, não há o que limpar */

/* ============================================================
   Campos
   ============================================================ */
input[type=text], textarea, select {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--borda-forte);
    border-radius: 6px;
    background: var(--card);
    color: var(--texto);
    font: inherit;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muito-suave); }
input:focus, textarea:focus, select:focus,
.btn:focus-visible, .icone-btn:focus-visible, .menu a:focus-visible {
    outline: 2px solid var(--foco);
    outline-offset: 1px;
}
select {
    appearance: none;
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a94a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    cursor: pointer;
}
select:disabled { opacity: .6; cursor: wait; }

/* ============================================================
   Coluna lateral
   ============================================================ */
.coluna { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.form-ia { display: flex; flex-direction: column; gap: 14px; }
.form-ia label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 700; }

.dica {
    display: flex;
    gap: 6px;
    margin-top: 12px;
    color: var(--suave);
    font-size: 12px;
    line-height: 1.45;
}
.dica svg { width: 14px; height: 14px; margin-top: 1px; }

.origem { margin: 0 0 14px; font-size: 12.5px; color: var(--suave); line-height: 1.5; }
.origem code { background: var(--card-suave); border: 1px solid var(--borda); padding: 1px 5px; border-radius: 4px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px;
    border: 1px solid var(--borda);
    border-left: 3px solid var(--acento);
    border-radius: 8px;
}
.stat.verde { border-left-color: var(--verde); }
.stat-valor { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }

.status-base {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 12px;
    margin: 0 0 4px;
    font-size: 13px;
}
.status-base dt { color: var(--suave); }
.status-base dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* ============================================================
   Feedback
   ============================================================ */
.indicador {
    display: none;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: var(--suave);
    padding: 8px 0 0;
}
.chat-rodape .indicador { padding: 0 0 10px; }
.indicador.htmx-request { display: flex; }
.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--borda-forte);
    border-top-color: var(--acento);
    border-radius: 50%;
    animation: girar .8s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }

.aviso {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #a9d8bb;
    background: var(--verde-fundo);
    color: var(--verde);
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 500;
}
.aviso.erro { background: var(--perigo-fundo); border-color: var(--perigo-borda); color: var(--perigo); }

/* ============================================================
   Responsivo
   ============================================================ */
@media (max-width: 1100px) {
    .layout { grid-template-columns: 1fr; }
    .chat { height: 70vh; height: 75dvh; }
}
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        z-index: 20;
        transform: translateX(-100%);
        transition: transform .2s;
    }
    .menu-aberto .sidebar { transform: none; }
    .menu-aberto .sidebar-fundo { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(0, 0, 0, .4); }
    .so-mobile { display: inline-grid; }
    .topbar { padding: 0 12px; gap: 8px; }
    .usuario-topo div { display: none; }
    .conteudo { padding: 16px; }
    .linha, .linha.assistente { max-width: 94%; }
    .campo-chat textarea { font-size: 16px; }
}
@media (max-width: 520px) {
    .topbar-titulo span:not(.sobretitulo) { display: none; }
    .pagina-titulo h1 { font-size: 18px; }
}

/* Fontes clicáveis e dialog com o detalhe do problema */
button.fonte-link {
    font-family: inherit;
    color: inherit;
    cursor: pointer;
}
button.fonte-link:hover {
    border-color: var(--acento);
    background: var(--acento-fundo);
}
.dialogo-fonte {
    width: min(640px, calc(100vw - 32px));
    max-height: 85vh;
    padding: 0;
    border: 1px solid var(--borda);
    border-radius: 14px;
    background: var(--card);
    color: var(--texto);
    box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.dialogo-fonte::backdrop { background: rgba(10, 14, 24, .55); }
.dialogo-cabecalho {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--borda);
}
.dialogo-cabecalho h2 { margin: 0; font-size: 16px; }
.dialogo-fechar {
    border: 0;
    background: none;
    color: var(--suave);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}
.dialogo-corpo { padding: 6px 18px 18px; overflow-y: auto; max-height: calc(85vh - 60px); }
.dialogo-corpo h3 {
    margin: 14px 0 4px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--suave);
}
.dialogo-corpo p { margin: 0; white-space: pre-wrap; line-height: 1.5; }

/* Lista de conversas do usuário (menu lateral) */
.conversas { padding: 0 12px; display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.nova-conversa {
    display: block;
    text-align: center;
    padding: 9px 12px;
    border: 1px dashed var(--sidebar-borda);
    border-radius: 8px;
    color: var(--acento);
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
}
.nova-conversa:hover { background: rgba(255, 255, 255, .06); }
.lista-conversas { list-style: none; margin: 0; padding: 0; max-height: 34vh; overflow-y: auto; }
.lista-conversas a {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 7px 10px;
    border-radius: 8px;
    border-left: 3px solid transparent;
    color: var(--sidebar-texto);
    text-decoration: none;
    font-size: 13px;
}
.lista-conversas a:hover { background: rgba(255, 255, 255, .06); }
.lista-conversas a.ativa { border-left-color: var(--acento); background: rgba(255, 255, 255, .08); color: #fff; }
.conv-titulo { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lista-conversas small { opacity: .6; font-size: 11px; }

/* Botão de excluir no fim de cada conversa: só aparece com o mouse em cima */
.lista-conversas li { position: relative; }
.lista-conversas a { padding-right: 34px; }
.conv-excluir {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    display: none;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--sidebar-texto);
    cursor: pointer;
}
.conv-excluir svg { width: 15px; height: 15px; }
.lista-conversas li:hover .conv-excluir,
.conv-excluir:focus-visible { display: inline-flex; }
.conv-excluir:hover { background: rgba(255, 255, 255, .12); color: #ff8a8a; }
