/* ============================================================
 * Stacking plan - interactive building cross-section.
 *
 * Building-agnostic wiring for an interactive stacking plan.
 * The per-building elevation SVG is hand-illustrated and lives
 * in the site (see example.html and README.md). This file styles
 * only the WIRING + interaction states + tooltip + table + per-row
 * expand panel.
 *
 * Per-row expand: each row shows compact info (suite, floor, RSF,
 * status, condition). An optional `<button class="stacking-row-toggle">`
 * reveals a sibling `.stacking-row-details` panel underneath with
 * notes + resource links. Multiple rows can be expanded simultaneously.
 *
 * Variant axes (see README):
 *   B) suiteFields    - markup-driven; any of data-condition,
 *                       data-notes, data-floorplan-url, data-test-fit-url,
 *                       data-virtual-tour-url, in addition to base
 *                       data-floor / data-rsf / data-status / data-slice
 *   C) sliceMode      - 'per-floor' (default) | 'per-suite'
 *                       (detected from data-slice key distribution;
 *                       JS handles either case transparently)
 *   D) sliceShape     - 'rect' (default) | 'custom'
 *                       (JS doesn't care about geometry; it just looks
 *                       up SVG elements by [data-slice] and toggles
 *                       state classes - the SVG owns the shape)
 *
 * Token contract (all overridable via shared/css/tokens.css):
 *   --bg-base, --bg-2, --ink, --ink-soft,
 *   --accent, --accent-bright, --accent-muted,
 *   --font-display, --font-sans, --font-mono,
 *   --container-pad, --container-max,
 *   --ease, --duration-fast
 *
 * Slice color follows the site's --accent token (set per site in
 * style.css per shared/css/tokens.css). Trophy yellow is the brand
 * mark and is NOT used here.
 *
 * Local opacity / scale knobs (override on .stacking, optional):
 *   --slice-idle:           0.45   slice fill opacity at rest
 *   --slice-hover:          0.7    slice fill opacity on hover/active
 *   --slice-stroke-hover:   0.9    slice stroke opacity on hover/active
 *   --row-hot-bg:           color-mix accent overlay for row hover
 *
 * Reference: 119 W 57 stacking-plan-embed.html + interactive-stacking-plan.md SOP.
 * ============================================================ */

.stacking {
  --slice-idle: 0.45;
  --slice-hover: 0.7;
  --slice-stroke-hover: 0.9;
  --row-hot-bg: color-mix(in srgb, var(--accent) 12%, transparent);

  padding: var(--space-section) var(--container-pad);
  background: var(--bg-base);
  position: relative;
}

.stacking-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 6.4rem;
  align-items: start;
}

.stacking-header {
  grid-column: 1 / -1;
  margin-bottom: 4.8rem;
}

.stacking-eyebrow {
  font-family: var(--font-mono);
  font-size: var(--type-eyebrow);
  font-weight: 500;
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1.2rem;
}

.stacking-title {
  font-family: var(--font-display);
  font-size: var(--type-h1);
  letter-spacing: var(--ls-display);
  line-height: var(--lh-snug);
  color: var(--ink);
  margin: 0;
}

.stacking-lede {
  font-family: var(--font-sans);
  font-size: var(--type-body);
  line-height: var(--lh-body);
  color: var(--ink-soft);
  max-width: 56ch;
  margin-top: 1.6rem;
}

/* ---------- SVG diagram column ---------- */

.stacking-wrap {
  position: relative;
  width: 100%;
}

.stacking-svg {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
}

/* The slice overlay. Visible at rest (--slice-idle: 0.45) so a
 * visitor scan-glances availability without needing to hover.
 * Color follows the site's --accent token. */
.stacking-svg .slice {
  fill: var(--accent);
  fill-opacity: var(--slice-idle);
  stroke: var(--accent);
  stroke-opacity: 0;
  cursor: pointer;
  transition:
    fill-opacity var(--duration-fast) var(--ease),
    stroke-opacity var(--duration-fast) var(--ease);
}

.stacking-svg .slice.is-hover {
  fill-opacity: var(--slice-hover);
  stroke-opacity: var(--slice-stroke-hover);
}

/* Leased: invisible, non-interactive. Mirrored from the table
 * row by JS at boot via data-status="leased". */
.stacking-svg .slice[data-status="leased"] {
  fill-opacity: 0;
  stroke-opacity: 0;
  pointer-events: none;
  cursor: default;
}

/* Keyboard focus ring on the slice - drawn as the slice stroke. */
.stacking-svg .slice:focus {
  outline: none;
  stroke-opacity: var(--slice-stroke-hover);
  fill-opacity: var(--slice-hover);
}

/* ---------- Tooltip (created by JS, appended to .stacking-wrap) ---------- */

.stack-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg-base);
  border: 1px solid var(--accent);
  padding: 1.2rem 1.6rem 1.4rem;
  min-width: 14rem;
  opacity: 0;
  transform: translateY(0.4rem);
  transition:
    opacity var(--duration-fast) var(--ease),
    transform var(--duration-fast) var(--ease);
  z-index: var(--z-overlay);
}
.stack-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.stack-tooltip-floor {
  font-family: var(--font-display);
  font-size: 2rem;
  letter-spacing: var(--ls-display);
  color: var(--ink);
  line-height: 1.1;
}

.stack-tooltip-line {
  font-family: var(--font-sans);
  font-size: 1.2rem;
  color: var(--ink-soft);
  margin-top: 0.4rem;
  line-height: 1.3;
}

