/**
 * Professional Tables CSS
 * Consistent table styling with fixed column widths for perfect alignment
 */

:root {
    /* Table color scheme */
    --table-bg: transparent;
    --table-header-bg: rgba(255, 255, 255, 0.02);
    --table-header-border: rgba(255, 255, 255, 0.08);
    --table-row-border: rgba(255, 255, 255, 0.05);
    --table-row-hover: rgba(93, 79, 232, 0.05);
    --table-text-primary: #ffffff;
    --table-text-secondary: #9ca3af;
    --table-text-muted: #6b7280;
    
    /* Status colors */
    --status-success: #22c55e;
    --status-danger: #ef4444;
    --status-warning: #f59e0b;
    --status-info: #3b82f6;
    --status-primary: #5d4fe8;
}

/* Base table container */
.professional-table-container {
    width: 100%;
    overflow-x: auto;
    position: relative;
    border-radius: 12px;
    background: var(--card-bg);
}

/* Scrollbar styling */
.professional-table-container::-webkit-scrollbar {
    height: 8px;
    background: rgba(255, 255, 255, 0.02);
}

.professional-table-container::-webkit-scrollbar-thumb {
    background: rgba(93, 79, 232, 0.3);
    border-radius: 4px;
}

.professional-table-container::-webkit-scrollbar-thumb:hover {
    background: rgba(93, 79, 232, 0.5);
}

/* Base professional table */
.professional-orders-table {
    width: 100%;
    min-width: 1000px; /* Minimum width to prevent squishing */
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
    font-family: 'Inter', sans-serif;
}

/* Column width definitions for All Orders table */
.orders-table-all {
    --col-date: 150px;
    --col-pair: 100px;
    --col-type: 90px;
    --col-side: 70px;
    --col-price: 110px;
    --col-amount: 110px;
    --col-filled: 80px;
    --col-total: 120px;
    --col-status: 100px;
    --col-action: 90px;
}

/* Column width definitions for Order History table */
.orders-table-history {
    --col-date: 150px;
    --col-pair: 100px;
    --col-type: 90px;
    --col-side: 70px;
    --col-price: 100px;
    --col-avg-price: 100px;
    --col-amount: 110px;
    --col-filled: 80px;
    --col-total: 120px;
    --col-status: 100px;
}

/* Column width definitions for Trade History table */
.trades-table {
    --col-date: 150px;
    --col-pair: 100px;
    --col-type: 80px;
    --col-side: 70px;
    --col-price: 110px;
    --col-amount: 110px;
    --col-pnl: 130px;
    --col-status: 90px;
    --col-total: 120px;
}

/* Column width definitions for Positions table */
.positions-table {
    --col-symbol: 120px;
    --col-side: 80px;
    --col-size: 100px;
    --col-entry: 110px;
    --col-mark: 110px;
    --col-margin: 100px;
    --col-pnl: 110px;
    --col-roe: 90px;
    --col-liq: 120px;
    --col-action: 90px;
}

/* Table headers */
.professional-orders-table thead {
    background: var(--table-header-bg);
    position: sticky;
    top: 0;
    z-index: 10;
}

.professional-orders-table thead tr {
    border-bottom: 2px solid var(--table-header-border);
}

.professional-orders-table thead th {
    padding: 16px 12px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--table-text-secondary);
    background: transparent;
    border: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sortable headers */
.professional-orders-table thead th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}

.professional-orders-table thead th.sortable:hover {
    color: var(--table-text-primary);
}

.professional-orders-table thead th.sortable i {
    margin-left: 6px;
    font-size: 10px;
    opacity: 0.5;
    transition: all 0.2s;
}

.professional-orders-table thead th.sortable.sort-asc i,
.professional-orders-table thead th.sortable.sort-desc i {
    opacity: 1;
    color: var(--status-primary);
}

.professional-orders-table thead th.sortable.sort-asc i:before {
    content: "\f0de"; /* fa-sort-up */
}

.professional-orders-table thead th.sortable.sort-desc i:before {
    content: "\f0dd"; /* fa-sort-down */
}

/* Align specific columns */
.professional-orders-table thead th.text-right,
.professional-orders-table tbody td.text-right {
    text-align: right;
    padding-right: 16px;
}

.professional-orders-table thead th.text-center,
.professional-orders-table tbody td.text-center {
    text-align: center;
}

/* Table body */
.professional-orders-table tbody tr {
    border-bottom: 1px solid var(--table-row-border);
    transition: background 0.2s;
}

.professional-orders-table tbody tr:hover {
    background: var(--table-row-hover);
}

