/* ── Variables ── */
:root {
  --fondo:      #0d0d0d;
  --superficie: #1a1a2e;
  --sup2:       #22223a;
  --acento:     #c084fc;
  --acento2:    #f472b6;
  --texto:      #f8f8f8;
  --texto-suave:#a0a0b0;
  --exito:      #4ade80;
  --advertencia:#facc15;
  --error:      #f87171;
  --borde:      rgba(255,255,255,0.08);
  --radius:     12px;
  --radius-sm:  8px;
  --sombra:     0 8px 32px rgba(0,0,0,0.5);
}

/* ── Reset básico ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--fondo);
  color: var(--texto);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
img { display: block; }

/* ── Header ── */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(13,13,13,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--borde);
}
.header-inner {
  max-width: 1400px; margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
}
.logo {
  display: flex; align-items: center; gap: 10px;
}
.logo-icon { font-size: 1.5rem; }
.logo-text {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem; font-weight: 700;
  background: linear-gradient(135deg, var(--acento), var(--acento2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.header-tipo {
  font-size: 0.95rem; font-weight: 500;
}
.btn-historial {
  padding: 8px 18px;
  border: 1px solid var(--borde);
  border-radius: 20px;
  font-size: 0.85rem; font-weight: 500;
  color: var(--texto-suave);
  transition: all 0.2s;
}
.btn-historial:hover {
  border-color: var(--acento);
  color: var(--acento);
}

/* ── Home ── */
.home-main {
  max-width: 1200px; margin: 0 auto; padding: 48px 24px 80px;
}
.home-hero {
  text-align: center; margin-bottom: 48px;
}
.home-hero h1 {
  font-family: 'Playfair Display', serif;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  margin-bottom: 12px;
}
.home-hero p {
  color: var(--texto-suave); font-size: 1.1rem;
}

/* ── Grid de tipos ── */
.tipos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}
.tipo-card {
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  display: flex; flex-direction: column; gap: 16px;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  position: relative; overflow: hidden;
}
.tipo-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--acento);
  opacity: 0; transition: opacity 0.2s;
}
.tipo-card:hover {
  transform: translateY(-4px);
  border-color: rgba(var(--acento), 0.3);
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}
.tipo-card:hover::before { opacity: 1; }
.tipo-icono { font-size: 2.4rem; }
.tipo-info { flex: 1; }
.tipo-info h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem; margin-bottom: 8px;
}
.tipo-info p {
  color: var(--texto-suave);
  font-size: 0.85rem; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.btn-crear {
  display: inline-block; align-self: flex-start;
  padding: 9px 20px;
  background: var(--acento);
  color: #000; font-weight: 600; font-size: 0.85rem;
  border-radius: 8px; transition: opacity 0.2s;
}
.btn-crear:hover { opacity: 0.85; }

/* ── Layout crear.php ── */
.crear-layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  height: calc(100vh - 60px);
  overflow: hidden;
}
.config-panel {
  border-right: 1px solid var(--borde);
  overflow-y: auto;
  background: var(--superficie);
}
.config-inner { padding: 28px 24px 48px; display: flex; flex-direction: column; gap: 24px; }
.tipo-header { }
.tipo-badge {
  display: inline-block;
  padding: 6px 14px;
  border: 1px solid;
  border-radius: 20px;
  font-size: 0.85rem; font-weight: 600;
  margin-bottom: 12px;
}
.tipo-desc {
  font-size: 0.85rem; color: var(--texto-suave); line-height: 1.6;
}
.seccion-config { }
.seccion-config h3 {
  font-size: 0.8rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--texto-suave);
  margin-bottom: 12px;
}
.config-hint {
  font-size: 0.82rem; color: var(--texto-suave);
  line-height: 1.5; margin-top: 8px;
}
.opcional { font-size: 0.75rem; font-weight: 400; opacity: 0.6; }

/* Inputs */
input[type=text], input[type=number], textarea, select {
  width: 100%;
  background: var(--fondo);
  border: 1px solid var(--borde);
  border-radius: var(--radius-sm);
  color: var(--texto);
  font-family: inherit; font-size: 0.9rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s;
}
input[type=text]:focus, input[type=number]:focus, textarea:focus {
  border-color: var(--acento);
}
input::placeholder { color: var(--texto-suave); }

.field-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field-group label { font-size: 0.82rem; color: var(--texto-suave); }

.radio-group { display: flex; gap: 12px; flex-wrap: wrap; }
.radio-group.vertical { flex-direction: column; gap: 8px; }
.radio-group label {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.88rem; cursor: pointer;
}
input[type=radio] { accent-color: var(--acento); }

/* Buscador */
.buscador-wrap { display: flex; gap: 8px; margin-bottom: 10px; }
.buscador-wrap input { flex: 1; }
.buscador-wrap button, #buscador-btn {
  padding: 10px 16px;
  background: var(--acento); color: #000;
  border: none; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.85rem; white-space: nowrap;
}
.buscador-wrap button:hover { opacity: 0.85; }

/* Resultados búsqueda */
.resultados-lista {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 280px; overflow-y: auto;
}
.resultado-item {
  display: flex; align-items: center; gap:12px;
  padding: 10px;
  background: var(--fondo);
  border: 1px solid var(--borde); border-radius: var(--radius-sm);
  cursor: pointer; transition: border-color 0.15s;
}
.resultado-item:hover { border-color: var(--acento); }
.resultado-item img {
  width: 36px; height: 52px; object-fit: cover;
  border-radius: 4px; flex-shrink: 0;
  background: var(--sup2);
}
.resultado-item .r-info { flex: 1; min-width: 0; }
.resultado-item .r-titulo {
  font-size: 0.85rem; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.resultado-item .r-autor {
  font-size: 0.75rem; color: var(--texto-suave); margin-top: 2px;
}
.resultado-item .r-add {
  font-size: 1.2rem; color: var(--acento); flex-shrink: 0;
}
.resultados-loading { color: var(--texto-suave); font-size: 0.85rem; padding: 8px 0; }
.resultados-error { color: var(--error); font-size: 0.85rem; }

/* Lista de libros añadidos */
.libros-lista { display: flex; flex-direction: column; gap: 8px; }
.libro-item {
  background: var(--fondo);
  border: 1px solid var(--borde); border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex; align-items: flex-start; gap: 10px;
}
.libro-item.dragging { opacity: 0.4; }
.libro-thumb {
  width: 32px; height: 46px; object-fit: cover;
  border-radius: 3px; background: var(--sup2); flex-shrink: 0;
}
.libro-data { flex: 1; min-width: 0; }
.libro-titulo { font-size: 0.82rem; font-weight: 500; margin-bottom: 3px; }
.libro-autor { font-size: 0.75rem; color: var(--texto-suave); }
.libro-extras { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.libro-extras input[type=text], .libro-extras input[type=number], .libro-extras textarea {
  font-size: 0.78rem; padding: 5px 8px;
}
.libro-extras .char-count { font-size: 0.7rem; color: var(--texto-suave); text-align: right; }
.libro-extras select {
  font-size: 0.78rem; padding: 5px 8px;
}
.libro-handle { cursor: grab; color: var(--texto-suave); padding: 0 2px; align-self: center; }
.libro-remove {
  background: none; border: none; color: var(--texto-suave);
  font-size: 1rem; padding: 2px; flex-shrink: 0; align-self: flex-start;
  transition: color 0.15s;
}
.libro-remove:hover { color: var(--error); }
.libro-favorito-btn {
  background: none; border: 1px solid var(--borde);
  border-radius: 4px; color: var(--texto-suave);
  font-size: 0.7rem; padding: 3px 7px; margin-top: 4px;
  transition: all 0.15s;
}
.libro-favorito-btn.activo {
  border-color: var(--advertencia); color: var(--advertencia);
}
.count-badge {
  display: inline-block;
  background: var(--acento); color: #000;
  font-size: 0.7rem; font-weight: 700;
  border-radius: 10px; padding: 1px 7px; margin-left: 4px;
}

/* Fondos */
.fondos-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px;
}
.fondo-opt {
  aspect-ratio: 1; border-radius: 6px;
  border: 2px solid transparent; cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.fondo-opt:hover { transform: scale(1.1); }
.fondo-opt.selected { border-color: var(--acento); }

/* Botón grabar */
.btn-grabar {
  width: 100%;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--acento), var(--acento2));
  color: #000; font-weight: 700; font-size: 1rem;
  border: none; border-radius: var(--radius);
  transition: opacity 0.2s, transform 0.15s;
  margin-top: 8px;
}
.btn-grabar:hover:not(:disabled) { opacity: 0.9; transform: translateY(-1px); }
.btn-grabar:disabled { opacity: 0.35; cursor: not-allowed; }

