:root {
  --bg-main: #0f0f11;
  --bg-panel: #18181b;
  --bg-card: #1f1f24;
  --bg-input: #27272a;
  --border: #2e2e34;
  --text-main: #f4f4f5;
  --text-muted: #a1a1aa;
  --accent: #FF5722;
  --accent-hover: #f4511e;
  --chord-red: #ff5252;
  --section-gold: #FFB74D;
  --section-bg: #2a2418;
  --scale-blue: #64B5F6;
  --green: #4ade80;
  --lyric-font-size: 17px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Safe area para iPad y iPhone en modo pantalla completa (standalone PWA) */
.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* HEADER SUPERIOR */
.top-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  gap: 8px;
  flex-shrink: 0;
}

.brand-area {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
}

.brand-text-wrap {
  min-width: 0;
  flex: 1 1 120px;
}

.church-select {
  max-width: 210px;
  padding: 6px 10px;
  font-weight: 700;
  font-size: 12px;
  text-overflow: ellipsis;
}

.menu-toggle-btn {
  display: none;
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  flex-shrink: 0;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.cloud-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  background: #1b2e22;
  color: #4ade80;
  border: 1px solid #2e5c3e;
  white-space: nowrap;
}

.cloud-badge.offline {
  background: #2f241c;
  color: #ffb74d;
  border-color: #5c432e;
}

/* BOTONES */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: transform 0.08s ease, background 0.15s ease;
  color: var(--text-main);
  background: var(--bg-input);
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.96);
}

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

.btn-secondary {
  background: var(--bg-input);
  border-color: #383842;
}

.btn-green {
  background: #2e7d32;
  color: #fff;
}

.btn-danger {
  background: #3f1d1d;
  color: #fca5a5;
  border-color: #7f1d1d;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

/* LAYOUT PRINCIPAL (SIDEBAR + ESCENARIO) */
.main-body {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* SIDEBAR IZQUIERDO */
.sidebar {
  width: 340px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 20;
}

.nav-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 10px 12px 6px 12px;
}

.nav-tab {
  background: #121215;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 6px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}

.nav-tab.active {
  background: #2a1d17;
  color: #ff8a65;
  border-color: var(--accent);
}

/* SELECTOR DE EVENTO ACTIVO */
.event-selector-box {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: #141418;
}

.event-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.event-select {
  flex: 1;
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid #3f3f46;
  border-radius: 7px;
  padding: 7px 8px;
  font-size: 13px;
  font-weight: 600;
}

.search-box-wrap {
  padding: 8px 12px 6px 12px;
}

.search-input {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
}

.sidebar-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 5px;
  padding: 0 12px 8px 12px;
}

.song-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px;
  -webkit-overflow-scrolling: touch;
}

.song-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px;
  margin-bottom: 5px;
  border-radius: 8px;
  background: #141417;
  border: 1px solid transparent;
  cursor: pointer;
  gap: 8px;
}

.song-item.active {
  background: #281c17;
  border-color: var(--accent);
}

.song-item-info {
  min-width: 0;
  flex: 1;
}

.song-item-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.song-item-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.song-item-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.key-pill {
  background: var(--bg-input);
  color: #ff7043;
  font-weight: 800;
  font-size: 12px;
  padding: 3px 7px;
  border-radius: 5px;
  border: 1px solid #3f3f46;
}

.order-btn {
  background: #222227;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 11px;
  cursor: pointer;
}

.sidebar-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* PANEL PRINCIPAL DERECHO (VISTA ESCENARIO Y EDITOR) */
.content-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-main);
}

/* BARRA DE CONTROL DEL CANTO (TONO, TRANSPOSICIÓN, ZOOM, MODO) */
.song-toolbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.song-header-meta {
  min-width: 180px;
  flex: 1;
}

.current-song-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.current-song-details {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.transpose-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #141418;
  padding: 5px 8px;
  border-radius: 9px;
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.transpose-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.key-select-live {
  background: var(--bg-input);
  color: #ff8a65;
  font-weight: 800;
  font-size: 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 5px 8px;
}

.stage-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* BARRA DE NAVEGACIÓN RÁPIDA DE EVENTO (ANTERIOR / SIGUIENTE) */
.event-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #1c1613;
  border-bottom: 1px solid #432818;
  padding: 6px 14px;
  font-size: 12px;
  color: #ffb74d;
}

/* CONTENEDOR DE VISTA ESCENARIO (ATRIL) */
.stage-viewer {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 18px 20px 80px 20px;
  -webkit-overflow-scrolling: touch;
  user-select: text;
  -webkit-user-select: text;
}

.stage-notes-banner {
  background: #1c1917;
  border-left: 3px solid var(--section-gold);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: #fde68a;
  margin-bottom: 14px;
}

