/* Feel Young AI 客服小幫手 — 聶永真 spec; product cards feature-flagged off in v1 */
:root {
  --fy-ai-apricot: #f0a890;
  --fy-ai-apricot-deep: #e8927a;
  --fy-ai-oat: #faf6f1;
  --fy-ai-text: #3d2a5c;
  --fy-ai-muted: #7a6a90;
  --fy-ai-line: #5a3c781f;
  --fy-ai-white: #ffffff;
}

#fy-aichat-root {
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  color: var(--fy-ai-text);
  position: fixed;
  z-index: 99990;
  right: 16px;
  bottom: 16px;
  box-sizing: border-box;
}
#fy-aichat-root *, #fy-aichat-root *::before, #fy-aichat-root *::after {
  box-sizing: border-box;
}

#fy-aichat-launcher {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: #c96b52;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px #f0a89055;
  padding: 0;
}
#fy-aichat-launcher:hover { background: #b85a42; }
#fy-aichat-launcher svg { width: 26px; height: 26px; display: block; }

#fy-aichat-panel {
  display: none;
  position: absolute;
  right: 0;
  bottom: 68px;
  width: 360px;
  max-width: calc(100vw - 24px);
  height: min(560px, calc(100vh - 100px));
  background: var(--fy-ai-white);
  border: 1px solid var(--fy-ai-line);
  border-radius: 16px;
  box-shadow: 0 12px 40px #3d2a5c22;
  flex-direction: column;
  overflow: hidden;
}
#fy-aichat-root.is-open #fy-aichat-panel { display: flex; }

@media (max-width: 480px) {
  #fy-aichat-root { right: 0; bottom: 0; left: 0; }
  #fy-aichat-launcher { position: fixed; right: 16px; bottom: 16px; }
  #fy-aichat-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }
}

.fy-ai-head {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--fy-ai-line);
  background: linear-gradient(105deg, #fff8f5, #faf6fb);
  flex-shrink: 0;
}
.fy-ai-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.fy-ai-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--fy-ai-text);
}
.fy-ai-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--fy-ai-muted);
  line-height: 1.4;
}
.fy-ai-hours {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--fy-ai-muted);
  line-height: 1.4;
}
.fy-ai-close {
  border: none;
  background: transparent;
  color: var(--fy-ai-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.fy-ai-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #fffefc;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fy-ai-msg {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.fy-ai-msg.ai {
  align-self: flex-start;
  background: var(--fy-ai-oat);
  color: var(--fy-ai-text);
}
.fy-ai-msg.user {
  align-self: flex-end;
  background: #f0a890;
  color: #3d2a5c;
}
.fy-ai-msg .fy-ai-line-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 13px;
  color: #7b4fa0;
  text-decoration: underline;
}
.fy-ai-ref {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--fy-ai-muted);
}

.fy-ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 2px;
}
.fy-ai-chip {
  border: 1px solid var(--fy-ai-line);
  background: #fff;
  color: var(--fy-ai-text);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  line-height: 1.3;
}
.fy-ai-chip:hover { border-color: var(--fy-ai-apricot); }

