/* SyncOS — interface. Tokens (:root) e estilos. */

:root {
  color-scheme: dark;

  --color-accent: #ff4b2b;
  --color-accent-hover: #e93e21;
  --color-success: #22c77a;
  --color-warning: #f2a33a;
  --color-danger: #e84d4d;

  --bg: #111114;
  --bg-deep: #0d0d10;
  --surface: #17171b;
  --surface-hover: #1d1d22;
  --border: #303036;
  --text: #f2f2f3;
  --text-muted: #96969f;
  --text-subtle: #64646d;
  --focus: #ff8a73;

  --font-sans: Inter, "SF Pro Text", "SF Pro Display", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --ease: cubic-bezier(0.2, 0, 0, 1);
  --dur-fast: 140ms;
  --dur-layout: 220ms;

  --topbar-h: 64px;
  --content-w: 720px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ---------- App shell ---------- */

.app {
  display: grid;
  grid-template-columns: 0 minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) auto;
  grid-template-areas:
    "top top"
    "rail stage"
    "rail dock";
  height: 100dvh;
}
.topbar { grid-area: top; }
.threads { grid-area: rail; }
.stage { grid-area: stage; }
.dock { grid-area: dock; }

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: var(--space-3); }

.brand-mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  display: block;
  object-fit: cover;
}

.brand-name {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.status { display: inline-flex; align-items: center; gap: var(--space-2); }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-subtle);
}
.status[data-status="online"] .status-dot { background: var(--color-success); }
.status[data-status="degraded"] .status-dot { background: var(--color-warning); }
.status[data-status="offline"] .status-dot { background: var(--color-danger); }

.divider { width: 1px; height: 16px; background: var(--border); }

/* ---------- Stage: orb + transcript ---------- */

.stage {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-8) var(--space-6) var(--space-4);
}

.presence {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: auto 0;
  transition: margin var(--dur-layout) var(--ease);
}

.orb-wrap {
  width: min(460px, 56vh, 82vw);
  transition: width var(--dur-layout) var(--ease);
}

signal-orb { width: 100%; }

/* Cérebro (brain.js): na abertura e na espera ocupa o lugar do orb. */
.orb-wrap { position: relative; }
.brain-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
signal-orb, .readout { transition: opacity 650ms var(--ease); }
.presence.brain-on signal-orb, .presence.brain-on .readout { opacity: 0; }

.readout {
  margin-top: calc(var(--space-6) * -1);
  text-align: center;
}
.readout p {
  margin: var(--space-2) 0 0;
  min-height: 1.55em;
  color: var(--text-muted);
}

.stage.has-messages .presence { margin: 0 0 var(--space-6); }
.stage.has-messages .orb-wrap { width: min(220px, 28vh, 50vw); }
.stage.has-messages .readout { margin-top: calc(var(--space-3) * -1); }

.transcript {
  width: 100%;
  max-width: var(--content-w);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.transcript:empty { display: none; }

.message {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  max-width: 85%;
}
.message .eyebrow { display: block; margin-bottom: var(--space-1); font-size: 0.7rem; }
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message .files { margin-top: var(--space-2); font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-muted); }

.message[data-from="user"] { align-self: flex-end; }
.message[data-from="syncos"] { align-self: flex-start; }
.message[data-from="system"] {
  align-self: center;
  max-width: 100%;
  background: transparent;
  border-style: dashed;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ---------- Dock: composer ---------- */

.dock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6) calc(var(--space-5) + env(safe-area-inset-bottom));
}

.composer {
  width: 100%;
  max-width: var(--content-w);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: var(--space-2);
  transition: border-color var(--dur-fast) var(--ease);
}
.composer:focus-within { border-color: #4a4a52; }

.composer-row { display: flex; align-items: flex-end; gap: var(--space-2); }

.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 180px;
  padding: 10px var(--space-2);
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  line-height: 1.5;
}
.composer textarea::placeholder { color: var(--text-subtle); }

