/* =============================================
   LAYOUT.CSS - Topbar, Sidebar, Subbar, Search
   Extracted from includes/header.php
   ============================================= */

:root {
  /* NAVBAR PIÙ ALTA PER LOGO GRANDE */
  --tb-h: clamp(100px, 14vh, 160px);
  --sb-h: 56px;
  --ink-h: 3px;
  --radius: 14px;
  --brand-glow: 32, 128, 255;

  --bg: #0b0c10;
  --fg: #0f1115;
  --border: rgba(255, 255, 255, .08);
  --text: #e7e9ee;
  --muted: #a9afbb;
  --accent: #0d6efd;
  --accent-2: #7bc9ff;
  --chip: rgba(255, 255, 255, .06);
  --surface: rgba(255, 255, 255, .06);
  --glass: rgba(255, 255, 255, .08);

  --sidebar-w: 280px;
  --sidebar-w-collapsed: 64px;
  --sidebar-bg: #0f1115;
}

:root[data-theme="light"] {
  --bg: #f4f6f9;
  --fg: #ffffff;
  --border: rgba(0, 0, 0, .08);
  --text: #181b22;
  --muted: #5b6374;
  --accent: #0d6efd;
  --accent-2: #74c0fc;
  --chip: rgba(0, 0, 0, .05);
  --surface: rgba(0, 0, 0, .04);
  --glass: rgba(255, 255, 255, .72);

  --sidebar-bg: #ffffff;
}

html,
body {
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
  text-decoration: none;
}

#pageContent {
  padding: 18px;
  transition: margin-left .2s ease;
}

/* ===== Topbar ===== */
#topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--tb-h);
  backdrop-filter: saturate(140%) blur(12px);
  background:
    linear-gradient(180deg, var(--glass), rgba(0, 0, 0, 0)),
    linear-gradient(180deg, rgba(var(--brand-glow), .08), rgba(0, 0, 0, 0));
  border-bottom: 1px solid var(--border);
  display: grid;
  /* 3 colonne uguali -> la sinistra non è più attaccata al bordo */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: center;
  gap: 12px;
  padding-inline: 20px;
}

/* SX: logo e pulsante centrati nella colonna sinistra */
#topbar .left-tools {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

#topbar .center-search {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 0 16px;
}

#topbar .right-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

/* niente margine a sinistra -> logo davvero centrato nel gruppo */
#topbar .navbar-brand {
  margin-left: 0;
}

/* LOGO GRANDE */
.brand-logo {
  height: calc(var(--tb-h) - 24px);
  max-height: 140px;
  width: auto;
  border-radius: 12px;
}

@media (prefers-reduced-motion:no-preference) {
  .brand-logo {
    transition: transform .2s ease, box-shadow .2s ease;
  }

  .brand-logo:hover {
    transform: translateY(-1px) scale(1.02);
    box-shadow: 0 14px 44px rgba(var(--brand-glow), .28);
  }
}

/* Search centrale */
.search-wrap {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .38rem .7rem;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: var(--chip);
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
}

.search-wrap input {
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  width: 100%;
}

@media (max-width: 767.98px) {
  #topbar .center-search {
    display: none;
  }
}

.btn {
  border-radius: 12px;
}

@media (prefers-reduced-motion:no-preference) {
  .btn {
    transition: transform .12s ease, box-shadow .12s ease;
  }

  .btn:hover {
    transform: translateY(-1px);
  }

  .btn:active {
    transform: translateY(0);
  }
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(120% 120% at 20% 20%, var(--accent), rgba(13, 110, 253, .25));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(var(--brand-glow), .18);
}

/* Mobile search */
#mobileSearchBar {
  backdrop-filter: saturate(140%) blur(10px);
  background: var(--glass);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
}

/* ===== Subbar (navbar mode) ===== */
#subbar {
  position: sticky;
  top: var(--tb-h);
  z-index: 90;
  backdrop-filter: saturate(140%) blur(10px);
  background: linear-gradient(180deg, var(--glass), rgba(0, 0, 0, 0));
  border-bottom: 1px solid var(--border);
}

#subbar .nav {
  gap: .35rem;
  position: relative;
  justify-content: center;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  mask-image: linear-gradient(to right, transparent 0, #000 24px, #000 calc(100% - 24px), transparent 100%);
  padding: 8px 12px;
}

#subbar .nav::-webkit-scrollbar {
  display: none;
}

#subbar .nav-link {
  border-radius: 999px;
  padding: .5rem 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--muted);
  position: relative;
  white-space: nowrap;
  scroll-snap-align: center;
}

#subbar .nav-link.active {
  color: var(--accent);
  background: rgba(13, 110, 253, .12);
}

#inkBar {
  position: absolute;
  height: var(--ink-h);
  bottom: -1px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
  box-shadow: 0 0 16px rgba(var(--brand-glow), .35);
  transition: left .25s ease, width .25s ease;
  pointer-events: none;
}

