/* ===== ACTN Flow Chat — design system (marca navy/verde/lima) ===== */
:root {
  /* Marca */
  --navy: #1E345D;      --navy-700: #16284a;   --navy-50: #eef2f8;
  --green: #2f8a4a;     --green-700: #25703c;  --green-50: #ecf6ef;
  --lime: #99C635;
  /* Neutros */
  --bg: #f6f7f9;        --surface: #ffffff;    --surface-2: #f1f3f6;
  --line: #e6e9ef;      --line-strong: #d7dce4;
  --ink: #1f2733;       --ink-soft: #44505f;   --muted: #788393;
  /* Semânticos */
  --ok: #2f8a4a;        --err: #c2362b;        --warn: #b7791f;
  /* Forma */
  --r-sm: 8px;  --r: 12px;  --r-lg: 16px;  --r-pill: 999px;
  --sh-sm: 0 1px 2px rgba(20,32,55,.06);
  --sh: 0 2px 8px rgba(20,32,55,.07), 0 1px 2px rgba(20,32,55,.05);
  --sh-lg: 0 12px 32px rgba(20,32,55,.12);
  --ring: 0 0 0 3px rgba(48,138,74,.25);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; color: var(--ink); background: var(--bg);
  font: 15px/1.6 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--green-700); text-decoration: none; }
