/* ============================================================
   BRAIN TERMINAL V2 - MOBILE RESPONSIVE
   Breakpoints: 768px (tablet), 480px (phone)
   ============================================================ */

/* Mobile fast actions: desktop'ta gizli */
.mobile-fast-actions {
    display: none;
}

/* ============ MOBILE NAV TOGGLE ============ */
.mobile-nav-toggle {
    display: none;
    position: fixed;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    background: rgba(10, 10, 20, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 5px 8px;
    gap: 4px;
    backdrop-filter: blur(20px);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.7);
}

.mobile-nav-toggle button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: transparent;
    border: none;
    color: #666;
    padding: 7px 18px;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 60px;
}

.mobile-nav-toggle button .nav-icon {
    font-size: 18px;
    line-height: 1;
}

.mobile-nav-toggle button .nav-label {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.3px;
    line-height: 1;
}

.mobile-nav-toggle button.active {
    background: rgba(41, 98, 255, 0.15);
    color: #2962ff;
}

.mobile-nav-toggle button:active {
    transform: scale(0.93);
}

/* ============ TABLET: <= 1024px ============ */
@media (max-width: 1024px) {
    html {
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
        overflow: hidden !important;
    }

    body {
        position: fixed !important;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100% !important;
        height: 100% !important;
        overflow: hidden !important;
    }

    .app-container {
        display: block !important;
        position: fixed !important;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
        overflow: hidden !important;
    }

    .sidebar {
        display: none !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .right-sidebar {
        display: none !important;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .main-area {
        position: absolute !important;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
    }
}

/* ============ MOBILE: <= 768px ============ */
@media (max-width: 768px) {
    body {
        font-size: 13px;
    }

    .app-container {
        display: block !important;
        width: 100% !important;
        grid-template-columns: none !important;
    }

    .main-area {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }

    /* ---- Mobile Nav ---- */
    .mobile-nav-toggle {
        display: flex;
    }

    /* ---- Sidebar (Left) ---- */
    .sidebar {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-width: 100%;
        min-width: 0;
        z-index: 9000;
        padding: 12px;
        padding-bottom: 80px;
        overflow-y: auto;
        overflow-x: hidden;
        background: rgba(5, 5, 5, 0.98);
        backdrop-filter: blur(20px);
    }

    .sidebar.mobile-visible {
        display: flex !important;
        flex-direction: column !important;
    }

    /* Sidebar mobile layout fixes */
    .sidebar .logo-container {
        margin-bottom: 10px;
        padding-bottom: 8px;
    }

    .sidebar .logo-container img {
        max-height: 60px;
        width: auto;
    }

    .sidebar .sidebar-content {
        gap: 8px;
    }

    .sidebar .settings-grid-row {
        margin-top: 8px !important;
        max-width: 100% !important;
        gap: 6px;
    }

    .sidebar .settings-grid-row .cyber-btn {
        padding: 8px 10px;
        font-size: 12px;
        min-height: 36px;
    }

    /* AI Terminal cards - compact on mobile */
    .sidebar .ai-terminal-card {
        margin-top: 8px !important;
        min-height: 80px;
        flex: none !important;
    }

    .sidebar .ai-terminal-header {
        padding: 8px 12px;
    }

    .sidebar .ai-terminal-content {
        padding: 8px;
    }

    .sidebar .terminal-log {
        min-height: 50px;
        max-height: 120px;
        font-size: 10px;
        padding: 6px;
    }

    /* Referral card compact */
    .sidebar .referral-card {
        margin-top: 12px !important;
        padding: 8px 10px !important;
    }

    /* ---- Right Sidebar ---- */
    .right-sidebar {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-width: 100%;
        min-width: 0;
        z-index: 9000;
        padding: 15px;
        padding-bottom: 80px;
        overflow-y: auto;
        background: rgba(5, 5, 5, 0.98);
        backdrop-filter: blur(20px);
    }

    .right-sidebar.mobile-visible {
        display: flex !important;
    }

    /* ---- Main Area ---- */
    .main-area {
        display: flex !important;
        flex-direction: column !important;
        padding: 8px !important;
        padding-bottom: 70px !important;
    }

    .main-area.mobile-hidden {
        display: none;
    }

    /* ---- Top Bar (sadece coin search + timeframe) ---- */
    .top-bar {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 6px !important;
        padding: 6px 8px !important;
        margin-bottom: 4px !important;
        overflow: visible !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        position: relative !important;
        z-index: 100 !important;
    }

    /* Coin input + timeframe — top-bar'ın tamamı */
    .selector-group {
        display: flex !important;
        flex-direction: row !important;
        flex: 1 !important;
        gap: 6px !important;
        overflow: visible !important;
        align-items: center !important;
    }

    .symbol-input-wrapper {
        flex: 1 !important;
        position: relative !important;
        display: flex !important;
        align-items: center !important;
        min-width: 0 !important;
        overflow: visible !important;
        z-index: 200 !important;
    }

    #symbol-search-input {
        flex: 1 !important;
        min-width: 0 !important;
        max-width: none !important;
        font-size: 16px !important; /* iOS zoom engelle */
        padding: 10px 36px 10px 12px !important; /* sağda ok butonu için boşluk */
        min-height: 44px !important;
        box-sizing: border-box !important;
        width: 100% !important;
    }

    #symbol-dropdown-btn {
        position: absolute !important;
        right: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        width: 36px !important;
        background: transparent !important;
        border: none !important;
        color: #888 !important;
        font-size: 16px !important;
        cursor: pointer !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 !important;
        transition: color 0.2s !important;
    }

    #symbol-dropdown-btn:active {
        color: #2962ff !important;
    }

    #timeframe-select {
        font-size: 16px !important; /* iOS zoom engelle */
        min-height: 44px !important;
    }

    #timeframe-select {
        flex-shrink: 0 !important;
        width: 68px !important;
        font-size: 14px !important;
        padding: 7px 4px !important;
        box-sizing: border-box !important;
    }

    /* Balance Row — bağımsız, 3 ayrı kart */
    .balance-group {
        display: flex !important;
        flex-direction: row !important;
        width: 100% !important;
        gap: 4px !important;
        margin-bottom: 4px !important;
        box-sizing: border-box !important;
    }

    .cyber-metric {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        flex: 1 !important;
        min-width: 0 !important;
        padding: 5px 4px !important;
        text-align: center !important;
        box-sizing: border-box !important;
    }

    .cyber-metric .label {
        display: block !important;
        font-size: 9px !important;
        margin-bottom: 2px !important;
        white-space: nowrap !important;
        color: #888 !important;
    }

    .cyber-metric .value {
        display: block !important;
        font-size: 12px !important;
        font-weight: bold !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        width: 100% !important;
        text-align: center !important;
    }

    /* Hide tooltips and eye icon on mobile */
    .balance-group .tooltip-wrapper,
    #coin-toolbar .tooltip-wrapper,
    #balance-visibility-toggle {
        display: none !important;
    }

    /* Fast Actions: mobile'da chart panelinde göster, right-sidebar'dakini gizle */
    .mobile-fast-actions {
        display: block !important;
        padding: 6px 0 4px 0;
        flex-shrink: 0;
    }

    .right-sidebar .quick-actions {
        display: none !important;
    }

    /* Right-sidebar fast-actions başlık kısmını da gizle */
    .right-sidebar > div:first-child {
        display: none !important;
    }

    /* ---- Coin Toolbar ---- */
    #coin-toolbar {
        padding: 4px 6px !important;
        gap: 4px !important;
        min-height: 34px !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        touch-action: pan-x !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
    }

    #coin-toolbar::-webkit-scrollbar {
        display: none !important;
    }

    #coin-toolbar button {
        font-size: 11px !important;
        padding: 4px 10px !important;
        white-space: nowrap !important;
        flex-shrink: 0 !important;
        min-height: 28px !important;
    }

    /* ---- Resizer (mobile touch-friendly) ---- */
    .resizer {
        height: 20px !important;
        padding: 8px 0 !important;
        touch-action: none !important;
        -webkit-user-select: none !important;
        user-select: none !important;
    }
    .resizer::after {
        width: 60px !important;
        height: 4px !important;
        opacity: 0.8 !important;
    }

    /* ---- Chart ---- */
    .chart-container {
        height: 45vh;
        min-height: 120px;
        margin-bottom: 0;
        border-radius: 6px;
        flex-shrink: 0;
        overflow: hidden !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    /* Force LightweightCharts to not overflow */
    .chart-container > div,
    .chart-container canvas,
    .chart-container table {
        max-width: 100% !important;
    }

    /* ---- Tabs ---- */
    .tabs {
        margin-bottom: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-shrink: 0;
    }

    .tab-btn {
        padding: 8px 12px;
        font-size: 11px;
        white-space: nowrap;
    }

    .tab-content {
        min-height: 100px;
        max-height: none;
        flex: 1;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    /* ---- Positions Grid ---- */
    .positions-grid {
        overflow-x: auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    .positions-grid table {
        font-size: 9px;
        min-width: 400px;
    }

    #tab-positions {
        padding: 0 !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        max-height: 50vh;
    }

    .pos-card {
        width: 100% !important;
    }

    #positions-mobile-cards {
        width: 100% !important;
        padding: 8px !important;
        box-sizing: border-box !important;
    }

    .tabs {
        margin-bottom: 4px !important;
    }

    /* ---- Trade History Table ---- */
    #tab-history {
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    .cyber-table {
        font-size: 9px;
        min-width: 500px;
        table-layout: auto;
    }

    .cyber-table th,
    .cyber-table td {
        padding: 4px 3px;
        white-space: nowrap;
    }

    /* Hide less important columns on mobile */
    .cyber-table th:nth-child(5),
    .cyber-table td:nth-child(5),
    .cyber-table th:nth-child(6),
    .cyber-table td:nth-child(6),
    .cyber-table th:nth-child(9),
    .cyber-table td:nth-child(9) {
        display: none;
    }

    #history-stats {
        gap: 6px;
        padding: 8px;
        font-size: 10px;
    }

    /* ---- Quick Actions (Right Sidebar) ---- */
    .quick-actions {
        gap: 8px;
    }

    .cyber-btn {
        padding: 10px 15px;
        font-size: 13px;
    }

    /* ---- Sentiment Panel ---- */
    .sentiment-panel {
        padding: 10px;
    }

    .sentiment-exchange-stats {
        padding-left: 0;
        flex-wrap: wrap;
        gap: 6px;
    }

    /* ---- News Feed ---- */
    .ai-news-container {
        max-height: 60vh;
    }

    .ai-news-feed-direct {
        padding: 10px;
    }

    .news-item-title {
        font-size: 11px;
    }

    /* ---- Settings Panel ---- */
    #settings-panel {
        width: 100% !important;
        max-width: 100% !important;
        flex-direction: column;
    }

    .settings-sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 10px;
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        gap: 4px;
        align-items: center;
    }

    .settings-header {
        padding: 0 10px 0 0;
        border-bottom: none;
        margin-bottom: 0;
    }

    .settings-logo {
        font-size: 14px;
        letter-spacing: 1px;
    }

    .settings-nav-btn {
        padding: 8px 12px;
        font-size: 11px;
        border-left: none;
        border-bottom: 2px solid transparent;
        border-radius: 6px;
    }

    .settings-nav-btn.active {
        border-left: none;
        border-bottom: 2px solid #00e5ff;
        background: rgba(0, 229, 255, 0.08);
    }

    .settings-status {
        display: none;
    }

    .settings-content {
        padding: 15px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .settings-close-btn {
        top: 10px;
        right: 15px;
        font-size: 28px;
    }

    .settings-section {
        padding: 15px;
        margin-bottom: 15px;
    }

    .settings-section h3 {
        font-size: 13px;
    }

    .settings-input-group input,
    .settings-input-group select {
        font-size: 14px; /* Prevent iOS zoom on focus */
        padding: 10px 12px;
    }

    .custom-checkbox-wrapper label {
        font-size: 12px;
    }

    /* Scanner grid - single column on mobile */
    #scan-list-container {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    /* ---- AI Terminal Cards (Sidebar) ---- */
    .ai-terminal-card {
        min-height: 100px;
    }

    .terminal-log {
        min-height: 60px;
        font-size: 10px;
    }

    /* ---- Referral Card ---- */
    .referral-card {
        padding: 8px 10px !important;
    }

    /* ---- Logs ---- */
    #logs-container {
        max-height: 250px !important;
    }

    /* ---- Error Log Table ---- */
    #error-log-table {
        font-size: 9px;
    }

    /* ---- Volume Spikes Tab ---- */
    #tab-volume-spikes {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    .vs-header-bar {
        flex-direction: column;
        gap: 4px;
        padding: 6px 10px;
        align-items: flex-start;
    }

    .vs-header-left {
        font-size: 10px;
    }

    .vs-header-right {
        font-size: 9px;
    }

    .vs-table {
        font-size: 10px;
        min-width: 520px;
    }

    .vs-table thead th {
        padding: 5px 6px;
        font-size: 9px;
    }

    .vs-table td {
        padding: 6px;
    }

    .vs-coin-name {
        font-size: 11px;
    }

    .vs-coin-pair {
        font-size: 8px;
    }

    .vs-dir-badge {
        font-size: 9px;
        padding: 2px 5px;
    }

    .vs-buy-pct {
        font-size: 8px;
    }

    .vs-price-val {
        font-size: 10px;
    }

    .vs-price-change {
        font-size: 9px;
    }

    .vs-spike-badge {
        font-size: 10px;
        padding: 2px 6px;
    }

    .vs-vol-now {
        font-size: 10px;
    }

    .vs-vol-avg {
        font-size: 8px;
    }

    .vs-time {
        font-size: 9px;
        white-space: nowrap;
    }

    .vs-table-wrapper {
        max-height: 300px;
    }
}

