/* Thanh trên cùng — header sidebar + content liền một hàng (desktop) */

/* ── Mobile viewport & safe area (iPhone X+, iOS Safari) ── */
html {
  height: 100%;
  height: 100dvh;
}

@supports (-webkit-touch-callout: none) {
  html {
    height: -webkit-fill-available;
  }
}

.app-viewport-shell,
body.app-viewport-shell {
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

@supports (-webkit-touch-callout: none) {
  .app-viewport-shell,
  body.app-viewport-shell {
    height: -webkit-fill-available;
    max-height: -webkit-fill-available;
  }
}

.app-viewport-main {
  flex: 1 1 0%;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Vùng cuộn nội dung tab — padding đáy cho home indicator + thanh Safari */
.app-shell-main {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* !important: Tailwind p-4/p-6/p-8 không được ghi đè padding đáy */
  padding-bottom: max(3.5rem, calc(2rem + env(safe-area-inset-bottom, 0px))) !important;
  scroll-padding-bottom: max(3.5rem, calc(2rem + env(safe-area-inset-bottom, 0px)));
}

@media (min-width: 768px) {
  .app-shell-main {
    padding-bottom: 2rem !important;
    scroll-padding-bottom: 2rem;
  }
}

/* Spacer cuối tab — đảm bảo thẻ/card cuối không dính sát đáy màn hình */
@media (max-width: 767px) {
  .tab-content.active::after,
  .app-shell-main #page-content::after {
    content: '';
    display: block;
    height: max(1.25rem, env(safe-area-inset-bottom, 0px));
    pointer-events: none;
  }
}

@media (max-width: 767px) {
  .app-viewport-main > header.h-16,
  main.flex-1 > header.h-16 {
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(4rem + env(safe-area-inset-top, 0px));
    min-height: calc(4rem + env(safe-area-inset-top, 0px));
  }
}

.app-safe-bottom {
  padding-bottom: max(3.5rem, calc(2rem + env(safe-area-inset-bottom, 0px)));
}

.app-sticky-footer-bar {
  padding-bottom: max(3.5rem, calc(2rem + env(safe-area-inset-bottom, 0px)));
}

@media (min-width: 768px) {
  .app-sticky-footer-bar {
    padding-bottom: 1rem;
  }
}

.app-shell-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.app-shell-body {
  display: flex;
  flex: 1 1 0%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

/* Sau gộp header: main/aside co theo vùng còn lại, không còn 100vh */
.app-shell-root .app-shell-body > main.flex-1 {
  height: auto !important;
  max-height: none;
  flex: 1 1 0%;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-shell-root .app-shell-body > aside.app-sidebar-shell {
  height: auto !important;
  max-height: none;
  align-self: stretch;
  min-height: 0;
}

/* Vùng cuộn nội dung trang (layout app-shell-root) */
.app-shell-root .app-shell-body > main.flex-1 > .app-shell-main {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.app-shell-header-row {
  display: none;
  flex-shrink: 0;
  height: 4rem;
  align-items: stretch;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(229, 231, 235, 0.95);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  position: relative;
  z-index: 40;
}

.app-shell-header-brand {
  display: flex;
  align-items: center;
  width: 16rem;
  flex-shrink: 0;
  padding: 0 0.75rem;
  border-right: 1px solid rgba(243, 244, 246, 0.95);
  background: linear-gradient(to right, #f8fafc, #ffffff);
}

.app-shell-header-brand .app-sidebar-brand-bar {
  width: 100%;
  height: 100%;
  border-bottom: none !important;
  background: transparent;
  padding-left: 0;
  padding-right: 0;
}

.app-shell-header-main {
  display: flex;
  flex: 1 1 0%;
  align-items: center;
  justify-content: flex-end;
  padding: 0 1.25rem;
  gap: 0.75rem;
  min-width: 0;
}

.app-desktop-topbar {
  display: none;
  flex-shrink: 0;
  height: 4rem;
  padding: 0 1.25rem;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(229, 231, 235, 0.95);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  position: relative;
  z-index: 40;
}

@media (min-width: 768px) {
  .app-shell-header-row {
    display: flex;
  }

  /* Topbar cũ trong main (bản duplicate) — không hiển thị */
  main.flex-1 > .app-desktop-topbar {
    display: none !important;
  }

  /* Ẩn profile ở đáy sidebar — đã chuyển lên topbar */
  aside.app-sidebar-shell .app-sidebar-profile-footer {
    display: none !important;
  }

  /* Sidebar không bo góc trên — header đã tách ra hàng riêng */
  aside.app-sidebar-shell {
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;
  }
}

.app-topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Chuông thông báo ── */
.user-notify-wrap {
  position: relative;
  flex-shrink: 0;
}

.user-notify-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.625rem;
  height: 2.625rem;
  border-radius: 9999px;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #4b5563;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.user-notify-btn:hover {
  border-color: #93c5fd;
  background: #eff6ff;
  color: #1d4ed8;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.12);
}

.user-notify-btn[aria-expanded='true'] {
  border-color: #3b82f6;
  background: #dbeafe;
  color: #1d4ed8;
}

.user-notify-btn .fa-bell {
  font-size: 1.05rem;
}

.user-notify-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 1.125rem;
  height: 1.125rem;
  padding: 0 4px;
  border-radius: 9999px;
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 700;
  line-height: 1.125rem;
  text-align: center;
  display: none;
  box-shadow: 0 0 0 2px #fff;
}

.user-notify-badge.visible {
  display: block;
}

.user-notify-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 300;
  width: min(22rem, calc(100vw - 1.5rem));
  max-height: min(26rem, 72vh);
  display: none;
  flex-direction: column;
  border-radius: 1rem;
  border: 1px solid #e5e7eb;
  background: #fff;
  box-shadow: 0 16px 48px -12px rgba(15, 23, 42, 0.22);
  overflow: hidden;
}

.user-notify-panel.open {
  display: flex;
}

.user-notify-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #f3f4f6;
  background: linear-gradient(to right, #f8fafc, #fff);
}

.user-notify-panel-header h3 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 700;
  color: #111827;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.user-notify-panel-header h3::before {
  content: '';
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  background: #3b82f6;
}

.user-notify-mark-all {
  font-size: 0.6875rem;
  font-weight: 600;
  color: #2563eb;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
}

.user-notify-mark-all:hover {
  background: #eff6ff;
}

.user-notify-list {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-height: 0;
}

/* ── Mobile: bottom sheet (tránh bị clip bởi overflow trên .app-viewport-main) ── */
.user-notify-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 109;
  border: 0;
  padding: 0;
  margin: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  cursor: default;
}

