/* Highlight chord name in green when playing */
.char[data-chord].playing::before {
    color: #2ecc40 !important;
    background: none;
}

/* Highlight chord-display elements when parent char is playing */
.char[data-chord].playing .chord-display {
    color: #2ecc40 !important;
}
/* Chord display using data-chord attribute on .char */
.char[data-chord] {
    position: relative;
}
.char[data-chord]::before {
    content: attr(data-chord);
    position: absolute;
    top: -1.4em;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85em;
    font-weight: bold;
    color: #1a4fa3;
    white-space: nowrap;
    pointer-events: none;
    z-index: 2;
}

/* Alternative chord display using a real element instead of ::before */
.char[data-chord] .chord-display {
    position: absolute;
    top: -1.4em;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85em;
    font-weight: bold;
    color: #1a4fa3;
    white-space: nowrap;
    pointer-events: none;
    z-index: 2;
}

/* Hide ::before when we have a real chord-display element */
.char[data-chord]:has(.chord-display)::before,
.char[data-chord].has-chord-display::before {
    display: none !important;
}
/* Instrumental cell chord: align left, match lyrics font size, no background */
.instrumental-cell .chord {
    position: relative !important;
    color: blue;
    font-weight: bold;
    font-size: 0.8em; /* Match chord lyrics size */
    cursor: grab;
    user-select: none;
    text-align: left;
    margin-left: 4px;
    bottom: 0 !important;
}

/* Override chord positioning for instrumental cells - center the chord in the cell */
.instrumental-cell .char[data-chord]::before {
    position: static !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    display: inline !important;
}

/* Hide the actual char content in instrumental cells (it's just a non-breaking space) */
.instrumental-cell .char[data-chord] {
    font-size: 0;
    color: transparent;
}

/* Hide the actual char content in standalone instrumental sections (it's just a non-breaking space) */
.song-section.instrumental-section .char[data-chord] {
    font-size: 0;
    color: transparent;
}

/* Style the chord display in instrumental cells */
.instrumental-cell .char[data-chord]::before {
    font-size: 14px;
    color: #1a4fa3;
    font-weight: bold;
}

/* Override chord positioning for standalone instrumental sections */
.song-section.instrumental-section .char[data-chord]::before {
    position: static !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    display: inline !important;
    font-size: 14px;
    color: #1a4fa3;
    font-weight: bold;
}

/* Style the real chord-display elements in instrumental cells */
.instrumental-cell .char[data-chord] .chord-display {
    position: static !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    display: inline !important;
    font-size: 14px;
    color: #1a4fa3;
    font-weight: bold;
}

/* Hide ::before in instrumental cells when chord-display element exists */
.instrumental-cell .char[data-chord]:has(.chord-display)::before,
.instrumental-cell .char[data-chord].has-chord-display::before {
    display: none !important;
}

/* Styling for standalone instrumental sections (not in table cells) */
.song-section.instrumental-section .char[data-chord] .chord-display {
    position: static !important;
    transform: none !important;
    top: auto !important;
    left: auto !important;
    display: inline !important;
    font-size: 14px;
    color: #1a4fa3;
    font-weight: bold;
}

/* Hide ::before in standalone instrumental sections when chord-display element exists */
.song-section.instrumental-section .char[data-chord]:has(.chord-display)::before,
.song-section.instrumental-section .char[data-chord].has-chord-display::before {
    display: none !important;
}

/* Instrumental Section Table Styling */
.instrumental-table {
    width: auto;
    border-collapse: collapse;
    display: inline-table;
    margin: 0;
    padding: 0;
    vertical-align: baseline;
}
.instrumental-cell {
    border: 1px dashed #e8e8e8;
    width: 48px;
    height: 20px;
    text-align: center;
    vertical-align: middle;
    background: none;
}

@media print {
    .instrumental-cell {
        border: none !important;
        background: none !important;
    }
}
/* Loading Spinner Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255,255,255,0.95);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.loading-text {
    margin-top: 18px;
    font-size: 1.5em;
    color: #333;
    font-weight: 500;
}
/* Sidebar toggle switches for Play Click, Loop, Play on Hover */
.checkbox-row .flat-sharp-toggle-row {
    margin-top: 0;
    margin-bottom: 8px;
    gap: 10px;
    align-items: center;
    display: flex;
}
.checkbox-row .flat-sharp-toggle-row label:first-child {
    min-width: 80px;
    color: #444;
    margin-right: 6px;
}
.checkbox-row .switch {
    margin-left: 0;
}
/* --- Flat/Sharp Toggle Switch --- */
.flat-sharp-toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

