/* Importar tipografías de Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&family=Lato:wght@300;400;700&family=Nunito+Sans:wght@300;400;600;700&display=swap');

:root {
    /* Colores Corporativos */
    --primary-color: #00509D;        /* Azul intenso */
    --primary-hover: #003d7a;        /* Azul intenso más oscuro */
    --secondary-color: #30C48D;      /* Verde turquesa */
    --secondary-hover: #28a374;      /* Verde turquesa más oscuro */
    --white-pure: #FFFFFF;           /* Blanco puro */
    --gray-light: #F4F6F8;           /* Gris claro */
    --gray-dark: #333333;            /* Negro grisáceo */
    
    /* Colores de estado */
    --success-color: #30C48D;        /* Verde turquesa para éxito */
    --error-color: #dc2626;          /* Rojo para errores */
    --warning-color: #d97706;        /* Naranja para advertencias */
    
    /* Colores de fondo y superficie */
    --bg-color: #FFFFFF;
    --surface-color: #F4F6F8;
    --text-color: #00509D;
    --text-secondary: #333333;
    --border-color: #e2e8f0;
    
    /* Sombras corporativas */
    --shadow: 0 2px 4px 0 rgba(0, 80, 157, 0.1);
    --shadow-lg: 0 4px 12px 0 rgba(0, 80, 157, 0.15);
    --shadow-button: 0 2px 8px 0 rgba(48, 196, 141, 0.2);
    
    /* Tipografías */
    --font-heading: 'Poppins', sans-serif;
    --font-body: 'Lato', 'Nunito Sans', sans-serif;
    
    /* Bordes redondeados */
    --border-radius: 8px;
    --border-radius-lg: 12px;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --surface-color: #2d2d2d;
    --text-color: #FFFFFF;
    --text-secondary: #F4F6F8;
    --border-color: #404040;
    --shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 12px 0 rgba(0, 0, 0, 0.4);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    font-weight: 400;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #003d7a 100%);
    color: var(--white-pure);
    padding: 30px 0;
    margin-bottom: 30px;
    box-shadow: var(--shadow-lg);
    border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

h1 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 2.5rem;
    color: var(--white-pure);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

h2, h3 {
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 15px;
}

h2 {
    font-size: 1.8rem;
}

h3 {
    font-size: 1.4rem;
}

.theme-toggle {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.2);
}

.input-section {
    background: var(--white-pure);
    padding: 30px;
    border-radius: var(--border-radius-lg);
    margin-bottom: 30px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.input-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--primary-color);
    font-family: var(--font-heading);
    font-size: 0.95rem;
}

input, select {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 16px;
    font-family: var(--font-body);
    background: var(--white-pure);
    color: var(--text-color);
    transition: all 0.3s ease;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(48, 196, 141, 0.1);
    transform: translateY(-1px);
}

.btn-primary, .btn-secondary {
    padding: 14px 28px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 16px;
    font-weight: 600;
    font-family: var(--font-heading);
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    box-shadow: var(--shadow-button);
}

.btn-primary {
    background: linear-gradient(135deg, var(--secondary-color) 0%, #28a374 100%);
    color: var(--white-pure);
    width: 100%;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #28a374 0%, #20875f 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(48, 196, 141, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--white-pure);
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
    box-shadow: var(--shadow);
}

.btn-secondary:hover {
    background: var(--primary-color);
    color: var(--white-pure);
    transform: translateY(-1px);
}

.examples-section {
    margin-bottom: 30px;
    background: var(--surface-color);
    padding: 25px;
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--border-color);
}

.examples-section h3 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.examples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.example-btn {
    padding: 18px;
    background: var(--white-pure);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    color: var(--text-color);
    font-size: 14px;
    font-family: var(--font-body);
    box-shadow: var(--shadow);
}

.example-btn:hover {
    border-color: var(--secondary-color);
    background: linear-gradient(135deg, var(--secondary-color) 0%, #28a374 100%);
    color: var(--white-pure);
    transform: translateY(-2px);
    box-shadow: var(--shadow-button);
}

.results-section {
    margin-bottom: 30px;
}

.result-card, .error-card, .success-card {
    padding: 25px;
    border-radius: var(--border-radius-lg);
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border-left: 4px solid;
}

.result-card {
    background: var(--white-pure);
    border-left-color: var(--primary-color);
    border: 1px solid var(--border-color);
}

.result-card h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
}

