/*
 * global-search.css — workspace-wide search modal (#globalSearchPanel) and the
 * Create sidebar search launcher. Uses shared surface/border/text tokens so
 * Default, Dark, Sutra, and custom themes stay readable. Cascade position:
 * loaded with feature styles, before the responsive layer and contracts.
 */

.global-search-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Panel + card ===== */
.global-search-panel {
  position: fixed;
  inset: 0;
  z-index: 1420;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 9vh 20px 20px;
}
.global-search-panel.active { display: flex; }
.global-search-backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, #000 46%, transparent);
}
.global-search-card {
  position: relative;
  width: 100%;
  max-width: 720px;
  min-width: 0;
  padding: 14px;
  display: grid;
  gap: 8px;
  max-height: 82vh;
  overflow: hidden;
  border-radius: var(--radius);
  animation: global-search-in 140ms ease;
}
/* Search results must stay readable over editors and dense dashboards. This
   modal is intentionally solid even when the user's general card style is
   Glass or Minimal; the backdrop still provides the layered modal treatment. */
#globalSearchPanel .global-search-card {
  background: var(--bg-primary, #fff);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  border: 1px solid var(--surface-border-strong, var(--glass-border));
  box-shadow: var(--shadow-soft-lg, 0 24px 52px rgba(0, 0, 0, 0.28));
}
@keyframes global-search-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

/* ===== Input row ===== */
.global-search-inputrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 14px;
  border-radius: calc(var(--radius) - 6px);
  background: color-mix(in srgb, var(--surface-bg) 70%, transparent);
  border: 1px solid color-mix(in srgb, var(--surface-border) 80%, transparent);
}
.global-search-panel.active .global-search-inputrow:focus-within {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--surface-border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.global-search-input-icon { color: var(--text-muted); font-size: 0.95rem; flex: none; }
.global-search-field {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  font-size: 1.08rem;
  color: inherit;
  padding: 10px 0;
}
.global-search-field::placeholder { color: var(--text-muted); }
.global-search-clear,
.global-search-close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--surface-border) 70%, transparent);
  background: color-mix(in srgb, var(--surface-bg) 80%, transparent);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 120ms ease, color 120ms ease;
}
.global-search-clear:hover,
.global-search-close:hover {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: inherit;
}
.global-search-clear[hidden] { display: none; }
.global-search-kbd {
  flex: none;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border: 1px solid color-mix(in srgb, var(--surface-border) 80%, transparent);
  background: color-mix(in srgb, var(--surface-bg) 60%, transparent);
  border-radius: 6px;
  padding: 3px 7px;
  white-space: nowrap;
}

