/* 3DViewer — scoped styles, paired with js/3dviewer/viewer.js */

#3dviewer {
  background: #0b0f1a;
  color: #f7f7fb;
  font-family: Inter, -apple-system, sans-serif;
  position: relative;
  overflow: hidden;
}

body.v3d-fullscreen { overflow: hidden; }
body.v3d-fullscreen #3dviewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: hidden;
}
body.v3d-fullscreen header,
body.v3d-fullscreen .promo-bar,
body.v3d-fullscreen .promo-tab,
body.v3d-fullscreen #promoSpacer,
body.v3d-fullscreen .language-bar,
body.v3d-fullscreen .site-footer,
body.v3d-fullscreen footer,
body.v3d-fullscreen .mobile-footer-nav {
  display: none !important;
}

/* ─── Canvas — fills the viewport ─────────────────────────────── */
.v3d-scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #0b0f1a;
  cursor: grab;
  display: block;
}
.v3d-scene:active { cursor: grabbing; }

/* ─── Top-right action cluster (Play tour + Close) ────────────── */
.v3d-actions {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  z-index: 20;
}
.v3d-action-btn {
  background: rgba(11,15,26,0.85);
  border: 1px solid rgba(215,181,109,0.5);
  color: #d7b56d;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  backdrop-filter: blur(6px);
}
.v3d-action-btn:hover { background: rgba(215,181,109,0.18); }
.v3d-action-btn.tour {
  background: rgba(11,15,26,0.85);
  border-color: #60a5fa;
  color: #bfdbfe;
}
.v3d-action-btn.tour:hover { background: rgba(96,165,250,0.18); }
.v3d-action-btn.tour.active { background: rgba(96,165,250,0.40); }
.v3d-action-btn.upload {
  background: rgba(11,15,26,0.85);
  border-color: #06b6d4;
  color: #a5f3fc;
}
.v3d-action-btn.upload:hover { background: rgba(6,182,212,0.18); }

.v3d-close {
  background: rgba(11,15,26,0.85);
  border: 1px solid rgba(255,255,255,0.18);
  color: #f7f7fb;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  backdrop-filter: blur(6px);
}
.v3d-close:hover { background: rgba(255,255,255,0.12); }

