/* Small layout variable: gap between sidebar left edge and active item's white background */
:root {
  --sidebar-active-gap: 8px;
}

/* Sidebar overlay - ẩn vì cutout đã xử lý bằng pseudo-elements (::before/::after) */
.sidebar-overlay {
  display: none !important;
}

/* =============================================
   SIDEBAR - Pill-shape, fixed trái màn hình
   Phong cách: hiện đại, mềm mại, neumorphism nhẹ
   ============================================= */

/* Đẩy nội dung chính sang phải để tránh sidebar (chỉ khi có sidebar) */
/* Layout: left 5px + sidebar 96px + gap 20px = 121px */
.has-sidebar {
  --main-content-offset: 121px;
  padding-left: var(--main-content-offset);
}

/* Wrapper sidebar cố định bên trái */
#app-sidebar {
  /* Ghi đè width cũ, dùng pill-shape (mở rộng) */
  width: 96px !important;

  /* Cố định vào viewport: top-left */
  position: fixed;
  left: 5px;
  top: 5px;
  transform: none;
  z-index: 50;

  /* Full height pill with gap from viewport */
  height: calc(100vh - 10px);
  border-radius: 24px;

  /* Gradient sử dụng màu đặc trưng hệ thống (mặc định: from blue-600 to pink-500) */
  background: linear-gradient(160deg, var(--app-primary-start, #2563EB) 0%, var(--app-primary-end, #EC4899) 100%);

  /* Neumorphism nhẹ */
  box-shadow:
    6px 6px 16px rgba(0, 0, 0, 0.18),
    -2px -2px 8px rgba(255, 255, 255, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);

  /* Layout dọc căn giữa */
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 0;

  /* Tắt style cũ */
  background-color: unset;
  border-radius: 24px;

  /* Cho phép pseudo-elements vượt ra ngoài */
  overflow: visible;
}

/* Vùng logo trên cùng */
.sidebar-logo-area {
  margin-bottom: 16px;
}

/* Logo wrapper trong sidebar */
.sidebar-logo-wrapper {
  --logo-size: 44px;
  width: var(--logo-size);
  height: var(--logo-size);
  border-radius: 9999px;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.25);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.sidebar-logo-wrapper img {
  width: 65%;
  height: 65%;
  object-fit: contain;
}

/* Slider điều chỉnh màu - thu nhỏ, nằm ngang 45px */
.sidebar-hue-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 48px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.4);
  outline: none;
  cursor: pointer;
  margin-bottom: 12px;
}

.sidebar-hue-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

/* Nav container - mở rộng toàn bộ chiều rộng sidebar */
.sidebar-nav {
  width: 100%;
  display: flex;
}

.sidebar-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  width: 100%;
}

/* Wrapper li cần position: relative */
.sidebar-nav ul li {
  position: relative;
  display: flex;
  justify-content: center;
}

/* Mỗi item menu */
.sidebar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 72px;
  padding: 12px 0;
  border-radius: 20px;
  color: rgba(255, 255, 255, 0.88);
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  gap: 6px;
  box-sizing: border-box;
}

/* Hover state */
.sidebar-item:hover {
  background: rgba(255, 255, 255, 0.15);
  color: white;
}

