:root {
  --bg: #0b0614;
  --bg2: #130b22;
  --card: #1a1030;
  --line: #2d1f4d;
  --text: #f1eafe;
  --muted: #9b8cc0;
  --accent: #a855f7;
  --accent2: #7c3aed;
  --glow: rgba(168, 85, 247, .35);
  --ok: #34d399;
  --bad: #f87171;
  --warn: #fbbf24;
  --user: #3b1d6e;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--bad); min-height: 1.4em; margin: 6px 0 0; font-size: 14px; }
#app { position: relative; }
.screen { height: 100dvh; display: flex; flex-direction: column; }

/* botões e campos */
.btn { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 16px; font: inherit; font-weight: 600; cursor: pointer; }
.btn.primary { background: linear-gradient(135deg, var(--accent2), var(--accent)); border-color: transparent;
  box-shadow: 0 0 18px var(--glow); }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
input, select, textarea { width: 100%; background: var(--bg2); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; font: inherit; font-size: 16px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--glow); }
.icon-btn { background: none; border: 0; color: var(--text); width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 12px; font-size: 18px; cursor: pointer; }
.icon-btn:active { background: var(--card); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 22px; }
.logo { width: 64px; height: 64px; border-radius: 16px; }
.logo.sm { width: 52px; height: 52px; }

/* login */
#login { align-items: center; justify-content: center; padding: 20px; background:
  radial-gradient(600px 400px at 50% -10%, rgba(124, 58, 237, .35), transparent), var(--bg); }
.login-card { width: 100%; max-width: 380px; text-align: center; display: grid; gap: 12px;
  box-shadow: 0 0 40px rgba(124, 58, 237, .2); }
.login-card h1 { margin: 4px 0 0; font-size: 26px; }
.login-card .logo { margin: 0 auto; }
.login-card p { margin: 0; }

/* topo */
.top { display: flex; align-items: center; gap: 4px; padding: calc(var(--safe-t) + 6px) 8px 6px;
  background: rgba(11, 6, 20, .92); border-bottom: 1px solid var(--line); backdrop-filter: blur(8px); z-index: 5; }
