/* ========================================
   Race Pacing — Tool-specific styles
   ======================================== */

/* Container principal */
.predictor-container {
    max-width: 1200px;
    margin: var(--spacing-lg) auto;
    padding: 0 var(--spacing-md);
}

.tool-grid {
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    gap: var(--spacing-lg);
}

@media (max-width: 968px) {
    .tool-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }
}

/* Section Input */
.input-section {
    background: var(--bpc-surface, #fff);
    padding: var(--spacing-lg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--bpc-border-soft);
}

.input-section h2 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: var(--spacing-md);
    color: var(--bpc-text);
}

.section-title-red {
    border-left: 4px solid var(--bpc-primary, #DC2626);
    padding-left: 12px;
}

.input-group {
    margin-bottom: var(--spacing-md);
}

.input-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--bpc-text);
    font-size: 0.95rem;
}

.input-group label .unit {
    font-weight: 400;
    font-size: 0.85rem;
    opacity: 0.6;
}

.time-inputs {
    display: flex;
    align-items: center;
    gap: 10px;
}

.time-inputs input {
    width: 90px;
    padding: 12px;
    border: 2px solid var(--bpc-border-soft);
    border-radius: var(--radius);
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    transition: border-color 0.3s, box-shadow 0.3s;
    background: #fff;
    color: var(--bpc-text);
}

.time-inputs input:focus {
    outline: none;
    border-color: var(--bpc-primary);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.time-inputs span {
    font-size: 0.9rem;
    color: var(--bpc-text-muted);
    font-weight: 500;
}

.number-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--bpc-border-soft);
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    transition: border-color 0.3s, box-shadow 0.3s;
    background: #fff;
    color: var(--bpc-text);
    font-family: 'Inter', sans-serif;
}

.number-input:focus {
    outline: none;
    border-color: var(--bpc-primary);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.bpc-select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--bpc-border-soft);
    border-radius: var(--radius);
    font-size: 1rem;
    background-color: #fff;
    cursor: pointer;
    transition: border-color 0.3s, box-shadow 0.3s;
    font-family: 'Inter', sans-serif;
    color: var(--bpc-text);
}

.bpc-select:focus {
    outline: none;
    border-color: var(--bpc-primary);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.helper-text {
    font-size: 0.82rem;
    color: var(--bpc-text-muted);
    margin-top: 6px;
    line-height: 1.4;
}

.range-description {
    font-size: 0.85rem;
    color: var(--bpc-text-muted);
    margin-top: 8px;
    font-style: italic;
    background: var(--bpc-water);
    padding: 8px 12px;
    border-radius: 8px;
    border-left: 3px solid var(--bpc-secondary);
}

/* Course info box */
.course-info {
    margin-top: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.85rem;
    display: flex;
    gap: 16px;
    align-items: center;
}

.course-info .info-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
    font-size: 0.82rem;
}

/* Checkbox group */
.checkbox-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #DC2626;
    cursor: pointer;
}

.checkbox-group label {
    margin-bottom: 0;
    cursor: pointer;
    font-size: 0.92rem;
}

/* Bouton de calcul */
.calc-btn {
    width: 100%;
    margin-top: 20px;
    padding: 16px;
    font-size: 1.1rem;
    font-weight: 700;
    background: var(--bpc-gradient);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.calc-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.calc-btn:disabled {
    opacity: 0.7;
    cursor: wait;
}

/* Collapsible advanced section */
.calibration-box {
    margin: 20px 0;
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: var(--radius);
    overflow: hidden;
}

.calib-header {
    padding: 12px 16px;
    background: #e0f2fe;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    color: #0369a1;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.calib-header:hover {
    background: #bae6fd;
}

.calib-content {
    padding: 16px;
    display: none;
}

/* Zone de resultats */
.results-section {
    position: sticky;
    top: 100px;
    height: fit-content;
}

.results-box {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: white;
    padding: var(--spacing-lg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-dark);
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.results-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 800;
    color: white;
}

.algorithm-badge {
    background: rgba(255, 255, 255, 0.15);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.main-result {
    text-align: center;
    margin: 2rem 0;
    padding: 2rem 1.5rem;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    border: 2px solid rgba(255, 255, 255, 0.15);
}

.main-result h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    opacity: 0.7;
    margin-bottom: 1rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
}

.big-time {
    font-size: 3.5rem;
    font-weight: 900;
    color: #38bdf8;
    line-height: 1;
    text-shadow: 0 2px 10px rgba(56, 189, 248, 0.3);
}

.format-label {
    margin-top: 8px;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.5);
}

/* Legs grid — 3 columns */
.legs-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin-top: 1.5rem;
}

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

.leg-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 14px 10px;
    border-radius: 12px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: border-color 0.3s;
}

.leg-card:hover {
    border-color: rgba(103, 232, 249, 0.2);
}

.leg-icon {
    font-size: 1.2rem;
    margin-bottom: 6px;
    color: rgba(255, 255, 255, 0.5);
}

.leg-time {
    font-weight: 800;
    font-size: 1.15rem;
    color: #67E8F9;
    margin-bottom: 2px;
}

.leg-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 6px;
}

.leg-details {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.4);
    line-height: 1.3;
    margin-top: 4px;
}

/* Transitions */
.sub-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 12px;
}

.stat-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 12px;
    border-radius: 12px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-val {
    font-weight: 800;
    font-size: 1.1rem;
    color: #67E8F9;
    margin-bottom: 0.3rem;
}

