/* StationHQ Song Request Widget v1 */
:root {
    --shq-sr-bg: #0f0f1a;
    --shq-sr-text: #e2e8f0;
    --shq-sr-title: #ffffff;
    --shq-sr-artist: #a78bfa;
    --shq-sr-btn: #7c3aed;
    --shq-sr-btn-text: #ffffff;
    --shq-sr-accent: #a78bfa;
    --shq-sr-page: var(--shq-sr-accent);
    --shq-sr-radius: 12px;
    --shq-sr-font: system-ui, -apple-system, sans-serif;
    --shq-sr-heading-font: var(--shq-sr-font);
    --shq-sr-title-size: 16px;
    --shq-sr-title-weight: 600;
    --shq-sr-artist-size: 13px;
    --shq-sr-artist-weight: 400;
    --shq-sr-btn-size: 14px;
    --shq-sr-art-size: 140px;
    --shq-sr-muted: color-mix(in srgb, var(--shq-sr-text) 55%, transparent);
    --shq-sr-border: color-mix(in srgb, var(--shq-sr-bg) 60%, white 12%);
    --shq-sr-card: color-mix(in srgb, var(--shq-sr-bg) 85%, white 4%);
}

* { box-sizing: border-box; }

/* Standalone /request-page: normal document scroll so listeners can reach
 * every song card AND the pagination bar.
 *
 * Embed mode (iframe): still prefer host auto-resize (postMessage) so the
 * external site scrolls as one page. BUT many WordPress / Elementor pastes
 * use a fixed iframe height without the resize <script> — overflow:hidden
 * then clipped card grids to ~6 songs and hid Prev/Next. Keep overflow-y
 * auto as a fallback so listeners can always scroll to the full page and
 * the pager inside a short iframe. */
html {
    height: auto;
    overflow-y: auto;
}

body.shq-sr {
    margin: 0;
    padding: 16px;
    padding-bottom: 72px;
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    background: var(--shq-sr-bg);
    color: var(--shq-sr-text);
    font-family: var(--shq-sr-font);
    font-size: 14px;
    line-height: 1.45;
}

html.shq-sr-embed,
html.shq-sr-embed body.shq-sr {
    /* Do NOT force overflow:hidden — fixed-height embeds without the host
     * resize listener must be able to scroll to songs 7+ and pagination. */
    overflow-x: hidden;
    overflow-y: auto;
    min-height: 0;
    /* Must be `auto`, not `100%`. Stretching the document to the iframe
     * viewport made `documentElement.scrollHeight` report the iframe's own
     * height, so the height we posted to the host could only ever grow: page 1
     * of a catalogue sized the frame tall, and a shorter page after that kept
     * the tall frame and left a blank gap under the pager. A short iframe still
     * scrolls, because its content is taller than its viewport either way. */
    height: auto;
}

body.shq-sr.shq-sr--embedded {
    padding-bottom: 16px;
    min-height: 0;
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
}

.shq-sr-header { margin-bottom: 14px; text-align: center; }

.shq-sr-title {
    margin: 0 0 4px;
    font-size: 1.25rem;
    font-weight: 700;
    font-family: var(--shq-sr-heading-font);
    color: var(--shq-sr-title);
}

.shq-sr-sub {
    margin: 0;
    font-size: 0.85rem;
    color: var(--shq-sr-muted);
}

.shq-sr-search-wrap { margin-bottom: 12px; }

.shq-sr-search {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--shq-sr-radius);
    border: 1px solid var(--shq-sr-border);
    background: color-mix(in srgb, var(--shq-sr-bg) 80%, white 5%);
    color: var(--shq-sr-text);
    font: inherit;
    outline: none;
}

.shq-sr-search:focus {
    border-color: var(--shq-sr-accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--shq-sr-accent) 25%, transparent);
}

.shq-sr-count {
    margin: 0 0 10px;
    font-size: 0.75rem;
    color: var(--shq-sr-muted);
    text-align: center;
}

/* ── Compact list (default) ───────────────────────────────────────────────── */
.shq-sr-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.shq-sr-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--shq-sr-card);
    border: 1px solid var(--shq-sr-border);
    border-radius: var(--shq-sr-radius);
    cursor: pointer;
}

.shq-sr-card:hover {
    background: color-mix(in srgb, var(--shq-sr-bg) 75%, white 8%);
}

