/* ======================= CONTENT EDITING OVERLAY ======================= */
.content-edit-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.45);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.content-edit-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.content-edit-overlay.active .content-edit-container {
    animation: dialog-pop 0.25s cubic-bezier(0.34, 1.2, 0.64, 1);
}

.content-edit-container {
    width: 92%;
    max-width: 1600px;
    height: 93vh;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content-edit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    gap: 12px;
    flex-wrap: nowrap;
    min-width: 0;
}

/* Title section: takes remaining space but NEVER pushes actions off screen.
   flex: 1 1 0 + min-width: 0 is the key flex truncation combo. */
.content-edit-title-section {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
}

.content-edit-title-section h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.content-edit-title-section p {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0;
}

/* Meta row: author truncates, separator and key NEVER shrink */
.content-edit-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    min-width: 0;
    overflow: hidden;
}

/* Author paragraph: shrinks and truncates */
.content-edit-meta > p:first-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex-shrink: 1;
    margin: 0;
}

.content-edit-separator {
    color: var(--text-tertiary);
    font-size: 12px;
    flex-shrink: 0;
}

/* Key label: NEVER shrinks, NEVER wraps — always fully visible */
.content-edit-key {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--accent);
    font-weight: 600;
    flex-shrink: 0;
    white-space: nowrap;
}

.content-edit-key i {
    font-size: 12px;
}

/* Actions side: never shrinks */
.content-edit-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.content-edit-zoom-controls {
    display: flex;
    gap: 4px;
    padding-right: 12px;
    border-right: 1px solid var(--border);
}

.icon-btn-small {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 14px;
}

.icon-btn-small:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    color: var(--text-primary);
}

.icon-btn-small:active {
    transform: scale(0.95);
}

.icon-btn-small:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    border-color: var(--border);
}

.icon-btn-small:disabled:hover {
    background: var(--surface);
    color: var(--text-secondary);
}

.content-edit-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.content-edit-input-section {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

.content-edit-input-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 20px;
    border-bottom: 1px solid var(--border-light);
}

/* Syntax hint: takes remaining space, truncates when tight */
.content-edit-syntax-hint {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    font-size: 12px;
    color: var(--text-tertiary);
}

/* Prose text truncates when space is tight */
.content-edit-syntax-hint span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    display: block;
}

/* Code badges inside hint */
.content-edit-syntax-hint code {
    background: var(--background);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--accent);
    font-weight: 600;
    white-space: nowrap;
}

.content-edit-textarea {
    flex: 1;
    border: none;
    outline: none;
    padding: 20px;
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--surface);
    resize: none;
    overflow-y: auto;
    overflow-x: auto;
    white-space: pre;
    -webkit-spell-check: false;
    text-decoration: none;
}

.content-edit-textarea::placeholder {
    color: var(--text-tertiary);
}

