:root {
  --bg: #0b0d10; --bg-2: #12151a; --panel: #161a20; --panel-2: #1c2129;
  --border: #262c36; --text: #e8eaed; --muted: #8b93a1;
  --accent: #6d8bff; --accent-2: #9b7bff; --user-bubble: #24304d;
  --ok: #35c08a; --danger: #ff6b6b; --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); overscroll-behavior: none; -webkit-font-smoothing: antialiased; }
.screen { height: 100dvh; }
.hidden { display: none !important; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; font-size: 20px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 6px 20px rgba(109,139,255,.35); }
.brand-mark.small { width: 30px; height: 30px; border-radius: 9px; font-size: 15px; box-shadow: none; }
.brand-name { font-size: 22px; font-weight: 700; letter-spacing: -.3px; }

/* LOGIN */
.login-screen { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(109,139,255,.14), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 22px; padding: 30px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.login-card .brand { justify-content: center; }
.login-sub { text-align: center; color: var(--muted); margin: 10px 0 26px; font-size: 14px; }
#login-form { display: flex; flex-direction: column; }
#login-form label { font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
#login-form input { background: var(--bg-2); border: 1px solid var(--border); color: var(--text); border-radius: 12px; padding: 14px; font-size: 16px; outline: none; transition: border-color .15s; }
#login-form input:focus { border-color: var(--accent); }
#login-btn { margin-top: 22px; padding: 15px; border: none; border-radius: 12px; cursor: pointer; font-size: 16px; font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); transition: transform .06s, opacity .15s; }
#login-btn:active { transform: scale(.98); }
#login-btn:disabled { opacity: .6; }
.error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 16px; text-align: center; }

/* APP LAYOUT */
.app-screen { position: relative; overflow: hidden; }
.chat-col { display: flex; flex-direction: column; height: 100dvh; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 18; opacity: 0; transition: opacity .2s; }
.scrim.show { opacity: 1; }

/* DRAWER */
.drawer { position: fixed; top: 0; left: 0; bottom: 0; width: 82%; max-width: 320px; z-index: 20;
  background: var(--bg-2); border-right: 1px solid var(--border); transform: translateX(-102%); transition: transform .24s ease;
  display: flex; flex-direction: column; padding: calc(14px + var(--safe-top)) 12px calc(12px + var(--safe-bottom)); }
.drawer.open { transform: translateX(0); box-shadow: 12px 0 40px rgba(0,0,0,.5); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 14px; }
.new-chat { width: 100%; padding: 13px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-size: 15px; font-weight: 600; cursor: pointer; }
.new-chat:active { background: var(--panel-2); }
.chat-list { flex: 1; overflow-y: auto; margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.chat-item { padding: 12px 12px; border-radius: 11px; cursor: pointer; display: flex; align-items: center; gap: 8px; color: var(--text); }
.chat-item:active, .chat-item.active { background: var(--panel); }
.chat-item .title { flex: 1; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .del { color: var(--muted); font-size: 16px; opacity: .6; padding: 2px 4px; }
.drawer-logout { margin-top: 10px; padding: 12px; border-radius: 11px; border: 1px solid var(--border); background: transparent; color: var(--muted); font-size: 14px; cursor: pointer; }

/* TOPBAR */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(10px + var(--safe-top)) 12px 10px;
  background: rgba(11,13,16,.85); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.agent-picker { display: flex; gap: 6px; background: var(--panel); border: 1px solid var(--border); padding: 4px; border-radius: 12px; }
.agent-btn { border: none; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; padding: 8px 12px; border-radius: 9px; cursor: pointer; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.agent-btn.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.agent-btn .dot { font-size: 10px; color: var(--accent-2); font-weight: 700; }
.icon-btn { background: var(--panel); border: 1px solid var(--border); color: var(--text); width: 40px; height: 40px; border-radius: 11px; font-size: 18px; cursor: pointer; display: grid; place-items: center; }
.icon-btn.round { border-radius: 50%; width: 44px; height: 44px; flex-shrink: 0; }

/* MESSAGES */
.messages { flex: 1; overflow-y: auto; padding: 18px 14px 8px; display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }
.empty-state { margin: auto; text-align: center; max-width: 320px; padding: 20px; position: relative; }
.empty-glow { position: absolute; inset: -40px 0 auto; height: 160px; background: radial-gradient(circle at 50% 0, rgba(155,123,255,.22), transparent 70%); filter: blur(10px); z-index: -1; }
.empty-state h2 { font-size: 24px; margin: 0 0 10px; letter-spacing: -.4px; }
.empty-state p { color: var(--muted); font-size: 14px; line-height: 1.5; }
.msg { max-width: 88%; padding: 12px 15px; border-radius: var(--radius); font-size: 15px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user-bubble); border-bottom-right-radius: 5px; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.msg.assistant.monark { border-color: rgba(155,123,255,.4); }
.msg .meta { display: block; margin-top: 8px; font-size: 11px; color: var(--muted); }
.msg img.att-img { max-width: 100%; border-radius: 10px; margin-bottom: 8px; display: block; }
.msg .att-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; margin-bottom: 8px; color: var(--muted); }
.typing { display: inline-flex; gap: 4px; } .typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2){ animation-delay: .2s } .typing i:nth-child(3){ animation-delay: .4s }
@keyframes blink { 0%,60%,100%{opacity:.3} 30%{opacity:1} }

/* ATTACH TRAY */
.att-tray { display: flex; gap: 8px; padding: 8px 12px; overflow-x: auto; background: rgba(11,13,16,.9); border-top: 1px solid var(--border); }
.att-pill { display: flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 6px 8px; font-size: 12px; white-space: nowrap; flex-shrink: 0; }
.att-pill img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.att-pill .x { color: var(--muted); cursor: pointer; font-weight: 700; padding: 0 2px; }
.att-pill.rec { color: var(--danger); }

/* COMPOSER */
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px calc(10px + var(--safe-bottom)); background: rgba(11,13,16,.9); backdrop-filter: blur(12px); border-top: 1px solid var(--border); }
.composer textarea { flex: 1; resize: none; max-height: 140px; background: var(--panel); border: 1px solid var(--border); color: var(--text); border-radius: 14px; padding: 13px 14px; font-size: 16px; outline: none; font-family: inherit; line-height: 1.4; }
.composer textarea:focus { border-color: var(--accent); }
#mic-btn.recording { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{ box-shadow: 0 0 0 0 rgba(255,107,107,.5) } 50%{ box-shadow: 0 0 0 8px rgba(255,107,107,0) } }
#send { width: 46px; height: 46px; flex-shrink: 0; border: none; border-radius: 13px; color: #fff; font-size: 18px; cursor: pointer; background: linear-gradient(135deg, var(--accent), var(--accent-2)); transition: transform .06s, opacity .15s; }
#send:active { transform: scale(.95); } #send:disabled { opacity: .5; }
#send.stop { background: var(--danger); }
.composer.editing textarea { border-color: var(--accent-2); box-shadow: 0 0 0 2px rgba(155,123,255,.25); }

/* chat item: custo */
.chat-item .ci-main { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; }
.chat-item .cost { font-size: 11px; color: var(--muted); background: var(--panel-2); border-radius: 6px; padding: 2px 6px; flex-shrink: 0; }

/* botão editar na mensagem do usuário */
.msg.user { position: relative; }
.edit-btn { position: absolute; left: -32px; bottom: 4px; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border); background: var(--panel); color: var(--muted); font-size: 13px; cursor: pointer; opacity: .7; }
.edit-btn:active { background: var(--panel-2); }

