/* chat/chat.css */
:root {
  --primary: #e07070;
  --primary-deep: #d05a5a;
  --bg: #faf6f3;
  --bubble-ai: #ffffff;
  --bubble-user: #e07070;
  --text: #2a2520;
  --text-muted: #6a635a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Noto Sans TC', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.chat-header {
  text-align: center;
  padding: 20px 16px 12px;
  border-bottom: 1px solid #ece4dc;
}
.chat-header h1 { margin: 0 0 4px; font-size: 20px; }
.chat-header p { margin: 0; color: var(--text-muted); font-size: 14px; }

.chat-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
  align-items: start;
  transition: max-width 0.4s ease, grid-template-columns 0.4s ease;
}
/* When quote panel has content, expand to two columns */
.chat-main:has(.quote-panel:not(:empty)) {
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  max-width: 1100px;
}
@media (max-width: 900px) {
  .chat-main:has(.quote-panel:not(:empty)) { grid-template-columns: 1fr; }
}
.chat-section { display: flex; flex-direction: column; min-width: 0; }
.quote-panel {
  display: none;
  position: sticky;
  top: 16px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  padding: 14px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  animation: quote-slide-in 0.35s ease-out;
}
.quote-panel:not(:empty) { display: block; }
@media (max-width: 900px) {
  .quote-panel { position: static; order: 2; }
  .chat-section { order: 1; }
}
@keyframes quote-slide-in {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.msg {
  display: flex;
  margin-bottom: 12px;
  gap: 10px;
}
.msg.ai { justify-content: flex-start; }
.msg.user { justify-content: flex-end; }

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.msg-avatar svg { width: 100%; height: 100%; display: block; }
.msg-avatar:not(:has(svg)) {
  background: var(--primary);
  color: white;
  font-weight: bold;
}
.msg.user .msg-avatar { display: none; }

.msg-bubble {
  max-width: min(520px, calc(100% - 60px));
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--bubble-ai);
  line-height: 1.6;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg.user .msg-bubble {
  background: var(--bubble-user);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg.ai .msg-bubble {
  border: 1px solid #ece4dc;
  border-bottom-left-radius: 4px;
}

.tw-cursor::after {
  content: '|';
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.chat-input {
  display: flex;
  gap: 8px;
  padding: 12px 0 0;
  border-top: 1px solid #ece4dc;
}
.chat-input textarea {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #ece4dc;
  border-radius: 8px;
  resize: none;
  font: inherit;
}
.chat-input button {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0 18px;
  font-weight: 600;
  cursor: pointer;
}
.chat-input button:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.chat-footer {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  padding: 10px 16px 20px;
}
.alt-link { color: var(--primary); text-decoration: underline; }

/* quote card */
.quote-card {
  background: white;
  border: 2px solid var(--primary);
  border-radius: 12px;
  padding: 20px;
  margin: 12px 0;
  box-shadow: 0 4px 12px rgba(224,112,112,0.15);
}
.quote-card h3 { margin: 0 0 4px; color: var(--primary-deep); }
.quote-meta { color: #6b6b6b; font-size: 13px; margin-bottom: 12px; }
.quote-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 14px; }
.quote-table th, .quote-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #ede0da;
  text-align: left;
  vertical-align: top;
}
.quote-table thead th {
  background: #fdf8f6;
  font-weight: 600;
  color: var(--primary-deep);
  font-size: 12px;
  letter-spacing: 0.5px;
}
.quote-table .amt { text-align: right; white-space: nowrap; }
.quote-table tfoot .quote-total th {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary-deep);
  background: #fdf8f6;
  border-bottom: none;
  padding-top: 12px;
  padding-bottom: 12px;
}
.quote-card .qrow {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px dashed #ece4dc;
}
.quote-card .total {
  font-weight: 700;
  font-size: 18px;
  color: var(--primary-deep);
  padding-top: 8px;
  margin-top: 8px;
  border-top: 2px solid var(--primary);
}
.quote-card .actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.quote-card button {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.quote-card .btn-primary { background: var(--primary); color: white; }
.quote-card .btn-secondary { background: white; color: var(--primary); border: 1px solid var(--primary); }

.fallback-banner {
  background: #fff4d6;
  border: 1px solid #e6c66a;
  padding: 10px 14px;
  border-radius: 8px;
  margin: 8px 0;
  font-size: 14px;
}

/* quick-reply chip groups for structured-choice questions */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 12px 46px;
}
.chip {
  background: #fff;
  border: 1.5px solid var(--primary);
  color: var(--primary-deep);
  padding: 7px 14px;
  border-radius: 999px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}
.chip:hover:not(:disabled) { background: #fce8e8; }
.chip.selected {
  background: var(--primary);
  color: #fff;
}
.chip:disabled {
  opacity: 0.45;
  cursor: default;
}
.chip-none {
  border-color: #b8b0a8;
  color: var(--text-muted);
}
.chip-none.selected {
  background: var(--text-muted);
  border-color: var(--text-muted);
}
.chip-submit {
  background: var(--primary-deep);
  color: #fff;
  border: 1.5px solid var(--primary-deep);
  padding: 7px 18px;
  border-radius: 999px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-left: 4px;
}
.chip-submit:hover:not(:disabled) { filter: brightness(1.05); }
.chip-submit:disabled { opacity: 0.45; cursor: default; }
@media (max-width: 480px) { .chip-group { margin-left: 8px; } }

/* Embedded chip group — sits inside an ai message bubble, grouped per
   section heading (one row per group). */
.chip-group.chip-group-embedded {
  flex-direction: column;
  align-items: stretch;
  margin: 10px 0 0 0;
  padding-top: 10px;
  border-top: 1px dashed #ece4dc;
  gap: 8px;
}
.chip-group.chip-group-embedded .chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
/* Divider between adjacent chip rows (skips the submit row). */
.chip-group.chip-group-embedded .chip-row + .chip-row:not(.chip-row-submit) {
  border-top: 2px solid #e8d8d2;
  padding-top: 10px;
}
.chip-group.chip-group-embedded .chip-row-submit {
  justify-content: flex-end;
  margin-top: 2px;
}
@media (max-width: 480px) {
  .chip-group.chip-group-embedded { margin-left: 0; }
}

/* video preview gallery — clicked from "看作品風格" route */
.video-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 6px 0 14px 46px;
}
@media (max-width: 480px) {
  .video-gallery { margin-left: 8px; grid-template-columns: 1fr 1fr; }
}
.video-card {
  background: #fff;
  border: 1px solid #ece4dc;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.video-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0,0,0,0.08);
  border-color: var(--primary);
}
.video-card-preview {
  position: relative;
  background: #000;
  aspect-ratio: 16/9;
}
.video-card-preview video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.video-card-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: rgba(255,255,255,0.95);
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  pointer-events: none;
}
.video-card-label {
  padding: 8px 10px;
}
.video-card-label strong {
  display: block;
  font-size: 14px;
  color: var(--text);
}
.video-card-label span {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* full-screen video lightbox */
.video-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 16px;
}
.video-lightbox-inner {
  width: 100%;
  max-width: 720px;
  background: #1a1a1a;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.video-lightbox-inner video {
  width: 100%;
  max-height: 60vh;
  background: #000;
  display: block;
}
.video-lightbox-meta {
  padding: 10px 16px;
  color: #fff;
  background: #1a1a1a;
}
.video-lightbox-meta strong { font-size: 16px; }
.video-lightbox-meta span {
  display: block;
  margin-top: 2px;
  color: #b8b0a8;
  font-size: 13px;
}
.video-lightbox-actions {
  display: flex;
  gap: 8px;
  padding: 12px 16px 16px;
  background: #1a1a1a;
}
.video-lightbox-actions button {
  flex: 1;
  padding: 10px 14px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid;
}
.video-lightbox-actions .btn-secondary {
  background: transparent;
  color: #fff;
  border-color: rgba(255,255,255,0.4);
}
.video-lightbox-actions .btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* multi-select chip (g_priorities) */
.chip.chip-cta {
  background: var(--primary);
  color: white;
  border: 0;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 24px;
  box-shadow: 0 3px 10px rgba(224, 112, 112, 0.3);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.chip.chip-cta:hover { transform: translateY(-1px); box-shadow: 0 5px 14px rgba(224, 112, 112, 0.4); }
.chip.chip-cta:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.chip-group-cta { margin: 12px 0; display: flex; justify-content: center; }

.chip.chip-multi.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.chip.chip-multi.over-max {
  animation: chip-shake 0.3s;
}
@keyframes chip-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* soft prompt chips (exploring/comparing) and ready-to-book gate */
.chip.chip-soft, .chip.chip-gate {
  background: rgba(224, 112, 112, 0.08);
  border: 1.5px solid rgba(224, 112, 112, 0.4);
  color: var(--primary-deep);
}
.chip.chip-soft:hover:not(:disabled),
.chip.chip-gate:hover:not(:disabled) {
  background: rgba(224, 112, 112, 0.15);
}

/* === Rich text rendering for assistant bubbles === */

/* msg-bubble 內 p 重設 margin（壓掉瀏覽器預設 1em） */
.msg-bubble p {
  margin: 0 0 6px 0;
}
.msg-bubble p:last-child {
  margin-bottom: 0;
}

/* 訊息小標題 */
.msg-h {
  font-weight: 600;
  font-size: 0.98em;
  color: var(--primary, #d97a8a);
  margin: 4px 0 2px 0;
  letter-spacing: 0.02em;
}
.msg-h:first-child { margin-top: 0; }

/* 訊息條列 */
.msg-list {
  list-style: none;
  padding: 0;
  margin: 0 0 6px 0;
}
.msg-list li {
  position: relative;
  padding: 2px 0 4px 14px;
  line-height: 1.5;
}
.msg-list li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 11px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--primary, #d97a8a);
  opacity: 0.7;
}

/* bullet 子說明 */
.msg-sub {
  margin-top: 1px;
  font-size: 0.92em;
  color: var(--text-muted, #888);
  line-height: 1.45;
}

/* inline strong: 只變粗，不換色 */
.msg-bubble strong {
  font-weight: 600;
  color: inherit;
}

/* === Pre-stream thinking indicator === */

.msg-bubble.tw-thinking {
  color: var(--text-muted, #888);
  font-style: italic;
  font-size: 0.95em;
  min-height: 1.4em;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.msg-bubble.tw-thinking::before {
  content: "生成中";
}

.msg-bubble.tw-thinking::after {
  content: "";
  display: inline-block;
  width: 60px;
  height: 16px;
  margin-left: 6px;
  vertical-align: middle;
  background-color: var(--primary, #d97a8a);
  -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 16'><path d='M2 14 Q 2 10 6 10 L 11 10 Q 13 10 13 14 Z' fill='black'/><circle cx='15' cy='9' r='5' fill='black'/><path d='M3 11 L 3 7' stroke='black' stroke-width='1.4' stroke-linecap='round'/><circle cx='3' cy='6.5' r='1' fill='black'/><path d='M5 10 L 6 6' stroke='black' stroke-width='1.4' stroke-linecap='round'/><circle cx='6' cy='5.5' r='1' fill='black'/></svg>");
  mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 16'><path d='M2 14 Q 2 10 6 10 L 11 10 Q 13 10 13 14 Z' fill='black'/><circle cx='15' cy='9' r='5' fill='black'/><path d='M3 11 L 3 7' stroke='black' stroke-width='1.4' stroke-linecap='round'/><circle cx='3' cy='6.5' r='1' fill='black'/><path d='M5 10 L 6 6' stroke='black' stroke-width='1.4' stroke-linecap='round'/><circle cx='6' cy='5.5' r='1' fill='black'/></svg>");
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: 24px 16px;
  mask-size: 24px 16px;
  /* Off-screen wrap: snail enters left, crawls across, exits right; loop seamless */
  animation: snail-crawl 4s linear infinite;
}

@keyframes snail-crawl {
  0%   { -webkit-mask-position: -24px center; mask-position: -24px center; }
  100% { -webkit-mask-position: 60px center;  mask-position: 60px center; }
}
