/**
 * Prompt Studio Header - Complete Layout Fix
 * Fixes: Logo stacking, quality score sizing, language switcher positioning
 */

/* ===================================
   HEADER CONTAINER - MORE SPACE
   =================================== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px; /* More vertical padding */
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  min-height: 80px; /* More height for breathing room */
  height: auto;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  flex-wrap: nowrap;
  gap: 20px; /* More gap between elements */
  overflow: visible; /* Allow dropdowns to show */
}

/* ===================================
   LEFT SIDE: Sidebar Toggle + Logo
   =================================== */
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.sidebar-toggle-header {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.sidebar-toggle-header:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.05);
}

/* Logo - Stacked Layout */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.logo-icon {
  font-size: 28px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-text {
  display: flex;
  flex-direction: column; /* Stack vertically */
  line-height: 1.2;
  gap: 2px;
}

.logo-text span {
  font-size: 16px;
  font-weight: 700;
  color: white;
  white-space: nowrap;
}

.logo-text small {
  font-size: 11px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
}

/* ===================================
   CENTER/RIGHT: Header Controls
   =================================== */
.header-controls {
  display: flex;
  align-items: center;
  gap: 20px; /* More space between groups */
  flex: 1;
  min-width: 0; /* Allow shrinking */
  overflow: visible;
  justify-content: space-between; /* Space out primary and secondary groups */
}

/* Primary Group: Action Buttons + Menus */
.header-primary-group {
  display: flex;
  align-items: center;
  gap: 16px; /* Reduced from 20px to prevent overlap */
  flex-shrink: 1; /* Allow shrinking if needed */
  min-width: 0;
  overflow: visible;
  flex-wrap: wrap; /* Allow wrapping if needed */
}

.header-primary-actions {
  display: flex;
  align-items: center;
  gap: 10px; /* Reduced from 14px for tighter spacing */
  flex-wrap: nowrap;
  flex-shrink: 1;
  min-width: 0;
}

.header-primary-actions > button,
.header-primary-actions > .generate-versions-container {
  padding: 8px 12px; /* Reduced from 8px 14px for more compact buttons */
  font-size: 13px;
  white-space: nowrap;
  flex-shrink: 0;
  margin: 0 !important;
}

.header-primary-actions > .generate-versions-container {
  margin-right: 0 !important; /* Removed extra margin */
}

/* Ensure button text doesn't duplicate */
.header-primary-actions > button > span,
.header-primary-actions > .generate-versions-container > button > span {
  display: inline;
  margin-left: 6px;
}

.header-menus {
  display: flex;
  align-items: center;
  gap: 10px; /* Reduced from 16px for tighter menu spacing */
  flex-shrink: 1; /* Allow shrinking */
}

/* Make header menu buttons more compact */
.header-menus .btn {
  padding: 8px 12px !important; /* More compact than default 10px 16px */
  font-size: 13px !important;
  gap: 6px !important;
}

.header-menus .btn i {
  font-size: 12px;
}

.header-menus .btn span {
  font-size: 13px;
}

/* ===================================
   SECONDARY GROUP: Mode + Language + User (Quality is absolute)
   POSITIONED AT FAR RIGHT
   =================================== */
.header-secondary-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0 !important; /* Never shrink */
  overflow: visible;
  position: relative;
  margin-left: auto !important; /* Always push to far right */
  padding-right: 80px; /* Reduced from 100px - space for absolute quality score */
}

/* Quality Score - TOP RIGHT CORNER ABSOLUTE POSITIONING */
.quality-score-container {
  position: absolute;
  top: 8px; /* Slightly below header top */
  right: 24px; /* Match header padding */
  z-index: 1001;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* Header Quality Score - Compact percentage badge */
.header-secondary-group .quality-score-container,
.header-secondary-group .quality-score {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.header-secondary-group .quality-score {
  font-size: 13px !important; /* Readable percentage */
  font-weight: 700 !important; /* Bold */
  padding: 6px 14px !important; /* Compact padding */
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2) 0%, rgba(220, 38, 38, 0.2) 100%) !important;
  border: 1.5px solid rgba(239, 68, 68, 0.5) !important;
  border-radius: 8px !important;
  color: white !important;
  white-space: nowrap !important;
  min-width: 50px !important; /* Minimum width for badge */
  height: auto !important;
  transition: all 0.3s ease !important;
  line-height: 1.4 !important;
  margin: 0 !important;
  position: relative !important;
}

