/* ============================================================
   Bruna AI — tema escuro editorial esverdeado (ref. Chatterbox)
   Painéis em vidro escuro, acento lima, tipografia Inter + Grotesk.
   ============================================================ */
:root {
  --bg: #0b100c;
  --panel: rgba(255, 255, 255, .032);
  --panel-solid: #111712;
  --panel-2: rgba(255, 255, 255, .055);
  --line: rgba(255, 255, 255, .09);
  --line-soft: rgba(255, 255, 255, .06);
  --ink: #eef3ec;
  --muted: #9aa79c;
  --faint: #66735f;
  --lime: #c9f24b;
  --lime-2: #7fe08a;
  --lime-ink: #131a10;
  --danger: #e0807a;
  --radius: 18px;
  --font-sans: "Inter", -apple-system, "Segoe UI", sans-serif;
  --font-disp: "Space Grotesk", "Inter", sans-serif;
  --shadow: 0 24px 70px -30px rgba(0, 0, 0, .8);
}

body.light {
  --bg: #eef0e9;
  --panel: rgba(255, 255, 255, .75);
  --panel-solid: #f7f8f3;
  --panel-2: rgba(20, 30, 20, .05);
  --line: rgba(20, 30, 20, .12);
  --line-soft: rgba(20, 30, 20, .08);
  --ink: #141a14;
  --muted: #5c665c;
  --faint: #9aa39a;
  --lime-ink: #131a10;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font-sans); color: var(--ink);
  background: var(--bg); min-height: 100dvh;
  -webkit-font-smoothing: antialiased; overflow: hidden;
  transition: background .35s ease, color .35s ease;
}

/* ---------- fundo ambiente ---------- */
.bg { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
body.light .bg { opacity: .5; }
.glow { position: absolute; border-radius: 50%; filter: blur(90px); opacity: .5; animation: drift 16s ease-in-out infinite alternate; }
.glow-a { width: 480px; height: 480px; left: -140px; top: -120px; background: radial-gradient(circle, rgba(201,242,75,.35), transparent 65%); }
.glow-b { width: 620px; height: 620px; right: -180px; bottom: -220px; background: radial-gradient(circle, rgba(64,140,90,.4), transparent 65%); animation-delay: -6s; }
.glow-c { width: 380px; height: 380px; left: 30%; top: 45%; background: radial-gradient(circle, rgba(201,242,75,.12), transparent 65%); animation-delay: -11s; }
@keyframes drift { from { transform: translate(0,0) scale(1); } to { transform: translate(50px,-36px) scale(1.12); } }

/* ---------- moldura ---------- */
.shell {
  position: relative; z-index: 1;
  height: 100dvh; display: flex; flex-direction: column;
  padding: 14px; gap: 12px;
}
.top {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 8px 12px;
  backdrop-filter: blur(18px); animation: drop .5s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes drop { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
.logo {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--lime), #8fd66a);
  color: var(--lime-ink); font: 700 17px var(--font-disp);
  display: grid; place-items: center;
  box-shadow: 0 0 22px rgba(201,242,75,.35);
}
.tabs {
  display: flex; gap: 2px; margin: 0 auto;
  background: rgba(0,0,0,.28); border: 1px solid var(--line-soft);
  border-radius: 999px; padding: 4px;
}
body.light .tabs { background: rgba(20,30,20,.06); }
.tab {
  border: 0; background: transparent; color: var(--muted);
  font: 500 12.5px var(--font-sans); padding: 8px 20px; border-radius: 999px;
  cursor: pointer; transition: all .22s ease;
}
.tab:hover { color: var(--ink); }
.tab.active { background: rgba(255,255,255,.09); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
body.light .tab.active { background: #fff; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.tbtn {
  width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel);
  color: var(--muted); display: inline-grid; place-items: center; cursor: pointer;
  transition: all .2s ease;
}
.tbtn:hover { color: var(--ink); border-color: var(--faint); transform: translateY(-1px); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line);
  background: radial-gradient(circle at 30% 30%, #d8c49a, #8a6f4d);
  color: #1c160c; font: 700 13px var(--font-disp); cursor: pointer;
}
.only-mobile { display: none !important; }

/* ---------- grelha ---------- */
.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 56px 1fr 300px; gap: 12px;
}

/* trilho */
.rail {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(18px); display: flex; flex-direction: column; align-items: center;
  gap: 8px; padding: 14px 0; animation: drop .55s .05s cubic-bezier(.2,.8,.2,1) both;
}
.rbtn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid transparent;
  background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer;
  transition: all .2s ease;
}
.rbtn:hover { color: var(--ink); background: var(--panel-2); border-color: var(--line); transform: translateY(-1px); }
.rbtn.on { color: var(--lime); background: rgba(201,242,75,.1); border-color: rgba(201,242,75,.35); }
.rail-sep { width: 22px; height: 1px; background: var(--line); margin: 6px 0; }

