/* Estilos para el contenedor principal de la animación SVG */
#animacionessvg {
    display: none; /* Oculto por defecto, gestionado por JavaScript */
}

/* Estilo para el toast de notificaciones */
#toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 500;
    color: white;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s, top 0.3s;
    background-color: #ef4444; /* Color por defecto para errores (bg-red-500) */
}

#toast.show {
    top: 40px;
    opacity: 1;
    visibility: visible;
}

/* Menú contextual para Keyframes */
#keyframe-menu {
    position: absolute;
    display: none;
    background-color: white;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 8px;
    z-index: 1001;
    width: 150px;
}

#keyframe-menu > div {
    display: flex;
    flex-direction: column;
    gap: 8px; /* space-y-2 */
}

#keyframe-menu label {
    font-size: 14px; /* text-sm */
    font-weight: 500; /* font-medium */
    color: #374151; /* text-gray-700 */
}

#keyframe-menu select {
    margin-top: 4px; /* mt-1 */
    display: block;
    width: 100%;
    padding-left: 12px; /* pl-3 */
    padding-right: 40px; /* pr-10 */
    padding-top: 8px; /* py-2 */
    padding-bottom: 8px; /* py-2 */
    font-size: 16px; /* text-base */
    border: 1px solid #d1d5db; /* border-gray-300 */
    border-radius: 6px; /* rounded-md */
}

#keyframe-menu select:focus {
    outline: none;
    border-color: #4f46e5; /* focus:border-indigo-500 */
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2); /* Anillo de foco */
}


#keyframe-menu button {
    width: 100%;
    background-color: #ef4444; /* bg-red-500 */
    color: white;
    font-size: 14px; /* text-sm */
    font-weight: 700; /* font-bold */
    padding: 8px 16px; /* py-2 px-4 */
    border-radius: 6px; /* rounded-md */
}

#keyframe-menu button:hover {
    background-color: #dc2626; /* hover:bg-red-600 */
}


/* Cabecera */
#animacionessvg header {
    background-color: white;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1); /* shadow-md */
    padding: 12px; /* p-3 */
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 20;
    flex-wrap: wrap;
    gap: 8px; /* gap-2 */
    position: fixed;
    bottom: 43%;
left: 0%;
}

#animacionessvg header h1 {
    font-size: 1.25rem; /* text-xl */
    font-weight: 700; /* font-bold */
    color: #374151; /* text-gray-700 */
}

#animacionessvg header > div {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px; /* gap-2 */
}

/* Botones de la cabecera */
#animacionessvg header button {
    font-weight: 700; /* font-bold */
    padding: 8px 16px; /* py-2 px-4 */
    border-radius: 8px; /* rounded-lg */
    transition: background-color 0.2s;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1); /* shadow */
}

#import-svg-btn { background-color: #f59e0b; color: white; }
#import-svg-btn:hover { background-color: #d97706; }
#import-img-btn { background-color: #f97316; color: white; }
#import-img-btn:hover { background-color: #ea580c; }
#add-rect-btn { background-color: #3b82f6; color: white; }
#add-rect-btn:hover { background-color: #2563eb; }
#add-circle-btn { background-color: #22c55e; color: white; }
#add-circle-btn:hover { background-color: #16a34a; }

/* Contenedor del color picker */
#animacionessvg header .color-picker-container {
    display: flex;
    align-items: center;
    gap: 8px; /* space-x-2 */
}

#animacionessvg header label[for="color-picker"] {
    font-weight: 600; /* font-semibold */
}

#color-picker {
    width: 40px; /* w-10 */
    height: 40px; /* h-10 */
    border-radius: 8px; /* rounded-lg */
    border: 2px solid #d1d5db; /* border-2 border-gray-300 */
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-color: transparent;
    padding: 0;
}
#color-picker::-webkit-color-swatch {
    border-radius: 6px;
    border: none;
}
#color-picker::-moz-color-swatch {
    border-radius: 6px;
    border: none;
}


/* Acciones de selección */
#selection-actions {
    display: none; /* hidden por defecto */
    align-items: center;
    gap: 8px; /* space-x-2 */
}

#selection-actions.flex {
    display: flex;
}

#flip-h-btn, #flip-v-btn {
    background-color: #0ea5e9; /* bg-sky-500 */
    color: white;
    padding: 8px 12px; /* py-2 px-3 */
}
#flip-h-btn:hover, #flip-v-btn:hover {
    background-color: #0284c7; /* hover:bg-sky-600 */
}

