/* ============================================================
   ALPHA BOOTES ENTERPRISE PLATFORM
   Layout: Sidebar + Topbar + Content Grid
   ============================================================ */

/* ── App Container ────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar content";
  min-height: 100vh;
  /* KHÔNG transition grid-template-columns: cột dùng 1fr không nội suy được
     → khung lưới bị "kẹt" giữa chừng (bug menu nhấp nháy/không thu gọn).
     Chuyển hiệu ứng mượt sang width của .sidebar bên dưới. */
}

#app.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed) 1fr;
}

/* ── Collapsed = thanh icon (icon-only rail) ──────────────── */
#app.sidebar-collapsed .sidebar-logo-text,
#app.sidebar-collapsed .sidebar-logo-sub,
#app.sidebar-collapsed .sidebar-item-label,
#app.sidebar-collapsed .sidebar-item-chevron,
#app.sidebar-collapsed .sidebar-item-badge,
#app.sidebar-collapsed .sidebar-user-info,
#app.sidebar-collapsed .sidebar-sub,
#app.sidebar-collapsed .sidebar-section-label {
  display: none !important;
}
#app.sidebar-collapsed .sidebar-header {
  flex-direction: column;
  gap: 8px;
  padding-left: 0;
  padding-right: 0;
  justify-content: center;
}
#app.sidebar-collapsed .sidebar-logo { justify-content: center; gap: 0; }
#app.sidebar-collapsed .sidebar-item {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}
#app.sidebar-collapsed .sidebar-item-icon { margin: 0; }
#app.sidebar-collapsed .sidebar-user { justify-content: center; padding-left: 0; padding-right: 0; }
/* icon nút thu gọn xoay khi đã thu gọn (gợi ý mở rộng) */
#app.sidebar-collapsed .sidebar-collapse-btn { transform: rotate(180deg); }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-primary);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: var(--z-sidebar);
  overflow: hidden;
  transition: width var(--transition-slow);
}

.sidebar-header {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-lg);
  border-bottom: 1px solid var(--border-primary);
  flex-shrink: 0;
  gap: var(--sp-md);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  text-decoration: none;
  min-width: 0;
}

.sidebar-logo-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--fw-bold);
  font-size: var(--fs-md);
  color: var(--text-inverse);
  flex-shrink: 0;
  box-shadow: var(--shadow-glow);
}

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

.sidebar-logo-name {
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  white-space: nowrap;
  letter-spacing: 0.5px;
}

.sidebar-logo-sub {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.sidebar-collapse-btn {
  margin-left: auto;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Sidebar Entity Switcher */
.sidebar-entity-switcher {
  padding: var(--sp-md) var(--sp-lg);
  border-bottom: 1px solid var(--border-primary);
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.entity-switch-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: var(--sp-sm) var(--sp-md);
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.entity-switch-btn:hover {
  border-color: var(--border-accent);
  background: var(--bg-hover);
}

.entity-switch-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.entity-switch-indicator.group    { background: var(--accent-primary); }
.entity-switch-indicator.arctorus { background: var(--status-info); }
.entity-switch-indicator.arctozen { background: var(--status-success); }

.entity-switch-label {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entity-switch-chevron {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform var(--transition-fast);
}

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-sm) 0;
}

.sidebar-section {
  padding: var(--sp-xs) 0;
}

.sidebar-section-label {
  padding: var(--sp-sm) var(--sp-lg);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-sm) var(--sp-lg);
  margin: 1px var(--sp-sm);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  position: relative;
  text-decoration: none;
}

.sidebar-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-item.active {
  background: var(--accent-muted);
  color: var(--accent-primary);
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--accent-primary);
  border-radius: 0 3px 3px 0;
}

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

.sidebar-item.active .sidebar-item-icon {
  opacity: 1;
}

.sidebar-item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-item-badge {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  padding: 1px 7px;
  border-radius: var(--radius-full);
  background: var(--accent-muted);
  color: var(--accent-primary);
  flex-shrink: 0;
}

.sidebar-item-chevron {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform var(--transition-fast);
}

