/* ==========================================
   PULIDO DE DETALLES (capa aditiva)
   Transiciones, retroalimentación al pulsar, foco visible
   y entradas suaves. Se puede quitar sin afectar la estructura.
   ========================================== */

/* Retroalimentación al pulsar botones */
button, .btn-primary, .btn-secondary, .btn-ghost, .icon-btn, .new-prompt-btn, .nav-item, .chip, .style-pick {
  transition: transform .15s ease, background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease, filter .2s ease, opacity .2s ease;
}
button:not(:disabled):active,
.btn-primary:not(:disabled):active,
.btn-secondary:not(:disabled):active,
.btn-ghost:not(:disabled):active,
.icon-btn:active {
  transform: scale(.97);
}
button:disabled, .btn-primary:disabled, .btn-secondary:disabled { opacity: .5; cursor: not-allowed; }

/* Foco visible para teclado (sin molestar al ratón) */
:focus:not(:focus-visible) { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent, #818cf8);
  outline-offset: 2px;
}

/* Entrada suave de modales y menús */
@keyframes polishIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.modal:not(.hidden) {
  animation: polishIn .25s cubic-bezier(.2, .8, .2, 1) both;
}
.modal-overlay:not(.hidden) {
  animation: polishFade .2s ease both;
}
@keyframes polishFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Tarjetas de apps: elevación al pasar el cursor */
.app-card, .gallery-card, .card-app, .app-item {
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
@media (hover: hover) {
  .app-card:hover, .gallery-card:hover, .card-app:hover, .app-item:hover {
    transform: translateY(-2px);
  }
}

/* Movimiento reducido: respeta la preferencia del sistema */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Botón "Crear" de la barra de escribir: el agente solo construye cuando está activo */
.agent-build-toggle {
  display: inline-flex; align-items: center; gap: 4px;
  height: 28px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--border, rgba(255, 255, 255, .12));
  background: transparent; color: var(--text-secondary, #9aa3b8);
  font: inherit; font-size: 12px; cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
}
.agent-build-toggle:hover { color: var(--text-primary, #e5e7eb); }
.agent-build-toggle.on {
  color: var(--accent, #818cf8);
  border-color: var(--accent, #818cf8);
  background: rgba(129, 140, 248, .12);
}

/* ---------- Barra de GitHub del agente ---------- */
.agent-gh-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 8px auto 0; max-width: 100%; padding: 8px 12px; border-radius: 12px;
  border: 1px solid var(--border, rgba(255, 255, 255, .1));
  background: var(--panel-solid, #14141a); font-size: 12px; color: var(--text-secondary, #9aa3b8);
}
.agent-gh-bar.hidden { display: none; }
.gh-ico { font-size: 16px; color: var(--accent, #818cf8); }
.gh-repo { color: var(--text-primary, #e5e7eb); font-weight: 600; }
.gh-sep { opacity: .4; }
.gh-stats { margin-left: auto; }
.gh-stats .add, .chg-n .add { color: #34d399; font-weight: 600; }
.gh-stats .del, .chg-n .del { color: #f87171; font-weight: 600; }
.gh-btn {
  display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 10px;
  border-radius: 8px; border: 1px solid var(--accent, #818cf8); background: rgba(129, 140, 248, .12);
  color: var(--accent, #818cf8); font: inherit; font-size: 12px; cursor: pointer;
}
.gh-btn .material-symbols-outlined { font-size: 14px; }
.gh-btn.ghost { border-color: transparent; background: transparent; color: var(--text-secondary, #9aa3b8); }

/* ---------- Panel lateral del agente ---------- */
.agent-side-panel {
  position: fixed; top: 72px; bottom: 16px; left: 236px; width: 340px; z-index: 900;
  display: flex; flex-direction: column; border-radius: 16px; overflow: hidden;
  border: 1px solid var(--border, rgba(255, 255, 255, .1));
  background: var(--panel-solid, #14141a); box-shadow: 0 20px 50px rgba(0, 0, 0, .45);
}
.agent-side-panel.hidden { display: none; }
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; font-weight: 600; color: var(--text-primary, #e5e7eb);
  border-bottom: 1px solid var(--border, rgba(255, 255, 255, .08));
}
.side-body { padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.side-sub { font-size: 12px; color: var(--text-secondary, #9aa3b8); }
.side-empty { font-size: 13px; color: var(--text-secondary, #9aa3b8); padding: 12px 4px; }
.side-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border, rgba(255, 255, 255, .06)); background: transparent;
  color: var(--text-primary, #e5e7eb); font: inherit; font-size: 13px; text-align: left; width: 100%;
}
button.side-row { cursor: pointer; }
button.side-row:hover { background: rgba(255, 255, 255, .04); }
.side-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-tag { font-size: 11px; color: var(--text-secondary, #9aa3b8); }
.side-tag.ok { color: #34d399; }
.side-action {
  height: 34px; border-radius: 10px; border: 1px solid var(--accent, #818cf8);
  background: rgba(129, 140, 248, .12); color: var(--accent, #818cf8); font: inherit; font-size: 13px; cursor: pointer;
}
.side-action.ghost { border-color: var(--border, rgba(255, 255, 255, .12)); background: transparent; color: var(--text-secondary, #9aa3b8); }
.chg-row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center;
  padding: 8px 10px; border-radius: 8px; font-size: 12px;
  border: 1px solid var(--border, rgba(255, 255, 255, .06));
}
.chg-status { font-size: 10px; text-transform: uppercase; padding: 2px 6px; border-radius: 6px; background: rgba(255, 255, 255, .06); }
.chg-status.added { color: #34d399; }
.chg-status.removed { color: #f87171; }
.chg-status.modified { color: #fbbf24; }
.chg-path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-primary, #e5e7eb); }
@media (max-width: 720px) { .agent-side-panel { left: 8px; right: 8px; width: auto; top: 64px; } }

/* Botón TV dentro de la pantalla del agente (esquina superior derecha) */
#view-agent { position: relative; }
.agent-tv-btn {
  position: absolute; top: 14px; right: 16px; z-index: 60;
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  border: 1px solid var(--border, rgba(255, 255, 255, .12)); background: var(--panel-solid, #14141a);
  color: var(--text-secondary, #9aa3b8); cursor: pointer; transition: color .2s, border-color .2s;
}
.agent-tv-btn:hover { color: var(--text-primary, #e5e7eb); }
.agent-tv-btn.on { color: var(--accent, #818cf8); border-color: var(--accent, #818cf8); }

/* ---------- Columna derecha del agente (Cambios del agente + Conexiones) ---------- */
.agent-right-rail {
  position: absolute; top: 0; right: 0; bottom: 0; width: 300px; z-index: 55;
  display: flex; flex-direction: column; gap: 4px; overflow-y: auto;
  padding: 12px; box-sizing: border-box;
  background: var(--panel-solid, #14141a);
  border-left: 1px solid var(--border, rgba(255, 255, 255, .08));
}
.agent-right-rail.hidden { display: none; }
.rail-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-secondary, #9aa3b8); padding: 4px 2px 10px;
}
.rail-toggle {
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 13px;
  border: 1px solid var(--border, rgba(255, 255, 255, .12)); background: transparent;
  color: var(--text-secondary, #9aa3b8);
}
.rail-toggle:hover { color: var(--text-primary, #e5e7eb); }
.rail-sec { display: flex; flex-direction: column; gap: 8px; padding: 8px 0 14px; border-top: 1px solid var(--border, rgba(255, 255, 255, .06)); }
.rail-title { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-primary, #e5e7eb); }
.rail-title .material-symbols-outlined { font-size: 16px; color: var(--accent, #818cf8); }
.rail-body { display: flex; flex-direction: column; gap: 6px; }
.agent-rail-show {
  position: absolute; top: 14px; right: 60px; z-index: 60; height: 36px; padding: 0 10px; border-radius: 10px;
  border: 1px solid var(--border, rgba(255, 255, 255, .12)); background: var(--panel-solid, #14141a);
  color: var(--text-secondary, #9aa3b8); font: inherit; font-size: 13px; cursor: pointer;
}
.agent-rail-show.hidden { display: none; }
.agent-fluid-container.rail-open { margin-right: 300px; }
@media (max-width: 720px) {
  .agent-right-rail { width: 88vw; }
  .agent-fluid-container.rail-open { margin-right: 0; }
}

/* Botón TV: la vista previa aparece cuando se activa, con o sin proyecto */
.agent-fluid-container.tv-on .agent-right-zone { display: flex !important; }

/* Con la columna abierta, el botón TV se corre para no tapar >> */
#view-agent:has(.agent-right-rail:not(.hidden)) .agent-tv-btn { right: 316px; }

/* ---------- Menú lateral: esquinas redondeadas y animación de abrir/ocultar ---------- */
.sidebar {
  border-radius: 28px;
  transition:
    width .5s cubic-bezier(.2, .8, .2, 1),
    box-shadow .4s ease,
    opacity .3s ease;
}
.sidebar .nav-btn,
.sidebar .new-prompt-btn {
  border-radius: 14px;
  transition: background .2s ease, color .2s ease, transform .25s cubic-bezier(.2, .8, .2, 1);
}
.sidebar .nav-text,
.sidebar .logo-text,
.sidebar .nav-label {
  transition: opacity .25s ease, transform .35s cubic-bezier(.2, .8, .2, 1);
}
.sidebar.collapsed .nav-text,
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-label {
  opacity: 0;
  transform: translateX(-8px);
  pointer-events: none;
}
.sidebar:not(.collapsed) .nav-text,
.sidebar:not(.collapsed) .logo-text {
  animation: sbLabelIn .35s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes sbLabelIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .sidebar .nav-text, .sidebar .logo-text, .sidebar .nav-label { transition: none !important; animation: none !important; }
}

/* ---------- Barra de escribir: centrada en "inicio"; abajo se alinea a la derecha y se acorta ---------- */
.state-chat .mega-input-wrapper {
  width: min(600px, 100%) !important;
  margin-left: auto !important;
  margin-right: 0 !important;
  transition: width .5s cubic-bezier(.2, .8, .2, 1), margin .5s cubic-bezier(.2, .8, .2, 1);
}
@media (max-width: 720px) {
  .state-chat .mega-input-wrapper { width: 100% !important; margin-left: 0 !important; }
}

/* ---------- Crear (build) se ve como el chat centrado; la vista previa solo aparece con el TV ---------- */
.state-build { justify-content: center; }
.state-build .agent-left-zone {
  width: 100%; max-width: 840px; margin: 0 auto; gap: 22px;
}
.state-build .agent-right-zone { display: none; }


/* ---------- TV abierto: el chat se corre a la izquierda y la vista previa ocupa la derecha ---------- */
.agent-fluid-container.tv-on {
  justify-content: flex-start;
  gap: 18px;
  padding: 24px;
}
.agent-fluid-container.tv-on .agent-left-zone {
  flex: 0 0 min(840px, 50%);
  width: min(840px, 50%);
  max-width: none;
  min-width: 0;
  margin: 0;
}
.agent-fluid-container.tv-on .agent-right-zone {
  display: flex !important;
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
}
@media (max-width: 720px) {
  .agent-fluid-container.tv-on { padding: 12px; }
  .agent-fluid-container.tv-on .agent-left-zone { flex: 1 1 auto; width: 100%; }
  .agent-fluid-container.tv-on .agent-right-zone { display: none !important; }
}

/* ---------- Chat: barra de escribir y barra de GitHub con el mismo ancho que el historial ---------- */
.state-chat .mega-input-wrapper,
.state-chat .agent-gh-bar {
  width: min(780px, 100%) !important;
  max-width: 100%;
  margin-left: auto !important;
  margin-right: auto !important;
}


/* ---------- Menú, TV o panel abiertos: la barra se achica y los mensajes se mueven ---------- */
.state-chat .mega-input-wrapper,
.state-chat .agent-gh-bar {
  transition: width .5s cubic-bezier(.2, .8, .2, 1), margin .5s cubic-bezier(.2, .8, .2, 1), padding .5s cubic-bezier(.2, .8, .2, 1);
}
body:has(#main-sidebar:not(.collapsed)) #agent-fluid-container.state-chat {
  padding-left: 224px;
}
body:has(#main-sidebar:not(.collapsed)) .state-chat .mega-input-wrapper,
.state-chat.rail-open .mega-input-wrapper {
  width: min(560px, 100%) !important;
}
@media (max-width: 720px) {
  body:has(#main-sidebar:not(.collapsed)) #agent-fluid-container.state-chat { padding-left: 40px; }
  body:has(#main-sidebar:not(.collapsed)) .state-chat .mega-input-wrapper,
  .state-chat.rail-open .mega-input-wrapper { width: 100% !important; }
}

/* Crear igual que chat: mensajes y barra en el mismo lugar; solo paneles y TV cambian el espacio */
.state-build { padding: 32px 40px; }
.state-build .agent-left-zone { max-width: 840px; margin: 0 auto; }
.state-build .mega-input-wrapper,
.state-build .agent-gh-bar {
  width: min(780px, 100%) !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

/* ---------- Categorías de animación (v2): menú, mensajes y vistas ---------- */

/* Cambio de vista: la sección que se muestra aparece con un desvanecido suave */
@keyframes yzgViewIn { from { opacity: 0; } to { opacity: 1; } }
html:not(.yzg-no-anim-views) .view:not(.hidden) {
  animation: yzgViewIn .3s ease backwards;
}

/* Mensajes del chat: se puede apagar la entrada de cada mensaje */
html.yzg-no-anim-messages .agent-view .msg-group {
  animation: none !important;
}

/* Menú lateral: se puede apagar la animación de abrir y cerrar */
html.yzg-no-anim-sidebar .sidebar,
html.yzg-no-anim-sidebar .sidebar * {
  transition: none !important;
  animation: none !important;
}

/* ---------- Categorías de animación (v3): barra, avisos e iconos ---------- */

/* Barra de escribir: sube al aparecer y se ilumina al escribir */
@keyframes yzgRise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
html:not(.yzg-no-anim-input) .mega-input-wrapper {
  animation: yzgRise .45s cubic-bezier(.2, .8, .2, 1) backwards;
}
html:not(.yzg-no-anim-input) .mega-input-box {
  transition: box-shadow .3s ease, border-color .3s ease;
}
html:not(.yzg-no-anim-input) .mega-input-box:focus-within {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #818cf8) 28%, transparent);
}

/* Avisos: suben desde abajo y se desvanecen (showToast añade la clase yzg-toast) */
@keyframes yzgToastIn { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }
html:not(.yzg-no-anim-toasts) .yzg-toast {
  animation: yzgToastIn .3s cubic-bezier(.2, .8, .2, 1) both;
}

/* Iconos del menú: crecen al pasar el cursor */
html:not(.yzg-no-anim-icons) .sidebar .nav-btn .material-symbols-outlined {
  transition: transform .2s cubic-bezier(.2, .8, .2, 1);
}
html:not(.yzg-no-anim-icons) .sidebar .nav-btn:hover .material-symbols-outlined {
  transform: scale(1.12);
}
