/* ============================================================
   mobile-terminal.css — TradingView-quality mobile overrides
   Loaded AFTER styles.css to override terminal mobile UX
   Target: 375px (iPhone SE) → 430px (iPhone 15 Pro Max)
   ============================================================ */

/* ============================================================
   1. TOP NAVIGATION — compact 44px, icons-only
   ============================================================ */

@media (max-width: 768px) {
    .app-nav {
        height: 44px;
        padding: 0 10px;
        gap: 8px;
    }

    /* Smaller logo on mobile */
    .app-nav-logo {
        font-size: 0; /* Hide text */
        gap: 0;
    }
    img.app-nav-logo-icon {
        width: 24px !important;
        height: 24px !important;
    }

    /* Current pair label in nav */
    .mobile-current-pair {
        font-size: 13px;
        font-weight: 700;
        letter-spacing: -0.3px;
        margin-left: 6px;
    }

    /* Hamburger: ensure 44px touch target */
    .mobile-nav-hamburger {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-left: auto;
    }

    /* Nav links overlay: account for smaller nav */
    .app-nav-links {
        top: 44px;
    }

    /* Hide desktop-only nav items */
    .app-nav-right {
        display: none !important;
    }

    .cmd-palette-hint {
        display: none;
    }
}


/* ============================================================
   2. MOBILE LAYOUT CONTAINER — fill viewport precisely
   ============================================================ */

@media (max-width: 768px) {
    .mobile-layout-container {
        top: 44px; /* Match compact nav */
        bottom: calc(52px + env(safe-area-inset-bottom, 0px));
    }
}


/* ============================================================
   3. CHART OVERLAY BAR — [TF dropdown] [Symbol centered] [ƒx btn]
   Compact 36px, hide non-essential elements
   ============================================================ */

