/**
 * Bay Navigator - Responsive Layout & WCAG Compliance
 *
 * This file handles:
 * - Responsive grid layouts for program cards
 * - WCAG 2.2 AAA target size compliance
 * - Vision Pro / Spatial computing adaptations
 * - High contrast mode support
 * - Search suggestions & highlights
 *
 * Note: Component styles (search panel, filter buttons, cards) are in modern-ui.css
 * Note: Design tokens are in design-tokens.css
 */

:root {
  /* Vision Pro / Spatial Computing specific tokens */
  --touch-target-min: 60px;
  --interaction-padding: 1.25rem;
}

/* ============================================================
   PROGRAM CARDS GRID LAYOUT
   ============================================================ */

.programs-container,
#search-results {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

/* Tablet - 2 columns */
@media (min-width: 768px) {
  .programs-container,
  #search-results {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Desktop - 3 columns */
@media (min-width: 1024px) {
  .programs-container,
  #search-results {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ============================================================
   PROGRAM CARD STRUCTURE
   ============================================================ */

.program-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: var(--interaction-padding);
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  position: relative;
  flex: 1 1 calc(33.333% - 1rem);
  min-width: 280px;
  max-width: 100%;
  box-sizing: border-box;
  box-shadow: var(--shadow-sm);
  min-height: 280px;
}

.program-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.program-card-header {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
}

/* Position favorite button in top right corner */
.program-card .favorite-toggle-corner {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 10;
  flex-shrink: 0;
}

/* Ensure program name doesn't overlap favorite button */
.program-card-header > div {
  padding-right: 3rem;
}

.program-name {
  font-size: var(--font-size-lg, 1.125rem);
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-word;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.program-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary);
}

.program-area,
.program-category {
  background: var(--bg-surface-alt, #f9fafb);
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-sm);
}

/* Eligibility icons and badges */
.eligibility-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
  font-size: var(--font-size-sm, 0.875rem);
  line-height: 1;
}

.eligibility-badge {
  width: auto;
  padding: 0.25rem 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-alt, #f9fafb);
  cursor: help;
  transition: background 0.2s ease;
  min-width: 44px;
  min-height: 44px;
}

.eligibility-badge:hover {
  background: var(--bg-hover, #e0f7fa);
}

.program-benefit {
  flex: 1;
  font-size: var(--font-size-base, 1rem);
  color: var(--text-secondary);
  line-height: 1.6;
  margin: 1rem 0;
}

.program-footer {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.program-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.25rem;
  min-height: var(--touch-target-min);
  background: var(--color-primary-dark, #00838f);
  color: white;
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s ease;
}

.program-link:hover {
  background: var(--color-primary-darker, #006064);
  text-decoration: none;
}

.program-link:focus {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
  box-shadow: var(--focus-ring-shadow);
}

.program-link::after {
  content: ' →';
  margin-left: 0.5rem;
}

/* Timeframe badge */
.program-timeframe {
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary);
  padding: 0.5rem 0.75rem;
  background: var(--bg-surface-alt);
  border-radius: var(--radius-sm);
  align-self: flex-start;
}

/* ============================================================
   VERIFIED BADGE STYLES
   ============================================================ */

.verified-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: all 0.2s ease;
  margin-left: 0.5rem;
}

.verified-badge svg {
  width: 12px;
  height: 12px;
}

/* Green: Verified within 60 days */
.verified-badge.fresh {
  background: var(--color-success);
  color: white;
}

/* Yellow: 61-179 days */
.verified-badge.aging {
  background: var(--color-warning);
  color: white;
}

/* Red: 180+ days - needs verification */
.verified-badge.stale {
  background: var(--color-error);
  color: white;
}

/* ============================================================
   SEARCH RESULTS
   ============================================================ */

.results-count {
  font-size: var(--font-size-base, 1rem);
  color: var(--text-heading);
  font-weight: 500;
}

.no-results {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem var(--interaction-padding);
  color: var(--text-muted);
}

.no-results p {
  margin-bottom: 1.5rem;
  font-size: var(--font-size-lg, 1.125rem);
}

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */

/* Tablet and small screens */
@media (max-width: 768px) {
  .programs-container,
  #search-results {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  /* Prevent horizontal scroll */
  body {
    overflow-x: hidden;
  }

  .container {
    padding: 0 1rem;
    max-width: 100%;
    overflow-x: hidden;
  }
}

/* Vision Pro optimizations - narrow windows */
@media (max-width: 600px) {
  :root {
    --interaction-padding: 1rem;
  }

  .programs-container,
  #search-results {
    gap: 1rem;
  }

  .program-card {
    padding: 1rem;
    min-height: auto;
    flex: 1 1 100%;
    min-width: 100%;
  }

  .program-name {
    font-size: 1.125rem;
    padding-right: 3rem;
  }

  .program-meta {
    font-size: 0.875rem;
  }
}

/* Very narrow Vision Pro windows */
@media (max-width: 400px) {
  .container {
    padding: 0 0.75rem;
  }

  .program-card {
    padding: 0.875rem;
  }

  .eligibility-badges {
    gap: 0.25rem;
  }

  .eligibility-badge {
    min-height: 40px;
    min-width: 40px;
    font-size: 1.125rem;
  }
}

