/**
 * GRO Unified Header System v1.0
 *
 * Pixel-perfect header design for all GRO applications
 * Last updated: 2025-10-17
 *
 * Usage:
 * <link rel="stylesheet" href="[path]/gro-header.css">
 *
 * Supports: Light/Dark themes, Mobile responsive, All frameworks
 */

/* ========================================
   CSS CUSTOM PROPERTIES (Design Tokens)
   ======================================== */

:root {
  /* === Layout === */
  --gro-header-height: 56px;
  --gro-header-padding-x: 16px;
  --gro-header-padding-y: 6px;

  /* === Logo === */
  --gro-logo-size: 28px;
  --gro-logo-radius: 6px;

  /* === Brand === */
  --gro-brand-size: 16px;
  --gro-brand-weight: 700;
  --gro-brand-color: #4aa9e8;
  --gro-brand-font: 'korolev', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* === Divider === */
  --gro-divider-height: 20px;
  --gro-divider-width: 1px;

  /* === Spacing === */
  --gro-gap-xl: 16px;
  --gro-gap-lg: 12px;
  --gro-gap-md: 8px;
  --gro-gap-sm: 6px;
  --gro-gap-xs: 4px;

  /* === Typography === */
  --gro-app-indicator-size: 13px;
  --gro-nav-font-size: 13px;
  --gro-nav-font-weight: 500;
  --gro-badge-font-size: 11px;
  --gro-badge-font-weight: 500;

  /* === Nav Links === */
  --gro-nav-padding: 6px 12px;
  --gro-nav-radius: 6px;
  --gro-nav-gap: var(--gro-gap-md);

  /* === Badges === */
  --gro-badge-padding: 6px 12px;
  --gro-badge-radius: 6px;
  --gro-badge-gap: var(--gro-gap-xs);

  /* === Emoji === */
  --gro-emoji-size: 16px;

  /* === Z-Index === */
  --gro-header-z: 1000;
  --gro-nav-z: 10;

  /* === Transitions === */
  --gro-transition: all 0.2s ease;

  /* === Colors - Light Mode (Default) === */
  --gro-bg: #ffffff;
  --gro-text: #233548;
  --gro-text-muted: #7f8c8d;
  --gro-border: #ccc5ca;
  --gro-surface: #f3f0f2;
  --gro-ring: #ccc5ca;

  /* Active states */
  --gro-active-bg: rgba(37, 99, 235, 0.1);
  --gro-active-color: rgb(37, 99, 235);
  --gro-active-border: rgba(37, 99, 235, 0.3);

  /* Hover states */
  --gro-hover-bg: rgba(0, 0, 0, 0.05);
  --gro-hover-color: var(--gro-text);

  /* Status colors */
  --gro-status-connected-bg: rgba(34, 197, 94, 0.2);
  --gro-status-connected-color: rgb(34, 197, 94);
  --gro-status-connected-dot: rgb(74, 222, 128);
}

/* === Dark Mode === */
body.dark,
body[data-theme="dark"],
.dark {
  --gro-bg: #0a0a0a;
  --gro-text: #e8e8e8;
  --gro-text-muted: #888888;
  --gro-border: #2a2a2a;
  --gro-surface: #1a1a1a;
  --gro-ring: #2a2a2a;

  /* Active states - brighter in dark mode */
  --gro-active-bg: rgba(74, 169, 232, 0.2);
  --gro-active-color: rgb(96, 165, 250);
  --gro-active-border: rgba(74, 169, 232, 0.3);

  /* Hover states */
  --gro-hover-bg: rgba(255, 255, 255, 0.05);
  --gro-hover-color: var(--gro-text);
}


/* ========================================
   HEADER STRUCTURE
   ======================================== */

.gro-header {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  height: var(--gro-header-height);
  background: var(--gro-bg);
  border-bottom: 1px solid var(--gro-border);
  z-index: var(--gro-header-z);
  display: flex;
  align-items: center;
}

.gro-header__inner {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: var(--gro-header-padding-y) var(--gro-header-padding-x);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}


/* ========================================
   LEFT SECTION: BRAND
   ======================================== */

.gro-header__brand {
  display: flex;
  align-items: center;
  gap: var(--gro-gap-lg);
  flex-shrink: 0;
}

.gro-header__logo-group {
  display: flex;
  align-items: center;
  gap: var(--gro-gap-md);
}

.gro-header__logo {
  width: var(--gro-logo-size);
  height: var(--gro-logo-size);
  border-radius: var(--gro-logo-radius);
  object-fit: cover;
}

.gro-header__name {
  font-family: var(--gro-brand-font);
  font-size: var(--gro-brand-size);
  font-weight: var(--gro-brand-weight);
  color: var(--gro-brand-color);
  letter-spacing: 0.02em;
}