.header-secondary-group .quality-score:hover {
  transform: translateY(-1px) !important;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4) !important;
}

/* Quality Value - Just the percentage */
.header-secondary-group .quality-value {
  font-weight: 700 !important;
  font-size: 13px !important;
  color: #ffffff !important;
  display: inline !important;
  margin: 0 !important;
  padding: 0 !important;
  background: none !important;
  border: none !important;
}

/* Hide any icons or labels in header quality score */
.header-secondary-group .quality-score i,
.header-secondary-group .quality-score .quality-label,
.header-secondary-group .quality-score .quality-label-text {
  display: none !important;
}

/* Quality Score Categories - Color Coding (Header Specific) */
.header-secondary-group .quality-score.excellent {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2) 0%, rgba(5, 150, 105, 0.2) 100%) !important;
  border-color: rgba(16, 185, 129, 0.5) !important;
}

.header-secondary-group .quality-score.excellent:hover {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.3) 0%, rgba(5, 150, 105, 0.3) 100%) !important;
  border-color: rgba(16, 185, 129, 0.7) !important;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3) !important;
}

.header-secondary-group .quality-score.good {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2) 0%, rgba(37, 99, 235, 0.2) 100%) !important;
  border-color: rgba(59, 130, 246, 0.5) !important;
}

.header-secondary-group .quality-score.good:hover {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.3) 0%, rgba(37, 99, 235, 0.3) 100%) !important;
  border-color: rgba(59, 130, 246, 0.7) !important;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3) !important;
}

.header-secondary-group .quality-score.fair {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(217, 119, 6, 0.2) 100%) !important;
  border-color: rgba(245, 158, 11, 0.5) !important;
}

.header-secondary-group .quality-score.fair:hover {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.3) 0%, rgba(217, 119, 6, 0.3) 100%) !important;
  border-color: rgba(245, 158, 11, 0.7) !important;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3) !important;
}

.header-secondary-group .quality-score.poor {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2) 0%, rgba(220, 38, 38, 0.2) 100%) !important;
  border-color: rgba(239, 68, 68, 0.5) !important;
}

.header-secondary-group .quality-score.poor:hover {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.3) 0%, rgba(220, 38, 38, 0.3) 100%) !important;
  border-color: rgba(239, 68, 68, 0.7) !important;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3) !important;
}

/* Mode Toggle - Compact */
.mode-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.1);
  padding: 6px 12px;
  border-radius: 8px;
}

.mode-toggle-label,
.mode-toggle-target {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.9);
  white-space: nowrap;
}

.toggle-switch {
  width: 48px;
  height: 24px;
  background: rgba(255, 255, 255, 0.3);
  border: none;
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background 0.3s ease;
}

.toggle-slider {
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.3s ease;
}

.toggle-switch.active .toggle-slider {
  transform: translateX(24px);
}

/* Language Switcher - Proper Sizing */
#languageSwitcher {
  flex-shrink: 0;
  overflow: visible;
  position: relative;
  z-index: 100;
}

#languageSwitcher .language-btn {
  padding: 6px 12px;
  font-size: 13px;
  white-space: nowrap;
  min-width: auto;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
}

#languageSwitcher .language-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

#languageSwitcher .language-btn .flag {
  font-size: 18px;
}

#languageSwitcher .language-btn .lang-name {
  font-size: 12px;
}

/* User Menu - Compact */
.user-menu {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.3s ease;
  flex-shrink: 0;
  position: relative;
}

.user-menu:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.05);
}

.user-menu > i {
  font-size: 22px;
  color: white;
}

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

/* Large Screens (1400px+) - All Elements Visible */
@media (min-width: 1400px) {
  .header {
    padding: 12px 32px;
  }

  .header-controls {
    max-width: calc(100% - 200px - 400px); /* More space for secondary group */
  }
}

