/* Keten Mobile Improvements */

/* Mobile-specific styles for chain visualization */
@media (max-width: 992px) {
    /* Make chain detail panel sticky on mobile for better visibility */
    .chain-detail-panel {
        position: sticky;
        top: 70px; /* Account for header */
        z-index: 10;
        margin-bottom: 10px;
        padding: 20px;
    }

    /* Adjust chain visualization container */
    .chain-visualization {
        padding: 20px 15px;
        gap: 20px;
    }

    /* Optimize chain row for mobile */
    .chain-row {
        gap: 10px;
        padding: 0;
    }

    /* Make arrows smaller and less prominent */
    .chain-arrow {
        font-size: 1.2rem;
        opacity: 0.5;
        margin: 2px 0;
    }

    /* Smaller nodes on mobile */
    .chain-node {
        width: 80px;
        height: 80px;
        box-shadow: 0 3px 10px rgba(0,0,0,0.1);
    }

    .node-icon {
        width: 36px;
        height: 36px;
        font-size: 16px;
        margin-bottom: 5px;
    }

    .chain-node h4 {
        font-size: 0.75rem;
        line-height: 1.2;
    }

    /* Chain details mobile optimization */
    .chain-details {
        margin-top: 20px;
    }

    /* Mobile detail cards */
    .chain-detail {
        padding: 20px;
        margin-bottom: 40px; /* Increased to prevent overlap */
        /* Add visual connection to active node */
        border-top: 4px solid #4a7c3a;
        position: relative;
        z-index: 1;
    }

    /* Stack problem and solution vertically on mobile */
    .detail-content {
        flex-direction: column;
        gap: 20px;
    }

    /* Smaller headers on mobile */
    .detail-header h3 {
        font-size: 1.1rem;
    }

    .detail-problem h4, .detail-solution h4 {
        font-size: 1rem;
    }

    /* Optimize list spacing */
    .detail-problem ul, .detail-solution ul {
        padding-left: 15px;
    }

    .detail-problem li, .detail-solution li {
        margin-bottom: 8px;
        font-size: 0.95rem;
    }

    /* Hide feedback text on very small screens */
    .chain-feedback {
        font-size: 0.85rem;
        padding: 5px;
    }
}

/* Very small screens (phones in portrait) */
@media (max-width: 576px) {
    /* Even smaller nodes with better padding */
    .chain-node {
        width: 70px;
        height: 70px;
        padding: 10px 5px; /* Added internal padding */
    }

    .node-icon {
        width: 28px; /* Reduced from 32px */
        height: 28px; /* Reduced from 32px */
        font-size: 12px; /* Reduced from 14px */
        margin-bottom: 4px; /* Adjusted spacing */
    }

    .chain-node h4 {
        font-size: 0.6rem; /* Reduced from 0.7rem */
        line-height: 1.1;
    }

    /* Simplify arrows */
    .chain-arrow {
        font-size: 1rem;
    }

    /* Compact detail panel */
    .chain-detail-panel {
        padding: 15px;
    }

    .detail-header h3 {
        font-size: 1rem;
    }

    /* Add scroll hint for chain */
    .chain-visualization::after {
        content: "← Scroll horizontaal →";
        display: block;
        text-align: center;
        font-size: 0.75rem;
        color: #999;
        margin-top: 10px;
        display: none; /* Will show via JS when needed */
    }
}

/* Accordion-style implementation for mobile */
@media (max-width: 768px) {
    /* Create accordion container */
    .mobile-chain-accordion {
        display: none; /* Hidden by default, shown via JS on mobile */
        margin-top: 30px;
    }

    .mobile-chain-item {
        background: white;
        border-radius: 8px;
        margin-bottom: 10px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        overflow: hidden;
        transition: all 0.3s ease;
    }

    .mobile-chain-header {
        display: flex;
        align-items: center;
        padding: 15px;
        cursor: pointer;
        background: #f8f8f5;
        transition: background 0.3s ease;
    }

    .mobile-chain-header:hover {
        background: #f0f0ed;
    }

    .mobile-chain-header.active {
        background: #4a7c3a;
        color: white;
    }

    .mobile-chain-header .node-icon {
        margin-right: 15px;
        margin-bottom: 0;
    }

    .mobile-chain-header.active .node-icon {
        background: white;
        color: #4a7c3a;
    }

    .mobile-chain-content {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        padding: 0 15px;
    }

    .mobile-chain-content.active {
        max-height: 1000px;
        padding: 15px;
    }

    /* Arrow indicator */
    .mobile-chain-header::after {
        content: "▼";
        margin-left: auto;
        font-size: 0.8rem;
        transition: transform 0.3s ease;
    }

    .mobile-chain-header.active::after {
        transform: rotate(180deg);
    }
}

