/**
 * Search Interface Styles - Zone A1
 * Google-simple search experience with Modern Slate Dark Theme
 */

/* ===========================
   Search Container
   =========================== */

.search-container {
  position: fixed;
  top: 57px;
  left: 0;
  right: 0;
  z-index: 40;
  background-color: #1a1a1a;
  border-bottom: 1px solid #2e2e2e;
  padding: 1rem 1.5rem;
}

.search-inner {
  max-width: 90rem; /* 1440px max-width */
  margin: 0 auto;
}

/* ===========================
   Search Input Wrapper
   =========================== */

.search-wrapper {
  position: relative;
  max-width: 80%;
  margin: 0 auto;
}

/* Mobile: full width */
@media (max-width: 768px) {
  .search-wrapper {
    max-width: 100%;
  }
}

/* ===========================
   Search Input Field
   =========================== */

#search-input {
  width: 100%;
  background-color: #0a0a0a;
  border: 1px solid #2e2e2e;
  border-radius: 0.5rem; /* 8px */
  padding: 0.875rem 3rem 0.875rem 1.25rem; /* 14px 48px 14px 20px */
  font-size: 16px; /* Prevents zoom on iOS */
  line-height: 1.5;
  color: #f5f5f5;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#search-input::placeholder {
  color: #94a3b8;
  opacity: 1;
}

/* Focus state - 3px amber ring */
#search-input:focus {
  outline: none;
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

/* Hover state */
#search-input:hover:not(:focus) {
  border-color: #3a3a3a;
}

/* ===========================
   Clear Button (X Icon)
   =========================== */

#clear-search {
  position: absolute;
  right: 3rem; /* 48px - space for search button */
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: #94a3b8;
  transition: color 0.2s ease, opacity 0.2s ease;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

#clear-search.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

#clear-search:hover {
  color: #f5f5f5;
}

#clear-search:focus {
  outline: none;
  color: #f59e0b;
}

#clear-search svg {
  width: 1.25rem; /* 20px */
  height: 1.25rem;
}

/* ===========================
   Search Button
   =========================== */

#search-button {
  position: absolute;
  right: 0.75rem; /* 12px */
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  padding: 0.5rem;
  cursor: pointer;
  color: #f59e0b;
  transition: color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

#search-button:hover {
  color: #fbbf24;
}

#search-button:focus {
  outline: none;
  color: #fbbf24;
}

#search-button svg {
  width: 1.5rem; /* 24px */
  height: 1.5rem;
}

/* ===========================
   Quick Filters Section
   =========================== */

.quick-filters {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.quick-filter-btn {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  background-color: #1a1a1a;
  color: #f5f5f5;
  border: 1px solid #3a3a3a;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.quick-filter-btn:hover {
  background-color: #2a2a2a;
  border-color: #f59e0b;
  color: #f59e0b;
}

.quick-filter-btn:focus {
  outline: none;
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

.quick-filter-btn.active {
  background-color: #f59e0b;
  border-color: #f59e0b;
  color: #0a0a0a;
}

/* ===========================
   Keyboard Shortcut Animations
   =========================== */

/* Pulse animation when focusing via / key */
@keyframes search-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(245, 158, 11, 0);
  }
}

.search-pulse {
  animation: search-pulse 0.6s ease-out;
  border-color: #f59e0b !important;
}

/* Fade-out animation when clearing via Esc */
.search-clearing {
  opacity: 0.5;
  transition: opacity 0.2s ease;
}

/* ===========================
   Keyboard Shortcut Hint
   =========================== */

.search-hint {
  position: absolute;
  right: 4rem; /* Space for both buttons */
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.75rem;
  color: #94a3b8;
  background-color: #1a1a1a;
  border: 1px solid #2e2e2e;
  border-radius: 0.25rem;
  padding: 0.125rem 0.375rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

#search-input:not(:focus):placeholder-shown ~ .search-hint {
  opacity: 1;
}

@media (max-width: 768px) {
  .search-hint {
    display: none;
  }
}

/* ===========================
   Loading State
   =========================== */

.search-wrapper.loading #search-button svg {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* ===========================
   Accessibility - Screen Reader Only
   =========================== */

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

/* ===========================
   Mobile Optimizations
   =========================== */

@media (max-width: 768px) {
  .search-container {
    padding: 0.75rem 1rem;
  }

  #search-input {
    font-size: 16px; /* Prevents iOS zoom */
    padding: 0.75rem 2.75rem 0.75rem 1rem;
  }

  .quick-filters {
    margin-top: 0.5rem;
    gap: 0.375rem;
  }

  .quick-filter-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
  }
}

/* ===========================
   Touch Device Optimizations
   =========================== */

