/* MegaSFX AI — extends MegaMix app styles */

.navbar-links a.nav-active {
    color: #a78bfa;
}
.navbar-links a.nav-active::after {
    transform: scaleX(1);
    opacity: 1;
}

.megasfx-hero-title {
    font-size: 1.5rem;
    color: #e2e8f0;
    margin: 0 0 8px;
    font-weight: 600;
}

.megasfx-hero-sub {
    color: #94a3b8;
    font-size: 0.95rem;
    margin: 0 0 24px;
    max-width: 52rem;
}

.megasfx-prompt-heading {
    font-size: 1rem;
    font-weight: 600;
    color: #e2e8f0;
    margin: 0 0 10px;
}

.megasfx-preset-hint {
    margin: 18px 0 10px;
    color: #94a3b8;
}

.megasfx-suggested-wrap {
    margin: 16px 0 8px;
    padding: 14px 14px 10px;
    border-radius: 14px;
    border: 1px solid rgba(139, 92, 246, 0.35);
    background: linear-gradient(145deg, rgba(139, 92, 246, 0.1), rgba(15, 23, 42, 0.55));
}

.megasfx-suggested-header {
    margin-bottom: 10px;
}

.megasfx-suggested-title {
    margin: 0 0 4px;
    font-size: 1rem;
    font-weight: 600;
    color: #e9d5ff;
}

.megasfx-suggested-sub {
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.4;
}

.megasfx-suggested-grid {
    margin-bottom: 10px;
}

.sfx-preset-card.sfx-suggested-card {
    align-items: stretch;
    text-align: left;
    min-height: 108px;
}

.sfx-suggested-card .sfx-preset-emoji {
    align-self: center;
    font-size: 1.5rem;
}

.sfx-suggested-card .sfx-preset-name {
    font-size: 0.88rem;
    line-height: 1.25;
}

.sfx-suggested-reason {
    margin: 0;
    font-size: 0.72rem;
    line-height: 1.35;
    color: #94a3b8;
}

.megasfx-suggested-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.megasfx-suggested-loading {
    margin: 0 0 10px;
    font-size: 0.85rem;
    color: #c4b5fd;
}

.sfx-preset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin: 0 0 16px;
}

.sfx-preset-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 10px;
    border-radius: 12px;
    border: 2px solid rgba(139, 92, 246, 0.25);
    background: rgba(15, 23, 42, 0.6);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    text-align: center;
    font: inherit;
    color: inherit;
}

.sfx-preset-card:hover {
    border-color: rgba(139, 92, 246, 0.55);
    background: rgba(30, 41, 59, 0.8);
}

.sfx-preset-card.selected {
    border-color: #8b5cf6;
    background: rgba(139, 92, 246, 0.12);
    box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.35);
}

.sfx-preset-emoji {
    font-size: 1.75rem;
    line-height: 1;
}

.megasfx-waveform-wrap {
    position: relative;
    width: 100%;
    margin-bottom: 8px;
    cursor: grab;
    touch-action: none;
    overflow: hidden;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.3);
}

.megasfx-waveform-wrap canvas {
    display: block;
    width: 100%;
    height: 70px;
    position: relative;
    z-index: 1;
}

.megasfx-trim-ui {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.megasfx-trim-ui.hidden {
    display: none;
}

.megasfx-trim-shade {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(2, 6, 23, 0.62);
    pointer-events: none;
}

.megasfx-trim-shade-left {
    left: 0;
}

.megasfx-trim-shade-right {
    right: 0;
}

.megasfx-trim-selection {
    position: absolute;
    top: 0;
    bottom: 0;
    border-top: 2px solid rgba(251, 191, 36, 0.95);
    border-bottom: 2px solid rgba(251, 191, 36, 0.95);
    box-shadow: inset 0 0 0 1px rgba(251, 191, 36, 0.25);
    pointer-events: none;
}

.megasfx-trim-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 18px;
    margin-left: -9px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: ew-resize;
    pointer-events: auto;
    z-index: 3;
    touch-action: none;
}

.megasfx-trim-handle::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 4px;
    margin-left: -2px;
    border-radius: 2px;
    background: #fbbf24;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.megasfx-trim-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 10px;
    height: 28px;
    margin: -14px 0 0 -5px;
    border-radius: 4px;
    background: #fbbf24;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}