.error-card {
    background: linear-gradient(135deg, #fef2f2 0%, #fde8e8 100%);
    border-left-color: var(--error-color);
    color: var(--error-color);
}

[data-theme="dark"] .error-card {
    background: linear-gradient(135deg, #2d1b1b 0%, #3d2020 100%);
    color: #ff6b6b;
}

.success-card {
    background: linear-gradient(135deg, #f0fdf4 0%, #e6ffed 100%);
    border-left-color: var(--success-color);
    color: var(--success-color);
}

[data-theme="dark"] .success-card {
    background: linear-gradient(135deg, #1a2e1a 0%, #2d5a2d 100%);
    color: var(--secondary-color);
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
    color: var(--text-secondary);
    background: var(--surface-color);
    border-radius: var(--border-radius-lg);
    margin: 20px 0;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.history-section {
    background: var(--white-pure);
    padding: 30px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--surface-color);
}

.history-header h3 {
    color: var(--primary-color);
    margin-bottom: 0;
}

.history-controls {
    display: flex;
    gap: 12px;
}

.history-container {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 10px;
}

.history-container::-webkit-scrollbar {
    width: 6px;
}

.history-container::-webkit-scrollbar-track {
    background: var(--surface-color);
    border-radius: 3px;
}

.history-container::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 3px;
}

.history-item {
    padding: 18px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 12px;
    background: var(--surface-color);
    transition: all 0.3s ease;
    border-left: 4px solid var(--secondary-color);
}

.history-item:hover {
    box-shadow: var(--shadow);
    transform: translateY(-1px);
    background: var(--white-pure);
}

.history-expression {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 8px;
    font-family: var(--font-heading);
    font-size: 0.95rem;
}

.history-result {
    color: var(--text-secondary);
    font-size: 14px;
    font-family: var(--font-body);
    line-height: 1.4;
}

.math-result {
    background: var(--surface-color);
    padding: 20px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    margin: 15px 0;
    text-align: center;
    font-size: 1.1rem;
}

/* Contador de progreso de inicialización */
.initialization-progress {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 2rem;
    margin-bottom: 1.5rem;
    text-align: center;
    border: 2px solid var(--primary);
}

.initialization-progress h3 {
    color: var(--primary);
    margin-bottom: 1.5rem;
    font-size: 1.25rem;
}

.progress-container {
    margin-bottom: 2rem;
}

.progress-bar {
    width: 100%;
    height: 12px;
    background: var(--border);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 6px;
    width: 0%;
    transition: width 0.5s ease;
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: shimmer 2s infinite;
}

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

.progress-text {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

#progress-percentage {
    font-weight: 700;
    color: var(--primary);
}

#progress-status {
    color: var(--text-secondary);
    font-style: italic;
}

.progress-steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.progress-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    transition: all 0.3s ease;
}

.progress-step.completed {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    transform: scale(1.05);
}

.progress-step.loading {
    background: linear-gradient(135deg, #f39c12, #e67e22);
    color: white;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.step-icon {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.progress-step span {
    font-size: 0.85rem;
    font-weight: 600;
}

.step-status {
    font-size: 1rem;
}

.progress-step.completed .step-status::before {
    content: '✅';
}

.progress-step.loading .step-status::before {
    content: '⏳';
}

.progress-step.error .step-status::before {
    content: '❌';
}

.btn-secondary:hover {
    background: var(--primary-color);
    color: var(--white-pure);
    transform: translateY(-1px);
}

.examples-section {
    margin-bottom: 30px;
    background: var(--surface-color);
    padding: 25px;
    border-radius: var(--border-radius-lg);
    border: 1px solid var(--border-color);
}

.examples-section h3 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.3rem;
}

.examples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.example-btn {
    padding: 18px;
    background: var(--white-pure);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: left;
    color: var(--text-color);
    font-size: 14px;
    font-family: var(--font-body);
    box-shadow: var(--shadow);
}

.example-btn:hover {
    border-color: var(--secondary-color);
    background: linear-gradient(135deg, var(--secondary-color) 0%, #28a374 100%);
    color: var(--white-pure);
    transform: translateY(-2px);
    box-shadow: var(--shadow-button);
}

.results-section {
    margin-bottom: 30px;
}

.result-card, .error-card, .success-card {
    padding: 25px;
    border-radius: var(--border-radius-lg);
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border-left: 4px solid;
}

.result-card {
    background: var(--white-pure);
    border-left-color: var(--primary-color);
    border: 1px solid var(--border-color);
}

.result-card h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
}

.error-card {
    background: linear-gradient(135deg, #fef2f2 0%, #fde8e8 100%);
    border-left-color: var(--error-color);
    color: var(--error-color);
}

[data-theme="dark"] .error-card {
    background: linear-gradient(135deg, #2d1b1b 0%, #3d2020 100%);
    color: #ff6b6b;
}

.success-card {
    background: linear-gradient(135deg, #f0fdf4 0%, #e6ffed 100%);
    border-left-color: var(--success-color);
    color: var(--success-color);
}

[data-theme="dark"] .success-card {
    background: linear-gradient(135deg, #1a2e1a 0%, #2d5a2d 100%);
    color: var(--secondary-color);
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
    color: var(--text-secondary);
    background: var(--surface-color);
    border-radius: var(--border-radius-lg);
    margin: 20px 0;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.history-section {
    background: var(--white-pure);
    padding: 30px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--surface-color);
}

.history-header h3 {
    color: var(--primary-color);
    margin-bottom: 0;
}

.history-controls {
    display: flex;
    gap: 12px;
}

.history-container {
    max-height: 400px;
    overflow-y: auto;
    padding-right: 10px;
}

.history-container::-webkit-scrollbar {
    width: 6px;
}

.history-container::-webkit-scrollbar-track {
    background: var(--surface-color);
    border-radius: 3px;
}

.history-container::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 3px;
}

.history-item {
    padding: 18px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 12px;
    background: var(--surface-color);
    transition: all 0.3s ease;
    border-left: 4px solid var(--secondary-color);
}

.history-item:hover {
    box-shadow: var(--shadow);
    transform: translateY(-1px);
    background: var(--white-pure);
}

.history-expression {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 8px;
    font-family: var(--font-heading);
    font-size: 0.95rem;
}

.history-result {
    color: var(--text-secondary);
    font-size: 14px;
    font-family: var(--font-body);
    line-height: 1.4;
}

.math-result {
    background: var(--surface-color);
    padding: 20px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    margin: 15px 0;
    text-align: center;
    font-size: 1.1rem;
}

/* Estilos para MathJax */
.MathJax {
    color: var(--primary-color) !important;
}

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

.result-card, .error-card, .success-card {
    animation: fadeIn 0.3s ease-out;
}

/* Estilos para botones de operación */
.operation-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 8px;
}

.operation-btn {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    padding: 16px 20px;
    background: var(--white-pure);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}

.operation-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(48, 196, 141, 0.1), transparent);
    transition: left 0.5s ease;
}

.operation-btn:hover::before {
    left: 100%;
}

.operation-btn:hover {
    border-color: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(48, 196, 141, 0.2);
    background: linear-gradient(135deg, rgba(48, 196, 141, 0.05) 0%, rgba(0, 80, 157, 0.05) 100%);
}

.operation-btn.active {
    background: linear-gradient(135deg, var(--secondary-color) 0%, #28a374 100%);
    border-color: var(--secondary-color);
    color: var(--white-pure);
    box-shadow: 0 4px 16px rgba(48, 196, 141, 0.3);
    transform: translateY(-1px);
}

.operation-btn.active:hover {
    background: linear-gradient(135deg, #28a374 0%, #20875f 100%);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(48, 196, 141, 0.4);
}

.op-icon {
    font-size: 18px;
    min-width: 20px;
    text-align: center;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

.operation-btn.active .op-icon {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.op-text {
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* Responsive para botones de operación */
@media (max-width: 768px) {
    .operation-buttons {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .operation-btn {
        padding: 14px 16px;
        font-size: 13px;
    }
    
    .op-icon {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .operation-buttons {
        grid-template-columns: 1fr;
    }
}

/* Tema oscuro para botones de operación */
[data-theme="dark"] .operation-btn {
    background: var(--surface-color);
    border-color: #404040;
    color: var(--text-color);
}

[data-theme="dark"] .operation-btn:hover {
    background: linear-gradient(135deg, rgba(48, 196, 141, 0.1) 0%, rgba(0, 80, 157, 0.1) 100%);
    border-color: var(--secondary-color);
}

[data-theme="dark"] .operation-btn.active {
    background: linear-gradient(135deg, var(--secondary-color) 0%, #28a374 100%);
    color: var(--white-pure);
}

@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .header-content {
        flex-direction: column;
        gap: 20px;
        text-align: center;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .examples-grid {
        grid-template-columns: 1fr;
    }
    
    .history-header {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
    }
    
    .history-controls {
        justify-content: center;
    }
    
    .btn-primary, .btn-secondary {
        padding: 12px 20px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .input-section, .history-section {
        padding: 20px;
    }
    
    h1 {
        font-size: 1.8rem;
    }
    
    .examples-section {
        padding: 20px;
    }
}

/* Estados de focus mejorados para accesibilidad */
button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

/* Mejoras de contraste para modo oscuro */
[data-theme="dark"] .math-result {
    background: var(--gray-dark);
    border-color: #555;
}

[data-theme="dark"] .history-item {
    background: var(--gray-dark);
    border-color: #555;
}

[data-theme="dark"] .history-item:hover {
    background: #404040;
}