/* markdown */
.msg.assistant h3 { font-size: 17px; margin: 14px 0 8px; letter-spacing: -.2px; }
.msg.assistant h4 { font-size: 15px; margin: 12px 0 6px; color: #cfd4dc; }
.msg.assistant p { margin: 8px 0; }
.msg.assistant ul, .msg.assistant ol { margin: 8px 0; padding-left: 22px; }
.msg.assistant li { margin: 4px 0; }
.msg.assistant a { color: var(--accent); }
.msg.assistant strong { color: #fff; font-weight: 700; }
.msg.assistant code.inline { background: var(--bg-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.code-block { margin: 10px 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #0d1117; }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; background: #11161d; border-bottom: 1px solid var(--border); }
.code-head .lang { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.copy-btn { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); font-size: 12px; padding: 4px 10px; border-radius: 7px; cursor: pointer; }
.copy-btn:active { background: var(--accent); }
.code-block pre { margin: 0; padding: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.code-block code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; line-height: 1.5; color: #e6edf3; white-space: pre; }
.msg.generating { color: var(--text); }

/* agente Claudio desabilitado */
.agent-btn:disabled { opacity: .4; }
.agent-btn[data-agent="claudio"].active { color: #ffd591; }

/* barra de projeto */
.project-bar { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 14px; background: var(--bg-2); border: none; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 13px; cursor: pointer; text-align: left; }
.project-bar .pb-icon { font-size: 14px; }
.project-bar #project-name { flex: 1; color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-bar .pb-caret { color: var(--muted); }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.sheet-card { position: absolute; left: 0; right: 0; bottom: 0; background: var(--panel); border-top-left-radius: 22px; border-top-right-radius: 22px; border-top: 1px solid var(--border); padding: 12px 18px calc(20px + var(--safe-bottom)); max-height: 80dvh; overflow-y: auto; animation: slideup .22s ease; }
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 4px auto 14px; }
.sheet-card h3 { margin: 0 0 6px; font-size: 18px; }
.sheet-sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; line-height: 1.5; }
.proj-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.proj-opt { display: flex; align-items: center; gap: 10px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-2); cursor: pointer; }
.proj-opt.active { border-color: var(--accent); }
.proj-opt .p-name { flex: 1; font-weight: 600; }
.proj-opt .p-path { font-size: 11px; color: var(--muted); }
.proj-new { display: flex; gap: 8px; margin-bottom: 10px; }
.proj-new input { flex: 1; background: var(--bg-2); border: 1px solid var(--border); color: var(--text); border-radius: 11px; padding: 12px; font-size: 15px; outline: none; }
.proj-new button { padding: 0 18px; border: none; border-radius: 11px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-weight: 700; cursor: pointer; }
.proj-none { width: 100%; padding: 12px; border: 1px dashed var(--border); border-radius: 11px; background: transparent; color: var(--muted); cursor: pointer; }
