/* Automação IA — chat
   Paleta "mar de Fortaleza": mineral claro, mar profundo e um sol âmbar só no símbolo. */

@font-face {
  font-family: "Figtree";
  src: url("/fonts/figtree.woff2") format("woff2");
  font-weight: 300 900;
  font-display: swap;
}
@font-face {
  font-family: "Literata";
  src: url("/fonts/literata.woff2") format("woff2");
  font-weight: 200 900;
  font-display: swap;
}

:root {
  --bg: #F3F5F4;
  --side: #E8EDEB;
  --side-hover: #DCE4E1;
  --surface: #FFFFFF;
  --ink: #16201F;
  --ink-2: #33403E;
  --muted: #5E6B69;
  --line: #D6DDDA;
  --accent: #0B6E73;
  --accent-hover: #095B5F;
  --accent-ink: #FFFFFF;
  --accent-soft: #D7EAE9;
  --sun: #F0A52B;
  --bubble: #E1E9E7;
  --code-bg: #EEF2F1;
  --code-head: #E3E9E7;
  --danger: #B3261E;
  --shadow: 0 1px 2px rgba(22, 32, 31, .06), 0 6px 24px rgba(22, 32, 31, .07);
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Literata", "Iowan Old Style", Georgia, serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;
  --side-w: 272px;
  --col: 760px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121817; --side: #0D1211; --side-hover: #1B2423; --surface: #1A2221;
    --ink: #E6ECEA; --ink-2: #C5CFCC; --muted: #93A19E; --line: #2A3533;
    --accent: #4FB8B6; --accent-hover: #6CC9C7; --accent-ink: #0B1413; --accent-soft: #173533;
    --sun: #F3B54A; --bubble: #22302E; --code-bg: #0F1514; --code-head: #19211F; --danger: #F2827A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121817; --side: #0D1211; --side-hover: #1B2423; --surface: #1A2221;
  --ink: #E6ECEA; --ink-2: #C5CFCC; --muted: #93A19E; --line: #2A3533;
  --accent: #4FB8B6; --accent-hover: #6CC9C7; --accent-ink: #0B1413; --accent-soft: #173533;
  --sun: #F3B54A; --bubble: #22302E; --code-bg: #0F1514; --code-head: #19211F; --danger: #F2827A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15.5px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

svg[viewBox="0 0 24 24"] { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.mark-sun { fill: var(--sun); }
.mark-sail { fill: var(--accent); }
.mark-wave { fill: none; stroke: var(--accent); stroke-width: 3.2; stroke-linecap: round; opacity: .55; }

/* ---------- Botões ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 999px; padding: 10px 18px; font-weight: 600; background: none; transition: background .15s, border-color .15s; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { border-color: var(--line); }
.btn-ghost:hover { background: var(--side-hover); }
.btn-link { color: var(--muted); font-weight: 500; padding: 6px 10px; }
.btn-link:hover { color: var(--ink); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13.5px; }
.btn[disabled] { opacity: .6; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 10px; background: none; color: var(--muted); }
.icon-btn:hover { background: var(--side-hover); color: var(--ink); }

/* ---------- Layout ---------- */
.app { display: flex; height: 100dvh; overflow: hidden; }
.sidebar {
  width: var(--side-w); flex: none; display: flex; flex-direction: column;
  background: var(--side); border-right: 1px solid var(--line); padding: 12px 10px 10px; gap: 8px;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

/* ---------- Barra lateral ---------- */
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 6px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 30px; height: 30px; }
.brand-name { font-family: var(--serif); font-size: 18px; font-weight: 600; letter-spacing: -.01em; }
.new-chat {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-weight: 600; color: var(--ink);
}
.new-chat:hover { border-color: var(--accent); }
.search { display: flex; align-items: center; gap: 8px; padding: 0 12px; border-radius: 12px; color: var(--muted); }
.search:focus-within { background: var(--surface); }
.search input { flex: 1; min-width: 0; border: 0; background: none; padding: 9px 0; outline: none; }
.search input::placeholder { color: var(--muted); }

.conv-list { flex: 1; overflow-y: auto; margin: 4px -4px 0; padding: 0 4px; scrollbar-width: thin; }
.conv-group { margin: 14px 8px 4px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.conv { position: relative; display: flex; align-items: center; border-radius: 10px; }
.conv:hover, .conv.active { background: var(--side-hover); }
.conv-open { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 9px 36px 9px 10px; border-radius: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.conv.active .conv-open { color: var(--ink); font-weight: 600; }
.conv-del { position: absolute; right: 4px; width: 30px; height: 30px; opacity: 0; }
.conv:hover .conv-del, .conv.active .conv-del, .conv-del:focus-visible { opacity: 1; }
.conv-del svg { width: 17px; height: 17px; }
.conv-empty { padding: 18px 10px; color: var(--muted); font-size: 14px; }

.side-foot { border-top: 1px solid var(--line); padding: 10px 4px 2px; display: grid; gap: 10px; }
.usage { font-size: 13px; color: var(--muted); padding: 0 6px; }
.usage-bar { height: 4px; border-radius: 4px; background: var(--line); margin-top: 6px; overflow: hidden; }
.usage-bar > span { display: block; height: 100%; background: var(--accent); border-radius: inherit; width: 0; transition: width .3s; }
.usage.full .usage-bar > span { background: var(--danger); }
.profile { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.profile-who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.role-badge { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; flex: none; }
.profile-text { display: grid; min-width: 0; line-height: 1.25; }
.role-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-link { border: 0; background: none; padding: 0; text-align: left; font-size: 12.5px; color: var(--muted); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: var(--line); }
.profile-link:hover { color: var(--accent); text-decoration-color: currentColor; }
.i-moon { display: none; }
[data-mode="dark"] .i-sun { display: none; }
[data-mode="dark"] .i-moon { display: block; }

/* ---------- Topo ---------- */
.topbar { display: flex; align-items: center; gap: 6px; padding: 10px 14px; min-height: 58px; }
.model-picker { position: relative; margin-right: auto; }
.model-btn { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 7px 10px; border-radius: 10px; font-weight: 600; font-size: 16.5px; color: var(--ink); }
.model-btn:hover, .model-btn[aria-expanded="true"] { background: var(--side-hover); }
.model-btn svg { width: 18px; height: 18px; color: var(--muted); }
.model-btn.single { cursor: default; }
.model-btn.single:hover { background: none; }
.model-btn.single svg { display: none; }
.model-menu {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; width: min(320px, 86vw);
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 6px;
}
.model-opt { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 12px; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 10px; }
.model-opt:hover, .model-opt:focus-visible { background: var(--side-hover); }
.model-opt-name { font-weight: 600; }
.model-opt-desc { grid-column: 1; font-size: 13px; color: var(--muted); }
.model-opt-check { grid-row: 1 / span 2; grid-column: 2; color: var(--accent); visibility: hidden; }
.model-opt[aria-selected="true"] .model-opt-check { visibility: visible; }
.model-sep { margin: 8px 12px 4px; font-size: 12.5px; color: var(--muted); font-weight: 600; }

/* ---------- Conversa ---------- */
.thread { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-padding-bottom: 24px; }
.messages { max-width: var(--col); margin: 0 auto; padding: 8px 20px 28px; }
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 0 24px; }
.empty-mark { width: 56px; height: 56px; margin-bottom: 18px; }
.greeting {
  margin: 0; font-family: var(--serif); font-weight: 350; font-size: clamp(30px, 4.6vw, 44px);
  line-height: 1.15; letter-spacing: -.015em; color: var(--ink); max-width: 16ch; text-wrap: balance;
  font-variation-settings: "opsz" 60;
}
.main.is-empty .thread { flex: 0 1 auto; display: flex; align-items: flex-end; justify-content: center; min-height: 38vh; padding-bottom: 28px; }
.main.is-empty .messages { display: none; }
.main:not(.is-empty) .empty { display: none; }
.main.is-empty .composer-wrap { flex: 1; }
.main.is-empty .disclaimer { visibility: hidden; }

.msg { margin: 22px 0; }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user .bubble {
  max-width: min(85%, 620px); background: var(--bubble); padding: 10px 16px; border-radius: 20px 20px 6px 20px;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.55;
}
.msg-ai .body { font-size: 16px; line-height: 1.68; overflow-wrap: anywhere; }
.msg-error { margin-top: 10px; padding: 10px 14px; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); background: color-mix(in srgb, var(--danger) 7%, transparent); font-size: 14.5px; }
.msg-note { color: var(--muted); font-size: 13.5px; margin-top: 6px; }

.actions { display: flex; gap: 2px; margin-top: 6px; margin-left: -8px; }
.act { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--muted); padding: 6px 8px; border-radius: 8px; font-size: 13px; }
.act:hover { background: var(--side-hover); color: var(--ink); }
.act svg { width: 17px; height: 17px; }
.act-model { margin-left: auto; font-size: 12.5px; color: var(--muted); padding: 6px 8px; }

/* Raciocínio recolhível */
.think { margin: 0 0 12px; border-left: 2px solid var(--line); }
.think summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px; color: var(--muted); font-size: 14px; font-weight: 500; border-radius: 8px; user-select: none; }
.think summary::-webkit-details-marker { display: none; }
.think summary:hover { color: var(--ink); }
.think summary svg { width: 16px; height: 16px; transition: transform .15s; }
.think[open] summary svg { transform: rotate(90deg); }
.think-body { padding: 4px 14px 6px; color: var(--muted); font-size: 14.5px; line-height: 1.6; white-space: pre-wrap; max-height: 360px; overflow-y: auto; }
.think.live summary .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }

