/* ============================================================
   ALP Layout — layout.css
   App shell: sidebar, header, content area, mobile responsiveness
   ============================================================ */

/* ── App Layout Grid ──────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: 1fr;
  min-height: 100vh;
  width: 100%;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  background: #000000;
  border-right: 1px solid var(--border-primary);
  z-index: var(--z-sidebar);
  transition: transform var(--duration-slow) var(--ease-out);
  overflow: hidden;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
}

.sidebar-inner {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(212, 175, 55, 0.02) 0%, transparent 30%, transparent 70%, rgba(212, 175, 55, 0.01) 100%);
  pointer-events: none;
}

.sidebar::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 1px;
  height: 100%;
  background: linear-gradient(180deg, transparent, rgba(212, 175, 55, 0.15), transparent);
  pointer-events: none;
}

/* ── Sidebar Logo ─────────────────────────────────────────── */
.sidebar-logo {
  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;
  position: relative;
  height: var(--header-height);
}

.sidebar-logo::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(212, 175, 55, 0.3), transparent);
}

.sidebar-logo-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #D4AF37, #997a15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  color: #0a0a0a;
  flex-shrink: 0;
  box-shadow: 
    0 0 20px rgba(212, 175, 55, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
  position: relative;
}

.sidebar-logo-text {
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  letter-spacing: var(--tracking-tight);
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-logo-badge {
  font-size: 10px;
  font-weight: var(--font-semibold);
  color: var(--cyber-green);
  background: rgba(0, 255, 136, 0.1);
  border: 1px solid rgba(0, 255, 136, 0.2);
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  box-shadow: 0 0 16px rgba(0, 255, 136, 0.15);
  animation: pulse-badge 2s ease-in-out infinite;
}

@keyframes pulse-badge {
  0%, 100% {
    box-shadow: 0 0 12px rgba(0, 255, 136, 0.15);
  }
  50% {
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.25);
  }
}

/* ── Sidebar Navigation ───────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

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

.sidebar-nav-section:first-child {
  margin-top: 0;
}

.sidebar-nav-label {
  font-size: 11px;
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-1);
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2.5) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
  -webkit-user-select: none;
  user-select: none;
}

.sidebar-nav-item:hover {
  background: rgba(212, 175, 55, 0.06);
  color: var(--text-primary);
  transform: translateX(2px);
}

.sidebar-nav-item.active {
  background: linear-gradient(90deg, rgba(212, 175, 55, 0.12), rgba(212, 175, 55, 0.03));
  color: #D4AF37;
  box-shadow: inset 0 1px 2px rgba(212, 175, 55, 0.1);
}

.sidebar-nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: linear-gradient(180deg, #D4AF37, #E8C547);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  box-shadow: 0 0 12px rgba(212, 175, 55, 0.4);
}

.sidebar-nav-item.active::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-md);
  border: 1px solid rgba(212, 175, 55, 0.2);
  pointer-events: none;
}

.sidebar-nav-item i,
.sidebar-nav-item .nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-md);
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity var(--transition-fast);
}

.sidebar-nav-item:hover i,
.sidebar-nav-item:hover .nav-icon,
.sidebar-nav-item.active i,
.sidebar-nav-item.active .nav-icon {
  opacity: 1;
}

.sidebar-nav-item .nav-badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: var(--font-semibold);
  background: var(--color-danger);
  color: #fff;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  padding: 0 6px;
}

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

.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(--transition-base);
}

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

.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: #ffffff;
  flex-shrink: 0;
}

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

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

.sidebar-user-role {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: capitalize;
}

.sidebar-user-menu-btn {
  color: var(--text-muted);
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}

.sidebar-user-menu-btn:hover {
  color: var(--text-primary);
}

/* ── Main Content Area ────────────────────────────────────── */
.main-content {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Header ───────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: var(--header-height);
  padding: 0 var(--space-6);
  background: rgba(0, 0, 0, 0.90);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border-bottom: 1px solid var(--border-primary);
  transition: all var(--transition-slow);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.25), transparent);
  pointer-events: none;
}

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