.shq-sr-thumb {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: calc(var(--shq-sr-radius) - 2px);
    background: color-mix(in srgb, var(--shq-sr-bg) 70%, white 8%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 1.1rem;
}

.shq-sr--cards .shq-sr-thumb {
    width: var(--shq-sr-art-size);
    height: var(--shq-sr-art-size);
    border-radius: var(--shq-sr-radius);
    font-size: 2rem;
}

.shq-sr-thumb img { width: 100%; height: 100%; object-fit: cover; }

.shq-sr-meta { flex: 1; min-width: 0; }

.shq-sr-song-title {
    font-weight: var(--shq-sr-title-weight);
    font-size: var(--shq-sr-title-size);
    font-family: var(--shq-sr-heading-font);
    color: var(--shq-sr-title);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shq-sr-song-artist {
    font-size: var(--shq-sr-artist-size);
    font-weight: var(--shq-sr-artist-weight);
    color: var(--shq-sr-artist);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shq-sr-dur {
    font-size: 0.75rem;
    color: var(--shq-sr-muted);
    flex-shrink: 0;
}

.shq-sr-btn {
    flex-shrink: 0;
    padding: 6px 14px;
    border: none;
    border-radius: var(--shq-sr-radius);
    background: var(--shq-sr-btn);
    color: var(--shq-sr-btn-text);
    font: inherit;
    font-size: var(--shq-sr-btn-size);
    font-weight: 600;
    cursor: pointer;
}

.shq-sr-btn:hover {
    filter: brightness(1.08);
}

.shq-sr-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.shq-sr-btn-ghost {
    background: transparent;
    color: var(--shq-sr-text);
    border: 1px solid var(--shq-sr-border);
}

/* ── Grid cards layout ────────────────────────────────────────────────────── */
.shq-sr--cards .shq-sr-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(calc(var(--shq-sr-art-size) + 48px), 1fr));
}

/* Fixed column count override — set when the embed URL passes `cols=N` (1..8).
   Mobile (≤640px) always collapses to a single column for readability. */
.shq-sr--cards.shq-sr--cols-fixed .shq-sr-list {
    grid-template-columns: repeat(var(--shq-sr-cols, 3), minmax(0, 1fr));
}
@media (max-width: 640px) {
    .shq-sr--cards.shq-sr--cols-fixed .shq-sr-list {
        grid-template-columns: 1fr;
    }
}

.shq-sr--cards .shq-sr-card {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
    padding: 12px;
    position: relative;
}

.shq-sr--cards .shq-sr-thumb {
    margin: 0 auto 10px;
}

.shq-sr--cards .shq-sr-meta {
    flex: none;
    width: 100%;
    margin-bottom: 8px;
}

.shq-sr--cards .shq-sr-song-title,
.shq-sr--cards .shq-sr-song-artist {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.shq-sr--cards .shq-sr-dur {
    display: block;
    margin-bottom: 8px;
}

.shq-sr--cards .shq-sr-request-btn {
    width: 100%;
    opacity: 1;
}

@media (hover: hover) {
    .shq-sr--cards .shq-sr-request-btn {
        opacity: 0;
        transition: opacity 0.15s ease;
    }

    .shq-sr--cards .shq-sr-card:hover .shq-sr-request-btn {
        opacity: 1;
    }
}

/* Album art size presets */
.shq-sr--art-small { --shq-sr-art-size: 80px; }
.shq-sr--art-medium { --shq-sr-art-size: 140px; }
.shq-sr--art-large { --shq-sr-art-size: 200px; }
.shq-sr--art-xlarge { --shq-sr-art-size: 260px; }

.shq-sr-empty {
    text-align: center;
    padding: 32px 16px;
    color: var(--shq-sr-muted);
}

.shq-sr-spinner {
    width: 28px;
    height: 28px;
    margin: 0 auto 10px;
    border: 3px solid var(--shq-sr-border);
    border-top-color: var(--shq-sr-accent);
    border-radius: 50%;
    animation: shq-sr-spin 0.7s linear infinite;
}

@keyframes shq-sr-spin { to { transform: rotate(360deg); } }

.shq-sr-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
    margin-bottom: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--shq-sr-border);
}

/* Keep the pager visible while scrolling a long catalogue (full page AND
 * fixed-height WordPress iframes that scroll internally). */
