:root {
  --bg: #0b0d12;
  --bg-2: #11141b;
  --panel: #161a23;
  --panel-2: #1d2230;
  --line: #262c3b;
  --text: #e7e9f0;
  --muted: #8b93a7;
  --accent: #2ee6c5;
  --accent-2: #7c6cff;
  --accent-ink: #04130f;
  --danger: #ff5d73;
  --warn: #ffb547;
  --ok: #3ddc84;
  --user-bubble: #1f2a3d;
  --code-bg: #0d1017;
  --radius: 14px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;
  --brand-font: "Space Grotesk", var(--font);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fb; --bg-2: #eef0f6; --panel: #ffffff; --panel-2: #f1f3f9; --line: #dfe3ec;
    --text: #151925; --muted: #5d6578; --accent: #0fb89a; --accent-2: #5b4bf0; --accent-ink: #ffffff;
    --user-bubble: #e6ecf8; --code-bg: #0f1320; color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; margin: 0; }

/* ---------- elementos básicos ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px;
  padding: 9px 14px; font-weight: 500; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.btn:active { transform: scale(.98); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--accent-2)));
  border-color: transparent; color: var(--accent-ink); font-weight: 600;
}
.btn.ghost { background: transparent; text-align: left; }
.btn.danger { color: var(--danger); background: transparent; }
.btn.wide { width: 100%; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.link { background: none; border: 0; color: var(--accent); padding: 0; }
.icon-btn {
  background: transparent; border: 0; width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center; font-size: 18px; flex-shrink: 0;
}
.icon-btn:hover { background: var(--panel-2); }
.select, input:not([type=checkbox]), textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; outline: none;
}
.select:focus, input:focus, textarea:focus { border-color: var(--accent); }
.pill {
  display: inline-block; min-width: 20px; padding: 0 7px; border-radius: 99px; font-size: 12px;
  background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); margin-left: 4px;
}
.pill:empty { display: none; }

.brand { display: flex; align-items: center; gap: 10px; font: 700 20px var(--brand-font); letter-spacing: -.02em; }
.brand img { width: 30px; height: 30px; }
.brand.big { font-size: 30px; justify-content: center; }
.brand.big img { width: 46px; height: 46px; }

/* ---------- login ---------- */
.auth {
  height: 100dvh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 20% -10%, color-mix(in srgb, var(--accent-2) 22%, transparent), transparent),
              radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--accent) 18%, transparent), transparent), var(--bg);
}
.auth-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: 28px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.auth-card p { text-align: center; margin: -4px 0 6px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-card input { padding: 11px 12px; font-size: 16px; color: var(--text); }
.auth-card .btn { padding: 11px; }

/* ---------- layout ---------- */
.app { display: flex; height: 100dvh; }
.sidebar {
  width: 280px; flex-shrink: 0; background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px; padding: calc(14px + var(--safe-t)) 12px calc(12px + var(--safe-b));
}
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 6px; }
.search { width: 100%; font-size: 14px; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.conv-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 12px 10px 4px; }
.conv {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 9px; cursor: pointer;
  font-size: 14px; color: color-mix(in srgb, var(--text) 85%, var(--muted));
}
.conv span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv:hover { background: var(--panel); }
.conv.active { background: var(--panel-2); color: var(--text); }
.conv .conv-actions { display: none; gap: 2px; }
.conv:hover .conv-actions, .conv.active .conv-actions { display: flex; }
.conv-actions button { background: none; border: 0; padding: 2px 4px; color: var(--muted); font-size: 13px; }
.conv-actions button:hover { color: var(--text); }
.side-bottom { display: flex; flex-direction: column; gap: 4px; border-top: 1px solid var(--line); padding-top: 10px; }
.user-row { display: flex; justify-content: space-between; align-items: center; font-size: 14px; padding: 6px 10px 0; color: var(--muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-t)) 16px 10px;
  border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
}
.topbar .select { max-width: 260px; min-width: 0; font-size: 14px; }
.switch { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--warn); user-select: none; cursor: pointer; }
.switch input { accent-color: var(--warn); width: 16px; height: 16px; }

