/* ============================================
   ESTILOS GENERALES
   ============================================ */

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

body {
    font-family: Arial, sans-serif;
    padding: 20px;
    background: #f5f5f5;
}

/* ============================================
   CONTENEDOR PRINCIPAL
   ============================================ */

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

h1 {
    color: #333;
    margin-bottom: 20px;
    text-align: center;
}

/* ============================================
   LAYOUT
   ============================================ */

.layout {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 30px;
}

.panel {
    background: #fafafa;
    padding: 20px;
    border-radius: 8px;
}

.panel h2 {
    font-size: 18px;
    margin-bottom: 15px;
    color: #555;
}

/* ============================================
   SERIES DE DATOS
   ============================================ */

.serie-section {
    background: white;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 5px;
    border: 2px solid #ddd;
}

.serie-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.serie-name {
    font-weight: bold;
    color: #333;
}

.btn-remove-serie {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.btn-remove-serie:hover {
    background: #c0392b;
}

/* ============================================
   TABLAS
   ============================================ */

table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
}

th,
td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: center;
}

th {
    background: #3498db;
    color: white;
}

/* ============================================
   INPUTS
   ============================================ */

input[type="number"] {
    width: 100%;
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 3px;
}

.color-input {
    width: 50px;
    height: 30px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}

select {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
}

/* ============================================
   BOTONES
   ============================================ */

.btn {
    padding: 8px 15px;
    margin: 5px 5px 5px 0;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-success {
    background: #27ae60;
    color: white;
}

.btn-success:hover {
    background: #229954;
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
}

.help-btn {
    background: #3498db;
    color: white;
    border: none;
    width: 25px;
    height: 25px;
    border-radius: 50%;
    cursor: pointer;
    font-weight: bold;
    margin-left: 10px;
    font-size: 14px;
}

.help-btn:hover {
    background: #2980b9;
}

/* ============================================
   GRÁFICA
   ============================================ */

.chart-container {
    position: relative;
    height: 600px;
}

.controls {
    margin-top: 15px;
}

/* ============================================
   ECUACIONES Y AYUDA
   ============================================ */

.equation-display {
    background: #ecf0f1;
    padding: 10px;
    margin-top: 10px;
    border-radius: 5px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.help-text {
    background: #fff3cd;
    border: 1px solid #ffc107;
    padding: 10px;
    margin-top: 10px;
    border-radius: 5px;
    font-size: 12px;
    display: none;
}

/* ============================================
   SISTEMA DE AYUDA
   ============================================ */

#helpButton {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    transition: all 0.3s ease;
}

#helpButton:hover {
    transform: scale(1.1);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.help-tab.active {
    border-bottom: 3px solid #667eea !important;
    color: #667eea !important;
}

.help-tab:hover {
    background: rgba(102, 126, 234, 0.1);
}

/* ============================================
   RESPONSIVE - DISPOSITIVOS MÓVILES
   ============================================ */

/* ============================================
   RESPONSIVE - DISPOSITIVOS MÓVILES
   ============================================ */

/* Tablet y Móvil (hasta 1024px) */
@media (max-width: 1024px) {

    /* Ajustar padding del body */
    body {
        padding: 10px;
    }

    .container {
        padding: 15px;
    }

    /* Título más pequeño */
    h1 {
        font-size: 18px;
        margin-bottom: 15px;
    }

    /* Header en columna para móvil */
    header {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 10px;
    }

    header h1 {
        font-size: 16px;
        flex: 1;
    }

    /* Mostrar botón hamburguesa en móvil */
    #mobileMenuBtn {
        display: block !important;
    }

    /* Menú del header colapsado por defecto en móvil */
    /* Menú del header estilo "Popover" */
    #headerMenu {
        display: none;
        position: absolute;
        top: 60px;
        right: 10px;
        width: 220px !important;
        flex-direction: column !important;
        gap: 8px !important;
        padding: 15px;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        border-radius: 12px;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
        z-index: 2000;
        border: 1px solid rgba(255, 255, 255, 0.1);
        animation: menuSlideIn 0.2s ease-out;
    }

    @keyframes menuSlideIn {
        from {
            opacity: 0;
            transform: translateY(-10px) scale(0.95);
        }

        to {
            opacity: 1;
            transform: translateY(0) scale(1);
        }
    }

    /* Botones dentro del menú popover */
    #headerMenu .btn,
    #headerMenu button {
        width: 100% !important;
        margin: 0 !important;
        text-align: left;
        display: block;
        background: rgba(255, 255, 255, 0.15) !important;
        color: white !important;
        border: 1px solid rgba(255, 255, 255, 0.2) !important;
        backdrop-filter: blur(5px);
        transition: all 0.2s ease;
    }

    #headerMenu .btn:hover,
    #headerMenu button:hover {
        background: rgba(255, 255, 255, 0.25) !important;
        transform: translateX(5px);
    }

    /* Ajustar el contenedor de herramientas dentro del menú */
    #headerMenu nav {
        width: 100%;
    }



    /* Menú de herramientas posicionado correctamente */
    #toolsMenu {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 15px 15px 0 0 !important;
        max-height: 50vh;
        overflow-y: auto;
        z-index: 2000 !important;
    }

    /* Intro section más compacta */
    .intro-section {
        padding: 15px !important;
    }

    .intro-section h3 {
        font-size: 1em !important;
    }

    .intro-section ul {
        font-size: 13px;
        padding-left: 15px !important;
    }

    .intro-section li {
        margin-bottom: 8px;
    }

    /* Layout en columna única */
    .layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    /* Paneles con menos padding */
    .panel {
        padding: 15px;
    }

    .panel h2 {
        font-size: 16px;
    }

    /* Botones más grandes para táctil */
    .btn {
        padding: 10px 15px;
        font-size: 14px;
        margin: 5px 2px;
    }

    .btn-remove-serie {
        padding: 8px 12px;
        font-size: 14px;
    }

    /* Header de serie en columna */
    .serie-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .serie-header>div {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
        width: 100%;
    }

    /* Tablas con scroll horizontal */
    .serie-section table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    /* Inputs de tabla más grandes */
    input[type="number"] {
        min-width: 60px;
        font-size: 16px;
        /* Evita zoom en iOS */
    }

    /* Gráfica más pequeña en móvil */
    .chart-container {
        height: 350px;
    }

    /* Controles en columna */
    .controls {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .controls input[type="text"],
    .controls input[type="number"] {
        width: 100% !important;
        font-size: 16px;
    }

    .controls label {
        display: block;
        margin-bottom: 5px;
    }

    /* Panel de configuración */
    #config-panel-content>div {
        grid-template-columns: 1fr !important;
    }

    /* Config section colapsable */
    .config-section {
        padding: 10px !important;
    }

    .config-section summary {
        font-size: 14px;
    }

    /* Footer más compacto */
    footer {
        font-size: 12px;
    }

    footer p {
        margin: 8px 0 !important;
    }

    /* Select más grande */
    select {
        font-size: 16px;
        padding: 10px;
    }

    /* Color input más grande */
    .color-input {
        width: 60px;
        height: 40px;
    }

    /* Modales ajustados para móvil */
    #helpModal>div,
    #errorPropagationModal>div,
    #dimensionalAnalysisModal>div {
        width: 95% !important;
        max-width: 95% !important;
        margin: 10px auto !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }

    /* Tabs de ayuda en scroll horizontal */
    #helpModal>div>div:first-of-type {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 5px;
        padding-bottom: 5px;
    }

    .help-tab {
        flex-shrink: 0;
        font-size: 12px !important;
        padding: 8px 12px !important;
    }

    /* Botón de ayuda flotante */
    #helpButton {
        width: 45px !important;
        height: 45px !important;
        font-size: 20px !important;
        bottom: 15px !important;
        right: 15px !important;
    }
}

