/**
 * Webzi Studio - Estilos principales
 * ===================================
 * Arquitectura: BEM + Custom Properties
 * Mobile-first responsive
 */

/* =========================================
   CSS RESET & BASE
   ========================================= */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background-color: var(--studio-bg);
    color: var(--studio-text);
    line-height: 1.5;
    min-height: 100vh;
    overflow: hidden;
}

/* =========================================
   CSS CUSTOM PROPERTIES (Variables)
   ========================================= */
:root {
    /* Marca Webzi Studio */
    --studio-primary: #5b21b6;
    --studio-primary-hover: #4c1d95;
    --studio-accent: #7c3aed;
    --studio-accent-hover: #6d28d9;

    /* Fondos */
    --studio-bg: #0f0f13;
    --studio-surface: #1a1a24;
    --studio-surface-hover: #242432;
    --studio-surface-elevated: #22222e;

    /* Bordes */
    --studio-border: rgba(255, 255, 255, 0.08);
    --studio-border-strong: rgba(255, 255, 255, 0.15);

    /* Texto */
    --studio-text: #e8e8f0;
    --studio-text-muted: #9090a8;
    --studio-text-dim: #6b6b80;

    /* Estados */
    --studio-success: #22c55e;
    --studio-warning: #f59e0b;
    --studio-error: #ef4444;

    /* Layout */
    --header-height: 56px;
    --preview-width: 60%;
    --chat-width: 40%;
    --chat-min-width: 320px;
    --chat-max-width: 480px;

    /* Tipografia */
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Espaciado */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Bordes redondeados */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Transiciones */
    --transition-fast: 0.15s ease;
    --transition: 0.25s ease;
    --transition-slow: 0.4s ease;

    /* Sombras */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* =========================================
   LAYOUT PRINCIPAL
   ========================================= */
.studio {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.studio__main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* =========================================
   HEADER
   ========================================= */
.studio-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 var(--spacing-md);
    background: var(--studio-surface);
    border-bottom: 1px solid var(--studio-border);
    flex-shrink: 0;
}

.studio-logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    text-decoration: none;
    color: var(--studio-text);
}

.studio-logo__icon {
    width: 32px;
    height: 32px;
}

.studio-logo__text {
    font-size: 1.125rem;
    font-weight: 500;
    letter-spacing: -0.02em;
}

.studio-logo__text strong {
    color: var(--studio-accent);
    font-weight: 600;
}

.studio-header__actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

/* =========================================
   BOTONES
   ========================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn--primary {
    background: var(--studio-accent);
    color: white;
}

.btn--primary:hover:not(:disabled) {
    background: var(--studio-accent-hover);
}

.btn--secondary {
    background: var(--studio-surface-hover);
    color: var(--studio-text);
}

.btn--secondary:hover:not(:disabled) {
    background: var(--studio-border-strong);
}

.btn--ghost {
    background: transparent;
    color: var(--studio-text-muted);
}

.btn--ghost:hover:not(:disabled) {
    background: var(--studio-surface-hover);
    color: var(--studio-text);
}

.btn--icon {
    padding: var(--spacing-sm);
    width: 36px;
    height: 36px;
}

.btn--publish {
    background: linear-gradient(135deg, var(--studio-accent), var(--studio-primary));
    color: white;
    padding: var(--spacing-sm) var(--spacing-lg);
}

.btn--publish:hover:not(:disabled) {
    filter: brightness(1.1);
}

.btn--publish.is-loading {
    pointer-events: none;
}

.btn--publish.is-success {
    background: var(--studio-success);
}

.btn--publish.is-error {
    background: var(--studio-error);
}

/* =========================================
   PANEL DE PREVIEW (Columna izquierda)
   ========================================= */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--studio-bg);
    border-right: 1px solid var(--studio-border);
    overflow: hidden;
    min-width: 0;
}

.preview-panel__content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* Canvas Wireframe (estado inicial) */
.canvas-wireframe {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
    transition: opacity var(--transition-slow);
}

.canvas-wireframe.is-hidden {
    opacity: 0;
    pointer-events: none;
}

.canvas-wireframe__grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(124, 58, 237, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(124, 58, 237, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    opacity: 0.5;
}

.canvas-wireframe__skeleton {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    z-index: 1;
}

.skeleton-block {
    background: var(--studio-surface);
    border-radius: var(--radius-md);
    animation: skeleton-pulse 2s ease-in-out infinite;
}

.skeleton-block--hero {
    height: 180px;
}

.skeleton-block--nav {
    height: 48px;
}

.skeleton-block--section {
    height: 120px;
}

.skeleton-block--cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-sm);
    height: 100px;
}

.skeleton-block--cards > div {
    background: var(--studio-surface-hover);
    border-radius: var(--radius-sm);
}

@keyframes skeleton-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.7; }
}