/* Flat/Sharp toggle switch styles - 50% smaller */
.switch {
    position: relative;
    display: inline-block;
    width: 25px; /* Reduced width */
    height: 11px; /* Reduced height */
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 12px; /* Reduced border radius */
}
.slider:before {
    position: absolute;
    content: "";
    height: 9px; /* Reduced height */
    width: 9px; /* Reduced width */
    left: 1px; /* Adjusted position */
    bottom: 1px; /* Adjusted position */
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider {
    background-color: #007bff;
}
input:checked + .slider:before {
    transform: translateX(14px); /* Fine-tuned for 25px width and 9px ball */
}
#flat-sharp-label {
    font-size: 0.75em; /* Reduced font size */
    margin-left: 2.5px; /* Adjusted margin */
    vertical-align: middle;
    transition: color 0.3s;
}
:root {
    --panel-width: 280px;
}
html {
    scroll-behavior: smooth;
}
body {
    font-family: sans-serif;
    margin: 0;
    height: 100vh;
    overflow: hidden;
    background-color: #fff;
    position: relative;
}
.main-content {
    position: absolute;
    top: 0;
    left: 0;
    right: var(--panel-width);
    bottom: 0;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
}
.main-content.panel-open {
    right: var(--panel-width);
}
.main-content {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    transition: filter 0.3s ease;
}
.main-content.panel-open {
    /* Keep editor usable when panel is open */
    right: 0;
}
.fixed-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #fff;
    padding-left: 20px;
    border-bottom: 1px dashed #e0e0e0;
}

.scrollable-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.song-info {
    margin-bottom: 20px;
    display: block;
}

#copyright-label {
  padding-left: 10px;
}
/* Copyright row inline layout */
.copyright-row {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #777;
}
.song-info input {
    width: auto;
    padding: 4px 8px;
    box-sizing: border-box;
    border: 1px solid transparent;
    background-color: transparent;
    outline: none;
    border-radius: 4px;
    transition: background-color 0.2s, border-color 0.2s;
    margin-bottom: 8px;
    display: block;
}
/* Copyright input stays inline in copyright-row */
.copyright-row input {
    margin-bottom: 0;
    display: inline-block;
    padding-left: 0;
}
.song-info input:hover {
    background-color: #f0f0f0;
}
.song-info input:focus {
    background-color: #fff;
    border-color: #ccc;
}
#song-title {
    font-size: 2.2em;
    font-weight: bold;
    color: #222;
}
#song-artist {
    font-size: 1.4em;
    font-style: italic;
    color: #555;
    margin-bottom: 15px;
}
#song-copyright {
    font-size: 0.9em;
    color: #777;
    margin-bottom: 2px;
}
.chord-toolbar {
    margin-bottom: 20px;
    padding: 10px;
    background-color: #fff;
}