.stat-label {
    font-size: 0.72rem;
    opacity: 0.5;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Coupling section */
.coupling-section {
    margin-top: 1.5rem;
    padding: 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
}

.coupling-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.45);
    margin-bottom: 10px;
}

.coupling-desc {
    font-size: 0.88rem;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.4;
    margin-bottom: 12px;
}

.coupling-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.coupling-stat {
    text-align: center;
}

.coupling-stat-val {
    font-weight: 800;
    font-size: 1.05rem;
    color: #67E8F9;
}

.coupling-stat-label {
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-top: 2px;
}

/* Glycogen bar */
.glycogen-bar-container {
    margin-top: 12px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    height: 8px;
    overflow: hidden;
}

.glycogen-bar {
    height: 100%;
    border-radius: 8px;
    transition: width 0.6s ease, background 0.3s;
}

.glycogen-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.4);
    margin-top: 4px;
}

/* Segment breakdown */
.segment-section {
    margin-top: 1.5rem;
    padding: 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
}

.segment-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.45);
    margin-bottom: 4px;
}

.segment-section-header i {
    color: #67E8F9;
}

.seg-discipline {
    margin-top: 12px;
}

.seg-discipline-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.45);
    margin-bottom: 10px;
}

.seg-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.seg-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
    white-space: nowrap;
}

.seg-table thead {
    background: rgba(255, 255, 255, 0.04);
}

.seg-table th {
    padding: 8px 10px;
    font-weight: 700;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.35);
    text-align: right;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.seg-table .seg-th-label {
    text-align: left;
}

.seg-table td {
    padding: 8px 10px;
    text-align: right;
    color: rgba(255, 255, 255, 0.6);
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.seg-table tbody tr:last-child td {
    border-bottom: none;
}

.seg-table tbody tr:hover {
    background: rgba(103, 232, 249, 0.04);
}

.seg-td-label {
    text-align: left !important;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8) !important;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.seg-td-power {
    font-weight: 700;
    color: #67E8F9 !important;
}

.seg-td-time {
    font-weight: 700;
    color: rgba(255, 255, 255, 0.85) !important;
}

/* Warnings */
.warnings-section {
    margin-top: 1.5rem;
}

.warning-banner {
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.25);
    color: #FBBF24;
}

.warning-banner.error {
    background: rgba(220, 38, 38, 0.12);
    border-color: rgba(220, 38, 38, 0.25);
    color: #F87171;
}

/* Analysis section */
.analysis-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.warning-pill {
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 800;
    display: inline-block;
    margin-bottom: 1rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.analysis-text {
    font-size: 0.9rem;
    line-height: 1.7;
    color: rgba(255, 255, 255, 0.7);
}

.analysis-text strong {
    color: #67E8F9;
    font-weight: 700;
}

/* ── Overflow guard (mobile) ── */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Force all containers to respect parent width */
.results-box,
.results-section,
.coupling-section,
.segment-section,
.analysis-section,
.warnings-section {
    overflow: hidden;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    word-break: break-word;
    overflow-wrap: break-word;
}

.main-result {
    overflow: hidden;
    min-width: 0;
}

.main-result h3 {
    overflow: hidden;
    text-overflow: ellipsis;
}

.big-time {
    overflow-wrap: break-word;
    word-break: break-all;
}

.leg-details {
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    hyphens: auto;
}

.coupling-desc,
.analysis-text {
    word-break: break-word;
    overflow-wrap: break-word;
}

/* Sub-stats (transitions) — ensure grid stays within bounds */
.sub-stats {
    min-width: 0;
}
.sub-stats .stat-item {
    min-width: 0;
    overflow: hidden;
}

/* Coupling stats — prevent overflow */
.coupling-stats {
    min-width: 0;
}
.coupling-stat {
    min-width: 0;
    overflow: hidden;
}

/* Segment tables — scrollable on mobile instead of overflowing */
.seg-table-wrap {
    max-width: 100%;
}

.seg-table {
    min-width: 0;
}

/* Responsive */
@media (max-width: 968px) {
    .results-section {
        position: relative;
        top: 0;
    }

    .big-time {
        font-size: 2.5rem;
    }

    .predictor-container {
        padding: 0 12px;
        max-width: 100vw;
        box-sizing: border-box;
    }

    .tool-grid {
        max-width: 100%;
        overflow: hidden;
    }

    .results-box {
        padding: 16px;
    }

    .main-result {
        padding: 1.2rem 1rem;
    }

    .leg-card {
        padding: 12px 8px;
        min-width: 0;
    }

    .leg-details {
        font-size: 0.7rem;
    }

    /* Segment table: smaller font + allow horizontal scroll */
    .seg-table {
        font-size: 0.72rem;
    }

    .seg-table th,
    .seg-table td {
        padding: 6px 6px;
    }

    .seg-td-label {
        max-width: 120px;
    }

    /* Analysis text */
    .analysis-text {
        font-size: 0.82rem;
    }
}

@media (max-width: 400px) {
    .big-time {
        font-size: 2rem;
    }

    .main-result h3 {
        font-size: 0.75rem;
        letter-spacing: 1px;
    }

    .legs-grid {
        gap: 8px;
    }

    .coupling-stats {
        gap: 8px;
    }

    .coupling-stat-val {
        font-size: 0.9rem;
    }

    .seg-table th,
    .seg-table td {
        padding: 5px 4px;
        font-size: 0.68rem;
    }

    .seg-td-label {
        max-width: 100px;
    }
}
