/* ==========================================================================
   BARIYAAR ALGO TRADING — MASTER RESPONSIVE STYLESHEET
   Comprehensive Multi-Device Layout Engine (Phones, Tablets, Landscape & Desktops)
   ========================================================================== */

/* ─── 1. GLOBAL MOBILE VIEWPORT RESET & CONTAINMENT ─── */
*, *::before, *::after {
    box-sizing: border-box !important;
}

html, body {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    position: relative;
}

/* ─── 2. UNIVERSAL CONTAINER CONTAINMENT ─── */
.dashboard-container,
.container,
.main-content,
.global-container,
.page-wrapper,
.portal-container {
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
}

/* ─── 3. UNIVERSAL TOUCH-SCROLL DATA WRAPPERS ─── */
.bariyaar-table-scroll,
.table-wrap,
.table-responsive {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: thin;
    position: relative;
}

/* Sleek subtle scrollbars for touch scroll tables */
.bariyaar-table-scroll::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar,
.table-responsive::-webkit-scrollbar {
    height: 5px;
    width: 5px;
}
.bariyaar-table-scroll::-webkit-scrollbar-track,
.table-wrap::-webkit-scrollbar-track,
.table-responsive::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}
.bariyaar-table-scroll::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb,
.table-responsive::-webkit-scrollbar-thumb {
    background: rgba(0, 229, 255, 0.4);
    border-radius: 4px;
}

/* ─── 4. UNIVERSAL MOBILE BOTTOM APP NAVIGATION BAR (NATIVE APP FEEL) ─── */
.mobile-bottom-nav {
    display: none;
}

