/* ============================================
   Station Grid Component Styles
   Responsive layout for radio station display
   ============================================ */

/* Container for all station bars */
.rm-station-grid {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100vw; /* Full viewport width for edge-to-edge on mobile */
    margin: 0;
    position: relative;
    left: 50%;
    right: 50%;
    margin-left: -50vw;
    margin-right: -50vw;
}

/* Sidebar mode - use container width instead of viewport width */
.rm-station-grid--sidebar {
    width: 100%; /* Use container width for sidebar */
    position: static;
    left: auto;
    right: auto;
    margin-left: 0;
    margin-right: 0;
}

/* Breakout mode - break out of container on desktop with max-width limit */
.rm-station-grid--breakout {
    /* Default mobile: stays in container (inherits from --sidebar) */
}

/* Individual station bar */
.rm-station-bar {
    position: relative;
    width: 100%;
    height: 80px; /* Reduced height for mobile (2/3 of original) */
    overflow: hidden; /* CRITICAL: Clip zoomed background */
    cursor: pointer;
    transition: height 0.6s ease, box-shadow 0.6s ease, z-index 0s;
}

/* Background layer - uses ::after pseudo-element for smooth transform zoom */
.rm-station-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: var(--bg-image); /* Set via inline style as CSS custom property */
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    z-index: 0; /* Behind overlay and content */
    transition: transform 0.6s ease; /* Smooth GPU-accelerated zoom */
}

/* Playing station bar - 50% taller with shadows and zoomed background */
.rm-station-bar:has(.qtmplayer-donutcontainer.rm-playing) {
    height: 120px; /* 50% taller when playing (80px * 1.5) */
    box-shadow: 0 -3px 8px rgba(0, 0, 0, 0.3), 0 3px 8px rgba(0, 0, 0, 0.3); /* Shadows top and bottom */
    z-index: 5; /* Lift above other bars */
}

/* Zoom background when playing - uses transform instead of background-size */
.rm-station-bar:has(.qtmplayer-donutcontainer.rm-playing)::after {
    transform: scale(1.5); /* 50% zoom - smooth transition via transform */
}

/* Hover effects are defined in desktop media query below */

/* Dark overlay for better text readability */
.rm-station-bar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.2) 100%);
    pointer-events: none;
    z-index: 1; /* Above background (::after), below content */
    transition: background 0.6s ease; /* Smooth transition for overlay changes */
}

/* Mobile: Lighter overlay for playing station */
@media (max-width: 767px) {
    .rm-station-bar:has(.qtmplayer-donutcontainer.rm-playing)::before {
        background: linear-gradient(to right, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.1) 100%);
    }
}

/* Clickable link overlay (covers most of bar except play button) */
.rm-station-bar__link {
    position: absolute;
    top: 0;
    left: 0;
    right: 70px; /* Reserve space for play button (reduced for smaller button) */
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: 20px;
    text-decoration: none;
    z-index: 2;
}

/* Content container */
.rm-station-bar__content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Station title styling */
.rm-station-bar__title {
    color: #ffffff;
    font-size: 20px; /* Slightly smaller for mobile */
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    letter-spacing: 0.5px;
}

/* Song data container - hidden by default */
.rm-station-bar__songdata {
    display: none;
    flex-direction: column;
    gap: 2px;
    margin-top: 4px;
}

/* Show song data when playing */
.rm-station-bar:has(.qtmplayer-donutcontainer.rm-playing) .rm-station-bar__songdata {
    display: flex;
}

