/**
 * RaceMetrics Sectionals Component Styles
 */

/* Container */
.sectionals-container {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
}

/* Header */
.sectionals-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #1e3a5f 0%, #2d5a87 100%);
    color: white;
}

.sectionals-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.sectionals-title .race-info {
    font-size: 12px;
    opacity: 0.85;
}

.sectionals-controls select {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 12px;
}

.sectionals-controls select option {
    color: #333;
}

/* Tabs */
.sectionals-tabs {
    display: flex;
    background: #f5f5f5;
    border-bottom: 1px solid #e0e0e0;
}

.sectionals-tabs .tab-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #666;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
}

.sectionals-tabs .tab-btn:hover {
    background: rgba(0,0,0,0.05);
    color: #333;
}

.sectionals-tabs .tab-btn.active {
    color: #1e3a5f;
    border-bottom-color: #1e3a5f;
    background: white;
}

/* Panels */
.sectionals-panel {
    display: none;
    padding: 16px;
}

.sectionals-panel.active {
    display: block;
}

/* Grid wrapper for horizontal scroll */
.sectionals-grid-wrapper {
    overflow-x: auto;
    margin-bottom: 16px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
}

/* Data grid */
.sectionals-grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    white-space: nowrap;
}

.sectionals-grid th,
.sectionals-grid td {
    padding: 6px 8px;
    text-align: center;
    border-bottom: 1px solid #eee;
}

.sectionals-grid th {
    background: #f8f9fa;
    font-weight: 600;
    color: #333;
    position: sticky;
    top: 0;
    z-index: 1;
}

.sectionals-grid th .par-value {
    display: block;
    font-weight: 400;
    font-size: 10px;
    color: #666;
}

.sectionals-grid .horse-col {
    text-align: left;
    position: sticky;
    left: 0;
    background: white;
    z-index: 2;
    min-width: 140px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sectionals-grid th.horse-col {
    background: #f8f9fa;
}

.sectionals-grid .pos-col {
    width: 40px;
    font-weight: 600;
}

.sectionals-grid .data-col {
    min-width: 55px;
}

.sectionals-grid .horse-name {
    font-weight: 500;
    color: #333;
}

/* Color coding for times (lower = better = green) */
.sectionals-grid .much-faster {
    background: #22c55e;
    color: white;
}

.sectionals-grid .faster {
    background: #86efac;
    color: #166534;
}

.sectionals-grid .on-par {
    background: #fef9c3;
    color: #713f12;
}

.sectionals-grid .slower {
    background: #fecaca;
    color: #991b1b;
}

.sectionals-grid .much-slower {
    background: #ef4444;
    color: white;
}

/* Position grid specifics */
.position-grid .leader {
    background: #fef3c7 !important;
    color: #92400e !important;
    font-weight: 700;
}

.position-grid .lengths {
    font-size: 10px;
    color: inherit;
    opacity: 0.85;
}

.position-grid .section-time {
    font-size: 10px;
    font-weight: 500;
    padding: 1px 4px;
    border-radius: 3px;
    display: inline-block;
    margin-top: 2px;
}

.position-grid .section-time.much-faster {
    background: #22c55e;
    color: white;
}

.position-grid .section-time.faster {
    background: #86efac;
    color: #166534;
}

.position-grid .section-time.on-par {
    background: #fef9c3;
    color: #713f12;
}

.position-grid .section-time.slower {
    background: #fecaca;
    color: #991b1b;
}

.position-grid .section-time.much-slower {
    background: #ef4444;
    color: white;
}

/* Chart container */
.sectionals-chart-container {
    height: 300px;
    margin: 16px 0;
    padding: 8px;
    background: #fafafa;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
}

/* Legend */
.sectionals-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    margin-top: 8px;
}

.sectionals-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.2s;
}

.sectionals-legend .legend-item:hover {
    background: rgba(0,0,0,0.05);
}

