* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body, html { margin: 0; padding: 0; height: 100%; width: 100%; overflow: hidden; font-family: 'Segoe UI', sans-serif; overscroll-behavior: none; -webkit-user-select: none; user-select: none; }

/* Safe area support for modern phones with notch */
:root {
    --sat: env(safe-area-inset-top, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    /* Mobile layout heights */
    --nav-h: 56px;
    --search-h: 56px;
}

#map {
    height: 100%;
    width: 100%;
    background-color: #7CFC00;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Cg fill='%2355aa55' opacity='0.2'%3E%3Cpath d='M10 10l5 20H5zM30 5l5 20h-10zM5 30l5 8h-10z'/%3E%3C/g%3E%3C/svg%3E");
    cursor: default;
    touch-action: manipulation;
}

/* Voergang Texture */
path.voergang-texture {
    fill: url(#voerPattern) !important;
    fill-opacity: 1 !important;
    stroke: #8D6E63 !important;
    stroke-width: 2px !important;
}

/* Legenda */
.legend {
    background: rgba(255, 255, 255, 0.95);
    padding: 12px 15px;
    color: #333;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    border-radius: 4px;
    font-size: 13px;
    min-width: 280px;
    max-width: 350px;
    border: 1px solid #ccc;
    max-height: 80vh;
    overflow-y: auto;
}
.legend h4 {
    margin: 0 0 8px;
    color: #444;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
}
.legend i { width: 16px; height: 16px; float: left; margin-right: 8px; border: 1px solid rgba(0,0,0,0.2); }

.legend-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: #666;
    padding: 0;
    width: 24px;
    height: 24px;
    display: none;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.legend-toggle:hover {
    color: #333;
}

.legend-content {
    display: block;
    transition: max-height 0.3s ease;
}

.legend.collapsed .legend-content {
    display: none;
}

.legend.collapsed .legend-toggle {
    transform: rotate(180deg);
}

.legend.collapsed h4 {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

/* --- KOE NUMMER LABELS --- */
.cow-label {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: #000000 !important;
    font-weight: 900;
    font-size: 13px;
    text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff;
    display: none; /* Standaard uit */
    margin-top: -2px !important;
}

/* Verwijder het witte pijltje (driehoekje) */
.cow-label::before { display: none; }

/* Debug-modus ID label */
.debug-id-label {
    background: rgba(0,0,0,0.75) !important;
    color: #fff !important;
    font-size: 10px !important;
    font-weight: 700 !important;
    padding: 2px 6px !important;
    border: none !important;
    border-radius: 3px !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3) !important;
    pointer-events: none !important;
    white-space: nowrap !important;
}
.debug-id-label::before { display: none !important; }

/* Als de kaart de class 'show-labels' heeft, laat ze zien */
.show-labels .cow-label { display: block; }

/* --- KOE INFO SECTIE IN LEGENDA --- */
.cow-info-section {
    display: none;
    border-top: 2px solid #4CAF50;
    padding-top: 12px;
    margin-top: 12px;
}

.cow-info-section.active {
    display: block;
}

.cow-info-section h4 {
    margin: 0 0 10px 0;
    color: #2E7D32;
    font-size: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: none;
    padding-bottom: 0;
}

.cow-info-section .close-btn {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.cow-info-section .close-btn:hover {
    color: #f44336;
}

.cow-info-section .info-content {
    line-height: 1.6;
    font-size: 13px;
}

.cow-info-section .info-content b {
    color: #555;
}

/* --- TOP ZONE (flex container voorkomt overlap) --- */
.top-zone {
    position: absolute;
    top: calc(6px + var(--sat));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    max-width: 94%;
    width: auto;
    pointer-events: none;
}
.top-zone > * {
    pointer-events: auto;
}

/* --- ZOEKBALK BOVEN --- */
.search-control {
    background: white;
    padding: 6px 10px;
    border-radius: 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
    justify-content: center;
    width: auto;
}

.search-control input {
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 6px 10px;
    font-size: 13px;
    width: 110px;
    outline: none;
    min-height: 36px;
    -webkit-user-select: text;
    user-select: text;
    min-width: 0;
}

.search-control input:focus {
    border-color: #4CAF50;
}

.search-control button {
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 12px;
    padding: 6px 12px;
    font-weight: 600;
    cursor: pointer;
    font-size: 12px;
    min-height: 36px;
    touch-action: manipulation;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Desktop: show text, hide icon */
.search-btn .btn-icon { display: none; }
.search-btn .btn-text { display: inline; }

.search-control button:hover {
    background: #45a049;
}

.search-control button:active {
    transform: scale(0.98);
}

.search-control button.clear-btn {
    background: #f44336;
    padding: 8px 14px;
}

.search-control button.clear-btn:hover {
    background: #da190b;
}

/* Highlighted cow styling */
.highlighted-cow-marker {
    position: relative;
}

.highlighted-cow-marker::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    background: rgba(76, 175, 80, 0.4);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
    z-index: -1;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

.highlighted-cow-marker img {
    position: relative;
    z-index: 1;
}

/* --- SCHAKELAAR MIDDEN ONDER --- */
.bottom-control {
    position: absolute;
    bottom: calc(12px + var(--sab));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: white;
    padding: 8px 14px;
    border-radius: 25px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #333;
    font-size: 12px;
    max-width: 94%;
    flex-wrap: wrap;
    justify-content: center;
}

/* Toggle Switch Styling */
.switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 28px; }
.slider:before { position: absolute; content: ""; height: 22px; width: 22px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: #4CAF50; }
input:checked + .slider:before { transform: translateX(22px); }

/* === HAMBURGER / LEGENDA BTN — verborgen, logica in mobile-nav-bar === */
.hamburger-btn { display: none; }

/* Mobiele legenda overlay */
.mobile-legend-overlay {
    display: none; position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4); z-index: 1010; opacity: 0; transition: opacity 0.3s ease;
    pointer-events: none;
}
.mobile-legend-overlay.active { opacity: 1; pointer-events: auto; }

.mobile-legend-panel {
    display: none; position: absolute; top: 0; right: 0; bottom: 0;
    width: 300px; max-width: 85vw; background: white; z-index: 1011;
    box-shadow: -4px 0 20px rgba(0,0,0,0.25);
    transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.mobile-legend-panel.active { transform: translateX(0); }

.legend-panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: calc(16px + var(--sat)) 16px 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    position: sticky; top: 0; background: white; z-index: 1;
}
.legend-panel-header h3 { margin: 0; font-size: 16px; color: #333; display: flex; align-items: center; gap: 8px; }
.legend-panel-close {
    background: #f5f5f5; border: none; border-radius: 50%; width: 32px; height: 32px;
    font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: #555; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.legend-panel-close:active { background: #e0e0e0; }

#mobileLegendContent { padding: 8px 16px calc(16px + var(--sab)) 16px; }

.mobile-legend-panel .legend-item {
    display: flex; align-items: center; padding: 10px 0;
    border-bottom: 1px solid #f0f0f0; font-size: 14px; color: #444;
}
.mobile-legend-panel .legend-item i {
    width: 22px; height: 22px; border-radius: 4px; margin-right: 12px;
    border: 1px solid rgba(0,0,0,0.15); flex-shrink: 0;
}
.mobile-legend-panel .legend-item:last-child { border-bottom: none; }

/* === MOBIELE KOE-INFO BOTTOM SHEET === */
.cow-info-mobile {
    position: absolute; bottom: 0; left: 0; right: 0;
    z-index: 1005; background: white; border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.18);
    padding: 16px 20px 20px;
    max-height: 55vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
    transform: translateY(100%); transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    display: block;
}
.cow-info-mobile.active { transform: translateY(0); pointer-events: auto; }
.cow-info-mobile .drag-handle { width: 36px; height: 4px; background: #ddd; border-radius: 2px; margin: 0 auto 14px; }
.cow-info-mobile h4 { margin: 0 0 10px; color: #2E7D32; font-size: 16px; display: flex; justify-content: space-between; align-items: center; }
.cow-info-mobile .close-btn {
    background: #f5f5f5; border: none; border-radius: 50%; font-size: 18px; cursor: pointer;
    color: #555; width: 36px; height: 36px; min-width: 36px;
    display: flex; align-items: center; justify-content: center;
    touch-action: manipulation;
}
.cow-info-mobile .close-btn:active { background: #e0e0e0; }
.cow-info-mobile .info-content { line-height: 1.8; font-size: 14px; }
.cow-info-mobile .info-content b { color: #555; }

/* === MOBIELE BOTTOM NAV BAR === */
.mobile-nav-bar {
    display: none; /* desktop: verborgen */
}

/* === ZOOM FABS (mobiel) === */
.zoom-fabs {
    display: none; /* desktop: verborgen */
}

/* === RESPONSIVE: MOBILE === */
@media screen and (max-width: 768px) {

    /* Desktop-only elementen verbergen */
    #desktopBottomControl { display: none !important; }
    .leaflet-control-zoom { display: none !important; }
    .leaflet-bottom.leaflet-right .legend { display: none !important; }
    .cow-info-section { display: none !important; }

    /* Legenda overlay en panel tonen */
    .mobile-legend-overlay, .mobile-legend-panel { display: block; }

    /* === SEARCH BAR: verborgen panel boven nav bar, opent via Zoek nav-knop === */
    .top-zone {
        position: absolute;
        top: auto;
        bottom: calc(var(--nav-h) + var(--sab));
        left: 0; right: 0;
        transform: translateY(100%);
        max-width: 100%; width: 100%;
        flex-direction: row;
        align-items: center;
        padding: 8px 10px;
        gap: 6px;
        background: rgba(255, 255, 255, 0.97);
        -webkit-backdrop-filter: blur(12px);
        backdrop-filter: blur(12px);
        box-shadow: 0 -1px 0 rgba(0,0,0,0.07);
        border-top: 1px solid rgba(0,0,0,0.06);
        z-index: 1001;
        pointer-events: none;
        opacity: 0;
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
        visibility: hidden;
    }
    .top-zone.active {
        transform: translateY(0);
        pointer-events: auto;
        opacity: 1;
        visibility: visible;
    }

    .search-control {
        flex: 1; min-width: 0; width: 100%;
        background: transparent; box-shadow: none; padding: 0; border-radius: 0; gap: 6px;
    }

    .search-control input {
        flex: 1; width: auto; min-width: 0;
        font-size: 14px; min-height: 40px;
        border-radius: 10px; padding: 8px 12px;
        border: 1.5px solid #e0e0e0;
    }
    .search-control input:focus { border-color: #4CAF50; }

    .search-btn { min-height: 40px; padding: 8px 14px; border-radius: 10px; }
    .search-btn .btn-text { display: none; }
    .search-btn .btn-icon { display: inline; font-size: 18px; line-height: 1; }

    .clear-btn { min-height: 40px; padding: 8px 12px; border-radius: 10px; }

    /* === BOTTOM NAV BAR === */
    .mobile-nav-bar {
        display: flex;
        position: absolute;
        bottom: 0; left: 0; right: 0;
        height: calc(var(--nav-h) + var(--sab));
        padding-bottom: var(--sab);
        padding-top: 4px;
        background: white;
        box-shadow: 0 -1px 0 rgba(0,0,0,0.09), 0 -4px 20px rgba(0,0,0,0.08);
        border-top: 1px solid rgba(0,0,0,0.06);
        z-index: 1000;
        justify-content: space-around;
        align-items: flex-start;
    }

    .nav-btn {
        display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
        gap: 3px; flex: 1; background: transparent; border: none; cursor: pointer;
        text-decoration: none; color: #777; padding: 6px 2px; min-height: 52px;
        font-family: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
        transition: color 0.15s ease; position: relative;
    }
    .nav-icon { font-size: 22px; line-height: 1.1; display: block; }
    .nav-label { font-size: 10px; font-weight: 600; white-space: nowrap; color: inherit; }
    .nav-btn:active { color: #4CAF50; }
    .nav-btn.active { color: #4CAF50; }
    /* Active indicator dot */
    .nav-btn.active::after {
        content: ''; position: absolute; bottom: 2px;
        width: 4px; height: 4px; border-radius: 50%; background: #4CAF50;
    }

    /* === ZOOM FABS === */
    .zoom-fabs {
        display: flex; flex-direction: column; gap: 8px;
        position: absolute;
        right: 12px;
        bottom: calc(var(--nav-h) + var(--sab) + 16px);
        z-index: 999;
    }
    .zoom-fab {
        width: 46px; height: 46px; border-radius: 14px;
        background: white; border: none;
        box-shadow: 0 2px 12px rgba(0,0,0,0.18);
        font-size: 26px; font-weight: 300; color: #333;
        cursor: pointer; display: flex; align-items: center; justify-content: center;
        touch-action: manipulation; -webkit-tap-highlight-color: transparent;
        line-height: 1; transition: transform 0.12s ease, box-shadow 0.12s ease;
        user-select: none;
    }
    .zoom-fab:active { transform: scale(0.9); box-shadow: 0 1px 6px rgba(0,0,0,0.15); }

    /* === COW INFO BOTTOM SHEET ===
       bottom: 0 (van base-stijl). translateY(100%) = volledig buiten beeld naar onderen.
       Bij .active: omhoog schuiven tot boven de nav bar via transform. */
    .cow-info-mobile {
        bottom: 0;
        max-height: 60vh;
    }
    .cow-info-mobile.active {
        /* Schuif omhoog zodat onderkant precies boven nav bar uitkomt */
        transform: translateY(calc(-1 * (var(--nav-h) + var(--sab))));
        pointer-events: auto;
    }

    /* Legend panel full height */
    .mobile-legend-panel { top: 0; bottom: 0; }

    /* Legenda & labels */
    .cow-label { font-size: 11px; }
    .legend h4 { font-size: 13px; }
    .legend-toggle { display: flex !important; }
}

@media screen and (max-width: 480px) {
    .top-zone { padding: 7px 8px; gap: 5px; }
    .search-control input { font-size: 13px; min-height: 38px; padding: 7px 10px; }
    .search-btn, .clear-btn { min-height: 38px; }
    .zoom-fabs { right: 10px; gap: 6px; }
    .zoom-fab { width: 42px; height: 42px; font-size: 24px; border-radius: 12px; }
    .nav-icon { font-size: 20px; }
    .nav-label { font-size: 9px; }
    .cow-info-mobile .info-content { font-size: 13px; }
    .cow-info-mobile { padding: 14px 16px 18px; }
}

@media screen and (max-width: 360px) {
    .top-zone { padding: 6px 6px; }
    .search-control input { font-size: 12px; min-height: 36px; padding: 6px 8px; }
    .zoom-fab { width: 38px; height: 38px; font-size: 22px; }
    .nav-icon { font-size: 18px; }
    .nav-label { font-size: 9px; }
}

@media screen and (orientation: landscape) and (max-height: 500px) {
    :root { --nav-h: 48px; --search-h: 48px; }
    .top-zone { padding: 5px 8px; }
    .search-control input { min-height: 36px; }
    .zoom-fab { width: 38px; height: 38px; font-size: 22px; }
    .cow-info-mobile { max-height: 50vh; }
}

/* === DESKTOP (min-width: 769px) === */
@media screen and (min-width: 769px) {
    .top-zone {
        position: absolute;
        top: calc(10px + var(--sat));
        left: 50%; transform: translateX(-50%);
        bottom: auto; width: auto; max-width: 94%;
        flex-direction: column;
        padding: 0; gap: 5px;
        background: transparent; box-shadow: none; border-top: none;
        pointer-events: none;
    }
    .top-zone > * { pointer-events: auto; }
    .search-control {
        background: white; box-shadow: 0 2px 10px rgba(0,0,0,0.2);
        padding: 8px 14px; border-radius: 24px; gap: 6px; width: auto;
    }
    .search-control input { width: 180px; font-size: 14px; padding: 8px 14px; min-height: 40px; border-radius: 14px; border: 1px solid #ddd; }
    .search-btn { min-height: 40px; padding: 8px 16px; border-radius: 14px; font-size: 13px; }
    .search-btn .btn-text { display: inline; }
    .search-btn .btn-icon { display: none; }
    .clear-btn { min-height: 40px; padding: 8px 14px; border-radius: 14px; }
    #desktopBottomControl { display: flex; }
    .mobile-nav-bar { display: none !important; }
    .zoom-fabs { display: none !important; }
    .mobile-legend-overlay, .mobile-legend-panel { display: none !important; }
    .cow-info-mobile { display: none !important; }
    .leaflet-bottom.leaflet-right .legend { display: block !important; }
}

/* Elegant Loading Screen */
.skeleton-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, #7CFC00 0%, #6BCF00 100%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.6s ease;
}

.skeleton-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-icon {
    width: 80px;
    height: 80px;
    margin-bottom: 30px;
    position: relative;
    animation: bounce 1.5s ease-in-out infinite;
}

.loading-icon::before {
    content: '🐄';
    font-size: 80px;
    display: block;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
}

@keyframes bounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-20px) scale(1.1); }
}

.loading-text {
    color: white;
    font-size: 24px;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
    margin-bottom: 20px;
    animation: fadeInOut 2s ease-in-out infinite;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.loading-dots {
    display: flex;
    gap: 10px;
}

.loading-dot {
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    animation: dotPulse 1.4s ease-in-out infinite;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.loading-dot:nth-child(1) { animation-delay: 0s; }
.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
    0%, 100% { transform: scale(0.8); opacity: 0.5; }
    50% { transform: scale(1.2); opacity: 1; }
}

.skeleton-overlay::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 60 60'%3E%3Cg fill='%23ffffff' opacity='0.05'%3E%3Cpath d='M15 15l8 32H7zM45 8l8 32h-16zM8 45l8 13h-16z'/%3E%3C/g%3E%3C/svg%3E");
    opacity: 0.3;
    animation: patternMove 20s linear infinite;
}

@keyframes patternMove {
    0% { background-position: 0 0; }
    100% { background-position: 60px 60px; }
}

@media screen and (max-width: 768px) {
    .loading-icon { width: 60px; height: 60px; }
    .loading-icon::before { font-size: 60px; }
    .loading-text { font-size: 18px; }
    .loading-dot { width: 10px; height: 10px; }
}

/* ?legend=off: verberg legenda (desktop-paneel, mobiel paneel & nav-knop).
   Let op: het desktop koe-info-paneel zit ín .legend en valt hiermee ook weg. */
body.no-legend .legend,
body.no-legend .mobile-legend-panel,
body.no-legend #hamburgerBtn { display: none !important; }

/* ?embed=1: pure kaart voor inbedding — verberg zoekbalk, nav-balk,
   desktop bottom-control en mobiele zoom-knoppen */
body.no-embed #topZone,
body.no-embed #mobileNavBar,
body.no-embed #desktopBottomControl,
body.no-embed #zoomFabs { display: none !important; }