.stack-tooltip-line.is-prebuilt {
  color: var(--accent-bright);
  font-weight: 600;
}

/* ---------- Availability table column ---------- */

.stacking-table {
  border-top: 1px solid var(--ink);
}

.stacking-row {
  display: grid;
  grid-template-columns: 8rem 1fr auto auto;
  gap: 2.4rem;
  align-items: center;
  padding: 2rem 1.6rem;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  transition: background var(--duration-fast) var(--ease);
  text-decoration: none;
  color: inherit;
}

/* When the row is itself an <a> (variant: no toggle, whole-row link),
 * upgrade to pointer for the click affordance. */
a.stacking-row {
  cursor: pointer;
}

/* When a row is immediately followed by an expanded details panel,
 * suppress its own bottom border so the panel inherits the divider. */
.stacking-row:has(+ .stacking-row-details:not(.is-collapsed)) {
  border-bottom-color: transparent;
}

.stacking-row[data-status="leased"] {
  opacity: 0.45;
  cursor: default;
}

.stacking-row.is-hover {
  background: var(--row-hot-bg);
}

.stacking-row-floor {
  font-family: var(--font-mono);
  font-size: var(--type-meta);
  font-weight: 500;
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
  color: var(--accent);
}

.stacking-row-suite {
  font-family: var(--font-display);
  font-size: 2.2rem;
  letter-spacing: var(--ls-display);
  color: var(--ink);
  line-height: 1.2;
}

.stacking-row-detail {
  font-family: var(--font-sans);
  font-size: 1.3rem;
  color: var(--ink-soft);
  margin-top: 0.4rem;
}

.stacking-row-rsf {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  color: var(--ink);
  white-space: nowrap;
}

/* Optional inline resource links (floor plan / test fit / virtual tour).
 * Renderable per-row by the site; styled here so the look is consistent. */
.stacking-row-links {
  display: flex;
  flex-wrap: wrap;
  gap: 1.2rem;
  margin-top: 0.6rem;
}

.stacking-row-link {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  padding-bottom: 0.2rem;
  transition: color var(--duration-fast) var(--ease),
              border-color var(--duration-fast) var(--ease);
}

.stacking-row-link:hover,
.stacking-row-link:focus-visible {
  color: var(--accent-bright);
  border-color: var(--accent-bright);
}

/* ---------- Per-row expand ---------- */
/* Each row may carry a `<button class="stacking-row-toggle">` whose
 * `aria-controls` points to a sibling `.stacking-row-details` element.
 * The details panel renders fully visible on initial paint (graceful
 * no-JS); JS adds .is-collapsed + max-height:0 on boot to enable
 * expand UX. Multiple rows can be expanded simultaneously - no
 * accordion auto-close. */

.stacking-row-toggle {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 3.2rem;
  height: 3.2rem;
  padding: 0;
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 50%;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  line-height: 1;
  transition:
    color var(--duration-fast) var(--ease),
    border-color var(--duration-fast) var(--ease),
    background var(--duration-fast) var(--ease);
}

.stacking-row-toggle::before {
  /* Chevron drawn from two borders rotated 45deg. Color inherits. */
  content: "";
  display: block;
  width: 0.8rem;
  height: 0.8rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-0.15rem) rotate(45deg);
  transition: transform var(--duration-fast) var(--ease);
}

.stacking-row-toggle:hover,
.stacking-row-toggle:focus-visible {
  color: var(--accent-bright);
  border-color: var(--accent-bright);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  outline: none;
}

.stacking-row-toggle[aria-expanded="true"]::before {
  transform: translateY(0.15rem) rotate(-135deg);
}

.stacking-row-details {
  overflow: hidden;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  transition: max-height 0.4s var(--ease);
}

/* Collapsed state. JS adds this class on boot (graceful no-JS = expanded
 * by default for SSR / crawlers). aria-expanded on the toggle is the
 * screen-reader signal; we keep the panel in the AT tree because the
 * collapse animation requires a non-zero rendered box to animate out
 * of, so [hidden] / display:none would skip the transition. */
.stacking-row-details.is-collapsed {
  max-height: 0;
}

.stacking-row-details-inner {
  padding: 1.6rem 1.6rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.stacking-row-details-notes {
  font-family: var(--font-sans);
  font-size: 1.4rem;
  line-height: var(--lh-body);
  color: var(--ink-soft);
  max-width: 56ch;
}

/* The links row inside the details panel reuses .stacking-row-links +
 * .stacking-row-link from above for consistent styling. */

/* ---------- Mobile ---------- */
/* At narrow widths the SVG stays visible but slices become non-
 * interactive (table is the primary interface; touch never fires
 * a row link via the slice). */

@media (max-width: 768px) {
  .stacking { padding: var(--space-section-mobile) var(--container-pad); }
  .stacking-inner {
    grid-template-columns: 1fr;
    gap: 3.2rem;
  }
  .stacking-wrap {
    max-width: 36rem;
    margin: 0 auto;
  }
  .stacking-svg .slice {
    pointer-events: none;
  }
  .stacking-row {
    grid-template-columns: 1fr auto auto;
    gap: 1.2rem;
  }
  .stacking-row-floor {
    grid-column: 1 / -1;
    margin-bottom: 0.4rem;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .stacking-svg .slice,
  .stack-tooltip,
  .stacking-row,
  .stacking-row-toggle,
  .stacking-row-toggle::before,
  .stacking-row-details {
    transition: none;
  }
}
