:root {
  --color-bg: 249 250 251;
  --color-surface: 255 255 255;
  --color-surface-muted: 243 244 246;
  --color-text: 17 24 39;
  --color-text-secondary: 75 85 99;
  --color-muted: 107 114 128;
  --color-border: 229 231 235;
  --color-primary: 37 99 235;
  --color-primary-hover: 29 78 216;
  --color-accent: 124 58 237;
  --color-success: 22 163 74;
  --color-warning: 180 83 9;
  --color-danger: 220 38 38;
  --radius: 12px;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.08);
  --shadow-md: 0 4px 12px rgb(0 0 0 / 0.1);
}

.dark {
  --color-bg: 17 24 39;
  --color-surface: 31 41 55;
  --color-surface-muted: 55 65 81;
  --color-text: 243 244 246;
  --color-text-secondary: 209 213 219;
  --color-muted: 156 163 175;
  --color-border: 75 85 99;
  --color-primary: 96 165 250;
  --color-primary-hover: 147 197 253;
  --color-accent: 167 139 250;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: rgb(var(--color-bg));
  color: rgb(var(--color-text));
  line-height: 1.5;
  min-height: 100dvh;
}

button, input, select { font: inherit; }

.hidden { display: none !important; }

.app-shell {
  max-width: 960px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar,
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgb(var(--color-surface));
  border-bottom: 1px solid rgb(var(--color-border));
}

.app-header-meta {
  margin: 0.35rem 1rem 0.5rem;
  font-size: 0.8rem;
}

.app-header-meta.subtle-banner {
  background: rgb(var(--color-surface-muted));
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius);
  padding: 0.45rem 0.75rem;
}

.app-header .topbar-row {
  padding: 0.75rem 1rem 0;
}

.app-header .tabs {
  padding: 0.5rem 1rem 0;
  border-bottom: none;
  background: transparent;
}

.app-header-toolbar {
  padding: 0 1rem 0.5rem;
}

.toolbar-toggle-row {
  padding: 0.15rem 1rem 0.35rem;
  font-size: 0.82rem;
}

.topbar {
  padding: 0.75rem 1rem 0.5rem;
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.topbar h1,
.topbar h1.app-title,
.app-header h1.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.app-title-icon {
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
}

.app-title span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sync-update-banner .link-btn {
  margin-left: 0.35rem;
}

.icon-btn.local-app-btn { font-size: 1rem; opacity: 0.85; }
.icon-btn.local-app-btn.local-app-online { color: rgb(var(--color-primary)); opacity: 1; }
.icon-btn.local-app-btn.local-app-offline { opacity: 0.45; }
.local-app-ajuste { margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid rgb(var(--color-border)); }
.local-app-ajuste-title { font-size: 0.9rem; margin: 0 0 0.35rem; }
.local-app-url.mono { font-size: 0.78rem; word-break: break-all; color: rgb(var(--color-muted)); margin: 0.35rem 0 0.5rem; }
.local-app-ajuste-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; align-items: center; }

