/* =================================================================
   style.css - DISEÑO PROFESIONAL PARA DASHBOARD "TODO EN UNO"
   ================================================================= */

:root {
    --strava-orange: #FC5200;
    --text-dark: #232323;
    --text-medium: #595959;
    --text-light: #8c8c8c;
    --bg-main: #f7f7f7;
    --bg-card: #ffffff;
    --border-color: #e8e8e8;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
    --border-radius-lg: 16px;
    --border-radius-md: 8px;
}

* {
    box-sizing: border-box;
}

body {
    background: linear-gradient(120deg, #fff 0%, #f7f7f7 100%);
    font-family: 'Segoe UI', 'Roboto', Arial, sans-serif;
    color: #222;
    margin: 0;
    padding: 0;
}

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

/* --- LOGIN Y ELEMENTOS GLOBALES --- */
#login-section {
    background: var(--bg-card);
    padding: 3rem 2rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow);
    text-align: center;
    max-width: 550px;
    margin: 5rem auto;
}

#login-section h1 {
    font-size: 2.2rem;
    color: var(--strava-orange);
    margin-bottom: 0.5rem;
}

#login-section p {
    font-size: 1.1rem;
    margin-bottom: 2rem;
}

button {
    background: #fc4c02;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.7em 1.5em;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s;
    margin: 0.2em 0.5em;
}

button:hover {
    background: #d84300;
}

.hidden {
    display: none !important;
}

/* --- LAYOUT DE LA APP --- */
#app-section header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

#app-section header h1 {
    margin: 0;
    font-size: 2.2rem;
    color: var(--text-dark);
}

#logout-button {
    background-color: var(--text-medium);
}

#logout-button:hover {
    background-color: var(--text-dark);
}

main {
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* --- COMPONENTES --- */
.summary-grid,
.charts-grid {
    display: grid;
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.summary-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2rem;
    margin-bottom: 2.5rem;
}

.full-width {
    grid-column: 1 / -1;
}

.card,
.chart-container {
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 4px 18px rgba(252, 76, 2, 0.08), 0 1.5px 4px rgba(0, 0, 0, 0.04);
    padding: 1.7rem 1.2rem 2.2rem 1.2rem;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
    border-top: 4px solid #fc4c02;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    transition: box-shadow 0.2s;
}

.card h3 {
    margin: 0 0 0.25rem 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-light);
    text-transform: uppercase;
}

.card p {
    margin: 0;
    font-size: 2.8rem;
    font-weight: 700;
    color: var(--text-dark);
}

.chart-container:hover {
    box-shadow: 0 8px 32px rgba(252, 76, 2, 0.16), 0 2px 8px rgba(0, 0, 0, 0.07);
}

.chart-container h3 {
    margin-bottom: 1.2rem;
    font-size: 1.18rem;
    font-weight: 700;
    color: #fc4c02;
    letter-spacing: 0.02em;
    text-align: left;
}

.chart-container canvas {
    width: 100% !important;
    max-width: 100%;
    display: block;
    margin: 0 auto;
    background: #fff;
    border-radius: 10px;
    border: 1.5px solid #f5e7e0;
    box-shadow: none;
}

#cal-heatmap {
    margin-top: 1rem;
}

#activity-map {
    height: 340px;
    margin-bottom: 2rem;
    border-radius: 14px;
    overflow: hidden;
    min-width: 200px;
}

/* --- PANTALLA DE CARGA Y RESPONSIVE --- */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(247, 247, 247, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.spinner {
    border: 8px solid #e1e4e8;
    border-top: 8px solid var(--strava-orange);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
}

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

    100% {
        transform: rotate(360deg);
    }
}

@media (max-width: 900px) {
    .charts-grid {
        grid-template-columns: 1fr;
        gap: 1.2rem;
    }
}

@media (max-width: 800px) {
    .charts-grid {
        max-width: 100vw;
        padding: 0 0.2rem;
    }

    .chart-container {
        padding: 1rem 0.2rem;
    }

    .chart-container canvas {
        height: 220px !important;
    }

    .activity-details-col {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    body {
        padding: 1rem;
    }
}

@media (max-width: 700px) {
    .charts-grid {
        grid-template-columns: 1fr;
        gap: 1.2rem;
        padding: 0 0.2rem;
        max-width: 100vw;
    }

    .chart-container {
        padding: 1rem 0.2rem 1.5rem 0.2rem;
    }

    .chart-container canvas {
        height: 180px !important;
    }
}

/* style.css */

/* --- TABLAS Y LISTAS --- */
.df-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.95em;
    margin-top: 1rem;
}

