/* ===================== RESET & BASE ===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ffffff;
  --sidebar-bg: #f7f6f3;
  --sidebar-border: #e9e8e4;
  --hover: #efede9;
  --selected: #e3e1dc;
  --text: #37352f;
  --text-muted: #9b9a97;
  --text-black: #1a1a1a;
  --accent: #4f46e5;
  --danger: #ef4444;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'Courier New', Courier, monospace;
  --radius: 6px;
  --controls-h: 52px;
}

html, body { height: 100%; font-family: var(--font-ui); color: var(--text); background: var(--bg); font-size: 14px; }
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: 13px; color: var(--text); }
input, textarea, select { font-family: var(--font-ui); color: var(--text); font-size: 14px; }
ul { list-style: none; }

/* ===================== DESKTOP LAYOUT ===================== */
#app { display: flex; height: 100vh; overflow: hidden; }
#mobileApp { display: none; }

/* ===================== RESIZE HANDLES ===================== */
.resize-handle {
  width: 4px; flex-shrink: 0;
  background: transparent; cursor: col-resize;
  transition: background 0.15s; position: relative; z-index: 10;
}
.resize-handle:hover, .resize-handle.dragging { background: var(--accent); }

/* ===================== SIDEBARS ===================== */
.sidebar {
  display: flex; flex-direction: column; height: 100%;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  flex-shrink: 0; overflow: hidden;
}
.sidebar-artists { width: 220px; }
.sidebar-songs   { width: 230px; }

.sidebar-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px; height: 48px; flex-shrink: 0;
}

.sidebar-title {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}

.btn-add {
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; font-size: 18px; color: var(--text-muted);
  transition: background 0.1s, color 0.1s; flex-shrink: 0;
}
.btn-add:hover { background: var(--selected); color: var(--text); }

.sidebar-footer {
  padding: 8px 10px 12px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0; display: flex; flex-direction: column; gap: 2px;
}

.btn-footer-action, .btn-settings {
  width: 100%; text-align: left;
  padding: 6px 10px; border-radius: var(--radius);
  font-size: 12px; color: var(--text-muted);
  transition: background 0.1s, color 0.1s;
}
.btn-footer-action:hover, .btn-settings:hover { background: var(--hover); color: var(--text); }
.btn-footer-action.syncing { color: var(--accent); }
.btn-footer-action.done    { color: #16a34a; }

/* ===================== SEARCH ===================== */
.search-wrap { padding: 0 10px 6px; flex-shrink: 0; }

.search-input {
  width: 100%;
  background: rgba(0,0,0,0.04); border: 1px solid transparent;
  border-radius: var(--radius); padding: 6px 10px; font-size: 13px;
  outline: none; transition: border-color 0.15s, background 0.15s;
}
.search-input:focus { background: var(--bg); border-color: var(--sidebar-border); }

/* ===================== TAG FILTER ===================== */
.tag-filter-row {
  padding: 0 10px 8px; flex-shrink: 0;
}
.tag-filter-row:empty { display: none; }

.tag-select {
  width: 100%;
  border: 1px solid var(--sidebar-border); border-radius: var(--radius);
  padding: 5px 8px; font-size: 12px;
  background: var(--bg); color: var(--text);
  font-family: var(--font-ui); outline: none; cursor: pointer;
  transition: border-color 0.15s;
}
.tag-select:focus { border-color: var(--accent); }
.tag-select.has-value { color: var(--text-black); border-color: var(--accent); }

/* ===================== ITEM LIST ===================== */
.item-list { overflow-y: auto; flex: 1; padding: 2px 6px 8px; }

.item-list li {
  padding: 6px 10px;
  border-radius: 5px; cursor: pointer;
  font-size: 13.5px; font-weight: 400; color: var(--text);
  transition: background 0.1s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  user-select: none; line-height: 1.5;
}
.item-list li:hover { background: var(--hover); }
.item-list li.active {
  background: var(--selected);
  color: var(--text-black);
}

/* "Tous" separator line */
.item-list li.item-tous {
  font-size: 13px; color: var(--text-muted);
  border-bottom: 1px solid var(--sidebar-border);
  border-radius: 5px 5px 0 0; margin-bottom: 4px;
}
.item-list li.item-tous.active { color: var(--text-black); }

.item-count { font-size: 11px; color: var(--text-muted); margin-left: 4px; }

/* Alphabetical section headers in song list */
.list-letter-head {
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-muted);
  padding: 8px 10px 2px; cursor: default;
  pointer-events: none; border-radius: 0;
  background: transparent !important;
}