.chord-mode-toggles {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.mode-toggle {
    padding: 8px 16px;
    border: none;
    background: #fff;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    color: #666;
}

.mode-toggle:hover {
    background: #f8f9fa;
    color: #007bff;
}

.mode-toggle.active {
    background: #007bff;
    color: white;
}

.inline-delete-btn {
    display: none;
    position: absolute;
    top: -11px;
    left: -24px;
    z-index: 10;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.inline-delete-btn[style*="inline-block"], 
.inline-delete-btn[style*="flex"] {
    display: flex !important;
}

.inline-delete-btn:hover {
    background: #ff3742;
}

.inline-beat-badge {
    display: none;
    position: absolute;
    top: -11px;
    left: -24px;
    z-index: 10;
    background: #007bff;
    color: white;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    font-size: 10px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    font-weight: bold;
}

.inline-beat-badge[style*="inline-block"],
.inline-beat-badge[style*="flex"] {
    display: flex !important;
}

.inline-beat-badge:hover {
    background: #0056b3;
}
.chord-placeholder {
    display: inline-block;
    width: 60px;
    height: 70px;
    cursor: grab;
    user-select: none;
    vertical-align: top;
    position: relative;
}

.chord-container-relative {
    position: relative;
}
.chord-toolbar-delete-btn {
    position: absolute;
    right: 4px;
    top: -10px;
    z-index: 10;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    box-shadow: none;
    color: #888;
    display: none;
}

.chord-lyrics-delete-btn:hover {
  color: #d33;
}
/* --- Section Styles --- */
#song-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    min-width: 0;
}
.song-section {
    /* Borders and background removed for WYSIWYG feel */
    position: relative; 
}

/* Reduce spacing for instrumental sections to match lyric line spacing */
.song-section.instrumental-section {
    margin: 0;
    padding: 0;
}
.section-header {
    /* Header is now just bold text */
    padding: 15px;
    font-size: 1.1em;
    font-weight: bold;
    color: #000;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.lyrics-editor {
    padding: 0 15px 0;
    white-space: pre-wrap;
    line-height: 2.5;
}
.lyrics-editor:focus {
    outline: none;
}
.char, .chord-container {
    display: inline-block;
    vertical-align: bottom;
}
    /*
     * Every character in lyrics must be wrapped in a .char span for drag-and-drop support.
     * Ensure .char spans have dragover and drop event listeners attached in JS.
     */
.char:hover { background-color: #e0e0e0; }
.chord-container { position: relative; }
.chord {
    position: absolute;
    bottom: 1.8em;
    left: 0;
    font-weight: bold;
    font-size: 0.8em;
    color: blue;
    cursor: grab;
    user-select: none;
    transition: color 0.2s;
}
.chord.playing {
    color: green;
}
.chord-container:not(:has(.char)) {
    padding-right: 2px;
    padding-left: 2px;
}

/* --- Comment Styles --- */
.section-header.comment, .section-header.comment-italic {
    font-style: italic;
    color: #555;
}
.section-header.comment-box {
    border: 1px solid #ccc;
    background-color: #f9f9f9;
    padding: 10px;
}

/* --- Page Break Style --- */
.page-break-indicator {
    text-align: center;
    margin: 20px 0;
    padding: 0 15px;
    color: #888;
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 15px;
}
.page-break-indicator::before,
.page-break-indicator::after {
    content: '';
    flex-grow: 1;
    height: 1px;
    background-color: #ccc;
}

/* --- In-line Delete Button --- */
.section-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #ccc;
    font-size: 1em;
    padding: 5px;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
}
.song-section:hover .section-delete-btn {
    visibility: visible;
    opacity: 1;
}
.section-delete-btn:hover {
    color: #dc3545; /* Red */
}
/* Special positioning for page break delete button */
.song-section[data-type="Page Break"] .section-delete-btn {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
}

/* --- Side Panel --- */

.side-panel.open {
    transform: translateX(0);
}
.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--panel-width);
    height: 100vh;
    background-color: #e9ecef;
    border-left: 1px solid #ccc;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    z-index: 100;
    box-shadow: -2px 0 16px 0 rgba(0,0,0,0.08);
    padding: 10px;
}
.panel-controls label {
    display: block;
    font-size: 0.8em;
    color: #555;
    margin-bottom: 4px;
}
.control-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}
.control-row select, .control-row input {
    flex-grow: 1;
}
.control-row input[type="number"] {
    width: 70px;
    flex-grow: 0;
}
.control-row input[type="checkbox"] {
    flex-grow: 0;
    width: auto;
    margin-left: 5px;
}
.panel-controls select, .panel-controls button, .panel-controls input {
    padding: 8px;
}
.checkbox-row {
    display: flex;
    gap: 20px;
    align-items: center;
    margin-top: 5px;
}
.checkbox-row > div {
    display: flex;
    align-items: center;
    gap: 5px;
}
.checkbox-row label {
    margin: 0;
    user-select: none;
}
#section-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex-grow: 1;
}
.panel-actions {
    padding: 15px 10px;
    border-top: 1px solid #ccc;
    background-color: #e9ecef;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.panel-actions button {
    width: 100%;
    padding: 10px;
}
#section-list li {
    display: flex;
    align-items: center;
    padding: 12px 10px;
    background-color: #fff;
    border-bottom: 1px solid #ddd;
    cursor: pointer;
    user-select: none;
}
#section-list li:hover { background-color: #f8f9fa; }
#section-list li.page-break-item {
    color: #888;
    font-style: italic;
}
#section-list li.page-break-item .section-name {
    cursor: default;
}
#section-list li.instrumental-item {
    color: #888;
    font-style: italic;
    cursor: default;
}
#section-list li.instrumental-item .section-name {
    cursor: default;
}
#section-list li.drag-over {
    border-top: 2px solid orange;
}
.section-name { flex-grow: 1; }
.section-name-input {
    flex-grow: 1;
    padding: 4px;
    font-size: 1em;
    border: 1px solid #007bff;
}
.delete-section-btn-panel {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 1.2em;
    visibility: hidden;
}
#section-list li:hover .delete-section-btn-panel {
    visibility: visible;
}

