/* ==========================================================================
   AllAIs · capa «Ultravioleta»
   1) Ajustes del tema oscuro (los tokens viven en styles.css).
   2) Composer móvil de una línea que se abre al escribir.
   3) Efectos: entrada con lluvia de caracteres y respuesta que se decodifica.
   Se carga después de styles.css y compare.css.
   ========================================================================== */

/* ---------- 1. Tema oscuro ------------------------------------------------ */

:root[data-theme="dark"] .workspace {
  background:
    radial-gradient(900px 520px at 50% -160px, rgba(139, 124, 255, 0.2) 0%, transparent 70%),
    radial-gradient(700px 500px at 100% 100%, rgba(46, 230, 214, 0.06) 0%, transparent 70%),
    var(--ground);
}

:root[data-theme="dark"] .sidebar {
  --surface: #151422;
  --surface-2: #1c1b2b;
  --surface-3: #262438;
  --ink: #f4f3ff;
  --ink-2: #c4c1de;
  --ink-3: #a9a6c7;
  --line: #2c2a44;
  --line-strong: #3d3a5c;
  --accent: #8b7cff;
  --accent-ink: #0b0a14;
  --accent-soft: rgba(139, 124, 255, 0.14);
  --accent-ring: rgba(139, 124, 255, 0.4);
  background:
    radial-gradient(420px 260px at 0% 0%, rgba(139, 124, 255, 0.12), transparent 70%),
    linear-gradient(180deg, #100f1c 0%, #0a0914 100%);
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.05), 12px 0 40px -24px rgba(0, 0, 0, 0.8);
}

:root[data-theme="dark"] .send-button,
:root[data-theme="dark"] #loginButton {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 10px 22px -12px rgba(139, 124, 255, 0.8);
}

:root[data-theme="dark"] .prompt-workbench {
  background:
    linear-gradient(var(--surface), var(--surface)) padding-box,
    linear-gradient(180deg, rgba(170, 160, 255, 0.42), rgba(170, 160, 255, 0.1)) border-box;
}

:root[data-theme="dark"] .prompt-workbench::before {
  background: radial-gradient(closest-side, rgba(139, 124, 255, 0.3), transparent);
}

:root[data-theme="dark"] .topbar-model,
:root[data-theme="dark"] .language-switch,
:root[data-theme="dark"] .theme-toggle {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: none;
}

:root[data-theme="dark"] .account-avatar,
:root[data-theme="dark"] .topbar-account.is-signed {
  background: linear-gradient(150deg, #b9afff 0%, #6a5cd6 100%);
  color: #0b0a14;
}

:root[data-theme="dark"] .model-dot {
  background: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(46, 230, 214, 0.22);
}

/* ---------- Preferencias en el panel lateral (solo teléfono) --------------- */

/* Panel de preferencias del menú lateral: lectura siempre, idioma y tema en
   teléfono (en pantallas grandes viven en la barra superior). */
.prefs-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.prefs-row + .prefs-row {
  margin-top: 8px;
}

.prefs-mobile {
  display: none;
}

.prefs-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-3);
}

.read-switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.read-step {
  display: grid;
  place-items: center;
  width: 42px;
  height: 38px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-3);
  font-family: var(--font-read);
  line-height: 1;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}

.read-step:hover {
  color: var(--ink);
}

.read-step.is-on {
  background: var(--accent);
  color: var(--accent-ink);
}

.read-step:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.panel-prefs .language-button {
  min-width: 44px;
  min-height: 40px;
}

.panel-prefs .theme-toggle {
  width: 44px;
  height: 44px;
}

/* ---------- 2. Composer móvil ---------------------------------------------- */

.composer-summary {
  display: none;
}

