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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    padding: 10px;
    color: #333;
    font-size: 14px;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    background: white;
    border: 1px solid #ddd;
}

.tabs {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #667eea;
    border-bottom: 2px solid #5568d3;
    padding: 8px 15px;
    gap: 15px;
    flex-wrap: wrap;
}

.tabs-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    flex: 1;
}

.race-header-info {
    display: flex;
    gap: 15px;
    align-items: center;
    color: white;
    font-weight: 600;
    font-size: 1.5em;
    white-space: nowrap;
}

.race-date {
    color: white;
}

.race-venue {
    color: white;
    padding-left: 10px;
    border-left: 2px solid rgba(255, 255, 255, 0.3);
}

.tab-btn {
    padding: 8px 16px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    font-size: 1.2em;
    font-weight: 900;
    color: #666;
}

.tab-btn:hover {
    background: #f0f0f0;
}

.tab-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.race-content {
    padding: 15px;
    display: none;
}

.race-content.active {
    display: block;
}

.race-info {
    background: #f8f9fa;
    padding: 10px;
    margin-bottom: 15px;
    border: 1px solid #e0e0e0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.race-info-item {
    padding: 5px;
    flex: 0 1 auto;
    min-width: fit-content;
}

.race-info-label {
    font-size: 0.75em;
    color: #666;
    text-transform: uppercase;
    margin-bottom: 3px;
}

.race-info-value {
    font-size: 0.95em;
    font-weight: 600;
    color: #333;
}

