:root {
  --accent: #25d366;
  --fs: 15px;
  --bg: #0b141a; --panel: #111b21; --panel-2: #202c33; --hover: #2a3942; --line: #222d34;
  --text: #e9edef; --muted: #8696a0; --in: #202c33; --out: #005c4b; --chat-bg: #0b141a;
  --doodle: rgba(255,255,255,.035); --code: #0d1418; --shadow: 0 1px .5px rgba(0,0,0,.25);
}
:root.light {
  --bg: #eae6df; --panel: #ffffff; --panel-2: #f0f2f5; --hover: #f5f6f6; --line: #e9edef;
  --text: #111b21; --muted: #667781; --in: #ffffff; --out: #d9fdd3; --chat-bg: #efeae2;
  --doodle: rgba(0,0,0,.045); --code: #f4f6f8; --shadow: 0 1px .5px rgba(11,20,26,.13);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: var(--fs)/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif; }
body { overflow: hidden; height: 100dvh; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted) 45%, transparent) transparent; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- login */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); padding: 20px; }
.login-card { width: min(360px, 100%); background: var(--panel); border-radius: 16px; padding: 32px 24px; text-align: center; display: grid; gap: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0 0 8px; color: var(--muted); }
.login-logo, .empty-logo { width: 72px; height: 72px; margin: 0 auto 4px; display: grid; place-items: center; font-size: 36px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 20%, transparent); }
input, textarea, select { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid transparent; border-radius: 10px; padding: 11px 14px; outline: none; width: 100%; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.btn { border: 0; border-radius: 22px; padding: 10px 20px; cursor: pointer; background: var(--panel-2); font-weight: 600; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: #e5484d22; color: #ff6b70; }
.btn:disabled { opacity: .5; cursor: default; }
.err { color: #ff6b70; min-height: 1.2em; font-size: 14px; }

/* ---------- layout */
.app { display: grid; grid-template-columns: minmax(300px, 30%) 1fr auto; height: 100dvh; max-width: 1700px; margin: 0 auto; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.side-head, .chat-head, .drawer-head { height: 60px; display: flex; align-items: center; gap: 8px; padding: 0 12px 0 16px; background: var(--panel-2); flex-shrink: 0; padding-top: env(safe-area-inset-top); box-sizing: content-box; }
.side-head { justify-content: space-between; }
.side-title { font-size: 19px; font-weight: 700; }
.head-actions { display: flex; gap: 2px; margin-left: auto; }
.icon-btn { background: none; border: 0; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; color: var(--muted); flex-shrink: 0; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.search-wrap { margin: 8px 12px; position: relative; }
.search-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); }
.search-wrap input { padding: 8px 12px 8px 40px; border-radius: 8px; }
.gw-banner { margin: 4px 12px 8px; padding: 10px 12px; border-radius: 8px; background: #ffb02e22; color: #ffb02e; font-size: 13px; }

.agent-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.agent { display: flex; gap: 13px; align-items: center; padding: 0 0 0 14px; cursor: pointer; height: 72px; }
.agent:hover { background: var(--hover); }
.agent.active { background: var(--panel-2); }
.agent .meta { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: center; border-bottom: 1px solid var(--line); padding-right: 14px; }
.agent .row1, .agent .row2 { display: flex; align-items: center; gap: 8px; }
.agent .name { font-size: 16.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent .time { font-size: 12px; color: var(--muted); }
.agent .preview { flex: 1; font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent .preview.typing { color: var(--accent); font-weight: 500; }
.agent.unread .time { color: var(--accent); font-weight: 600; }
.agent .badge { min-width: 20px; height: 20px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; padding: 0 6px; }
.avatar { width: 49px; height: 49px; border-radius: 50%; display: grid; place-items: center; font-size: 25px; flex-shrink: 0; background: var(--c, var(--accent)); position: relative; user-select: none; }
.avatar.sm { width: 40px; height: 40px; font-size: 21px; }
.avatar.lg { width: 120px; height: 120px; font-size: 60px; margin: 0 auto; }

/* ---------- chat */
.chat { position: relative; display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); }
.chat::before { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 1; }
.wp-doodle .chat::before { background-image: radial-gradient(var(--doodle) 1.4px, transparent 1.6px), radial-gradient(var(--doodle) 1.4px, transparent 1.6px); background-size: 26px 26px; background-position: 0 0, 13px 13px; }
.wp-gradient .chat::before { background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%); }
.empty-chat { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); border-bottom: 6px solid var(--accent); background: var(--panel-2); position: relative; z-index: 1; }
.empty-chat h2 { color: var(--text); font-weight: 300; font-size: 30px; margin: 10px 0; }
.chat-head { z-index: 2; padding-left: 8px; border-left: 1px solid var(--line); }
.chat-who { display: flex; align-items: center; gap: 12px; background: none; border: 0; cursor: pointer; text-align: left; min-width: 0; flex: 1; padding: 4px 6px; border-radius: 8px; }
.who-text { min-width: 0; }
.who-name { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-status { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-status.typing { color: var(--accent); }
.back { display: none; }

.messages { flex: 1; overflow-y: auto; position: relative; z-index: 1; overscroll-behavior: contain; }
.msgs-inner { padding: 14px 6% 10px; display: flex; flex-direction: column; gap: 3px; max-width: 1100px; margin: 0 auto; }
#liveSlot { display: contents; }
.day-sep { align-self: center; margin: 10px 0 8px; background: var(--panel-2); color: var(--muted); font-size: 12.5px; padding: 5px 12px; border-radius: 8px; box-shadow: var(--shadow); text-transform: uppercase; }
.sys-note { align-self: center; margin: 6px 0; background: color-mix(in srgb, #ffd279 22%, var(--panel)); color: var(--text); font-size: 12.5px; padding: 6px 12px; border-radius: 8px; max-width: 85%; text-align: center; }
.bubble { position: relative; max-width: min(78%, 760px); padding: 6px 9px 8px; border-radius: 8px; box-shadow: var(--shadow); word-wrap: break-word; overflow-wrap: anywhere; font-size: var(--fs); }
.bubble.in { align-self: flex-start; background: var(--in); }
.bubble.out { align-self: flex-end; background: var(--out); }
.bubble.first.in { border-top-left-radius: 0; margin-top: 8px; }
.bubble.first.out { border-top-right-radius: 0; margin-top: 8px; }
.bubble.first.in::before, .bubble.first.out::before { content: ""; position: absolute; top: 0; width: 8px; height: 13px; }
.bubble.first.in::before { left: -8px; background: var(--in); clip-path: polygon(0 0, 100% 0, 100% 100%); }
.bubble.first.out::before { right: -8px; background: var(--out); clip-path: polygon(0 0, 100% 0, 0 100%); }
.bubble .stamp { float: right; margin: 6px 0 -5px 12px; font-size: 11px; color: var(--muted); line-height: 1; position: relative; top: 4px; white-space: nowrap; }
.bubble.out .stamp::after { content: " ✓✓"; color: #53bdeb; }
.bubble .content > :first-child { margin-top: 0; }
.bubble .content > :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 .5em; white-space: pre-wrap; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: .6em 0 .3em; font-size: 1.05em; }
.bubble ul, .bubble ol { margin: .2em 0 .5em; padding-left: 1.4em; }
.bubble li { margin: .1em 0; }
.bubble a { color: #53bdeb; }
.bubble code { background: var(--code); padding: 1px 5px; border-radius: 4px; font: .88em/1.4 Consolas, "Cascadia Code", monospace; }
.bubble pre { background: var(--code); padding: 10px 12px; border-radius: 6px; overflow-x: auto; margin: .4em 0; position: relative; }
.bubble pre code { background: none; padding: 0; white-space: pre; display: block; }
.bubble pre .copy { position: absolute; top: 4px; right: 4px; font-size: 11px; background: var(--panel-2); border: 0; border-radius: 4px; padding: 2px 7px; cursor: pointer; color: var(--muted); opacity: .8; }
.bubble blockquote { margin: .3em 0; padding: 2px 10px; border-left: 3px solid var(--accent); color: var(--muted); }
.bubble table { border-collapse: collapse; margin: .4em 0; font-size: .92em; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.bubble th { background: var(--code); }
.bubble hr { border: 0; border-top: 1px solid var(--line); }
.bubble img.media, .bubble video.media { max-width: 100%; max-height: 420px; border-radius: 6px; display: block; margin: 4px 0; background: #0003; }
.bubble audio.media { width: 100%; min-width: 240px; margin: 4px 0; }
.file-card { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--code); border-radius: 6px; margin: 4px 0; text-decoration: none; color: var(--text) !important; }
.file-card .ic { font-size: 22px; }
.user-imgs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 4px; }
.user-imgs img { max-width: 220px; max-height: 220px; border-radius: 6px; }

.tools { margin: 0 0 6px; font-size: 13px; }
.tools summary { cursor: pointer; color: var(--muted); list-style: none; display: flex; align-items: center; gap: 6px; user-select: none; }
.tools summary::-webkit-details-marker { display: none; }
.tools summary::before { content: "🔧"; font-size: 12px; }
.tool-item { margin: 4px 0 0; padding: 5px 8px; border-radius: 6px; background: var(--code); }
.tool-item .tn { font-weight: 600; font-size: 12.5px; }
.tool-item .tp { color: var(--muted); font: 12px/1.35 Consolas, monospace; white-space: pre-wrap; max-height: 160px; overflow: auto; margin-top: 2px; }
.tool-item.running .tn::after { content: " …"; }
.tool-item.failed .tn { color: #ff6b70; }
.live-tools { display: flex; flex-direction: column; gap: 3px; margin-bottom: 4px; font-size: 13px; color: var(--muted); }
.live-tools .lt { display: flex; gap: 6px; align-items: baseline; }
.live-tools .lt.running { color: var(--accent); }
.live-tools .lt span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: Consolas, monospace; font-size: 12px; }
.dots { display: inline-flex; gap: 4px; padding: 6px 2px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite both; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.bubble.error { background: #e5484d33; }
.commentary { color: var(--muted); font-style: italic; font-size: .93em; margin-bottom: 4px; }

.scroll-down { position: absolute; right: 22px; bottom: 82px; z-index: 3; width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--panel-2); color: var(--muted); box-shadow: 0 2px 6px rgba(0,0,0,.3); cursor: pointer; display: grid; place-items: center; }

.composer { z-index: 2; background: var(--panel-2); padding: 6px 10px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; max-width: 1100px; margin: 0 auto; }
.composer textarea { overflow-y: hidden; resize: none; max-height: 160px; min-height: 42px; border-radius: 21px; padding: 10px 16px; background: var(--panel); line-height: 1.4; }
.send-btn { flex-shrink: 0; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; cursor: pointer; display: grid; place-items: center; }
.send-btn svg { fill: currentColor; stroke: none; width: 21px; height: 21px; }
.send-btn.stop { background: #e5484d; }
.attach-preview { display: flex; gap: 6px; max-width: 1100px; margin: 0 auto; flex-wrap: wrap; }
.attach-preview:not(:empty) { padding: 6px 0; }
.attach-preview .ap { position: relative; }
.attach-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.attach-preview button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: #e5484d; color: #fff; font-size: 13px; cursor: pointer; line-height: 1; }

/* ---------- drawer */
.drawer { width: 400px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.drawer-title { font-size: 16px; font-weight: 500; }
.drawer-body { flex: 1; overflow-y: auto; padding-bottom: env(safe-area-inset-bottom); }
.sec { padding: 16px 20px; border-bottom: 8px solid var(--bg); }
.sec h3 { margin: 0 0 10px; font-size: 14px; color: var(--accent); font-weight: 500; }
.sec.center { text-align: center; }
.field { display: grid; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); }
.field textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch.on { border-color: var(--text); }
.emojis { display: flex; gap: 4px; flex-wrap: wrap; }
.emojis button { font-size: 22px; background: none; border: 0; border-radius: 8px; padding: 4px; cursor: pointer; }
.emojis button.on { background: var(--hover); }
.mem { white-space: pre-wrap; font: 12.5px/1.45 Consolas, monospace; background: var(--code); padding: 10px; border-radius: 8px; max-height: 260px; overflow: auto; color: var(--muted); }
.skill { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.skill b { font-weight: 600; }
.skill div { color: var(--muted); font-size: 12.5px; }
.sess { display: flex; align-items: center; gap: 10px; padding: 12px 20px; cursor: pointer; border-bottom: 1px solid var(--line); }
.sess:hover { background: var(--hover); }
.sess.on { background: var(--panel-2); }
.sess .st { flex: 1; min-width: 0; }
.sess .st div:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sess .st div:last-child { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.muted { color: var(--muted); font-size: 13px; }
.tabs { display: flex; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.tabs button { flex: 1; background: none; border: 0; padding: 12px 4px; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; font-size: 14px; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- modal / toast */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; width: min(480px, 100%); max-height: 90dvh; overflow-y: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.modal h2 { margin: 0 0 14px; font-size: 19px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #333d; color: #fff; padding: 10px 18px; border-radius: 20px; z-index: 60; font-size: 14px; max-width: 90vw; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; margin-bottom: 10px; }
.check input { width: auto; margin-top: 3px; }

/* ---------- celular */
@media (max-width: 820px) {
  .app { grid-template-columns: 100%; }
  .sidebar, .chat, .drawer { grid-row: 1; grid-column: 1; }
  .chat { display: none; }
  body.chat-open .chat { display: flex; }
  body.chat-open .sidebar { display: none; }
  .drawer { width: 100%; z-index: 5; }
  body.drawer-open .chat, body.drawer-open .sidebar { display: none; }
  .back { display: grid; }
  .chat-head { border-left: 0; padding-left: 2px; }
  .msgs-inner { padding: 10px 10px 8px; }
  .bubble { max-width: 88%; }
  .composer textarea { font-size: 16px; }
  .scroll-down { bottom: 76px; right: 14px; }
  .side-head { background: var(--panel); }
  .agent .meta { border-bottom-color: transparent; }
}
@media (min-width: 821px) { .drawer { animation: slidein .18s ease-out; } }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }
