/* ─── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

/*
  Paleta:
    color1 #a57368  terracota  → acento principal, botones activos, logo
    color2 #b39579  camel      → texto secundario, faint
    color3 #cac2a8  piedra     → bordes, separadores
    color4 #efefdf  crema      → tags, fondos de inputs, superficies cálidas
    color5 #f9f9f9  casi blanco→ fondo de página
*/

:root {
  --bg:           #f9f9f9;  /* color5 – fondo de página      */
  --surface:      #ffffff;  /* blanco – tarjetas / modales   */
  --surface-warm: #efefdf;  /* color4 – superficies cálidas  */
  --border:       #cac2a8;  /* color3 – bordes               */
  --border-soft:  #dedad0;  /* entre color3 y color4         */
  --text:         #2e1e1a;  /* marrón oscuro cálido          */
  --text-soft:    #7a6255;  /* marrón medio cálido           */
  --text-faint:   #b39579;  /* color2 – texto atenuado       */
  --accent:       #a57368;  /* color1 – terracota            */
  --accent-hover: #8a5048;  /* terracota más oscuro          */
  --tag-bg:       #efefdf;  /* color4                        */
  --tag-text:     #7a6255;
  --radius:       6px;
  --shadow:       0 1px 3px rgba(165,115,104,.10), 0 4px 12px rgba(165,115,104,.06);
  --shadow-lg:    0 8px 32px rgba(165,115,104,.14), 0 2px 8px rgba(165,115,104,.07);
  --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ─── Header ────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}
.logo-icon {
  font-size: 20px;
  color: var(--accent);
}
.logo-text {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.3px;
  color: var(--text);
}
.header-stats {
  font-size: 13px;
  color: var(--text-faint);
}

/* ─── Search ────────────────────────────────────────────────────────────── */
.search-section {
  max-width: 720px;
  margin: 40px auto 0;
  padding: 0 24px;
}
.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 14px;
  width: 18px;
  height: 18px;
  color: var(--text-faint);
  pointer-events: none;
  flex-shrink: 0;
}
#search-input {
  width: 100%;
  padding: 13px 44px 13px 44px;
  font-size: 16px;
  font-family: var(--font);
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 50px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#search-input::placeholder { color: var(--text-faint); }
#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(165,115,104,.15);
}
.clear-btn {
  position: absolute;
  right: 14px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-faint);
  font-size: 15px;
  line-height: 1;
  padding: 4px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
}
.clear-btn:hover { color: var(--text); background: var(--tag-bg); }
.clear-btn.visible { display: flex; }

.search-meta {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-faint);
  text-align: center;
  min-height: 20px;
}

/* ─── Main Grid ─────────────────────────────────────────────────────────── */
main {
  max-width: 1280px;
  margin: 32px auto 80px;
  padding: 0 24px;
}
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* ─── Book Card ─────────────────────────────────────────────────────────── */
.book-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: box-shadow .15s, transform .15s, border-color .15s;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.book-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--border);
  transform: translateY(-1px);
}
.book-num {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: .5px;
  text-transform: uppercase;
}
.book-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  letter-spacing: -.2px;
}
.book-title-es {
  font-size: 13px;
  color: var(--text-soft);
  font-style: italic;
  margin-top: -6px;
}
.book-author {
  font-size: 13px;
  color: var(--text-soft);
}
.book-preview {
  font-size: 13px;
  color: var(--text-soft);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}
.book-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 2px;
}
.tag {
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
}
.book-badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  background: #efe8d8;
  color: #7a5828;
  font-weight: 600;
  letter-spacing: .3px;
  align-self: flex-start;
}

/* ─── Pagination ────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 40px;
  flex-wrap: wrap;
}
.page-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  transition: background .1s, border-color .1s;
}
.page-btn:hover:not(:disabled) { background: var(--tag-bg); border-color: var(--border); }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.page-btn:disabled { opacity: .35; cursor: default; }
.page-ellipsis { color: var(--text-faint); padding: 0 4px; }

/* ─── Empty & Loading ───────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 24px;
  color: var(--text-soft);
  font-size: 16px;
}
.empty-state em { font-style: normal; font-weight: 600; color: var(--text); }

.loading {
  display: flex;
  justify-content: center;
  padding: 80px 0;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── FAB ───────────────────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 52px;
  height: 52px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(165,115,104,.35);
  transition: background .15s, transform .15s;
  z-index: 50;
}
.fab:hover { background: var(--accent-hover); transform: scale(1.06); }
.fab svg { width: 22px; height: 22px; }

/* ─── Modal ─────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(46,30,26,.35);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: 10px;
  max-width: 680px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  padding: 32px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-faint);
  line-height: 1;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: color .1s, background .1s;
}
.modal-close:hover { color: var(--text); background: var(--tag-bg); }

/* Book detail modal */
.modal-book-num  { font-size: 12px; color: var(--text-faint); font-weight: 600; letter-spacing: .5px; text-transform: uppercase; margin-bottom: 8px; }
.modal-book-title { font-size: 22px; font-weight: 700; letter-spacing: -.4px; line-height: 1.3; margin-bottom: 4px; }
.modal-book-title-es { font-size: 16px; color: var(--text-soft); font-style: italic; margin-bottom: 10px; }
.modal-book-author { font-size: 15px; color: var(--text-soft); margin-bottom: 16px; }
.modal-divider { border: none; border-top: 1px solid var(--border-soft); margin: 16px 0; }
.modal-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.modal-body { font-size: 15px; line-height: 1.75; color: var(--text); white-space: pre-wrap; }
.modal-lang-note {
  font-size: 12px;
  color: var(--text-soft);
  margin-top: 16px;
  padding: 8px 12px;
  background: var(--surface-warm);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
}

/* Add / edit form modal */
.modal-form { max-width: 560px; }
.modal-title { font-size: 20px; font-weight: 700; margin-bottom: 24px; letter-spacing: -.3px; }
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text); }
.form-group small { font-size: 12px; color: var(--text-faint); }
.form-group input,
.form-group textarea {
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 13px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface-warm);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  resize: vertical;
}
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(165,115,104,.12);
  background: var(--surface);
}
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.btn-primary, .btn-secondary {
  padding: 9px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--tag-bg); color: var(--text-soft); border: 1px solid var(--border-soft); }
.btn-secondary:hover { background: var(--surface-warm); border-color: var(--border); color: var(--text); }
.form-message { font-size: 13px; margin-top: 12px; padding: 10px 14px; border-radius: var(--radius); display: none; }
.form-message.success { background: #efe8d8; color: #7a5828; display: block; border-left: 3px solid #b39579; }
.form-message.error   { background: #fce8e4; color: #882020; display: block; border-left: 3px solid #c07070; }

/* ─── Modal action bar ──────────────────────────────────────────────────── */
.modal-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
}
.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  color: var(--text-soft);
  transition: background .13s, color .13s, border-color .13s;
  font-family: var(--font);
}
.btn-icon svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-icon:hover { background: var(--tag-bg); color: var(--text); border-color: var(--border); }
.btn-icon.btn-danger { color: #a04040; }
.btn-icon.btn-danger:hover { background: #fce8e4; border-color: #d4a0a0; color: #7a1a1a; }

/* Copy success flash */
.btn-icon.copied { background: #efe8d8; color: #7a5828; border-color: #c8b090; }

/* Delete confirmation modal */
.modal-confirm { max-width: 400px; }
.confirm-text { color: var(--text-soft); font-size: 15px; margin: 10px 0 24px; line-height: 1.5; }
.btn-danger-solid { background: #b84040 !important; color: #fff !important; }
.btn-danger-solid:hover { background: #8a2828 !important; }

/* ─── Header nav ────────────────────────────────────────────────────────── */
.header-nav {
  display: flex;
  gap: 4px;
}
.nav-btn {
  padding: 6px 16px;
  border-radius: 20px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-soft);
  cursor: pointer;
  font-family: var(--font);
  transition: background .13s, color .13s;
}
.nav-btn:hover  { background: var(--tag-bg); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; }

/* ─── Authors / Topics views ─────────────────────────────────────────────── */
.view-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.view-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.3px;
}
.btn-back {
  background: none;
  border: 1px solid var(--border-soft);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-soft);
  font-family: var(--font);
  transition: background .13s, color .13s, border-color .13s;
}
.btn-back:hover { background: var(--tag-bg); color: var(--text); border-color: var(--border); }

/* Authors alphabetical list */
.alpha-list {
  columns: 3;
  column-gap: 24px;
}
@media (max-width: 900px) { .alpha-list { columns: 2; } }
@media (max-width: 540px) { .alpha-list { columns: 1; } }

.author-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 9px 14px;
  margin-bottom: 4px;
  border-radius: var(--radius);
  cursor: pointer;
  break-inside: avoid;
  transition: background .12s, border-color .12s;
  border: 1px solid transparent;
}
.author-item:hover { background: var(--surface); border-color: var(--border-soft); }
.author-name { font-size: 14px; font-weight: 500; color: var(--text); }
.author-count {
  font-size: 11px;
  color: var(--text-faint);
  background: var(--tag-bg);
  padding: 1px 7px;
  border-radius: 10px;
  flex-shrink: 0;
  margin-left: 8px;
}

/* Topics grid */
.topics-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.topic-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 30px;
  cursor: pointer;
  transition: background .13s, border-color .13s, transform .13s;
}
.topic-card:hover {
  background: var(--surface-warm);
  border-color: var(--accent);
  transform: translateY(-1px);
}
.topic-name { font-size: 14px; font-weight: 600; color: var(--text); }
.topic-count {
  font-size: 12px;
  color: var(--text-faint);
  background: var(--tag-bg);
  padding: 2px 8px;
  border-radius: 10px;
}
.topic-card:hover .topic-count { background: var(--border-soft); color: var(--text-soft); }

/* ─── Flat list (Libros / filtered results) ──────────────────────────────── */
.flat-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.list-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s, border-color .12s;
  border: 1px solid transparent;
}
.list-item:hover { background: var(--surface); border-color: var(--border-soft); }
.list-num  { font-size: 11px; color: var(--text-faint); font-weight: 600; text-align: right; }
.list-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.list-title { font-size: 14px; font-weight: 600; color: var(--text);
              white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-title-en { font-size: 12px; color: var(--text-faint); font-style: italic;
                 white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-author { font-size: 13px; color: var(--text-soft); white-space: nowrap; flex-shrink: 0; }
.view-count  { font-size: 13px; color: var(--text-faint); }

.empty-inline {
  color: var(--text-soft);
  font-size: 15px;
  padding: 60px 0;
  text-align: center;
  width: 100%;
}

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .header-inner { flex-wrap: wrap; gap: 8px; height: auto; padding: 10px 16px; }
  .header-nav   { order: 3; width: 100%; justify-content: center; padding-bottom: 4px; }
  .header-stats { font-size: 12px; }
  .search-section { margin-top: 16px; }
  .books-grid { grid-template-columns: 1fr; }
  .modal { padding: 24px; }
  .fab { bottom: 20px; right: 20px; }
}
