/* ==========================================================================
   Estúdio de Agentes — folha de estilo
   ==========================================================================
   Sem framework, sem build. Só CSS moderno.

   Duas ideias sustentam o visual:

   1. Cada agente tem uma cor. Ela entra em --accent e o resto da interface
      é derivado dela com color-mix(). Trocar de agente repinta a tela inteira,
      e como --accent está registrado com @property, a troca é animada.

   2. Movimento com significado. Nada se mexe de enfeite: a esfera cresce com
      o volume real do áudio, as ferramentas deslizam quando disparam de
      verdade. Quem assiste consegue ler o estado do sistema sem legenda.
   ========================================================================== */

/* Registrar a variável faz o navegador interpolar a cor em vez de trocar
   de uma vez. É o que deixa a troca de agente suave. */
@property --accent {
  syntax: "<color>";
  inherits: true;
  initial-value: #5b8cff;
}

@property --level {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

:root {
  --accent: #5b8cff;
  --level: 0;

  --bg: #070810;
  --bg-2: #0b0d17;
  --surface: rgba(255, 255, 255, 0.028);
  --surface-hi: rgba(255, 255, 255, 0.055);
  --line: rgba(255, 255, 255, 0.09);
  --line-hi: rgba(255, 255, 255, 0.16);

  --text: #eef1f8;
  --muted: #8f98ad;
  --faint: #626c82;

  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;

  --r-sm: 9px;
  --r-md: 13px;
  --r-lg: 20px;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur: 0.42s;

  --sidebar-w: 288px;

  color-scheme: dark;
  transition: --accent 0.7s var(--ease);
}

* {
  box-sizing: border-box;
  min-width: 0;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.55 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Névoa de fundo: dois halos que respiram devagar na cor do agente.
   Fica atrás de tudo e não intercepta clique. */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: -30%;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(
    45% 45% at 22% 18%,
    color-mix(in srgb, var(--accent) 22%, transparent),
    transparent 70%
  );
  filter: blur(30px);
  opacity: 0.85;
  animation: drift 26s var(--ease-in-out) infinite alternate;
}

body::after {
  background: radial-gradient(
    40% 40% at 82% 88%,
    color-mix(in srgb, var(--accent) 15%, transparent),
    transparent 70%
  );
  animation-duration: 34s;
  animation-direction: alternate-reverse;
}

/* Enquanto o agente fala, o fundo inteiro pulsa junto. */
body.is-speaking::before,
body.is-speaking::after {
  opacity: calc(0.55 + var(--level) * 0.5);
  transition: opacity 0.16s linear;
}

@keyframes drift {
  from {
    transform: translate3d(-3%, -2%, 0) scale(1);
  }
  to {
    transform: translate3d(4%, 3%, 0) scale(1.14);
  }
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
  background-clip: content-box;
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* ==========================================================================
   Estrutura
   ========================================================================== */

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}

/* --- barra lateral --- */

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.022), transparent 40%);
  backdrop-filter: blur(14px);
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 18px 18px 14px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  flex: none;
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 45%, #000));
  box-shadow: 0 5px 18px -6px var(--accent);
}
.brand-mark svg {
  width: 16px;
  height: 16px;
}

.brand-text strong {
  display: block;
  font-size: 13.5px;
  font-weight: 620;
  letter-spacing: -0.01em;
}
.brand-text span {
  display: block;
  font-size: 10.5px;
  color: var(--faint);
  letter-spacing: 0.03em;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 18px 10px;
}

.sidebar-head h2 {
  margin: 0;
  font-size: 10.5px;
  font-weight: 620;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
}

.agent-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 0;
}

/* Cartão de agente. O ::before é a barrinha colorida que cresce quando
   selecionado — mais barato e mais elegante que trocar a borda. */
.agent-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    transform 0.16s var(--ease);
}

.agent-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 3px;
  height: 0;
  border-radius: 0 3px 3px 0;
  background: var(--dot);
  transform: translateY(-50%);
  transition: height var(--dur) var(--ease);
}

