/* ════════════════════════════════════════════════════════════
   layout.css — Sidebar, Topbar, Main, Mobile Nav
   ════════════════════════════════════════════════════════════ */

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--night-2);
  border-right: 1px solid var(--night-3);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100;
  box-shadow: 4px 0 40px rgba(0,0,0,.6);
}

/* Sidebar glow edge */
#sidebar::after {
  content: '';
  position: absolute; top: 0; right: 0; bottom: 0; width: 1px;
  background: linear-gradient(180deg,
    transparent 0%, var(--blue-glow) 30%,
    var(--red-glow) 70%, transparent 100%);
  opacity: .6;
}

.sidebar-header {
  padding: 1.6rem 1.4rem;
  display: flex; align-items: center; gap: .9rem;
  border-bottom: 1px solid var(--night-3);
  position: relative;
}
.sidebar-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--blue), var(--red));
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 16px var(--blue-glow);
}
.sidebar-icon svg { color: #fff; }
.sidebar-title {
  font-family: var(--display);
  font-size: 1.25rem; letter-spacing: .1em; color: var(--white);
}
.sidebar-subtitle {
  font-size: .65rem; color: var(--ink-dim);
  letter-spacing: .12em; text-transform: uppercase;
}

/* ── Nav section label ───────────────────────────────────── */
.nav-sec {
  padding: 1.4rem 1.4rem .4rem;
  font-size: .62rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .15em;
  color: var(--night-5);
}

/* ── Nav items ───────────────────────────────────────────── */
.nav-item {
  display: flex; align-items: center; gap: .85rem;
  padding: .72rem 1.4rem;
  color: var(--ink-dim);
  cursor: pointer; font-size: .875rem; font-weight: 400;
  transition: all var(--tr);
  border-left: 2px solid transparent;
  position: relative;
}
.nav-item:hover {
  color: var(--ink);
  background: rgba(255,255,255,.03);
}
.nav-item.active {
  color: var(--white);
  background: linear-gradient(90deg, rgba(59,124,244,.12), transparent);
  border-left-color: var(--blue);
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 2px; border-radius: 1px;
  background: linear-gradient(180deg, var(--blue), var(--blue-bright));
  box-shadow: 0 0 8px var(--blue-glow);
}
.nav-item svg { flex-shrink: 0; opacity: .5; transition: opacity var(--tr); }
.nav-item:hover svg { opacity: .8; }
.nav-item.active svg { opacity: 1; color: var(--blue-bright); }

/* ── Sidebar user ────────────────────────────────────────── */
.sidebar-user {
  margin-top: auto;
  border-top: 1px solid var(--night-3);
  padding: 1.1rem 1.4rem;
}
.user-info { display: flex; align-items: center; gap: .8rem; margin-bottom: .8rem; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--red));
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 700; color: #fff; flex-shrink: 0;
  box-shadow: 0 2px 12px var(--blue-glow);
}
.user-name  { font-size: .875rem; font-weight: 600; color: var(--white); }
.user-email { font-size: .7rem; color: var(--ink-dim); word-break: break-all; margin-top: .1rem; }
.user-role  { font-size: .65rem; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .08em; }

.btn-logout {
  width: 100%;
  background: rgba(232,53,43,.08);
  border: 1px solid rgba(232,53,43,.2);
  color: var(--ink-dim);
  border-radius: var(--radius-sm);
  padding: .52rem;
  font-family: var(--sans); font-size: .8rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  transition: all var(--tr);
}
.btn-logout:hover {
  background: rgba(232,53,43,.18);
  color: var(--red-text);
  border-color: rgba(232,53,43,.4);
}

