:root {
  --ink: #1e1b4b;
  --indigo: #3730a3;
  --indigo-mid: #4338ca;
  --indigo-light: #6366f1;
  --brass: #b45309;
  --lavanda: #e0e7ff;
  --paper: #eef2ff;
  --card: #ffffff;
  --line: #c7d2fe;
  --muted: #5b6478;
  --bg: #f5f7ff;
  --ok: #166534;
  --ok-bg: #dcfce7;
  --warn: #92400e;
  --warn-bg: #fef3c7;
  --bad: #991b1b;
  --bad-bg: #fee2e2;
}

* { box-sizing: border-box; }

html { overflow-x: hidden; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Segoe UI", system-ui, sans-serif;
  line-height: 1.45;
}

body.ficha-open { overflow: hidden; }

a { color: inherit; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }

.top {
  background: var(--indigo);
  color: #f8fafc;
}
.top-inner,
.wrap {
  max-width: 1140px;
  margin: 0 auto;
  padding: 0 24px;
  min-width: 0;
}
.top-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 72px;
  gap: 16px;
  min-width: 0;
}
.logo {
  text-decoration: none;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.logo small {
  display: block;
  font-weight: 500;
  font-size: 11px;
  opacity: 0.85;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.top nav {
  display: flex;
  gap: 8px 16px;
  align-items: center;
  font-size: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}
.top nav a { text-decoration: none; }
.top nav a:not(.btn):hover { text-decoration: underline; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--lavanda);
  color: var(--indigo);
  font-weight: 650;
  text-decoration: none;
  padding: 10px 18px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(55, 48, 163, 0.18);
}
.btn:hover { background: #eef2ff; }
.btn-line {
  background: transparent;
  color: var(--indigo);
  border: 1px solid var(--indigo);
  box-shadow: none;
}
.btn-line:hover { background: var(--lavanda); }
.top .btn {
  background: #e0e7ff;
  color: var(--indigo);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 40px;
  padding: 48px 0 36px;
  align-items: center;
}
.hero > * { min-width: 0; }
.kicker {
  color: var(--brass);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  margin: 0;
}
.top .kicker,
.socio-box .kicker { color: #fde68a; }
h1, h2, h3 { font-weight: 700; letter-spacing: -0.02em; overflow-wrap: anywhere; }
h1 { font-size: clamp(28px, 4vw, 40px); line-height: 1.2; margin: 10px 0 12px; }
h2 { font-size: 26px; margin: 0 0 12px; }
.lead { font-size: 17px; color: var(--muted); max-width: min(36rem, 100%); line-height: 1.55; margin: 0 0 16px; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.hero-photo {
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(55, 48, 163, 0.2);
  min-width: 0;
}
.hero-photo img { width: 100%; height: 280px; object-fit: cover; }

.gallery {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.gallery img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 12px;
}

.section { padding: 36px 0 12px; }
.section h2 { margin-bottom: 12px; }

.modules {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.modules article {
  background: var(--card);
  border-radius: 12px;
  padding: 22px;
  border-left: 4px solid var(--indigo);
  min-width: 0;
}
.modules h3 { margin: 0 0 10px; font-size: 17px; color: var(--indigo); }
.modules p { color: var(--muted); line-height: 1.55; margin: 0 0 6px; font-size: 14px; }

.catalog-header {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
}
.catalog-tools {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.search-box { width: 100%; max-width: 420px; }
.search-box input,
.stats input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}
.filters { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-start; }
.filters button {
  background: var(--card);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
}
.filters button:hover { border-color: var(--indigo-mid); }
.filters button.active {
  background: var(--indigo);
  color: white;
  border-color: var(--indigo);
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 16px;
}
.books-grid.is-empty { display: block; }
.book-card {
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(55, 48, 163, 0.08);
  cursor: pointer;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  min-width: 0;
  text-align: left;
}
.book-card:hover,
.book-card:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(55, 48, 163, 0.16);
  outline: none;
  border-color: var(--lavanda);
}
.book-card .cover-wrap {
  aspect-ratio: 2 / 3;
  background: linear-gradient(160deg, #c7d2fe, #818cf8);
  overflow: hidden;
}
.book-card .cover-wrap img,
.cover-fallback {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cover-fallback {
  display: grid;
  place-items: center;
  color: var(--indigo);
  font-size: 42px;
  font-weight: 700;
  background: linear-gradient(160deg, #c7d2fe, #a5b4fc);
}
.book-card .info {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.book-card h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-card .autor {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.empty-catalog {
  background: var(--card);
  border-radius: 12px;
  padding: 32px;
  text-align: center;
  color: var(--muted);
  grid-column: 1 / -1;
}

.disponibilidad {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  display: inline-block;
  font-weight: 700;
  margin-top: auto;
  width: fit-content;
}
.disponibilidad.disponible { background: var(--ok-bg); color: var(--ok); }
.disponibilidad.prestado { background: var(--bad-bg); color: var(--bad); }
.disponibilidad.reservado { background: var(--warn-bg); color: var(--warn); }

.socio-box {
  background: linear-gradient(135deg, var(--indigo) 0%, var(--indigo-light) 100%);
  color: white;
  padding: 28px;
  border-radius: 12px;
  margin-top: 28px;
}
.socio-box h3 { margin: 0 0 8px; }
.socio-box p { margin: 0 0 8px; opacity: 0.95; }
.admin-link {
  text-align: center;
  margin-top: 28px;
  padding: 24px;
  background: var(--card);
  border-radius: 12px;
}

.reserva-card {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 2px 12px rgba(55, 48, 163, 0.08);
}
.reserva-card form { display: grid; gap: 12px; }
.reserva-card .row-2 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}
.form-error { color: #b42318; font-size: 13px; min-height: 1.2em; margin: 0; }

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
}
.modal-back[hidden] { display: none; }
.ficha {
  position: relative;
  background: white;
  border-radius: 16px;
  max-width: 720px;
  width: 100%;
  max-height: min(90vh, 760px);
  display: grid;
  grid-template-columns: minmax(0, 220px) minmax(0, 1fr);
  overflow: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.ficha .ficha-cover { background: var(--lavanda); min-width: 0; }
.ficha .ficha-cover img,
.ficha .ficha-cover .cover-fallback {
  width: 100%;
  height: 100%;
  min-height: 280px;
  object-fit: cover;
}
.ficha .ficha-body {
  padding: 28px 28px 24px;
  min-width: 0;
}
.ficha .ficha-body h2 {
  margin: 8px 40px 6px 0;
  font-size: 22px;
  line-height: 1.25;
}
.ficha .close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 18px;
  background: #eef2ff;
  cursor: pointer;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}
.ficha-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  margin: 16px 0;
  font-size: 14px;
}
.ficha-meta span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.ficha-meta strong { font-weight: 700; word-break: break-word; }

.table-wrap { overflow-x: auto; min-width: 0; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}
th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  background: #f8fafc;
}
td, th { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: #f5f7ff; }

.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.tag.disponible { background: var(--ok-bg); color: var(--ok); }
.tag.prestado { background: var(--lavanda); color: var(--indigo); }
.tag.reservado { background: var(--warn-bg); color: var(--warn); }
.tag.reparacion { background: #f3f4f6; color: #374151; }
.tag.activo { background: var(--lavanda); color: var(--indigo); }
.tag.vencido { background: var(--bad-bg); color: var(--bad); }
.tag.devuelto { background: #e5e7eb; color: #374151; }
.tag.pendiente { background: var(--warn-bg); color: var(--warn); }
.tag.lista { background: #dbeafe; color: #1e40af; }
.tag.cumplida,
.tag.cancelada { background: #e5e7eb; color: #374151; }

footer,
.panel-foot {
  padding: 36px 24px 48px;
  color: var(--muted);
  font-size: 14px;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto auto auto minmax(420px, 1fr);
  min-width: 0;
}
.app > * { min-width: 0; }
.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  padding: 20px 24px 10px;
  background: var(--paper);
  flex-wrap: wrap;
}
.toolbar h1 { font-size: 24px; margin: 4px 0 0; }
.eyebrow {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.tabs {
  display: flex;
  gap: 0;
  padding: 0 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tabs button {
  background: transparent;
  border: none;
  padding: 12px 18px;
  font-weight: 650;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
}
.tabs button.on {
  color: var(--indigo);
  border-bottom-color: var(--indigo);
}

.stats {
  display: flex;
  gap: 8px;
  padding: 12px 24px;
  flex-wrap: wrap;
  background: var(--paper);
  align-items: center;
}
.stats button,
.stats div {
  background: white;
  border: 1px solid var(--line);
  padding: 8px 12px;
  min-width: 0;
  flex: 1 1 140px;
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
}
.stats strong { display: block; font-size: 18px; color: var(--indigo); }
.stats .on { border-color: var(--indigo); background: var(--lavanda); }
.stats input {
  flex: 1 1 220px;
  width: auto;
  min-width: 0;
  max-width: 100%;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  min-height: 0;
  background: var(--paper);
}
.list { padding: 0 24px 32px; overflow: auto; min-width: 0; }
.row { cursor: pointer; }
.row.on { background: var(--lavanda); }
.thumb {
  width: 36px;
  height: 52px;
  object-fit: cover;
  border-radius: 3px;
  background: var(--lavanda);
}

.detail {
  background: white;
  border-left: 1px solid var(--line);
  padding: 16px 24px 32px;
  overflow: auto;
  min-width: 0;
}
.detail h2 { font-size: 18px; margin: 0 0 4px; }
.detail-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 8px;
}
.cover-lg {
  width: 88px;
  height: 128px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--lavanda);
  flex-shrink: 0;
}
.cover-lg.cover-fallback {
  height: 128px;
  font-size: 28px;
}
.lead-sm { color: var(--muted); font-size: 14px; margin: 0; }
.meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  margin: 12px 0;
  font-size: 14px;
}
.meta span { display: block; color: var(--muted); font-size: 12px; }

label { display: block; font-size: 13px; color: var(--muted); margin-top: 10px; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
}
.actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.ghost {
  background: white;
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
}
.ghost:hover { border-color: var(--indigo-mid); }
.btn-panel {
  background: var(--indigo);
  color: white;
  border: 0;
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 650;
}
.btn-panel:hover { background: #312e81; }
.btn-danger {
  background: #991b1b;
  color: white;
  border: 0;
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
}

.multa-box {
  background: var(--bad-bg);
  border: 1px solid #fca5a5;
  border-radius: 8px;
  padding: 12px;
  margin: 12px 0;
  font-size: 13px;
}
.multa-box h4 { margin: 0 0 8px; font-size: 13px; color: var(--bad); }
.prestamo-section {
  background: var(--lavanda);
  border: 1px solid #a5b4fc;
  border-radius: 8px;
  padding: 12px;
  margin: 12px 0;
}
.prestamo-section h4 { margin: 0 0 8px; font-size: 13px; color: var(--indigo); }
.amount { text-align: right; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1e1b4b;
  color: white;
  padding: 14px 28px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  max-width: calc(100% - 32px);
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

@media (max-width: 960px) {
  .hero,
  .modules,
  .workspace,
  .ficha,
  .reserva-card .row-2,
  .gallery,
  .ficha-meta,
  .meta {
    grid-template-columns: minmax(0, 1fr);
  }
  .top-inner,
  .toolbar { align-items: stretch; }
  .top nav,
  .toolbar-actions,
  .filters { justify-content: flex-start; }
  .search-box { max-width: none; }
  .hero-photo img { height: 200px; }
  .ficha .ficha-cover img,
  .ficha .ficha-cover .cover-fallback {
    min-height: 200px;
    max-height: 260px;
  }
  .detail { border-left: 0; border-top: 1px solid var(--line); }
  .toolbar-actions { width: 100%; }
  .toolbar-actions button { flex: 1 1 calc(50% - 8px); }
  .toolbar-actions .btn-panel { flex: 1 1 100%; }
}

@media (max-width: 640px) {
  .top-inner,
  .wrap { padding: 0 16px; }
  .top-inner { padding-top: 12px; padding-bottom: 12px; flex-direction: column; align-items: stretch; }
  .top nav { justify-content: flex-start; }
  .top nav a.btn { width: 100%; }
  .toolbar,
  .tabs,
  .stats,
  .list,
  .detail { padding-left: 16px; padding-right: 16px; }
  .hero { padding-top: 28px; }
  .books-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .gallery { grid-template-columns: 1fr; }
  .gallery img { height: 140px; }

  .list table { box-shadow: none; background: transparent; }
  .list thead { display: none; }
  .list tr {
    display: block;
    background: white;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
  }
  .list td {
    border: 0;
    padding: 6px 0;
    display: grid;
    grid-template-columns: 7rem minmax(0, 1fr);
    align-items: start;
    gap: 8px;
    overflow-wrap: anywhere;
  }
  .list td.thumb-cell {
    display: block;
    padding-bottom: 8px;
  }
  .list td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
  }
  .list td.thumb-cell::before { content: none; }
}
