/**
 * /directory — readable light “island” isolated from global Aurora dark theme (app.css imports).
 * Uses body:has(.directory-hero) so rules win against style.css / theconnect-brand.css !important.
 */

/* --- Reset global dark-theme bleed ---------------------------------- */
body:has(.directory-hero) {
  color-scheme: light;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif !important;
  background: #fafafa !important;
  color: #111827 !important;
  font-size: 16px !important;
  line-height: 1.6 !important;
}

body:has(.directory-hero)::before {
  content: none !important;
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  height: 0 !important;
  width: 0 !important;
  background: none !important;
}

* {
  box-sizing: border-box;
}

/*
 * Navigation: only directory uses .nav-bar (templates/marketplace/directory_home.html).
 * Scope with nav.nav-bar — not body:has() — so rules always apply (global brand uses .nav-links a !important).
 */
nav.nav-bar {
  display: block !important;
  background: #ffffff !important;
  border-bottom: 1px solid #e5e7eb !important;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06) !important;
  backdrop-filter: none !important;
  position: sticky !important;
  top: 0 !important;
  z-index: 100 !important;
  padding: 18px 20px !important;
}

nav.nav-bar .nav-container {
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
  max-width: 1400px !important;
  margin: 0 auto !important;
}

nav.nav-bar .nav-logo {
  font-size: 1.6rem !important;
  font-weight: 800 !important;
  color: #f97366 !important;
  -webkit-text-fill-color: #f97366 !important;
  background: none !important;
  background-clip: border-box !important;
  filter: none !important;
  text-decoration: none !important;
}

nav.nav-bar .nav-logo-sub {
  color: #0f172a !important;
  -webkit-text-fill-color: #0f172a !important;
  font-weight: 700 !important;
  margin-left: 0.15rem !important;
}

nav.nav-bar .nav-links {
  display: flex !important;
  gap: clamp(12px, 3vw, 30px) !important;
  align-items: center !important;
  flex-wrap: wrap !important;
}

/* High contrast on light bar (beats theconnect-brand .nav-links a) */
nav.nav-bar .nav-links a {
  color: #0f172a !important;
  -webkit-text-fill-color: #0f172a !important;
  text-decoration: none !important;
  font-weight: 700 !important;
  font-size: max(14px, 0.875rem) !important;
  margin-left: 0 !important;
  letter-spacing: 0.02em !important;
  text-transform: none !important;
}

nav.nav-bar .nav-links a:hover {
  color: #c2410c !important;
  -webkit-text-fill-color: #c2410c !important;
}

nav.nav-bar .nav-links a:focus-visible {
  outline: 2px solid #f97366 !important;
  outline-offset: 3px !important;
}

nav.nav-bar .nav-button {
  background: #f97366 !important;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  padding: 10px 25px !important;
  border-radius: 25px !important;
  font-weight: 700 !important;
}

/* Typography: readable body copy (overrides p, span !important from brand) */
body:has(.directory-hero) p,
body:has(.directory-hero) li,
body:has(.directory-hero) small {
  font-size: max(14px, 1rem) !important;
  line-height: 1.55 !important;
}

body:has(.directory-hero) .section-header h2,
body:has(.directory-hero) #searchResultsSection .section-header h2 {
  color: #111827 !important;
  -webkit-text-fill-color: unset !important;
  text-shadow: none !important;
  font-weight: 800 !important;
}

body:has(.directory-hero) .section-header p,
body:has(.directory-hero) #searchResultsSection .section-header p {
  color: #4b5563 !important;
  -webkit-text-fill-color: unset !important;
}

body:has(.directory-hero) .category-card h3,
body:has(.directory-hero) .listing-card h3,
body:has(.directory-hero) h3.listing-title {
  color: #1f2937 !important;
  -webkit-text-fill-color: unset !important;
  text-shadow: none !important;
  font-weight: 700 !important;
}

body:has(.directory-hero) .listing-tagline,
body:has(.directory-hero) .listing-content p {
  color: #4b5563 !important;
}

body:has(.directory-hero) .listing-meta,
body:has(.directory-hero) .listing-meta span {
  color: #64748b !important;
}

body:has(.directory-hero) .listing-meta i {
  color: #f97366 !important;
}

body:has(.directory-hero) .category-count,
body:has(.directory-hero) .category-count span {
  color: #ea580c !important;
}

body:has(.directory-hero) .empty-state h3 {
  color: #475569 !important;
}

body:has(.directory-hero) .empty-state p {
  color: #64748b !important;
}

