/* ============================================================
   RESPONSIVE.CSS - Master Responsive & Bug-Fix Layer
   Black Liquidity Trading Academy
   ============================================================
   This file is loaded LAST on every page to fix:
   - Overflow issues
   - Mobile layout bugs  
   - Typography scaling
   - iOS Safari quirks
   - z-index conflicts
   - Touch target sizes
   ============================================================ */

/* ── GLOBAL RESETS & SAFETY ──────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    overflow-x: hidden;
    width: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Force all images responsive */
img, video, canvas, svg {
    max-width: 100%;
    height: auto;
}

/* iOS safe area padding */
@supports (padding: env(safe-area-inset-bottom)) {
    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
    .main-wrapper {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Fix iOS 100vh issue */
@supports (-webkit-touch-callout: none) {
    .hero-section,
    .hero {
        min-height: -webkit-fill-available;
    }
}

/* ── RESPONSIVE TYPOGRAPHY WITH CLAMP ───────────────── */
:root {
    --fs-xs: clamp(0.7rem, 1.5vw, 0.8rem);
    --fs-sm: clamp(0.8rem, 1.8vw, 0.9rem);
    --fs-base: clamp(0.9rem, 2vw, 1rem);
    --fs-md: clamp(1rem, 2.2vw, 1.15rem);
    --fs-lg: clamp(1.1rem, 2.5vw, 1.4rem);
    --fs-xl: clamp(1.4rem, 3vw, 2rem);
    --fs-2xl: clamp(1.8rem, 4vw, 3rem);
    --fs-3xl: clamp(2rem, 5vw, 3.5rem);
    --fs-hero: clamp(2.2rem, 6vw, 4.5rem);
}

/* ── SIDEBAR MOBILE FIX ─────────────────────────────── */
@media (max-width: 860px) {
    .sidebar {
        transform: translateX(-110%) !important;
        position: fixed !important;
        width: 280px !important;
        z-index: 500 !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        padding: 24px !important;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-top: calc(24px + env(safe-area-inset-top)) !important;
        padding-bottom: calc(24px + env(safe-area-inset-bottom)) !important;
    }

    .sidebar.is-open {
        transform: translateX(0) !important;
    }

    /* Backdrop when sidebar is open */
    .sidebar.is-open::after {
        content: '';
        position: fixed;
        top: 0;
        left: 280px;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: -1;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* Sidebar menu scrollable */
    .sidebar .sidebar-menu {
        overflow-y: auto;
        flex-shrink: 1;
        min-height: 0;
        -webkit-overflow-scrolling: touch;
    }

    /* Sidebar footer stays visible */
    .sidebar .sidebar-footer-nav {
        flex-shrink: 0;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .sidebar .logout-btn-full {
        margin-bottom: 8px;
    }

    /* Mobile bar spacing fix */
    .blt-mobilebar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 300;
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        padding: 12px 16px;
        padding-top: calc(12px + env(safe-area-inset-top));
        background: var(--card-bg, #121212);
        border-bottom: 1px solid var(--border-color, #2a2a2a);
        gap: 10px;
        min-height: 56px;
    }

    /* Push content below mobile bar */
    .main-content {
        padding-top: 60px !important;
    }

    /* Header inside main-content: hide on mobile to avoid overlap */
    .main-content > header {
        position: relative !important;
        top: auto !important;
    }

    /* Close button in sidebar */
    #mobile-close-btn {
        display: grid !important;
    }

    /* Sidebar footer */
    .sidebar .footer-btn-grid {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .sidebar .sidebar-logo span,
    .sidebar .sidebar-menu a span,
    .sidebar .footer-btn-grid .footer-tile span,
    .sidebar .logout-btn-full span {
        opacity: 1 !important;
        pointer-events: auto !important;
    }
}

/* ── HEADER ACTIONS RESPONSIVE ──────────────────────── */
@media (max-width: 768px) {
    .main-content > header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
        padding: 1rem !important;
    }

    .header-actions {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .zoom-controls {
        display: none !important; /* Hide zoom on mobile - not useful */
    }

    .header-title {
        font-size: var(--fs-base) !important;
        word-break: break-word;
    }

    .nav-usr-name {
        display: none; /* Hide username text on mobile */
    }
}

@media (max-width: 480px) {
    .main-content > header {
        padding: 0.75rem !important;
    }
}

/* ── INDEX / LANDING PAGE ────────────────────────────── */

/* Hero section */
.hero-section {
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for iOS */
}

.hero-content h1 {
    font-size: var(--fs-hero);
    line-height: 1.08;
    letter-spacing: -1px;
}

.hero-content p {
    font-size: var(--fs-md);
}

.hero-stats {
    flex-wrap: wrap;
}

.stat span {
    font-size: clamp(1.5rem, 3vw, 2rem);
}

/* Section titles */
.section-title {
    font-size: var(--fs-2xl) !important;
}

.section-subtitle {
    font-size: var(--fs-base);
}

/* Pricing */
.pricing-title h2 {
    font-size: var(--fs-2xl) !important;
}

.price {
    font-size: clamp(2.5rem, 5vw, 3.5rem);
}

/* CTA */
.final-cta-section h2 {
    font-size: var(--fs-2xl) !important;
}

/* Login modal */
.login-section {
    padding: 1rem;
}

.login-card {
    max-width: 450px;
    width: 100%;
    margin: 0 auto;
    max-height: 90vh;
    overflow-y: auto;
}

/* Index header fix */
.hero-section ~ .login-section,
.login-section {
    z-index: 1000;
}

@media (max-width: 768px) {
    /* Index header */
    header:has(.logo-container) {
        padding: 1rem;
    }

    .brand-name {
        font-size: 1rem;
    }

    .hero-section {
        padding-top: 80px !important;
    }

    .hero-content {
        padding: 0 1rem;
    }

    .hero-content h1 {
        letter-spacing: -0.5px;
    }

    .hero-actions {
        flex-direction: column;
        width: 100%;
        gap: 1rem;
    }

    .btn-entry {
        width: 100%;
        justify-content: center;
        padding: 1rem 1.5rem;
        font-size: 1rem;
    }

    .hero-stats {
        flex-direction: column;
        gap: 1.5rem;
        text-align: center;
    }

    /* Grids to single column */
    .steps-grid,
    .testimonials-grid,
    .pricing-grid {
        grid-template-columns: 1fr !important;
    }

    /* Section padding reduction */
    section {
        padding: 3rem 1rem !important;
    }

    .final-cta-section {
        padding: 4rem 1rem !important;
    }

    .step-card,
    .testimonial-card,
    .price-card {
        padding: 2rem 1.5rem;
    }

    .login-card {
        padding: 2rem 1.5rem;
        border-radius: 16px;
    }
}

@media (max-width: 390px) {
    .hero-content h1 {
        font-size: 1.8rem;
    }

    .hero-content p {
        font-size: 0.95rem;
    }

    .badge {
        font-size: 0.7rem;
        padding: 0.4rem 0.8rem;
    }
}

/* ── DASHBOARD ───────────────────────────────────────── */
.dashboard-content {
    padding: clamp(1rem, 3vw, 2rem);
}

.progress-title h2 {
    font-size: clamp(1.1rem, 2.5vw, 1.5rem);
}

@media (max-width: 768px) {
    .dash-two-cols {
        grid-template-columns: 1fr !important;
    }

    .dash-three-cols {
        grid-template-columns: 1fr !important;
    }

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

    .hero-progress {
        padding: 1.5rem !important;
    }

    .progress-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .achievements-grid {
        flex-direction: column;
    }

    .achievement-badge {
        min-width: unset !important;
        width: 100%;
    }

    .analysis-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.3rem;
    }
}

@media (max-width: 480px) {
    .metrics-grid {
        grid-template-columns: 1fr !important;
    }

    .metric-value {
        font-size: 1.5rem !important;
    }

    .action-item {
        padding: 0.8rem;
    }

    .action-text {
        font-size: 0.85rem;
    }
}

/* ── ACADEMY (Netflix style) ─────────────────────────── */
.hero {
    min-height: 50vh;
}

.hero-title {
    font-size: var(--fs-3xl) !important;
}

.hero-desc {
    font-size: var(--fs-base);
}

@media (max-width: 860px) {
    .hero {
        height: auto !important;
        min-height: 40vh;
        margin-bottom: 0 !important;
        padding: 2rem 4% !important;
        align-items: flex-end !important;
    }

    .hero-content {
        max-width: 100% !important;
    }

    .hero-title {
        font-size: clamp(1.5rem, 5vw, 2rem) !important;
    }

    .hero-desc {
        font-size: 0.9rem;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .hero-buttons {
        flex-wrap: wrap;
    }

    .hero-buttons .btn {
        padding: 0.6rem 1.2rem;
        font-size: 0.9rem;
    }

    /* Carousel cards */
    .card-item {
        min-width: 160px !important;
        height: 90px !important;
    }

    .card-item:hover {
        transform: scale(1.05) !important; /* Less aggressive on mobile */
        z-index: 10;
    }

    /* Hide slider handles on mobile - use swipe */
    .slider-handle {
        display: none !important;
    }

    .carousel-title {
        font-size: 1.1rem;
    }

    .content-sections {
        padding: 0 3% !important;
    }

    .carousel-container {
        margin-bottom: 2rem;
    }

    .carousel-title .explore {
        opacity: 1 !important;
    }
}

@media (max-width: 480px) {
    .card-item {
        min-width: 140px !important;
        height: 80px !important;
    }

    .card-title {
        font-size: 0.7rem !important;
    }
}

/* ── EPISODE PAGE ────────────────────────────────────── */
.player-section {
    padding: 0 clamp(1rem, 3vw, 2rem);
}

.ep-title {
    font-size: clamp(1.4rem, 3.5vw, 2.2rem) !important;
}

.ep-desc {
    font-size: var(--fs-base);
}

@media (max-width: 768px) {
    .player-section {
        margin: 1rem auto !important;
    }

    .video-wrapper {
        border-radius: 8px !important;
    }

    .ep-tags {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .module-header {
        padding: 1rem;
    }

    .module-title-wrapper {
        gap: 1rem;
    }

    .module-title {
        font-size: 0.95rem !important;
    }

    .module-content {
        padding: 0 1rem 1.5rem 1rem !important;
    }

    .modules-accordion {
        margin-bottom: 4rem !important;
    }

    .concepts-title {
        font-size: 1.2rem;
        margin: 2rem 0 1rem;
    }
}

/* ── PROP FIRMS ──────────────────────────────────────── */
.pf-hero h1 {
    font-size: var(--fs-2xl) !important;
}

.pf-section-title {
    font-size: var(--fs-xl) !important;
}

@media (max-width: 768px) {
    .pf-hero {
        padding: 2.5rem 1.5rem !important;
    }

    .pf-hero h1 {
        line-height: 1.2;
    }

    .pf-hero p {
        font-size: 1rem;
    }

    .flow-container {
        flex-direction: column;
        gap: 1.5rem;
        padding: 1.5rem;
    }

    .flow-arrow {
        display: none;
    }

    .flow-step {
        flex-direction: row;
        min-width: unset;
        gap: 1rem;
    }

    .flow-icon {
        width: 48px;
        height: 48px;
        flex-shrink: 0;
    }

    .fail-grid {
        grid-template-columns: 1fr !important;
    }

    .timeline-step {
        flex-direction: column;
        gap: 1rem;
    }

    .simulator-card {
        padding: 1.5rem;
    }

    /* Table scroll */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .prop-table {
        min-width: 600px;
    }

    .prop-table th,
    .prop-table td {
        padding: 0.8rem;
        font-size: 0.85rem;
    }

    .rules-list {
        max-width: 100%;
    }

    .pf-cta-final h2 {
        font-size: clamp(1.5rem, 4vw, 2.5rem) !important;
    }

    .pf-section {
        margin-bottom: 2.5rem;
    }
}

/* ── PROFILE ─────────────────────────────────────────── */
@media (max-width: 860px) {
    .profile-container {
        grid-template-columns: 1fr !important;
        padding: 1rem !important;
        gap: 1.5rem;
    }

    .profile-sidebar {
        padding: 2rem 1.5rem;
    }

    .avatar-wrapper {
        width: 120px;
        height: 120px;
    }

    .profile-form-area {
        padding: 1.5rem;
    }

    .form-row {
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .btn-save {
        width: 100%;
        text-align: center;
    }

    /* intl-tel-input fix */
    .iti {
        width: 100% !important;
    }
}

/* ── TRADING MODE ────────────────────────────────────── */
@media (max-width: 1024px) {
    .middle-grid {
        grid-template-columns: 1fr !important;
    }

    .engine-content {
        flex-direction: column !important;
    }

    .gauges-container {
        flex-wrap: wrap;
        justify-content: center;
    }

    .gauge-card {
        min-width: 150px;
        flex: 1 1 calc(50% - 1rem);
    }
}

@media (max-width: 768px) {
    .cockpit-layout {
        padding: 1rem;
    }

    .engine-metrics {
        flex-direction: column;
    }

    .engine-value {
        font-size: 2rem !important;
    }

    .gauge-card {
        flex: 1 1 100%;
    }

    .builder-content {
        max-height: 250px;
    }

    .rule-if,
    .rule-then {
        flex-direction: column;
        align-items: flex-start;
    }

    .condition-select,
    .action-select {
        width: 100%;
    }
}

/* ── KYC / MODALS ────────────────────────────────────── */
.crop-modal.show,
.kyc-modal.show,
.crop-modal[style*="flex"],
.kyc-modal[style*="flex"] {
    display: flex !important;
}

@media (max-width: 768px) {
    .crop-modal-content,
    .kyc-modal .kyc-content {
        width: 95% !important;
        max-width: 100% !important;
        padding: 1.5rem !important;
        max-height: 90vh;
        overflow-y: auto;
    }

    .kyc-modal {
        padding: 0.5rem;
    }

    .upload-area {
        min-height: 120px !important;
    }
}

/* ── TOUCH TARGETS ───────────────────────────────────── */
@media (pointer: coarse) {
    button,
    .btn,
    .btn-entry,
    .btn-subscribe,
    .btn-login,
    .btn-save,
    .btn-mode,
    .btn-continue,
    .btn-primary-large,
    .footer-tile,
    .sidebar-menu a,
    .action-item,
    .module-header,
    a[href] {
        min-height: 44px;
    }

    .sidebar-menu a {
        padding: 14px 16px !important;
    }

    .action-item {
        padding: 12px !important;
    }

    .module-header {
        padding: 14px !important;
    }

    /* Larger checkboxes */
    .checkbox {
        width: 24px !important;
        height: 24px !important;
    }
}

/* ── LIGHT THEME PATCHES ─────────────────────────────── */
[data-theme="light"] .hero-content h1,
body:not([data-theme="dark"]) .hero-content h1 {
    background: linear-gradient(180deg, #000 0%, #444 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

[data-theme="light"] .dash-card,
body:not([data-theme="dark"]) .dash-card {
    background: var(--card-bg, #fff);
    border-color: var(--border-color, #e5e5e5);
}

[data-theme="light"] .hero-progress,
body:not([data-theme="dark"]) .hero-progress {
    background: linear-gradient(145deg, #f5f5f5, #fff);
    border-color: var(--border-color, #e5e5e5);
}

[data-theme="light"] .action-item,
body:not([data-theme="dark"]) .action-item {
    background: #f8f8f8;
    border-color: var(--border-color, #e5e5e5);
}

[data-theme="light"] .metric-value,
body:not([data-theme="dark"]) .metric-value {
    color: var(--text-color, #000);
}

[data-theme="light"] .progress-stats span,
body:not([data-theme="dark"]) .progress-stats span {
    color: var(--text-color, #000);
}

[data-theme="light"] .content-sections,
body:not([data-theme="dark"]) .content-sections {
    background: linear-gradient(to top, var(--bg-color, #fff) 80%, transparent) !important;
}

[data-theme="light"] .error-card,
body:not([data-theme="dark"]) .error-card {
    background: linear-gradient(145deg, #fff, rgba(255, 68, 68, 0.03));
}

[data-theme="light"] .error-recommendation,
body:not([data-theme="dark"]) .error-recommendation {
    background: rgba(0, 0, 0, 0.03);
}

[data-theme="light"] .mentor-note,
body:not([data-theme="dark"]) .mentor-note {
    background: rgba(0, 0, 0, 0.02);
    color: #555;
}

[data-theme="light"] .achievement-badge,
body:not([data-theme="dark"]) .achievement-badge {
    background: #f8f8f8;
    border-color: var(--border-color, #e5e5e5);
}

[data-theme="light"] .badge-info h4,
body:not([data-theme="dark"]) .badge-info h4 {
    color: var(--text-color, #000);
}

/* ── ANIMATION PERFORMANCE ───────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Optimize card hover on mobile */
@media (hover: none) {
    .card-item:hover {
        transform: none !important;
    }

    .card-item:hover .card-info {
        opacity: 1;
    }

    .card-info {
        opacity: 1 !important;
    }

    .step-card:hover,
    .price-card:hover,
    .fail-card:hover,
    .dash-card:hover {
        transform: none !important;
    }
}

/* ── SCROLLBAR STYLING ───────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.3);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(128, 128, 128, 0.5);
}

/* Backdrop Overlay Default (Hidden on Desktop) */
.theme-selector-overlay {
    display: none;
}

/* ── THEME SELECTOR MOBILE ───────────────────────────── */

@media (max-width: 768px) {
    /* Backdrop Overlay */
    .theme-selector-overlay {
        display: block !important;
        background: rgba(0, 0, 0, 0.45) !important;
        backdrop-filter: blur(6px) !important;
        -webkit-backdrop-filter: blur(6px) !important;
        z-index: 290 !important;
    }

    /* Compact Panel */
    .theme-selector-panel {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        right: auto !important;
        bottom: auto !important;
        transform: translate(-50%, -50%) !important;
        width: min(92vw, 420px) !important;
        max-height: 70dvh !important;
        margin-top: 0 !important;
        border-radius: 24px !important;
        padding: 0.75rem !important;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5) !important;
        z-index: 300 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        padding-top: calc(0.75rem + env(safe-area-inset-top)) !important;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom)) !important;
    }

    /* Compact Items */
    .theme-selector-panel .flex-col.gap-4 {
        gap: 1rem !important;
        padding: 0.5rem 0 !important;
    }

    .theme-selector-panel button {
        padding: 0.6rem 0.75rem !important;
        min-height: unset !important;
        border-radius: 14px !important;
        gap: 0.75rem !important;
    }

    .theme-selector-panel .w-8.h-8 {
        width: 1.75rem !important;
        height: 1.75rem !important;
        border-radius: 10px !important;
    }

    .theme-selector-panel .w-8.h-8 svg {
        width: 1rem !important;
        height: 1rem !important;
    }

    .theme-selector-panel .text-\[10px\] {
        font-size: 0.75rem !important;
    }

    /* Family headers */
    .theme-selector-panel .mb-2.flex.items-center.gap-2 {
        margin-bottom: 0.5rem !important;
    }

    /* Sticky header in panel */
    .theme-selector-panel .sticky {
        padding-top: 0.25rem !important;
        padding-bottom: 0.75rem !important;
        margin-bottom: 0.5rem !important;
    }

    /* Prevent body scroll when open */
    body:has(.theme-selector-panel) {
        overflow: hidden !important;
    }
}


/* ── DASHBOARD HEADER MOBILE ─────────────────────────── */
@media (max-width: 860px) {
    /* Dashboard header: adapt for mobile with mobilebar present */
    header.sticky {
        position: relative !important;
        top: auto !important;
        z-index: 50;
        height: auto !important;
        min-height: 56px;
        padding: clamp(0.75rem, 2vw, 1rem) clamp(1rem, 3vw, 2rem) !important;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Page title smaller on mobile */
    header h2 {
        font-size: clamp(0.9rem, 3.5vw, 1.25rem) !important;
    }

    /* Hide the market session panel on mobile - it's lg:flex already */
    /* Profile link in header - compact */
    header .flex-1:last-child {
        gap: 0.5rem !important;
    }
}

/* ── MAIN CONTENT MOBILE ─────────────────────────────── */
@media (max-width: 860px) {
    .main-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .dashboard-content,
    main.flex-1 {
        padding: clamp(0.75rem, 3vw, 1.5rem) !important;
        overflow-x: hidden;
    }
}

/* ── IPHONE / MOBILE SPECIFIC (max-width: 480px) ────── */
@media (max-width: 480px) {
    /* Header ultra-compact */
    header.sticky {
        padding: 0.6rem 0.75rem !important;
    }

    header h2 {
        font-size: 0.85rem !important;
    }

    /* Dashboard content tight padding */
    .dashboard-content,
    main.flex-1 {
        padding: 0.75rem !important;
    }

    /* Cards: reduce padding */
    .dash-card,
    .metric-card,
    .stat-card,
    .profile-card,
    .module-card {
        padding: 1rem !important;
    }

    /* Grids single column */
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4,
    .lg\:grid-cols-2,
    .lg\:grid-cols-3,
    .lg\:grid-cols-4,
    .md\:grid-cols-2,
    .md\:grid-cols-3 {
        grid-template-columns: 1fr !important;
    }

    /* Buttons full width */
    .btn-new-trade,
    .btn-primary-large,
    .btn-update {
        width: 100%;
        text-align: center;
        justify-content: center;
    }

    /* Fix flex wrapping */
    .flex.gap-4,
    .flex.gap-6,
    .flex.gap-8 {
        flex-wrap: wrap;
    }

    /* Journal search input */
    .search-input {
        width: 100% !important;
    }

    /* Journal trades grid */
    .trades-grid {
        grid-template-columns: 1fr !important;
    }

    /* Journal filters scroll */
    .journal-filters {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        padding-bottom: 0.5rem;
    }

    /* Journal header stack */
    .journal-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .journal-title {
        font-size: 1.4rem;
    }

    /* FAQ compact */
    .faq-hero h1 {
        font-size: 1.6rem;
    }

    .faq-question {
        padding: 1rem;
        font-size: 0.9rem;
    }

    .faq-answer p,
    .faq-answer ul {
        padding: 0 1rem 1rem;
    }

    /* Profile avatar smaller */
    .avatar-wrapper {
        width: 100px;
        height: 100px;
    }

    .profile-card {
        padding: 1.5rem !important;
        border-radius: 16px;
    }
}

/* ── IPHONE PRO MAX SPECIFIC (430px width) ───────────── */
@media (max-width: 430px) {
    /* Mobile bar brand text */
    .blt-mobilebar .brand {
        font-size: 0.85rem;
        gap: 8px;
    }

    /* Sidebar logo orb smaller */
    .blt-mobilebar .sidebar-logo-orb {
        width: 28px;
        height: 28px;
    }

    /* Section margins */
    .dash-section,
    .pf-section,
    .cashflow-section {
        margin-bottom: 1.5rem;
    }

    /* Large text clamping */
    h3.text-3xl,
    h3.text-2xl {
        font-size: clamp(1.2rem, 5vw, 1.6rem) !important;
    }

    h4.text-2xl {
        font-size: clamp(1rem, 4vw, 1.4rem) !important;
    }

    /* Metric values */
    .text-2xl.font-black {
        font-size: clamp(1.2rem, 5vw, 1.5rem) !important;
    }

    /* Fix Estado del Trader card horizontal overflow */
    .flex.items-center.gap-8 {
        flex-direction: column !important;
        gap: 1rem !important;
        text-align: center;
    }

    /* Grid columns override for Tailwind grids */
    [class*="lg:grid-cols"],
    [class*="md:grid-cols"] {
        grid-template-columns: 1fr !important;
    }

    /* Rounded corners smaller */
    .rounded-3xl {
        border-radius: 16px !important;
    }

    /* Padding p-8 override */
    .p-8 {
        padding: 1rem !important;
    }

    .p-6 {
        padding: 0.75rem !important;
    }

    /* Trading hub cockpit */
    .cockpit-layout {
        padding: 0.5rem !important;
    }

    /* Hub carousel cards */
    .module-card {
        min-width: 240px !important;
        max-width: 240px !important;
    }

    /* Academy hub hero */
    .hub-hero {
        padding: 1.5rem 1rem !important;
    }

    .hub-hero h1 {
        font-size: 1.5rem !important;
    }

    /* Hub controls stack */
    .hub-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .hub-search {
        min-width: unset;
        width: 100%;
    }

    /* Prop firms */
    .prop-firms-content {
        padding: 1rem;
    }

    /* View trade modal full width */
    .view-trade-modal {
        width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        border-radius: 0 !important;
    }

    .view-modal-sidebar {
        width: 100% !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border-color);
    }

    /* Trade modal */
    .trade-modal {
        width: 95% !important;
        max-height: 85vh !important;
        max-height: 85dvh !important;
        padding: 1.25rem !important;
    }

    /* Form grid single column */
    .form-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ── MODAL FIXES FOR ALL MOBILE ──────────────────────── */
@media (max-width: 768px) {
    .modal-overlay {
        padding: 0.5rem;
    }

    .trade-modal,
    .kyc-modal .kyc-content,
    .crop-modal-content {
        max-height: 90vh !important;
        max-height: 90dvh !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* KYC modal */
    .kyc-modal {
        padding: env(safe-area-inset-top) 0.5rem env(safe-area-inset-bottom) !important;
    }

    /* Login card on mobile */
    .login-card {
        max-height: 90vh;
        max-height: 90dvh;
        overflow-y: auto;
    }
}

/* ── JOURNAL MOBILE FIXES ────────────────────────────── */
@media (max-width: 768px) {
    .journal-container {
        padding: 1rem;
    }

    .journal-stats {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-value {
        font-size: 1.4rem;
    }

    /* Staged date picker */
    .staged-date-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }

    /* Image gallery preview */
    .img-preview-item img {
        max-height: 200px;
    }
}

@media (max-width: 480px) {
    .journal-stats {
        grid-template-columns: 1fr !important;
    }
}

/* ── CASHFLOW MOBILE FIXES ───────────────────────────── */
@media (max-width: 480px) {
    .cashflow-header {
        flex-direction: column;
        align-items: stretch;
    }

    .cashflow-header .flex.gap-4 {
        flex-direction: row;
        width: 100%;
    }

    .cashflow-header .flex.gap-4 button {
        flex: 1;
    }
}

/* ── PROFILE MOBILE FIXES ────────────────────────────── */
@media (max-width: 480px) {
    .profile-container {
        padding: 0.5rem !important;
    }

    .input-group {
        margin-bottom: 1rem;
    }

    .custom-input {
        padding: 0.8rem 1rem;
        font-size: 16px; /* Prevents iOS zoom on input focus */
    }

    .btn-update {
        padding: 1rem 2rem;
        width: 100%;
    }

    /* Upload zone */
    .upload-zone {
        padding: 2rem 1rem;
    }
}

/* ── VIEWPORT HEIGHT FIX FOR ALL MOBILE ──────────────── */
@media (max-width: 860px) {
    /* Replace 100vh usage with dvh */
    .hero-section,
    .login-section {
        min-height: 100vh;
        min-height: 100dvh;
        height: auto;
    }

    /* View trade modal */
    .view-trade-modal {
        height: 90vh;
        height: 90dvh;
    }
}

/* ── PREVENT HORIZONTAL OVERFLOW GLOBALLY ────────────── */
html, body {
    overflow-x: hidden !important;
    max-width: 100vw;
}

.main-wrapper,
.dashboard-content,
main,
section {
    max-width: 100%;
    overflow-x: hidden;
}

/* ── INPUT ZOOM PREVENTION (iOS) ─────────────────────── */
@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important; /* Prevents Safari zoom on focus */
    }
}

/* ── PRINT ───────────────────────────────────────────── */
@media print {
    .sidebar,
    .blt-mobilebar,
    .theme-toggle,
    .zoom-controls,
    #stars-canvas,
    .hero-overlay {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
    }
}
