/* ============================================
   Mobile Trading Interface - PocketOption Style
   ============================================ */

/* Prevent zoom on double tap */
* {
    touch-action: manipulation;
}

@media (max-width: 768px) {
    /* ==========================================
       Hide unnecessary elements
       ========================================== */
    .nav-links,
    .market-info-bar,
    .main-footer,
    .positions-sidebar,
    .price-display,
    .trade-info,
    .panel-header,
    .drawing-toolbar,
    .toolbar-section,
    .chart-tools,
    .chart-controls,
    .timeframe-selector,
    .potential-return,
    .chat-widget-btn,
    .chat-window,
    #chat-widget-btn,
    #chat-window,
    .notification-btn,
    .settings-btn,
    .quick-lots,
    .section-label {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
        overflow: hidden !important;
        visibility: hidden !important;
        position: absolute !important;
        left: -9999px !important;
    }

    /* Force positions-sidebar to not take any grid space */
    .positions-sidebar {
        display: none !important;
        grid-column: none !important;
        grid-row: none !important;
        flex: 0 !important;
        min-width: 0 !important;
        max-width: 0 !important;
    }

    /* ==========================================
       Base Styles
       ========================================== */
    * {
        box-sizing: border-box;
    }

    body {
        font-size: 14px;
        overflow: hidden;
        height: 100vh;
        background: #0d1117;
    }

    /* ==========================================
       HEADER - Clean & Minimal
       ========================================== */
    .header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
        height: 56px;
        padding: 0 12px;
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        justify-content: space-between;
        background: linear-gradient(180deg, #1a1f26 0%, #141920 100%);
        border-bottom: 1px solid #2d333b;
    }

    /* Hide header-right completely (logo, nav) */
    .header-right {
        display: none !important;
    }

    /* Header-left takes full width */
    .header-left {
        display: flex !important;
        align-items: center;
        justify-content: space-between !important;
        width: 100% !important;
        gap: 8px;
    }

    /* Logo - Hide on mobile */
    .logo {
        display: none !important;
    }

    /* Mobile Balance Group - Contains account indicator + balance */
    .mobile-balance-group {
        display: flex !important;
        align-items: center;
        gap: 8px;
        order: 2;
        flex-direction: row;
    }

    /* Account Indicator - Show on mobile */
    #account-type-indicator,
    .account-indicator {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        align-items: center;
        gap: 4px;
        padding: 6px 12px !important;
        border-radius: 20px !important;
        font-size: 0.7rem !important;
        cursor: pointer;
        font-weight: 600;
        white-space: nowrap;
        flex-shrink: 0;
        position: static !important;
        width: auto !important;
        height: auto !important;
        overflow: visible !important;
        z-index: 50 !important;
    }

    .account-indicator i,
    #account-type-indicator i {
        font-size: 0.65rem !important;
    }

    .account-indicator.demo,
    #account-type-indicator.demo {
        background: linear-gradient(135deg, #1f6feb 0%, #388bfd 100%) !important;
        color: white !important;
        border: none !important;
    }

    .account-indicator.real,
    #account-type-indicator.real {
        background: linear-gradient(135deg, #238636 0%, #2ea043 100%) !important;
        color: white !important;
        border: none !important;
    }

    /* User Section - Menu button on LEFT */
    .user-section {
        order: 1;
        display: flex !important;
        align-items: center;
    }

    /* Menu Button (hamburger) */
    .user-avatar {
        width: 40px !important;
        height: 40px !important;
        background: #21262d !important;
        border-radius: 10px !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        border: 1px solid #30363d;
    }

    .user-avatar i {
        font-size: 1.1rem;
    }

    /* Show hamburger icon on mobile, hide user icon */
    .user-avatar .desktop-icon {
        display: none !important;
    }

    .user-avatar .mobile-icon {
        display: block !important;
        color: #c9d1d9;
    }

    /* Show mobile menu items */
    .mobile-menu-item {
        display: flex !important;
    }

    /* User dropdown - Full menu */
    .user-dropdown {
        position: fixed !important;
        top: 56px !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-height: calc(100vh - 56px);
        background: #161b22;
        border-radius: 0 !important;
        border: none;
        border-top: 1px solid #30363d;
        box-shadow: 0 10px 40px rgba(0,0,0,0.5);
        z-index: 1000;
    }

    .user-info {
        padding: 16px;
        background: #21262d;
        border-bottom: 1px solid #30363d;
    }

    .dropdown-item {
        padding: 14px 16px !important;
        font-size: 1rem !important;
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .dropdown-item i {
        font-size: 1.1rem;
        width: 24px;
        text-align: center;
        color: #58a6ff;
    }

    /* Balance Display - Prominent */
    .balance-card {
        background: linear-gradient(135deg, #238636 0%, #1a7f37 100%) !important;
        padding: 6px 14px !important;
        border-radius: 20px !important;
        border: none !important;
        min-width: auto !important;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(35, 134, 54, 0.4);
    }

    .balance-item {
        display: flex !important;
        align-items: center;
        gap: 4px;
        flex-direction: row;
    }

    .balance-label {
        display: none !important;
    }

    .balance-value {
        font-size: 0.9rem !important;
        font-weight: 700;
        color: white !important;
        letter-spacing: -0.5px;
    }

    .currency {
        font-size: 0.7rem;
        color: rgba(255,255,255,0.9);
        font-weight: 600;
    }

    .wallet-buttons {
        position: fixed !important;
        top: 56px;
        left: 0;
        right: 0;
        background: #161b22;
        padding: 12px;
        border-bottom: 1px solid #30363d;
        display: flex;
        gap: 10px;
        z-index: 999;
    }

    .wallet-action-btn {
        flex: 1;
        padding: 12px;
        border-radius: 10px;
        font-size: 0.9rem;
    }

    .icon-btn {
        display: none !important;
    }

    .user-section {
        gap: 8px !important;
    }

    /* ==========================================
       MAIN CONTENT - Full Height Layout
       ========================================== */
    .main-content {
        margin: 0 !important;
        padding: 0 !important;
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        bottom: 0;
        overflow: hidden;
        width: 100% !important;
    }

    .trading-container {
        display: flex !important;
        flex-direction: column !important;
        height: 100% !important;
        width: 100% !important;
        padding: 0 !important;
        gap: 0 !important;
        margin: 0 !important;
        grid-template-columns: none !important;
    }

    /* ==========================================
       CHART SECTION - Full Width, Big
       ========================================== */
    .chart-section {
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        border: none !important;
        border-radius: 0 !important;
        background: #0d1117;
        min-height: 0;
        overflow: hidden;
        width: 100% !important;
        margin: 0 !important;
    }

    .chart-header {
        padding: 8px 10px !important;
        background: #161b22;
        border-bottom: 1px solid #21262d;
        display: flex !important;
        flex-direction: column;
        gap: 8px;
        flex-shrink: 0;
    }

    .pair-selector {
        display: flex;
        gap: 6px;
        overflow-x: auto;
        flex: 1;
        -webkit-overflow-scrolling: touch;
    }

    .pair-selector::-webkit-scrollbar {
        display: none;
    }

    .pair-btn {
        padding: 6px 12px !important;
        font-size: 0.8rem !important;
        background: #21262d;
        border: 1px solid #30363d;
        border-radius: 6px;
        color: #c9d1d9;
        white-space: nowrap;
        flex-shrink: 0;
        transition: all 0.2s;
    }

    .pair-btn.active {
        background: #58a6ff !important;
        border-color: #58a6ff !important;
        color: white !important;
    }

    .pair-icon {
        margin-left: 4px;
    }

    /* Chart controls - Show timeframe on mobile */
    .chart-controls {
        display: flex !important;
        justify-content: center;
    }

    .timeframe-selector {
        display: flex !important;
        gap: 4px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .timeframe-selector::-webkit-scrollbar {
        display: none;
    }

    .tf-btn {
        padding: 5px 10px !important;
        font-size: 0.75rem !important;
        background: #21262d;
        border: 1px solid #30363d;
        border-radius: 5px;
        color: #8b949e;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .tf-btn.active {
        background: #388bfd !important;
        border-color: #388bfd !important;
        color: white !important;
    }

    /* Chart wrapper - Takes all available space */
    .chart-wrapper {
        flex: 1 !important;
        min-height: 150px;
        padding: 0 !important;
        position: relative;
        background: #0d1117;
        width: 100% !important;
        max-width: 100% !important;
    }

    #candlestick-chart {
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
    }

    /* Price info overlay - HIDE on mobile */
    .price-info {
        display: none !important;
    }

    /* Candle timer */
    .candle-timer {
        position: absolute;
        top: 8px;
        left: 8px;
        background: rgba(13, 17, 23, 0.85);
        padding: 5px 8px;
        border-radius: 6px;
        z-index: 10;
        display: flex;
        align-items: center;
        gap: 5px;
    }

    .timer-label {
        font-size: 0.65rem;
        color: #8b949e;
    }

    .timer-value {
        font-size: 0.85rem;
        font-weight: 700;
        color: #58a6ff;
    }

    .volume-indicator {
        display: none !important;
    }

    /* ==========================================
       TRADING PANEL - Compact Bottom Bar
       ========================================== */
    .trading-panel {
        flex-shrink: 0;
        background: #161b22 !important;
        border-top: 1px solid #30363d !important;
        padding: 10px 12px !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        position: relative !important;
    }

    /* Mobile Trading Controls - Show Labels */
    .section-label {
        display: block !important;
        position: static !important;
        visibility: visible !important;
        width: auto !important;
        height: auto !important;
        overflow: visible !important;
        left: auto !important;
        font-size: 0.7rem !important;
        color: #8b949e !important;
        margin-bottom: 5px !important;
        font-weight: 600;
    }

    .duration-section {
        display: block !important;
        margin-bottom: 8px;
    }

    .duration-selector {
        display: flex !important;
        gap: 4px;
        overflow-x: auto;
        padding-bottom: 2px;
        -webkit-overflow-scrolling: touch;
    }

    .duration-selector::-webkit-scrollbar {
        display: none;
    }

    .duration-btn {
        padding: 6px 10px !important;
        font-size: 0.75rem !important;
        background: #21262d;
        border: 1px solid #30363d;
        border-radius: 6px;
        color: #8b949e;
        white-space: nowrap;
        flex-shrink: 0;
        transition: all 0.2s;
    }

    .duration-btn.active {
        background: #6e40c9 !important;
        border-color: #6e40c9 !important;
        color: white !important;
    }

    /* Lot Section - Show on mobile */
    .lot-section {
        display: block !important;
        margin-bottom: 10px;
    }

    .lot-input-wrapper {
        display: flex !important;
        align-items: center;
        gap: 8px;
        background: #21262d;
        border-radius: 10px;
        padding: 6px;
    }

    .lot-btn {
        width: 36px;
        height: 36px;
        border-radius: 8px;
        background: #30363d;
        border: none;
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        font-size: 1rem;
    }

    .lot-btn:active {
        background: #484f58;
    }

    .lot-input-container {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
    }

    .lot-input-container input {
        width: 100%;
        max-width: 120px;
        text-align: center;
        background: transparent;
        border: none;
        color: #f0f6fc;
        font-size: 1.1rem;
        font-weight: 700;
        font-family: 'Cairo', sans-serif;
    }

    .lot-input-container input:focus {
        outline: none;
    }

    .lot-currency {
        color: #8b949e;
        font-size: 0.8rem;
    }

    /* TRADE BUTTONS - Big and Beautiful */
    .trade-buttons {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .trade-btn {
        height: 56px !important;
        border-radius: 12px !important;
        border: none !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        justify-content: center;
        gap: 8px;
        font-family: 'Cairo', sans-serif;
        cursor: pointer;
        transition: all 0.2s;
        box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    }

    .trade-btn:active {
        transform: scale(0.98);
    }

    .trade-btn.buy {
        background: linear-gradient(135deg, #3fb950 0%, #238636 100%) !important;
        color: white;
        order: 1;
    }

    .trade-btn.buy:active {
        box-shadow: 0 2px 20px rgba(63, 185, 80, 0.5);
    }

    .trade-btn.sell {
        background: linear-gradient(135deg, #f85149 0%, #da3633 100%) !important;
        color: white;
        order: 2;
    }

    .trade-btn.sell:active {
        box-shadow: 0 2px 20px rgba(248, 81, 73, 0.5);
    }

    .trade-btn .btn-icon {
        width: 32px;
        height: 32px;
        background: rgba(255,255,255,0.2);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1rem;
    }

    .trade-btn .btn-text {
        font-size: 1.1rem;
        font-weight: 700;
    }

    .trade-btn .btn-price {
        display: none !important;
    }

    /* ==========================================
       TOAST - Auto-hide fix
       ========================================== */
    .toast {
        position: fixed !important;
        top: 70px !important;
        bottom: auto !important;
        left: 50% !important;
        right: auto !important;
        width: calc(100% - 24px) !important;
        max-width: 400px !important;
        transform: translateX(-50%) translateY(-150px) !important;
        border-radius: 12px;
        padding: 14px 18px;
        transition: transform 0.3s ease !important;
        z-index: 9999 !important;
    }

    .toast.show {
        transform: translateX(-50%) translateY(0) !important;
    }

    /* ==========================================
       MODALS - Mobile Optimized
       ========================================== */
    .modal-overlay {
        align-items: flex-end !important;
        padding: 0 !important;
    }

    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 85vh !important;
        border-radius: 20px 20px 0 0 !important;
        margin: 0;
    }

    .modal-header {
        padding: 16px 20px;
        border-bottom: 1px solid #30363d;
    }

    .modal-header h2 {
        font-size: 1.1rem;
    }

    .close-modal {
        width: 32px;
        height: 32px;
    }

    .modal-body {
        padding: 16px 20px;
        max-height: 70vh;
        overflow-y: auto;
    }

    /* Account Switcher Modal */
    .account-switcher-content {
        max-height: 70vh !important;
    }

    .account-options {
        gap: 12px;
    }

    .account-option {
        padding: 16px !important;
        border-radius: 12px;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .account-icon {
        width: 48px;
        height: 48px;
        margin-bottom: 10px;
    }

    .account-details h3 {
        font-size: 1rem;
        margin-bottom: 4px;
    }

    .account-details p {
        font-size: 0.8rem;
        color: #8b949e;
    }

    .account-balance {
        font-size: 0.9rem;
        margin-top: 8px;
        color: #3fb950;
    }

    .account-switch-btn {
        margin-top: 10px;
        padding: 8px 20px;
        border-radius: 8px;
        font-size: 0.85rem;
    }

    /* History modal */
    .history-tabs {
        display: flex;
        gap: 8px;
        margin-bottom: 16px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }

    .history-tabs::-webkit-scrollbar {
        display: none;
    }

    .history-tab {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 10px 16px;
        border: none;
        border-radius: 10px;
        background: #21262d;
        color: #8b949e;
        font-size: 0.85rem;
        font-weight: 600;
        font-family: 'Cairo', sans-serif;
        cursor: pointer;
        white-space: nowrap;
        flex-shrink: 0;
        transition: all 0.2s;
    }

    .history-tab i {
        font-size: 0.9rem;
    }

    .history-tab.active {
        background: linear-gradient(135deg, #58a6ff 0%, #388bfd 100%);
        color: white;
    }

    .history-tab-content {
        display: none;
    }

    .history-tab-content.active {
        display: block;
    }

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

    .stat-card {
        padding: 12px !important;
        border-radius: 10px;
    }

    .stat-card.pending {
        background: linear-gradient(135deg, #d29922 0%, #9e6a03 100%);
    }

    .stat-card.pending i {
        color: white;
    }

    .status-badge {
        display: inline-block;
        padding: 4px 8px;
        border-radius: 6px;
        font-size: 0.7rem;
        font-weight: 600;
    }

    .status-badge.success {
        background: rgba(63, 185, 80, 0.2);
        color: #3fb950;
    }

    .status-badge.warning {
        background: rgba(210, 153, 34, 0.2);
        color: #d29922;
    }

    .status-badge.info {
        background: rgba(88, 166, 255, 0.2);
        color: #58a6ff;
    }

    .status-badge.danger {
        background: rgba(248, 81, 73, 0.2);
        color: #f85149;
    }

    .history-table-container {
        overflow-x: auto;
        margin: 0 -20px;
        padding: 0 20px;
    }

    .history-table {
        min-width: 400px;
        font-size: 0.75rem;
    }

    /* ==========================================
       FEATURES GRID
       ========================================== */
    .features-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px;
    }

    .feature-item {
        padding: 14px;
        border-radius: 10px;
    }

    /* ==========================================
       FLOATING SUPPORT BUTTON
       ========================================== */
    .mobile-support-btn {
        position: fixed;
        bottom: 180px;
        left: 12px;
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: linear-gradient(135deg, #58a6ff 0%, #388bfd 100%);
        border: none;
        box-shadow: 0 4px 15px rgba(88, 166, 255, 0.4);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 90;
        transition: all 0.3s ease;
    }

    .mobile-support-btn:active {
        transform: scale(0.95);
    }

    .mobile-support-btn i {
        color: white;
        font-size: 1.2rem;
    }

    /* ==========================================
       MENU BUTTON FIX
       ========================================== */
    .user-avatar {
        position: relative;
        width: 36px !important;
        height: 36px !important;
        min-width: 36px;
    }

    /* ==========================================
       CHAT WINDOW - Show when opened on mobile
       ========================================== */
    .chat-window.open,
    #chat-window.open {
        display: flex !important;
        flex-direction: column !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        z-index: 10000 !important;
        visibility: visible !important;
        overflow: visible !important;
    }

    .chat-window.open .chat-header {
        padding: 16px;
        border-radius: 0;
    }

    .chat-window.open .chat-messages {
        flex: 1;
        overflow-y: auto;
        padding: 16px;
    }

    .chat-window.open .chat-input-area {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid #30363d;
    }

    .chat-window.open .chat-input-wrapper {
        flex: 1;
    }

    .chat-window.open .chat-input-wrapper input {
        width: 100%;
        padding: 12px 16px;
        font-size: 16px;
    }
}

/* ==========================================
   Extra Small Phones (< 360px)
   ========================================== */
@media (max-width: 360px) {
    .header {
        height: 50px;
        padding: 0 8px;
    }

    .main-content {
        top: 50px;
    }

    .balance-card {
        padding: 6px 10px !important;
    }

    .balance-value {
        font-size: 0.85rem !important;
    }

    .account-indicator {
        padding: 5px 8px !important;
        font-size: 0.7rem !important;
    }

    .pair-btn {
        padding: 5px 8px !important;
        font-size: 0.75rem !important;
    }

    .tf-btn {
        padding: 4px 8px !important;
        font-size: 0.7rem !important;
    }

    .duration-btn {
        padding: 5px 8px !important;
        font-size: 0.7rem !important;
    }

    .trade-btn {
        height: 50px !important;
    }

    .trade-btn .btn-text {
        font-size: 1rem;
    }

    .trade-btn .btn-icon {
        width: 28px;
        height: 28px;
        font-size: 0.9rem;
    }
}

/* ==========================================
   Landscape Mode
   ========================================== */
@media (max-width: 768px) and (orientation: landscape) {
    .header {
        height: 44px;
    }

    .main-content {
        top: 44px;
    }

    .trading-container {
        flex-direction: row;
    }

    .chart-section {
        flex: 1;
    }

    .chart-header {
        padding: 4px 8px !important;
    }

    .trading-panel {
        width: 220px;
        height: 100%;
        border-top: none !important;
        border-left: 1px solid #30363d !important;
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 8px !important;
    }

    .duration-section {
        margin-bottom: 6px;
    }

    .lot-section {
        margin-bottom: 6px;
    }

    .trade-buttons {
        flex-direction: column;
        gap: 6px;
    }

    .trade-btn {
        height: 44px !important;
    }
}
