/**
 * AILYDIAN — Enterprise Developer Search Modal
 * Vercel / Linear / Raycast command palette style
 * Zero dependencies, pure CSS
 */

/* ============================================================
   KEYFRAME ANIMATIONS
   ============================================================ */

@keyframes sm-overlay-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes sm-overlay-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes sm-modal-in {
  from {
    opacity: 0;
    transform: translateX(-50%) scale(0.96) translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) scale(1) translateY(0);
  }
}

@keyframes sm-modal-out {
  from {
    opacity: 1;
    transform: translateX(-50%) scale(1) translateY(0);
  }
  to {
    opacity: 0;
    transform: translateX(-50%) scale(0.96) translateY(-8px);
  }
}

@keyframes sm-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes sm-pulse-dot {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

/* ============================================================
   OVERLAY
   ============================================================ */

#search-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 99990;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  padding-bottom: 5vh;
  padding-left: 1rem;
  padding-right: 1rem;
  animation-duration: 180ms;
  animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  animation-fill-mode: both;
}

#search-modal-overlay.sm-visible {
  display: flex;
  animation-name: sm-overlay-in;
}

#search-modal-overlay.sm-closing {
  animation-name: sm-overlay-out;
  pointer-events: none;
}

/* ============================================================
   MODAL CONTAINER
   ============================================================ */

#search-modal {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;

  /* Glassmorphism dark background */
  background: rgba(12, 13, 18, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 24px 64px rgba(0, 0, 0, 0.7),
    0 8px 24px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);

  /* Position trick for left: 50% + translateX(-50%) animation */
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 12vh;

  animation-name: sm-modal-in;
  animation-duration: 220ms;
  animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
  animation-fill-mode: both;
}

#search-modal-overlay.sm-closing #search-modal {
  animation-name: sm-modal-out;
  animation-duration: 160ms;
  animation-timing-function: cubic-bezier(0.4, 0, 1, 1);
}

/* ============================================================
   HEADER
   ============================================================ */

.search-modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.search-modal-header-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

#search-modal-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #f1f5f9;
  font-size: 17px;
  font-weight: 400;
  font-family: inherit;
  line-height: 1.4;
  caret-color: #6e84ff;
  min-width: 0;
}

#search-modal-input::placeholder {
  color: rgba(255, 255, 255, 0.25);
  font-weight: 400;
}

.search-modal-esc-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.4);
  font-family: ui-monospace, 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition:
    background 0.15s ease,
    color 0.15s ease;
  user-select: none;
}

.search-modal-esc-badge:hover {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.7);
}

/* ============================================================
   BODY (SCROLL AREA)
   ============================================================ */

.search-modal-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  min-height: 0;
}

/* Custom scrollbar */
.search-modal-body::-webkit-scrollbar {
  width: 5px;
}

.search-modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.search-modal-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px;
}

.search-modal-body::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.search-modal-body {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}

/* ============================================================
   RECENT SEARCHES (EMPTY STATE)
   ============================================================ */

.search-modal-recent {
  padding: 8px;
}

.search-modal-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 6px 12px;
  gap: 8px;
}

.search-modal-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.3);
}

.search-modal-clear-recent {
  font-size: 11px;
  font-weight: 500;
  color: rgba(110, 132, 255, 0.7);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 0;
  transition: color 0.15s ease;
  font-family: inherit;
}

.search-modal-clear-recent:hover {
  color: #6e84ff;
}

/* ============================================================
   RESULT GROUPS
   ============================================================ */

.search-modal-results {
  padding: 8px;
}

.search-modal-group {
  margin-bottom: 4px;
}

.search-modal-group:last-child {
  margin-bottom: 0;
}

.search-modal-group-label {
  padding: 8px 12px 5px 12px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.28);
  user-select: none;
}

/* ============================================================
   RESULT ITEMS
   ============================================================ */

.search-modal-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition:
    background 0.12s ease,
    border-color 0.12s ease;
  border: 1px solid transparent;
  position: relative;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.search-modal-item:hover,
.search-modal-item.sm-active {
  background: rgba(110, 132, 255, 0.08);
  border-color: rgba(110, 132, 255, 0.18);
}

.search-modal-item.sm-active {
  background: rgba(110, 132, 255, 0.1);
  border-color: rgba(110, 132, 255, 0.22);
}

/* Icon container */
.search-modal-item-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 18px;
  line-height: 1;
  transition: background 0.12s ease;
}