.content-edit-preview-section {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content-edit-preview {
    flex: 1;
    padding: 40px 40px;
    overflow-y: auto;
    overflow-x: auto;
    background: var(--surface-elevated);
    box-shadow: inset 4px 4px 20px rgba(0, 0, 0, 0.03), 
                inset -1px -1px 20px rgba(0, 0, 0, 0.11);
}

/* Match the exact structure of lyrics-content */
.content-edit-preview .lyric-line {
    font-family: var(--font-mono);
    font-size: var(--preview-font-size, var(--font-size-songs));
    line-height: var(--line-height-songs);
    color: var(--text-primary);
    white-space: pre;
    font-weight: var(--lyrics-weight);
    margin: 0;
}

/* Match the exact chord styling from main display */
.content-edit-preview .chord {
    display: inline-block;
    color: var(--accent);
    font-weight: var(--chord-weight);
    font-size: var(--preview-font-size, var(--font-size-songs));
    font-family: var(--chord-font);
    position: relative;
    bottom: var(--chord-distance);
}

/* Inline chords inside text lines in preview — no position shift */
.content-edit-preview .chord.inline-chord {
    position: static;
    bottom: auto;
}

/* Match verse label styling */
.content-edit-preview .verse-label,
.content-edit-preview .section-label {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: var(--preview-font-size, var(--font-size-songs));
    font-weight: 600;
    color: color-mix(in srgb, var(--text-primary) 85%, transparent);
    display: block;
}

/* Match line color marker styling */
.content-edit-preview .lyric-line--marked {
    border-left: 2px solid var(--line-marker-color, #94a3b8);
    padding-left: 16px;
    padding-right: 1ch;
}

/* Match comment styling */
.content-edit-preview .comment {
    color: var(--text-tertiary);
    font-style: italic;
    opacity: 0.6;
}


/* ======================= LINE COLOR DROPDOWN ======================= */
.line-color-dropdown {
    position: relative;
    flex-shrink: 0;
}

.line-color-trigger {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
    white-space: nowrap;
}

.line-color-trigger:hover {
    border-color: var(--accent);
    color: var(--text-primary);
    background: var(--surface-hover);
}

.line-color-dropdown.open .line-color-trigger {
    border-color: var(--accent);
    color: var(--text-primary);
}

.line-color-trigger-pip {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    flex-shrink: 0;
    transition: background 0.15s;
}

.line-color-chevron {
    font-size: 9px;
    transition: transform 0.15s ease;
    opacity: 0.6;
}

.line-color-dropdown.open .line-color-chevron {
    transform: rotate(180deg);
}

.line-color-menu {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    min-width: 158px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15), 0 2px 6px rgba(0, 0, 0, 0.08);
    padding: 4px;
    z-index: 200;
    display: none;
    flex-direction: column;
    gap: 1px;
}

.line-color-dropdown.open .line-color-menu {
    display: flex;
}

.line-color-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 7px 10px;
    border: none;
    border-radius: 7px;
    background: transparent;
    cursor: pointer;
    text-align: left;
    transition: background 0.1s ease;
    color: var(--text-primary);
    font-size: 13px;
}

.line-color-item:hover {
    background: var(--surface-hover);
}

.line-color-swatch {
    width: 13px;
    height: 13px;
    border-radius: 3px;
    flex-shrink: 0;
}

.line-color-swatch[data-color="v"] { background: var(--line-color-verse); }
.line-color-swatch[data-color="c"] { background: var(--line-color-chorus); }
.line-color-swatch[data-color="b"] { background: var(--line-color-bridge); }
.line-color-swatch[data-color="p"] { background: var(--line-color-prechorus); }
/* Extra colors are fixed vivid shades so they always stand out */
.line-color-swatch--x { background: rgba(249, 115, 22, 0.90); }
.line-color-swatch--y { background: rgba(168, 85, 247, 0.90); }

.line-color-item-label {
    flex: 1;
    white-space: nowrap;
}

.line-color-item-code {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-tertiary);
    background: var(--background);
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
}

.line-color-divider {
    height: 1px;
    background: var(--border-light);
    margin: 3px 2px;
}

.line-color-item--remove {
    color: var(--text-secondary);
}

