/* ================================================
   RIBE SAMFÄLLIGHETSFÖRENING - Mobil & Webb CSS
   Extra responsivitet för alla enheter
================================================ */

/* ---- GLOBALT ---- */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* ---- SÖKRUTA ---- */
.search-container {
    position: relative;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 2rem;
    padding: 0.5rem 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    min-width: 200px;
}

.search-box:focus-within {
    border-color: #2c5530;
    box-shadow: 0 0 0 3px rgba(44, 85, 48, 0.15);
}

.search-input {
    border: none;
    background: transparent;
    outline: none;
    font-size: 0.95rem;
    width: 180px;
    color: #374151;
}

.search-input::placeholder {
    color: #9ca3af;
}

.search-results {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    border: 1px solid #e5e7eb;
    max-height: 400px;
    overflow-y: auto;
    z-index: 9999;
    display: none;
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 1rem 1.25rem;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.15s;
}

.search-result-item:hover {
    background: #f9fafb;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-title {
    font-weight: 600;
    color: #2c5530;
    margin-bottom: 0.25rem;
    font-size: 0.95rem;
}

.search-result-snippet {
    font-size: 0.85rem;
    color: #6b7280;
    line-height: 1.5;
}

.search-result-snippet mark,
.search-result-title mark {
    background: #fde68a;
    color: #1f2937;
    border-radius: 2px;
    padding: 0 2px;
}

.search-no-results {
    padding: 1.5rem;
    text-align: center;
    color: #6b7280;
    font-size: 0.9rem;
}

/* ======================================
   RESPONSIVITET - SURFPLATTOR (max 900px)
====================================== */
@media (max-width: 900px) {
    /* Välkommen-bilder */
    div[id="welcome"] img,
    #welcome img {
        max-width: 100% !important;
    }

    /* Drone-bildgalleri på mobil */
    div[style*="display: flex; justify-content: center; gap: 1rem"] {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }

    /* Kalender-rutnät: låt korten få plats med text */
    .hero-dates-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.75rem !important;
    }

    .date-card {
        min-width: 0 !important;
        overflow: visible !important;
    }

    .date-card h4,
    .date-card p {
        overflow-wrap: anywhere;
        word-break: break-word;
        hyphens: auto;
        max-width: 100%;
    }

    /* Footer */
    .footer-content {
        grid-template-columns: 1fr !important;
        text-align: center !important;
    }

    /* Sektions-knappar */
    .hero-buttons {
        flex-wrap: wrap !important;
        justify-content: center !important;
    }
}

