/* ============================================
   CPP LIBRARY - Menu ngang/dọc responsive
   Topbar + Dropdown + Sidebar (hamburger mobile)
   ============================================ */

/* === TOPBAR === */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem 0 1.25rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(12px);
}

body.theme-dark .topbar {
  background: #4a423b;
  border-bottom-color: #6c635a;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
  min-width: 0;
  overflow: visible;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Brand */
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: inherit;
  flex-shrink: 0;
}

.topbar .brand:hover { text-decoration: none; color: inherit; }

.topbar .brand-logo-img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 6px;
}

.topbar .brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.topbar .brand-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.topbar .brand-sub {
  font-size: clamp(0.45rem, 1.5vw, 0.7rem);
  color: var(--text-muted);
  white-space: normal;
  overflow: visible;
  word-break: keep-all;
  max-width: 220px;
}

.topbar .brand-title span { color: var(--accent-cpp); }

/* Brand responsive: EDULIB font size unchanged; only logo scales on small screens */
@media (max-width: 600px) {
  .topbar .brand-logo-img {
    width: 32px;
    height: 32px;
  }
}
@media (max-width: 480px) {
  .topbar .brand-logo-img {
    width: 28px;
    height: 28px;
  }
}

/* Brand short: bỏ tagline ở trang con (chỉ icon + Library) */
.topbar .brand-short .brand-sub { display: none; }

/* Search trong topbar-right: đủ rộng để nút x, đếm và nút prev/next không trồng lên nhau */
.topbar-right .search-container {
  flex: 0 1 auto;
  min-width: 0;
  width: 280px;
  max-width: 360px;
  margin: 0 0.5rem 0 0;
  position: relative;
}
.topbar .search-container {
  min-width: 0;
}

/* === MENU NGANG (Horizontal): luôn hiển thị đủ, ưu tiên hơn search === */
.horizontal-menu {
  flex: 0 0 auto;
  min-width: 0;
  margin-left: 0.5rem;
  display: flex;
  align-items: center;
  overflow: visible;
}

.horizontal-menu .menu-container {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-width: max-content;
  height: 100%;
  overflow: visible;
}

.horizontal-menu .nav-link {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 8px;
  border: 1.5px solid transparent;
  white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.horizontal-menu .nav-link:hover {
  border-color: #dc3545;
  color: #dc3545;
  background: rgba(220,53,69,0.07);
}

.horizontal-menu .nav-link.active {
  color: #0d6efd;
  background: rgba(13,110,253,0.1);
  border-color: transparent;
  font-weight: 600;
}

/* === DROPDOWN === */
.menu-dropdown {
  position: relative;
  display: inline-block;
  overflow: visible;
}

.menu-dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
  color: var(--text-secondary);
  background: none;
  border: 1.5px solid transparent;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border-radius: 8px;
  white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
a.menu-dropdown-toggle {
  text-decoration: none;
}
a.menu-dropdown-toggle:hover {
  text-decoration: none;
}

.menu-dropdown-toggle:hover {
  border-color: #dc3545;
  color: #dc3545;
  background: rgba(220,53,69,0.07);
}

.menu-dropdown.open .menu-dropdown-toggle {
  color: #0d6efd;
  background: rgba(13,110,253,0.1);
  border-color: transparent;
}

.menu-dropdown-arrow {
  font-size: 0.65rem;
  margin-left: 0.2rem;
  transition: transform 0.2s ease;
  color: var(--text-muted);
}

.menu-dropdown.open .menu-dropdown-arrow {
  transform: rotate(180deg);
}

.menu-dropdown-content {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  min-width: 200px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.08);
  z-index: 10001;
  overflow: visible;
  padding: 0.35rem;
  animation: dropdownFadeIn 0.15s ease;
}

.menu-dropdown-separator {
  height: 1px;
  margin: 0.25rem 0.5rem;
  background: rgba(148, 163, 184, 0.4);
}

