/* ════════════════════════════════════════════════════════════
   components.css — Tutti i componenti UI
   Bottoni · Form · Modal · Book Cards · Tabelle ·
   Stat Cards · Location Tree · User Cards · Mobile Sheets
   ════════════════════════════════════════════════════════════ */

/* ══════════════════ BUTTONS ═════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .62rem 1.25rem;
  border-radius: var(--radius);
  font-family: var(--sans); font-size: .875rem; font-weight: 600;
  cursor: pointer; border: none;
  transition: all var(--tr);
  letter-spacing: .01em;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--blue) 0%, #1a5de0 100%);
  color: #fff;
  box-shadow: 0 2px 12px var(--blue-glow);
}
.btn-primary:hover {
  box-shadow: 0 4px 24px var(--blue-glow);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-red {
  background: linear-gradient(135deg, var(--red) 0%, #c02015 100%);
  color: #fff;
  box-shadow: 0 2px 12px var(--red-glow);
}
.btn-red:hover { box-shadow: 0 4px 24px var(--red-glow); transform: translateY(-1px); }

.btn-ghost {
  background: var(--night-3);
  color: var(--ink);
  border: 1px solid var(--night-4);
}
.btn-ghost:hover { border-color: var(--blue); color: var(--blue-text); background: var(--blue-dim); }

.btn-sm { padding: .4rem .85rem; font-size: .8rem; }

/* FAB — mobile floating action button */
.btn-fab {
  position: fixed;
  bottom: calc(var(--mobile-nav-h) + 1.2rem);
  right: 1.2rem;
  width: 54px; height: 54px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--red));
  color: #fff; border: none; cursor: pointer;
  display: none;
  align-items: center; justify-content: center;
  box-shadow: 0 6px 32px var(--blue-glow), 0 6px 32px var(--red-glow);
  z-index: 150;
  transition: all var(--tr-spring);
}
.btn-fab:hover { transform: scale(1.08); }
.btn-fab:active { transform: scale(.95); }
@media (max-width: 768px) { .btn-fab { display: flex; } }

/* ══════════════════ FORM INPUTS ═════════════════════════ */
.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-group.full { grid-column: 1 / -1; }
.form-group label {
  font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--ink-dim);
}
.form-group input,
.form-group select,
.form-group textarea {
  background: var(--night-2);
  border: 1px solid var(--night-4);
  border-radius: var(--radius);
  padding: .75rem .95rem;
  font-family: var(--sans); font-size: .875rem;
  color: var(--ink-bright); outline: none; width: 100%;
  transition: border-color var(--tr), box-shadow var(--tr);
  -webkit-appearance: none;
}
.form-group input::placeholder { color: var(--ink-dim); }
.form-group select { color: var(--ink); }
.form-group select option { background: var(--night-2); }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-dim);
}
textarea { resize: vertical; min-height: 80px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ══════════════════ MODAL ═══════════════════════════════ */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(8px);
  z-index: 200; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--night-2);
  border: 1px solid var(--night-4);
  border-radius: var(--radius-lg);
  width: 90vw; max-width: 660px; max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(59,124,244,.08);
  animation: modalIn .25s cubic-bezier(.34,1.2,.64,1);
}
.modal::-webkit-scrollbar { width: 4px; }
.modal::-webkit-scrollbar-track { background: var(--night-2); }
.modal::-webkit-scrollbar-thumb { background: var(--night-4); border-radius: 2px; }

.modal-header {
  padding: 1.6rem 2rem 1.2rem;
  border-bottom: 1px solid var(--night-3);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0;
  background: var(--night-2); z-index: 1;
}
.modal-header h3 { font-family: var(--serif); font-size: 1.45rem; color: var(--white); }
.modal-stripe {
  width: 3px; height: 26px; border-radius: 2px;
  background: linear-gradient(180deg, var(--blue), var(--red));
  margin-right: .75rem; flex-shrink: 0;
  box-shadow: 0 0 10px var(--blue-glow);
}
.modal-header-inner { display: flex; align-items: center; }
.modal-close {
  background: var(--night-3); border: 1px solid var(--night-4);
  cursor: pointer; color: var(--ink-dim);
  padding: .4rem; border-radius: var(--radius-sm);
  transition: all var(--tr); line-height: 1;
}
.modal-close:hover { background: var(--red-dim); color: var(--red-text); border-color: rgba(232,53,43,.3); }