/* Preview 9:16 */
.preview-wrap {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px;
  background: #0a0a0a; overflow: hidden; padding: 24px;
}
.preview-label {
  font-size: 0.75rem; color: var(--texto-suave);
  text-transform: uppercase; letter-spacing: 0.1em;
}
.preview-frame {
  width: min(260px, 35vw);
  aspect-ratio: 9 / 16;
  border-radius: 16px; overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08), var(--sombra);
  position: relative;
}
.preview-fondo {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  transition: background 0.3s;
  background: #0d0d0d;
  position: relative;
}
.preview-titulo {
  position: absolute; top: 16px; left: 12px; right: 12px;
  font-family: 'Playfair Display', serif;
  font-size: 0.85rem; text-align: center;
  color: rgba(255,255,255,0.9); text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.preview-content {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 12px;
  gap: 8px;
}
.preview-placeholder {
  color: var(--texto-suave); font-size: 0.7rem;
  text-align: center; line-height: 1.6;
}
.preview-portada {
  width: 55%; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  object-fit: cover;
}
.preview-portadas-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 8px;
}
.preview-portadas-grid img {
  width: 100%; aspect-ratio: 2/3; object-fit: cover; border-radius: 4px;
}

/* Historial */
.historial-main {
  max-width: 1100px; margin: 0 auto; padding: 40px 24px 80px;
}
.page-title {
  font-family: 'Playfair Display', serif; font-size: 2rem; margin-bottom: 32px;
}
.stats-row {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 28px;
}
.stat-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--superficie); border: 1px solid;
  border-radius: 20px;
}
.stat-icono { font-size: 1rem; }
.stat-num { font-weight: 700; font-size: 1rem; }
.stat-nombre { font-size: 0.78rem; color: var(--texto-suave); }

.filtros-row {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 28px;
}
.filtro-btn {
  padding: 7px 16px;
  background: var(--superficie); border: 1px solid var(--borde);
  border-radius: 20px; font-size: 0.82rem; color: var(--texto-suave);
  transition: all 0.15s;
}
.filtro-btn:hover, .filtro-btn.active {
  border-color: var(--acento); color: var(--acento);
}

.historial-lista {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px;
}
.historial-card {
  background: var(--superficie); border: 1px solid var(--borde);
  border-radius: var(--radius); padding: 20px;
  position: relative;
}
.hcard-tipo { font-size: 0.78rem; font-weight: 600; margin-bottom: 8px; }
.hcard-titulo { font-size: 0.95rem; font-weight: 500; margin-bottom: 4px; }
.hcard-fecha { font-size: 0.75rem; color: var(--texto-suave); margin-bottom: 12px; }
.hcard-portadas { display: flex; gap: 5px; flex-wrap: wrap; }
.hcard-portadas img {
  width: 36px; height: 52px; object-fit: cover; border-radius: 4px;
}
.portadas-mas {
  width: 36px; height: 52px; background: var(--fondo);
  border-radius: 4px; display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; color: var(--texto-suave);
}
.hcard-borrar {
  position: absolute; top: 12px; right: 12px;
}
.hcard-borrar button {
  background: none; border: none; color: var(--texto-suave); font-size: 0.9rem;
  padding: 4px; transition: color 0.15s;
}
.hcard-borrar button:hover { color: var(--error); }
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--texto-suave);
}
.empty-state p { margin-bottom: 16px; font-size: 1rem; }

