/*
 * Kapable Platform — Shared Header
 * Uses --kp-* tokens from kapable-theme.css exclusively.
 * Height: 44px. Designed to work across all app surfaces.
 */

.kp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 44px;
  background: var(--kp-surface);
  border-bottom: 1px solid var(--kp-border);
  font-family: var(--kp-font);
  position: relative;
  z-index: 100;
  flex-shrink: 0;
}

/* ── Left: brand + app name ── */
.kp-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.kp-header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--kp-text);
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  transition: color 0.15s;
}
.kp-header-brand:hover {
  text-decoration: none;
  color: var(--kp-accent);
}
.kp-header-brand img {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  flex-shrink: 0;
}
.kp-header-mark {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: block;
}
/* Wordmark sizing in the header context (register rules live in kapable-theme.css) */
.kp-header-brand .kp-wordmark {
  font-size: 14px;
}

.kp-header-sep {
  color: var(--kp-text-muted);
  font-weight: 300;
  font-size: 16px;
  user-select: none;
  opacity: 0.5;
}

.kp-header-app {
  display: inline-flex;
  align-items: center;
  min-width: 24px;
  min-height: 24px;
  color: var(--kp-text-dim);
  font-weight: 500;
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
a.kp-header-app:hover,
a.kp-header-app:focus-visible {
  color: var(--kp-accent);
  text-decoration: none;
}

/* ── Right: actions ── */
.kp-header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Icon button (theme toggle, chat toggle) ── */
.kp-header-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: none;
  border: 1px solid transparent;
  color: var(--kp-text-dim);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  position: relative;
  padding: 0;
}
.kp-header-icon-btn:hover {
  background: var(--kp-surface-hi);
  border-color: var(--kp-border);
  color: var(--kp-text);
}
.kp-header-icon-btn svg {
  width: 16px;
  height: 16px;
}

/* Chat badge in header */
.kp-header-chat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--kp-danger);
  display: none;
}
.kp-header-chat-badge.visible {
  display: block;
}

/* ── User button ── */
.kp-header-user-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 4px;
  border-radius: 6px;
  background: none;
  border: 1px solid transparent;
  color: var(--kp-text-dim);
  font-size: 13px;
  cursor: pointer;
  font-family: var(--kp-font);
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.kp-header-user-btn:hover {
  background: var(--kp-surface-hi);
  border-color: var(--kp-border);
}
.kp-header-user-btn.open {
  background: var(--kp-surface-hi);
  border-color: var(--kp-border);
}

.kp-header-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--kp-accent-bg);
  color: var(--kp-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 11px;
  flex-shrink: 0;
}

.kp-header-chevron {
  width: 12px;
  height: 12px;
  opacity: 0.5;
  transition: transform 0.15s;
}
.kp-header-user-btn.open .kp-header-chevron {
  transform: rotate(180deg);
}

/* ── Dropdown ── */
.kp-header-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--kp-surface);
  border: 1px solid var(--kp-border);
  border-radius: var(--kp-radius, 8px);
  min-width: 200px;
  box-shadow: var(--kp-shadow-lg, 0 8px 24px rgba(15, 23, 42, 0.14));
  z-index: 200;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
  /* visibility keeps the CLOSED menu out of the tab order (a11y): opacity
     alone leaves invisible items keyboard-focusable. The delayed visibility
     transition preserves the fade-out. */
  visibility: hidden;
  transition: opacity 0.15s ease-out, transform 0.15s ease-out, visibility 0s linear 0.15s;
}
.kp-header-dropdown.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  visibility: visible;
  transition-delay: 0s;
}

.kp-header-dd-section {
  padding: 10px 12px;
}
.kp-header-dd-name {
  font-weight: 600;
  font-size: 13px;
  color: var(--kp-text);
}
.kp-header-dd-email {
  font-size: 12px;
  color: var(--kp-text-dim);
  margin-top: 2px;
}
.kp-header-dd-sep {
  height: 1px;
  background: var(--kp-border);
}

.kp-header-dd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--kp-text);
  cursor: pointer;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  font-family: var(--kp-font);
  transition: background 0.1s;
}
.kp-header-dd-item:hover {
  background: var(--kp-surface-hi);
  text-decoration: none;
}
.kp-header-dd-item svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  color: var(--kp-text-dim);
}
.kp-header-dd-item.danger {
  color: var(--kp-danger);
}
.kp-header-dd-item.danger svg {
  color: var(--kp-danger);
}
.kp-header-dd-item.danger:hover {
  background: var(--kp-danger-bg);
}

/* ── Mobile ── */
@media (max-width: 600px) {
  .kp-header { padding: 0 12px; }
  .kp-header-app { display: none; }
  .kp-header-sep { display: none; }
}