#delete-btn {
    background-color: #ef4444; /* bg-red-500 */
}
#delete-btn:hover {
    background-color: #dc2626; /* hover:bg-red-600 */
}


/* Contenido principal */
#animacionessvg main {
    flex-grow: 1;
    display: flex;
    padding: 16px; /* p-4 */
    overflow: hidden;
    gap: 16px; /* gap-4 */
}

/* Panel de capas */
#layer-panel {
    width: 33.333333%; /* w-1/3 */
    background-color: white;
    border-radius: 8px; /* rounded-lg */
    box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.05); /* shadow-inner */
    border: 1px solid #e5e7eb; /* border-gray-200 */
    display: flex;
    flex-direction: column;
    position: fixed;
    bottom: 0%;
    width: 100%;
     height: 46%;
     overflow-y: scroll;
left: 0%;
    }

#layer-panel h2 {
    font-size: 1.125rem; /* text-lg */
    font-weight: 700; /* font-bold */
    padding: 12px; /* p-3 */
    border-bottom: 1px solid #e5e7eb;
    background-color: #f9fafb; /* bg-gray-50 */
    border-top-left-radius: 8px; /* rounded-t-lg */
    border-top-right-radius: 8px;
}

#layer-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 8px; /* p-2 */
    display: flex;
    flex-direction: column;
    gap: 8px; /* space-y-2 */
}

.layer-item {
    padding: 8px; /* p-2 */
    border: 1px solid #d1d5db;
    border-radius: 8px; /* rounded-lg */
    background-color: #f9fafb; /* bg-gray-50 */
    cursor: pointer;
}

.layer-item:hover {
    background-color: #f3f4f6; /* hover:bg-gray-100 */
}

.layer-item.selected {
    background-color: #dbeafe; /* bg-blue-100 */
}

.layer-item > div:first-child {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.layer-item .font-medium { font-weight: 500; }
.layer-item .text-sm { font-size: 14px; }
.layer-item .capitalize { text-transform: capitalize; }
.layer-item .flex { display: flex; }
.layer-item .items-center { align-items: center; }
.layer-item .gap-1 { gap: 4px; }

.layer-item button {
    padding: 4px; /* p-1 */
    border-radius: 4px; /* rounded */
}
.layer-item button:hover {
    background-color: #e5e7eb; /* hover:bg-gray-200 */
}


.timeline-track {
    height: 16px; /* h-4 */
    background-color: #e5e7eb; /* bg-gray-200 */
    margin-top: 8px; /* mt-2 */
    border-radius: 9999px; /* rounded-full */
    position: relative;
}

.keyframe-marker {
    position: absolute;
    width: 12px;
    height: 12px;
    background-color: #f59e0b; /* bg-amber-500 */
    border: 1px solid #d97706; /* border-amber-600 */
    transform: translateX(-50%) rotate(45deg);
    top: 50%;
    margin-top: -6px;
    cursor: pointer;
}


/* Contenedor del Canvas */
#animacionessvg #canvas-container {
    flex-grow: 1;
    background-color: white;
    border-radius: 8px; /* rounded-lg */
    box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.05); /* shadow-inner */
    border: 1px solid #e5e7eb; /* border-gray-200 */
    overflow: hidden;
    height: 48dvh;
    top: 50%;
    
}

#svg-canvas {
    width: 100%;
    height: 100%;
    background-image:
        linear-gradient(45deg, #e9e9e9 25%, transparent 25%),
        linear-gradient(-45deg, #e9e9e9 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e9e9e9 75%),
        linear-gradient(-45deg, transparent 75%, #e9e9e9 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    cursor: default;
}

.selected-shape {
    /* Los estilos de selección se aplican a través de SVG (transform-controls) */
}

/* Controles de transformación SVG */
#transform-controls {
    visibility: hidden;
}

#transform-box-outline {
    fill: none;
    stroke: #0ea5e9; /* stroke-sky-500 */
    stroke-width: 1.5;
}

.handle {
    fill: white;
    stroke: #0ea5e9; /* stroke-sky-500 */
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
}