.fy-ai-age {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.fy-ai-age button {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  cursor: pointer;
}
.fy-ai-age .yes { background: #c96b52; color: #fff; }
.fy-ai-age .no { background: #eee8f2; color: var(--fy-ai-text); }

.fy-ai-foot {
  border-top: 1px solid var(--fy-ai-line);
  padding: 10px;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  background: #fff;
}
.fy-ai-foot input {
  flex: 1;
  border: 1px solid var(--fy-ai-line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 15px;
  font-family: inherit;
  color: var(--fy-ai-text);
  outline: none;
}
.fy-ai-foot input:focus { border-color: var(--fy-ai-apricot); }
.fy-ai-foot button.send {
  border: none;
  background: #c96b52;
  color: #fff;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.fy-ai-foot button.send:disabled { opacity: .5; cursor: not-allowed; }

/* Product cards — built but hidden unless FY_AICHAT_CARDS=true */
.fy-ai-cards-wrap {
  display: none;
  margin-top: 8px;
}
.fy-ai-cards-wrap.is-on { display: block; }
.fy-ai-cards-scroller {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.fy-ai-card {
  flex: 0 0 240px;
  width: 240px;
  border-radius: 12px;
  border: 1px solid var(--fy-ai-line);
  background: #fff;
  scroll-snap-align: start;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.fy-ai-card img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  background: #f3ece6;
}
.fy-ai-card-body { padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.fy-ai-card-name { font-size: 14px; font-weight: 600; color: var(--fy-ai-text); }
.fy-ai-card-price { font-size: 14px; color: var(--fy-ai-text); }
.fy-ai-card-reason { font-size: 12px; color: var(--fy-ai-muted); }
.fy-ai-card-license { font-size: 11px; color: var(--fy-ai-muted); }
.fy-ai-card-btn {
  margin-top: 6px;
  border: none;
  background: var(--fy-ai-apricot);
  color: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: block;
}

.fy-ai-handoff {
  margin-top: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--fy-ai-line);
  background: #fff8f5;
}
.fy-ai-handoff-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--fy-ai-text);
  margin-bottom: 8px;
}
.fy-ai-handoff-btn {
  display: block;
  text-align: center;
  text-decoration: none;
  background: var(--fy-ai-apricot);
  color: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}

/* --- 聶永真 UI fixes (aichat_review) --- */
#fy-aichat-root.is-open #fy-aichat-launcher { display: none; }
#fy-aichat-root .fy-ai-msg.user { color: #3d2a5c; background: #f0a890; }
#fy-aichat-launcher { background: #c96b52; }
#fy-aichat-launcher:hover { background: #b85a42; }
#fy-aichat-root .fy-ai-chip,
#fy-aichat-root .fy-ai-age button,
#fy-aichat-root .fy-ai-foot button.send,
#fy-aichat-root .fy-ai-handoff-btn,
#fy-aichat-root .fy-ai-card-btn {
  min-height: 44px;
}
@media (max-width: 480px) {
  #fy-aichat-root .fy-ai-foot input { font-size: 16px; }
}

/* Product recommendation cards (API-driven) */
.fy-ai-cards-wrap.is-on { display: block; margin-top: 8px; }
.fy-ai-cards-scroller {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.fy-ai-card {
  flex: 0 0 240px;
  width: 240px;
  border-radius: 12px;
  border: 1px solid var(--fy-ai-line);
  background: #fff;
  scroll-snap-align: start;
  overflow: hidden;
}
.fy-ai-card img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  object-position: center;
  background: #f3ece6;
  display: block;
}
.fy-ai-card-body { padding: 10px; display: flex; flex-direction: column; gap: 4px; font-size: 15px; line-height: 1.6; }
.fy-ai-card-name { font-size: 14px; font-weight: 600; color: #3d2a5c; }
.fy-ai-card-price { font-size: 14px; color: #3d2a5c; }
.fy-ai-card-reason, .fy-ai-card-license { font-size: 12px; color: var(--fy-ai-muted); }
.fy-ai-card-btn {
  margin-top: 6px;
  border: none;
  background: #c96b52;
  color: #fff;
  border-radius: 8px;
  padding: 10px;
  min-height: 44px;
  font-size: 14px;
  text-align: center;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
}


/* --- Designer v3 card media --- */
.fy-ai-card-media {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #f7f1ea; /* oat-white */
  overflow: hidden;
}
.fy-ai-card-media img,
.fy-ai-card img {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  object-position: center;
  background: #f7f1ea;
  display: block;
}
.fy-ai-card-badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  font-size: 11px;
  line-height: 1.2;
  color: #fff;
  background: rgba(0, 0, 0, 0.45);
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: none;
}
.fy-ai-card-name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}


/* Designer: 是 / 送出 = #c96b52 + white */
#fy-aichat-root .fy-ai-age .yes,
#fy-aichat-root .fy-ai-foot button.send {
  background: #c96b52;
  color: #fff;
}
#fy-aichat-root .fy-ai-age .yes:hover,
#fy-aichat-root .fy-ai-foot button.send:hover {
  background: #b85a42;
  color: #fff;
}

/* Session locked: greyed chips + composer (persist after minor lock) */
.fy-ai-chips.is-locked,
#fy-aichat-root.is-session-locked .fy-ai-chips {
  opacity: 0.55;
  pointer-events: none;
}
.fy-ai-chip.is-disabled,
.fy-ai-chip:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  color: #9a93a3;
  background: #f3f0f5;
  border-color: #e4dde9;
}
.fy-ai-chip.is-disabled:hover,
.fy-ai-chip:disabled:hover {
  border-color: #e4dde9;
}
.fy-ai-foot.is-locked,
#fy-aichat-root.is-session-locked .fy-ai-foot {
  opacity: 0.72;
}
.fy-ai-foot input:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  background: #f3f0f5;
  color: #9a93a3;
}
/* Locked refusal stays a normal AI bubble — no red / warning icon */
.fy-ai-msg.ai.is-locked-msg {
  color: var(--fy-ai-text);
}

/* aichat-rag 20261109 — blog citation cards (聶永真 spec) */
.fy-ai-cites { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; white-space: normal; }
.fy-ai-cite {
  background: #fff;
  border: 1px solid var(--fy-ai-line);
  border-radius: 12px;
  padding: 10px;
}
.fy-ai-cite-top { display: flex; gap: 8px; align-items: center; }
.fy-ai-cite-thumb {
  width: 64px; height: 36px; object-fit: cover; border-radius: 6px; flex-shrink: 0; background: #f3ece4;
}
.fy-ai-cite-title { font-size: 13px; font-weight: 600; line-height: 1.4; color: var(--fy-ai-text); }
.fy-ai-cite-quote {
  margin: 8px 0 6px;
  padding: 6px 10px;
  background: #fbf3ec;
  border-left: 2px solid var(--fy-ai-apricot-deep);
  border-radius: 0 6px 6px 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--fy-ai-text);
}
.fy-ai-cite-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; }
.fy-ai-cite-sec { color: var(--fy-ai-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fy-ai-cite-link { color: #c96b52; text-decoration: none; font-weight: 600; white-space: nowrap; }
.fy-ai-cite-link:hover { text-decoration: underline; }
.fy-ai-hint {
  font-size: 11px; color: var(--fy-ai-muted); text-align: center;
  padding: 0 10px 8px; background: #fff; flex-shrink: 0;
}

/* aichat-rag r2 — warm apricot AI bubbles, larger radius, typing indicator, card note */
.fy-ai-msg { border-radius: 18px; padding: 10px 14px; line-height: 1.65; }
.fy-ai-msg.ai { background: #fde6d8; border-bottom-left-radius: 6px; }
.fy-ai-msg.user { border-bottom-right-radius: 6px; }
.fy-ai-typing { color: var(--fy-ai-muted); font-size: 14px; }
.fy-ai-dots i { font-style: normal; display: inline-block; animation: fy-ai-blink 1.2s infinite both; }
.fy-ai-dots i:nth-child(2) { animation-delay: .2s; }
.fy-ai-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes fy-ai-blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .fy-ai-dots i { animation: none; opacity: .7; } }
.fy-ai-cite-note { font-size: 11px; color: var(--fy-ai-muted); margin-top: 2px; }
