.em-horizontal-grid {
    position: relative;
    width: 100%;
    overflow: visible;
    box-sizing: border-box;
}

.em-grid-container {
    display: flex;
    gap: 20px;
    overflow-y: visible;
    scroll-behavior: smooth;
     /* padding inside the scrollable container so content never scrolls under
         the viewport edge; box-sizing ensures padding is included in width calc */
     padding: 10px 0;
     box-sizing: border-box;
    
    -webkit-overflow-scrolling: touch;
    
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
    justify-content: flex-start;
    align-items: stretch;
}

@media (min-width: 1200px) {
    .em-grid-container {
        overflow-x: visible;
        flex-wrap: wrap;
    }

    .em-horizontal-grid[data-card-width="auto"] .em-grid-container {
        flex-wrap: nowrap;
    }
}

@media (max-width: 1199px) and (min-width: 769px) {
    .em-grid-container {
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .em-horizontal-grid[data-card-width="auto"] .em-grid-container {
        overflow-x: visible;
    }
}

@media (max-width: 768px) {
    .em-grid-container {
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .em-horizontal-grid[data-card-width="auto"] .em-grid-container {
        overflow-x: auto;
        flex-wrap: nowrap;
        justify-content: flex-start;
        width: 100%;
        max-width: 100%;
    }

    .em-horizontal-grid[data-card-width="auto"] .em-grid-card {
        flex-shrink: 0;
        flex-grow: 0;
        
    }
}

.em-grid-container.hide-scrollbar {
    
    scrollbar-width: none;
    
    -ms-overflow-style: none;
}

.em-grid-container.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

.em-grid-container::-webkit-scrollbar {
    height: 8px;
}

.em-grid-container::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.05);
    border-radius: 4px;
}

.em-grid-container::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
    
    -webkit-transition: background-color 0.3s ease;
    transition: background-color 0.3s ease;
}

.em-grid-container::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.4);
}

.em-grid-card {
    position: relative;
    border-radius: 8px;
    
    -webkit-transition: all 0.3s ease;
    transition: all 0.3s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    
    background: #ffffff;
    
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);

    /* ensure padding is included in width calculations so text doesn't overflow */
    box-sizing: border-box;
}

@media (min-width: 1200px) {
    .em-grid-card {
        flex: 1 1 auto;
        min-width: 250px;
        max-width: 400px;
    }
}

@media (max-width: 1199px) {
    .em-grid-card {
        flex-shrink: 0;
    }
}

.em-grid-card.no-shadow {
    box-shadow: none !important;
}

.em-grid-card:hover {
    
    -webkit-transform: translateY(-2px);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.em-grid-card.no-shadow:hover {
    box-shadow: none !important;
}

.em-grid-card-content {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    min-height: 100%;

    /* protect against text being visually cut off at edges */
    white-space: normal;
    overflow-wrap: break-word;
    word-break: break-word;
    box-sizing: border-box;
}

.em-grid-card-content img {
    width: 100%;
    height: auto;
    max-height: 300px; 
    object-fit: contain;
    object-position: center;
    border-radius: 6px;
    margin-bottom: 15px;
    
    -webkit-transition: transform 0.3s ease;
    transition: transform 0.3s ease;
}

.em-grid-card-content img:hover {
    
    -webkit-transform: scale(1.02);
    transform: scale(1.02);
}

@media (min-width: 1200px) {
    .em-grid-card-content img {
        max-height: 350px; 
    }
    
    .em-grid-card-content img:first-child {
        max-height: 400px; 
        margin-bottom: 25px;
    }
}

@media (min-width: 769px) and (max-width: 1199px) {
    .em-grid-card-content img {
        max-height: 280px;
    }
    
    .em-grid-card-content img:first-child {
        max-height: 320px;
        margin-bottom: 20px;
    }
}

@media (max-width: 768px) {
    .em-grid-card-content img {
        max-height: 200px;
        margin-bottom: 12px;
    }
    
    .em-grid-card-content img:first-child {
        max-height: 220px;
        margin-bottom: 15px;
    }
}

@media (max-width: 480px) {
    .em-grid-card-content img {
        max-height: 160px;
    }
    
    .em-grid-card-content img:first-child {
        max-height: 180px;
    }
}

.em-grid-card-content .image-container img,
.em-grid-card-content figure img {
    object-fit: contain;
}

@media (min-width: 1200px) {
    .em-grid-card-content .image-container img,
    .em-grid-card-content figure img {
        max-height: 420px; 
    }
}

@media (min-width: 769px) and (max-width: 1199px) {
    .em-grid-card-content .image-container img,
    .em-grid-card-content figure img {
        max-height: 320px;
    }
}

@media (max-width: 768px) {
    .em-grid-card-content .image-container img,
    .em-grid-card-content figure img {
        max-height: 220px;
    }
}

.em-grid-card-content img:not(:first-child) {
    margin-bottom: 10px;
    object-fit: contain;
}

@media (min-width: 1200px) {
    .em-grid-card-content img:not(:first-child) {
        max-height: 200px; 
    }
}

@media (min-width: 769px) and (max-width: 1199px) {
    .em-grid-card-content img:not(:first-child) {
        max-height: 160px;
    }
}

@media (max-width: 768px) {
    .em-grid-card-content img:not(:first-child) {
        max-height: 120px;
    }
}

.em-grid-card-content .image-gallery img {
    width: calc(50% - 5px);
    display: inline-block;
    margin: 2.5px;
    object-fit: contain;
}

@media (min-width: 1200px) {
    .em-grid-card-content .image-gallery img {
        max-height: 150px; 
    }
}

@media (min-width: 769px) and (max-width: 1199px) {
    .em-grid-card-content .image-gallery img {
        max-height: 120px;
    }
}

@media (max-width: 768px) {
    .em-grid-card-content .image-gallery img {
        max-height: 100px;
    }
}

.em-grid-card-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(248, 249, 250, 0.9);
    color: #6c757d;
    pointer-events: none;
    opacity: 0;
    
    -webkit-transition: opacity 0.3s ease;
    transition: opacity 0.3s ease;
}

