/* ==========================================================
    Biblioteca Digital - style.css
   Diseño moderno tipo Calibre Web / Komga, responsive, temas
   ========================================================== */

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --accent: #c084fc;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,.08);
  --transition: .18s ease;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-elevated: #171a23;
  --bg-sidebar: #14161f;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --border: #262a36;
  --hover: #1f2330;
  --card: #171a23;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background var(--transition), color var(--transition);
}
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; }

/* ---------------- App Shell ---------------- */
.app-shell { display: flex; min-height: 100vh; }

.app-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 100;
}
.sidebar-inner { min-width: 240px; display: flex; flex-direction: column; height: 100%; }

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
  .form-row { grid-template-columns: 1fr; }
  .topbar-search { display: none; }
}
.sidebar-inner { min-width: 240px; display: flex; flex-direction: column; height: 100%; }
.sidebar-brand {
  display: flex; align-items: center; justify-content: center;
  padding: 20px 18px; font-weight: 700; font-size: 18px;
  border-bottom: 1px solid var(--border);
}
.logo-icon { font-size: 22px; }
.logo-img { display: block; height: auto; max-height: 120px; width: auto; }
.sidebar-logo { height: 28px; max-height: 28px; }
.guest-brand .logo-img { max-height: 120px; margin: 0 auto 12px; }
.sidebar-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px; color: var(--text);
  font-size: 14px; font-weight: 500;
}
.nav-link:hover { background: var(--hover); }
.nav-link .ic { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; margin-bottom: 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.uname { font-weight: 600; font-size: 13px; }
.urole { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }
.logout { color: #ef4444; }

.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.app-topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 22px; border-bottom: 1px solid var(--border);
  background: var(--bg-elevated); position: sticky; top: 0; z-index: 50;
}
.icon-btn {
  background: none; border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 8px; cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: var(--hover); }
.topbar-search {
  flex: 1; display: flex; max-width: 480px; border: 1px solid var(--border);
  border-radius: 8px; overflow: hidden; background: var(--bg);
}
.topbar-search input { flex: 1; border: none; background: transparent; padding: 9px 12px; color: var(--text); outline: none; }
.topbar-search button { border: none; background: transparent; padding: 0 12px; cursor: pointer; color: var(--text-muted); }
.app-content { padding: 24px; flex: 1; }

/* ---------------- Guest layout (login/register) ---------------- */
.guest-body {
  background: linear-gradient(135deg, #0f172a, #1e1b4b);
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.guest-wrap { width: 100%; max-width: 420px; }
.guest-brand { text-align: center; margin-bottom: 22px; color: #e5e7eb; }
.guest-brand h1 { margin: 6px 0 2px; font-size: 26px; background: linear-gradient(90deg,#818cf8,#c084fc); -webkit-background-clip:text; background-clip:text; color: transparent; }
.guest-brand p { color: #94a3b8; margin: 0; font-size: 14px; }
.guest-card { background: #171a23; border-radius: 16px; padding: 30px; box-shadow: 0 10px 40px rgba(0,0,0,.4); border: 1px solid rgba(255,255,255,.06); color: #e5e7eb; }
.guest-card h2 { margin-top: 0; }
.guest-card label { display: block; margin: 14px 0 6px; font-size: 13px; color: #94a3b8; }
.guest-card input, .guest-card select, .guest-card textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,.15);
  background: #0f172a; color: #e5e7eb; font-size: 14px;
}
.guest-card .links { margin-top: 16px; font-size: 13px; text-align: center; color: #94a3b8; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.alert-error { background: rgba(239,68,68,.15); color: #fca5a5; border: 1px solid rgba(239,68,68,.3); }
.alert-success { background: rgba(34,197,94,.15); color: #86efac; border: 1px solid rgba(34,197,94,.3); }

/* ---------------- Buttons ---------------- */
.btn-primary, button.btn-primary {
  background: var(--primary); color: #fff; border: none; padding: 11px 18px;
  border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; display: inline-block;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
  background: var(--hover); color: var(--text); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 8px; cursor: pointer; font-size: 14px; display: inline-block;
}
.btn-danger { background: #ef4444; color: #fff; border: none; padding: 10px 16px; border-radius: 8px; cursor: pointer; }
.btn-block { width: 100%; text-align: center; }

/* ---------------- Cards / Grids ---------------- */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { margin: 0; font-size: 22px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; }
.stat-card .stat-label { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

.lib-grid, .book-grid { display: grid; gap: 18px; }
.lib-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.book-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

.lib-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; transition: transform var(--transition); }
.lib-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.lib-card h3 { margin: 0 0 6px; font-size: 16px; }
.lib-card p { color: var(--text-muted); font-size: 13px; margin: 0 0 10px; }
.lib-meta { display: flex; gap: 10px; font-size: 12px; color: var(--text-muted); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; background: var(--hover); color: var(--text-muted); }
.badge-owner { background: rgba(99,102,241,.15); color: var(--primary); }
.badge-admin { background: rgba(192,132,252,.15); color: var(--accent); }
.badge-read { background: rgba(34,197,94,.15); color: #22c55e; }
.badge-download { background: rgba(251,191,36,.15); color: #f59e0b; }

.book-card { cursor: pointer; }
.book-cover { width: 100%; aspect-ratio: 2/3; border-radius: 8px; overflow: hidden; background: var(--hover); box-shadow: var(--shadow); }
.book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-title { font-size: 13px; font-weight: 600; margin: 8px 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-author { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-bar { height: 4px; background: var(--border); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress-bar > span { display: block; height: 100%; background: var(--primary); }

/* ---------------- Forms ---------------- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-muted); font-weight: 600; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.dropzone {
  border: 2px dashed var(--border); border-radius: 12px; padding: 30px; text-align: center;
  color: var(--text-muted); cursor: pointer; transition: var(--transition);
}
.dropzone.dragover { border-color: var(--primary); background: var(--hover); }

table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th, table.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
table.data-table th { color: var(--text-muted); font-weight: 600; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab-link { padding: 10px 16px; cursor: pointer; color: var(--text-muted); border-bottom: 2px solid transparent; font-size: 14px; font-weight: 600; }
.tab-link.active { color: var(--primary); border-color: var(--primary); }
.tab-content { display: none; }
.tab-content.active { display: block; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 42px; margin-bottom: 10px; }

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
  .app-sidebar { display: none; position: relative; height: auto; width: 240px; }
  .app-sidebar.open { display: flex; }
  .form-row { grid-template-columns: 1fr; }
  .topbar-search { display: none; }
}