@media (hover: none) and (pointer: coarse) {
  /* Increase touch targets to 44x44px minimum */
  #search-button,
  #clear-search {
    padding: 0.75rem;
  }

  .quick-filter-btn {
    padding: 0.625rem 1rem;
    min-height: 44px;
  }
}

/* ===========================
   Focus Visible (Keyboard Navigation)
   =========================== */

*:focus-visible {
  outline: 2px solid #f59e0b;
  outline-offset: 2px;
}

/* ===========================
   Animation Classes
   =========================== */

.fade-in {
  animation: fadeIn 0.2s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.slide-in {
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateY(-10px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ===========================
   High Contrast Mode Support
   =========================== */

@media (prefers-contrast: high) {
  #search-input {
    border-width: 2px;
  }

  #search-input:focus {
    border-width: 3px;
  }

  .quick-filter-btn {
    border-width: 2px;
  }
}

/* ===========================
   Reduced Motion Support
   =========================== */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===========================
   Filter Toggle Button
   =========================== */

.filter-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background-color: #1a1a1a;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  color: #f5f5f5;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.filter-toggle-btn:hover {
  background-color: #2a2a2a;
  border-color: #f59e0b;
  color: #f59e0b;
}

.filter-toggle-btn:focus {
  outline: none;
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

.filter-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  background-color: #f59e0b;
  color: #0a0a0a;
  font-size: 12px;
  font-weight: 700;
  border-radius: 12px;
  min-width: 20px;
  text-align: center;
  line-height: 1;
}

.filter-count-badge.hidden {
  display: none;
}

/* ===========================
   Mobile Overlay
   =========================== */

.filter-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 49;
  animation: overlayFadeIn 0.3s ease;
}

.filter-overlay.hidden {
  display: none;
}

@keyframes overlayFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ===========================
   Sidebar States & Animations
   =========================== */

.sidebar {
  transition: transform 0.3s ease;
}

/* Desktop: Sidebar slides from left */
@media (min-width: 1024px) {
  .sidebar {
    position: sticky;
    top: 0;
    left: 0;
    height: calc(100vh - 64px);
  }

  .sidebar[data-state="collapsed"] {
    transform: translateX(-100%);
    position: absolute;
    left: 0;
  }

  .sidebar[data-state="expanded"] {
    transform: translateX(0);
  }
}

/* Mobile: Bottom sheet from bottom */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    max-height: 80vh;
    border-radius: 16px 16px 0 0;
    border-right: none;
    border-top: 1px solid #2e2e2e;
    z-index: 50;
    overflow-y: auto;
  }

  .sidebar[data-state="collapsed"] {
    transform: translateY(100%);
  }

  .sidebar[data-state="expanded"] {
    transform: translateY(0);
  }
}

/* Desktop slide animations */
@keyframes slideInLeft {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0);
  }
}

@keyframes slideOutLeft {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-100%);
  }
}

/* Mobile slide animations */
@keyframes slideInBottom {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes slideOutBottom {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(100%);
  }
}

/* ===========================
   Reset Filters Button
   =========================== */

.reset-filters-btn {
  width: 100%;
  margin-top: 24px;
  padding: 12px 16px;
  background-color: #dc2626;
  color: white;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.reset-filters-btn:hover {
  background-color: #ef4444;
  transform: translateY(-1px);
}

.reset-filters-btn:active {
  transform: translateY(0);
}

.reset-filters-btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.3);
}

/* ===========================
   Sidebar Close Button (Mobile)
   =========================== */

#sidebar-close-btn {
  padding: 0.5rem;
  border-radius: 0.375rem;
  transition: background-color 0.2s ease, color 0.2s ease;
}

#sidebar-close-btn:hover {
  background-color: #2a2a2a;
}

#sidebar-close-btn:focus {
  outline: none;
  box-shadow: 0 0 0 2px #f59e0b;
}

/* ===========================
   Filter Section Collapsible
   =========================== */

.filter-section-content {
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease;
}

.filter-section-content.collapsed {
  max-height: 0 !important;
  opacity: 0;
  margin-top: 0 !important;
}

.filter-section-toggle svg {
  transition: transform 0.2s ease;
}

.filter-section-toggle.collapsed svg {
  transform: rotate(-90deg);
}

/* ===========================
   Mobile Optimizations for Filters
   =========================== */

@media (max-width: 1023px) {
  /* Increase touch targets */
  .filter-toggle-btn {
    min-height: 44px;
    padding: 12px 16px;
  }

  #sidebar-close-btn {
    min-width: 44px;
    min-height: 44px;
  }

  .filter-section-toggle {
    min-height: 44px;
    padding: 12px 0;
  }

  /* Bottom sheet styling */
  .sidebar {
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
  }
}

