/* ═══════════════════════════════════════════════════════════
   Alvion O'quv Markazi — Layout (Sidebar + Header + Main)
   ═══════════════════════════════════════════════════════════ */

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--z-sidebar);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-primary);
  display: flex;
  flex-direction: column;
  transition: width var(--duration-slow) var(--ease-out-quint),
              transform var(--duration-slow) var(--ease-out-quint);
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5);
  border-bottom: 1px solid var(--border-primary);
  flex-shrink: 0;
  min-height: var(--header-height);
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #1a2a5e, #0f1a3d);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(26, 42, 94, 0.35);
}

.sidebar-logo svg {
  width: 20px;
  height: 20px;
  color: #fff;
}

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

.sidebar-brand-name {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  white-space: nowrap;
}

.sidebar-brand-sub {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  white-space: nowrap;
}

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

.sidebar-section {
  margin-bottom: var(--space-4);
}

.sidebar-section-title {
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--fs-base);
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out-quint);
  text-decoration: none;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

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

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

.sidebar-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.sidebar-link svg,
.sidebar-link i {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-link-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-link-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: var(--fw-bold);
  padding: 2px 7px;
  border-radius: var(--radius-full);
  min-width: 20px;
  text-align: center;
  line-height: 1.4;
}

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

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-in-out);
}

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

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

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

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

/* Sidebar collapse toggle */
.sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--duration-fast) var(--ease-in-out);
  border: none;
  background: none;
  margin-left: auto;
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

/* ── Main Content Area ── */
.main-wrapper {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--duration-slow) var(--ease-out-quint);
}

/* ── Header ── */
.header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-primary);
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  flex-shrink: 0;
  gap: var(--space-4);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-width: 0;
}

.header-mobile-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-in-out);
  border: none;
  background: none;
  flex-shrink: 0;
}

.header-mobile-toggle:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.header-page-info {
  min-width: 0;
}

.header-page-title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-page-subtitle {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

.header-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-in-out);
  border: none;
  background: none;
  position: relative;
}

.header-action:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.header-action svg {
  width: 20px;
  height: 20px;
}

.theme-toggle-icon {
  transition: transform var(--duration-base) var(--ease-out-quint);
}

.theme-toggle-icon:hover {
  transform: rotate(30deg);
}

/* ── Main Content ── */
.main-content {
  flex: 1;
  padding: var(--space-6);
  max-width: var(--content-max-width);
  width: 100%;
  margin: 0 auto;
}

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

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* ── Stats Grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-4);
}

/* ── Content Grid ── */
.content-grid {
  display: grid;
  gap: var(--space-6);
}

.content-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.content-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

/* ── Mobile Overlay ── */
.sidebar-mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: calc(var(--z-sidebar) - 1);
}

/* ═══════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════ */

/* ── Tablet (<= 1024px) ── */
@media (max-width: 1024px) {
  .sidebar {
    width: var(--sidebar-collapsed);
  }

  .sidebar-brand,
  .sidebar-section-title,
  .sidebar-link-text,
  .sidebar-link-badge,
  .sidebar-user-info,
  .sidebar-brand-sub {
    display: none;
  }

  .sidebar-header {
    justify-content: center;
    padding: var(--space-4);
  }

  .sidebar-link {
    justify-content: center;
    padding: var(--space-3);
  }

  .sidebar-link.active::before {
    display: none;
  }

  .sidebar-user {
    justify-content: center;
  }

  .sidebar-toggle {
    display: none;
  }

  .main-wrapper {
    margin-left: var(--sidebar-collapsed);
  }

  .content-grid-2 {
    grid-template-columns: 1fr;
  }

  .content-grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Mobile (<= 768px) ── */
@media (max-width: 768px) {
  .sidebar {
    width: var(--sidebar-width);
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar.open ~ .sidebar-mobile-overlay {
    display: block;
  }

  .sidebar-brand,
  .sidebar-section-title,
  .sidebar-link-text,
  .sidebar-link-badge,
  .sidebar-user-info {
    display: block;
  }

  .sidebar-brand-sub {
    display: block;
  }

  .sidebar-header {
    justify-content: flex-start;
    padding: var(--space-5);
  }

  .sidebar-link {
    justify-content: flex-start;
    padding: var(--space-2) var(--space-3);
  }

  .sidebar-link.active::before {
    display: block;
  }

  .sidebar-user {
    justify-content: flex-start;
  }

  .main-wrapper {
    margin-left: 0;
  }

  .header-mobile-toggle {
    display: flex;
  }

  .main-content {
    padding: var(--space-4);
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-3);
  }

  .content-grid-3 {
    grid-template-columns: 1fr;
  }

  .header {
    padding: 0 var(--space-4);
  }

  .modal {
    margin: var(--space-4);
    max-height: calc(100vh - var(--space-8));
    max-height: calc(100dvh - var(--space-8));
  }

  .toast-container {
    left: var(--space-4);
    right: var(--space-4);
    max-width: none;
  }
}

/* ── Small mobile (<= 480px) ── */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .page-header-actions {
    width: 100%;
  }

  .page-header-actions .btn {
    flex: 1;
    justify-content: center;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .header-page-subtitle {
    display: none;
  }

  .pagination {
    flex-direction: column;
    gap: var(--space-2);
  }
}
