/**
 * ============================================
 * HEADER COMPONENT STYLES
 * BrainDump MVP - Warm Vault Compatible
 * ============================================
 *
 * @version 9.0.0
 * @date 2026-01-06
 *
 * CHANGELOG:
 * v8.0.0 (2026-01-05):
 *   - CHANGED: Search bar is now wide and prominent
 *   - REMOVED: Upload button (moved to input section)
 *   - ADDED: Admin link button styling
 *   - IMPROVED: Profile dropdown accessibility
 * v7.0.0 (2026-01-05):
 *   - ADDED: Hamburger menu for sidebar toggle
 *   - ADDED: Profile dropdown menu
 * v6.0.0 (2026-01-02):
 *   - ADDED: Help Modal with Accordion
 * v5.0.0 (2025-12-11):
 *   - ADDED: Space-Selector integration styles
 */

/* ============================================
   HEADER BASE
   ============================================ */

.app-header {
  background: var(--color-bg-elevated, #1a1a1a);
  border-bottom: 1px solid var(--color-border, rgba(230, 184, 125, 0.15));
  
  padding: var(--spacing-md, 16px) var(--spacing-lg, 24px);
  
  position: sticky;
  top: 0;
  
  z-index: var(--z-sticky, 100);
  
  backdrop-filter: blur(8px);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ============================================
   LEFT SECTION - LOGO + SPACE SELECTOR
   ============================================ */

.header-left {
  display: flex;
  align-items: center;
  gap: var(--spacing-md, 16px);
}

.logo-link {
  text-decoration: none;
  color: inherit;
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs, 4px);
  
  font-size: var(--font-size-2xl, 24px);
  font-weight: 700;
  
  margin: 0;
  
  transition: transform 0.2s ease;
}

.logo-link:hover .logo {
  transform: scale(1.02);
}

.logo-text {
  background: linear-gradient(135deg, var(--color-primary, #E6B87D) 0%, var(--accent-amber-glow, #D48C44) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Divider between Logo and Space Selector */
.header-left space-selector {
  position: relative;
  padding-left: var(--spacing-md, 16px);
}

.header-left space-selector::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  
  width: 1px;
  height: 24px;
  
  background: var(--color-border, rgba(230, 184, 125, 0.2));
}

/* ============================================
   RIGHT SECTION - USER & ACTIONS
   ============================================ */

.header-right {
  display: flex;
  align-items: center;
  gap: var(--spacing-md, 16px);
}

/* User Info */
.user-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.user-greeting {
  font-size: var(--font-size-xs, 12px);
  color: var(--color-text-muted, #666);
}

.user-name {
  font-size: var(--font-size-base, 16px);
  font-weight: 600;
  color: var(--color-primary, #E6B87D);
}

/* Header Buttons */
.header-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs, 4px);
  
  padding: var(--spacing-xs, 4px) var(--spacing-sm, 8px);
  
  background: transparent;
  border: 1px solid var(--color-border, rgba(230, 184, 125, 0.2));
  border-radius: var(--radius-md, 8px);
  
  color: var(--color-text, #ffffff);
  font-family: inherit;
  font-size: var(--font-size-sm, 14px);
  text-decoration: none;
  
  cursor: pointer;
  
  transition: all 0.2s ease;
}

.header-btn:hover {
  background: rgba(230, 184, 125, 0.1);
  border-color: var(--color-primary, #E6B87D);
}

.header-logout-btn:hover {
  background: rgba(245, 87, 108, 0.1);
  border-color: #f5576c;
  color: #f5576c;
}

.btn-icon {
  font-size: 16px;
}

.btn-text {
  /* Hidden on mobile, shown on desktop */
}

/* ============================================
   THEME TOGGLE BUTTON (V3.1)
   ============================================ */

.header-theme-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 18px;
  transition: all 0.3s ease;
}

.header-theme-btn:hover {
  background: var(--v3-accent-bg, rgba(20, 184, 184, 0.15));
  border-color: var(--v3-accent, #14B8B8);
  transform: rotate(15deg);
}

.header-theme-btn .btn-icon {
  line-height: 1;
}

/* Light mode adjustments for header */
[data-v3-mode="light"] .app-header,
[data-theme="light"] .app-header {
  background: var(--v3-bg-secondary, #FFF8F0);
  border-bottom-color: var(--v3-border, rgba(0, 0, 0, 0.1));
}

[data-v3-mode="light"] .header-btn,
[data-theme="light"] .header-btn {
  color: var(--v3-text-primary, #1A1A1A);
  border-color: var(--v3-border, rgba(0, 0, 0, 0.1));
}

[data-v3-mode="light"] .header-btn:hover,
[data-theme="light"] .header-btn:hover {
  background: rgba(20, 184, 184, 0.1);
  border-color: var(--v3-accent, #14B8B8);
}

[data-v3-mode="light"] .logo,
[data-theme="light"] .logo {
  color: var(--v3-text-primary, #1A1A1A);
}

[data-v3-mode="light"] .header-search-bar,
[data-theme="light"] .header-search-bar {
  background: var(--v3-bg-card, #FFFFFF);
  border-color: var(--v3-border, rgba(0, 0, 0, 0.1));
  color: var(--v3-text-primary, #1A1A1A);
}

[data-v3-mode="light"] .header-search-bar .search-bar-text,
[data-theme="light"] .header-search-bar .search-bar-text {
  color: var(--v3-text-muted, rgba(0, 0, 0, 0.45));
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
  .app-header {
    padding: var(--spacing-sm, 8px) var(--spacing-md, 16px);
  }
  
  .header-left {
    gap: var(--spacing-sm, 8px);
  }
  
  .logo {
    font-size: var(--font-size-xl, 20px);
  }
  
  /* Hide logo text on small screens */
  .logo-text {
    display: none;
  }
  
  /* Space selector divider */
  .header-left space-selector::before {
    display: none;
  }
  
  .header-left space-selector {
    padding-left: 0;
  }
}

@media (max-width: 640px) {
  .user-info {
    display: none;
  }

  .header-btn .btn-text {
    display: none;
  }

  .header-btn {
    padding: var(--spacing-xs, 4px);
  }

  .btn-icon {
    font-size: 18px;
  }
}

/* ============================================
   HELP BUTTON (NEU v6.0)
   ============================================ */

.header-help-btn {
  background: rgba(100, 149, 237, 0.1);
  border-color: rgba(100, 149, 237, 0.3);
}

.header-help-btn:hover {
  background: rgba(100, 149, 237, 0.2);
  border-color: cornflowerblue;
}

/* ============================================
   HELP MODAL (NEU v6.0)
   ============================================ */

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}

.help-modal.hidden {
  display: none;
}

.help-modal--open {
  opacity: 1;
  visibility: visible;
}

.help-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.help-modal__content {
  position: relative;
  background: var(--color-bg-elevated, #1f1f23);
  border: 1px solid var(--color-border, rgba(230, 184, 125, 0.2));
  border-radius: 16px;
  max-width: 480px;
  width: 92%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  transform: scale(0.95) translateY(10px);
  transition: transform 0.25s ease;
}

.help-modal--open .help-modal__content {
  transform: scale(1) translateY(0);
}

.help-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border, rgba(230, 184, 125, 0.15));
}

.help-modal__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--color-primary, #E6B87D);
}

.help-modal__close {
  background: transparent;
  border: none;
  font-size: 28px;
  color: var(--color-text-muted, #888);
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color 0.2s;
}

.help-modal__close:hover {
  color: var(--color-text, #fff);
}

.help-modal__body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.help-modal__footer {
  padding: 12px 20px;
  border-top: 1px solid var(--color-border, rgba(230, 184, 125, 0.15));
  text-align: center;
}

.help-modal__version {
  font-size: 12px;
  color: var(--color-text-muted, #666);
}

/* ============================================
   HELP ACCORDION
   ============================================ */

.help-accordion {
  display: flex;
  flex-direction: column;
}

.help-accordion__item {
  border-bottom: 1px solid var(--color-border, rgba(230, 184, 125, 0.1));
}

.help-accordion__item:last-child {
  border-bottom: none;
}

.help-accordion__header {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 20px;
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.2s;
}

.help-accordion__header:hover {
  background: rgba(230, 184, 125, 0.05);
}

.help-accordion__icon {
  font-size: 18px;
  flex-shrink: 0;
}

.help-accordion__title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text, #fff);
}

.help-accordion__arrow {
  font-size: 12px;
  color: var(--color-text-muted, #888);
  transition: transform 0.2s;
}

.help-accordion__item--open .help-accordion__arrow {
  transform: rotate(180deg);
}

.help-accordion__content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 20px 0 50px;
}

.help-accordion__item--open .help-accordion__content {
  max-height: 400px;
  padding: 0 20px 16px 50px;
}

.help-accordion__content p {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: var(--color-text-secondary, #aaa);
  line-height: 1.5;
}

.help-accordion__content ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.help-accordion__content li {
  padding: 6px 0;
  font-size: 14px;
  color: var(--color-text-secondary, #aaa);
  line-height: 1.4;
}

.help-accordion__content li strong {
  color: var(--color-text, #fff);
}

/* Shortcuts Grid */
.help-shortcuts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.help-shortcut {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--color-text-secondary, #aaa);
}

.help-shortcut kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 24px;
  padding: 0 8px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary, #E6B87D);
}

/* ============================================
   HELP MODAL RESPONSIVE
   ============================================ */

@media (max-width: 480px) {
  .help-modal__content {
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    max-width: 100%;
  }

  .help-shortcuts-grid {
    grid-template-columns: 1fr;
  }

  .help-accordion__content {
    padding-left: 20px;
  }

  .help-accordion__item--open .help-accordion__content {
    padding-left: 20px;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .help-modal,
  .help-modal__content,
  .help-accordion__arrow,
  .help-accordion__content {
    transition: none;
  }
}

/* ============================================
   HAMBURGER MENU (NEU v7.0)
   ============================================ */

.header-hamburger {
  display: none;
  align-items: center;
  justify-content: center;

  width: 44px;
  height: 44px;

  background: transparent;
  border: none;
  border-radius: var(--radius-md, 8px);

  color: var(--color-text, #ffffff);
  font-size: 24px;

  cursor: pointer;

  transition: background 0.2s ease;
}

.header-hamburger:hover {
  background: rgba(230, 184, 125, 0.1);
}

.header-hamburger:active {
  background: rgba(230, 184, 125, 0.2);
}

/* Show hamburger on tablet and below */
@media (max-width: 1024px) {
  .header-hamburger {
    display: flex;
  }
}

/* ============================================
   HEADER CENTER SECTION (V8.0 - Wide Search)
   ============================================ */

.header-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 480px;
  margin: 0 var(--spacing-lg, 24px);
}

/* Search Bar - V8.0 Wide Search */
.header-search-bar {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm, 8px);

  width: 100%;
  padding: var(--spacing-sm, 8px) var(--spacing-md, 16px);

  background: var(--color-bg-input, rgba(255, 255, 255, 0.05));
  border: 1px solid var(--color-border, rgba(230, 184, 125, 0.2));
  border-radius: var(--radius-lg, 12px);

  color: var(--color-text-muted, #888);
  font-family: inherit;
  font-size: var(--font-size-sm, 14px);
  text-align: left;

  cursor: pointer;

  transition: all 0.2s ease;
}

.header-search-bar:hover {
  background: var(--color-bg-hover, rgba(255, 255, 255, 0.08));
  border-color: var(--color-primary, #E6B87D);
}

.header-search-bar:focus {
  outline: none;
  border-color: var(--color-primary, #E6B87D);
  box-shadow: 0 0 0 3px rgba(230, 184, 125, 0.15);
}

.search-bar-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.search-bar-text {
  flex: 1;
  color: var(--color-text-muted, #888);
}

.search-bar-shortcut {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  padding: 2px 6px;

  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm, 4px);

  font-family: system-ui, -apple-system, sans-serif;
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-muted, #888);
}

/* Admin Button - V8.0 */
.header-admin-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs, 4px);

  padding: var(--spacing-xs, 4px) var(--spacing-sm, 8px);

  background: transparent;
  border: 1px solid var(--color-border, rgba(230, 184, 125, 0.2));
  border-radius: var(--radius-md, 8px);

  color: var(--color-text, #ffffff);
  font-family: inherit;
  font-size: var(--font-size-sm, 14px);
  text-decoration: none;

  cursor: pointer;

  transition: all 0.2s ease;
}

.header-admin-btn:hover {
  background: rgba(230, 184, 125, 0.1);
  border-color: var(--color-primary, #E6B87D);
}

.header-admin-btn .btn-icon {
  font-size: 16px;
}

/* V8.0: Settings button removed - replaced by Admin link in header-right */

/* ============================================
   PROFILE DROPDOWN (NEU v7.0)
   ============================================ */

.header-profile-dropdown {
  position: relative;
}

/* V9.0: Profile button - borderless, clean */
.header-profile-btn {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm, 8px);

  padding: var(--spacing-xs, 4px);

  background: transparent;
  border: none;
  border-radius: 50%;

  cursor: pointer;

  transition: all 0.2s ease;
}

.header-profile-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}

/* Profile button with name - expanded view */
.profile-name {
  font-size: 14px;
  color: var(--color-text, #fff);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* V8.0: Profile arrow using CSS chevron instead of Unicode */
.profile-arrow {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--color-text-muted, #888);
  border-bottom: 2px solid var(--color-text-muted, #888);
  transform: rotate(45deg);
  margin-top: -3px;
  transition: transform 0.2s ease;
}

/* Arrow points up when dropdown is open */
[aria-expanded="true"] .profile-arrow {
  transform: rotate(-135deg);
  margin-top: 3px;
}

/* Hide profile name on mobile */
@media (max-width: 768px) {
  .profile-name,
  .profile-arrow {
    display: none;
  }

  .header-profile-btn {
    border-radius: 50%;
    padding: 2px;
  }
}

.profile-avatar {
  width: 36px;
  height: 36px;

  background: linear-gradient(135deg, var(--color-primary, #E6B87D) 0%, var(--accent-amber-glow, #D48C44) 100%);
  border-radius: 50%;

  display: flex;
  align-items: center;
  justify-content: center;

  color: var(--color-bg, #0a0a0a);
  font-size: var(--font-size-sm, 14px);
  font-weight: 700;
}

/* Dropdown Menu - CRITICAL FIX V3.0 */
.profile-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;

  min-width: 220px;

  background: var(--color-bg-elevated, #1f1f23);
  border: 1px solid var(--color-border, rgba(230, 184, 125, 0.2));
  border-radius: var(--radius-lg, 12px);

  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);

  transition: all 0.2s ease;

  z-index: var(--z-dropdown, 200);
}

/* Hidden state - default via .hidden class in HTML */
.profile-dropdown-menu.hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  pointer-events: none;
}

/* Visible state - when .hidden is removed */
.profile-dropdown-menu:not(.hidden) {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

/* Profile dropdown header */
.profile-dropdown-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border, rgba(230, 184, 125, 0.15));
}

.profile-dropdown-name {
  display: block;
  font-weight: 600;
  color: var(--color-text, #fff);
  margin-bottom: 2px;
}

.profile-dropdown-email {
  display: block;
  font-size: 12px;
  color: var(--color-text-muted, #888);
}

.profile-dropdown-divider {
  height: 1px;
  background: var(--color-border, rgba(230, 184, 125, 0.15));
  margin: 4px 0;
}

.profile-dropdown-logout {
  color: #f5576c !important;
}

.profile-dropdown-logout:hover {
  background: rgba(245, 87, 108, 0.1) !important;
}

.profile-dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm, 8px);

  width: 100%;
  padding: var(--spacing-sm, 8px) var(--spacing-md, 16px);

  background: transparent;
  border: none;

  color: var(--color-text, #ffffff);
  font-family: inherit;
  font-size: var(--font-size-sm, 14px);
  text-align: left;
  text-decoration: none;

  cursor: pointer;

  transition: background 0.2s ease;
}

.profile-dropdown-item:first-child {
  border-radius: var(--radius-lg, 12px) var(--radius-lg, 12px) 0 0;
}

.profile-dropdown-item:last-child {
  border-radius: 0 0 var(--radius-lg, 12px) var(--radius-lg, 12px);
}

.profile-dropdown-item:hover {
  background: rgba(230, 184, 125, 0.1);
}

.profile-dropdown-item--logout {
  border-top: 1px solid var(--color-border, rgba(230, 184, 125, 0.15));
  color: #f5576c;
}

.profile-dropdown-item--logout:hover {
  background: rgba(245, 87, 108, 0.1);
}

.profile-dropdown-item .item-icon {
  font-size: 16px;
  opacity: 0.8;
}

/* ============================================
   HEADER RESPONSIVE v8.0
   ============================================ */

@media (max-width: 768px) {
  .header-center {
    max-width: 300px;
    margin: 0 var(--spacing-sm, 8px);
  }

  .search-bar-text {
    display: none;
  }

  .header-search-bar {
    padding: var(--spacing-sm, 8px);
    justify-content: center;
  }

  .header-admin-btn .btn-text {
    display: none;
  }
}

@media (max-width: 640px) {
  .header-center {
    max-width: 200px;
  }

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

  .header-admin-btn {
    padding: var(--spacing-xs, 4px);
  }

  .profile-avatar {
    width: 32px;
    height: 32px;
    font-size: var(--font-size-xs, 12px);
  }
}

@media (max-width: 480px) {
  .header-center {
    flex: 0;
    max-width: none;
    width: 40px;
    margin: 0;
  }

  .header-search-bar {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }

  .search-bar-text,
  .search-bar-shortcut {
    display: none;
  }
}

/* ============================================
   ALL SCREENS: Space + Search together in center
   Logo left, Profile right
   ============================================ */

/* Base: Search appears right after space selector */
.header-left {
  display: flex;
  align-items: center;
  gap: var(--spacing-md, 16px);
  flex: 1;
}

.header-center {
  order: 0; /* Keep search in flow */
  margin: 0 var(--spacing-sm, 8px);
}

/* Mobile (< 640px): Compact layout */
@media (max-width: 640px) {
  .app-header {
    padding: var(--spacing-xs, 4px) var(--spacing-sm, 8px);
  }

  .header-content {
    gap: var(--spacing-xs, 4px);
  }

  .header-left {
    flex: 0 0 auto;
    gap: var(--spacing-xs, 4px);
  }

  /* Compact search icon on mobile */
  .header-center {
    flex: 0 0 auto;
    margin: 0;
  }

  .header-search-bar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
  }

  .search-bar-text,
  .search-bar-shortcut {
    display: none;
  }

  .search-bar-icon {
    font-size: 16px;
  }

  .header-right {
    flex: 0 0 auto;
  }
}

/* Tablet (641px - 900px): Medium search bar */
@media (min-width: 641px) and (max-width: 900px) {
  .header-center {
    flex: 0 1 200px;
    max-width: 200px;
    margin: 0 var(--spacing-sm, 8px);
  }

  .search-bar-text {
    display: none;
  }
}