/* --- Panel Toggle Button --- */
#toggle-panel-btn {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 1000;
    width: 45px;
    height: 45px;
    background-color: #343a40;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.2em;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: right 0.3s ease;
}

/* --- SVGuitar Styles --- */
.svguitar-chord-column {
    width: 50px;
}
.svguitar {
    width: 100%; /* Make SVG fill its container */
}
.name {
    width: 20em;
}

/* --- Modal Styles --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}
.modal-overlay.hidden {
    display: none;
}
.modal-content {
    background: #fff;
    padding: 20px 30px;
    border-radius: 8px;
    width: 80%;
    max-width: 600px;
    position: relative;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}
.modal-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 1.8em;
    cursor: pointer;
    color: #888;
}
.modal-content h2 {
    margin-top: 0;
}
#export-textarea, #import-textarea {
    width: 100%;
    min-height: 300px;
    margin-bottom: 10px;
    box-sizing: border-box;
}
.search-form {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}
.search-form input {
    flex-grow: 1;
    padding: 8px;
}
#chord-search-results {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    max-height: 40vh;
    overflow-y: auto;
    border-top: 1px solid #eee;
    margin-top: 20px;
    padding: 10px; 
}
.search-result-item {
    text-align: center;
    cursor: pointer;
}
.search-result-item .chord-placeholder:hover {
    border-color: #007bff;
}

.chord-wrapper {
	display: inline-block;
	text-align: center;
    vertical-align: top;
}

.chord-wrapper span {
	font-size: 10px;
	display: block;
}
#add-new-chord-btn {
    width: 100%;
    height: 100%;
    font-size: 3em;
    color: #ccc;
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1;
    border: 2px dashed #ccc;
    box-sizing: border-box;
    cursor: pointer;
    border-radius: 4px;
    transition: color 0.2s, border-color 0.2s;
}
#add-new-chord-btn:hover {
    color: #aaa;
    border-color: #aaa;
}

/* Print mode styling for data-print="true" attribute (WYSIWYG) */
body[data-print="true"] #delete-mode-toggle,
body[data-print="true"] #beat-mode-toggle,
body[data-print="true"] #toggle-ai-chat-btn,
body[data-print="true"] .chord-mode-toggles,
body[data-print="true"] .side-panel,
body[data-print="true"] #toggle-panel-btn {
    display: none !important;
}

body[data-print="true"] .fixed-header {
    border-bottom: none !important;
    box-shadow: none !important;
}

@media print {

    .page, .page-break, div[style*="break-after"] {
        break-after: page !important;
        page-break-after: always !important;
    }
    body, html {
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        position: static !important;
    }
    .main-content, .song-section, .lyrics-editor, .lyrics-editor-content, .container {
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        position: static !important;
        box-sizing: border-box !important;
    }
    /* Hide UI elements not needed for print */
    .sidebar, .toolbar, .header, .footer, .modal-overlay, .modal-content,
    #delete-mode-toggle, #beat-mode-toggle, #toggle-ai-chat-btn, .chord-mode-toggles {
        display: none !important;
    }
    /* Ensure all content is visible and not clipped */
    * {
        box-sizing: border-box !important;
    }
}

