/*
 * Light theme for the public Agent Finder pages (carousel, agent page,
 * market chooser). Dark is the default and is defined by the existing page
 * styles; every rule in this file is scoped to html[data-theme="light"], so
 * dark mode renders exactly as before.
 *
 * How it works:
 *  1. Tailwind v4 compiles text-white, bg-white/5, border-white/10, ... from
 *     var(--color-white). Re-pointing that variable to slate flips most
 *     utility colors at once.
 *  2. "Islands" that must keep their own colors (photo cards, video, colored
 *     buttons, the already-light Schedule Call modal) reset the variable.
 *  3. Page chrome with hard-coded dark inline styles or custom classes is
 *     overridden below (inline styles need !important).
 *
 * The theme is set before first paint by the inline script in
 * layouts/application.html.erb and toggled by shared/_theme_toggle.
 */

html[data-theme="light"] {
  color-scheme: light;
  --color-white: #0f172a; /* slate-900: text-white -> dark text, bg-white/5 -> faint tint */
  --af-page-bg: linear-gradient(180deg, #f8f6f2 0%, #efede8 50%, #f8f6f2 100%);
  --af-surface: rgba(255, 255, 255, 0.78);
  --af-surface-strong: rgba(255, 255, 255, 0.94);
  --af-border: rgba(15, 23, 42, 0.1);
  --af-border-strong: rgba(15, 23, 42, 0.16);
  --af-text: #0f172a;
  --af-text-muted: #475569;
  --af-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
}

/* ---- Islands: keep original (white-on-dark / already-light) colors ---- */
html[data-theme="light"] .carousel-card,
html[data-theme="light"] .apple-card,
html[data-theme="light"] .carousel-nav,
html[data-theme="light"] .video-container,
html[data-theme="light"] .custom-video-controls,
html[data-theme="light"] .custom-video-controls-detail,
html[data-theme="light"] .af-hero-media,
html[data-theme="light"] .badge-icon-circle,
html[data-theme="light"] .badge-icon-circle-detail,
html[data-theme="light"] .badge-tooltip,
html[data-theme="light"] .badge-tooltip-detail,
html[data-theme="light"] .apple-primary-button,
html[data-theme="light"] #detail-video-modal,
html[data-theme="light"] #schedule-modal,
html[data-theme="light"] .theme-fixed,
/* anything on a solid colored or gradient background keeps white icons/text */
html[data-theme="light"] [class*="bg-gradient-to"],
html[data-theme="light"] [class*="bg-blue-5"],
html[data-theme="light"] [class*="bg-blue-6"],
html[data-theme="light"] [class*="bg-green-5"],
html[data-theme="light"] [class*="bg-cyan-5"],
html[data-theme="light"] [class*="bg-orange-5"],
html[data-theme="light"] [class*="bg-red-5"],
html[data-theme="light"] [class*="bg-purple-5"] {
  --color-white: #fff;
}

/* pale accent icons need more weight on a light background */
html[data-theme="light"] .text-blue-300 { color: #2563eb; }

/* ---- Page backgrounds ---- */
html[data-theme="light"] body { background: #f8f6f2; }
html[data-theme="light"] [style*="linear-gradient(180deg, #1a1a1a 0%, #2d2d2d 50%, #1a1a1a 100%)"] {
  background: var(--af-page-bg) !important;
}
/* faint dot grid */
html[data-theme="light"] [style*="radial-gradient(circle, rgba(255,255,255,0.1) 1px"] {
  background-image: radial-gradient(circle, rgba(15, 23, 42, 0.5) 1px, transparent 1px) !important;
}

/* Logo is a white wordmark: render it dark */
html[data-theme="light"] img[src*="/assets/logo"] { filter: invert(1) brightness(0.15); }

/* ---- Market chooser splash ---- */
html[data-theme="light"] #market-chooser {
  background: radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.97) 0%, rgba(239, 237, 232, 0.98) 70%) !important;
}
html[data-theme="light"] .market-chooser-option {
  background: var(--af-surface-strong) !important;
  box-shadow: var(--af-shadow);
}

/* ---- Carousel page chrome ---- */
html[data-theme="light"] .nav-menu-item { color: var(--af-text); }
html[data-theme="light"] .nav-menu-item:hover { color: #334155; }
/* search box + Filters button */
html[data-theme="light"] #agent-search,
html[data-theme="light"] #open-filters-btn {
  background: var(--af-surface) !important;
  border-color: var(--af-border-strong) !important;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}