.agent-card:hover {
  background: var(--surface);
}
.agent-card:active {
  transform: scale(0.985);
}

.agent-card.selected {
  background: var(--surface-hi);
  border-color: var(--line);
}
.agent-card.selected::before {
  height: 62%;
}

.agent-avatar {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 17px;
  line-height: 1;
  background: color-mix(in srgb, var(--dot) 17%, transparent);
  border: 1px solid color-mix(in srgb, var(--dot) 32%, transparent);
  transition: transform var(--dur) var(--ease);
}
.agent-card:hover .agent-avatar {
  transform: scale(1.07) rotate(-4deg);
}

.agent-meta {
  flex: 1;
  min-width: 0;
}
.agent-meta strong {
  display: block;
  font-size: 13px;
  font-weight: 560;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-meta span {
  display: block;
  font-size: 11px;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Ponto verde de "conversa em andamento". */
.agent-card .on-air {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--ok);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.3s, transform 0.3s var(--ease);
}
.agent-card.on-air .on-air {
  opacity: 1;
  transform: scale(1);
  animation: blink 1.8s ease-in-out infinite;
}

@keyframes blink {
  50% {
    opacity: 0.35;
  }
}

.sidebar-foot {
  padding: 12px;
  border-top: 1px solid var(--line);
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(9px);
  }
}

/* --- área principal --- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  min-height: 63px;
}

.topbar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-title h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.012em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Alternador Palco / Estúdio. O indicador é um único elemento que desliza. */
.tabs {
  position: relative;
  display: flex;
  padding: 3px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--line);
}

.tabs .glider {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc(50% - 3px);
  border-radius: 8px;
  background: var(--surface-hi);
  border: 1px solid var(--line-hi);
  transition: transform var(--dur) var(--ease);
}
.tabs[data-view="studio"] .glider {
  transform: translateX(100%);
}

.tabs button {
  position: relative;
  z-index: 1;
  min-width: 84px;
  padding: 6px 14px;
  border: 0;
  background: none;
  color: var(--muted);
  font: 560 12.5px/1 inherit;
  border-radius: 8px;
  cursor: pointer;
  transition: color var(--dur) var(--ease);
}
.tabs button[aria-selected="true"] {
  color: var(--text);
}

.view-port {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  transition: opacity 0.34s var(--ease), transform 0.34s var(--ease);
}
.view[hidden] {
  display: block !important;
  opacity: 0;
  transform: translateX(var(--exit, -14px));
  pointer-events: none;
}

/* ==========================================================================
   Palco — onde a conversa acontece
   ========================================================================== */

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  min-height: 100%;
  padding: 40px 24px 32px;
  text-align: center;
}

/* --- a esfera --- */

.orb-wrap {
  position: relative;
  width: 210px;
  height: 210px;
  display: grid;
  place-items: center;
  flex: none;
}

/* Ondas que saem quando o agente começa a falar. */
.ripple {
  position: absolute;
  inset: 18px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  opacity: 0;
}
body.is-speaking .ripple {
  animation: ripple 2.3s var(--ease-in-out) infinite;
}
body.is-speaking .ripple:nth-child(2) {
  animation-delay: 0.75s;
}
body.is-speaking .ripple:nth-child(3) {
  animation-delay: 1.5s;
}

@keyframes ripple {
  0% {
    opacity: 0.6;
    transform: scale(0.82);
  }
  100% {
    opacity: 0;
    transform: scale(1.5);
  }
}

/* O corpo da esfera. A escala vem de --level, que o JS alimenta com o
   volume real do RTVI — por isso ela "respira" junto com a voz. */
