/* 
 * Self Trader Bot - History Page
 * Design: Dark cyberpunk with gold/orange accents
 */

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #16161f;
    --bg-card-hover: #1c1c28;
    --bg-table-header: #1a1a24;
    --bg-table-row-hover: #1e1e2a;
    --border-color: #2a2a3a;
    --border-hover: #f7931a;
    
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #6a6a7a;
    
    --accent-gold: #f7931a;
    --accent-gold-light: #fdb340;
    --accent-glow: rgba(247, 147, 26, 0.3);
    
    --success: #00d4aa;
    --danger: #ff4757;
    --warning: #ffc107;
    
    --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', 'Monaco', 'Courier New', monospace;
}

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

body {
    font-family: var(--font-main);
    color: var(--text-primary);
    min-height: 100vh;
    position: relative;
    background: 
        linear-gradient(135deg, #0a0a0f 0%, #0f0f18 25%, #12101a 50%, #0d0d14 75%, #0a0a0f 100%);
}

/* Animated gradient orbs */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: 
        radial-gradient(circle at 20% 20%, rgba(247, 147, 26, 0.12) 0%, transparent 25%),
        radial-gradient(circle at 80% 30%, rgba(139, 92, 246, 0.08) 0%, transparent 20%),
        radial-gradient(circle at 70% 80%, rgba(247, 147, 26, 0.1) 0%, transparent 25%),
        radial-gradient(circle at 10% 70%, rgba(59, 130, 246, 0.06) 0%, transparent 20%),
        radial-gradient(circle at 50% 50%, rgba(247, 147, 26, 0.05) 0%, transparent 40%);
    animation: float 20s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(2%, 2%) rotate(1deg); }
    50% { transform: translate(0, 3%) rotate(0deg); }
    75% { transform: translate(-2%, 1%) rotate(-1deg); }
}

/* Grid pattern overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(rgba(247, 147, 26, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(247, 147, 26, 0.03) 1px, transparent 1px);
    background-size: 50px 50px;
    pointer-events: none;
    z-index: 0;
    opacity: 0.5;
}

/* Navigation */
.navbar {
    background: rgba(18, 18, 26, 0.8);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.navbar > div {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.navbar a {
    color: var(--text-secondary);
    text-decoration: none;
    margin-right: 1.5rem;
    transition: color 0.2s;
    font-weight: 500;
}

.navbar a:hover {
    color: var(--accent-gold);
}

.navbar a.active {
    color: var(--accent-gold);
    position: relative;
}

.navbar a.active::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent-gold);
    border-radius: 2px;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

h1 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 1.75rem;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.tab {
    padding: 0.75rem 1.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
    font-size: 0.95rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.tab:hover {
    border-color: var(--accent-gold);
    color: var(--text-primary);
}

.tab.active {
    background: linear-gradient(135deg, var(--accent-gold) 0%, var(--accent-gold-light) 100%);
    border-color: var(--accent-gold);
    color: var(--bg-primary);
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    border-color: var(--border-hover);
    box-shadow: 0 0 20px var(--accent-glow);
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent-gold);
    font-family: var(--font-mono);
}

.stat-value.profit {
    color: var(--success);
}

.stat-value.loss {
    color: var(--danger);
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Profitability chart */
.profitability-chart-container {
    width: 100%;
    margin-top: 2rem;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    width: 100%;
}

.chart-card h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

#profitability-chart {
    max-height: 400px;
    width: 100% !important;
    height: 400px !important;
}

@media (max-width: 768px) {
    .profitability-chart-container {
        margin-top: 1rem;
    }
    
    #profitability-chart {
        height: 300px !important;
        max-height: 300px;
    }
    
    .chart-card {
        padding: 1rem;
    }
    
    .chart-card h3 {
        font-size: 0.95rem;
        margin-bottom: 0.75rem;
    }
    
    /* Адаптация заголовка и кнопки сброса для мобильных */
    .chart-card > div:first-child {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    
    .chart-card > div:first-child h3 {
        margin: 0;
    }
    
    #reset-lines-button {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
        width: 100%;
    }
}

/* Strategy stats */
.strategy-stats {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    width: 100%;
}

.strategy-stats h3 {
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.strategy-row {
    display: grid;
    grid-template-columns: minmax(200px, 1fr) minmax(80px, 1fr) minmax(80px, 1fr) minmax(80px, 1fr) minmax(80px, 1fr) minmax(100px, 1fr);
    align-items: center;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border-color);
    gap: 1.5rem;
    width: 100%;
}

.strategy-row:last-child {
    border-bottom: none;
}

.strategy-name {
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.95rem;
}