/* ---------- mensagens ---------- */
.messages { flex: 1; overflow-y: auto; padding: 24px 16px 8px; scroll-behavior: smooth; }
.msg { max-width: 820px; margin: 0 auto 22px; display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg.user .bubble {
  background: var(--user-bubble); padding: 10px 14px; border-radius: 18px 18px 4px 18px;
  max-width: min(85%, 640px); white-space: pre-wrap; word-break: break-word;
}
.msg.assistant .bubble { width: 100%; word-break: break-word; }
.msg-meta { display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-meta, .msg:last-child .msg-meta { opacity: 1; }
.msg-meta button { background: none; border: 0; color: var(--muted); padding: 0; font-size: 12px; }
.msg-meta button:hover { color: var(--text); }

.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 .8em; }
.bubble ul, .bubble ol { padding-left: 1.4em; margin: 0 0 .8em; }
.bubble h1, .bubble h2, .bubble h3 { font-family: var(--brand-font); line-height: 1.3; margin: 1.1em 0 .5em; }
.bubble h1 { font-size: 1.4em; } .bubble h2 { font-size: 1.2em; } .bubble h3 { font-size: 1.05em; }
.bubble a { color: var(--accent); }
.bubble blockquote { margin: 0 0 .8em; padding: 2px 14px; border-left: 3px solid var(--accent-2); color: var(--muted); }
.bubble table { border-collapse: collapse; margin: 0 0 1em; display: block; overflow-x: auto; font-size: 14px; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.bubble th { background: var(--panel); }
.bubble :not(pre) > code { font: .88em var(--mono); background: var(--panel-2); padding: 2px 6px; border-radius: 6px; }
.codeblock { position: relative; margin: 0 0 1em; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--code-bg); }
.codeblock-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; font: 12px var(--mono); color: #8b93a7; background: #151a26; }
.codeblock-head button { background: none; border: 0; color: #8b93a7; font-size: 12px; }
.codeblock-head button:hover { color: #fff; }
.codeblock pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.codeblock code { font: 13px/1.55 var(--mono); background: none !important; padding: 0 !important; color: #e6e8ee; }

.cursor > :last-child::after, .cursor:empty::after { content: "▋"; color: var(--accent); animation: blink 1s steps(2) infinite; margin-left: 2px; }
.cursor > .codeblock:last-child::after { display: block; padding: 0 0 4px 14px; }
@keyframes blink { 50% { opacity: 0; } }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: none; opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

details.think { margin: 0 0 10px; border-left: 2px solid var(--line); padding-left: 12px; color: var(--muted); font-size: 14px; }
details.think summary { cursor: pointer; font-size: 13px; list-style: none; }
details.think summary::before { content: "💭 "; }
details.think[open] summary { margin-bottom: 6px; }
details.think .think-body { white-space: pre-wrap; }

/* ---------- cartões de ferramentas ---------- */
.tool {
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); margin: 4px 0 12px; overflow: hidden;
}
.tool-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; font-size: 13px; }
.tool-head .tname { font-weight: 600; }
.tool-head .tstatus { margin-left: auto; font-size: 12px; padding: 1px 9px; border-radius: 99px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.tool.ok .tstatus { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.tool.error .tstatus { color: var(--danger); background: color-mix(in srgb, var(--danger) 14%, transparent); }
.tool.denied .tstatus { color: var(--muted); }
.tool.awaiting { border-color: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 15%, transparent); }
.tool.awaiting .tstatus { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.tool.running .tstatus::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--accent); animation: blink 1s infinite; }
.tool-cmd { margin: 0; padding: 8px 12px; background: var(--code-bg); color: #e6e8ee; font: 13px/1.5 var(--mono); white-space: pre-wrap; word-break: break-all; border-top: 1px solid var(--line); }
.tool-actions { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.tool-actions .note { font-size: 12px; color: var(--muted); flex-basis: 100%; }
.tool details { border-top: 1px solid var(--line); }
.tool details summary { padding: 7px 12px; font-size: 12px; color: var(--muted); cursor: pointer; }
.tool details pre { margin: 0; max-height: 340px; overflow: auto; padding: 10px 12px; background: var(--code-bg); color: #cfd3dc; font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; }

.error-box { border: 1px solid color-mix(in srgb, var(--danger) 50%, var(--line)); background: color-mix(in srgb, var(--danger) 8%, transparent); border-radius: 10px; padding: 10px 12px; font-size: 14px; white-space: pre-wrap; }

/* ---------- vazio ---------- */
.empty { max-width: 640px; margin: 8vh auto 0; text-align: center; padding: 0 8px; }
.empty-logo { width: 64px; height: 64px; margin-bottom: 8px; }
.empty h1 { font: 700 30px var(--brand-font); letter-spacing: -.02em; margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 8px 14px; font-size: 14px; }
.chip:hover { border-color: var(--accent); }

/* ---------- composer ---------- */
.composer { padding: 8px 16px calc(10px + var(--safe-b)); }
.composer-box {
  max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 8px 8px 8px 14px;
  transition: border-color .15s;
}
.composer-box:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.composer textarea { flex: 1; border: 0; background: transparent; resize: none; max-height: 220px; padding: 7px 0; font-size: 16px; line-height: 1.45; }
.send {
  width: 38px; height: 38px; border-radius: 12px; border: 0; flex-shrink: 0; font-size: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
}
.send:disabled { opacity: .35; cursor: default; }
.send.stop { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.hint { text-align: center; font-size: 12px; margin: 6px 0 0; }

/* ---------- diálogo ---------- */
.dlg {
  width: min(620px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); border: 1px solid var(--line);
  border-radius: 18px; background: var(--panel); color: var(--text); padding: 20px; overflow-y: auto;
}
.dlg::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(3px); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-head h2 { margin: 0; font: 700 22px var(--brand-font); }
.row { display: flex; gap: 8px; margin-top: 14px; }
.row input { flex: 1; min-width: 0; }
.machine-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.machine { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-2); }
.machine .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.machine .dot.on { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent); }
.machine .mi { flex: 1; min-width: 0; }
.machine .mi b { display: block; }
.machine .mi span { font-size: 12px; color: var(--muted); }
.install-box { margin-top: 16px; padding: 14px; border-radius: 12px; border: 1px dashed var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.install-box h3 { margin: 0 0 6px; font-size: 15px; }
.install-box pre { margin: 6px 0 12px; padding: 10px; border-radius: 8px; background: var(--code-bg); color: #e6e8ee; font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-all; }
.install-box .lbl { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); padding: 8px 16px; border-radius: 99px;
  font-size: 14px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,.3);
}

/* ---------- responsivo ---------- */
.only-mobile { display: none; }
.scrim { display: none; }
@media (max-width: 820px) {
  .only-mobile { display: grid; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(300px, 86vw);
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: 10px 0 40px rgba(0,0,0,.35);
  }
  .app.side-open .sidebar { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
  .topbar { padding-left: 8px; padding-right: 8px; gap: 6px; }
  .topbar .select { flex: 1; max-width: none; font-size: 13px; padding: 7px 6px; }
  .messages { padding: 16px 12px 8px; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .empty { margin-top: 4vh; }
  .empty h1 { font-size: 25px; }
  .hint { display: none; }
  .conv .conv-actions { display: flex; }
}

/* ================= v2: anexos, painel ao vivo, configurações ================= */
.composer-box { flex-wrap: wrap; }
.att-chips { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
.att-chips:empty { display: none; }
.attach { width: 38px; height: 38px; border-radius: 12px; border: 0; background: transparent; font-size: 18px; flex-shrink: 0; }
.attach:hover { background: var(--panel-2); }
.composer-box { padding-left: 6px; }
.att {
  display: inline-flex; align-items: center; gap: 6px; max-width: 240px; padding: 5px 6px 5px 10px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 13px;
}
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att small { color: var(--muted); white-space: nowrap; }
.att button { background: none; border: 0; color: var(--muted); padding: 0 4px; }
.att.loading { opacity: .65; }
.att.loading::after { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--muted); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.att.err { border-color: var(--danger); color: var(--danger); }
@keyframes spin { to { transform: rotate(360deg); } }
.msg.user .att-list { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; max-width: 85%; }
.msg.user .att { cursor: pointer; background: var(--panel); }
.msg.user .att img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; margin: -2px 0 -2px -6px; }

.drop {
  position: absolute; inset: 10px; z-index: 15; border: 2px dashed var(--accent); border-radius: 18px;
  background: color-mix(in srgb, var(--bg) 85%, var(--accent)); display: grid; place-items: center;
  text-align: center; font: 600 20px var(--brand-font); pointer-events: none;
}
.drop small { font: 400 13px var(--font); color: var(--muted); }

.notice { font-size: 13px; color: var(--muted); border-left: 2px solid var(--warn); padding: 2px 10px; margin: 0 0 10px; }
.msg-meta .regen { margin-left: auto; }

/* cartões compactos para ferramentas do workspace */
.tool.compact { background: transparent; border-style: dashed; }
.tool.compact .tool-head { padding: 6px 10px; }
.tool.compact .tool-cmd { display: none; }
.tool .tfile { font: 12px var(--mono); color: var(--accent); background: none; border: 0; padding: 0; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }
.tool .tfile:hover { text-decoration: underline; }
.tool.run .tool-cmd { display: block; }

/* painel lateral */
.ws-toggle { position: relative; margin-left: auto; }
.dotcount { position: absolute; top: 3px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 10px; line-height: 16px; font-weight: 700; }
.dotcount:empty { display: none; }
.panel {
  width: min(48vw, 760px); min-width: 360px; flex-shrink: 0; border-left: 1px solid var(--line); background: var(--bg-2);
  display: flex; flex-direction: column; padding-top: var(--safe-t);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.tabs button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; font-size: 13px; color: var(--muted); }
.tabs button.active { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.panel-actions { display: flex; gap: 2px; }
.panel-actions a { text-decoration: none; color: inherit; }
.panel-file { display: flex; align-items: center; gap: 10px; padding: 6px 14px; font: 12px var(--mono); color: var(--muted); border-bottom: 1px solid var(--line); min-height: 30px; }
.panel-file span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live { color: var(--accent); font: 600 11px var(--font); white-space: nowrap; animation: blink 1.2s infinite; }
.panel-body { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; overflow: auto; }
#v-preview iframe { width: 100%; height: 100%; border: 0; background: #fff; display: block; }
#v-preview img { max-width: 100%; display: block; margin: 16px auto; border-radius: 8px; }
#v-preview .md-view { padding: 20px 26px; max-width: 820px; }
#v-preview .placeholder { height: 100%; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 20px; }
#v-preview table.csv { border-collapse: collapse; font-size: 13px; margin: 12px; }
#v-preview table.csv td, #v-preview table.csv th { border: 1px solid var(--line); padding: 4px 8px; white-space: nowrap; }
#v-preview table.csv th { background: var(--panel); position: sticky; top: 0; }
#v-code { background: var(--code-bg); }
#v-code pre { margin: 0; padding: 14px 16px; min-height: 100%; }
#v-code code { font: 12.5px/1.6 var(--mono); color: #e6e8ee; background: none !important; white-space: pre; }
.files-bar { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg-2); flex-wrap: wrap; }
.file-tree { padding: 6px 6px 20px; }
.frow { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; font-size: 13px; cursor: pointer; }
.frow:hover { background: var(--panel); }
.frow.active { background: var(--panel-2); }
.frow .fname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frow .fsize { color: var(--muted); font-size: 12px; }
.frow .fdel { background: none; border: 0; color: var(--muted); opacity: 0; padding: 0 4px; }
.frow:hover .fdel { opacity: 1; }
.fdir { padding: 10px 8px 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

.settings { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.settings label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; }
.settings textarea { resize: vertical; font-size: 14px; color: var(--text); }
.row.end { justify-content: flex-end; }

@media (max-width: 1100px) {
  .panel { position: fixed; inset: 0 0 0 auto; width: min(100vw, 620px); min-width: 0; z-index: 35; box-shadow: -10px 0 40px rgba(0,0,0,.35); }
}
@media (max-width: 820px) {
  .panel { width: 100vw; }
  .tabs button { padding: 5px 9px; }
  .frow .fdel { opacity: 1; }
}

/* ================= v3: app desktop ================= */
a.btn { text-decoration: none; color: inherit; display: block; }
.this-pc { display: flex; align-items: center; gap: 12px; margin-top: 14px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); background: color-mix(in srgb, var(--accent) 7%, var(--bg-2)); }
.this-pc .mi { flex: 1; }
.this-pc .mi b { display: block; }
.this-pc .mi span { font-size: 12px; color: var(--muted); }
.toggle { position: relative; width: 44px; height: 26px; flex-shrink: 0; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span { position: absolute; inset: 0; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); transition: .2s; }
.toggle span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: .2s; }
.toggle input:checked + span { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + span::after { transform: translateX(18px); background: #fff; }
body.desktop-app .topbar { -webkit-app-region: no-drag; }

/* ================= v4: módulos, conhecimento, feedback, voz ================= */
.module-select { font-weight: 600; }
.empty-emoji { font-size: 54px; line-height: 1; display: block; margin-bottom: 8px; }
.pill.warn { background: color-mix(in srgb, var(--warn) 22%, transparent); color: var(--warn); }
.msg-meta button.on { color: var(--accent); }
.msg-meta [data-fb], .msg-meta [data-speak] { font-size: 13px; filter: grayscale(.4); }
.msg-meta [data-fb].on, .msg-meta [data-speak].on { filter: none; transform: scale(1.15); }
.attach.on { background: color-mix(in srgb, var(--danger) 18%, transparent); animation: blink 1.2s infinite; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 2px 0 8px; font-size: 12px; color: var(--muted); }
.sources button { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 2px 10px; font-size: 12px; color: var(--text); max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sources button:hover { border-color: var(--accent); }

.dlg.kc { width: min(1080px, calc(100vw - 20px)); height: min(860px, calc(100dvh - 20px)); display: flex; flex-direction: column; padding: 18px 20px; }
.dlg.kc:not([open]) { display: none; }
.kc-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 12px 0 0; border-bottom: 1px solid var(--line); }
.kc-tabs button { border: 0; background: none; padding: 8px 12px; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.kc-tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.kc-body { flex: 1; overflow-y: auto; padding: 14px 2px 10px; }
.kc-intro { font-size: 14px; color: var(--muted); margin-bottom: 14px; line-height: 1.55; }
.kc-add { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px dashed var(--line); border-radius: 12px; margin-bottom: 14px; }
.kc-add textarea { width: 100%; resize: vertical; color: var(--text); }
.kc-add-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.kc-search { display: flex; gap: 8px; margin-bottom: 10px; }
.kc-search input { flex: 1; color: var(--text); }
.kc-filter { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.kc-filter input { flex: 1; min-width: 140px; color: var(--text); }
.kc-list { display: flex; flex-direction: column; gap: 6px; }
.kc-item { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-2); cursor: default; }
.kc-item[data-doc] { cursor: pointer; }
.kc-item[data-doc]:hover { border-color: var(--accent); }
.kc-item.pending { border-color: color-mix(in srgb, var(--warn) 55%, var(--line)); }
.kc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.kc-actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.kc-hits { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.kc-hit { font-size: 13px; padding: 8px 10px; border-left: 3px solid var(--accent); background: var(--panel); border-radius: 0 8px 8px 0; cursor: pointer; white-space: pre-wrap; }
.kc-hit .tag { display: block; font-size: 11px; color: var(--accent); margin-bottom: 4px; }
.kc-doc { max-width: 860px; }
.kc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.kc-card { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: var(--bg-2); display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.kc-card:hover { border-color: var(--accent); }
.kc-card.off { opacity: .55; }
.kc-card.int { cursor: default; }
.kc-card.int label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.kc-card.int input:not([type=checkbox]) { color: var(--text); font-size: 13px; padding: 6px 8px; }
.kc-card-h { display: flex; align-items: center; gap: 8px; }
.kc-card-h .big { font-size: 22px; }
.kc-card-h .status { margin-left: auto; font-size: 11px; padding: 1px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.kc-card-h .status.on { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.kc-card p { margin: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tags span { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--panel-2); color: var(--muted); }
.kc-group { margin: 18px 0 8px; font: 600 14px var(--font); color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kc-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; max-width: 860px; }
.kc-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.kc-form input:not([type=checkbox]), .kc-form textarea, .kc-form select { color: var(--text); font-size: 14px; }
.kc-form textarea { resize: vertical; font: 13px/1.5 var(--mono); }
.kc-form fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.kc-form legend { font-size: 13px; color: var(--muted); padding: 0 6px; }
label.chk { flex-direction: row !important; align-items: center; gap: 6px; font-size: 13px; color: var(--text) !important; }
.int-msg, .dev-msg { white-space: pre-wrap; word-break: break-word; font-family: var(--mono); }
.int-msg.ok, .dev-msg.ok { color: var(--ok); }
.int-msg.err, .dev-msg.err { color: var(--danger); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; background: var(--bg-2); display: flex; flex-direction: column; }
.tile b { font: 700 26px var(--brand-font); }
.tile span { font-size: 12px; color: var(--muted); }
.warnbox { border: 1px solid color-mix(in srgb, var(--warn) 50%, var(--line)); background: color-mix(in srgb, var(--warn) 8%, transparent); padding: 10px 12px; border-radius: 10px; font-size: 13px; }
.kc-howto { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-top: 10px; font-size: 14px; }
.kc-howto summary { cursor: pointer; }
.kc-howto p { color: var(--muted); line-height: 1.6; }
@media (max-width: 820px) {
  .dlg.kc { padding: 14px 12px; }
  .kc-item { flex-direction: column; align-items: stretch; }
  .kc-actions { justify-content: flex-start; }
  .topbar .module-select { max-width: 42%; }
}
@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .topbar .select { flex: 1 1 38%; }
  .topbar .module-select { flex-basis: calc(100% - 50px); max-width: none; order: -1; }
  #open-side { order: -2; }
}

.dlg.ask { width: min(560px, calc(100vw - 24px)); }
.dlg.ask h3 { margin: 0 0 6px; font: 600 18px var(--brand-font); }
.dlg.ask p { margin: 0 0 10px; }
.dlg.ask input, .dlg.ask textarea { width: 100%; color: var(--text); font-size: 15px; }
.dlg.ask textarea { resize: vertical; }
.dlg.ask .row { margin-top: 14px; }

.tool-head .tname { white-space: nowrap; }
.tool-head .tfile { min-width: 0; }
.kc-card .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

.al-jobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; margin-bottom: 8px; }
.al-job { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; background: var(--bg-2); display: flex; flex-direction: column; gap: 4px; }
.al-job.off { opacity: .55; }
.al-job p { margin: 0; }
.al-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.al-st { margin-top: 4px; }
.toggle.sm { width: 38px; height: 22px; }
.toggle.sm span::after { width: 14px; height: 14px; }
.toggle.sm input:checked + span::after { transform: translateX(16px); }
.select.sm { padding: 4px 6px; font-size: 13px; }

/* grupos e usuários */
.gr-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.gr-mods { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.gr-mods .chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 3px 8px; border: 1px solid var(--border, #333); border-radius: 999px; cursor: pointer; }
.gr-mods .chip input { margin: 0; }

/* comparar modelos */
.cmp-dlg { width: min(1400px, 96vw); max-height: 92vh; }
.cmp-top { display: grid; gap: 8px; padding: 0 16px 12px; }
.cmp-top textarea { width: 100%; resize: vertical; padding: 10px; border-radius: 10px; border: 1px solid var(--border, #333); background: transparent; color: inherit; font: inherit; }
.cmp-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.cmp-pick .select { max-width: 260px; }
.cmp-cols { display: grid; grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); gap: 10px; padding: 0 16px 16px; overflow: auto; max-height: 62vh; }
.cmp-col { border: 1px solid var(--border, #333); border-radius: 12px; padding: 10px; min-width: 0; overflow: auto; }
.cmp-h { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; position: sticky; top: 0; background: inherit; }
@media (max-width: 760px) { .cmp-cols { grid-template-columns: 1fr; max-height: none; } }

/* galeria de ferramentas e modo anônimo */
.tools-title { margin: 22px 0 8px; text-align: center; }
.tools-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; max-width: 860px; margin: 0 auto; width: 100%; }
.tool-chip { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border, #2a2f3a); background: var(--panel, transparent); color: inherit; font: inherit; font-size: 13px; text-align: left; cursor: pointer; transition: border-color .15s, transform .15s; }
.tool-chip:hover { border-color: var(--accent, #6d8cff); transform: translateY(-1px); }
.tool-chip span { font-size: 16px; }
.tool-chip.on { border-color: var(--accent, #6d8cff); box-shadow: 0 0 0 1px var(--accent, #6d8cff) inset; }
body.incognito .composer, body.incognito .topbar { box-shadow: inset 0 -2px 0 #8b5cf6; }
@media (max-width: 560px) { .tools-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