.megasfx-trim-handle:focus-visible {
    outline: 2px solid #a78bfa;
    outline-offset: 2px;
}

.megasfx-trim-handle.is-dragging {
    cursor: ew-resize;
}

.megasfx-trim-hint {
    margin: 0 0 12px;
    color: #94a3b8;
    font-size: 0.82rem;
    line-height: 1.4;
}

.megasfx-trim-hint.hidden {
    display: none;
}

.sfx-preset-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: #e2e8f0;
    line-height: 1.25;
}

.megasfx-prompt-input {
    width: 100%;
    margin: 0;
}

.megasfx-duration-row {
    display: none;
}

.megasfx-duration-row label {
    font-size: 0.9rem;
    color: #94a3b8;
    min-width: 100px;
}

.megasfx-duration-row input[type="range"] {
    flex: 1 1 160px;
    min-width: 120px;
}

.megasfx-duration-value {
    font-size: 0.9rem;
    color: #c4b5fd;
    min-width: 4.5rem;
}

.megasfx-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-top: 16px;
}

.megasfx-status {
    color: #94a3b8;
    font-size: 0.9rem;
    margin: 0;
}

.megasfx-variations-title {
    margin: 0 0 8px;
    font-size: 1.15rem;
    color: #e2e8f0;
}

.megasfx-variations-sub {
    margin: 0 0 16px;
    color: #94a3b8;
    font-size: 0.92rem;
    line-height: 1.5;
    max-width: 52rem;
}

.megasfx-variation-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0 0 14px;
}

.megasfx-variation-row {
    display: grid;
    grid-template-columns: auto minmax(120px, 1fr) minmax(160px, 2.2fr) auto auto;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid rgba(139, 92, 246, 0.22);
    background: rgba(15, 23, 42, 0.55);
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.megasfx-variation-row:hover {
    border-color: rgba(139, 92, 246, 0.45);
    background: rgba(30, 41, 59, 0.75);
}

.megasfx-variation-row.is-selected {
    border-color: #8b5cf6;
    background: rgba(139, 92, 246, 0.12);
    box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.3);
}

.megasfx-variation-row.is-playing {
    border-color: rgba(167, 139, 250, 0.65);
    background: rgba(139, 92, 246, 0.16);
}

.megasfx-variation-play-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(139, 92, 246, 0.35);
    color: #fff;
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
}

.megasfx-variation-play-btn:hover {
    background: rgba(139, 92, 246, 0.55);
}

.megasfx-variation-row.is-playing .megasfx-variation-play-btn {
    background: #8b5cf6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.25);
}

.megasfx-variation-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.megasfx-variation-label {
    font-weight: 700;
    color: #f1f5f9;
    font-size: 0.92rem;
    line-height: 1.25;
}

.megasfx-variation-tag {
    margin: 0;
    font-size: 0.78rem;
    color: #94a3b8;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.megasfx-variation-wave-wrap {
    position: relative;
    min-width: 0;
    height: 44px;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.35);
    cursor: pointer;
    touch-action: none;
}

.megasfx-variation-waveform {
    display: block;
    width: 100%;
    height: 44px;
}

.megasfx-variation-time {
    flex-shrink: 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: #c4b5fd;
    font-variant-numeric: tabular-nums;
    min-width: 2.8rem;
    text-align: right;
}

.megasfx-variation-select {
    flex-shrink: 0;
    white-space: nowrap;
}

.megasfx-variation-row.is-selected .megasfx-variation-select {
    background: rgba(139, 92, 246, 0.35);
    border-color: rgba(167, 139, 250, 0.65);
}

@media (max-width: 720px) {
    .megasfx-variation-row {
        grid-template-columns: auto 1fr auto;
        grid-template-rows: auto auto;
    }

    .megasfx-variation-info {
        grid-column: 2;
        grid-row: 1;
    }

    .megasfx-variation-wave-wrap {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    .megasfx-variation-time {
        grid-column: 2;
        grid-row: 1;
        justify-self: end;
    }

    .megasfx-variation-select {
        grid-column: 3;
        grid-row: 1;
    }
}

.megasfx-step-locked {
    opacity: 0.45;
    pointer-events: none;
    user-select: none;
}

body[data-megasfx-ready="1"] #playback-section,
body[data-megasfx-ready="1"] #placement-section,
body[data-megasfx-ready="1"] #export-section {
    opacity: 1;
    pointer-events: auto;
    user-select: auto;
}