.professional-orders-table tbody td {
    padding: 14px 12px;
    font-size: 14px;
    color: var(--table-text-primary);
    background: transparent;
    border: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Specific column styling */
.professional-orders-table .col-date {
    font-size: 13px;
    color: var(--table-text-secondary);
    font-family: 'JetBrains Mono', monospace;
}

.professional-orders-table .col-pair {
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

.professional-orders-table .col-price,
.professional-orders-table .col-amount,
.professional-orders-table .col-total {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
}

.professional-orders-table .col-side-buy {
    color: var(--status-success);
    font-weight: 600;
    text-transform: uppercase;
}

.professional-orders-table .col-side-sell {
    color: var(--status-danger);
    font-weight: 600;
    text-transform: uppercase;
}

/* Status badges */
.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.status-badge.status-filled {
    background: rgba(34, 197, 94, 0.15);
    color: var(--status-success);
}

.status-badge.status-new,
.status-badge.status-pending {
    background: rgba(245, 158, 11, 0.15);
    color: var(--status-warning);
}

.status-badge.status-cancelled,
.status-badge.status-rejected {
    background: rgba(239, 68, 68, 0.15);
    color: var(--status-danger);
}

.status-badge.status-partially-filled {
    background: rgba(59, 130, 246, 0.15);
    color: var(--status-info);
}

/* Type badges */
.type-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    background: rgba(93, 79, 232, 0.1);
    color: var(--status-primary);
}

/* P&L styling */
.pnl-positive {
    color: var(--status-success);
    font-weight: 600;
}

.pnl-negative {
    color: var(--status-danger);
    font-weight: 600;
}

.pnl-container {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.pnl-amount {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

.pnl-percentage {
    font-size: 11px;
    opacity: 0.8;
}

.pnl-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    margin-top: 2px;
}

.pnl-badge.win {
    background: rgba(34, 197, 94, 0.2);
    color: var(--status-success);
}

.pnl-badge.loss {
    background: rgba(239, 68, 68, 0.2);
    color: var(--status-danger);
}

/* Action buttons */
.table-action-btn {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid;
}

.table-action-btn.btn-cancel {
    background: rgba(239, 68, 68, 0.1);
    color: var(--status-danger);
    border-color: rgba(239, 68, 68, 0.2);
}

.table-action-btn.btn-cancel:hover {
    background: rgba(239, 68, 68, 0.2);
    transform: translateY(-1px);
}

.table-action-btn.btn-close {
    background: rgba(239, 68, 68, 0.1);
    color: var(--status-danger);
    border-color: rgba(239, 68, 68, 0.2);
}

.table-action-btn.btn-close:hover {
    background: rgba(239, 68, 68, 0.2);
    transform: translateY(-1px);
}

/* Filled percentage */
.filled-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filled-bar-bg {
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.filled-bar-fill {
    height: 100%;
    background: var(--status-success);
    transition: width 0.3s;
}

.filled-percentage {
    font-size: 12px;
    font-weight: 500;
    color: var(--table-text-secondary);
}

/* Empty state */
.table-empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--table-text-secondary);
}

.table-empty-icon {
    font-size: 64px;
    margin-bottom: 24px;
    opacity: 0.3;
}

.table-empty-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--table-text-primary);
}

.table-empty-message {
    font-size: 14px;
    opacity: 0.8;
    max-width: 400px;
    margin: 0 auto 24px;
}

.table-empty-action {
    display: inline-block;
    padding: 10px 24px;
    background: var(--status-primary);
    color: white;
    border-radius: 8px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
}

.table-empty-action:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(93, 79, 232, 0.3);
}

/* Loading skeleton */
.table-skeleton {
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes skeleton-pulse {
    0%, 100% {
        opacity: 0.4;
    }
    50% {
        opacity: 0.7;
    }
}

.table-skeleton-row {
    height: 52px;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.05) 0%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0.05) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-wave 1.5s ease-in-out infinite;
    margin-bottom: 1px;
}

@keyframes skeleton-wave {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Pagination controls */
.table-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-top: 1px solid var(--table-row-border);
}

.table-pagination-info {
    font-size: 13px;
    color: var(--table-text-secondary);
}

.table-pagination-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.table-pagination-btn {
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--table-row-border);
    border-radius: 6px;
    color: var(--table-text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.table-pagination-btn:hover:not(:disabled) {
    background: rgba(93, 79, 232, 0.1);
    border-color: rgba(93, 79, 232, 0.3);
}

.table-pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.table-pagination-btn.active {
    background: var(--status-primary);
    border-color: var(--status-primary);
    color: white;
}

/* Mobile responsive - Card layout */
@media (max-width: 1200px) {
    .professional-orders-table {
        min-width: 900px;
    }
    
    .professional-orders-table thead th,
    .professional-orders-table tbody td {
        padding: 12px 8px;
        font-size: 13px;
    }
}

@media (max-width: 768px) {
    .professional-table-container {
        display: none;
    }
    
    .mobile-cards-container {
        display: block;
    }
    
    .order-card {
        background: var(--card-bg);
        border: 1px solid var(--table-row-border);
        border-radius: 12px;
        padding: 16px;
        margin-bottom: 12px;
    }
    
    .order-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 12px;
        padding-bottom: 12px;
        border-bottom: 1px solid var(--table-row-border);
    }
    
    .order-card-pair {
        font-size: 16px;
        font-weight: 600;
        font-family: 'JetBrains Mono', monospace;
    }
    
    .order-card-body {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
    
    .order-card-item {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }
    
    .order-card-label {
        font-size: 11px;
        text-transform: uppercase;
        color: var(--table-text-secondary);
        letter-spacing: 0.3px;
    }
    
    .order-card-value {
        font-size: 14px;
        font-weight: 500;
        color: var(--table-text-primary);
    }
    
    .order-card-footer {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid var(--table-row-border);
    }
}

/* Desktop-only features */
@media (min-width: 769px) {
    .mobile-cards-container {
        display: none;
    }
}

/* Print styles */
@media print {
    .professional-orders-table {
        font-size: 10px;
    }
    
    .professional-orders-table thead {
        position: static;
    }
    
    .table-action-btn,
    .table-pagination {
        display: none;
    }
}