/**
 * QMF Unified Header Styles
 * Layout: [Hamburger (mobile)] [Logo + Page Title] [Social Buttons] [User Avatar]
 * @version 2.0.0
 */

/* ============================================
   CSS Variables (QMF Standard)
   ============================================ */
:root {
  /* Header */
  --qmf-header-height: 64px;
  --qmf-header-height-mobile: 56px;
  --qmf-header-bg: #ffffff;
  --qmf-header-border: #e5e7eb;
  --qmf-header-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  
  /* Brand Colors */
  --qmf-brand-primary: #667eea;
  --qmf-brand-secondary: #764ba2;
  --qmf-brand-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  
  /* Text */
  --qmf-text-primary: #1f2937;
  --qmf-text-secondary: #6b7280;
  --qmf-text-muted: #9ca3af;
  
  /* Buttons */
  --qmf-btn-hover-bg: rgba(102, 126, 234, 0.1);
  --qmf-btn-active-bg: rgba(102, 126, 234, 0.15);
  
  /* Sizes */
  --qmf-avatar-size: 36px;
  --qmf-btn-size: 40px;
  --qmf-btn-size-mobile: 36px;
  
  /* Z-Index */
  --qmf-z-header: 1000;
  --qmf-z-dropdown: 1100;
  
  /* Transitions */
  --qmf-transition-fast: 0.15s ease;
  --qmf-transition: 0.25s ease;
  
  /* Radius */
  --qmf-radius-sm: 8px;
  --qmf-radius-md: 12px;
  --qmf-radius-lg: 16px;
  --qmf-radius-full: 9999px;
}

/* Dark Theme */
[data-theme="dark"],
.dark {
  --qmf-header-bg: #1f2937;
  --qmf-header-border: #374151;
  --qmf-text-primary: #f9fafb;
  --qmf-text-secondary: #d1d5db;
  --qmf-text-muted: #9ca3af;
  --qmf-btn-hover-bg: rgba(102, 126, 234, 0.2);
}

/* ============================================
   Base Header Structure
   ============================================ */
.qmf-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--qmf-header-height);
  background: var(--qmf-header-bg);
  border-bottom: 1px solid var(--qmf-header-border);
  box-shadow: var(--qmf-header-shadow);
  z-index: var(--qmf-z-header);
  display: flex;
  align-items: center;
  padding: 0 16px;
}

.qmf-header__inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  gap: 16px;
}

/* ============================================
   3-Zone Layout: Left | Center | Right
   ============================================ */

/* Left Zone: Site Logo + Brand */
.qmf-header__left,
.qmf-header__cluster--left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 0;
  justify-content: flex-start;
}

/* Hamburger Button - Only visible on mobile/tablet */
.qmf-header__hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--qmf-btn-size-mobile);
  height: var(--qmf-btn-size-mobile);
  border: none;
  background: transparent;
  border-radius: var(--qmf-radius-sm);
  cursor: pointer;
  color: var(--qmf-text-primary);
  transition: all var(--qmf-transition-fast);
}

.qmf-header__hamburger:hover {
  background: var(--qmf-btn-hover-bg);
}

.qmf-header__hamburger:active {
  background: var(--qmf-btn-active-bg);
  transform: scale(0.95);
}

.qmf-header__hamburger i {
  font-size: 18px;
}

/* Brand Section */
.qmf-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.qmf-header__brand:hover {
  text-decoration: none;
}

.qmf-header__logo {
  width: 36px;
  height: 36px;
  border-radius: var(--qmf-radius-sm);
  object-fit: contain;
  flex-shrink: 0;
}

.qmf-header__brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.qmf-header__brand-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--qmf-text-primary);
  margin: 0;
  background: var(--qmf-brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.qmf-header__page-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--qmf-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ============================================
   Center Zone: Main Quizzman Logo + Name
   ============================================ */
.qmf-header__center,
.qmf-header__cluster--center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.qmf-header__main-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
}

.qmf-header__main-logo:hover {
  opacity: 0.85;
}

.qmf-header__logo-img {
  height: 32px;
  width: auto;
  object-fit: contain;
}

.qmf-header__main-name {
  font-size: 1.25rem;
  font-weight: 700;
  background: var(--qmf-brand-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

/* ============================================
   Right Zone: Social Buttons + User
   ============================================ */
.qmf-header__right,
.qmf-header__cluster--right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 0;
  justify-content: flex-end;
}

/* Social Buttons Container */
.qmf-header__social {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Social Button Base Style */
.qmf-header__btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--qmf-btn-size);
  height: var(--qmf-btn-size);
  border: none;
  background: transparent;
  border-radius: var(--qmf-radius-md);
  cursor: pointer;
  color: var(--qmf-text-secondary);
  transition: all var(--qmf-transition-fast);
}

