/* ===== CSS Variables ===== */
:root {
  --sidebar-bg: #1e1e2e;
  --sidebar-text: #cdd6f4;
  --sidebar-muted: #6c7086;
  --sidebar-hover: #313244;
  --sidebar-active: #cba6f7;
  --accent: #cba6f7;
  --accent-dark: #9e79e0;

  --bg: #eff1f5;
  --card-bg: #ffffff;
  --text: #4c4f69;
  --text-muted: #7c7f93;
  --border: #dce0e8;
  --input-bg: #ffffff;

  --success: #40a02b;
  --warning: #df8e1d;
  --error: #d20f39;
  --info: #1e66f5;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.12);

  --sidebar-w: 220px;
  --transition: .15s ease;
}

[data-theme="dark"] {
  --bg: #11111b;
  --card-bg: #1e1e2e;
  --text: #cdd6f4;
  --text-muted: #a6adc8;
  --border: #313244;
  --input-bg: #313244;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
       background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, select, textarea { font: inherit; }
svg { display: inline-block; fill: none; stroke: currentColor;
      stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
      vertical-align: middle; }

/* ===== Layout ===== */
.layout { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  padding: 0;
  z-index: 100;
}

.sidebar-header {
  display: flex; align-items: center; gap: .65rem;
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-logo { font-size: 1.4rem; }
.sidebar-title { color: var(--sidebar-text); font-weight: 700; font-size: 1rem; letter-spacing: -.01em; }

.sidebar-nav { flex: 1; padding: .75rem .5rem; display: flex; flex-direction: column; gap: .2rem; }

.nav-link {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-muted);
  font-size: .9rem;
  transition: background var(--transition), color var(--transition);
}
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.nav-link.active { background: var(--sidebar-hover); color: var(--sidebar-active); }

.sidebar-footer {
  padding: .75rem 1rem;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex; align-items: center; gap: .5rem;
}
.user-info { display: flex; align-items: center; gap: .5rem; flex: 1; min-width: 0; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #1e1e2e;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .8rem; flex-shrink: 0;
}
.user-name { color: var(--sidebar-text); font-size: .85rem; font-weight: 500;
             overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-btn { color: var(--sidebar-muted); transition: color var(--transition); flex-shrink: 0; }
.logout-btn:hover { color: var(--error); }
.logout-btn svg { width: 17px; height: 17px; }

/* ===== Main content ===== */
.main-content {
  margin-left: var(--sidebar-w);
  padding: 1.75rem 2rem;
  flex: 1;
  min-width: 0;
}

/* ===== Page header ===== */
.page-header { margin-bottom: 1.5rem; }
.page-title { font-size: 1.5rem; font-weight: 700; display: flex; align-items: baseline; gap: .65rem; }
.book-count { font-size: .85rem; font-weight: 500; color: var(--text-muted);
              background: var(--border); padding: .15rem .5rem; border-radius: 20px; }
.back-link { display: inline-flex; align-items: center; gap: .3rem;
             color: var(--text-muted); font-size: .875rem; margin-bottom: .5rem;
             transition: color var(--transition); }
.back-link:hover { color: var(--accent); }

/* ===== Toolbar ===== */
.toolbar {
  display: flex; align-items: center; gap: 1rem;
  margin-bottom: 1.5rem; flex-wrap: wrap;
}
.search-form { display: flex; align-items: center; gap: .5rem; flex: 1; min-width: 200px; }
.search-input-wrap { position: relative; flex: 1; }
.search-icon { position: absolute; left: .65rem; top: 50%; transform: translateY(-50%);
               width: 15px; height: 15px; color: var(--text-muted); }
.search-input {
  width: 100%; padding: .5rem .75rem .5rem 2.1rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card-bg); color: var(--text);
  transition: border-color var(--transition);
}
.search-input:focus { outline: none; border-color: var(--accent); }
.search-clear { position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
                color: var(--text-muted); font-size: 1.1rem; line-height: 1; }
.search-clear:hover { color: var(--error); }

.toolbar-right { display: flex; align-items: center; gap: .5rem; }

.select-sm {
  padding: .45rem .65rem; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--card-bg); color: var(--text);
  font-size: .875rem;
}
.select-sm:focus { outline: none; border-color: var(--accent); }