.attachments {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-1) var(--space-1) var(--space-2);
}
.attachments:empty { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 260px;
  padding: 4px 6px 4px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button {
  display: grid; place-items: center;
  width: 22px; height: 22px;
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.chip button:hover { background: var(--surface-hover); color: var(--text); }

/* ---------- Buttons ---------- */

.icon-button {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px; height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.icon-button svg { width: 20px; height: 20px; }
.icon-button:hover { background: var(--surface-hover); color: var(--text); }
.icon-button:active { transform: scale(0.96); }
.icon-button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; background: transparent; }

.icon-button.send { border-color: var(--border); color: var(--text); }

.icon-button.mic { background: var(--color-accent); color: #fff; }
.icon-button.mic:hover { background: var(--color-accent-hover); }
.icon-button.mic[aria-pressed="true"] { background: var(--bg); color: var(--color-accent); border-color: var(--color-accent); }

.attach:focus-within, button:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- Topbar: botão de tarefas ---------- */

.tasks {
  min-height: 32px;
  padding: 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  cursor: pointer;
}
.tasks:hover:not(:disabled) { border-color: var(--border); color: var(--text); }
.tasks:disabled { cursor: default; }

/* ---------- Topbar: seletor de motor ---------- */

.engine-picker select {
  min-height: 32px;
  padding: 0 var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  cursor: pointer;
}
.engine-picker select:hover:not(:disabled) { border-color: var(--border); color: var(--text); }
.engine-picker select:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.engine-picker select:disabled { cursor: progress; }
.engine-picker option { background: var(--surface); color: var(--text); }


/* ---------- Threads (lateral) ---------- */

.threads {
  display: none;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-5) var(--space-3);
  background: var(--bg-deep);
  border-right: 1px solid var(--border);
}
.threads .eyebrow { padding: 0 var(--space-2); font-size: 0.68rem; }

@media (min-width: 900px) {
  .app.has-threads { grid-template-columns: 248px minmax(0, 1fr); }
  .app.has-threads .threads { display: flex; }
  .app.has-threads.threads-toggled { grid-template-columns: 0 minmax(0, 1fr); }
  .app.has-threads.threads-toggled .threads { display: none; }
}

.thread-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); }

.thread-tab {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.thread-tab:hover { background: var(--surface); }
.thread-tab[aria-current="true"] { background: var(--surface-hover); border-color: var(--border); }

.thread-top { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.thread-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.88rem; }
.thread-meta { padding-left: 16px; font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-muted); }

.thread-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--text-subtle); }
.thread-tab[data-status="running"] .thread-dot { background: var(--color-accent); animation: pulse 1.6s var(--ease) infinite; }
.thread-tab[data-status="done"] .thread-dot { background: var(--color-success); }
.thread-tab[data-status="error"] .thread-dot { background: var(--color-danger); }

@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- Mensagem do SyncOS: atividade + conteúdo ---------- */

.message[data-from="syncos"] { width: min(100%, 640px); max-width: 100%; }
.message[data-error="true"] { border-color: color-mix(in srgb, var(--color-danger) 45%, var(--border)); }

.activity { display: flex; flex-direction: column; gap: var(--space-1); }
.activity:empty { display: none; }
.message .activity { margin: var(--space-1) 0 var(--space-3); }

.op { border-radius: var(--radius-sm); }
.op-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  min-height: 32px;
  padding: 2px var(--space-2) 2px 2px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.76rem;
}
button.op-head { cursor: pointer; }
button.op-head:hover { background: var(--surface-hover); color: var(--text); }

.op-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.op-icon svg { width: 15px; height: 15px; }
.op[data-kind="tool"] .op-icon { color: var(--text); }
.op[data-status="running"] .op-icon { border-color: var(--color-accent); color: var(--color-accent); }
.op[data-status="error"] .op-icon { border-color: var(--color-danger); color: var(--color-danger); }

.op-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op[data-kind="tool"] .op-name { color: var(--text); }
.op-meta { margin-left: auto; flex: none; color: var(--text-subtle); }
.op[data-status="running"] .op-meta { color: var(--color-accent); }
.op[data-status="error"] .op-meta { color: var(--color-danger); }