body:has(.directory-hero) .loading-spinner p {
  color: #4b5563 !important;
}

/* Hero + trust row: light text on gradient */
body:has(.directory-hero) .directory-hero h1,
body:has(.directory-hero) .directory-hero .subtitle,
body:has(.directory-hero) .directory-hero p {
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
}

body:has(.directory-hero) .trust-badge-number,
body:has(.directory-hero) .trust-badge-label,
body:has(.directory-hero) .trust-badge i {
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
}

/* CTA band */
body:has(.directory-hero) .cta-section h2,
body:has(.directory-hero) .cta-section p {
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
}

body:has(.directory-hero) .cta-button {
  -webkit-text-fill-color: #f97366 !important;
}

body:has(.directory-hero) .cta-button.secondary {
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
}

/* Footer */
body:has(.directory-hero) .footer p,
body:has(.directory-hero) .footer {
  color: rgba(255, 255, 255, 0.92) !important;
}

body:has(.directory-hero) .footer .footer-links a {
  color: #cbd5e1 !important;
}

body:has(.directory-hero) .footer .footer-links a:hover {
  color: #ffffff !important;
}

/* Listing cards as links: no purple default */
body:has(.directory-hero) a.listing-card {
  text-decoration: none !important;
  color: inherit !important;
}

body:has(.directory-hero) a.listing-card:hover,
body:has(.directory-hero) a.listing-card:focus {
  text-decoration: none !important;
}

/* Search input: legible + avoid iOS zoom below 16px */
body:has(.directory-hero) .search-box input {
  color: #111827 !important;
  background: #ffffff !important;
  font-size: 16px !important;
  line-height: 1.5 !important;
  min-height: 48px !important;
}

body:has(.directory-hero) .search-box input::placeholder {
  color: #64748b !important;
  opacity: 1 !important;
}

body:has(.directory-hero) .search-box button {
  color: #ffffff !important;
  font-size: max(14px, 1rem) !important;
  min-height: 48px !important;
}

/* --- Layout (original directory styles) -------------------------------- */
.directory-hero {
  background: linear-gradient(135deg, #f97366 0%, #9a94bc 50%, #ffc857 100%);
  padding: 80px 20px 100px;
  text-align: center;
  color: white;
  position: relative;
  overflow: hidden;
}

.directory-hero::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="1" fill="white" opacity="0.1"/></svg>')
    repeat;
  opacity: 0.3;
}

.hero-content {
  position: relative;
  z-index: 1;
  max-width: 900px;
  margin: 0 auto;
}

.directory-hero h1 {
  font-size: clamp(2rem, 5vw, 3.5rem);
  margin-bottom: 1rem;
  font-weight: 800;
  line-height: 1.15;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.2);
}

.directory-hero .subtitle {
  font-size: clamp(1.05rem, 2.5vw, 1.4rem);
  opacity: 0.98;
  max-width: 700px;
  margin: 0 auto 2.5rem;
  line-height: 1.6;
}

.trust-badges {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin: 30px 0;
  flex-wrap: wrap;
}

.trust-badge {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  padding: 15px 25px;
  border-radius: 50px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  gap: 10px;
}

.trust-badge i {
  font-size: 1.5rem;
}

.trust-badge-text {
  text-align: left;
}

.trust-badge-number {
  font-size: 1.5rem;
  font-weight: 700;
}

.trust-badge-label {
  font-size: max(14px, 0.85rem);
  opacity: 0.95;
}

.search-container {
  max-width: 800px;
  margin: 0 auto;
}

.search-box {
  display: flex;
  gap: 10px;
  background: white;
  padding: 8px;
  border-radius: 50px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  align-items: stretch;
}

.search-box input {
  flex: 1;
  padding: 15px 25px;
  border: none;
  border-radius: 50px;
  outline: none;
}

.search-box button {
  padding: 15px 35px;
  background: linear-gradient(135deg, #ffc857 0%, #f97316 100%);
  border: none;
  border-radius: 50px;
  cursor: pointer;
  font-weight: 700;
  transition: all 0.3s;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4);
}

.search-box button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(245, 158, 11, 0.5);
}

.section-header {
  text-align: center;
  padding: 60px 20px 30px;
  max-width: 800px;
  margin: 0 auto;
}

.section-header h2 {
  font-size: clamp(1.75rem, 4vw, 2.8rem);
  margin-bottom: 15px;
  font-weight: 800;
  line-height: 1.2;
}