.head-title { flex: 1; min-width: 0; }
.ttl { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.usage { font-size: 12px; color: var(--muted); margin-right: 8px; white-space: nowrap; text-align: right; line-height: 1.25; }
.usage.warn { color: var(--warn); }
.dot { width: 11px; height: 11px; border-radius: 50%; background: #4b3d6e; margin-right: 10px; flex: none; }
.dot.run { background: var(--accent); box-shadow: 0 0 10px var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.banner { background: #3a2a05; color: #fde68a; padding: 10px 14px; font-size: 14px; border-bottom: 1px solid #5c4410; }
.banner code { background: rgba(0,0,0,.35); padding: 1px 6px; border-radius: 6px; user-select: all; }

/* conversa */
.feed { flex: 1; overflow-y: auto; padding: 14px 12px 16px; display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch; }
.empty { margin: auto; text-align: center; max-width: 320px; padding: 20px; }
.empty h2 { margin: 10px 0 6px; font-size: 20px; }
.msg { max-width: 92%; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); border: 1px solid #5b2fa3; padding: 9px 13px;
  border-radius: 18px 18px 4px 18px; white-space: pre-wrap; }
.msg.bot { align-self: flex-start; background: var(--card); border: 1px solid var(--line); padding: 10px 14px;
  border-radius: 18px 18px 18px 4px; }
.msg.bot > :first-child { margin-top: 0; } .msg.bot > :last-child { margin-bottom: 0; }
.msg p { margin: .5em 0; } .msg ul, .msg ol { margin: .5em 0; padding-left: 1.3em; } .msg li { margin: .15em 0; }
.msg h1, .msg h2, .msg h3, .msg h4 { margin: .8em 0 .3em; line-height: 1.25; } .msg h1 { font-size: 1.2em; } .msg h2 { font-size: 1.12em; } .msg h3, .msg h4 { font-size: 1.04em; }
.msg a { color: #c4a1ff; }
.msg code { background: rgba(0,0,0,.35); border-radius: 6px; padding: 1px 6px; font: .88em ui-monospace, Menlo, Consolas, monospace; }
.msg pre { position: relative; background: #07030f; border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  overflow-x: auto; margin: .6em 0; }
.msg pre code { background: none; padding: 0; font-size: 13px; white-space: pre; }
.copy { position: absolute; top: 6px; right: 6px; font-size: 12px; padding: 3px 8px; border-radius: 8px; background: var(--card);
  color: var(--muted); border: 1px solid var(--line); }

.tools { align-self: flex-start; width: 92%; display: flex; flex-direction: column; gap: 5px; }
.tool { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; font-size: 13.5px; overflow: hidden; }
.tool > summary { list-style: none; cursor: pointer; padding: 8px 11px; display: flex; gap: 8px; align-items: center; }
.tool > summary::-webkit-details-marker { display: none; }
.tool .nm { color: #c4a1ff; font-weight: 700; flex: none; }
.tool .sm { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
.tool .st { flex: none; font-weight: 700; }
.tool .st.ok { color: var(--ok); } .tool .st.bad { color: var(--bad); } .tool .st.wait { color: var(--muted); animation: pulse 1.2s infinite; }
.tool pre { margin: 0; padding: 10px 11px; border-top: 1px solid var(--line); max-height: 240px; overflow: auto;
  font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; color: #cfc3ea; }
.tool .cmd { padding: 8px 11px 0; font: 12px ui-monospace, Menlo, Consolas, monospace; color: var(--muted); white-space: pre-wrap; word-break: break-word; }

.note { align-self: center; font-size: 13px; color: var(--muted); text-align: center; padding: 2px 10px; }
.note.bad { color: var(--bad); } .note.ok { color: var(--ok); } .note.warn { color: var(--warn); }
.typing { align-self: flex-start; display: flex; gap: 5px; padding: 10px 14px; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: bounce 1.1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-5px); opacity: 1; } }
.jump { position: absolute; right: 14px; bottom: calc(118px + var(--safe-b)); width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 18px; z-index: 4; box-shadow: 0 4px 16px rgba(0,0,0,.5); }

/* rodapé */
.composer { padding: 8px 10px calc(8px + var(--safe-b)); background: rgba(11, 6, 20, .96); border-top: 1px solid var(--line); }
.modes { display: flex; gap: 6px; margin-bottom: 8px; align-items: center; }
.chips { display: flex; gap: 6px; flex: 1; min-width: 0; overflow-x: auto; }
#modelSel { width: auto; flex: none; padding: 4px 28px 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: #c4a1ff; border-color: var(--accent); }
.chip { background: var(--bg2); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 4px 12px;
  font: inherit; font-size: 13px; font-weight: 600; }
.chip.on { color: #fff; border-color: var(--accent); background: rgba(168, 85, 247, .22); }
.chip.on.total { border-color: var(--warn); background: rgba(251, 191, 36, .16); color: var(--warn); }
.composer .row { display: flex; gap: 8px; align-items: flex-end; }
#msg { resize: none; max-height: 160px; border-radius: 22px; padding: 11px 16px; line-height: 1.35; }
.send { flex: none; width: 46px; height: 46px; border-radius: 50%; border: 0; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent2), var(--accent)); box-shadow: 0 0 16px var(--glow); }
.send.stop { background: #b91c1c; box-shadow: 0 0 16px rgba(248, 113, 113, .4); }
.send:disabled { opacity: .45; }

/* menu lateral */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 20; }
.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(86vw, 340px); background: var(--bg2); border-right: 1px solid var(--line);
  z-index: 21; transform: translateX(-102%); transition: transform .22s ease; display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 12px) 14px calc(var(--safe-b) + 12px); gap: 10px; }
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.proj-row { display: flex; gap: 8px; }
.list-title { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; margin-top: 4px; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.chat-list li { display: flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px 4px 4px 12px; }
.chat-list li.on { border-color: var(--accent); }
.chat-list .t { flex: 1; min-width: 0; padding: 8px 0; cursor: pointer; }
.chat-list .t b { display: block; font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list .t span { font-size: 12px; color: var(--muted); }
.chat-list .del { background: none; border: 0; color: var(--muted); width: 38px; height: 38px; font-size: 15px; }
.chat-list .live { color: var(--accent); }
.drawer-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }

/* diálogo */
dialog { background: transparent; border: 0; padding: 0; color: var(--text); width: min(92vw, 420px); }
dialog::backdrop { background: rgba(0, 0, 0, .65); }
dialog .card { display: grid; gap: 12px; }
dialog h3 { margin: 0; } dialog label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; }

@media (min-width: 820px) {
  .feed, .composer { padding-left: max(12px, calc(50% - 400px)); padding-right: max(12px, calc(50% - 400px)); }
}

/* anexos, microfone, busca, status */
.send.ghost-btn { background: var(--card); border: 1px solid var(--line); box-shadow: none; color: var(--muted); }
.send.ghost-btn.rec { background: #b91c1c; border-color: transparent; color: #fff; animation: pulse 1s infinite; }
.atts { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.att { display: inline-flex; align-items: center; gap: 6px; background: var(--bg2); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 6px 4px 12px; font-size: 13px; max-width: 100%; }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46vw; }
.att.up { opacity: .6; }
.att button { background: none; border: 0; color: var(--muted); width: 26px; height: 26px; font-size: 14px; }
.msg.user .files { display: block; font-size: 12.5px; color: #d8c7ff; margin-bottom: 4px; }
#search { padding: 9px 14px; font-size: 15px; }
.chat-list li .acts { display: flex; flex: none; }
.chat-list .acts button { background: none; border: 0; color: var(--muted); width: 34px; height: 38px; font-size: 14px; }
.chat-list li .pin { color: var(--warn); }
.chat-list .snip { display: block; font-size: 12px; color: var(--muted); white-space: normal; margin-top: 2px; }
.chat-list .proj-tag { color: var(--accent); }
.toast { position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%); z-index: 40; max-width: 86vw;
  background: #2b1a4d; border: 1px solid var(--accent); color: var(--text); padding: 10px 16px; border-radius: 14px; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.6); text-align: center; }
.toast.bad { border-color: var(--bad); }
.sys { display: grid; gap: 8px; font-size: 14px; }
.sys .line { display: flex; justify-content: space-between; gap: 10px; color: var(--text); }
.sys .line span:first-child { color: var(--muted); }
.bar { height: 7px; background: var(--bg2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); }
.bar i.hot { background: var(--warn); } .bar i.crit { background: var(--bad); }
.h-sub { margin: 6px 0 0; font-size: 15px; }
.check { display: flex !important; flex-direction: row; align-items: center; gap: 10px; color: var(--text) !important; }
.check input { width: 22px; height: 22px; flex: none; }
dialog .card { max-height: 88dvh; overflow-y: auto; }
.ok-txt { color: var(--ok); } .bad-txt { color: var(--bad); }

.code-input { text-align: center; font-size: 28px; letter-spacing: .4em; padding-left: calc(14px + .4em); font-variant-numeric: tabular-nums; }

/* notificações e relatórios */
.badge { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; }
.rep-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rep-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 52dvh; overflow-y: auto; }
.rep-item { display: grid; gap: 2px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.rep-item.unread { border-color: var(--accent); }
.rep-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rep-view { max-width: 100%; max-height: 52dvh; overflow-y: auto; align-self: stretch; }
.dlg-actions.wrap { flex-wrap: wrap; justify-content: flex-start; }