@media (max-width: 768px) {
    /* Always reserve bottom clearance for mobile navigation bar */
    .dashboard-container,
    .container,
    .main-content,
    .global-container,
    .page-wrapper,
    .portal-container {
        padding-bottom: calc(74px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Fixed Native App Navigation Bar */
    .mobile-bottom-nav {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 58px !important;
        background: rgba(12, 14, 19, 0.96) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        border-top: 1px solid #2A2E42 !important;
        z-index: 9999 !important;
        justify-content: space-around !important;
        align-items: center !important;
        padding: 0 4px !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.65) !important;
        transform: translateZ(0);
    }

    .mobile-nav-item {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 2px !important;
        text-decoration: none !important;
        color: #8B8DA8 !important;
        font-family: 'Inter', system-ui, sans-serif !important;
        font-size: 9px !important;
        font-weight: 700 !important;
        letter-spacing: 0.3px !important;
        flex: 1 !important;
        height: 100% !important;
        transition: all 0.2s ease !important;
        position: relative !important;
        touch-action: manipulation;
    }

    .mobile-nav-item .nav-icon {
        font-size: 18px !important;
        line-height: 1 !important;
        transition: transform 0.2s ease;
    }

    .mobile-nav-item.active {
        color: #8B5CF6 !important;
    }

    .mobile-nav-item.active .nav-icon {
        transform: scale(1.15) !important;
        filter: drop-shadow(0 0 6px rgba(139, 92, 246, 0.75)) !important;
    }

    .mobile-nav-item.active::before {
        content: '' !important;
        position: absolute !important;
        top: 0 !important;
        left: 18% !important;
        right: 18% !important;
        height: 2.5px !important;
        background: linear-gradient(90deg, #8B5CF6, #EC4899) !important;
        border-radius: 0 0 3px 3px !important;
        box-shadow: 0 0 8px #8B5CF6 !important;
    }

    /* Light Mode Bottom Navigation Bar Override (Aurora Masterpiece: Molten Glass) */
    html:not([data-theme="dark"]) .mobile-bottom-nav {
        background: rgba(255, 255, 255, 0.96) !important;
        border-top: 1px solid #D8D5E0 !important;
        box-shadow: 0 -4px 20px rgba(30, 27, 46, 0.08) !important;
    }
    html:not([data-theme="dark"]) .mobile-nav-item {
        color: #7C7A8E !important;
    }
    html:not([data-theme="dark"]) .mobile-nav-item.active {
        color: #7C3AED !important;
    }
    html:not([data-theme="dark"]) .mobile-nav-item.active::before {
        background: linear-gradient(90deg, #7C3AED, #EC4899) !important;
        box-shadow: 0 0 8px rgba(124, 58, 237, 0.5) !important;
    }
    html:not([data-theme="dark"]) .mobile-nav-item.active .nav-icon {
        filter: drop-shadow(0 0 5px rgba(124, 58, 237, 0.5)) !important;
    }
}

/* ─── 5. UNIVERSAL HEADER MOBILE COMPACTION ─── */
@media (max-width: 768px) {
    header {
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 6px 10px !important;
        gap: 6px !important;
        border-radius: 8px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Hide redundant desktop nav buttons from header on mobile */
    header .global-radar-btn,
    header .nav-btn,
    header .action-btn,
    header .clock-box,
    header .clock-badge,
    header .digital-clock-box,
    header #btn-ec2-logs,
    header #btn-restart-bot,
    header #user-profile-badge,
    header .pulse-badge,
    header .timer-badge {
        display: none !important;
    }

    /* Compact brand HUD */
    .brand-hud {
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        width: auto !important;
    }
    .brand-logo {
        width: 26px !important;
        height: 26px !important;
        font-size: 13px !important;
    }
    .brand-text h1,
    .brand-title h1 {
        font-size: 11px !important;
        letter-spacing: 0.6px !important;
        white-space: nowrap !important;
    }
    .brand-text p,
    .brand-title p {
        display: none !important;
    }

    /* Compact Controls */
    .inst-switch-container,
    .inst-btn-group {
        gap: 3px !important;
    }
    .inst-btn {
        padding: 4px 7px !important;
        font-size: 9.5px !important;
    }
    .theme-btn,
    .ctrl-btn {
        padding: 4px 8px !important;
        font-size: 9.5px !important;
    }
    #theme-text,
    #sfx-text {
        display: none !important;
    }

    /* Top Right Drawer Hamburger Toggle on Mobile / PWA */
    .drawer-hamburger-btn {
        width: 36px !important;
        height: 36px !important;
        flex-shrink: 0 !important;
        display: flex !important;
    }
}

/* ─── 6. COCKPIT (DASHBOARD) VERTICAL PORTRAIT ENHANCEMENTS ─── */
@media (max-width: 860px) {
    /* Stack Cockpit Panels vertically with Tactical Order: Action First */
    .cockpit-grid-3col {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: 10px !important;
    }

    /* Panel 2 (Orderflow & Signals) First */
    .cockpit-panel:nth-child(2) {
        order: 1 !important;
    }
    /* Panel 3 (Execution Cockpits) Second */
    .cockpit-panel:nth-child(3) {
        order: 2 !important;
    }
    /* Panel 1 (Levels & Magnet Targets) Third */
    .cockpit-panel:nth-child(1) {
        order: 3 !important;
    }

    .cockpit-panel {
        width: 100% !important;
        padding: 8px 8px !important;
        border-radius: 10px !important;
    }

    /* Telemetry stats 2x2 grid */
    .telemetry-metrics-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px !important;
    }
    .tele-stat {
        padding: 6px 8px !important;
    }
    .tele-stat-lbl {
        font-size: 8.5px !important;
    }
    .tele-stat-val {
        font-size: 13px !important;
    }

    /* 4-Slot Options Orderbook Radar on Mobile */
    .options-radar-grid {
        grid-template-columns: 1fr !important;
        gap: 6px !important;
    }
    @media (min-width: 480px) and (max-width: 860px) {
        .options-radar-grid {
            grid-template-columns: repeat(2, 1fr) !important;
        }
    }

    .opt-slot-card {
        padding: 8px 10px !important;
    }
    .opt-strike-name {
        font-size: 13px !important;
    }
    .opt-strike-ltp {
        font-size: 15px !important;
    }

    /* Technical Indicator Bars (VWAP, HMA, VWMA, Cross) */
    .cockpit-indicator-bar {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 4px 8px !important;
        padding: 5px 8px !important;
        font-size: 10px !important;
    }

    /* Big Action Buy & Reject Buttons */
    .action-btns-grid {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 6px !important;
    }
    .btn-buy, .btn-reject {
        min-height: 42px !important;
        font-size: 12px !important;
        padding: 8px 12px !important;
    }

    /* Levels & Magnet Matrix */
    .matrix-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 4px !important;
    }
    .spot-middle-val,
    .magnet-target-val,
    .floor-target-val {
        font-size: 20px !important;
    }
    .level-breakdown-row {
        font-size: 9.5px !important;
        flex-wrap: wrap !important;
        gap: 4px !important;
    }

    /* Responsive Modals */
    .chart-modal-content,
    .logs-modal-content {
        width: 95vw !important;
        max-width: 95vw !important;
        max-height: 88vh !important;
        padding: 10px !important;
    }
}

/* ─── 7. OPTION CHAIN VERTICAL PORTRAIT ENHANCEMENTS ─── */
@media (max-width: 768px) {
    /* CRITICAL FIX: Never hide horizontal overflow on mobile option chain! Allow smooth touch scrolling */
    .table-wrap,
    .table-wrap.view-calls,
    .table-wrap.view-puts,
    .table-wrap.view-dual {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        width: 100% !important;
        max-width: 100vw !important;
        border-radius: 8px !important;
    }

    /* KPI Grid 2 columns */
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px !important;
    }
    .kpi-card {
        padding: 8px 10px !important;
    }
    .kpi-card:last-child {
        grid-column: 1 / -1 !important;
    }
    .kpi-value {
        font-size: 16px !important;
    }

    /* Perspective Command Bar */
    .chain-view-command-bar {
        flex-direction: column !important;
        padding: 8px 10px !important;
        gap: 8px !important;
    }
    .view-command-pills {
        width: 100% !important;
        display: flex !important;
    }
    .view-cmd-btn {
        flex: 1 !important;
        padding: 8px 8px !important;
        font-size: 10.5px !important;
        justify-content: center !important;
        text-align: center !important;
    }
    .view-cmd-btn .cmd-hint,
    .view-command-meta {
        display: none !important;
    }

    /* Floating Capsule sits safely above bottom nav */
    .floating-view-capsule {
        bottom: 68px !important;
        right: 12px !important;
        padding: 4px 6px !important;
        z-index: 1000 !important;
    }
    .float-btn {
        padding: 5px 10px !important;
        font-size: 9px !important;
    }
}