/* ── Badge stats Google Books ── */
.stats-google-badge {
  background: rgba(192,132,252,0.1);
  border: 1px solid rgba(192,132,252,0.3);
  border-radius: 6px; padding: 6px 10px;
  font-size: 0.75rem; color: #c084fc; font-weight: 500;
}

/* ── Paleta compacta — cuadrados de 18px fijos ── */
.fondos-grid-compacta {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 6px !important;
  grid-template-columns: unset !important;
}
.fondos-grid-compacta .fondo-opt {
  width: 18px !important;
  height: 18px !important;
  flex: none !important;
  aspect-ratio: unset !important;
  border-radius: 4px !important;
  border-width: 1px !important;
  min-height: unset !important;
}

/* ── Color picker personalizado ── */
.fondos-categoria-label {
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--texto-suave);
  margin: 10px 0 6px;
}
.fondos-grid { grid-template-columns: repeat(6, 1fr); }
.color-custom-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 4px;
}
input[type=color] {
  width: 24px; height: 24px; padding: 1px;
  border: 1px solid var(--borde); border-radius: 6px;
  background: none; cursor: pointer;
  -webkit-appearance: none;
}
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: none; border-radius: 4px; }
input[type=color]:focus { border-color: var(--acento); }
.color-custom-label { font-size: 0.8rem; color: var(--texto-suave); }
.color-custom-preview {
  width: 18px; height: 18px; border-radius: 50%;
  border: 1.5px solid transparent; transition: border-color 0.15s;
}
.color-custom-preview.selected { border-color: var(--acento); }

/* ── Validación — siempre visible cuando el botón está desactivado ── */
.validacion-msg {
  background: rgba(248,113,113,0.12);
  border: 1px solid rgba(248,113,113,0.35);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-size: 0.82rem; line-height: 1.55;
  padding: 11px 14px;
  margin-bottom: 6px;
  min-height: 0; display: block;
}
.validacion-msg:empty { display: none; }

/* ── Acciones extra (borrador, borradores) ── */
.acciones-extra {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; margin-top: 6px;
}
.btn-acc {
  padding: 11px 8px;
  background: var(--sup2);
  border: 1px solid var(--borde);
  border-radius: var(--radius);
  color: var(--texto-suave); font-size: 0.8rem;
  font-family: inherit; text-align: center;
  cursor: pointer; transition: all 0.18s;
  text-decoration: none;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  font-weight: 500;
}
.btn-acc:first-child {
  /* Guardar borrador — destacado con acento suave */
  background: rgba(192,132,252,0.1);
  border-color: rgba(192,132,252,0.3);
  color: #c084fc;
}
.btn-acc:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}
.btn-acc:first-child:hover {
  background: rgba(192,132,252,0.2);
  border-color: rgba(192,132,252,0.5);
}
.btn-acc:last-child:hover {
  border-color: var(--acento); color: var(--acento);
}