.modal-body { padding: 1.6rem 2rem; }

.modal-footer {
  padding: 1.2rem 2rem;
  border-top: 1px solid var(--night-3);
  display: flex; justify-content: flex-end; gap: .6rem;
  background: var(--night-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Mobile: bottom sheet */
@media (max-width: 768px) {
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    width: 100%; max-width: 100%; max-height: 90vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: sheetUp .3s cubic-bezier(.34,1.1,.64,1);
    border-bottom: none;
  }
  .modal-header { padding: 1.2rem 1.4rem 1rem; }
  .modal-body   { padding: 1.2rem 1.4rem; }
  .modal-footer { padding: 1rem 1.4rem; }
  .form-grid    { grid-template-columns: 1fr; }

  /* Drag handle */
  .modal::before {
    content: '';
    display: block; margin: .75rem auto .25rem;
    width: 36px; height: 4px; border-radius: 2px;
    background: var(--night-4);
  }
}

/* ══════════════════ STAT CARDS ══════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem; margin-bottom: 2rem;
}
.stat-card {
  background: var(--night-2);
  border: 1px solid var(--night-3);
  border-radius: var(--radius-lg);
  padding: 1.4rem 1.5rem;
  position: relative; overflow: hidden;
  transition: border-color var(--tr), box-shadow var(--tr), transform var(--tr);
  cursor: default;
}
.stat-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.stat-card:nth-child(1)::before { background: linear-gradient(90deg, var(--blue), var(--blue-bright)); }
.stat-card:nth-child(2)::before { background: linear-gradient(90deg, var(--red), var(--red-bright)); }
.stat-card:nth-child(3)::before { background: linear-gradient(90deg, var(--blue-bright), #60a5fa); }
.stat-card:nth-child(4)::before { background: linear-gradient(90deg, var(--gold), #fcd34d); }
.stat-card:hover {
  border-color: var(--night-4);
  box-shadow: var(--shadow-md);
  transform: translateY(-3px);
}
.stat-card:nth-child(1):hover { box-shadow: var(--shadow-md), 0 0 20px var(--blue-glow); }
.stat-card:nth-child(2):hover { box-shadow: var(--shadow-md), 0 0 20px var(--red-glow); }

.stat-label {
  font-size: .68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-dim); margin-bottom: .5rem;
}
.stat-value {
  font-family: var(--display);
  font-size: 3rem; letter-spacing: .04em; line-height: 1;
  color: var(--white);
}
.stat-sub { font-size: .78rem; color: var(--ink-dim); margin-top: .35rem; font-weight: 300; }

/* Mobile stat cards — horizontal scroll */
@media (max-width: 768px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: .75rem; margin-bottom: 1.5rem;
  }
  .stat-card { padding: 1rem 1.1rem; }
  .stat-value { font-size: 2.2rem; }
}

/* ══════════════════ BOOK CARDS ══════════════════════════ */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.2rem;
}
.book-card {
  background: var(--night-2);
  border: 1px solid var(--night-3);
  border-radius: var(--radius-lg);
  overflow: hidden; cursor: pointer;
  transition: all var(--tr);
  display: flex; flex-direction: column;
  position: relative;
}
.book-card::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: var(--radius-lg);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04);
  pointer-events: none;
}
.book-card:hover {
  transform: translateY(-5px) scale(1.01);
  border-color: var(--blue);
  box-shadow: var(--shadow-md), 0 0 24px var(--blue-glow);
}