.view-toggle { display: flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.view-btn { display: flex; align-items: center; justify-content: center;
            padding: .45rem .6rem; color: var(--text-muted);
            transition: background var(--transition), color var(--transition); }
.view-btn svg { width: 15px; height: 15px; }
.view-btn:hover { background: var(--border); color: var(--text); }
.view-btn.active { background: var(--accent); color: #1e1e2e; }

/* ===== Book grid ===== */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1.25rem;
}

.book-card {
  display: flex; flex-direction: column;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}
.book-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

.book-cover {
  position: relative;
  aspect-ratio: 2/3;
  background: var(--border);
  overflow: hidden;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }

.cover-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
}
.cover-placeholder span { font-size: 2.5rem; font-weight: 800; color: white; text-shadow: 0 2px 4px rgba(0,0,0,.2); }
.cover-placeholder.large span { font-size: 4rem; }

.status-badge {
  position: absolute; top: .4rem; right: .4rem;
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700;
}
.status-read { background: var(--success); color: white; }
.status-reading { background: var(--warning); color: white; }

.book-info { padding: .6rem .7rem .75rem; }
.book-title { font-size: .85rem; font-weight: 600; line-height: 1.3;
              display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
              overflow: hidden; margin-bottom: .2rem; }
.book-author { font-size: .78rem; color: var(--text-muted);
               overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stars-small { font-size: .75rem; color: #f59e0b; margin-top: .2rem; letter-spacing: -.05em; }

/* ===== Book list ===== */
.book-list { display: flex; flex-direction: column; gap: .35rem; }

.list-header {
  display: grid;
  grid-template-columns: 36px 1fr 1fr 1fr auto auto;
  gap: .75rem; align-items: center;
  padding: .4rem .75rem;
  font-size: .78rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .05em;
}

.list-row {
  display: grid;
  grid-template-columns: 36px 1fr 1fr 1fr auto auto;
  gap: .75rem; align-items: center;
  padding: .65rem .75rem;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  transition: background var(--transition);
}
.list-row:hover { background: var(--border); }

.list-cover-mini { width: 36px; height: 54px; border-radius: 3px; overflow: hidden; flex-shrink: 0; }
.list-cover-mini img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-mini-placeholder {
  width: 100%; height: 100%;
  background: var(--accent); color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem;
}

.list-title { font-weight: 600; font-size: .9rem; }

/* ===== Badges ===== */
.badge {
  display: inline-block; padding: .2rem .5rem;
  border-radius: 20px; font-size: .75rem; font-weight: 600;
}
.badge-unread { background: rgba(114,135,253,.15); color: #7287fd; }
.badge-reading { background: rgba(223,142,29,.15); color: var(--warning); }
.badge-read { background: rgba(64,160,43,.15); color: var(--success); }
.badge-lg { padding: .3rem .75rem; font-size: .85rem; }

/* ===== Tags ===== */
.tag-list { display: flex; flex-wrap: wrap; gap: .3rem; }
.tag { display: inline-block; padding: .15rem .45rem;
       background: rgba(203,166,247,.15); color: var(--accent-dark);
       border-radius: 20px; font-size: .75rem; font-weight: 500; }

/* ===== Stars ===== */
.stars-big { font-size: 1.3rem; color: #f59e0b; letter-spacing: .05em; margin: .3rem 0; }

/* ===== Empty state ===== */
.empty-state {
  text-align: center; padding: 4rem 2rem;
  color: var(--text-muted);
}
.empty-icon { font-size: 3.5rem; margin-bottom: 1rem; }
.empty-state p { margin-bottom: 1rem; font-size: 1rem; }

/* ===== Cards ===== */
.card { background: var(--card-bg); border-radius: var(--radius); padding: 1.5rem;
        box-shadow: var(--shadow); margin-bottom: 1.5rem; }
.card-title { font-size: 1.1rem; font-weight: 700; margin-bottom: .25rem; }
.card-desc { color: var(--text-muted); font-size: .875rem; margin-bottom: 1rem; line-height: 1.6; }

/* ===== Forms ===== */
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group label { font-size: .85rem; font-weight: 600; color: var(--text); }
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="email"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg); color: var(--text);
  transition: border-color var(--transition);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { outline: none; border-color: var(--accent); }
.form-group textarea { resize: vertical; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-grid .span-2 { grid-column: 1 / -1; }

.form-check { display: flex; align-items: center; gap: .5rem; margin: .5rem 0; }
.form-check input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); }
.form-check label { font-size: .875rem; cursor: pointer; }

.form-actions { display: flex; gap: .75rem; align-items: center; margin-top: 1.25rem; flex-wrap: wrap; }

.field-hint { font-size: .78rem; color: var(--text-muted); margin-top: .3rem; }
.field-hint code { background: var(--border); padding: .1em .35em; border-radius: 3px; font-size: .85em; }

.fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.fieldset legend { font-size: .8rem; font-weight: 700; text-transform: uppercase;
                   letter-spacing: .06em; color: var(--text-muted); padding: 0 .4rem; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 600;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #1e1e2e; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }

.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--text-muted); color: var(--card-bg); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); }

