:root {
  /* Paleta Educación Zenit */
  --blue:    #0EA5E9;
  --blue2:   #0284C7;
  --teal:    #0D9488;
  --green:   #4CAF50;
  --orange:  #F59E0B;
  --gradient: linear-gradient(135deg, #0EA5E9 0%, #0D9488 50%, #4CAF50 100%);
  /* Fondos oscuros (lectura cómoda) */
  --dark:    #0B1120;
  --dark2:   #111827;
  --surface: #1A2535;
  --card:    #1F2D40;
  --border:  rgba(255,255,255,0.08);
  --text:    #E8EDF3;
  --muted:   #7B92AA;
  --white:   #ffffff;
  --radius:  12px;
  --shadow:  0 4px 24px rgba(0,0,0,0.4);
  --transition: 0.2s ease;
}

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

body {
  font-family: 'Poppins', 'Segoe UI', system-ui, sans-serif;
  background: var(--dark);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--dark2); }
::-webkit-scrollbar-thumb { background: var(--surface); border-radius: 3px; }

/* ── Topbar ── */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--dark2);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1rem; color: var(--white);
}
.topbar-brand img { height: 32px; width: 32px; border-radius: 50%; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border-radius: 100px;
  padding: 6px 14px; font-size: 0.82rem; color: var(--muted);
}
.user-chip img { width: 24px; height: 24px; border-radius: 50%; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: 8px;
  font-size: 0.88rem; font-weight: 600; cursor: pointer;
  border: none; transition: var(--transition); font-family: inherit;
}
.btn-primary { background: var(--gradient); color: #fff; background-size: 200% auto; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: rgba(255,255,255,0.2); color: var(--text); }
.btn-danger { background: #b71c1c; color: #fff; }
.btn-danger:hover { background: #d32f2f; }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-google {
  background: #fff; color: #1a1a1a;
  border: 1px solid #e0e0e0; padding: 13px 28px;
  border-radius: 10px; font-size: 0.95rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  transition: box-shadow 0.2s, transform 0.15s;
  font-weight: 600;
}
.btn-google:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.2); transform: translateY(-1px); }
.btn-google svg { width: 20px; height: 20px; flex-shrink: 0; }

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at 60% 30%, rgba(14,165,233,0.12) 0%, rgba(13,148,136,0.08) 40%, transparent 70%),
              var(--dark);
}
.login-card {
  background: var(--dark2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%; max-width: 420px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-logo { width: 64px; height: 64px; border-radius: 50%; margin: 0 auto 20px; }
.login-card h1 { font-size: 1.4rem; font-weight: 700; color: var(--white); margin-bottom: 6px; }
.login-card .subtitle { font-size: 0.88rem; color: var(--muted); margin-bottom: 36px; }
.login-divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-size: 0.78rem; margin: 24px 0;
}
.login-divider::before, .login-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.login-footer { font-size: 0.75rem; color: var(--muted); margin-top: 28px; }

/* ── Main layout ── */
.layout { display: flex; min-height: calc(100vh - 60px); }
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--dark2);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 8px;
  font-size: 0.88rem; color: var(--muted);
  cursor: pointer; transition: var(--transition);
  border: none; background: none; width: 100%; text-align: left;
  font-family: inherit;
}
.sidebar-item:hover, .sidebar-item.active {
  background: var(--surface); color: var(--white);
}
.sidebar-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-spacer { flex: 1; }
.main { flex: 1; padding: 32px; overflow-y: auto; }

/* ── Page header ── */
.page-header { margin-bottom: 28px; }
.page-header h2 { font-size: 1.4rem; font-weight: 700; color: var(--white); }
.page-header p { font-size: 0.88rem; color: var(--muted); margin-top: 4px; }