.race-buttons-group {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

.tips-index-btn {
    padding: 8px 16px;
    background: #9db68f;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    transition: background 0.2s ease;
}

.tips-index-btn:hover {
    background: #8aa67a;
}

.track-workout-btn {
    padding: 8px 16px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    transition: background 0.2s ease;
}

.track-workout-btn:hover {
    background: #5568d3;
}

.race-visual-container {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.speedmap-section {
    flex: 1 1 auto;
    min-width: 300px;
    max-width: 820px;
}

.fav-style-chart-section {
    flex: 0 0 282px;
}

.speedmap-container {
    text-align: center;
    background: #f8f9fa;
    padding: 10px;
    border: 1px solid #e0e0e0;
    overflow: hidden;
}

.speedmap-image {
    max-width: 800px;
    width: 100%;
    height: auto;
    display: none;
    border: 1px solid #ddd;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-top: -280px;
}

.race-not-ready {
    padding: 20px;
    color: #666;
    font-size: 1em;
    font-style: italic;
    text-align: center;
}

.fav-style-chart-container {
    padding: 8px;
    text-align: center;
}

.fav-style-chart-container > div {
    margin: 0 auto;
    height: 280px;
    max-width: 280px;
}

.expand-all-container {
    margin-bottom: 10px;
    display: flex;
    gap: 15px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.expand-all-btn {
    padding: 6px 12px;
    background: #667eea;
    color: white;
    border: none;
    cursor: pointer;
    font-size: 0.85em;
}

.expand-all-btn:hover {
    background: #5568d3;
}

/* Prediction Container */
.prediction-container {
    flex: 1;
    min-width: 300px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.prediction-label {
    color: #666;
    font-weight: 600;
    font-size: 0.85em;
    white-space: nowrap;
}

.prediction-icon {
    font-size: 1em;
}

.prediction-title {
    color: #666;
    font-weight: 600;
    font-size: 0.8em;
    text-transform: uppercase;
}

.prediction-content {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}

.prediction-loading,
.prediction-error {
    color: #999;
    font-size: 0.8em;
    font-style: italic;
}

.prediction-error {
    color: #e53e3e;
}

.prediction-item {
    display: flex;
    align-items: center;
    gap: 4px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 4px 8px;
    transition: border-color 0.2s ease;
}

.prediction-item:hover {
    border-color: #667eea;
}

.prediction-medal {
    font-size: 1em;
    line-height: 1;
}

.prediction-position {
    background: #e0e0e0;
    color: #666;
    font-weight: 600;
    font-size: 0.7em;
    padding: 2px 5px;
    border-radius: 3px;
    min-width: 18px;
    text-align: center;
}

.prediction-horse {
    color: #333;
    font-weight: 600;
    font-size: 0.85em;
}

.runners-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    table-layout: auto;
}

.runners-table th {
    background: #667eea;
    color: white;
    padding: 6px 4px;
    text-align: left;
    font-weight: 600;
    font-size: 0.85em;
    border: 1px solid #5568d3;
    white-space: nowrap;
}

.runners-table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 24px;
}

.runners-table th.sortable:hover {
    background: #5568d3;
}

.sort-arrow {
    font-size: 0.85em;
    margin-left: 5px;
    color: rgba(255, 255, 255, 0.7);
    display: inline-block;
    width: 12px;
}

.runners-table th.sort-asc .sort-arrow,
.runners-table th.sort-desc .sort-arrow {
    color: white;
    font-weight: bold;
}

.runners-table td {
    padding: 5px 4px;
    border: 1px solid #e0e0e0;
    white-space: nowrap;
}

.runners-table tbody tr:nth-child(4n+1),
.runners-table tbody tr:nth-child(4n+2) {
    background: #fafafa;
}

.runner-row {
    cursor: pointer;
}

.runner-row:hover {
    background: #e8eaf6 !important;
}

.runner-no {
    font-weight: 700;
}

.horse-no {
    font-weight: 600;
    color: #667eea;
}

.horse-icon {
    filter: brightness(100);
}

.expand-icon {
    cursor: pointer;
    display: inline-block;
    width: 15px;
    text-align: center;
    color: #667eea;
    font-size: 0.7em;
    transition: transform 0.2s ease;
}

.expand-icon.expanded {
    transform: rotate(90deg);
}

.runner-details-row {
    display: none;
}

.runner-details-row.expanded {
    display: table-row;
}

.runner-details-cell {
    padding: 0 !important;
    background: #f9f9f9;
    border: 1px solid #ddd;
}

.runner-details-content {
    padding: 15px;
    overflow-x: auto;
}

.runner-details-wrapper {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.details-left {
    flex: 0 0 auto;
    min-width: 300px;
}

.details-right {
    flex: 1;
    min-width: 0;
    overflow-x: auto;
}

.details-loading {
    padding: 15px;
    text-align: center;
    color: #666;
    font-style: italic;
}

.details-loading.error {
    color: #ff4444;
}

.race-history-table {
    width: auto;
    font-size: 0.85em;
    border-collapse: collapse;
    table-layout: auto;
}

.race-history-table th {
    background: #667eea;
    color: white;
    padding: 5px 6px;
    text-align: left;
    font-size: 0.8em;
    white-space: nowrap;
    font-weight: 600;
    border: 1px solid #5568d3;
}

.race-history-table td {
    padding: 3px 6px;
    border: 1px solid #e0e0e0;
    white-space: nowrap;
}

.race-history-table tbody tr:nth-child(even) {
    background: #f5f5f5;
}

.race-history-table tbody tr:hover {
    background: #e8eaf6;
}

.odds-table-container {
    overflow-x: auto;
}

.odds-table {
    width: auto;
    font-size: 0.85em;
    border-collapse: collapse;
    background: white;
    table-layout: auto;
}

.odds-table th {
    background: #48bb78;
    color: white;
    padding: 5px 6px;
    text-align: center;
    font-size: 0.85em;
    white-space: nowrap;
    font-weight: 600;
    border: 1px solid #38a169;
}

.odds-table td {
    padding: 4px 6px;
    border: 1px solid #e0e0e0;
    text-align: center;
    white-space: nowrap;
}

.odds-table .odds-type-label {
    background: #f0fdf4;
    font-weight: 600;
    color: #166534;
    text-align: left;
    padding-left: 10px;
}

.odds-table tbody tr:nth-child(even) {
    background: #f9fafb;
}

.odds-table tbody tr:hover {
    background: #e0f2f1;
}

/* Odds difference styling */
.odds-diff-negative {
    background: #d1fae5;
    color: #065f46;
    font-weight: 600;
}

.odds-diff-positive {
    background: #fee2e2;
    color: #991b1b;
    font-weight: 500;
}

/* Preferred highlighting */
.preferred-cell {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%) !important;
    font-weight: 700;
    color: #92400e;
    position: relative;
    padding-right: 16px !important; /* Make room for star */
}

.preferred-cell::after {
    content: '★';
    position: absolute;
    right: 3px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65em;
    color: #f59e0b;
    opacity: 0.7;
    pointer-events: none;
}

.runner-row.most-preferred-horse {
    border-left: 4px solid #f59e0b;
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.3);
    background: linear-gradient(to right, #fffbeb 0%, transparent 100%) !important;
}

.runner-row.most-preferred-horse:hover {
    background: linear-gradient(to right, #fef3c7 0%, #e8eaf6 100%) !important;
}

.runner-row.most-preferred-horse .horse-no {
    color: #f59e0b;
    font-weight: 700;
}

.most-preferred-badge {
    display: inline-block;
    background: #f59e0b;
    color: white;
    font-size: 0.7em;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 5px;
    font-weight: 600;
}

/* Trade Calculator Section */
.trade-calculator-section {
    margin-top: 20px;
    border: 1px solid #e0e0e0;
    background: #fafafa;
}

.trade-calculator-tabs {
    display: flex;
    background: #f5f5f5;
    border-bottom: 2px solid #ddd;
    gap: 2px;
}

.trade-tab-btn {
    padding: 10px 20px;
    border: none;
    background: #e0e0e0;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    color: #666;
    transition: background 0.2s ease;
}

.trade-tab-btn:hover {
    background: #d0d0d0;
}

.trade-tab-btn.active {
    background: #667eea;
    color: white;
}

.trade-tab-content {
    display: none;
    padding: 15px;
}

.trade-tab-content.active {
    display: block;
}

.trade-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 15px;
}

.trade-control-label {
    font-size: 0.85em;
    font-weight: 600;
    color: #333;
    margin-right: 5px;
}

.runner-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex: 1;
}

.runner-select-btn,
.runner-radio-btn {
    padding: 6px 12px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    color: #666;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.runner-select-btn:hover,
.runner-radio-btn:hover {
    background: #f0f0f0;
    border-color: #667eea;
}

.runner-select-btn.selected {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* Exclude buttons use red to distinguish from cover (blue) */
[id*="-pareto-exclude-"] .runner-select-btn.selected {
    background: #e53e3e;
    color: white;
    border-color: #e53e3e;
}

.runner-radio-btn.selected {
    background: #48bb78;
    color: white;
    border-color: #48bb78;
}

.filter-control {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-left: auto;
}

.filter-label {
    font-size: 0.85em;
    font-weight: 600;
    color: #333;
}

.filter-toggle-btn {
    padding: 6px 14px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    color: #666;
    border-radius: 3px;
    min-width: 50px;
    transition: all 0.2s ease;
}

.filter-toggle-btn[data-filter="true"] {
    background: #48bb78;
    color: white;
    border-color: #48bb78;
}

.calculate-btn {
    padding: 8px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: background 0.2s ease;
}

.calculate-btn:hover {
    background: #5568d3;
}

.trade-metrics {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.metric-card {
    flex: 1;
    min-width: 120px;
    max-width: 180px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 12px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.metric-label {
    display: block;
    font-size: 0.75em;
    color: #666;
    text-transform: uppercase;
    margin-bottom: 8px;
    font-weight: 600;
}

.metric-value {
    display: block;
    font-size: 1.4em;
    font-weight: 700;
    color: #333;
}

.trade-plot-container {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 15px;
    height: 480px;
    overflow: hidden;
}

/* Pareto Section */
.pareto-section {
    margin-top: 20px;
    border: 1px solid #e0e0e0;
    background: #fafafa;
}

.pareto-header {
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-bottom: 2px solid #ddd;
    padding: 12px 15px;
    margin-top: 15px;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.pareto-title {
    font-size: 1em;
    font-weight: 700;
    color: #333;
    white-space: nowrap;
}

.pareto-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    flex: 1;
}

@media (max-width: 768px) {
    body {
        padding: 5px;
        font-size: 13px;
    }
    
    .tabs {
        padding: 6px 10px;
        gap: 10px;
    }
    
    .tabs-buttons {
        overflow-x: auto;
        flex-wrap: nowrap;
    }
    
    .race-header-info {
        font-size: 0.9em;
        gap: 10px;
        width: 100%;
        justify-content: center;
    }
    
    .tab-btn {
        padding: 6px 12px;
        font-size: 0.85em;
    }
    
    .race-content {
        padding: 10px;
    }
    
    .race-info {
        gap: 8px;
    }
    
    .race-visual-container {
        flex-direction: column;
        gap: 15px;
    }
    
    .speedmap-section,
    .fav-style-chart-section {
        flex: 1 1 100%;
        max-width: 100%;
    }
    
    .runners-table th,
    .runners-table td {
        padding: 5px;
        font-size: 0.85em;
    }
    
    .race-history-table {
        font-size: 0.75em;
    }
    
    .race-history-table th,
    .race-history-table td {
        padding: 3px;
    }
    
    .runner-details-wrapper {
        flex-direction: column;
    }
    
    .details-left {
        min-width: 100%;
    }
    
    .trade-calculator-tabs {
        gap: 1px;
    }
    
    .trade-tab-btn {
        padding: 8px 12px;
        font-size: 0.8em;
    }
    
    .trade-tab-content {
        padding: 10px;
    }
    
    .runner-buttons {
        gap: 3px;
    }
    
    .runner-select-btn,
    .runner-radio-btn {
        padding: 5px 10px;
        font-size: 0.8em;
    }
    
    .metric-card {
        min-width: 100px;
        padding: 10px;
    }
    
    .metric-value {
        font-size: 1.2em;
    }
    
    .trade-plot-container {
        height: 380px;
        padding: 10px;
    }
    
    .expand-all-container {
        flex-direction: column;
        gap: 10px;
    }
    
    .prediction-container {
        width: 100%;
        min-width: 100%;
    }
    
    .prediction-item {
        padding: 5px 10px;
        gap: 5px;
    }
    
    .prediction-horse {
        font-size: 0.85em;
    }
}