.gro-header__divider {
  height: var(--gro-divider-height);
  width: var(--gro-divider-width);
  background: var(--gro-ring);
  flex-shrink: 0;
}

.gro-header__app-indicator {
  display: flex;
  align-items: center;
  gap: var(--gro-gap-sm);
  color: var(--gro-text-muted);
  font-size: var(--gro-app-indicator-size);
  font-weight: var(--gro-nav-font-weight);
}

.gro-header__app-icon {
  font-size: var(--gro-emoji-size);
  line-height: 1;
}

.gro-header__app-name {
  font-size: var(--gro-app-indicator-size);
}


/* ========================================
   CENTER SECTION: NAVIGATION
   ======================================== */

.gro-header__nav {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--gro-nav-gap);
  z-index: var(--gro-nav-z);
}

/* ========================================
   RESPONSIVE: TABLET (768px-1024px)
   ======================================== */

/* On tablet, hide hamburger since full nav is visible below header */
@media (min-width: 768px) and (max-width: 1024px) {
  .gro-header__hamburger {
    display: none !important;
  }
}

/* ========================================
   RESPONSIVE: TABLET/DESKTOP BADGE ICONS
   ======================================== */

/* On medium screens (tablet to small desktop), make badges icon-only to prevent overlap */
@media (max-width: 1280px) {
  /* Hide TEXT LABELS in badges, but keep emoji icons */
  .gro-header__badge span:not(.gro-header__badge-dot):not(:first-child) {
    display: none;
  }

  /* Make badges more compact */
  .gro-header__badge {
    padding: 6px 8px !important;
    min-width: unset !important;
  }
}

/* ========================================
   RESPONSIVE: MOBILE LAYOUT
   ======================================== */

/* On mobile, nav should not be absolutely positioned */
@media (max-width: 1024px) {
  /* Reorganize header layout for mobile using grid */
  .gro-header__inner {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 8px;
    align-items: center;
    justify-content: initial !important; /* Remove space-between from desktop */
  }

  /* Brand stays on left - show logo + icon only */
  .gro-header__brand {
    grid-column: 1;
    justify-self: start;
  }

  /* Hide app name text on mobile, keep icon */
  .gro-header__app-name {
    display: none !important;
  }

  /* Nav in center - perfectly centered in the middle column */
  .gro-header__nav {
    position: static !important;
    transform: none !important;
    left: auto !important;
    grid-column: 2;
    justify-self: center !important;
    display: flex !important;
    gap: var(--gro-nav-gap);
    width: fit-content !important;
    margin: 0 auto !important;
  }

  /* Hide nav text labels on mobile, show icons only */
  .gro-header__nav-text {
    display: none !important;
  }

  /* Make nav links more compact (icon only) */
  .gro-header__nav-link {
    padding: 6px 8px !important;
    min-width: unset !important;
    gap: 0 !important;
  }

  /* Make nav icons bigger for better touch targets */
  .gro-header__nav-icon {
    font-size: 20px !important;
  }

  /* Actions on right - show ALL icons (Chat, Theme, Connected, User/Login, Hamburger) */
  .gro-header__actions {
    grid-column: 3;
    display: flex !important;
    align-items: center;
    gap: 4px !important;
  }

  /* Show ALL action items on mobile (no hiding) */
  .gro-header__actions > * {
    display: flex !important;
  }

  /* Show hamburger on mobile */
  .gro-header__hamburger {
    display: flex;
  }

  /* Tighter spacing on narrower screens */
  @media (max-width: 640px) {
    .gro-header__nav {
      gap: 2px !important;
    }

    .gro-header__nav-link {
      padding: 4px 6px !important;
    }

    .gro-header__nav-icon {
      font-size: 18px !important;
    }

    .gro-header__badge {
      padding: 4px 6px !important;
    }

    .gro-header__actions {
      gap: 2px !important;
    }
  }

  /* Even tighter on tiny screens */
  @media (max-width: 480px) {
    .gro-header__divider {
      display: none !important;
    }
  }
}

/* ========================================
   TRUE MOBILE (< 768px): Hide center nav, show ONLY hamburger menu
   ======================================== */