/* ===========================
   Accessibility - Focus Visible
   =========================== */

.filter-toggle-btn:focus-visible,
.reset-filters-btn:focus-visible,
#sidebar-close-btn:focus-visible {
  outline: 2px solid #f59e0b;
  outline-offset: 2px;
}

/* ===========================
   Recent Searches Dropdown
   =========================== */

.recent-searches-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: #1a1a1a;
  border: 1px solid #2e2e2e;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 50;
  max-height: 400px;
  overflow-y: auto;
  animation: slideDown 0.2s ease;
}

.recent-searches-dropdown.hidden {
  display: none;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Header */
.recent-searches-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #2e2e2e;
}

/* List */
.recent-searches-list {
  padding: 8px;
}

/* Individual Search Item */
.recent-search-item {
  padding: 12px 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
  margin-bottom: 4px;
}

.recent-search-item:last-child {
  margin-bottom: 0;
}

.recent-search-item:hover {
  background: #2a2a2a;
}

.recent-search-item:focus {
  outline: 2px solid #f59e0b;
  outline-offset: -2px;
}

/* Delete Button */
.delete-recent-btn {
  opacity: 0;
  transition: opacity 0.15s ease, color 0.15s ease;
  padding: 4px;
  cursor: pointer;
  flex-shrink: 0;
}

.recent-search-item:hover .delete-recent-btn {
  opacity: 1;
}

.delete-recent-btn:focus {
  opacity: 1;
  outline: 2px solid #f59e0b;
  border-radius: 4px;
}

/* Empty State */
.recent-searches-empty {
  padding: 32px 16px;
  text-align: center;
}

/* Scrollbar */
.recent-searches-dropdown::-webkit-scrollbar {
  width: 6px;
}

.recent-searches-dropdown::-webkit-scrollbar-thumb {
  background: #2e2e2e;
  border-radius: 3px;
}

.recent-searches-dropdown::-webkit-scrollbar-thumb:hover {
  background: #3a3a3a;
}

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

/* ===== Mobile: 320px - 767px ===== */
@media (max-width: 767px) {
  /* Search Container Mobile */
  .search-container {
    padding: 12px 16px;
    top: 56px; /* Adjust if header height changes on mobile */
  }

  /* Search Input Full Width on Mobile */
  .search-wrapper {
    max-width: 100%;
  }

  #search-input {
    width: 100%;
    font-size: 16px; /* Prevent iOS zoom */
    min-height: 48px;
    padding: 12px 48px 12px 16px;
  }

  /* Clear Button Touch Target */
  #clear-search {
    width: 44px;
    height: 44px;
    right: 4px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #clear-search svg {
    width: 20px;
    height: 20px;
  }

  /* Search Button Touch Target */
  #search-button {
    width: 44px;
    height: 44px;
    right: 48px; /* Positioned next to clear button */
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  #search-button svg {
    width: 20px;
    height: 20px;
  }

  /* Quick Filters Mobile */
  .quick-filters {
    margin-top: 8px;
    gap: 8px;
  }

  .quick-filter-btn {
    padding: 8px 12px;
    font-size: 13px;
    min-height: 40px;
    white-space: nowrap;
  }

  /* Filter Toggle Button Mobile */
  .filter-toggle-btn {
    padding: 10px 14px;
    font-size: 13px;
    min-height: 40px;
  }

  /* Recent Searches Dropdown Mobile */
  .recent-searches-dropdown {
    left: 16px;
    right: 16px;
    max-height: 60vh;
    border-radius: 12px;
  }

  .recent-search-item {
    padding: 14px 12px;
  }

  /* Delete buttons always visible on mobile */
  .delete-recent-btn {
    opacity: 1;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Case Cards Mobile */
  .case-card {
    padding: 16px;
    margin-bottom: 12px;
  }

  .case-card h2,
  .case-card h3 {
    font-size: 18px;
    line-height: 1.4;
  }

  .case-card .flex.gap-4 {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Stack buttons vertically on mobile */
  .case-card .flex.gap-3 {
    flex-direction: column;
    gap: 8px;
  }

  .case-card .flex.gap-3 > * {
    width: 100%;
  }

  /* Badges wrap on mobile */
  .case-card .flex.items-center.gap-2 {
    flex-wrap: wrap;
  }

  /* Pagination Mobile */
  nav[role="navigation"][aria-label="Pagination"] .flex {
    flex-wrap: wrap;
    gap: 4px;
  }

  nav[role="navigation"][aria-label="Pagination"] button {
    padding: 8px 12px;
    font-size: 13px;
    min-height: 44px;
  }

  /* Hide some page numbers on mobile */
  nav[role="navigation"][aria-label="Pagination"] button:not(.current):not(:first-child):not(:last-child):not(:nth-child(2)):not(:nth-last-child(2)) {
    display: none;
  }

  /* Sort Select Mobile */
  #sort-select {
    padding: 8px 12px;
    font-size: 13px;
    min-height: 44px;
  }

  /* Results Count Mobile */
  .text-2xl {
    font-size: 20px;
  }

  /* Main Content Mobile */
  main {
    padding: 16px;
  }

  /* Safe Area Support (iPhone Notch) */
  @supports (padding: env(safe-area-inset-bottom)) {
    .sidebar {
      padding-bottom: max(24px, env(safe-area-inset-bottom));
    }

    .recent-searches-dropdown {
      margin-bottom: env(safe-area-inset-bottom);
    }
  }
}

