/* ==========================================================================
   LEGAL DRAWER — accessible slide-over for the footer Disclosures control.
   Vanilla CSS, Flowkit tokens only. Mobile-first.
   ========================================================================== */

/* ── Scrim ─────────────────────────────────────────────────────────────── */
.legal-drawer-scrim {
  position: fixed;
  inset: 3rem 0 0 0; /* sit below the 3rem sticky nav */
  background: color-mix(in srgb, var(--text-primary) 40%, transparent);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--duration-slow) var(--ease-out),
    visibility var(--duration-slow) var(--ease-out);
  z-index: calc(var(--z-modal) - 1);
}

.legal-drawer-scrim.is-open {
  opacity: 1;
  visibility: visible;
}

/* ── Panel ─────────────────────────────────────────────────────────────── */
.legal-drawer {
  position: fixed;
  top: 3rem; /* clear the 3rem sticky nav */
  right: 0;
  bottom: 0;
  width: 100vw;
  max-width: 100vw;
  background: var(--bg-base);
  border-left: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-modal);
  transform: translateX(100%);
  visibility: hidden;
  transition:
    transform var(--duration-slow) var(--ease-out),
    visibility var(--duration-slow) var(--ease-out);
  will-change: transform;
  overscroll-behavior: contain;
}

.legal-drawer.is-open {
  transform: translateX(0);
  visibility: visible;
}

.legal-drawer__inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
}

/* ── Header ────────────────────────────────────────────────────────────── */
.legal-drawer__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-6);
  padding: var(--space-8) var(--space-6) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.legal-drawer__eyebrow {
  margin: 0 0 var(--space-2);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.legal-drawer__title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: var(--text-3xl);
  font-weight: 400;
  line-height: 1.15;
  color: var(--text-primary);
}

.legal-drawer__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--space-16);
  height: var(--space-16);
  flex-shrink: 0;
  margin-top: var(--space-1);
  padding: 0;
  background: none;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-circle);
  color: var(--text-primary);
  cursor: pointer;
  transition:
    background-color var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.legal-drawer__close:hover {
  background-color: var(--bg-elevated);
  border-color: var(--border-hover);
}

.legal-drawer__close:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ── Body ──────────────────────────────────────────────────────────────── */
.legal-drawer__body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-8) var(--space-6) var(--space-16);
}

.legal-drawer__intro {
  margin: 0 0 var(--space-10);
  font-size: var(--text-md);
  line-height: 1.65;
  color: var(--text-secondary);
  max-width: 60ch;
}

/* ── Section label (eyebrow above Big Three) ──────────────────────────── */
.legal-drawer__section-label {
  margin: 0 0 var(--space-5);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ── Big Three cards ──────────────────────────────────────────────────── */
.legal-drawer__big-three {
  margin-bottom: var(--space-12);
}

.legal-drawer__cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.legal-drawer__card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-6);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition:
    background-color var(--duration-normal) ease,
    border-color var(--duration-normal) ease,
    box-shadow var(--duration-normal) ease;
}

.legal-drawer__card:hover {
  background: var(--bg-base);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-sm);
}

.legal-drawer__card:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.legal-drawer__card-title {
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 400;
  line-height: 1.25;
  color: var(--text-primary);
}

.legal-drawer__card-desc {
  font-size: var(--text-sm);
  line-height: 1.55;
  color: var(--text-secondary);
}

.legal-drawer__card-cta {
  margin-top: var(--space-2);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-primary);
}

/* ── Prose sections ───────────────────────────────────────────────────── */
.legal-drawer__section {
  margin-bottom: var(--space-10);
  padding-bottom: var(--space-10);
  border-bottom: 1px solid var(--border-subtle);
}

.legal-drawer__section:last-of-type {
  border-bottom: none;
}

.legal-drawer__section-heading {
  margin: 0 0 var(--space-4);
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: 400;
  line-height: 1.25;
  color: var(--text-primary);
}

.legal-drawer__prose p {
  margin: 0 0 var(--space-4);
  font-size: var(--text-md);
  line-height: 1.7;
  color: var(--text-secondary);
}

.legal-drawer__prose p:last-child {
  margin-bottom: 0;
}

