/* เลื่อนทั้งแถบข้าง (ไม่ใช่เลื่อนเฉพาะ .nav) เพื่อให้ scrollbar ยาวเต็มความสูงจอ
   ส่วนหัวและส่วนท้ายใช้ sticky ตรึงไว้ ปุ่มออกจากระบบจึงยังกดได้โดยไม่ต้องเลื่อนลงไปหา */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  height: 100vh;
  overflow-y: auto;
  background: var(--brand);
  color: #fff;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.sidebar::-webkit-scrollbar {
  width: 8px;
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.26);
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.45);
}

.brand {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--brand);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: #fff;
  color: var(--brand);
  font-weight: 700;
}

.brand-text {
  font-size: 15px;
  font-weight: 600;
}

.nav {
  flex: 1;
  padding: 8px 0;
}

.nav a {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px 18px;
  color: rgba(255, 255, 255, 0.86);
  font-size: 14px;
  text-decoration: none;
}

.nav a:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
  text-decoration: none;
}

.nav a.active {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-weight: 600;
  box-shadow: inset 3px 0 0 #fff;
}

.sidebar-foot {
  position: sticky;
  bottom: 0;
  padding: 12px 14px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--brand);
}

.user-box {
  margin-bottom: 8px;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
}

.user-role {
  color: rgba(255, 255, 255, 0.66);
  font-size: 12px;
}

#sidebar-build {
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.45);
  font-size: 11px;
  text-align: center;
}

.main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
}

.page-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.view {
  padding: 20px 22px 60px;
}

.menu-toggle {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 60;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 18px;
  cursor: pointer;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(0, 0, 0, 0.35);
}

.grid {
  display: grid;
  gap: 14px;
}

.grid-cards {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
  }

  .menu-toggle {
    display: block;
  }

  .topbar {
    padding-left: 60px;
  }

  .view {
    padding: 14px 12px 60px;
  }
}