/* ======================================
   MOBIL - SMARTPHONES (max 768px)
====================================== */
@media (max-width: 768px) {

    /* --- Navbar --- */
    .navbar {
        padding: 0.5rem 1rem !important;
    }

    .nav-container {
        flex-wrap: wrap !important;
        padding: 0.5rem 1rem !important;
        gap: 0.5rem !important;
    }

    /* --- Sökning på mobil --- */
    .search-container {
        width: 100% !important;
        order: 10 !important;
    }

    .search-box {
        width: 100% !important;
        min-width: unset !important;
    }

    .search-input {
        width: 100% !important;
    }

    .search-results {
        position: fixed !important;
        left: 1rem !important;
        right: 1rem !important;
        top: auto !important;
        width: calc(100% - 2rem) !important;
        max-height: 50vh !important;
        z-index: 9999 !important;
    }

    /* --- PDF-knappar --- */
    a[href$=".pdf"],
    a[href*="pdf"] {
        display: block !important;
        width: 100% !important;
        text-align: center !important;
        margin-bottom: 0.5rem !important;
    }

    /* --- Kartor / Iframes --- */
    iframe {
        width: 100% !important;
        max-width: 100% !important;
        height: 300px !important;
    }

    /* --- Bilder --- */
    img {
        max-width: 100% !important;
        height: auto !important;
        border-radius: 0.5rem;
    }

    /* Välkommen-bildrader på mobil */
    #welcome div[style*="display: flex"] {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 0.5rem !important;
    }

    #welcome div[style*="display: flex"] img {
        width: 80px !important;
        height: 55px !important;
    }

    #welcome img#mainWelcomeImage {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
    }

    /* --- Sektions-innehåll --- */
    .container {
        padding: 0 1rem !important;
    }

    section {
        padding: 3rem 0 !important;
    }

    /* --- Rubriker --- */
    h1 { font-size: clamp(1.8rem, 6vw, 2.5rem) !important; }
    h2 { font-size: clamp(1.4rem, 5vw, 2rem) !important; }
    h3 { font-size: clamp(1.1rem, 4vw, 1.5rem) !important; }

    /* --- Hero --- */
    .hero-content {
        grid-template-columns: 1fr !important;
        padding: 1.5rem 1rem !important;
        text-align: center !important;
    }

    .hero-text p {
        font-size: 1rem !important;
    }

    /* --- Kategoriflikar (menytabs) --- */
    .menu-categories {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.5rem !important;
        position: static !important;
        top: auto !important;
    }

    .menu-tab {
        width: 100% !important;
        text-align: center !important;
        padding: 0.75rem 1rem !important;
    }

    /* --- Kortgalleri --- */
    .uniform-grid {
        grid-template-columns: 1fr !important;
    }

    /* --- Accordion --- */
    .accordion-header {
        font-size: 1rem !important;
        padding: 1rem !important;
    }

    /* --- Knappar --- */
    .btn {
        padding: 0.75rem 1.5rem !important;
        font-size: 0.95rem !important;
        touch-action: manipulation;
    }

    /* --- Hovring -> Tryck på mobil --- */
    .search-result-item:active {
        background: #f3f4f6 !important;
    }

    /* --- Hero-widgets: stapla klocka och datum under varandra --- */
    .hero,
    .hero-content,
    .hero-widgets,
    .clock-widget,
    .hero-dates,
    .date-card {
        overflow: visible !important;
    }

    .hero-content .hero-widgets,
    .hero-widgets {
        display: grid !important;
        grid-template-columns: 1fr !important;
        grid-template-areas:
            "clock"
            "dates" !important;
        gap: 1.25rem !important;
        width: 100% !important;
    }

    .clock-widget {
        display: block !important;
        width: 100% !important;
        max-width: none !important;
    }

    .hero-scroll {
        position: relative !important;
        bottom: auto !important;
        left: auto !important;
        margin: 0.25rem auto 1.5rem !important;
        z-index: 12 !important;
    }

    /* --- Dropdown-meny på mobil --- */
    .dropdown-content,
    .dropdown-submenu-content {
        position: static !important;
        opacity: 1 !important;
        visibility: visible !important;
        transform: none !important;
        box-shadow: none !important;
        display: none;
        background: rgba(255,255,255,0.8) !important;
    }

    .dropdown-content.show,
    .dropdown-submenu-content.show {
        display: block !important;
    }

    /* --- Scroll to top-knapp --- */
    .scroll-to-top {
        bottom: 1.5rem !important;
        right: 1rem !important;
        width: 3rem !important;
        height: 3rem !important;
        font-size: 1rem !important;
    }

    /* --- Tabell responsivitet --- */
    .mobile-responsive-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* --- Footer --- */
    .footer-content {
        grid-template-columns: 1fr !important;
        gap: 2rem !important;
        text-align: center !important;
    }

    .social-links {
        justify-content: center !important;
    }

    /* --- Grannsamverkan-sektion --- */
    .grann-content {
        grid-template-columns: 1fr !important;
    }
}

/* ======================================
   LITEN TELEFON (max 480px)
====================================== */
@media (max-width: 480px) {
    .hero-buttons {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .btn {
        width: 100% !important;
        text-align: center !important;
    }

    .date-card {
        padding: 0.75rem !important;
    }

    h2[style*="font-size: 2.5rem"] {
        font-size: 1.8rem !important;
    }

    /* Välkommen-bilder ännu mindre */
    #welcome div[style*="display: flex"] img {
        width: 65px !important;
        height: 45px !important;
    }

    /* PDF-knapp full bredd */
    a[href$=".pdf"] {
        font-size: 0.9rem !important;
        padding: 0.75rem 1rem !important;
    }
}

