/* ============================================================
   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;
    -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-bottom: env(safe-area-inset-bottom)) {
    body {
        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;
    }

    .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;
    }

    /* 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;
        background: var(--card-bg, #121212);
        border-bottom: 1px solid var(--border-color, #2a2a2a);
        gap: 10px;
    }

    /* 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);
}

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

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