.section-header p {
  font-size: max(15px, 1.125rem);
  line-height: 1.6;
}

.category-grid {
  max-width: 1400px;
  margin: 0 auto 80px;
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 25px;
}

.category-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  padding: 35px 25px;
  text-align: center;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.category-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #f97366, #9a94bc);
  transform: scaleX(0);
  transition: transform 0.4s;
}

.category-card:hover {
  border-color: #f97366;
  transform: translateY(-8px);
  box-shadow: 0 20px 40px rgba(102, 126, 234, 0.25);
}

.category-card:hover::before {
  transform: scaleX(1);
}

.category-icon-wrapper {
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
  background: linear-gradient(135deg, #f97366 0%, #9a94bc 100%);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.4s;
}

.category-card:hover .category-icon-wrapper {
  transform: scale(1.1) rotate(5deg);
  box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
}

.category-icon {
  font-size: 2.5rem;
  color: white;
}

.category-card h3 {
  font-size: max(16px, 1.4rem);
  margin-bottom: 12px;
  line-height: 1.3;
}

.category-count {
  font-size: max(14px, 1rem);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.category-count i {
  font-size: 0.9rem;
}

.featured-section {
  background: linear-gradient(180deg, #f9fafb 0%, #ffffff 100%);
  padding: 80px 20px;
  position: relative;
}

.featured-section::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 200px;
  background: linear-gradient(180deg, rgba(102, 126, 234, 0.03) 0%, transparent 100%);
}

.featured-grid {
  max-width: 1400px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
  gap: 35px;
  position: relative;
  z-index: 1;
}

.listing-card {
  background: white;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid #e5e7eb;
}

.listing-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
  border-color: #f97366;
}

.listing-image {
  width: 100%;
  height: 240px;
  object-fit: cover;
  background: linear-gradient(135deg, #f97366 0%, #9a94bc 50%, #ffc857 100%);
  position: relative;
  display: block;
}

.listing-image::after {
  content: "🏢";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 4rem;
  opacity: 0.3;
  pointer-events: none;
}

.listing-card img.listing-image::after {
  display: none;
}

.listing-content {
  padding: 25px;
}

.listing-badge {
  display: inline-block;
  background: linear-gradient(135deg, #ffc857 0%, #f97316 100%);
  color: white !important;
  -webkit-text-fill-color: #ffffff !important;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: max(12px, 0.8rem);
  font-weight: 700;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.listing-title {
  font-size: max(18px, 1.6rem);
  font-weight: 700;
  margin-bottom: 10px;
  line-height: 1.25;
}

.listing-tagline {
  margin-bottom: 18px;
  font-size: max(14px, 1rem);
  line-height: 1.55;
}

.listing-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 20px;
  font-size: max(14px, 0.9rem);
  padding-top: 15px;
  border-top: 1px solid #e5e7eb;
}

.listing-meta i {
  margin-right: 6px;
}

.cta-section {
  background: linear-gradient(135deg, #f97366 0%, #9a94bc 50%, #ffc857 100%);
  padding: 100px 20px;
  text-align: center;
  color: white;
  position: relative;
  overflow: hidden;
}

.cta-section::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="1" fill="white" opacity="0.1"/></svg>')
    repeat;
  opacity: 0.2;
}

.cta-content {
  position: relative;
  z-index: 1;
  max-width: 800px;
  margin: 0 auto;
}

.cta-section h2 {
  font-size: clamp(1.75rem, 4vw, 3rem);
  margin-bottom: 20px;
  font-weight: 800;
  line-height: 1.2;
}

.cta-section p {
  font-size: max(16px, 1.25rem);
  opacity: 0.98;
  margin-bottom: 40px;
  line-height: 1.6;
}

.cta-buttons {
  display: flex;
  gap: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

.cta-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: white;
  color: #f97366;
  padding: 18px 45px;
  border-radius: 50px;
  font-size: max(15px, 1.15rem);
  font-weight: 700;
  text-decoration: none;
  transition: all 0.4s;
  box-shadow: 0 10px 30px rgba(255, 255, 255, 0.3);
  line-height: 1.4;
}

.cta-button:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 50px rgba(255, 255, 255, 0.5);
}

.cta-button.secondary {
  background: rgba(255, 255, 255, 0.12);
  color: white;
  border: 2px solid white;
}

.loading-spinner {
  text-align: center;
  padding: 60px;
  grid-column: 1 / -1;
}

.spinner {
  width: 50px;
  height: 50px;
  margin: 0 auto 20px;
  border: 4px solid #e5e7eb;
  border-top-color: #f97366;
  border-radius: 50%;
  animation: directory-spin 0.8s linear infinite;
}

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

.empty-state {
  text-align: center;
  padding: 80px 20px;
  grid-column: 1 / -1;
}

.empty-state i {
  font-size: 5rem;
  color: #e5e7eb;
  margin-bottom: 20px;
}

.empty-state h3 {
  font-size: max(18px, 1.8rem);
  margin-bottom: 10px;
  line-height: 1.3;
}

.footer {
  background: #1f2937;
  color: white;
  padding: 50px 20px 30px;
  text-align: center;
}

.footer-links {
  margin: 25px 0;
  display: flex;
  gap: 30px;
  justify-content: center;
  flex-wrap: wrap;
}

@media (max-width: 768px) {
  .trust-badges {
    gap: 15px;
  }

  .trust-badge {
    padding: 12px 20px;
  }

  .category-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr));
    gap: 15px;
  }

  .featured-grid {
    grid-template-columns: 1fr;
  }

  .cta-buttons {
    flex-direction: column;
  }

  .search-box {
    flex-direction: column;
    border-radius: 16px;
  }

  .search-box input,
  .search-box button {
    border-radius: 12px;
    width: 100%;
  }
}