/* Medium Screens (1024px - 1399px) - Compact Mode */
@media (max-width: 1399px) {
  .header {
    padding: 10px 20px;
    gap: 12px;
  }

  .header-controls {
    max-width: calc(100% - 180px - 350px);
  }

  .header-primary-actions {
    gap: 10px; /* Reduce gap on smaller screens */
  }

  .header-primary-actions > button {
    padding: 6px 12px;
    font-size: 12px;
  }

  .header-primary-actions > button i {
    margin-right: 4px;
  }

  .header-menus {
    gap: 10px;
    margin-left: 10px;
  }

  .quality-score {
    font-size: 11px !important;
    padding: 5px 10px !important;
  }

  .mode-toggle-label {
    display: none; /* Hide "Switch to:" label */
  }
}

/* Small Tablets (768px - 1023px) - Hide Less Important Items */
@media (max-width: 1023px) {
  .header {
    padding: 8px 16px;
    gap: 8px;
  }

  .logo-text span {
    font-size: 14px;
  }

  .logo-text small {
    font-size: 10px;
  }

  /* Hide button text, keep icons */
  .header-primary-actions > button span {
    display: none;
  }

  .header-primary-actions > button i {
    margin-right: 0;
    font-size: 16px;
  }

  .header-primary-actions > button {
    padding: 8px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Compact menus */
  .header-menus .btn span {
    display: none;
  }

  .header-menus .btn {
    padding: 8px;
    width: 36px;
    height: 36px;
  }

  /* Hide mode toggle labels */
  .mode-toggle-label,
  .mode-toggle-target {
    display: none;
  }

  /* Language switcher - flag only */
  #languageSwitcher .language-btn .lang-name {
    display: none;
  }

  #languageSwitcher .language-btn {
    padding: 6px 10px;
  }
}

/* Mobile (< 768px) - Minimal UI */
@media (max-width: 767px) {
  .header {
    padding: 8px 12px;
    gap: 8px;
    min-height: 56px;
  }

  .logo-icon {
    font-size: 24px;
  }

  .logo-text span {
    font-size: 13px;
  }

  .logo-text small {
    font-size: 9px;
  }

  /* Hide quality score on mobile */
  .quality-score-container {
    display: none;
  }

  /* Smaller controls */
  .mode-toggle {
    padding: 4px 8px;
  }

  .toggle-switch {
    width: 40px;
    height: 20px;
  }

  .toggle-slider {
    width: 16px;
    height: 16px;
  }

  .toggle-switch.active .toggle-slider {
    transform: translateX(20px);
  }

  .user-menu {
    width: 32px;
    height: 32px;
  }

  .user-menu > i {
    font-size: 20px;
  }

  /* Minimal action buttons */
  .header-primary-actions {
    gap: 4px;
  }

  .header-primary-actions > button,
  .header-menus .btn {
    width: 32px;
    height: 32px;
    padding: 6px;
  }

  /* Language switcher compact */
  #languageSwitcher .language-btn {
    padding: 6px 8px;
  }

  #languageSwitcher .language-btn .flag {
    font-size: 16px;
  }
}

/* Extra Small Mobile (< 480px) - Ultra Compact */
@media (max-width: 479px) {
  .header {
    padding: 6px 8px;
  }

  /* Only show essential buttons */
  .header-primary-actions > button:not(:first-child):not(:last-child) {
    display: none;
  }

  .header-menus .dropdown:not(:first-child) {
    display: none;
  }

  .header-secondary-group {
    gap: 6px;
  }
}

/* ===================================
   DARK MODE SUPPORT
   =================================== */
@media (prefers-color-scheme: dark) {
  .header {
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  }

  .quality-score,
  .mode-toggle,
  #languageSwitcher .language-btn {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
  }

  .quality-score:hover,
  #languageSwitcher .language-btn:hover {
    background: rgba(255, 255, 255, 0.15);
  }
}

/* ===================================
   FIX: Prevent Layout Issues
   =================================== */

/* Ensure no overflow causes scrollbars */
.header,
.header-controls,
.header-primary-group,
.header-secondary-group {
  overflow: visible !important;
}

/* Dropdowns should overlay, not push content */
.dropdown-menu,
.user-dropdown,
.language-menu {
  position: absolute !important;
  z-index: 1001 !important;
}

/* Ensure flex items don't break layout */
.header > * {
  flex-shrink: 0;
}

.header-controls {
  flex-shrink: 1;
  min-width: 0;
}