a:hover { text-decoration: underline; }
.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icsprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ===== Topbar ===== */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px; padding: 0 22px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--navy); }
.brand:hover { text-decoration: none; }
.brand-logo { height: 42px; width: auto; display: block; }
.brand-sep { width: 1px; height: 26px; background: var(--line-strong); flex: none; }
.brand-actn { height: 30px; opacity: .85; }   /* nosso logo como co-marca (secundário) */
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.2px; color: var(--navy); }
.topnav { display: flex; align-items: center; gap: 4px; }
.topnav a { color: var(--ink-soft); padding: 7px 12px; border-radius: var(--r-pill); font-weight: 500; font-size: 14px; }
.topnav a:hover { background: var(--surface-2); color: var(--navy); text-decoration: none; }
.topnav .who { color: var(--muted); font-size: 13px; padding: 0 8px; }
.logout-form { display: inline-flex; margin: 0; }
.topnav .logout { color: var(--muted); border: 0; background: transparent; font: inherit; font-weight: 500; font-size: 14px; cursor: pointer; padding: 7px 12px; border-radius: var(--r-pill); }
.topnav .logout:hover { color: var(--err); background: #fbeae8; }
.usepct { font-size: 13px; color: var(--ink-soft); background: var(--surface-2); padding: 5px 11px; border-radius: var(--r-pill); }
.usepct strong { color: var(--navy); }
.usepct.warn { background: #fdf3e3; color: #8a5a16; } .usepct.warn strong { color: #8a5a16; }
.iconbutton.send.stop { background: var(--err); } .iconbutton.send.stop:hover { background: #a52a20; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 28px 22px 48px; }
/* Chat ocupa a viewport inteira; só o histórico rola. */
body.app { overflow: hidden; }
.wrap.full { max-width: none; margin: 0; padding: 0; height: calc(100dvh - 60px); }

/* ===== Botões (modernos: cantos suaves, micro-lift, sombra) ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; box-shadow: var(--sh-sm); -webkit-tap-highlight-color: transparent;
  transition: background .18s ease, border-color .18s ease, box-shadow .2s ease, transform .12s cubic-bezier(.34,1.56,.64,1);
}
.btn:hover { border-color: var(--line-strong); box-shadow: var(--sh); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.985); box-shadow: var(--sh-sm); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.primary { background: var(--green); border-color: transparent; color: #fff; box-shadow: 0 1px 2px rgba(20,32,55,.08), 0 6px 16px -6px rgba(47,138,74,.5); }
.btn.primary:hover { background: var(--green-700); box-shadow: 0 2px 4px rgba(20,32,55,.1), 0 10px 22px -8px rgba(47,138,74,.6); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--ink-soft); }
.btn.ghost:hover { background: var(--surface-2); box-shadow: none; transform: none; }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; transform: none; box-shadow: var(--sh-sm); }
.btn .ic { width: 16px; height: 16px; }

/* ===== Inputs ===== */
input, select, textarea {
  font: inherit; color: var(--ink); width: 100%;
  padding: 9px 12px; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r-sm); transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: var(--ring); }
label { font-size: 13px; color: var(--ink-soft); font-weight: 500; }
input, select, textarea { border-radius: 10px; }
/* Select com seta própria (mais moderno que o nativo) */
select { appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23788393' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; }
/* Input de arquivo com botão estilizado */
input[type=file] { padding: 6px; cursor: pointer; }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; font-size: 13px; padding: 7px 14px; margin-right: 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); color: var(--ink); cursor: pointer; transition: background .15s, border-color .15s, color .15s; }
input[type=file]::file-selector-button:hover { background: var(--surface); border-color: var(--green); color: var(--navy); }

/* ===== Alerts ===== */
.alert { padding: 11px 14px; border-radius: var(--r-sm); margin-bottom: 14px; font-size: 14px; border: 1px solid transparent; }
.alert.error { background: #fbeceb; color: #8f231b; border-color: #f3cfcb; }
.alert.ok { background: var(--green-50); color: var(--green-700); border-color: #cbe6d4; }

/* ===== Login ===== */
.login-card {
  max-width: 420px; margin: 11vh auto; background: var(--surface);
  padding: 40px 36px; border-radius: var(--r-lg); box-shadow: var(--sh-lg);
  border: 1px solid var(--line); text-align: center;
}
.login-logo { width: min(300px, 82%); height: auto; display: block; margin: 0 auto 14px; }
.login-card h1 { margin: 8px 0 2px; font-size: 22px; color: var(--navy); letter-spacing: -.3px; }
.login-card .muted { margin: 0 0 22px; }
.login-card form { display: grid; gap: 15px; text-align: left; }
.login-card label { display: grid; gap: 6px; }
.login-card .btn { margin-top: 4px; padding: 11px; }

/* ===== Layout do chat (app-shell) ===== */
.chat-layout { display: flex; gap: 16px; height: 100%; padding: 16px; }
.sb-backdrop { display: none; }   /* só aparece no mobile com a sidebar aberta */
.sidebar { width: 286px; flex: none; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-sm); padding: 14px; display: flex; flex-direction: column; gap: 12px; overflow: hidden;
  transition: width .3s cubic-bezier(.4,0,.2,1), padding .3s cubic-bezier(.4,0,.2,1), opacity .22s ease, margin .3s; }
.chat-layout.collapsed .sidebar { width: 0; padding-left: 0; padding-right: 0; border-width: 0; opacity: 0; pointer-events: none; margin-right: -16px; }
.sidebar > * { min-width: 258px; }   /* evita reflow do conteúdo ao recolher */
.conv-search { width: 100%; padding: 7px 11px; border: 1px solid var(--line); border-radius: var(--r-pill); font: inherit; font-size: 13px; color: var(--ink); background: var(--surface-2); }
.conv-search:focus { outline: none; border-color: var(--green); background: var(--surface); box-shadow: 0 0 0 3px rgba(48,138,74,.12); }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
/* Barra de rolagem das conversas: fina por padrão, engrossa ao aproximar o mouse
   (faixa fixa de 14px + borda transparente no polegar → sem reflow do layout). */
.conv-list::-webkit-scrollbar { width: 14px; }
.conv-list::-webkit-scrollbar-track { background: transparent; }
.conv-list::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 12px; border: 4px solid transparent; background-clip: padding-box; transition: border-width .15s ease, background-color .15s ease; }
.conv-list:hover::-webkit-scrollbar-thumb, .conv-list:focus-within::-webkit-scrollbar-thumb { border-width: 1px; background: var(--muted); }
.conv-list::-webkit-scrollbar-thumb:hover { background: var(--navy); }
.conv-list:hover { scrollbar-color: var(--muted) transparent; }
.conv-item { position: relative; padding: 10px 30px 10px 12px; border-radius: var(--r-sm); cursor: pointer; transition: background .12s; }
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--navy-50); }
.conv-item.active::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--lime); }
.conv-title { display: block; font-size: 14px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 50px; }
.conv-meta { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.conv-del, .conv-rename { position: absolute; top: 9px; border: 0; background: transparent; color: var(--muted); cursor: pointer; line-height: 1; padding: 3px; border-radius: 6px; opacity: 0; transition: opacity .12s, color .12s, background .12s; }
.conv-del { right: 6px; } .conv-rename { right: 32px; }
.conv-item:hover .conv-del, .conv-item:hover .conv-rename { opacity: 1; }
.conv-del:hover { color: var(--err); background: #fbeae8; }
.conv-rename:hover { color: var(--navy); background: var(--surface-2); }

.chat-main { flex: 1 1 auto; min-width: 0; position: relative; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-sm); overflow: hidden; }

/* Arrastar-e-soltar arquivos na conversa */
.dropzone { position: absolute; inset: 0; z-index: 40; display: none; align-items: center; justify-content: center; padding: 22px; background: rgba(30,52,93,.10); backdrop-filter: blur(1px); pointer-events: none; }
.dropzone.over { display: flex; }
.dropzone-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 30px 46px; border: 2px dashed var(--green); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--sh-lg); color: var(--navy); font-weight: 700; font-size: 15px; }
.dropzone-inner .ic { width: 30px; height: 30px; color: var(--green); }
/* Barra superior do chat: toggle da sidebar + controles */
.chat-bar { display: flex; align-items: center; gap: 14px; padding: 9px 14px; border-bottom: 1px solid var(--line); min-height: 56px; }
.ghosticon { color: var(--muted); }
.ghosticon:hover { background: var(--surface-2); color: var(--navy); }
.chat-bar-title { font-weight: 700; color: var(--navy); font-size: 15px; }
.chat-export { margin-left: auto; flex: none; }
.chat-controls { display: flex; gap: 16px; flex-wrap: wrap; }
.chat-controls label { display: flex; align-items: center; gap: 8px; }
.chat-controls select { width: auto; min-width: 180px; }