.icon-btn {
  border: none;
  background: rgb(var(--color-surface-muted));
  color: rgb(var(--color-text-secondary));
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.65rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

.search-bar { margin-top: 0.65rem; }

.search-bar input {
  width: 100%;
  border: 1px solid rgb(var(--color-border));
  background: rgb(var(--color-surface));
  color: rgb(var(--color-text));
  border-radius: 999px;
  padding: 0.55rem 1rem;
}

.filters {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.55rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.filters select {
  border: 1px solid rgb(var(--color-border));
  background: rgb(var(--color-surface));
  color: rgb(var(--color-text));
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.tabs {
  display: flex;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid rgb(var(--color-border));
  background: rgb(var(--color-surface));
}

.tab {
  border: none;
  background: transparent;
  color: rgb(var(--color-muted));
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

.tab.active {
  background: rgb(var(--color-primary) / 0.12);
  color: rgb(var(--color-primary));
}

.content { flex: 1; padding: 1rem; }

.meta-banner {
  background: rgb(var(--color-surface-muted));
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: rgb(var(--color-text-secondary));
  margin-bottom: 1rem;
}

.grid-libros {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.85rem;
}

.card-libro {
  background: rgb(var(--color-surface));
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}

.card-libro:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.portada-wrap {
  aspect-ratio: 2/3;
  background: rgb(var(--color-surface-muted));
  position: relative;
  overflow: hidden;
}

.portada-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.portada-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgb(var(--color-muted));
  font-size: 2rem;
  background: linear-gradient(135deg, rgb(var(--color-surface-muted)), rgb(var(--color-border)));
}

.card-body {
  padding: 0.65rem 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.card-body h3 {
  font-size: 0.9rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-body p {
  font-size: 0.78rem;
  color: rgb(var(--color-text-secondary));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  width: fit-content;
}

.badge.estado-no_iniciado { background: #f3f4f6; color: #374151; }
.badge.estado-en_progreso { background: #dbeafe; color: #1d4ed8; }
.badge.estado-completado { background: #dcfce7; color: #15803d; }
.badge.estado-pausado { background: #fef3c7; color: #b45309; }
.badge.estado-abandonado { background: #fee2e2; color: #b91c1c; }

.dark .badge.estado-no_iniciado { background: #374151; color: #e5e7eb; }

.etiquetas-row { display: flex; flex-wrap: wrap; gap: 0.25rem; }

.etiqueta {
  font-size: 0.68rem;
  color: white;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
}

.lista-card, .ubicacion-card {
  background: rgb(var(--color-surface));
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 0.65rem;
  cursor: pointer;
}

.lista-card-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.badge-inteligente {
  background: rgb(var(--color-accent) / 0.15);
  color: rgb(var(--color-accent));
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}

.ubicaciones-tree {
  background: rgb(var(--color-surface));
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius);
  padding: 0.5rem 0;
}

.ubicacion-node {
  --indent: calc(var(--depth, 0) * 1rem);
}

.ubicacion-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 1rem 0.55rem calc(1rem + var(--indent));
  border-bottom: 1px solid rgb(var(--color-border) / 0.6);
}

.ubicacion-node:last-child > .ubicacion-row:last-of-type {
  border-bottom: none;
}

.ubicacion-nombre {
  font-size: 0.92rem;
  font-weight: 500;
  min-width: 0;
}

.ubicacion-count {
  font-size: 0.78rem;
  color: rgb(var(--color-muted));
  white-space: nowrap;
  background: rgb(var(--color-surface-muted));
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.lista-card:hover, .ubicacion-card:hover { border-color: rgb(var(--color-primary)); }

.lista-card h3, .ubicacion-card h3 { font-size: 0.95rem; }

.lista-card p, .ubicacion-card p {
  font-size: 0.82rem;
  color: rgb(var(--color-muted));
  margin-top: 0.25rem;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: rgb(var(--color-muted));
}

.pagination {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
}

.pagination button {
  border: 1px solid rgb(var(--color-border));
  background: rgb(var(--color-surface));
  color: rgb(var(--color-text));
  padding: 0.4rem 0.85rem;
  border-radius: 0.5rem;
  cursor: pointer;
}

.pagination button:disabled { opacity: 0.45; cursor: not-allowed; }

.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: rgb(var(--color-surface));
  border: 1px solid rgb(var(--color-border));
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
}

.login-card h1 { font-size: 1.35rem; margin-bottom: 0.35rem; }

.login-card p {
  color: rgb(var(--color-muted));
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}

.login-card input {
  width: 100%;
  border: 1px solid rgb(var(--color-border));
  border-radius: 0.65rem;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.75rem;
  background: rgb(var(--color-bg));
  color: rgb(var(--color-text));
}

.login-card button[type="submit"],
.google-login-btn {
  display: block;
  width: 100%;
  border: none;
  background: rgb(var(--color-primary));
  color: white;
  padding: 0.7rem;
  border-radius: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}

.login-card button[type="submit"] {
  width: 100%;
}

.login-error {
  color: rgb(var(--color-danger));
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.45);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0.75rem 0 1rem;
}

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 1.5rem; }
}

.modal-panel {
  background: rgb(var(--color-surface));
  width: 100%;
  max-width: 640px;
  max-height: calc(100dvh - 1.5rem);
  overflow: auto;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.25rem 1rem 2rem;
  margin: 0 auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 640px) {
  .modal-panel {
    border-radius: var(--radius);
    max-height: calc(100dvh - 3rem);
    padding: 1.25rem 1.25rem 1.75rem;
  }
}

.modal-header {
  display: flex;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.modal-header .portada-wrap {
  width: 96px;
  flex-shrink: 0;
  border-radius: 0.5rem;
}

.modal-header-text h2 { font-size: 1.15rem; line-height: 1.3; }

.modal-header-text p {
  color: rgb(var(--color-text-secondary));
  font-size: 0.9rem;
}

.modal-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgb(var(--color-border));
}

.modal-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgb(var(--color-muted));
  margin-bottom: 0.5rem;
}

.modal-section p { font-size: 0.92rem; color: rgb(var(--color-text-secondary)); }
.modal-prosa { white-space: pre-wrap; line-height: 1.55; }
.modal-autor { font-size: 0.95rem; color: rgb(var(--color-text-secondary)); margin-bottom: 0.35rem; }
.modal-rating { color: #eab308; margin-left: 0.35rem; }
.modal-etiquetas { margin: 0 0 0.75rem; padding: 0 0.25rem; }

.modal-toolbar {
  display: flex;
  gap: 0.5rem;
  padding: 0 0.75rem 0.5rem;
}

.cloud-edit-badge,
.diario-cloud-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  background: rgb(var(--color-primary) / 0.12);
  color: rgb(var(--color-primary));
}

.lite-edit-form {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}

.lite-edit-form h4 {
  grid-column: 1 / -1;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgb(var(--color-muted));
  margin: 0.35rem 0 0;
}

.lite-field-check {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
}

.lite-field-check input[type="checkbox"] {
  width: auto;
  accent-color: rgb(var(--color-primary));
}

.lite-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.82rem;
}

.lite-field-wide { grid-column: 1 / -1; }

.lite-field span {
  color: rgb(var(--color-muted));
  font-weight: 600;
}

.lite-field input,
.lite-field select,
.lite-field textarea {
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid rgb(var(--color-border));
  border-radius: 0.4rem;
  background: rgb(var(--color-surface));
  color: rgb(var(--color-text));
  font-size: 0.88rem;
}

.lite-edit-hint { margin: 0.25rem 0 0.65rem; font-size: 0.78rem; }

.lite-edit-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.lite-nota-form {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgb(var(--color-border));
}

.diario-entry-cloud { border-left: 3px solid rgb(var(--color-primary) / 0.45); padding-left: 0.5rem; }

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
}
.diario-tipo { display: inline-block; margin-left: 0.5rem; font-size: 0.72rem; color: rgb(var(--color-muted)); text-transform: uppercase; }

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 1rem;
}

.meta-item span {
  display: block;
  font-size: 0.72rem;
  color: rgb(var(--color-muted));
  text-transform: uppercase;
}

.diario-entry {
  background: rgb(var(--color-surface-muted));
  border-radius: 0.65rem;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
}

.diario-entry time {
  display: block;
  font-size: 0.75rem;
  color: rgb(var(--color-muted));
  margin-bottom: 0.35rem;
}

.audio-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.72rem;
  color: rgb(var(--color-accent));
  margin-bottom: 0.35rem;
}

.close-modal {
  position: sticky;
  top: 0;
  float: right;
  margin-bottom: 0.5rem;
}

.loading {
  text-align: center;
  padding: 2rem;
  color: rgb(var(--color-muted));
}

/* Toolbar, vistas y filtros */
.toolbar-row { flex-wrap: wrap; align-items: center; }
.view-toggle { display: inline-flex; border: 1px solid rgb(var(--color-border)); border-radius: 999px; overflow: hidden; margin-left: auto; }
.view-btn { border: none; background: transparent; padding: 0.35rem 0.55rem; cursor: pointer; color: rgb(var(--color-muted)); font-size: 0.85rem; }
.view-btn.active { background: rgb(var(--color-primary) / 0.15); color: rgb(var(--color-primary)); }
.filters-advanced-toggle { display: flex; gap: 0.75rem; margin-top: 0.35rem; font-size: 0.82rem; }
.filters-advanced { margin-top: 0.5rem; }
.filter-check { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.82rem; color: rgb(var(--color-text-secondary)); }
.link-btn { border: none; background: none; color: rgb(var(--color-primary)); cursor: pointer; font: inherit; padding: 0; }
.filter-chip { font-size: 0.82rem; color: rgb(var(--color-text-secondary)); margin-top: 0.35rem; }
.hint-text { font-size: 0.85rem; color: rgb(var(--color-muted)); margin-bottom: 0.75rem; line-height: 1.45; }
.section-title { font-size: 1rem; margin-bottom: 0.75rem; }
.back-btn { border: none; background: none; color: rgb(var(--color-primary)); cursor: pointer; font: inherit; margin-bottom: 0.75rem; padding: 0; }

.subtle-banner { background: transparent; border: none; padding: 0 0 0.75rem; }
.warn-banner { border-color: #fde68a; background: #fffbeb; color: #92400e; }
.error-banner { border-color: #fecaca; background: #fef2f2; color: #b91c1c; }
.ok-banner { border-color: #bbf7d0; background: #f0fdf4; color: #15803d; }

.publish-cloud-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  border: none;
  border-radius: 0;
  border-bottom: 1px solid #0284c7;
  background: linear-gradient(90deg, #0284c7, #4f46e5);
  color: #fff;
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 25;
}
.publish-cloud-detail { font-size: 0.88rem; opacity: 0.95; flex: 1; min-width: 12rem; }
.publish-cloud-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.btn-publish-drive {
  border: none;
  background: #fff;
  color: #0369a1;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.45rem 0.85rem;
  border-radius: 0.45rem;
  cursor: pointer;
}
.btn-publish-drive:hover:not(:disabled) { background: #f0f9ff; }
.btn-publish-drive:disabled {
  opacity: 0.75;
  cursor: wait;
}
.publish-cloud-banner .link-btn { color: #e0f2fe; }

/* Vistas biblioteca */
.list-libros { display: flex; flex-direction: column; gap: 0.5rem; }
.card-lista { flex-direction: row; align-items: center; }
.card-lista .portada-wrap { width: 3.5rem; flex-shrink: 0; aspect-ratio: 2/3; }
.card-lista .card-body { padding: 0.5rem 0.75rem; }
.grid-compact { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.5rem; }
.card-compact .card-body h3 { font-size: 0.78rem; -webkit-line-clamp: 2; }
.card-compact .card-body p { font-size: 0.7rem; }
.portada-sm { aspect-ratio: 2/3; }
.portada-xs { width: 2.5rem; aspect-ratio: 2/3; flex-shrink: 0; }
.page-info { align-self: center; font-size: 0.82rem; color: rgb(var(--color-muted)); }
.page-info.solo { text-align: center; margin-top: 0.75rem; }

/* Tabla de libros */
.tabla-libros-wrap,
.tabla-scroll-outer {
  position: relative;
  border: 1px solid rgb(var(--color-border));
  border-radius: var(--radius);
  background: rgb(var(--color-surface));
}
.tabla-scroll-wrap {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  touch-action: pan-x pan-y;
  scrollbar-gutter: stable;
}
.tabla-scroll-head {
  overflow: hidden;
  pointer-events: none;
}
.tabla-scroll-head .tabla-sortable {
  pointer-events: auto;
  cursor: pointer;
}
.tabla-thead-sticky {
  position: sticky;
  top: var(--cloud-table-sticky-top, var(--cloud-sticky-top, 0));
  z-index: 20;
  background: rgb(var(--color-surface-muted));
  border-bottom: 1px solid rgb(var(--color-border));
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.08);
}
.tabla-thead-sticky .tabla-scroll-controls {
  pointer-events: auto;
}
.tabla-scroll-controls {
  position: sticky;
  right: 0;
  z-index: 7;
  white-space: nowrap;
  padding: 0.2rem 0.35rem !important;
  background: rgb(var(--color-surface-muted));
  box-shadow: -4px 0 8px rgb(0 0 0 / 0.06);
  vertical-align: middle;
}
.tabla-scroll-controls-spacer {
  visibility: hidden;
  padding: 0;
  border: none;
  overflow: hidden;
}
.tabla-scroll-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  margin: 0 0.1rem;
  border-radius: 0.35rem;
  border: 1px solid rgb(var(--color-border));
  background: rgb(var(--color-surface));
  color: rgb(var(--color-text-secondary));
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}
.tabla-scroll-btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}
.tabla-scroll-outer:not(.tabla-scroll-left) .tabla-scroll-btn-left,
.tabla-scroll-outer:not(.tabla-scroll-right) .tabla-scroll-btn-right {
  opacity: 0.35;
  pointer-events: none;
}
@media (hover: none) and (pointer: coarse) {
  .tabla-scroll-btn {
    width: 1.85rem;
    height: 1.85rem;
    font-size: 1.15rem;
  }
  .tabla-scroll-outer.tabla-scroll-left .tabla-scroll-btn-left,
  .tabla-scroll-outer.tabla-scroll-right .tabla-scroll-btn-right {
    opacity: 1;
    pointer-events: auto;
  }
}
.tabla-libros {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
}
.tabla-libros th {
  text-align: left;
  padding: 0.45rem 0.55rem;
  background: rgb(var(--color-surface-muted));
  color: rgb(var(--color-muted));
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 1px solid rgb(var(--color-border));
}
.tabla-libros-head th {
  border-bottom: none;
}
.tabla-libros thead .tabla-sticky-portada,
.tabla-libros thead .tabla-scroll-controls {
  z-index: 2;
}
.tabla-sticky-portada {
  position: sticky;
  left: 0;
  z-index: 2;
  background: rgb(var(--color-surface));
  box-shadow: 2px 0 6px rgb(0 0 0 / 0.05);
}
.tabla-libros-head .tabla-sticky-portada {
  background: rgb(var(--color-surface-muted));
}
.tabla-libros-body .tabla-sticky-portada {
  z-index: 1;
}
.tabla-libros td {
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid rgb(var(--color-border));
  vertical-align: middle;
  background: rgb(var(--color-surface));
}
.tabla-libro-row { cursor: pointer; transition: background 0.12s; }
.tabla-libro-row:hover td { background: rgb(var(--color-primary) / 0.06); }
.tabla-portada-head,
.tabla-portada { width: 2.5rem; padding: 0.3rem !important; }
.portada-thumb { width: 2rem; height: 3rem; object-fit: cover; border-radius: 0.25rem; display: block; }
.tabla-titulo { font-weight: 600; white-space: normal; line-height: 1.3; max-width: 14rem; }
.tabla-autor { color: rgb(var(--color-text-secondary)); max-width: 11rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabla-prim { white-space: nowrap; }
.tabla-fecha { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tabla-sec { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: rgb(var(--color-text-secondary)); }
.tabla-ruta { max-width: 12rem; font-size: 0.78rem; }
.tabla-etiq { max-width: 9rem; }

/* Mosaico de portadas */
.mosaico-zoom-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 0.55rem;
  font-size: 0.82rem;
  color: rgb(var(--color-text-secondary));
}
.biblioteca-extra-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  margin-top: 0.55rem;
  font-size: 0.82rem;
  color: rgb(var(--color-text-secondary));
}
.per-page-label { display: inline-flex; align-items: center; gap: 0.35rem; }
.per-page-label select {
  border: 1px solid rgb(var(--color-border));
  background: rgb(var(--color-surface));
  color: inherit;
  border-radius: 0.45rem;
  padding: 0.25rem 0.4rem;
  font: inherit;
}
.tabla-sortable { cursor: pointer; user-select: none; }
.tabla-sortable:hover { color: rgb(var(--color-primary)); }
.sort-icon { margin-left: 0.15rem; font-size: 0.72rem; }
.sort-icon.muted { opacity: 0.35; }
.hueco-item { cursor: default; }
.mosaico-zoom-label { flex-shrink: 0; }
.mosaico-zoom-row input[type="range"] { flex: 1; max-width: 12rem; }
.mosaico-zoom-val { min-width: 3rem; font-variant-numeric: tabular-nums; }
.columnas-tabla-wrap { position: relative; }
.columnas-tabla-btn { font-size: 1rem; line-height: 1; }
.columnas-tabla-panel {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  z-index: 40;
  min-width: 11rem;
  max-width: 14rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid rgb(var(--color-border));
  background: rgb(var(--color-surface));
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
}
.columnas-tabla-panel.hidden { display: none; }
.columnas-tabla-title {
  margin: 0 0 0.45rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgb(var(--color-muted));
}
.columnas-tabla-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 14rem;
  overflow-y: auto;
  margin-bottom: 0.45rem;
}
.columnas-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}
.columnas-check.disabled { opacity: 0.45; cursor: not-allowed; }
.columnas-check input { accent-color: rgb(var(--color-primary)); }
.columnas-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  justify-content: space-between;
  border-radius: 0.35rem;
  padding: 0.1rem 0;
}
.columnas-row.muted { opacity: 0.55; }
.columnas-row.drag-over {
  outline: 2px solid rgb(var(--color-primary) / 0.45);
  background: rgb(var(--color-primary) / 0.06);
}
.columnas-row.dragging { opacity: 0.45; }
.columnas-drag-handle {
  flex-shrink: 0;
  cursor: grab;
  color: rgb(var(--color-muted));
  font-size: 0.85rem;
  padding: 0.15rem 0.2rem;
  touch-action: none;
  user-select: none;
}
.columnas-drag-handle:active { cursor: grabbing; }
.columnas-mover { display: flex; gap: 0.1rem; flex-shrink: 0; }
.col-move-btn {
  border: none;
  background: transparent;
  color: rgb(var(--color-muted));
  font-size: 0.65rem;
  padding: 0.15rem 0.25rem;
  cursor: pointer;
  border-radius: 0.2rem;
}
.col-move-btn:hover:not(:disabled) { background: rgb(var(--color-surface-muted)); }
.col-move-btn:disabled { opacity: 0.3; cursor: default; }
.columnas-tabla-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-top: 0.15rem;
}
.btn-columnas-apply {
  border: none;
  background: rgb(var(--color-primary));
  color: #fff;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: 0.35rem;
  cursor: pointer;
}
.btn-columnas-apply:hover { filter: brightness(1.05); }
.mosaico-libros {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--mosaico-celda, 88px), 1fr));
  gap: 0;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid rgb(var(--color-border));
}
.mosaico-celda {
  position: relative;
  aspect-ratio: 2/3;
  padding: 0;
  border: none;
  cursor: pointer;
  background: rgb(var(--color-surface-muted));
  overflow: hidden;
}
.mosaico-celda img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.mosaico-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.15rem;
  padding: 0.45rem;
  background: linear-gradient(transparent 30%, rgb(0 0 0 / 0.85));
  color: #fff;
  font-size: 0.68rem;
  line-height: 1.25;
  opacity: 0;
  transition: opacity 0.15s;
  text-align: left;
}
.mosaico-celda:hover .mosaico-overlay,
.mosaico-celda:focus-visible .mosaico-overlay { opacity: 1; }
.mosaico-overlay strong { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mosaico-overlay em { font-style: normal; opacity: 0.9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Árbol de ubicaciones en biblioteca */
.ubic-arbol-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.65rem;
}
.btn-sm { padding: 0.35rem 0.65rem !important; font-size: 0.78rem !important; }
.ubic-arbol { display: flex; flex-direction: column; gap: 0.25rem; }
.ubic-arbol-node { margin-left: calc(var(--depth, 0) * 1rem); }
.ubic-arbol-toggle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  text-align: left;
  border: 1px solid rgb(var(--color-border));
  background: rgb(var(--color-surface));
  border-radius: 0.5rem;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  font: inherit;
  color: rgb(var(--color-text));
}
.ubic-arbol-toggle:hover { border-color: rgb(var(--color-primary)); background: rgb(var(--color-primary) / 0.04); }
.ubic-arbol-icon { width: 1rem; color: rgb(var(--color-muted)); flex-shrink: 0; }
.ubic-arbol-nombre { font-weight: 600; flex: 1; min-width: 0; }
.ubic-arbol-count { font-size: 0.78rem; color: rgb(var(--color-muted)); flex-shrink: 0; }
.ubic-arbol-body { margin: 0.35rem 0 0.5rem 1.25rem; display: flex; flex-direction: column; gap: 0.35rem; }
.ubic-libro-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  text-align: left;
  border: 1px solid rgb(var(--color-border));
  background: rgb(var(--color-surface));
  border-radius: 0.45rem;
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.ubic-libro-row:hover { border-color: rgb(var(--color-primary)); }
.ubic-libro-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.1rem; }
.ubic-libro-info strong { font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ubic-libro-info em { font-size: 0.78rem; color: rgb(var(--color-text-secondary)); font-style: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ubic-sin-ubicar .ubic-arbol-toggle { border-style: dashed; }

.sync-actions { flex-wrap: wrap; }

/* Diario global */
.diario-list { display: flex; flex-direction: column; gap: 0.65rem; }
.diario-card { background: rgb(var(--color-surface)); border: 1px solid rgb(var(--color-border)); border-radius: var(--radius); padding: 0.85rem; cursor: pointer; }
.diario-card:hover { border-color: rgb(var(--color-primary)); }
.diario-card-head { display: flex; gap: 0.65rem; align-items: flex-start; margin-bottom: 0.5rem; }
.diario-card-head h3 { font-size: 0.92rem; }
.diario-meta { font-size: 0.78rem; color: rgb(var(--color-muted)); }
.diario-extracto { font-size: 0.88rem; color: rgb(var(--color-text-secondary)); line-height: 1.45; }

/* Estadísticas */
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; margin-bottom: 1rem; }
.kpi-card { background: rgb(var(--color-surface)); border: 1px solid rgb(var(--color-border)); border-radius: var(--radius); padding: 0.85rem; }
.kpi-label { display: block; font-size: 0.72rem; color: rgb(var(--color-muted)); text-transform: uppercase; }
.kpi-value { display: block; font-size: 1.5rem; font-weight: 700; margin-top: 0.15rem; }
.stats-section { margin-bottom: 1.25rem; }
.stats-section h2 { font-size: 0.9rem; margin-bottom: 0.5rem; color: rgb(var(--color-text-secondary)); }
.bar-list { display: flex; flex-direction: column; gap: 0.4rem; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) 2fr auto; gap: 0.5rem; align-items: center; font-size: 0.82rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 0.45rem; background: rgb(var(--color-surface-muted)); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: rgb(var(--color-primary)); border-radius: 999px; }
.bar-count { color: rgb(var(--color-muted)); font-variant-numeric: tabular-nums; }
.stats-extras { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; font-size: 0.82rem; color: rgb(var(--color-muted)); }
.stats-salud { background: rgb(var(--color-surface)); border: 1px solid rgb(var(--color-border)); border-radius: var(--radius); padding: 1rem; }
.salud-bar-wrap { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.85rem; }
.salud-bar { flex: 1; height: 0.55rem; background: rgb(var(--color-surface-muted)); border-radius: 999px; overflow: hidden; }
.salud-bar-fill { height: 100%; background: linear-gradient(90deg, rgb(var(--color-primary)), rgb(var(--color-success))); border-radius: 999px; }
.salud-pct { font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.huecos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 0.45rem; }
.hueco-item { display: flex; flex-direction: column; gap: 0.1rem; padding: 0.45rem 0.55rem; background: rgb(var(--color-surface-muted)); border-radius: 0.45rem; font-size: 0.78rem; }
.hueco-label { font-weight: 600; }
.hueco-count { color: rgb(var(--color-muted)); }
.muted { color: rgb(var(--color-muted)); font-size: 0.88rem; }

