/* ===== CSS Custom Properties ===== */
:root {
    /* Colors */
    --bg-primary: #0a0b0d;
    --bg-secondary: #12141a;
    --bg-tertiary: #1a1d24;
    --bg-card: rgba(26, 29, 36, 0.7);
    --bg-hover: rgba(255, 255, 255, 0.05);
    
    --text-primary: #ffffff;
    --text-secondary: #a0a3b1;
    --text-muted: #6b6e7b;
    
    --accent-primary: #00d4aa;
    --accent-secondary: #00b894;
    --accent-gradient: linear-gradient(135deg, #00d4aa 0%, #00b894 100%);
    
    --green: #00d4aa;
    --green-dim: rgba(0, 212, 170, 0.15);
    --red: #ff4757;
    --red-dim: rgba(255, 71, 87, 0.15);
    --yellow: #ffa502;
    
    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(0, 212, 170, 0.3);
    
    /* Sizing */
    --header-height: 70px;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
    
    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px rgba(0, 212, 170, 0.2);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-secondary);
}

/* ===== App Container ===== */
.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: 
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 212, 170, 0.08) 0%, transparent 50%),
        var(--bg-primary);
}

/* ===== Header ===== */
.header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: rgba(10, 11, 13, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 24px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 36px;
    height: 36px;
    color: var(--accent-primary);
    filter: drop-shadow(0 0 8px rgba(0, 212, 170, 0.4));
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.logo h1 span {
    color: var(--text-secondary);
    font-weight: 400;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-radius: 20px;
    font-size: 0.85rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--yellow);
    animation: pulse 2s infinite;
}

.connection-status.connected .status-dot {
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
}

.connection-status.disconnected .status-dot {
    background: var(--red);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.last-update {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ===== Stats Bar ===== */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    padding: 20px 24px;
}

.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px 20px;
    transition: all var(--transition-normal);
}

.stat-card:hover {
    border-color: var(--border-glow);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    padding: 0 24px 24px;
}

/* ===== Controls (Tabs + Search) ===== */
.controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 20px;
}

.tabs {
    display: flex;
    gap: 8px;
    background: var(--bg-tertiary);
    padding: 4px;
    border-radius: var(--border-radius);
}

.tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: transparent;
    border: none;
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.tab svg {
    width: 18px;
    height: 18px;
}

.tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.tab.active {
    color: var(--bg-primary);
    background: var(--accent-gradient);
}

.search-container {
    position: relative;
    width: 300px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 10px 14px 10px 42px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
    transition: all var(--transition-fast);
}

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

.search-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 212, 170, 0.1);
}

/* ===== Tables ===== */
.table-container {
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    overflow: hidden;
}

.table-container.hidden {
    display: none;
}

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

.data-table thead {
    background: rgba(0, 0, 0, 0.3);
}

.data-table th {
    padding: 14px 16px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: color var(--transition-fast);
}

.data-table th.sortable:hover {
    color: var(--text-primary);
}

.data-table th.sortable span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.sort-icon {
    width: 14px;
    height: 14px;
    opacity: 0.3;
    transition: all var(--transition-fast);
}

.data-table th.sortable:hover .sort-icon {
    opacity: 0.6;
}

.data-table th.sortable.asc .sort-icon,
.data-table th.sortable.desc .sort-icon {
    opacity: 1;
    color: var(--accent-primary);
}

.data-table th.sortable.desc .sort-icon {
    transform: rotate(180deg);
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
    transition: background var(--transition-fast);
}

.data-table tbody tr {
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
    background: var(--bg-hover);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Market Column */
.market-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.market-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--accent-primary);
}

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

/* Price Cells */
.price-cell {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-weight: 500;
}

.price-up {
    animation: flashGreen 0.6s ease;
}

.price-down {
    animation: flashRed 0.6s ease;
}

@keyframes flashGreen {
    0%, 100% { background: transparent; }
    50% { background: var(--green-dim); }
}

@keyframes flashRed {
    0%, 100% { background: transparent; }
    50% { background: var(--red-dim); }
}

/* Change Cell */
.change-positive {
    color: var(--green);
}

.change-negative {
    color: var(--red);
}

.change-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
}

.change-badge.positive {
    background: var(--green-dim);
    color: var(--green);
}

.change-badge.negative {
    background: var(--red-dim);
    color: var(--red);
}

/* Leverage Badge */
.leverage-badge {
    display: inline-flex;
    padding: 4px 10px;
    background: rgba(255, 165, 2, 0.15);
    color: var(--yellow);
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
}

/* Funding Cell */
.funding-positive {
    color: var(--green);
}

.funding-negative {
    color: var(--red);
}

/* Volume/OI */
.volume-cell, .oi-cell {
    font-family: 'SF Mono', 'Fira Code', monospace;
    color: var(--text-secondary);
}

/* Loading State */
.loading-row td {
    text-align: center;
    padding: 60px 16px;
    color: var(--text-muted);
}

.loading-row td > * {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Empty State */
.empty-row td {
    text-align: center;
    padding: 60px 16px;
    color: var(--text-muted);
}

/* ===== Footer ===== */
.footer {
    padding: 20px 24px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
}

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

@media (max-width: 768px) {
    .header {
        padding: 0 16px;
        height: auto;
        flex-direction: column;
        gap: 12px;
        padding: 16px;
    }
    
    .header-left, .header-right {
        width: 100%;
        justify-content: center;
    }
    
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
        padding: 16px;
        gap: 12px;
    }
    
    .stat-card {
        padding: 12px 16px;
    }
    
    .stat-value {
        font-size: 1.2rem;
    }
    
    .main-content {
        padding: 0 16px 16px;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .tabs {
        width: 100%;
        justify-content: center;
    }
    
    .search-container {
        width: 100%;
    }
    
    .table-container {
        overflow-x: auto;
    }
    
    .data-table {
        min-width: 700px;
    }
}

@media (max-width: 480px) {
    .stats-bar {
        grid-template-columns: 1fr;
    }
    
    .logo h1 {
        font-size: 1rem;
    }
}