/* Client search (?q=): avoid flash of browse sections while results load */
body.directory-q-active .directory-browse-shell {
  display: none !important;
}

/* --- prefers-color-scheme: dark (readable slate, not raw global dark) ---- */
@media (prefers-color-scheme: dark) {
  body:has(.directory-hero) {
    color-scheme: dark;
    background: #0f172a !important;
    color: #e2e8f0 !important;
  }

  nav.nav-bar {
    background: #1e293b !important;
    border-bottom-color: #334155 !important;
  }

  nav.nav-bar .nav-logo-sub {
    color: #f8fafc !important;
    -webkit-text-fill-color: #f8fafc !important;
  }

  /* Near-white links on slate bar (was #cbd5e1 — too dim vs global muted) */
  nav.nav-bar .nav-links a {
    color: #f8fafc !important;
    -webkit-text-fill-color: #f8fafc !important;
  }

  nav.nav-bar .nav-links a:hover {
    color: #fecaca !important;
    -webkit-text-fill-color: #fecaca !important;
  }

  body:has(.directory-hero) .section-header h2,
  body:has(.directory-hero) #searchResultsSection .section-header h2,
  body:has(.directory-hero) .directory-search-root .section-header h2 {
    color: #f8fafc !important;
  }

  body:has(.directory-hero) .section-header p,
  body:has(.directory-hero) #searchResultsSection .section-header p,
  body:has(.directory-hero) .directory-search-root .section-header p {
    color: #94a3b8 !important;
  }

  body:has(.directory-hero) .category-card,
  body:has(.directory-hero) .listing-card {
    background: #1e293b !important;
    border-color: #334155 !important;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35) !important;
  }

  body:has(.directory-hero) .category-card h3,
  body:has(.directory-hero) .listing-card h3,
  body:has(.directory-hero) h3.listing-title {
    color: #f1f5f9 !important;
  }

  body:has(.directory-hero) .listing-tagline,
  body:has(.directory-hero) .listing-content p {
    color: #cbd5e1 !important;
  }

  body:has(.directory-hero) .listing-meta,
  body:has(.directory-hero) .listing-meta span {
    color: #94a3b8 !important;
  }

  body:has(.directory-hero) .featured-section {
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%) !important;
  }

  body:has(.directory-hero) .search-box {
    background: #1e293b !important;
    border: 1px solid #334155;
  }

  body:has(.directory-hero) .search-box input {
    background: #0f172a !important;
    color: #f1f5f9 !important;
    border: 1px solid #334155;
  }

  body:has(.directory-hero) .search-box input::placeholder {
    color: #64748b !important;
  }

  body:has(.directory-hero) .empty-state h3 {
    color: #cbd5e1 !important;
  }

  body:has(.directory-hero) .empty-state p,
  body:has(.directory-hero) .loading-spinner p {
    color: #94a3b8 !important;
  }

  body:has(.directory-hero) .category-count,
  body:has(.directory-hero) .category-count span {
    color: #fdba74 !important;
  }

  body:has(.directory-hero) .spinner {
    border-color: #334155;
    border-top-color: #f97366;
  }

  body:has(.directory-hero) .empty-state i {
    color: #334155 !important;
  }
}
