/* ==========================================================================
   Fijate Tools - Grabadora de notas de voz persistente
   Estilos canónicos Local-First y diseño premium de audio
   ========================================================================== */

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-primary: #38bdf8;
  --accent-secondary: #0284c7;
  --accent-gradient: linear-gradient(135deg, #38bdf8 0%, #2563eb 100%);
  --record-gradient: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  --border-color: #334155;
  --card-bg: #1e293b;
  --card-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent-primary: #0284c7;
  --accent-secondary: #0369a1;
  --accent-gradient: linear-gradient(135deg, #0284c7 0%, #1d4ed8 100%);
  --record-gradient: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  --border-color: #cbd5e1;
  --card-bg: #ffffff;
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
}

/* Reset y estructura general */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.25;
}

.mono-font {
  font-family: 'JetBrains Mono', monospace;
}

.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* Barra lateral publicidad canónica */
.tool-ad-sidebar {
  display: none;
  width: 300px;
  flex-shrink: 0;
}

@media (min-width: 1536px) {
  .tool-ad-sidebar {
    display: block;
  }
}

.ad-sticky-box {
  position: sticky;
  top: 1.5rem;
}

/* Migas de pan canónicas */
.tool-breadcrumbs {
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.tool-breadcrumbs ol {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  list-style: none;
}

.tool-breadcrumbs li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}

.tool-breadcrumbs a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color 0.2s;
}

.tool-breadcrumbs a:hover {
  text-decoration: underline;
}

/* Encabezado e introducción */
.tool-header-block {
  margin-bottom: 1.5rem;
}

.tool-title {
  font-size: 1.85rem;
  margin-bottom: 0.5rem;
}

.tool-lead {
  font-size: 1.05rem;
  color: var(--text-secondary);
}

/* Rejilla de la consola de grabación y biblioteca */
.audio-main-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 1.5rem;
  align-items: flex-start;
}

@media (max-width: 960px) {
  .audio-main-grid {
    grid-template-columns: 1fr;
  }
}

/* Tarjeta principal de grabación y consola */
.recording-studio-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.85rem;
  padding: 1.75rem;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Panel inicial de espera a grabar */
.record-start-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2rem 1rem;
  gap: 1.25rem;
}

.btn-record-big {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: var(--record-gradient);
  border: 4px solid rgba(239, 68, 68, 0.2);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 25px rgba(239, 68, 68, 0.35);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-record-big:hover {
  transform: scale(1.06);
  box-shadow: 0 14px 30px rgba(239, 68, 68, 0.45);
}

.btn-record-big svg {
  width: 36px;
  height: 36px;
}

.title-input-wrapper {
  max-width: 380px;
  width: 100%;
}

.input-record-title {
  width: 100%;
  height: 44px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 0 1rem;
  color: var(--text-primary);
  font-size: 0.95rem;
  text-align: center;
  outline: none;
}

.input-record-title:focus {
  border-color: var(--accent-primary);
}

/* Panel de grabación activa en vivo */
.active-recording-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  padding: 1rem 0;
}

.chronometer-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2.75rem;
  font-weight: 700;
  color: var(--danger);
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.recording-pulse-dot {
  width: 14px;
  height: 14px;
  background: var(--danger);
  border-radius: 50%;
  animation: pulse-red 1.2s infinite;
}