/* Children chips */
#subbar-children {
  position: sticky;
  top: calc(var(--tb-h) + var(--sb-h));
  z-index: 85;
  padding-top: 8px;
  padding-bottom: 10px;
  background: radial-gradient(1200px 90px at 50% -40px, rgba(var(--brand-glow), .10), transparent 60%), linear-gradient(180deg, var(--glass), rgba(0, 0, 0, 0));
  border-bottom: 1px solid var(--border);
}

#subbar-children .nav {
  gap: .5rem;
  justify-content: center;
  flex-wrap: wrap;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 6px 12px;
}

#subbar-children .nav-link {
  min-height: 44px;
  border-radius: 14px;
  padding: .52rem .9rem;
  display: flex;
  align-items: center;
  gap: .45rem;
  color: var(--muted);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .02));
  box-shadow: 0 6px 18px rgba(0, 0, 0, .08);
}

#subbar-children .nav-link.active {
  background: linear-gradient(90deg, rgba(13, 110, 253, .18), rgba(123, 201, 255, .18));
  color: var(--text);
  border-color: rgba(13, 110, 253, .35);
}

/* ===== Sidebar layout (Redesign) ===== */
#sidebar {
  position: fixed;
  top: var(--tb-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 10px 14px 24px;
  overflow-y: auto;
  display: none;
  z-index: 95;
  transition: width .2s cubic-bezier(0.4, 0, 0.2, 1), background .2s ease;
}

.layout-sidebar #sidebar {
  display: block;
}

.layout-sidebar #pageContent {
  margin-left: var(--sidebar-w);
}

.sb-topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 8px 10px;
  margin-bottom: 10px;
}

.sb-topbar .title {
  font-weight: 600;
  font-size: .9rem;
  opacity: .8;
}

.layout-sidebar #subbar,
.layout-sidebar #subbar-children {
  display: none !important;
}

.sb-section {
  margin-bottom: 4px;
  border-radius: 12px;
  overflow: hidden;
  background: transparent;
  border: none;
}

:root[data-theme="light"] .sb-section {
  background: rgba(0, 0, 0, .03);
}

.sb-sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--muted);
  border-radius: 10px;
  transition: all .15s ease;
  font-size: .92rem;
}

.sb-sec-head:hover {
  background: var(--surface);
  color: var(--text);
}

.sb-sec-head .left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sb-sec-head .bi {
  font-size: 1.1rem;
  transition: transform .2s ease;
}

.sb-sec-head.active {
  color: var(--accent);
  font-weight: 600;
}

.sb-sec-head.active .bi[class*="chevron"] {
  transform: rotate(90deg);
}

.sb-children {
  padding: 4px 0 8px 22px;
  display: none;
  position: relative;
}

/* Indentation line */
.sb-children::before {
  content: '';
  position: absolute;
  left: 20px;
  top: 0;
  bottom: 10px;
  width: 1px;
  background: var(--border);
}

.sb-children a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: .88rem;
  transition: all .15s ease;
  position: relative;
}

.sb-children a::before {
  content: '';
  position: absolute;
  left: -2px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 0;
  background: var(--accent);
  border-radius: 0 4px 4px 0;
  transition: height .2s ease;
}

.sb-children a.active {
  color: var(--text);
  background: rgba(var(--brand-glow), .08);
  font-weight: 600;
}

.sb-children a.active::before {
  height: 16px;
}

.sb-children a:hover {
  color: var(--text);
  background: var(--surface);
  padding-left: 14px;
}

/* ===== COLLASSO SIDEBAR (rail) ===== */
.layout-sidebar-collapsed #sidebar {
  width: var(--sidebar-w-collapsed);
  padding: 10px 8px;
}

.layout-sidebar-collapsed #pageContent {
  margin-left: var(--sidebar-w-collapsed);
}

.layout-sidebar-collapsed #sidebar .sb-text,
.layout-sidebar-collapsed #sidebar .sb-children,
.layout-sidebar-collapsed #sidebar .sb-topbar .title,
.layout-sidebar-collapsed #sidebar .sb-sec-head .bi[class*="chevron"] {
  display: none !important;
}

.layout-sidebar-collapsed #sidebar .sb-topbar {
  justify-content: center;
  padding: 8px 0;
  margin-bottom: 15px;
}

.layout-sidebar-collapsed #sidebar .sb-sec-head {
  justify-content: center;
  padding: 12px 0;
  border-radius: 12px;
}

.layout-sidebar-collapsed #sidebar .sb-sec-head.active {
  background: rgba(var(--brand-glow), .12);
  color: var(--accent);
}

.layout-sidebar-collapsed #sidebar .sb-section {
  margin: 0 0 8px 0;
}

@media (min-width: 992px) {
  .avatar {
    width: 38px;
    height: 38px;
  }
}