.orb {
  position: relative;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 46px;
  line-height: 1;
  background: radial-gradient(
      circle at 32% 28%,
      color-mix(in srgb, var(--accent) 60%, #fff 8%),
      color-mix(in srgb, var(--accent) 88%, #000) 58%,
      color-mix(in srgb, var(--accent) 40%, #000) 100%
    );
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent),
    0 18px 60px -14px color-mix(in srgb, var(--accent) 75%, transparent),
    inset 0 -14px 34px -18px #000;
  transform: scale(calc(1 + var(--level) * 0.17));
  transition: transform 0.11s linear, filter var(--dur) var(--ease);
}

@keyframes breathe {
  50% {
    filter: brightness(1.09);
  }
}

/* Desconectado: adormecida, mas ainda com a cor do agente. Apagar de vez
   deixaria a primeira impressão sem graça. */
body:not(.is-live) .orb {
  filter: saturate(0.55) brightness(0.72);
}

/* Anel de escuta: engrossa conforme o usuário fala. */
.listen-ring {
  position: absolute;
  width: 168px;
  height: 168px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 70%, transparent);
  opacity: 0;
  transform: scale(0.94);
  transition: opacity 0.24s, transform 0.14s var(--ease);
}
body.is-listening .listen-ring {
  opacity: 0.9;
  transform: scale(calc(1 + var(--level) * 0.13));
}

/* Anel de progresso enquanto conecta. */
.spinner-ring {
  position: absolute;
  width: 176px;
  height: 176px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--accent);
  opacity: 0;
  transition: opacity 0.3s;
}
body.is-connecting .spinner-ring {
  opacity: 1;
  animation: spin 1.05s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- textos e botão do palco --- */

.stage-name {
  margin: 0;
  font-size: 25px;
  font-weight: 640;
  letter-spacing: -0.025em;
}

.stage-desc {
  margin: 0;
  max-width: 46ch;
  color: var(--muted);
  font-size: 13.5px;
}

.stage-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 11px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 12.5px;
  color: var(--muted);
  transition: color var(--dur), border-color var(--dur), background var(--dur);
}
.stage-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
  transition: background var(--dur), box-shadow var(--dur);
}
body.is-live .stage-status {
  color: var(--text);
  border-color: color-mix(in srgb, var(--ok) 40%, transparent);
}
body.is-live .stage-status .dot {
  background: var(--ok);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 18%, transparent);
}
.stage-status.error {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}
.stage-status.error .dot {
  background: var(--danger);
}

/* --- a régua de controles ---
   Eram etiquetas informativas; viraram botões. A aparência muda pouco de
   propósito: quem já conhecia a tela reconhece a fileira, descobre que ela
   responde ao clique e não precisa aprender um painel novo. */

.dock {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  /* Largo o bastante para os cinco caberem numa linha só numa tela comum; em
     telas menores eles quebram sozinhos, que é o comportamento certo. */
  max-width: min(900px, 100%);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px 5px 12px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font: 500 11.5px/1 inherit;
  cursor: pointer;
  animation: rise-in 0.5s var(--ease) both;
  animation-delay: calc(var(--i) * 45ms);
  transition: background 0.22s, border-color 0.22s, color 0.22s,
    transform 0.16s var(--ease);
}
.chip:hover {
  background: var(--surface-hi);
  border-color: var(--line-hi);
  color: var(--text);
  transform: translateY(-1px);
}
.chip:active {
  transform: translateY(0) scale(0.97);
}
.chip .v {
  color: var(--text);
  font-weight: 550;
}
.chip .chev {
  width: 12px;
  height: 12px;
  opacity: 0.5;
  transition: transform 0.3s var(--ease), opacity 0.2s;
}
.chip.open {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 13%, transparent);
}
.chip.open .chev {
  transform: rotate(180deg);
  opacity: 1;
}

/* --- painéis flutuantes da régua --- */

.pop {
  position: fixed;
  z-index: 60;
  width: min(var(--pop-w, 440px), calc(100vw - 24px));
  max-height: min(70vh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 15px 16px 17px;
  border: 1px solid var(--line-hi);
  border-radius: var(--r-lg);
  /* Opaco de verdade. Com fundo translúcido (mesmo a 98%), o texto grande e
     claro do palco atravessava o painel e brigava com o formulário. Quem
     separa o painel do fundo aqui é a sombra, não a transparência. */
  background: #0d0f18;
  box-shadow: 0 26px 70px -18px #000, 0 0 0 1px rgba(255, 255, 255, 0.02);
  text-align: left;
  /* Nasce e morre com a mesma transição; a classe .in é quem manda. */
  opacity: 0;
  transform: translateY(-8px) scale(0.97);
  transform-origin: top center;
  transition: opacity 0.2s var(--ease), transform 0.3s var(--ease);
}
.pop.in {
  opacity: 1;
  transform: none;
}

.pop-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.pop-head h4 {
  flex: 1;
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.pop-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: 500 11.5px/1 inherit;
  cursor: pointer;
  white-space: nowrap;
}
.pop-link:hover {
  text-decoration: underline;
}
.pop-hint {
  margin: 5px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--faint);
}
.pop-body {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-top: 14px;
}