.btn-danger { background: rgba(210,15,57,.1); color: var(--error); }
.btn-danger:hover:not(:disabled) { background: var(--error); color: white; }

.btn-full { width: 100%; }

/* ===== Flash messages ===== */
.flash-container { margin-bottom: 1.25rem; display: flex; flex-direction: column; gap: .4rem; }
.auth-flash { position: fixed; top: 1rem; left: 50%; transform: translateX(-50%); width: 360px; z-index: 200; }

.flash {
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 500;
  animation: slideIn .2s ease;
}
.flash-success { background: rgba(64,160,43,.12); color: var(--success); border: 1px solid rgba(64,160,43,.2); }
.flash-error { background: rgba(210,15,57,.1); color: var(--error); border: 1px solid rgba(210,15,57,.2); }
.flash-info { background: rgba(30,102,245,.1); color: var(--info); border: 1px solid rgba(30,102,245,.2); }
.flash-warning { background: rgba(223,142,29,.1); color: var(--warning); border: 1px solid rgba(223,142,29,.2); }

.flash-close { font-size: 1.1rem; color: inherit; opacity: .6; margin-left: .5rem; }
.flash-close:hover { opacity: 1; }

@keyframes slideIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: none; } }

/* ===== Auth layout ===== */
.auth-layout {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 1rem;
}

.auth-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow-md);
}
.auth-logo { font-size: 2.5rem; text-align: center; margin-bottom: .5rem; }
.auth-title { font-size: 1.4rem; font-weight: 800; text-align: center; margin-bottom: .2rem; }
.auth-subtitle { color: var(--text-muted); text-align: center; font-size: .875rem; margin-bottom: 1.5rem; }
.auth-link { text-align: center; font-size: .875rem; color: var(--text-muted); margin-top: 1rem; }
.auth-link a { color: var(--accent); font-weight: 600; }
.auth-link a:hover { text-decoration: underline; }
.auth-card .form-group { margin-bottom: .85rem; }
.auth-card .btn-full { margin-top: .5rem; }

/* ===== Book detail ===== */
.book-detail {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 2.5rem;
  align-items: start;
}

.detail-cover img {
  width: 100%; border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  display: block;
}
.detail-cover .cover-placeholder.large {
  width: 100%; aspect-ratio: 2/3;
  border-radius: var(--radius);
}
.detail-actions { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }

.detail-title { font-size: 1.6rem; font-weight: 800; line-height: 1.2; margin-bottom: .3rem; }
.detail-author { font-size: 1rem; color: var(--text-muted); margin-bottom: .75rem; }

.meta-table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: .875rem; }
.meta-table th { text-align: left; color: var(--text-muted); font-weight: 500;
                 padding: .35rem 0; width: 120px; }
.meta-table td { padding: .35rem 0; }

.section-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .07em;
                 color: var(--text-muted); font-weight: 700; margin: 1.25rem 0 .5rem; }
.description { font-size: .9rem; line-height: 1.7; color: var(--text-muted); }
.notes-box { background: var(--bg); border-radius: var(--radius-sm); padding: .75rem 1rem;
             font-size: .9rem; line-height: 1.6; white-space: pre-wrap; }

