/* ========== CSS VARIABLES ========== */
:root {
  --primary: #0d6efd;
  --primary-light: #3d8bfd;
  --primary-dark: #0a58ca;
  --primary-50: #e7f1ff;
  --primary-100: #cfe2ff;
  --secondary: #6c757d;
  --accent: #ffc107;
  --success: #198754;
  --success-light: #d1e7dd;
  --warning: #ffc107;
  --warning-light: #fff3cd;
  --error: #dc3545;
  --error-light: #f8d7da;
  --info: #0dcaf0;
  --info-light: #cff4fc;

  --bg-page: #f5f6fa;
  --bg-card: #ffffff;
  --sidebar-bg: #1e2a3a;
  --sidebar-hover: rgba(255, 255, 255, 0.08);
  --sidebar-active: #0d6efd;

  --text-primary: #212529;
  --text-secondary: #6c757d;
  --text-muted: #adb5bd;
  --border: #dee2e6;
  --border-light: #e9ecef;

  --sidebar-w: 260px;
  --sidebar-collapsed-w: 64px;
  --navbar-h: 56px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);

  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Suppress transitions on initial page load (removed by sidebar.js) */
.sidebar-no-transition,
.sidebar-no-transition *,
.sidebar-no-transition *::before,
.sidebar-no-transition *::after {
  transition: none !important;
}

/* ========== LAYOUT SHELL ========== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ========== SIDEBAR ========== */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  color: rgba(255, 255, 255, 0.7);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition:
    width var(--transition-slow),
    transform var(--transition-slow);
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-w);
}

/* Sidebar Header / Brand */
.sidebar-brand {
  height: var(--navbar-h);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.sidebar-brand .brand-icon {
  width: 34px;
  height: 34px;
  background: linear-gradient(
    135deg,
    var(--primary) 0%,
    var(--primary-light) 100%
  );
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-brand .brand-text {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  opacity: 1;
  transition: opacity var(--transition);
}

/* Collapsed state: hide text elements */
.sidebar.collapsed .brand-text {
  opacity: 0;
  pointer-events: none;
}
.sidebar.collapsed .sidebar-label {
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
  padding: 0;
  margin: 0;
}
.sidebar.collapsed .nav-text {
  opacity: 0;
  pointer-events: none;
}
.sidebar.collapsed .nav-arrow {
  opacity: 0;
  pointer-events: none;
}
.sidebar.collapsed .nav-badge {
  display: none;
}
.sidebar.collapsed .sidebar-footer-info {
  display: none;
}

/* Collapsed submenu hidden (flyout on hover via position:fixed) */
.sidebar.collapsed .nav-sub {
  max-height: 0 !important;
  overflow: hidden !important;
  padding: 0 !important;
  visibility: hidden;
}
.sidebar.collapsed .sidebar-brand {
  overflow: hidden;
}

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 0;
}

.sidebar-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-nav li {
  list-style: none;
  margin: 0;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.sidebar-label {
  padding: 16px 20px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.35);
  opacity: 1;
  transition: opacity var(--transition);
  white-space: nowrap;
}

.nav-item {
  position: relative;
}

.nav-link-sidebar {
  display: flex;
  align-items: center;
  padding: 0 12px;
  height: 40px;
  gap: 12px;
  color: rgba(255, 255, 255, 0.65);
  font-size: 14px;
  font-weight: 450;
  border-radius: var(--radius-md);
  margin: 2px 8px;
  transition: all var(--transition);
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
}

.nav-link-sidebar:hover {
  background: var(--sidebar-hover);
  color: rgba(255, 255, 255, 0.9);
}

.nav-link-sidebar.active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 500;
}

.nav-link-sidebar .nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.nav-link-sidebar .nav-text {
  flex: 1;
  opacity: 1;
  transition: opacity var(--transition);
}

.nav-link-sidebar .nav-arrow {
  width: 16px;
  height: 16px;
  opacity: 0.5;
  transition:
    transform var(--transition),
    opacity var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.nav-item.open > .nav-link-sidebar .nav-arrow {
  transform: rotate(90deg);
}

.nav-link-sidebar .nav-badge {
  background: var(--error);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  line-height: 18px;
}

/* Sub-navigation */
.nav-sub {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--transition-slow);
}

.nav-sub li {
  display: block;
}

.nav-item.open > .nav-sub {
  max-height: 600px;
  overflow: visible;
}

/* Submenu items */
.nav-sub .nav-link-sidebar {
  padding: 0 12px 0 52px;
  height: 34px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.5);
  margin: 1px 8px;
  gap: 10px;
}