/* --- "só vale na próxima conexão" ---
   Fechada, não ocupa espaço nenhum: o palco não fica com um buraco esperando
   um aviso que talvez nunca venha. */

.apply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(520px, 100%);
  max-height: 0;
  padding: 0 14px;
  opacity: 0;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  color: color-mix(in srgb, var(--warn) 78%, #fff);
  font-size: 12px;
  text-align: left;
  transition: max-height 0.34s var(--ease), padding 0.34s var(--ease),
    opacity 0.24s, border-color 0.3s;
}
.apply-bar.show {
  max-height: 72px;
  padding: 10px 10px 10px 14px;
  opacity: 1;
  border-color: color-mix(in srgb, var(--warn) 32%, transparent);
}
.apply-bar svg {
  width: 15px;
  height: 15px;
  flex: none;
}
.apply-bar .grow {
  flex: 1;
  min-width: 0;
}

.stage-hint {
  margin: 0;
  font-size: 12px;
  color: var(--faint);
  max-width: 42ch;
}

/* --- painel de ferramentas ao vivo --- */

.tool-feed {
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.tool-feed:empty {
  display: none;
}

.tool-event {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 11px 13px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  animation: tool-in 0.45s var(--ease) both;
}

@keyframes tool-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
}

.tool-event .icon {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 13px;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.tool-event.running .icon {
  animation: spin 1.1s linear infinite;
}
.tool-event.done .icon {
  background: color-mix(in srgb, var(--ok) 16%, transparent);
  border-color: color-mix(in srgb, var(--ok) 34%, transparent);
}

.tool-event .body {
  flex: 1;
  min-width: 0;
}
.tool-event code {
  font: 550 12.5px/1.4 ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
  color: var(--text);
}
.tool-event .args,
.tool-event .result {
  display: block;
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--muted);
  word-break: break-word;
  font-family: ui-monospace, "Cascadia Mono", Menlo, monospace;
}
.tool-event .result {
  color: var(--faint);
  max-height: 3.2em;
  overflow: hidden;
}

/* ==========================================================================
   Estúdio — o editor
   ========================================================================== */

.studio {
  --exit: 14px;
  /* O padding de baixo é pequeno de propósito: como este elemento é o próprio
     contêiner de rolagem, a barra de salvar (sticky, bottom:0) gruda no fim da
     área de conteúdo, e não da janela. Um padding grande a empurraria para
     cima, para o meio da tela. Estes 16px viram a folga que faz a barra
     parecer flutuando. */
  padding: 26px 26px 16px;
  max-width: 900px;
  margin-inline: auto;
}

.section {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  margin-bottom: 13px;
  overflow: hidden;
  transition: border-color var(--dur) var(--ease);
}
.section:hover {
  border-color: var(--line-hi);
}

.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 15px 18px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.section-head .num {
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 620;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
}

.section-head h3 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.section-head p {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--faint);
}
.section-head .grow {
  flex: 1;
  min-width: 0;
}

.chev {
  width: 15px;
  height: 15px;
  flex: none;
  color: var(--faint);
  transition: transform var(--dur) var(--ease);
}
.section.open .chev {
  transform: rotate(180deg);
}