/* ===== Edit form ===== */
.edit-form { /* full width */ }
.edit-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 2rem;
  align-items: start;
}
.edit-cover-col img, .edit-cover-col .cover-placeholder.large {
  width: 100%; border-radius: var(--radius); box-shadow: var(--shadow);
}
.edit-cover-col .cover-placeholder.large { aspect-ratio: 2/3; }
.edit-fields-col { display: flex; flex-direction: column; gap: 1.25rem; }

/* ===== Upload drop zone ===== */
.drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 2.5rem 2rem; text-align: center;
  transition: border-color var(--transition), background var(--transition);
  cursor: default;
}
.drop-zone.drag-over { border-color: var(--accent); background: rgba(203,166,247,.05); }
.drop-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.drop-text { font-weight: 600; margin-bottom: .3rem; }
.drop-sub { color: var(--text-muted); font-size: .85rem; margin-bottom: .75rem; }
.drop-files { margin-top: .75rem; font-size: .8rem; color: var(--accent); font-weight: 500;
              word-break: break-all; }

/* ===== Settings ===== */
.settings-layout { max-width: 700px; }
.calibre-status {
  display: flex; justify-content: space-between; align-items: center;
  padding: .75rem 1rem; border-radius: var(--radius-sm);
  margin: 1rem 0; font-weight: 600;
}
.calibre-ok { background: rgba(64,160,43,.1); color: var(--success); }
.calibre-stats { display: flex; gap: 1rem; font-size: .8rem; font-weight: 400; }

.calibre-detail { margin: .75rem 0; }
.calibre-detail h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em;
                     color: var(--text-muted); margin-bottom: .5rem; }
.column-list { display: flex; flex-direction: column; gap: .3rem; }
.column-item { display: flex; justify-content: space-between; align-items: center;
               padding: .35rem .6rem; background: var(--bg); border-radius: var(--radius-sm); }
.column-name { font-size: .875rem; font-weight: 500; }
.column-type { font-size: .78rem; color: var(--text-muted); }

/* ===== Sync page ===== */
.last-sync-info { margin-bottom: 1.25rem; font-size: .9rem; }

.sync-phase { animation: slideIn .2s ease; }

.sync-card {
  max-width: 520px; margin: 0 auto;
  text-align: center; padding: 2.5rem 2rem;
}
.sync-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.sync-spinner { font-size: 2rem; margin-bottom: .75rem; animation: spin 2s linear infinite; display: inline-block; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.sync-card p { margin-bottom: .5rem; }
.sync-card .btn { margin-top: 1rem; }

.sync-results-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; gap: 1rem; flex-wrap: wrap;
}
.sync-results-actions { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }

