/* ─── Reset & Base ────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  color-scheme: light dark;
  --primary: #1a8a6a;
  --primary-dark: #14705a;
  --primary-light: #e0f5ee;
  --sidebar-bg: #0a3d3a;
  --sidebar-hover: #0d4f4a;
  --sidebar-active: #126b5e;
  --bg: #f8f9fa;
  --white: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --info: #2563eb;
  --info-light: #eff6ff;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ─── Login Screen ───────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--sidebar-bg) 0%, var(--primary) 100%);
}

.login-card {
  background: var(--white);
  border-radius: 12px;
  padding: 40px;
  width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo-img { width: 100px; height: 100px; object-fit: contain; margin-bottom: 8px; }
.login-logo p { color: var(--text-light); font-size: 14px; margin-top: 4px; }

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.password-wrap input {
  width: 100%;
  padding-right: 40px;
}
.password-eye {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: color .15s;
  user-select: none;
  -webkit-user-select: none;
}
.password-eye:hover { color: var(--text); }
.password-eye:active { color: var(--primary); }

.login-remember-row {
  margin-bottom: 4px;
}
.remember-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-light);
  cursor: pointer;
  user-select: none;
}
.remember-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
  min-height: 20px;
}

/* ─── Form Elements ──────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="search"],
textarea, select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s;
  background: var(--white);
  color: var(--text);
  caret-color: var(--primary);
  cursor: text;
}

input[type="text"]::selection, input[type="email"]::selection,
input[type="password"]::selection, input[type="number"]::selection,
input[type="date"]::selection, input[type="search"]::selection,
textarea::selection {
  background: var(--primary);
  color: #fff;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,138,106,.15);
}

textarea { resize: vertical; min-height: 80px; }

/* ─── Buttons ────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ─── App Shell ──────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ────────────────────────────────────── */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 16px 24px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar-brand-logo { width: 52px; height: 52px; object-fit: contain; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  color: rgba(255,255,255,.7);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.sidebar-link:hover { color: #fff; background: var(--sidebar-hover); }
.sidebar-link.active { color: #fff; background: var(--sidebar-active); }
.sidebar-link .icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-section {
  padding: 8px 24px 4px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: .4;
  margin-top: 8px;
}

.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(255,255,255,.1);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
}

.sidebar-username { font-size: 13px; font-weight: 500; }
.sidebar-role { font-size: 11px; opacity: .6; }

.sidebar-logout {
  background: none;
  border: none;
  color: rgba(255,255,255,.6);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
  font-family: inherit;
}
.sidebar-logout:hover { color: #fff; }

/* ─── Main Content ───────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 24px 32px;
  min-height: 100vh;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 { font-size: 22px; font-weight: 600; }

/* ─── Cards ──────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-header h3 { font-size: 15px; font-weight: 600; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.stat-card .stat-label { font-size: 12px; color: var(--text-light); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--text); margin-top: 4px; }
.stat-card .stat-icon { font-size: 20px; float: right; margin-top: -4px; }

/* ─── Tables ─────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-light);
  border-bottom: 2px solid var(--border);
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

tr:hover td { background: var(--bg); }

/* ─── Badges ─────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-gray { background: #f1f5f9; color: var(--text-light); }

/* ─── Tabs ───────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
}

.tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .15s;
  font-family: inherit;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ─── Search Bar ─────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.search-bar input {
  flex: 1;
  max-width: 360px;
}

/* ─── Toolbar ────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ─── Load More ──────────────────────────────────── */
.load-more-wrapper {
  text-align: center;
  padding: 16px 0;
}

/* ─── Empty State ────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-light);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ─── Toast ──────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: 8px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn .3s ease;
  max-width: 360px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }
.toast-warning { background: var(--warning); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ─── Modal ──────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-box {
  background: var(--white);
  border-radius: 12px;
  width: 500px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-light);
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ─── Progress Bar ───────────────────────────────── */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width .3s;
}

/* ─── Detail Row ─────────────────────────────────── */
.detail-row {
  display: flex;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.detail-row:last-child { border-bottom: none; }
.detail-label { width: 140px; font-size: 12px; color: var(--text-light); font-weight: 500; }
.detail-value { flex: 1; font-size: 13px; }

/* ─── Action Buttons Group ───────────────────────── */
.action-group {
  display: flex;
  gap: 4px;
}

/* ─── Inline Select ──────────────────────────────── */
select.inline-select {
  width: auto;
  padding: 3px 8px;
  font-size: 12px;
  border-radius: 4px;
}

/* ─── Spinner ────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-center {
  display: flex;
  justify-content: center;
  padding: 48px;
}

/* ─── Social Post Cards ─────────────────────────── */
.post-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 12px;
}

.post-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.post-avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}

.post-author-info {
  flex: 1;
  min-width: 0;
}

.post-author-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.post-author-username {
  font-size: 12px;
  color: var(--text-light);
}

.post-time {
  font-size: 12px;
  color: var(--text-light);
  white-space: nowrap;
}

.post-body {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.media-grid {
  display: grid;
  gap: 4px;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 10px;
}

.media-grid[data-count="1"] { grid-template-columns: 1fr; }
.media-grid[data-count="2"] { grid-template-columns: 1fr 1fr; }
.media-grid[data-count="3"] { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; }
.media-grid[data-count="3"] > :first-child { grid-column: span 2; }
.media-grid[data-count="4"] { grid-template-columns: 1fr 1fr; }

.media-grid img {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  display: block;
  cursor: pointer;
}

.media-grid video {
  width: 100%;
  max-height: 360px;
  background: #000;
  display: block;
  border-radius: 4px;
}

.media-grid audio {
  width: 100%;
  margin: 4px 0;
}

.post-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-light);
}

