/* ═══════════════════════════════════════════════════════════
   MOMENTUM SURFER — MOBILE RESPONSIVE STYLES
   Target: < 768px (tablet portrait + phones)
   Breakpoints: 1024 (tablet landscape), 768 (tablet portrait), 480 (phone)
   ═══════════════════════════════════════════════════════════ */

/* ─── Global tweaks for all sizes ────────────────────────────── */
html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: contain; }
* { -webkit-tap-highlight-color: rgba(0,242,255,0.1); }

/* Bigger touch targets semua button + link */
@media (hover: none) and (pointer: coarse) {
    button, .nav-item, .radar-filter-btn, .trade-filter-btn, .filter-btn,
    .btn-control, .btn-gradient, .mc-select, .refresh-btn {
        min-height: 40px;
    }
    input, select, textarea {
        font-size: 16px !important;   /* Prevent iOS zoom on focus */
    }
}

/* ═══════════════════════════════════════════════════════════
   TABLET LANDSCAPE (≤ 1024px)
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    :root { --sidebar-width: 200px; }
    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)) !important;
        gap: 0.7rem !important;
    }
    .main-content, main.main-content {
        padding: 1rem !important;
    }
    .radar-card-grid {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)) !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE (≤ 768px) — Hamburger drawer + vertical layout
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    :root { --sidebar-width: 260px; }

    /* Hamburger button (fixed top-left) */
    .mobile-hamburger {
        display: flex !important;
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 10001;
        width: 42px;
        height: 42px;
        border-radius: 50%;
        background: rgba(5, 11, 24, 0.95);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(0, 242, 255, 0.3);
        color: #00f2ff;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        font-size: 22px;
        padding: 0;
        user-select: none;
        box-shadow: 0 2px 12px rgba(0,0,0,0.5);
    }
    .mobile-hamburger:active { transform: scale(0.92); }

    /* Sidebar jadi drawer off-canvas */
    .app-container {
        display: block !important;
        min-height: 100vh;
    }
    .sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        height: 100vh;
        width: 260px !important;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.34, 1.4, 0.64, 1);
        z-index: 10000;
        padding: 4rem 1rem 1rem !important;
        box-shadow: 0 0 30px rgba(0,0,0,0.7);
    }
    body.sidebar-open .sidebar {
        transform: translateX(0);
    }
    body.sidebar-open::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.6);
        z-index: 9998;
        backdrop-filter: blur(2px);
    }

    .logo {
        font-size: 1rem !important;
        margin-bottom: 1.5rem !important;
    }
    .nav-item {
        padding: 0.8rem 0.9rem !important;
        font-size: 0.95rem !important;
    }

    /* Main content full width */
    .main-content, main.main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 60px 0.75rem 1rem !important;
    }

    /* Header compact */
    .header {
        flex-direction: column !important;
        gap: 0.8rem !important;
        align-items: flex-start !important;
        padding: 0.5rem 0 !important;
    }
    .header h1 {
        font-size: 1.2rem !important;
        padding-left: 52px;  /* reserve space for hamburger */
    }
    .header p { font-size: 0.8rem !important; }
    .header-controls {
        width: 100%;
        justify-content: flex-end;
    }
    .btn-control {
        padding: 0.5rem 0.8rem !important;
        font-size: 0.78rem !important;
    }
    .btn-control .status-text { display: inline !important; }
    .status-badge {
        font-size: 0.75rem !important;
        padding: 0.35rem 0.7rem !important;
    }

    /* Stats grid — 2 columns on mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.5rem !important;
        margin-bottom: 0.8rem !important;
    }
    .stat-card {
        padding: 0.8rem 0.7rem !important;
        border-radius: 10px !important;
    }
    .stat-label {
        font-size: 0.65rem !important;
        letter-spacing: 0.8px;
    }
    .stat-value {
        font-size: 1.1rem !important;
        word-break: break-word;
    }
    .stat-trend {
        font-size: 0.7rem !important;
    }

    /* Regime banner */
    .regime-banner {
        padding: 0.6rem 0.8rem !important;
        font-size: 0.8rem !important;
        flex-wrap: wrap;
    }

    /* Section headers */
    .section-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }
    .section-header h2 {
        font-size: 1rem !important;
    }

    /* Radar header controls — wrap */
    .radar-header-bar {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.6rem !important;
    }
    .radar-controls {
        width: 100%;
        display: flex !important;
        flex-wrap: wrap;
        gap: 0.4rem !important;
    }
    .radar-filter-btn {
        padding: 0.4rem 0.7rem !important;
        font-size: 0.72rem !important;
    }
    .search-input {
        flex: 1 1 100%;
        padding: 0.5rem 0.8rem !important;
        font-size: 16px !important; /* iOS no-zoom */
    }

    /* Radar card grid — 1 column */
    .radar-card-grid {
        grid-template-columns: 1fr !important;
        max-height: 520px !important;
    }

    /* Tables — responsive. Either scroll horizontal or stack */
    .table-section {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 10px;
    }
    .table-section table {
        min-width: 640px;  /* ensure scroll when needed */
    }
    .table-section th, .table-section td {
        padding: 0.5rem 0.6rem !important;
        font-size: 0.8rem !important;
        white-space: nowrap;
    }
    /* First column sticky kiri biar konteks tetap kelihatan saat scroll */
    .table-section th:first-child,
    .table-section td:first-child {
        position: sticky;
        left: 0;
        background: #040c18;
        z-index: 2;
    }

    /* Trade filter bar — wrap */
    .trade-filter-bar {
        width: 100%;
        display: flex !important;
        flex-wrap: wrap;
        gap: 0.3rem !important;
    }
    .trade-filter-btn {
        padding: 0.4rem 0.7rem !important;
        font-size: 0.72rem !important;
    }
    #trade-search {
        flex: 1 1 100% !important;
        font-size: 16px !important;
    }

    /* Mascot smaller on mobile */
    .bot-mascot {
        bottom: 10px !important;
        right: 10px !important;
    }
    .mascot-body {
        width: 56px !important;
        height: 56px !important;
        font-size: 26px !important;
    }
    .mascot-bubble {
        max-width: calc(100vw - 80px) !important;
        font-size: 11px !important;
        padding: 8px 12px !important;
    }
    .mascot-history {
        max-width: calc(100vw - 32px) !important;
        max-height: 60vh !important;
    }

    /* Modal overrides */
    .modal-overlay .modal-content,
    .modal-content {
        width: calc(100vw - 20px) !important;
        max-width: 100% !important;
        margin: 10px !important;
        padding: 1rem !important;
    }

    /* Iframe tab views — hilangkan max height 100vh karena topbar hamburger */
    .tab-view iframe {
        height: calc(100vh - 60px) !important;
    }

    /* Sidebar footer */
    .sidebar-footer {
        font-size: 0.75rem !important;
    }
    .regime-badge {
        padding: 0.35rem 0.6rem !important;
        font-size: 0.72rem !important;
    }

    /* Positions table alt — kalau mau stack jadi cards */
    .position-card-mobile {
        display: block;
        background: rgba(255,255,255,0.03);
        border-radius: 10px;
        padding: 0.8rem;
        margin-bottom: 0.6rem;
    }
}

