/* ══════════════════════════════════════════════════════════════
   TONICSOLFA — Interface style logiciel de bureau
   ══════════════════════════════════════════════════════════════ */

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    background-color: #1e1e1e;
    color: #d4d4d4;
    overflow: hidden;
}

/* ══ Header / Barre de menu ══════════════════════════════════ */
#app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    background: linear-gradient(180deg, #3c3c3c 0%, #2d2d2d 100%);
    border-bottom: 1px solid #1a1a1a;
    padding: 0 16px;
    user-select: none;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* ══ Menu déroulant ══════════════════════════════════════════ */
.menu-bar {
    display: flex;
    align-items: center;
}

.menu-item {
    position: relative;
}

.menu-button {
    background: transparent;
    border: none;
    color: #cccccc;
    padding: 8px 12px;
    font-size: 0.9em;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.15s;
}

.menu-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.menu-item:focus-within .menu-button,
.menu-item.open .menu-button {
    background-color: rgba(255, 255, 255, 0.15);
}

.menu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 220px;
    background-color: #2d2d2d;
    border: 1px solid #404040;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    padding: 4px 0;
}

.menu-item:focus-within .menu-dropdown,
.menu-item.open .menu-dropdown {
    display: block;
}

.menu-dropdown button {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 8px 16px;
    background: transparent;
    border: none;
    color: #cccccc;
    font-size: 0.9em;
    cursor: pointer;
    text-align: left;
    gap: 10px;
}

.menu-dropdown button:hover {
    background-color: #094771;
    color: #ffffff;
}

.menu-dropdown button i {
    width: 16px;
    text-align: center;
    color: #888;
}

.menu-dropdown button:hover i {
    color: #ffffff;
}

.menu-dropdown .shortcut {
    margin-left: auto;
    font-size: 0.85em;
    color: #888;
}

.menu-dropdown button:hover .shortcut {
    color: #bbbbbb;
}

.menu-separator {
    height: 1px;
    background-color: #404040;
    margin: 4px 8px;
}

.app-title {
    font-size: 1.1em;
    font-weight: 600;
    color: #ffffff;
    letter-spacing: 0.5px;
}

.app-title i {
    color: #4fc3f7;
    margin-right: 8px;
}

.header-center {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-right {
    min-width: 100px;
}

/* ══ Contrôles de transport ══════════════════════════════════ */
.transport-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-right: 20px;
}

.transport-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 1em;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background-color: #3c3c3c;
    color: #cccccc;
    transition: all 0.15s ease;
}

.transport-btn:hover {
    background-color: #505050;
}

.transport-btn--play {
    width: 44px;
    height: 44px;
    font-size: 1.1em;
    background: linear-gradient(180deg, #4caf50 0%, #388e3c 100%);
    color: #ffffff;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.transport-btn--play:hover {
    background: linear-gradient(180deg, #66bb6a 0%, #43a047 100%);
    transform: scale(1.05);
}

.transport-btn--play.playing {
    background: linear-gradient(180deg, #ff9800 0%, #f57c00 100%);
}

.transport-btn--play.playing:hover {
    background: linear-gradient(180deg, #ffb74d 0%, #fb8c00 100%);
}

/* ══ Groupes de contrôle (tempo, latence) ════════════════════ */
.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    border-left: 1px solid #4a4a4a;
}

.control-group label {
    font-size: 0.8em;
    color: #999;
    white-space: nowrap;
}

.control-group input[type="range"] {
    width: 80px;
    height: 4px;
    cursor: pointer;
    accent-color: #4fc3f7;
    background: #555;
    border-radius: 2px;
}

.control-group span:not(.unit) {
    font-size: 0.9em;
    font-weight: 600;
    color: #ffffff;
    min-width: 32px;
    text-align: right;
}

.control-group .unit {
    font-size: 0.75em;
    color: #888;
}

.control-group select {
    background-color: #3c3c3c;
    border: 1px solid #555;
    border-radius: 4px;
    color: #ffffff;
    padding: 4px 8px;
    font-size: 0.85em;
    cursor: pointer;
    outline: none;
}

.control-group select:hover {
    border-color: #4fc3f7;
}

.control-group select:focus {
    border-color: #4fc3f7;
    box-shadow: 0 0 0 2px rgba(79, 195, 247, 0.2);
}

/* ══ Switch mode lecture/édition ═════════════════════════════ */
.mode-switch {
    gap: 2px !important;
    padding-left: 20px !important;
}

.mode-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 30px;
    padding: 0;
    border: 1px solid #404040;
    background-color: #3c3c3c;
    color: #888;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.15s;
}

.mode-btn:first-child {
    border-radius: 4px 0 0 4px;
}

.mode-btn:last-child {
    border-radius: 0 4px 4px 0;
}

.mode-btn:hover {
    background-color: #505050;
    color: #ccc;
}

.mode-btn.active {
    background-color: #0e639c;
    border-color: #1177bb;
    color: #ffffff;
}

/* ══ Mode lecture : masquer la toolbar d'édition ═════════════ */
body.mode-lecture #editor-toolbar {
    display: none;
}

body.mode-lecture #table-container td {
    cursor: default;
}

