/* ═══════════════════════════════════════════════════════════════════
 * El3rrab Trading System — Unified Mobile Stylesheet
 *
 * Consolidates: mobile_responsive, mobile_menu, mobile_ux,
 *               mobile_v2, modal_filters_mobile, dxy_mobile_fix
 *
 * Sections:
 *   1. Mobile-only structural components (always-loaded shells)
 *   2. Tablet breakpoint (≤ 1024px)
 *   3. Mobile breakpoint (≤ 768px)
 *      3.1  Top bar / Mobile bar
 *      3.2  Hamburger drawer
 *      3.3  Header + DXY block
 *      3.4  Controls (search, scan, alerts)
 *      3.5  Sort & filter bar (collapsible)
 *      3.6  Results grid + cards
 *      3.7  Symbol modal: tabs, sub-tabs, sticky header
 *      3.8  Modal filters (Breakouts / Divergences / Patterns)
 *      3.9  Settings modal
 *      3.10 Telegram log modal
 *      3.11 Forms / inputs / touch targets
 *      3.12 Misc UX panels (insights, track-setup, plans, levels)
 *   4. Small phones (≤ 480px)
 *   5. Touch-device tweaks (hover:none, pointer:coarse)
 *   6. Desktop overrides (≥ 769px) — hide mobile-only shells
 * ═══════════════════════════════════════════════════════════════════ */


/* ═══════════════════════════════════════════════════════════════════
 * 1. Mobile-only structural components — hidden by default
 * ═══════════════════════════════════════════════════════════════════ */

.mobile-bar,
.mobile-drawer-overlay,
.mobile-filters-toggle,
.mobile-bottom-nav,
.mobile-pull-indicator {
    display: none;
}


/* ═══════════════════════════════════════════════════════════════════
 * 0. Global no-horizontal-overflow guard for mobile
 *    Some legacy DXY/strongest widgets ignored width constraints —
 *    this forces every container to clip rather than blow out the page.
 * ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    html, body {
        max-width: 100vw;
        overflow-x: hidden !important;
    }

    .container,
    .header,
    .header-content,
    .controls,
    .controls-alerts,
    .sort-filter-bar,
    .results-grid,
    .top-strongest-bar,
    .strongest-now,
    .quick-wins,
    .quick-wins-bar {
        max-width: 100% !important;
        box-sizing: border-box;
    }

    /* DXY block: ALWAYS fit viewport, scroll horizontally inside if needed */
    .header-dxy,
    div.header-dxy#header-dxy {
        max-width: calc(100vw - 24px) !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
    }

    /* Hide ALL pair badges + score badges + extra info inside DXY on mobile.
       Keeps just the big price (which is what fits on a phone). */
    .header-dxy .dxy-pairs-grid,
    .header-dxy .dxy-pair-badge,
    .header-dxy .dxy-score-badge,
    .header-dxy .dxy-strength-badge,
    .header-dxy .header-dxy-strength,
    .header-dxy .header-dxy-changes,
    .header-dxy .header-dxy-change,
    .header-dxy .header-dxy-label {
        display: none !important;
    }

    /* Strongest-now bar — let it scroll horizontally instead of overflowing */
    .top-strongest-bar,
    .strongest-now {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        flex-wrap: nowrap !important;
    }
    .top-strongest-bar > *,
    .strongest-now > * {
        flex-shrink: 0;
    }
}


/* ═══════════════════════════════════════════════════════════════════
 * 2. Tablet (≤ 1024px)
 * ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
    .container {
        padding: 12px !important;
    }

    .results-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }

    .header-content {
        flex-wrap: wrap;
        gap: 12px;
    }

    /* Modal filter bars compact slightly on tablet */
    .breakouts-stats-bar,
    .divergences-stats-bar,
    .patterns-stats-bar {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)) !important;
        gap: 6px !important;
        padding: 12px 16px !important;
    }

    .breakouts-filters,
    .div-filters,
    .patterns-filters {
        padding: 8px 16px !important;
        gap: 8px !important;
    }
}