/* Acordeão sem medir altura no JS: grid-template-rows de 0fr para 1fr. */
.section-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur) var(--ease);
}
.section.open .section-body {
  grid-template-rows: 1fr;
}
.section-body > div {
  overflow: hidden;
  min-height: 0;
}
.section-inner {
  padding: 2px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

/* --- campos --- */

/* Só os rótulos de campo de verdade. O ":not(.switch)" importa: um
   interruptor também é um <label>, e sem essa exclusão esta regra venceria
   o display:flex dele por especificidade, achatando o botão em cima do texto. */
.field > label:not(.switch),
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 550;
  color: var(--muted);
}
.field .help {
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--faint);
  line-height: 1.5;
}

.row {
  display: grid;
  gap: 13px;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

textarea {
  resize: vertical;
  min-height: 96px;
  line-height: 1.6;
  font-family: ui-monospace, "Cascadia Mono", Menlo, monospace;
  font-size: 12.5px;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent) 65%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
  background: rgba(0, 0, 0, 0.4);
}

input::placeholder,
textarea::placeholder {
  color: var(--faint);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238f98ad' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 15px;
  padding-right: 32px;
  cursor: pointer;
}
select option {
  background: #12141f;
}

/* --- botões --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-hi);
  color: var(--text);
  font: 560 13px/1 inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s, transform 0.14s var(--ease),
    box-shadow 0.24s, opacity 0.2s;
}
.btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.09);
  border-color: var(--line-hi);
  transform: translateY(-1px);
}
.btn:active:not(:disabled) {
  transform: translateY(0) scale(0.975);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn svg {
  width: 15px;
  height: 15px;
  flex: none;
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #05070d;
  font-weight: 620;
  box-shadow: 0 8px 24px -10px var(--accent);
}
.btn.primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 88%, #fff);
  box-shadow: 0 12px 30px -10px var(--accent);
}

.btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}
.btn.danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn.ghost:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
}

.btn.wide {
  width: 100%;
}

.btn.big {
  padding: 13px 30px;
  font-size: 14.5px;
  border-radius: 11px;
}

.btn.stop {
  background: var(--danger);
  border-color: transparent;
  color: #1a0505;
  box-shadow: 0 8px 24px -10px var(--danger);
}
.btn.stop:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 88%, #fff);
}

.icon-btn {
  width: 30px;
  height: 30px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.16s var(--ease);
}
.icon-btn:hover {
  background: var(--surface-hi);
  color: var(--text);
}
.icon-btn:active {
  transform: scale(0.9);
}
.icon-btn svg {
  width: 15px;
  height: 15px;
}
.icon-btn.danger:hover {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, transparent);
}

/* --- interruptores --- */

.switch {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, 0.16);
  cursor: pointer;
  transition: border-color 0.24s, background 0.24s;
}
.switch:hover {
  border-color: var(--line-hi);
}
.switch.on {
  border-color: color-mix(in srgb, var(--accent) 42%, transparent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

/* Só o botão, sem moldura. Usado onde o rótulo já vem de fora, como no
   cabeçalho de um servidor MCP. */
.switch.bare {
  padding: 0;
  border: 0;
  background: none;
  gap: 0;
}
.switch.bare:hover,
.switch.bare.on {
  border: 0;
  background: none;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.track {
  position: relative;
  width: 34px;
  height: 19px;
  flex: none;
  margin-top: 1px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
  transition: background var(--dur) var(--ease);
}
.track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #cdd4e3;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.switch.on .track {
  background: var(--accent);
}
.switch.on .track::after {
  transform: translateX(15px);
  background: #fff;
}

.switch .text strong {
  display: block;
  font-size: 12.5px;
  font-weight: 550;
}
.switch .text code {
  font: 550 12px/1.4 ui-monospace, "Cascadia Mono", Menlo, monospace;
}
.switch .text span {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--faint);
  line-height: 1.5;
}

/* --- seletores em grade (modelo, voz, cor, emoji) --- */

.grid {
  display: grid;
  gap: 8px;
}
.grid.models {
  grid-template-columns: repeat(auto-fit, minmax(232px, 1fr));
}
.grid.voices {
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  max-height: 268px;
  overflow-y: auto;
  padding-right: 4px;
}

.pick {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, 0.16);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.24s, background 0.24s, transform 0.16s var(--ease);
}
.pick:hover {
  border-color: var(--line-hi);
  background: var(--surface);
  transform: translateY(-1px);
}
.pick.on {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 26%, transparent);
}