.user-notify-backdrop.open {
  display: block;
}

body.user-notify-open {
  overflow: hidden;
  touch-action: none;
}

@media (max-width: 767px) {
  .user-notify-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 110;
    width: 100%;
    max-width: none;
    max-height: min(78vh, calc(100dvh - env(safe-area-inset-top, 0px) - 3.5rem));
    border-radius: 1.25rem 1.25rem 0 0;
    border-bottom: none;
    box-shadow: 0 -8px 40px rgba(15, 23, 42, 0.18);
    transform: translateY(100%);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.28s ease, opacity 0.22s ease, visibility 0.28s;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .user-notify-panel.open {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
  }

  .user-notify-panel-header {
    padding: 1rem 1rem 0.75rem;
    flex-shrink: 0;
  }

  .user-notify-panel-header h3 {
    font-size: 1rem;
  }

  .user-notify-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border: none;
    border-radius: 9999px;
    background: #f3f4f6;
    color: #4b5563;
    cursor: pointer;
    flex-shrink: 0;
  }

  .user-notify-mark-all {
    font-size: 0.75rem;
    padding: 0.375rem 0.625rem;
    min-height: 2.25rem;
  }

  .user-notify-item {
    padding: 0.875rem 1rem;
    min-height: 3.25rem;
  }

  .user-notify-item-title {
    font-size: 0.875rem;
  }

  .user-notify-item-body {
    font-size: 0.8125rem;
    -webkit-line-clamp: 4;
  }
}

@media (min-width: 768px) {
  .user-notify-close {
    display: none;
  }
}

.user-notify-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.75rem 1rem;
  border: none;
  border-bottom: 1px solid #f3f4f6;
  background: #fff;
  cursor: pointer;
  transition: background 0.12s;
}

.user-notify-item:hover {
  background: #f9fafb;
}

.user-notify-item.unread {
  background: #eff6ff;
}

.user-notify-item-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #111827;
  margin: 0 0 0.25rem;
}

.user-notify-item-body {
  font-size: 0.75rem;
  color: #4b5563;
  margin: 0;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.user-notify-item-time {
  font-size: 0.625rem;
  color: #9ca3af;
  margin-top: 0.35rem;
}

.user-notify-empty {
  padding: 2rem 1rem;
  text-align: center;
  font-size: 0.8125rem;
  color: #6b7280;
}

/* ── Profile góc phải ── */
.app-topbar-profile-wrap {
  position: relative;
}

.app-topbar-profile-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  max-width: min(14rem, 36vw);
  padding: 0.25rem 0.5rem 0.25rem 0.25rem;
  border-radius: 9999px;
  border: 1px solid #e5e7eb;
  background: #fff;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.app-topbar-profile-btn:hover {
  border-color: #c7d2fe;
  background: #f8fafc;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.08);
}

.app-topbar-profile-btn[aria-expanded='true'] {
  border-color: #818cf8;
  background: #eef2ff;
}

.app-topbar-avatar {
  width: 2.125rem;
  height: 2.125rem;
  border-radius: 9999px;
  background: linear-gradient(135deg, #dbeafe, #e0e7ff);
  color: #3730a3;
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.app-topbar-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.app-topbar-chevron {
  font-size: 0.625rem;
  color: #9ca3af;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.app-topbar-profile-btn[aria-expanded='true'] .app-topbar-chevron {
  transform: rotate(180deg);
}

.app-topbar-profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 290;
  min-width: 11rem;
  padding: 0.35rem;
  border-radius: 0.75rem;
  border: 1px solid #e5e7eb;
  background: #fff;
  box-shadow: 0 12px 40px -8px rgba(15, 23, 42, 0.18);
  display: none;
}

.app-topbar-profile-menu.open {
  display: block;
}

.app-topbar-menu-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: none;
  border-radius: 0.5rem;
  background: transparent;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #374151;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
}

.app-topbar-menu-item:hover {
  background: #f3f4f6;
  color: #111827;
}

.app-topbar-menu-item.danger {
  color: #dc2626;
}

.app-topbar-menu-item.danger:hover {
  background: #fef2f2;
}

.app-topbar-menu-divider {
  height: 1px;
  margin: 0.25rem 0.35rem;
  background: #f3f4f6;
}

/* Mobile: chỉ chuông trước nút menu (không hiển thị profile trên header) */
.app-mobile-topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

@media (min-width: 768px) {
  .app-mobile-topbar-actions {
    display: none;
  }
}