/* ===== Small Mobile: 320px - 374px (iPhone SE) ===== */
@media (max-width: 374px) {
  .search-container {
    padding: 10px 12px;
  }

  #search-input {
    font-size: 15px;
    padding: 10px 44px 10px 12px;
  }

  .quick-filter-btn {
    padding: 6px 10px;
    font-size: 12px;
  }

  .case-card {
    padding: 12px;
  }

  .case-card h2,
  .case-card h3 {
    font-size: 16px;
  }
}

/* ===== Large Mobile / Phablet: 414px - 767px ===== */
@media (min-width: 414px) and (max-width: 767px) {
  .search-container {
    padding: 14px 18px;
  }

  .quick-filter-btn {
    padding: 9px 14px;
    font-size: 14px;
  }
}

/* ===== Tablet Portrait: 768px - 1023px ===== */
@media (min-width: 768px) and (max-width: 1023px) {
  .search-wrapper {
    max-width: 90%;
  }

  .search-container {
    padding: 16px 24px;
  }

  .case-card {
    padding: 20px;
  }

  main {
    padding: 24px;
  }

  /* Buttons still touch-friendly on tablet */
  .quick-filter-btn {
    min-height: 44px;
  }

  #search-button,
  #clear-search {
    min-width: 44px;
    min-height: 44px;
  }
}

/* ===== Tablet Landscape / Small Desktop: 1024px+ ===== */
@media (min-width: 1024px) {
  .search-wrapper {
    max-width: 80%;
  }

  /* Desktop sidebar behavior */
  .sidebar {
    max-height: none;
  }
}

/* ===== Touch Device Optimizations ===== */
@media (hover: none) and (pointer: coarse) {
  /* All touch targets minimum 44x44px */
  #search-button,
  #clear-search,
  .quick-filter-btn,
  .filter-toggle-btn,
  #sidebar-close-btn,
  .delete-recent-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 10px 16px;
  }

  /* Always show delete buttons on touch devices */
  .delete-recent-btn {
    opacity: 1;
  }

  /* Remove hover states on touch devices */
  .recent-search-item:hover {
    background: transparent;
  }

  /* But keep active states for tap feedback */
  .recent-search-item:active {
    background: #2a2a2a;
  }

  .quick-filter-btn:hover {
    background-color: #1a1a1a;
    border-color: #3a3a3a;
    color: #f5f5f5;
  }

  .quick-filter-btn:active {
    background-color: #2a2a2a;
    border-color: #f59e0b;
    color: #f59e0b;
  }

  /* Case cards no hover lift on touch */
  .case-card:hover {
    transform: none;
    box-shadow: none;
  }

  .case-card:active {
    transform: scale(0.98);
  }
}

/* ===== Landscape Orientation (Mobile) ===== */
@media (max-width: 767px) and (orientation: landscape) {
  /* Reduce heights in landscape mode */
  .sidebar {
    max-height: 70vh;
  }

  .recent-searches-dropdown {
    max-height: 50vh;
  }

  /* Reduce vertical padding */
  .search-container {
    padding: 8px 16px;
  }
}

/* ===== Prevent Horizontal Scroll ===== */
body {
  overflow-x: hidden;
  max-width: 100vw;
}

* {
  box-sizing: border-box;
}

/* Ensure images and embeds don't overflow */
img,
video,
iframe {
  max-width: 100%;
  height: auto;
}

/* ===== High Contrast Mode (Accessibility) ===== */
@media (prefers-contrast: high) {
  @media (max-width: 767px) {
    #search-input {
      border-width: 2px;
    }

    .quick-filter-btn {
      border-width: 2px;
    }
  }
}

/* ===== Reduced Motion (Accessibility) ===== */
@media (prefers-reduced-motion: reduce) {
  .recent-searches-dropdown,
  .case-card,
  .search-pulse,
  .search-clearing {
    animation: none !important;
    transition: none !important;
  }
}
