/* ═══════════════════════════════════════════════════════════════
   Mobile Responsive — iPhone 17 Pro (393×852) + all phones
   ═══════════════════════════════════════════════════════════════ */

/* Safe areas for notch/dynamic island */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* ─── Phone (max-width: 768px) ─── */
@media (max-width: 768px) {
    /* Body */
    body {
        padding-top: var(--safe-top);
        padding-bottom: var(--safe-bottom);
        overflow: hidden;
    }

    /* Toolbar: compact */
    .chart-toolbar {
        height: 40px;
        padding: 0 8px;
        padding-top: var(--safe-top);
        gap: 2px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .toolbar-drag-zone {
        gap: 2px;
        padding: 0 60px 0 4px;
    }

    .toolbar-item .toolbar-btn {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }

    /* Instrument selector: smaller */
    .instrument-selector {
        gap: 1px;
    }

    .inst-btn {
        width: 28px;
        height: 24px;
    }

    .inst-icon {
        font-size: 0.6rem;
        padding: 1px 3px;
    }

    /* Timeframe buttons: smaller */
    .tf-btn {
        padding: 3px 6px;
        font-size: 0.7rem;
    }

    /* Hide separator on mobile */
    .toolbar-separator {
        display: none;
    }

    /* Logo smaller */
    .toolbar-logo-fixed .yai-text {
        font-size: 1rem;
    }

    /* Stats bar: hide on mobile */
    .stats-bar {
        display: none;
    }

    /* Chart: full width */
    .center-panel {
        width: 100%;
    }

    .chart-area {
        height: calc(100vh - 40px - var(--safe-top) - var(--safe-bottom));
    }

    #chart-container {
        height: 100% !important;
        min-height: 300px;
    }

    /* Right panel: fullscreen overlay on mobile */
    .right-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 100vw !important;
        max-width: 100vw !important;
        z-index: 2000;
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .right-panel:not(.collapsed) {
        transform: translateX(0);
    }

    .right-panel.collapsed {
        transform: translateX(100%);
    }

    /* Panel body: full height with scroll */
    .atp-body {
        height: calc(100vh - 50px - var(--safe-top));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(20px + var(--safe-bottom));
    }

    /* Signal box: compact */
    .atp-sig-prices {
        flex-wrap: wrap;
    }

    /* Account card: compact */
    .atp-ac-metrics {
        flex-wrap: wrap;
    }

    .atp-metric {
        min-width: 45%;
    }

    /* Modals: fullscreen on mobile */
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    /* Dropdown: full width */
    .instrument-dropdown {
        left: 4px !important;
        right: 4px !important;
        width: auto !important;
    }

    /* Mobile menu button */
    .mobile-menu-toggle {
        display: flex !important;
    }
}

/* ─── iPhone 17 Pro specific (393px width) ─── */
@media (max-width: 430px) {
    .chart-toolbar {
        height: 38px;
    }

    /* Only show 3 instrument buttons + dropdown */
    .instrument-selector .inst-btn:nth-child(n+4):not(.dropdown-trigger) {
        display: none;
    }

    /* Timeframes: only show key ones */
    .timeframe-group .tf-btn:not(.active):not(.dropdown-trigger) {
        display: none;
    }

    .timeframe-group .tf-btn.active,
    .timeframe-group .tf-btn.dropdown-trigger {
        display: flex;
    }

    /* Panel header compact */
    .atp-header {
        padding: 8px 10px;
    }

    /* Larger touch targets */
    .atp-sig-btn {
        min-height: 44px;
        font-size: 0.9rem;
    }

    .atp-pos-btn {
        min-height: 40px;
    }
}

/* ─── Landscape mode ─── */
@media (max-height: 500px) and (orientation: landscape) {
    .chart-toolbar {
        height: 34px;
    }

    .chart-area {
        height: calc(100vh - 34px);
    }

    .right-panel {
        width: 50vw !important;
    }

    .atp-body {
        height: calc(100vh - 40px);
    }
}

/* ─── Touch improvements ─── */
@media (hover: none) and (pointer: coarse) {
    /* Larger tap targets */
    .toolbar-btn,
    .inst-btn,
    .tf-btn {
        min-width: 36px;
        min-height: 36px;
    }

    /* No hover effects on touch */
    .toolbar-btn:hover,
    .inst-btn:hover,
    .tf-btn:hover {
        background: transparent;
    }

    /* Prevent text selection on tap */
    .atp-header,
    .atp-body,
    .chart-toolbar {
        -webkit-user-select: none;
        user-select: none;
    }

    /* Smooth scrolling */
    .atp-body,
    .atp-trades-content {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
}

/* ─── PWA standalone mode ─── */
@media (display-mode: standalone) {
    body {
        padding-top: var(--safe-top);
    }

    .chart-toolbar {
        padding-top: var(--safe-top);
    }
}

/* ─── Safe area fixes ─── */
.toast-container-minimal {
    bottom: calc(20px + var(--safe-bottom)) !important;
}

@media (max-width: 768px) {
    /* Prevent iOS auto-zoom on input focus */
    input, select, textarea {
        font-size: 16px !important;
    }

    /* Modal safe area padding */
    .modal-content {
        padding-bottom: var(--safe-bottom);
    }

    /* Body scroll lock when modal open */
    body.modal-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }
}

@media (max-width: 430px) {
    /* Notification panel width for iPhone */
    .notification-panel {
        width: calc(100vw - 20px) !important;
        right: 10px !important;
    }
}