/* ═══════════════════════════════════════════════════════════════════
 * 3. Mobile (≤ 768px)
 * ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

    /* ───────────── 3.1 Top bar / Mobile bar ───────────── */

    /* Hide the original cluttered top-bar on mobile */
    #top-bar {
        display: none !important;
    }

    /* Show compact mobile-bar (injected by mobile_menu.js) */
    .mobile-bar {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 8px 12px;
        background: var(--bg-card-solid, #161827);
        border-bottom: 1px solid var(--border, #2a2a3a);
        position: sticky;
        top: 0;
        z-index: 100;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        padding-top: max(8px, env(safe-area-inset-top));
    }

    .mobile-bar-btn {
        background: transparent;
        border: 1px solid var(--border, #2a2a3a);
        border-radius: 8px;
        width: 44px;
        height: 44px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        transition: all 0.2s;
    }

    .mobile-bar-btn:active {
        transform: scale(0.95);
        background: var(--bg-hover, rgba(255, 255, 255, 0.05));
    }

    .mobile-hamburger {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        width: 18px;
        height: 14px;
    }

    .mobile-hamburger span {
        display: block;
        height: 2px;
        width: 100%;
        background: var(--text, #fff);
        border-radius: 2px;
        transition: all 0.3s;
    }

    .mobile-bar-title {
        flex: 1;
        display: flex;
        align-items: center;
        gap: 6px;
        overflow: hidden;
    }

    .mobile-bar-logo {
        font-size: 18px;
        flex-shrink: 0;
    }

    .mobile-bar-name {
        font-size: 13px;
        font-weight: 700;
        color: var(--text, #fff);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-status-pulse {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #48bb78;
        flex-shrink: 0;
        animation: mobile-pulse 2s ease-in-out infinite;
    }

    @keyframes mobile-pulse {
        0%, 100% { box-shadow: 0 0 0 0 rgba(72, 187, 120, 0.5); }
        50%      { box-shadow: 0 0 0 4px rgba(72, 187, 120, 0); }
    }

    /* Top-bar's auto-update toggle (now lives in settings) */
    .top-bar .tb-toggle {
        display: none !important;
    }


    /* ───────────── 3.1.3 Floating-element collision fixes ─────────────
       Bottom nav is ~64px tall + safe-area inset. Anything fixed at the
       bottom must clear it, otherwise it covers the home/menu tabs. */

    /* Setups FAB is fully replaced by the bottom-nav "Setups" tab on mobile.
       Hide the FAB to avoid the duplicate red badge over the Home tab. */
    .setups-fab {
        display: none !important;
    }

    /* Floating DXY pill — push above the bottom nav */
    #header-dxy.floating {
        bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
    }


    /* ───────────── 3.1.4 Pull-to-refresh indicator ───────────── */

    .mobile-pull-indicator {
        display: flex !important;
        align-items: center;
        justify-content: center;
        gap: 8px;
        position: fixed;
        top: env(safe-area-inset-top, 0);
        left: 50%;
        transform: translate(-50%, -120px);
        z-index: 9999;
        padding: 10px 18px;
        border-radius: 24px;
        background: linear-gradient(135deg, #6366f1, #8b5cf6);
        color: #fff;
        font-size: 13px;
        font-weight: 700;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
        opacity: 0;
        pointer-events: none;
        transition: transform 0.15s ease-out, opacity 0.2s ease;
    }

    .mobile-pull-indicator.visible {
        opacity: 1;
    }

    .mobile-pull-indicator.refreshing .mpi-spinner {
        animation: mpi-spin 0.9s linear infinite;
    }

    .mobile-pull-indicator.success {
        background: linear-gradient(135deg, #10b981, #059669);
    }

    .mobile-pull-indicator.error {
        background: linear-gradient(135deg, #ef4444, #dc2626);
    }

    .mpi-spinner {
        font-size: 16px;
        line-height: 1;
        display: inline-block;
    }

    @keyframes mpi-spin {
        from { transform: rotate(0deg); }
        to   { transform: rotate(360deg); }
    }


    /* ───────────── 3.1.5 Bottom navigation bar ───────────── */

    .mobile-bottom-nav {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr);
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 90;
        background: var(--bg-card-solid, #161827);
        border-top: 1px solid var(--border, #2a2a3a);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        padding-bottom: env(safe-area-inset-bottom, 0);
        transform: translateY(0);
        transition: transform 0.25s ease, opacity 0.2s ease;
    }

    .mobile-bottom-nav.hidden {
        transform: translateY(110%);
        pointer-events: none;
        opacity: 0;
    }

    .mbn-tab {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 8px 4px;
        min-height: 56px;
        background: transparent;
        border: none;
        color: var(--text-muted, #999);
        font-family: inherit;
        font-size: 10px;
        font-weight: 600;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: color 0.15s, transform 0.08s;
    }

    .mbn-tab:active {
        transform: scale(0.92);
        color: var(--accent-primary, #6366f1);
    }

    .mbn-icon { font-size: 20px; line-height: 1; }
    .mbn-label { font-size: 10px; line-height: 1.1; }

    /* Push page content up so it isn't covered by the fixed bottom nav */
    body { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0)); }


    /* ───────────── 3.2 Hamburger drawer ───────────── */

    .mobile-drawer-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 9998;
        opacity: 0;
        transition: opacity 0.3s;
    }

    .mobile-drawer-overlay.show {
        display: block;
        opacity: 1;
    }

    .mobile-drawer {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 85%;
        max-width: 360px;
        background: var(--bg-card-solid, #161827);
        border-left: 1px solid var(--border, #2a2a3a);
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.4);
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        display: flex;
        flex-direction: column;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .mobile-drawer-overlay.show .mobile-drawer {
        transform: translateX(0);
    }

    .mobile-drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px;
        border-bottom: 1px solid var(--border, #2a2a3a);
        background: linear-gradient(180deg, rgba(99, 102, 241, 0.05), transparent);
        position: sticky;
        top: 0;
        z-index: 1;
        backdrop-filter: blur(10px);
    }

    .mobile-drawer-header h3 {
        margin: 0;
        font-size: 16px;
        color: var(--text, #fff);
    }

    .mobile-drawer-close {
        background: var(--bg-secondary, #1a1a2a);
        border: 1px solid var(--border, #2a2a3a);
        border-radius: 6px;
        width: 40px;
        height: 40px;
        color: var(--text, #fff);
        cursor: pointer;
        font-size: 14px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s;
    }

    .mobile-drawer-close:active {
        background: var(--bg-hover, #252535);
        transform: scale(0.92);
    }

    .mobile-drawer-body {
        flex: 1;
        padding: 16px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .mobile-section {
        margin-bottom: 20px;
    }

    .mobile-section-title {
        font-size: 12px;
        font-weight: 700;
        color: var(--text-muted, #999);
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-bottom: 10px;
        padding: 0 4px;
    }

    .mobile-cards-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .mobile-status-card {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 12px;
        background: var(--bg-secondary, #1a1a2a);
        border: 1px solid var(--border, #2a2a3a);
        border-radius: 10px;
        transition: all 0.2s;
    }

    .mobile-status-card.status-ok {
        border-color: rgba(72, 187, 120, 0.3);
        background: rgba(72, 187, 120, 0.05);
    }

    .mobile-status-card.status-bad {
        border-color: rgba(245, 101, 101, 0.3);
        background: rgba(245, 101, 101, 0.05);
    }

    .mobile-status-icon {
        font-size: 22px;
        flex-shrink: 0;
    }

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

    .mobile-status-label {
        font-size: 11px;
        color: var(--text-muted, #999);
        margin-bottom: 2px;
    }

    .mobile-status-value {
        font-size: 13px;
        font-weight: 700;
        color: var(--text, #fff);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-info-list {
        background: var(--bg-secondary, #1a1a2a);
        border: 1px solid var(--border, #2a2a3a);
        border-radius: 10px;
        overflow: hidden;
    }

    .mobile-info-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 16px;
        border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.05));
        font-size: 13px;
        min-height: 44px;
    }

    .mobile-info-row:last-child {
        border-bottom: none;
    }

    .mobile-info-row.mobile-clickable {
        cursor: pointer;
        transition: background 0.15s;
    }

    .mobile-info-row.mobile-clickable:active {
        background: var(--bg-hover, rgba(255, 255, 255, 0.05));
    }

    .mobile-info-label {
        color: var(--text-muted, #999);
    }

    .mobile-info-value {
        color: var(--text, #fff);
        font-weight: 600;
        text-align: left;
    }

    .mobile-mono {
        font-family: 'JetBrains Mono', monospace;
        font-size: 12px;
    }

    .mobile-actions-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .mobile-action-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        padding: 16px 8px;
        background: var(--bg-secondary, #1a1a2a);
        border: 1px solid var(--border, #2a2a3a);
        border-radius: 10px;
        cursor: pointer;
        transition: all 0.2s;
        color: var(--text, #fff);
        font-family: inherit;
        font-size: 12px;
        font-weight: 600;
        min-height: 64px;
    }

    .mobile-action-btn:active {
        transform: scale(0.95);
        background: var(--bg-hover, #252535);
        border-color: var(--accent-primary, #4a9eff);
    }

    .mobile-action-btn span:first-child {
        font-size: 22px;
    }


    /* ───────────── 3.3 Header + DXY block ───────────── */
    /* On mobile the .mobile-bar already shows the brand title, and the
       bottom nav has a Paper tab — so the original .header collapses to
       just a centered DXY pill. */

    .header {
        padding: 6px 10px !important;
        margin-bottom: 8px !important;
    }

    .header-content {
        gap: 8px !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Hide redundant header sections on mobile */
    .header-title,
    .header-paper,
    .header-paper-top,
    .header-paper-equity,
    .header-paper-positions,
    .header-paper-footer {
        display: none !important;
    }

    /* DXY: compact pill (price + arrow only) — high specificity overrides dxy_premium */
    .header .header-dxy,
    .header-content .header-dxy,
    div.header-dxy#header-dxy {
        min-width: auto !important;
        max-width: max-content !important;
        width: auto !important;
        padding: 6px 10px !important;
        gap: 4px !important;
        flex-direction: row !important;
        align-items: center !important;
        flex-shrink: 0 !important;
        overflow: hidden !important;
    }

    .header-dxy .header-dxy-value,
    div.header-dxy#header-dxy .header-dxy-value {
        display: inline-flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 4px !important;
        font-size: inherit !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .header-dxy .header-dxy-icon,
    div.header-dxy#header-dxy .header-dxy-icon {
        font-size: 0.95rem !important;
        line-height: 1 !important;
    }

    .header-dxy #header-dxy-price,
    div.header-dxy#header-dxy #header-dxy-price {
        font-size: 0.92rem !important;
        font-weight: 700 !important;
        line-height: 1 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .header-dxy .header-dxy-arrow,
    div.header-dxy#header-dxy .header-dxy-arrow {
        font-size: 0.85rem !important;
        line-height: 1 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Hide everything else in DXY block on mobile */
    .header-dxy-strength,
    .header-dxy-changes,
    .header-dxy-change,
    .header-dxy-label,
    .header-dxy::before,
    .header-dxy::after {
        display: none !important;
    }


    /* ───────────── 3.4 Controls (search, scan, alerts) ───────────── */

    .controls {
        flex-wrap: wrap !important;
        gap: 8px !important;
        padding: 8px !important;
    }

    .controls .btn {
        padding: 8px 12px !important;
        font-size: 0.85rem !important;
        flex: 1 1 auto;
        min-width: 100px;
    }

    .search-wrapper {
        width: 100% !important;
        flex: 1 1 100% !important;
        order: -1;
    }

    .search-input {
        font-size: 16px !important; /* prevents iOS zoom */
        padding: 10px 36px 10px 16px !important;
    }

    .controls-alerts {
        width: 100% !important;
        flex: 1 1 100% !important;
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 8px !important;
    }

    .ca-card {
        padding: 10px 8px !important;
        flex-direction: column !important;
        gap: 6px !important;
        text-align: center;
        min-width: 0 !important;
    }

    .ca-icon { font-size: 1.3rem !important; }
    .ca-info { width: 100%; }

    .ca-label {
        font-size: 0.65rem !important;
        line-height: 1.2 !important;
    }

    .ca-detail { display: none !important; }

    .ca-count {
        font-size: 1.2rem !important;
        font-weight: 700;
    }


    /* ───────────── 3.5 Sort & filter bar (collapsible) ───────────── */

    .sort-filter-bar {
        position: relative;
        padding: 8px !important;
        margin-bottom: 8px !important;
        background: rgba(15, 23, 42, 0.6) !important;
        border-radius: 10px !important;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    .mobile-filters-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        padding: 10px 14px;
        background: linear-gradient(135deg, #6366f1, #8b5cf6);
        color: #fff;
        border: none;
        border-radius: 8px;
        font-family: inherit;
        font-weight: 700;
        font-size: 0.9rem;
        cursor: pointer;
        min-height: 44px;
        transition: filter 0.15s ease, transform 0.08s ease;
    }

    .mobile-filters-toggle:active {
        transform: scale(0.98);
        filter: brightness(0.95);
    }

    .sort-filter-bar.mobile-expanded .mobile-filters-toggle {
        background: linear-gradient(135deg, #ef4444, #dc2626);
        margin-bottom: 8px;
    }

    .mft-caret {
        margin-inline-start: auto;
        font-size: 0.85rem;
        opacity: 0.85;
    }

    /* Collapsed: hide sections */
    .sort-filter-bar .sort-section,
    .sort-filter-bar .filter-section {
        display: none;
    }

    /* Expanded: show sections stacked */
    .sort-filter-bar.mobile-expanded .sort-section,
    .sort-filter-bar.mobile-expanded .filter-section {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        padding: 10px;
        background: rgba(0, 0, 0, 0.2);
        border-radius: 8px;
        margin-bottom: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .sort-divider { display: none !important; }

    .sort-filter-bar .sort-label {
        flex-basis: 100%;
        font-size: 0.78rem !important;
        color: #a78bfa !important;
        font-weight: 700;
        margin-bottom: 4px;
    }

    .sort-filter-bar .sort-btn,
    .sort-filter-bar .filter-btn,
    .sort-filter-bar .signal-filter-btn {
        padding: 6px 10px !important;
        font-size: 0.78rem !important;
        white-space: nowrap;
        flex: 0 1 auto;
        flex-shrink: 0;
        min-height: 36px;
    }

    .sort-filter-bar .filter-count {
        font-size: 0.7rem !important;
        padding: 1px 6px !important;
    }


    /* ───────────── 3.6 Results grid + cards ───────────── */

    .results-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .card,
    .symbol-card {
        padding: 12px !important;
    }

    .card-header {
        flex-wrap: wrap !important;
        margin-bottom: 8px !important;
    }

    .card-title,
    .symbol-name {
        font-size: 1.1rem !important;
        font-weight: 800 !important;
    }

    .card-price {
        font-size: 1.05rem !important;
        font-weight: 700 !important;
    }

    .narrator-badge {
        font-size: 0.78rem !important;
        padding: 4px 10px !important;
        border-radius: 6px !important;
    }

    .narrator-headline-mini {
        font-size: 0.78rem !important;
        line-height: 1.4 !important;
        margin-top: 4px !important;
    }

    .breakout-badge {
        font-size: 0.74rem !important;
        padding: 5px 8px !important;
        border-radius: 6px !important;
        margin-top: 6px !important;
    }

    .zone-row {
        font-size: 0.78rem !important;
        padding: 4px 6px !important;
    }

    .zone-price {
        font-size: 0.85rem !important;
        font-weight: 700;
    }

    .zone-meta { font-size: 0.7rem !important; }

    .card-meta {
        font-size: 0.72rem !important;
        gap: 4px !important;
    }

    .card-meta-item { padding: 2px 6px !important; }


    /* ───────────── 3.7 Symbol modal: tabs, sub-tabs, sticky header ───────────── */

    .modal-overlay { padding: 0 !important; }

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

    .modal-header {
        padding: 10px 12px !important;
        gap: 6px;
        align-items: center;
        position: sticky !important;
        top: 0;
        background: rgba(15, 23, 42, 0.98) !important;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        z-index: 100;
        border-bottom: 1px solid rgba(99, 102, 241, 0.15);
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .modal-header h2 {
        font-size: 1rem !important;
        font-weight: 700;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* 🆕 Compact live price for mobile modal header */
    .modal-title-row {
        gap: 8px !important;
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }
    .modal-live-price {
        font-size: 0.85rem !important;
        padding: 2px 7px !important;
        min-width: 70px !important;
    }

    .modal-header-actions {
        gap: 4px !important;
        display: flex;
        align-items: center;
    }

    .modal-action-btn,
    .modal-close {
        min-width: 40px !important;
        min-height: 40px !important;
        width: 40px !important;
        height: 40px !important;
        padding: 0 !important;
        font-size: 1rem !important;
        flex-shrink: 0;
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    .modal-body { padding: 12px !important; padding-top: 8px !important; }

    /* Modal tabs: icon-only (active expands to label).
       Pinned to the BOTTOM of the modal on mobile. .modal is flex-column,
       so order:99 + flex-shrink:0 puts the bar last and prevents squeeze.
       The body has flex:1 + overflow-y:auto, so it scrolls above the bar. */
    .modal-tabs {
        gap: 4px !important;
        padding: 6px 8px !important;
        background: rgba(15, 23, 42, 0.95) !important;
        border-radius: 0 !important;
        margin: 0 !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
        order: 99;
        flex-shrink: 0;
        position: static !important;       /* override desktop sticky:top */
        top: auto !important;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        z-index: 99;
        border-top: 1px solid rgba(99, 102, 241, 0.18);
        border-bottom: none !important;
        padding-bottom: max(6px, env(safe-area-inset-bottom)) !important;
    }

    .modal-tabs::-webkit-scrollbar {
        height: 0;
        display: none;
    }

    .modal-tabs .tab-btn[data-icon] {
        font-size: 0;
        padding: 9px 10px !important;
        flex: 0 0 auto;
        min-width: 44px;
        min-height: 40px;
        white-space: nowrap;
        text-align: center;
        position: relative;
        transition: min-width 0.25s ease, padding 0.25s ease;
    }

    .modal-tabs .tab-btn[data-icon]::before {
        content: attr(data-icon);
        font-size: 1.15rem;
        display: inline-block;
        line-height: 1;
    }

    .modal-tabs .tab-btn[data-icon].active::after {
        content: ' ' attr(data-label);
        font-size: 0.82rem;
        font-weight: 700;
        margin-right: 5px;
        color: #fff;
    }

    .modal-tabs .tab-btn[data-icon].active {
        min-width: max-content;
        padding: 9px 14px !important;
    }

    /* Tab buttons fallback (no data-icon) */
    .tab-btn {
        padding: 8px 12px !important;
        font-size: 0.8rem !important;
        white-space: nowrap;
        flex-shrink: 0;
        min-height: 40px;
    }

    /* Analysis sub-tabs */
    .analysis-subtabs {
        gap: 3px !important;
        padding: 3px !important;
    }

    .analysis-subtab-btn[data-icon] {
        font-size: 0;
        padding: 8px 10px !important;
        flex: 0 0 auto;
        min-width: 44px;
        min-height: 40px;
        white-space: nowrap;
        text-align: center;
        position: relative;
        transition: min-width 0.25s ease, padding 0.25s ease;
    }

    .analysis-subtab-btn[data-icon]::before {
        content: attr(data-icon);
        font-size: 1.1rem;
        display: inline-block;
        line-height: 1;
    }

    .analysis-subtab-btn[data-icon].active::after {
        content: ' ' attr(data-label);
        font-size: 0.78rem;
        font-weight: 700;
        margin-right: 5px;
        color: #fff;
    }

    .analysis-subtab-btn[data-icon].active {
        min-width: max-content;
        padding: 8px 14px !important;
    }


    /* ───────────── 3.8 Modal filters (Breakouts / Divergences / Patterns) ───────────── */

    .breakouts-stats-bar,
    .divergences-stats-bar,
    .patterns-stats-bar {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 4px !important;
        padding: 8px 10px !important;
    }

    .bs-stat-card,
    .div-stat-card,
    .patterns-stat-card {
        padding: 6px 4px !important;
        border-radius: 6px !important;
    }

    .bs-stat-label,
    .div-stat-label,
    .patterns-stat-label {
        font-size: 0.55rem !important;
        margin-bottom: 1px !important;
        line-height: 1.1 !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .bs-stat-value,
    .div-stat-value,
    .patterns-stat-value {
        font-size: 0.95rem !important;
        line-height: 1 !important;
    }

    .bs-stat-meta,
    .div-stat-meta,
    .patterns-stat-meta {
        font-size: 0.5rem !important;
        margin-top: 1px !important;
        line-height: 1.1 !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .breakouts-filters,
    .div-filters,
    .patterns-filters {
        display: flex !important;
        flex-direction: column !important;
        gap: 4px !important;
        padding: 6px 10px !important;
        background: rgba(15, 20, 33, 0.4) !important;
    }

    .bf-group,
    .div-filter-group,
    .patterns-filter-group {
        display: flex !important;
        align-items: center !important;
        gap: 4px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        flex-wrap: nowrap !important;
        padding-bottom: 2px;
        scrollbar-width: none;
    }

    .bf-group::-webkit-scrollbar,
    .div-filter-group::-webkit-scrollbar,
    .patterns-filter-group::-webkit-scrollbar {
        display: none;
    }

    .bf-label,
    .div-filter-label,
    .patterns-filter-label {
        font-size: 0.65rem !important;
        margin: 0 !important;
        flex-shrink: 0 !important;
        min-width: 38px !important;
        color: var(--text-muted) !important;
        font-weight: 600;
    }

    .bf-btn,
    .div-filter-btn,
    .patterns-filter-btn {
        padding: 4px 8px !important;
        font-size: 0.65rem !important;
        border-radius: 5px !important;
        flex-shrink: 0 !important;
        white-space: nowrap !important;
        min-height: 36px !important;
        line-height: 1.2 !important;
    }

    .bf-btn.active,
    .div-filter-btn.active,
    .patterns-filter-btn.active {
        background: var(--primary) !important;
        color: white !important;
        border-color: var(--primary) !important;
        font-weight: 700;
    }

    .breakouts-modal .modal-close,
    .divergences-modal .modal-close,
    .patterns-modal .modal-close {
        min-width: 40px;
        min-height: 40px;
        font-size: 1.3rem;
    }

    .breakouts-modal .modal-header,
    .divergences-modal .modal-header,
    .patterns-modal .modal-header {
        padding: 10px 14px !important;
    }

    .breakouts-modal .modal-header h2,
    .divergences-modal .modal-header h2,
    .patterns-modal .modal-header h2 {
        font-size: 0.95rem !important;
    }

    .breakouts-summary-bar {
        padding: 6px 10px !important;
        font-size: 0.75rem !important;
    }


    /* ───────────── 3.9 Settings modal ───────────── */

    .settings-modal { border-radius: 0 !important; }

    .settings-tabs {
        overflow-x: auto;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
    }

    .settings-tab-btn {
        flex-shrink: 0;
        font-size: 11px !important;
        padding: 8px 10px !important;
        min-height: 40px;
    }

    .settings-body { padding: 12px !important; }

    .set-section { padding: 12px !important; }

    .set-section-title { font-size: 13px !important; }

    .set-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 6px !important;
    }

    .set-input-label {
        min-width: 0 !important;
        width: 100%;
        font-size: 12px !important;
    }

    .set-input,
    .set-select {
        width: 100% !important;
    }

    .set-info-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .set-theme-grid,
    .set-checkbox-grid,
    .set-types-grid {
        grid-template-columns: 1fr !important;
    }

    .set-actions { flex-direction: column !important; }
    .set-btn { width: 100%; }


    /* ───────────── 3.10 Telegram log modal ───────────── */

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

    .tg-log-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .tg-log-stat-value { font-size: 18px !important; }
    .tg-log-entries { padding: 8px !important; }
    .tg-log-entry { padding: 8px !important; }


    /* ───────────── 3.11 Forms / inputs / touch targets ───────────── */

    /* WCAG 2.5.5 AA — primary touch targets ≥ 44×44 */
    button,
    input[type="button"],
    input[type="submit"],
    .btn {
        min-height: 44px;
    }

    /* Compact chips/toggles allowed slightly smaller */
    .filter-btn,
    .sort-btn,
    .signal-filter-btn,
    .bf-btn,
    .div-filter-btn,
    .patterns-filter-btn,
    .ap-btn {
        min-height: 36px;
    }

    /* Prevent iOS auto-zoom on focus (16px = no zoom threshold) */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Restore smaller input where readability isn't compromised */
    .set-input[type="number"],
    .set-cd-input {
        font-size: 14px !important;
    }


    /* ───────────── 3.12 Misc UX panels ───────────── */

    .quick-actions-bar {
        padding: 8px !important;
        gap: 5px !important;
        margin-bottom: 10px !important;
    }

    .qa-btn {
        padding: 7px 10px !important;
        font-size: 0.78rem !important;
        gap: 5px;
    }

    .qa-btn span:first-child { font-size: 0.95rem; }

    .smart-insights-section { padding: 10px !important; }

    .insight-card {
        padding: 10px !important;
        gap: 8px;
    }

    .insight-icon { font-size: 1.25rem; }
    .insight-title { font-size: 0.85rem; }
    .insight-body { font-size: 0.8rem; line-height: 1.5; }

    .track-setup-buttons {
        flex-direction: column;
        gap: 8px;
    }

    .track-btn {
        min-height: 56px;
        padding: 12px !important;
    }

    .track-btn-title { font-size: 0.95rem !important; }
    .track-btn-sub { font-size: 0.78rem !important; }

    .plans-grid,
    .narrator-points-grid,
    .analysis-grid {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    .collapsible-header { padding: 12px 14px !important; }
    .collapsible-title { font-size: 0.9rem !important; }

    .levels-grid { gap: 8px; }
    .levels-group { padding: 8px; }
    .levels-group-title { font-size: 0.78rem; }

    .ss-summary-banner { padding: 10px !important; }
    .ss-summary-text { font-size: 0.78rem !important; }
}


/* ═══════════════════════════════════════════════════════════════════
 * 4. Small phones (≤ 480px)
 * ═══════════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    .header { padding: 4px 6px !important; margin-bottom: 6px !important; }

    .header .header-dxy,
    div.header-dxy#header-dxy {
        padding: 5px 8px !important;
        gap: 3px !important;
    }

    .header-dxy #header-dxy-price,
    div.header-dxy#header-dxy #header-dxy-price {
        font-size: 0.85rem !important;
    }

    .header-dxy .header-dxy-icon { font-size: 0.85rem !important; }
    .header-dxy .header-dxy-arrow { font-size: 0.78rem !important; }

    .symbol-card { padding: 10px !important; }
    .symbol-name { font-size: 1rem !important; }
    .card-price { font-size: 0.95rem !important; }

    .ca-card { padding: 8px 4px !important; }
    .ca-icon { font-size: 1.1rem !important; }
    .ca-label { font-size: 0.6rem !important; }
    .ca-count { font-size: 1rem !important; }

    /* Keep only the first DXY change column on tiny screens */
    .header-dxy:not(.floating) .header-dxy-change:nth-child(n+2) {
        display: none !important;
    }

    /* Modal action buttons slightly smaller */
    .modal-action-btn,
    .modal-close {
        min-width: 38px !important;
        min-height: 38px !important;
        width: 38px !important;
        height: 38px !important;
        font-size: 0.9rem !important;
    }

    /* Modal tabs */
    .modal-tabs .tab-btn[data-icon] {
        min-width: 40px;
        padding: 7px 9px !important;
    }

    .modal-tabs .tab-btn[data-icon].active::after { font-size: 0.76rem; }

    .analysis-subtab-btn[data-icon] {
        min-width: 40px;
        padding: 7px 8px !important;
    }

    .analysis-subtab-btn[data-icon].active::after { font-size: 0.74rem; }

    .modal-header { padding: 8px 10px !important; }
    .modal-header h2 { font-size: 0.95rem !important; }

    /* Modal-filter stats: drop to 2 columns when 4 won't fit */
    .breakouts-stats-bar,
    .divergences-stats-bar,
    .patterns-stats-bar {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 4px !important;
    }

    .bs-stat-meta,
    .div-stat-meta,
    .patterns-stat-meta {
        display: none !important;
    }

    .bf-btn,
    .div-filter-btn,
    .patterns-filter-btn {
        padding: 3px 7px !important;
        font-size: 0.6rem !important;
    }

    .qa-btn {
        padding: 6px 8px !important;
        font-size: 0.72rem !important;
        min-width: 36px;
        justify-content: center;
    }

    .qa-btn span:nth-child(2) { display: none; }

    .set-tier-buttons { flex-direction: column !important; }
    .set-tier-btn { width: 100%; }
}


/* ═══════════════════════════════════════════════════════════════════
 * 5. Touch-device tweaks (hover:none, pointer:coarse)
 * ═══════════════════════════════════════════════════════════════════ */

@media (hover: none) and (pointer: coarse) {
    .tb-pill,
    .tb-item,
    .ca-card,
    .filter-btn,
    .sort-btn,
    .set-tier-btn,
    .set-checkbox,
    .set-type-btn {
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(99, 102, 241, 0.2);
    }

    /* Disable hover lift effects (they get stuck on touch) */
    .ca-card:hover,
    .tb-pill:hover,
    .filter-btn:hover,
    .qa-btn:hover,
    .modal-action-btn:hover,
    .insight-card:hover,
    .track-btn:hover,
    .collapsible-section:hover {
        transform: none !important;
    }

    /* Press-down feedback */
    .qa-btn:active,
    .modal-action-btn:active,
    .track-btn:active {
        transform: scale(0.96) !important;
        transition: transform 0.08s ease !important;
    }
}


/* ═══════════════════════════════════════════════════════════════════
 * 6. Desktop (≥ 769px) — hide mobile-only shells
 * ═══════════════════════════════════════════════════════════════════ */

@media (min-width: 769px) {
    .mobile-bar,
    .mobile-drawer-overlay,
    .mobile-bottom-nav {
        display: none !important;
    }
    /* NOTE: .mobile-filters-toggle is now used on desktop too — see
       components/desktop_filters_collapsible.css. Do not hide it here. */
}


/* ═══════════════════════════════════════════════════════════════════
 * 7. Per-Type Cooldown Cards (settings, not breakpoint-gated)
 * NOTE: kept here for compatibility — owner: settings_modal.css
 * ═══════════════════════════════════════════════════════════════════ */

.set-types-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
}

.set-type-card {
    background: var(--bg-secondary, rgba(255, 255, 255, 0.02));
    border: 1px solid var(--border, #2a2a3a);
    border-radius: 8px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: opacity 0.2s;
}

.set-type-card.disabled { opacity: 0.55; }

.set-type-header {
    display: flex;
    align-items: center;
    gap: 12px;
}

.set-type-info { flex: 1; }

.set-type-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text, #fff);
}

.set-type-hint {
    font-size: 11px;
    color: var(--text-muted, #999);
    margin-top: 2px;
}

.set-type-cooldown {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border, rgba(255, 255, 255, 0.05));
}

.set-cd-label {
    font-size: 12px;
    color: var(--text-muted, #999);
    flex-shrink: 0;
}

.set-cd-input {
    width: 80px !important;
    text-align: center;
    font-weight: 600;
}

.set-cd-unit {
    font-size: 11px;
    color: var(--text-muted, #999);
}

.set-cd-hours {
    font-size: 11px;
    color: var(--accent-primary, #4a9eff);
    font-weight: 600;
    margin-right: auto;
}


/* ═══════════════════════════════════════════════════════════════════
 * 8. Light theme overrides (modal filter bars)
 * ═══════════════════════════════════════════════════════════════════ */

[data-theme="light"] .breakouts-filters,
[data-theme="light"] .div-filters,
[data-theme="light"] .patterns-filters {
    background: rgba(0, 0, 0, 0.03) !important;
}

[data-theme="light"] .bf-btn.active,
[data-theme="light"] .div-filter-btn.active,
[data-theme="light"] .patterns-filter-btn.active {
    background: var(--primary) !important;
    color: white !important;
}