/* ── Ebook grid ── */
.ebooks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
}
.ebook-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}
.ebook-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.ebook-cover {
  aspect-ratio: 3/4;
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.ebook-cover img { width: 100%; height: 100%; object-fit: cover; }
.ebook-cover-placeholder {
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: var(--muted); font-size: 0.75rem; text-align: center; padding: 12px;
}
.ebook-cover-placeholder svg { width: 40px; height: 40px; opacity: 0.4; }
.ebook-info { padding: 14px; }
.ebook-info h3 { font-size: 0.88rem; font-weight: 600; color: var(--white); margin-bottom: 4px; line-height: 1.4; }
.ebook-info p { font-size: 0.75rem; color: var(--muted); }
.ebook-btn { margin-top: 12px; width: 100%; justify-content: center; }

/* ── Empty state ── */
.empty-state {
  text-align: center; padding: 64px 24px; color: var(--muted);
}
.empty-state svg { width: 56px; height: 56px; margin: 0 auto 16px; opacity: 0.3; }
.empty-state h3 { font-size: 1rem; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 0.85rem; }

/* ── Lector PDF ── */
.reader-topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--dark2); border-bottom: 1px solid var(--border);
  padding: 0 20px; height: 56px;
  display: flex; align-items: center; gap: 16px;
}
.reader-title { font-size: 0.9rem; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-controls { display: flex; align-items: center; gap: 8px; }
.reader-controls span { font-size: 0.82rem; color: var(--muted); min-width: 80px; text-align: center; }
.pdf-container {
  display: flex; flex-direction: column; align-items: center;
  padding: 24px 16px; gap: 16px; min-height: calc(100vh - 56px);
  background: #3a3a3a;
}
.pdf-container canvas {
  max-width: 100%; border-radius: 4px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.pdf-loading {
  color: var(--muted); font-size: 0.9rem;
  display: flex; align-items: center; gap: 8px; padding: 48px;
}

/* ── Admin: tabla usuarios ── */
.admin-tabs { display: flex; gap: 4px; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.admin-tab {
  padding: 10px 20px; font-size: 0.88rem; font-weight: 600;
  color: var(--muted); cursor: pointer; border: none; background: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: var(--transition); font-family: inherit;
}
.admin-tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.admin-section { display: none; }
.admin-section.active { display: block; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
thead th {
  background: var(--surface); color: var(--muted);
  padding: 12px 16px; text-align: left; font-weight: 600;
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em;
}
tbody tr { border-top: 1px solid var(--border); }
tbody tr:hover { background: rgba(255,255,255,0.02); }
tbody td { padding: 12px 16px; color: var(--text); }
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 100px;
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
}
.badge-admin { background: rgba(14,165,233,0.2); color: #7DD3FC; }
.badge-user  { background: rgba(76,175,80,0.2); color: #86EFAC; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--dark2); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; width: 100%; max-width: 480px;
  box-shadow: var(--shadow);
}
.modal h3 { font-size: 1.1rem; font-weight: 700; color: var(--white); margin-bottom: 6px; }
.modal .modal-sub { font-size: 0.84rem; color: var(--muted); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.checkbox-list { display: flex; flex-direction: column; gap: 10px; max-height: 300px; overflow-y: auto; }
.checkbox-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 8px; background: var(--surface);
  cursor: pointer;
}
.checkbox-item input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--blue); }
.checkbox-item label { font-size: 0.88rem; cursor: pointer; flex: 1; }
.checkbox-item .check-autor { font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

/* ── Form ── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-group label { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.form-group input, .form-group textarea {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; color: var(--text);
  font-size: 0.9rem; font-family: inherit; outline: none; transition: var(--transition);
}
.form-group input:focus, .form-group textarea:focus { border-color: var(--blue); }
.form-group textarea { resize: vertical; min-height: 80px; }
.upload-area {
  border: 2px dashed var(--border); border-radius: 8px;
  padding: 24px; text-align: center; color: var(--muted);
  cursor: pointer; transition: var(--transition); font-size: 0.85rem;
}
.upload-area:hover { border-color: var(--blue); color: var(--text); }
.upload-area input { display: none; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 20px;
  font-size: 0.88rem; color: var(--text);
  box-shadow: var(--shadow); opacity: 0; transform: translateY(8px);
  transition: opacity 0.3s, transform 0.3s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-left: 3px solid #4caf50; }
.toast.error   { border-left: 3px solid #f44336; }

/* ── Loader ── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main { padding: 20px 16px; }
  .ebooks-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
  .login-card { padding: 36px 24px; }
  .reader-topbar { padding: 0 12px; }
}