@media (max-width: 767px) {
  /* Simplify to 2-column grid: Brand | Actions */
  .gro-header__inner {
    grid-template-columns: auto auto !important;
  }

  /* Hide the center verb navigation completely */
  .gro-header__nav {
    display: none !important;
  }

  /* Actions move to right side */
  .gro-header__actions {
    grid-column: 2 !important;
    justify-self: end;
  }

  /* Show ONLY: Connected, Chat, Login/User, Theme, Hamburger */

  /* First, hide all badges */
  .gro-header__actions .gro-header__badge {
    display: none !important;
  }

  /* Then show specific badges we want on mobile */

  /* Connected status badge - show on mobile */
  .gro-header__badge.gro-header__badge--connected,
  .gro-header__badge#agent-status {
    display: flex !important;
  }

  /* Chat badge - show on mobile */
  .gro-header__badge[href*="chat"],
  .gro-header__badge[href*="Chat"],
  .gro-header__badge[href*="8083"] {
    display: flex !important;
  }

  /* Login/Logout/User badges - show on mobile */
  .gro-header__badge[href*="login"],
  .gro-header__badge[href*="logout"],
  .gro-header__badge[href="/login"],
  .gro-header__badge[href="/logout"] {
    display: flex !important;
  }

  /* Theme toggle - MUST show on mobile with high specificity */
  .gro-header__badge.gro-header__theme-toggle,
  #themeBadge {
    display: flex !important;
  }

  /* Hamburger - MUST show on mobile */
  .gro-header__hamburger {
    display: flex !important;
  }

  /* Hide text in badges, show ONLY emoji icons */
  /* BUT keep the theme toggle icon visible! */
  .gro-header__badge:not(.gro-header__theme-toggle) span:not(.gro-header__badge-dot):last-child {
    display: none !important;
  }

  /* Theme toggle should always show its icon */
  .gro-header__theme-toggle span,
  #themeBadge span,
  #themeIcon {
    display: inline !important;
  }

  /* Make actions tighter */
  .gro-header__actions {
    gap: 6px !important;
  }

  /* Ensure hamburger is ALWAYS visible with proper contrast */
  .gro-header__hamburger {
    opacity: 1 !important;
    visibility: visible !important;
  }

  /* Hamburger lines need strong contrast in BOTH modes */
  .gro-header__hamburger-line {
    background: var(--gro-text) !important;
    opacity: 1 !important;
  }
}

/* ========================================
   HAMBURGER FIX: Ensure visibility in BOTH light and dark modes
   ======================================== */

/* Make hamburger button more visible with subtle background */
.gro-header__hamburger {
  border: 1px solid var(--gro-border) !important;
  border-radius: 6px !important;
  padding: 8px !important;
  z-index: 10000 !important;
  position: relative !important;
}

/* Default (light mode): VERY DARK hamburger lines for maximum contrast */
.gro-header__hamburger-line {
  background: #000000 !important;
  height: 3px !important;  /* Thicker for better visibility */
}

/* Dark mode: VERY LIGHT hamburger lines for maximum contrast */
body.dark .gro-header__hamburger-line,
body[data-theme="dark"] .gro-header__hamburger-line {
  background: #ffffff !important;
  height: 3px !important;
}

.gro-header__nav-link {
  display: flex;
  align-items: center;
  gap: var(--gro-gap-xs);
  padding: var(--gro-nav-padding);
  border-radius: var(--gro-nav-radius);
  color: var(--gro-text-muted);
  text-decoration: none;
  font-size: var(--gro-nav-font-size);
  font-weight: var(--gro-nav-font-weight);
  transition: var(--gro-transition);
  cursor: pointer;
  background: transparent;
  border: none;
}

.gro-header__nav-link:hover {
  background: var(--gro-hover-bg);
  color: var(--gro-hover-color);
}

.gro-header__nav-link--active,
.gro-header__nav-link.active {
  background: var(--gro-active-bg);
  color: var(--gro-active-color);
}

.gro-header__nav-icon {
  font-size: var(--gro-emoji-size);
  line-height: 1;
}

.gro-header__nav-text {
  font-size: var(--gro-nav-font-size);
}


/* ========================================
   RIGHT SECTION: ACTIONS
   ======================================== */

.gro-header__actions {
  display: flex;
  align-items: center;
  gap: var(--gro-gap-md);
  flex-shrink: 0;
}

.gro-header__badge {
  display: flex;
  align-items: center;
  gap: var(--gro-badge-gap);
  padding: var(--gro-badge-padding);
  border-radius: var(--gro-badge-radius);
  background: transparent;
  color: var(--gro-text);
  font-size: var(--gro-badge-font-size);
  font-weight: var(--gro-badge-font-weight);
  text-decoration: none;
  cursor: pointer;
  transition: var(--gro-transition);
  border: none;
  white-space: nowrap;
}

.gro-header__badge:hover {
  background: var(--gro-hover-bg);
}

/* Connected status badge */
.gro-header__badge--connected {
  background: var(--gro-status-connected-bg);
  color: var(--gro-status-connected-color);
}

.gro-header__badge--connected .gro-header__badge-dot {
  background: var(--gro-status-connected-dot);
}

/* Disconnected status badge */
.gro-header__badge--disconnected {
  background: rgba(248, 113, 113, 0.2);
  color: rgb(248, 113, 113);
}

.gro-header__badge--disconnected .gro-header__badge-dot {
  background: rgb(248, 113, 113);
}

.gro-header__badge-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--gro-status-connected-dot);
  border-radius: 50%;
  flex-shrink: 0;
}