@media (max-width: 640px) {
  .topbar .language-switch,
  .topbar .theme-toggle {
    display: none;
  }

  .prefs-mobile {
    display: flex;
  }

  .composer-dock {
    width: calc(100% - 24px);
    padding-top: 6px;
  }

  .prompt-workbench {
    gap: 8px;
    padding: 10px;
    border-radius: 22px;
  }

  .prompt-workbench::before {
    display: none;
  }

  .send-button {
    width: 44px;
    min-height: 44px;
    border-radius: 50%;
  }

  /* En reposo: una sola línea, como una píldora */
  .prompt-workbench:not(.is-open) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0 6px;
    padding: 6px;
    border-radius: 28px;
  }

  .prompt-workbench:not(.is-open) .composer-input-row {
    flex: 1;
    min-width: 0;
    padding: 0 0 0 12px;
  }

  .prompt-workbench:not(.is-open) #promptInput {
    height: 44px !important;
    min-height: 0;
    padding: 10px 0;
    line-height: 24px;
    white-space: nowrap;
    overflow: hidden !important;
    text-overflow: ellipsis;
  }

  .prompt-workbench:not(.is-open) .composer-footer {
    display: contents;
  }

  .prompt-workbench:not(.is-open) .composer-tools,
  .prompt-workbench:not(.is-open) .compare-selector,
  .prompt-workbench:not(.is-open) .openrouter-model-row,
  .prompt-workbench:not(.is-open) .media-model-select,
  .prompt-workbench:not(.is-open) .quota-note,
  .prompt-workbench:not(.is-open) .selected-provider-note {
    display: none !important;
  }

  .prompt-workbench:not(.is-open) .composer-send {
    flex: none;
    margin: 0;
    gap: 6px;
  }

  .prompt-workbench:not(.is-open) .attachment-list {
    order: 3;
    width: 100%;
    padding: 6px 6px 2px;
  }

  .prompt-workbench:not(.is-open) .composer-summary:not([hidden]) {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 10px;
    border: 0;
    border-radius: 22px;
    background: var(--surface-2);
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
  }

  .composer-summary-dots {
    display: inline-flex;
  }

  .composer-summary-dots i {
    width: 10px;
    height: 10px;
    margin-left: -3px;
    border: 2px solid var(--surface-2);
    border-radius: 50%;
  }

  /* Abierto: espacio para escribir, modelos en un carril y herramientas en una fila */
  .prompt-workbench.is-open .composer-input-row {
    padding: 2px 6px 0;
  }

  .prompt-workbench.is-open #promptInput {
    min-height: 72px;
    padding: 4px 0;
  }

  .prompt-workbench.is-open .compare-selector {
    padding: 0;
  }

  .prompt-workbench.is-open .compare-selector-hint:not(.is-warn) {
    display: none;
  }

  .prompt-workbench.is-open .compare-chips {
    flex-wrap: nowrap;
    width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .prompt-workbench.is-open .compare-chips::-webkit-scrollbar {
    display: none;
  }

  .prompt-workbench.is-open .compare-chip {
    flex: none;
    min-height: 44px;
  }

  .prompt-workbench.is-open .composer-footer {
    flex-wrap: wrap;
    gap: 8px;
    padding: 0;
  }

  .prompt-workbench.is-open .composer-tools {
    flex: 1;
    flex-wrap: nowrap;
    width: auto;
    gap: 6px;
  }

  .prompt-workbench.is-open .attach-button,
  .prompt-workbench.is-open .web-search-option {
    flex: none;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--ink);
  }

  .prompt-workbench.is-open .web-search-option .switch-track,
  .prompt-workbench.is-open .web-search-option > span:not(.switch-track) {
    display: none;
  }

  .prompt-workbench.is-open .web-search-option .web-icon {
    width: 19px;
    height: 19px;
  }

  .prompt-workbench.is-open .web-search-option:has(input:checked) {
    background: var(--accent);
    color: var(--accent-ink);
  }

  .prompt-workbench.is-open .compare-toggle {
    flex: none;
    justify-content: center;
    min-width: 52px;
    height: 44px;
    padding: 0 10px;
    border: 0;
    border-radius: 12px;
    background: var(--surface-2);
  }

  .prompt-workbench.is-open .compare-toggle-label {
    display: none;
  }

  .prompt-workbench.is-open .composer-send {
    flex: none;
    margin-left: auto;
  }

  .prompt-workbench.is-open .quota-note {
    display: none;
  }

  .prompt-workbench.is-open .openrouter-model-row,
  .prompt-workbench.is-open .media-model-select:not([hidden]) {
    order: 5;
    width: 100%;
    max-width: none;
  }

  .prompt-workbench.is-open .openrouter-model-select {
    min-height: 44px;
    max-width: none;
  }

  /* El acceso a la guía flotaba sobre el botón de enviar: sube a la esquina
     superior, bajo la barra, y solo se muestra en la pantalla de inicio. */
  .allais-tour-reopen {
    top: calc(var(--promo-h, 0px) + 64px);
    right: 12px;
    bottom: auto;
  }

  body:not(.is-empty) .allais-tour-reopen {
    display: none;
  }

  /* Con conversación en pantalla, lo accesorio bajo el composer no roba altura */
  body:not(.is-empty) .limit-note,
  body:not(.is-empty) .composer-hint {
    display: none;
  }
}