.df-table th,
.df-table td {
    border: 1px solid #ddd;
    padding: 8px 10px;
    text-align: left;
}

.df-table th {
    background: #f8f9fa;
    font-weight: 600;
    color: var(--text-medium);
}

.df-table tr:nth-child(even) {
    background: #fdfdfd;
}


/* --- GEAR SECTION STYLES (VERSIÓN DEFINITIVA) --- */

#gear-cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.edit-mode-toggle {
    width: 100%;
    text-align: right;
    margin-bottom: 1rem;
}

.gear-card {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow);
    padding: 1.2rem 1.5rem;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
    border-top: 4px solid var(--text-light); /* Borde gris por defecto */
}

.gear-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
}

.gear-card.primary {
    border-top-color: var(--strava-orange); /* Naranja si es primario */
}

.gear-card.retired {
    opacity: 0.7;
    background-color: #f8f9fa;
}
.gear-card.retired:hover {
    transform: none;
    box-shadow: var(--shadow);
}

.badge {
    position: absolute;
    top: 12px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: bold;
    text-transform: uppercase;
    color: white;
}
.primary-badge {
    left: 12px;
    background-color: var(--strava-orange);
}
.retired-badge {
    right: 12px;
    background-color: var(--text-medium);
}

.gear-card h4 {
    margin: 0 0 0.25rem 0;
    font-size: 1.15em;
    color: var(--text-dark);
}

.gear-distance { /* Aplicado al <p> */
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--strava-orange);
    margin: 0;
    line-height: 1;
}

.durability-bar {
    width: 100%;
    height: 10px;
    background-color: #e9ecef;
    border-radius: 5px;
    overflow: hidden;
    margin: 1rem 0 0.25rem 0;
}

.durability-progress {
    height: 100%;
    border-radius: 5px;
    transition: width 0.5s ease-out;
}

.gear-card small {
    color: var(--text-light);
    font-size: 0.85rem;
}

.gear-stats {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    width: 100%;
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--text-medium);
}
.gear-stats span {
    flex: 1;
    text-align: center;
}
.gear-stats span:first-child { text-align: left; }
.gear-stats span:last-child { text-align: right; }


.alert-danger {
    color: #721c24;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: var(--border-radius-md);
    padding: 0.75rem 1.25rem;
    margin-top: 1rem;
    width: 100%;
    text-align: center;
    font-weight: bold;
}

.gear-edit-fields {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--border-color);
    width: 100%;
    font-size: 0.9rem;
}
.gear-edit-fields div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}
.gear-edit-fields input {
    width: 80px;
    padding: 5px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}
.gear-edit-fields button.save-gear-btn {
    width: 100%;
    margin-top: 0.5rem;
    background-color: #28a745;
}
.gear-edit-fields button.save-gear-btn:hover {
    background-color: #218838;
}

/* --- ESTILOS DE activity.html (que se habían perdido) --- */
.activity-details-row {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
    flex-wrap: wrap; /* Para que sea responsive */
}

.activity-details-col {
    flex: 1 1 300px; /* Crecerá y se encogerá, con una base de 300px */
    background: #fff;
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.activity-details-col ul {
    list-style: none;
    padding: 0;
    margin: 0;
    line-height: 1.6;
}

.activity-details-col h3 {
    margin-top: 0;
    color: var(--strava-orange);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
}

@media print {
  #export-buttons {
    display: none !important;
  }
}

/* --- Estilos para la calculadora VDOT incrustada --- */

.iframe-responsive-container {
    position: relative;
    overflow: hidden;
    width: 100%;
    /* La altura original es 1600px, la mantenemos aquí */
    /* Puedes ajustar esta altura si lo ves necesario */
    height: 1600px; 
    border: 1px solid #ddd; /* Un borde sutil para enmarcarlo */
    border-radius: 8px;
}

.iframe-responsive-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

#calculator-container p {
    margin-top: -1em;
    margin-bottom: 1.5em;
    font-size: 0.9em;
    color: #666;
}

/* --- Estilos para el Sistema de Pestañas --- */

.tab-nav {
    display: flex;
    border-bottom: 2px solid #ddd;
    margin-bottom: 1.5em;
}

.tab-link {
    padding: 10px 20px;
    cursor: pointer;
    border: none;
    background-color: transparent;
    font-size: 1.1em;
    font-weight: 500;
    color: #555;
    position: relative;
    top: 2px; /* Alinea el borde inferior con el de la barra */
    border-bottom: 2px solid transparent;
}

