/**
 * Mobile Tables & Orderbook CSS
 *
 * Makes data tables and orderbooks mobile-friendly:
 * - Simplified orderbook view on mobile
 * - Horizontal scroll for complex tables
 * - Collapsible sections
 * - Card-based layouts for mobile
 */

/* ==========================================================================
   Mobile Orderbook - Simplified View
   ========================================================================== */

@media (max-width: 768px) {
    /* Hide full orderbook on mobile by default */
    .orderbook-full {
        display: none;
    }

    /* Show mobile orderbook summary */
    .orderbook-mobile {
        display: block;
    }

    /* Orderbook Summary Card */
    .orderbook-summary {
        display: flex;
        justify-content: space-between;
        align-items: stretch;
        gap: 8px;
        padding: 12px;
        background: rgba(255, 255, 255, 0.03);
        border-radius: 12px;
        margin-bottom: 12px;
    }

    .orderbook-summary-item {
        flex: 1;
        text-align: center;
        padding: 12px 8px;
        background: rgba(255, 255, 255, 0.02);
        border-radius: 8px;
    }

    .orderbook-summary-item.bid {
        border-left: 3px solid #00ff88;
    }

    .orderbook-summary-item.ask {
        border-left: 3px solid #ff4444;
    }

    .orderbook-summary-item.spread {
        border-left: 3px solid #ffcc00;
    }

    .orderbook-summary-label {
        font-size: 11px;
        color: rgba(255, 255, 255, 0.5);
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-bottom: 6px;
    }

    .orderbook-summary-value {
        font-size: 16px;
        font-weight: 600;
        color: #fff;
    }

    .orderbook-summary-value.bid {
        color: #00ff88;
    }

    .orderbook-summary-value.ask {
        color: #ff4444;
    }

    /* Expand button */
    .expand-orderbook-btn {
        width: 100%;
        padding: 12px;
        background: rgba(0, 150, 255, 0.1);
        border: 1px solid rgba(0, 150, 255, 0.3);
        border-radius: 8px;
        color: #00cfff;
        font-size: 14px;
        font-weight: 500;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-height: 44px;
        transition: all 0.2s ease;
    }

    .expand-orderbook-btn:active {
        background: rgba(0, 150, 255, 0.2);
    }

    .expand-orderbook-btn svg {
        width: 16px;
        height: 16px;
        transition: transform 0.3s ease;
    }

    .expand-orderbook-btn.expanded svg {
        transform: rotate(180deg);
    }

    /* Expanded orderbook on mobile */
    .orderbook-expandable {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    .orderbook-expandable.expanded {
        max-height: 400px;
        margin-top: 12px;
    }

    /* Compact orderbook rows for mobile */
    .orderbook-rows-compact {
        max-height: 300px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .orderbook-row-compact {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 12px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        font-size: 13px;
    }

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

    .orderbook-row-compact.bid .orderbook-price {
        color: #00ff88;
    }

    .orderbook-row-compact.ask .orderbook-price {
        color: #ff4444;
    }

    .orderbook-price {
        font-weight: 600;
        min-width: 70px;
    }

    .orderbook-amount {
        color: rgba(255, 255, 255, 0.7);
        text-align: center;
        flex: 1;
    }

    .orderbook-total {
        color: rgba(255, 255, 255, 0.5);
        text-align: right;
        min-width: 70px;
    }

    /* Original orderbook - make more compact on mobile when shown */
    .orderbook {
        padding: 12px;
    }

    .orderbook .panel-title {
        font-size: 12px;
        margin-bottom: 10px;
    }

    .orderbook-header {
        font-size: 11px; /* iOS min accessibility */
        padding-bottom: 8px;
    }

    .orderbook-row {
        font-size: 11px;
        padding: 6px 0;
    }

    .orderbook-rows {
        max-height: 150px;
    }
}

/* Desktop - hide mobile orderbook */
@media (min-width: 769px) {
    .orderbook-mobile {
        display: none;
    }

    .orderbook-full {
        display: block;
    }
}

/* ==========================================================================
   Time & Sales - Mobile Optimized
   ========================================================================== */

@media (max-width: 768px) {
    .time-sales,
    .trades-list {
        padding: 12px;
    }

    .time-sales .panel-title,
    .trades-list .panel-title {
        font-size: 12px;
        margin-bottom: 10px;
    }

    /* Card-based layout for trades on mobile */
    .trade-item-mobile {
        display: flex;
        flex-direction: column;
        padding: 12px;
        background: rgba(255, 255, 255, 0.02);
        border-radius: 8px;
        margin-bottom: 8px;
    }

    .trade-item-mobile:last-child {
        margin-bottom: 0;
    }

    .trade-item-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 8px;
    }

    .trade-item-time {
        font-size: 11px;
        color: rgba(255, 255, 255, 0.5);
    }

    .trade-item-symbol {
        font-size: 13px;
        font-weight: 600;
        color: #fff;
        padding: 4px 8px;
        background: rgba(0, 150, 255, 0.15);
        border-radius: 4px;
    }

    .trade-item-details {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .trade-item-address {
        font-size: 11px;
        color: rgba(255, 255, 255, 0.4);
        font-family: monospace;
    }

    .trade-item-amount {
        font-size: 14px;
        font-weight: 600;
        color: #00cfff;
    }

    /* Compact trade row */
    .trade-row-compact {
        display: grid;
        grid-template-columns: 60px 1fr auto;
        gap: 8px;
        padding: 8px 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        font-size: 12px;
        align-items: center;
    }

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

/* ==========================================================================
   Horizontal Scroll Container
   ========================================================================== */

.table-scroll-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.table-scroll-container::-webkit-scrollbar {
    height: 6px;
}

.table-scroll-container::-webkit-scrollbar-track {
    background: transparent;
}

.table-scroll-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.table-scroll-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

@media (max-width: 768px) {
    .table-scroll-container {
        margin: 0 -12px;
        padding: 0 12px;
    }

    .table-scroll-container table {
        min-width: 500px;
    }
}

/* ==========================================================================
   Collapsible Sections
   ========================================================================== */

.collapsible-section {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.collapsible-section.expanded {
    max-height: 1000px;
    transition: max-height 0.5s ease-in;
}

.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.collapsible-header:active {
    background: rgba(255, 255, 255, 0.05);
}

.collapsible-arrow {
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease;
}

.collapsible-header.expanded .collapsible-arrow {
    transform: rotate(180deg);
}

/* ==========================================================================
   Data Cards (Mobile alternative to tables)
   ========================================================================== */

@media (max-width: 768px) {
    .data-card {
        background: rgba(255, 255, 255, 0.03);
        border-radius: 12px;
        padding: 16px;
        margin-bottom: 12px;
    }

    .data-card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 12px;
        padding-bottom: 12px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .data-card-title {
        font-size: 14px;
        font-weight: 600;
        color: #fff;
    }

    .data-card-badge {
        font-size: 11px;
        padding: 4px 8px;
        border-radius: 4px;
        background: rgba(0, 150, 255, 0.15);
        color: #00cfff;
    }

    .data-card-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
    }

    .data-card-label {
        font-size: 12px;
        color: rgba(255, 255, 255, 0.5);
    }

    .data-card-value {
        font-size: 13px;
        font-weight: 500;
        color: #fff;
    }
}

/* ==========================================================================
   Panel Grid - Mobile Stack
   ========================================================================== */

@media (max-width: 768px) {
    .panel-grid,
    .panels-row,
    .right-panel {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .panel,
    .orderbook,
    .position-panel,
    .recent-markets {
        width: 100%;
        margin: 0;
    }

    /* Make panels collapsible on mobile */
    .panel-collapsible .panel-content {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    .panel-collapsible.expanded .panel-content {
        max-height: 500px;
    }

    .panel-collapsible .panel-title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        cursor: pointer;
        padding: 12px 0;
    }

    .panel-collapsible .panel-title::after {
        content: '';
        width: 0;
        height: 0;
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
        border-top: 5px solid rgba(255, 255, 255, 0.5);
        transition: transform 0.3s ease;
    }

    .panel-collapsible.expanded .panel-title::after {
        transform: rotate(180deg);
    }
}

/* ==========================================================================
   Leaderboard Tables - Mobile
   ========================================================================== */

@media (max-width: 768px) {
    .leaderboard-table {
        width: 100%;
    }

    .leaderboard-row {
        display: flex;
        align-items: center;
        padding: 12px;
        gap: 12px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }

    .leaderboard-rank {
        width: 24px;
        height: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        font-weight: 700;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.1);
        flex-shrink: 0;
    }

    .leaderboard-rank.gold {
        background: linear-gradient(135deg, #ffd700, #ffb800);
        color: #000;
    }

    .leaderboard-rank.silver {
        background: linear-gradient(135deg, #c0c0c0, #a0a0a0);
        color: #000;
    }

    .leaderboard-rank.bronze {
        background: linear-gradient(135deg, #cd7f32, #a56629);
        color: #fff;
    }

    .leaderboard-info {
        flex: 1;
        min-width: 0;
    }

    .leaderboard-name {
        font-size: 14px;
        font-weight: 600;
        color: #fff;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .leaderboard-address {
        font-size: 11px;
        color: rgba(255, 255, 255, 0.4);
        font-family: monospace;
    }

    .leaderboard-value {
        font-size: 14px;
        font-weight: 600;
        color: #00ff88;
        text-align: right;
        flex-shrink: 0;
    }
}

/* ==========================================================================
   Market Cards - Mobile Grid
   ========================================================================== */

@media (max-width: 768px) {
    .market-grid {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .market-card {
        display: flex;
        flex-direction: column;
        padding: 16px;
        background: rgba(255, 255, 255, 0.03);
        border-radius: 12px;
        border: 1px solid rgba(255, 255, 255, 0.05);
    }

    .market-card-image {
        width: 100%;
        height: 120px;
        object-fit: cover;
        border-radius: 8px;
        margin-bottom: 12px;
    }

    .market-card-title {
        font-size: 14px;
        font-weight: 600;
        color: #fff;
        margin-bottom: 8px;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .market-card-stats {
        display: flex;
        gap: 16px;
        font-size: 12px;
        color: rgba(255, 255, 255, 0.6);
    }

    .market-card-stat {
        display: flex;
        align-items: center;
        gap: 4px;
    }
}