/* Para pantallas muy pequeñas (< 480px) */
@media (max-width: 480px) {
    h1 {
        font-size: 14px;
    }

    header h1 {
        font-size: 14px !important;
    }

    .container {
        padding: 8px;
    }

    /* Botones del header en una columna */
    header>div {
        grid-template-columns: 1fr !important;
    }

    .btn {
        font-size: 12px;
        padding: 8px 10px;
    }

    .chart-container {
        height: 280px;
    }

    /* Intro section aún más compacta */
    .intro-section {
        padding: 10px !important;
    }

    .intro-section h3 {
        font-size: 0.9em !important;
    }

    .intro-section ul {
        font-size: 12px;
    }

    /* Ecuaciones con texto más pequeño */
    .equation-display {
        font-size: 10px;
        padding: 8px;
    }

    /* Tabla de datos más compacta */
    th,
    td {
        padding: 5px;
        font-size: 12px;
    }

    input[type="number"] {
        min-width: 50px;
        padding: 4px;
    }
}

/* Cursor para gráfica con pan habilitado */
#myChart {
    cursor: grab;
}

#myChart:active {
    cursor: grabbing;
}

/* ============================================
   DESKTOP OVERRIDES (Fix for layout regression)
   ============================================ */
@media (min-width: 1025px) {

    /* Restore 2-column layout */
    .layout {
        grid-template-columns: 400px 1fr !important;
        gap: 30px !important;
    }

    /* Reset header menu to normal flow */
    #headerMenu {
        display: flex !important;
        position: static !important;
        width: auto !important;
        flex-direction: row !important;
        background: transparent !important;
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        gap: 10px !important;
        margin-top: 0 !important;
        border-top: none !important;
        animation: none !important;
    }

    /* Reset buttons in header */
    #headerMenu .btn,
    #headerMenu button {
        width: auto !important;
        margin: 0 5px !important;
        text-align: center !important;
        border: none !important;
        display: inline-block !important;
        backdrop-filter: none !important;
        color: white !important;
    }

    /* Restore specific button colors */
    /* Herramientas */
    #headerMenu nav button {
        background-color: #6c5ce7 !important;
    }

    #headerMenu nav button:hover {
        background-color: #5a4ad1 !important;
    }

    /* Guardar */
    #headerMenu .btn-primary {
        background-color: #3498db !important;
    }

    #headerMenu .btn-primary:hover {
        background-color: #2980b9 !important;
    }

    /* Cargar */
    #headerMenu .btn-success {
        background-color: #27ae60 !important;
    }

    #headerMenu .btn-success:hover {
        background-color: #229954 !important;
    }

    /* Presentar */
    #headerMenu button[onclick*="togglePresentationMode"] {
        background-color: #9b59b6 !important;
    }

    #headerMenu button[onclick*="togglePresentationMode"]:hover {
        background-color: #8e44ad !important;
    }

    /* Compartir */
    #headerMenu button[onclick*="copyShareURL"] {
        background-color: #3498db !important;
    }

    #headerMenu button[onclick*="copyShareURL"]:hover {
        background-color: #2980b9 !important;
    }

    /* Hover effects generic */
    #headerMenu .btn:hover,
    #headerMenu button:hover {
        transform: scale(1.05) !important;
    }
}