/* ============================================
   CASSY PAGE
   Conversation on the left, what Cassy knows and how results are sorted on
   the right. On a phone everything stacks, the conversation first.
   Uses the shared brand tokens from theme.css. Mobile first.
   ============================================ */

.cassy { background: linear-gradient(180deg, var(--brand-soft, #f4effe) 0, #fff 340px); min-height: 70vh; }
.cassy-container { width: 100%; max-width: 1140px; margin: 0 auto; padding: 0 16px; }
.cassy-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header */
.cassy-hero { padding: 24px 0 8px; }
.cassy-hero-inner { display: flex; align-items: center; gap: 14px; }
.cassy-avatar { width: 56px; height: auto; flex: none; }
.cassy-title { font-size: clamp(24px, 5vw, 36px); margin: 0 0 4px; color: var(--brand-ink, #1f1636); }
.cassy-sub { margin: 0; color: var(--text-medium, #4b4266); font-size: 16px; line-height: 1.5; max-width: 620px; }

/* Layout */
.cassy-layout { display: grid; gap: 16px; padding-bottom: 40px; padding-top: 12px; }
.cassy-main { min-width: 0; }

.cassy-card { background: #fff; border: 1px solid rgba(91, 47, 184, 0.14); border-radius: 20px; box-shadow: var(--shadow-md, 0 6px 18px rgba(63, 31, 134, 0.1)); padding: 16px; }

/* Safety banner */
.cassy-safety { border-radius: 14px; padding: 14px 16px; margin-bottom: 12px; border: 2px solid #c0392b; background: #fdecea; color: #5a1410; }
.cassy-safety[data-kind="crisis"] { border-color: #b7791f; background: #fff7e6; color: #5a3a06; }
.cassy-safety strong { display: block; font-size: 17px; margin-bottom: 4px; }
.cassy-safety a { color: inherit; font-weight: 700; }

/* Sign-in gate */
.cassy-gate { border: 1px solid rgba(91, 47, 184, 0.2); background: var(--brand-soft, #f4effe); border-radius: 16px; padding: 16px; margin-bottom: 12px; }
.cassy-gate h2 { margin: 0 0 4px; font-size: 18px; }
.cassy-gate p { margin: 0 0 12px; color: var(--text-medium, #4b4266); line-height: 1.5; }
.cassy-gate-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* Buttons */
.cassy-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 20px; border-radius: 12px; font-weight: 700; font-size: 16px; text-decoration: none; border: 1.5px solid transparent; cursor: pointer; }
.cassy-btn-primary { background: var(--brand, #5b2fb8); color: #fff; }
.cassy-btn-primary:hover { background: var(--brand-dark, #3f1f86); }
.cassy-btn-primary[disabled] { opacity: 0.6; cursor: not-allowed; }
.cassy-btn-secondary { background: #fff; color: var(--brand, #5b2fb8); border-color: var(--brand, #5b2fb8); }
.cassy-link { background: none; border: none; color: var(--brand, #5b2fb8); font-weight: 700; text-decoration: underline; cursor: pointer; padding: 8px 4px; font-size: 15px; }

/* Thread */
.cassy-thread { display: flex; flex-direction: column; gap: 12px; max-height: 520px; overflow-y: auto; padding: 4px 2px 8px; scroll-behavior: smooth; }
.cassy-msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.cassy-msg-user { justify-content: flex-end; }
.cassy-msg-who img { width: 28px; height: auto; display: block; }
.cassy-bubble { padding: 12px 14px; border-radius: 18px; line-height: 1.55; font-size: 16px; max-width: 88%; overflow-wrap: anywhere; }
.cassy-msg-assistant .cassy-bubble { background: var(--brand-soft, #f4effe); color: var(--brand-ink, #1f1636); border-bottom-left-radius: 6px; }
.cassy-msg-user .cassy-bubble { background: var(--brand, #5b2fb8); color: #fff; border-bottom-right-radius: 6px; }
.cassy-typing { display: inline-flex; gap: 4px; padding: 14px 16px; }
.cassy-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--brand-light, #7c5cd6); animation: cassyBounce 1.2s infinite ease-in-out; }
.cassy-typing span:nth-child(2) { animation-delay: 0.15s; }
.cassy-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cassyBounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.5; } 40% { transform: translateY(-5px); opacity: 1; } }

/* Starter cards and quick replies */
.cassy-starters { display: grid; grid-template-columns: 1fr; gap: 8px; margin: 12px 0 4px; }
.cassy-starter { display: flex; align-items: center; gap: 10px; text-align: left; min-height: 52px; padding: 10px 14px; background: #fff; border: 1.5px solid rgba(91, 47, 184, 0.22); border-radius: 14px; color: var(--brand-ink, #1f1636); font-weight: 700; font-size: 15px; cursor: pointer; }
.cassy-starter svg { color: var(--brand, #5b2fb8); flex: none; }
.cassy-starter:hover { border-color: var(--brand, #5b2fb8); background: var(--brand-soft, #f4effe); }
.cassy-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 2px; }
.cassy-chip { min-height: 40px; padding: 8px 16px; border-radius: 999px; border: 1.5px solid var(--brand, #5b2fb8); background: #fff; color: var(--brand, #5b2fb8); font-weight: 700; font-size: 15px; cursor: pointer; }
.cassy-chip:hover { background: var(--brand-soft, #f4effe); }
.cassy-question { margin: 10px 0 0; font-weight: 700; color: var(--brand-ink, #1f1636); }

/* Input */
.cassy-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 12px; }
.cassy-form textarea { flex: 1; min-width: 0; resize: none; min-height: 48px; max-height: 140px; padding: 12px 14px; border: 1.5px solid rgba(91, 47, 184, 0.25); border-radius: 14px; font-size: 16px; line-height: 1.4; font-family: inherit; }
.cassy-form textarea:focus { outline: 3px solid rgba(91, 47, 184, 0.3); border-color: var(--brand, #5b2fb8); }
.cassy-privacy { margin: 10px 0 0; font-size: 13px; color: var(--text-light, #6b6385); line-height: 1.5; }

/* Results */
.cassy-results { margin-top: 20px; }
.cassy-results-title { font-size: 22px; margin: 0 0 4px; }
.cassy-tier { margin-top: 20px; }
.cassy-tier-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 10px; }
.cassy-tier-name { font-size: 18px; margin: 0; }
.cassy-tier-hint { font-size: 14px; color: var(--text-light, #6b6385); }
.cassy-tier[data-tier="tier1"] .cassy-tier-name::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--brand, #5b2fb8); margin-right: 8px; }
.cassy-tier[data-tier="tier2"] .cassy-tier-name::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #d89b2b; margin-right: 8px; }
.cassy-tier[data-tier="tier3"] .cassy-tier-name::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #9a93b3; margin-right: 8px; }
.cassy-cards { display: grid; grid-template-columns: 1fr; gap: 12px; }

.cassy-result { background: #fff; border: 1px solid rgba(91, 47, 184, 0.16); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.cassy-result-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.cassy-result-title { font-size: 18px; margin: 0; line-height: 1.3; }
.cassy-result-title a { color: var(--brand-ink, #1f1636); text-decoration: none; }
.cassy-result-title a:hover { color: var(--brand, #5b2fb8); text-decoration: underline; }
.cassy-tag { display: inline-block; font-size: 12px; font-weight: 700; color: var(--brand, #5b2fb8); background: var(--brand-soft, #f4effe); padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.cassy-result-summary { margin: 0; color: var(--text-medium, #4b4266); line-height: 1.55; font-size: 15px; }
.cassy-why { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.cassy-why li { font-size: 14px; color: var(--brand-ink, #1f1636); padding-left: 24px; position: relative; line-height: 1.45; }
.cassy-why li::before { content: ""; position: absolute; left: 2px; top: 3px; width: 14px; height: 14px; background: var(--brand, #5b2fb8); mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 5 5L20 7'/%3E%3C/svg%3E") center / contain no-repeat; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 5 5L20 7'/%3E%3C/svg%3E") center / contain no-repeat; }
.cassy-confirm { margin: 0; font-size: 13px; color: var(--text-light, #6b6385); background: #faf8ff; border-radius: 10px; padding: 8px 10px; line-height: 1.45; }
.cassy-confirm strong { color: var(--brand-ink, #1f1636); }
.cassy-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.cassy-actions .cassy-btn { min-height: 40px; padding: 8px 16px; font-size: 15px; }
.cassy-empty { padding: 18px; border: 1px dashed rgba(91, 47, 184, 0.3); border-radius: 14px; color: var(--text-medium, #4b4266); background: #faf8ff; }

/* Side column */
.cassy-side { display: grid; gap: 12px; align-content: start; }
.cassy-side-card { background: #fff; border: 1px solid rgba(91, 47, 184, 0.14); border-radius: 16px; padding: 16px; }
.cassy-side-title { font-size: 16px; margin: 0 0 10px; }
.cassy-profile { margin: 0; display: grid; gap: 8px; }
.cassy-profile div { display: grid; grid-template-columns: 110px 1fr; gap: 8px; font-size: 14px; }
.cassy-profile dt { color: var(--text-light, #6b6385); font-weight: 700; }
.cassy-profile dd { margin: 0; color: var(--brand-ink, #1f1636); }
.cassy-profile dd.is-empty { color: var(--text-lighter, #9a93b3); }
.cassy-reset { margin-top: 8px; padding-left: 0; }
.cassy-remember { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; font-size: 14px; font-weight: 600; }
.cassy-remember input { width: 18px; height: 18px; margin-top: 1px; flex: none; }
.cassy-sort { margin: 0 0 8px; padding-left: 18px; display: grid; gap: 8px; font-size: 14px; line-height: 1.45; color: var(--text-medium, #4b4266); }
.cassy-note { margin: 0; font-size: 13px; color: var(--text-light, #6b6385); }

@media (min-width: 640px) {
  .cassy-starters { grid-template-columns: repeat(2, 1fr); }
  .cassy-cards { grid-template-columns: repeat(2, 1fr); }
  .cassy-avatar { width: 72px; }
  .cassy-card { padding: 22px; }
}

@media (min-width: 960px) {
  .cassy-layout { grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; }
  .cassy-side { position: sticky; top: 84px; }
  .cassy-thread { max-height: 460px; }
}

/* While a search runs: a line in the chat and placeholder cards */
.cassy-results { scroll-margin-top: 84px; }
.cassy-results-title:focus { outline: none; }
.cassy-share { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.cassy-searching { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; }
.cassy-spinner { width: 18px; height: 18px; flex: none; border-radius: 50%; border: 3px solid rgba(91, 47, 184, 0.2); border-top-color: var(--brand, #5b2fb8); animation: cassySpin 0.9s linear infinite; }
@keyframes cassySpin { to { transform: rotate(360deg); } }
.cassy-skel { border-radius: 8px; background: linear-gradient(100deg, #efeaf9 30%, #f9f6ff 50%, #efeaf9 70%); background-size: 200% 100%; animation: cassyShimmer 1.4s linear infinite; }
@keyframes cassyShimmer { from { background-position: 180% 0; } to { background-position: -20% 0; } }
.cassy-skel-title { height: 20px; width: 70%; }
.cassy-skel-line { height: 13px; width: 100%; }
.cassy-skel-short { height: 13px; width: 55%; }
.cassy-skel-btn { height: 40px; width: 130px; border-radius: 12px; margin-top: 4px; }
.cassy-skel-card { min-height: 170px; }

/* The way from the chat to the results */
.cassy-matches { padding: 2px 0 2px 36px; }
.cassy-matches-btn { width: 100%; }
.cassy-tier { animation: cassyRise 0.3s ease both; }
@keyframes cassyRise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* The bubble: shows only when the chat has scrolled away */
.cassy-fab { position: fixed; right: 16px; bottom: calc(65px + env(safe-area-inset-bottom, 0px) + 14px); width: 62px; height: 62px; padding: 0; border-radius: 50%; background: #fff; border: 2px solid var(--brand, #5b2fb8); box-shadow: 0 8px 24px rgba(63, 31, 134, 0.32); display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 1030; animation: cassyRise 0.2s ease both; }
.cassy-fab img { width: 34px; height: auto; display: block; }
.cassy-fab:focus-visible { outline: 3px solid rgba(91, 47, 184, 0.45); outline-offset: 2px; }
.cassy-fab.is-busy::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 3px solid transparent; border-top-color: var(--brand, #5b2fb8); animation: cassySpin 0.9s linear infinite; }
.cassy-fab-dot { position: absolute; top: 0; right: 0; width: 16px; height: 16px; border-radius: 50%; background: #e0457b; border: 2px solid #fff; }

/* The chat, slid up over the results */
html.cassy-sheet-open { overflow: hidden; }
.cassy-sheet { position: fixed; inset: 0; z-index: 2600; }
.cassy-sheet-backdrop { position: absolute; inset: 0; background: rgba(27, 20, 64, 0.5); }
.cassy-sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; height: 88vh; height: 88dvh; background: #fff; border-radius: 20px 20px 0 0; display: flex; flex-direction: column; overscroll-behavior: contain; box-shadow: 0 -10px 40px rgba(27, 20, 64, 0.3); animation: cassySheetUp 0.24s ease both; }
@keyframes cassySheetUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.cassy-sheet-head { position: relative; display: flex; align-items: center; gap: 8px; padding: 18px 10px 10px 16px; border-bottom: 1px solid rgba(91, 47, 184, 0.12); color: var(--brand-ink, #1f1636); touch-action: none; }
.cassy-sheet-head img { width: 26px; height: auto; }
.cassy-sheet-grip { position: absolute; top: 7px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 4px; background: rgba(91, 47, 184, 0.25); }
.cassy-sheet-close { margin-left: auto; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: none; border: none; color: var(--brand-ink, #1f1636); cursor: pointer; border-radius: 50%; }
.cassy-sheet-close:hover { background: var(--brand-soft, #f4effe); }
.cassy-sheet-body { flex: 1; min-height: 0; display: flex; }
.cassy-sheet-body .cassy-card { flex: 1; min-width: 0; display: flex; flex-direction: column; border: 0; border-radius: 0; box-shadow: none; padding: 12px 16px calc(10px + env(safe-area-inset-bottom, 0px)); }
.cassy-sheet-body .cassy-thread { flex: 1; min-height: 0; max-height: none; overscroll-behavior: contain; }
.cassy-sheet-body .cassy-privacy { display: none; }

@media (min-width: 768px) {
  .cassy-sheet-panel { left: auto; right: 24px; bottom: 24px; width: 420px; height: min(640px, 82vh); border-radius: 20px; }
  .cassy-sheet-grip { display: none; }
  .cassy-sheet-head { padding-top: 10px; touch-action: auto; }
  .cassy-sheet-backdrop { background: rgba(27, 20, 64, 0.22); }
}

@media (min-width: 1200px) {
  .cassy-fab { bottom: 28px; right: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  .cassy-typing span, .cassy-spinner, .cassy-skel, .cassy-tier, .cassy-fab, .cassy-fab.is-busy::after, .cassy-sheet-panel { animation: none; }
  .cassy-thread { scroll-behavior: auto; }
}

/* An element marked hidden must stay hidden even when its class sets a display value. */
.cassy [hidden] { display: none !important; }

.cassy button, .cassy textarea, .cassy input { font-family: inherit; }
.cassy-save { width: 44px; min-width: 44px; padding: 0; }
.cassy-save.is-saved { background: var(--brand, #5b2fb8); color: #fff; }
.cassy-save.is-saved svg { fill: currentColor; }