.line-color-item--remove:hover {
    background: color-mix(in srgb, #ef4444 8%, transparent);
    color: #ef4444;
}

.line-color-remove-icon {
    width: 13px;
    text-align: center;
    flex-shrink: 0;
    font-size: 11px;
}


/* ======================= CONTENT EDIT RESPONSIVE ======================= */
/*
   Strategy: always one row in the header, no vertical stacking of panels.
   — Author truncates; separator and key label are always fully visible.
   — Panel goes near-full-screen at 1100px to reclaim margin space early.
   — Panel goes truly full-screen at 900px.
   — Textarea font shrinks progressively at 1100px → 900px.
   — Preview font scaling: --content-edit-zoom-scale is set on the container
     at each breakpoint. applyPreviewZoom() in content-editing.js reads this
     and multiplies the user's chosen zoom by it, so +/- still works but the
     base level shifts down on smaller screens.
*/
/* ── 1300px: start minor tightening a bit earlier ── */
@media (max-width: 1300px) {
    .content-edit-header {
        gap: 10px;
    }
    .content-edit-actions {
        gap: 6px;
    }
    .content-edit-zoom-controls {
        padding-right: 10px;
    }
}

/* ── 1250px: small margins + font starts shrinking ── */
@media (max-width: 1250px) {
    .content-edit-overlay {
        padding: 10px;
        box-sizing: border-box;
    }

    .content-edit-container {
        width: 100%;
        max-width: 100%;
        height: calc(100dvh - 20px);
        border-radius: 12px;
        --content-edit-zoom-scale: 0.92;
    }

    .content-edit-title-section h2 {
        font-size: 18px;
    }

    .content-edit-title-section p,
    .content-edit-meta > p:first-child,
    .content-edit-key {
        font-size: 13px;
    }

    .content-edit-header {
        padding: 10px 16px;
    }

    .content-edit-input-header {
        padding: 8px 16px;
    }

    .content-edit-textarea {
        font-size: 13px;
        padding: 16px;
    }
}

/* ── 1050px: tighten further ── */
@media (max-width: 1050px) {
    .content-edit-container {
        --content-edit-zoom-scale: 0.85;
    }

    .content-edit-title-section h2 {
        font-size: 16px;
    }

    .content-edit-textarea {
        font-size: 12px;
        padding: 14px;
    }
}

/* ── 900px: truly full-screen, tighten everything further ── */
@media (max-width: 900px) {
    .content-edit-overlay {
        padding: 0;
    }

    .content-edit-container {
        height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        --content-edit-zoom-scale: 0.78;
    }

    /* On narrow screens: hide preview, editor takes full width */
    .content-edit-preview-section {
        display: none;
    }

    .content-edit-input-section {
        border-right: none;
    }

    /* Zoom controls only relevant when preview is visible */
    .content-edit-zoom-controls {
        display: none;
    }

    .content-edit-title-section h2 {
        font-size: 15px;
        margin-bottom: 2px;
    }

    .content-edit-title-section p,
    .content-edit-meta > p:first-child,
    .content-edit-key,
    .content-edit-separator {
        font-size: 12px;
    }

    .content-edit-header {
        padding: 8px 14px;
        gap: 6px;
    }

    .content-edit-actions {
        gap: 4px;
    }

    .icon-btn-small {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .content-edit-input-header {
        padding: 6px 14px;
    }

    .content-edit-syntax-hint {
        font-size: 11px;
    }

    .content-edit-textarea {
        font-size: 12px;
        padding: 14px;
    }

    .content-edit-preview {
        padding: 24px;
    }
}


/* ======================= MOBILE BOTTOM BAR ======================= */
/* Hidden by default — shown only on phones (≤ 600px) */
.content-edit-mobile-bar {
    display: none;
    flex-shrink: 0;
}


/* ======================= TOUCH-DEVICE OVERRIDES (pointer: coarse) ======================= */
/*
   Applies to all tablets and phones.
   Hides +/- zoom buttons — pinch-to-zoom is used on each panel instead.
   Everything else (header, fonts, buttons) uses the existing width-based rules unchanged.
*/
@media (pointer: coarse) {
    .content-edit-zoom-controls {
        display: none;
    }
}


/* ======================= TABLET LANDSCAPE: FULL-SCREEN ======================= */
/*
   On any touch tablet held in landscape, remove the floating-panel margin and
   let the editor fill the whole screen.  Portrait tablets keep their existing
   behaviour (floating or full-screen depends on width via the 900px rule above).
*/
@media (pointer: coarse) and (orientation: landscape) {
    .content-edit-overlay {
        padding: 0;
    }

    .content-edit-container {
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        border-radius: 0;
        box-shadow: none;
    }
}


/* ======================= MOBILE PHONE (≤ 600px): STICKY BOTTOM BAR + TOOLBAR ======================= */
/*
   Header is unchanged — the existing width-based rules handle it.
   Save/Cancel move to a sticky bar at the bottom.
   The editor toolbar row is simplified: syntax hint hidden, line color button sized for touch.
*/
@media (max-width: 600px) {
    /* Move Save/Cancel out of the header down to the sticky bar */
    .content-edit-actions {
        display: none;
    }

    /* Sticky bottom bar */
    .content-edit-mobile-bar {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        background: var(--surface);
        border-top: 1px solid var(--border);
    }

    .content-edit-mobile-bar .btn-content-cancel,
    .content-edit-mobile-bar .btn-content-save {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 12px 16px;
        font-size: 15px;
    }

    /* Toolbar row: not useful on mobile (can't easily select text, syntax hint too small) */
    .content-edit-input-header {
        display: none;
    }
}