.canvas-wireframe__label {
    position: absolute;
    bottom: var(--spacing-xl);
    left: 50%;
    transform: translateX(-50%);
    color: var(--studio-text-dim);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.canvas-wireframe__label svg {
    width: 16px;
    height: 16px;
    animation: bounce 1.5s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* Estado: Generando */
.canvas-generating {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
    padding: var(--spacing-xl);
}

.canvas-generating.is-active {
    opacity: 1;
    pointer-events: auto;
}

/* Animación visual de construcción */
.build-animation {
    width: 100%;
    max-width: 280px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: var(--spacing-md);
    background: var(--studio-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--studio-border);
}

.build-section {
    border-radius: var(--radius-sm);
    background: var(--studio-surface-hover);
    transition: all 0.5s ease;
    position: relative;
    overflow: hidden;
}

.build-section::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(168, 85, 247, 0.3), transparent);
    transform: translateX(-100%);
    animation: shimmer 2s infinite;
}

.build-section.is-built {
    background: linear-gradient(135deg, var(--studio-primary), var(--studio-accent));
    box-shadow: 0 0 12px rgba(168, 85, 247, 0.4);
}

.build-section.is-built::after {
    animation: none;
    background: transparent;
}

.build-section--header { height: 24px; }
.build-section--hero { height: 60px; }
.build-section--content { height: 40px; }
.build-section--footer { height: 20px; }

@keyframes shimmer {
    100% { transform: translateX(100%); }
}

/* Info de construcción */
.canvas-generating__info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
    width: 100%;
    max-width: 280px;
}

.canvas-generating__step {
    color: var(--studio-text);
    font-size: 0.9375rem;
    font-weight: 500;
    text-align: center;
    min-height: 24px;
    transition: opacity 0.15s ease;
}

.canvas-generating__progress {
    width: 100%;
    height: 6px;
    background: var(--studio-surface-hover);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.canvas-generating__progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--studio-primary), var(--studio-accent));
    width: 0%;
    transition: width 0.5s ease;
    border-radius: var(--radius-full);
}

.canvas-generating__progress-text {
    color: var(--studio-text-muted);
    font-size: 0.8125rem;
    font-weight: 600;
}

/* iFrame de Preview */
.preview-iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: white;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-slow);
}

.preview-iframe.is-active {
    opacity: 1;
    pointer-events: auto;
}

/* Responsive preview dentro del iframe */
.preview-iframe.is-mobile {
    width: 375px;
    height: 100%;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-lg);
}

.preview-iframe.is-tablet {
    width: 768px;
    height: 100%;
    left: 50%;
    transform: translateX(-50%);
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-lg);
}

/* =========================================
   TOOLBAR DE PREVIEW
   ========================================= */
.preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--studio-surface);
    border-top: 1px solid var(--studio-border);
}

.preview-toolbar__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--studio-text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.preview-toolbar__btn:hover {
    background: var(--studio-surface-hover);
    color: var(--studio-text);
}

.preview-toolbar__btn.is-active {
    background: var(--studio-accent);
    color: white;
}

.preview-toolbar__btn svg {
    width: 20px;
    height: 20px;
}

.preview-toolbar__divider {
    width: 1px;
    height: 24px;
    background: var(--studio-border);
    margin: 0 var(--spacing-sm);
}

/* =========================================
   PANEL DE CHAT (Columna derecha)
   ========================================= */
.chat-panel {
    width: var(--chat-width);
    min-width: var(--chat-min-width);
    max-width: var(--chat-max-width);
    display: flex;
    flex-direction: column;
    background: var(--studio-surface);
    flex-shrink: 0;
}

/* Header del Chat */
.chat-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--studio-border);
}

.chat-header__avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--studio-accent), var(--studio-primary));
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-header__avatar svg {
    width: 24px;
    height: 24px;
    color: white;
}

.chat-header__info {
    flex: 1;
    min-width: 0;
}

.chat-header__title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--studio-text);
}

.chat-header__subtitle {
    font-size: 0.8125rem;
    color: var(--studio-text-muted);
}

/* Mensajes del Chat */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--studio-border-strong);
    border-radius: var(--radius-full);
}

/* Mensaje individual */
.chat-msg {
    display: flex;
    gap: var(--spacing-sm);
    max-width: 90%;
    animation: message-in 0.3s ease;
}

@keyframes message-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-msg--user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg--assistant {
    align-self: flex-start;
}

.chat-msg__avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-md);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-msg--assistant .chat-msg__avatar {
    background: linear-gradient(135deg, var(--studio-accent), var(--studio-primary));
}

.chat-msg--user .chat-msg__avatar {
    background: var(--studio-surface-hover);
}

.chat-msg__avatar svg {
    width: 16px;
    height: 16px;
    color: white;
}

.chat-msg__content {
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-lg);
    font-size: 0.9375rem;
    line-height: 1.5;
}