/* palco */
.stage {
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px;
  backdrop-filter: blur(20px); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  animation: rise .55s .1s cubic-bezier(.2,.8,.2,1) both; position: relative;
}
.stage::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(600px 220px at 15% 30%, rgba(201,242,75,.07), transparent 70%);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.stage-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 0; position: relative; z-index: 2;
}
.engine-pill {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px 6px 8px;
  font: 600 12px var(--font-sans); background: rgba(0,0,0,.25);
}
body.light .engine-pill { background: rgba(255,255,255,.7); }
.pulse { width: 20px; height: 20px; border-radius: 50%; background: conic-gradient(from 0deg, var(--lime), #3f7d53, var(--lime)); animation: spin 3s linear infinite; position: relative; }
.pulse::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--panel-solid); }
@keyframes spin { to { transform: rotate(360deg); } }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: 38px; min-width: 180px; z-index: 20;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 12px;
  padding: 6px; box-shadow: var(--shadow); animation: pop .2s ease both;
}
.menu[hidden] { display: none; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; color: var(--ink); font: 500 13px var(--font-sans); padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--panel-2); }
.menu button.danger { color: var(--danger); }
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.98); } to { opacity: 1; transform: none; } }

/* herói */
.hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px 28px 8px; position: relative; z-index: 1; overflow-y: auto; }
.orb { width: 74px; height: 74px; margin-bottom: 18px; position: relative; }
.orb span {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 40deg, #1d3a24, var(--lime) 25%, #0e1a10 50%, var(--lime-2) 75%, #1d3a24);
  filter: saturate(1.2); animation: spin 7s linear infinite;
  -webkit-mask: radial-gradient(circle, transparent 30%, #000 32%, #000 62%, transparent 64%);
  mask: radial-gradient(circle, transparent 30%, #000 32%, #000 62%, transparent 64%);
}
.orb::before { content: ""; position: absolute; inset: 22px; border-radius: 50%; background: radial-gradient(circle, rgba(201,242,75,.9), rgba(201,242,75,.15) 60%, transparent 70%); animation: breathe 3s ease-in-out infinite; }
.orb::after { content: ""; position: absolute; inset: -26px; border-radius: 50%; background: radial-gradient(circle, rgba(201,242,75,.16), transparent 65%); filter: blur(6px); }
@keyframes breathe { 0%,100% { transform: scale(1); opacity: .8; } 50% { transform: scale(1.25); opacity: 1; } }
.hero h1 { font: 600 clamp(24px, 3.4vw, 34px)/1.25 var(--font-disp); margin: 0; letter-spacing: -.3px; animation: rise .5s .15s both; }
.hero-sub { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; animation: rise .5s .22s both; }
.sug-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 18px; animation: rise .5s .3s both; }
.sug {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
  font: 500 12px var(--font-sans); padding: 8px 14px; border-radius: 999px; cursor: pointer;
  transition: all .2s ease;
}
.sug:hover { color: var(--ink); border-color: rgba(201,242,75,.5); transform: translateY(-1px); }

/* fio */
.thread { flex: 1; overflow-y: auto; padding: 18px 26px 8px; display: flex; flex-direction: column; gap: 16px; position: relative; z-index: 1; }
.thread[hidden] { display: none; }
.thread::-webkit-scrollbar, .history-list::-webkit-scrollbar { width: 6px; }
.thread::-webkit-scrollbar-thumb, .history-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
.msg { display: flex; gap: 10px; animation: rise .3s cubic-bezier(.2,.8,.2,1) both; max-width: 720px; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; font: 700 11px var(--font-disp); margin-top: 2px; }
.msg.user .msg-avatar { background: linear-gradient(135deg, var(--lime), var(--lime-2)); color: var(--lime-ink); }
.msg.assistant .msg-avatar { border: 1px solid rgba(201,242,75,.4); color: var(--lime); }
.msg-body { min-width: 0; }
.msg-text { font-size: 13.8px; line-height: 1.7; background: var(--panel-2); border: 1px solid var(--line-soft); border-radius: 4px 14px 14px 14px; padding: 11px 15px; }
.msg.user .msg-text { background: rgba(201,242,75,.12); border-color: rgba(201,242,75,.3); border-radius: 14px 4px 14px 14px; }
.msg-text p { margin: 0 0 9px; } .msg-text p:last-child { margin: 0; }
.msg-text pre { background: rgba(0,0,0,.5); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; overflow-x: auto; font-size: 12.3px; }
body.light .msg-text pre { background: #141a14; color: #eef3ec; }
.msg-text code { font-family: ui-monospace, Menlo, monospace; font-size: .88em; background: rgba(255,255,255,.09); padding: 1px 5px; border-radius: 4px; }
.msg-text pre code { background: none; padding: 0; }
.msg-text ul, .msg-text ol { margin: 8px 0 8px 18px; padding: 0; } .msg-text li { margin-bottom: 3px; }
.msg-text a { color: var(--lime); }
.msg-time { font-size: 10.5px; color: var(--faint); margin-top: 4px; }
.msg.user .msg-time { text-align: right; }
.caret::after { content: "▍"; color: var(--lime); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.typing { display: flex; align-items: center; gap: 5px; padding: 2px 28px 8px; color: var(--muted); font-size: 12px; }
.typing[hidden] { display: none; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--lime); animation: tp 1.1s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes tp { 0%,60%,100% { transform: none; opacity: .35; } 30% { transform: translateY(-4px); opacity: 1; } }

/* composer */
.composer {
  margin: 10px 22px 20px; border: 1px solid var(--line); border-radius: 16px;
  background: rgba(0,0,0,.3); backdrop-filter: blur(12px);
  padding: 14px 14px 10px; position: relative; z-index: 2;
  transition: border-color .25s ease, box-shadow .25s ease;
}
body.light .composer { background: rgba(255,255,255,.85); }
.composer:focus-within { border-color: rgba(201,242,75,.55); box-shadow: 0 0 0 3px rgba(201,242,75,.12); }
.composer-top { display: flex; gap: 9px; align-items: flex-start; color: var(--lime); padding: 0 2px; }
.composer-top svg { margin-top: 5px; flex-shrink: 0; }
.composer textarea { flex: 1; border: 0; outline: 0; resize: none; background: transparent; color: var(--ink); font: 400 13.8px/1.6 var(--font-sans); max-height: 150px; padding: 2px 0 6px; }
.composer textarea::placeholder { color: var(--faint); }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line-soft); padding-top: 9px; margin-top: 4px; }
.composer-tools, .composer-send { display: flex; align-items: center; gap: 7px; }
.tool {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  height: 30px; min-width: 30px; border-radius: 999px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 500 11.5px var(--font-sans); cursor: pointer; transition: all .2s ease;
}
.tool:hover { color: var(--ink); border-color: var(--faint); transform: translateY(-1px); }
.tool.pill.on { color: var(--lime-ink); background: var(--lime); border-color: var(--lime); box-shadow: 0 0 16px rgba(201,242,75,.35); }
.tool.round.on { color: var(--lime); border-color: var(--lime); }
.tool.round.rec { color: #ff8a80; border-color: #ff8a80; animation: breathe 1.2s infinite; }
.send {
  width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer;
  background: linear-gradient(135deg, var(--lime), #63c96f); color: var(--lime-ink);
  display: grid; place-items: center; box-shadow: 0 4px 20px rgba(201,242,75,.4);
  transition: transform .15s ease, box-shadow .2s ease, opacity .15s;
}
.send:hover { transform: translateY(-1px) scale(1.04); box-shadow: 0 6px 26px rgba(201,242,75,.55); }
.send:active { transform: scale(.93); }
.send:disabled { opacity: .45; transform: none; box-shadow: none; }

/* histórico */
.history {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(18px); display: flex; flex-direction: column; min-height: 0;
  animation: rise .55s .18s cubic-bezier(.2,.8,.2,1) both; overflow: hidden;
}
.history-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px; }
.history-head h2 { font: 600 15px var(--font-disp); margin: 0; }
.new-chat {
  border: 1px solid var(--line); background: rgba(0,0,0,.3); color: var(--ink);
  font: 600 11.5px var(--font-sans); border-radius: 999px; padding: 7px 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; transition: all .2s ease;
}
.new-chat span { color: var(--lime); font-size: 14px; line-height: 1; }
.new-chat:hover { border-color: rgba(201,242,75,.5); transform: translateY(-1px); }
.history-search { display: flex; align-items: center; gap: 7px; margin: 0 12px 8px; border: 1px solid var(--line-soft); border-radius: 9px; padding: 7px 10px; color: var(--faint); background: rgba(0,0,0,.2); }
body.light .history-search { background: rgba(20,30,20,.04); }
.history-search input { border: 0; outline: 0; background: none; color: var(--ink); font: 400 12px var(--font-sans); width: 100%; }
.history-list { flex: 1; overflow-y: auto; padding: 0 12px 12px; display: flex; flex-direction: column; gap: 2px; }
.hgroup { font: 600 10.5px var(--font-sans); letter-spacing: 1px; text-transform: uppercase; color: var(--faint); padding: 12px 6px 6px; }
.hitem {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  border: 1px solid transparent; background: transparent; color: var(--muted);
  border-radius: 10px; padding: 9px 10px; font: 500 12px var(--font-sans); cursor: pointer;
  transition: all .18s ease; animation: rise .25s ease both;
}
.hitem:hover { background: var(--panel-2); color: var(--ink); }
.hitem.active { background: var(--panel-2); border-color: var(--line); color: var(--ink); }
.hitem .hic { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--line); display: grid; place-items: center; flex-shrink: 0; color: var(--faint); }
.hitem.active .hic { color: var(--lime); border-color: rgba(201,242,75,.4); }
.hitem span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hempty { font-size: 12px; color: var(--faint); padding: 12px 6px; line-height: 1.6; }
.history-foot { border-top: 1px solid var(--line-soft); padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 7px; }
.db-status { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--muted); }
.db-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--lime); }
.db-status.local .dot { background: #d8a94e; } .db-status.err .dot { background: var(--danger); }
.history-links { display: flex; gap: 2px; }
.hlink { background: none; border: 0; color: var(--faint); font: 500 11.5px var(--font-sans); cursor: pointer; padding: 5px 8px; border-radius: 6px; }
.hlink:hover { color: var(--ink); background: var(--panel-2); }

/* overlay */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(5,8,6,.6); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 18px; animation: drop .2s ease both; }
.overlay[hidden] { display: none; }
.dialog { width: 100%; max-width: 500px; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); animation: pop .25s cubic-bezier(.2,.9,.3,1.15) both; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 18px; border-bottom: 1px solid var(--line-soft); }
.dialog-head h3 { font: 600 17px var(--font-disp); margin: 0; }
.dialog-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 11px; }
.dialog-lead { font-size: 12.5px; line-height: 1.65; color: var(--muted); margin: 0; }
.dialog-lead code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; font-size: 11.5px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; }
.field input, .field textarea { border: 1px solid var(--line); border-radius: 9px; background: rgba(0,0,0,.25); color: var(--ink); padding: 9px 12px; font: 400 13px var(--font-sans); outline: none; resize: vertical; }
body.light .field input, body.light .field textarea { background: #fff; }
.field input:focus, .field textarea:focus { border-color: var(--lime); box-shadow: 0 0 0 3px rgba(201,242,75,.14); }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 13px 18px; border-top: 1px solid var(--line-soft); }
.spacer { flex: 1; }
.ghost { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 9px; padding: 8px 14px; font: 600 12.5px var(--font-sans); cursor: pointer; }
.ghost:hover { color: var(--ink); border-color: var(--faint); }
.ghost.danger:hover { color: var(--danger); border-color: var(--danger); }
.solid { background: var(--lime); border: 1px solid var(--lime); color: var(--lime-ink); border-radius: 9px; padding: 8px 18px; font: 700 12.5px var(--font-sans); cursor: pointer; }
.solid:hover { filter: brightness(1.06); }

#toast-root { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1a211a; border: 1px solid var(--line); color: var(--ink); font-size: 12.5px; font-weight: 500; padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow); animation: pop .25s ease both; }
.toast.err { border-color: var(--danger); color: #f0b9b4; }
.toast.out { opacity: 0; transform: translateY(6px); transition: all .3s ease; }

/* responsivo */
@media (max-width: 1080px) { .layout { grid-template-columns: 56px 1fr; } .history { position: fixed; top: 76px; bottom: 14px; right: 14px; width: min(320px, 88vw); z-index: 30; transform: translateX(110%); transition: transform .32s cubic-bezier(.2,.8,.2,1); } .history.open { transform: none; box-shadow: var(--shadow); } .only-mobile { display: inline-grid !important; } }
@media (max-width: 640px) {
  body { overflow: auto; } .shell { height: auto; min-height: 100dvh; }
  .layout { grid-template-columns: 1fr; } .rail { display: none; }
  .stage { min-height: 78dvh; } .tabs .tab { padding: 8px 12px; }
  .composer { margin: 10px 12px 14px; } .thread { padding: 14px 14px 6px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