.strategy-row span {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.strategy-win-rate {
    color: var(--success) !important;
    font-weight: 700;
    font-family: var(--font-mono);
    text-align: right;
    font-size: 0.95rem;
}

/* Strategy table header */
.strategy-header {
    display: grid;
    grid-template-columns: minmax(200px, 1fr) minmax(80px, 1fr) minmax(80px, 1fr) minmax(80px, 1fr) minmax(80px, 1fr) minmax(100px, 1fr);
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 2px solid var(--border-color);
    gap: 1.5rem;
    margin-bottom: 0.5rem;
    width: 100%;
}

.strategy-header span {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* Filters */
.filters {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.filters input,
.filters select {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.6rem 1rem;
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.filters input:focus,
.filters select:focus {
    outline: none;
    border-color: var(--accent-gold);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.filters input::placeholder {
    color: var(--text-muted);
}

/* Table wrapper for horizontal scroll */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
    -webkit-tap-highlight-color: transparent;
}

/* Table */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

th,
td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    background: var(--bg-table-header);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    user-select: none;
}

th:hover {
    color: var(--text-primary);
}

th.sorted {
    color: var(--accent-gold);
}

tr {
    transition: background 0.15s;
}

tr:hover {
    background: var(--bg-table-row-hover);
}

td strong {
    color: var(--text-primary);
}

/* Status colors */
.status-profit {
    color: var(--success);
    font-weight: 600;
}

.status-loss {
    color: var(--danger);
    font-weight: 600;
}

.status-demo {
    color: #58a6ff;
    font-weight: 600;
    font-size: 0.85rem;
}

.status-real {
    color: #ffa657;
    font-weight: 600;
    font-size: 0.85rem;
}

.status-empty {
    color: var(--text-muted);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.pagination button {
    padding: 0.6rem 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

.pagination button:hover:not(:disabled) {
    border-color: var(--accent-gold);
    color: var(--accent-gold);
}

.pagination button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination span {
    color: var(--text-muted);
}

/* Loading state */
.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
    position: relative;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-gold);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 0.5rem;
    vertical-align: middle;
}

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

/* Session selector */
.session-selector {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 2rem;
}

.session-selector h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
    font-size: 1rem;
}

.session-list {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.session-item {
    padding: 1rem 1rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    width: 180px;
    min-width: 180px;
    max-width: 180px;
    flex: 0 0 180px;
    box-sizing: border-box;
}

.session-item:hover {
    border-color: var(--accent-gold);
    background: var(--bg-card-hover);
}

.session-item.active {
    border-color: var(--success);
    background: rgba(0, 212, 170, 0.08);
    box-shadow: 0 0 15px rgba(0, 212, 170, 0.2);
}

.session-item .session-type {
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.session-item .session-date {
    font-size: 0.85rem;
    line-height: 1.25;
    height: 1.5em;
    color: var(--text-muted);
    min-width: 100%;
    white-space: pre;
}

/* Responsive */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .strategy-row {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .navbar {
        padding: 0.75rem 1rem;
    }

    .navbar a {
        margin-right: 0.75rem;
        font-size: 0.9rem;
    }

    .tabs {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .tab {
        padding: 0.6rem 1.25rem;
        font-size: 0.9rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Адаптивность для блока прибыльности от депозита */
    #profitability-stats-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Адаптивность для блока ставок */
    #rates-grid {
        grid-template-columns: 1fr !important;
    }

    .filters {
        flex-direction: column;
    }

    .filters input,
    .filters select {
        width: 100%;
        font-size: 16px;
    }

    .session-list {
        flex-direction: column;
    }

    .session-item {
        width: 100%;
        min-width: 0;
        flex: 0 0 auto;
    }
    
    /* Таблицы стратегий - горизонтальный скролл */
    .strategy-stats {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .strategy-stats #strategy-list {
        min-width: 800px;
    }
    
    .strategy-header,
    .strategy-row {
        min-width: 800px;
    }
    
    /* Мобильная версия таблицы - горизонтальный скролл */
    #positions-section {
        position: relative;
    }
    
    #positions-table {
        min-width: 1200px;
        display: table;
    }
    
    #positions-table th,
    #positions-table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.85rem;
    }
    
    #positions-table th {
        font-size: 0.75rem;
    }
    
    /* Пагинация фиксированная, не скроллится */
    .pagination {
        position: relative;
        width: 100%;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .pagination button {
        flex: 1;
        min-width: 100px;
    }
    
    .pagination span {
        width: 100%;
        text-align: center;
        order: -1;
    }

    .pagination button {
        min-height: 44px;
    }

    #stats-section .demo-only-stats > div:first-child {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    #stats-section .demo-only-stats > div:first-child > div {
        flex-direction: column !important;
        align-items: flex-start !important;
        width: 100%;
    }

    #strategy-profitability-chart {
        max-height: 280px !important;
    }

    .strategy-profitability-chart-container .chart-card > div:first-child {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .strategy-profitability-chart-container .chart-card > div:first-child > div {
        width: 100%;
    }

    .strategy-profitability-chart-container select,
    .strategy-profitability-chart-container button {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0.75rem;
    }

    .navbar a {
        margin-right: 0.5rem;
        font-size: 0.85rem;
    }

    h1 {
        font-size: 1.35rem;
    }

    .subtitle {
        font-size: 0.85rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .tab {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
        width: 100%;
    }

    .tabs {
        flex-direction: column;
    }

    #positions-table th,
    #positions-table td {
        padding: 0.5rem 0.35rem;
        font-size: 0.75rem;
    }

    #positions-table th {
        font-size: 0.7rem;
    }

    #positions-table {
        min-width: 1000px;
    }
}

/* Hide demo-only elements for REAL sessions */
body.real-session .demo-only-stats,
body.real-session .demo-only-tab {
    display: none !important;
}