/* Active state - nền trắng, đổ bóng nhẹ */
.sidebar-item.active {
  background: var(--page-bg-color, #f9fafbf6);
  color: hsl(var(--app-primary-hue, 210), 75%, 45%);
  margin-left: var(--sidebar-active-gap);
  width: calc(100% - var(--sidebar-active-gap));
  padding: 12px 8px;
  border-radius: 30px 0 0 30px;
  position: relative;
  z-index: 3;
  box-sizing: border-box;
}

/* Góc cong lõm phía TRÊN item active */
.sidebar-nav ul li:has(.sidebar-item.active)::before {
  content: '';
  position: absolute;
  right: 0;
  bottom: 100%;
  width: 24px;
  height: 24px;
  z-index: 2;
  background: radial-gradient(circle at 0% 0%, transparent 24px, var(--page-bg-color, #f9fafbf6) 24px);
}

/* Góc cong lõm phía DƯỚI item active */
.sidebar-nav ul li:has(.sidebar-item.active)::after {
  content: '';
  position: absolute;
  right: 0;
  top: 100%;
  width: 24px;
  height: 24px;
  z-index: 2;
  background: radial-gradient(circle at 0% 100%, transparent 24px, var(--page-bg-color, #f9fafbf6) 24px);
}



/* Icon SVG */
.sidebar-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.sidebar-icon svg {
  width: 20px;
  height: 20px;
}

/* Submenu — floating panel bên phải item cha, canh theo vị trí "Công cụ" */
.sidebar-submenu {
  position: absolute;
  left: calc(100% + 14px);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 2px solid transparent;
  background:
    linear-gradient(#ffffff, #ffffff) padding-box,
    linear-gradient(135deg, var(--app-primary-ocean), var(--app-primary-rose)) border-box;
  border-radius: 16px;
  padding: 8px;
  box-shadow:
    0 20px 60px -8px rgba(37, 99, 235, 0.12),
    0 30px 80px -16px rgba(236, 72, 153, 0.08),
    0 8px 24px -4px rgba(0, 0, 0, 0.06);
  z-index: 100;
  min-width: 200px;
}

/* Arrow connector — mũi tên gradient nối với sidebar, liền mạch với viền */
.sidebar-submenu::after {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 16px;
  background: linear-gradient(135deg, var(--app-primary-ocean), var(--app-primary-rose));
  clip-path: polygon(0 50%, 100% 0, 100% 100%);
  z-index: 1;
}

/* Responsive: thu nhỏ submenu trên mobile theo sidebar */
@media (max-width: 768px) {
  .sidebar-submenu {
    left: calc(100% + 10px);
    min-width: 180px;
  }
}

.sidebar-subitem {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  color: var(--gray-600);
  text-decoration: none;
  transition: all 0.18s ease;
  font-size: 13px;
  font-weight: 500;
  position: relative;
  padding-left: 16px;
}

.sidebar-subitem:hover {
  background: var(--primary-50);
  color: var(--primary-700);
}

.sidebar-subitem.active {
  background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
  color: #fff;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--primary-500) 35%, transparent);
}

.sidebar-subicon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-subicon svg {
  width: 16px;
  height: 16px;
  display: block;
}

.sidebar-sublabel {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

/* Badge hiển thị số task chưa hoàn thành */
.sidebar-badge {
  position: absolute;
  top: -6px;
  right: -8px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #dc2626;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Bottom section — mặc định màu đen, active đồng bộ .sidebar-item.active */
.sidebar-bottom .sidebar-item:not(.active) {
  color: #1a1a1a;
}

.sidebar-bottom .sidebar-item:not(.active) .sidebar-icon svg {
  filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.25));
}

/* Label nhỏ bên dưới icon */
.sidebar-label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: center;
  line-height: 1.15;
  white-space: nowrap;
}

/* Xử lý tràn tên người dùng ở cuối sidebar */
.sidebar-label-user {
  max-width: 100%;
  padding: 0 10px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Vùng swatch màu dưới cùng */
.sidebar-swatch-area {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.sidebar-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  opacity: 0.7;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.sidebar-swatch-label {
  font-size: 8px;
  color: rgba(255, 255, 255, 0.6);
  font-weight: 500;
}

/* Layout helpers for splitting sidebar into three vertical areas */
.sidebar-middle {
  flex: 1 1 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}

.sidebar-bottom {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 12px;
}

/* Ensure hovering the active item keeps its white background (no blue overlay) */
.sidebar-nav ul li .sidebar-item.active:hover {
  background: var(--page-bg-color, #f9fafb) !important;
  color: hsl(var(--app-primary-hue, 210), 75%, 45%) !important;
  box-shadow: inset 0 0 0 999px rgba(0, 0, 0, 0.03) !important;
}


/* Hover state cho các item đang active */
.sidebar-item.active:hover {
  box-shadow: inset 0 0 0 999px rgba(0, 0, 0, 0.05);
  color: hsl(var(--app-primary-hue, 210), 75%, 45%);
}

@media (max-width: 768px) {
  .has-sidebar {
    padding-left: 81px;
  }

  #app-sidebar {
    width: 56px !important;
    left: 5px;
    top: 5px;
    height: calc(100vh - 10px);
  }

  .sidebar-item {
    width: 44px;
    min-height: 42px;
    padding: 9px 0;
    gap: 0;
  }

  .sidebar-item .sidebar-label {
    display: none;
  }

  .sidebar-logo-wrapper {
    --logo-size: 36px;
  }

  .sidebar-item.active {
    width: calc(100% - var(--sidebar-active-gap));
    padding: 9px 4px;
  }
}