/* General Styles */
body {
    margin: 0;
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* header {
    text-align: center;
    margin: 20px 0;
} */

h1 {
    font-size: 36px;
    color: #f3e0eb;
    text-align: center;
    margin: 30px 0;
}

/* Sidebar Styles */
.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 380px;
    background-color: rgba(34, 34, 34, 0.92);
    box-shadow: -4px 0 8px rgba(0, 0, 0, 0.4);
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 1000;
    scroll-behavior: smooth;
    /* Custom scrollbar styling */
    scrollbar-width: thin;
    scrollbar-color: #b50c33 #333;
}

.sidebar.closed {
    transform: translateX(100%);
}

/* Custom scrollbar for Webkit browsers (Chrome, Safari, Edge) */
.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track {
    background: #333;
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #b50c33;
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: #c9085c;
}

/* Desktop embedded sidebar */
@media (min-width: 769px) and (orientation: landscape) {
    main {
        display: flex;
        max-width: 1600px;
        margin: 0 auto;
        padding: 20px;
        gap: 30px;
    }
    .sidebar {
        width: 380px;
        flex-shrink: 0;
        position: relative;
        top: auto;
        right: auto;
        height: auto;
        transform: none;
        box-shadow: none;
        border-left: 2px solid #b50c33;
        margin-left: 20px;
        order: 2;
        opacity: 1;
        visibility: visible;
        transition: opacity 0.3s cubic-bezier(0.4,0,0.2,1), visibility 0.3s;
        display: block;
    }
    .sidebar.closed {
        opacity: 0;
        visibility: hidden;
        transform: none;
        display: none;
    }
    .sidebar.sidebar-animating {
        display: block;
    }
    #media-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 25px;
        margin: 20px auto;
        padding: 20px;
        max-width: 1400px;
        grid-auto-rows: min-content;
        transition: gap 0.3s cubic-bezier(0.4,0,0.2,1), padding 0.3s cubic-bezier(0.4,0,0.2,1), all 0.3s cubic-bezier(0.4,0,0.2,1);
    }
    main.sidebar-closed {
        display: block !important;
    }
    main.sidebar-closed #media-grid {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 20px !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 25px !important;
    }
}

@media (min-width: 1800px) and (max-width: 2099px) {
    #media-grid {
        grid-template-columns: repeat(3, 1fr);
        max-width: none !important;
        width: 100% !important;
        margin: 0 !important;
    }
}

/* Mobile layout - no vw units, clean and simple */
@media (max-width: 580px), (orientation: portrait) {
    html, body {
        margin: 0;
        padding: 0;
        overflow-x: hidden;
    }
    
    main {
        display: block !important;
        margin: 0;
        padding: 0;
        max-width: none;
    }
    
    #media-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 16px;
        margin: 0;
        padding: 16px;
        width: 100%;
        max-width: none;
    }
    
    .media-card {
        width: 100%;
        max-width: none;
        margin: 0 0 16px 0;
        border-radius: 12px;
        box-sizing: border-box;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        height: 100%;
        width: 100%;
        transform: translateX(100%);
        box-shadow: -4px 0 8px rgba(0, 0, 0, 0.4);
        border-left: none;
        margin-left: 0;
        order: unset;
        z-index: 1000;
    }

    .sidebar.closed {
        transform: translateX(100%);
        display: block;
    }
    
    .sidebar:not(.closed) {
        transform: translateX(0);
    }

    header-title {
        padding: 48px 16px 16px 16px;
    }

    .sidebar-toggle {
        margin-left: 8px;
    }

    .mobile-close-sidebar {
        display: block !important;
    }
    
    .collapsible-content.nested-content .tag-filter {
        width: 100%;
    }
}

@media (min-width: 769px) and (max-width: 1799px) {
    #media-grid {
        grid-template-columns: 1fr 1fr;
    }
    .media-card {
        width: 95%;
        max-width: 600px;
        margin: 0 auto 16px auto;
    }
}

