/* ═══════════════════════════════════════════════════════
   Spot Trading Mobile Responsive — XT-style layout
   Form (left) + Order Book (right) side by side
   ═══════════════════════════════════════════════════════ */
@media only screen and (max-width: 768px) {

    /* ─── Reset ─── */
    * {
        box-sizing: border-box;
        -webkit-tap-highlight-color: transparent;
    }

    body {
        padding-bottom: 60px;
    }

    /* ─── Header — Hidden on mobile ─── */
    .dashboard-header {
        display: none !important;
    }

    .header-left,
    .header-right,
    .header-nav {
        display: none !important;
    }

    .breadcrumb {
        display: none !important;
    }

    .desktop-only {
        display: none !important;
    }

    /* ─── Hide chart, old mobile nav, market trades, market selector ─── */
    .chart-area .chart-container {
        display: none !important;
    }

    .mobile-nav {
        display: none !important;
    }

    #market-trades-tab {
        display: none !important;
    }

    .tabs-header {
        display: none !important;
    }

    .market-selector {
        display: none !important;
    }

    /* ─── Main Grid: [form | book] → orders ─── */
    .trading-content {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        grid-template-rows: 1fr auto !important;
        grid-template-areas:
            "form book"
            "orders orders" !important;
        height: auto !important;
        min-height: calc(100vh - 44px - 60px);
        padding: 0 !important;
        gap: 0 !important;
        background: var(--bg-primary);
    }

    /* ─── Ticker Bar ─── */
    .spot-ticker-bar {
        display: flex;
        align-items: center;
        padding: 6px 10px;
        gap: 14px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        border-bottom: 1px solid var(--border-light);
    }

    .spot-ticker-bar::-webkit-scrollbar {
        display: none;
    }

    .ticker-item.main-ticker {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-shrink: 0;
        padding-right: 12px;
        border-right: 1px solid var(--border-light);
    }

    .pair-with-icon {
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .market-icon {
        width: 18px;
        height: 18px;
    }

    .ticker-pair {
        font-size: 14px;
        font-weight: 700;
        white-space: nowrap;
        cursor: pointer;
    }

    .ticker-pair-arrow {
        font-size: 8px;
        margin-left: 3px;
        color: var(--text-muted);
    }

    .market-picker-dropdown {
        left: 0 !important;
        right: 0;
        width: 100% !important;
        max-height: 75vh;
        border-radius: 0 0 16px 16px;
    }

    .market-picker-dropdown.open {
        animation: _pickerMobileSlide 0.25s ease forwards;
    }

    @keyframes _pickerMobileSlide {
        from { opacity: 0; transform: translateY(-12px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    .picker-search {
        padding: 12px 16px;
    }

    .picker-search input {
        font-size: 15px;
    }

    .picker-tabs {
        padding: 8px 12px;
    }

    .picker-tab {
        padding: 8px 0;
        font-size: 12px;
    }

    .picker-list {
        max-height: calc(75vh - 110px);
        -webkit-overflow-scrolling: touch;
    }

    .picker-item {
        padding: 10px 16px;
        gap: 12px;
    }

    .picker-item-icon {
        width: 30px;
        height: 30px;
        font-size: 11px;
    }

    .picker-item-name {
        font-size: 14px;
    }

    .picker-item-change {
        font-size: 12px;
    }

    .ticker-price {
        font-size: 14px;
        font-weight: 700;
        padding: 2px 6px;
        border-radius: 4px;
        white-space: nowrap;
    }

    .ticker-stats {
        display: flex;
        gap: 14px;
        flex-shrink: 0;
    }

    .ticker-stat {
        display: flex;
        flex-direction: column;
        gap: 1px;
        flex-shrink: 0;
    }

    .stat-label {
        font-size: 8px;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        opacity: 0.6;
        white-space: nowrap;
    }

    .stat-value {
        font-size: 11px;
        font-weight: 600;
        white-space: nowrap;
    }

    /* ═════════════════════════════════════════════════════
       LEFT COLUMN — Trade Form
       ═════════════════════════════════════════════════════ */
    .right-column {
        grid-area: form !important;
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        order: unset !important;
        overflow: visible !important;
        border-right: 1px solid var(--border-light);
        background: var(--bg-primary);
    }

    .trading-forms-wrapper {
        background: var(--bg-primary);
    }

    .form-tabs {
        display: flex;
        border-bottom: 1px solid var(--border-light);
        background: var(--bg-secondary);
        position: sticky;
        top: 0;
        z-index: 5;
    }

    .form-tab {
        flex: 1;
        padding: 8px 0;
        font-size: 12px;
        font-weight: 600;
        min-height: 34px;
        position: relative;
        transition: color 0.2s;
    }

    .trading-form-container {
        padding: 8px !important;
    }

    .form-body {
        overflow: visible !important;
        max-height: none !important;
        display: flex;
        flex-direction: column;
        gap: 6px;
    }

    .balance-display {
        display: flex;
        align-items: center;
        gap: 4px;
        padding: 5px 8px;
        font-size: 11px;
        background: var(--bg-secondary);
        border-radius: 6px;
        border: 1px solid var(--border-light);
    }

    .balance-display .value {
        font-weight: 600;
        margin-left: auto;
    }

    .input-field {
        display: flex;
        align-items: center;
        padding: 0;
        min-height: 36px;
        border: 1px solid var(--border-light);
        border-radius: 6px;
        background: var(--bg-secondary);
        overflow: hidden;
        transition: border-color 0.2s;
    }

    .input-field:focus-within {
        border-color: var(--accent, #6366f1);
    }

    .input-field .field-label {
        padding: 0 8px;
        font-size: 11px;
        color: var(--text-muted);
        white-space: nowrap;
        min-width: 38px;
    }

    .input-field input {
        flex: 1;
        font-size: 13px;
        font-weight: 600;
        min-height: 36px;
        padding: 4px 0;
        border: none !important;
        background: transparent !important;
        text-align: right;
        color: var(--text-primary);
        -webkit-appearance: none;
    }

    .input-field .field-suffix {
        padding: 0 8px;
        font-size: 10px;
        color: var(--text-muted);
        white-space: nowrap;
        font-weight: 500;
    }

    /* Percentage buttons */
    .percent-selector {
        display: flex;
        gap: 3px;
    }

    .percent-btn {
        flex: 1;
        padding: 4px 2px;
        font-size: 10px;
        min-height: 26px;
        border-radius: 4px;
        font-weight: 600;
        border: 1px solid var(--border-light);
        background: var(--bg-secondary);
        color: var(--text-secondary);
        cursor: pointer;
        transition: all 0.15s ease;
    }

    .percent-btn:active {
        transform: scale(0.96);
    }

    .total-display {
        display: flex;
        align-items: center;
        gap: 4px;
        padding: 5px 8px;
        font-size: 11px;
    }

    .total-display .value {
        font-weight: 600;
        margin-left: auto;
    }

    .btn-execute {
        padding: 10px;
        font-size: 13px;
        font-weight: 700;
        min-height: 40px;
        border-radius: 6px;
        letter-spacing: 0.02em;
        margin-top: 2px;
    }

    .btn-execute:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    /* ═════════════════════════════════════════════════════
       RIGHT COLUMN — Order Book
       ═════════════════════════════════════════════════════ */
    .left-column {
        grid-area: book !important;
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        order: unset !important;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .left-column::-webkit-scrollbar {
        display: none;
    }

    .left-tabs-container {
        width: 100%;
    }

    .order-book {
        max-height: none;
    }

    .order-book-columns {
        display: flex;
        justify-content: space-between;
        font-size: 9px;
        padding: 4px 8px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--text-muted);
        border-bottom: 1px solid var(--border-light);
        font-weight: 600;
        position: sticky;
        top: 0;
        background: var(--bg-primary);
        z-index: 5;
    }

    .order-book-content {
        max-height: none;
        overflow-y: hidden;
    }

    .order-book-asks,
    .order-book-bids {
        max-height: 35vh;
        overflow-y: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .order-book-asks::-webkit-scrollbar,
    .order-book-bids::-webkit-scrollbar {
        display: none;
    }

    .order-book-row {
        font-size: 10px;
        padding: 2px 8px;
        min-height: 20px;
        font-family: 'Roboto Mono', monospace;
        display: flex;
        align-items: center;
    }

    .order-book-spread {
        padding: 5px 8px;
        font-size: 13px;
        font-weight: 700;
        display: flex;
        align-items: center;
        gap: 6px;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-light);
        border-bottom: 1px solid var(--border-light);
    }

    .spread-details {
        font-size: 10px;
        font-weight: 500;
        opacity: 0.6;
    }

    /* ═════════════════════════════════════════════════════
       BOTTOM — Open Orders (full width)
       ═════════════════════════════════════════════════════ */
    .chart-area {
        grid-area: orders !important;
        grid-column: 1 / -1 !important;
        order: unset !important;
        width: 100% !important;
    }

    .open-orders {
        border-top: 1px solid var(--border-light);
        background: var(--bg-secondary);
    }

    .orders-header {
        padding: 8px 10px;
        display: flex;
        align-items: center;
    }

    .orders-header h3 {
        font-size: 12px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.3px;
    }

    .orders-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-height: 250px;
        overflow-y: auto;
    }

    .orders-table {
        min-width: 580px;
        font-size: 10px;
    }

    .orders-table th,
    .orders-table td {
        padding: 6px 5px;
        white-space: nowrap;
        font-family: 'Roboto Mono', monospace;
    }

    .orders-table th {
        font-size: 9px;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        position: sticky;
        top: 0;
        background: var(--bg-secondary);
        z-index: 1;
        color: var(--text-muted);
    }

    .no-orders td {
        text-align: center;
        padding: 20px 6px !important;
        color: var(--text-muted);
        font-size: 12px;
        font-family: 'Inter', sans-serif;
    }

    /* ─── Modal ─── */
    .modalO {
        padding: 10px;
    }

    .modalO-content {
        width: 100% !important;
        max-width: none !important;
        max-height: 90vh;
        border-radius: 12px;
    }

    .modalO-header {
        padding: 14px 16px;
    }

    .modalO-body {
        padding: 12px 16px;
    }

    .modalO-actions {
        padding: 12px 16px;
        gap: 8px;
    }

    .confirm-row {
        font-size: 13px;
        padding: 8px 0;
    }

    /* ─── Toast ─── */
    .toast {
        bottom: 70px;
        right: 10px;
        left: 10px;
        width: auto;
        border-radius: 10px;
    }

    /* ─── Connection Status ─── */
    .connection-status {
        top: 50px;
        right: 8px;
        font-size: 11px;
        padding: 6px 10px;
    }
}

/* ─── Small Screens (≤480px) ─── */
@media only screen and (max-width: 480px) {

    .ticker-pair {
        font-size: 12px;
    }

    .ticker-price {
        font-size: 12px;
    }

    .ticker-stats {
        gap: 10px;
    }

    .stat-value {
        font-size: 10px;
    }

    .stat-label {
        font-size: 7px;
    }

    .order-book-row {
        font-size: 9px;
        padding: 2px 6px;
    }

    .order-book-columns {
        font-size: 8px;
    }

    .input-field {
        min-height: 34px;
    }

    .input-field input {
        font-size: 12px;
        min-height: 34px;
    }

    .input-field .field-label {
        font-size: 10px;
        padding: 0 6px;
    }

    .btn-execute {
        padding: 8px;
        font-size: 12px;
        min-height: 36px;
    }

    .percent-btn {
        font-size: 9px;
        padding: 3px 1px;
        min-height: 22px;
    }

    .balance-display {
        font-size: 10px;
        padding: 4px 6px;
    }

    .total-display {
        font-size: 10px;
        padding: 4px 6px;
    }

    /* Hide some columns on very small screens */
    .orders-table th:nth-child(6),
    .orders-table td:nth-child(6),
    .orders-table th:nth-child(7),
    .orders-table td:nth-child(7) {
        display: none;
    }

    .modalO-body {
        padding: 10px 12px;
    }

    .confirm-row {
        font-size: 12px;
    }
}

/* ─── Very Small Screens (320px) ─── */
@media only screen and (max-width: 320px) {
    .btn-execute {
        padding: 6px;
        font-size: 11px;
        min-height: 32px;
    }

    .order-book-row {
        font-size: 8px;
    }
}

/* ─── Landscape Orientation ─── */
@media only screen and (max-width: 768px) and (orientation: landscape) {
    .trading-content {
        min-height: auto;
    }

    body {
        padding-bottom: 60px;
    }
}

/* ─── Small Height Devices ─── */
@media only screen and (max-height: 600px) {
    .order-book-asks,
    .order-book-bids {
        max-height: 120px;
    }
}

/* ═══ PWA Standalone Mode — scoped to pwa-mode for browser parity ═══ */
html.pwa-mode .dashboard-header {
    display: none !important;
}