/* Barra colorata in cima — simula la costola del libro */
.book-bar {
  height: 4px;
  background: linear-gradient(90deg, var(--blue), var(--blue-bright));
  position: relative;
}
.book-bar::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.2), transparent);
  animation: shimmer 3s infinite;
  background-size: 200% 100%;
}
.book-bar.g-sagg { background: linear-gradient(90deg, #059669, #34d399); }
.book-bar.g-fan  { background: linear-gradient(90deg, #7c3aed, #c084fc); }
.book-bar.g-stor { background: linear-gradient(90deg, var(--red), #fb923c); }
.book-bar.g-pol  { background: linear-gradient(90deg, #0ea5e9, #7dd3fc); }

.book-body { padding: 1.1rem; flex: 1; display: flex; flex-direction: column; gap: .25rem; }

.book-genre {
  font-size: .66rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--blue-text); background: var(--blue-dim);
  display: inline-block; border-radius: 4px;
  padding: .15rem .55rem; margin-bottom: .4rem;
  border: 1px solid rgba(59,124,244,.2);
}
.book-title {
  font-family: var(--serif); font-size: .95rem; font-weight: 400;
  line-height: 1.35; color: var(--white);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.book-author { font-size: .78rem; color: var(--ink-dim); font-weight: 300; }
.book-loc {
  margin-top: auto; padding-top: .85rem;
  display: flex; align-items: center; gap: .4rem;
  font-size: .72rem; color: var(--ink-dim);
  border-top: 1px solid var(--night-3);
}
.book-loc svg { color: var(--red-bright); flex-shrink: 0; }

/* Mobile: 2 columns */
@media (max-width: 768px) {
  .books-grid { grid-template-columns: repeat(2, 1fr); gap: .75rem; }
  .book-body  { padding: .9rem; }
  .book-title { font-size: .88rem; }
}
@media (max-width: 360px) {
  .books-grid { grid-template-columns: 1fr; }
}

/* ══════════════════ TABLE ═══════════════════════════════ */
.table-wrap {
  background: var(--night-2);
  border: 1px solid var(--night-3);
  border-radius: var(--radius-lg); overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
thead { background: var(--night-3); }
th {
  text-align: left; padding: .85rem 1.2rem;
  font-size: .7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--ink-dim);
}
td {
  padding: .85rem 1.2rem;
  border-bottom: 1px solid var(--night-3);
  font-size: .875rem; vertical-align: middle;
  color: var(--ink);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--night-3); cursor: pointer; }
.td-title { font-family: var(--serif); color: var(--white); }

/* Mobile: table scrolls horizontally */
@media (max-width: 768px) {
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 600px; }
}

/* ══════════════════ BADGES ══════════════════════════════ */
.loc-badge {
  display: inline-flex; align-items: center; gap: .35rem;
  background: var(--blue-dim); color: var(--blue-text);
  border: 1px solid rgba(59,124,244,.2);
  border-radius: var(--radius-sm); padding: .2rem .65rem;
  font-size: .75rem; font-weight: 600;
}
.genre-badge {
  background: var(--night-3); color: var(--ink-dim);
  border: 1px solid var(--night-4);
  border-radius: var(--radius-sm); padding: .2rem .55rem;
  font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
}

/* ══════════════════ BOOK DETAIL ═════════════════════════ */
.detail-loc {
  display: flex; align-items: center; gap: 1rem;
  background: linear-gradient(135deg, rgba(59,124,244,.15), rgba(232,53,43,.08));
  border: 1px solid rgba(59,124,244,.2);
  border-radius: var(--radius);
  padding: 1rem 1.3rem; margin-bottom: 1.4rem;
}
.detail-loc svg { color: var(--blue-text); flex-shrink: 0; }
.detail-loc-text strong { font-size: .95rem; color: var(--white); display: block; }
.detail-loc-text span   { font-size: .78rem; color: var(--ink-dim); }

.detail-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: .85rem; margin-bottom: 1.2rem;
}
.detail-item .dl {
  font-size: .68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--ink-dim); margin-bottom: .25rem;
}
.detail-item .dd { font-size: .9rem; color: var(--ink); }
.detail-notes {
  background: var(--night-3); border: 1px solid var(--night-4);
  border-radius: var(--radius); padding: .9rem 1.1rem;
  font-size: .875rem; color: var(--ink-dim); font-weight: 300;
  line-height: 1.7;
}

@media (max-width: 768px) {
  .detail-grid { grid-template-columns: 1fr; }
}

/* ══════════════════ VIEW TOGGLE ═════════════════════════ */
.view-toggle { display: flex; gap: .3rem; }
.view-btn {
  background: var(--night-3); border: 1px solid var(--night-4);
  border-radius: var(--radius-sm); padding: .48rem .65rem;
  cursor: pointer; color: var(--ink-dim); transition: all var(--tr); line-height: 1;
}
.view-btn.active {
  background: var(--blue); border-color: var(--blue); color: #fff;
  box-shadow: 0 2px 10px var(--blue-glow);
}
.view-btn:hover:not(.active) { border-color: var(--blue); color: var(--blue-text); }

/* ══════════════════ SEARCH RESULTS ═════════════════════ */
.results-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.4rem;
}
.results-count { font-size: .875rem; color: var(--ink-dim); }
.results-count strong { color: var(--white); }

/* ══════════════════ LOCATION TREE ══════════════════════ */
.loc-node {
  background: var(--night-2); border: 1px solid var(--night-3);
  border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 1rem;
  transition: border-color var(--tr);
}
.loc-node:hover { border-color: var(--night-4); }

.loc-node-head {
  background: linear-gradient(90deg, var(--night-3), var(--night-4));
  padding: 1rem 1.4rem;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--night-4);
}
.loc-node-head h3 {
  font-size: .95rem; font-weight: 600; color: var(--white);
  display: flex; align-items: center; gap: .6rem;
}
.loc-node-head h3 svg { color: var(--blue-text); }
.loc-node-head span { font-size: .78rem; color: var(--ink-dim); }
.loc-node-head-actions { display: flex; align-items: center; gap: .75rem; }

.btn-add-scaffale {
  background: rgba(59,124,244,.1); border: 1px solid rgba(59,124,244,.25);
  color: var(--blue-text); border-radius: var(--radius-sm);
  padding: .3rem .75rem; cursor: pointer;
  font-family: var(--sans); font-size: .78rem;
  transition: all var(--tr);
}
.btn-add-scaffale:hover { background: var(--blue-dim); border-color: var(--blue); }

.scaffale-list { padding: .75rem; display: flex; flex-direction: column; gap: .4rem; }
.scaffale-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: .65rem 1rem;
  background: var(--night-3); border-radius: var(--radius-sm);
  font-size: .875rem; border: 1px solid transparent;
  transition: border-color var(--tr);
}
.scaffale-item:hover { border-color: var(--night-4); }
.scaffale-name { font-weight: 500; color: var(--ink); }
.scaffale-count {
  background: var(--blue-dim); color: var(--blue-text);
  border: 1px solid rgba(59,124,244,.2);
  border-radius: 100px; font-size: .72rem; font-weight: 600;
  padding: .12rem .6rem;
}

/* Mobile: location cards fullwidth */
@media (max-width: 768px) {
  .loc-node-head { flex-direction: column; align-items: flex-start; gap: .6rem; }
  .loc-node-head-actions { width: 100%; justify-content: space-between; }
}

/* ══════════════════ USER CARDS ══════════════════════════ */
.user-card {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--night-2); border: 1px solid var(--night-3);
  border-radius: var(--radius); padding: 1rem 1.4rem; margin-bottom: .6rem;
  transition: border-color var(--tr), box-shadow var(--tr);
}
.user-card:hover { border-color: var(--night-4); box-shadow: var(--shadow-sm); }
.user-card-left { display: flex; align-items: center; gap: .9rem; }
.uavatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--red));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem; color: #fff; flex-shrink: 0;
  box-shadow: 0 2px 10px var(--blue-glow);
}
.uname  { font-weight: 600; font-size: .95rem; color: var(--white); }
.uemail { font-size: .78rem; color: var(--ink-dim); }
.role-badge {
  font-size: .68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  border-radius: var(--radius-sm); padding: .2rem .65rem;
}
.role-badge.admin  { background: var(--red-dim); color: var(--red-text); border: 1px solid rgba(232,53,43,.25); }
.role-badge.utente { background: var(--blue-dim); color: var(--blue-text); border: 1px solid rgba(59,124,244,.25); }