/* ── Main wrapper ────────────────────────────────────────── */
#main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ──────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-h);
  background: rgba(13,15,28,.85);
  border-bottom: 1px solid var(--night-3);
  padding: 0 2rem;
  display: flex; align-items: center; gap: 1rem;
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.search-wrap { position: relative; flex: 1; max-width: 480px; }
.search-wrap svg {
  position: absolute; left: 1rem; top: 50%;
  transform: translateY(-50%);
  color: var(--ink-dim); pointer-events: none;
  transition: color var(--tr);
}
#search-input {
  width: 100%;
  background: var(--night-3);
  border: 1px solid var(--night-4);
  border-radius: 100px;
  padding: .65rem 1.2rem .65rem 2.8rem;
  font-family: var(--sans); font-size: .875rem;
  color: var(--ink-bright); outline: none;
  transition: all var(--tr);
}
#search-input::placeholder { color: var(--ink-dim); }
#search-input:focus {
  background: var(--night-2);
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-dim);
}
#search-input:focus + svg,
.search-wrap:focus-within svg { color: var(--blue-bright); }

/* ── Content area ────────────────────────────────────────── */
#content { padding: 2rem; flex: 1; }

/* ═══════════════════════════════════════════════════════════
   MOBILE — Bottom navigation con glassmorphism
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  #sidebar {
    /* trasforma in bottom nav */
    width: 100%; height: var(--mobile-nav-h);
    position: fixed; bottom: 0; top: auto; left: 0; right: 0;
    flex-direction: row; padding: 0;
    border-right: none;
    border-top: 1px solid var(--night-3);
    background: rgba(13,15,28,.92);
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    box-shadow: 0 -8px 40px rgba(0,0,0,.7);
    z-index: 200;
    /* rimuovi la glow edge verticale */
    after: none;
  }
  #sidebar::after { display: none; }

  .sidebar-header,
  .nav-sec,
  .sidebar-user { display: none; }

  .nav-item {
    flex-direction: column; gap: .2rem;
    font-size: .6rem; font-weight: 500;
    padding: .55rem .2rem;
    flex: 1; justify-content: center; align-items: center;
    border-left: none;
    border-top: 2px solid transparent;
    text-align: center;
    letter-spacing: .03em;
  }
  .nav-item:hover { background: none; }
  .nav-item.active {
    background: none;
    border-left: none;
    border-top-color: var(--blue);
    color: var(--blue-bright);
  }
  .nav-item.active::before { display: none; }
  .nav-item.active svg { color: var(--blue-bright); opacity: 1; }
  /* pop animation quando si seleziona */
  .nav-item.active .nav-icon-wrap { animation: nav-pop .3s var(--tr-spring) both; }

  .nav-icon-wrap {
    width: 40px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 10px;
    transition: background var(--tr);
  }
  .nav-item.active .nav-icon-wrap {
    background: var(--blue-dim);
  }

  #main { margin-left: 0; padding-bottom: var(--mobile-nav-h); }

  #topbar {
    padding: 0 1rem;
    height: 56px;
  }

  #content { padding: 1rem; }
}

/* ── Extra small screens ─────────────────────────────────── */
@media (max-width: 380px) {
  .nav-item { font-size: .55rem; }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE USER HEADER — visibile solo su mobile
   Mostra avatar, nome, email e logout in cima al topbar
   ═══════════════════════════════════════════════════════════ */
#mobile-user-bar {
  display: none;
}