#rotation-handle { cursor: grab; }
.resize-handle { vector-effect: non-scaling-stroke; }
.resize-handle[data-handle*="top-left"], .resize-handle[data-handle*="bottom-right"] { cursor: nwse-resize; }
.resize-handle[data-handle*="top-right"], .resize-handle[data-handle*="bottom-left"] { cursor: nesw-resize; }
.resize-handle[data-handle*="top-middle"], .resize-handle[data-handle*="bottom-middle"] { cursor: ns-resize; }
.resize-handle[data-handle*="middle-left"], .resize-handle[data-handle*="middle-right"] { cursor: ew-resize; }

#rotation-line {
    stroke: #0ea5e9; /* stroke-sky-500 */
    stroke-width: 1.5;
}


/* Pie de página (Controles de la línea de tiempo) */
#animacionessvg footer {
    background-color: white;
    box-shadow: 0 -2px 5px -1px rgba(0, 0, 0, 0.1), 0 -1px 3px -1px rgba(0, 0, 0, 0.1); /* shadow-up */
    padding: 16px; /* p-4 */
    z-index: 10;
    border-top: 1px solid #e5e7eb;
        position: fixed;
    bottom: 46%;
    right: 0%;
}

#animacionessvg footer > div {
    display: flex;
    align-items: center;
    gap: 24px; /* space-x-6 */
}

#animacionessvg footer .controls-group {
    display: flex;
    align-items: center;
    gap: 12px; /* space-x-3 */
}

#animacionessvg footer #play-btn {
    background-color: #4f46e5; /* bg-indigo-500 */
    width: 96px; /* w-24 */
}
#animacionessvg footer #play-btn:hover { background-color: #4338ca; }
#animacionessvg footer #play-btn.bg-red-500 { background-color: #ef4444; }
#animacionessvg footer #play-btn.bg-red-500:hover { background-color: #dc2626; }


#set-keyframe-btn {
    background-color: #10b981; /* bg-teal-500 */
}
#set-keyframe-btn:hover {
    background-color: #059669; /* hover:bg-teal-600 */
}

#animacionessvg footer .timeline-controls-group {
    flex-grow: 1;
    display: flex;
    align-items: center;
    gap: 12px; /* space-x-3 */
}

#time-label {
    font-family: monospace;
    font-size: 1.125rem; /* text-lg */
    width: 96px; /* w-24 */
    text-align: center;
}

#timeline-slider {
    width: 100%; /* w-full */
    height: 12px; /* h-3 */
    background-color: #e5e7eb; /* bg-gray-200 */
    border-radius: 9999px; /* rounded-lg */
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}
#timeline-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #4f46e5; /* Color del pulgar */
    border-radius: 50%;
    cursor: pointer;
}
#timeline-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #4f46e5;
    border-radius: 50%;
    cursor: pointer;
}


#animacionessvg footer .duration-controls-group {
    display: flex;
    align-items: center;
    gap: 8px; /* space-x-2 */
}
#animacionessvg footer label[for="duration-input"] {
    font-weight: 600; /* font-semibold */
}

#duration-input {
    width: 80px; /* w-20 */
    padding: 8px; /* p-2 */
    border: 1px solid #d1d5db; /* border-gray-300 */
    border-radius: 8px; /* rounded-lg */
    text-align: center;
}

#export-btn3 {
    background-color: #8b5cf6; /* bg-purple-500 */
}
#export-btn3:hover {
    background-color: #7c3aed; /* hover:bg-purple-600 */
}

/* Inputs ocultos */
.hidden {
    display: none;
}



/* AÑADIR ESTO EN animacionessvg.css */

#gestion-escenas-svg {
    position: absolute;
    top: 15px;
    left: 15px;
    z-index: 100;
}

#selector-escena-svg-btn2 {
    padding: 8px 16px;
    background-color: #6d28d9; /* violet-700 */
    color: white;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#selector-escena-svg-btn2:hover {
    background-color: #5b21b6; /* violet-800 */
}

#lista-escenas-svg-popup {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 8px;
    background-color: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    width: 220px;
    padding: 8px;
}

#lista-escenas-svg-popup.hidden {
    display: none;
}

#lista-escenas-svg-popup hr {
    margin: 8px 0;
    border-color: #f3f4f6;
}

#crear-nueva-escena-svg-btn, .escena-svg-item button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 12px;
    border-radius: 6px;
    background: none;
    border: none;
    cursor: pointer;
}

#crear-nueva-escena-svg-btn {
    font-weight: 600;
    color: #16a34a; /* green-600 */
}

#crear-nueva-escena-svg-btn:hover {
    background-color: #f0fdf4; /* green-50 */
}