/* ─── 8. STOCKS RADAR VERTICAL PORTRAIT ENHANCEMENTS ─── */
@media (max-width: 680px) {
    .grid-container {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
    .stock-card {
        padding: 12px 14px !important;
    }
    .metrics-ribbon {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px !important;
    }
    .filter-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }
    .section-title {
        font-size: 11.5px !important;
        padding: 8px 12px !important;
    }
}

/* ─── 9. PLAYBOOK WAR ROOM VERTICAL PORTRAIT ENHANCEMENTS ─── */
@media (max-width: 768px) {
    .hero-grid {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }
    .stat-box {
        padding: 10px 12px !important;
    }
    .cluster-grid,
    .battlefield-grid,
    .priority-card,
    .tab-pane.active {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }
    .priority-card {
        padding: 12px 12px !important;
    }
}

/* ─── 10. GLOBAL INDICES RADAR VERTICAL PORTRAIT ENHANCEMENTS ─── */
@media (max-width: 768px) {
    .world-clocks-bar {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
    .clock-pill {
        flex: 1 1 calc(50% - 6px) !important;
        padding: 4px 8px !important;
    }
    .indices-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px !important;
    }
    .timetable-grid {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }
    .chart-view-panel {
        flex-direction: column !important;
    }
}
@media (max-width: 400px) {
    .indices-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ─── 11. CONNECT BROKER VERTICAL PORTRAIT ENHANCEMENTS ─── */
@media (max-width: 680px) {
    .broker-cards-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    .risk-calculator-pod {
        grid-template-columns: 1fr !important;
        gap: 6px !important;
    }
    .vault-box {
        padding: 16px 12px !important;
    }
    .hero-section {
        padding: 16px 12px !important;
        margin: 12px 0 !important;
    }
    .hero-title {
        font-size: 16px !important;
    }
}

/* ─── 12. AUTHENTICATION & LOGIN VERTICAL PORTRAIT ENHANCEMENTS ─── */
@media (max-width: 680px) {
    .portal-nav-tabs {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }
    .portal-tab-btn {
        padding: 10px 12px !important;
    }
    .broker-cards-grid {
        grid-template-columns: 1fr !important;
    }
}