.tab-link:hover {
    background-color: #f4f4f4;
    color: #000;
}

.tab-link.active {
    color: #FC5200; /* Color naranja de Strava */
    border-bottom-color: #FC5200;
    font-weight: bold;
}

.tab-content {
    display: none; /* Oculta todas las pestañas por defecto */
}

.tab-content.active {
    display: block; /* Muestra solo la pestaña activa */
}

/* --- Estilos para la calculadora VDOT (los mismos que antes) --- */

.iframe-responsive-container {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 1600px; 
    border: 1px solid #ddd;
    border-radius: 8px;
}

.iframe-responsive-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

#calculator-container p {
    margin-top: -1em;
    margin-bottom: 1.5em;
    font-size: 0.9em;
    color: #666;
}

/* --- Estilos para los Controles de Predicción --- */
.prediction-controls {
    background-color: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 1em;
    margin-bottom: 1.5em;
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: flex-end;
}

.prediction-controls fieldset {
    border: none;
    padding: 0;
    margin: 0;
    min-width: 200px;
}

.prediction-controls legend {
    font-weight: bold;
    margin-bottom: 0.5em;
    font-size: 1em;
    color: #333;
}

.prediction-controls .control-group {
    display: flex;
    gap: 1rem;
}

.prediction-controls .control-group.sliders {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.prediction-controls label {
    display: flex;
    align-items: center;
    gap: 0.3em;
    font-size: 0.9em;
}

.prediction-controls input[type="range"] {
    width: 100%;
}

#update-predictions-btn {
    padding: 0.5em 1em;
    background-color: #FC5200;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    margin-left: auto; /* Empuja el botón a la derecha */
}

#update-predictions-btn:hover {
    background-color: #d94700;
}

/* --- Estilos para las Nuevas Secciones de Datos en activity.html --- */
.data-section {
    margin-top: 2.5em;
    padding-top: 1.5em;
    border-top: 1px solid #eee;
}

.data-section h3 {
    margin-bottom: 0.25em;
    font-size: 1.5em;
    color: #333;
}

.data-section p {
    margin-top: 0;
    margin-bottom: 1em;
    font-size: 0.9em;
    color: #666;
}

.table-container {
    max-height: 400px; /* Limita la altura de las tablas largas */
    overflow-y: auto;  /* Añade scroll vertical si es necesario */
    border: 1px solid #ddd;
    border-radius: 5px;
}

/* --- Estilos para la Sección de Clasificación de Carrera --- */
#run-classifier-results {
    display: flex;
    flex-direction: column;
    gap: 0.75em;
}

.classifier-result {
    display: grid;
    grid-template-columns: 150px 1fr 60px; /* Tipo | Barra | Porcentaje */
    align-items: center;
    gap: 1em;
}

.classifier-type {
    font-weight: bold;
    font-size: 1.1em;
    text-align: right;
}

.classifier-bar-container {
    width: 100%;
    background-color: #e5e7eb;
    border-radius: 999px;
    height: 1.25em;
    overflow: hidden;
}

.classifier-bar {
    height: 100%;
    border-radius: 999px;
    transition: width 0.5s ease-in-out;
}

.classifier-score {
    font-weight: bold;
    font-size: 1.1em;
}

/* =================================================================
   NUEVOS ESTILOS PARA LAYOUT FLEXIBLE (Side-by-Side)
   ================================================================= */

.side-by-side-container {
    display: flex;
    flex-wrap: wrap; /* Permite que los elementos se coloquen debajo en pantallas pequeñas */
    gap: 2rem;       /* Espacio entre las columnas */
    align-items: stretch; /* Hace que ambas columnas tengan la misma altura */
    margin-top: 1.5em;
    margin-bottom: 2rem;
}

/* 
  Cada hijo directo del contenedor se convertirá en una columna flexible.
  flex: 1; -> Ocupará el espacio disponible.
  min-width: 300px; -> Ancho mínimo antes de que salte a la siguiente línea.
*/
.side-by-side-container > * {
    flex: 1;
    min-width: 300px; 
}


/* Ajustes específicos para los contenedores dentro de la estructura flexible */

/* El contenedor del clasificador ya tiene la clase .data-section, que le da borde, etc. */
/* No necesita estilos adicionales. */


/* Ajustes para el contenedor del mapa */
#activity-map-container {
    display: flex; /* Lo convertimos en flex para que el mapa ocupe todo el alto */
    flex-direction: column;
}