/* Masquer les sélections en mode lecture */
body.mode-lecture #table-container td.selected {
    background-color: transparent !important;
    outline: none !important;
}

/* Masquer le / de retour à la ligne en mode lecture */
body.mode-lecture #table-container .line-break-char {
    display: none;
}

/* Masquer le tempo en mode lecture */
body.mode-lecture #meta-tempo {
    display: none;
}

/* ══ Container principal ═════════════════════════════════════ */
#main-container {
    display: flex;
    height: calc(100vh - 48px);
    overflow: hidden;
}

/* ══ Sidebar (liste des morceaux) ════════════════════════════ */
#sidebar {
    width: 250px;
    min-width: 150px;
    max-width: 500px;
    background-color: #252526;
    border-right: 1px solid #1a1a1a;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 12px 16px;
    font-size: 0.8em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #888;
    background-color: #2d2d2d;
    border-bottom: 1px solid #1a1a1a;
    user-select: none;
}

.sidebar-header i {
    margin-right: 8px;
    color: #4fc3f7;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

#piece-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

#piece-list li {
    padding: 10px 16px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: all 0.15s ease;
    font-size: 0.95em;
    display: flex;
    align-items: center;
    gap: 10px;
}

#piece-list li:hover {
    background-color: #2a2d2e;
}

#piece-list li.active {
    background-color: #37373d;
    border-left-color: #4fc3f7;
    color: #ffffff;
}

#piece-list li::before {
    content: '\f001';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    color: #666;
    font-size: 0.85em;
}

#piece-list li.active::before {
    color: #4fc3f7;
}

/* ══ Splitter ════════════════════════════════════════════════ */
#splitter {
    width: 4px;
    background-color: #1a1a1a;
    cursor: col-resize;
    transition: background-color 0.15s;
}

#splitter:hover,
#splitter.dragging {
    background-color: #4fc3f7;
}

/* ══ Panneau principal ═══════════════════════════════════════ */
#main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: #1e1e1e;
}

/* ══ Barre d'outils éditeur ══════════════════════════════════ */
#editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    padding: 8px 12px;
    min-height: 44px;
    background-color: #2d2d2d;
    border-bottom: 1px solid #1a1a1a;
}

