@media (max-width: 768px) {
  header {
    padding: 0.5rem 0.75rem;
    height: 56px;
    min-height: 56px;
    overflow: visible;
    position: relative;
    z-index: 1001;
    gap: 0.5rem;
  }
  
  /* Reorder elements for mobile: LOGO > SEARCHBAR > PROFILE > NOTIFICATION > TOKENS > SETTINGS */
  .header-left {
    order: 1;
    flex-shrink: 0;
    min-width: auto;
  }
  
  .logo img {
    height: 36px;
    width: auto;
    flex-shrink: 0;
  }
  
  .logo-text {
    display: none;
  }
  
  /* Search container - positioned between logo and profile */
  .search-container {
    margin: 0;
    justify-content: flex-end;
    flex: 1;
    min-width: 0;
    max-width: none;
    order: 2;
    position: static;
  }
  
  /* Search icon button - matches other icons */
  .search-icon-mobile {
    display: flex;
    font-size: 1.1rem;
    padding: 0;
    background: var(--bubble-bg, #f1f1f1);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    color: var(--nav-link, #666);
    border: 1px solid var(--border, #e0e0e0);
    flex-shrink: 0;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 1003;
  }
  
  .search-icon-mobile:hover {
    background: var(--bubble-hover-bg, #e9e9e9);
    color: var(--nav-link-hover, #333);
    transform: scale(1.05);
  }
  
  /* FIXED: Mobile search bar - proper dark mode support */
  .search-bar {
    position: fixed;
    left: 0;
    right: 0;
    top: 56px;
    width: 100vw;
    margin: 0;
    padding: 0.875rem;
    background: var(--header-bg, #ffffff);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    z-index: 1002;
    display: none;
    border-bottom: 1px solid var(--border, #e0e0e0);
    animation: slideDown 0.3s ease-out;
    box-sizing: border-box;
    overflow: visible;
  }
  
  .search-bar.active {
    display: block;
  }
  
  @keyframes slideDown {
    from {
      opacity: 0;
      transform: translateY(-10px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  /* FIXED: Search input wrapper - proper dark mode colors */
  .search-input-wrapper {
    position: relative;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: visible;
  }
  
  .search-input-wrapper input {
    width: 100%;
    padding: 0.875rem 3rem 0.875rem 2.75rem;
    font-size: 1rem;
    border-radius: 12px;
    border: 2px solid var(--search-border, #ddd);
    background: var(--search-bg, #fff);
    color: var(--text, #333);
    box-sizing: border-box;
    transition: all 0.2s ease;
  }
  
  .search-input-wrapper input:focus {
    outline: none;
    border-color: var(--accent-color, #8B5CF6);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
    background: var(--search-bg, #fff);
  }
  
  .search-input-wrapper input::placeholder {
    color: var(--text-muted, #999);
  }
  
  .search-icon {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.1rem;
    color: var(--search-icon, #666);
    pointer-events: none;
  }
  
  .clear-button {
    position: absolute;
    right: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.1rem;
    color: var(--search-icon, #666);
    cursor: pointer;
    background: transparent;
    border: none;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
  }
  
  .clear-button:hover {
    color: var(--nav-link-hover, #333);
    transform: translateY(-50%) scale(1.1);
  }
  
  /* FIXED: Mobile search suggestions positioning */
  .search-suggestions {
    position: fixed !important;
    top: 112px !important;
    left: 15px !important;
    right: 15px !important;
    width: calc(100vw - 30px) !important;
    max-height: 60vh !important;
    z-index: 1003 !important;
    background: var(--dropdown-bg, #ffffff) !important;
    border: 1px solid var(--border, #ddd) !important;
    border-radius: 8px !important;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2) !important;
    overflow-y: auto !important;
  }
  
  /* Header actions - optimized layout with proper order */
  .header-actions {
    gap: 0.5rem;
    min-width: 0;
    flex-shrink: 0;
    justify-content: flex-end;
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    order: 3;
  }
  
  /* Profile with background color */
  .profile-pic-mini {
    background-color: var(--accent-color, #8B5CF6);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    border: 1px solid var(--border, #e0e0e0);
    flex-shrink: 0;
    order: 1; /* PROFILE comes first in the actions section */
  }
  
  .profile-name {
    display: none;
  }
  
  /* Notifications */
  .notifications {
    order: 2; /* NOTIFICATION comes after profile */
  }
  
  .notification-bell {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bubble-bg, #f1f1f1);
    border: 1px solid var(--border, #e0e0e0);
    transition: all 0.2s ease;
    flex-shrink: 0;
    cursor: pointer;
  }
  
  /* Wallet dropdown */
  .wallet-dropdown {
    order: 3; /* TOKENS comes after notification */
  }
  
  .wallet-toggle {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    border-radius: 20px;
    flex-shrink: 0;
    white-space: nowrap;
    transition: all 0.2s ease;
    background: var(--bubble-bg, #f1f1f1);
    border: 1px solid var(--border, #e0e0e0);
  }
  
  .wallet-toggle:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  }
  
  .wallet-toggle .token-count {
    font-size: 0.8rem;
    font-weight: 700;
  }
  
  .token-icon {
    font-size: 0.9rem;
  }
  
  /* Settings dropdown */
  .settings-dropdown {
    order: 4; /* SETTINGS comes last */
  }
  
  .settings-toggle {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bubble-bg, #f1f1f1);
    border: 1px solid var(--border, #e0e0e0);
    transition: all 0.2s ease;
    flex-shrink: 0;
    cursor: pointer;
  }
  
  /* Dark mode toggle */
  .dark-mode-toggle {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bubble-bg, #f1f1f1);
    border: 1px solid var(--border, #e0e0e0);
    transition: all 0.2s ease;
    flex-shrink: 0;
    cursor: pointer;
  }
  
  /* Hover effects for all icons */
  .notification-bell:hover,
  .settings-toggle:hover,
  .dark-mode-toggle:hover,
  .profile-pic-mini:hover,
  .wallet-toggle:hover {
    background: var(--bubble-hover-bg, #e9e9e9);
    transform: scale(1.05);
    border-color: var(--nav-link-hover, #999);
  }
  
  /* Notification badge positioning */
  .notification-bell {
    position: relative;
  }
  
  .notification-count {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ef4444;
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.15rem 0.35rem;
    border-radius: 10px;
    min-width: 16px;
    text-align: center;
    border: 2px solid var(--header-bg, #fff);
  }
  
  /* Auth links - clean and compact */
  .auth-links {
    gap: 0.5rem;
    display: flex;
    align-items: center;
    flex-shrink: 0;
  }
  
  .auth-links a {
    padding: 0.5rem 0.875rem;
    font-size: 0.875rem;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s ease;
    flex-shrink: 0;
    white-space: nowrap;
    text-decoration: none;
  }
  
  .auth-links .login-link {
    color: var(--nav-link, #666);
    border: 1px solid var(--border, #e0e0e0);
    background: var(--bubble-bg, #f8f9fa);
  }
  
  .auth-links .login-link:hover {
    background: var(--bubble-hover-bg, #e9ecef);
    border-color: var(--nav-link-hover, #495057);
    color: var(--nav-link-hover, #333);
  }
  
  .auth-links .signup-link {
    background: var(--accent-color, #8B5CF6);
    color: white;
    border: 1px solid var(--accent-color, #8B5CF6);
  }
  
  .auth-links .signup-link:hover {
    background: var(--accent-color-hover, #7c3aed);
    border-color: var(--accent-color-hover, #7c3aed);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
  }
  
  /* Mobile search overlay for better UX */
  .search-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1001;
    backdrop-filter: none;
  }
  
  .search-overlay.active {
    display: block;
  }
  
  @keyframes fadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }
}

/* Extra small devices optimization */
@media (max-width: 380px) {
  header {
    padding: 0.4rem 0.5rem;
  }
  
  .header-actions {
    gap: 0.35rem;
  }
  
  .auth-links {
    gap: 0.35rem;
  }
  
  .auth-links a {
    padding: 0.45rem 0.7rem;
    font-size: 0.8rem;
  }
  
  .wallet-toggle {
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
  }
  
  .profile-pic-mini,
  .notification-bell,
  .settings-toggle,
  .dark-mode-toggle,
  .search-icon-mobile {
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }
  
  .search-bar {
    padding: 0.75rem;
  }
  
  .search-input-wrapper input {
    padding: 0.75rem 2.75rem 0.75rem 2.5rem;
    font-size: 0.95rem;
  }
}

@media (max-width: 480px) {
  header {
    padding: 0.3rem 0.5rem;
    height: 50px;
    gap: 0.3rem;
  }
  
  .logo img {
    height: 32px;
  }
  
  /* Beautiful icon-only auth buttons */
  .auth-links .login-link span,
  .auth-links .signup-link span {
    display: none;
  }
  
  .auth-links .login-link,
  .auth-links .signup-link {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 0;
    position: relative;
    transition: all 0.2s ease;
  }
  
  /* Clean, modern icons using Font Awesome */
  .auth-links .login-link::after,
  .auth-links .signup-link::after {
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .auth-links .login-link::after {
    content: "\f2f6";
    color: var(--nav-link, #666);
  }
  
  .auth-links .signup-link::after {
    content: "\f234";
    color: white;
  }
  
  /* Remove the old ::before content to avoid duplicates */
  .auth-links .login-link:before,
  .auth-links .signup-link:before {
    content: none;
  }
  
  /* Hide wallet text on smallest screens */
  .wallet-toggle .wallet-text {
    display: none;
  }
  
  .wallet-toggle {
    padding: 0.3rem 0.5rem;
    min-width: 36px;
    justify-content: center;
  }
  
  /* Even more compact icons */
  .profile-pic-mini,
  .notification-bell,
  .settings-toggle,
  .dark-mode-toggle,
  .search-icon-mobile {
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }
  
  .header-actions {
    gap: 0.3rem;
  }
  
  /* Ensure header elements don't wrap */
  .header-left,
  .search-container,
  .header-actions {
    flex-shrink: 0;
  }
  
  /* Force header to be a single row */
  header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    overflow: hidden;
  }
}

/* Improved animations */
@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Overlay for search - better UX */
.search-overlay {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.15);
  z-index: 999;
  display: none;
  animation: fadeIn 0.3s ease-out;
  backdrop-filter: none;
}

.search-bar.active ~ .search-overlay {
  display: block;
}

/* Prevent body scroll when search is open */
body.search-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
}