.legal-drawer__prose ul {
  margin: 0 0 var(--space-4);
  padding-left: var(--space-6);
  display: grid;
  gap: var(--space-3);
}

.legal-drawer__prose li {
  font-size: var(--text-md);
  line-height: 1.7;
  color: var(--text-secondary);
}

.legal-drawer__prose a {
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 0.15em;
  text-decoration-thickness: 1px;
  transition: color var(--duration-fast) ease;
}

.legal-drawer__prose a:hover {
  color: var(--accent-hover);
}

.legal-drawer__prose a:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Calculator disclaimer — visually distinct block */
.legal-drawer__disclaimer {
  padding: var(--space-5) var(--space-6);
  background: var(--bg-elevated);
  border-left: 2px solid var(--text-muted);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm) !important;
  line-height: 1.65 !important;
  color: var(--text-secondary) !important;
}

/* ── "Read more" links ────────────────────────────────────────────────── */
.legal-drawer__read-more {
  display: inline-block;
  margin-top: var(--space-4);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-primary);
  text-decoration: none;
  border-bottom: 1px solid var(--border-hover);
  padding-bottom: 2px;
  transition:
    color var(--duration-fast) ease,
    border-color var(--duration-fast) ease;
}

.legal-drawer__read-more:hover {
  color: var(--accent-hover);
  border-color: var(--text-primary);
}

.legal-drawer__read-more:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* ── Footer meta + doc links ──────────────────────────────────────────── */
.legal-drawer__footer {
  margin-top: var(--space-4);
  padding-top: var(--space-8);
  border-top: 1px solid var(--border-subtle);
}

.legal-drawer__effective {
  margin: 0 0 var(--space-6);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.6;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

.legal-drawer__doc-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3) var(--space-6);
}

.legal-drawer__doc-links a {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--duration-fast) ease;
}

.legal-drawer__doc-links a:hover {
  color: var(--text-primary);
}

.legal-drawer__doc-links a:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* ── Desktop: slide-over width ────────────────────────────────────────── */
@media (min-width: 768px) {
  .legal-drawer {
    width: min(460px, 100vw);
    max-width: 460px;
  }

  .legal-drawer__header {
    padding: var(--space-10) var(--space-8) var(--space-6);
  }

  .legal-drawer__body {
    padding: var(--space-8) var(--space-8) var(--space-20);
  }
}

@media (min-width: 1024px) {
  .legal-drawer {
    width: min(480px, 100vw);
    max-width: 480px;
  }
}

/* ── Reduced motion ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .legal-drawer-scrim,
  .legal-drawer {
    transition: none;
  }

  .legal-drawer {
    transform: none;
    opacity: 0;
  }

  .legal-drawer.is-open {
    opacity: 1;
  }
}

/* finelli.css — Footer styles only.
   The navigation lives in components/GlobalNav/global-nav.css (single source). */

/* ── Footer ──────────────────────────────────────────────────────────────── */
.finelli-footer {
  background-color: var(--bg-shell);
  position: relative;
  z-index: 10;
  margin-top: auto;
  overflow: hidden;
}

/* Skyline background, feathered: the top of the image fades into the
   off-white over roughly the first half, so it blends rather than hard-edges. */
.finelli-footer::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  aspect-ratio: 1585 / 530;
  /* Absolute URL: the DevLink bundler's css-loader resolves root-relative
     url() as a module and fails — an absolute URL is passed through. */
  background-image: url("https://www.jamesfinelliteam.com/app/footer/footer-desktop.webp");
  background-repeat: no-repeat;
  background-position: bottom center;
  background-size: 100% 100%;
  opacity: 0.55;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.25) 45%, rgba(0, 0, 0, 0.8) 100%);
  mask-image: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.25) 45%, rgba(0, 0, 0, 0.8) 100%);
  pointer-events: none;
  z-index: 0;
}

.finelli-footer-main,
.finelli-footer-bottom {
  position: relative;
  z-index: 1;
}

.finelli-footer-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 4rem 2.5rem 0;
}

.finelli-footer-top {
  display: grid;
  grid-template-columns: 1.5fr 4fr;
  gap: 3rem;
}

.finelli-footer-tier-1 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2rem;
}