.menu-dropdown-label {
  padding: 0.4rem 0.75rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

@keyframes dropdownFadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.menu-dropdown.open .menu-dropdown-content {
  display: block;
}

body.theme-dark .menu-dropdown-content {
  background: #3d3630;
  border-color: #6c635a;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}

/* Sidebar: submenu dọc, không sổ ngang */
.sidebar-nav .menu-submenu-panel {
  position: static;
  margin-left: 0;
  box-shadow: none;
  border: none;
  background: transparent;
  padding-left: 0.75rem;
}
.sidebar-nav .menu-submenu:hover .menu-submenu-panel {
  display: block;
}

body.theme-dark .menu-submenu-panel {
  background: #3d3630;
  border-color: #6c635a;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}

.menu-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  color: #1a1a2e;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 8px;
  border: 1.5px solid transparent;
  margin: 2px 0;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.menu-dropdown-item:hover {
  border-color: #dc3545;
  color: #dc3545;
  background: rgba(220,53,69,0.07);
  text-decoration: none;
}

.menu-submenu {
  position: relative;
}
.menu-submenu-toggle {
  width: 100%;
}
.menu-submenu-panel {
  position: absolute;
  top: 0;
  left: 100%;
  margin-left: 6px;
  min-width: 200px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.16), 0 2px 8px rgba(0,0,0,0.18);
  padding: 0.35rem;
  display: none;
  z-index: 10002;
}
.menu-submenu:hover .menu-submenu-panel {
  display: block;
}
.menu-submenu-arrow {
  margin-left: auto;
  font-size: 0.7rem;
  opacity: 0.7;
}

.menu-dropdown-item.active {
  background: rgba(13,110,253,0.1);
  color: #0d6efd;
  font-weight: 600;
  border-color: transparent;
}

.menu-dropdown-item i {
  width: 18px;
  text-align: center;
  color: #6c757d;
  font-size: 0.875rem;
  transition: color 0.18s ease;
}
.menu-dropdown-item:hover i { color: #dc3545; }
.menu-dropdown-item.active i { color: #0d6efd; }

body.theme-dark .menu-dropdown-item { color: #d0c5bd; }
body.theme-dark .menu-dropdown-item:hover { border-color: #dc3545; color: #dc3545; background: rgba(220,53,69,0.14); }
body.theme-dark .menu-dropdown-item i { color: #c4b8ae; }
body.theme-dark .menu-dropdown-item:hover i { color: #dc3545; }

/* Nút icon topbar */
.topbar .btn-icon {
  width: 36px;
  height: 36px;
  border: 1.5px solid transparent;
  background: transparent;
  color: var(--text-primary);
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.topbar .btn-icon:hover {
  border-color: #dc3545;
  color: #dc3545;
  background: rgba(220,53,69,0.08);
  transform: scale(1.08);
}

.topbar .sidebar-toggle {
  display: none;
}

/* === SIDEBAR (Mobile) === */
.cpp-sidebar {
  display: none;
  position: fixed;
  left: -280px;
  top: 56px;
  width: 260px;
  height: calc(100vh - 56px);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-strong);
  z-index: 1001;
  transition: left 0.3s ease;
  overflow-y: auto;
}

body.sidebar-open .cpp-sidebar {
  left: 0;
}

.cpp-sidebar-inner {
  padding: 1rem 0.75rem;
}

.cpp-sidebar .search-container {
  padding: 0 0.75rem 1rem;
  margin: 0;
  max-width: none;
}

.cpp-sidebar .search-input {
  width: 100%;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 8px;
  border: 1.5px solid transparent;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.sidebar-nav .nav-link:hover {
  border-color: #dc3545;
  color: #dc3545;
  background: rgba(220,53,69,0.07);
  text-decoration: none;
}

.sidebar-nav .nav-link i {
  width: 22px;
  text-align: center;
  color: var(--accent-cpp);
  transition: color 0.18s ease;
}
.sidebar-nav .nav-link:hover i { color: #dc3545; }

/* Sidebar dropdown */
.sidebar-nav .menu-dropdown {
  display: block;
}

.sidebar-nav .menu-dropdown-toggle {
  width: 100%;
  justify-content: flex-start;
  padding: 0.75rem 1rem;
  text-align: left;
}

.sidebar-nav .menu-dropdown-content {
  position: static;
  box-shadow: none;
  border: none;
  background: transparent !important;
  animation: none !important;
  margin: 0.25rem 0 0.5rem 0.75rem;
  padding: 0.25rem 0;
  border-left: 2px solid #dee2e6;
  padding-left: 0.75rem;
  display: none;
}

.sidebar-nav .menu-dropdown.open .menu-dropdown-content {
  display: block;
}

.sidebar-nav .menu-dropdown-item {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border-radius: 8px;
  border: 1.5px solid transparent;
  color: var(--text-primary) !important;
  background: transparent !important;
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
}
.sidebar-nav .menu-dropdown-item:hover {
  border-color: #dc3545 !important;
  color: #dc3545 !important;
  background: rgba(220,53,69,0.07) !important;
}

/* Phần menu Quản lý trong sidebar (admin) */
.sidebar-admin-section {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.sidebar-admin-section .sidebar-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 1rem 0.5rem;
  margin-bottom: 0.25rem;
}
.sidebar-admin-section .sidebar-nav-divider {
  display: block;
  height: 1px;
  background: var(--border);
  margin: 0.5rem 1rem;
}
.sidebar-admin-section .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  border: 1.5px solid transparent;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
.sidebar-admin-section .nav-link:hover {
  border-color: #dc3545;
  color: #dc3545;
  background: rgba(220,53,69,0.07);
}
.sidebar-admin-section .nav-link.active {
  background: rgba(13,110,253,0.1);
  color: #0d6efd;
  border-color: #0d6efd;
  font-weight: 600;
}
.sidebar-admin-section .nav-link .badge {
  margin-left: auto;
  background: rgba(14, 165, 233, 0.2);
  color: var(--accent-cpp);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
}
.sidebar-admin-section .nav-link.active .badge {
  background: rgba(255, 255, 255, 0.3);
}

.sidebar-admin-section .menu-dropdown {
  display: block;
}
.sidebar-admin-section .menu-dropdown-toggle {
  width: 100%;
  justify-content: flex-start;
  padding: 0.65rem 1rem;
  text-align: left;
  background: none;
  border: 1.5px solid transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-radius: 8px;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
.sidebar-admin-section .menu-dropdown-toggle:hover {
  border-color: #dc3545;
  color: #dc3545;
  background: rgba(220,53,69,0.07);
}
.sidebar-admin-section .menu-dropdown-content {
  position: static;
  box-shadow: none;
  border: none;
  background: transparent !important;
  animation: none !important;
  margin: 0.25rem 0 0.5rem 0.75rem;
  padding: 0.25rem 0;
  border-left: 2px solid #dee2e6;
  padding-left: 0.75rem;
  display: none;
}
.sidebar-admin-section .menu-dropdown.open .menu-dropdown-content {
  display: block;
}
.sidebar-admin-section .menu-dropdown-item {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-radius: 8px;
  border: 1.5px solid transparent;
  color: var(--text-primary) !important;
  background: transparent !important;
  transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
}
.sidebar-admin-section .menu-dropdown-item:hover {
  border-color: #dc3545 !important;
  color: #dc3545 !important;
  background: rgba(220,53,69,0.07) !important;
}
.sidebar-admin-section .menu-dropdown.active .menu-dropdown-toggle,
.sidebar-admin-section .menu-dropdown.open .menu-dropdown-toggle {
  color: #0d6efd;
  background: rgba(13,110,253,0.08);
  border-color: transparent;
}

/* Giao diện sáng: tăng tương phản menu sidebar (dễ nhìn trên nền trắng) */
body:not(.theme-dark):not([data-theme="dark"]) .cpp-sidebar .sidebar-nav .nav-link,
body:not(.theme-dark):not([data-theme="dark"]) .cpp-sidebar .sidebar-nav .menu-dropdown-toggle,
body:not(.theme-dark):not([data-theme="dark"]) .cpp-sidebar .sidebar-admin-section .nav-link {
  color: #1e293b;
}
body:not(.theme-dark):not([data-theme="dark"]) .cpp-sidebar .sidebar-admin-section .sidebar-section-title {
  color: #475569;
}
body:not(.theme-dark):not([data-theme="dark"]) .cpp-sidebar .sidebar-nav .nav-link i,
body:not(.theme-dark):not([data-theme="dark"]) .cpp-sidebar .sidebar-nav .menu-dropdown-toggle i {
  color: #0ea5e9;
}
body:not(.theme-dark):not([data-theme="dark"]) .cpp-sidebar .sidebar-admin-section .nav-link:not(.active) i {
  color: #64748b;
}
body:not(.theme-dark):not([data-theme="dark"]) .cpp-sidebar .sidebar-admin-section .menu-dropdown-toggle {
  color: #1e293b;
}
body:not(.theme-dark):not([data-theme="dark"]) .cpp-sidebar .sidebar-admin-section .menu-dropdown-toggle i {
  color: #0ea5e9;
}
body:not(.theme-dark):not([data-theme="dark"]) .cpp-sidebar {
  background: #ffffff;
  border-right-color: #e2e8f0;
}

/* === BACKDROP: nhẹ, không blur === */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 56px 0 0 0;
  background: rgba(0, 0, 0, 0.18);
  z-index: 1000;
  backdrop-filter: none;
}

body.sidebar-open .sidebar-backdrop {
  display: block;
}

/* === RESPONSIVE: Hamburger + Sidebar ===
   Breakpoint 992px: switch to hamburger before nav items can overlap.
   Desktop (≥992px) keeps full horizontal nav; below that, sidebar only. */
@media (max-width: 991px) {
  .horizontal-menu {
    display: none !important;
  }

  .topbar .sidebar-toggle {
    display: inline-flex !important;
  }

  .cpp-sidebar {
    display: block;
  }

  .topbar-right .search-container {
    width: 240px;
    max-width: 300px;
    flex-shrink: 1;
    min-width: 0;
  }
}

@media (max-width: 768px) {
  .topbar .search-container {
    display: none;
  }

  .cpp-sidebar .search-container {
    display: block;
  }
}

@media (max-width: 600px) {
  .cpp-sidebar .search-container {
    display: block;
  }
}
