/* =========================================================
   SIDEBAR + LAYOUT
   ========================================================= */

.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 100;
  transition: width 0.4s cubic-bezier(0.4,0,0.2,1), transform 0.4s cubic-bezier(0.4,0,0.2,1);
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-logo-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.sidebar-logo-icon svg {
  width: 20px; height: 20px;
  fill: #fff;
}

.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-logo-text strong {
  font-size: 1rem;
  font-weight: 800;
  background: linear-gradient(135deg, #fff 40%, var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

.sidebar-logo-text span {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Nav ── */
.sidebar-nav {
  flex: 1;
  padding: 16px 10px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.nav-section-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  padding: 12px 10px 6px;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.3s;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  overflow: hidden;
  position: relative;
  margin-bottom: 2px;
  text-decoration: none;
}

.nav-item:hover {
  background: rgba(124,58,237,0.12);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(124,58,237,0.18);
  color: #fff;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent-light));
  border-radius: 0 4px 4px 0;
}

.nav-item-icon {
  width: 20px; height: 20px;
  flex-shrink: 0;
  opacity: 0.75;
  transition: var(--transition);
}
.nav-item:hover .nav-item-icon,
.nav-item.active .nav-item-icon { opacity: 1; }

.nav-item-label { flex: 1; }

.nav-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  flex-shrink: 0;
}

/* ── Sidebar footer ── */
.sidebar-footer {
  padding: 16px 10px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  overflow: hidden;
}
.sidebar-user:hover { background: var(--bg-card); }

.sidebar-logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 8px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: var(--transition);
}
.sidebar-logout-btn:hover {
  background: rgba(239,68,68,0.15);
  color: #FCA5A5;
}

.sidebar-user-info {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
}
.sidebar-user-info strong {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-info span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Toggle btn ── */
.sidebar-toggle {
  position: fixed;
  top: 22px;
  left: calc(var(--sidebar-width) - 16px);
  width: 32px; height: 32px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 101;
  transition: left 0.4s cubic-bezier(0.4,0,0.2,1), var(--transition);
  color: var(--text-secondary);
}
.sidebar-toggle:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.sidebar-toggle svg {
  width: 14px; height: 14px;
  transition: transform 0.4s;
}
.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }

/* ── Collapsed sidebar ── */
.sidebar-collapsed .sidebar {
  width: 70px;
}
.sidebar-collapsed .sidebar-toggle {
  left: 54px;
}
.sidebar-collapsed .nav-section-label { opacity: 0; }
.sidebar-collapsed .nav-item-label { opacity: 0; width: 0; }
.sidebar-collapsed .nav-badge { display: none; }
.sidebar-collapsed .sidebar-logo-text { opacity: 0; width: 0; }
.sidebar-collapsed .sidebar-user-info { opacity: 0; width: 0; }

/* ── Main content ── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  transition: margin-left 0.4s cubic-bezier(0.4,0,0.2,1);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  overflow-x: clip;
}
.sidebar-collapsed .main-content { margin-left: 70px; }

/* ── Topbar ── */
.topbar {
  height: 68px;
  background: rgba(11,11,24,0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 1.05rem;
  font-weight: 700;
  flex: 1;
}

.topbar-search {
  position: relative;
  width: 280px;
}
.topbar-search input {
  width: 100%;
  padding: 9px 16px 9px 40px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: var(--transition);
}
.topbar-search input::placeholder { color: var(--text-muted); }
.topbar-search input:focus {
  border-color: var(--accent);
  background: rgba(124,58,237,0.08);
}
.topbar-search-icon {
  position: absolute;
  left: 13px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  width: 16px; height: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition);
  position: relative;
  background: transparent;
  border: none;
}
.topbar-btn:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}
.topbar-btn svg { width: 18px; height: 18px; }

/* ── Page content ── */
.page-content {
  flex: 1;
  padding: 28px;
  overflow-x: hidden;
  min-width: 0;
}

/* ── Mobile overlay ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
  backdrop-filter: blur(4px);
}

/* ── Tablet: auto-collapse sidebar (1024px → 768px) ── */
@media (max-width: 1024px) and (min-width: 769px) {
  :root { --sidebar-width: 70px; }

  .sidebar { width: 70px; }
  .sidebar-toggle { left: 54px; }
  .sidebar-toggle svg { transform: rotate(180deg); }

  .sidebar .nav-section-label { opacity: 0; pointer-events: none; }
  .sidebar .nav-item-label    { opacity: 0; width: 0; overflow: hidden; }
  .sidebar .nav-badge         { display: none; }
  .sidebar .sidebar-logo-text { opacity: 0; width: 0; overflow: hidden; }
  .sidebar .sidebar-user-info { opacity: 0; width: 0; overflow: hidden; }

  .topbar { padding: 0 18px; }
  .topbar-search { width: 200px; }
  .page-content { padding: 20px; }
}

/* ── Mobile (≤ 768px) ── */
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }

  .sidebar {
    transform: translateX(-100%);
    width: 260px !important;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0,0,0,0.6);
  }
  .main-content {
    margin-left: 0 !important;
  }
  .sidebar-overlay.show {
    display: block;
  }
  .sidebar-toggle {
    display: none;
  }

  /* Topbar mobile */
  .topbar {
    height: 60px;
    padding: 0 14px;
    gap: 10px;
  }
  .topbar-title { font-size: 0.95rem; }
  .topbar-search { width: 0; overflow: hidden; padding: 0; border: none; opacity: 0; pointer-events: none; }
  #topbarDate   { display: none; }

  /* Topbar search icon trigger */
  .topbar-search-toggle { display: flex !important; }

  .page-content { padding: 14px; }
}

/* Search toggle button (hidden on desktop) */
.topbar-search-toggle { display: none; }

/* ── Topbar search expanded on mobile ── */
@media (max-width: 768px) {
  .topbar.search-open .topbar-search {
    position: absolute;
    top: 0; left: 0; right: 0;
    width: 100%;
    height: 60px;
    background: var(--sidebar-bg);
    z-index: 10;
    display: flex;
    align-items: center;
    padding: 0 14px;
    opacity: 1;
    overflow: visible;
    border: none;
  }
  .topbar.search-open .topbar-search input {
    width: 100%;
    font-size: 0.9rem;
  }
}