.finelli-footer-stack {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.finelli-footer-brand {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Brand lock-up — matches the Site Map (.directory-heading) display typography */
.finelli-footer .finelli-logo {
  font-family: var(--font-display, "Italiana", "Compass Display", serif);
  /* ~13% larger than --text-3xl (22px), +12% again — client-tuned wordmark. */
  font-size: 1.74rem;
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: 0.01em;
  color: var(--text-primary);
  text-decoration: none;
  transition: color 150ms ease;
}

.finelli-footer .finelli-logo:hover {
  color: #000;
}

.finelli-footer-tagline {
  color: #4a4a4a;
  font-size: 0.875rem;
  line-height: 1.5;
  max-width: 280px;
}

.finelli-footer-social {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

.finelli-footer-social a {
  color: var(--text-muted, #666);
  transition: color 150ms ease;
}

.finelli-footer-social a:hover {
  color: var(--text-primary, #000);
}

.finelli-footer-social svg,
.finelli-footer-social img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  display: block;
}

.finelli-footer-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.finelli-footer-heading {
  font-family: var(--font-body, sans-serif);
  font-size: 0.75rem;
  font-weight: 500;
  color: #6b6b6b;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0;
}

.finelli-footer-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.finelli-footer-link {
  font-size: 0.875rem;
  color: #1f1f1f;
  text-decoration: none;
  transition: color 150ms ease;
}

.finelli-footer-link:hover {
  color: var(--text-primary, #000);
}

/* ── Footer Collapsible "More" (tier 2) ──────────────────────────────────── */
.finelli-footer-more {
  margin-top: 3rem;
  padding-top: 3rem;
  border-top: 1px solid var(--border-subtle, #e5e5e5);
}

.finelli-footer-more-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0;
  background: none;
  border: none;
  font-family: var(--font-body, sans-serif);
  font-size: 0.75rem;
  font-weight: 500;
  color: #6b6b6b;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: color 150ms ease;
}

.finelli-footer-more-toggle:hover {
  color: #000;
}

.finelli-footer-more-chevron {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 250ms ease;
  margin-left: 0.125rem;
  flex-shrink: 0;
}

.finelli-footer-more-chevron.open {
  transform: rotate(-135deg);
}

/* Animated open/close */
.finelli-footer-more-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 320ms cubic-bezier(0.22, 1, 0.36, 1);
}

.finelli-footer-more-panel.open {
  grid-template-rows: 1fr;
}

.finelli-footer-more-panel-inner {
  overflow: hidden;
  min-height: 0;
}

.finelli-footer-more-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2rem;
  padding-top: 1.5rem;
}

/* ── Footer legal (row 3) ────────────────────────────────────────────────── */
.finelli-footer-legalsection {
  display: flex;
  align-items: flex-start;
  gap: 2.5rem;
  margin-top: 3rem;
  padding-top: 3rem;
  border-top: 1px solid var(--border-subtle, #e5e5e5);
}

.finelli-footer-legalsection-label {
  flex-shrink: 0;
}

.finelli-footer-legalsection-content {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  flex: 1 1 auto;
}

.finelli-footer-legal-primary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.75rem;
}

.finelli-footer-legal-secondary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem 1.5rem;
}

.finelli-footer-legallink {
  font-size: 0.875rem;
  font-weight: 400;
  color: #1f1f1f;
  text-decoration: none;
  white-space: nowrap;
  transition: color 150ms ease;
}

.finelli-footer-legallink:hover {
  color: #000;
}

/* Secondary row — quieter */
.finelli-footer-legal-secondary .finelli-footer-legallink {
  font-size: 0.875rem;
  color: #4a4a4a;
}

.finelli-footer-legal-secondary .finelli-footer-legallink:hover {
  color: #1f1f1f;
}

/* Disclosures button — opens the LegalDrawer */
.finelli-footer-disclosures-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  border-bottom: 1px dashed currentColor;
  padding-bottom: 1px;
  transition: color 150ms ease, border-color 150ms ease;
}

.finelli-footer-disclosures-btn:hover {
  color: #000;
}

.finelli-footer-disclosures-btn:focus-visible {
  outline: 2px solid var(--border-focus, #2d62ff);
  outline-offset: 3px;
  border-radius: 2px;
}

/* External FH PDF link — conspicuous, with a small tag */
.finelli-footer-fh-pdf {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.finelli-footer-fh-pdf-tag {
  display: inline-block;
  padding: 0.1rem 0.3rem;
  font-family: var(--font-body, sans-serif);
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #4a4a4a;
  background: #e8e8e8;
  border-radius: 2px;
  line-height: 1.2;
}

.finelli-footer-compliance {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  flex-shrink: 0;
}

.finelli-footer-compliance img {
  display: block;
  height: 26px;
  width: auto;
  opacity: 0.8;
}

/* ── Footer bottom (row 4) ───────────────────────────────────────────────── */
.finelli-footer-bottom {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem 2.5rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: #4a4a4a;
}

.finelli-footer-broker {
  margin: 0;
  color: #6b6b6b;
  line-height: 1.5;
  max-width: 90ch;
}

.finelli-footer-copyright {
  margin: 0;
  color: #4a4a4a;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 991px) {
  .finelli-footer-top {
    grid-template-columns: 1fr;
    gap: 2rem;
  }

  .finelli-footer-tier-1 {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Flatten the Team+Explore stack so all four groups share the grid evenly
     (2×2) instead of leaving Services dangling on its own row. */
  .finelli-footer-stack {
    display: contents;
  }

  .finelli-footer-more-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .finelli-footer-bottom {
    padding: 1.25rem 2rem;
  }
}

@media (max-width: 767px) {
  .finelli-footer::before {
    aspect-ratio: 346 / 996;
    background-image: url("https://www.jamesfinelliteam.com/app/footer/footer-mobile.webp");
  }

  .finelli-footer-main {
    padding: 2.5rem 1.5rem 0;
  }

  /* Single left-aligned column on phones. */
  .finelli-footer-tier-1 {
    grid-template-columns: 1fr;
  }

  .finelli-footer-more-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .finelli-footer-legalsection {
    flex-direction: column;
    gap: 1rem;
  }

  .finelli-footer-legal-primary {
    gap: 0.625rem 1.25rem;
  }

  .finelli-footer-legal-secondary {
    gap: 0.375rem 1rem;
  }

  .finelli-footer-bottom {
    padding: 1.25rem 1.5rem 1.5rem;
  }
}

/* Design tokens for DevLink code components (footer + legal drawer).
 *
 * The app gets these from src/styles/tokens.css via :root. A Shadow DOM has no
 * :root — and custom properties only inherit INTO a shadow root if the host
 * defines them — so we define the subset these components use on :host. An
 * undefined var() makes its whole declaration invalid, so the list must cover
 * every token the footer + drawer reference.
 * Harmless when loaded in the app (the app already defines every token). */

:host {
  --text-primary: #171717;
  --text-secondary: #525252;
  --text-muted: #737373;
  --text-inverse: #ffffff;

  --text-xs: 0.6875rem;
  --text-sm: 0.75rem;
  --text-md: 0.875rem;
  --text-lg: 0.9375rem;
  --text-xl: 1rem;
  --text-2xl: 1.125rem;
  --text-3xl: 1.375rem;

  --font-body: "Compass Sans", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, sans-serif;
  --font-heading: "Compass Display", serif;
  --font-display: "Italiana", "Compass Display", serif;
  --font-mono: "GT Pressura Mono", "SF Mono", "Fira Code", monospace;

  --space-1: 0.25rem;
  --space-2: 0.375rem;
  --space-3: 0.5rem;
  --space-4: 0.625rem;
  --space-5: 0.75rem;
  --space-6: 1rem;
  --space-8: 1.25rem;
  --space-10: 1.5rem;
  --space-12: 2rem;
  --space-16: 3rem;
  --space-20: 4rem;

  --duration-fast: 0.15s;
  --duration-normal: 0.2s;
  --duration-slow: 0.3s;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  --radius-xs: 2px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-circle: 50%;

  --border-subtle: #e5e5e5;
  --border-focus: #2d62ff;
  --border-hover: #d4d4d4;

  --bg-base: #ffffff;
  --bg-surface: #fafafa;
  --bg-elevated: #f5f5f5;
  --bg-shell: #f3f3f3;

  --accent-hover: #262626;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.15);

  --z-modal: 1000;
}