.search-modal-item:hover .search-modal-item-icon,
.search-modal-item.sm-active .search-modal-item-icon {
  background: rgba(110, 132, 255, 0.1);
  border-color: rgba(110, 132, 255, 0.2);
}

/* Text content */
.search-modal-item-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-modal-item-title {
  font-size: 14px;
  font-weight: 500;
  color: #e8ecf0;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-modal-item.sm-active .search-modal-item-title {
  color: #ffffff;
}

.search-modal-item-desc {
  font-size: 12.5px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.38);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Arrow indicator on active */
.search-modal-item-arrow {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  color: rgba(110, 132, 255, 0.5);
  opacity: 0;
  transition: opacity 0.12s ease;
}

.search-modal-item:hover .search-modal-item-arrow,
.search-modal-item.sm-active .search-modal-item-arrow {
  opacity: 1;
}

/* Highlight marks */
.search-modal-item-title mark,
.search-modal-item-desc mark {
  background: transparent;
  color: #6e84ff;
  font-weight: 600;
}

/* ============================================================
   EMPTY / NO RESULTS STATE
   ============================================================ */

.search-modal-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 12px;
  text-align: center;
}

.search-modal-empty-icon {
  width: 40px;
  height: 40px;
  color: rgba(255, 255, 255, 0.15);
}

.search-modal-empty-title {
  font-size: 15px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.5);
}

.search-modal-empty-subtitle {
  font-size: 13px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.25);
  margin-top: -4px;
}

/* ============================================================
   LOADING STATE
   ============================================================ */

.search-modal-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 36px 20px;
  gap: 8px;
}

.search-modal-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(110, 132, 255, 0.15);
  border-top-color: #6e84ff;
  border-radius: 50%;
  animation: sm-spin 0.65s linear infinite;
}

.search-modal-loading-text {
  font-size: 13px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.3);
}

/* ============================================================
   FOOTER
   ============================================================ */

.search-modal-footer {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px 12px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.search-modal-hint {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.25);
  white-space: nowrap;
}

.search-modal-hint kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 5px;
  min-width: 20px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  font-family: ui-monospace, 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 10px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.4);
  line-height: 1.6;
}

.search-modal-footer-spacer {
  flex: 1;
}

.search-modal-footer-brand {
  font-size: 11px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.12);
  letter-spacing: 0.02em;
}

.search-modal-footer-brand span {
  color: rgba(196, 30, 58, 0.5);
}

/* ============================================================
   LIGHT THEME SUPPORT
   ============================================================ */

@media (prefers-color-scheme: light) {
  #search-modal-overlay {
    background: rgba(0, 0, 0, 0.4);
  }

  #search-modal {
    background: rgba(252, 253, 255, 0.98);
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.04),
      0 24px 64px rgba(0, 0, 0, 0.18),
      0 8px 24px rgba(0, 0, 0, 0.1);
  }

  .search-modal-header {
    border-bottom-color: rgba(0, 0, 0, 0.07);
  }

  .search-modal-header-icon {
    color: rgba(0, 0, 0, 0.3);
  }

  #search-modal-input {
    color: #0f1117;
    caret-color: #6e84ff;
  }

  #search-modal-input::placeholder {
    color: rgba(0, 0, 0, 0.25);
  }

  .search-modal-esc-badge {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.1);
    color: rgba(0, 0, 0, 0.4);
  }

  .search-modal-esc-badge:hover {
    background: rgba(0, 0, 0, 0.09);
    color: rgba(0, 0, 0, 0.65);
  }

  .search-modal-section-label,
  .search-modal-group-label {
    color: rgba(0, 0, 0, 0.35);
  }

  .search-modal-item:hover,
  .search-modal-item.sm-active {
    background: rgba(110, 132, 255, 0.07);
    border-color: rgba(110, 132, 255, 0.2);
  }

  .search-modal-item-icon {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.07);
  }

  .search-modal-item:hover .search-modal-item-icon,
  .search-modal-item.sm-active .search-modal-item-icon {
    background: rgba(110, 132, 255, 0.08);
    border-color: rgba(110, 132, 255, 0.18);
  }

  .search-modal-item-title {
    color: #0f1117;
  }

  .search-modal-item.sm-active .search-modal-item-title {
    color: #0f1117;
  }

  .search-modal-item-desc {
    color: rgba(0, 0, 0, 0.42);
  }

  .search-modal-empty-title {
    color: rgba(0, 0, 0, 0.45);
  }

  .search-modal-empty-subtitle {
    color: rgba(0, 0, 0, 0.28);
  }

  .search-modal-empty-icon {
    color: rgba(0, 0, 0, 0.15);
  }

  .search-modal-loading-text {
    color: rgba(0, 0, 0, 0.3);
  }

  .search-modal-footer {
    border-top-color: rgba(0, 0, 0, 0.06);
  }

  .search-modal-hint {
    color: rgba(0, 0, 0, 0.3);
  }

  .search-modal-hint kbd {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.1);
    color: rgba(0, 0, 0, 0.4);
  }

  .search-modal-footer-brand {
    color: rgba(0, 0, 0, 0.15);
  }

  .search-modal-footer-brand span {
    color: rgba(196, 30, 58, 0.45);
  }

  .search-modal-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
  }

  .search-modal-body::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
  }

  .search-modal-body {
    scrollbar-color: rgba(0, 0, 0, 0.12) transparent;
  }

  .search-modal-clear-recent {
    color: rgba(110, 132, 255, 0.65);
  }
}

