:root {
  --bg: #0d0d0d;
  --bg-elev: #161616;
  --bg-elev-2: #1e1e1e;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --text-dim: #9a9a9a;
  --accent: #c1272d;
  --accent-hover: #d93b41;
  --danger: #c1272d;
  --radius: 8px;
  --radius-sm: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }

button {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
}

input, textarea, select {
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, textarea:focus {
  border-color: var(--accent);
}
textarea { resize: vertical; }

/* ============ TOPBAR ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  line-height: 1.1;
}
.brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  flex-shrink: 0;
}
.brand-text {
  display: flex;
  flex-direction: column;
}
.brand-title {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
}
.brand-tagline {
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 0.03em;
  margin-top: 0.15rem;
}
.tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.tab {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
}
.tab:hover { color: var(--text); background: var(--bg-elev-2); }
.tab.is-active {
  color: var(--text);
  background: var(--bg-elev-2);
  border-color: var(--border);
}
.tab--primary {
  background: var(--accent);
  color: white;
}
.tab--primary:hover { background: var(--accent-hover); color: white; }

.tab--editor {
  font-size: 0.85rem;
  padding: 0.4rem 0.65rem;
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.tab--editor:hover { color: var(--text); }
.tab--editor.is-active {
  color: white;
  background: #2a6b3a;
  border-color: #2a6b3a;
}

/* Elementos visibles solo en modo editor. Se ocultan por defecto (modo lectura). */
body:not(.is-editor) #new-button,
body:not(.is-editor) [data-action="new-song"],
body:not(.is-editor) [data-action="new-setlist"],
body:not(.is-editor) [data-action="edit-song"],
body:not(.is-editor) [data-action="edit-setlist"],
body:not(.is-editor) [data-action="delete-song"],
body:not(.is-editor) [data-action="delete-setlist"],
body:not(.is-editor) [data-action="add-song-to-setlist"],
body:not(.is-editor) .setlist-song-controls,
body:not(.is-editor) #song-form .form-actions,
body:not(.is-editor) #setlist-form .form-actions {
  display: none !important;
}

/* En modo lectura deshabilitamos inputs del editor de canción/setlist para
   reforzar que la vista es solo lectura (si el usuario navega a un detalle). */
body:not(.is-editor) #song-form input,
body:not(.is-editor) #song-form textarea,
body:not(.is-editor) #setlist-form input,
body:not(.is-editor) #setlist-form textarea {
  pointer-events: none;
  opacity: 0.85;
}

/* ============ VIEWS ============ */
#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
}
.view { display: none; }
.view.is-active { display: block; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.view-header h1 { flex: 1; min-width: 0; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1.5rem 0 0.75rem;
  flex-wrap: wrap;
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.9rem;
  font-weight: 500;
  background: var(--bg-elev-2);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: #262626; }
.btn--primary { background: var(--accent); color: white; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--secondary { background: var(--bg-elev-2); border-color: var(--border); }
.btn--ghost { background: transparent; color: var(--text-dim); }
.btn--ghost:hover { color: var(--text); background: var(--bg-elev-2); }
.btn--danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn--danger:hover { background: var(--danger); color: white; }
.btn--block { width: 100%; }

/* ============ SEARCH ============ */
.search-input {
  margin-bottom: 0.75rem;
}

/* ============ LISTS ============ */
.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.item:hover { background: var(--bg-elev-2); }
.item-main { flex: 1; min-width: 0; }
.item-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-sub {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem 1rem;
  font-style: italic;
}

/* Empty state de biblioteca con el poster de la banda */
.empty-library {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 2.5rem 1rem;
}
.empty-poster {
  max-width: 320px;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  opacity: 0.85;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.empty-message {
  margin: 0;
  color: var(--text-dim);
  font-style: italic;
  max-width: 36ch;
}

/* ============ FORMS ============ */
.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
@media (min-width: 640px) {
  .form-row { grid-template-columns: 1fr 1fr; }
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.field > span {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.lyrics-input {
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.5;
  min-height: 300px;
  white-space: pre;
  overflow-x: auto;
}
.form-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}
.form-actions .btn--danger { margin-left: auto; }

/* ============ SETLIST SONGS ============ */
.setlist-songs-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  counter-reset: none;
}
.setlist-song {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.setlist-song-order {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 700;
}
.setlist-song-main {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}
.setlist-song-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.setlist-song-sub {
  color: var(--text-dim);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.setlist-song-controls {
  display: flex;
  gap: 0.2rem;
  flex-shrink: 0;
}
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  padding: 0;
  transition: color 0.15s, border-color 0.15s;
}
.icon-btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ============ MODAL ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  overflow-y: auto;
}
.modal-content {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  width: 100%;
  max-width: 560px;
  margin-top: 4vh;
}
.modal-content--small { max-width: 360px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.new-menu-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.modal-text {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin: 0 0 0.75rem;
}

.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
}
.qr-container canvas {
  background: white;
  padding: 0.75rem;
  border-radius: var(--radius);
}
.qr-url {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  word-break: break-all;
  text-align: center;
  margin: 0;
}

/* ============ PERFORM MODE ============ */
.perform {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
}
.perform-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
}
.perform-title {
  font-size: 1.35rem;
  font-weight: 700;
}
.perform-sub {
  margin-top: 0.25rem;
  color: var(--text-dim);
  font-size: 0.9rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.perform-sub span:not(:empty)::before {
  content: "";
}
#perform-key:not(:empty)::before {
  content: "♬ ";
  color: var(--accent);
}
#perform-position {
  margin-left: auto;
}
.perform-content {
  flex: 1;
  margin: 0;
  padding: 1.5rem 1.25rem 5rem;
  font-family: var(--mono);
  font-size: 1.05rem;
  line-height: 1.7;
  white-space: pre;
  overflow: auto;
  color: var(--text);
}
.perform-nav {
  position: fixed;
  bottom: 1rem;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 1rem;
  pointer-events: none;
}
.perform-arrow {
  pointer-events: auto;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 1.75rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.perform-arrow:hover { background: var(--accent); border-color: var(--accent); color: white; }

@media (min-width: 720px) {
  .perform-content { font-size: 1.15rem; padding: 2rem 2.5rem 5rem; }
  .perform-title { font-size: 1.6rem; }
}

/* ============ LOADING ============ */
.app-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 0.75rem 1.25rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  z-index: 300;
  font-size: 0.9rem;
}

/* ============ LIVE INDICATOR ============ */
.live-indicator {
  position: fixed;
  bottom: 0.75rem;
  right: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.6rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--text-dim);
  z-index: 50;
  user-select: none;
}
.live-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #6b6b6b;
  transition: background 0.2s;
}
.live-indicator.is-on .live-dot {
  background: #3fcf6e;
  box-shadow: 0 0 8px rgba(63, 207, 110, 0.5);
  animation: live-pulse 2s ease-in-out infinite;
}
.live-indicator.is-off .live-dot { background: #6b6b6b; }
@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ============ TOASTS ============ */
.toasts {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 400;
  pointer-events: none;
  max-width: 90vw;
}
.toast {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.2s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}
.toast--success { border-color: #2a6b3a; }
.toast--error { border-color: var(--accent); }
.toast.is-out { opacity: 0; transform: translateY(8px); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