.sync-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.sync-table thead th {
  text-align: left; padding: .75rem 1rem;
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.sync-table tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
.sync-table tbody tr:last-child { border-bottom: none; }
.sync-table tbody tr:hover { background: var(--bg); }
.sync-table td { padding: .7rem 1rem; vertical-align: middle; }
.sync-table td input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.sync-table-title { font-weight: 600; }

.progress-bar-wrap {
  width: 100%; height: 10px;
  background: var(--border); border-radius: 10px; overflow: hidden;
}
.progress-bar-fill {
  height: 100%; background: var(--accent);
  border-radius: 10px;
  transition: width .3s ease;
}

/* ===== Upload progress ===== */
.upload-progress {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem 0 1rem;
  text-align: center;
}
.upload-progress.visible { display: flex; }
.upload-pct {
  font-size: 3rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.upload-label {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: .25rem;
}
.upload-info {
  font-size: .8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.upload-processing {
  display: none;
  align-items: center;
  gap: .5rem;
  color: var(--text-muted);
  font-size: .875rem;
}
.upload-processing.visible { display: flex; }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Saved searches ===== */
.saved-searches {
  display: flex; align-items: center; gap: .4rem;
  flex-wrap: wrap; margin-bottom: 1rem;
}
.saved-searches-label {
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted); margin-right: .2rem;
}
.saved-search-chip {
  display: inline-block; padding: .3rem .75rem;
  border-radius: 20px; font-size: .8rem; font-weight: 500;
  background: var(--card-bg); border: 1px solid var(--border);
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
}
.saved-search-chip:hover { border-color: var(--accent); color: var(--accent); }
.saved-search-chip.active { background: var(--accent); border-color: var(--accent); color: #1e1e2e; font-weight: 600; }

/* ===== Utilities ===== */
.text-muted { color: var(--text-muted); font-size: .875rem; }
code { background: var(--border); padding: .1em .35em; border-radius: 3px;
       font-family: 'Courier New', monospace; font-size: .85em; }

/* ===== Nav badge ===== */
.nav-badge {
  margin-left: auto;
  background: var(--error);
  color: white;
  font-size: .65rem; font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 .3rem;
}

/* ===== Stats page ===== */
.stats-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}
.stats-col { display: flex; flex-direction: column; gap: 1.5rem; }

/* Bar chart mensile */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  height: 140px;
  padding-top: 1.5rem;
}
.bar-group { display: flex; flex-direction: column; align-items: center; gap: .3rem; flex: 1; }
.bar-wrap { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.bar-val { font-size: .7rem; color: var(--text-muted); margin-bottom: .2rem; }
.bar-fill {
  width: 70%; min-height: 4px;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  transition: height .4s ease;
}
.bar-label { font-size: .7rem; color: var(--text-muted); white-space: nowrap; }

/* Breakdown bar */
.breakdown-bar {
  display: flex; height: 18px; border-radius: 9px; overflow: hidden; margin: .75rem 0;
}
.seg { height: 100%; transition: width .4s ease; }
.seg-read    { background: var(--success); }
.seg-reading { background: var(--warning); }
.seg-unread  { background: var(--border); }

.breakdown-legend { display: flex; flex-wrap: wrap; gap: .75rem; }
.legend-item { display: flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--text-muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-read    { background: var(--success); }
.dot-reading { background: var(--warning); }
.dot-unread  { background: var(--border); border: 1px solid var(--text-muted); }

/* Tag cloud */
.tag-cloud { display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; }
.tag-cloud-item {
  color: var(--accent-dark); background: rgba(203,166,247,.12);
  padding: .15rem .5rem; border-radius: 20px;
  transition: background var(--transition);
}
.tag-cloud-item:hover { background: rgba(203,166,247,.28); }
.tag-cloud-item sup { font-size: .6em; opacity: .7; }

/* Author chart */
.author-chart { display: flex; flex-direction: column; gap: .5rem; }
.author-row { display: grid; grid-template-columns: 1fr 2fr auto; gap: .6rem; align-items: center; }
.author-name { font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.author-bar-wrap { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.author-bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width .4s ease; }
.author-cnt { font-size: .78rem; font-weight: 600; color: var(--accent); }

/* Top rated list */
.top-rated-list { display: flex; flex-direction: column; gap: .6rem; }
.top-rated-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem; border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.top-rated-row:hover { background: var(--border); }
.top-rated-cover { width: 36px; height: 54px; object-fit: cover; border-radius: 3px; flex-shrink: 0; }
.top-rated-placeholder {
  width: 36px; height: 54px; border-radius: 3px; flex-shrink: 0;
  background: var(--accent); color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.top-rated-info { min-width: 0; }
.top-rated-title { font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== Btn ghost ===== */
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--border); color: var(--text); }

/* ===== Home page ===== */
.home-section { margin-bottom: 2rem; }
.section-title {
  font-size: .8rem; font-weight: 700; margin-bottom: 1rem;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: .35rem;
  transition: transform var(--transition), box-shadow var(--transition);
}
a.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon { font-size: 1.8rem; line-height: 1; }
.stat-value { font-size: 2rem; font-weight: 800; color: var(--accent); line-height: 1; }
.stat-label { font-size: .8rem; color: var(--text-muted); font-weight: 500; }

/* ===== Carousel ===== */
.carousel-outer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
}
.carousel-viewport {
  flex: none;
  overflow: hidden;
}
.carousel-track {
  display: flex;
  gap: 1rem;
  transition: transform .4s cubic-bezier(.4,0,.2,1);
  will-change: transform;
}
.carousel-slide {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
  color: var(--text);
}
.carousel-slide:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }

.carousel-cover-wrap {
  position: relative;
  aspect-ratio: 2/3;
  background: var(--border);
  overflow: hidden;
}
.carousel-cover-img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.carousel-cover-placeholder {
  width: 100%; height: 100%;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: 2.5rem; font-weight: 800; color: white;
}
.carousel-info {
  padding: .65rem .75rem .8rem;
  display: flex; flex-direction: column; gap: .2rem;
}
.carousel-title {
  font-size: .85rem; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.carousel-author { color: var(--text-muted); font-size: .78rem;
                   overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.carousel-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--card-bg);
  border: 1px solid var(--border);
  font-size: 1.4rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  color: var(--text);
  transition: background var(--transition), color var(--transition), opacity var(--transition);
  user-select: none;
}
.carousel-btn:hover:not(:disabled) { background: var(--accent); color: white; border-color: var(--accent); }
.carousel-btn:disabled { opacity: .35; cursor: default; }

.carousel-dots {
  display: flex;
  justify-content: center;
  gap: .5rem;
  margin-top: .75rem;
  margin-bottom: 2rem;
}
.carousel-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--border);
  cursor: pointer;
  border: none;
  padding: 0;
  transition: background var(--transition), transform var(--transition);
}
.carousel-dot.active { background: var(--accent); transform: scale(1.4); }