/* Enhanced mobile experience */
@media (max-width: 768px) {
    /* Prevent detail overlap with content below */
    .chain-details {
        margin-bottom: 50px; /* Extra space at bottom */
    }
    
    /* Make detail panel not sticky on very small screens to prevent overlap */
    .chain-detail-panel {
        position: relative; /* Changed from sticky */
        top: auto;
    }

    /* Add touch feedback */
    .chain-node:active {
        transform: scale(0.95);
    }

    /* Better tap targets with more padding */
    .chain-node {
        min-width: 70px;
        min-height: 70px;
        padding: 8px 4px; /* Added internal padding */
    }
    
    /* Smaller icons and text for 768px */
    .node-icon {
        width: 32px; /* Reduced from 36px */
        height: 32px;
        font-size: 14px; /* Reduced from 16px */
    }
    
    .chain-node h4 {
        font-size: 0.65rem; /* Reduced from 0.75rem */
    }

    /* Visual feedback for active state */
    .chain-node.active {
        background-color: #4a7c3a;
        color: white;
    }

    .chain-node.active .node-icon {
        background-color: white;
        color: #4a7c3a;
    }

    .chain-node.active h4 {
        color: white;
    }

    /* Smooth scroll to detail */
    html {
        scroll-behavior: smooth;
    }
}

/* Challenges section mobile optimization */
@media (max-width: 992px) {
    .keten-challenges {
        padding: 20px;
        gap: 20px;
    }

    .challenge-header h3 {
        font-size: 1.2rem;
    }

    /* Optimize diagram for mobile */
    .challenge-diagram img {
        max-height: 300px;
        object-fit: contain;
        width: 100%;
    }

    .challenge-explanation {
        font-size: 0.95rem;
    }

    .challenge-list {
        font-size: 0.9rem;
    }
}

/* Horizontal scroll for chain on very small screens */
@media (max-width: 576px) {
    .chain-links {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 10px;
    }

    .chain-row {
        flex-direction: row;
        width: max-content;
        gap: 8px;
    }

    .chain-arrow {
        transform: none;
        align-self: center;
    }

    /* Scroll indicator */
    .chain-links {
        position: relative;
    }

    .chain-links::after {
        content: "";
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 30px;
        background: linear-gradient(to right, transparent, rgba(255,255,255,0.8));
        pointer-events: none;
    }
}

/* Alternative: Tab-style for mobile */
.mobile-tabs-container {
    display: none; /* Will be shown via JS on mobile */
}

@media (max-width: 768px) {
    .mobile-tabs {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 10px;
        padding: 10px 0;
        margin-bottom: 20px;
    }

    .mobile-tab {
        flex: 0 0 auto;
        padding: 10px 20px;
        background: #f8f8f5;
        border-radius: 20px;
        cursor: pointer;
        transition: all 0.3s ease;
        white-space: nowrap;
        font-size: 0.9rem;
    }

    .mobile-tab.active {
        background: #4a7c3a;
        color: white;
    }

    .mobile-tab-content {
        display: none;
        animation: fadeIn 0.3s ease;
    }

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

    @keyframes fadeIn {
        from { opacity: 0; transform: translateY(10px); }
        to { opacity: 1; transform: translateY(0); }
    }
}

/* iPhone-specific overflow prevention */
@media (max-width: 414px) {
    /* Prevent horizontal overflow on all grid containers */
    .chain-visualization,
    .problem-breakdown,
    .hero-stats {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Force single column layouts */
    .chain-links,
    .chain-row {
        flex-direction: column !important;
        width: 100% !important;
        gap: 10px !important;
    }
    
    /* Ensure proper spacing */
    .chain-node,
    .breakdown-card {
        margin: 0 auto !important;
        max-width: calc(100vw - 30px) !important;
    }
    
    /* Statistics section specific fixes */
    .stats-container,
    .stats-grid {
        overflow-x: hidden !important;
        max-width: 100% !important;
        padding: 0 10px !important;
    }
    
    .stat-card {
        max-width: calc(100vw - 25px) !important;
        overflow: hidden !important;
        word-wrap: break-word !important;
    }
    
    .stat-number {
        font-size: 1.4rem !important;
        word-break: break-word !important;
    }
}
