/* =========================================
   LAYOUT CSS — Sidebar, Topbar, Grid
   ========================================= */

/* ── Auth Pages ── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0F172A 0%, #1E293B 60%, #0F172A 100%);
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
}

.auth-page::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  background: radial-gradient(circle, rgba(79,70,229,0.18) 0%, transparent 70%);
  top: -200px; left: -200px;
  pointer-events: none;
}

.auth-page::after {
  content: '';
  position: absolute;
  width: 400px; height: 400px;
  background: radial-gradient(circle, rgba(79,70,229,0.12) 0%, transparent 70%);
  bottom: -100px; right: -100px;
  pointer-events: none;
}

/* ── App Shell ── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: 256px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  height: 100vh;
  z-index: 200;
  transition: transform var(--dur-md) var(--ease);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.brand-icon {
  width: 38px; height: 38px;
  background: var(--primary);
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(79,70,229,0.4);
}

.brand-icon svg { color: white; }

.brand-text { overflow: hidden; }

.brand-name {
  font-size: 0.9375rem;
  font-weight: 700;
  color: #F1F5F9;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.brand-tagline {
  font-size: 0.6875rem;
  color: var(--sidebar-text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ── Sidebar Nav ── */
.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sidebar-text);
  opacity: 0.5;
  padding: 1rem 1rem 0.375rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5625rem 1rem;
  color: var(--sidebar-text);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  border-left: 2px solid transparent;
  margin: 1px 0;
  position: relative;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: #E2E8F0;
  text-decoration: none;
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: #FFFFFF;
  border-left-color: var(--primary);
}

.nav-item.active .nav-icon { color: var(--primary); opacity: 1; }

.nav-icon {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  opacity: 0.6;
  transition: opacity var(--dur) var(--ease);
}

.nav-item:hover .nav-icon { opacity: 0.9; }

.nav-label { flex: 1; }

.nav-badge {
  background: var(--primary);
  color: white;
  font-size: 0.625rem;
  font-weight: 700;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
  line-height: 1.4;
}

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: 0.5rem 1rem;
}

/* ── Sidebar Footer ── */
.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.sidebar-user:hover { background: var(--sidebar-hover); }

.user-avatar-lg {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #7C3AED);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8125rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.user-meta { flex: 1; overflow: hidden; }

.user-display-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #F1F5F9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role-label {
  font-size: 0.6875rem;
  color: var(--sidebar-text);
}

.logout-btn {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  color: var(--sidebar-text);
  border-radius: var(--radius);
  transition: all var(--dur) var(--ease);
  flex-shrink: 0;
  cursor: pointer;
}

.logout-btn:hover { background: rgba(220,38,38,0.15); color: #F87171; }

/* ── Mobile Toggle ── */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 0.875rem; left: 0.875rem;
  z-index: 300;
  background: var(--sidebar-bg);
  color: white;
  border: 1px solid rgba(255,255,255,0.1);
  padding: 0.4375rem;
  border-radius: var(--radius);
  align-items: center; justify-content: center;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 190;
  backdrop-filter: blur(2px);
}

/* ── Main Wrapper ── */
.main-wrapper {
  flex: 1;
  margin-left: 256px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* ── Topbar ── */
.topbar {
  height: 60px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.topbar-info { flex-shrink: 0; }

.topbar-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.topbar-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.2;
}

.topbar-search {
  flex: 1;
  max-width: 360px;
  margin-left: 1.25rem;
  position: relative;
}

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

.topbar-search input {
  width: 100%;
  height: 36px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0 1rem 0 2.375rem;
  font-size: 0.8125rem;
  color: var(--text);
  transition: all var(--dur) var(--ease);
  outline: none;
}

.topbar-search input::placeholder { color: var(--text-light); }

.topbar-search input:focus {
  border-color: var(--primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  position: relative;
}

.topbar-icon-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.notif-dot {
  position: absolute;
  top: 7px; right: 7px;
  width: 6px; height: 6px;
  background: var(--danger);
  border-radius: 50%;
  border: 1.5px solid white;
}

.topbar-user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.625rem 0.25rem 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}

.topbar-user-chip:hover { border-color: var(--primary); background: var(--primary-light); }

.topbar-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #7C3AED);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700; color: white;
}

.topbar-username {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main Content ── */
.main-content {
  flex: 1;
  padding: 1.5rem;
  overflow-x: hidden;
}

.page-section { display: none; }
.page-section.active { display: block; }

/* ── Page Header ── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header-left h1 {
  font-size: 1.375rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.025em;
}

.page-header-left p {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.page-header-actions { display: flex; gap: 0.625rem; align-items: center; flex-wrap: wrap; }

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ── Content Grid ── */
.content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

/* ── Responsive ── */
@media (max-width: 1280px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 1024px) {
  .content-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .sidebar-toggle { display: flex; }
  .main-wrapper { margin-left: 0; }
  .topbar { padding: 0 1rem 0 3.75rem; }
  .topbar-search { display: none; }
  .main-content { padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; }
  .page-header-actions { width: 100%; }
  .page-header-actions .btn { flex: 1; justify-content: center; }
}