/* ===== Mobile topbar (nascosta su desktop) ===== */
.mobile-topbar { display: none; }
.sidebar-overlay { display: none; }
.sidebar-close { display: none; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  /* Topbar */
  .mobile-topbar {
    display: flex; align-items: center; gap: .75rem;
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    height: 52px; padding: 0 1rem;
    background: var(--sidebar-bg);
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
  }
  .hamburger {
    color: var(--sidebar-text); padding: .3rem;
    border-radius: var(--radius-sm); flex-shrink: 0;
    transition: background var(--transition);
  }
  .hamburger:hover { background: var(--sidebar-hover); }
  .hamburger svg { width: 22px; height: 22px; display: block; }
  .mobile-title { color: var(--sidebar-text); font-weight: 700; font-size: .95rem; flex: 1; }
  .mobile-upload-btn {
    color: var(--sidebar-muted); padding: .3rem;
    transition: color var(--transition);
  }
  .mobile-upload-btn:hover { color: var(--sidebar-text); }
  .mobile-upload-btn svg { width: 20px; height: 20px; display: block; }

  /* Sidebar come drawer laterale */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 300;
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-close {
    display: flex; align-items: center; justify-content: center;
    margin-left: auto; color: var(--sidebar-muted); padding: .25rem;
    border-radius: var(--radius-sm);
    transition: color var(--transition);
  }
  .sidebar-close:hover { color: var(--sidebar-text); }
  .sidebar-close svg { width: 18px; height: 18px; }

  /* Overlay scuro dietro il drawer */
  .sidebar-overlay {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 250;
    opacity: 0; pointer-events: none;
    transition: opacity .25s ease;
  }
  .sidebar-overlay.visible { opacity: 1; pointer-events: auto; }

  /* Main content sotto la topbar */
  .layout { display: block; }
  .main-content {
    margin-left: 0;
    padding: 1rem;
    padding-top: calc(52px + 1rem);
  }

  /* Griglia libri */
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .85rem; }

  /* Layout pagine */
  .book-detail { grid-template-columns: 1fr; }
  .detail-cover { max-width: 200px; margin: 0 auto; }
  .edit-layout { grid-template-columns: 1fr; }
  .edit-cover-col { max-width: 180px; }

  /* Form */
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }

  /* Lista libri: mostra solo colonne essenziali */
  .list-header { grid-template-columns: 36px 1fr auto; }
  .list-row { grid-template-columns: 36px 1fr auto; }
  .list-header span:nth-child(n+3):not(:nth-child(5)),
  .list-row > span:nth-child(n+3):not(:nth-child(5)) { display: none; }

  /* Toolbar */
  .toolbar { flex-direction: column; align-items: stretch; }
  .search-form { width: 100%; }
  .toolbar-right { justify-content: flex-end; }

  /* Saved searches scroll orizzontale su mobile */
  .saved-searches { flex-wrap: nowrap; overflow-x: auto; padding-bottom: .3rem; }
  .saved-searches::-webkit-scrollbar { height: 3px; }
  .saved-searches::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

  /* Auth */
  .auth-card { padding: 2rem 1.25rem; }

  /* Home */
  .stats-grid { grid-template-columns: repeat(3, 1fr); gap: .75rem; }
  .stat-card { padding: 1rem; }
  .stat-value { font-size: 1.6rem; }

  /* Stats */
  .stats-layout { grid-template-columns: 1fr; }

  /* Carousel mobile: 1 carta visibile, bottoni più piccoli */
  .carousel-btn { width: 28px; height: 28px; font-size: 1.1rem; }
  .stats-grid { grid-template-columns: repeat(3, 1fr); gap: .5rem; }
  .stat-card { padding: .75rem .5rem; }
  .stat-value { font-size: 1.4rem; }
  .stat-icon { font-size: 1.4rem; }
}