/* ============ GRID BOT OVERLAY MOBILE ============ */
@media (max-width: 768px) {
    #grid-bot-overlay {
        z-index: 10001;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    #grid-bot-modal {
        position: relative !important;
        top: 0 !important; left: 0 !important;
        transform: none !important;
        width: 100% !important; max-height: none !important;
        min-height: 100vh; min-height: 100dvh;
        border-radius: 0 !important;
    }
    #gbm-body {
        flex-direction: column !important;
        overflow-y: visible !important;
        min-height: 0;
    }
    #gbm-chart-panel {
        flex: none !important;
        height: 240px;
        min-height: 200px;
        max-height: 280px;
        border-right: none !important;
        border-bottom: 1px solid rgba(255,255,255,0.05);
    }
    #gbm-orderbook-panel {
        width: 100% !important;
        max-height: none !important;
        border-right: none !important;
        border-bottom: 1px solid rgba(255,255,255,0.05);
        overflow: visible !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
    }
    #gbm-orderbook-panel .ob-header {
        width: 100% !important;
        flex-shrink: 0 !important;
        order: 1 !important;
    }
    /* Price divider: full width, between header and columns */
    #gbm-ob-divider {
        width: 100% !important;
        flex-shrink: 0 !important;
        order: 2 !important;
    }
    /* Sells (left column) and buys (right column): side by side */
    #gbm-ob-sells {
        width: 50% !important;
        flex: none !important;
        max-height: 200px !important;
        overflow-y: auto !important;
        border-right: 1px solid rgba(255,255,255,0.05) !important;
        box-sizing: border-box !important;
        order: 3 !important;
    }
    #gbm-ob-buys {
        width: 50% !important;
        flex: none !important;
        max-height: 200px !important;
        overflow-y: auto !important;
        box-sizing: border-box !important;
        order: 4 !important;
    }
    /* Order rows compact for mobile */
    .ob-row {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 2px !important;
        padding: 2px 6px !important;
        font-size: 9px !important;
    }
    .ob-side {
        min-width: 18px !important;
        font-size: 7px !important;
        display: inline-block !important;
    }
    .ob-price {
        flex: 1 !important;
        text-align: right !important;
        font-size: 9px !important;
        display: inline-block !important;
    }
    .ob-amt {
        min-width: 35px !important;
        text-align: right !important;
        font-size: 8px !important;
        display: inline-block !important;
    }
    #gbm-dashboard {
        width: 100% !important;
        padding-bottom: 80px !important;
    }
}