/* Mobile: user cards responsive */
@media (max-width: 768px) {
  .user-card { flex-direction: column; align-items: flex-start; gap: .75rem; }
  .user-card-left { width: 100%; }
  .user-card > div:last-child { width: 100%; justify-content: flex-end; }
}

/* ══════════════════ MOBILE UTILS ════════════════════════ */
/* Pull-to-refresh indicator placeholder */
@media (max-width: 768px) {
  /* Scrollbar mobile nascosta */
  * { scrollbar-width: none; }
  *::-webkit-scrollbar { display: none; }

  /* Touch feedback */
  .book-card:active { transform: scale(.97); }
  .btn:active       { transform: scale(.96); }
  .nav-item:active  { opacity: .6; }

  /* Safe area per notch */
  .modal-footer { padding-bottom: max(1rem, env(safe-area-inset-bottom)); }
  #sidebar {
    /*padding-bottom: env(safe-area-inset-bottom);*/
    padding-bottom: 2.5%;
    height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom));
  }
}

/* ══════════════════ MOBILE OVERFLOW FIX (Extra) ═════════ */
/* Garantisce che nessun figlio forzi larghezza > 100vw   */
@media (max-width: 768px) {
  /* Table nella dashboard: min-width ridotto per fit mobile */
  .table-wrap table { min-width: 440px; }

  /* Stat card text non va a capo in modo strano */
  .stat-label { font-size: .62rem; }
  .stat-sub   { font-size: .72rem; }

  /* Book card body non esplode */
  .book-body { overflow: hidden; }
  .book-title { font-size: .85rem; }

  /* Auth form su mobile: nessun overflow */
  .auth-form-panel { max-width: 100vw; overflow-x: hidden; }
  .auth-form-inner { max-width: 100%; }
  .form-field input { font-size: 16px; } /* previene zoom iOS */
  .form-group input,
  .form-group select,
  .form-group textarea { font-size: 16px; } /* previene zoom iOS */

  /* Modal: nessun overflow */
  .modal { max-width: 100vw; overflow-x: hidden; }
  .modal-body { overflow-x: hidden; }

  /* Location tree su mobile */
  .loc-node { overflow: hidden; }
  .scaffale-item { flex-wrap: wrap; gap: .4rem; }
}