@media (min-width: 1800px) {
    #media-grid {
        grid-template-columns: 1fr 1fr 1fr;
    }
    .media-card {
        width: 95%;
        max-width: 600px;
        margin: 0 auto 16px auto;
    }
}

.sidebar-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sidebar h3 {
    text-align: center;
    font-size: 24px;
    color: #f3e0eb;
    margin-bottom: 20px;
}

.sidebar h4 {
    margin-top: 20px;
    margin-bottom: 12px;
    font-size: 18px;
    color: #ffffff;
    font-weight: 600;
    text-align: center;
}

/* Sidebar Toggle Button */
.sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    position: static !important;
    top: auto;
    right: auto;
    z-index: 900;
    width: 56px;
    height: 56px;
    background-color: #b50c33;
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    font-size: 24px;
    line-height: 56px;
    text-align: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.sidebar-toggle:hover,
.sidebar-toggle:focus {
    background-color: #c9085c;
    color: #fff;
    transform: scale(1.08);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

/* Mobile Close Button */
.mobile-close-sidebar {
    display: none;
    position: absolute;
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    background-color: #b50c33;
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
    transition: all 0.3s ease;
    z-index: 1002;
}

.mobile-close-sidebar:hover {
    background-color: #c9085c;
    transform: scale(1.1);
}

/* Search Container */
.search-container {
    width: 100%;
    margin-bottom: 20px;
}

.search-input-wrapper {
    position: relative;
    width: 100%;
}

.search-input {
    width: 100%;
    padding: 12px 16px;
    padding-right: 48px; /* Space for the button */
    border: 2px solid #b50c33;
    border-radius: 22px;
    background-color: #333;
    color: #e0e7f3;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    box-sizing: border-box;
}

.search-input:focus {
    border-color: #c9085c;
    box-shadow: 0 0 8px rgba(193, 27, 102, 0.4);
}

.search-input::placeholder {
    color: #888;
}

.search-button {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    background-color: #b50c33;
    color: #e0e7f3;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.search-button:hover {
    background-color: #c9085c;
    transform: translateY(-50%) scale(1.1);
}

.search-button .search-icon {
    width: 16px;
    height: 16px;
    color: #ffffff;
    display: block;
}

/* Collapsible Section */
.collapsible-section {
    margin-bottom: 20px;
    width: 100%;
}

.collapsible-toggle {
    width: 100%;
    padding: 0;
    background: none;
    color: #ffffff;
    border: none;
    cursor: pointer;
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: color 0.3s ease;
    margin: 20px 0 24px 0;
    text-align: left;
}

.collapsible-toggle:hover {
    color: #e0e7f3;
}

.collapsible-toggle .toggle-icon {
    transition: transform 0.3s ease;
    font-size: 12px;
    color: #b50c33;
}

.collapsible-toggle.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.collapsible-content {
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%;
    padding-top: 8px;
}

.collapsible-content.collapsed {
    max-height: 0;
    overflow: hidden;
    padding: 0;
    margin: 0;
}

/* Nested collapsible sections */
.collapsible-section.nested {
    margin-bottom: 10px;
    margin-left: 0;
}

.collapsible-toggle.nested-toggle {
    font-size: 14px;
    font-weight: 500;
    margin: 10px 0 5px 0;
    padding: 8px 12px;
    background-color: rgba(181, 12, 51, 0.3);
    border-radius: 8px;
    border: 1px solid rgba(181, 12, 51, 0.5);
}

.collapsible-content.nested-content {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 8px;
}

.collapsible-content.nested-content.collapsed {
    max-height: 0;
    overflow: hidden;
    padding: 0;
    margin: 0;
}

.collapsible-content.nested-content .tag-filter {
    width: 49%;
    min-width: 0;
    box-sizing: border-box;
    padding: 12px 20px;
    margin-bottom: 12px;
    background-color: #b50c33;
    color: #ffffff;
    border: none;
    border-radius: 22px;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.3s ease, color 0.3s ease, transform 0.2s ease;
    font-size: 16px;
    font-weight: 500;
    position: relative;
    overflow: hidden;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Ensure train types section has proper spacing */
.collapsible-section:last-child {
    margin-bottom: 30px;
}

/* Add bottom padding to sidebar content to prevent cutoff */
.sidebar-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 60px;
    min-height: 100vh;
    box-sizing: border-box;
}

/* Search Suggestions */
.search-suggestions {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: #333;
    border: 2px solid #b50c33;
    border-top: none;
    border-radius: 0 0 12px 12px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    margin-top: 2px;
}

.suggestion-item {
    padding: 12px 16px;
    color: #e0e7f3;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-bottom: 1px solid #444;
    margin-top: 2px;
    margin-bottom: 2px;
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background-color: #b50c33;
    color: #fff;
}

/* Filter Status */
.filter-status {
    width: 100%;
    text-align: center;
    margin-bottom: 15px;
    padding: 8px 12px;
    background-color: rgba(181, 12, 51, 0.2);
    border-radius: 12px;
    border: 1px solid rgba(181, 12, 51, 0.3);
}

.filter-status span {
    color: #ffffff;
    font-size: 14px;
    font-weight: 500;
}

/* Filters */
.tag-filter {
    display: block;
    width: 100%;
    padding: 12px 20px;
    margin-bottom: 12px;
    background-color: #b50c33;
    color: #ffffff;
    border: none;
    border-radius: 22px;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.3s ease, color 0.3s ease, transform 0.2s ease;
    font-size: 16px;
    font-weight: 500;
    position: relative;
    overflow: hidden;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tag-filter:hover {
    background-color: #c11b8a;
    color: #fff;
    transform: translateY(-2px);
}

.tag-filter.active {
    background-color: #c11b8a;
    color: #fff;
    box-shadow: 0 0 12px rgba(193, 27, 138, 0.6);
    transform: translateY(-2px);
}

.tag-filter.active::before {
    content: "";
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20 6L9 17L4 12' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    display: block;
}

.type-filter {
    display: block;
    width: 100%;
    padding: 12px 20px;
    margin-bottom: 12px;
    background-color: #b50c33;
    color: #ffffff;
    border: none;
    border-radius: 22px;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.3s ease, color 0.3s ease, transform 0.2s ease;
    font-size: 16px;
    font-weight: 500;
    position: relative;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.type-filter:hover {
    background-color: #c11b8a;
    color: #fff;
    transform: translateY(-2px);
}

.type-filter.active {
    background-color: #c11b8a;
    color: #fff;
    box-shadow: 0 0 12px rgba(193, 27, 138, 0.6);
    transform: translateY(-2px);
}

.type-filter.active::before {
    content: "";
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M20 6L9 17L4 12' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.clear-filters {
    display: block;
    width: 100%;
    padding: 12px 20px;
    margin-bottom: 20px;
    background-color: #b50c33;
    color: #ffffff;
    border: none;
    border-radius: 22px;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.3s ease, color 0.3s ease;
    font-size: 16px;
    font-weight: 500;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-filters:hover {
    background-color: #c11b8a;
    color: #fff;
}

/* Media Grid - removed problematic vw calculation */
@media (max-width: 1100px) {
    #media-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Media Card */
.media-card {
    background-color: #333;
    border: 2px solid #444;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    border-radius: 12px;
    overflow: hidden;
    text-align: center;
    transition: opacity 0.3s cubic-bezier(0.4,0,0.2,1), transform 0.3s cubic-bezier(0.4,0,0.2,1);
    width: 100%;
    display: flex;
    flex-direction: column;
    height: fit-content;
}

.media-card h3 {
    padding: 15px 15px 8px 15px;
    margin: 0;
    flex-grow: 0;
}

.media-card p {
    padding: 0 15px 15px 15px;
    margin: 0;
    flex-grow: 1;
}

.media-card:hover {
    border-color: #c9085c; /* Border changes to magenta color upon hover */
    box-shadow: 0 0 15px rgba(193, 27, 102, 0.8); /* Magenta glow effect */
    transform: translateY(-4px); /* Subtle lift on hover */
}

/* Adjust Images */
.media-card img {
    width: 100%;
    height: 240px;
    object-fit: cover; /* Crop image to fit card dimensions */
    display: block;
    border: none;
    flex-shrink: 0;
}

/* Adjust Videos */
.media-card iframe {
    width: 100%;
    height: 240px;
    display: block;
    border: none;
    flex-shrink: 0;
}

/* Media Placeholder */
.media-placeholder {
    width: 100%;
    height: 240px;
    background-color: #555;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 18px;
    font-weight: bold;
    flex-shrink: 0;
}

/* Additional mobile optimizations */
@media (max-width: 480px) {
    .sidebar h3 {
        font-size: 20px;
        margin-bottom: 15px;
    }

    .sidebar h4 {
        font-size: 16px;
        margin-top: 15px;
        margin-bottom: 12px;
    }

    .media-card h3 {
        font-size: 18px;
    }

    .media-card p {
        font-size: 14px;
    }
}

.collapsible-content > .tag-filter:first-child,
.collapsible-content > .type-filter:first-child {
    margin-top: 0;
}

.tag-filter:hover,
.tag-filter.active,
.type-filter:hover,
.type-filter.active {
    z-index: 100;
}

header-title {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 32px 0 32px;
    gap: 16px;
}

header-title h1 {
    flex: 1;
    margin: 0;
    text-align: center;
}

.media-card.fade-out {
    opacity: 0;
    pointer-events: none;
}

/* Desktop: 2 columns if below 1100px */
@media (min-width: 581px) and (max-width: 1099px) {
    #media-grid {
        grid-template-columns: 1fr 1fr !important;
    }
}

/* Desktop: 2 columns if between 1000px and 1099px */
@media (min-width: 1000px) and (max-width: 1099px) {
    #media-grid {
        grid-template-columns: 1fr 1fr !important;
    }
}

/* When sidebar is open: 1 column if under 1200px */
@media (min-width: 581px) and (max-width: 1199px) {
    main:not(.sidebar-closed) #media-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Tag Matching Mode Toggle */
.matching-mode-container {
    width: 100%;
    margin-bottom: 20px;
}

.matching-mode-label {
    display: block;
    color: #ffffff;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 12px;
}

.matching-mode-toggle {
    display: flex;
    gap: 8px;
    width: 100%;
}

.mode-button {
    flex: 1;
    padding: 12px 16px;
    background-color: #333;
    color: #e0e7f3;
    border: 2px solid #b50c33;
    border-radius: 12px;
    cursor: pointer;
    text-align: center;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60px;
}

.mode-button:hover {
    background-color: #444;
    border-color: #c9085c;
}

.mode-button.active {
    background-color: #b50c33;
    color: #ffffff;
    border-color: #c9085c;
    box-shadow: 0 0 12px rgba(181, 12, 51, 0.4);
}

.mode-text {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 4px;
}

.mode-description {
    font-size: 13px;
    opacity: 0.8;
    line-height: 1.2;
}

/* Mobile optimization for mode buttons */
@media (max-width: 580px), (orientation: portrait) {
    .matching-mode-toggle {
        flex-direction: column;
        gap: 8px;
    }
    
    .mode-button {
        min-height: 50px;
    }
    
    .mode-text {
        font-size: 15px;
    }
    
    .mode-description {
        font-size: 12px;
    }
}

/* Very large screens: 4 columns */
@media (min-width: 2100px) {
    main {
        max-width: none !important;
    }
    #media-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        max-width: none !important;
        width: 100% !important;
        margin: 0 !important;
    }
    main.sidebar-closed #media-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        max-width: none !important;
        width: 100% !important;
        margin: 0 !important;
    }
}

/* Ultra-wide screens: 5 columns */
@media (min-width: 3000px) {
    main {
        max-width: none !important;
    }
    #media-grid {
        grid-template-columns: repeat(5, 1fr) !important;
        max-width: none !important;
        width: 100% !important;
        margin: 0 !important;
    }
    main.sidebar-closed #media-grid {
        grid-template-columns: repeat(5, 1fr) !important;
        max-width: none !important;
        width: 100% !important;
        margin: 0 !important;
    }
}