/* Song list with artist subtitle (when Tous selected) */
.song-item-artist {
  display: block; font-size: 11px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 1px;
}

/* ===================== MAIN TAB AREA ===================== */
.tab-main {
  flex: 1; display: flex; flex-direction: column;
  height: 100%; overflow: hidden; position: relative; min-width: 0;
}

.tab-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 15px;
}

.tab-viewer { display: none; flex-direction: column; height: 100%; overflow: hidden; }
.tab-viewer.visible { display: flex; }

/* ===================== CONTROLS BAR ===================== */
.tab-controls {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 20px; min-height: var(--controls-h);
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0; gap: 12px; background: var(--bg);
}

.tab-meta {
  display: flex; align-items: center; gap: 6px;
  min-width: 0; flex-wrap: wrap; flex: 1;
}

.meta-title { font-size: 15px; font-weight: 600; white-space: nowrap; }
.meta-artist { font-size: 13px; color: var(--text-muted); white-space: nowrap; }

.meta-badge {
  font-size: 11px; color: var(--text-muted);
  background: var(--sidebar-bg); border: 1px solid var(--sidebar-border);
  padding: 2px 7px; border-radius: 20px; white-space: nowrap;
}
.meta-badge:empty { display: none; }

.meta-custom-badge {
  font-size: 11px; color: var(--text-muted);
  background: var(--sidebar-bg); border: 1px solid var(--sidebar-border);
  padding: 2px 7px; border-radius: 20px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 4px;
}
.meta-stars { color: #f59e0b; letter-spacing: -1px; }

/* Tags in meta bar */
.meta-tag {
  font-size: 11px; color: var(--accent);
  background: #eef2ff; border: 1px solid #c7d2fe;
  padding: 2px 7px; border-radius: 20px; white-space: nowrap;
}

.controls-right {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}

.ctrl-group {
  display: flex; align-items: center; gap: 4px;
  background: var(--sidebar-bg); border: 1px solid var(--sidebar-border);
  border-radius: var(--radius); padding: 3px 6px;
}

.ctrl-btn {
  height: 26px; min-width: 26px; padding: 0 6px; border-radius: 4px;
  font-size: 13px; display: flex; align-items: center; justify-content: center;
  transition: background 0.1s;
}
.ctrl-btn:hover { background: var(--selected); }
.ctrl-btn--primary { background: var(--accent); color: white; font-size: 11px; }
.ctrl-btn--primary:hover { background: #4338ca; }
.ctrl-btn--primary.active { background: #dc2626; }
.ctrl-btn--primary.active:hover { background: #b91c1c; }
.ctrl-btn--wide { padding: 0 10px; }
.ctrl-btn--muted { color: var(--text-muted); }
.ctrl-btn--muted:hover { color: var(--danger); background: #fef2f2; }

.ctrl-label {
  font-size: 12px; color: var(--text-muted);
  min-width: 48px; text-align: center;
}

/* ===================== TAB BODY ===================== */
.tab-body {
  flex: 1; overflow-y: auto; padding: 28px 40px 60px; scroll-behavior: smooth;
}

/* ===================== TAB CONTENT RENDERING ===================== */
.chord-sheet { font-size: 14px; line-height: 1; }

.section-block { margin-bottom: 20px; }
.section-block:last-child { margin-bottom: 0; }

.section-label {
  font-family: var(--font-ui); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); margin-bottom: 10px;
}

.chord-lyric-pair { margin-bottom: 2px; }

.chord-row { white-space: pre; min-height: 1.5em; line-height: 1.5em; color: var(--text-black); }
.lyric-row { white-space: pre; line-height: 1.7em; margin-bottom: 4px; color: var(--text-black); }
.lyric-only { white-space: pre; line-height: 1.7em; margin-bottom: 2px; color: var(--text-black); }

.chord-inline { font-weight: 800; color: var(--text-black); cursor: pointer; display: inline; }
.chord-inline:hover { text-decoration: underline; }

.paragraph-break { height: 16px; }

/* ---- Inline chord-lyric segments (sans-serif rendering) ---- */
/* Each segment groups a chord with the lyric syllables beneath it */
.cl-pair {
  display: inline-flex;
  flex-wrap: wrap;
  line-height: 1;
  margin-bottom: 4px;
}

.cl-seg {
  display: inline-flex;
  flex-direction: column;
}

/* Chord slot: always reserves vertical space even when empty */
.cl-c {
  display: block;
  min-height: 1.4em;
  line-height: 1.4em;
  padding-right: 6px;   /* visual gap between chord and next chord */
}

/* Lyric slice beneath each chord */
.cl-l {
  display: block;
  line-height: 1.7em;
  white-space: pre;
  color: var(--text-black);
}

/* Chord-only line (no lyrics): flex row with fixed gap */
.cl-chord-only {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
  min-height: 1.4em;
  line-height: 1.4em;
  margin-bottom: 4px;
}

/* ===================== FULLSCREEN ===================== */
body.fullscreen #app .sidebar { display: none; }
body.fullscreen #app .resize-handle { display: none; }
body.fullscreen .tab-controls { padding: 0 32px; }
body.fullscreen #btnFullscreen { background: var(--selected); }

/* Fullscreen tab body: scrollable, no padding (padding goes on columns) */
body.fullscreen .tab-body { padding: 0; overflow-y: auto; }

/* Continuous multi-column layout */
.fs-continuous {
  display: flex;
  align-items: flex-start;
  min-height: 100%;
}

.fs-col {
  flex: 1;
  padding: 28px 36px 60px;
  min-width: 0;
}

/* Section separator within fullscreen columns */
body.fullscreen .section-block {
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--sidebar-border);
}
body.fullscreen .section-block:last-child {
  border-bottom: none; padding-bottom: 0; margin-bottom: 0;
}

/* ===================== CHORD TOOLTIP ===================== */
.chord-tooltip {
  position: fixed; z-index: 1000;
  background: var(--bg); border: 1px solid var(--sidebar-border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 8px 10px 10px; pointer-events: none; display: none;
}
.chord-tooltip.visible { display: block; }

.tooltip-name {
  font-size: 13px; font-weight: 700; color: var(--text-black);
  margin-bottom: 8px; text-align: center;
}

/* ===================== MODALS ===================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35);
  z-index: 500; display: none; align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg); border-radius: 10px;
  width: 600px; max-width: 95vw; max-height: 92vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal--settings { width: 520px; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 14px; border-bottom: 1px solid var(--sidebar-border); flex-shrink: 0;
}
.modal-header h2 { font-size: 16px; font-weight: 600; }

.modal-close {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; font-size: 16px; color: var(--text-muted);
}
.modal-close:hover { background: var(--hover); color: var(--text); }

.modal-body {
  padding: 18px 22px; overflow-y: auto; flex: 1;
  display: flex; flex-direction: column; gap: 14px;
}

.modal-footer {
  padding: 14px 22px; border-top: 1px solid var(--sidebar-border);
  display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0;
}

/* ===================== FORM ===================== */
.form-row { display: flex; gap: 14px; }
.form-row .form-group { flex: 1; }
.form-row--small .form-group { flex: 0 0 auto; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.label-hint { font-weight: 400; }

.form-group input,
.form-group textarea,
.form-group select {
  border: 1px solid var(--sidebar-border); border-radius: var(--radius);
  padding: 7px 10px; outline: none; background: var(--bg);
  transition: border-color 0.15s; resize: vertical;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus { border-color: var(--accent); }
.form-group textarea { font-family: var(--font-mono); font-size: 13px; }
.form-group input[type="number"] { width: 80px; }

.btn-primary {
  background: var(--accent); color: white; border-radius: var(--radius);
  padding: 8px 18px; font-size: 14px; font-weight: 500; transition: background 0.15s;
}
.btn-primary:hover { background: #4338ca; }

.btn-secondary {
  background: var(--sidebar-bg); color: var(--text);
  border: 1px solid var(--sidebar-border); border-radius: var(--radius);
  padding: 8px 18px; font-size: 14px; transition: background 0.15s;
}
.btn-secondary:hover { background: var(--selected); }

/* ===================== STAR RATING ===================== */
.star-rating { display: flex; gap: 4px; }
.star-rating .star {
  font-size: 22px; cursor: pointer; color: #d1d5db;
  transition: color 0.1s, transform 0.1s; line-height: 1; user-select: none;
}
.star-rating .star.filled { color: #f59e0b; }
.star-rating .star:hover { transform: scale(1.15); }

/* ===================== RANGE INPUT ===================== */
.range-input {
  width: 100%; accent-color: var(--accent); height: 4px;
  margin-top: 4px; cursor: pointer;
  border: none !important; padding: 0 !important; background: transparent !important;
}

/* ===================== SETTINGS ===================== */
.settings-section {
  border: 1px solid var(--sidebar-border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.settings-section-title {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted);
}
.settings-hint { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

.field-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-bottom: 1px solid var(--sidebar-border);
}
.field-row:last-child { border-bottom: none; }
.field-row input[type="text"] {
  flex: 1; border: 1px solid var(--sidebar-border);
  border-radius: var(--radius); padding: 5px 8px; font-size: 13px; outline: none;
}
.field-row input[type="text"]:focus { border-color: var(--accent); }
.field-row select {
  border: 1px solid var(--sidebar-border); border-radius: var(--radius);
  padding: 5px 8px; font-size: 13px; background: var(--bg); outline: none;
}
.btn-remove-field {
  width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  border-radius: 4px; font-size: 14px; color: var(--text-muted); flex-shrink: 0;
}
.btn-remove-field:hover { background: #fef2f2; color: var(--danger); }
.btn-add-field { font-size: 13px; color: var(--accent); padding: 6px 0; text-align: left; }
.btn-add-field:hover { text-decoration: underline; }

/* ===================== TAG MANAGEMENT (settings) ===================== */
.tag-manage-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 0; border-bottom: 1px solid var(--sidebar-border);
}
.tag-manage-row:last-of-type { border-bottom: none; }

.tag-manage-name {
  flex: 1; font-size: 13px; font-weight: 500; color: var(--text);
}
.tag-manage-count {
  font-size: 12px; color: var(--text-muted); flex-shrink: 0;
}
.tag-manage-del {
  font-size: 11px; color: var(--danger);
  border: 1px solid var(--danger); border-radius: 4px;
  padding: 2px 8px; flex-shrink: 0; transition: background 0.1s;
}
.tag-manage-del:hover { background: #fef2f2; }
.tag-manage-expand {
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px; font-size: 12px; color: var(--text-muted);
  flex-shrink: 0; transition: background 0.1s;
}
.tag-manage-expand:hover { background: var(--hover); color: var(--text); }

/* Song list inside an expanded tag */
.tag-song-list {
  margin: 2px 0 10px; border-radius: var(--radius);
  background: var(--sidebar-bg); overflow: hidden;
}
.tag-song-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; transition: background 0.1s;
}
.tag-song-item:hover { background: var(--hover); }
.tag-song-rm {
  width: 18px; height: 18px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 3px; font-size: 11px; color: var(--text-muted);
  transition: background 0.1s, color 0.1s;
}
.tag-song-rm:hover { background: #fef2f2; color: var(--danger); }
.tag-song-title { font-size: 13px; color: var(--text); flex: 1; }
.tag-song-artist { font-size: 11px; color: var(--text-muted); }

/* ===================== MOBILE ===================== */
@media (max-width: 767px) {
  #app { display: none; }
  #mobileApp { display: flex; flex-direction: column; height: 100vh; background: var(--bg); }

  .mob-header {
    display: flex; align-items: center; gap: 8px; padding: 12px 16px;
    border-bottom: 1px solid var(--sidebar-border);
    background: var(--sidebar-bg); flex-shrink: 0;
  }
  .mob-back { font-size: 22px; color: var(--accent); padding: 0 4px; line-height: 1; }
  .mob-title { flex: 1; font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mob-add { font-size: 22px; color: var(--accent); padding: 0 4px; }

  .mob-footer {
    display: flex; flex-shrink: 0;
    border-top: 1px solid var(--sidebar-border);
    background: var(--sidebar-bg);
  }
  .mob-footer-btn {
    flex: 1; padding: 14px 8px;
    font-size: 14px; color: var(--text-muted);
    text-align: center; line-height: 1;
    border-right: 1px solid var(--sidebar-border);
    transition: background 0.1s, color 0.1s;
  }
  .mob-footer-btn:last-child { border-right: none; }
  .mob-footer-btn:active { background: var(--hover); color: var(--text); }
  .mob-footer-btn.syncing { color: var(--accent); }
  .mob-footer-btn.done    { color: #16a34a; }

  .mob-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
  .mob-search-wrap { padding: 10px 12px 6px; }

  .mob-tab-view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

  .mob-tab-controls {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0; flex-wrap: wrap; background: var(--sidebar-bg);
    transition: all 0.2s;
  }

  .mob-tab-body { flex: 1; overflow-y: scroll; -webkit-overflow-scrolling: touch; padding: 16px 16px 40px; }
  .mob-tab-body .chord-sheet { font-size: 13px; }

  .item-list { padding: 4px 8px 20px; }
  .item-list li { font-size: 20px; padding: 9px 12px; line-height: 1.4; }
  .item-list li.item-tous { font-size: 18px; }
  .item-list li.list-letter-head { font-size: 13px; }
  .song-item-artist { font-size: 14px; }

  .modal {
    width: 100%; max-width: 100%; max-height: 100%;
    border-radius: 0; height: 100%;
  }
}

/* ===================== SCROLLBAR ===================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--sidebar-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #ccc; }