.nav-sub .nav-link-sidebar .nav-icon {
  width: 16px;
  height: 16px;
  font-size: 14px;
}

.nav-sub .nav-link-sidebar:hover {
  color: rgba(255, 255, 255, 0.85);
  background: var(--sidebar-hover);
}

.nav-sub .nav-link-sidebar.active {
  color: #fff;
  background: rgba(13, 110, 253, 0.15);
}

/* Flyout popup submenu when collapsed */
.sidebar.collapsed .nav-item[data-has-sub]:hover > .nav-sub {
  max-height: none !important;
  overflow: visible !important;
  visibility: visible !important;
  position: fixed;
  left: var(--sidebar-collapsed-w);
  width: 220px;
  background: var(--sidebar-bg);
  border-radius: 0 8px 8px 0;
  box-shadow: 4px 4px 16px rgba(0, 0, 0, 0.3);
  padding: 8px 0 !important;
  z-index: 200;
}

.sidebar.collapsed .nav-item[data-has-sub]:hover > .nav-sub li {
  display: block;
}

.sidebar.collapsed .nav-item[data-has-sub]:hover > .nav-sub .nav-link-sidebar {
  padding: 0 16px;
  margin: 1px 8px;
  height: 34px;
  white-space: nowrap;
}

.sidebar.collapsed .nav-item[data-has-sub]:hover > .nav-sub .nav-text {
  opacity: 1 !important;
  pointer-events: auto !important;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.sidebar-footer-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
}

.sidebar-footer-info .status-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-footer-info .status-text {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  white-space: nowrap;
}

.sidebar-footer-info .status-label {
  font-size: 11px;
  color: var(--success);
  margin-left: auto;
  white-space: nowrap;
}

/* ========== MAIN WRAPPER ========== */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-w);
  transition: margin-left var(--transition-slow);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
}

.sidebar.collapsed ~ .main-wrapper {
  margin-left: var(--sidebar-collapsed-w);
}

/* ========== TOP NAVBAR ========== */
.top-navbar {
  height: var(--navbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.navbar-toggle {
  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);
  background: none;
  border: none;
  cursor: pointer;
}

.navbar-toggle:hover {
  background: var(--primary-50);
  color: var(--primary);
}

.navbar-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.navbar-breadcrumb .bc-separator {
  color: var(--text-muted);
  font-size: 12px;
}

.navbar-breadcrumb .bc-current {
  color: var(--text-primary);
  font-weight: 600;
}

.navbar-breadcrumb .bc-parent {
  color: var(--text-secondary);
  text-decoration: none;
}

.navbar-spacer {
  flex: 1;
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.navbar-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  position: relative;
  transition: all var(--transition);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
}

.navbar-btn:hover {
  background: var(--bg-page);
  color: var(--text-primary);
}

.navbar-btn .notif-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 18px;
  height: 18px;
  background: var(--error);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid var(--bg-card);
  padding: 0 3px;
}

.navbar-divider {
  width: 1px;
  height: 28px;
  background: var(--border);
  margin: 0 8px;
}

.navbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition);
}

.navbar-user:hover {
  background: var(--bg-page);
}

.navbar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.navbar-user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.navbar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.navbar-user-role {
  font-size: 11px;
  color: var(--text-muted);
}

/* ========== MAIN CONTENT ========== */
.main-content {
  flex: 1;
  padding: 24px;
  background: var(--bg-page);
}

/* ========== PAGE HEADER ========== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h4 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.page-header .page-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ========== SIDEBAR OVERLAY (mobile) ========== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 90;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
  display: block;
}

/* ========== FOOTER ========== */
.app-footer {
  padding: 16px 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-light);
  background: var(--bg-page);
}

/* ========== AUTH LAYOUT ========== */
.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-page);
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 2rem;
}

.auth-card .auth-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-card .auth-logo .brand-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(
    135deg,
    var(--primary) 0%,
    var(--primary-light) 100%
  );
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 12px;
}

.auth-card .auth-logo h5 {
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.auth-card .auth-logo p {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    width: var(--sidebar-w);
  }
  .main-wrapper {
    margin-left: 0 !important;
  }
  .navbar-user-info {
    display: none;
  }
}

@media (max-width: 576px) {
  .main-content {
    padding: 16px;
  }
  .top-navbar {
    padding: 0 16px;
    gap: 8px;
  }
  .navbar-breadcrumb {
    display: none;
  }
  .navbar-actions {
    gap: 0px;
  }
  .navbar-btn {
    width: 32px;
    height: 32px;
  }
  .navbar-user {
    padding: 4px;
  }
  .navbar-user .bi-chevron-down {
    display: none;
  }
}