.typing { display: inline-flex; gap: 5px; padding: 8px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: pulse 1.1s ease-in-out infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 100% { opacity: .25; transform: scale(.85); } 50% { opacity: 1; transform: scale(1); } }
.cursor::after { content: ""; display: inline-block; width: .5em; height: 1.05em; vertical-align: -.15em; margin-left: 2px; background: var(--accent); border-radius: 2px; animation: pulse 1s ease-in-out infinite; }

/* ---------- Markdown ---------- */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .9em; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); font-weight: 600; line-height: 1.3; margin: 1.4em 0 .5em; letter-spacing: -.01em; }
.md h1 { font-size: 1.5em; } .md h2 { font-size: 1.3em; } .md h3 { font-size: 1.13em; } .md h4 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 .9em; padding-left: 1.5em; }
.md li { margin: .25em 0; }
.md li > p { margin: 0; }
.md a { color: var(--accent); text-underline-offset: 2px; }
.md blockquote { margin: 0 0 .9em; padding: .2em 1em; border-left: 3px solid var(--accent-soft); color: var(--ink-2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.4em 0; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); padding: .12em .38em; border-radius: 6px; }
.md strong { font-weight: 650; }
.code { margin: 0 0 1em; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--code-bg); }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 4px 14px; background: var(--code-head); font-size: 12.5px; color: var(--muted); }
.code-copy { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--muted); padding: 5px 8px; border-radius: 7px; font-size: 12.5px; }
.code-copy:hover { color: var(--ink); background: var(--side-hover); }
.code-copy svg { width: 15px; height: 15px; }
.code pre { margin: 0; padding: 14px 16px; overflow-x: auto; font: 13.5px/1.6 var(--mono); tab-size: 2; }
.code pre code { background: none; padding: 0; font-size: inherit; border-radius: 0; }
.table-wrap { margin: 0 0 1em; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.md table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
.md th, .md td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.md th { background: var(--code-head); font-weight: 650; }
.md tr:last-child td { border-bottom: 0; }

/* ---------- Caixa de mensagem ---------- */
.composer-wrap { padding: 0 16px calc(10px + env(safe-area-inset-bottom)); }
.composer {
  max-width: var(--col); margin: 0 auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: 26px; padding: 12px 12px 10px 18px; box-shadow: var(--shadow); transition: border-color .15s;
}
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.composer textarea {
  display: block; width: 100%; resize: none; border: 0; outline: none; background: none;
  padding: 4px 0; max-height: 220px; line-height: 1.5; font-size: 16px;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }
.composer-hint { font-size: 12.5px; color: var(--muted); }
.send-btn { display: grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-ink); flex: none; transition: background .15s, opacity .15s; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn[disabled] { opacity: .35; cursor: default; }
.send-btn svg { width: 20px; height: 20px; stroke-width: 2.2; }
.send-btn .i-stop { display: none; fill: currentColor; stroke: none; }
.send-btn.stop .i-stop { display: block; }
.send-btn.stop .i-send { display: none; }
.send-btn.stop { background: var(--ink); color: var(--bg); }
.disclaimer { text-align: center; font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }

/* ---------- Tela de acesso ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card { width: min(380px, 100%); display: grid; gap: 14px; text-align: center; }
.gate-mark { width: 64px; height: 64px; margin: 0 auto 4px; }
.gate-title { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 34px; letter-spacing: -.015em; }
.gate-text { margin: 0 0 6px; color: var(--muted); }
.field input { width: 100%; padding: 12px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); outline: none; font-size: 16px; }
.field input:focus { border-color: var(--accent); }
.form-error { margin: 0; min-height: 1.2em; color: var(--danger); font-size: 14px; }

/* ---------- Diálogo ---------- */
.dialog { border: 1px solid var(--line); border-radius: 20px; padding: 0; background: var(--surface); color: var(--ink); width: min(400px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(10, 16, 15, .45); }
.dialog-body { display: grid; gap: 12px; padding: 22px; }
.dialog-title { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 22px; }
.dialog-text { margin: 0 0 4px; color: var(--muted); font-size: 14.5px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 999px; font-size: 14px; z-index: 60; box-shadow: var(--shadow); }

.only-mobile { display: none; }
.scrim { display: none; }

/* ---------- Celular ---------- */
@media (max-width: 860px) {
  .only-mobile { display: inline-grid; }
  .sidebar {
    position: fixed; z-index: 50; inset: 0 auto 0 0; width: min(86vw, 320px);
    transform: translateX(-102%); transition: transform .22s ease; box-shadow: var(--shadow);
  }
  .app.side-open .sidebar { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(10, 16, 15, .45); }
  .topbar { padding: 8px 8px; min-height: 52px; }
  .model-picker { margin: 0 auto; }
  .messages { padding: 4px 16px 24px; }
  .composer-wrap { padding: 0 10px calc(8px + env(safe-area-inset-bottom)); }
  .composer-hint { display: none; }
  .composer-row { justify-content: flex-end; margin-top: 2px; }
  .composer { border-radius: 24px; padding: 10px 10px 10px 16px; }
  .main.is-empty .thread { min-height: 34vh; }
  .msg-user .bubble { max-width: 90%; }
  .conv-del { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