.pick .name {
  display: block;
  font-size: 12.5px;
  font-weight: 560;
}
.pick .sub {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--faint);
  line-height: 1.45;
}
.pick .grow {
  flex: 1;
  min-width: 0;
}

/* Selo de "a busca funciona neste modelo". */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.badge.ok {
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 14%, transparent);
}
.badge.warn {
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 14%, transparent);
}

.voice-play {
  width: 24px;
  height: 24px;
  flex: none;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.3);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, transform 0.16s var(--ease);
}
.voice-play:hover {
  color: var(--text);
  border-color: var(--line-hi);
  transform: scale(1.12);
}
.voice-play svg {
  width: 11px;
  height: 11px;
}
.voice-play.loading svg {
  animation: spin 0.9s linear infinite;
}
.voice-play.playing {
  color: var(--accent);
  border-color: var(--accent);
  animation: pulse-ring 1.1s ease-out infinite;
}

@keyframes pulse-ring {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent);
  }
  100% {
    box-shadow: 0 0 0 8px transparent;
  }
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.swatch {
  width: 27px;
  height: 27px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  background: var(--c);
  transition: transform 0.2s var(--ease), box-shadow 0.2s;
}
.swatch:hover {
  transform: scale(1.16);
}
.swatch.on {
  border-color: #fff;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 45%, transparent);
}

.emoji-pick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.emoji-pick button {
  width: 33px;
  height: 33px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: transform 0.18s var(--ease), border-color 0.2s, background 0.2s;
}
.emoji-pick button:hover {
  transform: translateY(-2px) scale(1.08);
  border-color: var(--line-hi);
}
.emoji-pick button.on {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

/* --- controles deslizantes --- */

.slider-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}
.slider-head .val {
  font: 550 12px/1 ui-monospace, "Cascadia Mono", Menlo, monospace;
  color: var(--accent);
  transition: color var(--dur);
}
.slider-head .val.auto {
  color: var(--faint);
}

input[type="range"] {
  width: 100%;
  height: 22px;
  appearance: none;
  background: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 99px;
  background: linear-gradient(
    90deg,
    var(--accent) var(--pct, 0%),
    rgba(255, 255, 255, 0.12) var(--pct, 0%)
  );
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  transition: transform 0.16s var(--ease);
}

/* Em "automático" o valor mostrado é só o padrão do modelo, não uma escolha
   sua. O controle fica apagado para não parecer que você definiu algo. */
input[type="range"].auto::-webkit-slider-runnable-track {
  background: rgba(255, 255, 255, 0.12);
}
input[type="range"].auto::-webkit-slider-thumb {
  border-color: rgba(255, 255, 255, 0.3);
  background: #9aa3b6;
}
input[type="range"]:hover::-webkit-slider-thumb {
  transform: scale(1.18);
}
input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.3);
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
}
input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--accent);
}

/* --- avisos --- */

.notice {
  display: flex;
  gap: 10px;
  padding: 11px 13px;
  border-radius: var(--r-md);
  font-size: 11.5px;
  line-height: 1.55;
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  background: color-mix(in srgb, var(--warn) 9%, transparent);
  color: color-mix(in srgb, var(--warn) 72%, #fff);
  animation: rise-in 0.36s var(--ease) both;
}
.notice svg {
  width: 15px;
  height: 15px;
  flex: none;
  margin-top: 1px;
}
.notice b {
  color: #fff;
  font-weight: 600;
}
.notice code {
  font-family: ui-monospace, "Cascadia Mono", Menlo, monospace;
}

/* --- servidores MCP --- */

.mcp-item {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, 0.2);
  overflow: hidden;
  animation: rise-in 0.4s var(--ease) both;
}
.mcp-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
}
.mcp-head .grow {
  flex: 1;
  min-width: 0;
}
.mcp-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.mcp-item.off {
  opacity: 0.5;
}

/* --- barra de salvar, fixa no rodapé --- */