html[data-theme="light"] #agent-search::placeholder { color: #64748b; }
/* filters modal */
html[data-theme="light"] [style*="rgba(30, 30, 30, 0.98)"] {
  background: rgba(255, 255, 255, 0.98) !important;
  border-color: var(--af-border) !important;
}
html[data-theme="light"] [style*="background: rgba(255, 255, 255, 0.02); border: 1px solid rgba(255, 255, 255, 0.05)"] {
  background: rgba(15, 23, 42, 0.03) !important;
  border-color: rgba(15, 23, 42, 0.08) !important;
}
html[data-theme="light"] .filter-checkbox { border-color: rgba(15, 23, 42, 0.3); background-color: #fff; }
/* "Swipe/scroll to browse" pill + empty-search message */
html[data-theme="light"] .apple-instructions-dark {
  background: var(--af-surface-strong);
  border-color: var(--af-border);
  box-shadow: var(--af-shadow);
}
html[data-theme="light"] [style*="background: rgba(255, 255, 255, 0.05); backdrop-filter: blur(20px)"] {
  background: var(--af-surface-strong) !important;
  border-color: var(--af-border) !important;
}
html[data-theme="light"] .apple-secondary-button-dark {
  background: var(--af-surface-strong);
  border-color: var(--af-border-strong);
  color: var(--af-text);
}

/* carousel arrows: solid so they read over both the page and the cards */
html[data-theme="light"] .apple-nav-button {
  background: rgba(255, 255, 255, 0.96);
  border-color: var(--af-border-strong);
  color: var(--af-text);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.14);
}
html[data-theme="light"] .apple-nav-button:hover { background: #fff; }

/* ---- Agent page ---- */
html[data-theme="light"] [style*="background: rgba(26, 26, 26, 0.8)"] {          /* sticky header */
  background: rgba(248, 246, 242, 0.85) !important;
}
html[data-theme="light"] [style*="background: rgba(26, 26, 26, 0.95)"] {         /* phone CTA footer */
  background: rgba(248, 246, 242, 0.96) !important;
  border-top-color: var(--af-border) !important;
}
html[data-theme="light"] .mobile-cta-footer { box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.08); }
html[data-theme="light"] .apple-detail-card {
  background: var(--af-surface);
  border-color: var(--af-border);
  box-shadow: var(--af-shadow);
}
html[data-theme="light"] [style*="background: rgba(255, 255, 255, 0.03); border: 1px solid rgba(255, 255, 255, 0.08)"] { /* review cards */
  background: rgba(15, 23, 42, 0.025) !important;
  border-color: rgba(15, 23, 42, 0.08) !important;
}
html[data-theme="light"] .apple-header-button,
html[data-theme="light"] .apple-secondary-button {
  background: var(--af-surface-strong);
  border-color: var(--af-border-strong);
  color: var(--af-text);
}
html[data-theme="light"] .apple-detail-tag {
  color: var(--af-text);
  background: rgba(15, 23, 42, 0.05);
  border-color: rgba(15, 23, 42, 0.12);
}
/* green / purple tag chips: darker text for contrast on light */
html[data-theme="light"] [style*="color: #6ee7b7"] { color: #047857 !important; background: rgba(16, 185, 129, 0.12) !important; }
html[data-theme="light"] [style*="color: #c084fc"] { color: #7e22ce !important; background: rgba(168, 85, 247, 0.1) !important; }
/* "Call Now": white button on dark becomes a dark button on light */
html[data-theme="light"] .agent-detail-page .apple-primary-button {
  background: #0f172a;
  color: #fff;
}
html[data-theme="light"] .agent-detail-page .apple-primary-button:hover { background: #1e293b; }

/* ---- Mobile/tablet menu (agents/index #mobile-menu) ----
   Base styles are the dark theme; light overrides follow. */
.af-menu-button { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; }

.af-menu-backdrop {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.25s ease, visibility 0s linear 0.25s;
}
.af-menu-backdrop.is-open { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity 0.25s ease; }

.af-menu {
  position: absolute; top: 100%; left: 12px; right: 12px; z-index: 30;
  max-width: 440px; margin-left: auto;
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: translateY(-8px) scale(0.98); transform-origin: top right;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.22s;
}
.af-menu.is-open {
  opacity: 1; visibility: visible; pointer-events: auto; transform: none;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.af-menu-panel {
  padding: 16px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(38, 38, 40, 0.96) 0%, rgba(24, 24, 26, 0.96) 100%);
  -webkit-backdrop-filter: blur(30px) saturate(160%); backdrop-filter: blur(30px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif;
  color: #fff;
  max-height: calc(100dvh - 96px); overflow-y: auto;
}
.af-menu-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5); margin: 4px 4px 8px;
}
.af-menu-label:not(:first-child) { margin-top: 18px; }

/* segmented control (market + appearance) */
.af-segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px;
  border-radius: 14px; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.08);
}
.af-segment {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 10px; border-radius: 10px;
  font-size: 14px; font-weight: 600; color: rgba(255, 255, 255, 0.7);
  text-decoration: none; white-space: nowrap; cursor: pointer; background: transparent; border: 0;
  transition: background 0.2s ease, color 0.2s ease;
}
.af-segment svg { width: 16px; height: 16px; }
.af-segment:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.af-segment.is-active,
.af-segment[aria-pressed="true"] {
  color: #fff; background: rgba(255, 255, 255, 0.16);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), inset 0 0 0 0.5px rgba(255, 255, 255, 0.15);
}
.af-segment:focus-visible, .af-menu-link:focus-visible { outline: 2px solid rgba(96, 165, 250, 0.8); outline-offset: 2px; }
.af-segmented-sm .af-segment { min-height: 36px; font-size: 13px; }