.stage-section-badge {
  display: inline-block;
  background: var(--section-bg);
  color: var(--section-gold);
  border: 1px solid #FFA726;
  border-radius: 5px;
  padding: 3px 9px;
  font-weight: 800;
  font-size: 13px;
  margin: 12px 0 5px 0;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

.stage-chord-line {
  font-family: "Menlo", "SF Mono", "Courier New", monospace;
  font-size: var(--lyric-font-size, 17px);
  font-weight: 700;
  color: var(--chord-red);
  white-space: pre;
  line-height: 1.25;
  margin-top: 4px;
}

.stage-lyric-line {
  font-family: "Menlo", "SF Mono", "Courier New", monospace;
  font-size: var(--lyric-font-size, 17px);
  color: var(--text-main);
  white-space: pre;
  line-height: 1.35;
  margin-bottom: 4px;
}

.stage-spacer {
  height: 12px;
}

/* CONTENEDOR DE EDICIÓN (MODO TRADICIONAL EN IPAD/IPHONE) */
.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
  gap: 10px;
  overflow-y: auto;
}

.editor-meta-grid {
  display: grid;
  grid-template-columns: 2fr 1.3fr 90px 80px 90px;
  gap: 8px;
  background: var(--bg-card);
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-group label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.field-input {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid #383842;
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 14px;
}

.scale-bar {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.scale-chord-btn {
  background: #222226;
  color: var(--scale-blue);
  border: 1px solid #32323a;
  border-radius: 6px;
  padding: 6px 10px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.section-tag-btn {
  background: var(--section-bg);
  color: var(--section-gold);
  border: 1px solid #4a3820;
  border-radius: 6px;
  padding: 6px 8px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
}

.lyrics-textarea {
  flex: 1;
  min-height: 280px;
  width: 100%;
  background: #141417;
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-family: "Menlo", "SF Mono", "Courier New", monospace;
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
  user-select: text;
  -webkit-user-select: text;
}

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

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-list {
  flex: 1;
  overflow-y: auto;
  background: #121215;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}

.modal-check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px solid #1f1f24;
  font-size: 14px;
  cursor: pointer;
}

.toast-banner {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1e3a2f;
  color: #86efac;
  border: 1px solid #2e7d32;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 8px 20px rgba(0,0,0,0.5);
}

.hidden {
  display: none !important;
}

/* RESPONSIVE PARA IPHONE, ANDROID Y PANTALLAS COMPACTAS (SOLO CELULARES) */
@media (max-width: 820px) {
  .menu-toggle-btn {
    display: inline-flex;
  }
  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 86%;
    max-width: 340px;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.7);
    transform: translateX(-102%);
    transition: transform 0.22s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .editor-meta-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* Encabezado en 2 filas limpias que NUNCA se salen de la pantalla en celular */
  .top-header {
    flex-direction: column;
    align-items: stretch;
    padding: 6px 8px;
    gap: 6px;
    width: 100%;
  }
  .brand-area {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
  }
  .menu-toggle-btn {
    padding: 6px 9px;
    font-size: 15px;
  }
  .brand-logo {
    width: 26px;
    height: 26px;
  }
  .brand-text-wrap {
    flex: 1 1 auto;
    min-width: 0;
  }
  .brand-title {
    font-size: 13px;
  }
  .brand-subtitle {
    font-size: 9.5px;
  }
  .church-select {
    flex: 0 1 140px;
    max-width: 145px;
    min-width: 95px;
    padding: 5px 6px;
    font-size: 11px;
  }
  .header-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    overflow: visible;
  }
  .header-actions .btn,
  .header-actions .cloud-badge {
    flex: 1 1 auto;
    justify-content: center;
    text-align: center;
    padding: 5px 6px;
    font-size: 10.5px;
    min-width: 0;
  }

  /* Barra de datos del canto actual (Título completo + Tono + Zoom/Scroll) en celular */
  .song-toolbar {
    padding: 6px 8px;
    gap: 6px;
    flex-direction: column;
    align-items: stretch;
  }
  .song-header-meta {
    width: 100%;
    min-width: 0;
  }
  .current-song-title {
    font-size: 14px;
    line-height: 1.2;
    white-space: normal;
    word-break: break-word;
  }
  .current-song-details {
    font-size: 11px;
    line-height: 1.25;
    white-space: normal;
    word-break: break-word;
    margin-top: 2px;
  }
  .transpose-controls {
    width: 100%;
    padding: 4px 6px;
    gap: 4px;
    justify-content: space-between;
  }
  .transpose-controls .btn-sm {
    padding: 4px 7px;
    font-size: 11px;
    flex: 1 1 auto;
  }
  .key-select-live {
    font-size: 12px;
    padding: 3px 6px;
  }
  .stage-controls {
    width: 100%;
    gap: 5px;
    justify-content: space-between;
  }
  .stage-controls .btn-sm {
    flex: 1 1 auto;
    padding: 5px 8px;
    font-size: 11px;
  }
  .stage-viewer {
    padding: 10px 10px 70px 10px;
  }
}

/* BOTÓN MODO GRUPO / MODO LIBRE */
.follow-director-btn {
  font-weight: 600;
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s ease;
  cursor: pointer;
}

.follow-director-btn.follow-active {
  background: #14532d !important;
  color: #86efac !important;
  border: 1px solid #22c55e !important;
}

.follow-director-btn.follow-active:hover {
  background: #166534 !important;
}

.follow-director-btn.follow-free {
  background: #451a03 !important;
  color: #fde68a !important;
  border: 1px solid #f59e0b !important;
}

.follow-director-btn.follow-free:hover {
  background: #78350f !important;
}

.church-badge-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
}

.btn-text-sm {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.2s;
}

.btn-text-sm:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