@media (max-width: 768px) {
    /* Hide overlay bar inside mobile tab content —
       mobile-chart-header replaces it */
    .mobile-tab-content .chart-overlay-bar {
        display: none !important;
    }

    /* Standalone (non-mobile-tab) overlay bar: compact layout */
    .chart-overlay-bar {
        height: 36px;
        padding: 2px 6px !important;
        gap: 4px !important;
        align-items: center;
        overflow: visible;
    }

    /* Hide elements not needed on mobile overlay bar */
    .chart-star-btn,
    .chart-fav-chips,
    .chart-share-btn,
    .chart-compare-dropdown,
    .chart-close-btn {
        display: none !important;
    }

    /* TF dropdown — left side, compact */
    .chart-tf-dropdown {
        flex-shrink: 0 !important;
        margin-left: 0 !important;
        order: 1;
    }
    .chart-tf-toggle {
        padding: 4px 8px !important;
        font-size: 11px !important;
        min-height: 28px;
        line-height: 1.2;
    }
    .chart-tf-menu {
        min-width: 120px;
    }
    .chart-tf-option {
        padding: 10px 14px !important;
        min-height: 44px !important; /* Touch target */
        font-size: 13px !important;
        display: flex;
        align-items: center;
    }
    .chart-tf-group-label {
        padding: 8px 14px 4px;
    }

    /* Symbol — centered, fills space */
    .chart-title-label {
        flex: 1 !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        order: 2;
        min-height: 32px;
        padding: 2px 6px !important;
    }
    .chart-title-symbol {
        font-size: 13px !important;
    }
    .chart-title-exchange {
        font-size: 9px;
    }

    /* ƒx / indicator button — right side */
    .chart-overlay-bar .panel-header-btn {
        order: 3;
        flex-shrink: 0 !important;
        min-width: 36px;
        min-height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}


/* ============================================================
   4. MOBILE CHART HEADER — symbol + TF strip
   ============================================================ */

@media (max-width: 768px) {
    .mobile-chart-header {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 4px 6px;
        background: var(--bg-elevated);
        border-bottom: 1px solid var(--border-subtle);
        flex-shrink: 0;
        min-height: 40px;
    }

    /* Symbol selector button */
    .mobile-chart-symbol {
        font-size: 12px;
        font-weight: 700;
        padding: 4px 8px;
        min-height: 32px;
        border-radius: 4px;
        flex-shrink: 0;
    }
}


/* ============================================================
   5. MOBILE TF STRIP — horizontal scroll, compact buttons
   ============================================================ */

@media (max-width: 768px) {
    .mobile-tf-strip {
        display: flex;
        gap: 3px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex: 1;
        min-width: 0;
        flex-wrap: nowrap;
        align-items: center;
    }
    .mobile-tf-strip::-webkit-scrollbar {
        display: none;
    }

    .mobile-tf-btn {
        flex-shrink: 0;
        min-width: 32px;
        height: 32px;
        padding: 6px 10px;
        font-size: 11px;
        font-weight: 500;
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid var(--border-subtle);
        border-radius: 4px;
        color: var(--text-secondary);
        font-family: var(--font-mono);
        cursor: pointer;
        transition: all 0.12s;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
    }

    .mobile-tf-btn.active {
        background: #22c55e !important;
        color: #000 !important;
        border-color: #22c55e !important;
        font-weight: 700;
    }

    .mobile-tf-btn:active {
        opacity: 0.7;
    }
}


/* ============================================================
   6. MOBILE TAB BAR (bottom) — 52px, safe area, green active
   ============================================================ */

@media (max-width: 768px) {
    .mobile-tab-bar {
        height: 52px !important;
        background: #080808 !important;
        border-top: 1px solid var(--border-subtle);
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    }

    .mobile-tab {
        height: 52px;
        gap: 2px;
        padding: 4px 2px;
        min-width: 52px;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .mobile-tab-icon {
        width: 22px;
        height: 22px;
    }
    .mobile-tab-icon svg {
        width: 18px;
        height: 18px;
    }

    .mobile-tab-label {
        font-size: 11px;
        letter-spacing: 0.2px;
    }

    /* Active tab: green */
    .mobile-tab.active {
        color: #22c55e;
    }
    .mobile-tab.active::after {
        background: #22c55e;
    }

    /* Pressed state */
    .mobile-tab:active {
        background: rgba(34, 197, 94, 0.06);
    }
}


/* ============================================================
   7. MOBILE CHART SIZING — fill available space
   ============================================================ */

@media (max-width: 768px) {
    /* Tab content fills between nav and tab bar */
    .mobile-tab-content {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    /* Widget content fills tab */
    .mobile-widget-content {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    /* Canvas container fills widget */
    .mobile-widget-content > div {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    /* Prevent any scrolling on chart tab */
    .mobile-tab-content[data-tab="chart"] {
        overflow: hidden !important;
    }
}


/* ============================================================
   8. TOUCH INTERACTIONS — 44px+ tap targets
   ============================================================ */

@media (max-width: 768px) {
    /* All buttons: minimum touch target */
    .mobile-chart-symbol,
    .mobile-tf-btn,
    .mobile-tab,
    .mobile-more-item,
    .mobile-back-btn,
    .mobile-wl-add-btn,
    .chart-tf-toggle,
    .chart-overlay-bar .panel-header-btn {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        user-select: none;
        -webkit-user-select: none;
    }

    /* Ensure 44px min on critical interactive elements */
    .mobile-more-item {
        min-height: 48px;
    }

    .mobile-wl-row {
        min-height: 52px;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
}


/* ============================================================
   9. TICKER STRIP — hide on mobile
   ============================================================ */

@media (max-width: 768px) {
    .ticker-strip {
        display: none;
    }
}


/* ============================================================
   10. COMMAND PALETTE — mobile optimizations
   ============================================================ */

@media (max-width: 768px) {
    .cmd-palette-overlay {
        padding-top: 20px;
        align-items: flex-start;
    }

    .cmd-palette {
        max-width: 100vw;
        border-radius: 0;
        max-height: 100vh;
    }

    .cmd-palette-input {
        font-size: 16px; /* Prevent iOS zoom */
    }

    .cmd-palette-item {
        padding: 12px 16px;
        min-height: 44px;
    }
}


/* ============================================================
   11. SETTINGS DROPDOWN — mobile positioning
   ============================================================ */

@media (max-width: 768px) {
    .settings-dropdown .settings-menu {
        position: fixed !important;
        top: 44px !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        max-width: 100vw !important;
        border-radius: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        z-index: 10001;
    }
}


/* ============================================================
   12. CHART SEARCH MODAL — fullscreen on mobile
   ============================================================ */

@media (max-width: 768px) {
    .chart-search-overlay {
        padding: 0 !important;
    }

    .chart-search-modal {
        max-width: 100vw !important;
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }

    .chart-search-input {
        font-size: 16px !important; /* Prevent iOS zoom */
        min-height: 44px;
    }

    .chart-search-item {
        min-height: 44px;
        padding: 10px 14px;
    }
}


/* ============================================================
   13. MOBILE WATCHLIST — polish
   ============================================================ */

@media (max-width: 768px) {
    .mobile-wl-header {
        padding: 10px 14px;
        min-height: 44px;
    }

    .mobile-wl-row {
        padding: 10px 14px;
        min-height: 52px;
    }

    .mobile-wl-price {
        font-size: 13px;
        font-weight: 600;
    }

    .mobile-wl-change {
        font-size: 11px;
        font-weight: 600;
        min-width: 56px;
        text-align: right;
    }

    .mobile-wl-symbol {
        font-size: 13px;
        font-weight: 700;
    }
}


/* ============================================================
   14. ORDERBOOK / TRADE TAPE — mobile tweaks
   ============================================================ */

@media (max-width: 768px) {
    /* Orderbook: tighter density on mobile */
    .ob-row {
        font-size: 11px;
        min-height: 22px;
    }

    .ob-header {
        font-size: 9px;
        padding: 4px 8px;
    }

    .ob-spread {
        font-size: 10px;
        padding: 4px 8px;
    }

    /* Trade tape rows */
    .tt-row {
        font-size: 10px;
        min-height: 20px;
    }

    .tt-header {
        font-size: 9px;
        padding: 4px 8px;
    }
}


/* ============================================================
   15. DEPTH CHART — mobile sizing
   ============================================================ */

@media (max-width: 768px) {
    .depth-chart-container {
        min-height: 200px;
    }
}


/* ============================================================
   16. MOBILE MORE MENU — polish
   ============================================================ */

@media (max-width: 768px) {
    .mobile-more-list {
        padding: 8px;
        gap: 4px;
    }

    .mobile-more-item {
        padding: 14px 16px;
        border-radius: 8px;
        min-height: 48px;
    }

    .mobile-subview-header {
        min-height: 44px;
    }

    .mobile-back-btn {
        min-width: 44px;
        min-height: 44px;
    }
}


/* ============================================================
   17. MOBILE TRADE CTA
   ============================================================ */

@media (max-width: 768px) {
    .mobile-trade-cta {
        padding: 24px 16px;
        text-align: center;
    }

    .mobile-trade-cta-icon {
        font-size: 32px;
        margin-bottom: 8px;
    }

    .mobile-trade-cta-text {
        font-size: 14px;
        font-weight: 600;
        margin-bottom: 4px;
    }

    .mobile-trade-cta-sub {
        font-size: 12px;
        color: var(--text-muted);
    }
}


/* ============================================================
   18. MOBILE FAB — adjusted for 52px tab bar
   ============================================================ */

@media (max-width: 768px) {
    .mobile-fab {
        width: 40px;
        height: 40px;
        font-size: 22px;
    }
}


/* ============================================================
   19. DRAWING TOOLBAR — hidden on mobile (JS also hides it)
   ============================================================ */

@media (max-width: 768px) {
    .drawing-toolbar {
        display: none !important;
    }
}


/* ============================================================
   20. INDICATOR LEGEND — compact on mobile
   ============================================================ */

@media (max-width: 768px) {
    .overlay-legend {
        top: 2px;
        left: 4px;
        gap: 4px;
        max-width: calc(100vw - 16px);
        flex-wrap: wrap;
    }

    .overlay-legend-item {
        font-size: 9px;
    }
}


/* ============================================================
   21. PREVENT iOS RUBBER-BAND / OVERSCROLL on terminal
   ============================================================ */

@media (max-width: 768px) {
    .page-terminal {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    .page-terminal #terminal {
        height: 100%;
        overflow: hidden;
    }
}


/* ============================================================
   22. LANDSCAPE PHONE — ultra-compact
   ============================================================ */

@media (max-width: 768px) and (max-height: 500px) {
    .app-nav {
        height: 36px;
    }

    .mobile-layout-container {
        top: 36px;
    }

    .mobile-tab-bar {
        height: 44px !important;
    }

    .mobile-tab {
        height: 44px;
    }

    .mobile-tab-label {
        display: none;
    }
}