/* ── Recensioni ── */
.reviews-section { margin-top: 2rem; }
.reviews-section .section-label { margin-bottom: .75rem; }

.review-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  margin-bottom: .75rem;
}
.review-card.own { border-color: var(--accent); }

.review-header {
  display: flex; align-items: center; gap: .6rem;
  flex-wrap: wrap; margin-bottom: .5rem;
}
.review-username {
  font-weight: 600; font-size: .88rem;
}
.review-you {
  font-size: .72rem; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-radius: 4px; padding: 1px 6px; font-weight: 600;
}
.review-stars { color: var(--accent); letter-spacing: .05em; font-size: .9rem; }
.review-date {
  font-size: .72rem; color: var(--text-muted);
  margin-left: auto;
}
.review-text {
  font-size: .875rem; color: var(--text); line-height: 1.6;
  white-space: pre-line;
}
.review-edit-link {
  display: inline-block; margin-top: .5rem;
  font-size: .75rem; color: var(--text-muted);
  background: none; border: none; border-bottom: 1px dashed var(--border);
  padding: 0; cursor: pointer; font-family: inherit;
}
.review-edit-link:hover { color: var(--accent); border-color: var(--accent); }

.add-review-prompt {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1rem;
  border: 1px dashed var(--border); border-radius: 10px;
  color: var(--text-muted); font-size: .875rem;
}
.btn-link-accent {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--accent); font-weight: 500; font-size: inherit;
  white-space: nowrap;
}
.btn-link-accent:hover { text-decoration: underline; }

/* Stelle interattive */
.star-selector {
  display: flex; gap: .2rem; font-size: 2rem;
  cursor: pointer; margin-bottom: 1rem; width: fit-content;
}
.star-btn { color: var(--border); transition: color .1s; user-select: none; line-height: 1; }
.star-btn.lit { color: #f5a623; }

/* Form inline recensione */
.review-form-card {
  background: var(--card-bg);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-top: 1rem;
}
.review-form-title { font-size: 1rem; font-weight: 600; margin-bottom: .875rem; }
.review-textarea {
  width: 100%; box-sizing: border-box;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: .6rem .75rem; font-size: .9rem; font-family: inherit;
  resize: vertical; margin-bottom: 1rem;
}
.review-textarea:focus { outline: none; border-color: var(--accent); }
.review-form-actions { display: flex; gap: .75rem; }

/* ── Paginazione ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  padding: 1.75rem 0 .75rem;
  flex-wrap: wrap;
}
.page-btn {
  min-width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; padding: 0 .55rem;
  font-size: .82rem; font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--card-bg);
  transition: background .15s, color .15s, border-color .15s;
  user-select: none;
}
.page-btn:hover { background: var(--border); color: var(--text); }
.page-current {
  background: var(--accent); border-color: var(--accent);
  color: #fff; font-weight: 600;
  pointer-events: none;
}
.page-disabled {
  opacity: .3; pointer-events: none;
}
.page-ellipsis {
  color: var(--text-muted); font-size: .82rem;
  padding: 0 .2rem; line-height: 34px;
}
.page-info {
  font-size: .73rem; color: var(--text-muted);
  text-align: center; padding-bottom: 1.5rem;
}

