/* ==========================================================================
   Global Search Component Styles
   Extracted from dashboard.css for reuse across all pages.

   Usage:
     <link rel="stylesheet" href="/css/search.css">

   Requires CSS custom properties (design tokens) to be defined on :root.
   Falls back to sensible defaults if variables are missing.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Container
   -------------------------------------------------------------------------- */
.nav-search-container {
  flex-shrink: 0;
}

.global-search {
  position: relative;
  width: 220px;
}

/* --------------------------------------------------------------------------
   Search icon (magnifying glass inside the input)
   -------------------------------------------------------------------------- */
.global-search .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted, #94a3b8);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Search input
   -------------------------------------------------------------------------- */
.global-search .search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: var(--border-radius, 12px);
  font-size: 0.875rem;
  background: var(--bg-hover, #f1f5f9);
  color: var(--text-primary, #0f172a);
  transition: all 0.2s;
}

.global-search .search-input:focus {
  outline: none;
  border-color: var(--color-primary, #e87722);
  background: var(--bg-card, #ffffff);
  box-shadow: 0 0 0 3px var(--color-primary-light, #fde4d0);
}

.global-search .search-input::placeholder {
  color: var(--text-muted, #94a3b8);
}

/* --------------------------------------------------------------------------
   Results dropdown
   -------------------------------------------------------------------------- */
.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  min-width: 360px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--bg-card, #ffffff);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: var(--border-radius, 12px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  z-index: 1000;
}

/* --------------------------------------------------------------------------
   Loading indicator
   -------------------------------------------------------------------------- */
.search-results-loading {
  padding: 16px;
  text-align: center;
  color: var(--text-secondary, #64748b);
}

/* --------------------------------------------------------------------------
   Result groups
   -------------------------------------------------------------------------- */
.search-results-group {
  border-bottom: 1px solid var(--border-color, #e2e8f0);
}

.search-results-group:last-child {
  border-bottom: none;
}

.search-results-group-title,
.search-results-group-header {
  padding: 8px 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted, #94a3b8);
  background: var(--bg-hover, #f1f5f9);
}

/* --------------------------------------------------------------------------
   Individual result item
   -------------------------------------------------------------------------- */
.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--text-primary, #0f172a);
  text-decoration: none;
  transition: background 0.15s;
  cursor: pointer;
}

.search-result-item:hover {
  background: var(--bg-hover, #f1f5f9);
}

/* --------------------------------------------------------------------------
   Result icon (circular badge)
   -------------------------------------------------------------------------- */
.search-result-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-hover, #f1f5f9);
  color: var(--text-secondary, #64748b);
}

.search-result-icon.commitment-icon { background: rgba(232, 119, 34, 0.1); color: #e87722; }
.search-result-icon.person-icon     { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; }
.search-result-icon.meeting-icon    { background: rgba(16, 185, 129, 0.1); color: #10b981; }

/* --------------------------------------------------------------------------
   Result content (title + meta)
   -------------------------------------------------------------------------- */
.search-result-content {
  flex: 1;
  min-width: 0;
}

.search-result-title {
  font-weight: 500;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-title mark {
  background: rgba(255, 214, 0, 0.4);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

.search-result-meta {
  font-size: 0.75rem;
  color: var(--text-secondary, #64748b);
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-result-meta mark {
  background: rgba(255, 214, 0, 0.4);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

.search-result-who {
  font-weight: 500;
}

.search-result-deadline {
  color: var(--text-muted, #94a3b8);
}

.search-result-type {
  color: var(--text-muted, #94a3b8);
  font-size: 0.7rem;
  text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   Status badge (commitments)
   -------------------------------------------------------------------------- */
.search-result-status {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
}

.search-result-status.status-open {
  background: rgba(232, 119, 34, 0.1);
  color: #e87722;
}

.search-result-status.status-fulfilled {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
}

.search-result-status.status-missed {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

/* --------------------------------------------------------------------------
   Reliability score badge (people)
   -------------------------------------------------------------------------- */
.search-result-score {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
}

.search-result-score.score-high   { color: #10b981; }
.search-result-score.score-medium { color: #f59e0b; }
.search-result-score.score-low    { color: #ef4444; }

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */
.search-results-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-secondary, #64748b);
}

/* --------------------------------------------------------------------------
   Meeting search card enhancements (snippet, speakers, source badge)
   -------------------------------------------------------------------------- */
.search-result-meeting-card {
  flex-wrap: wrap;
}

.search-result-meeting-card .search-result-content {
  flex: 1;
  min-width: 0;
}

.search-result-snippet {
  font-size: 0.75rem;
  color: var(--text-secondary, #64748b);
  line-height: 1.4;
  margin-top: 4px;
  max-height: 2.8em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.search-result-snippet mark {
  background: rgba(255, 214, 0, 0.4);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

.search-result-source-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 500;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
  letter-spacing: 0.3px;
}

.search-result-speakers {
  font-size: 0.7rem;
  color: var(--text-muted, #94a3b8);
  font-style: italic;
}

.search-result-commit-count {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  border-radius: 12px;
  background: rgba(232, 119, 34, 0.1);
  color: #e87722;
  font-size: 0.7rem;
  font-weight: 600;
}

/* ==========================================================================
   Highlight flash animation (scrollToCommitment)
   ========================================================================== */
@keyframes highlight-flash {
  0%, 100% { background-color: transparent; }
  50%      { background-color: rgba(255, 214, 0, 0.3); }
}

.highlight-flash {
  animation: highlight-flash 0.5s ease-in-out 3;
}

/* ==========================================================================
   Dark mode overrides
   ========================================================================== */
[data-theme="dark"] .global-search .search-input {
  background: var(--bg-hover, #334155);
  border-color: var(--border-color, #334155);
  color: var(--text-primary, #f1f5f9);
}

[data-theme="dark"] .global-search .search-input:focus {
  background: var(--bg-card, #1e293b);
  border-color: var(--color-primary, #e87722);
  box-shadow: 0 0 0 3px rgba(232, 119, 34, 0.25);
}

[data-theme="dark"] .global-search .search-input::placeholder {
  color: var(--text-muted, #64748b);
}

[data-theme="dark"] .global-search .search-icon {
  color: var(--text-muted, #64748b);
}

[data-theme="dark"] .search-results {
  background: var(--bg-card, #1e293b);
  border-color: var(--border-color, #334155);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .search-results-group {
  border-bottom-color: var(--border-color, #334155);
}

[data-theme="dark"] .search-results-group-title,
[data-theme="dark"] .search-results-group-header {
  color: var(--text-muted, #64748b);
  background: var(--bg-hover, #334155);
}

[data-theme="dark"] .search-result-item {
  color: var(--text-primary, #f1f5f9);
}

[data-theme="dark"] .search-result-item:hover {
  background: var(--bg-hover, #334155);
}

[data-theme="dark"] .search-result-title mark {
  background: rgba(255, 214, 0, 0.25);
}

[data-theme="dark"] .search-result-meta mark {
  background: rgba(255, 214, 0, 0.25);
}

[data-theme="dark"] .search-result-meta {
  color: var(--text-secondary, #94a3b8);
}

[data-theme="dark"] .search-result-deadline {
  color: var(--text-muted, #64748b);
}

[data-theme="dark"] .search-result-type {
  color: var(--text-muted, #64748b);
}

[data-theme="dark"] .search-results-loading {
  color: var(--text-secondary, #94a3b8);
}

[data-theme="dark"] .search-results-empty {
  color: var(--text-secondary, #94a3b8);
}

[data-theme="dark"] .search-result-icon {
  background: var(--bg-hover, #334155);
  color: var(--text-secondary, #94a3b8);
}

/* Colored icons keep their colors in dark mode */
[data-theme="dark"] .search-result-icon.commitment-icon { background: rgba(232, 119, 34, 0.15); color: #f97316; }
[data-theme="dark"] .search-result-icon.person-icon     { background: rgba(139, 92, 246, 0.15); color: #a78bfa; }
[data-theme="dark"] .search-result-icon.meeting-icon    { background: rgba(16, 185, 129, 0.15); color: #34d399; }

/* Status badges in dark mode — slightly brighter for readability */
[data-theme="dark"] .search-result-status.status-open      { background: rgba(232, 119, 34, 0.15); color: #f97316; }
[data-theme="dark"] .search-result-status.status-fulfilled  { background: rgba(16, 185, 129, 0.15); color: #34d399; }
[data-theme="dark"] .search-result-status.status-missed     { background: rgba(239, 68, 68, 0.15); color: #f87171; }

/* Score badges in dark mode */
[data-theme="dark"] .search-result-score.score-high   { color: #34d399; }
[data-theme="dark"] .search-result-score.score-medium { color: #fbbf24; }
[data-theme="dark"] .search-result-score.score-low    { color: #f87171; }

/* Meeting search enhancements in dark mode */
[data-theme="dark"] .search-result-snippet {
  color: var(--text-secondary, #94a3b8);
}

[data-theme="dark"] .search-result-snippet mark {
  background: rgba(255, 214, 0, 0.25);
}

[data-theme="dark"] .search-result-source-badge {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

[data-theme="dark"] .search-result-speakers {
  color: var(--text-muted, #64748b);
}

[data-theme="dark"] .search-result-commit-count {
  background: rgba(232, 119, 34, 0.15);
  color: #f97316;
}

/* Highlight flash in dark mode */
[data-theme="dark"] .highlight-flash {
  animation: highlight-flash-dark 0.5s ease-in-out 3;
}

@keyframes highlight-flash-dark {
  0%, 100% { background-color: transparent; }
  50%      { background-color: rgba(255, 214, 0, 0.15); }
}

/* ==========================================================================
   Responsive breakpoints
   ========================================================================== */

/* Tablet and below: shrink the search input */
@media (max-width: 768px) {
  .global-search {
    width: 180px;
  }

  .search-results {
    min-width: 300px;
    /* Anchor to the right edge of the input so it doesn't overflow viewport */
    left: auto;
    right: 0;
  }
}

/* Mobile: full-width search when the nav allows it */
@media (max-width: 480px) {
  .global-search {
    width: 100%;
  }

  .search-results {
    min-width: 0;
    width: 100%;
    left: 0;
    right: 0;
    max-height: 60vh;
  }

  .search-result-item {
    padding: 8px 10px;
    gap: 8px;
  }

  .search-result-icon {
    width: 24px;
    height: 24px;
  }

  .search-result-icon svg {
    width: 12px;
    height: 12px;
  }

  .search-result-title {
    font-size: 0.875rem;
  }

  .search-result-meta {
    font-size: 0.7rem;
  }
}