/* ======================================
   TOUCH-VÄNLIGA KLICKBARA ELEMENT
====================================== */
a, button, .menu-tab, .accordion-header,
.search-result-item, .nav-link, .btn {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Minsta tryckytor = 44px (Apple/Google standard) */
.nav-link,
.menu-tab,
.btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ======================================
   BILDER OCH MEDIA - ALLTID RESPONSIVA
====================================== */
img, video, canvas, svg, embed, object, iframe {
    max-width: 100%;
}

iframe[src*="google.com/maps"],
iframe[src*="maps.google"] {
    width: 100% !important;
    border-radius: 0.75rem;
    border: none;
}

/* ======================================
   PRINTING
====================================== */
@media print {
    .navbar, .scroll-to-top,
    .search-container, .hamburger {
        display: none !important;
    }
    body {
        font-size: 12pt;
        color: black;
        background: white;
    }
}

/* ======================================
   GUIDE-CARD FIX - Kategorikort på mobil
   Problem: "Mer info"-knapp skärs av till
   höger pga white-space:nowrap + flex.
   Fix: wrap layout, knapp på egen rad.
====================================== */

/* Alltid: Förhindra kort från att orsaka horisontell scroll */
.guide-card {
    max-width: 100%;
    box-sizing: border-box;
}

/* Alltid: body-delen ska inte trycka ut knappen */
.guide-card__body {
    min-width: 0;
    flex: 1 1 0;
    overflow-wrap: break-word;
    word-break: break-word;
}

.guide-card__meta {
    overflow-wrap: break-word;
    word-break: break-word;
}

/* Mobil < 640px: Flex wrappas, knappen hamnar på ny rad */
@media (max-width: 640px) {
    .guide-card {
        flex-wrap: wrap !important;
        padding: 1rem 0.95rem !important;
        gap: 0.7rem !important;
    }

    /* Ikon: lite mindre */
    .guide-card__icon {
        width: 46px !important;
        height: 46px !important;
        flex: 0 0 46px !important;
    }

    /* Body: ta kvarvarande plats */
    .guide-card__body {
        flex: 1 1 calc(100% - 46px - 0.7rem) !important;
        min-width: 0 !important;
    }

    /* "Mer info"-knappen: bryt nowrap, lägg på ny rad med indrag */
    .guide-card__cta {
        white-space: normal !important;
        flex-basis: 100% !important;
        width: fit-content !important;
        margin-left: calc(46px + 0.7rem) !important;
        align-self: flex-start !important;
        font-size: 0.85rem !important;
        padding: 0.38rem 0.7rem !important;
    }

    /* Rubrik lite kompaktare */
    .guide-card__title {
        font-size: 1.05rem !important;
        line-height: 1.25 !important;
    }

    /* Beskrivning: visa all text, ej klipt */
    .guide-card__meta {
        font-size: 0.9rem !important;
        -webkit-line-clamp: unset !important;
        overflow: visible !important;
        display: block !important;
    }

    /* Grid för guide-korten: alltid en kolumn */
    .guide-cards-grid,
    .guide-cards-list {
        grid-template-columns: 1fr !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.65rem !important;
    }
}

/* Extra smal skärm < 400px */
@media (max-width: 400px) {
    .guide-card {
        padding: 0.8rem 0.75rem !important;
        gap: 0.55rem !important;
    }

    .guide-card__icon {
        width: 38px !important;
        height: 38px !important;
        flex: 0 0 38px !important;
    }

    .guide-card__icon i {
        font-size: 1rem !important;
    }

    .guide-card__cta {
        margin-left: calc(38px + 0.55rem) !important;
        font-size: 0.8rem !important;
    }

    .guide-card__title {
        font-size: 0.97rem !important;
    }
}

/* ======================================
   MENU-ITEM FIX - korrigering på mobil
====================================== */
@media (max-width: 640px) {
    .menu-item {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        padding: 1rem !important;
    }

    .item-info {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        overflow-wrap: break-word !important;
    }

    .menu-item a.btn,
    .menu-item .btn {
        flex-basis: 100% !important;
        width: 100% !important;
    }
}