.sidebar-item.expanded .sidebar-item-chevron {
  transform: rotate(90deg);
}

/* Nested sub-items */
.sidebar-sub {
  overflow: hidden;
  max-height: 0;
  transition: max-height var(--transition-slow);
}

.sidebar-sub.open {
  max-height: 800px;
}

.sidebar-sub .sidebar-item {
  padding-left: calc(var(--sp-lg) + 28px);
  font-size: var(--fs-sm);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: var(--sp-md) var(--sp-lg);
  border-top: 1px solid var(--border-primary);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: var(--sp-sm);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.sidebar-user:hover {
  background: var(--bg-hover);
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  color: var(--text-inverse);
  flex-shrink: 0;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.sidebar-user-name {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
  grid-area: topbar;
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-xl);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  backdrop-filter: blur(12px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  min-width: 0;
}

.topbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
  font-size: var(--fs-sm);
  overflow: hidden;
}

.breadcrumb-item {
  color: var(--text-muted);
  white-space: nowrap;
  transition: color var(--transition-fast);
  cursor: pointer;
}

.breadcrumb-item:hover {
  color: var(--text-primary);
}

.breadcrumb-item.current {
  color: var(--text-primary);
  font-weight: var(--fw-semibold);
  cursor: default;
}

.breadcrumb-sep {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  flex-shrink: 0;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

.topbar-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  position: relative;
}

.topbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.topbar-btn .badge-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--status-danger);
  border: 2px solid var(--bg-secondary);
}

.topbar-search {
  position: relative;
}

.topbar-search-input {
  width: 220px;
  height: 34px;
  font-size: var(--fs-sm);
  padding: 0 var(--sp-md) 0 34px;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.topbar-search-input:focus {
  width: 300px;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.topbar-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.topbar-search-kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-primary);
  pointer-events: none;
}

/* ── Content Area ─────────────────────────────────────────── */
.content {
  grid-area: content;
  padding: var(--content-padding);
  max-width: var(--content-max-width);
  width: 100%;
  min-width: 0;   /* cho phép cột 1fr co lại — nội dung rộng (bảng nhiều cột) tự scroll trong card thay vì tràn trang */
  min-height: calc(100vh - var(--topbar-height));
  animation: fadeIn var(--transition-normal) both;
}

/* ── Page Header ──────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-xl);
  flex-wrap: wrap;
  gap: var(--sp-md);
}

.page-header-left {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
}

.page-title {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

/* ── Empty State ──────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4xl) var(--sp-xl);
  text-align: center;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin-bottom: var(--sp-lg);
  color: var(--text-muted);
  opacity: 0.5;
}

.empty-state-title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  margin-bottom: var(--sp-sm);
}

.empty-state-text {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  max-width: 360px;
  margin-bottom: var(--sp-xl);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 1024px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "content";
  }

  .sidebar {
    position: fixed;
    left: -100%;
    width: var(--sidebar-width);
    transition: left var(--transition-slow);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.mobile-open {
    left: 0;
  }

  /* trên mobile, nút thu gọn desktop vô nghĩa → ẩn; dùng hamburger ở topbar */
  .sidebar-collapse-btn { display: none !important; }

  /* mobile thì luôn hiện đủ nội dung (bỏ chế độ icon-rail của desktop) */
  #app.sidebar-collapsed { grid-template-columns: 1fr; }
  #app.sidebar-collapsed .sidebar-item-label,
  #app.sidebar-collapsed .sidebar-logo-text,
  #app.sidebar-collapsed .sidebar-item-chevron,
  #app.sidebar-collapsed .sidebar-sub.open,
  #app.sidebar-collapsed .sidebar-user-info { display: revert !important; }

  .content {
    padding: var(--sp-base);
  }

  /* lớp nền mờ khi mở drawer */
  #sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-sidebar) - 1);
  }
}

/* backdrop chỉ hiện khi sidebar mở trên mobile */
#sidebar-backdrop { display: none; }

@media (max-width: 640px) {
  .topbar-search-input {
    width: 140px;
  }
  .topbar-search-input:focus {
    width: 180px;
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