/* ─── Top-center cluster: bucket toggle + help chip side-by-side ── */
.v3d-top-center {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 20;
}
.v3d-bucket-toggle {
  display: flex;
  gap: 4px;
  background: rgba(11,15,26,0.85);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 999px;
  padding: 4px;
  backdrop-filter: blur(6px);
}
.v3d-bucket-chip {
  background: transparent;
  border: 1px solid transparent;
  color: #94a3b8;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.v3d-bucket-chip:hover { color: #e2e8f0; }
.v3d-bucket-chip.active {
  background: rgba(215,181,109,0.18);
  border-color: rgba(215,181,109,0.5);
  color: #d7b56d;
}

/* ─── Help chip (now lives next to the bucket toggle in .v3d-top-center) ── */
.v3d-help-chip {
  position: relative;
}
.v3d-help-q {
  background: #d7b56d;
  color: #0b0f1a;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: help;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  transition: transform 0.15s, box-shadow 0.15s;
}
@media (hover: hover) and (pointer: fine) {
  .v3d-help-chip:hover .v3d-help-q {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(215,181,109,0.5);
  }
  .v3d-help-chip:hover .v3d-help-text { opacity: 1; pointer-events: auto; }
}
.v3d-help-chip.show .v3d-help-text { opacity: 1; pointer-events: auto; }
.v3d-help-text {
  position: absolute;
  top: 38px;
  /* Anchor to the chip — translateX(-50%) horizontally centres on the chip */
  left: 50%;
  transform: translateX(-50%);
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  background: rgba(11,15,26,0.96);
  border: 1px solid rgba(215,181,109,0.30);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.74rem;
  color: #cbd5e1;
  line-height: 1.5;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 30;
}
.v3d-help-section {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.v3d-help-section:last-child { border-bottom: none; }
.v3d-help-h {
  color: #d7b56d;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.v3d-help-text b {
  color: #f7f7fb;
  font-weight: 600;
}
@media (max-width: 600px) {
  .v3d-help-text { width: 280px; }
}

/* ─── Layer panel (top-left corner) ───────────────────────────── */
.v3d-layers-panel {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 230px;
  max-height: calc(100vh - 50px);
  max-height: calc(100dvh - 50px);
  background: rgba(11,15,26,0.85);
  border: 1.5px solid rgba(215,181,109,0.35);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(6px);
  z-index: 15;
}
.v3d-layers-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 4px 8px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.6px;
  color: #d7b56d;
  background: rgba(0,0,0,0.6);
  flex-shrink: 0;
}
.v3d-layers-toggle {
  background: transparent;
  border: 1px solid rgba(215,181,109,0.4);
  color: #d7b56d;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.v3d-layers-toggle:hover { background: rgba(215,181,109,0.18); }
.v3d-layers-body {
  padding: 8px 12px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}
.v3d-layers-panel.collapsed .v3d-layers-body { display: none; }
.v3d-layer-group {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.v3d-layer-group-title {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #94a3b8;
  text-transform: uppercase;
  padding: 4px 0 2px;
}
.v3d-layers-body label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  cursor: pointer;
  color: #cbd5e1;
  font-size: 0.78rem;
}
.v3d-layers-body input[type="checkbox"] {
  accent-color: #d7b56d;
  cursor: pointer;
  flex-shrink: 0;
}
.v3d-layer-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
/* Per-layer record count badge — populated after substance loads from
   _meta.record_counts. Right-aligned within the label so all counts
   align in a vertical column. Dim when zero. */
.v3d-layer-count {
  margin-left: auto;
  font-size: 0.68rem;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  padding-left: 6px;
}
.v3d-layer-count.zero { color: #475569; }

/* Tenement summary card — compact at-a-glance metadata block at the top
   of the layer panel. Hidden until populated (display:none default).
   Single tenement: ID, type/status, holder, area, dates. Multi-tenement:
   count header + lead + holder spread. */
.v3d-tenement-summary {
  display: none;
  background: rgba(215, 181, 109, 0.08);
  border: 1px solid rgba(215, 181, 109, 0.25);
  border-radius: 4px;
  padding: 6px 8px;
  margin-bottom: 6px;
}
.v3d-ts-id {
  color: #d7b56d;
  font-weight: 700;
  font-size: 0.84rem;
  letter-spacing: 0.2px;
}
.v3d-ts-sub {
  color: #94a3b8;
  font-size: 0.7rem;
  margin-top: 1px;
  margin-bottom: 4px;
}
.v3d-ts-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.7rem;
  line-height: 1.3;
  padding: 1px 0;
}
.v3d-ts-row > span:first-child {
  color: #64748b;
  flex-shrink: 0;
}
.v3d-ts-row > span:last-child {
  color: #cbd5e1;
  text-align: right;
  word-break: break-word;
}
/* When the chev is also present, push the count to its left so the
   chev sits in its existing margin-left:auto slot. */
.v3d-layer-chev + .v3d-layer-count,
.v3d-layer-count + .v3d-layer-chev { margin-left: 4px; }
/* Layer-level fetch failure indicator. Sits in the same slot as the count
   badge — replaces it when a data_gap is present so the user knows the 0
   is "we tried and failed" not "no data exists here". Hover shows reason. */
.v3d-layer-warn {
  margin-left: auto;
  font-size: 0.78rem;
  color: #f97316;
  flex-shrink: 0;
  padding-left: 6px;
  cursor: help;
}
.v3d-layer-warn + .v3d-layer-chev,
.v3d-layer-chev + .v3d-layer-warn { margin-left: 4px; }

/* Collapsible sub-toggle groups (Drillholes, Heritage, Deposits, Environmental, Roads/rail/power). */
.v3d-layer-chev {
  margin-left: auto;
  color: #64748b;
  font-size: 0.7rem;
  padding: 0 4px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
.v3d-layer-chev:hover { color: #d7b56d; }
.v3d-layer-sub {
  margin-left: 18px;
  padding-left: 8px;
  border-left: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: 2px;
  margin-bottom: 4px;
}
.v3d-layer-sub label {
  font-size: 0.72rem;
  color: #94a3b8;
  padding: 2px 0;
}
.v3d-layer-sub label:hover { color: #cbd5e1; }
.v3d-layer-sub .v3d-layer-swatch {
  width: 8px;
  height: 8px;
}
/* Rows for entities not yet rendered — visible in panel as a roadmap. */
.v3d-layers-body label.coming {
  color: #475569;
  cursor: not-allowed;
  opacity: 0.55;
}
.v3d-layers-body label.coming input[type="checkbox"] { cursor: not-allowed; }
.v3d-layers-body label.coming .v3d-layer-swatch { opacity: 0.4; }
.v3d-layers-body label.coming::after {
  content: ' soon';
  font-size: 0.62rem;
  color: #64748b;
  font-style: italic;
  margin-left: auto;
  flex-shrink: 0;
}
/* User-data layer rows (CSV uploads) — cyan accent + remove (×) button */
.v3d-layer-group.user-data {
  border-left: 2px solid #06b6d4;
  padding-left: 6px;
  margin-bottom: 4px;
}
.v3d-layer-group.user-data .v3d-layer-group-title {
  color: #06b6d4;
}
.v3d-user-layer-remove {
  margin-left: auto;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.18);
  color: #cbd5e1;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.v3d-user-layer-remove:hover {
  background: rgba(248,113,113,0.18);
  border-color: #f87171;
  color: #fecaca;
}

/* ─── Mini-map PiP (top-right, beneath the action cluster) ────── */
.v3d-pip {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 180px;
  height: 180px;
  background: rgba(11,15,26,0.85);
  border: 1.5px solid rgba(215,181,109,0.35);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(6px);
  z-index: 15;
}
.v3d-pip-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 4px 4px 8px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.6px;
  color: #d7b56d;
  background: rgba(0,0,0,0.6);
  flex-shrink: 0;
}
.v3d-pip-toggle {
  background: transparent;
  border: 1px solid rgba(215,181,109,0.4);
  color: #d7b56d;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.v3d-pip-toggle:hover { background: rgba(215,181,109,0.18); }
.v3d-pip canvas {
  width: 100%;
  flex: 1;
  display: block;
  min-height: 0;
}
.v3d-pip.collapsed { height: auto; }
.v3d-pip.collapsed canvas { display: none; }

/* ─── Floating feature-detail card — anchors to clicked marker ─── */
/* JS sets `left` and `top` per frame to track the anchor's screen
   position; the transform offsets the card up + left so it sits
   centred above the anchor with a small gap. A CSS triangle tail
   points down to the anchor point. */
.v3d-detail {
  position: absolute;
  left: 0;
  top: 0;
  width: 280px;
  max-height: 40vh;
  background: rgba(11,15,26,0.94);
  border: 1px solid rgba(215,181,109,0.30);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  z-index: 25;
  opacity: 0;
  transform: translate(-50%, calc(-100% - 14px));
  pointer-events: none;
  transition: opacity 180ms ease;
  display: flex;
  flex-direction: column;
  overflow: visible;
}
.v3d-detail.on {
  opacity: 1;
  pointer-events: auto;
}
.v3d-detail.off-screen {
  opacity: 0 !important;
  pointer-events: none !important;
}
/* Tail — small diamond pointing down to the anchor */
.v3d-detail::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 12px;
  height: 12px;
  background: rgba(11,15,26,0.94);
  border-right: 1px solid rgba(215,181,109,0.30);
  border-bottom: 1px solid rgba(215,181,109,0.30);
  transform: translateX(-50%) rotate(45deg);
}
.v3d-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.v3d-detail-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 10px;
  background: #d7b56d;
  color: #0b0f1a;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.4px;
}
.v3d-detail-close {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.18);
  color: #cbd5e1;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.v3d-detail-close:hover { background: rgba(255,255,255,0.10); }
.v3d-detail-body {
  padding: 12px 14px;
  overflow-y: auto;
  font-size: 0.82rem;
  color: #e2e8f0;
}
.v3d-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.v3d-detail-row:last-child { border-bottom: none; }
/* Data source attribution row — slightly muted so it doesn't compete with
   the substantive fields above, but still readable for citation use. */
.v3d-detail-row.v3d-detail-source {
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.08);
  border-bottom: none;
  font-size: 0.7rem;
  opacity: 0.75;
}
.v3d-detail-row.v3d-detail-source .v3d-detail-value {
  font-style: italic;
  color: #cbd5e1;
}
.v3d-detail-label {
  color: #94a3b8;
  font-size: 0.74rem;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.v3d-detail-value {
  color: #f7f7fb;
  text-align: right;
  word-break: break-word;
}
.v3d-detail-empty {
  color: #94a3b8;
  font-style: italic;
  text-align: center;
  padding: 20px 0;
}

/* ─── Centered status card (errors + loading messages) ──────── */
.v3d-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, calc(-50% + 8px));
  max-width: 520px;
  background: rgba(11,15,26,0.94);
  border: 1px solid rgba(215,181,109,0.35);
  border-radius: 12px;
  padding: 14px 22px;
  backdrop-filter: blur(6px);
  font-size: 0.9rem;
  color: #cbd5e1;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: center;
}
.v3d-toast.show {
  opacity: 1;
  transform: translate(-50%, -50%);
}
.v3d-toast.loading {
  flex-direction: column;
  padding: 28px 36px;
  gap: 16px;
}
.v3d-toast-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(215,181,109,0.20);
  border-top-color: #d7b56d;
  border-radius: 50%;
  animation: v3dSpin 0.85s linear infinite;
}
@keyframes v3dSpin {
  to { transform: rotate(360deg); }
}

