/* Variables CSS para colores y espaciado */
:root {
    --primary-color: #007cba;
    --primary-color-dark: #005a8b;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --success-color-dark: #1e7e34;
    --error-color: #dc3545;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --danger-color-dark: #c82333;
    --light-bg: #f8f9fa;
    --white: #ffffff;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #adb5bd;
    --gray-600: #6c757d;
    --gray-700: #495057;
    --gray-800: #343a40;
    --gray-900: #212529;

    --border-radius: 8px;
    --border-radius-small: 4px;
    --box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --box-shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.15);
    --transition: all 0.3s ease;

    --spacing-xs: 5px;
    --spacing-sm: 10px;
    --spacing-md: 20px;
    --spacing-lg: 30px;
    --spacing-xl: 50px;
}

/* Reset básico */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Estilos base */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--gray-800);
    background-color: var(--light-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: var(--white);
    padding: var(--spacing-md);
    text-align: center;
    box-shadow: var(--box-shadow);
    margin-bottom: var(--spacing-md);
}

.header__title {
    color: var(--primary-color);
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: var(--spacing-xs);
}

.header__subtitle {
    color: var(--gray-500);
    font-size: 1rem;
}

/* Container principal */
.main-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
}

/* Panel de control */
.control-panel {
    background: var(--white);
    padding: var(--spacing-lg);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

.url-section {
    margin-bottom: var(--spacing-md);
}

.url-input-container {
    display: flex;
    gap: var(--spacing-sm);
    align-items: end;
}

.url-input {
    flex: 1;
    font-family: monospace;
    font-size: 14px;
}

/* FIX: Eliminar efectos automáticos que causan cambio de tamaño */
.url-input:valid,
.url-input:invalid {
    /* Mantener tamaño y estilo original */
    padding: 10px;
    margin: 0;
    box-sizing: border-box;
    border-color: var(--gray-300);
    background-color: var(--white);
}

/* Estados personalizados SIN cambio de tamaño */
.url-input--valid {
    border-color: var(--success-color) !important;
    background-color: rgba(40, 167, 69, 0.05) !important;
}

.url-input--invalid {
    border-color: var(--error-color) !important;
    background-color: rgba(220, 53, 69, 0.05) !important;
}

/* Configuración de descarga */
.download-config {
    border-top: 1px solid var(--gray-200);
    padding-top: var(--spacing-md);
}

.config-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: var(--spacing-md);
    align-items: end;
}

.form__group--small {
    margin-bottom: 0;
}

/* Formularios */
.form__group {
    margin-bottom: var(--spacing-md);
}

.form__label {
    display: block;
    margin-bottom: var(--spacing-xs);
    font-weight: 600;
    color: var(--gray-700);
    font-size: 14px;
}

.form__input,
.form__select {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--gray-300);
    border-radius: var(--border-radius-small);
    font-size: 14px;
    /* FIX: Solo transición de colores, NO de tamaño */
    transition: border-color 0.3s ease, background-color 0.3s ease;
    box-sizing: border-box;
}

.form__input:focus,
.form__select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.1);
}

/* Botones */
.button {
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius-small);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    /* FIX: Evitar cambio de tamaño en botones */
    white-space: nowrap;
    min-width: 120px;
}

.button--primary {
    background-color: var(--primary-color);
    color: var(--white);
}

.button--primary:hover:not(:disabled) {
    background-color: var(--primary-color-dark);
}

.button--secondary {
    background-color: var(--secondary-color);
    color: var(--white);
}

.button--secondary:hover:not(:disabled) {
    background-color: var(--gray-700);
}

.button--success {
    background-color: var(--success-color);
    color: var(--white);
}

.button--success:hover:not(:disabled) {
    background-color: var(--success-color-dark);
}

.button--danger {
    background-color: var(--danger-color);
    color: var(--white);
}

.button--danger:hover:not(:disabled) {
    background-color: var(--danger-color-dark);
}

.button--small {
    padding: 6px 12px;
    font-size: 12px;
    min-width: 80px;
}

.button:disabled {
    background-color: var(--gray-400);
    color: var(--gray-600);
    cursor: not-allowed;
}

/* Visor de documento */
.document-viewer {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    overflow: hidden;
}

.viewer-header {
    padding: var(--spacing-md);
    background: var(--gray-100);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
}

.viewer-title {
    color: var(--gray-700);
    font-size: 1.1rem;
    margin: 0;
}

.document-info {
    display: flex;
    gap: var(--spacing-md);
    flex-wrap: wrap;
}

.info-item {
    font-size: 14px;
    color: var(--gray-600);
    background: var(--white);
    padding: 4px 8px;
    border-radius: var(--border-radius-small);
    border: 1px solid var(--gray-300);
}

/* Iframe container */
.iframe-container {
    position: relative;
    height: 600px;
    background: var(--gray-100);
}

.document-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: var(--white);
}

.iframe-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.overlay-content {
    text-align: center;
    color: var(--gray-500);
}