/* ============ SMALL PHONE: <= 400px ============ */
@media (max-width: 400px) {
    .chart-container {
        height: 38vh;
        min-height: 120px;
    }

    .top-bar {
        padding: 6px 8px;
    }

    .balance-group {
        gap: 2px;
    }

    .cyber-metric {
        padding: 3px 4px;
    }

    .cyber-metric .label {
        font-size: 7px;
    }

    .cyber-metric .value {
        font-size: 10px;
    }

    .tab-btn {
        padding: 6px 8px;
        font-size: 10px;
    }

    .vs-table {
        min-width: 460px;
        font-size: 9px;
    }

    .vs-table thead th {
        padding: 4px 5px;
        font-size: 8px;
    }

    .vs-table td {
        padding: 5px;
    }

    .mobile-nav-toggle button {
        padding: 6px 10px;
        font-size: 16px;
        min-width: 38px;
    }
}

/* ============ LANDSCAPE PHONE ============ */
@media (max-width: 768px) and (orientation: landscape) {
    .chart-container {
        height: 55vh;
        min-height: 120px;
    }

    .tab-content {
        max-height: 150px;
    }

    .top-bar {
        flex-direction: row;
        gap: 10px;
    }

    .balance-group {
        width: auto;
    }

    .selector-group {
        width: auto;
    }
}

/* ============ TOUCH IMPROVEMENTS ============ */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .tab-btn {
        min-height: 44px;
    }

    .coin-tb-btn {
        min-height: 32px;
    }

    .settings-nav-btn {
        min-height: 44px;
    }

    .cyber-btn {
        min-height: 44px;
    }

    /* Disable hover effects on touch devices */
    .ai-terminal-card:hover,
    .ai-news-container:hover,
    .ai-chat-container:hover,
    .thinking-card:hover {
        transform: none;
    }

    /* Smooth scrolling */
    .tab-content,
    .terminal-log,
    .ai-news-feed-direct,
    .positions-grid,
    #tab-history {
        -webkit-overflow-scrolling: touch;
    }
}