/* ─── Tour caption (centered above bottom) ───────────────────── */
.v3d-tour-caption {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(11,15,26,0.94);
  border: 1.5px solid #d7b56d;
  color: #fff;
  padding: 14px 32px;
  border-radius: 14px;
  font-size: 0.95rem;
  max-width: 70%;
  text-align: center;
  font-weight: 500;
  letter-spacing: 0.2px;
  z-index: 100;
  display: none;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  pointer-events: none;
}
.v3d-tour-caption.on { display: block; animation: v3dTourFade 0.4s ease; }
@keyframes v3dTourFade {
  from { opacity: 0; transform: translate(-50%, -14px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ─── Chat — always-visible ask bar at bottom-center; panel rises above ── */
.v3d-ask-bar {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: min(700px, calc(100vw - 32px));
  background: rgba(11,15,26,0.94);
  border: 1px solid rgba(215,181,109,0.35);
  border-radius: 999px;
  padding: 6px 6px 6px 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(6px);
  z-index: 1015;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
.v3d-ask-bar:focus-within {
  border-color: rgba(215,181,109,0.7);
  box-shadow: 0 8px 30px rgba(215,181,109,0.25);
}
.v3d-ask-bar .v3d-chat-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  padding: 8px 0;
  font-family: inherit;
  font-size: 0.92rem;
  outline: none;
}
.v3d-ask-bar .v3d-chat-input::placeholder { color: #94a3b8; }
.v3d-ask-bar .v3d-chat-send {
  background: linear-gradient(135deg, #d7b56d, #b8944a);
  border: none;
  color: #0b0f1a;
  padding: 8px 18px;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s, box-shadow 0.12s;
}
.v3d-ask-bar .v3d-chat-send:hover {
  transform: scale(1.04);
  box-shadow: 0 4px 12px rgba(215,181,109,0.45);
}
.v3d-ask-bar .v3d-chat-mic {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.18);
  color: #94a3b8;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.v3d-ask-bar .v3d-chat-mic:hover { color: #f7f7fb; border-color: rgba(255,255,255,0.4); }
.v3d-ask-bar .v3d-chat-mic.on {
  color: #fecaca;
  border-color: #f87171;
  background: rgba(248,113,113,0.18);
  animation: v3dMicPulse 1.2s ease-in-out infinite;
}
@keyframes v3dMicPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248,113,113,0.5); }
  50%      { box-shadow: 0 0 0 8px rgba(248,113,113,0); }
}

.v3d-chat-panel {
  position: fixed;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%);
  width: min(820px, calc(100vw - 32px));
  height: 480px;
  max-height: 60vh;
  max-height: 60dvh;
  background: #0b0f1a;
  border: 1.5px solid rgba(215,181,109,0.4);
  border-radius: 14px;
  display: none;
  flex-direction: column;
  z-index: 1020;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  font-family: Inter, sans-serif;
  overflow: hidden;
}
.v3d-chat-panel.on { display: flex; }
.v3d-chat-header {
  padding: 12px 16px;
  background: linear-gradient(180deg, #151b2a, #0b0f1a);
  border-bottom: 1px solid rgba(215,181,109,0.18);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: #d7b56d;
  letter-spacing: 0.4px;
}
.v3d-chat-header-close {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 6px;
}
.v3d-chat-header-close:hover { color: #fff; }
.v3d-chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 0.86rem;
  line-height: 1.5;
}
.v3d-chat-history::-webkit-scrollbar { width: 6px; }
.v3d-chat-history::-webkit-scrollbar-thumb { background: rgba(215,181,109,0.25); border-radius: 3px; }
.v3d-chat-msg { max-width: 88%; padding: 9px 13px; border-radius: 10px; word-wrap: break-word; }
.v3d-chat-msg.user {
  align-self: flex-end;
  background: rgba(96,165,250,0.14);
  border: 1px solid rgba(96,165,250,0.3);
  color: #e0e7ff;
}
.v3d-chat-msg.bot {
  align-self: flex-start;
  background: rgba(215,181,109,0.08);
  border: 1px solid rgba(215,181,109,0.25);
  color: #f7f7fb;
}
.v3d-chat-msg.bot .ai-badge {
  font-size: 9px;
  letter-spacing: 0.8px;
  font-weight: 700;
  color: #d7b56d;
  margin-right: 6px;
}
.v3d-chat-md { display: inline; }
.v3d-chat-md ul { margin: 6px 0; padding-left: 20px; }
.v3d-chat-md li { margin: 2px 0; }
.v3d-chat-md code {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86em;
}
.v3d-chat-md strong { color: #f7f7fb; font-weight: 700; }
.v3d-chat-md em { color: #cbd5e1; font-style: italic; }
.v3d-chat-md ol { margin: 6px 0; padding-left: 22px; }
.v3d-chat-md .v3d-chat-h {
  font-family: inherit;
  color: #d7b56d;
  font-weight: 700;
  margin: 12px 0 4px;
  letter-spacing: 0.2px;
  line-height: 1.3;
}
.v3d-chat-md h3.v3d-chat-h { font-size: 0.96rem; }
.v3d-chat-md h4.v3d-chat-h { font-size: 0.88rem; color: #f7f7fb; }
.v3d-chat-md h5.v3d-chat-h { font-size: 0.82rem; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.5px; }
.v3d-chat-md .v3d-chat-h:first-child { margin-top: 4px; }
.v3d-chat-md .v3d-chat-hr {
  border: none;
  border-top: 1px solid rgba(215,181,109,0.18);
  margin: 10px 0;
}
.v3d-chat-md .v3d-chat-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 0.78rem;
  background: rgba(255,255,255,0.02);
  border-radius: 6px;
  overflow: hidden;
}
.v3d-chat-md .v3d-chat-table th {
  text-align: left;
  padding: 6px 9px;
  background: rgba(215,181,109,0.10);
  color: #d7b56d;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(215,181,109,0.20);
}
.v3d-chat-md .v3d-chat-table td {
  padding: 5px 9px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: #e2e8f0;
  vertical-align: top;
}
.v3d-chat-md .v3d-chat-table tr:last-child td { border-bottom: none; }
.v3d-chat-md .v3d-chat-holeid {
  color: #ffd700;
  background: rgba(255,215,0,0.10);
  padding: 1px 5px;
  border-radius: 3px;
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px dashed rgba(255,215,0,0.5);
}
.v3d-chat-md .v3d-chat-holeid:hover {
  background: rgba(255,215,0,0.22);
  color: #fff8d2;
}
.v3d-chat-followups {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed rgba(255,255,255,0.10);
}
.v3d-chat-followup-pill {
  background: rgba(96,165,250,0.10);
  border: 1px solid rgba(96,165,250,0.35);
  color: #bfdbfe;
  padding: 5px 11px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
}
.v3d-chat-followup-pill:hover {
  background: rgba(96,165,250,0.22);
  border-color: rgba(96,165,250,0.6);
  color: #e0e7ff;
}
.v3d-chat-typing {
  display: inline-block;
  color: #d7b56d;
  animation: v3dTypingPulse 1.2s ease-in-out infinite;
}
@keyframes v3dTypingPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}
.v3d-chat-msg.bot .show3d-btn {
  display: block;
  margin-top: 8px;
  background: rgba(96,165,250,0.18);
  border: 1px solid rgba(96,165,250,0.5);
  color: #bfdbfe;
  padding: 5px 11px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  font-weight: 600;
}
.v3d-chat-msg.bot .show3d-btn:hover { background: rgba(96,165,250,0.3); }
.v3d-chat-input-row {
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  gap: 8px;
}
.v3d-chat-input {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  padding: 8px 11px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}
.v3d-chat-input:focus { border-color: #d7b56d; }
.v3d-chat-send {
  background: rgba(215,181,109,0.22);
  border: 1px solid rgba(215,181,109,0.5);
  color: #d7b56d;
  padding: 8px 14px;
  border-radius: 6px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}
.v3d-chat-send:hover { background: rgba(215,181,109,0.35); }
.v3d-chat-suggestions {
  padding: 0 16px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.v3d-chat-suggest-pill {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.15);
  color: #94a3b8;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.74rem;
  cursor: pointer;
  font-family: inherit;
}
.v3d-chat-suggest-pill:hover { color: #d7b56d; border-color: rgba(215,181,109,0.4); }

/* ─── Touch tablets (iPad portrait + landscape) ──────────────────
   Coarse-pointer / no-hover devices up to 1024px wide.
   Goals: 44px tap targets, 16px input font (no iOS zoom-on-focus),
   safe-area insets so fixed chat bar isn't hidden by Safari toolbar,
   dvh so dynamic toolbars don't crop scrollable panels. */
@media (max-width: 1024px) and (pointer: coarse), (max-width: 1024px) and (hover: none) {
  .v3d-action-btn,
  .v3d-close { padding: 11px 16px; font-size: 0.86rem; }
  .v3d-bucket-chip { padding: 9px 14px; font-size: 0.82rem; }
  .v3d-help-q { width: 36px; height: 36px; font-size: 0.95rem; }

  .v3d-layers-toggle,
  .v3d-pip-toggle,
  .v3d-user-layer-remove { width: 32px; height: 32px; font-size: 15px; border-radius: 6px; }
  .v3d-detail-close { width: 36px; height: 36px; font-size: 18px; border-radius: 6px; }

  .v3d-ask-bar { padding: 6px 6px 6px 16px; }
  .v3d-ask-bar .v3d-chat-mic { width: 44px; height: 44px; font-size: 16px; }
  .v3d-ask-bar .v3d-chat-send { padding: 11px 22px; font-size: 0.9rem; }
  .v3d-ask-bar .v3d-chat-input { font-size: 16px; padding: 10px 0; }
  .v3d-chat-input { font-size: 16px; padding: 10px 12px; }
  .v3d-chat-send { padding: 10px 16px; }

  .v3d-layer-chev { padding: 6px 10px; font-size: 0.85rem; }
  .v3d-layers-body label { padding: 8px 0; font-size: 0.84rem; gap: 10px; }
  .v3d-layer-sub label { padding: 6px 0; font-size: 0.8rem; }
  .v3d-layer-group-title { font-size: 10px; padding-top: 8px; }
  .v3d-layer-count { font-size: 0.78rem; }
  .v3d-layer-swatch { width: 12px; height: 12px; }
  .v3d-layer-sub .v3d-layer-swatch { width: 10px; height: 10px; }
  .v3d-layers-body input[type="checkbox"] { width: 18px; height: 18px; }

  /* Honour iOS safe-area for fixed bottom panels */
  .v3d-ask-bar { bottom: max(18px, calc(env(safe-area-inset-bottom) + 12px)); }
  .v3d-chat-panel { bottom: max(78px, calc(env(safe-area-inset-bottom) + 70px)); }

  .v3d-chat-panel { height: min(480px, 60dvh); }
}

/* iPad portrait squeeze (≤900px wide): shrink top cluster + side panels
   so layers-panel + bucket-toggle + actions don't collide. */
@media (max-width: 900px) {
  .v3d-actions { top: 12px; right: 12px; gap: 6px; }
  .v3d-action-btn,
  .v3d-close { padding: 9px 12px; font-size: 0.78rem; }
  .v3d-top-center { top: 12px; gap: 8px; }
  .v3d-bucket-toggle { padding: 3px; gap: 2px; }
  .v3d-bucket-chip { padding: 8px 11px; font-size: 0.74rem; }
  .v3d-layers-panel { width: 200px; top: 12px; left: 12px; }
  .v3d-pip { width: 140px; height: 140px; bottom: 14px; right: 14px; }
  .v3d-detail { width: 260px; max-height: 50vh; max-height: 50dvh; }
  .v3d-tour-caption { font-size: 0.85rem; padding: 12px 18px; max-width: 86%; }
}

/* iPad Mini portrait + small tablets (≤780px): tightest packing — there
   isn't room for layers-panel | bucket-toggle | actions on a single row,
   so drop the top-center cluster down to a second row below the actions.
   Layers panel narrows to leave the canvas usable. */
@media (max-width: 780px) {
  .v3d-action-btn,
  .v3d-close { padding: 8px 10px; font-size: 0.72rem; letter-spacing: 0.2px; }
  .v3d-actions { gap: 4px; }
  .v3d-bucket-toggle { padding: 2px; }
  .v3d-bucket-chip { padding: 6px 10px; font-size: 0.7rem; letter-spacing: 0; }
  .v3d-top-center { top: 60px; gap: 6px; }
  .v3d-help-q { width: 30px; height: 30px; font-size: 0.85rem; }
  .v3d-layers-panel { width: 180px; }
  .v3d-pip { width: 120px; height: 120px; }
}
