/* ============================================================================
   Tables Styles
   - Standard table styles
   - Mobile table view
   - Open positions table
   - Pagination
   - Sorting indicators
   ============================================================================ */

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid rgba(102, 126, 234, 0.1);
    color: #cbd5e1;
}

body.light-theme th,
body.light-theme td {
    color: #334155;
}

th {
    background: rgba(15, 23, 34, 0.6);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9em;
}

body.light-theme th {
    background: rgba(248, 250, 252, 0.8);
}

tr:hover {
    background: rgba(102, 126, 234, 0.05);
}

/* Open Positions Table Column Widths */
#openTradesTable th:nth-child(1),
#openTradesTable td:nth-child(1) {
    min-width: 120px;
    white-space: nowrap;
}

#openTradesTable th:nth-child(2),
#openTradesTable td:nth-child(2) {
    min-width: 85px;
}

#openTradesTable th:nth-child(3),
#openTradesTable td:nth-child(3) {
    min-width: 60px;
}

#openTradesTable th:nth-child(4),
#openTradesTable td:nth-child(4) {
    min-width: 60px;
}

#openTradesTable th:nth-child(5),
#openTradesTable td:nth-child(5) {
    min-width: 95px;
}

#openTradesTable th:nth-child(6),
#openTradesTable td:nth-child(6) {
    min-width: 110px;
}

#openTradesTable th:nth-child(7),
#openTradesTable td:nth-child(7) {
    min-width: 90px;
}

#openTradesTable th:nth-child(8),
#openTradesTable td:nth-child(8) {
    min-width: 70px;
}

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.pagination-info {
    color: var(--text-secondary);
    font-size: 0.9em;
}

.pagination-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

.pagination-button {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.3s;
    color: var(--text-primary);
}

.pagination-button:hover:not(:disabled) {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: rgba(102, 126, 234, 0.4);
}

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

.page-numbers {
    display: flex;
    gap: 5px;
}

.page-number {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.3s;
    color: var(--text-primary);
}

.page-number.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: rgba(102, 126, 234, 0.4);
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
}

.page-number:hover:not(.active) {
    background: rgba(102, 126, 234, 0.1);
    border-color: rgba(102, 126, 234, 0.3);
}

.expandable-row {
    cursor: pointer;
}

.expandable-row:hover {
    background: rgba(255, 255, 255, 0.05);
}

.detail-row {
    background: rgba(255, 255, 255, 0.02);
    display: none;
}

.detail-row.show {
    display: table-row;
}

.detail-row td {
    padding-left: 40px;
}

/* Mobile Table View for Summary */
.mobile-table-view {
    display: none;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-table {
    width: 100%;
    min-width: 700px;
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 60px var(--shadow), 0 10px 30px rgba(102, 126, 234, 0.1);
    border: 1px solid var(--border-color);
    transition: background 0.3s;
}

.mobile-table-header {
    display: grid;
    grid-template-columns: 0.6fr 2.5fr 1.2fr 0.8fr 1fr 1.2fr 1.2fr 1fr 1.2fr;
    gap: 8px;
    padding: 12px 8px;
    background: rgba(15, 23, 34, 0.6);
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

body.light-theme .mobile-table-header {
    background: rgba(248, 250, 252, 0.8);
}

.mobile-table-header > div {
    text-align: left;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.mobile-table-header > div:hover {
    color: #667eea;
}

.sort-indicator {
    font-size: 10px;
    color: var(--text-secondary);
    opacity: 0.3;
}

.sort-indicator.active {
    opacity: 1;
    color: var(--text-secondary);
    font-weight: bold;
}

.mobile-table-row {
    display: grid;
    grid-template-columns: 0.6fr 2.5fr 1.2fr 0.8fr 1fr 1.2fr 1.2fr 1fr 1.2fr;
    gap: 8px;
    padding: 12px 8px;
    border-bottom: 1px solid rgba(102, 126, 234, 0.1);
    cursor: pointer;
    transition: background 0.2s;
}

.mobile-table-row:hover {
    background: rgba(102, 126, 234, 0.05);
}

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

.mobile-cell {
    font-size: 14px;
    display: flex;
    align-items: center;
    text-align: left;
    justify-content: flex-start;
    color: var(--text-primary);
}

.mobile-cell.name-cell {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

.name-main {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1.1em;
}

.name-updated {
    font-size: 12px;
    color: var(--text-secondary);
}

.mobile-cell.name {
    font-weight: 600;
    color: var(--text-primary);
}

.mobile-cell.gain,
.mobile-cell.profit {
    font-weight: 600;
}

.mobile-cell.positive,
.mobile-cell.gain.positive,
.mobile-cell.profit.positive {
    color: #48bb78 !important;
}

.mobile-cell.negative,
.mobile-cell.gain.negative,
.mobile-cell.profit.negative {
    color: #f56565 !important;
}

.mobile-cell.updated {
    font-size: 12px;
    color: #94a3b8;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    table {
        font-size: 0.85em;
    }

    th, td {
        padding: 8px 4px;
    }

    /* Open Positions table - adjust for mobile */
    #openTradesTable th:nth-child(1),
    #openTradesTable td:nth-child(1) {
        min-width: 110px;
        font-size: 0.85em;
        padding: 8px 6px;
    }

    #openTradesTable th,
    #openTradesTable td {
        font-size: 0.85em;
    }

    .pagination {
        flex-direction: column;
        gap: 15px;
    }

    .pagination-buttons {
        width: 100%;
        justify-content: center;
    }

    .pagination-button {
        flex: 0 1 auto;
        font-size: 0.85em;
        padding: 8px 12px;
        white-space: nowrap;
    }

    .page-numbers {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Mobile table view - fixed column widths */
    .mobile-table-header,
    .mobile-table-row {
        grid-template-columns: 35px 140px 90px 70px 75px 85px 85px 70px 85px;
    }
}

/* Secondary UTC sub-line under broker time in trades / positions tables.
   Renders as a small muted line underneath the primary time. */
.trade-time-utc {
    font-size: 0.75em;
    color: var(--text-secondary);
    opacity: 0.8;
}
