/* Cancionero - Estilos responsive */

:root {
  --color-primary: #2c5f8d;
  --color-primary-dark: #1e4a6e;
  --color-bg: #f5f6f8;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-text-muted: #666;
  --color-border: #ddd;
  --color-mark: #fff3a3;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --font-size-base: 16px;
  --font-size-lyrics: 18px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: var(--font-size-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Cabecera */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow);
}

.header-content {
  max-width: 900px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-title {
  font-size: 1.4rem;
  font-weight: 600;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
}

.app-title:hover {
  opacity: 0.85;
}

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

.stats {
  font-size: 0.85rem;
  opacity: 0.9;
  background: rgba(255, 255, 255, 0.15);
  padding: 4px 10px;
  border-radius: 12px;
  white-space: nowrap;
}

/* Contenedor principal */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
}

/* Vistas */
.view {
  display: none;
}

.view.active {
  display: block;
}

/* Caja de búsqueda */
.search-box {
  position: relative;
  margin-bottom: 16px;
}

.search-box input {
  width: 100%;
  padding: 14px 44px 14px 16px;
  font-size: 1.05rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.2s;
}

.search-box input:focus {
  outline: none;
  border-color: var(--color-primary);
}

#btn-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
}

/* Botones */
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  padding: 6px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  min-width: 36px;
  min-height: 36px;
}

.btn-icon:hover {
  background: rgba(0, 0, 0, 0.08);
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
  width: 100%;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--color-primary-dark);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Resultados */
.results {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.result-item:hover {
  box-shadow: var(--shadow);
  border-color: var(--color-primary);
}

.result-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--color-primary-dark);
}

.result-snippet {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  line-height: 1.4;
  word-break: break-word;
}

mark {
  background: var(--color-mark);
  border-radius: 2px;
  padding: 0 2px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-muted);
}

.empty-state h3 {
  margin-bottom: 8px;
  color: var(--color-text);
}

/* Vista de canto */
.song-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--color-border);
}

.song-title {
  flex: 1;
  font-size: 1.4rem;
  color: var(--color-primary-dark);
  word-break: break-word;
}

.btn-back {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-primary);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
}

.btn-back:hover {
  background: rgba(44, 95, 141, 0.1);
}

.song-lyrics {
  font-family: inherit;
  font-size: var(--font-size-lyrics);
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--color-surface);
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  min-height: 50vh;
}

.song-lyrics.song-lyrics-with-chords {
  font-family: "SFMono-Regular", SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  line-height: 1.45;
}

.song-chords-line,
.song-verse-line {
  display: block;
  white-space: pre-wrap;
}

.song-chords-line {
  color: var(--color-primary);
  font-style: italic;
  font-weight: 600;
  min-height: 1.45em;
}

.song-verse-line {
  margin-bottom: 0.2em;
}

/* En modo acordes, cada línea de acordes se resalta en un recuadro celeste
   con esquinas redondeadas (igual que en el editor de acordes). */
.song-lyrics-with-chords .song-chords-line-filled {
  display: inline-block;
  background: #eef4ff;
  border-radius: 8px;
  padding: 2px 8px;
}

/* Compensa el padding horizontal del recuadro para que la letra siga
   alineada bajo los acordes. */
.song-lyrics-with-chords .song-verse-line {
  padding-left: 8px;
}

/* Pie del canto: icono para descargar ese canto en PDF */
.song-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

/* Pie de la vista de lista: icono para descargar la lista en PDF */
.list-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.list-footer .btn-icon:disabled {
  opacity: 0.4;
  cursor: default;
}

.list-footer .btn-icon:disabled:hover {
  background: none;
}

.btn-song-pdf {
  color: var(--color-primary);
}

.btn-song-pdf:hover {
  background: rgba(44, 95, 141, 0.1);
}

/* Reproductor del MP3 del canto */
.btn-song-audio {
  color: var(--color-primary);
}

.btn-song-audio:hover {
  background: rgba(44, 95, 141, 0.1);
}

.btn-song-audio.is-playing {
  background: rgba(44, 95, 141, 0.16);
}