.qmf-header__btn:hover {
  background: var(--qmf-btn-hover-bg);
  color: var(--qmf-brand-primary);
  transform: translateY(-1px);
}

.qmf-header__btn:active {
  background: var(--qmf-btn-active-bg);
  transform: translateY(0) scale(0.95);
}

.qmf-header__btn i {
  font-size: 17px;
}

/* Badge on buttons */
.qmf-header__badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: linear-gradient(135deg, #ff4444, #ff6b6b);
  color: white;
  font-size: 10px;
  font-weight: 700;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(255, 68, 68, 0.4);
  animation: qmf-badge-pulse 2s infinite;
}

.qmf-header__badge:empty,
.qmf-header__badge[data-count="0"] {
  display: none;
}

@keyframes qmf-badge-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Divider */
.qmf-header__divider {
  width: 1px;
  height: 28px;
  background: var(--qmf-header-border);
  margin: 0 8px;
}

/* ============================================
   User Avatar Dropdown
   ============================================ */
.qmf-header__user {
  position: relative;
}

.qmf-header__user-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  background: transparent;
  border: 1px solid var(--qmf-header-border);
  border-radius: var(--qmf-radius-full);
  cursor: pointer;
  transition: all var(--qmf-transition-fast);
}

.qmf-header__user-toggle:hover {
  background: var(--qmf-btn-hover-bg);
  border-color: var(--qmf-brand-primary);
}

.qmf-header__avatar {
  width: var(--qmf-avatar-size);
  height: var(--qmf-avatar-size);
  border-radius: 50%;
  object-fit: cover;
  background: var(--qmf-btn-hover-bg);
}

.qmf-header__user-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--qmf-text-primary);
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.qmf-header__chevron {
  font-size: 10px;
  color: var(--qmf-text-muted);
  transition: transform var(--qmf-transition-fast);
}

.qmf-header__user--open .qmf-header__chevron {
  transform: rotate(180deg);
}

/* Dropdown Menu */
.qmf-header__menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--qmf-header-bg);
  border: 1px solid var(--qmf-header-border);
  border-radius: var(--qmf-radius-md);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
  padding: 8px;
  z-index: var(--qmf-z-dropdown);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all var(--qmf-transition-fast);
}

.qmf-header__user--open .qmf-header__menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.qmf-header__menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--qmf-radius-sm);
  color: var(--qmf-text-primary);
  text-decoration: none;
  font-size: 14px;
  transition: all var(--qmf-transition-fast);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.qmf-header__menu-item:hover {
  background: var(--qmf-btn-hover-bg);
  color: var(--qmf-brand-primary);
}

.qmf-header__menu-item i {
  width: 18px;
  text-align: center;
  color: var(--qmf-text-secondary);
}

.qmf-header__menu-item:hover i {
  color: var(--qmf-brand-primary);
}

.qmf-header__menu-divider {
  height: 1px;
  background: var(--qmf-header-border);
  margin: 6px 0;
}

.qmf-header__menu-item--danger {
  color: #ef4444;
}

.qmf-header__menu-item--danger:hover {
  background: #fee2e2;
  color: #dc2626;
}

.qmf-header__menu-item--danger i {
  color: #ef4444;
}

/* ============================================
   Auth States
   ============================================ */
.qmf-auth-only {
  display: none;
}

body.authenticated .qmf-auth-only {
  display: flex;
}

body.authenticated .qmf-guest-only {
  display: none;
}

/* ============================================
   Responsive Design
   ============================================ */

/* Tablet and below */
@media (max-width: 1024px) {
  .qmf-header__hamburger {
    display: flex;
  }
  
  .qmf-header__user-name {
    display: none;
  }
  
  .qmf-header__user-toggle {
    padding: 4px;
    border-radius: 50%;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .qmf-header {
    padding: 0 12px;
    height: var(--qmf-header-height-mobile);
  }
  
  .qmf-header__inner {
    gap: 8px;
  }
  
  .qmf-header__logo {
    width: 32px;
    height: 32px;
  }
  
  .qmf-header__brand-name {
    font-size: 15px;
  }
  
  .qmf-header__page-title {
    font-size: 11px;
  }
  
  .qmf-header__btn {
    width: var(--qmf-btn-size-mobile);
    height: var(--qmf-btn-size-mobile);
  }
  
  .qmf-header__btn i {
    font-size: 16px;
  }
  
  .qmf-header__divider {
    margin: 0 4px;
    height: 24px;
  }
  
  .qmf-header__avatar {
    width: 32px;
    height: 32px;
  }
  
  /* Hide social buttons on small mobile - use QAM instead */
  .qmf-header__social {
    display: none;
  }
  
  .qmf-header__divider {
    display: none;
  }
}

/* Small mobile */
@media (max-width: 480px) {
  .qmf-header__brand-text {
    display: none;
  }
  
  .qmf-header__logo {
    width: 36px;
    height: 36px;
  }
}

/* ============================================
   System Dark Mode (auto)
   ============================================ */
@media (prefers-color-scheme: dark) {
  .qmf-header.auto-dark {
    --qmf-header-bg: #1f2937;
    --qmf-header-border: #374151;
    --qmf-text-primary: #f9fafb;
    --qmf-text-secondary: #d1d5db;
    --qmf-text-muted: #9ca3af;
    --qmf-btn-hover-bg: rgba(102, 126, 234, 0.2);
  }
}

/* ============================================
   Notification Container Fix - No Extra Space
   ============================================ */
/* Container được append vào body - không chiếm diện tích */
.qmf-noti-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  overflow: visible;
  pointer-events: none;
}