@media(max-width:768px) {
  #mobile-user-bar.visible {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1rem;
    background: var(--night-2);
    border-bottom: 1px solid var(--night-3);
    gap: .75rem;
    position: sticky; top: 0; z-index: 51;
  }

  .mob-user-left {
    display: flex; align-items: center; gap: .65rem;
  /*  min-width: 0; flex: 1;*/
  }
  .mob-avatar {
    width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(135deg, var(--blue), var(--red));
    display: flex; align-items: center; justify-content: center;
    font-size: .85rem; font-weight: 700; color: #fff;
    box-shadow: 0 2px 10px var(--blue-glow);
  }
  .mob-user-info { min-width: 0; }
  .mob-user-name {
    font-size: .85rem; font-weight: 600; color: var(--white);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .mob-user-role {
    font-size: .68rem; color: var(--ink-dim);
    text-transform: uppercase; letter-spacing: .07em;
  }

  .mob-logout-btn {
    flex-shrink: 0;
    background: rgba(232,53,43,.1);
    border: 1px solid rgba(232,53,43,.25);
    color: var(--red-text);
    border-radius: var(--radius-sm);
    padding: .4rem .75rem;
    font-family: var(--sans); font-size: .75rem; font-weight: 600;
    cursor: pointer;
    display: flex; align-items: center; gap: .35rem;
    transition: all var(--tr);
    white-space: nowrap;
  }
  .mob-logout-btn:hover,
  .mob-logout-btn:active {
    background: rgba(232,53,43,.22);
    color: #fff;
  }

  /* Nascondi il topbar desktop su mobile e mostra solo search */
  #topbar {
    padding: .55rem 1rem;
    height: auto;
    /* Il btn "Aggiungi Libro" è nascosto su mobile: uso il FAB */
  }
  #topbar .js-nuovo-libro { display: none; }
  #topbar > div[style*="flex:1"] { display: none; }

  /* Fix tabella recenti: scroll orizzontale */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
  }
  table { min-width: 500px; }

  /* Fix stats grid overflow */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: .65rem !important;
    overflow: visible;
  }
  .stat-value { font-size: 2rem !important; }
  .stat-card  { padding: 1rem !important; }


/* ── Fix books grid overflow ─────────────────────────────── */
@media(max-width:768px) {
  .books-grid { max-width: 100%; }
}

/* ═══════════════════════════════════════════════════════════
   LOGO — Metti Libri
   ═══════════════════════════════════════════════════════════ */

/* ── Sidebar logo area ───────────────────────────────────── */
.sidebar-header {
  /* override: ora usa logo SVG, non l'icona semplice */
  padding: 1.2rem 1.4rem;
  gap: .75rem;
}
.sidebar-logo-icon {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  /* Leggero glow azzurro a richiamare il colore del logo */
  filter: drop-shadow(0 2px 8px rgba(47,111,178,.5));
  transition: filter var(--tr);
}
.sidebar-logo-icon:hover {
  filter: drop-shadow(0 4px 16px rgba(47,111,178,.7));
}
.sidebar-brand-text { min-width: 0; }

/* Testo logo bicolore nella sidebar */
.sidebar-title {
  font-family: var(--display);
  font-size: 1.3rem; letter-spacing: .1em;
  line-height: 1; color: var(--white);
}
.sbt-metti { color: #5b9bff; }   /* azzurro elettrico */
.sbt-libri  { color: #7FB069; }  /* verde del logo */

/* ── Auth brand logo ─────────────────────────────────────── */
.brand-logo-icon {
  /* override: ridimensionato per il SVG più complesso */
  width: 56px; height: 56px;
  background: none;          /* rimuove il gradiente */
  box-shadow: none;
  filter: drop-shadow(0 3px 12px rgba(47,111,178,.45));
}
.brand-logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.brand-logo-name-metti {
  font-family: var(--display);
  font-size: 1.6rem; letter-spacing: .12em;
  color: #5b9bff;
  line-height: 1;
}
.brand-logo-name-libri {
  font-family: var(--display);
  font-size: 1.6rem; letter-spacing: .12em;
  color: #7FB069;
  line-height: 1;
}

/* ── Mobile user bar — logo a sinistra ──────────────────── */
@media(max-width:768px) {
  #mobile-user-bar.visible {
    justify-content: flex-start;
    gap: .75rem;
  }
  .mob-logo {
    display: flex; align-items: center; gap: .45rem;
    flex-shrink: 0;
  }
  .mob-logo svg {
    filter: drop-shadow(0 1px 6px rgba(47,111,178,.5));
  }
  .mob-logo-text {
    font-family: var(--display);
    font-size: .95rem; letter-spacing: .08em;
    line-height: 1;
  }
  /* Spinge user info e logout verso destra */
  .mob-user-left { margin-left: auto; }
}