/* ══════════════════ PAGINAZIONE ═════════════════════════ */
.pagination-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-top: 1.8rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--night-3);
}

.pagination-info {
  font-size: .8rem;
  color: var(--ink-dim);
  font-weight: 300;
  white-space: nowrap;
}
.pagination-info strong { color: var(--ink); font-weight: 600; }

.pagination-controls {
  display: flex;
  align-items: center;
  gap: .3rem;
}

.pg-btn {
  min-width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--night-2);
  border: 1px solid var(--night-4);
  border-radius: var(--radius-sm);
  color: var(--ink-dim);
  font-family: var(--sans); font-size: .82rem; font-weight: 500;
  cursor: pointer;
  transition: all var(--tr);
  padding: 0 .5rem;
  text-decoration: none;
  user-select: none;
}
.pg-btn:hover:not(:disabled):not(.pg-btn--active) {
  background: var(--night-3);
  border-color: var(--blue);
  color: var(--blue-text);
}
.pg-btn--active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  box-shadow: 0 2px 10px var(--blue-glow);
  cursor: default;
}
.pg-btn--nav { gap: .25rem; }
.pg-btn:disabled {
  opacity: .3;
  cursor: not-allowed;
}
.pg-btn--ellipsis {
  background: transparent;
  border-color: transparent;
  cursor: default;
  color: var(--ink-dim);
  pointer-events: none;
}

/* Selettore "per pagina" */
.pagination-perpage {
  display: flex; align-items: center; gap: .5rem;
  font-size: .78rem; color: var(--ink-dim);
}
.pagination-perpage select {
  background: var(--night-2);
  border: 1px solid var(--night-4);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-family: var(--sans); font-size: .78rem;
  padding: .3rem .5rem;
  outline: none;
  cursor: pointer;
  transition: border-color var(--tr);
}
.pagination-perpage select:focus { border-color: var(--blue); }