/* ---------- 3. Efectos ----------------------------------------------------- */

/* Respuesta que se decodifica: cola de caracteres al final del texto en curso */
.fx-noise {
  margin-left: 1px;
  color: var(--accent);
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 0.86em;
  letter-spacing: 0.02em;
  white-space: nowrap;
  user-select: none;
}

/* Mientras dura la entrada se cubre la app y se retienen el diálogo de acceso
   y la guía, que se dibujan por encima de todo. El respaldo que retira la clase
   pase lo que pase vive en el script de index.html. */
html.fx-intro body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: #08070f;
}

html.fx-intro dialog[open],
html.fx-intro .allais-tour-root {
  visibility: hidden;
}

.fx-intro-layer {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #08070f;
  opacity: 1;
  transform-origin: 50% 50%;
  transition: opacity 0.6s ease, transform 0.65s cubic-bezier(0.5, 0, 0.9, 0.4);
}

/* Salida: la escena se acerca y se disuelve sobre la app. */
.fx-intro-layer.is-leaving {
  opacity: 0;
  transform: scale(1.22);
  pointer-events: none;
}

.fx-intro-layer canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Con el destello la lluvia se abre hacia el espectador. */
.fx-intro-rain {
  transform-origin: 50% 50%;
  transition: opacity 0.9s ease, transform 1.1s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.fx-intro-layer.is-logo .fx-intro-rain {
  opacity: 0.5;
  transform: scale(1.45);
}

/* Resplandor detrás del logo: aparece con el destello y respira. */
.fx-intro-halo {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(84vw, 460px);
  height: min(48vw, 260px);
  transform: translate(-50%, -50%) scale(0.6);
  background: radial-gradient(closest-side, rgba(110, 96, 255, 0.3), rgba(46, 230, 214, 0.08) 55%, transparent 100%);
  opacity: 0;
  pointer-events: none;
}

.fx-intro-layer.is-logo .fx-intro-halo {
  animation: fx-halo-in 0.7s ease-out forwards, fx-halo-breathe 2.4s ease-in-out 0.7s infinite alternate;
}

@keyframes fx-halo-in {
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes fx-halo-breathe {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to { opacity: 0.7; transform: translate(-50%, -50%) scale(1.08); }
}

.fx-intro-logo {
  position: relative;
  width: min(44vw, 260px);
  height: auto;
  opacity: 0;
  will-change: transform, opacity, filter;
}

/* Entrada del logo: irrumpe sobreexpuesto, con un par de saltos, y luego flota. */
.fx-intro-layer.is-logo .fx-intro-logo {
  animation: fx-logo-in 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) forwards, fx-logo-float 2.6s ease-in-out 0.6s infinite alternate;
}

@keyframes fx-logo-in {
  0% { opacity: 0; transform: scale(1.16); filter: brightness(2.6) saturate(1.4); }
  18% { opacity: 1; transform: scale(1.1) translateX(-5px) skewX(-3deg); }
  30% { opacity: 0.55; transform: scale(1.08) translateX(4px) skewX(2deg); }
  44% { opacity: 1; transform: scale(1.05) translateX(-2px); filter: brightness(1.7) saturate(1.2); }
  100% { opacity: 1; transform: scale(1); filter: brightness(1) saturate(1); }
}

@keyframes fx-logo-float {
  from { opacity: 1; transform: translateY(-3px) scale(1); }
  to { opacity: 1; transform: translateY(3px) scale(1.035); }
}

/* El contenedor «pensando» es flex (para los tres puntos); al llegar texto debe
   fluir como párrafo para que la cola de caracteres siga a la última palabra. */
.message.pending.streaming .message-content {
  display: block;
}

/* Versión serena de la entrada, para quien pide reducir el movimiento:
   sin lluvia, sin destellos ni desplazamientos; solo aparece y se va. */
.fx-intro-layer.is-calm .fx-intro-logo {
  animation: none;
  transition: opacity 0.55s ease;
}

.fx-intro-layer.is-calm.is-logo .fx-intro-logo {
  opacity: 1;
}

.fx-intro-layer.is-calm .fx-intro-halo {
  transform: translate(-50%, -50%) scale(1);
  transition: opacity 0.55s ease;
  animation: none;
}

.fx-intro-layer.is-calm.is-logo .fx-intro-halo {
  opacity: 1;
}

.fx-intro-layer.is-calm,
.fx-intro-layer.is-calm.is-leaving {
  transform: none;
  transition: opacity 0.6s ease;
}