/* ============================================================
   DATA-THEME ATTRIBUTE SUPPORT (for JS-driven theming)
   ============================================================ */

[data-theme='light'] #search-modal {
  background: rgba(252, 253, 255, 0.98);
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.04),
    0 24px 64px rgba(0, 0, 0, 0.18),
    0 8px 24px rgba(0, 0, 0, 0.1);
}

[data-theme='light'] .search-modal-header {
  border-bottom-color: rgba(0, 0, 0, 0.07);
}

[data-theme='light'] .search-modal-header-icon {
  color: rgba(0, 0, 0, 0.3);
}

[data-theme='light'] #search-modal-input {
  color: #0f1117;
}

[data-theme='light'] #search-modal-input::placeholder {
  color: rgba(0, 0, 0, 0.25);
}

[data-theme='light'] .search-modal-esc-badge {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.1);
  color: rgba(0, 0, 0, 0.4);
}

[data-theme='light'] .search-modal-section-label,
[data-theme='light'] .search-modal-group-label {
  color: rgba(0, 0, 0, 0.35);
}

[data-theme='light'] .search-modal-item:hover,
[data-theme='light'] .search-modal-item.sm-active {
  background: rgba(110, 132, 255, 0.07);
  border-color: rgba(110, 132, 255, 0.2);
}

[data-theme='light'] .search-modal-item-icon {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.07);
}

[data-theme='light'] .search-modal-item-title {
  color: #0f1117;
}

[data-theme='light'] .search-modal-item-desc {
  color: rgba(0, 0, 0, 0.42);
}

[data-theme='light'] .search-modal-footer {
  border-top-color: rgba(0, 0, 0, 0.06);
}

[data-theme='light'] .search-modal-hint {
  color: rgba(0, 0, 0, 0.3);
}

[data-theme='light'] .search-modal-hint kbd {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.1);
  color: rgba(0, 0, 0, 0.4);
}

[data-theme='light'] .search-modal-footer-brand {
  color: rgba(0, 0, 0, 0.15);
}

/* ============================================================
   MOBILE RESPONSIVE
   ============================================================ */

@media (max-width: 680px) {
  #search-modal-overlay {
    padding-top: 0;
    align-items: flex-start;
  }

  #search-modal {
    top: 0;
    left: 0;
    right: 0;
    max-width: 100%;
    border-radius: 0 0 16px 16px;
    transform: none;
    animation-name: sm-modal-in-mobile;
    max-height: 80vh;
  }

  @keyframes sm-modal-in-mobile {
    from {
      opacity: 0;
      transform: translateY(-20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  #search-modal-overlay.sm-closing #search-modal {
    animation-name: sm-modal-out-mobile;
  }

  @keyframes sm-modal-out-mobile {
    from {
      opacity: 1;
      transform: translateY(0);
    }
    to {
      opacity: 0;
      transform: translateY(-20px);
    }
  }

  .search-modal-footer {
    gap: 10px;
    padding: 8px 16px 10px 16px;
    flex-wrap: wrap;
  }

  .search-modal-hint {
    font-size: 11px;
  }
}

/* ============================================================
   TRIGGER INPUT OVERRIDE — header search becomes a button
   ============================================================ */

#live-search-input,
#search-input {
  cursor: pointer !important;
  caret-color: transparent !important;
  user-select: none !important;
}

#live-search-input:focus,
#search-input:focus {
  outline: none !important;
}