body[data-megasfx-variations="1"] #panel-variations {
    opacity: 1;
    pointer-events: auto;
    user-select: auto;
}

body[data-megasfx-ready="1"] #playback-section .megasfx-unlock-hint,
body[data-megasfx-ready="1"] #placement-section .megasfx-unlock-hint,
body[data-megasfx-ready="1"] #export-section .megasfx-unlock-hint {
    display: none;
}

body[data-megasfx-variations="1"] #panel-variations > .megasfx-unlock-hint {
    display: none;
}

.megasfx-step-locked .megasfx-unlock-hint {
    opacity: 1;
    pointer-events: auto;
}

.megasfx-unlock-hint {
    color: #94a3b8;
    font-size: 0.9rem;
    margin: 0 0 12px;
}

.megasfx-unlock-hint.hidden {
    display: none;
}

.megasfx-status-error {
    color: #f87171;
}

.megasfx-export-section {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.megasfx-preview-meta {
    font-size: 0.85rem;
    color: #94a3b8;
    margin: 0 0 12px;
}

.megasfx-level-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 14px;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.18);
    max-width: 360px;
}

.megasfx-level-label {
    flex-shrink: 0;
    font-size: 0.88rem;
    font-weight: 600;
    color: #cbd5e1;
    min-width: 3.5rem;
}

.megasfx-level-row input[type="range"] {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
}

#playback-section .step3-unified-card.iterate-card {
    gap: 0;
}

#playback-section #preview-card {
    position: relative;
}

/* Keep loading overlay out of document flow so chat layout never jumps */
#playback-section #mix-loading-block {
    position: absolute;
    left: 0;
    right: 0;
    top: 8px;
    z-index: 4;
    margin: 0;
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(139, 92, 246, 0.35);
    pointer-events: none;
}

#playback-section #mix-loading-block.hidden {
    display: none;
}

#playback-section .chat-wrap.chat-card {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    contain: none;
}

#playback-section .step3-chat-header-row {
    flex: 0 0 auto;
    margin-bottom: 10px;
}

/* Only the history scrolls — header, presets, and input stay fully visible */
#playback-section .chat-messages {
    height: 168px;
    min-height: 168px;
    max-height: 168px;
    flex: 0 0 168px;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: auto;
    overscroll-behavior: contain;
}

#playback-section .chat-message {
    margin-bottom: 8px;
    line-height: 1.45;
    word-break: break-word;
    animation: none;
}

#playback-section .chat-message-user {
    color: #a78bfa;
}

#playback-section .chat-message-bot {
    color: #94a3b8;
}

#playback-section .quick-prompts {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 88px;
    overflow-y: auto;
    overflow-x: hidden;
    margin: 10px 0;
    padding-right: 2px;
    overscroll-behavior: contain;
}

#playback-section .quick-prompts .quick-prompt {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 0.78rem;
}

#playback-section .chat-input-wrap {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 0;
    padding-bottom: 2px;
}

#playback-section .chat-input-wrap #chat-input,
#playback-section .chat-input-wrap #chat-send {
    flex-shrink: 0;
}

#playback-section .chat-input-wrap #chat-input {
    flex: 1 1 auto;
    min-width: 0;
}

/* Step 4 — intelligent placement */
.placement-section {
    margin-bottom: 28px;
}

.megasfx-placement-title {
    margin: 0 0 8px;
    font-size: 1.15rem;
    color: #e2e8f0;
}

.megasfx-placement-sub {
    margin: 0 0 16px;
    color: #94a3b8;
    font-size: 0.92rem;
    line-height: 1.5;
    max-width: 52rem;
}

.megasfx-placement-track-card {
    padding: 18px;
    border-radius: 14px;
    border: 1px solid rgba(139, 92, 246, 0.25);
    background: rgba(15, 23, 42, 0.55);
}

.megasfx-placement-track-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.megasfx-placement-track-name {
    font-weight: 600;
    color: #f1f5f9;
}

