:root {
  --search-bg: #ffffff;
  --search-border: #e2e8f0;
  --search-text: #0f172a;
  --search-muted: #64748b;
  --search-shadow: 0 12px 30px -22px rgba(15, 23, 42, 0.45);
}

.global-search-wrapper {
  position: relative;
  width: 100%;
  flex: 1 1 420px;
  max-width: 480px;
}

.global-search-input {
  width: 100%;
  border: 1px solid var(--search-border);
  border-radius: 14px;
  padding: 10px 14px;
  background: var(--search-bg);
  color: var(--search-text);
  font-size: 14px;
  outline: none;
}

.global-search-input:focus {
  border-color: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.25);
}

.global-search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--search-bg);
  border: 1px solid var(--search-border);
  border-radius: 14px;
  box-shadow: var(--search-shadow);
  max-height: 320px;
  overflow-y: auto;
  z-index: 200;
}

.global-search-results.hidden {
  display: none;
}

.global-search-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.global-search-item:hover,
.global-search-item.active {
  background: #f1f5f9;
}

.global-search-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--search-text);
}

.global-search-path {
  font-size: 12px;
  color: var(--search-muted);
  direction: ltr;
}

.global-search-fixed {
  position: fixed;
  top: var(--header-height, 4rem); /* sits below the header, not on top of it */
  left: 0;
  right: 0;
  width: 100%;
  z-index: 45; /* below header (60) and sidebar (50) — search bar is in the content zone */
  background: transparent;
  backdrop-filter: none;
  border-bottom: none;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

@media (min-width: 768px) {
  .global-search-fixed {
    /* Uses shared sidebar width token; if unavailable, 16rem fallback preserves default desktop sidebar clearance. */
    right: var(--nav-sidebar-width, 16rem);
    width: auto;
  }
}

.global-search-row {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

#global-search-slot.global-search-slot {
  width: 100%;
}

body.has-global-search {
  scroll-margin-top: 72px;
}

/* Compensate for fixed search bar in the main content area only —
   the header position must NOT change when the search bar is injected */
body.has-global-search #main-view {
  padding-top: 62px;
}

.page-search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  border: 1px solid var(--search-border);
  border-radius: 14px;
  padding: 10px 14px;
  margin-bottom: 16px;
  box-shadow: var(--search-shadow);
}

.page-search-bar input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  color: var(--search-text);
  background: transparent;
}

.page-search-clear {
  border: none;
  background: #e2e8f0;
  color: #334155;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.table-toolbar input {
  flex: 1;
  border: 1px solid var(--search-border);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 13px;
}

.table-sortable th {
  cursor: pointer;
  user-select: none;
}

.table-sort-indicator {
  font-size: 10px;
  margin-right: 6px;
  color: #94a3b8;
}

@media (max-width: 640px) {
  .global-search-wrapper {
    max-width: 100%;
  }

  .global-search-fixed,
  .global-search-row {
    justify-content: flex-start;
    gap: 10px;
  }
}
