/* ============================================================
   TADWERA DESIGN SYSTEM — header.css
   Shared Header — Always LTR, Never changes with language
   ============================================================ */

.ds-header {
  /* Critical: direction is always LTR regardless of page language */
  direction: ltr !important;

  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  z-index: var(--z-sticky);

  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  gap: var(--space-4);

  background: hsl(var(--bg-dash-sidebar));
  border-bottom: var(--border-width) solid hsl(var(--border-muted));

  transition: background var(--duration-normal) var(--ease-default),
              border-color var(--duration-normal) var(--ease-default);
}

/* ── Logo — Always Left ──────────────────────────────────── */
.ds-header-logo {
  display: flex;
  align-items: center;
  gap: 0;
  text-decoration: none;
  flex-shrink: 0;
  opacity: 0.9;
  transition: opacity var(--duration-fast) var(--ease-default);
}

.ds-header-logo:hover {
  opacity: 1;
}

.ds-header-logo-img-wrap {
  display: block;
  line-height: 0;
}

.ds-header-logo-img {
  height: 32px;
  width: auto;
  max-height: 32px;
  display: block;
  object-fit: contain;
}

.dark-logo {
  display: block;
}

.light-logo {
  display: none;
}

[data-theme="light"] .dark-logo {
  display: none;
}

[data-theme="light"] .light-logo {
  display: block;
}

[data-theme="dark"] .dark-logo {
  display: block;
}

[data-theme="dark"] .light-logo {
  display: none;
}

[data-theme="extra-dark"] .dark-logo {
  display: block;
}

[data-theme="extra-dark"] .light-logo {
  display: none;
}

/* ── Nav — Center ────────────────────────────────────────── */
.ds-header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: 1;
  justify-content: center;
}

.ds-nav-link {
  display: inline-flex;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: hsl(var(--foreground-light));
  text-decoration: none;
  border-radius: var(--radius-md);
  border: var(--border-width) solid transparent;
  transition: color var(--duration-fast) var(--ease-default),
              background var(--duration-fast) var(--ease-default);
  white-space: nowrap;
}

.ds-nav-link:hover {
  color: hsl(var(--foreground));
  background: hsl(var(--bg-surface-200));
  text-decoration: none;
}

.ds-nav-link.active {
  color: hsl(var(--foreground));
  background: hsl(var(--bg-surface-200));
  border-color: hsl(var(--border-muted));
}

/* ── Tools — Always Right ────────────────────────────────── */
.ds-header-tools {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-shrink: 0;
}

/* Search button */
.ds-search-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 32px;
  padding: 0 var(--space-3);
  background: hsl(var(--bg-control));
  border: var(--border-width) solid hsl(var(--border-control));
  border-radius: var(--radius-md);
  color: hsl(var(--foreground-muted));
  font-size: var(--text-xs);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
  white-space: nowrap;
}
.ds-search-btn:hover {
  border-color: hsl(var(--border-strong));
  color: hsl(var(--foreground));
}
.ds-search-btn .search-kbd {
  background: hsl(var(--bg-surface-200));
  border: var(--border-width) solid hsl(var(--border-muted));
  border-radius: var(--radius-xs);
  padding: 0 var(--space-1);
  font-size: 10px;
  color: hsl(var(--foreground-muted));
  font-family: var(--font-mono);
}

/* Icon buttons (theme + language) */
.ds-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: var(--border-width) solid transparent;
  background: transparent;
  color: hsl(var(--foreground-muted));
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
  position: relative;
  flex-shrink: 0;
}
.ds-icon-btn:hover {
  background: hsl(var(--bg-surface-200));
  color: hsl(var(--foreground));
  border-color: hsl(var(--border-muted));
}
.ds-icon-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Burger — mobile only */
.ds-burger-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  border: var(--border-width) solid hsl(var(--border));
  background: transparent;
  color: hsl(var(--foreground-light));
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
}
.ds-burger-btn:hover { background: hsl(var(--bg-surface-200)); }
.ds-burger-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; }

