.ia-main { width: min(100% - 40px, 1000px); margin: 24px auto 48px; display: grid; gap: 16px; }
.ia-card { border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 20px; display: grid; gap: 8px; box-shadow: var(--shadow); }
.ia-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ia-head { justify-content: space-between; margin-bottom: 4px; }
.ia-head h1, .ia-head h2 { margin: 0; font-size: calc(19px * var(--pelison-type-scale, 1)); font-weight: 650; }
.ia-label { font-size: calc(13px * var(--pelison-type-scale, 1)); font-weight: 600; color: var(--muted); margin-top: 6px; }
.ia-select, .ia-text, .ia-textarea { width: 100%; box-sizing: border-box; border: 1px solid var(--border); background: var(--surface-soft); color: var(--text); border-radius: 10px; padding: 10px 12px; font: inherit; font-size: calc(15px * var(--pelison-type-scale, 1)); }
.ia-select:focus, .ia-text:focus, .ia-textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.ia-textarea { resize: vertical; line-height: 1.5; }
.ia-input { min-height: 260px; }
.ia-output { min-height: 420px; background: var(--surface); }
.ia-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.ia-link { background: none; border: 0; color: var(--blue); cursor: pointer; padding: 0; font: inherit; }
.ia-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.ia-actions kbd { font: inherit; font-size: 11px; opacity: .7; margin-left: 6px; }
.ia-status { font-size: calc(13px * var(--pelison-type-scale, 1)); color: var(--muted); }
.ia-warning { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--highlight); color: var(--text); font-size: 14px; }
.ia-dialog { width: min(100% - 24px, 980px); max-height: calc(100vh - 48px); border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); padding: 20px; box-sizing: border-box; }
.ia-dialog::backdrop { background: #0006; }
.ia-templates-layout { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }
.ia-templates-list ul { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 4px; }
.ia-templates-list li button { width: 100%; text-align: left; border: 1px solid transparent; background: none; color: var(--text); border-radius: 8px; padding: 8px 10px; cursor: pointer; font: inherit; }
.ia-templates-list li button:hover { background: var(--surface-soft); }
.ia-templates-list li button.active { background: var(--blue-soft); border-color: var(--blue); }
.ia-template-form { display: grid; gap: 6px; }
.ia-template-form .ia-textarea { min-height: 340px; }
@media (max-width: 700px) {
  .ia-main { width: calc(100% - 24px); margin: 16px auto 32px; }
  .ia-card { padding: 16px; }
  .ia-templates-layout { grid-template-columns: 1fr; }
  .ia-input { min-height: 200px; }
}
.ia-style-button { width: 100%; text-align: left; border: 1px solid var(--border); background: var(--surface-soft); color: var(--text); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; cursor: pointer; font: inherit; font-weight: 600; }
.ia-style-button small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.ia-style-button.active { background: var(--blue-soft); border-color: var(--blue); }
.ia-template-form .ia-example { min-height: 200px; }
.ia-template-form[hidden] { display: none; }
@media (max-width: 1024px) { .ia-actions kbd { display: none; } }
.ia-fields { display: grid; gap: 6px; margin-bottom: 4px; }
.ia-field { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-soft); font-size: calc(14px * var(--pelison-type-scale, 1)); }
.ia-field-name { font-weight: 600; min-width: 150px; }
.ia-field-count { flex: 1; color: var(--muted); font-variant-numeric: tabular-nums; }
.ia-field-ok .ia-field-count { color: #1f8a4c; }
.ia-field-over, .ia-field-under { border-color: var(--danger); }
.ia-field-over .ia-field-count, .ia-field-under .ia-field-count { color: var(--danger); font-weight: 600; }
.ia-field-button { padding: 6px 12px; min-height: 0; font-size: 13px; }
:root[data-theme="dark"] .ia-field-ok .ia-field-count { color: #6fd39a; }

/* ---------- Modo chat ---------- */
.ia-chat { display: flex; flex-direction: column; gap: 12px; min-height: calc(100dvh - 140px); }
.ia-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 12px; border: 1px solid var(--border); background: var(--surface); border-radius: 12px; }
.ia-toolbar-template { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 220px; font-size: 13px; color: var(--muted); font-weight: 600; }
.ia-toolbar-template .ia-select { padding: 8px 10px; font-size: 14px; }
.ia-switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); cursor: pointer; white-space: nowrap; }
.ia-switch input { width: 16px; height: 16px; accent-color: var(--blue); }
.ia-mode-link { font-size: 12px; color: var(--muted); text-decoration: none; }
.ia-mode-link:hover { color: var(--blue); text-decoration: underline; }
.ia-thread { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 4px 0 8px; }
.ia-empty { margin: auto; max-width: 520px; text-align: center; color: var(--muted); padding: 40px 12px; }
.ia-empty h1 { margin: 0 0 10px; color: var(--text); font-size: calc(22px * var(--pelison-type-scale, 1)); font-weight: 650; }
.ia-empty p { margin: 0; line-height: 1.55; font-size: 14px; }
.ia-msg { scroll-margin-top: 16px; max-width: min(860px, 100%); border-radius: 14px; font-size: calc(14px * var(--pelison-type-scale, 1)); line-height: 1.5; }
.ia-msg-user { align-self: flex-end; max-width: min(640px, 92%); background: var(--blue-soft); padding: 10px 14px; border-bottom-right-radius: 4px; }
.ia-msg-text { white-space: pre-wrap; word-break: break-word; }
.ia-msg-text.ia-collapsed { max-height: 9.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 65%, transparent); mask-image: linear-gradient(#000 65%, transparent); }
.ia-msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.ia-msg-ai { align-self: stretch; background: var(--surface); border: 1px solid var(--border); padding: 12px; display: grid; gap: 8px; box-shadow: var(--shadow); border-bottom-left-radius: 4px; }
.ia-doc { width: 100%; box-sizing: border-box; border: 0; background: transparent; color: var(--text); font: inherit; line-height: 1.55; resize: none; padding: 4px; overflow: hidden; min-height: 80px; }
.ia-doc:focus { outline: 1px dashed var(--border); border-radius: 6px; }
.ia-msg-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ia-copy-icon { display: inline-grid; place-items: center; width: 26px; height: 26px; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; }
.ia-copy-icon:hover { background: var(--surface-soft); color: var(--text); }
.ia-copy-icon svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ia-templates-extra { display: flex; gap: 14px; justify-content: center; padding-top: 4px; }
.ia-templates-extra .ia-mode-link { margin-left: 0; }
.ia-sources-btn { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 8px; border: 0; border-radius: 6px; background: none; color: var(--muted); font: inherit; font-size: 12.5px; cursor: pointer; }
.ia-sources-btn:hover { background: var(--surface-soft); color: var(--text); }
.ia-sources-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ia-sources-backdrop { position: fixed; inset: 0; z-index: 60; }
.ia-sources-pop { position: fixed; z-index: 61; max-height: min(60vh, 420px); display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: 0 12px 32px #0f172a2e; overflow: hidden; }
.ia-sources-title { padding: 12px 16px 8px; font-size: 12.5px; color: var(--muted); }
.ia-sources-list { overflow-y: auto; padding: 0 6px 8px; display: flex; flex-direction: column; }
.ia-sources-item { display: block; padding: 9px 10px; border-radius: 9px; color: var(--text); text-decoration: none; }
.ia-sources-item:hover, .ia-sources-item:focus-visible { background: var(--surface-soft); outline: none; }
.ia-sources-host { display: block; font-size: 12px; color: var(--muted); }
.ia-sources-name { display: block; font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }
@media (max-width: 700px) {
  .ia-sources-backdrop { background: #0f172a59; }
  .ia-sources-pop { left: 8px; right: 8px; bottom: 8px; border-radius: 18px; max-height: 70vh; }
}
.ia-msg-meta { font-size: 12px; color: var(--muted); }
/* Barra de ações (copiar, fontes, tempo): fora do balão, sem fundo. PC: só no hover; touch: sempre visível. */
.ia-turn { display: flex; flex-direction: column; align-self: stretch; gap: 2px; }
.ia-turn > .ia-bubble { border-radius: 14px; border-bottom-left-radius: 4px; }
.ia-turn > .ia-msg-actions { min-height: 28px; padding: 0 8px; gap: 6px; }
@media (hover: hover) and (pointer: fine) {
  .ia-turn > .ia-msg-actions { opacity: 0; transition: opacity .15s; }
  .ia-turn:hover > .ia-msg-actions, .ia-turn:focus-within > .ia-msg-actions { opacity: 1; }
}
.ia-mini-button { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 7px; padding: 6px 11px; font: inherit; font-size: 12.5px; cursor: pointer; }
.ia-mini-button:hover { background: var(--surface-soft); }
.ia-mini-button:disabled { opacity: .6; cursor: default; }
.ia-mini-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.ia-mini-primary:hover { background: var(--blue-hover); }
.ia-typing { display: flex; align-items: center; gap: 5px; width: fit-content; color: var(--muted); }
.ia-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: ia-blink 1.2s infinite ease-in-out; }
.ia-dot:nth-child(2) { animation-delay: .15s; } .ia-dot:nth-child(3) { animation-delay: .3s; }
.ia-typing-text { margin-left: 6px; font-size: 13px; }
@keyframes ia-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.ia-composer { position: sticky; bottom: 0; z-index: 5; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 8px; box-shadow: 0 -6px 24px #0000000d; }
.ia-composer-row { display: flex; align-items: flex-end; gap: 8px; }
.ia-input { flex: 1; min-height: 44px; max-height: 40vh; overflow-y: auto; resize: none; border: 0; background: transparent; color: var(--text); font: inherit; font-size: calc(15px * var(--pelison-type-scale, 1)); line-height: 1.45; padding: 10px 6px; }
.ia-input:focus { outline: none; }
.ia-attach { width: 40px; height: 40px; flex-shrink: 0; }
.ia-send { width: 44px; height: 40px; padding: 0; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; border-radius: 10px; }
.ia-send:disabled { opacity: .45; }
.ia-composer-meta { display: flex; justify-content: space-between; gap: 10px; padding: 2px 6px 0; font-size: 12px; color: var(--muted); }
.ia-attachments { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 4px 8px; }
.ia-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 240px; border: 1px solid var(--border); background: var(--surface-soft); border-radius: 9px; padding: 4px 8px 4px 4px; font-size: 12px; }
.ia-chip img { width: 30px; height: 30px; object-fit: cover; border-radius: 5px; }
.ia-chip-icon { width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; border-radius: 5px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; }
.ia-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ia-chip small { color: var(--muted); white-space: nowrap; }
.ia-chip-remove { border: 0; background: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 0 2px; }
.ia-drop { position: fixed; inset: 12px; z-index: 50; display: flex; align-items: center; justify-content: center; border: 3px dashed var(--blue); border-radius: 18px; background: color-mix(in srgb, var(--surface) 88%, transparent); color: var(--blue); font-size: 20px; font-weight: 650; pointer-events: none; }
.ia-drop[hidden] { display: none; }
.ia-fields[hidden] { display: none; }
@media (max-width: 700px) {
  .ia-chat { min-height: calc(100dvh - 90px); }
  .ia-hint { display: none; }
  .ia-toolbar { padding: 8px; gap: 8px; }
  .ia-toolbar-template span { display: none; }
  .ia-msg-user { max-width: 96%; }
  .ia-field-name { min-width: 0; }
}
@media (max-width: 700px) {
  .ia-toolbar { gap: 6px 10px; }
  .ia-toolbar-template { flex-basis: 100%; min-width: 0; }
  .ia-toolbar #ia-new { padding: 6px 10px; min-height: 0; font-size: 13px; }
  .ia-mode-link { margin-left: auto; }
  .ia-switch { font-size: 12.5px; }
}
/* Saudação inicial e botão raio (modelo superior). */
.ia-greeting { width: fit-content; align-self: flex-start; padding: 10px 14px; box-shadow: none; }
.ia-composer-meta:has(.ia-status:empty) { display: none; }
.ia-bolt { width: 40px; height: 40px; flex-shrink: 0; color: var(--muted); }
.ia-bolt svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.ia-bolt[aria-pressed="true"] svg { fill: url(#ia-bolt-gradient); stroke: url(#ia-bolt-gradient); }
.ia-bolt[aria-pressed="true"] { background: var(--blue-soft); }
.ia-toolbar-template { margin: 0; }
/* Menu "/" de modelos, pílula do modelo atual e pontinhos de "escrevendo". */
.ia-toolbar { justify-content: flex-end; border: 0; background: none; padding: 0; gap: 14px; }
.ia-toolbar #ia-new { padding: 6px 12px; min-height: 0; font-size: 13px; }
.ia-composer { position: sticky; }
.ia-template-pill { display: inline-flex; margin: 2px 4px 2px; border: 0; background: var(--blue-soft); color: var(--blue); border-radius: 999px; padding: 3px 10px; font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.ia-template-pill[hidden] { display: none; }
.ia-slash { position: absolute; left: 8px; right: 8px; bottom: calc(100% + 6px); max-width: 360px; margin: 0; padding: 6px; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow), 0 8px 28px #0000001f; display: grid; gap: 2px; max-height: 50vh; overflow-y: auto; }
.ia-slash[hidden] { display: none; }
.ia-slash li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.ia-slash li.active, .ia-slash li:hover { background: var(--blue-soft); }
.ia-slash li small { color: var(--muted); font-size: 11.5px; }
.ia-typing { padding: 14px 16px; gap: 6px; }
.ia-typing .ia-dot { width: 8px; height: 8px; animation: ia-float 1.2s infinite ease-in-out; }
.ia-typing .ia-dot:nth-child(2) { animation-delay: .15s; } .ia-typing .ia-dot:nth-child(3) { animation-delay: .3s; }
@keyframes ia-float { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-6px); opacity: 1; } }
@media (max-width: 700px) { .ia-toolbar { gap: 10px; } .ia-mode-link { margin-left: 0; } }
/* Nome "SecretárIA" em cima das mensagens da IA. */
.ia-sender { display: block; font-size: 12px; font-weight: 600; color: var(--muted); line-height: 1.2; letter-spacing: -.1px; }
.ia-sender span { font-weight: 700; background: linear-gradient(90deg, var(--blue), #8b5cf6); -webkit-background-clip: text; background-clip: text; color: transparent; }
.ia-msg-ai .ia-sender { margin: 0 0 -4px 4px; }
.ia-greeting { display: grid; gap: 3px; }
.ia-greeting .ia-sender, .ia-typing .ia-sender { margin: 0; }
.ia-typing { display: grid; gap: 6px; }
.ia-dots { display: inline-flex; align-items: center; gap: 6px; height: 1.5em; }
.ia-dots .ia-dot { width: 8px; height: 8px; animation: ia-float 1.2s infinite ease-in-out; }
.ia-dots .ia-dot:nth-child(2) { animation-delay: .15s; } .ia-dots .ia-dot:nth-child(3) { animation-delay: .3s; }
.ia-typing { padding: 10px 14px; }
/* Balão rápido do raio (modo Super), no lugar do title nativo, que demora. */
.ia-bolt { position: relative; }
.ia-bolt[data-tip]::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); right: -6px; width: max-content; max-width: 240px; padding: 6px 10px; border-radius: 7px; background: #1f2530; color: #fff; font-size: 12px; font-weight: 500; line-height: 1.3; text-align: left; white-space: normal; pointer-events: none; opacity: 0; transform: translateY(3px); transition: opacity .12s ease, transform .12s ease; z-index: 30; }
.ia-bolt[data-tip]:is(:hover, :focus-visible)::after { opacity: 1; transform: none; transition-delay: .1s; }
:root[data-theme="dark"] .ia-bolt[data-tip]::after { background: #e9edf3; color: #1f2530; }
/* Pílula do modelo ativo com × para voltar à conversa normal. */
.ia-template-pill { align-items: center; padding: 0 2px 0 0; }
.ia-template-pill:not([hidden]) { display: inline-flex; }
.ia-template-pill button { border: 0; background: none; color: inherit; font: inherit; cursor: pointer; padding: 3px 4px 3px 10px; }
.ia-template-pill #ia-template-clear { padding: 0 8px 0 4px; font-size: 15px; line-height: 1; opacity: .7; }
.ia-template-pill #ia-template-clear:hover { opacity: 1; }

/* Histórico de conversas: botão flutuante à esquerda + menu lateral. */
:root { --ia-history-w: 290px; --ia-history-top: 64px; }
.ia-history-toggle { position: fixed; z-index: 40; top: calc(var(--ia-history-top) + 14px); left: 16px; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); display: grid; place-items: center; cursor: pointer; box-shadow: 0 4px 14px #252b361f; transition: left .28s cubic-bezier(.2,.8,.2,1), background .15s; }
.ia-history-toggle:hover { background: var(--surface-soft); }
.ia-history-toggle svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ia-history-chevron { transition: transform .28s; transform-origin: 5.9px 12px; }
body.ia-history-open .ia-history-chevron { transform: scaleX(-1); }
body.ia-history-open .ia-history-toggle { left: calc(var(--ia-history-w) - 22px); }
.ia-history { position: fixed; z-index: 35; top: var(--ia-history-top); bottom: 0; left: 0; width: var(--ia-history-w); background: var(--surface); border-right: 1px solid var(--border); padding: 14px 12px 10px; display: flex; flex-direction: column; gap: 4px; transform: translateX(-100%); transition: transform .28s cubic-bezier(.2,.8,.2,1); }
.ia-history:not([hidden]) { display: flex; }
body.ia-history-open .ia-history { transform: none; }
.ia-history-new { margin: 0 26px 6px 0; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; padding: 10px; font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; }
.ia-history-new:hover { background: var(--surface-soft); }
.ia-history-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.ia-history-group { font-size: 12px; color: var(--muted); margin: 12px 8px 4px; }
.ia-history-item { position: relative; display: flex; align-items: flex-start; border-radius: 9px; }
.ia-history-item:hover { background: var(--surface-soft); }
.ia-history-item.is-active { background: var(--blue-soft); }
.ia-history-open-btn { flex: 1; min-width: 0; border: 0; background: none; color: var(--text); text-align: left; font: inherit; font-size: 14px; line-height: 1.35; padding: 8px 4px 8px 10px; cursor: pointer; }
.ia-history-item.is-active .ia-history-open-btn { color: var(--blue); }
.ia-history-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ia-history-sub { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.ia-history-pin { flex: none; width: 30px; height: 30px; margin: 6px 4px 0 0; border: 0; border-radius: 8px; background: none; color: var(--muted); display: grid; place-items: center; cursor: pointer; opacity: 0; transition: opacity .15s; }
.ia-history-pin svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ia-history-more { flex: none; width: 30px; height: 30px; margin: 6px 4px 0 -4px; border: 0; border-radius: 8px; background: none; color: var(--muted); display: grid; place-items: center; cursor: pointer; opacity: 0; transition: opacity .15s; }
.ia-history-more svg { width: 18px; height: 18px; fill: currentColor; stroke: none; }
.ia-history-more:hover { background: var(--surface); }
/* PC: fixar e "…" só aparecem com o mouse em cima (fixada continua visível). */
.ia-history-item:hover .ia-history-pin, .ia-history-pin:focus-visible, .ia-history-pin[aria-pressed="true"],
.ia-history-item:hover .ia-history-more, .ia-history-more:focus-visible, .ia-history-item.menu-open .ia-history-more { opacity: 1; }
.ia-history-item.menu-open { background: var(--surface-soft); }
.ia-history-menu { position: absolute; z-index: 5; top: 36px; right: 4px; min-width: 150px; padding: 4px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); box-shadow: 0 8px 24px #0f172a29; display: flex; flex-direction: column; }
.ia-history-menu button { border: 0; background: none; color: var(--text); font: inherit; font-size: 14px; text-align: left; padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.ia-history-menu button:hover, .ia-history-menu button:focus-visible { background: var(--surface-soft); outline: none; }
.ia-history-menu button.is-danger { color: var(--danger); }
.ia-history-item.is-renaming .ia-history-pin, .ia-history-item.is-renaming .ia-history-more { display: none; }
.ia-history-rename { flex: 1; min-width: 0; margin: 4px; padding: 7px 8px; border: 1px solid var(--blue); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-size: 14px; }
.ia-history-pin[aria-pressed="true"] { color: var(--blue); }
.ia-history-pin[aria-pressed="true"] svg { fill: currentColor; }
.ia-history-pin:hover { background: var(--surface); }
.ia-history-empty { color: var(--muted); font-size: 13px; padding: 10px; }
.ia-history-foot { margin: 6px 8px 0; font-size: 12px; color: var(--muted); }
.ia-history-backdrop { position: fixed; inset: 0; z-index: 34; background: #0f172a59; }
@media (hover: none) { .ia-history-pin, .ia-history-more { opacity: .55; } }
@media (min-width: 900px) {
  .ia-main { width: min(100% - 160px, 1000px); }
  .ia-history-backdrop { display: none !important; }
  body.ia-history-open .ia-main { width: min(100% - var(--ia-history-w) - 80px, 1000px); margin-left: calc(var(--ia-history-w) + max(40px, (100% - var(--ia-history-w) - 1000px) / 2)); }
  .ia-main { transition: margin-left .28s cubic-bezier(.2,.8,.2,1); }
}
@media (max-width: 899px) {
  :root { --ia-history-w: min(300px, 84vw); }
  /* Celular: o botão fica no começo da barra "Nova conversa"; aberto, flutua na borda do menu. */
  .ia-history-toggle { position: static; width: 38px; height: 38px; box-shadow: none; flex: none; margin-right: auto; }
  body.ia-history-open .ia-history-toggle { position: fixed; top: calc(var(--ia-history-top) + 12px); left: calc(var(--ia-history-w) - 19px); box-shadow: 0 4px 14px #252b361f; }
  .ia-history { z-index: 45; }
  body.ia-history-open .ia-history-toggle { z-index: 46; }
}
@media (prefers-reduced-motion: reduce) { .ia-history, .ia-history-toggle, .ia-main, .ia-history-chevron { transition: none; } }

/* Menus do cabeçalho (3 barras, conta, busca) sempre por cima do histórico e do botão dele. */
body.ia-page header.rx-topbar, body.ia-page header.app-header { z-index: 60; }
@media (max-width: 899px) { body:not(.ia-history-open) .ia-history-toggle { z-index: auto; } }

/* Seta para voltar ao fim da conversa (discreta, acima da caixa de texto). */
.ia-to-bottom { position: absolute; left: 50%; bottom: calc(100% + 12px); transform: translateX(-50%); width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--muted); display: grid; place-items: center; cursor: pointer; box-shadow: 0 2px 10px #252b3614; animation: ia-to-bottom-in .18s ease both; }
.ia-to-bottom[hidden] { display: none; }
.ia-to-bottom:hover { color: var(--text); background: var(--surface-soft); }
.ia-to-bottom svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
@keyframes ia-to-bottom-in { from { opacity: 0; transform: translate(-50%, 4px); } }
@media (prefers-reduced-motion: reduce) { .ia-to-bottom { animation: none; } }

/* Memória da IA */
.ia-memory-link { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-size: 12px; }
.ia-memory-link:hover { color: var(--text); }
.ia-memory-dialog { width: min(100% - 24px, 560px); }
.ia-memory-help { margin: 6px 0 12px; font-size: 13px; color: var(--muted); line-height: 1.45; }
.ia-memory-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; max-height: 50vh; overflow-y: auto; }
.ia-memory-item { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; line-height: 1.4; }
.ia-memory-item span { flex: 1; }
.ia-memory-remove { border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; }
.ia-memory-remove:hover { color: var(--danger, #c0392b); }
.ia-memory-empty { color: var(--muted); font-size: 13px; padding: 6px 2px; }

.ia-templates-extra .ia-mode-link { margin-left: 0; }
.ia-settings-only #ia-style-open, .ia-settings-only #ia-templates-list, .ia-settings-only #ia-template-new, .ia-settings-only #ia-style-form, .ia-settings-only #ia-template-form { display: none !important; }
.ia-settings-only .ia-templates-layout { display: block; }
.ia-settings-only .ia-templates-extra { justify-content: flex-start; }
#ia-templates-dialog.ia-settings-only { width: min(360px, calc(100vw - 32px)); }

/* Nova conversa: ícone de nota, embaixo do botão do histórico (mesmo estilo). */
.ia-new-chat { position: fixed; z-index: 40; top: calc(var(--ia-history-top) + 68px); left: 16px; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); display: grid; place-items: center; cursor: pointer; padding: 0; box-shadow: 0 4px 14px #252b361f; transition: left .28s cubic-bezier(.2,.8,.2,1), background .15s; }
.ia-new-chat:hover { background: var(--surface-soft); }
.ia-new-chat svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
body.ia-history-open .ia-new-chat { left: calc(var(--ia-history-w) - 22px); }
@media (max-width: 899px) {
  /* Celular: ao lado do botão do histórico, na barra. */
  .ia-new-chat, body.ia-history-open .ia-new-chat { position: static; width: 38px; height: 38px; box-shadow: none; flex: none; }
  .ia-history-toggle { margin-right: 0; }
  .ia-toolbar { justify-content: flex-start; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) { .ia-new-chat { transition: none; } }

/* Resposta da conversa livre: texto com **negrito**. */
.ia-answer { white-space: pre-wrap; word-break: break-word; line-height: 1.55; padding: 4px; }
.ia-answer strong { font-weight: 650; }
.ia-answer-link { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }

/* Fundo animado com o degradê da Ana (Configurações > Fundo animado na SecretárIA).
   Só transform/opacity animam, para não pesar; fica parado com "reduzir movimento". */
.ia-aurora { display: none; }
body.ia-aurora-on .ia-aurora { display: block; position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; background: var(--bg); }
body.ia-aurora-on { background: transparent; }
.ia-aurora span { position: absolute; width: 62vmax; height: 62vmax; border-radius: 50%; filter: blur(70px); opacity: .2; will-change: transform; animation: ia-aurora-drift 26s ease-in-out infinite alternate; }
.ia-aurora span:nth-child(1) { background: var(--blue); top: -24vmax; left: -16vmax; }
.ia-aurora span:nth-child(2) { background: #8b5cf6; bottom: -28vmax; right: -18vmax; animation-duration: 32s; animation-delay: -9s; }
.ia-aurora span:nth-child(3) { background: linear-gradient(90deg, var(--blue), #8b5cf6); width: 44vmax; height: 44vmax; top: 30%; left: 40%; opacity: .12; animation-duration: 38s; animation-delay: -17s; }
:root[data-theme="dark"] .ia-aurora span { opacity: .16; }
:root[data-theme="dark"] .ia-aurora span:nth-child(3) { opacity: .1; }
@keyframes ia-aurora-drift {
  0% { transform: translate(0, 0) scale(1) rotate(0deg); }
  50% { transform: translate(14vw, 10vh) scale(1.12) rotate(40deg); }
  100% { transform: translate(-8vw, 18vh) scale(.94) rotate(80deg); }
}
/* Enquanto a Ana pensa, o fundo acende de leve. */
.ia-aurora span { transition: opacity 1.2s ease; }
body.ia-thinking .ia-aurora span:nth-child(1), body.ia-thinking .ia-aurora span:nth-child(2) { opacity: .32; }
body.ia-thinking .ia-aurora span:nth-child(3) { opacity: .22; }
@media (prefers-reduced-motion: reduce) { .ia-aurora span { animation: none; transition: none; } }

/* ---------- Rolagem do chat (V101) ----------
   Cabeçalho fixo no topo; caixa de digitar fixa embaixo, sem "pular": a distância
   dela até a borda é a mesma parada e rolando. A conversa começa depois dos botões
   flutuantes (histórico e nova conversa), mesmo com zoom. */
body.ia-page { --ia-composer-gap: calc(16px + env(safe-area-inset-bottom, 0px)); --ia-left-clear: 76px; }
body.ia-page header.rx-topbar, body.ia-page header.app-header { position: sticky; top: 0; }
html body.ia-page main.ia-main { margin-bottom: 0; }
.ia-page .ia-chat { min-height: calc(100dvh - var(--ia-history-top) - 24px); }
.ia-page .ia-msg { scroll-margin-top: calc(var(--ia-history-top) + 16px); }
.ia-page .ia-composer { bottom: var(--ia-composer-gap); margin-bottom: var(--ia-composer-gap); }
@media (min-width: 900px) {
  body.ia-page.ia-history-open { --ia-left-clear: calc(var(--ia-history-w) + 36px); }
  html body.ia-page main.ia-main, html body.ia-page.ia-history-open main.ia-main {
    width: 100%; margin-left: auto; margin-right: auto;
    padding-left: max(var(--pelison-page-gutter), calc(var(--ia-left-clear) - max(0px, (100vw - var(--pelison-page-max) - 2 * var(--pelison-page-gutter)) / 2)));
    transition: padding-left .28s cubic-bezier(.2,.8,.2,1);
  }
}
@media (max-width: 899px) { body.ia-page { --ia-composer-gap: calc(10px + env(safe-area-inset-bottom, 0px)); } }
@media (prefers-reduced-motion: reduce) { html body.ia-page main.ia-main { transition: none; } }

/* Botões flutuantes (histórico e nova conversa) no mesmo traço delicado da busca
   e do tema do cabeçalho: cinza suave, linha 1,7; escurece só ao passar o mouse. */
.ia-history-toggle, .ia-new-chat { color: var(--muted); }
@media (min-width: 900px) { .ia-history-toggle, .ia-new-chat { box-shadow: 0 2px 10px #252b3614; } }
.ia-history-toggle:hover, .ia-new-chat:hover { color: var(--text); }
.ia-history-toggle svg, .ia-new-chat svg { width: 20px; height: 20px; stroke-width: 1.7; }
@media (min-width: 900px) { :root[data-theme="dark"] .ia-history-toggle, :root[data-theme="dark"] .ia-new-chat { box-shadow: 0 2px 10px #00000040; } }

/* Título completo da conversa ao passar o mouse (só quando está cortado na lista). */
.ia-history-tip { position: fixed; z-index: 70; max-width: 320px; padding: 6px 10px; border-radius: 7px; background: #1f2530; color: #fff; font-size: 12.5px; font-weight: 500; line-height: 1.35; pointer-events: none; box-shadow: 0 4px 14px #0000002e; }
.ia-history-tip[hidden] { display: none; }
:root[data-theme="dark"] .ia-history-tip { background: #e9edf3; color: #1f2530; }