.em-grid-card:hover .em-grid-card-placeholder {
    opacity: 1;
}

.em-grid-placeholder-content {
    text-align: center;
    padding: 20px;
}

.em-grid-placeholder-content i {
    font-size: 24px;
    margin-bottom: 8px;
    color: #dee2e6;
}

.em-grid-placeholder-content span {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
}

.em-grid-placeholder-content small {
    font-size: 12px;
    opacity: 0.7;
}

.em-grid-navigation {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    transform: translateY(-50%);
    pointer-events: none;
    z-index: 10;
    width: 100%;
    max-width: 100%;
    overflow: visible;
    /* Verbesserte Container-Behandlung */
    min-height: 40px;
    /* respect device safe areas (notch) */
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
}

@media (min-width: 1200px) {
    .em-grid-navigation {
        display: none;
    }
}

.em-grid-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    color: #333;
    cursor: pointer;
    pointer-events: auto;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    z-index: 11;
    /* Verbesserte Basis-Positionierung */
    min-width: 32px;
    min-height: 32px;
    /* Verhindert Button-Überlappung mit Content */
    backdrop-filter: blur(2px);
}

.em-grid-nav-btn:hover {
    background: #ffffff;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    
    -webkit-transform: translateY(-50%) scale(1.1);
    transform: translateY(-50%) scale(1.1);
}

.em-grid-nav-btn.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.em-grid-prev {
    left: 10px;
}

.em-grid-next {
    right: 10px;
}

/* Responsive Button-Anpassungen für verschiedene Container-Größen */
.em-horizontal-grid {
    /* Stelle sicher, dass der Grid-Container Platz für Buttons lässt */
    min-height: 60px;
}

/* Verbesserte Sichtbarkeit bei schmalen Containern */
@media (max-width: 500px) {
    .em-grid-nav-btn {
        background: rgba(255, 255, 255, 0.95);
        box-shadow: 0 3px 12px rgba(0,0,0,0.25);
    }
}

/* Spezielle Behandlung für sehr schmale Container */
.em-horizontal-grid[style*="max-width"] .em-grid-navigation,
.em-horizontal-grid .em-grid-container[style*="max-width"] ~ .em-grid-navigation {
    /* Dynamische Anpassung wird über JavaScript gehandhabt */
    overflow: visible;
}

.em-grid-placeholder {
    text-align: center;
    padding: 60px 20px;
    color: #6c757d;
}

.em-grid-placeholder i {
    font-size: 48px;
    margin-bottom: 16px;
    color: #dee2e6;
}

.em-grid-placeholder h3 {
    margin: 0 0 8px 0;
    font-size: 20px;
    font-weight: 600;
}

.em-grid-placeholder p {
    margin: 0;
    font-size: 14px;
    opacity: 0.8;
}

@media (max-width: 768px) {
    /* Move horizontal spacing into the scrollable container so swiping
       doesn't hide content behind parent padding. JS layout uses innerWidth(). */
    .em-grid-container {
        padding: 5px 16px;
        gap: 15px;
    }
    
    .em-grid-card {
        min-width: 250px;
    }
    
    .em-grid-card-content {
        padding: 15px;
    }
    
    .em-grid-nav-btn {
        width: 36px;
        height: 36px;
        font-size: 12px;
    }
    
    .em-grid-prev {
        left: 15px;
    }
    
    .em-grid-next {
        right: 15px;
    }
}

@media (max-width: 480px) {
    .em-grid-container {
        gap: 10px;
        padding-left: 16px;
        padding-right: 16px;
    }
}

@media (max-width: 480px) {
    .em-grid-container {
        gap: 10px;
        padding-left: 20px;
        padding-right: 20px;
    }
    
    .em-grid-card {
        min-width: 200px;
    }
    
    .em-grid-card-content {
        padding: 12px;
    }
    
    .em-grid-nav-btn {
        width: 32px;
        height: 32px;
        font-size: 11px;
    }
    
    .em-grid-prev {
        left: 20px;
    }
    
    .em-grid-next {
        right: 20px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .em-grid-container {
        scroll-behavior: auto;
    }
    
    .em-grid-card,
    .em-grid-nav-btn,
    .em-grid-card-placeholder {
        transition: none;
    }
    
    .em-grid-card:hover {
        transform: none;
    }
    
    .em-grid-nav-btn:hover {
        
        -webkit-transform: translateY(-50%);
        transform: translateY(-50%);
    }
}

.em-grid-nav-btn:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

.em-horizontal-grid:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

@media print {
    .em-grid-container {
        overflow: visible;
        display: block;
    }
    
    .em-grid-card {
        display: inline-block;
        width: 300px;
        margin: 10px;
        break-inside: avoid;
    }
    
    .em-grid-navigation {
        display: none;
    }
}

/* Indikator-Striche (dynamisch) */
.em-indicators {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    margin-top: 12px;
    pointer-events: auto;
}

.em-indicators .dash:focus {
    outline: 2px solid rgba(0,123,255,0.25);
    outline-offset: 3px;
}

.em-indicators .dash {
    display: block;
    width: 46px;
    height: 6px;
    background: #51515170;
    border-radius: 999px;
    transition: all 220ms ease;
}

.em-indicators .dash.active {
    background: #b3b3b3;
}

@media (max-width: 480px) {
    .em-indicators {
        margin-top: 8px;
        gap: 6px;
    }

    .em-indicators .dash {
        width: 36px;
        height: 5px;
    }
}