#activity-map {
    width: 100%;
    flex-grow: 1; /* Hace que el mapa ocupe todo el espacio vertical disponible en su contenedor */
    min-height: 400px; /* Asegura una altura mínima para el mapa */
    border-radius: 8px;
    border: 1px solid var(--border-color);
}


/* Ajustes para los gráficos de splits, que también usan el side-by-side */
#splits-section .side-by-side-container {
    gap: 1rem; /* Un poco menos de espacio entre los gráficos */
}

#splits-section .chart-container {
    /* Los chart-container ya tienen estilos que funcionan bien como columnas flexibles */
    min-width: 250px; /* Ancho mínimo más pequeño para los gráficos */
}

/* --- Estilos para los Controles de Fecha y Año --- */

/* --- Estilos para los Controles de Fecha y Año (Versión Mejorada) --- */

.date-controls-container {
    display: flex;
    flex-wrap: wrap; /* Para que se ajuste en pantallas pequeñas */
    align-items: center;
    gap: 1rem 2rem; /* 1rem de espacio vertical, 2rem horizontal */
    padding: 1rem;
    background-color: #f8f9fa;
    border-radius: var(--border-radius-md);
    margin-bottom: 1.5em;
    border: 1px solid var(--border-color);
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.75rem; /* Espacio entre los elementos DENTRO de un grupo */
}

/* Estilo para los botones de año */
.year-buttons button {
    background-color: #e9ecef;
    color: var(--text-medium);
    font-weight: 600;
    padding: 0.5em 1em;
}

.year-buttons button:hover {
    background-color: #ced4da;
    color: var(--text-dark);
}

/* Estilo para el botón de año activo */
.year-buttons button.active {
    background-color: var(--strava-orange);
    color: white;
}


/* --- Estilos para la sección de Perfil y Zonas --- */

.profile-and-zones-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

/* Estilos específicos para la tarjeta de perfil */
.profile-content {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.profile-content img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid var(--strava-orange);
}

.profile-details {
    font-size: 0.9em;
    line-height: 1.6;
}

.profile-details span {
    display: block;
}

.profile-details .name {
    font-size: 1.3em;
    font-weight: bold;
    color: var(--text-dark);
}

.profile-details .location {
    color: var(--text-medium);
}

.profile-details .stats {
    color: var(--text-light);
    font-style: italic;
}


/* Estilos específicos para la tarjeta de zonas */
.zones-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.zone-group {
    border-left: 3px solid var(--border-color);
    padding-left: 1rem;
}

.zone-group h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1em;
    color: var(--text-dark);
}

.zone-bar {
    display: flex;
    height: 20px;
    border-radius: 4px;
    overflow: hidden;
    font-size: 0.75em;
    font-weight: bold;
    color: white;
}

.zone-segment {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Colores para las zonas de Frecuencia Cardíaca (Z1 a Z5) */
.hr-z1 { background-color: #d1d5db; color: #374151; }
.hr-z2 { background-color: #60a5fa; }
.hr-z3 { background-color: #34d399; }
.hr-z4 { background-color: #f59e0b; }
.hr-z5 { background-color: #ef4444; }


/* --- Ajustes para el nuevo layout en activity.html --- */

/* Asegura que el contenedor del gráfico de zonas se comporte como una columna flex */
#hr-zones-section {
    display: flex;
    flex-direction: column;
}

/* El contenedor interno del canvas debe crecer para ocupar el espacio */
.chart-container-inner {
    flex-grow: 1;
    position: relative; /* Necesario para que Chart.js mida el tamaño correctamente */
    width: 100%;
    height: 100%;
    min-height: 250px; /* Asegura una altura mínima para el gráfico */
}

/* El mapa ya no es una columna flexible, así que le damos un margen superior */
#activity-map-container {
    margin-top: 2rem;
}

#activity-map {
    height: 450px; /* Un poco más alto para que aproveche el ancho completo */
}

.disclaimer {
    font-size: 0.8em;
    color: #666;
    margin-top: 10px;
    line-height: 1.4;
}
/* Contenedor del gráfico */
.chart-container #hour-matrix {
    width: 100%;         /* que ocupe todo el ancho del contenedor */
    max-width: 900px;    /* opcional: limitar ancho máximo */
    height: 350px;       /* altura fija */
    margin: auto;        /* centrar horizontalmente */
}

/* Opcional: si quieres que todos los gráficos tengan un límite similar */
.chart-container canvas {
    max-height: 400px;
}