/* Container được đặt trong header */
.qmf-header .qmf-noti-container,
.qmf-header__cluster .qmf-noti-container {
  position: static;
  width: auto;
  height: auto;
  display: contents;
  pointer-events: auto;
}

/* Widget cần pointer events */
.qmf-noti-container .notification-widget {
  position: relative;
  display: inline-flex;
  align-items: center;
  pointer-events: auto;
}

/* Dropdown phải ẩn hoàn toàn khi không show */
.qmf-noti-container .noti-dropdown,
.noti-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 360px;
  max-height: 480px;
  background: var(--qmf-header-bg, #fff);
  border: 1px solid var(--qmf-header-border, #e5e7eb);
  border-radius: var(--qmf-radius-lg, 16px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  z-index: var(--qmf-z-dropdown, 1100);
  /* Hidden by default */
  display: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px) scale(0.95);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  pointer-events: auto;
}

.noti-dropdown.show {
  display: flex;
  flex-direction: column;
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Noti bell button trong widget */
.noti-bell-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--qmf-btn-size, 40px);
  height: var(--qmf-btn-size, 40px);
  padding: 0;
  border: none;
  background: transparent;
  color: var(--qmf-text-secondary, #6b7280);
  border-radius: var(--qmf-radius-sm, 8px);
  cursor: pointer;
  transition: all var(--qmf-transition-fast, 0.15s ease);
}

.noti-bell-btn:hover {
  background: var(--qmf-btn-hover-bg, rgba(102, 126, 234, 0.1));
  color: var(--qmf-brand-primary, #667eea);
}

.noti-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  color: #fff;
  background: linear-gradient(135deg, #ff4444, #ff6b6b);
  border-radius: 9px;
  box-shadow: 0 2px 6px rgba(255, 68, 68, 0.4);
}

.noti-badge:empty,
.noti-badge[style*="display: none"] {
  display: none !important;
}

/* Noti dropdown internal styles */
.noti-dropdown .noti-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--qmf-brand-gradient, linear-gradient(135deg, #667eea 0%, #764ba2 100%));
  color: #fff;
}

.noti-dropdown .noti-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.noti-dropdown .noti-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.noti-dropdown .noti-header-actions button {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.noti-dropdown .noti-header-actions button:hover {
  background: rgba(255, 255, 255, 0.3);
}

.noti-dropdown .noti-close-btn {
  padding: 6px 8px;
}

.noti-dropdown .noti-list {
  flex: 1;
  overflow-y: auto;
  max-height: 350px;
  padding: 8px 0;
}

.noti-dropdown .noti-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 20px;
  color: var(--qmf-text-muted, #9ca3af);
}

.noti-dropdown .noti-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--qmf-brand-primary, #667eea);
  border-radius: 50%;
  animation: noti-spin 0.8s linear infinite;
}

@keyframes noti-spin {
  to { transform: rotate(360deg); }
}

.noti-dropdown .noti-footer {
  padding: 12px 16px;
  text-align: center;
  border-top: 1px solid var(--qmf-header-border, #e5e7eb);
  background: #fafbfc;
}

.noti-dropdown .noti-view-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--qmf-brand-primary, #667eea);
  text-decoration: none;
  border-radius: 20px;
  transition: all 0.2s ease;
}

.noti-dropdown .noti-view-all:hover {
  background: rgba(102, 126, 234, 0.1);
}

/* Mobile responsive */
@media (max-width: 480px) {
  .qmf-noti-container .noti-dropdown,
  .noti-dropdown {
    position: fixed;
    top: var(--qmf-header-height-mobile, 56px);
    left: 8px;
    right: 8px;
    min-width: unset;
    max-height: calc(100vh - var(--qmf-header-height-mobile, 56px) - 16px);
  }
}

/* ============================================
   Reduce Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  .qmf-header__badge {
    animation: none;
  }
  
  .qmf-header *,
  .qmf-header *::before,
  .qmf-header *::after {
    transition-duration: 0.01ms !important;
  }
}