.megasfx-placement-mood {
    display: inline-flex;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #ddd6fe;
    background: rgba(139, 92, 246, 0.2);
    border: 1px solid rgba(139, 92, 246, 0.35);
    text-transform: capitalize;
}

.megasfx-placement-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.megasfx-placement-status {
    margin: 0 0 12px;
    color: #94a3b8;
    font-size: 0.88rem;
}

.megasfx-placement-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 12px;
    color: #c4b5fd;
    font-size: 0.88rem;
}

.megasfx-placement-loading.hidden {
    display: none;
}

.megasfx-placement-play-wrap {
    margin-bottom: 10px;
}

.megasfx-placement-waveform-wrap {
    position: relative;
    width: 100%;
    margin-bottom: 10px;
    border-radius: 10px;
    overflow: hidden;
    cursor: crosshair;
    touch-action: none;
    background: rgba(0, 0, 0, 0.35);
}

.megasfx-placement-canvas {
    display: block;
    width: 100%;
    height: 96px;
}

.megasfx-placement-markers {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.megasfx-placement-marker {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 14px;
    margin-left: -7px;
    pointer-events: auto;
    cursor: grab;
    z-index: 2;
}

.megasfx-placement-marker.is-selected {
    z-index: 3;
}

.megasfx-placement-marker-pin {
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fbbf24;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.35);
}

.megasfx-placement-marker-line {
    position: absolute;
    top: 14px;
    bottom: 0;
    left: 50%;
    width: 2px;
    margin-left: -1px;
    background: rgba(251, 191, 36, 0.85);
}

.megasfx-placement-marker.is-selected .megasfx-placement-marker-pin {
    background: #8b5cf6;
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.45);
}

.megasfx-placement-marker.is-selected .megasfx-placement-marker-line {
    background: rgba(139, 92, 246, 0.95);
}

.megasfx-placement-marker.is-dragging {
    cursor: grabbing;
}

.megasfx-placement-progress-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.megasfx-placement-marker-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.megasfx-placement-marker-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) minmax(280px, 1.4fr) auto auto;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.megasfx-placement-marker-row.is-selected {
    border-color: rgba(139, 92, 246, 0.45);
    background: rgba(139, 92, 246, 0.08);
}

.megasfx-placement-marker-time {
    font-weight: 600;
    color: #fbbf24;
    font-variant-numeric: tabular-nums;
    min-width: 3.5rem;
}

.megasfx-placement-marker-reason {
    color: #94a3b8;
    font-size: 0.85rem;
    line-height: 1.35;
}

.megasfx-placement-marker-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
    min-width: 0;
}

.megasfx-placement-marker-volume,
.megasfx-placement-marker-pan {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.megasfx-placement-marker-volume {
    flex: 1 1 120px;
    max-width: 160px;
}

.megasfx-placement-marker-pan {
    flex: 1 1 140px;
    max-width: 170px;
    position: relative;
    flex-wrap: wrap;
}

.megasfx-placement-marker-volume-label,
.megasfx-placement-marker-pan-label {
    flex-shrink: 0;
    font-size: 0.78rem;
    font-weight: 600;
    color: #94a3b8;
    min-width: 2.2rem;
}

.megasfx-placement-marker-pan-label {
    min-width: 4.5rem;
}

.megasfx-placement-marker-pan-value {
    color: #c4b5fd;
    font-variant-numeric: tabular-nums;
}

.megasfx-placement-marker-volume-slider,
.megasfx-placement-marker-pan-slider {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
}

.megasfx-placement-marker-pan-ends {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding-left: 4.5rem;
    margin-top: -4px;
    font-size: 0.68rem;
    color: #64748b;
    letter-spacing: 0.02em;
}

@media (max-width: 900px) {
    .megasfx-placement-marker-row {
        grid-template-columns: auto 1fr;
    }

    .megasfx-placement-marker-controls {
        grid-column: 1 / -1;
    }

    .megasfx-placement-marker-row > [data-action="duplicate"],
    .megasfx-placement-marker-row > [data-action="delete"] {
        justify-self: start;
    }
}

.megasfx-placement-hint {
    margin: 12px 0 0;
}
