/* SinapseFlow — portal. Padrão da categoria (apps de chat de IA), executado com capricho. */
:root {
  --bg: #ffffff;
  --side: #f7f7f8;
  --ink: #111827;
  --ink-2: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-2: #eef0f3;
  --hover: #eeeff2;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: #eef2ff;
  --accent-hover: #4338ca;
  --amber: #f59e0b;
  --amber-soft: #fef3c7;
  --amber-ink: #92400e;
  --danger: #b91c1c;
  --bubble: #f3f4f6;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, .05);
  --shadow-md: 0 4px 14px -4px rgba(17, 24, 39, .12), 0 1px 3px rgba(17, 24, 39, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 16px/1.6 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--accent); text-underline-offset: 3px; }
h1 { font-size: clamp(26px, 3.2vw, 34px); line-height: 1.2; letter-spacing: -.02em; margin: 0; font-weight: 700; text-wrap: balance; }
.muted { color: var(--muted); }
.lead { color: var(--ink-2); font-size: 17px; margin: 8px 0 0; }
::selection { background: #c7d2fe; color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
* { scrollbar-width: thin; scrollbar-color: #d1d5db transparent; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- botões ---------- */
.btn-primary { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 11px 16px; font-weight: 600; font-size: 15px; transition: background .15s; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-primary svg { width: 18px; height: 18px; }
.btn-block { width: 100%; padding: 13px; }
.btn-ghost { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 9px; border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-size: 14px; font-weight: 500; background: #fff; }
.btn-ghost:hover { background: var(--hover); }
.btn-ghost svg { width: 16px; height: 16px; }
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--ink); }
.form-error { color: var(--danger); font-size: 14px; min-height: 1.4em; margin: 4px 0 0; }

/* ---------- avatar das equipes ---------- */
.av { --s: 40px; width: var(--s); height: var(--s); border-radius: 50%; flex: none; display: grid; place-items: center; overflow: hidden;
  background: hsl(var(--h, 240) 70% 94%); color: hsl(var(--h, 240) 55% 32%); font-weight: 700; font-size: calc(var(--s) * .38); letter-spacing: .01em; }
.av img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; background: var(--side); }
.login-card { width: min(400px, 100%); background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 36px 32px 28px; box-shadow: var(--shadow-md); display: grid; gap: 16px; }
.login-logo { width: 44px; height: 44px; color: var(--accent); }
.login-card h1 { font-size: 26px; }
.login-card .muted { margin: -8px 0 4px; }
.field { display: grid; gap: 6px; font-size: 14px; font-weight: 500; color: var(--ink-2); }
input, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; caret-color: var(--accent); transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px #e0e7ff; }

/* ---------- estrutura ---------- */
.app { display: grid; grid-template-columns: 272px 1fr; height: 100dvh; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; padding: 14px 12px 10px; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 10px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-logo { width: 28px; height: 28px; color: var(--accent); }
.side-new { margin: 0 2px 6px; }
.side-link { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; font-size: 15px; color: var(--ink-2); text-align: left; }
.side-link svg { width: 18px; height: 18px; color: var(--muted); }
.side-link:hover, .side-link.active { background: var(--hover); color: var(--ink); }
.side-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 14px 12px 4px; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.chat-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; text-align: left; }
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: #e7e8ec; }
.chat-item .av { --s: 28px; }
.chat-item .t { flex: 1; min-width: 0; display: grid; }
.chat-item .t b { font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .t small { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.waiting { background: var(--amber); }
.dot.running { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.chat-empty { font-size: 14px; color: var(--muted); padding: 6px 12px; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px 6px 4px; border-top: 1px solid var(--line); margin-top: 6px; }
.me-av { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 13px; flex: none; }
.me-txt { flex: 1; min-width: 0; display: grid; line-height: 1.3; }
.me-txt b { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-txt small { font-size: 12px; color: var(--muted); }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; }
.view { flex: 1; min-height: 0; overflow-y: auto; }
.only-mobile { display: none; }

/* ---------- início ---------- */
.home-inner, .files-inner, .start-inner { max-width: 960px; margin: 0 auto; padding: clamp(28px, 6vh, 64px) 28px 48px; }
.squads { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-top: 32px; }
.squad { text-align: left; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; align-content: start; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .2s var(--ease-out), transform .2s var(--ease-out); }
.squad:hover { border-color: #c7d2fe; box-shadow: var(--shadow-md); transform: translateY(-2px); }
.squad-top { display: flex; align-items: center; gap: 12px; }
.squad .av { --s: 52px; }
.squad b { display: block; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.squad .head { font-size: 14px; color: var(--muted); }
.squad p { margin: 0; font-size: 14.5px; line-height: 1.5; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.badge { justify-self: start; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--amber-soft); color: var(--amber-ink); }
.badge.running { background: var(--accent-soft); color: var(--accent-hover); }

/* ---------- novo pedido ---------- */
.start-inner { max-width: 760px; }
.link-back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 14px; padding: 4px 6px 4px 0; margin-bottom: 20px; }
.link-back:hover { color: var(--ink); }
.link-back svg { width: 18px; height: 18px; }
.start-team { display: flex; gap: 18px; align-items: center; margin-bottom: 24px; }
.start-team .av { --s: 72px; }
.start-team h1 { font-size: clamp(24px, 3vw, 30px); }
.start-team p { margin: 4px 0 0; color: var(--ink-2); }

/* ---------- compositor ---------- */
.composer { display: flex; align-items: flex-end; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 8px 8px 8px 16px; box-shadow: var(--shadow-md); transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: #c7d2fe; box-shadow: 0 0 0 3px #eef2ff, var(--shadow-md); }
.composer textarea { flex: 1; border: 0; padding: 9px 0; resize: none; max-height: 220px; line-height: 1.5; background: transparent; box-shadow: none; }
.composer textarea:focus { box-shadow: none; }
.composer-big { flex-direction: column; align-items: stretch; padding: 14px 14px 10px 18px; }
.composer-big textarea { min-height: 110px; }
.composer-row { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.hint { font-size: 13px; color: var(--muted); }
.send { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; transition: background .15s, opacity .15s; }
.send:hover { background: var(--accent-hover); }
.send:disabled { opacity: .35; cursor: default; }
.send svg { width: 18px; height: 18px; stroke-width: 2.4; }

/* ---------- conversa ---------- */
.view-chat { display: flex; flex-direction: column; overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--line-2); background: rgba(255, 255, 255, .92); }
.chat-head .av { --s: 36px; }
.chat-head .t { display: grid; line-height: 1.3; min-width: 0; }
.chat-head b { font-size: 15px; font-weight: 600; }
.chat-head small { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread { flex: 1; overflow-y: auto; }
.thread-inner { max-width: 768px; margin: 0 auto; padding: 28px 24px 12px; display: flex; flex-direction: column; gap: 26px; }
.msg-user { align-self: flex-end; max-width: 80%; background: var(--bubble); padding: 10px 16px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-team { display: grid; grid-template-columns: 32px 1fr; gap: 12px; animation: rise .35s var(--ease-out); }
.msg-team .av { --s: 32px; }
.msg-team .who { font-size: 14px; font-weight: 600; margin: 4px 0 2px; }
.msg-error { align-self: center; font-size: 14px; color: var(--danger); background: #fef2f2; padding: 8px 14px; border-radius: 10px; }
.chat-foot { max-width: 816px; width: 100%; margin: 0 auto; padding: 8px 24px 14px; }
.working { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-2); padding: 0 4px 10px; }
.working-av { position: relative; }
.working-av .av { --s: 24px; }
.working-av::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 2px solid var(--accent); opacity: .6; animation: ring 1.4s ease-in-out infinite; }
.foot-note { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 0; }

/* ---------- markdown das respostas ---------- */
.md { overflow-wrap: anywhere; color: var(--ink); }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h3 { font-size: 17px; margin: 20px 0 8px; letter-spacing: -.01em; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md li::marker { color: var(--muted); }
.md strong { font-weight: 600; }
.md code { font: 13.5px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bubble); padding: 1px 5px; border-radius: 5px; }
.md pre { background: var(--side); border: 1px solid var(--line); padding: 12px 14px; border-radius: 10px; overflow-x: auto; white-space: pre-wrap; font-size: 14px; }
.md table { border-collapse: collapse; margin: 0 0 12px; font-size: 14.5px; display: block; overflow-x: auto; }
.md td { border: 1px solid var(--line); padding: 6px 10px; vertical-align: top; }
.md tr:first-child td { background: var(--side); font-weight: 600; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* ---------- arquivos ---------- */
.view-files { display: flex; }
.files-inner { flex: 1; min-width: 0; }
.files { list-style: none; margin: 28px 0 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.files li + li { border-top: 1px solid var(--line-2); }
.file { width: 100%; display: flex; align-items: center; gap: 12px; padding: 13px 16px; text-align: left; background: #fff; }
.file:hover, .file.active { background: var(--side); }
.file svg { color: var(--muted); }
.file .t { flex: 1; min-width: 0; display: grid; line-height: 1.35; }
.file b { font-weight: 500; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file small { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file time { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.files-empty { padding: 28px 20px; text-align: center; color: var(--muted); }
.preview { width: min(560px, 46vw); border-left: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; min-height: 0; }
.preview-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 12px 20px; border-bottom: 1px solid var(--line-2); }
.preview-head b { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-body { flex: 1; overflow-y: auto; padding: 20px 24px 32px; font-size: 15px; }

/* ---------- movimento ---------- */
@keyframes pulse { 50% { opacity: .3; } }
@keyframes ring { 0% { transform: scale(.9); opacity: .7; } 100% { transform: scale(1.35); opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- celular ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: grid; }
  .topbar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line-2); padding-top: max(8px, env(safe-area-inset-top)); }
  .topbar-title { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 20; transform: translateX(-102%); transition: transform .28s var(--ease-out); box-shadow: 0 0 40px rgba(0,0,0,.15); }
  .app.side-open .side { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(17, 24, 39, .35); z-index: 15; }
  .chat-head { display: none; }
  .home-inner, .files-inner, .start-inner { padding: 24px 18px 40px; }
  .squads { grid-template-columns: 1fr; margin-top: 22px; }
  .thread-inner { padding: 18px 16px 8px; }
  .msg-user { max-width: 88%; }
  .chat-foot { padding: 6px 12px max(10px, env(safe-area-inset-bottom)); }
  .foot-note { display: none; }
  .hint { display: none; }
  .composer-row { justify-content: flex-end; }
  .view-files { display: block; }
  .preview { position: fixed; inset: 0; width: auto; z-index: 25; border: 0; }
}