/* ══════════════════ ORDINAMENTO ══════════════════════════ */
.sort-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}
.sort-bar-label {
  font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--ink-dim);
  white-space: nowrap;
}
.sort-btn {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .35rem .75rem;
  background: var(--night-2);
  border: 1px solid var(--night-4);
  border-radius: 100px;
  font-family: var(--sans); font-size: .78rem; font-weight: 500;
  color: var(--ink-dim);
  cursor: pointer;
  transition: all var(--tr);
  white-space: nowrap;
}
.sort-btn:hover { border-color: var(--blue); color: var(--blue-text); }
.sort-btn.active {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: var(--blue-text);
  font-weight: 600;
}
.sort-btn .sort-arrow {
  font-size: .7rem;
  display: inline-block;
  transition: transform var(--tr);
}
.sort-btn.active .sort-arrow { color: var(--blue-bright); }

/* Mobile paginazione */
@media(max-width:768px) {
  .pagination-wrap { justify-content: center; flex-direction: column; align-items: center; gap: .6rem; }
  .pagination-info { text-align: center; }
  .pg-btn { min-width: 38px; height: 38px; font-size: .85rem; }
  .sort-bar { gap: .35rem; }
  .sort-btn { font-size: .75rem; padding: .32rem .65rem; }
  .pagination-perpage { justify-content: center; }
}

/* ══════════════════ EDIT INLINE — posizioni & scaffali ══ */
.btn-loc-action {
  background: rgba(59,124,244,.1);
  border: 1px solid rgba(59,124,244,.2);
  color: var(--blue-text);
  border-radius: var(--radius-sm);
  padding: .28rem .42rem;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all var(--tr);
  line-height: 1;
  flex-shrink: 0;
}
.btn-loc-action:hover {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: var(--blue-bright);
  transform: scale(1.08);
}
.btn-loc-action:active { transform: scale(.95); }

/* Scaffale item ora ha layout flex per ospitare il bottone edit */
.scaffale-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.scaffale-name { font-weight: 600; flex: 1; min-width: 0; }

/* Nasconde edit button fino all'hover sulla riga */
.scaffale-item .btn-edit-scaffale {
  opacity: 0;
  transition: opacity var(--tr), background var(--tr);
}
.scaffale-item:hover .btn-edit-scaffale { opacity: 1; }

/* Su mobile: sempre visibile */
@media(max-width:768px) {
  .scaffale-item .btn-edit-scaffale { opacity: 1; }
  .btn-edit-posizione { opacity: 1 !important; }
}

/* Bottone edit posizione — visibile solo su hover della testata */
.btn-edit-posizione {
  opacity: 0;
  transition: opacity var(--tr), background var(--tr);
}
.loc-node-head:hover .btn-edit-posizione { opacity: 1; }

/* ══════════════════ ISBN SCANNER ════════════════════════ */

/* ── Bottone scanner accanto al campo ISBN ───────────────── */
.isbn-input-wrap {
  display: flex;
  align-items: stretch;
  gap: 0;
}
.isbn-input-wrap input {
  border-radius: var(--radius) 0 0 var(--radius) !important;
  flex: 1;
  min-width: 0;
}
.btn-isbn-scan {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  width: 42px;
  background: var(--blue);
  border: 1px solid var(--blue);
  border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  color: #fff;
  cursor: pointer;
  transition: background var(--tr), box-shadow var(--tr), transform var(--tr);
  padding: 0;
}
.btn-isbn-scan:hover {
  background: var(--blue-mid);
  box-shadow: -2px 0 12px var(--blue-glow);
}
.btn-isbn-scan:active { transform: scale(.94); }
/* Pulse animation quando la fotocamera non è supportata */
@media (hover: none) {
  /* touch device: bottone più grande */
  .btn-isbn-scan { width: 48px; }
}