/* Borradores page */
.borrador-card { border-left: 3px solid var(--acento); }
.borrador-acciones { display: flex; gap: 8px; margin-top: 12px; }
.btn-borrador-editar {
  flex: 1; padding: 8px 12px; background: var(--acento); color: #000;
  border-radius: 8px; font-size: 0.82rem; font-weight: 600; text-align: center; text-decoration: none;
  transition: opacity 0.15s;
}
.btn-borrador-editar:hover { opacity: 0.85; }
.btn-borrador-borrar {
  padding: 8px 12px; background: none;
  border: 1px solid var(--borde); border-radius: 8px;
  color: var(--texto-suave); font-size: 0.8rem; cursor: pointer;
  transition: all 0.15s;
}
.btn-borrador-borrar:hover { border-color: var(--error); color: var(--error); }
.campo-requerido {
  border-color: rgba(248,113,113,0.6) !important;
  background: rgba(248,113,113,0.05) !important;
}
.libros-vacio {
  color: var(--texto-suave); font-size: 0.8rem; padding: 4px 0;
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* Mood config en crear */
.mood-config-lista { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.mood-config-item {
  background: var(--fondo); border: 1px solid var(--borde);
  border-radius: var(--radius-sm); padding: 10px;
}
.mood-config-item .mood-label { font-size: 0.82rem; font-weight: 500; margin-bottom: 6px; }
.mood-libro-asignado {
  display: flex; align-items: center; gap: 8px; margin-top: 6px;
}
.mood-libro-asignado img { width: 24px; height: 36px; object-fit: cover; border-radius: 2px; }
.mood-libro-asignado span { font-size: 0.78rem; color: var(--texto-suave); }
.mood-libro-asignado button {
  background: none; border: none; color: var(--error); font-size: 0.8rem; margin-left: auto;
}

/* Responsive */
@media (max-width: 740px) {
  .crear-layout { grid-template-columns: 1fr; height: auto; }
  .preview-wrap { display: none; }
  .config-panel { height: auto; overflow-y: visible; }
}

/* ── Buscador header ── */
.buscador-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.buscador-header h3 { margin-bottom: 0 !important; }
.btn-manual-libro {
  padding: 5px 12px; background: rgba(192,132,252,0.15);
  border: 1px solid rgba(192,132,252,0.35); border-radius: 20px;
  color: #c084fc; font-size: 0.75rem; font-weight: 600; cursor: pointer;
  transition: background 0.15s;
}
.btn-manual-libro:hover { background: rgba(192,132,252,0.28); }

/* ── Modal libro manual ── */
.modal-manual {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,0.75); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.modal-manual-box {
  background: var(--superficie); border: 1px solid var(--borde);
  border-radius: 16px; padding: 28px 28px 24px;
  width: min(420px, 95vw); display: flex; flex-direction: column; gap: 16px;
  max-height: 90vh; overflow-y: auto;
}
.modal-manual-header {
  display: flex; align-items: center; justify-content: space-between;
}
.modal-manual-header h3 {
  font-family: 'Playfair Display', serif; font-size: 1.1rem;
}
.modal-manual-header button {
  background: none; border: none; color: var(--texto-suave); font-size: 1.1rem; cursor: pointer;
}
.portada-opciones {
  display: flex; flex-direction: column; gap: 10px;
}
.portada-opcion { display: flex; flex-direction: column; gap: 5px; }
.portada-op-label { font-size: 0.72rem; color: var(--texto-suave); }
.portada-opcion-sep { text-align: center; color: var(--texto-suave); font-size: 0.8rem; }
.btn-subir-portada {
  display: inline-block; padding: 8px 14px;
  background: rgba(255,255,255,0.05); border: 1px dashed var(--borde);
  border-radius: 6px; cursor: pointer; font-size: 0.82rem; color: var(--texto-suave);
  transition: background 0.15s;
}
.btn-subir-portada:hover { background: rgba(255,255,255,0.1); }
.portada-preview-mini {
  width: 60px; height: 88px; border-radius: 5px;
  background: var(--fondo) center/cover no-repeat;
  border: 1px solid var(--borde);
  margin-top: 4px; flex-shrink: 0;
}
.modal-manual-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.checkbox-guardar {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.76rem; color: var(--texto-suave); cursor: pointer;
}
.checkbox-guardar input { accent-color: var(--acento); }

/* Badges en resultados de búsqueda */
.badge-personalizado {
  display: inline-block; padding: 1px 7px; border-radius: 10px;
  background: rgba(192,132,252,0.2); color: #c084fc;
  font-size: 0.65rem; font-weight: 600; margin-left: 4px;
}

/* Prevent auto-zoom on mobile and iPad (Safari requires min 16px) */
@media (max-width: 1024px) {
  input[type=text],
  input[type=number],
  textarea,
  select,
  .buscador-wrap input {
    font-size: 16px !important;
  }
}

/* Indicador visual al seleccionar libro para intercambiar en iPad */
.libro-item.selected-for-swap {
  border-color: var(--acento) !important;
  background: rgba(192, 132, 252, 0.15) !important;
  box-shadow: 0 0 12px rgba(192, 132, 252, 0.4);
}