.messages { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: 28px clamp(16px, 6%, 64px); display: flex; flex-direction: column; align-items: center; gap: 24px; scroll-behavior: smooth; }
.msg { width: 100%; max-width: 880px; }
.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 10px; border: 3px solid var(--surface); }
.messages::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.empty-hint { margin: auto; text-align: center; color: var(--muted); max-width: 360px; }
.hint-logo { height: 56px; opacity: .55; margin-bottom: 12px; }
.messages.loading .msg { animation: none; }                    /* sem animação no carregamento em massa */
.loading-hint { margin: auto; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.spinner { width: 18px; height: 18px; border: 2.5px solid var(--line-strong); border-top-color: var(--green); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Mensagens — fluxo limpo (estilo Claude), sem balões pesados */
.msg { display: flex; flex-direction: column; gap: 5px; animation: msgIn .34s cubic-bezier(.22,.68,.36,1) both; }
@keyframes msgIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .msg { animation: none; } * { scroll-behavior: auto !important; } }
.msg .role { font-size: 12px; font-weight: 600; letter-spacing: .3px; color: var(--muted); text-transform: uppercase; }
.msg-time { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); margin-left: 8px; font-size: 11px; opacity: .8; }
.msg.user { align-items: flex-end; }
.msg.user .bubble { background: var(--navy); color: #fff; padding: 11px 15px; border-radius: 14px 14px 4px 14px; max-width: min(680px, 88%); }
.msg.user .role { color: var(--muted); }
.msg.assistant .bubble { color: var(--ink); max-width: 100%; }
.msg.assistant .role { color: var(--green-700); }
.cursor::after { content: "▋"; margin-left: 2px; color: var(--green); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Markdown dentro das mensagens */
.bubble { font-size: 15px; line-height: 1.65; }
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { color: var(--navy); line-height: 1.3; margin: 18px 0 8px; font-weight: 700; }
.bubble h1 { font-size: 1.45em; } .bubble h2 { font-size: 1.25em; padding-bottom: 4px; border-bottom: 2px solid var(--green); }
.bubble h3 { font-size: 1.1em; color: var(--green-700); } .bubble h4 { font-size: 1em; }
.bubble p { margin: 9px 0; } .bubble ul, .bubble ol { margin: 9px 0; padding-left: 22px; } .bubble li { margin: 3px 0; }
.bubble a { color: var(--green-700); text-decoration: underline; }
.bubble strong { color: var(--navy); } .msg.user .bubble strong { color: #fff; }
.bubble code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .88em; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.msg.user .bubble code { background: rgba(255,255,255,.18); }
.bubble pre { background: #0f1b2e; color: #e6edf6; padding: 14px 16px; border-radius: var(--r); overflow-x: auto; margin: 12px 0; }
.bubble pre code { background: none; padding: 0; font-size: 13px; color: inherit; }
.bubble blockquote { margin: 12px 0; padding: 6px 14px; border-left: 4px solid var(--lime); background: var(--surface-2); border-radius: 0 var(--r-sm) var(--r-sm) 0; color: var(--ink-soft); }
.bubble hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.bubble table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13.5px; box-shadow: var(--sh-sm); border-radius: var(--r-sm); overflow: hidden; }
.bubble th { background: var(--navy); color: #fff; text-align: left; padding: 8px 11px; font-weight: 600; }
.bubble td { border-bottom: 1px solid var(--line); padding: 8px 11px; vertical-align: top; }
.bubble tr:last-child td { border-bottom: 0; }
.bubble tbody tr:nth-child(even) { background: var(--surface-2); }

/* Ações por mensagem + export */
.msg-actions { display: flex; gap: 4px; margin-top: 2px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions { opacity: 1; }
.regen-btn { display: none; }                                  /* só na última resposta */
.messages > .msg:last-child .regen-btn { display: inline-flex; }
.iconbtn { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border: 0; background: transparent; color: var(--muted); border-radius: 6px; cursor: pointer; font: inherit; font-size: 12px; text-decoration: none; }
.iconbtn:hover { background: var(--surface-2); color: var(--navy); }
.export-bar { display: flex; gap: 8px; align-items: center; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line-strong); flex-wrap: wrap; }
.doc-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--navy); margin-right: 2px; }
.export-link { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--green-700); border: 1px solid var(--line-strong); border-radius: var(--r-pill); padding: 4px 11px; }
.export-link:hover { background: var(--green-50); border-color: var(--green); text-decoration: none; }

/* Composer fixo na base da área de chat */
.composer { padding: 12px clamp(14px, 5%, 56px) 6px; border-top: 1px solid var(--line); }
.composer-main { display: flex; align-items: flex-end; gap: 6px; max-width: 880px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 18px; padding: 7px 7px 7px 14px; box-shadow: var(--sh); transition: border-color .18s ease, box-shadow .2s ease; }
.composer-main:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(48,138,74,.16), var(--sh); }

