/* Search Modal - Unified 2025 (Desktop & Mobile) */
:root {
  --search-glass-blur: 20px;
  --search-overlay-bg: rgba(0,0,0,0.42);
  --search-modal-bg: linear-gradient(180deg, color-mix(in srgb, var(--glass-color) 90%, transparent) 0%, color-mix(in srgb, var(--bg-secondary) 80%, transparent) 100%);
  --search-border: color-mix(in srgb, var(--glass-border) 90%, transparent);
}

[data-theme='dark'] {
  --search-overlay-bg: rgba(0,0,0,0.6);
  --search-modal-bg: linear-gradient(180deg, rgba(24,24,26,0.85) 0%, rgba(24,24,26,0.75) 100%);
  --search-border: rgba(255,255,255,0.08);
}

/* Common Overlay */
.search-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 14000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--search-overlay-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s;
}

.search-modal-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

/* Common Modal Container */
.search-modal-container {
  position: relative;
  display: flex;
  flex-direction: column !important; /* Force column layout as requested */
  background: var(--search-modal-bg);
  border: 1px solid var(--search-border);
  backdrop-filter: blur(var(--search-glass-blur)) saturate(150%);
  -webkit-backdrop-filter: blur(var(--search-glass-blur)) saturate(150%);
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.2, 1);
}

/* Input Area */
.search-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--search-border);
}

.search-input-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 36px; /* Adjusted for input margin (22px + 14px) */
  color: var(--text-secondary);
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.2s;
}

.search-input {
  width: 90%;
  margin: 0 22px;
  height: 52px;
  padding: 0 50px 0 56px; /* Increased left padding for icon, right for clear btn */
  border-radius: 14px;
  border: 1px solid var(--search-border);
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  color: var(--text);
  font-size: 17px;
  transition: all 0.2s ease;
}

.search-input:not(:placeholder-shown) ~ .search-icon {
  opacity: 0;
  visibility: hidden;
}

.search-input:focus {
  outline: none;
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.15);
}

/* Clear button inside input */
.search-clear-btn {
  position: absolute;
  right: 34px; /* Adjusted for input margin */
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: rgba(128,128,128,0.2);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
  z-index: 2;
}

.search-input:not(:placeholder-shown) ~ .search-clear-btn {
  opacity: 1;
  visibility: visible;
}

.search-clear-btn:hover {
  background: rgba(128,128,128,0.4);
  color: var(--text);
}

.search-close-btn, .modal-close-btn {
  position: absolute;
  top: 24px;
  right: 18px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  z-index: 10;
}

.search-close-btn:hover {
  background: rgba(0,0,0,0.05);
  color: var(--text);
}

/* Results Area */
.search-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.search-results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s ease;
  text-decoration: none;
  color: var(--text);
  position: relative; /* For absolute positioning if needed */
}

.search-result-item:hover, .search-result-item:focus {
  background: rgba(var(--accent-rgb), 0.08);
}

.search-thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  background: rgba(0,0,0,0.05);
  flex-shrink: 0;
}

.search-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.search-title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 20px; /* Prevent overlap with price arrow */
}

.search-meta {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Hide "Click to view" on very small screens if it overlaps */
@media (max-width: 360px) {
    .search-meta { display: none; }
}

.search-price {
  font-weight: 700;
  color: var(--accent);
  margin-left: auto;
  font-size: 15px;
  flex-shrink: 0;
}

/* Hints / Empty State */
.search-hint {
  text-align: center;
  color: var(--text-secondary);
  margin-top: 40px;
  font-size: 15px;
}

/* DESKTOP STYLES */
@media (min-width: 769px) {
  .search-modal-container {
    width: min(900px, 90vw);
    height: min(650px, 85vh);
    border-radius: 24px;
    /* flex-direction: row;  <-- Removed to respect column layout request */
    transform: scale(0.98);
    opacity: 0;
  }

  .search-modal-overlay.is-open .search-modal-container {
    transform: scale(1);
    opacity: 1;
  }

  .search-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden; /* Prevent double scrollbar */
  }

  .search-sidebar {
    /* width: 280px; */ /* Sidebar logic removed or adapted for column layout if needed, but user asked for column */
    /* border-left: 1px solid var(--search-border); */
    border-top: 1px solid var(--search-border); /* Changed to top border for column layout */
    background: rgba(0,0,0,0.02);
    padding: 20px;
    display: flex;
    flex-direction: row; /* Horizontal tags on desktop column layout */
    gap: 20px;
    flex-shrink: 0;
  }
  
  .search-sidebar > div {
      flex: 1;
  }

  .search-sidebar h4 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-weight: 600;
  }

  .tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .search-tag {
    padding: 6px 12px;
    border-radius: 20px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--search-border);
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
  }

  .search-tag:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
  }
}

/* MOBILE / TABLET STYLES */
@media (max-width: 768px) {
  .search-modal-overlay {
    align-items: flex-start; /* Align to top */
    background: var(--bg); /* Full opaque background for mobile feel or very dark blur */
  }

  .search-modal-container {
    width: 100%;
    height: 100%; /* Full screen */
    height: 100dvh; /* Dynamic viewport height */
    border-radius: 0;
    border: none;
    background: var(--bg);
    transform: translateY(10px);
    opacity: 0;
  }

  .search-modal-overlay.is-open .search-modal-container {
    transform: translateY(0);
    opacity: 1;
  }

  .search-header {
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top)); /* Telegram safe area */
    gap: 10px;
    background: var(--bg-secondary); /* Slightly distinct header */
  }

  .search-input {
    height: 44px;
    font-size: 16px;
    border-radius: 10px;
  }

  .search-close-btn {
    font-size: 16px;
    width: auto;
    padding: 0 8px;
    font-weight: 500;
    color: var(--accent);
  }

  .search-sidebar {
    display: none; /* No sidebar on mobile */
  }

  .search-body {
    padding: 12px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom)); /* Bottom safe area */
  }

  /* Adjust results for touch */
  .search-result-item {
    padding: 8px;
  }
  
  .search-thumb {
    width: 48px;
    height: 48px;
  }
}
