/**
 * Performance Chart Styles
 * Shared styles for performance charts with bars, trend lines, and labels
 */

/* Performance Chart Container */
.performance-chart {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid #334155;
    border-radius: 16px;
    padding: 2rem;
    margin-bottom: 3rem;
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 1;
}

/* Chart Header */
.chart-header {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.chart-header .chart-title { grid-column: 1; grid-row: 1; }
.chart-header .chart-header-actions { grid-column: 2; grid-row: 1; align-self: start; justify-self: end; }
.chart-header .chart-controls { grid-column: 1 / -1; grid-row: 2; margin-bottom: 1rem; }
.chart-header .chart-legend { grid-column: 1 / -1; grid-row: 3; }

.chart-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.chart-title {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chart-title h3 {
    color: #f8fafc;
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 0.5rem 0;
}

.chart-metric {
    color: #10b981;
    font-size: 1.25rem;
    font-weight: 800;
    background: rgba(16, 185, 129, 0.1);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    border: 1px solid rgba(16, 185, 129, 0.3);
    align-self: flex-start;
    width: fit-content;
}

.chart-legend {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #cbd5e1;
    font-size: 0.9rem;
}

.legend-color {
    width: 16px;
    height: 3px;
    border-radius: 2px;
}

.legend-color.profit {
    background: linear-gradient(90deg, #ef4444, #10b981);
}

.legend-color.trend {
    background: #10b981;
}

/* Chart Container */
.chart-container {
    position: relative;
    height: 300px;
    margin-bottom: 1rem;
}

.chart-grid {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.grid-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(71, 85, 105, 0.3);
}

/* Chart Bars */
.chart-bars {
    display: flex;
    align-items: end;
    justify-content: space-between;
    height: 100%;
    padding: 0 1rem;
    position: relative;
    z-index: 2;
}

.bar-item {
    width: 16px;
    background: linear-gradient(to top, #ef4444, #10b981);
    border-radius: 2px 2px 0 0;
    position: relative;
    height: var(--height);
    animation: growUp 1.5s ease-out;
    animation-fill-mode: both;
    cursor: pointer;
    transition: all 0.3s ease;
}

.bar-item[data-value*="-"] {
    background: linear-gradient(to top, #ef4444, #f87171);
}

.bar-item:hover {
    transform: scaleY(1.1);
    filter: brightness(1.2);
}

.bar-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.95);
    color: #f8fafc;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    border: 1px solid #334155;
}

.bar-item:hover .bar-tooltip {
    opacity: 1;
}

/* Trend Line */
.trend-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    pointer-events: none;
}

/* Chart Labels */
.chart-labels {
    display: flex;
    justify-content: space-between;
    color: #94a3b8;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0 1rem;
}

.chart-audit-link-wrap {
    margin-top: 0.9rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.chart-display-mode-note {
    margin-top: 0.45rem;
    font-size: 0.78rem;
    line-height: 1.35;
    color: #94a3b8;
    text-align: center;
    max-width: 360px;
}

.chart-performance-disclaimer {
    margin-top: 0.3rem;
    font-size: 0.74rem;
    line-height: 1.35;
    color: #64748b;
    text-align: center;
    max-width: 360px;
}

.chart-audit-link {
    background: transparent;
    border: 1px solid #334155;
    color: #cbd5e1;
    border-radius: 999px;
    padding: 0.45rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
    margin-bottom: 0.5rem;
}

.chart-audit-link:hover:not(:disabled) {
    border-color: rgba(16, 185, 129, 0.5);
    color: #10b981;
    background: rgba(16, 185, 129, 0.08);
}

.chart-audit-link:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Results Stats */
.results-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    position: relative;
    z-index: 1;
}

.results-stats .stat-card {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid #334155;
    border-radius: 12px;
    padding: 2rem 1.5rem;
    text-align: center;
    backdrop-filter: blur(10px);
    transition: all 0.3s ease;
    animation: fadeInUp 0.8s ease-out;
    animation-fill-mode: both;
}

.results-stats .stat-card:nth-child(1) { animation-delay: 0.1s; }
.results-stats .stat-card:nth-child(2) { animation-delay: 0.2s; }
.results-stats .stat-card:nth-child(3) { animation-delay: 0.3s; }
.results-stats .stat-card:nth-child(4) { animation-delay: 0.4s; }

.results-stats .stat-card:hover {
    transform: translateY(-4px);
    border-color: #10b981;
    box-shadow: 0 10px 30px rgba(16, 185, 129, 0.2);
}

.stat-number {
    font-size: 2.5rem;
    font-weight: 800;
    color: #10b981;
    margin-bottom: 0.5rem;
    line-height: 1;
}

.stat-label {
    color: #cbd5e1;
    font-size: 1rem;
    font-weight: 500;
}

.stat-best-strategy {
    margin-top: 0.35rem;
    color: #94a3b8;
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.25;
}

/* Animations */
@keyframes growUp {
    from {
        height: 0;
    }
    to {
        height: var(--height);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Advanced Chart Controls ─────────────────────────────────────────────── */

.chart-controls {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: flex-end;
}

.chart-control-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chart-control-group label {
    color: #94a3b8;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.chart-select {
    background: rgba(30, 41, 59, 0.9);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2394a3b8' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: 0.72rem;
    background-position: right 0.5rem center;
    color: #e2e8f0;
    border: 1px solid #475569;
    border-radius: 6px;
    padding: 0.35rem 2rem 0.35rem 0.5rem;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.2s ease, opacity 0.2s ease;
    min-width: 110px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.chart-select:hover:not(:disabled) {
    border-color: #10b981;
}

.chart-select:focus {
    outline: none;
    border-color: #10b981;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.chart-select:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.chart-display-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    outline: none;
    background: transparent;
    color: #64748b;
    border-radius: 6px;
    padding: 0.35rem;
    margin: 0;
    font-size: 1.6rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.chart-display-toggle-btn:hover {
    border-color: #475569;
    color: #e2e8f0;
}

.chart-display-toggle-btn.active {
    border-color: #10b981;
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
    opacity: 1;
}

/* Chart settings gear button */
.chart-settings-btn {
    background: transparent;
    border: 1px solid transparent;
    outline: none;
    color: #64748b;
    font-size: 1.6rem;
    cursor: pointer;
    padding: 0.35rem;
    margin: 0;
    border-radius: 6px;
    line-height: 1;
    transition: color 0.2s ease, border-color 0.2s ease, transform 0.3s ease;
    -webkit-appearance: none;
    appearance: none;
}

.chart-settings-btn:hover {
    color: #e2e8f0;
    border-color: #475569;
}

.chart-settings-btn.active {
    color: #10b981;
    border-color: rgba(16, 185, 129, 0.3);
    transform: rotate(90deg);
}

/* Collapsible controls panel */
.chart-controls-collapsed {
    display: none !important;
}

.chart-controls-expanded {
    display: flex !important;
}

/* Strategy info button (in legend) */
.strategy-info-btn {
    background: transparent;
    border: none;
    outline: none;
    color: rgba(148, 163, 184, 0.4);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0;
    margin: 0;
    line-height: 1;
    transition: color 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.strategy-info-btn:hover {
    color: #10b981;
}

/* Best strategy highlight on legend item */
.legend-item.best-strategy {
    background: rgba(16, 185, 129, 0.1);
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: #10b981;
}

.legend-item.best-strategy span {
    font-weight: 600;
}

/* Loading overlay for API re-fetch */
.performance-chart.chart-loading {
    position: relative;
}

.performance-chart.chart-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    border-radius: 16px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Strategy comparison in modals */
.strategy-comparison {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid #334155;
}

.comparison-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.comparison-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border-radius: 6px;
    background: rgba(30, 41, 59, 0.4);
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.comparison-item.best {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
}

.comparison-indicator {
    width: 4px;
    height: 24px;
    border-radius: 2px;
    flex-shrink: 0;
}

.comparison-content {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.comparison-label {
    font-size: 0.85rem;
    color: #cbd5e1;
    font-weight: 500;
}

.comparison-value {
    font-size: 0.85rem;
    color: #f8fafc;
    font-weight: 600;
}

.best-indicator {
    color: #10b981;
    font-size: 0.75rem;
    margin-left: 0.25rem;
}

/* Pick audit modal */
.pick-audit-modal-content {
    width: min(1100px, 95vw);
    max-height: 85vh;
}

.pick-audit-table-wrap {
    overflow: auto;
    max-height: 62vh;
    border: 1px solid #334155;
    border-radius: 8px;
}

.metric-modal .modal-body .pick-audit-table-wrap {
    overflow-x: auto;
}

.pick-audit-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.45rem;
    margin-bottom: 0.6rem;
}

.pick-audit-export-btn,
.pick-audit-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid #334155;
    background: rgba(15, 23, 42, 0.85);
    color: #e2e8f0;
    border-radius: 8px;
    padding: 0.4rem 0.65rem;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.pick-audit-export-btn:hover:not(:disabled),
.pick-audit-toggle-btn:hover:not(:disabled) {
    border-color: #10b981;
    color: #10b981;
    background: rgba(15, 23, 42, 0.95);
}

.pick-audit-toggle-btn.active {
    border-color: #10b981;
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}

.pick-audit-export-btn:disabled,
.pick-audit-toggle-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.pick-audit-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.metric-modal .modal-body .pick-audit-table {
    min-width: 475px;
    max-width: 475px;
    width: 475px;
}

.pick-audit-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #0f172a;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.68rem;
    text-align: left;
    padding: 0.6rem 0.55rem;
    border-bottom: 1px solid #334155;
}

.pick-audit-table tbody td {
    padding: 0.52rem 0.55rem;
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
    color: #e2e8f0;
    white-space: nowrap;
}

.pick-audit-table tbody tr:nth-child(even) td {
    background: rgba(15, 23, 42, 0.45);
}

.pick-result {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.15rem 0.45rem;
    font-size: 0.72rem;
    font-weight: 700;
}

.pick-result.win {
    color: #10b981;
    background: rgba(16, 185, 129, 0.13);
}

.pick-result.loss {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.13);
}

.pick-net.pos {
    color: #10b981;
    font-weight: 700;
}

.pick-net.neg {
    color: #ef4444;
    font-weight: 700;
}

.pick-audit-empty {
    text-align: center;
    color: #94a3b8 !important;
    font-style: italic;
    padding: 1rem !important;
}

/* Fallback for old ul/li styles (no longer used) */
.strategy-comparison ul,
.strategy-comparison li {
    display: none;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .chart-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .chart-controls {
        width: 100%;
    }

    .chart-legend {
        flex-direction: column;
        align-items: center;
        gap: 0.75rem;
    }
    
    .results-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .performance-chart {
        padding: 1.5rem;
    }
    
    .chart-header {
        gap: 0.75rem;
        text-align: center;
    }

    .chart-title {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .chart-metric {
        align-self: center;
        font-size: 1.1rem;
    }

    .chart-controls {
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
    }

    .chart-control-group {
        width: 100%;
        max-width: 260px;
    }

    .chart-select {
        width: 100%;
        min-width: unset;
    }

    .chart-audit-link {
        width: 100%;
        max-width: 320px;
        justify-content: center;
    }

    .pick-audit-modal-content {
        width: 96vw;
    }

    .pick-audit-table {
        font-size: 0.76rem;
    }

    .pick-audit-actions {
        justify-content: flex-start;
    }

    .metric-modal .modal-body {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .chart-legend {
        justify-content: center !important;
        align-items: center;
        gap: 1rem;
        flex-wrap: wrap;
    }

    .legend-item {
        font-size: 0.85rem;
        max-width: 260px;
    }
    
    .chart-container {
        height: 250px;
    }
    
    .results-stats {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .results-stats .stat-card {
        padding: 1.5rem 1rem;
    }
    
    .stat-number {
        font-size: 2rem;
    }
}