.escena-svg-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.escena-svg-item button.load-btn {
    flex-grow: 1;
}
.escena-svg-item button:hover {
    background-color: #f3f4f6; /* gray-100 */
}

.escena-svg-item button.delete-scene-btn {
    color: #ef4444; /* red-500 */
    font-weight: bold;
    flex-grow: 0;
    width: 30px;
}
.escena-svg-item button.delete-scene-btn:hover {
    background-color: #fee2e2; /* red-100 */
}


/* Ocultar el editor manual original */
#animacionessvg header,
#animacionessvg aside#layer-panel {
    display: none;
}

/* Estilos para la nueva vista de IA */
#ai-animation-view {
    display: grid;
    grid-template-areas:
        "prompt-panel canvas"
        "footer       canvas";
    grid-template-columns: 350px 1fr;
    grid-template-rows: auto 1fr;
    height: 100%;
    gap: 1rem;
    padding: 1rem;
    box-sizing: border-box;
}

#ai-prompt-panel {
    position: absolute;
    left: 50%; transform: translateX(-50%);
  top: 0%; height: 40%; width: 70%;
    z-index: 1000;
    background-color: var(--color-fondo-panel); /* Usando tus variables de color */
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
 resize: none;
    grid-area: prompt-panel;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 40%;
    padding: 1.5rem;
    background-color: var(--color-fondo-panel); /* Usando tus variables de color */
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

#ai-prompt-panel h3 {
    margin: 0;
    color: var(--color-texto-principal);
}

#ai-prompt-panel p {
    font-size: 0.9em;
    color: var(--color-texto-secundario);
    margin-bottom: 0.5rem;
}

#ai-prompt-input {
    height: 150px;
    resize: vertical;
    width: 100%;
    box-sizing: border-box;
}

#ai-generate-button {
    padding: 12px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    border: none;
    border-radius: 8px;
    background-color: #4f46e5; /* Color principal */
    color: white;
    transition: background-color 0.2s;
}

#ai-generate-button:hover {
    background-color: #4338ca;
}

#ai-generate-button:disabled {
    background-color: #999;
    cursor: not-allowed;
}

#canvas-container {
    grid-area: canvas;
    /* Los estilos existentes para el canvas-container deberían funcionar bien */
}

#animacionessvg footer {
    grid-area: footer;
    align-self: end; /* Alinea el footer abajo del todo en su celda */
}

/* Estilos para el contenedor de estado de la IA */
#ai-status-container {
    margin-top: 1rem;
    padding: 1rem;
    background-color: rgba(0,0,0,0.1);
    border-radius: 8px;
    text-align: center;
}

.spinner-carga-modal {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 4px solid #fff;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
    margin: 0 auto 0.5rem auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- ESTILOS PARA EL PANEL DE ESCENAS GENERADAS (Pega esto en tu CSS) --- */

#ai-scenes-panel {
    grid-area: prompt-panel; /* Se ubicará en la misma área de la grid */
    margin-top: 18rem; /* Ajusta este valor si es necesario para separarlo del panel de prompt */
    background-color: var(--color-fondo-panel, #f9fafb);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    max-height: 45vh; /* Altura máxima para que no ocupe toda la pantalla */
    overflow: hidden;
}

#ai-scenes-panel h3 {
    margin: 0 0 1rem 0;
    color: var(--color-texto-principal);
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-borde, #e5e7eb);
}

#ai-scenes-list {
    flex-grow: 1;
    overflow-y: auto; /* Habilita el scroll si la lista es larga */
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.ai-scene-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background-color: var(--color-fondo-secundario, #fff);
    border: 1px solid var(--color-borde, #e5e7eb);
    border-radius: 8px;
    transition: background-color 0.2s;
}

.ai-scene-item.active {
    background-color: #dbeafe; /* Un color para destacar la escena activa */
    border-color: #4f46e5;
}

.ai-scene-item span {
    font-weight: 500;
}

.ai-scene-item .scene-buttons {
    display: flex;
    gap: 0.5rem;
}

.ai-scene-item button {
    padding: 0.3rem 0.6rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    color: white;
    transition: opacity 0.2s;
}

.ai-scene-item button:hover {
    opacity: 0.85;
}

.load-scene-btn {
    background-color: #3b82f6; /* Azul */
}

.delete-scene-btn {
    background-color: #ef4444; /* Rojo */
}

.empty-list-placeholder {
    text-align: center;
    color: #9ca3af;
    padding: 2rem 0;
}