/* ── Overlay + scroll lock (used by burger drawers) ───────── */
.ds-drawer-overlay {
  position: fixed;
  inset: 0;
  background: hsl(var(--bg-overlay) / 0.55);
  z-index: 198;
  display: block;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  touch-action: manipulation;
}
.ds-drawer-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.ds-scroll-locked { overflow: hidden; }

/* ── Landing: mobile nav drawer (slide fully off-screen when closed) ─
   LTR: panel on the right → closed = translateX(100%) (off to the right).
   RTL: panel on the left → closed = translateX(-100%) (off to the left).
   Open: translateX(0). Use [dir] + .open/.active so closed state never loses
   to a weaker rule (fixes drawer jumping to the wrong position on close).
   ─────────────────────────────────────────────────────────────────── */
.lp-mobile-nav,
.sidebar-drawer.mobile-nav {
  position: fixed;
  top: 0;
  bottom: 0;
  width: min(280px, 88vw);
  max-width: 100%;
  height: 100vh;
  height: 100dvh;
  background: hsl(var(--bg-dialog));
  box-shadow: var(--shadow-xl);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  will-change: transform;
}

[dir="ltr"] .lp-mobile-nav,
[dir="ltr"] .sidebar-drawer.mobile-nav {
  left: auto;
  right: 0;
  border-inline-start: var(--border-width) solid hsl(var(--border));
  transform: translateX(100%);
}

[dir="rtl"] .lp-mobile-nav,
[dir="rtl"] .sidebar-drawer.mobile-nav {
  left: 0;
  right: auto;
  border-inline-end: var(--border-width) solid hsl(var(--border));
  border-inline-start: none;
  transform: translateX(-100%);
}

[dir="ltr"] .lp-mobile-nav.open,
[dir="ltr"] .lp-mobile-nav.active,
[dir="ltr"] .sidebar-drawer.mobile-nav.open,
[dir="ltr"] .sidebar-drawer.mobile-nav.active,
[dir="rtl"] .lp-mobile-nav.open,
[dir="rtl"] .lp-mobile-nav.active,
[dir="rtl"] .sidebar-drawer.mobile-nav.open,
[dir="rtl"] .sidebar-drawer.mobile-nav.active {
  transform: translateX(0);
}

.lp-mobile-nav-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: var(--border-width) solid hsl(var(--border-muted));
}
.lp-mobile-nav-title {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: hsl(var(--foreground));
}
.lp-mobile-nav-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: var(--border-width) solid hsl(var(--border));
  background: transparent;
  color: hsl(var(--foreground-muted));
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-default),
              color var(--duration-fast) var(--ease-default);
}
.lp-mobile-nav-close:hover { background: hsl(var(--bg-surface-200)); color: hsl(var(--foreground)); }

.lp-mobile-nav-body { padding: var(--space-3); overflow: auto; }
.lp-mobile-nav-links {
  display: flex !important;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: var(--space-1);
}
.lp-mobile-nav-link {
  justify-content: flex-start;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  border: var(--border-width) solid hsl(var(--border-muted));
  background: hsl(var(--bg-surface-100));
}
.lp-mobile-nav-link.active {
  border-color: hsl(var(--brand) / 0.35);
  background: hsl(var(--brand) / 0.08);
}

/* ── Header Dropdown ─────────────────────────────────────── */
.ds-header-dropdown {
  position: relative;
}

.ds-header-dropdown-menu {
  position: absolute;
  top: calc(100% + var(--space-2));
  right: 0;
  min-width: 160px;
  background: hsl(var(--bg-dialog));
  border: var(--border-width) solid hsl(var(--border));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
  z-index: var(--z-dropdown);
  display: none;
  animation: headerDropIn var(--duration-normal) var(--ease-out);
}
.ds-header-dropdown-menu.open { display: block; }

@keyframes headerDropIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ds-header-dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  color: hsl(var(--foreground-light));
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: start;
  transition: background var(--duration-fast) var(--ease-default),
              color var(--duration-fast) var(--ease-default);
  white-space: nowrap;
}
.ds-header-dropdown-item:hover {
  background: hsl(var(--bg-surface-200));
  color: hsl(var(--foreground));
}
.ds-header-dropdown-item.active {
  color: hsl(var(--brand));
  background: hsl(var(--brand-200));
  font-weight: var(--weight-medium);
}
.ds-header-dropdown-item .item-check {
  margin-inline-start: auto;
  width: 14px; height: 14px;
  color: hsl(var(--brand));
  opacity: 0;
}
.ds-header-dropdown-item.active .item-check { opacity: 1; }