.toolbar-btn {
    position: relative;
    width: 34px;
    height: 30px;
    padding: 0;
    border: 1px solid #404040;
    border-radius: 3px;
    background-color: #3c3c3c;
    cursor: pointer;
    color: #cccccc;
    font-size: 0.9em;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toolbar-btn:hover {
    background-color: #505050;
    border-color: #606060;
}

.toolbar-btn--active {
    background-color: #0e639c !important;
    color: #ffffff !important;
    border-color: #1177bb !important;
}

.toolbar-btn--active:hover {
    background-color: #1177bb !important;
}

.toolbar-btn--disabled,
.toolbar-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.toolbar-btn--disabled:hover,
.toolbar-btn:disabled:hover {
    background-color: #3c3c3c;
    border-color: #404040;
}

.icon-badge {
    font-size: 0.55em;
    margin-left: 1px;
    align-self: flex-start;
    margin-top: 2px;
}

.toolbar-separator {
    width: 1px;
    height: 22px;
    background-color: #404040;
    margin: 0 6px;
}

.toolbar-btn--save {
    color: #89d185;
    border-color: #4a6a48;
}

.toolbar-btn--save:hover {
    background-color: #3a4a38;
}

.toolbar-btn--saved {
    background-color: #4caf50 !important;
    color: #ffffff !important;
    border-color: #388e3c !important;
}

/* Tooltips */
.toolbar-btn::after {
    content: attr(aria-label);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background-color: #252526;
    color: #cccccc;
    font-size: 0.75em;
    white-space: nowrap;
    padding: 4px 10px;
    border-radius: 3px;
    border: 1px solid #404040;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    font-family: sans-serif;
    font-weight: normal;
    z-index: 1000;
}

.toolbar-btn:hover::after {
    opacity: 1;
}

/* ══ Titre de la partition ═══════════════════════════════════ */
#partition-header {
    padding: 20px 40px 16px;
    background-color: #fffef8;
    border-bottom: none;
    text-align: center;
}

#partition-title {
    margin: 0;
    font-family: 'Quicksand', Helvetica, Arial, sans-serif;
    font-size: 2em;
    font-weight: 700;
    color: #1a1a1a;
    letter-spacing: 0.05em;
    outline: none;
    min-height: 1.2em;
}

#partition-title:empty::before {
    content: 'Sans titre';
    color: #aaa;
}

#partition-title[contenteditable="true"]:focus {
    background-color: rgba(0, 123, 255, 0.05);
    border-radius: 4px;
}

#partition-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-family: 'Quicksand', Helvetica, Arial, sans-serif;
    font-size: 1em;
    color: #555;
}

#meta-composer {
    text-align: right;
    outline: none;
    min-width: 50px;
    order: 1;
}

#meta-composer:empty::before {
    content: 'Compositeur';
    color: #bbb;
}

#meta-composer[contenteditable="true"]:focus {
    background-color: rgba(0, 123, 255, 0.05);
    border-radius: 4px;
}

#meta-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}

#meta-key, #meta-time, #meta-tempo {
    text-align: left;
    outline: none;
    min-width: 30px;
}

#meta-key::before {
    content: 'Clé: ';
    color: #888;
}

#meta-key:empty::before {
    content: 'Clé';
    color: #bbb;
}

#meta-time::before {
    content: 'Mesure: ';
    color: #888;
}

#meta-time:empty::before {
    content: 'Mesure';
    color: #bbb;
}

#meta-tempo::before {
    content: 'Tempo: ';
    color: #888;
}

#meta-tempo:empty::before {
    content: 'Tempo';
    color: #bbb;
}

#meta-tempo::after {
    content: ' BPM';
    color: #888;
}

#meta-tempo:empty::after {
    content: '';
}

#meta-key[contenteditable="true"]:focus,
#meta-time[contenteditable="true"]:focus,
#meta-tempo[contenteditable="true"]:focus {
    background-color: rgba(0, 123, 255, 0.05);
    border-radius: 4px;
}

/* ══ Container de la partition (tableaux) ════════════════════ */
#table-container {
    flex: 1;
    overflow: auto;
    padding: 32px 40px;
    background-color: #fffef8;
}

#table-container table {
    border-collapse: collapse;
    table-layout: fixed;
    width: 100%;
    font-family: 'Quicksand', Helvetica, Arial, sans-serif;
    font-size: 1.15em;
    line-height: 1.8;
    margin-bottom: 24px;
    color: #1a1a1a;
}

#table-container td {
    position: relative;
    text-align: center;
    white-space: nowrap;
    cursor: pointer;
    padding: 2px 16px;
    box-sizing: border-box;
    letter-spacing: 0.03em;
    font-weight: 400;
    line-height: 1.2;
}