/* Zona para subir el MP3 desde el modal de edición */
.audio-drop {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  background: #eef4ff;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.audio-drop:hover,
.audio-drop.is-over {
  border-color: var(--color-primary);
  background: #dbe9ff;
}

.audio-drop-main {
  margin: 0;
  font-size: 0.9rem;
  color: var(--color-text);
}

.audio-drop-link {
  color: var(--color-primary);
  text-decoration: underline;
}

.audio-drop-state {
  margin: 6px 0 0;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  white-space: pre-line; /* el estado y el fichero preparado van en dos líneas */
}

/* Botón para quitar el MP3 que ya tiene el canto */
.btn-audio-remove {
  margin-top: 8px;
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-audio-remove:hover {
  background: var(--color-primary);
  color: #fff;
}

.btn-toggle-chords {
  color: var(--color-primary);
}

.btn-toggle-chords.is-active {
  background: rgba(44, 95, 141, 0.14);
  color: var(--color-primary-dark);
}

.btn-transpose {
  color: var(--color-primary);
}

.btn-transpose:hover {
  background: rgba(44, 95, 141, 0.1);
}

.song-preview-empty {
  display: block;
  color: var(--color-text-muted);
  font-style: italic;
}

/* Nota / instrucción breve del canto (ej. "En tonalidad de SOL") */
.song-note {
  margin: -8px 0 14px;
  padding: 8px 14px;
  font-size: 0.95rem;
  font-style: italic;
  font-weight: 600;
  color: #7a5c00;
  background: #fff8e1;
  border: 1px dashed #e0c060;
  border-radius: 8px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--color-surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--color-border);
}

.modal-header h3 {
  font-size: 1.2rem;
}

.modal-body {
  padding: 16px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
}

.form-group input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.6;
  resize: vertical;
  white-space: pre-wrap;
}

.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* Modal de edición de canto */
.edit-hint {
  margin-bottom: 14px;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.edit-chords-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 6px;
}

.edit-chords-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.edit-chords-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.edit-chords-toolbar .btn-secondary {
  padding: 8px 12px;
  font-size: 0.9rem;
}

.edit-chord-grid {
  font-family: "SFMono-Regular", SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  background: #fbfcfe;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 12px;
  max-height: 52vh;
  overflow: auto;
}

.chord-editor-row {
  margin-bottom: 10px;
}

.chord-editor-hit {
  width: 100%;
  display: block;
  text-align: left;
  border: 1px dashed transparent;
  background: #eef4ff;
  border-radius: 8px;
  padding: 6px 10px;
  color: var(--color-primary);
  cursor: pointer;
  font-family: "SFMono-Regular", SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 1rem;
  line-height: 1.4;
}

.chord-editor-hit:hover,
.chord-editor-hit.is-active {
  border-color: var(--color-primary);
  background: #e4eefc;
}

.chord-editor-line,
.chord-editor-lyric {
  display: block;
  white-space: pre-wrap;
  word-break: break-word;
}

.chord-editor-lyric {
  padding: 4px 10px 0;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.55;
}

.chord-editor-caret {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  vertical-align: text-bottom;
  background: var(--color-primary-dark);
  margin-right: -2px;
}

.chord-editor-probe {
  position: absolute;
  visibility: hidden;
  pointer-events: none;
}

.edit-actions .btn-primary {
  width: auto;
}

/* Zona peligrosa del modal de edición: eliminar el canto */
.edit-danger {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
}

.load-result {
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  display: none;
}

.load-result.show {
  display: block;
}

.load-result.success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.load-result.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.load-result.loading {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
}

/* Gestión de la lista */
.modal-content-wide {
  max-width: 520px;
}

.list-section-title {
  margin: 18px 0 8px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.list-search-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.list-search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
}

.list-search-title {
  flex: 1;
  word-break: break-word;
}

.btn-add {
  color: var(--color-primary);
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1;
}

.btn-add.added {
  color: #2e7d32;
  cursor: default;
}

.list-search-empty,
.list-empty {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  padding: 8px 0;
}

.list-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Elemento de la lista (canto o texto): fila + campo de nota */
.list-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.list-item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
}

.list-item-note {
  width: 100%;
  padding: 6px 10px;
  font: inherit;
  font-size: 0.85rem;
  font-style: italic;
  color: #7a5c00;
  background: #fffdf5;
  border: 1px dashed #e0c060;
  border-radius: 8px;
}

/* Nota en modo lectura (se edita con el lápiz) */
.list-item-note-view {
  margin: 0;
  padding: 6px 10px;
  font-size: 0.85rem;
  font-style: italic;
  color: #7a5c00;
  background: #fffdf5;
  border: 1px dashed #e0c060;
  border-radius: 8px;
  word-break: break-word;
}

.btn-edit-note {
  color: var(--color-primary);
}

