/* =========================================================
   拿順 AI 選型助理 — 樣式表
   深色主題 / 手機優先 / Powered by Sowing AI
   品牌色：深藍 #0B2545、青 #35C4E8、橘 #FF8A3D
   ========================================================= */

:root {
  --navy-900: #071a33;
  --navy-800: #0B2545;
  --navy-700: #123059;
  --navy-600: #1a3d6e;
  --cyan: #35C4E8;
  --cyan-soft: rgba(53, 196, 232, 0.14);
  --orange: #FF8A3D;
  --orange-deep: #e5731f;
  --text-main: #EAF2FA;
  --text-dim: #A8BDD4;
  --text-faint: #7d94ad;
  --border-soft: rgba(53, 196, 232, 0.18);
  --bubble-ai: #12305c;
  --bubble-user: #1c4a6e;
  --danger: #ff7b7b;
  --radius-lg: 18px;
  --radius-sm: 8px;
  --topbar-h: 60px;
  --maxw: 780px;
  --font: 'Noto Sans TC', 'PingFang TC', 'Microsoft JhengHei', system-ui, sans-serif;
}

/* kiosk 模式：展場平板字級放大一階 */
html.kiosk { font-size: 112.5%; }

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text-main);
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(53, 196, 232, 0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(255, 138, 61, 0.07), transparent 55%),
    linear-gradient(180deg, var(--navy-800) 0%, var(--navy-900) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* 螢幕閱讀器專用 */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ===== 頂部列 ===== */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 30;
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  background: rgba(7, 26, 51, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}

.topbar-inner {
  max-width: var(--maxw);
  height: var(--topbar-h);
  margin: 0 auto;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center;
  width: 38px; height: 38px; flex: none;
  border-radius: 9px;
  background: var(--navy-700);
  box-shadow: 0 0 0 1px var(--border-soft);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { font-size: 1rem; font-weight: 700; line-height: 1.25; white-space: nowrap; }
.brand-sub {
  font-size: 0.68rem; color: var(--text-faint);
  letter-spacing: 0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.btn-human {
  display: inline-flex; align-items: center; gap: 6px;
  flex: none;
  padding: 8px 13px;
  font-family: inherit; font-size: 0.82rem; font-weight: 700;
  color: #201202;
  background: linear-gradient(135deg, var(--orange), var(--orange-deep));
  border: 0; border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(255, 138, 61, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn-human:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(255, 138, 61, 0.45); }
.btn-human:active { transform: translateY(0); }

/* ===== 對話捲動區 ===== */
.chat-scroll {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  left: 0; right: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--navy-600) transparent;
}

.chat-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 18px 14px 24px;
}

/* 開場抬頭 */
.hero { text-align: center; padding: 14px 6px 22px; }
.hero-title {
  margin: 0 0 8px;
  font-size: clamp(1.45rem, 5.5vw, 2rem);
  font-weight: 900;
  letter-spacing: 0.01em;
  line-height: 1.25;
}
.hero-title .accent {
  background: linear-gradient(90deg, var(--cyan), #7fdcf3);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-tagline { margin: 0 0 10px; font-size: 0.95rem; color: var(--text-dim); }
.hero-disclaimer {
  display: inline-block;
  margin: 0;
  padding: 5px 12px;
  font-size: 0.72rem;
  color: var(--text-faint);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: rgba(53, 196, 232, 0.05);
}

/* ===== 訊息串 ===== */
.chat-log { display: flex; flex-direction: column; gap: 14px; }

.msg-row { display: flex; }
.msg-row.from-ai { justify-content: flex-start; }
.msg-row.from-user { justify-content: flex-end; }

@media (prefers-reduced-motion: no-preference) {
  .msg-enter { animation: msg-in 150ms ease-out; }
  @keyframes msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
  }
}

.bubble {
  max-width: 86%;
  padding: 11px 15px;
  font-size: 0.95rem;
  line-height: 1.65;
  border-radius: var(--radius-lg);
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: normal;
}
.from-ai .bubble {
  background: var(--bubble-ai);
  border: 1px solid var(--border-soft);
  border-bottom-left-radius: 6px;
  color: var(--text-main);
}
.from-user .bubble {
  background: linear-gradient(135deg, var(--bubble-user), #1a5f7e);
  border-bottom-right-radius: 6px;
  color: #f2fbff;
}

/* AI 氣泡內的簡易 markdown 樣式 */
.bubble p { margin: 0 0 0.55em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0.3em 0 0.55em; padding-left: 1.35em; }
.bubble li { margin: 0.2em 0; }
.bubble strong { color: #9be2f5; font-weight: 700; }
.from-user .bubble strong { color: inherit; }

/* 打字中指示 */
.typing { display: inline-flex; align-items: center; gap: 5px; padding: 4px 2px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--cyan);
  opacity: 0.5;
}
@media (prefers-reduced-motion: no-preference) {
  .typing i { animation: typing-bounce 1.1s infinite ease-in-out; }
  .typing i:nth-child(2) { animation-delay: 0.18s; }
  .typing i:nth-child(3) { animation-delay: 0.36s; }
  @keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
  }
}

/* 快速回覆晶片 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 2px 4px; }
.chip {
  padding: 9px 15px;
  font-family: inherit; font-size: 0.86rem; font-weight: 500;
  color: var(--cyan);
  background: var(--cyan-soft);
  border: 1px solid rgba(53, 196, 232, 0.4);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}
.chip:hover { background: rgba(53, 196, 232, 0.24); transform: translateY(-1px); }
.chip:active { transform: translateY(0); }

/* 系統提示（錯誤 / 引導） */
.sys-note {
  align-self: center;
  max-width: 92%;
  padding: 8px 14px;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed var(--border-soft);
  border-radius: var(--radius-sm);
}
.sys-note.is-error { color: var(--danger); border-color: rgba(255, 123, 123, 0.35); }

/* 重試按鈕 */
.btn-retry {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 8px;
  padding: 7px 16px;
  font-family: inherit; font-size: 0.84rem; font-weight: 700;
  color: var(--navy-900);
  background: var(--cyan);
  border: 0; border-radius: 999px;
  cursor: pointer;
}
.btn-retry:hover { filter: brightness(1.1); }

/* 內嵌動作按鈕（例如「留下聯絡方式」） */
.btn-inline {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 8px;
  padding: 8px 16px;
  font-family: inherit; font-size: 0.85rem; font-weight: 700;
  color: #201202;
  background: linear-gradient(135deg, var(--orange), var(--orange-deep));
  border: 0; border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(255, 138, 61, 0.3);
}
.btn-inline:hover { filter: brightness(1.06); }

/* ===== 留資表單卡片 ===== */
.lead-card {
  align-self: stretch;
  max-width: 100%;
  padding: 18px 16px;
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  border: 1px solid rgba(255, 138, 61, 0.35);
  border-radius: var(--radius-lg);
}
.lead-card h2 {
  margin: 0 0 4px;
  font-size: 1.05rem; font-weight: 700;
  color: var(--orange);
}
.lead-card .lead-desc { margin: 0 0 14px; font-size: 0.83rem; color: var(--text-dim); }

.lead-field { margin-bottom: 11px; }
.lead-field label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.78rem; font-weight: 500;
  color: var(--text-dim);
}
.lead-field .req { color: var(--orange); }
.lead-field input, .lead-field textarea {
  width: 100%;
  padding: 10px 12px;
  font-family: inherit; font-size: 0.92rem;
  color: var(--text-main);
  background: rgba(7, 26, 51, 0.6);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s ease;
}
.lead-field input:focus, .lead-field textarea:focus { border-color: var(--cyan); }
.lead-field textarea { resize: vertical; min-height: 60px; }
.lead-error { margin: 6px 0 0; font-size: 0.78rem; color: var(--danger); }

.lead-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.btn-lead-submit {
  flex: 1 1 auto;
  padding: 11px 18px;
  font-family: inherit; font-size: 0.92rem; font-weight: 700;
  color: #201202;
  background: linear-gradient(135deg, var(--orange), var(--orange-deep));
  border: 0; border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(255, 138, 61, 0.3);
}
.btn-lead-submit:disabled { opacity: 0.55; cursor: wait; }
.btn-pinchat {
  flex: 1 1 auto;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px;
  font-family: inherit; font-size: 0.92rem; font-weight: 700;
  color: var(--cyan);
  background: transparent;
  border: 1px solid rgba(53, 196, 232, 0.5);
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
}
.btn-pinchat:hover { background: var(--cyan-soft); }
.btn-lead-cancel {
  flex: 0 0 auto;
  padding: 11px 14px;
  font-family: inherit; font-size: 0.85rem;
  color: var(--text-faint);
  background: transparent; border: 0;
  cursor: pointer;
}
.btn-lead-cancel:hover { color: var(--text-dim); }

.lead-success { text-align: center; padding: 10px 0; }
.lead-success .icon { font-size: 2rem; }
.lead-success h2 { margin: 6px 0 4px; color: var(--cyan); font-size: 1.05rem; }
.lead-success p { margin: 0; font-size: 0.85rem; color: var(--text-dim); }

/* ===== 回到底部按鈕 ===== */
.btn-scroll-bottom {
  position: fixed;
  right: 16px;
  bottom: calc(110px + env(safe-area-inset-bottom, 0px));
  z-index: 25;
  display: grid; place-items: center;
  width: 40px; height: 40px;
  color: var(--navy-900);
  background: var(--cyan);
  border: 0; border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(53, 196, 232, 0.4);
}

/* ===== 輸入區（固定底部） ===== */
.composer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  padding: 10px 14px calc(8px + env(safe-area-inset-bottom, 0px));
  background: rgba(7, 26, 51, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-soft);
}

.composer-inner {
  position: relative;
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.composer-input {
  flex: 1;
  min-height: 46px;
  max-height: 132px;
  padding: 12px 14px;
  font-family: inherit; font-size: 0.95rem; line-height: 1.5;
  color: var(--text-main);
  background: var(--navy-700);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  outline: none;
  resize: none;
  transition: border-color 0.15s ease;
}
.composer-input:focus { border-color: var(--cyan); }
.composer-input::placeholder { color: var(--text-faint); }
.composer-input:disabled { opacity: 0.6; }

.char-count {
  position: absolute;
  right: 66px;
  top: -22px;
  font-size: 0.72rem;
  color: var(--text-faint);
  background: rgba(7, 26, 51, 0.85);
  padding: 2px 8px;
  border-radius: 999px;
}
.char-count.is-limit { color: var(--orange); font-weight: 700; }

.btn-send {
  flex: none;
  display: grid; place-items: center;
  width: 46px; height: 46px;
  color: var(--navy-900);
  background: linear-gradient(135deg, var(--cyan), #22a8cc);
  border: 0; border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(53, 196, 232, 0.3);
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn-send:hover:not(:disabled) { transform: translateY(-1px); }
.btn-send:disabled { opacity: 0.35; cursor: default; box-shadow: none; }

.composer-note {
  max-width: var(--maxw);
  margin: 6px auto 0;
  font-size: 0.66rem;
  color: var(--text-faint);
  text-align: center;
}

/* Turnstile 隱形掛載點 */
#turnstile-holder { position: fixed; bottom: 0; left: 0; z-index: -1; }

/* kiosk 模式：隱藏外部連結（保留轉真人按鈕） */
html.kiosk .external { display: none !important; }

/* 鍵盤焦點可視性 */
button:focus-visible, .chip:focus-visible, a:focus-visible,
input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* 降低動效偏好 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===== 響應式 ===== */
@media (max-width: 420px) {
  .brand-sub { display: none; }
  .btn-human span { display: none; }
  .btn-human { padding: 9px 11px; }
  .bubble { max-width: 90%; }
}

@media (min-width: 768px) {
  .chat-inner { padding: 26px 20px 32px; }
  .bubble { font-size: 1rem; }
  .hero { padding-top: 26px; }
}
