/* Fix for mobile overflow on small screens (e.g. 390x844) */

@media (max-width: 440px) {
    /* Reduce horizontal margins for main containers of inQool blocks */
    .link-box__container,
    .link-signpost__container,
    .link-info__container {
        margin-left: 10px !important;
        margin-right: 10px !important;
    }

    /* Ensure text breaks to prevent overflow */
    .link-box__item-heading,
    .link-signpost__item,
    .link-info__item-heading,
    h1, h2, h3, h4, h5, h6 {
        word-break: break-word !important;
        overflow-wrap: anywhere !important;
        hyphens: auto;
    }

    /* Adjust padding for link-box items if they still overflow */
    .link-box__item {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    /* Ensure grid columns don't force overflow */
    .link-signpost__grid {
        grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)) !important;
        gap: 15px !important;
    }

    /* Fix for any potential fixed widths in common block elements */
    .wp-block-inqool-post-list,
    .wp-block-inqool-event-list {
        width: 100% !important;
        overflow-x: hidden;
    }

    /* Project Milestones (Milníky projektu) - vertical layout for mobile */
    .project-milestone__flex {
        flex-direction: column !important;
        align-items: center !important;
        position: relative !important;
    }

    /* Vertical axis for mobile */
    .project-milestone__flex:before {
        content: "" !important;
        position: absolute !important;
        left: 50% !important;
        top: 20px !important;
        bottom: 20px !important;
        width: 1px !important;
        background-image: linear-gradient(to bottom, #b3b3b3 40%, rgba(255, 255, 255, 0) 0%) !important;
        background-position: left !important;
        background-size: 1px 10px !important;
        background-repeat: repeat-y !important;
        background-color: transparent !important;
        transform: translateX(-50%) !important;
        z-index: 0 !important;
    }

    .project-milestone__axis {
        display: none !important; /* Hide the horizontal axis */
    }

    .project-milestone__item-wrapper {
        grid-template-rows: none !important;
        grid-template-columns: 1fr !important;
        margin-right: 0 !important;
        margin-bottom: 40px !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
    }

    .project-milestone__item-wrapper:last-child {
        margin-bottom: 0 !important;
    }

    .project-milestone__item {
        max-width: 100% !important;
        min-width: 0 !important;
        width: 100% !important;
        box-sizing: border-box !important;
        order: 2 !important;
    }

    .project-milestone__item:after {
        display: none !important; /* Hide arrows for vertical layout */
    }

    .project-milestone__item-middle {
        margin: 10px 0 !important;
        order: 1 !important;
        z-index: 1 !important;
        position: relative !important;
    }

    /* Hide the empty divs used for grid spacing in horizontal layout */
    .project-milestone__item-wrapper > div:not(.project-milestone__item):not(.project-milestone__item-middle) {
        display: none !important;
    }

    .project-milestone__content {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    /* Remove pseudo-shadows on mobile to prevent weird overlay issues */
    .project-milestone__wrapper:before,
    .project-milestone__wrapper:after {
        display: none !important;
    }
}

/* General safety for overflow */
body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
}
