/**
 * SBN Rhythm Library Frontend Styles
 * Mirrors the admin interface design
 */

/* Page Container */
.sbn-rhythm-library {
    max-width: 1400px;
    margin: 40px auto;
    padding: 0 20px;
}

/* Page Header */
.sbn-rhythm-library-header {
    margin-bottom: 40px;
}

.sbn-rhythm-library-header h1 {
    font-size: 32px;
    font-weight: 700;
    color: #1d2327;
    margin-bottom: 8px;
}

.sbn-rhythm-library-intro {
    font-size: 16px;
    color: #646970;
    line-height: 1.6;
}

/* Category Headers */
.sbn-category-header {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #50575e;
    margin: 40px 0 20px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e85d3b;
}

.sbn-category-header:first-of-type {
    margin-top: 20px;
}

/* Patterns Grid */
.sbn-patterns-category {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}

@media (max-width: 768px) {
    .sbn-patterns-category {
        grid-template-columns: 1fr;
    }
}

/* Pattern Card */
.sbn-pattern-card {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 20px;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.sbn-pattern-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

/* Pattern Header */
.sbn-pattern-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
}

.sbn-pattern-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1d2327;
    line-height: 1.3;
}

.sbn-pattern-slug {
    font-size: 11px;
    background: #f0f0f1;
    padding: 3px 10px;
    border-radius: 12px;
    color: #646970;
    font-weight: 500;
    white-space: nowrap;
}

/* Pattern Info */
.sbn-pattern-info {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 500;
}

.sbn-pattern-time,
.sbn-pattern-bars,
.sbn-pattern-bpm {
    background: #f6f7f7;
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid #e5e5e5;
    color: #50575e;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sbn-pattern-time::before {
    content: '⏱';
    font-size: 14px;
}

.sbn-pattern-bars::before {
    content: '𝄞';
    font-size: 14px;
}

/* Pattern Description */
.sbn-pattern-desc {
    font-size: 14px;
    color: #646970;
    line-height: 1.6;
    margin: 0 0 16px;
}

/* Pattern Preview Container */
.sbn-pattern-preview {
    background: #f9f9f9;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid #e5e5e5;
    overflow: hidden;
}

/* Truncated preview for multi-bar patterns */
.sbn-pattern-preview.is-truncated {
    position: relative;
    max-height: 120px; /* show ~1 bar */
    overflow: hidden;
}

.sbn-pattern-preview-fade {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 48px;
    background: linear-gradient(transparent, #f9f9f9);
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 0 12px 6px;
    pointer-events: none;
}

.sbn-multibar-hint {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #e85d3b;
    background: rgba(249, 249, 249, 0.9);
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid rgba(232, 93, 59, 0.3);
}

/* Card Footer: Play + Details */
.sbn-pattern-card-footer {
    display: flex;
    gap: 8px;
}

/* Play Button */
.sbn-pattern-play-btn {
    flex: 1;
    padding: 9px 14px;
    background: #fff;
    border: 2px solid #e85d3b;
    border-radius: 6px;
    color: #e85d3b;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.sbn-pattern-play-btn:hover {
    background: #fff5f3;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(232, 93, 59, 0.15);
}

.sbn-pattern-play-btn:active {
    transform: translateY(0);
}

.sbn-pattern-play-btn.is-playing {
    background: #e85d3b;
    border-color: #d04a2a;
    color: #fff;
    box-shadow: 0 2px 8px rgba(232, 93, 59, 0.3);
}

.sbn-pattern-play-btn::before {
    content: '▶';
    font-size: 11px;
}

.sbn-pattern-play-btn.is-playing::before {
    content: '⏸';
}

/* Details Button */
.sbn-pattern-details-btn {
    padding: 9px 14px;
    background: transparent;
    border: 2px solid #ddd;
    border-radius: 6px;
    color: #50575e;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.sbn-pattern-details-btn:hover {
    border-color: #999;
    color: #1d2327;
    background: #f6f7f7;
}

/* ============================================================
   MODAL
   ============================================================ */

.sbn-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(3px);
    animation: sbn-modal-fade-in 0.18s ease;
}

.sbn-modal-overlay[hidden] {
    display: none;
}

@keyframes sbn-modal-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

body.sbn-modal-open {
    overflow: hidden;
}

.sbn-modal-container {
    background: #fff;
    border-radius: 12px;
    padding: 32px;
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    animation: sbn-modal-slide-up 0.22s ease;
}

@keyframes sbn-modal-slide-up {
    from { transform: translateY(16px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.sbn-modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    background: #f0f0f1;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    color: #646970;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.sbn-modal-close:hover {
    background: #e0e0e0;
    color: #1d2327;
}

/* Modal header */
.sbn-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.sbn-modal-title-group h2 {
    margin: 0 0 6px;
    font-size: 22px;
    font-weight: 700;
    color: #1d2327;
}

.sbn-modal-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.sbn-modal-bpm {
    background: #f6f7f7;
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid #e5e5e5;
    color: #50575e;
    font-size: 13px;
    font-weight: 500;
}

/* Modal description */
.sbn-modal-desc {
    font-size: 14px;
    color: #50575e;
    line-height: 1.7;
    margin: 0 0 24px;
}

/* Modal sections */
.sbn-modal-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #f0f0f1;
}

.sbn-modal-section-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #50575e;
    margin: 0 0 12px;
}

/* Full-width grid in modal (no truncation) */
.sbn-modal-grid-preview {
    overflow-x: auto;
    max-height: none !important;
}

