/* =============================================================================
   Connect Shell — Wave 3 DEV-1 (additive, frontend-only)
   3-pane, dual-mode, offset-aware messaging shell for messaging-hub.html.

   - Height = calc(100vh - var(--app-header-offset)) (NOT h-screen) so it sits
     flush below the shared header in standalone mode and flush to the top of
     the dashboard iframe when embedded (--app-header-offset = 0).
   - Gold brand tokens (var(--marriage-gold) / var(--love-pink)); text/icons on
     light surfaces use --marriage-gold-700 via a11y.css .gold-text/.gold-icon.
   - Drawers (Column C / image / video / family) are offset-aware: position:static
     or display:none under html.page-mode-embedded so they NEVER float over the
     dashboard chrome. Re-keyed away from `fixed inset-0 z-50`.
   ============================================================================= */

/* ---- Outer shell --------------------------------------------------------- */
.connect-shell {
  display: flex;
  height: calc(100vh - var(--app-header-offset, 4rem));
  min-height: 0;            /* allow inner panes to scroll, not the page */
  overflow: hidden;
  background: var(--surface-1, #f9fafb);
}
.dark .connect-shell { background: #0f172a; }

/* Column A — conversation list rail (320px, independently scrolling) */
.connect-rail {
  width: 20rem;            /* 320px */
  flex: 0 0 20rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 0.0625rem solid var(--border-1, #e5e7eb);
  background: #ffffff;
}
.dark .connect-rail { background: #1f2937; border-right-color: #374151; }

.connect-rail__head { flex: 0 0 auto; }
.connect-rail__list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;        /* the rail scrolls independently */
}

/* Column B — thread pane (the only viewport-anchored scroll region) */
.connect-thread {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.connect-thread__head { flex: 0 0 auto; }
.connect-thread__messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;        /* ONLY this region scrolls in the thread column */
}
.connect-thread__composer { flex: 0 0 auto; }   /* pinned offset-aware, NOT position:fixed */

/* Column C — progressive context drawer (docked on wide standalone) */
.connect-drawer {
  width: 20rem;
  flex: 0 0 20rem;
  border-left: 0.0625rem solid var(--border-1, #e5e7eb);
  background: #ffffff;
  overflow-y: auto;
  min-height: 0;
}
.dark .connect-drawer { background: #1f2937; border-left-color: #374151; }

/* ---- Brand: gold message bubbles + active states ------------------------- */
/* Override the legacy off-brand orange/purple gradients (messaging-hub.css). */
.message-sent {
  background: linear-gradient(135deg, var(--love-pink-500, #ec4899), var(--marriage-gold-500, #d4af37)) !important;
  color: #ffffff;
}
.message-received {
  background: var(--surface-2, #f3f4f6) !important;
  backdrop-filter: none !important;
  border: 0.0625rem solid var(--border-1, #e5e7eb) !important;
  color: var(--text-1, #111827);
}
.dark .message-received {
  background: rgba(255, 255, 255, 0.06) !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
  color: #f3f4f6;
}
.conversation-item:hover {
  background-color: var(--marriage-gold-100, #fef3c7) !important;
  transform: none !important;       /* no horizontal jitter — keeps rows ≤56px stable */
}
.dark .conversation-item:hover { background-color: rgba(212, 175, 55, 0.12) !important; }
.conversation-item.active {
  background: var(--marriage-gold-100, #fef3c7) !important;
  border-left: 0.25rem solid var(--marriage-gold-500, #d4af37) !important;
}
.dark .conversation-item.active {
  background: rgba(212, 175, 55, 0.16) !important;
}

/* Encryption / TLS pill -> calm gold-on-light instead of green gradient */
.connect-shell .encryption-indicator {
  background: var(--marriage-gold-100, #fef3c7);
  color: var(--marriage-gold-700, #b8860b);
}
.dark .connect-shell .encryption-indicator {
  background: rgba(212, 175, 55, 0.16);
  color: var(--marriage-gold-300, #fbbf24);
}

/* ---- Density (QA target: rows ≤56px, ≥8 visible above the fold) ---------- */
.conversation-item { padding-top: 0.625rem; padding-bottom: 0.625rem; }

/* ---- Drawer primitive (offset-aware, focus-trapped) ---------------------- */
/* Used by image / video / family drawers. Standalone: slide-in sheet anchored
   below the shared header (top: var(--app-header-offset)). Embedded: position
   static / collapsed so it never floats over the dashboard chrome. */
.connect-sheet {
  position: fixed;
  top: var(--app-header-offset, 4rem);
  right: 0;
  bottom: 0;
  width: min(28rem, 100%);
  max-width: 100%;
  background: #ffffff;
  box-shadow: -0.5rem 0 1.5rem rgba(0, 0, 0, 0.18);
  z-index: 40;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--motion-base, 0.2s) var(--ease-decelerate, ease);
}
.dark .connect-sheet { background: #1f2937; }
.connect-sheet.is-open { transform: translateX(0); }
.connect-sheet[hidden] { display: none; }

.connect-sheet__backdrop {
  position: fixed;
  top: var(--app-header-offset, 4rem);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 39;
}
.connect-sheet__backdrop[hidden] { display: none; }

.connect-sheet__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 0.0625rem solid var(--border-1, #e5e7eb);
}
.dark .connect-sheet__head { border-bottom-color: #374151; }
.connect-sheet__body { flex: 1 1 auto; overflow-y: auto; padding: 1.25rem; }
.connect-sheet__foot {
  flex: 0 0 auto;
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 0.0625rem solid var(--border-1, #e5e7eb);
}
.dark .connect-sheet__foot { border-top-color: #374151; }

/* Image drawer fills its sheet with a dark stage */
.connect-sheet--image .connect-sheet__body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111827;
}

/* ---- EMBEDDED MODE: nothing floats over the dashboard iframe -------------- */
html.page-mode-embedded .connect-sheet,
html.page-mode-embedded .connect-sheet__backdrop {
  position: static;
  top: auto;
  transform: none;
  width: 100%;
  max-width: 100%;
  box-shadow: none;
  z-index: auto;
}
/* A closed sheet stays hidden; an open one renders in-flow (never an overlay). */
html.page-mode-embedded .connect-sheet:not(.is-open) { display: none; }
html.page-mode-embedded .connect-sheet__backdrop { display: none; }

/* ---- Jump-to-latest control --------------------------------------------- */
.connect-jump-latest {
  position: absolute;
  bottom: 5.5rem;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  border-radius: 9999px;
  background: var(--marriage-gold-500, #d4af37);
  color: #ffffff;
  font-size: 0.8125rem;
  font-weight: 600;
  box-shadow: 0 0.375rem 1rem rgba(0, 0, 0, 0.2);
  border: none;
  cursor: pointer;
  z-index: 5;
}
.connect-jump-latest[hidden] { display: none; }

/* ---- SR-only message prefix (sender + time, read before the body) -------- */
.connect-msg-srprefix {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Responsive: rail collapse keyed to the SHELL container (768px) ------ */
/* Wide standalone keeps all 3 columns. The slide-in sheet handles the drawer
   below 768px; the JS toggles a single-column class for the iframe / narrow. */
@container connect (max-width: 768px) {
  .connect-drawer { display: none; }
}

/* Embedded mode is single-column always, regardless of width. */
html.page-mode-embedded .connect-drawer { display: none; }

/* Mobile-first stack (window-level fallback where container queries are off) */
@media (max-width: 768px) {
  .connect-shell.is-thread-open .connect-rail { display: none; }
  .connect-shell:not(.is-thread-open) .connect-thread { display: none; }
}

/* ---- Composer template picker (Wave 3 DEV-2) ----------------------------- */
/* Anchored above the composer toolbar button; opens upward so it never needs
   to float over the dashboard chrome. Stays in the composer's stacking context
   (the wrapping .relative), so embedded mode needs no special handling. */
.connect-template-picker {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 0;
  width: 22rem;
  max-width: min(22rem, 85vw);
  max-height: 20rem;
  overflow-y: auto;
  background: #ffffff;
  border: 0.0625rem solid var(--border-1, #e5e7eb);
  border-radius: 0.75rem;
  box-shadow: 0 0.75rem 2rem rgba(0, 0, 0, 0.18);
  z-index: 30;
  padding: 0.5rem;
}
.dark .connect-template-picker {
  background: #1f2937;
  border-color: #374151;
}
.connect-template-picker[hidden] { display: none; }

.connect-template-picker__group {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--marriage-gold-700, #b8860b);
  padding: 0.5rem 0.5rem 0.25rem;
}

.connect-template-picker__item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem;
  border-radius: 0.5rem;
  background: transparent;
  border: none;
  cursor: pointer;
}
.connect-template-picker__item:hover,
.connect-template-picker__item:focus-visible {
  background: var(--marriage-gold-100, #fef3c7);
}
.dark .connect-template-picker__item:hover,
.dark .connect-template-picker__item:focus-visible {
  background: rgba(212, 175, 55, 0.14);
}
.connect-template-picker__item-title {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-1, #111827);
}
.dark .connect-template-picker__item-title { color: #f3f4f6; }
.connect-template-picker__item-preview {
  display: block;
  font-size: 0.75rem;
  color: var(--text-2, #6b7280);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ---- AstroMatchCard (Wave 3 DEV-3) --------------------------------------- */
/* In-thread Guna-Milan / kundali compatibility trust signal, docked first in
   the Column C context drawer. Gold brand; semantic level color via the
   --astro-level-color custom prop set inline from getCompatibilityLevel. */
.astro-match-card {
  border: 0.0625rem solid var(--marriage-gold-200, #fde68a);
  border-radius: 0.75rem;
  background: var(--marriage-gold-50, #fffbeb);
  padding: 0.875rem;
  margin-bottom: 1rem;
}
.dark .astro-match-card {
  background: rgba(212, 175, 55, 0.08);
  border-color: rgba(212, 175, 55, 0.28);
}
.astro-match-card__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.astro-match-card__title {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--marriage-gold-700, #b8860b);
}
.dark .astro-match-card__title { color: var(--marriage-gold-300, #fbbf24); }

.astro-match-card__score {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}
.astro-match-card__ring {
  flex: 0 0 auto;
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 9999px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 0.25rem solid var(--astro-level-color, var(--marriage-gold-500, #d4af37));
  background: #ffffff;
}
.dark .astro-match-card__ring { background: #1f2937; }
.astro-match-card__pct {
  font-size: 1.125rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text-1, #111827);
}
.dark .astro-match-card__pct { color: #f3f4f6; }
.astro-match-card__guna {
  font-size: 0.5625rem;
  color: var(--text-2, #6b7280);
  margin-top: 0.125rem;
}
.astro-match-card__level { font-weight: 700; font-size: 0.9375rem; }
.astro-match-card__sub {
  display: block;
  font-size: 0.75rem;
  color: var(--text-2, #6b7280);
}
.astro-match-card__muted {
  font-size: 0.8125rem;
  color: var(--text-2, #6b7280);
  margin-bottom: 0.625rem;
}

.astro-match-card__toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin-top: 0.75rem;
  padding: 0.25rem 0;
  background: none;
  border: none;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--marriage-gold-700, #b8860b);
  cursor: pointer;
}
.dark .astro-match-card__toggle { color: var(--marriage-gold-300, #fbbf24); }

.astro-match-card__doshas {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}
.astro-match-card__doshas[hidden] { display: none; }
.astro-match-card__doshas li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.375rem 0;
  border-top: 0.0625rem solid var(--marriage-gold-200, #fde68a);
  font-size: 0.8125rem;
}
.dark .astro-match-card__doshas li { border-top-color: rgba(212, 175, 55, 0.22); }
.astro-dosha-name { color: var(--text-1, #111827); }
.dark .astro-dosha-name { color: #f3f4f6; }
.astro-dosha-status { color: var(--text-2, #6b7280); font-weight: 600; }

.astro-match-card__cta {
  display: block;
  text-align: center;
  margin-top: 0.875rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 700;
  color: #ffffff;
  text-decoration: none;
  background: linear-gradient(135deg, var(--love-pink-500, #ec4899), var(--marriage-gold-500, #d4af37));
}
.astro-match-card__cta:hover { filter: brightness(1.04); }

/* Skeleton placeholders (loading state — never a bare spinner) */
.astro-skel {
  background: linear-gradient(90deg, rgba(0,0,0,0.06) 25%, rgba(0,0,0,0.12) 37%, rgba(0,0,0,0.06) 63%);
  background-size: 400% 100%;
  animation: astroSkel 1.4s ease infinite;
  border-radius: 0.375rem;
}
.dark .astro-skel {
  background: linear-gradient(90deg, rgba(255,255,255,0.06) 25%, rgba(255,255,255,0.12) 37%, rgba(255,255,255,0.06) 63%);
  background-size: 400% 100%;
}
.astro-skel--ring { width: 4.5rem; height: 4.5rem; border-radius: 9999px; margin-bottom: 0.75rem; }
.astro-skel--line { height: 0.75rem; margin-bottom: 0.5rem; }
.astro-skel--short { width: 60%; }
@keyframes astroSkel { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) {
  .astro-skel { animation: none; }
}

/* ---- Reduced motion (a11y.css owns the global rule; belt-and-suspenders) -- */
@media (prefers-reduced-motion: reduce) {
  .connect-sheet { transition: none; }
}