.header-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  white-space: nowrap;
}

.header-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-left: var(--space-2);
  white-space: nowrap;
}

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

/* ── Header Search ────────────────────────────────────────── */
.header-search {
  position: relative;
  width: 280px;
  margin-left: auto;
}

.header-search-input {
  width: 100%;
  height: 36px;
  padding: 0 var(--space-4) 0 36px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  transition: all var(--transition-base);
}

.header-search-input::placeholder {
  color: var(--text-muted);
}

.header-search-input:focus {
  border-color: var(--accent-primary);
  background: var(--bg-input);
  box-shadow: 0 0 0 3px var(--accent-primary-ring);
}

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

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

/* ── Header Action Buttons ────────────────────────────────── */
.header-action {
  position: relative;
  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-base);
  cursor: pointer;
}

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

.header-action .notification-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: var(--color-danger);
  border-radius: var(--radius-pill);
  border: 2px solid var(--bg-secondary);
}

/* ── Theme Toggle ─────────────────────────────────────────── */
.theme-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-base);
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--color-warning);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  transition: transform var(--duration-normal) var(--ease-spring), opacity var(--duration-fast);
}

[data-theme='light'] .theme-toggle .icon-moon { display: none; }
[data-theme='light'] .theme-toggle .icon-sun  { display: block; }
:root .theme-toggle .icon-sun  { display: none; }
:root .theme-toggle .icon-moon { display: block; }

/* ── Header User Profile ─────────────────────────────────── */
.header-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-base);
  border-left: 1px solid var(--border-primary);
  padding-left: var(--space-4);
  margin-left: var(--space-2);
}

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

.header-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: #ffffff;
  flex-shrink: 0;
  transition: box-shadow var(--transition-base);
}

.header-user:hover .header-user-avatar {
  box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent-primary);
}

.header-user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.header-user-name {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.2;
}

.header-user-role {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: capitalize;
  line-height: 1.2;
  margin-top: 2px;
}

.header-logout-btn {
  color: var(--text-muted);
  transition: color var(--transition-fast), background var(--transition-base);
}

.header-logout-btn:hover {
  color: var(--color-danger);
  background: var(--color-danger-muted);
}

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

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

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

.page-header-title {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--text-primary);
}

.page-header-description {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

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

/* ── Mobile Menu Icon Button ────────────────────────── */
.mobile-menu-btn {
  display: none;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
}

.mobile-menu-btn:hover {
  background: rgba(212, 175, 55, 0.12);
  border-color: rgba(212, 175, 55, 0.3);
  color: #D4AF37;
  transform: scale(1.04);
}

.mobile-menu-btn.active {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}

/* ── Mobile Overlay ───────────────────────────────────────── */
.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mobile-overlay.active {
  opacity: 1;
}

/* ── Responsive: Tablet and Below ─────────────────────────── */
@media (max-width: 1024px) {
  .header-search {
    width: 180px;
  }

  .header-search-shortcut {
    display: none;
  }
}

@media (max-width: 768px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1000;
    width: 260px;
    transform: translateX(-100%);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  }

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

  .main-content {
    grid-column: 1;
    width: 100%;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .mobile-overlay {
    display: block;
    pointer-events: none;
  }

  .mobile-overlay.active {
    pointer-events: auto;
  }

  .header {
    padding: 0 12px;
    gap: 8px;
  }

  .header-left {
    gap: 8px;
  }

  .header-title {
    font-size: 15px;
  }

  .header-search {
    display: none;
  }

  .header-subtitle {
    display: none;
  }

  .header-user-info {
    display: none;
  }

  .connection-indicator {
    display: none;
  }

  .page-content {
    padding: var(--page-padding-mobile);
  }

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

@media (max-width: 480px) {
  .header-telegram-badge {
    display: none !important;
  }

  .page-header-title {
    font-size: var(--text-xl);
  }

  .header-user-avatar {
    width: 30px;
    height: 30px;
    font-size: 12px;
  }
}