/* link rows */
.af-menu-links { display: flex; flex-direction: column; gap: 2px; }
.af-menu-link {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 10px;
  border-radius: 14px; color: #fff; text-decoration: none; font-size: 16px; font-weight: 500;
  transition: background 0.2s ease;
}
.af-menu-link:hover { background: rgba(255, 255, 255, 0.06); }
.af-menu-link.is-current { background: rgba(59, 130, 246, 0.14); }
.af-menu-icon {
  width: 36px; height: 36px; flex-shrink: 0; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.08); color: rgba(255, 255, 255, 0.85);
}
.af-menu-icon svg { width: 20px; height: 20px; }
.af-menu-link.is-current .af-menu-icon { background: #3b82f6; color: #fff; }
.af-menu-text { flex: 1; }
.af-menu-trailing { width: 16px; height: 16px; color: rgba(255, 255, 255, 0.4); }
.af-menu-here { font-size: 12px; font-weight: 600; color: #93c5fd; }

.af-menu-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 14px; padding: 14px 4px 2px; border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.af-menu-footer-label { font-size: 14px; font-weight: 500; color: rgba(255, 255, 255, 0.75); }
.af-menu-footer .af-segmented { flex: 0 1 190px; min-width: 0; }
.af-menu-footer .af-segment { padding: 0 8px; }

@media (prefers-reduced-motion: reduce) {
  .af-menu, .af-menu.is-open, .af-menu-backdrop, .af-menu-backdrop.is-open { transition: none; }
}

/* light theme */
html[data-theme="light"] .af-menu-backdrop { background: rgba(15, 23, 42, 0.18); }
html[data-theme="light"] .af-menu-panel {
  background: rgba(255, 255, 255, 0.97);
  border-color: var(--af-border);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.16), 0 2px 8px rgba(15, 23, 42, 0.06);
  color: var(--af-text);
}
html[data-theme="light"] .af-menu-label { color: #64748b; }
html[data-theme="light"] .af-segmented { background: rgba(15, 23, 42, 0.05); border-color: rgba(15, 23, 42, 0.06); }
html[data-theme="light"] .af-segment { color: #475569; }
html[data-theme="light"] .af-segment:hover { color: var(--af-text); background: rgba(15, 23, 42, 0.04); }
html[data-theme="light"] .af-segment.is-active,
html[data-theme="light"] .af-segment[aria-pressed="true"] {
  color: var(--af-text); background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12), inset 0 0 0 0.5px rgba(15, 23, 42, 0.08);
}
html[data-theme="light"] .af-menu-link { color: var(--af-text); }
html[data-theme="light"] .af-menu-link:hover { background: rgba(15, 23, 42, 0.04); }
html[data-theme="light"] .af-menu-link.is-current { background: rgba(59, 130, 246, 0.1); }
html[data-theme="light"] .af-menu-icon { background: rgba(15, 23, 42, 0.06); color: #334155; }
html[data-theme="light"] .af-menu-link.is-current .af-menu-icon { background: #2563eb; color: #fff; }
html[data-theme="light"] .af-menu-trailing { color: #94a3b8; }
html[data-theme="light"] .af-menu-here { color: #1d4ed8; }
html[data-theme="light"] .af-menu-footer { border-top-color: var(--af-border); }
html[data-theme="light"] .af-menu-footer-label { color: #334155; }

/* ---- Theme switch cross-fade (see afToggleTheme) ---- */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 450ms;
  animation-timing-function: ease-in-out;
}

/* ---- Theme toggle (shared/_theme_toggle) ---- */
.af-theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 9999px; flex-shrink: 0; cursor: pointer;
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.08);
  border: 0.5px solid rgba(255, 255, 255, 0.15);
  transition: background 0.2s ease;
}
.af-theme-toggle:hover { background: rgba(255, 255, 255, 0.14); }
.af-theme-toggle:focus-visible { outline: 2px solid rgba(96, 165, 250, 0.8); outline-offset: 2px; }
.af-theme-toggle .af-icon-moon { display: none; }
html[data-theme="light"] .af-theme-toggle {
  color: var(--af-text);
  background: var(--af-surface-strong);
  border-color: var(--af-border-strong);
}
html[data-theme="light"] .af-theme-toggle:hover { background: #fff; }
html[data-theme="light"] .af-theme-toggle .af-icon-sun { display: none; }
html[data-theme="light"] .af-theme-toggle .af-icon-moon { display: inline; }
