/* ============================================================================
   FIRMITAS · SERVICE CHART — layout, island controls, details overlay
   Loaded after studio.css so spacing overrides win cleanly.
   Panel/overlay chrome lives here; canvas colours live in chart/config.js.
   ========================================================================== */

/* ── Placement: full services section is the chart ────────────────────────
   build-lab / build-stage / service-list are gone (2026-09-23 full swap).
   Heading + services-foot spacing stay; chart is the only body. */
.services .chart {
  margin: 0 0 26px;
  /* Taller than the old mock so the map has room to breathe at 16:9 */
  max-height: min(72vh, 820px);
}
@media (max-width: 900px) {
  .services .chart {
    max-height: none;
    margin-bottom: 22px;
  }
}

/* ── Chart panel ──────────────────────────────────────────────────────── */
.chart {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 18px;
  overflow: hidden;
  background: #1a1224;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 30px 60px -30px rgba(20, 8, 30, 0.65);
  isolation: isolate;
  /* Sensible touch panning: map is not a scroll surface */
  touch-action: manipulation;
}

@media (max-width: 760px) {
  .chart { aspect-ratio: 4 / 5; border-radius: 14px; }
}

.chart-ocean,
.chart-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.chart-ocean { z-index: 0; background: #0b3a3f; }
.chart-canvas { z-index: 1; }
.chart-canvas[hidden] { display: none; }
.chart-canvas[hidden] { display: none; }

/* No-JS / pre-boot fallback — plain, honest, not a broken empty box */
.chart-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  padding: 32px;
  text-align: center;
  color: var(--stone, #f6eee9);
  font: 15px/1.6 Manrope, sans-serif;
  background:
    radial-gradient(120% 80% at 30% 20%, #2e2040, #1a1224 70%);
  z-index: 1;
}
.chart-fallback p { margin: 0; color: var(--muted, #c4b3ca); font-size: 13px; }
.chart[data-live] .chart-fallback { display: none; }

/* ── Hint ─────────────────────────────────────────────────────────────── */
.chart-hint {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  margin: 0;
  z-index: 4;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid rgba(231, 217, 190, 0.18);
  background: rgba(26, 18, 36, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: rgba(231, 217, 190, 0.82);
  font: 500 11px/1 Manrope, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
  transition: opacity 0.5s var(--ease, cubic-bezier(.16, 1, .3, 1)),
              transform 0.5s var(--ease, cubic-bezier(.16, 1, .3, 1));
  white-space: nowrap;
}
.chart-hint[data-hide] {
  opacity: 0;
  transform: translateX(-50%) translateY(6px);
}

/* ── Island buttons (keyboard + pointer targets) ──────────────────────── */
.chart-nodes {
  position: absolute;
  inset: 0;
  z-index: 3;
}

.chart-isle {
  --isle-r: 60px;
  position: absolute;
  transform: translate(-50%, -50%);
  /* Explicit height required — children are all absolute, so without this
     the button collapses to 0 and real pointer events never hit it. */
  width: calc(var(--isle-r) * 2.4);
  height: calc(var(--isle-r) * 2.4);
  min-width: 72px;
  min-height: 72px;
  max-width: 160px;
  max-height: 160px;
  padding: 0;
  border: 0;
  background: none;
  color: #e7d9be;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 6px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Invisible but generous hit disc centred on the island */
.chart-isle-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--isle-r) * 1.7);
  height: calc(var(--isle-r) * 1.7);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 1px solid transparent;
  transition: border-color 0.35s var(--ease, cubic-bezier(.16, 1, .3, 1)),
              background 0.35s var(--ease, cubic-bezier(.16, 1, .3, 1));
  pointer-events: none;
}

.chart-isle:hover .chart-isle-ring,
.chart-isle:focus-visible .chart-isle-ring,
.chart-isle[aria-expanded="true"] .chart-isle-ring {
  border-color: rgba(255, 128, 100, 0.75);
  background: rgba(255, 128, 100, 0.06);
}

.chart-isle:focus-visible {
  outline: none;
}
.chart-isle:focus-visible .chart-isle-ring {
  outline: 2px solid #ff8064;
  outline-offset: 3px;
}

.chart-isle-no {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, calc(-100% - calc(var(--isle-r) * 0.95)));
  font: 600 10px/1 Manrope, sans-serif;
  letter-spacing: 0.14em;
  color: rgba(201, 171, 114, 0.9);
  pointer-events: none;
  transition: color 0.3s ease;
}

.chart-isle-label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, calc(var(--isle-r) * 1.05));
  width: max-content;
  max-width: 120px;
  text-align: center;
  font: 500 11px/1.35 Manrope, sans-serif;
  letter-spacing: 0.04em;
  color: rgba(231, 217, 190, 0.88);
  text-shadow: 0 1px 8px rgba(10, 4, 14, 0.85);
  pointer-events: none;
  transition: color 0.3s ease, transform 0.35s var(--ease, cubic-bezier(.16, 1, .3, 1));
}

.chart-isle:hover .chart-isle-label,
.chart-isle:focus-visible .chart-isle-label,
.chart-isle[aria-expanded="true"] .chart-isle-label {
  color: #ff8064;
  transform: translate(-50%, calc(var(--isle-r) * 1.05 + -2px));
}

.chart-isle[aria-expanded="true"] .chart-isle-no {
  color: #ff8064;
}