/* ── Séparateur : à gauche de chaque cellule (sauf 1ère) ── */
#table-container td + td::before {
    content: ':';
    color: #888;
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    text-align: center;
}

/* ── : à gauche de la 1ère cellule (début de table) ── */
#table-container td:first-child::before {
    content: ':';
    color: #888;
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    text-align: center;
}

/* ── : à droite de la dernière cellule (fin de table) ── */
#table-container td:last-child::after {
    content: ':';
    color: #888;
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    text-align: center;
}

/* ── Pas de : à gauche si début de mesure manuel (remplacé par barre) ── */
#table-container td.mesure-col::before {
    content: none !important;
}

/* ── Barre de mesure (début) — 1ère colonne : bordure gauche ── */
#table-container td.mesure-col-self {
    border-left: 2px solid #1a1a1a !important;
}
#table-container td.mesure-col-self::before {
    content: none !important;
}

/* ── Barre de mesure (début) — autres colonnes : bordure gauche ── */
#table-container td.mesure-col {
    border-left: 2px solid #1a1a1a !important;
}

/* ── Pas de ::after sur la cellule précédente (on utilise border maintenant) ── */
#table-container td.mesure-col-next::after {
    content: none !important;
}

/* ── Barre de mesure (fin) — bordure droite ── */
#table-container td.mesure-fin-col {
    border-right: 2px solid #1a1a1a !important;
}
#table-container td.mesure-fin-col::after {
    content: none !important;
}

/* ── Demi-barre de mesure (gauche) — segment | à gauche de chaque cellule ── */
#table-container td.demi-mesure-gauche::before {
    content: '|' !important;
    font-weight: bold;
    color: #1a1a1a;
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    text-align: center;
}

/* ── Demi-barre de mesure (droite) — segment | à droite de chaque cellule ── */
#table-container td.demi-mesure-droite::after {
    content: '|' !important;
    font-weight: bold;
    color: #1a1a1a;
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    text-align: center;
}

/* ── Ligne de paroles (non jouée) ── */
#table-container tr.paroles-row td {
    font-style: normal;
    color: #333;
    font-size: 0.9em;
    letter-spacing: 0.01em;
    border-left: none !important;
    border-right: none !important;
}

/* Masquer les : et | pour les lignes de paroles */
#table-container tr.paroles-row td::before,
#table-container tr.paroles-row td::after {
    content: none !important;
}

/* ── Marque d'octave (traits obliques en indice) ── */
#table-container .octave-mark {
    font-size: 0.5em;
    letter-spacing: -0.15em;
}

/* ── Sélection multiple de cellules ── */
#table-container td.selected {
    background-color: rgba(0, 123, 255, 0.2) !important;
    outline: 2px solid #007bff;
    outline-offset: -2px;
}

/* ── Mélisme (soulignement continu pour syllabe prolongée) ── */
#table-container td.melisme {
    position: relative;
}

/* Utiliser un span enfant pour le trait (évite conflit avec ::after du séparateur) */
#table-container td.melisme .melisme-line {
    position: absolute;
    bottom: 0.15em;
    left: 0;
    right: 0;
    height: 1px;
    background-color: #555;
    pointer-events: none;
}

/* Étendre le trait à gauche pour les cellules qui ne sont pas le début du mélisme */
#table-container td.melisme:not(.melisme-start) .melisme-line {
    left: -8px;
}

/* Étendre le trait à droite pour les cellules qui ne sont pas la fin du mélisme */
#table-container td.melisme:not(.melisme-end) .melisme-line {
    right: -8px;
}

/* ── Ligne voix masculine ── */
#table-container tr.voix-masculine td {
    background-color: #e8f0ff;
}

/* ── Colonne en cours de lecture ── */
#table-container td.playing-col {
    background-color: #ffe066 !important;
    transition: background-color 0.1s ease-in;
}

#table-container tr.voix-masculine td.playing-col {
    background-color: #ffd633 !important;
}

