/* Chaqar IA — UI/UX Phase 8
   Calm, source-first and mobile-ready conversational workspace. */

[data-product-surface="ai"] {
  background:
    radial-gradient(circle at 84% 0%, rgb(124 58 237 / .08), transparent 30rem),
    #f8fafc;
}

[data-product-surface="ai"] .cq-app-header { border-bottom-color: rgb(221 214 254 / .82); }
[data-product-surface="ai"] [data-student-navigation] .cq-app-nav-link.is-current { color: #6d28d9; background: #f5f3ff; box-shadow: inset 0 0 0 1px #ede9fe; }

.cq-ai-page { max-width: 1440px; }

.cq-ai-trust-strip {
  display: flex;
  align-items: center;
  gap: .55rem 1rem;
  overflow-x: auto;
  padding: .65rem .85rem;
  border: 1px solid #ede9fe;
  border-radius: 1rem;
  color: #64748b;
  background: rgb(255 255 255 / .78);
  font-size: .7rem;
  font-weight: 750;
  white-space: nowrap;
  scrollbar-width: none;
}

.cq-ai-trust-strip::-webkit-scrollbar { display: none; }
.cq-ai-trust-strip span { display: inline-flex; align-items: center; gap: .42rem; }
.cq-ai-trust-strip i { width: .45rem; height: .45rem; border-radius: 999px; background: #7c3aed; }

.cq-ai-history { overflow: hidden; padding: 0; }
.cq-ai-history-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem; border-bottom: 1px solid #f1f5f9; }
.cq-ai-history-kicker { color: #7c3aed; font-size: .65rem; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.cq-ai-history-toggle { display: grid; width: 2.35rem; height: 2.35rem; place-items: center; border: 1px solid #e2e8f0; border-radius: .7rem; color: #64748b; background: #fff; }
.cq-ai-history-toggle svg { transition: transform var(--cq-motion-fast); }
.cq-ai-history[data-collapsed="true"] .cq-ai-history-toggle svg { transform: rotate(-90deg); }
.cq-ai-history-body { padding: 1rem; }
.cq-ai-history[data-collapsed="true"] .cq-ai-history-body { display: none; }

.cq-ai-history-link {
  border: 1px solid transparent;
  min-width: 13rem;
}

.cq-ai-history-link.is-active {
  border-color: #ddd6fe;
  color: #5b21b6;
  background: linear-gradient(135deg, #faf5ff, #f5f3ff);
}

.cq-ai-hero {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: clamp(1rem, 3vw, 1.5rem);
  border: 1px solid #e9e5ff;
  border-radius: 1.35rem;
  background:
    radial-gradient(circle at 92% 12%, rgb(167 139 250 / .18), transparent 34%),
    rgb(255 255 255 / .9);
}

.cq-ai-context { flex: 0 0 auto; padding: .75rem .9rem; border: 1px solid #ddd6fe; border-radius: .85rem; background: #faf5ff; }

.cq-ai-workspace { overflow: clip; border-color: #ddd6fe; box-shadow: 0 24px 70px rgb(91 33 182 / .1); }
.cq-ai-thread { min-height: min(39rem, 66vh); max-height: 68vh; overflow-y: auto; scroll-behavior: smooth; background: linear-gradient(180deg, #fff 0%, #fafafa 100%); }
.cq-ai-message { width: min(100%, 52rem); }
.cq-ai-message-meta { display: flex; align-items: center; gap: .45rem; margin-bottom: .4rem; color: #94a3b8; font-size: .65rem; font-weight: 700; }
.cq-ai-user-bubble { width: fit-content; max-width: min(100%, 42rem); margin-left: auto; padding: .8rem 1rem; border-radius: 1.15rem 1.15rem .35rem 1.15rem; color: #fff; background: linear-gradient(135deg, #6d28d9, #7c3aed); box-shadow: 0 12px 30px rgb(109 40 217 / .16); font-size: .88rem; line-height: 1.65; }
.cq-ai-assistant-card { overflow: hidden; border: 1px solid #e2e8f0; border-radius: 1.2rem 1.2rem 1.2rem .35rem; background: #fff; box-shadow: 0 12px 34px rgb(15 23 42 / .055); }
.cq-ai-answer-header { display: flex; align-items: center; gap: .6rem; min-height: 3.8rem; padding: .8rem 1rem; border-bottom: 1px solid #f1f5f9; background: #fcfcfd; }
.cq-ai-icon-button { display: grid; width: 2.2rem; height: 2.2rem; margin-left: auto; place-items: center; border: 1px solid #e2e8f0; border-radius: .65rem; color: #64748b; background: #fff; }
.cq-ai-icon-button:hover { color: #6d28d9; border-color: #ddd6fe; background: #faf5ff; }
.cq-ai-answer-content { padding: 1rem; }
.cq-ai-answer-content :where(h2, h3) { color: #0f172a; font-family: var(--cq-font-editorial); font-weight: 750; }
.cq-ai-answer-content h2 { margin: 1.25rem 0 .55rem; font-size: 1.15rem; }
.cq-ai-answer-content h3 { margin: 1rem 0 .45rem; font-size: 1rem; }

.cq-ai-pending { display: flex; align-items: center; gap: .9rem; padding: 1.2rem 1rem; }
.cq-ai-thinking { display: inline-flex; gap: .2rem; align-items: center; height: 1.5rem; padding: 0 .55rem; border-radius: 999px; background: #f5f3ff; }
.cq-ai-thinking i { width: .3rem; height: .3rem; border-radius: 999px; background: #7c3aed; animation: cq-ai-pulse 1.2s infinite ease-in-out; }
.cq-ai-thinking i:nth-child(2) { animation-delay: .16s; }
.cq-ai-thinking i:nth-child(3) { animation-delay: .32s; }
@keyframes cq-ai-pulse { 0%, 70%, 100% { opacity: .28; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-3px); } }

.cq-ai-sources { border-top: 1px solid #f1f5f9; }
.cq-ai-sources summary { display: flex; cursor: pointer; list-style: none; align-items: center; gap: .5rem; padding: .85rem 1rem; color: #475569; font-size: .72rem; font-weight: 850; text-transform: uppercase; letter-spacing: .06em; }
.cq-ai-sources summary::-webkit-details-marker { display: none; }
.cq-ai-sources summary svg { margin-left: auto; transition: transform var(--cq-motion-fast); }
.cq-ai-sources:not([open]) summary svg { transform: rotate(-90deg); }
.cq-ai-source-count { display: inline-grid; min-width: 1.35rem; height: 1.35rem; place-items: center; border-radius: 999px; color: #6d28d9; background: #ede9fe; font-size: .65rem; }
.cq-ai-source-grid { display: grid; gap: .6rem; padding: 0 1rem 1rem; }
.cq-ai-source-card { display: block; padding: .8rem; border: 1px solid #e2e8f0; border-radius: .85rem; background: #fff; transition: border-color var(--cq-motion-fast), background var(--cq-motion-fast); }
.cq-ai-source-card:hover { border-color: #c4b5fd; background: #faf5ff; }
.cq-ai-source-rank { display: grid; width: 1.7rem; height: 1.7rem; flex: 0 0 auto; place-items: center; border-radius: .55rem; color: #6d28d9; background: #ede9fe; font-size: .65rem; font-weight: 850; }
.cq-ai-source-kind { display: inline-flex; padding: .18rem .42rem; border-radius: 999px; color: #6d28d9; background: #f5f3ff; font-size: .58rem; font-weight: 850; text-transform: uppercase; }
.cq-ai-source-kind.is-bible { color: #92400e; background: #fef3c7; }

.cq-ai-feedback { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; padding: .75rem 1rem; border-top: 1px solid #f1f5f9; color: #94a3b8; font-size: .7rem; }
.cq-ai-feedback button { padding: .3rem .55rem; border: 1px solid #e2e8f0; border-radius: .55rem; color: #64748b; background: #fff; font-weight: 700; }
.cq-ai-feedback button:hover { color: #5b21b6; border-color: #ddd6fe; background: #faf5ff; }

.cq-ai-empty-state { max-width: 43rem; margin-inline: auto; padding: clamp(2.5rem, 8vw, 5rem) 1rem; text-align: center; }
.cq-ai-suggestions { display: grid; gap: .65rem; margin-top: 1.5rem; }
.cq-ai-suggestions button { padding: .75rem .9rem; border: 1px solid #e2e8f0; border-radius: .85rem; color: #475569; background: #fff; font-size: .78rem; font-weight: 750; text-align: left; transition: border-color var(--cq-motion-fast), color var(--cq-motion-fast), background var(--cq-motion-fast); }
.cq-ai-suggestions button::after { float: right; color: #8b5cf6; content: "→"; }
.cq-ai-suggestions button:hover { color: #5b21b6; border-color: #c4b5fd; background: #faf5ff; }

.cq-ai-composer { position: sticky; bottom: 0; z-index: 3; padding: .85rem; border-top: 1px solid #e2e8f0; background: rgb(255 255 255 / .96); backdrop-filter: blur(14px); }
.cq-ai-composer-label { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .45rem; color: #64748b; font-size: .68rem; font-weight: 750; }
.cq-ai-composer-row { display: flex; flex-direction: column; gap: .65rem; }
.cq-ai-question { min-height: 3.3rem; max-height: 11rem; resize: none; line-height: 1.5; }
.cq-ai-send { min-height: 3.3rem; }
.cq-ai-disclaimer { margin-top: .45rem; color: #94a3b8; font-size: .65rem; line-height: 1.45; }
.cq-ai-composer [disabled] { cursor: not-allowed; opacity: .58; }

@media (min-width: 640px) {
  .cq-ai-hero { flex-direction: row; align-items: flex-end; justify-content: space-between; }
  .cq-ai-source-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cq-ai-suggestions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cq-ai-composer-row { flex-direction: row; align-items: flex-end; }
  .cq-ai-send { flex: 0 0 auto; }
}

@media (min-width: 1024px) {
  .cq-ai-layout { grid-template-columns: 18rem minmax(0, 1fr); gap: 1.25rem; }
  .cq-ai-history { top: 6.4rem; }
  .cq-ai-history[data-collapsed="true"] .cq-ai-history-body { display: block; }
}

@media (max-width: 1023px) {
  .cq-ai-thread { min-height: 32rem; max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  .cq-ai-thinking i { animation: none; opacity: .65; }
  .cq-ai-thread { scroll-behavior: auto; }
}
