@use 'variables' as v;
@use 'mixins' as m;

// ─────────────────────────────────────────────
// Topbar shell
// ─────────────────────────────────────────────
.topbar {
  @include m.flex-between;
  height: v.$topbar-height;
  padding: 0 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: v.$z-topbar;
  gap: 16px;
  flex-shrink: 0;
  transition: background-color 150ms ease, border-color 150ms ease;
}

// ─────────────────────────────────────────────
// Left: hamburger + breadcrumb
// ─────────────────────────────────────────────
.topbar-left {
  @include m.flex-start;
  gap: 12px;
  min-width: 0;
}

.topbar-toggle {
  display: none;

  @include m.max-lg {
    display: flex;
  }

  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: v.$radius-md;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all v.$transition-base;
  flex-shrink: 0;
  outline: none;

  &:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
  }

  &:focus-visible {
    @include m.focus-ring;
  }

  svg { width: 20px; height: 20px; }
}

// ─────────────────────────────────────────────
// Center: Search
// ─────────────────────────────────────────────
.topbar-search {
  flex: 1;
  max-width: 460px;
  position: relative;
}

.topbar-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;

  svg { width: 18px; height: 18px; }
}

.topbar-search-input {
  width: 100%;
  height: 40px;
  padding: 0 16px 0 40px;
  border: 1px solid var(--border-color);
  border-radius: v.$radius-lg;
  font-size: v.$font-size-sm;
  color: var(--text-primary);
  background: var(--bg-hover);
  transition: all v.$transition-base;

  &::placeholder { color: var(--text-muted); }

  &:focus {
    outline: none;
    background: var(--bg-surface);
    border-color: v.$primary-border;
    @include m.focus-ring;
  }

  &::-webkit-search-cancel-button { display: none; }
}

.topbar-search-kbd {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: v.$font-size-2xs;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-hover-strong);
  border: 1px solid var(--border-color);
  border-radius: v.$radius-sm;
  padding: 2px 6px;
  pointer-events: none;
}

.topbar-search-clear {
  @include m.flex-center;
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  border-radius: v.$radius-full;
  color: var(--text-muted);
  cursor: pointer;

  &:hover { background: var(--bg-hover-strong); color: var(--text-primary); }

  svg { width: 13px; height: 13px; }
}

// ─────────────────────────────────────────────
// Search dropdown panel
// ─────────────────────────────────────────────
.topbar-search-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: v.$radius-md;
  box-shadow: v.$shadow-lg;
  max-height: 420px;
  overflow-y: auto;
  z-index: v.$z-dropdown;
  padding: 6px;
  @include m.scrollbar-thin;
}

.topbar-search-status {
  padding: 14px 10px;
  font-size: v.$font-size-sm;
  color: var(--text-muted);
  text-align: center;
}

.topbar-search-group + .topbar-search-group {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--border-color);
}

.topbar-search-group-label {
  font-size: v.$font-size-2xs;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 8px 4px;
}

.topbar-search-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: v.$radius-sm;
  font-family: v.$font-family;
  cursor: pointer;
  text-align: left;

  &.is-active,
  &:hover { background: var(--bg-hover); }

  &-label {
    font-size: v.$font-size-sm;
    font-weight: 500;
    color: var(--text-primary);
    @include m.truncate;
  }

  &-sub {
    font-size: v.$font-size-xs;
    color: var(--text-muted);
    flex-shrink: 0;
    @include m.truncate;
    max-width: 40%;
  }
}

// ─────────────────────────────────────────────
// Right: Actions
// ─────────────────────────────────────────────
.topbar-actions {
  @include m.flex-start;
  gap: 4px;
  flex-shrink: 0;
}

.topbar-icon-btn {
  @include m.flex-center;
  position: relative;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: v.$radius-md;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all v.$transition-base;
  outline: none;

  &:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
  }

  &:focus-visible {
    @include m.focus-ring;
  }

  svg { width: 20px; height: 20px; }
}

.topbar-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 8px;
  height: 8px;
  background: v.$danger;
  border-radius: v.$radius-full;
  border: 2px solid var(--bg-surface);
}

.topbar-lang {
  @include m.flex-start;
  gap: 6px;
  padding: 0 10px;
  height: 34px;
  border: 1px solid var(--border-color);
  border-radius: v.$radius;
  background: transparent;
  font-size: v.$font-size-sm;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background v.$transition-base;

  &:hover { background: var(--bg-hover); }

  svg { width: 14px; height: 14px; }
}

.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--border-color);
  margin: 0 4px;
}

// ─────────────────────────────────────────────
// Mobile responsive adjustments
// ─────────────────────────────────────────────
@media (max-width: 640px) {
  .topbar {
    padding: 0 10px;
    gap: 8px;
  }

  .topbar-search-kbd {
    display: none;
  }

  .topbar-search-panel {
    position: fixed;
    top: 58px;
    left: 12px;
    right: 12px;
    width: auto;
    max-width: calc(100vw - 24px);
    z-index: 20000;
  }

  .topbar-lang,
  .topbar-help-btn,
  .topbar-divider {
    display: none !important;
  }
}