/* ── Feedback inline sotto il campo ISBN ─────────────────── */
.isbn-feedback {
  font-size: .78rem; margin-top: .3rem;
  min-height: 1rem;
  transition: opacity .2s;
}
.isbn-feedback.ok  { color: #4ade80; }
.isbn-feedback.err { color: var(--red-text); }

/* Spinner inline per il lookup ISBN */
.isbn-lookup-spinner {
  display: inline-block;
  width: 11px; height: 11px;
  border: 2px solid rgba(255,255,255,.2);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: -.15em;
  margin-right: .3rem;
}

/* ── Scanner overlay ─────────────────────────────────────── */
.isbn-scanner-root {
  display: none; /* mostrato via JS */
  position: fixed; inset: 0; z-index: 9999;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 1rem;
}

.scanner-box {
  background: var(--night-2);
  border: 1px solid var(--night-4);
  border-radius: var(--radius-lg);
  width: 100%; max-width: 420px;
  overflow: hidden;
  box-shadow: 0 32px 80px rgba(0,0,0,.9), 0 0 0 1px rgba(59,124,244,.15);
  animation: modalIn .25s cubic-bezier(.34,1.2,.64,1);
}

/* Header */
.scanner-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.2rem .85rem;
  border-bottom: 1px solid var(--night-3);
}
.scanner-title {
  display: flex; align-items: center; gap: .55rem;
  font-size: .95rem; font-weight: 600; color: var(--white);
}
.scanner-title svg { color: var(--blue-bright); }
.scanner-close {
  background: var(--night-3); border: 1px solid var(--night-4);
  color: var(--ink-dim); cursor: pointer;
  border-radius: var(--radius-sm); padding: .35rem;
  transition: all var(--tr); line-height: 1;
}
.scanner-close:hover { background: var(--red-dim); color: var(--red-text); }

/* Viewport video */
.scanner-viewport {
  position: relative;
  background: #000;
  aspect-ratio: 4/3;
  overflow: hidden;
}
.scanner-video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

/* Frame angolato sovrapposto al video */
.scanner-frame {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.scanner-frame-corner {
  position: absolute;
  width: 28px; height: 28px;
  border-color: var(--blue-bright);
  border-style: solid;
  border-width: 0;
}
.scanner-frame-corner.tl { top: 16%; left: 8%; border-top-width: 3px; border-left-width: 3px; border-radius: 4px 0 0 0; }
.scanner-frame-corner.tr { top: 16%; right: 8%; border-top-width: 3px; border-right-width: 3px; border-radius: 0 4px 0 0; }
.scanner-frame-corner.bl { bottom: 16%; left: 8%; border-bottom-width: 3px; border-left-width: 3px; border-radius: 0 0 0 4px; }
.scanner-frame-corner.br { bottom: 16%; right: 8%; border-bottom-width: 3px; border-right-width: 3px; border-radius: 0 0 4px 0; }

/* Linea di scansione animata */
.scanner-line {
  position: absolute;
  left: 9%; right: 9%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--blue-bright), var(--blue), var(--blue-bright), transparent);
  border-radius: 1px;
  box-shadow: 0 0 8px var(--blue-glow);
  animation: scanner-sweep 2s ease-in-out infinite;
}
@keyframes scanner-sweep {
  0%   { top: 17%; opacity: .9; }
  50%  { top: 80%; opacity: 1; }
  100% { top: 17%; opacity: .9; }
}

/* Hint testo sopra il video */
.scanner-hint {
  position: absolute; bottom: 10%; left: 0; right: 0;
  text-align: center;
  font-size: .78rem; color: rgba(255,255,255,.7);
  letter-spacing: .03em;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
  pointer-events: none;
}