/* Song title */
.rm-station-bar__song-title {
    color: #ffffff;
    font-size: 18px;
    font-weight: 600;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    margin: 0;
    line-height: 1.2;
    /* Limit to 1 line on mobile */
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Song artist */
.rm-station-bar__song-artist {
    color: rgba(200, 200, 200, 0.9); /* Light gray instead of white */
    font-size: 14px;
    font-weight: 400;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    margin: 0;
    line-height: 1.2;
    /* Limit to 1 line on mobile */
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Play button container */
.rm-station-bar__play-container {
    position: absolute;
    top: 0;
    right: 0;
    width: 70px; /* Reduced for smaller button */
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3; /* Higher than link to capture clicks */
}

/* qtmplayer integration - maintain exact classes from station_swiper.php */
.rm-station-bar .qtmplayer-donutcontainer {
    width: 50px !important; /* Smaller on mobile */
    height: 50px !important; /* Smaller on mobile */
    background: rgba(255, 255, 255, 0.5); /* White with less transparency */
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.7) !important; /* White border, less transparent than background */
    outline: none !important;
    box-shadow: none !important;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.rm-station-bar .qtmplayer-donutcontainer:hover {
    background: rgba(255, 255, 255, 0.65);
    border-color: rgba(255, 255, 255, 0.85) !important; /* Slightly more opaque border on hover */
    transform: scale(1.1);
}

.rm-station-bar .qtmplayer-trackitem {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    width: 100%;
    height: 100%;
}

.rm-station-bar .qtmplayer-play {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    cursor: pointer;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
}

.rm-station-bar .material-icons {
    color: #333333; /* Dark gray icon */
    font-size: 32px; /* Slightly larger icon */
    line-height: 1;
}

/* Active/playing state - green background with white icon */
.rm-station-bar .qtmplayer-donutcontainer.rm-playing {
    background: rgba(92, 177, 62, 0.9) !important; /* Brand green */
    border-color: rgba(255, 255, 255, 0.9) !important; /* More opaque white border when playing */
}

.rm-station-bar .qtmplayer-donutcontainer.rm-playing .material-icons {
    color: #ffffff !important; /* White icon when active */
}

.rm-station-bar .qtmplayer-donutcontainer.rm-playing:hover {
    background: rgba(92, 177, 62, 1) !important; /* Solid green on hover */
    border-color: rgba(255, 255, 255, 1) !important; /* Fully opaque white border on hover */
}

/* ============================================
   Desktop Layout (768px and above)
   Sidebar mode stays in mobile layout
   ============================================ */
@media (min-width: 768px) {
    /* Force sidebar mode to keep mobile layout on desktop viewports */
    .rm-station-grid--sidebar:not(.rm-station-grid--breakout) {
        flex-direction: column !important;
        width: 100% !important;
        height: auto !important;
        position: static !important;
        left: auto !important;
        right: auto !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        border-radius: 0 !important;
    }

    /* Breakout mode on desktop - independent of sidebar mode */
    .rm-station-grid--breakout {
        /* Viewport breaking with max-width limit */
        width: calc(min(100vw, var(--breakout-width, 1460px))) !important;
        position: relative !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        margin: 0 !important;
    }

    /* Sidebar + Breakout: switch to horizontal on desktop */
    .rm-station-grid--sidebar.rm-station-grid--breakout {
        flex-direction: row !important;
        height: 120px !important;
        overflow: hidden !important;
    }

    .rm-station-grid--sidebar.rm-station-grid--breakout .rm-station-bar {
        flex: 1;
        height: 100%;
        min-width: 0;
        overflow: hidden;
    }

    /* Normal desktop grid (horizontal layout) */
    .rm-station-grid:not(.rm-station-grid--sidebar):not(.rm-station-grid--breakout) {
        flex-direction: row;
        height: 120px; /* Lower height for wider aspect ratio (closer to 16:9) */
        width: 100%; /* Reset to container width on desktop */
        position: static;
        left: auto;
        right: auto;
        margin-left: 0;
        margin-right: 0;
        border-bottom-left-radius: 12px; /* Rounded bottom-left corner */
        border-bottom-right-radius: 12px; /* Rounded bottom-right corner */
        overflow: hidden; /* Ensure child elements respect border radius */
    }

    /* Breakout mode: no border radius */
    .rm-station-grid--breakout {
        flex-direction: row;
        height: 120px;
        overflow: hidden;
    }

    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar {
        flex: 1;
        height: 100%; /* Full height of grid */
        min-width: 0; /* Allow flex items to shrink */
        overflow: hidden; /* Ensure zoomed background is clipped */
    }

    /* Desktop: Background zoom on hover (not in sidebar mode OR in breakout mode) */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar:hover::after {
        transform: scale(1.5); /* 50% zoom on hover */
    }

    /* Desktop: Background zoom when playing (only if NOT hovering) */
    /* This prevents redundant zoom - if already hovering (zoomed to 1.5), stay there */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar:has(.qtmplayer-donutcontainer.rm-playing):not(:hover)::after {
        transform: scale(1.5); /* Same zoom as hover */
    }

    /* Ensure content container doesn't overflow */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar__content {
        max-height: 100%; /* Prevent content from expanding bar */
        overflow: hidden; /* Hide any overflow */
    }

    /* Playing station - no size change on desktop */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar:has(.qtmplayer-donutcontainer.rm-playing) {
        height: 100%; /* Override mobile height change - stay full grid height */
        /* No flex change - all bars stay same width */
        /* Zoom is handled by ::after transform above */
    }

    /* Lighter overlay when playing (not just on hover) */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar:has(.qtmplayer-donutcontainer.rm-playing)::before {
        background: linear-gradient(to right, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.1) 100%);
    }

    /* Lighter overlay on hover */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar:hover::before {
        background: linear-gradient(to right, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.1) 100%);
    }

    /* Horizontal text for desktop (readable) */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar__title {
        writing-mode: horizontal-tb; /* Normal horizontal text */
        transform: none; /* Remove rotation */
        font-size: 18px; /* Larger station name */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        text-align: center; /* Center text */
    }

    /* Song info on desktop */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar__song-title {
        font-size: 16px; /* Larger title */
        text-align: center; /* Center text */
        display: -webkit-box;
        -webkit-line-clamp: 2; /* Limit to 2 lines */
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar__song-artist {
        font-size: 13px; /* Larger artist */
        text-align: center; /* Center text */
        display: -webkit-box;
        -webkit-line-clamp: 2; /* Limit to 2 lines */
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Link area - upper portion for content */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar__link {
        right: 0;
        bottom: 45%; /* Leave bottom 45% for button area */
        left: 0;
        top: 0;
        padding: 10px;
        padding-top: 15px; /* Space at top */
        justify-content: flex-start; /* Align to top */
        align-items: center; /* Center horizontally */
    }

    /* Content container - let it grow with song info */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar__content {
        max-height: none !important; /* Allow growth for song info */
        overflow: visible !important; /* Show all content */
    }

    /* Play button in lower portion */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar__play-container {
        top: 65%; /* Position lower - further from content */
        right: auto;
        bottom: auto;
        left: 50%; /* Center horizontally */
        transform: translate(-50%, -50%); /* Center both directions */
        width: auto;
        height: auto;
        transition: opacity 0.6s ease, transform 0.6s ease; /* Smooth fade out and slide */
    }

    /* Hide play button when playing (unless hovering) */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar:has(.qtmplayer-donutcontainer.rm-playing):not(:hover) .rm-station-bar__play-container {
        opacity: 0; /* Fade out */
        pointer-events: none; /* Disable clicks */
    }

    /* Show play button when hovering over playing station */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar:has(.qtmplayer-donutcontainer.rm-playing):hover .rm-station-bar__play-container {
        opacity: 1; /* Fade in */
        pointer-events: auto; /* Enable clicks */
    }

    /* Hide song data when hovering over playing station (to show button) */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar:has(.qtmplayer-donutcontainer.rm-playing):hover .rm-station-bar__songdata {
        opacity: 0;
    }

    /* Ensure songdata has transition for smooth fade */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar__songdata {
        transition: opacity 0.6s ease;
    }

    /* Smaller button on desktop */
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar .qtmplayer-donutcontainer {
        width: 40px !important; /* Smaller on desktop */
        height: 40px !important;
    }

    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar .material-icons {
        font-size: 24px; /* Smaller icon */
    }
}

/* ============================================
   Larger Desktop Layout (1040px and above)
   Sidebar mode excluded
   ============================================ */
@media (min-width: 1040px) {
    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) {
        height: 140px; /* Slightly taller for larger screens, keeping wider aspect ratio */
    }

    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar__title {
        font-size: 20px; /* Larger station name on big screens */
        text-align: center; /* Center text */
    }

    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar__song-title {
        font-size: 17px; /* Larger title on big screens */
        text-align: center; /* Center text */
        display: -webkit-box;
        -webkit-line-clamp: 2; /* Limit to 2 lines */
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar__song-artist {
        font-size: 14px; /* Larger artist on big screens */
        text-align: center; /* Center text */
        display: -webkit-box;
        -webkit-line-clamp: 2; /* Limit to 2 lines */
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar .qtmplayer-donutcontainer {
        width: 45px !important; /* Slightly larger button */
        height: 45px !important;
    }

    :is(.rm-station-grid:not(.rm-station-grid--sidebar), .rm-station-grid--breakout) .rm-station-bar .material-icons {
        font-size: 28px;
    }
}

/* ============================================
   Accessibility Improvements
   ============================================ */
.rm-station-bar__link:focus,
.rm-station-bar .qtmplayer-play:focus {
    outline: 3px solid #5CB13E;
    outline-offset: 2px;
}

/* Keyboard navigation support */
.rm-station-bar__link:focus-visible,
.rm-station-bar .qtmplayer-play:focus-visible {
    outline: 3px solid #5CB13E;
    outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .rm-station-bar,
    .rm-station-bar .qtmplayer-donutcontainer {
        transition: none;
    }

    .rm-station-bar:hover {
        transform: none;
    }
}