.global-search-help {
  margin: 0 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ===== Filter chips + count ===== */
.global-search-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px;
  min-width: 0;
}
.global-search-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}
.global-search-chip {
  border: 1px solid color-mix(in srgb, var(--surface-border) 80%, transparent);
  background: color-mix(in srgb, var(--surface-bg) 55%, transparent);
  color: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: 999px;
  padding: 5px 13px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.global-search-chip:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.global-search-chip.is-active {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  font-weight: 600;
}
.global-search-count {
  flex: none;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.global-search-count[hidden] { display: none; }

/* ===== Results ===== */
.global-search-results {
  overflow-y: auto;
  min-height: 120px;
  max-height: 52vh;
  padding: 2px;
  display: grid;
  gap: 4px;
  align-content: start;
}
.global-search-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  border-radius: calc(var(--radius) - 8px);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 100ms ease;
}
.global-search-item:hover,
.global-search-item.is-active {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  outline: none;
}
.global-search-item-icon {
  flex: none;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  font-size: 0.85rem;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  margin-top: 2px;
}
.global-search-icon-lock { font-size: 0.7rem; margin-left: 3px; }
.global-search-item-main {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  gap: 2px;
}
.global-search-item-typelabel {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.global-search-item-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: inherit;
  overflow-wrap: anywhere;
}
.global-search-item-sub {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.global-search-item-path {
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.global-search-item-snippet {
  font-size: 0.8rem;
  color: color-mix(in srgb, currentColor 78%, var(--text-muted));
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}
.global-search-item-snippet mark,
.global-search-item-title mark {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}
.global-search-item-locked { font-style: italic; }
.global-search-item-meta {
  flex: none;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: right;
  max-width: 130px;
  margin-top: 4px;
}
.global-search-more {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  padding: 8px 4px;
}

/* ===== Empty state ===== */
.global-search-empty {
  font-size: 0.84rem;
  color: var(--text-muted);
  padding: 26px 12px;
  text-align: center;
  display: grid;
  gap: 6px;
  justify-items: center;
}
.global-search-empty i { font-size: 1.2rem; opacity: 0.7; }
.global-search-empty p { margin: 0; }
.global-search-empty-hint { font-size: 0.76rem; opacity: 0.85; }

/* ===== Initial state: recents + quick actions ===== */
.global-search-panel-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: start;
}
.global-search-panel-block {
  border: 1px solid color-mix(in srgb, var(--surface-border) 70%, transparent);
  border-radius: calc(var(--radius) - 8px);
  padding: 10px 12px;
  background: color-mix(in srgb, var(--surface-bg) 40%, transparent);
}
.global-search-panel-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.global-search-panel-block-head i { margin-right: 4px; }
.global-search-clear-recents {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.74rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
}
.global-search-clear-recents:hover { color: inherit; background: color-mix(in srgb, var(--surface-bg) 80%, transparent); }
.global-search-recent-list,
.global-search-action-list {
  display: grid;
  gap: 2px;
}
.global-search-recent,
.global-search-action {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 0.82rem;
  text-align: left;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 100ms ease;
}
.global-search-recent i,
.global-search-action i:first-child { color: var(--text-muted); font-size: 0.78rem; width: 14px; flex: none; }
.global-search-recent:hover,
.global-search-action:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.global-search-action-caret {
  margin-left: auto;
  font-size: 0.68rem;
  color: var(--text-muted);
}
.global-search-action span { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== Footer hints ===== */
.global-search-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 6px 2px;
  border-top: 1px solid color-mix(in srgb, var(--surface-border) 60%, transparent);
  font-size: 0.72rem;
  color: var(--text-muted);
}
.global-search-footer kbd {
  font-family: inherit;
  font-size: 0.68rem;
  border: 1px solid color-mix(in srgb, var(--surface-border) 80%, transparent);
  border-radius: 5px;
  padding: 1px 5px;
  background: color-mix(in srgb, var(--surface-bg) 60%, transparent);
  margin-right: 3px;
}

/* ===== Sidebar launcher ===== */
.sidebar-search { position: relative; }
.sidebar-search-launcher {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--surface-border) 70%, transparent);
  background: color-mix(in srgb, var(--surface-bg) 55%, transparent);
  color: inherit;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.84rem;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}
.sidebar-search-launcher:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}
.sidebar-search-launcher i.fa-search { color: var(--text-muted); font-size: 0.82rem; }
.sidebar-search-launcher-label { flex: 1 1 auto; text-align: left; min-width: 0; }
.sidebar-search-kbd { font-size: 0.64rem; padding: 2px 6px; }

/* ===== Responsive ===== */
/* Phone sheet geometry (overlay root stays full-viewport; the card becomes a
   top sheet) is owned by styles/responsive/mobile.css, which loads later.
   This block only adjusts component-level behavior inside the card. */
@media (max-width: 640px) {
  .global-search-results { max-height: none; min-height: 0; }
  /* The card grid gives the results row the remaining sheet height. */
  .global-search-card { grid-template-rows: auto auto auto minmax(0, 1fr) auto; }
  .global-search-panel-columns { grid-template-columns: 1fr; }
  .global-search-item-meta { display: none; }
  .global-search-footer { display: none; }
  .global-search-kbd { display: none; }
  /* Filter row scrolls horizontally inside the card instead of stretching it. */
  .global-search-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; min-width: 0; }
  .global-search-chips::-webkit-scrollbar { display: none; }
  .global-search-chip { flex: none; }
  /* 44px primary touch targets on phones. */
  .global-search-chip { min-height: 44px; padding: 8px 16px; }
  .global-search-clear,
  .global-search-close { width: 44px; height: 44px; }
  .global-search-recent,
  .global-search-action { min-height: 44px; }
  .global-search-clear-recents { min-height: 44px; padding: 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .global-search-card { animation: none; }
  .global-search-item,
  .global-search-chip,
  .sidebar-search-launcher { transition: none; }
}