.list-item-note:focus {
  outline: none;
  border-style: solid;
  border-color: var(--color-primary);
}

.list-item-note::placeholder {
  color: #b9a468;
  font-style: italic;
}

.list-item-num {
  min-width: 24px;
  font-weight: 700;
  color: var(--color-primary);
  text-align: center;
}

.list-item-title {
  flex: 1;
  word-break: break-word;
}

.list-item-title.unavailable {
  color: var(--color-text-muted);
  text-decoration: line-through;
}

.btn-remove {
  color: #b00020;
  font-size: 1.2rem;
  font-weight: 700;
}

#btn-follow-list {
  margin-top: 18px;
}

/* Menú de utilidades y submenús */
.menu-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  margin-bottom: 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.menu-option:hover {
  border-color: var(--color-primary);
  background: #f0f5fa;
}

.menu-option-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--color-primary-dark);
}

.menu-option-desc {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.btn-back-text {
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 12px;
}

.btn-back-text:hover {
  text-decoration: underline;
}

/* Fila para añadir un texto a la lista */
.add-text-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.add-text-row input[type="text"] {
  flex: 1;
  min-width: 0;
}

.pos-input {
  width: 58px;
  flex-shrink: 0;
  text-align: center;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-secondary:hover {
  background: var(--color-primary);
  color: #fff;
}

/* Asa de arrastre */
.drag-handle {
  cursor: grab;
  color: var(--color-text-muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 4px 2px;
  touch-action: none; /* permite arrastrar con el dedo sin hacer scroll */
  user-select: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.list-item-row.dragging,
.list-item.dragging > .list-item-row {
  opacity: 0.6;
  border-color: var(--color-primary);
  background: #eef4ff;
}

/* Gestión de listas: selector y botones */
.list-manage-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
  flex-wrap: wrap;
}

.list-select {
  flex: 1;
  min-width: 140px;
  padding: 8px 10px;
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-primary-dark);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.list-select:focus {
  outline: none;
  border-color: var(--color-primary);
}

.song-header .list-select {
  flex: 1;
}

.btn-secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.btn-danger {
  color: #b00020;
  border-color: #b00020;
}

.btn-danger:hover {
  background: #b00020;
  color: #fff;
  border-color: #b00020;
}

.btn-danger:disabled:hover {
  background: var(--color-surface);
  color: #b00020;
}

/* Elemento de texto (separador) en la lista */
.list-item-text {
  flex: 1;
  font-style: italic;
  color: #7a5c00;
  background: #fff8e1;
  border-radius: 6px;
  padding: 2px 8px;
  word-break: break-word;
}

/* Seguir lista */
.follow-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.follow-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.follow-item:hover {
  box-shadow: var(--shadow);
  border-color: var(--color-primary);
}

.follow-item.unavailable {
  opacity: 0.6;
  cursor: default;
}

.follow-num {
  min-width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary);
  color: #fff;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.follow-title {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-primary-dark);
  word-break: break-word;
}

/* Título + nota del canto en la vista de la lista */
.follow-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.follow-note {
  font-size: 0.85rem;
  font-style: italic;
  font-weight: 600;
  color: #7a5c00;
  word-break: break-word;
}

/* Separador de texto en la vista de lista */
.follow-text {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-style: italic;
  font-weight: 600;
  color: #7a5c00;
  background: #fff8e1;
  border: 1px dashed #e0c060;
  border-radius: var(--radius);
  text-align: center;
  word-break: break-word;
}

/* Utilidades */
.hidden {
  display: none !important;
}

/* Adaptación móvil */
@media (max-width: 600px) {
  .header-content {
    flex-wrap: wrap; /* el contador ya no cabe junto al título: baja de línea */
    row-gap: 6px;
  }

  .app-title {
    font-size: 1.2rem;
  }

  .header-actions {
    gap: 6px;
  }

  .container {
    padding: 12px;
  }

  .song-title {
    font-size: 1.2rem;
  }

  .song-lyrics {
    padding: 14px;
  }

  .edit-chords-toolbar .btn-secondary {
    flex: 1 1 auto;
    min-width: 62px;
  }

  .edit-chord-grid {
    padding: 10px;
    max-height: none;
  }

  .search-box input {
    font-size: 1rem;
    padding: 12px 40px 12px 14px;
  }
}

/* Adaptación para pantallas grandes (PC) */
@media (min-width: 901px) {
  .container {
    padding: 24px;
  }
}