.op-detail {
  margin: var(--space-1) 0 var(--space-2) 36px;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
}
.op-detail .eyebrow { display: block; margin-bottom: var(--space-1); font-size: 0.66rem; }
.op-detail pre {
  margin: 0 0 var(--space-3);
  max-height: 260px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.op-detail pre:last-child { margin-bottom: 0; }
.op-empty { margin: 0; color: var(--text-subtle); font-size: 0.8rem; }

.content { min-height: 24px; }
.content p, .content ul, .content ol { margin: 0 0 var(--space-3); }
.content > :last-child { margin-bottom: 0; }
.content ul, .content ol { padding-left: var(--space-5); }
.content h4 { margin: var(--space-2) 0; font-size: 1rem; font-weight: 600; }
.content code { font-family: var(--font-mono); font-size: 0.85em; padding: 1px 5px; border-radius: 5px; background: var(--bg); border: 1px solid var(--border); }
.content pre { margin: 0 0 var(--space-3); padding: var(--space-3); overflow-x: auto; border-radius: var(--radius-md); background: var(--bg); border: 1px solid var(--border); }
.content pre code { padding: 0; border: 0; background: none; font-size: 0.8rem; }
.content a:not(.media-link) { color: var(--focus); text-underline-offset: 2px; }
.content a:not(.media-link):hover { color: var(--text); }
.content .table-wrap { margin: 0 0 var(--space-3); max-width: 100%; overflow-x: auto; }
.content table { border-collapse: collapse; font-size: 0.9rem; }
.content th, .content td { padding: var(--space-1) var(--space-3); border: 1px solid var(--border); text-align: left; vertical-align: top; }
.content th { font-weight: 600; background: var(--bg); }
.content th.al-center, .content td.al-center { text-align: center; }
.content th.al-right, .content td.al-right { text-align: right; }
.content .media-link { display: inline-block; }
.content img.media { display: block; max-width: min(100%, 512px); height: auto; margin: var(--space-2) 0; border-radius: var(--radius-md); border: 1px solid var(--border); }
.content audio.media { display: block; width: 100%; max-width: 420px; margin: var(--space-2) 0; }
.content .live-qr { display: inline-flex; flex-direction: column; gap: var(--space-2); margin: var(--space-2) 0; padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg); }
.content .live-qr img { width: 240px; height: 240px; border-radius: var(--radius-sm); background: #fff; image-rendering: pixelated; }
.content .live-qr-status { font-size: 0.8rem; color: var(--text-muted); max-width: 240px; }
.content .muted { color: var(--text-muted); }
.error-text { color: #ff8b8b; }

.loader { display: flex; gap: 5px; padding: var(--space-2) 0; }
.loader span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); animation: bounce 0.9s var(--ease) infinite; }
.loader span:nth-child(2) { animation-delay: 0.15s; }
.loader span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ---------- Botão enviar/parar ---------- */

.icon-button.send .icon-stop { display: none; }
.icon-button.send[data-mode="stop"] .icon-send { display: none; }
.icon-button.send[data-mode="stop"] .icon-stop { display: block; width: 16px; height: 16px; }
.icon-button.send[data-mode="stop"] { border-color: var(--color-accent); color: var(--color-accent); }

/* ---------- Drawer de thread ---------- */

.drawer {
  margin: 0 0 0 auto;
  width: min(520px, 100vw);
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-deep);
  color: var(--text);
}
.drawer::backdrop { background: rgb(0 0 0 / 0.5); }
.drawer[open] { animation: slide-in var(--dur-layout) var(--ease); }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }

.drawer-panel { display: flex; flex-direction: column; gap: var(--space-5); height: 100%; overflow-y: auto; padding: var(--space-5) var(--space-6) var(--space-8); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.drawer-head h2 { margin: var(--space-1) 0 0; font-size: 1.25rem; font-weight: 550; letter-spacing: -0.01em; overflow-wrap: anywhere; }

.drawer-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--space-2) var(--space-5);
  margin: 0;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: 0.85rem;
}
.drawer-meta dt { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); align-self: center; }
.drawer-meta dd { margin: 0; }