.ds-header-dropdown-label {
  padding: var(--space-2) var(--space-3) var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: hsl(var(--foreground-muted));
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
}

.ds-header-dropdown-separator {
  height: 1px;
  background: hsl(var(--border-muted));
  margin: var(--space-1) 0;
}

/* ── Search Overlay ──────────────────────────────────────── */
.search-overlay {
  position: fixed;
  inset: 0;
  background: hsl(var(--bg-overlay) / 0.6);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
}
.search-overlay.open { display: flex; }

.search-modal {
  width: 100%;
  max-width: 560px;
  background: hsl(var(--bg-dialog));
  border: var(--border-width) solid hsl(var(--border));
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: searchIn var(--duration-normal) var(--ease-out);
}
@keyframes searchIn {
  from { opacity: 0; transform: translateY(-12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-width) solid hsl(var(--border-muted));
}
.search-input-wrapper svg {
  width: 18px; height: 18px;
  color: hsl(var(--foreground-muted));
  flex-shrink: 0;
  stroke: currentColor; fill: none;
  stroke-width: 1.5; stroke-linecap: round;
}
.search-input-field {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: var(--text-base);
  font-family: var(--font-sans);
  color: hsl(var(--foreground));
  line-height: 1.5;
}
.search-input-field::placeholder { color: hsl(var(--foreground-muted)); }
.search-close-btn {
  font-size: var(--text-xs);
  color: hsl(var(--foreground-muted));
  background: hsl(var(--bg-surface-200));
  border: var(--border-width) solid hsl(var(--border-muted));
  border-radius: var(--radius-xs);
  padding: 2px var(--space-2);
  cursor: pointer;
  font-family: var(--font-mono);
  transition: all var(--duration-fast);
}
.search-results {
  max-height: 360px;
  overflow-y: auto;
  padding: var(--space-2);
}
.search-result-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background var(--duration-fast);
  text-decoration: none;
}
.search-result-item:hover, .search-result-item.selected {
  background: hsl(var(--bg-surface-200));
}
.search-result-icon {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  background: hsl(var(--bg-surface-300));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: hsl(var(--foreground-muted));
}
.search-result-title { font-size: var(--text-sm); font-weight: var(--weight-medium); color: hsl(var(--foreground)); }
.search-result-section { font-size: var(--text-xs); color: hsl(var(--foreground-muted)); }
.search-empty {
  padding: var(--space-10) var(--space-6);
  text-align: center;
  color: hsl(var(--foreground-muted));
  font-size: var(--text-sm);
}

/* ── Sidebar Nav (docs) ──────────────────────────────────── */
.sidebar-nav { padding: 0 var(--space-3); }
.sidebar-nav-section { margin-bottom: var(--space-6); }
.sidebar-nav-section-title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: hsl(var(--foreground-muted));
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  padding: 0 var(--space-3) var(--space-2);
}
.sidebar-nav-link {
  display: block;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: hsl(var(--foreground-light));
  text-decoration: none;
  border-radius: var(--radius-md);
  border-inline-start: 2px solid transparent;
  transition: color var(--duration-fast), background var(--duration-fast),
              border-color var(--duration-fast);
  line-height: var(--leading-snug);
}
.sidebar-nav-link:hover {
  color: hsl(var(--foreground-light));
  background: hsl(var(--bg-surface-200));
  text-decoration: none;
}
.sidebar-nav-link.active {
  color: hsl(var(--brand));
  background: hsl(var(--brand-200));
  border-inline-start-color: hsl(var(--brand));
  font-weight: var(--weight-medium);
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1024px) {
  .ds-header-nav { display: none; }
  .ds-burger-btn { display: flex; }
}

@media (max-width: 768px) {
  .ds-header { padding: 0 var(--space-4); }
  .ds-search-btn .search-text { display: none; }
  .ds-search-btn .search-kbd { display: none; }
  .ds-search-btn { width: 32px; padding: 0; justify-content: center; }
}
