/* ============================================================
   SOVJANI FAMILY PORTAL — Component styles
   Base, header, hero, footer, keyframes and page transitions
   follow sovjani.com's css/styles.css. The service
   cards follow the site's .inq-card (the design system's Card).
   ============================================================ */

/* ---------- BASE ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--sov-charcoal-900);
  color: var(--sov-ivory);
  font-family: var(--font-body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: rgba(250, 192, 145, 0.28); color: var(--sov-ivory); }

img, svg, video { display: block; }

a { color: inherit; }

/* Keyboard focus: the design system's 2px apricot ring, offset 3px. */
.brand:focus-visible,
.nav-link:focus-visible,
.service:focus-visible,
.footer-link:focus-visible {
  outline: 2px solid var(--sov-apricot);
  outline-offset: 3px;
}

/* ============================================================
   CROSS-DOCUMENT PAGE TRANSITIONS  (View Transitions API)
   Same rules as sovjani.com. Browsers only run these between
   same-origin pages, so today they apply to future portal pages
   (not to arrivals from sovjani.com or the Access sign-in).
   ============================================================ */
@view-transition { navigation: auto; }

@keyframes vt-leave { to   { opacity: 0; transform: translateY(-18px); } }
@keyframes vt-enter { from { opacity: 0; transform: translateY(26px); } }

::view-transition-old(root) { animation: vt-leave 0.3s cubic-bezier(.22,.61,.27,1) both; }
::view-transition-new(root) { animation: vt-enter 0.55s cubic-bezier(.22,.61,.27,1) 0.12s both; }

.site-header { view-transition-name: site-nav; }
::view-transition-group(site-nav) { animation-duration: 0.45s; animation-timing-function: cubic-bezier(.22,.61,.27,1); }

/* ============================================================
   KEYFRAMES  (from sovjani.com)
   ============================================================ */
@keyframes sovRise   { from { opacity: 0; transform: translateY(26px); } to { opacity: 1; transform: none; } }
@keyframes sovScroll { 0%, 100% { transform: scaleY(0.4); opacity: 0.35; transform-origin: top; } 50% { transform: scaleY(1); opacity: 0.9; transform-origin: top; } }
@keyframes sovZoom   { from { transform: scale(1); } to { transform: scale(1.08); } }
@keyframes formRise  { from { opacity: 0; transform: translateY(44px); } to { opacity: 1; transform: none; } }

/* ============================================================
   ARRIVAL  (the inquiry page's entrance, no curtain)
   The header holds still; the page rises in as inquiries.html's
   .form-scene does, and main.js staggers the headline and cards.
   ============================================================ */
.portal { animation: formRise .9s cubic-bezier(.22, .61, .27, 1) both; }

/* ============================================================
   PERSISTENT HEADER  (sovjani.com .site-header)
   ============================================================ */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 90;
  background: rgba(35, 36, 39, 0.72);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(231, 220, 204, 0.10);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(20px, 4vw, 40px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  cursor: pointer;
}
.brand-mark { width: 28px; height: 28px; object-fit: contain; }
.brand-word {
  font-family: var(--font-brand);
  font-weight: 500;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--sov-apricot);
  font-size: 15px;
  padding-left: 0.24em;
}
.nav {
  display: flex;
  align-items: center;
  gap: clamp(16px, 3vw, 34px);
}
.nav-link {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-decoration: none;
  transition: opacity .25s ease;
}
/* Same look as sovjani.com's .nav-link--portal ("Member Portal ↗"). */
.nav-link--accent { color: var(--sov-apricot); }
.nav-link--accent:hover { opacity: 0.6; }

/* ============================================================
   HERO  (sovjani.com .hero, at 60% of the screen)
   ============================================================ */
.hero {
  position: relative;
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 120px clamp(24px, 6vw, 80px) 110px;
  overflow: hidden;
  background: var(--sov-charcoal-900);
}
.hero-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 55%;
  filter: saturate(0.5) brightness(0.42) contrast(0.98);
  z-index: 0;
  animation: sovZoom 44s ease-in-out infinite alternate;
}
.hero-scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(180deg,
    rgba(28, 29, 32, 0.56) 0%,
    rgba(28, 29, 32, 0.66) 55%,
    rgba(35, 36, 39, 0.88) 100%);
}
.hero-inner {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
}
.hero-title {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(36px, 5.2vw, 76px);
  line-height: 1.1;
  letter-spacing: -0.008em;
  color: var(--sov-ivory);
  margin: 0;
  max-width: 17ch;
}
.accent { color: var(--sov-apricot); }
.scroll-cue {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
}
.scroll-cue span {
  display: block;
  width: 1px;
  height: 52px;
  background: var(--sov-apricot);
  animation: sovScroll 2.8s ease-in-out infinite;
}

/* ============================================================
   REVEAL-ON-LOAD utility (driven by main.js)
   ============================================================ */
[data-reveal] { opacity: 1; }
.reveal-armed[data-reveal] { opacity: 0; }

/* ============================================================
   SERVICES  (cards = sovjani.com .inq-card)
   ============================================================ */