.sectionals-legend .legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}

.sectionals-legend .legend-name {
    color: #333;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sectionals-legend input[type="checkbox"] {
    width: 12px;
    height: 12px;
    cursor: pointer;
}

/* Loading state */
.sectionals-loading {
    text-align: center;
    padding: 48px 16px;
    color: #666;
}

.sectionals-loading .loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e0e0e0;
    border-top-color: #1e3a5f;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error state */
.sectionals-error {
    text-align: center;
    padding: 32px 16px;
    color: #dc2626;
    background: #fef2f2;
    border-radius: 6px;
    margin: 16px;
}

/* Locked state (non-platinum) */
.sectionals-locked {
    text-align: center;
    padding: 48px 24px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 8px;
    margin: 16px;
}

.sectionals-locked .lock-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.sectionals-locked h3 {
    margin: 0 0 8px;
    color: #1e3a5f;
    font-size: 20px;
}

.sectionals-locked p {
    margin: 0 0 8px;
    color: #666;
}

.sectionals-locked .upgrade-text {
    color: #1e3a5f;
    font-weight: 500;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .sectionals-header {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    .sectionals-tabs {
        flex-wrap: wrap;
    }

    .sectionals-tabs .tab-btn {
        flex: 1 1 50%;
        font-size: 12px;
        padding: 8px 12px;
    }

    .sectionals-legend {
        gap: 4px;
    }

    .sectionals-legend .legend-item {
        font-size: 10px;
    }

    .sectionals-legend .legend-name {
        max-width: 80px;
    }
}

/* Splitter bar for resizing (between grid and chart) */
.sectionals-splitter {
    height: 6px;
    background: linear-gradient(to right, #22c55e, #22c55e);
    cursor: ns-resize;
    margin: 8px 0;
    border-radius: 3px;
}

.sectionals-splitter:hover {
    background: linear-gradient(to right, #16a34a, #16a34a);
}

/* Hover effects on grid rows */
.sectionals-grid tbody tr:hover {
    background: #f0f9ff;
}

.sectionals-grid tbody tr:hover .horse-col {
    background: #f0f9ff;
}

/* Print styles */
@media print {
    .sectionals-tabs,
    .sectionals-controls,
    .sectionals-legend input {
        display: none !important;
    }

    .sectionals-panel {
        display: block !important;
        page-break-inside: avoid;
    }

    .sectionals-chart-container {
        height: 200px !important;
    }
}

/* ============================================================================
   NEW TAB STYLES
   ============================================================================ */

/* Tabs overflow scrolling for many tabs */
.sectionals-tabs {
    overflow-x: auto;
    scrollbar-width: thin;
}

.sectionals-tabs .tab-btn {
    flex: 0 0 auto;
    min-width: fit-content;
    padding: 10px 12px;
    font-size: 12px;
}

/* Section highlighting */
.sectionals-grid .highlighted-section {
    outline: 3px solid #3b82f6 !important;
    outline-offset: -2px;
    background: #dbeafe !important;
    color: #1e3a5f !important; /* Ensure text is readable on blue highlight */
}

/* Heat Map Tab */
.heatmap-container {
    padding: 8px 0;
}

.heatmap-info {
    font-size: 12px;
    color: #666;
    margin-bottom: 12px;
    text-align: center;
}

.heatmap-grid .heatmap-cell {
    cursor: pointer;
    min-width: 50px;
    height: 32px;
    transition: transform 0.1s;
}

.heatmap-grid .heatmap-cell:hover {
    transform: scale(1.1);
    z-index: 5;
    position: relative;
}

.heatmap-grid .heatmap-header {
    cursor: pointer;
}

.heatmap-grid .heatmap-header:hover {
    background: #e0e0e0;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
    font-size: 11px;
    color: #666;
}

.heatmap-legend .heatmap-gradient {
    width: 200px;
    height: 16px;
    background: linear-gradient(to right, #22c55e, #fef9c3, #ef4444);
    border-radius: 4px;
    border: 1px solid #ccc;
}

.heatmap-label {
    font-weight: 500;
}

/* Stride Analysis Tab */
.stride-analysis {
    padding: 8px 0;
}

.horse-color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
    flex-shrink: 0;
}

.stride-intro {
    font-size: 13px;
    color: #666;
    margin-bottom: 12px;
    text-align: center;
}

.stride-averages {
    text-align: center;
    font-size: 12px;
    color: #666;
    background: #f0f0f0;
    padding: 8px;
    border-radius: 4px;
    margin-top: 12px;
}

.stride-grid .above-avg {
    background: #dcfce7;
    color: #166534;
    font-weight: 600;
}

.stride-grid .below-avg {
    background: #fee2e2;
    color: #991b1b;
}

/* Top Speed Tab */
.topspeed-analysis {
    padding: 8px 0;
}

.topspeed-grid .rank-1 {
    background: #fef3c7;
    font-weight: 700;
    color: #92400e;
}

.topspeed-grid .rank-2 {
    background: #e5e7eb;
    font-weight: 600;
    color: #374151;
}

.topspeed-grid .rank-3 {
    background: #fed7aa;
    font-weight: 600;
    color: #9a3412;
}

.topspeed-grid .speed-bar-cell {
    padding: 6px 4px;
    width: 150px;
}

.topspeed-grid .speed-bar {
    height: 16px;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    border-radius: 3px;
    min-width: 4px;
}

/* Running Style Tab */
.running-style-analysis {
    padding: 8px 0;
}

.style-intro {
    font-size: 13px;
    color: #666;
    margin-bottom: 16px;
    text-align: center;
}

.style-groups {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.style-group {
    background: #f8f9fa;
    border-radius: 8px;
    overflow: hidden;
}

.style-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: white;
    font-weight: 600;
}

.style-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.style-name {
    flex: 1;
}

.style-count {
    font-size: 11px;
    color: #666;
    font-weight: 400;
}

.style-horses {
    padding: 8px 12px;
    font-size: 11px;
    color: #444;
}

.style-horse {
    display: inline-block;
    margin: 2px 4px;
    padding: 2px 6px;
    background: white;
    border-radius: 4px;
}

.style-horse sup {
    font-size: 9px;
    color: #888;
}

.style-grid .positive-gain {
    background: #dcfce7;
    color: #166534;
    font-weight: 600;
}

.style-grid .negative-gain {
    background: #fee2e2;
    color: #991b1b;
}

/* Deviation Tab */
.deviation-grid .font-bold {
    font-weight: 700;
}

/* Comparison mode hint */
.sectionals-controls label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    cursor: pointer;
}

.sectionals-controls input[type="checkbox"] {
    cursor: pointer;
}

/* Metrics Tab */
.metrics-analysis {
    padding: 8px 0;
}

.metrics-grid td.data-col {
    font-variant-numeric: tabular-nums;
    min-width: 52px;
    font-size: 11px;
    padding: 5px 6px;
}

.metrics-grid th.data-col {
    font-size: 11px;
    padding: 6px 6px;
}

.metrics-sortable {
    cursor: pointer;
    user-select: none;
}

.metrics-sortable:hover {
    background: #e9ecef !important;
}

.metrics-sort-arrow {
    font-size: 9px;
    color: #aaa;
    margin-left: 2px;
}

.metrics-sort-arrow.active {
    color: #1e3a5f;
}

/* Responsive adjustments for new tabs */
@media (max-width: 768px) {
    .sectionals-tabs .tab-btn {
        padding: 8px 8px;
        font-size: 10px;
    }

    .style-groups {
        grid-template-columns: 1fr;
    }

    .heatmap-legend .heatmap-gradient {
        width: 120px;
    }

    .topspeed-grid .speed-bar-cell {
        width: 80px;
    }
}