/* ============================================================
   WCAG 2.2 TARGET SIZE (2.5.8) COMPLIANCE
   ============================================================ */

/* Explicit target size guarantees */
.filter-btn,
.reset-btn,
.program-link,
#search-input,
.sort-select {
  min-height: var(--touch-target-min);
  min-width: 24px;
}

.eligibility-badge {
  min-width: 44px;
  min-height: 44px;
}

/* Touch target spacing for mobile */
@media (max-width: 600px) {
  .filter-btn,
  .program-link {
    min-height: var(--touch-target-min);
  }
}

/* ============================================================
   HIGH CONTRAST MODE SUPPORT
   ============================================================ */

@media (prefers-contrast: more) {
  body {
    color: var(--text-primary);
  }

  a {
    text-decoration: underline;
  }

  .program-card {
    border-width: 2px;
  }

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

/* ============================================================
   SEARCH SUGGESTIONS & HIGHLIGHTS
   ============================================================ */

.search-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border: 2px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  max-height: 300px;
  overflow-y: auto;
}

.suggestions-section {
  padding: 0.5rem 0;
}

.suggestions-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
}

.suggestions-label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.5rem 1rem;
  display: block;
}

.clear-recent {
  font-size: var(--font-size-xs);
  color: var(--color-primary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: background-color 0.2s ease;
}

.clear-recent:hover {
  background-color: rgba(0, 172, 193, 0.1);
}

.suggestion-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  transition: background-color 0.15s ease;
}

.suggestion-item:hover,
.suggestion-item.selected {
  background-color: var(--bg-hover);
}

.suggestion-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.suggestion-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Search highlight */
.search-highlight,
mark.search-highlight {
  background-color: rgba(0, 172, 193, 0.3);
  color: inherit;
  padding: 0.1em 0.2em;
  border-radius: 2px;
  font-weight: 600;
}

/* ============================================================
   DARK MODE - Component Adjustments
   Uses CSS variables from design-tokens.css
   ============================================================ */

@media (prefers-color-scheme: dark) {
  .program-card {
    background: var(--card-bg);
    border-color: var(--card-border);
  }

  .program-card:hover {
    background: var(--bg-surface-alt);
  }

  .program-area,
  .program-category,
  .program-timeframe,
  .eligibility-badge {
    background: var(--bg-surface-alt);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
  }

  .program-name {
    color: var(--text-primary);
  }

  .program-benefit {
    color: var(--text-secondary);
  }

  .results-count {
    color: var(--text-heading);
  }

  .search-suggestions {
    background: var(--bg-surface);
    border-color: var(--border-color);
  }

  .suggestion-item:hover,
  .suggestion-item.selected {
    background-color: var(--bg-surface-alt);
  }

  .search-highlight,
  mark.search-highlight {
    background-color: rgba(0, 172, 193, 0.4);
  }
}

/* Manual dark mode toggle */
:root[data-theme="dark"] .program-card,
body[data-theme="dark"] .program-card {
  background: var(--card-bg);
  border-color: var(--card-border);
}

:root[data-theme="dark"] .program-card:hover,
body[data-theme="dark"] .program-card:hover {
  background: var(--bg-surface-alt);
}

:root[data-theme="dark"] .program-area,
:root[data-theme="dark"] .program-category,
:root[data-theme="dark"] .program-timeframe,
:root[data-theme="dark"] .eligibility-badge,
body[data-theme="dark"] .program-area,
body[data-theme="dark"] .program-category,
body[data-theme="dark"] .program-timeframe,
body[data-theme="dark"] .eligibility-badge {
  background: var(--bg-surface-alt);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

:root[data-theme="dark"] .program-name,
body[data-theme="dark"] .program-name {
  color: var(--text-primary);
}

:root[data-theme="dark"] .program-benefit,
body[data-theme="dark"] .program-benefit {
  color: var(--text-secondary);
}

:root[data-theme="dark"] .results-count,
body[data-theme="dark"] .results-count {
  color: var(--text-heading);
}

:root[data-theme="dark"] .search-suggestions,
body[data-theme="dark"] .search-suggestions {
  background: var(--bg-surface);
  border-color: var(--border-color);
}

:root[data-theme="dark"] .suggestion-item:hover,
:root[data-theme="dark"] .suggestion-item.selected,
body[data-theme="dark"] .suggestion-item:hover,
body[data-theme="dark"] .suggestion-item.selected {
  background-color: var(--bg-surface-alt);
}

:root[data-theme="dark"] .search-highlight,
:root[data-theme="dark"] mark.search-highlight,
body[data-theme="dark"] .search-highlight,
body[data-theme="dark"] mark.search-highlight {
  background-color: rgba(0, 172, 193, 0.4);
}

/* ============================================================
   UTILITIES
   ============================================================ */

.hidden {
  display: none !important;
}

.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;
}

.skip-to-content {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-primary);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  z-index: var(--z-dropdown);
}

.skip-to-content:focus {
  top: 0;
}