.savebar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  margin-top: 18px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(10, 12, 20, 0.86);
  backdrop-filter: blur(16px);
  box-shadow: 0 -8px 30px -14px #000;
}
.savebar .grow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--faint);
}
.savebar .grow svg {
  width: 13px;
  height: 13px;
  flex: none;
  color: var(--ok);
}
.savebar .grow.dirty {
  color: var(--warn);
}
.savebar .grow.dirty svg {
  color: var(--warn);
  animation: spin 0.9s linear infinite;
}

/* --- estado vazio --- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 100%;
  padding: 40px;
  text-align: center;
  color: var(--muted);
  animation: rise-in 0.5s var(--ease) both;
}
.empty .big-emoji {
  font-size: 42px;
  animation: breathe 4s var(--ease-in-out) infinite;
}
.empty h2 {
  margin: 0;
  font-size: 18px;
  color: var(--text);
  font-weight: 600;
}
.empty p {
  margin: 0;
  max-width: 40ch;
  font-size: 13px;
}

/* ==========================================================================
   Sobreposições — avisos e confirmação
   ========================================================================== */

/* No topo, e não embaixo: a barra de salvar já ocupa o rodapé do Estúdio, e
   avisos brigando com o botão Salvar seria o pior lugar possível. */
.toasts {
  position: fixed;
  z-index: 60;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 16px;
  border-radius: 99px;
  border: 1px solid var(--line-hi);
  background: rgba(16, 19, 30, 0.94);
  backdrop-filter: blur(14px);
  box-shadow: 0 14px 40px -12px #000;
  font-size: 12.5px;
  animation: toast-in 0.4s var(--ease) both;
}
.toast.out {
  animation: toast-out 0.3s var(--ease-in-out) both;
}
.toast.ok {
  border-color: color-mix(in srgb, var(--ok) 42%, transparent);
}
.toast.error {
  border-color: color-mix(in srgb, var(--danger) 42%, transparent);
}
.toast svg {
  width: 15px;
  height: 15px;
  flex: none;
}
.toast.ok svg {
  color: var(--ok);
}
.toast.error svg {
  color: var(--danger);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-16px) scale(0.94);
  }
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(-10px) scale(0.96);
  }
}

dialog {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
}
dialog::backdrop {
  background: rgba(4, 5, 10, 0.68);
  backdrop-filter: blur(5px);
  animation: fade-in 0.28s var(--ease) both;
}
dialog[open] .modal {
  animation: modal-in 0.34s var(--ease) both;
}

.modal {
  width: min(400px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid var(--line-hi);
  border-radius: var(--r-lg);
  background: #10131e;
  box-shadow: 0 30px 80px -20px #000;
}
.modal h3 {
  margin: 0 0 7px;
  font-size: 16px;
  font-weight: 620;
}
.modal p {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}
.modal .actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.95);
  }
}

/* ==========================================================================
   Responsivo e acessibilidade
   ========================================================================== */

/* --- peças compartilhadas --- */

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn.small {
  padding: 5px 11px;
  font-size: 11.5px;
  border-radius: 7px;
}

.notice.ok {
  border-color: color-mix(in srgb, var(--ok) 30%, transparent);
  background: color-mix(in srgb, var(--ok) 8%, transparent);
  color: color-mix(in srgb, var(--ok) 76%, #fff);
}

/* Sem descrição, o parágrafo continua no DOM (para poder ser preenchido ao
   vivo enquanto se digita) mas não deve abrir um vão no palco. */
.stage-desc:empty {
  display: none;
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 42vh;
  }
  .studio {
    padding: 18px 15px 80px;
  }
  .dock {
    max-width: 100%;
  }
  .chip {
    padding: 5px 8px 5px 10px;
    font-size: 11px;
  }
  .orb-wrap {
    width: 178px;
    height: 178px;
  }
  .orb {
    width: 112px;
    height: 112px;
    font-size: 38px;
  }
}

/* Quem pediu menos movimento recebe menos movimento. A interface continua
   inteira: só param as animações decorativas. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .orb {
    transform: none !important;
  }
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