/* Footer do chat */
.chat-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; max-width: 880px; margin: 0 auto; padding: 4px 8px 12px; flex-wrap: wrap; }
.foot-brand { font-size: 12px; font-weight: 700; color: var(--navy); letter-spacing: .2px; }
.foot-brand .dot { color: var(--lime); margin: 0 1px; }
.foot-hint { font-size: 11.5px; color: var(--muted); }
.chat-foot kbd { font-family: inherit; font-size: 10.5px; background: var(--surface-2); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; color: var(--ink-soft); }
.foot-usage { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.foot-usage strong { color: var(--navy); }
.foot-usage .usebar { width: 90px; height: 6px; }

/* Barra de uso (cliente: só %, sem US$) */
.usebar { display: inline-block; width: 130px; height: 8px; background: var(--line); border-radius: var(--r-pill); overflow: hidden; vertical-align: middle; }
.usebar-fill { display: block; height: 100%; background: var(--green); border-radius: var(--r-pill); transition: width .35s ease; }
.usebar.warn .usebar-fill { background: var(--warn); }
.usebar.over .usebar-fill { background: var(--err); }
.use-row { display: flex; align-items: center; gap: 12px; }
.use-row .usebar { width: 220px; height: 10px; }
.use-pct { font-size: 18px; color: var(--navy); }
.use-row .usebar.over ~ .use-pct { color: var(--err); }
.composer textarea { border: 0; padding: 8px 4px; resize: none; max-height: 200px; background: transparent; box-shadow: none; }
.composer textarea:focus { box-shadow: none; }
.attach-row { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 8px; }
.attach-row:empty { display: none; }
.iconbutton { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; flex: none; border: 0; background: transparent; color: var(--muted); border-radius: 10px; cursor: pointer; transition: background .12s, color .12s; }
.iconbutton:hover { background: var(--surface-2); color: var(--navy); }
.iconbutton.send { background: var(--green); color: #fff; box-shadow: 0 4px 12px -4px rgba(47,138,74,.6); }
.iconbutton.send:hover { background: var(--green-700); transform: translateY(-1px) scale(1.04); }
.iconbutton.send:active { transform: scale(.95); }
.iconbutton:disabled { opacity: .5; cursor: default; }
.iconbutton.recording { color: var(--err); background: #fbeae8; animation: pulseRec 1.1s ease-in-out infinite; }
.iconbutton.busy { opacity: .6; }
@keyframes pulseRec { 50% { background: #f6d4d1; } }

.pending-chip { display: inline-flex; align-items: center; gap: 7px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 4px 8px 4px 12px; font-size: 13px; max-width: 240px; }
.pending-chip .att-nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-rm { border: 0; background: transparent; color: var(--muted); font-size: 16px; cursor: pointer; line-height: 1; padding: 0 2px; }
.att-rm:hover { color: var(--err); }
.msg-atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.att-thumb { max-width: 170px; max-height: 170px; border-radius: var(--r); border: 1px solid var(--line); display: block; cursor: zoom-in; transition: filter .12s; }
.att-thumb:hover { filter: brightness(.94); }
/* upload em curso: preview + barra de progresso */
.att-figure { position: relative; display: inline-block; line-height: 0; }
/* anexo de imagem cujo arquivo não existe mais no servidor */
.att-missing { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; width: 150px; height: 110px; border: 1px dashed var(--line-strong); border-radius: var(--r); background: var(--surface-2); color: var(--muted); font-size: 12px; text-align: center; }
.att-missing .att-ic { font-size: 22px; filter: grayscale(1); opacity: .6; }
.att-figure.uploading .att-thumb { filter: brightness(.82) saturate(.7); cursor: default; }
.att-bar { position: absolute; left: 8px; right: 8px; bottom: 8px; height: 6px; border-radius: var(--r-pill); background: rgba(255,255,255,.6); overflow: hidden; box-shadow: 0 1px 3px rgba(20,32,55,.25); }
.att-bar > span { display: block; height: 100%; width: 0; border-radius: var(--r-pill); background: var(--green); transition: width .15s ease; }
.att-chip.uploading { position: relative; padding-bottom: 13px; color: var(--muted); }
.att-chip.uploading .att-bar { left: 10px; right: 10px; bottom: 6px; background: var(--surface-2); box-shadow: none; }
.att-chip { display: inline-flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-sm); padding: 8px 12px; color: var(--ink); max-width: 260px; }
.att-chip:hover { border-color: var(--green); text-decoration: none; }
.att-chip .att-nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.att-chip .att-sz { font-size: 12px; color: var(--muted); }
.att-ic { font-size: 16px; }

/* ===== Admin ===== */
.admin h1 { margin: 4px 0 6px; font-size: 24px; color: var(--navy); letter-spacing: -.4px; }
.admin > .muted { margin-top: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-sm); padding: 22px; margin-bottom: 20px; }
.panel h2 { margin: 0 0 16px; font-size: 17px; color: var(--navy); }
.row-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row-form input, .row-form select { width: auto; }
.stack-form { display: grid; gap: 14px; max-width: 660px; }
.stack-form label { display: grid; gap: 6px; }
.check { display: flex !important; flex-direction: row !important; align-items: center; gap: 9px; }
.check input { width: auto; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.grid tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover { background: var(--surface-2); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.inline { display: flex; gap: 6px; align-items: center; }
.inline input { width: 130px; }
.tag { font-size: 12px; padding: 3px 10px; border-radius: var(--r-pill); font-weight: 600; }
.tag.on { background: var(--green-50); color: var(--green-700); }
.tag.off { background: var(--surface-2); color: var(--muted); }
.mini-logo { height: 30px; width: auto; border-radius: 5px; }
.logo-preview img { height: 50px; margin-top: 4px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
.bar { width: 96px; height: 8px; background: var(--line); border-radius: var(--r-pill); overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 7px; }
.bar-fill { height: 100%; background: var(--green); border-radius: var(--r-pill); }
.bar-fill.over { background: var(--err); }
.over-txt { color: var(--err); font-weight: 600; }
/* Valor em US$: dólares grandes, centavos pequenos */
.cost { white-space: nowrap; display: inline-flex; align-items: baseline; }
.cost-int { font-size: 1.22em; font-weight: 700; color: var(--navy); line-height: 1; letter-spacing: -.3px; }
.cost-frac { font-size: .85em; color: var(--muted); }
td.muted .cost-int { color: var(--ink-soft); }

/* ===== Toasts ===== */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--navy); color: #fff; padding: 11px 15px; border-radius: var(--r); box-shadow: var(--sh-lg); font-size: 14px; max-width: 340px; animation: toastIn .2s ease; }
.toast.err { background: var(--err); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ===== Lightbox de imagem ===== */
.lightbox { position: fixed; inset: 0; z-index: 100; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 30px; background: rgba(15,23,42,.82); animation: lbIn .15s ease; }
.lightbox.open { display: flex; }
.lightbox-img { max-width: 92vw; max-height: 82vh; object-fit: contain; border-radius: 10px; box-shadow: var(--sh-lg); background: #fff; }
.lightbox-close { position: absolute; top: 16px; right: 20px; width: 42px; height: 42px; border: 0; border-radius: 50%; background: rgba(255,255,255,.16); color: #fff; font-size: 26px; line-height: 1; cursor: pointer; transition: background .15s; }
.lightbox-close:hover { background: rgba(255,255,255,.32); }
.lightbox-bar { display: flex; align-items: center; gap: 18px; color: #e8edf5; font-size: 13px; max-width: 92vw; }
.lightbox-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox-open { color: #bcd6ff; white-space: nowrap; }
@keyframes lbIn { from { opacity: 0; } }

@media (max-width: 760px) {
  .chat-layout { padding: 10px; gap: 10px; position: relative; }
  /* overlay NÃO cobre a tela toda: deixa uma faixa à direita p/ tocar e fechar */
  .sidebar { position: absolute; z-index: 30; top: 10px; bottom: 10px; left: 10px; right: auto; width: min(82vw, 300px); box-shadow: var(--sh-lg);
    transition: transform .28s cubic-bezier(.4,0,.2,1), opacity .2s; }
  .sidebar > * { min-width: 0; }
  .chat-layout.collapsed .sidebar { transform: translateX(-115%); opacity: 0; padding: 14px; border-width: 1px; margin: 0; }
  /* backdrop: aparece quando a sidebar está aberta; tocar fecha (JS) */
  .chat-layout:not(.collapsed) .sb-backdrop { display: block; position: absolute; inset: 0; z-index: 29; background: rgba(15,23,42,.35); }
}

/* ===== Editor da base (OFICINA) — app-shell de altura cheia ===== */
.base-shell { display: flex; gap: 16px; height: 100%; padding: 16px; }

/* Painel de arquivos */
.base-side { width: 304px; flex: none; display: flex; flex-direction: column; gap: 12px; padding: 16px; overflow: hidden; }
.base-side-head h1 { font-size: 18px; margin: 0 0 2px; color: var(--navy); letter-spacing: -.3px; }
.base-side-head p { margin: 0; }
.seg-group { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 11px; }
.seg { flex: 1; text-align: center; padding: 7px 8px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--ink-soft); transition: background .15s, color .15s, box-shadow .15s; }
.seg:hover { text-decoration: none; color: var(--navy); }
.seg.active { background: var(--surface); color: var(--navy); box-shadow: var(--sh-sm); }
.base-list { flex: 1 1 auto; overflow-y: auto; list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.base-list li { padding: 8px 10px; border-radius: 9px; cursor: pointer; transition: background .12s; }
.base-list li:hover { background: var(--surface-2); }
.base-list li.active { background: var(--navy-50); box-shadow: inset 3px 0 0 var(--lime); }
.base-list li a { display: block; font-size: 13.5px; font-weight: 600; color: var(--ink); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.base-list li.active a { color: var(--navy); }
.base-list .fmeta { font-size: 11px; color: var(--muted); }
.base-side-foot { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.base-new { display: flex; gap: 6px; }
.base-new input { width: auto; flex: 1; min-width: 0; }
.base-new .btn { padding: 8px 11px; flex: none; }

/* Painel do editor */
.base-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; padding: 0; overflow: hidden; position: relative; }
.base-flash { padding: 9px 16px; font-size: 13.5px; }
.base-flash.ok { background: var(--green-50); color: var(--green-700); }
.base-flash.err { background: #fbeceb; color: #8f231b; }
.base-ed-bar { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.base-ed-file { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--navy); font-weight: 700; font-size: 15px; }
.base-ed-file .ic { color: var(--green); }
.base-ed-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.base-ed-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.btn.danger { color: var(--err); }
.btn.danger:hover { background: #fbeae8; border-color: #f3cfcb; }
.base-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; padding: 9px 18px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.md-btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); border-radius: 8px; padding: 5px 10px; font-size: 13px; cursor: pointer; line-height: 1.2; transition: border-color .15s, color .15s, transform .1s; }
.md-btn:hover { border-color: var(--green); color: var(--navy); transform: translateY(-1px); }
.md-btn:active { transform: none; }
.toolbar-hint { margin-left: auto; font-size: 12px; color: var(--muted); }
.base-ed-body { flex: 1 1 auto; min-height: 0; display: flex; padding: 16px 18px; }
.base-pane { flex: 1; min-height: 0; display: flex; }
.base-textarea { height: 100%; width: 100%; min-height: 0; resize: none; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.6; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: var(--surface-2); }
.base-textarea:focus { outline: none; border-color: var(--green); background: var(--surface); box-shadow: 0 0 0 3px rgba(48,138,74,.15); }
.base-visual { flex: 1; height: 100%; width: 100%; min-height: 0; overflow: auto; padding: 20px clamp(18px, 5%, 48px); border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.base-visual:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(48,138,74,.12); }
.base-visual:empty::before { content: "Comece a escrever…"; color: var(--muted); }
/* toggle Visual/Markdown na toolbar */
.mode-toggle { flex: none; padding: 3px; }
.mode-toggle .seg { flex: 0 0 auto; border: 0; background: transparent; font: inherit; font-weight: 600; cursor: pointer; padding: 4px 13px; }
.mode-toggle .seg.active { background: var(--surface); color: var(--navy); box-shadow: var(--sh-sm); }
.tb-sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 6px; }
/* barra de controles de tabela (modo visual) */
.base-tabletools { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; padding: 8px 18px; border-bottom: 1px solid var(--line); background: var(--green-50); animation: ttIn .18s ease; }
.base-tabletools[hidden] { display: none; }
.tt-label { font-size: 12px; font-weight: 700; color: var(--green-700); margin-right: 4px; }
@keyframes ttIn { from { opacity: 0; } }
.base-empty { margin: auto; text-align: center; color: var(--muted); }
.base-empty-ic { width: 46px; height: 46px; opacity: .35; margin-bottom: 10px; }

/* Gaveta de histórico */
.hist-drawer { position: absolute; top: 0; right: 0; bottom: 0; width: 380px; max-width: 92%; background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--sh-lg); transform: translateX(100%); transition: transform .3s cubic-bezier(.4,0,.2,1); display: flex; flex-direction: column; z-index: 6; }
.hist-drawer.open { transform: none; }
.hist-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); color: var(--navy); }
.hist-close { border: 0; background: transparent; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; border-radius: 6px; }
.hist-close:hover { color: var(--err); background: var(--surface-2); }
.hist-list { overflow-y: auto; padding: 6px 18px 18px; }
.hist-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.hist-item:last-child { border-bottom: 0; }
.hist-when { font-size: 13.5px; font-weight: 600; color: var(--ink); }

@media (max-width: 860px) {
  .base-side { width: 240px; }
  .base-split { grid-template-columns: 1fr; }
}