.services {
  border-top: 1px solid rgba(231, 220, 204, 0.10);
  padding: clamp(56px, 9vh, 96px) clamp(24px, 6vw, 80px) clamp(72px, 12vh, 140px);
}
/* Base grid; browsers without container queries or :has() keep it.
   The balanced rows are set further down (see BALANCED ROWS). */
.services-grid {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: clamp(14px, 2vw, 24px);
}
.service {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 40px;
  min-height: 172px;
  height: 100%;
  padding: clamp(24px, 2.6vw, 32px);
  background: var(--sov-charcoal-800);
  border: 1px solid rgba(231, 220, 204, 0.12);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--sov-ivory);
  transition: background .25s ease, border-color .25s ease;
}
.service:hover {
  background: var(--sov-charcoal-700);
  border-color: rgba(250, 192, 145, 0.32);
}
.service-icon {
  width: 30px;
  height: 30px;
  color: var(--sov-apricot);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.service-name {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: clamp(22px, 2vw, 26px);
  line-height: 1.2;
}
.service-arrow {
  position: absolute;
  top: clamp(24px, 2.6vw, 32px);
  right: clamp(24px, 2.6vw, 32px);
  width: 16px;
  height: 16px;
  color: var(--sov-apricot);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform .35s cubic-bezier(.22, .61, .27, 1);
}
.service:hover .service-arrow { transform: translate(2px, -2px); }

/* Phones: two across (also the fallback grid), with smaller cards. */
@media (max-width: 520px) {
  .services-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .service { min-height: 140px; gap: 28px; }
  .service-name { font-size: 20px; }
}

/* ============================================================
   BALANCED ROWS  (pure CSS, works without JS)
   Cards take as many columns as fit at about 190px each, then the
   rows are evened out: five cards go 2+2+1, 3+2, then 5 across,
   never 4+1. With room for f columns and n cards the count is
   ceil(n / ceil(n / f)). The :has() exceptions below are the only
   card counts where that comes out under f, so this holds for any
   number of cards. A card left alone on the last row spans the full
   width. Container widths: room for k columns = k × 190px + gaps.
   ============================================================ */
@supports (container-type: inline-size) and selector(:has(*)) {
  .services { container-type: inline-size; }
  .services-grid { --cols: 2; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); }
  .services-grid > li:only-child { grid-column: 1 / -1; }

  /* Room for 2 (phones, small tablets) */
  @container (width < 598px) {
    .services-grid > li:last-child:nth-child(odd) { grid-column: 1 / -1; }
  }

  /* Room for 3 */
  @container (598px <= width < 816px) {
    .services-grid { --cols: 3; }
    .services-grid:has(> li:nth-child(2):last-child),
    .services-grid:has(> li:nth-child(4):last-child) { --cols: 2; }
    .services-grid > li:last-child:nth-child(3n+7) { grid-column: 1 / -1; }
  }

  /* Room for 4 */
  @container (816px <= width < 1045px) {
    .services-grid { --cols: 4; }
    .services-grid:has(> li:nth-child(2):last-child) { --cols: 2; }
    .services-grid:has(> li:nth-child(3):last-child),
    .services-grid:has(> li:nth-child(5):last-child),
    .services-grid:has(> li:nth-child(6):last-child),
    .services-grid:has(> li:nth-child(9):last-child) { --cols: 3; }
    .services-grid > li:last-child:nth-child(4n+13) { grid-column: 1 / -1; }
  }

  /* Room for 5 (the grid stops growing at 1240px) */
  @container (width >= 1045px) {
    .services-grid { --cols: 5; }
    .services-grid:has(> li:nth-child(2):last-child) { --cols: 2; }
    .services-grid:has(> li:nth-child(3):last-child),
    .services-grid:has(> li:nth-child(6):last-child) { --cols: 3; }
    .services-grid:has(> li:nth-child(4):last-child),
    .services-grid:has(> li:nth-child(7):last-child),
    .services-grid:has(> li:nth-child(8):last-child),
    .services-grid:has(> li:nth-child(11):last-child),
    .services-grid:has(> li:nth-child(12):last-child),
    .services-grid:has(> li:nth-child(16):last-child) { --cols: 4; }
    .services-grid > li:last-child:nth-child(5n+21) { grid-column: 1 / -1; }
  }
}

/* ============================================================
   FOOTER  (sovjani.com .site-footer)
   ============================================================ */
.site-footer {
  border-top: 1px solid rgba(231, 220, 204, 0.10);
  padding: clamp(56px, 8vh, 84px) clamp(24px, 6vw, 80px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}
.footer-mark { width: 34px; height: 34px; object-fit: contain; opacity: 0.9; }
.footer-sig {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--sov-taupe);
}
.footer-link {
  margin-top: 6px;
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--sov-apricot);
  text-decoration: none;
  transition: opacity .25s ease;
}
.footer-link:hover { opacity: 0.6; }

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  html { scroll-behavior: auto; }
  *,
  *::before,
  *::after { animation: none !important; }
  .reveal-armed[data-reveal] { opacity: 1 !important; transform: none !important; }
}