.overlay-icon {
    font-size: 4rem;
    margin-bottom: var(--spacing-md);
}

.overlay-text {
    font-size: 1.1rem;
    margin: 0;
}

/* Progreso de descarga */
.download-progress {
    background: var(--white);
    padding: var(--spacing-lg);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.progress-title {
    color: var(--gray-700);
    font-size: 1.1rem;
    margin: 0;
}

.progress-container {
    margin-bottom: var(--spacing-md);
}

.progress-bar {
    width: 100%;
    height: 24px;
    background-color: var(--gray-200);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: var(--spacing-sm);
}

.progress-bar__fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), #4dabf7);
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 12px;
}

.progress-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.progress-text {
    color: var(--gray-700);
    font-weight: 500;
}

.progress-percentage {
    color: var(--gray-600);
    font-weight: 600;
    font-size: 14px;
}

/* Preview de página actual */
.current-page-preview {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--gray-100);
    border-radius: var(--border-radius-small);
}

.preview-label {
    font-weight: 600;
    color: var(--gray-700);
    font-size: 14px;
}

.preview-canvas {
    width: 80px;
    height: 100px;
    border: 1px solid var(--gray-300);
    border-radius: var(--border-radius-small);
    object-fit: contain;
    background: var(--white);
}

.preview-info {
    font-size: 14px;
    color: var(--gray-600);
    font-weight: 500;
}

/* Mensajes de estado */
.status-message {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    border-radius: var(--border-radius);
    margin-bottom: var(--spacing-md);
}

.status-message--success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.status-message--error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.status-message--warning {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.status-message--info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

.status-icon {
    font-size: 1.2rem;
}

.status-message__text {
    margin: 0;
    font-weight: 500;
    flex: 1;
}

/* Sección de script manual */
.script-section {
    background: var(--white);
    padding: var(--spacing-lg);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    margin-top: var(--spacing-md);
}

.script-container {
    width: 100%;
}

.script-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.script-title {
    color: var(--gray-700);
    font-size: 1.1rem;
    margin: 0;
}

.script-textarea {
    width: 100%;
    min-height: 300px;
    padding: var(--spacing-md);
    border: 2px solid var(--gray-300);
    border-radius: var(--border-radius-small);
    font-family: 'Courier New', Consolas, monospace;
    font-size: 12px;
    line-height: 1.4;
    background-color: #f8f9fa;
    color: var(--gray-800);
    resize: vertical;
    box-sizing: border-box;
}

.script-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.1);
}

.script-instructions {
    margin-top: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--gray-100);
    border-radius: var(--border-radius-small);
    border-left: 4px solid var(--primary-color);
}

.script-instructions p {
    margin: 0 0 var(--spacing-sm) 0;
    color: var(--gray-700);
    font-weight: 600;
}

.script-instructions ol {
    margin: var(--spacing-sm) 0 0 var(--spacing-md);
    color: var(--gray-700);
}

.script-instructions li {
    margin-bottom: var(--spacing-xs);
    line-height: 1.5;
}

/* Footer */
.footer {
    background: var(--white);
    padding: var(--spacing-md);
    text-align: center;
    margin-top: var(--spacing-xl);
    border-top: 1px solid var(--gray-200);
}

.footer__text {
    color: var(--gray-500);
    font-size: 14px;
    margin: 0;
}

/* Utilidades */
.hidden {
    display: none !important;
}

[hidden] {
    display: none !important;
}

/* Responsive design */
@media (max-width: 768px) {
    .header__title {
        font-size: 1.5rem;
    }

    .main-container {
        padding: 0 var(--spacing-sm);
    }

    .control-panel,
    .download-progress,
    .script-section {
        padding: var(--spacing-md);
    }

    .url-input-container {
        flex-direction: column;
        align-items: stretch;
    }

    .config-row {
        grid-template-columns: 1fr;
    }

    .viewer-header {
        flex-direction: column;
        align-items: stretch;
    }

    .document-info {
        justify-content: center;
    }

    .iframe-container {
        height: 400px;
    }

    .current-page-preview {
        flex-direction: column;
        text-align: center;
    }

    .script-header {
        flex-direction: column;
        align-items: stretch;
        gap: var(--spacing-sm);
    }

    .script-textarea {
        font-size: 11px;
        min-height: 250px;
    }
}

/* Animaciones */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from {
        max-height: 0;
        opacity: 0;
    }
    to {
        max-height: 200px;
        opacity: 1;
    }
}

.status-message,
.download-progress,
.download-config,
.script-section {
    animation: fadeIn 0.3s ease;
}

.download-config:not([hidden]) {
    animation: slideDown 0.3s ease;
}

/* Estados de focus mejorados para accesibilidad */
.button:focus,
.form__input:focus,
.form__select:focus,
.script-textarea:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Hover effects */
.control-panel:hover,
.document-viewer:hover,
.download-progress:hover,
.script-section:hover {
    box-shadow: var(--box-shadow-lg);
    transition: var(--transition);
}