@media (max-width: 760px) {
  .chart-isle-label { font-size: 10px; max-width: 88px; }
  .chart-isle[data-isle="building"] .chart-isle-label { transform: translate(-28%, calc(var(--isle-r) * 1.05)); text-align: right; }
  .chart-isle[data-isle="seo"] .chart-isle-label { transform: translate(-50%, calc(var(--isle-r) * -1.35)); text-align: center; max-width: 72px; }
  .chart-isle[data-isle="ai"] .chart-isle-label { transform: translate(-22px, calc(var(--isle-r) * 1.05)); text-align: right; max-width: 86px; }
  .chart-isle-no { font-size: 9px; }
  .chart-hint { bottom: 12px; font-size: 10px; padding: 7px 12px; }
}

/* ── Details overlay ──────────────────────────────────────────────────── */
.chart-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: clamp(14px, 3vw, 36px);
  pointer-events: none;
  /* Fade layer — card itself slides */
  opacity: 0;
  transition: opacity 0.45s var(--ease, cubic-bezier(.16, 1, .3, 1));
}
.chart-overlay[hidden] { display: none; }
.chart-overlay[data-open] {
  opacity: 1;
  /* Keep the layer transparent to pointers — only .chart-card captures, so
     island buttons under the open card stay hoverable/clickable. */
  pointer-events: none;
}

/* Soft scrim so the card reads over the map without trapping the pointer */
.chart-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(90% 80% at 80% 70%, rgba(12, 6, 18, 0.15), rgba(12, 6, 18, 0.55));
  opacity: 0;
  transition: opacity 0.45s var(--ease, cubic-bezier(.16, 1, .3, 1));
  pointer-events: none;
}
.chart-overlay[data-open]::before { opacity: 1; }

.chart-card {
  position: relative;
  pointer-events: auto;
  width: min(400px, 100%);
  max-height: min(86%, 520px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: clamp(20px, 3vw, 32px);
  border-radius: 14px;
  background:
    linear-gradient(160deg, rgba(59, 41, 69, 0.96), rgba(30, 20, 40, 0.97));
  border: 1px solid rgba(231, 217, 190, 0.14);
  box-shadow:
    0 24px 48px -20px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: #f6eee9;
  transform: translateY(18px) scale(0.985);
  opacity: 0;
  transition:
    transform 0.55s var(--ease, cubic-bezier(.16, 1, .3, 1)),
    opacity 0.45s var(--ease, cubic-bezier(.16, 1, .3, 1));
}
.chart-overlay[data-open] .chart-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.chart-card-num {
  display: inline-block;
  font: 600 11px/1 Manrope, sans-serif;
  letter-spacing: 0.16em;
  color: #c9ab72;
  margin-bottom: 14px;
}

.chart-card h3 {
  margin: 0 28px 8px 0;
  font: 500 clamp(22px, 2.4vw, 28px)/1.15 'Bricolage Grotesque', sans-serif;
  letter-spacing: -0.03em;
  color: #f6eee9;
}

.chart-card-deck {
  margin: 0 0 14px;
  font: 400 15px/1.45 'Bricolage Grotesque', sans-serif;
  color: #ff8064;
}

.chart-card-body {
  margin: 0;
  font: 400 13.5px/1.65 Manrope, sans-serif;
  color: #c4b3ca;
}

.chart-card-rule {
  height: 1px;
  margin: 18px 0;
  border: 0;
  background: linear-gradient(90deg, rgba(201, 171, 114, 0.45), transparent);
}

.chart-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: center;
}

.chart-card-primary,
.chart-card-secondary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font: 600 12px/1 Manrope, sans-serif;
  letter-spacing: 0.04em;
  min-height: 42px;
  transition: color 0.3s ease, background 0.3s ease, border-color 0.3s ease;
}
.chart-card-primary svg,
.chart-card-secondary svg {
  width: 16px;
  height: 16px;
}

.chart-card-primary {
  padding: 0 18px;
  border-radius: 999px;
  background: #ff8064;
  color: #281b2f;
  border: 1px solid #ff8064;
}
.chart-card-primary:hover,
.chart-card-primary:focus-visible {
  background: #ff957c;
  border-color: #ff957c;
}

.chart-card-secondary {
  color: #f6eee9;
  border-bottom: 1px solid rgba(246, 238, 233, 0.35);
  padding-bottom: 4px;
  border-radius: 0;
}
.chart-card-secondary:hover,
.chart-card-secondary:focus-visible {
  color: #ff8064;
  border-color: #ff8064;
}

.chart-card-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(246, 238, 233, 0.22);
  background: rgba(0, 0, 0, 0.25);
  color: #f6eee9;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.3s ease, border-color 0.3s ease, transform 0.3s ease;
}
.chart-card-close:hover,
.chart-card-close:focus-visible {
  background: rgba(255, 128, 100, 0.15);
  border-color: #ff8064;
  transform: rotate(90deg);
}
.chart-card-close:focus-visible {
  outline: 2px solid #ff8064;
  outline-offset: 2px;
}
.chart-card-close svg {
  width: 16px;
  height: 16px;
}

/* Mobile: card becomes a bottom sheet inside the panel */
@media (max-width: 760px) {
  .chart-overlay {
    align-items: flex-end;
    justify-content: stretch;
    padding: 12px;
  }
  .chart-card {
    width: 100%;
    max-height: 72%;
  }
}

/* Reduced motion: no travel, just state */
@media (prefers-reduced-motion: reduce) {
  .chart-overlay,
  .chart-overlay::before,
  .chart-card,
  .chart-hint,
  .chart-isle-label,
  .chart-isle-ring,
  .chart-card-close {
    transition: none !important;
  }
  .chart-card {
    transform: none;
  }
}

/* motion-off class used by overhaul.js global kill-switch */
body.motion-off .chart-overlay,
body.motion-off .chart-card,
body.motion-off .chart-hint {
  transition: none !important;
}