/* Status bar (spinner + messaggio) */
.scanner-status {
  display: flex; align-items: center; gap: .65rem;
  padding: .85rem 1.2rem;
  border-top: 1px solid var(--night-3);
  font-size: .875rem; color: var(--ink-dim);
}
.scanner-spinner {
  width: 18px; height: 18px; flex-shrink: 0;
  border: 2px solid var(--night-4);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* Result panel */
.scanner-result {
  padding: 1rem 1.2rem;
  border-top: 1px solid var(--night-3);
}
.scanner-result-isbn {
  font-family: var(--display);
  font-size: 1.2rem; letter-spacing: .08em;
  color: var(--blue-bright); margin-bottom: .5rem;
}
.scanner-result-info {
  font-size: .875rem; color: var(--ink);
  line-height: 1.5; min-height: 1.5rem;
  margin-bottom: .85rem;
}
.scanner-result-actions {
  display: flex; gap: .5rem; justify-content: flex-end;
}
.scanner-result-actions .btn-primary.confirmed {
  background: #22c55e;
  box-shadow: 0 2px 10px rgba(34,197,94,.35);
}

/* Error panel */
.scanner-error {
  padding: 1.5rem 1.2rem;
  border-top: 1px solid var(--night-3);
  display: flex; flex-direction: column;
  align-items: center; gap: .75rem; text-align: center;
}
.scanner-error svg { color: var(--red-text); opacity: .8; }
.scanner-error p { font-size: .875rem; color: var(--ink-dim); margin: 0; }

/* ── Mobile: scanner full-screen ─────────────────────────── */
@media(max-width:520px) {
  .isbn-scanner-root { padding: 0; align-items: flex-end; }
  .scanner-box {
    max-width: 100%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    animation: sheetUp .28s cubic-bezier(.34,1.1,.64,1);
  }
  .scanner-viewport { aspect-ratio: 3/4; }
}

/* ══════════════════ COVER UPLOAD WIDGET ════════════════ */
.cover-upload-widget {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

/* ── Preview ───────────────────────────────────────────── */
.cover-preview-wrap {
  width: 110px; flex-shrink: 0;
  height: 150px;
  border-radius: var(--radius);
  border: 2px dashed var(--night-4);
  background: var(--night-3);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  transition: border-color var(--tr);
}
.cover-preview-wrap.has-image {
  border-style: solid;
  border-color: var(--blue);
}
.cover-preview-img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.cover-preview-empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: .5rem; color: var(--ink-dim);
  font-size: .72rem; text-align: center; padding: .5rem;
}
.cover-preview-empty svg { opacity: .4; }

/* ── Actions ───────────────────────────────────────────── */
.cover-actions {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  flex: 1;
  min-width: 140px;
}
.btn-cover-action {
  display: flex; align-items: center; gap: .55rem;
  padding: .6rem .9rem;
  background: var(--night-3);
  border: 1px solid var(--night-4);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-family: var(--sans); font-size: .82rem; font-weight: 500;
  cursor: pointer;
  transition: all var(--tr);
  white-space: nowrap;
  width: 100%;
}
.btn-cover-action:hover {
  border-color: var(--blue);
  color: var(--blue-text);
  background: var(--blue-dim);
}
.btn-cover-action svg { flex-shrink: 0; }

.btn-cover-remove {
  color: var(--red-text) !important;
  border-color: rgba(232,53,43,.25) !important;
  background: var(--red-dim) !important;
}
.btn-cover-remove:hover {
  border-color: var(--red) !important;
  background: rgba(232,53,43,.2) !important;
}

/* ── Upload status ─────────────────────────────────────── */
.cover-upload-status {
  display: flex; align-items: center; gap: .6rem;
  font-size: .82rem; color: var(--ink-dim);
  margin-top: .25rem;
  width: 100%;
}
.cover-upload-spinner {
  width: 16px; height: 16px; flex-shrink: 0;
  border: 2px solid var(--night-4);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* Mobile: layout orizzontale compatto */
@media(max-width:480px) {
  .cover-upload-widget { gap: .75rem; }
  .cover-preview-wrap  { width: 88px; height: 120px; }
  .btn-cover-action    { font-size: .78rem; padding: .5rem .75rem; }
}

/* ══════════════════ BOOK COVER — card e dettaglio ═══════ */

/* Cover nelle card griglia */
.book-cover-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 2/3;
  overflow: hidden;
  background: var(--night-3);
  flex-shrink: 0;
}
.book-cover-img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .35s var(--tr);
}
.book-card:hover .book-cover-img { transform: scale(1.04); }

/* Barra colorata sovrapposta alla copertina (in basso) */
.book-bar-overlay {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--blue), var(--blue-bright));
}
.book-bar-overlay.g-sagg { background: linear-gradient(90deg,#059669,#34d399); }
.book-bar-overlay.g-fan  { background: linear-gradient(90deg,#7c3aed,#c084fc); }
.book-bar-overlay.g-stor { background: linear-gradient(90deg,var(--red),#fb923c); }

/* Cover nel modal dettaglio */
.detail-cover-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 1.4rem;
}
.detail-cover-img {
  max-height: 220px;
  max-width: 160px;
  width: auto;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,.06);
  object-fit: contain;
  display: block;
}

/* Mobile: cover un po' più alta */
@media(max-width:768px) {
  .detail-cover-img { max-height: 180px; max-width: 130px; }
}