.sbn-modal-play-btn {
    margin-top: 12px;
}

/* Songs list */
.sbn-modal-songs-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sbn-modal-songs-loading,
.sbn-modal-songs-empty {
    font-size: 13px;
    color: #999;
    font-style: italic;
}

.sbn-modal-song-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #f9f9f9;
    border: 1px solid #e5e5e5;
    border-radius: 6px;
    flex-wrap: wrap;
}

.sbn-modal-song-title {
    font-size: 14px;
    font-weight: 600;
    color: #1d2327;
    flex: 1;
    min-width: 0;
}

.sbn-modal-song-composer {
    font-size: 13px;
    color: #646970;
}

.sbn-modal-song-key {
    font-size: 11px;
    font-weight: 700;
    background: #e85d3b;
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
}

/* Responsive modal */
@media (max-width: 600px) {
    .sbn-modal-container {
        padding: 20px 16px;
        border-radius: 10px;
    }
    .sbn-modal-header {
        flex-direction: column;
    }
}
.sbn-pattern-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sbn-pattern-grid-row {
    display: flex;
    gap: 4px;
    align-items: center;
}

.sbn-pattern-grid-label {
    width: 60px;
    font-size: 11px;
    font-weight: 600;
    color: #646970;
    text-align: right;
    padding-right: 10px;
    line-height: 28px;
    flex-shrink: 0;
}

.sbn-pattern-grid-cells {
    display: flex;
    gap: 4px;
    flex: 1;
}

.sbn-pattern-grid-cell {
    width: 28px;
    height: 28px;
    border: 2px solid #ddd;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: #ccc;
    background: #fff;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

/* (Bar separator / measure-start styles removed) */

/* Beat Labels */
.sbn-pattern-grid-cell.is-beat-label {
    background: none;
    border: none;
    font-size: 11px;
    font-weight: 600;
    color: #999;
    cursor: default;
}

/* Hit States */
.sbn-pattern-grid-cell.is-hit {
    background: #fff5f3;
    border-color: #e85d3b;
    color: #e85d3b;
}

.sbn-pattern-grid-cell.is-accent {
    background: #e85d3b;
    border-color: #d04a2a;
    color: #fff;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(232, 93, 59, 0.2);
}

.sbn-pattern-grid-cell.is-thumb {
    border-style: dashed;
    border-width: 2px;
}

.sbn-pattern-grid-cell.is-thumb.is-hit {
    background: #f5f5f5;
    border-color: #666;
    border-style: solid;
    color: #333;
}

/* (Play button styles moved to Card Footer section above) */

/* Responsive Adjustments */
@media (max-width: 480px) {
    .sbn-pattern-card {
        padding: 16px;
    }
    
    .sbn-pattern-header h3 {
        font-size: 16px;
    }
    
    .sbn-pattern-grid-cell {
        width: 24px;
        height: 24px;
        font-size: 10px;
    }
    
    .sbn-pattern-grid-label {
        width: 50px;
        font-size: 10px;
    }
}

/* Empty State */
.sbn-empty-state {
    text-align: center;
    padding: 80px 40px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-top: 20px;
}

.sbn-empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.sbn-empty-state h2 {
    font-size: 24px;
    margin-bottom: 8px;
    color: #1d2327;
}

.sbn-empty-state p {
    color: #646970;
    margin-bottom: 24px;
    font-size: 16px;
}

/* Loading State */
.sbn-loading {
    text-align: center;
    padding: 60px 20px;
    color: #646970;
}

.sbn-loading::before {
    content: '⏳';
    font-size: 48px;
    display: block;
    margin-bottom: 16px;
    animation: sbn-pulse 1.5s ease-in-out infinite;
}

@keyframes sbn-pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Accessibility */
.sbn-pattern-play-btn:focus {
    outline: 2px solid #e85d3b;
    outline-offset: 2px;
}

.sbn-pattern-grid-cell:focus {
    outline: 2px solid #2271b1;
    outline-offset: 1px;
}

/* Print Styles */
@media print {
    .sbn-pattern-play-btn {
        display: none;
    }
    
    .sbn-pattern-card {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

/* ============================================================
   MODAL — Integrated play row with mix slider
   ============================================================ */

.sbn-modal-play-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 14px;
    padding: 12px 14px;
    background: #f9f9f9;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
}

/* Mix slider row */
.sbn-modal-mix-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.sbn-modal-mix-label {
    font-size: 11px;
    font-weight: 600;
    color: #999;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sbn-modal-mix-slider {
    flex: 1;
    accent-color: #e85d3b;
    cursor: pointer;
    height: 4px;
}

/* Song items as links */
a.sbn-modal-song-item {
    text-decoration: none;
    color: inherit;
    transition: background 0.15s, border-color 0.15s;
}

a.sbn-modal-song-item:hover {
    background: #fff5f3;
    border-color: #e85d3b;
}

a.sbn-modal-song-item:hover .sbn-modal-song-title {
    color: #e85d3b;
}

.sbn-modal-song-title {
    transition: color 0.15s;
}

/* Active step highlight during sequencer playback */
.sbn-pattern-grid-cell.is-active-step {
    outline: 2px solid #2271b1;
    outline-offset: 1px;
    background-color: rgba(34, 113, 177, 0.08) !important;
    transition: outline 0.05s;
}

.sbn-pattern-grid-cell.is-accent.is-active-step,
.sbn-pattern-grid-cell.is-hit.is-active-step {
    outline: 2px solid #2271b1;
}
