/* IH Index Analytics Page Styles */
/* 與 ihorse.app 主題一致的樣式 */

/* ===========================================
   CSS Variables (與 new-theme 一致)
   =========================================== */
:root {
    --ih-primary: var(--corporate-blue, #003366);
    --ih-primary-light: var(--logo-blue, #005B9A);
    --ih-accent: var(--accent-blue, #007BFF);
    --ih-success: var(--success-green, #28a745);
    --ih-warning: var(--warning-orange, #ffc107);
    --ih-danger: var(--danger-red, #dc3545);
    --ih-gray-100: var(--gray-light, #F8F9FA);
    --ih-gray-600: #666;
    --ih-gray-800: #333;
    --ih-white: #ffffff;
    --ih-shadow-sm: 0 2px 4px rgba(0,51,102,0.08);
    --ih-shadow-md: 0 4px 12px rgba(0,51,102,0.12);
    --ih-radius-sm: 6px;
    --ih-radius-md: 10px;
}

/* ===========================================
   Page Header
   =========================================== */
.page-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--ih-primary);
}

.page-header h1 {
    color: var(--ih-primary);
    margin-bottom: 0.5rem;
    font-size: 1.75rem;
}

.page-header p {
    color: var(--ih-gray-600);
    margin: 0;
}

/* ===========================================
   IH Analytics Container
   =========================================== */
.ih-analytics {
    max-width: 1400px;
    margin: 0 auto;
    font-size: 0.85rem;
}

/* ===========================================
   Tab Navigation
   =========================================== */
.tab-nav {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid #dee2e6;
    padding-bottom: 0;
}

.tab-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: var(--ih-gray-100);
    color: var(--ih-gray-600);
    cursor: pointer;
    font-size: 0.85rem;
    border-radius: var(--ih-radius-sm) var(--ih-radius-sm) 0 0;
    transition: all 0.3s;
    border: 1px solid #dee2e6;
    border-bottom: none;
    margin-bottom: -2px;
}

.tab-btn:hover {
    background: #e3f2fd;
    color: var(--ih-primary);
}

.tab-btn.active {
    background: var(--ih-white);
    color: var(--ih-primary);
    font-weight: bold;
    border-bottom: 2px solid var(--ih-white);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ===========================================
   Cards
   =========================================== */
.card {
    background: var(--ih-white);
    border-radius: var(--ih-radius-md);
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--ih-shadow-md);
    transition: box-shadow 0.3s, transform 0.3s;
}

/* Filter Card - Collapsible Style */
.filter-card {
    padding: 0;
    overflow: hidden;
}

.filter-card .card-header {
    padding: 0.75rem 1rem;
    border-radius: var(--ih-radius-md) var(--ih-radius-md) 0 0;
}

.filter-card .card-header h5 {
    font-size: 0.9rem;
    margin: 0;
}

.filter-card .card-body {
    padding: 1rem;
}

.filter-card .collapse {
    border-top: 1px solid rgba(0,0,0,0.1);
}

.card:hover {
    box-shadow: 0 8px 25px rgba(0,51,102,0.15);
}

.card h2 {
    color: var(--ih-primary);
    margin-bottom: 0.75rem;
    font-size: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card.full-width {
    grid-column: 1 / -1;
}

/* ===========================================
   Stats Grid
   =========================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
}

.stat-card {
    text-align: center;
    padding: 1rem;
    background: var(--ih-white);
    border-radius: var(--ih-radius-md);
    border: 2px solid var(--ih-primary);
    box-shadow: var(--ih-shadow-sm);
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--ih-shadow-md);
}

.stat-value {
    display: block;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--ih-primary);
    line-height: 1.2;
}

.stat-label {
    display: block;
    font-size: 0.7rem;
    color: var(--ih-gray-600);
    margin-top: 0.25rem;
    font-weight: 500;
}

.stat-detail {
    font-size: 0.65rem;
    color: var(--ih-gray-600);
    margin-top: 0.25rem;
}

.stat-hint {
    font-size: 0.6rem;
    color: #999;
    margin-top: 0.25rem;
}

.stat-card-highlight {
    border-color: #ff9800;
    background: linear-gradient(135deg, #fff8e1 0%, #ffffff 100%);
}

.stat-card-highlight .stat-value {
    color: #e65100;
}

.stat-card-secondary {
    border-color: var(--ih-accent);
}

.stat-card-secondary .stat-value {
    color: var(--ih-accent);
}

/* ===========================================
   Loading States
   =========================================== */
.loading-container {
    text-align: center;
    padding: 2rem;
}

.loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 3px solid #dee2e6;
    border-radius: 50%;
    border-top-color: var(--ih-primary);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-container p {
    margin-top: 1rem;
    color: var(--ih-gray-600);
}

/* ===========================================
   Forms
   =========================================== */
.search-form-inline,
.form-inline {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.search-form-inline .form-group,
.form-inline .form-group {
    flex: 1;
    min-width: 180px;
    margin-bottom: 0;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--ih-gray-800);
    font-size: 0.8rem;
}

.form-group input,
.form-group select,
.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 2px solid #ced4da;
    border-radius: var(--ih-radius-sm);
    font-size: 0.85rem;
    font-family: inherit;
    transition: all 0.2s ease;
    background: var(--ih-white);
}

.form-group input:focus,
.form-group select:focus,
.form-control:focus {
    outline: none;
    border-color: var(--ih-primary);
    box-shadow: 0 0 0 3px rgba(0, 51, 102, 0.15);
}

.form-group select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

/* ===========================================
   Data Tables
   =========================================== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--ih-radius-md);
    border: 1px solid #dee2e6;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.data-table th {
    background-color: var(--ih-primary);
    color: white;
    font-weight: 500;
    padding: 0.5rem 0.4rem;
    text-align: left;
    white-space: nowrap;
    font-size: 0.75rem;
}

.data-table td {
    padding: 0.4rem;
    vertical-align: middle;
    border-bottom: 1px solid #dee2e6;
}

.data-table tbody tr:hover {
    background-color: rgba(0, 51, 102, 0.04);
}

/* Table Cell Types */
.horse-number {
    text-align: center;
    background: var(--ih-gray-100);
    font-weight: bold;
    font-family: 'Courier New', monospace;
}

.horse-numbers {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.horse-num {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    background: var(--ih-gray-100);
    border-radius: var(--ih-radius-sm);
    font-size: 0.8rem;
    font-family: 'Courier New', monospace;
}

.race-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.race-venue {
    padding: 0.15rem 0.5rem;
    border-radius: var(--ih-radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
}

.venue-st {
    background: var(--ih-primary);
    color: white;
}

.venue-hv {
    background: #6c757d;
    color: white;
}

/* ===========================================
   Badges
   =========================================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--ih-radius-sm);
    white-space: nowrap;
}

.badge-success {
    background-color: var(--ih-success);
    color: white;
}

.badge-info {
    background-color: var(--ih-accent);
    color: white;
}

.badge-secondary {
    background-color: #6c757d;
    color: white;
}

/* IH Index Badge */
.ih-badge,
.ih-index-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: bold;
    font-size: 0.85em;
    background: linear-gradient(135deg, var(--ih-success) 0%, #20c997 100%);
    color: white;
}

.ih-index-badge.ih-tier-high {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
}

.ih-index-badge.ih-tier-medium {
    background: linear-gradient(135deg, #ffc107 0%, #fd7e14 100%);
    color: #333;
}

.ih-index-badge.ih-tier-low {
    background: linear-gradient(135deg, #dc3545 0%, #e83e8c 100%);
    color: white;
}

/* Odds Badge */
.odds-badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    background: #e3f2fd;
    color: var(--ih-accent);
    border-radius: var(--ih-radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    margin-left: 0.25rem;
}

/* ===========================================
   Hit Status
   =========================================== */
.hit-status {
    text-align: center;
}

tr.hit-top1 {
    background: linear-gradient(90deg, #fff9c4 0%, #ffffff 100%) !important;
}

tr.hit-top3 {
    background: linear-gradient(90deg, #e3f2fd 0%, #ffffff 100%) !important;
}

.ih-rank {
    text-align: center;
    font-weight: 600;
}

.rank-good {
    color: var(--ih-success);
}

.rank-medium {
    color: #ff9800;
}

.rank-poor {
    color: var(--ih-danger);
}

/* ===========================================
   Accuracy Legend
   =========================================== */
.accuracy-legend {
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--ih-gray-100);
    border-radius: var(--ih-radius-md);
}

.accuracy-legend h4 {
    color: var(--ih-primary);
    margin-bottom: 0.75rem;
    font-size: 1rem;
}

.accuracy-legend ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.accuracy-legend li {
    padding: 0.4rem 0;
    border-bottom: 1px solid #dee2e6;
    font-size: 0.8rem;
    color: var(--ih-gray-600);
}

.accuracy-legend li:last-child {
    border-bottom: none;
}

.accuracy-legend strong {
    color: var(--ih-gray-800);
}

.stats-period {
    color: var(--ih-gray-600);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

/* ===========================================
   Compare & History Forms
   =========================================== */
.compare-form,
.history-form {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.compare-form .form-group,
.history-form .form-group {
    flex: 1;
    min-width: 200px;
    margin-bottom: 0;
}

.compare-result,
.history-result {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--ih-gray-100);
    border-radius: var(--ih-radius-md);
}

.compare-result h4,
.history-result h4 {
    color: var(--ih-primary);
    margin-bottom: 1rem;
}

.compare-summary {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--ih-white);
    border-radius: var(--ih-radius-sm);
}

.compare-summary h5 {
    color: var(--ih-primary);
    margin-bottom: 0.5rem;
}

.best-indicators {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.best-item {
    padding: 0.25rem 0.75rem;
    background: #e3f2fd;
    border-radius: var(--ih-radius-sm);
    font-size: 0.85rem;
    color: var(--ih-primary);
}

tr.best-horse {
    background: #fff9c4 !important;
}

td.best-factor {
    background: #c8e6c9 !important;
    font-weight: bold;
}

/* History Stats */
.history-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--ih-white);
    border-radius: var(--ih-radius-sm);
}

.stat-item {
    padding: 0.5rem 1rem;
    background: var(--ih-gray-100);
    border-radius: var(--ih-radius-sm);
    font-size: 0.9rem;
}

/* ===========================================
   Upcoming Picks
   =========================================== */
.upcoming-picks-card {
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
}

.upcoming-header {
    margin-bottom: 1rem;
}

.upcoming-header h2 {
    border-bottom: none;
    padding-bottom: 0;
}

.race-info-text {
    color: var(--ih-gray-600);
    font-size: 0.95rem;
}

.upcoming-table tr.rank-1 {
    background: linear-gradient(90deg, #fff9c4 0%, #ffffff 100%);
}

.upcoming-table tr.rank-2 {
    background: linear-gradient(90deg, #e3f2fd 0%, #ffffff 100%);
}

.upcoming-table tr.rank-3 {
    background: linear-gradient(90deg, #fff3e0 0%, #ffffff 100%);
}

.rank-badge {
    font-size: 1.2rem;
}

.race-detail {
    font-size: 0.8rem;
    color: #ffffff !important;
    display: block;
    font-weight: 500;
    background: transparent !important;
}

/* Pace Style Badges */
.pace-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: var(--ih-radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
}

.pace-leader {
    background: #ef4444;
    color: white;
}

.pace-stalker {
    background: #f97316;
    color: white;
}

.pace-midpack {
    background: #3b82f6;
    color: white;
}

.pace-closer {
    background: #8b5cf6;
    color: white;
}

.pace-unknown {
    background: #9ca3af;
    color: white;
}

/* Download Section - 放在標題區域 */
.download-section {
    margin-top: 0.75rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.upcoming-header .download-section {
    margin-top: 0.75rem;
    padding-top: 0;
    border-top: none;
}

.btn-download {
    padding: 0.5rem 1.25rem;
    font-size: 0.9rem;
}

.download-hint {
    margin: 0;
    font-size: 0.8rem;
    color: var(--ih-gray-600);
}

/* ===========================================
   No Data
   =========================================== */
.no-data {
    color: var(--ih-gray-600);
    font-style: italic;
    padding: 1rem;
    text-align: center;
    background: var(--ih-gray-100);
    border-radius: var(--ih-radius-sm);
}

.no-data-hint {
    color: #17a2b8;
    font-size: 0.9rem;
    text-align: center;
    padding: 0.5rem 1rem;
    margin-top: 0.5rem;
}

/* ===========================================
   Responsive - 參考 race-overview 頁面字體大小
   =========================================== */
@media (max-width: 768px) {
    .ih-analytics {
        font-size: 0.8rem;
    }
    
    .page-header h1 {
        font-size: 1.2rem;
    }
    
    .tab-nav {
        flex-wrap: wrap;
    }
    
    .tab-btn {
        flex: 1;
        min-width: 100px;
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }
    
    .card {
        padding: 0.75rem;
    }
    
    .card h2 {
        font-size: 0.9rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.4rem;
    }
    
    .stat-card {
        padding: 0.6rem;
    }
    
    .stat-value {
        font-size: 1.1rem;
    }
    
    .stat-label {
        font-size: 0.65rem;
    }
    
    .stat-detail {
        font-size: 0.6rem;
    }
    
    .stats-period {
        font-size: 0.75rem;
    }
    
    .search-form-inline,
    .compare-form,
    .history-form {
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-form-inline .form-group,
    .compare-form .form-group,
    .history-form .form-group {
        min-width: 100%;
    }
    
    .form-group label {
        font-size: 0.75rem;
    }
    
    .form-group input,
    .form-group select,
    .form-control {
        font-size: 0.8rem;
        padding: 0.4rem 0.6rem;
    }
    
    .data-table {
        font-size: 0.72rem;
    }
    
    .data-table th {
        font-size: 0.68rem;
        padding: 0.4rem 0.3rem;
    }
    
    .data-table td {
        padding: 0.35rem 0.3rem;
    }
    
    .accuracy-legend {
        padding: 0.75rem;
    }
    
    .accuracy-legend h4 {
        font-size: 0.85rem;
    }
    
    .accuracy-legend li {
        font-size: 0.72rem;
        padding: 0.3rem 0;
    }
    
    .best-indicators {
        flex-direction: column;
    }
    
    .no-data {
        font-size: 0.8rem;
    }
    
    .no-data-hint {
        font-size: 0.75rem;
    }
    
    .race-info-text {
        font-size: 0.8rem;
    }
    
    .btn-download {
        font-size: 0.8rem;
        padding: 0.4rem 1rem;
    }
    
    .download-hint {
        font-size: 0.7rem;
    }
}

@media (max-width: 480px) {
    .ih-analytics {
        font-size: 0.75rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.35rem;
    }
    
    .stat-card {
        padding: 0.5rem;
    }
    
    .stat-value {
        font-size: 1rem;
    }
    
    .stat-label {
        font-size: 0.6rem;
    }
    
    .tab-btn {
        font-size: 0.75rem;
        padding: 0.4rem 0.5rem;
    }
    
    .data-table {
        font-size: 0.68rem;
    }
    
    .data-table th {
        font-size: 0.65rem;
    }
}

/* ===========================================
   Bet Simulation Card
   =========================================== */
.bet-simulation-card {
    margin-top: 1.5rem;
    background: linear-gradient(135deg, #f0fff4 0%, #ffffff 100%);
    border: 2px solid var(--ih-success);
}

.bet-simulation-card h2 {
    color: var(--ih-success);
}

/* 淨盈虧卡片 - 盈利時（綠色背景白字） */
.bet-simulation-card .stat-card-highlight {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%) !important;
    border-color: #28a745 !important;
}

.bet-simulation-card .stat-card-highlight .stat-value {
    color: white !important;
}

.bet-simulation-card .stat-card-highlight .stat-label {
    color: rgba(255, 255, 255, 0.9) !important;
}

.bet-simulation-card .stat-card-highlight .stat-detail {
    color: rgba(255, 255, 255, 0.85) !important;
}

/* 淨盈虧卡片 - 虧損時（紅色背景白字） */
.bet-simulation-card .stat-card-danger {
    background: linear-gradient(135deg, #dc3545 0%, #e83e8c 100%) !important;
    border-color: #dc3545 !important;
}

.bet-simulation-card .stat-card-danger .stat-value {
    color: white !important;
}

.bet-simulation-card .stat-card-danger .stat-label {
    color: rgba(255, 255, 255, 0.9) !important;
}

.bet-simulation-card .stat-card-danger .stat-detail {
    color: rgba(255, 255, 255, 0.85) !important;
}

/* 命中率卡片（藍色背景白字） */
.bet-simulation-card .stat-card-secondary {
    background: linear-gradient(135deg, #007bff 0%, #6610f2 100%) !important;
    border-color: #007bff !important;
}

.bet-simulation-card .stat-card-secondary .stat-value {
    color: white !important;
}

.bet-simulation-card .stat-card-secondary .stat-label {
    color: rgba(255, 255, 255, 0.9) !important;
}

.bet-simulation-card .stat-card-secondary .stat-detail {
    color: rgba(255, 255, 255, 0.85) !important;
}

/* 確保普通 stat-card 內的文字顏色正確 */
.bet-simulation-card .stat-card .stat-label {
    color: #555;
}

.bet-simulation-card .stat-card .stat-detail {
    color: #666;
}

/* 覆蓋 text-success 和 text-danger 在特殊卡片中的顏色 */
.bet-simulation-card .stat-card-highlight .text-success,
.bet-simulation-card .stat-card-danger .text-danger,
.bet-simulation-card .stat-card-secondary .stat-value {
    color: white !important;
}

.bet-breakdown {
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--ih-gray-100);
    border-radius: var(--ih-radius-md);
}

.bet-breakdown h4 {
    color: var(--ih-primary);
    margin-bottom: 0.75rem;
    font-size: 1rem;
}

.breakdown-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--ih-white);
    border-radius: var(--ih-radius-sm);
    font-size: 0.9rem;
    border: 1px solid #e9ecef;
    box-shadow: var(--ih-shadow-sm);
}

.breakdown-label {
    color: var(--ih-gray-600);
    font-size: 0.85rem;
}

.breakdown-value {
    font-weight: 700;
    color: var(--ih-success);
    font-size: 1rem;
}

.recent-wins-section {
    margin-top: 1.5rem;
}

.recent-wins-section h4 {
    color: var(--ih-primary);
    margin-bottom: 0.75rem;
    font-size: 1rem;
}

/* Bet Simulation Table */
.bet-sim-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    background: var(--ih-white);
    border-radius: var(--ih-radius-sm);
    overflow: hidden;
}

.bet-sim-table thead {
    background: linear-gradient(135deg, var(--ih-success) 0%, #20c997 100%);
}

.bet-sim-table th {
    color: white !important;
    background: transparent !important;
    padding: 0.6rem 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
}

.bet-sim-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #e9ecef;
    color: #333;
    vertical-align: middle;
}

.bet-sim-table tbody tr:hover {
    background: #f8f9fa;
}

.bet-sim-table tbody tr:last-child td {
    border-bottom: none;
}

/* Mobile adjustments for bet simulation */
@media (max-width: 768px) {
    .breakdown-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .breakdown-item {
        padding: 0.6rem 0.8rem;
        font-size: 0.85rem;
    }
    
    .breakdown-label {
        font-size: 0.8rem;
    }
    
    .breakdown-value {
        font-size: 0.9rem;
    }
    
    .bet-simulation-card .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .bet-sim-table {
        font-size: 0.8rem;
    }
    
    .bet-sim-table th,
    .bet-sim-table td {
        padding: 0.5rem 0.4rem;
    }
    
    .recent-wins-section .table-responsive {
        margin: 0 -0.5rem;
        padding: 0 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}