@keyframes pulse-red {
  0% { transform: scale(0.9); opacity: 0.8; box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { transform: scale(1.15); opacity: 1; box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
  100% { transform: scale(0.9); opacity: 0.8; box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Canvas de onda en vivo */
.canvas-onda-vivo-box {
  width: 100%;
  height: 110px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.65rem;
  overflow: hidden;
}

#canvas-onda-vivo {
  width: 100%;
  height: 100%;
  display: block;
}

.recording-controls-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

/* Marcas temporales en vivo */
.chips-marcas-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  max-width: 600px;
}

.chip-marca {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  padding: 0.25rem 0.65rem;
  border-radius: 1rem;
  font-size: 0.775rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent-primary);
}

/* Panel del reproductor integrado */
.player-studio-panel {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

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

.canvas-onda-rep-box {
  width: 100%;
  height: 70px;
  background: var(--bg-secondary);
  border-radius: 0.5rem;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

#canvas-onda-reproductor {
  width: 100%;
  height: 100%;
  display: block;
}

/* Barra de progreso de audio */
.scrubber-container {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.audio-progress-slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  background: var(--bg-tertiary);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.audio-progress-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.time-readout-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.775rem;
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
}

/* Botonera de control de reproducción */
.player-controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.playback-buttons {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.speed-select {
  height: 38px;
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.4rem;
  padding: 0 28px 0 0.65rem;
  font-size: 0.825rem;
  font-family: 'JetBrains Mono', monospace;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  white-space: nowrap;
}

.speed-select option {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

/* Editor de notas de la grabación */
.notes-editor-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.notes-textarea {
  width: 100%;
  min-height: 110px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 0.85rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  resize: vertical;
  outline: none;
}

.notes-textarea:focus {
  border-color: var(--accent-primary);
}

/* Lista de marcas de tiempo del reproductor */
.marcas-reproductor-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.marcas-lista-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.btn-marca-salto {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.4rem;
  padding: 0.35rem 0.65rem;
  color: var(--text-primary);
  font-size: 0.8rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s;
}

.btn-marca-salto:hover {
  border-color: var(--accent-primary);
  background: rgba(56, 189, 248, 0.1);
}

.marca-seg {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--accent-primary);
}

.texto-vacio-marcas {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Columna derecha: Biblioteca de audios */
.audios-sidebar-panel {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.85rem;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--card-shadow);
}

.search-audios-input {
  width: 100%;
  height: 42px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 0 1rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
}

.search-audios-input:focus {
  border-color: var(--accent-primary);
}

.audios-scroll-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 600px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.item-audio {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 0.65rem;
  padding: 0.85rem 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.item-audio:hover {
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}

.item-audio.activo {
  border-color: var(--accent-primary);
  background: rgba(56, 189, 248, 0.08);
  box-shadow: inset 3px 0 0 var(--accent-primary);
}

.item-audio-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.item-audio-titulos {
  flex: 1;
  min-width: 0;
}

.item-audio-nombre {
  font-size: 0.925rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-audio-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.item-audio-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
}

.badge-duracion {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
}

.badge-notas {
  color: var(--accent-primary);
}

.btn-icon-fav {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.15rem;
  cursor: pointer;
  padding: 0.1rem;
  line-height: 1;
  transition: color 0.2s;
}

.btn-icon-fav:hover,
.btn-icon-fav.favorito {
  color: #f59e0b;
}

.empty-state-audios {
  padding: 2.5rem 1rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}

/* Botones universales */
.btn-principal,
.btn-secundario,
.btn-peligro {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 42px;
  padding: 0 1.25rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  text-decoration: none;
}

.btn-principal {
  background: var(--accent-gradient);
  color: #ffffff;
}

.btn-principal:hover {
  opacity: 0.92;
}

.btn-secundario {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secundario:hover {
  background: var(--border-color);
}

.btn-secundario.activo {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.btn-peligro {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-peligro:hover {
  background: var(--danger);
  color: #ffffff;
}

.btn-sm {
  height: 36px;
  padding: 0 0.85rem;
  font-size: 0.825rem;
}

/* Modales accesibles */
.modal-container {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding: 1rem;
}

.modal-container.activo {
  opacity: 1;
  pointer-events: auto;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.modal-box {
  position: relative;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.85rem;
  max-width: 500px;
  width: 100%;
  padding: 1.75rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

/* Indicador de carga */
.indicador-carga-box {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--card-bg);
  border: 1px solid var(--accent-primary);
  border-radius: 0.65rem;
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--card-shadow);
  z-index: 9999;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(56, 189, 248, 0.2);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.oculto {
  display: none !important;
}

/* Responsive móvil */
@media (max-width: 640px) {
  .tool-layout {
    padding: 0 0.75rem;
    margin: 1rem auto 2rem;
  }

  .audio-main-grid {
    grid-template-columns: 1fr;
  }

  .chronometer-display {
    font-size: 2.2rem;
  }

  .recording-controls-actions button {
    flex: 1 1 100%;
    width: 100%;
  }

  .player-controls-row {
    flex-direction: column;
    align-items: stretch;
  }

  .playback-buttons {
    justify-content: space-between;
  }

  .speed-select {
    width: 100%;
  }
}