/* Más / Sincronizar */
.mas-menu { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.65rem; }
.mas-card { display: flex; flex-direction: column; align-items: flex-start; gap: 0.25rem; background: rgb(var(--color-surface)); border: 1px solid rgb(var(--color-border)); border-radius: var(--radius); padding: 1rem; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.mas-card:hover { border-color: rgb(var(--color-primary)); }
.mas-card span { font-weight: 600; font-size: 0.95rem; }
.mas-card small { font-size: 0.78rem; color: rgb(var(--color-muted)); }

.sync-section { max-width: 36rem; }
.sync-steps { display: flex; flex-direction: column; gap: 0.75rem; margin: 1rem 0; }
.sync-step { display: flex; gap: 0.75rem; font-size: 0.88rem; line-height: 1.45; }
.sync-step-num { flex-shrink: 0; width: 1.5rem; height: 1.5rem; border-radius: 999px; background: rgb(var(--color-primary) / 0.15); color: rgb(var(--color-primary)); display: flex; align-items: center; justify-content: center; font-size: 0.78rem; font-weight: 700; }
.sync-actions { display: flex; flex-wrap: wrap; gap: 0.65rem; margin-bottom: 1rem; }
.btn-primary { border: none; background: rgb(var(--color-primary)); color: white; padding: 0.65rem 1rem; border-radius: 0.65rem; cursor: pointer; font: inherit; font-weight: 600; }
.btn-primary:hover { background: rgb(var(--color-primary-hover)); }
.btn-secondary { display: inline-flex; align-items: center; border: 1px solid rgb(var(--color-border)); background: rgb(var(--color-surface)); padding: 0.65rem 1rem; border-radius: 0.65rem; cursor: pointer; font: inherit; }
.file-label { cursor: pointer; }
.sync-status { font-size: 0.85rem; padding: 0.75rem; border-radius: var(--radius); }
.sync-status.ok { background: rgb(var(--color-success) / 0.1); color: rgb(var(--color-success)); }
.sync-status.warn { background: #fffbeb; color: #92400e; }

.ajuste-row { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; font-size: 0.9rem; }
.ajuste-row select { padding: 0.5rem; border-radius: 0.5rem; border: 1px solid rgb(var(--color-border)); background: rgb(var(--color-surface)); color: inherit; }

.ubicacion-clickable { width: 100%; border: none; background: transparent; cursor: pointer; font: inherit; color: inherit; text-align: left; }
.ubicacion-clickable:hover { background: rgb(var(--color-primary) / 0.06); }

@media (min-width: 640px) {
  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