.chat-msg--assistant .chat-msg__content {
    background: var(--studio-surface-elevated);
    color: var(--studio-text);
    border-bottom-left-radius: var(--radius-sm);
}

.chat-msg--user .chat-msg__content {
    background: var(--studio-accent);
    color: white;
    border-bottom-right-radius: var(--radius-sm);
}

.chat-msg__content p {
    margin-bottom: var(--spacing-sm);
}

.chat-msg__content p:last-child {
    margin-bottom: 0;
}

.chat-msg__content strong {
    font-weight: 600;
}

/* Indicador de escribiendo */
.chat-typing {
    display: none;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    color: var(--studio-text-muted);
    font-size: 0.8125rem;
}

.chat-typing.is-active {
    display: flex;
}

.chat-typing__dots {
    display: flex;
    gap: 4px;
}

.chat-typing__dot {
    width: 6px;
    height: 6px;
    background: var(--studio-text-muted);
    border-radius: 50%;
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.chat-typing__dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-typing__dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Area de Input */
.chat-input-area {
    padding: var(--spacing-md);
    border-top: 1px solid var(--studio-border);
    background: var(--studio-surface);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: var(--spacing-sm);
    background: var(--studio-bg);
    border: 1px solid var(--studio-border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-sm);
    transition: border-color var(--transition-fast);
}

.chat-input-wrapper:focus-within {
    border-color: var(--studio-accent);
}

.chat-input-wrapper.has-files {
    flex-direction: column;
    align-items: stretch;
}

/* Preview de archivos adjuntos */
.chat-files-preview {
    display: none;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--studio-border);
    margin-bottom: var(--spacing-sm);
}

.chat-files-preview.has-files {
    display: flex;
}

.chat-file-thumb {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--studio-surface);
}

.chat-file-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-file-thumb__remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
}

/* Botón de upload */
.chat-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--studio-text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-upload-btn:hover {
    background: var(--studio-surface-hover);
    color: var(--studio-text);
}

.chat-upload-btn svg {
    width: 20px;
    height: 20px;
}

.chat-upload-btn input {
    display: none;
}

/* Botón de upload deshabilitado (hasta que exista un sitio) */
.chat-upload-btn.is-disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.chat-upload-btn.is-disabled:hover {
    background: transparent;
    color: var(--studio-text-muted);
}

/* Textarea */
.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--studio-text);
    font-family: var(--font-body);
    font-size: 0.9375rem;
    line-height: 1.5;
    resize: none;
    min-height: 36px;
    max-height: 150px;
    padding: var(--spacing-sm) 0;
}

.chat-input::placeholder {
    color: var(--studio-text-dim);
}

.chat-input:focus {
    outline: none;
}

/* Botón enviar */
.chat-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--studio-accent);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--studio-accent-hover);
}

.chat-send-btn:disabled {
    background: var(--studio-surface-hover);
    color: var(--studio-text-dim);
    cursor: not-allowed;
}

.chat-send-btn svg {
    width: 18px;
    height: 18px;
}

/* =========================================
   INDICADOR DE CREDITOS
   ========================================= */
.credits-indicator {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--studio-surface-hover);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    color: var(--studio-text-muted);
}

.credits-indicator__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--studio-success);
}

.credits-indicator.is-warning .credits-indicator__dot {
    background: var(--studio-warning);
}

.credits-indicator.is-urgent .credits-indicator__dot {
    background: var(--studio-error);
}

/* =========================================
   MODALES
   ========================================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
}

.modal-overlay.is-active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--studio-surface);
    border-radius: var(--radius-xl);
    padding: var(--spacing-xl);
    max-width: 440px;
    width: 100%;
    transform: scale(0.95);
    transition: transform var(--transition);
}

.modal-overlay.is-active .modal {
    transform: scale(1);
}

.modal__title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    color: var(--studio-text);
}

.modal__text {
    color: var(--studio-text-muted);
    margin-bottom: var(--spacing-lg);
    line-height: 1.6;
}

.modal__actions {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: flex-end;
}

/* =========================================
   RESPONSIVE
   ========================================= */

/* Tablet */
@media (max-width: 1024px) {
    :root {
        --chat-width: 45%;
        --chat-max-width: none;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .studio__main {
        flex-direction: column;
    }

    .preview-panel {
        flex: none;
        height: 40vh;
        min-height: 250px;
        border-right: none;
        border-bottom: 1px solid var(--studio-border);
    }

    .chat-panel {
        width: 100%;
        min-width: auto;
        max-width: none;
        flex: 1;
    }

    .preview-toolbar {
        padding: var(--spacing-xs) var(--spacing-sm);
    }

    .canvas-wireframe__skeleton {
        max-width: 90%;
    }

    .skeleton-block--cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* =========================================
   UTILITIES
   ========================================= */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.hidden {
    display: none !important;
}