.drawer-summary, .drawer-section { display: flex; flex-direction: column; gap: var(--space-2); }
.drawer-summary .eyebrow, .drawer-section .eyebrow { font-size: 0.68rem; }
.drawer-summary p { margin: 0; padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-left: 2px solid var(--color-success); border-radius: var(--radius-md); background: var(--surface); }

/* ---------- Consumo (cota, custo e tokens) ---------- */

.usage-toggle[data-level="warning"] { color: var(--color-warning); }
.usage-toggle[data-level="danger"] { color: var(--color-danger); }
.usage-limits, .usage-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.usage-limit {
  display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); font-size: 0.88rem;
}
.usage-limit-head, .usage-item { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); }
.usage-item { padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 0.85rem; }
.usage-item > div { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.usage-value { font-family: var(--font-mono); font-size: 0.76rem; color: var(--text-muted); text-align: right; }
.usage-limit .meta, .usage-item .meta { font-family: var(--font-mono); font-size: 0.7rem; color: var(--text-subtle); overflow-wrap: anywhere; }
.meter { height: 6px; border-radius: var(--radius-pill); background: var(--border); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--color-success); transition: width var(--dur-layout) var(--ease); }
.meter[data-level="warning"] > span { background: var(--color-warning); }
.meter[data-level="danger"] > span { background: var(--color-danger); }
.usage-actions { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.usage-note, .usage-empty { margin: 0; color: var(--text-muted); font-size: 0.82rem; }
.usage-credit { margin: 0; color: var(--text-subtle); font-size: 0.75rem; }
.usage-credit a { color: var(--text-muted); }

/* ---------- Botões genéricos ---------- */

.btn {
  min-height: 40px;
  padding: 0 var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--surface-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--color-accent); border-color: var(--color-accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--color-accent-hover); }
.btn-ghost { background: transparent; }
.icon-button.small { width: 32px; height: 32px; }
.icon-button.small svg { width: 16px; height: 16px; }

/* ---------- Aprovações ---------- */

.approvals { width: 100%; max-width: var(--content-w); display: flex; flex-direction: column; gap: var(--space-2); }
.approvals:empty { display: none; }

.approval {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.approval[data-done] { border-color: var(--border); opacity: 0.7; }
.approval[data-done] .approval-actions { display: none; }
.approval-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.approval-title { margin: 0; font-weight: 550; }
.approval-details {
  margin: 0; max-height: 180px; overflow: auto; padding: var(--space-3);
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg);
  font-family: var(--font-mono); font-size: 0.74rem; white-space: pre-wrap; overflow-wrap: anywhere;
}
.approval-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }
.approval-status { margin: 0; min-height: 1em; font-size: 0.8rem; color: var(--text-muted); }
.login-card input {
  flex: 1; min-height: 44px; padding: 0 var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg); color: var(--text); font: inherit;
}
.login-card input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Progresso de subsistema ---------- */

.progress { display: block; height: 4px; margin: 6px 0 0 16px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--color-accent); transition: width var(--dur-layout) var(--ease); }

/* ---------- Avisos (toasts) ---------- */

.toasts { position: fixed; right: var(--space-4); bottom: var(--space-4); z-index: 20; display: flex; flex-direction: column; gap: var(--space-2); }
.toast {
  display: flex; flex-direction: column; gap: 2px; max-width: 340px; padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border); border-left: 3px solid var(--text-muted); border-radius: var(--radius-md);
  background: var(--bg-deep); font-size: 0.85rem;
}
.toast[data-level="urgente"] { border-left-color: var(--color-danger); }
.toast span { color: var(--text-muted); }

/* ---------- Login ---------- */