body.shq-sr .shq-sr-pagination:not([hidden]) {
    position: sticky;
    bottom: 0;
    z-index: 20;
    margin-bottom: 0;
    background: color-mix(in srgb, var(--shq-sr-bg) 92%, transparent);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid color-mix(in srgb, var(--shq-sr-page) 35%, var(--shq-sr-border));
    box-shadow: 0 -8px 24px color-mix(in srgb, #000 35%, transparent);
}

.shq-sr-page-btn {
    min-width: 36px;
    padding: 6px 12px;
    border-radius: var(--shq-sr-radius);
    border: 1px solid color-mix(in srgb, var(--shq-sr-page) 45%, var(--shq-sr-border));
    background: color-mix(in srgb, var(--shq-sr-page) 14%, var(--shq-sr-card));
    color: var(--shq-sr-page);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.shq-sr-page-btn:hover:not(:disabled) {
    background: color-mix(in srgb, var(--shq-sr-page) 28%, var(--shq-sr-card));
    border-color: var(--shq-sr-page);
}

.shq-sr-page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.shq-sr-page-btn.is-active {
    background: var(--shq-sr-page);
    border-color: var(--shq-sr-page);
    color: var(--shq-sr-btn-text);
}

.shq-sr-page-btn.is-nav {
    background: var(--shq-sr-btn);
    border-color: var(--shq-sr-btn);
    color: var(--shq-sr-btn-text);
}

.shq-sr-page-btn.is-nav:hover:not(:disabled) {
    filter: brightness(1.08);
}

.shq-sr-page-ellipsis {
    color: var(--shq-sr-page);
    opacity: 0.55;
    font-size: 0.85rem;
    padding: 0 2px;
    user-select: none;
}

.shq-sr-page-info {
    font-size: 0.8rem;
    color: var(--shq-sr-page);
    font-weight: 600;
    margin: 0 4px;
}

.shq-sr-toast {
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: var(--shq-sr-radius);
    font-size: 0.85rem;
    text-align: center;
}

.shq-sr-toast[data-tone="ok"] {
    background: color-mix(in srgb, #22c55e 20%, transparent);
    color: #86efac;
    border: 1px solid color-mix(in srgb, #22c55e 40%, transparent);
}

.shq-sr-toast[data-tone="err"] {
    background: color-mix(in srgb, #ef4444 20%, transparent);
    color: #fca5a5;
    border: 1px solid color-mix(in srgb, #ef4444 40%, transparent);
}

.shq-sr-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    /* Prefer the top of the iframe so a tall auto-sized embed still shows
     * the form when the host scrolls this frame into view. */
    align-items: flex-start;
    justify-content: center;
    padding: 24px 16px 16px;
    z-index: 100;
}

.shq-sr-modal[hidden] { display: none; }

.shq-sr-modal-card {
    width: 100%;
    max-width: 360px;
    padding: 18px;
    background: var(--shq-sr-bg);
    border: 1px solid var(--shq-sr-border);
    border-radius: calc(var(--shq-sr-radius) + 4px);
    /* Never let the request form exceed the visible frame — if it would,
     * scroll inside the card so the message box + Send button stay reachable
     * without the visitor scrolling the whole widget. */
    max-height: calc(100% - 32px);
    overflow-y: auto;
}

.shq-sr-modal-title {
    margin: 0 0 4px;
    font-size: 1.05rem;
    font-family: var(--shq-sr-heading-font);
    color: var(--shq-sr-title);
}

.shq-sr-modal-artist {
    margin: 0 0 12px;
    font-size: 0.85rem;
    color: var(--shq-sr-artist);
}

.shq-sr-modal-msg {
    width: 100%;
    min-height: 72px;
    padding: 10px;
    margin-bottom: 6px;
    border-radius: var(--shq-sr-radius);
    border: 1px solid var(--shq-sr-border);
    background: color-mix(in srgb, var(--shq-sr-bg) 80%, white 5%);
    color: var(--shq-sr-text);
    font: inherit;
    resize: vertical;
}

.shq-sr-char {
    margin: 0 0 12px;
    font-size: 0.75rem;
    color: var(--shq-sr-muted);
    text-align: right;
}

.shq-sr-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    /* Keep the action buttons pinned to the bottom of the (scrollable) card so
     * "Send Request" is always visible even when the card content scrolls. */
    position: sticky;
    bottom: -18px;
    padding: 12px 0 2px;
    margin-top: 4px;
    background: var(--shq-sr-bg);
}
