.header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 var(--theme-space-4);
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--theme-bg-tertiary);
  box-shadow: var(--theme-shadow-sm);
}

.header-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--theme-space-2);
}

.header-logo {
  display: inline-flex;
  align-items: center;
  color: var(--theme-color-primary);
  cursor: pointer;
}

.header-beta-badge {
  padding: 2px var(--theme-space-2);
  font-size: var(--theme-font-xs);
  font-weight: var(--theme-font-weight-semibold);
  color: var(--theme-color-primary);
  background: var(--theme-bg-secondary);
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-full);
  white-space: nowrap;
}

@media (max-width: 480px) {
  .header-beta-badge {
    display: none;
  }
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--theme-space-1);
}

.header-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--theme-color-primary);
  pointer-events: none;
  animation: header-hint-nudge 1.2s ease-in-out infinite;
}

@keyframes header-hint-nudge {
  0%, 100% { transform: translateX(0); opacity: 0.55; }
  50% { transform: translateX(4px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .header-hint {
    animation: none;
  }
}

.header-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--theme-radius-md);
  color: var(--theme-text-primary);
  transition: background 120ms ease;
}

.header-toggle:hover {
  background: var(--theme-bg-tertiary);
}

.header-menu {
  position: absolute;
  top: calc(100% + var(--theme-space-2));
  right: var(--theme-space-4);
  min-width: 260px;
  padding: var(--theme-space-3);
  background: var(--theme-surface-raised);
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-md);
  box-shadow: var(--theme-shadow-lg);
  z-index: var(--theme-z-dropdown);
}

.header-menu[hidden] {
  display: none;
}

.header-menu-section + .header-menu-section {
  margin-top: var(--theme-space-3);
  padding-top: var(--theme-space-3);
  border-top: 1px solid var(--theme-border-subtle);
}

.header-menu-label {
  margin-bottom: var(--theme-space-2);
  font-size: var(--theme-font-xs);
  font-weight: var(--theme-font-weight-semibold);
  color: var(--theme-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.header-menu-row {
  display: flex;
  gap: var(--theme-space-2);
  flex-wrap: wrap;
}

.header-menu-option {
  display: inline-flex;
  align-items: center;
  gap: var(--theme-space-2);
  padding: var(--theme-space-2) var(--theme-space-3);
  font-size: var(--theme-font-sm);
  color: var(--theme-text-primary);
  background: var(--theme-bg-secondary);
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-sm);
  transition: background 120ms ease, border-color 120ms ease;
}

.header-menu-option:hover {
  background: var(--theme-bg-tertiary);
}

.header-menu-option.is-active {
  background: var(--theme-color-primary);
  color: var(--theme-text-inverse);
  border-color: var(--theme-color-primary);
}

.header-menu-langs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--theme-space-1);
}

.header-menu-lang {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--theme-space-2) var(--theme-space-1);
  font-size: var(--theme-font-xs);
  color: var(--theme-text-primary);
  background: var(--theme-bg-secondary);
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-sm);
  transition: background 120ms ease, border-color 120ms ease;
  cursor: pointer;
  min-width: 0;
}

.header-menu-lang:hover {
  background: var(--theme-bg-tertiary);
}

.header-menu-lang.is-active {
  background: var(--theme-color-primary);
  color: var(--theme-text-inverse);
  border-color: var(--theme-color-primary);
}

.header-menu-lang-code {
  font-size: var(--theme-font-xs);
  font-weight: var(--theme-font-weight-semibold);
  line-height: 1;
}

.header-menu-lang-name {
  font-size: 9px;
  line-height: 1;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.header-menu-action {
  display: flex;
  align-items: center;
  gap: var(--theme-space-2);
  width: 100%;
  padding: var(--theme-space-2) var(--theme-space-3);
  font-size: var(--theme-font-sm);
  color: var(--theme-text-primary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--theme-radius-sm);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.header-menu-action:hover {
  background: var(--theme-bg-secondary);
  border-color: var(--theme-border-subtle);
}

.header-menu-action[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}

.header-menu-action + .header-menu-action {
  margin-top: var(--theme-space-1);
}

.header-user {
  display: flex;
  align-items: center;
  gap: var(--theme-space-2);
  width: 100%;
  padding: var(--theme-space-2) var(--theme-space-3);
  font-size: var(--theme-font-sm);
  color: var(--theme-text-primary);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--theme-radius-md, 8px);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background 150ms, border-color 150ms;
}

.header-user:hover {
  background: var(--theme-bg-tertiary, #eeeeea);
}

.header-user:hover .header-user-name {
  text-decoration: underline;
}

.header-user--guest {
  color: var(--theme-text-secondary);
}

.header-user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--theme-radius-full);
  overflow: hidden;
  background: var(--theme-color-primary);
  color: var(--theme-text-inverse);
  font-size: var(--theme-font-xs);
  font-weight: var(--theme-font-weight-semibold);
  flex-shrink: 0;
}

.header-user--guest .header-user-avatar {
  background: var(--theme-bg-secondary);
  color: var(--theme-text-secondary);
  border: 1px solid var(--theme-border-subtle);
}

.header-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.header-user-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