/* ═══════════════════════════════════════════════════════════
   PHONE (≤ 480px) — Ultra compact
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .main-content, main.main-content {
        padding: 58px 0.5rem 0.8rem !important;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.4rem !important;
    }
    .stat-card { padding: 0.7rem 0.6rem !important; }
    .stat-value { font-size: 1rem !important; }
    .header h1 { font-size: 1.1rem !important; }
    .btn-control .status-text { display: none !important; }
    .status-badge > span { display: none; }

    .mascot-body {
        width: 50px !important;
        height: 50px !important;
        font-size: 22px !important;
    }
}

/* ═══════════════════════════════════════════════════════════
   IFRAME PAGES — Mobile overrides (learning_lab, training_log, dll)
   Pages ini self-contained (punya CSS sendiri), overrides via common class
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* Stats strip (Lab + Training Log) */
    .stats-strip {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .ss-item {
        padding: 8px 10px !important;
    }
    .ss-val {
        font-size: 14px !important;
    }

    /* Topbar */
    .topbar {
        height: auto !important;
        padding: 8px 12px !important;
        flex-wrap: wrap;
        gap: 8px !important;
    }

    /* Main grid (Lab) */
    .main {
        grid-template-columns: 1fr !important;
        padding: 10px !important;
    }

    /* Panel spacing */
    .panel {
        padding: 10px !important;
    }
    .panel-hdr {
        font-size: 10px !important;
        padding-bottom: 8px !important;
    }

    /* Filter bar */
    .filter-bar {
        flex-wrap: wrap;
        padding: 10px !important;
        gap: 6px !important;
    }
    .filter-btn {
        padding: 6px 10px !important;
        font-size: 10px !important;
    }

    /* Trade row (training_log + lab) */
    .trade-row,
    .trade-row-ext {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 4px !important;
        font-size: 11px !important;
        padding: 10px 8px !important;
        border-bottom: 2px solid rgba(15, 32, 53, 0.6) !important;
    }
    .trade-row.hdr,
    .trade-row-ext:first-child {
        display: none !important;  /* hide header row, gunakan label inline */
    }
    .trade-row > span::before,
    .trade-row-ext > span::before {
        content: attr(data-label) " ";
        color: #475569;
        font-size: 9px;
        font-weight: 700;
        letter-spacing: 0.5px;
    }

    /* ML panel phase row */
    .phase-row {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
    .current-phase, .phase-pipeline, .model-meta {
        padding: 10px !important;
    }
    .pipeline-steps .lbl {
        font-size: 8px !important;
    }

    /* Insights grid */
    .insights-grid {
        grid-template-columns: 1fr !important;
    }

    /* ML config grid */
    .mc-grid {
        grid-template-columns: 1fr !important;
    }

    /* Daily digest wrapper — single column */
    .wrapper {
        grid-template-columns: 1fr !important;
    }
    .wrapper .sidebar {
        max-height: 200px !important;
        height: auto !important;
        border-right: none !important;
        border-bottom: 1px solid #0f2035 !important;
    }
    .wrapper .main {
        padding: 16px 12px !important;
    }
}