/* Theme toggle */
.gro-header__theme-toggle {
  cursor: pointer;
}


/* ========================================
   MOBILE HAMBURGER
   ======================================== */

.gro-header__hamburger {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 8px;
  margin-left: var(--gro-gap-md);
}

.gro-header__hamburger-line {
  width: 20px;
  height: 2px;
  background: var(--gro-text);
  border-radius: 1px;
  transition: var(--gro-transition);
}

.gro-header__hamburger[aria-expanded="true"] .gro-header__hamburger-line:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.gro-header__hamburger[aria-expanded="true"] .gro-header__hamburger-line:nth-child(2) {
  opacity: 0;
}

.gro-header__hamburger[aria-expanded="true"] .gro-header__hamburger-line:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}


/* ========================================
   MOBILE MENU
   ======================================== */

.gro-header__mobile-menu {
  display: none;
  position: fixed;
  top: 56px; /* Height of header */
  left: 0;
  right: 0;
  padding: 16px;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  max-height: calc(100vh - 56px);
  overflow-y: auto;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Light mode menu (default) */
.gro-header__mobile-menu {
  background: #ffffff;
  border-bottom: 1px solid #ccc5ca;
  color: #233548;
}

/* Dark mode menu */
body.dark .gro-header__mobile-menu,
body[data-theme="dark"] .gro-header__mobile-menu {
  background: #0a0a0a;
  border-bottom: 1px solid #2a2a2a;
  color: #e8e8e8;
}

.gro-header__mobile-menu.active {
  display: flex !important;
}

/* Light mode menu links */
.gro-header__mobile-menu a {
  padding: var(--gro-gap-md);
  color: #233548;
  text-decoration: none;
  border-radius: var(--gro-nav-radius);
  transition: var(--gro-transition);
}

/* Dark mode menu links */
body.dark .gro-header__mobile-menu a,
body[data-theme="dark"] .gro-header__mobile-menu a {
  color: #e8e8e8;
}

/* Light mode menu hover */
.gro-header__mobile-menu a:hover {
  background: rgba(0, 0, 0, 0.05);
}

/* Dark mode menu hover */
body.dark .gro-header__mobile-menu a:hover,
body[data-theme="dark"] .gro-header__mobile-menu a:hover {
  background: rgba(255, 255, 255, 0.05);
}


/* ========================================
   SECONDARY NAVIGATION (Optional)
   ======================================== */

.gro-header__secondary {
  border-top: 1px solid var(--gro-ring);
  background: var(--gro-surface);
  padding: 4px 0;
}

.gro-header__secondary-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  gap: 2px;
  padding: 0 var(--gro-header-padding-x);
  flex-wrap: wrap;
}

.gro-header__secondary-link {
  padding: 8px 14px;
  border-radius: var(--gro-nav-radius);
  text-decoration: none;
  font-size: var(--gro-nav-font-size);
  font-weight: var(--gro-nav-font-weight);
  color: var(--gro-text);
  transition: var(--gro-transition);
}

.gro-header__secondary-link:hover {
  background: var(--gro-hover-bg);
}


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

/* All mobile responsive styles are now in the main @media (max-width: 1024px) block above (around line 218) */


/* ========================================
   UTILITY CLASSES
   ======================================== */

.gro-desktop-only {
  display: block;
}

@media (max-width: 768px) {
  .gro-desktop-only {
    display: none !important;
  }
}

.gro-mobile-only {
  display: none;
}

@media (max-width: 768px) {
  .gro-mobile-only {
    display: block;
  }
}


/* ========================================
   LEGACY CLASS SUPPORT
   (For backwards compatibility during migration)
   ======================================== */

/* Map old class names to new ones */
.site-header {
  /* Legacy wrapper - just ensure it doesn't interfere */
  all: unset;
  display: block;
  width: 100%;
}

.header-inner {
  /* Alias for gro-header__inner */
}

.verb-nav {
  /* Alias for gro-header__nav */
}

.verb-link {
  /* Alias for gro-header__nav-link */
}

.selection-badge {
  /* Alias for gro-header__badge */
}

.agent-status.connected {
  /* Alias for gro-header__badge--connected */
}


/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
  .gro-header {
    position: static;
    border-bottom: 1px solid #000;
  }

  .gro-header__nav,
  .gro-header__actions {
    display: none;
  }
}


/* ========================================
   ACCESSIBILITY
   ======================================== */

/* Focus visible styles */
.gro-header__nav-link:focus-visible,
.gro-header__badge:focus-visible {
  outline: 2px solid var(--gro-brand-color);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .gro-header *,
  .gro-header *::before,
  .gro-header *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .gro-header {
    border-bottom-width: 2px;
  }

  .gro-header__nav-link--active {
    border: 2px solid var(--gro-active-color);
  }
}