/* ══ Scrollbar personnalisée ═════════════════════════════════ */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #1e1e1e;
}

::-webkit-scrollbar-thumb {
    background: #424242;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555555;
}

.sidebar-content::-webkit-scrollbar-track {
    background: #252526;
}

#table-container::-webkit-scrollbar-track {
    background: #fffef8;
}

#table-container::-webkit-scrollbar-thumb {
    background: #d0cfc8;
}

#table-container::-webkit-scrollbar-thumb:hover {
    background: #b0afa8;
}

/* ══ Message d'accueil ═══════════════════════════════════════ */
#welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #888;
    text-align: center;
}

#welcome-message i.fa-folder-open {
    font-size: 4em;
    margin-bottom: 20px;
    color: #ccc;
}

#welcome-message p {
    font-size: 1.2em;
    margin: 8px 0;
}

#welcome-message .hint {
    font-size: 0.9em;
    color: #aaa;
    margin-top: 16px;
}

#welcome-message .hint i {
    color: #888;
}

/* ══ Indices pour les octaves ════════════════════════════════ */
#table-container td sub.octave-mark {
    font-size: 0.65em;
    font-family: 'Helvetica Neue', 'Arial Narrow', sans-serif;
    font-weight: 300;
    font-stretch: condensed;
    vertical-align: baseline;
    position: relative;
    top: 0.3em;
    letter-spacing: -0.05em;
}

/* ══ Séparateurs style partition traditionnelle ══════════════ */
#table-container td + td::before,
#table-container td:first-child::before {
    color: #555;
    font-style: normal;
    font-weight: normal;
}

#table-container td:last-child::after {
    color: #555;
    font-style: normal;
}

/* ══ Section des paroles (après les tables) ══════════════════ */
#lyrics-section {
    background-color: #fffef8;
    border-top: 1px solid #ddd;
}

/* La visibilité est gérée par JavaScript via style.display */

#lyrics-header {
    padding: 8px 40px;
    border-bottom: 1px solid #eee;
}

.lyrics-toggle-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    color: #555;
    font-family: 'Quicksand', Helvetica, Arial, sans-serif;
    font-size: 0.9em;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.15s;
}

.lyrics-toggle-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.lyrics-toggle-btn i {
    transition: transform 0.2s;
    font-size: 0.8em;
}

#lyrics-section.collapsed .lyrics-toggle-btn i {
    transform: rotate(-90deg);
}

#lyrics-container {
    padding: 24px 40px 32px;
    font-family: 'Quicksand', Helvetica, Arial, sans-serif;
    font-size: 1em;
    line-height: 1.6;
    color: #333;
    column-count: 2;
    column-gap: 60px;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.2s ease;
}

#lyrics-section.collapsed #lyrics-container {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
}

#lyrics-container:empty {
    display: none;
}

#lyrics-container .lyrics-verse {
    break-inside: avoid;
    margin-bottom: 1.5em;
}

#lyrics-container .verse-number {
    font-weight: 600;
    color: #1a1a1a;
}

#lyrics-container .lyrics-line {
    margin: 0;
    padding-left: 1em;
    text-indent: -1em;
}

/* ══ En-tête d'accords ══════════════════════════════════════ */
thead.chord-header tr.chord-row td {
    text-align: left;
    font-weight: 600;
    font-size: 0.85em;
    color: #666;
    padding: 2px 8px !important;
    border: none !important;
    height: auto !important;
    min-height: unset !important;
    background: transparent !important;
}

/* Pas de : ni barres de mesure dans le thead */
thead.chord-header td::before,
thead.chord-header td::after {
    content: none !important;
    display: none !important;
}

thead.chord-header td {
    border-left: none !important;
    border-right: none !important;
}

/* Accords cliquables */
thead.chord-header td.chord-cell {
    cursor: pointer;
}

thead.chord-header td.chord-cell:hover {
    color: #1a56db;
}

/* Masquer les accords */
body.hide-chords thead.chord-header {
    display: none;
}