.post-footer .post-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.post-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

/* ─── Compose Box ───────────────────────────────── */
.compose-box {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 16px;
}

.compose-box textarea {
  border: none;
  resize: none;
  font-size: 15px;
  line-height: 1.5;
  min-height: 60px;
  padding: 8px 0;
  width: 100%;
}

.compose-box textarea:focus {
  outline: none;
  box-shadow: none;
}

.media-preview {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.media-preview-item {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.media-preview-item img,
.media-preview-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-preview-item .media-type-icon {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  font-size: 20px;
  color: var(--text-light);
}

.media-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,.6);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.compose-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.compose-toolbar .btn-attach {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-light);
  font-family: inherit;
}
.compose-toolbar .btn-attach:hover { background: var(--bg); color: var(--text); }

.compose-toolbar select {
  width: auto;
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 6px;
}

.compose-toolbar .spacer { flex: 1; }

/* ─── Responsive ─────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 60px; min-width: 60px; }
  .sidebar-link span, .sidebar-section,
  .sidebar-username, .sidebar-role, .sidebar-logout { display: none; }
  .sidebar-brand { padding: 16px 12px; }
  .sidebar-link { padding: 12px; justify-content: center; }
  .main-content { margin-left: 60px; padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ─── Shortcut tiles (user dashboard) ─────────────── */
.shortcut-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  padding: 4px 0;
}
.shortcut-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, border-color .15s;
  cursor: pointer;
}
.shortcut-tile:hover { background: var(--bg-hover, #f5f5f5); border-color: var(--primary); }
.shortcut-icon { font-size: 24px; }


/* ─── Library ─────────────────────────────────────── */
.library-controls { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.lib-search-wrap { position: relative; }
.lib-search {
  width: 100%; padding: 10px 18px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 24px;
  background: var(--white); color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.lib-search:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,138,106,.15); }

.lib-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.lib-pill {
  padding: 6px 16px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--white); color: var(--text-light); font-size: 13px;
  cursor: pointer; transition: all .15s; font-family: inherit;
}
.lib-pill:hover { border-color: var(--primary); color: var(--primary); }
.lib-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

/* Language toggle on browse page */
.lib-lang-toggle { display: flex; align-items: center; gap: 4px; }

/* Book grid */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.book-card {
  background: var(--white); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; cursor: pointer; transition: transform .15s, box-shadow .15s;
}
.book-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.book-cover {
  aspect-ratio: 2 / 3; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
  padding: 12px; position: relative; overflow: hidden;
}
.book-cover-text { font-size: 30px; font-weight: 700; color: rgba(255,255,255,.9); line-height: 1; }
.book-cover-cat {
  font-size: 10px; font-weight: 600; letter-spacing: .8px; text-transform: uppercase;
  color: rgba(255,255,255,.7); background: rgba(0,0,0,.2); padding: 2px 8px; border-radius: 10px;
}
.book-card-body { padding: 12px 12px 14px; }
.book-title { font-size: 13px; font-weight: 600; line-height: 1.4; margin-bottom: 4px; color: var(--text); }
.book-desc { font-size: 12px; color: var(--text-light); line-height: 1.4; }

/* Collection stacked effect */
.collection-cover { position: relative; overflow: visible !important; }
.collection-cover::before,
.collection-cover::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--col-c1, #1a8a6a), var(--col-c2, #0a3d3a));
  border-radius: 6px 6px 0 0; z-index: -1;
}
.collection-cover::before { transform: rotate(-3deg) translate(-5px, 3px); opacity: .65; }
.collection-cover::after  { transform: rotate(3deg) translate(5px, 3px);  opacity: .45; }
.collection-badge { background: #e0e7ff !important; color: #4338ca !important; }

/* Upload feedback */
.upload-progress { font-size: 12px; color: var(--text-light); margin-top: 4px; }
.upload-done  { font-size: 12px; color: var(--success); margin-top: 4px; }
.upload-error { font-size: 12px; color: var(--danger);  margin-top: 4px; }

/* ─── Book cover image ────────────────────────────── */
.book-cover-img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}