.login-page { display: grid; place-items: center; min-height: 100dvh; padding: var(--space-4); }
.login { display: flex; flex-direction: column; align-items: center; gap: var(--space-6); width: min(380px, 100%); }
.login-card {
  display: flex; flex-direction: column; gap: var(--space-4); width: 100%; padding: var(--space-6);
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface);
}
.login-card h1 { margin: 0; font-size: 1.25rem; font-weight: 550; }
.login-card label { display: flex; flex-direction: column; gap: var(--space-1); font-size: 0.85rem; color: var(--text-muted); }
.login-error { margin: 0; min-height: 1.2em; color: #ff8b8b; font-size: 0.85rem; }
.login-submit { min-height: 44px; }
.login-note { margin: 0; font-size: 0.78rem; color: var(--text-subtle); text-align: center; }

/* ---------- Responsivo ---------- */

@media (max-width: 899px) {
  .app.threads-toggled .threads {
    display: flex;
    position: fixed;
    z-index: 10;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    max-height: 60dvh;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 640px) {
  :root { --topbar-h: 56px; }
  .topbar { padding: 0 var(--space-4); }
  .topbar-meta .divider { display: none; }
  .drawer-panel { padding: var(--space-4); }
  .stage { padding: var(--space-6) var(--space-4) var(--space-3); }
  .dock { padding-left: var(--space-3); padding-right: var(--space-3); }
  .message { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- Chave liga/desliga ---------- */
.power {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: 0; border: 0; background: transparent; cursor: pointer;
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-muted);
}
.power:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; border-radius: var(--radius-pill); }
.power:disabled { cursor: progress; opacity: 0.6; }
.power-track {
  position: relative; width: 36px; height: 20px; border-radius: var(--radius-pill);
  background: var(--color-success); transition: background var(--dur-fast) var(--ease);
}
.power-thumb {
  position: absolute; top: 2px; left: 18px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: left var(--dur-fast) var(--ease);
}
.power[aria-checked="false"] .power-track { background: var(--border); }
.power[aria-checked="false"] .power-thumb { left: 2px; }
.power[aria-checked="false"] .power-label { color: var(--color-danger); }
.status[data-status="off"] .status-dot { background: var(--color-danger); }
body[data-power="off"] .composer { opacity: 0.5; }

.resume-dialog {
  width: min(440px, calc(100vw - 32px)); padding: var(--space-6); border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--surface); color: var(--text);
}
.resume-dialog::backdrop { background: rgb(0 0 0 / 0.6); }
.resume-dialog h2 { margin: 0 0 var(--space-2); font-size: 1.1rem; font-weight: 550; }
.resume-dialog p { margin: 0 0 var(--space-3); color: var(--text-muted); }
.resume-dialog ul { margin: 0 0 var(--space-4); padding-left: var(--space-5); }
.resume-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }

/* ---------- Página de configurações ---------- */
.settings-page { min-height: 100dvh; }
.settings {
  width: min(760px, 100%); margin: 0 auto; padding: var(--space-6) var(--space-4) var(--space-12);
  display: flex; flex-direction: column; gap: var(--space-6);
}
.settings-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.settings-head h1 { margin: 0; font-size: 1.35rem; font-weight: 550; }
.settings-head a { color: var(--text-muted); text-decoration: none; font-size: 0.9rem; }
.settings-head a:hover { color: var(--text); }
.settings-section {
  border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface);
  padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4);
}
.settings-section h2 { margin: 0; font-size: 1rem; font-weight: 550; }
.settings-field { display: flex; flex-direction: column; gap: var(--space-1); }
.settings-field > span { font-size: 0.88rem; }
.settings-field small { color: var(--text-subtle); font-size: 0.78rem; }
.settings-field .source { font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-subtle); }
.settings-field input[type="text"], .settings-field input[type="number"], .settings-field select, .settings-field textarea {
  min-height: 40px; padding: var(--space-2) var(--space-3); border: 1px solid var(--border);
  border-radius: var(--radius-md); background: var(--bg); color: var(--text); font: inherit;
}
.settings-field textarea { min-height: 96px; resize: vertical; }
.settings-field :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.settings-field.check { flex-direction: row; align-items: center; gap: var(--space-2); }
.settings-actions { display: flex; align-items: center; gap: var(--space-3); }
.settings-status { margin: 0; font-size: 0.85rem; color: var(--text-muted); }
.settings-status[data-kind="error"] { color: var(--color-danger); }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.history li {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 0.85rem;
}
.history .meta { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-subtle); }
@media (prefers-reduced-motion: reduce) { .power-track, .power-thumb { transition: none; } }
#sections { display: flex; flex-direction: column; gap: var(--space-6); }
.settings-nav { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.settings-nav a {
  padding: var(--space-1) var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-pill);
  color: var(--text-muted); text-decoration: none; font-size: 0.8rem;
}
.settings-nav a:hover { color: var(--text); border-color: var(--text-subtle); }
.settings-section { scroll-margin-top: var(--space-4); }
.settings-field > label { font-size: 0.88rem; }
.settings-intro { margin: 0; color: var(--text-muted); font-size: 0.85rem; }
.settings-subtitle { margin: 0; font-size: 0.88rem; font-weight: 550; }
.picker, .list-inputs { display: flex; flex-direction: column; gap: var(--space-2); }
.choices-row { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); }
.choices-status[data-kind="error"] { color: var(--color-warning); }
.btn-small { min-height: 28px; padding: 2px var(--space-3); font-size: 0.78rem; }
.keys { display: flex; flex-direction: column; gap: var(--space-3); }
.key-row {
  display: flex; flex-direction: column; gap: var(--space-2);
  padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-md);
}
.key-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-3); }
.key-name { font-family: var(--font-mono); font-size: 0.85rem; overflow-wrap: anywhere; }
.key-state { font-size: 0.78rem; color: var(--text-subtle); }
.key-state.on { color: var(--color-success); }
.key-row small { color: var(--text-subtle); font-size: 0.78rem; }
.key-actions, .key-edit, .key-add { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); }
.key-edit[hidden], .picker [hidden] { display: none; }
.key-actions label { font-size: 0.8rem; color: var(--text-muted); }
.key-edit input, .key-add input { flex: 1 1 200px; min-width: 0; }
.keys input, .keys select, .key-add input, .key-add select, #twofa-code {
  min-height: 40px; padding: var(--space-2) var(--space-3); border: 1px solid var(--border);
  border-radius: var(--radius-md); background: var(--bg); color: var(--text); font: inherit;
}
.keys :focus-visible, .key-add :focus-visible, #twofa-code:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.twofa-field { display: block; margin-bottom: var(--space-1); font-size: 0.85rem; color: var(--text-muted); }
#twofa-code { width: 100%; margin-bottom: var(--space-4); letter-spacing: 0.2em; }

/* ---------- Modo fala ---------- */
.icon-button.speak[aria-pressed="true"] { color: var(--color-accent); border-color: var(--color-accent); }
.spoken {
  margin-top: var(--space-1); padding: var(--space-3); border: 1px solid var(--border);
  border-radius: var(--radius-md); display: flex; flex-direction: column; gap: var(--space-2);
}
.spoken .loader { padding: var(--space-1) 0; }
.spoken audio { width: 100%; height: 36px; }
.spoken details { font-size: 0.88rem; color: var(--text-muted); }
.spoken summary { cursor: pointer; }
/* Setinha do modo voz: mostra/esconde o texto completo da resposta. */
.reply-toggle {
  display: inline-flex; align-items: center; gap: var(--space-1);
  margin: var(--space-2) 0 0; padding: var(--space-1) var(--space-2) var(--space-1) var(--space-1);
  border: 0; border-radius: var(--radius-sm); background: transparent;
  color: var(--text-muted); font: inherit; font-size: 0.85rem; cursor: pointer;
}
.reply-toggle:hover { background: var(--surface-hover); color: var(--text); }
.reply-toggle-icon { display: grid; place-items: center; width: 20px; height: 20px; }
.reply-toggle-icon svg { width: 18px; height: 18px; transition: transform var(--dur-fast) var(--ease); }
.reply-toggle[aria-expanded="true"] .reply-toggle-icon svg { transform: rotate(180deg); }
.reply-toggle + .content:not([hidden]) { margin-top: var(--space-2); }
@media (prefers-reduced-motion: reduce) { .reply-toggle-icon svg { transition: none; } }