/* ─── Full-page Reader ─────────────────────────────── */
.lib-reader-page { animation: fadeIn .2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.reader-page { max-width: 820px; margin: 0 auto; }

/* Sticky topbar — breaks out of .reader-page inner padding */
.reader-page-topbar {
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
  margin: 0 -32px 24px;
  padding: 11px 32px;
  background: var(--blur-bg, rgba(248,249,250,.97));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.reader-back-btn {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 14px; font-size: 13px; color: var(--text-light);
  cursor: pointer; font-family: inherit; transition: all .15s;
}
.reader-back-btn:hover { border-color: var(--primary); color: var(--primary); }

.reader-page-hero {
  display: flex; align-items: flex-start; gap: 24px;
  margin-bottom: 36px; padding-bottom: 28px;
  border-bottom: 1px solid var(--border);
}
.reader-hero-cover {
  width: 80px; height: 100px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700; color: rgba(255,255,255,.95);
  box-shadow: 0 6px 18px rgba(0,0,0,.22); position: relative;
}
.reader-hero-cover.collection-cover-mini::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit;
  background: inherit; transform: rotate(-4deg) translate(-4px, 3px); opacity: .5; z-index: -1;
}
.reader-hero-info { flex: 1; min-width: 0; }
.reader-page-title { font-size: 26px; font-weight: 700; line-height: 1.3; color: var(--text); margin: 6px 0 10px; }
.reader-page-desc { font-size: 14px; color: var(--text-light); line-height: 1.7; margin-top: 4px; }

.reader-entry-count {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .8px; color: var(--text-light); margin-bottom: 20px;
}

/* Text content */
.reader-page-content { margin-bottom: 48px; }

.text-entry-single {
  font-family: 'Crimson Pro', Georgia, serif;
  font-size: 18px; line-height: 2.1; color: var(--text);
  white-space: pre-wrap; word-break: break-word;
}

/* Hadith cards */
.text-entry-card {
  display: block; padding: 0; margin-bottom: 8px;
  background: var(--white); border: 1px solid #e8edf2;
  border-radius: 10px; transition: box-shadow .15s, border-color .15s;
  overflow: hidden;
}
.text-entry-card:hover { border-color: #c8d6e0; box-shadow: 0 2px 10px rgba(0,0,0,.07); }

/* Clickable header row */
.te-header {
  display: flex; align-items: center; justify-content: flex-end;
  padding: 8px 16px; cursor: pointer; user-select: none;
  transition: background .12s;
}
.te-header:hover { background: #f8fafb; }
.te-chevron { font-size: 11px; color: #94a3b8; flex-shrink: 0; }

/* Expandable body */
.te-body {
  padding: 16px 20px 20px;
  display: flex; flex-direction: column; gap: 16px;
  border-top: 1px solid #eef1f4;
}
.text-entry-card.collapsed .te-body { display: none; }

/* Language blocks inside te-body */
.lang-ar {
  font-family: 'Amiri', 'Noto Naskh Arabic', serif;
  font-size: 21px; line-height: 2.4; color: #1a2234;
  white-space: pre-wrap; word-break: break-word;
}
.lang-en {
  font-family: 'Crimson Pro', Georgia, serif;
  font-size: 17px; line-height: 1.95; color: #374151;
  white-space: pre-wrap; word-break: break-word;
}

/* Chapter / section heading dividers */
.te-heading {
  padding: 28px 2px 10px; margin-bottom: 4px;
  border-bottom: 2px solid var(--primary-light);
  font-size: 13px; font-weight: 600; color: var(--primary);
  letter-spacing: .2px;
}

/* Language visibility controlled by class on .reader-page */
.reader-page.show-ar .lang-en { display: none; }
.reader-page.show-en .lang-ar { display: none; }
/* Hide cards that have no content for the active language */
.reader-page.show-en .text-entry-card:not(:has(.lang-en)) { display: none; }
.reader-page.show-ar .text-entry-card:not(:has(.lang-ar)) { display: none; }

/* Language toggle bar (legacy, kept for any inline uses) */
.lang-toggle-bar { display: flex; align-items: center; gap: 4px; margin-bottom: 18px; flex-wrap: wrap; }
.lang-toggle-label { font-size: 12px; color: var(--text-light); margin-right: 2px; }
.lang-btn {
  padding: 4px 13px; font-size: 12px; font-weight: 500;
  border: 1px solid var(--border); border-radius: 20px;
  background: var(--white); color: var(--text-light);
  cursor: pointer; font-family: inherit; transition: all .15s;
}
.lang-btn:hover { border-color: var(--primary); color: var(--primary); }
.lang-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Keep legacy rule for .text-entry-body in case it appears elsewhere */
.text-entry-body {
  font-family: 'Crimson Pro', Georgia, serif;
  font-size: 17px; line-height: 1.95; color: var(--text);
  white-space: pre-wrap; word-break: break-word; flex: 1;
}
.text-entry-body[dir="rtl"] {
  font-family: 'Amiri', 'Noto Naskh Arabic', serif;
  font-size: 21px; line-height: 2.4;
}

.reader-empty-body {
  font-size: 14px; color: var(--text-light); font-style: italic;
  padding: 40px 0; text-align: center;
}

/* Source documents accordion */
.reader-source-section { margin-top: 28px; }
.reader-source-toggle {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 12px 16px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; font-weight: 500; color: var(--text-light);
  cursor: pointer; font-family: inherit; transition: all .15s;
}
.reader-source-toggle:hover { border-color: var(--primary); color: var(--text); }
.reader-source-chevron { font-size: 12px; }
.reader-source-body {
  padding: 12px; border: 1px solid var(--border);
  border-top: none; border-radius: 0 0 8px 8px;
}
.reader-file-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 4px; flex-wrap: wrap;
}
.reader-file-name { font-size: 12px; color: var(--text); word-break: break-all; flex: 1; }

/* Collection tabs — sticky below topbar */
.col-tabs-bar {
  display: flex; flex-wrap: nowrap; gap: 0;
  border-bottom: 2px solid var(--border); margin-bottom: 28px;
  overflow-x: auto; scrollbar-width: none;
  position: sticky; top: 53px; z-index: 19;
  margin: 0 -32px;
  padding: 0 32px;
  background: var(--blur-bg, rgba(248,249,250,.97));
  backdrop-filter: blur(8px);
}
.col-tabs-bar::-webkit-scrollbar { display: none; }
.col-tab {
  padding: 12px 20px; font-size: 13px; font-weight: 500;
  color: var(--text-light); cursor: pointer; background: none; border: none;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: all .15s; font-family: inherit; white-space: nowrap; flex-shrink: 0;
}
.col-tab:hover { color: var(--text); }
.col-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ─── Sidebar theme toggle ───────────────────────── */
.sidebar-theme {
  display: flex; gap: 4px; margin: 8px 0 6px;
}
.sidebar-theme-btn {
  flex: 1; background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1); border-radius: 6px;
  color: rgba(255,255,255,.45); padding: 5px 0; font-size: 14px;
  cursor: pointer; font-family: inherit; transition: all .15s;
}
.sidebar-theme-btn:hover { background: rgba(255,255,255,.1); color: rgba(255,255,255,.8); }
.sidebar-theme-btn.active { background: rgba(255,255,255,.15); color: #fff; border-color: rgba(255,255,255,.3); }

/* ─── Dark theme ─────────────────────────────────── */
.dark {
  color-scheme: dark;
  --bg: #0f1117;
  --white: #161b22;
  --text: #e6edf3;
  --text-light: #8b949e;
  --border: #30363d;
  --primary-light: rgba(26,138,106,.18);
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.5);
  --blur-bg: rgba(13,17,23,.97);
}
.dark input, .dark textarea, .dark select {
  background: var(--white);
  color: var(--text);
  border-color: var(--border);
}

/* Card & surface overrides (hardcoded colors → dark) */
.dark .text-entry-card { border-color: #21262d; }
.dark .text-entry-card:hover { border-color: #30363d; box-shadow: 0 2px 12px rgba(0,0,0,.4); }
.dark .te-header:hover { background: #1c2128; }
.dark .te-body { border-top-color: #21262d; }
.dark .lang-ar { color: #f0ece0; }
.dark .lang-en { color: #c9d1d9; }
.dark .te-heading { border-bottom-color: rgba(26,138,106,.2); }
.dark .book-card { border-color: #21262d; }
.dark .book-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.5); }
.dark .lib-search { background: var(--white); color: var(--text); border-color: var(--border); }
.dark .lib-pill { background: var(--white); border-color: var(--border); color: var(--text-light); }
.dark .reader-source-toggle { background: var(--white); }
.dark .reader-source-body { background: var(--white); }
.dark .modal-box { background: var(--white); }
.dark .modal-header { border-bottom-color: var(--border); }
.dark .modal-footer { border-top-color: var(--border); }
.dark .card { background: var(--white); }
.dark .card-header { border-bottom-color: var(--border); }
.dark .stat-card { background: var(--white); }
.dark .table-wrapper { background: var(--white); }
.dark th { background: var(--bg); }
.dark .badge-gray { background: #2d333b; color: #8b949e; }

/* Mobile */
@media (max-width: 640px) {
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .reader-page-title { font-size: 20px; }
  .lang-ar { font-size: 18px; }
  .lang-en { font-size: 15px; }
  .te-body { padding-left: 46px; }
  .col-tab { padding: 10px 14px; font-size: 12px; }
  .reader-page-topbar { margin: 0 -16px 16px; padding: 10px 16px; }
  .col-tabs-bar { top: 48px; margin-left: -16px; margin-right: -16px; padding: 0 16px; }
}

/* ─── Toggle Switch ──────────────────────────────── */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #cbd5e1;
  border-radius: 26px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* ─── Library bookmark button ───────────────────── */
.book-cover { position: relative; }

.book-bm-btn {
  position: absolute;
  top: 8px; right: 8px;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.45);
  color: rgba(255,255,255,0.7);
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
  z-index: 2;
}
.book-bm-btn:hover { background: rgba(0,0,0,0.65); color: #fff; }
.book-bm-btn.active { color: #fcd34d; background: rgba(0,0,0,0.55); }

.reader-bm-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-light);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.reader-bm-btn:hover { border-color: #fcd34d; color: var(--text); }
.reader-bm-btn.active { color: #fcd34d; border-color: #fcd34d; background: rgba(252,211,77,0.08); }

/* ─── Reading position pin ───────────────────────── */
.te-header { display: flex; align-items: center; }

.te-pin-btn {
  margin-left: auto;
  opacity: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 4px;
  color: var(--text-light);
  transition: opacity 0.15s;
  line-height: 1;
}
.te-header:hover .te-pin-btn { opacity: 0.6; }
.te-header:hover .te-pin-btn:hover { opacity: 1; }
.te-pin-btn.active { opacity: 1; filter: none; }

.te-pinned { outline: 2px solid rgba(245,158,11,0.45); outline-offset: 2px; border-radius: 8px; }

.reader-resume-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 16px;
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.3);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text);
}

/* ─── Guest bar ──────────────────────────────────── */
#guest-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.guest-bar-logo { height: 32px; width: auto; display: block; }
.guest-bar-actions { display: flex; gap: 8px; align-items: center; }

#guest-page-container {
  min-height: calc(100vh - 56px);
  padding: 0 24px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ─── Auth tabs ──────────────────────────────────── */
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.auth-tab {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.auth-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
