/* Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  background: #212121;
  color: #e5e7eb;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Header */
/* Header 外框 */
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 12px 0 24px;
  background: #050a14;
  color: #fff;
}

/* 左上「TW Stock」 */
.left-title {
  font-weight: 600;
  font-size: 1rem;
  color: #cfd3dc;
}
.left-title span{
  color:#999999;
  font-size: 1rem;
  padding-left: 0.5rem;
}

.top-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* 小螢幕的 AI toggle 按鈕底色、圓角、hover 過渡 */
.ai-toggle-btn {
  display: none;  /* 1024px 以下才會打開 */
  padding: 0.3rem 0.3rem;
  border-radius: 50%;
  background: #020617;
  border: 1px solid #4b5563;
  cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease;
}

.ai-toggle-btn img{
  width: 24px;
  opacity: 80%;
}

.ai-toggle-btn:hover {
  background: #4b5563;
}

/* TradingView Ticker 固定寬、高（用裁切方式控制） */
.tv-ticker-wrapper {
  overflow: hidden;    /* 多出來的高度裁掉 */
  display: flex;
  align-items: top;
}

/* 下面那行 TradingView 的字改成白色 */
.tradingview-widget-copyright .blue-text,
.tradingview-widget-copyright a {
  color: #ffffff !important;
}

/* 主體：左側主區 + 右側 Chat */
.dashboard {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(260px, 1.2fr);
  gap: 0.75rem;
  padding: 0.75rem;

  /* 重要：讓它佔滿 header 以外的高度 */
  flex: 1;
  min-height: 0;
  height: auto;
}

/* 左側：兩排布局 */
.main-left {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  height: 100%;
  min-height: 0;  
}

/* 第一排：圖表 + 新聞直播（佔左側 60% 高度） */
.row-top {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  flex: 6;                 /* 高度比例：6 */
  height: fit-content;
  gap: 1rem;
}

/* 第二排：新聞文章（佔左側 40% 高度） */
.row-bottom {
  flex: 4;                 /* 高度比例：4 */
  min-height: 0;           /* 避免 overflow */
  display: flex;
}

/* TradingView chart container */
.tv-container {
  width: 100%;
  overflow: hidden;
}

.tradingview-widget-container {
  border-radius: 0.75rem;
  height: 50vh;
}

#tradingview_taiex {
  height: 100%;
  border-radius: 0.75rem;
}
.chart-card {
  background: #020617;
  border: 1px solid #1f2937;
  border-radius: 0.75rem;
  padding: 0.75rem 0.9rem;
}


#candlestick-chart iframe {
  width: 100%;
  height: 45vh;
  min-height: 360px;
  border: none;
}

.card-body {
  padding: 0 !important;
}

/* Panel 基礎 */
.panel {
  background: #020617;
  border: 1px solid #1f2937;
  border-radius: 0.75rem;
  padding: 0.75rem 0.9rem;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.panel-header h2 {
  font-size: 1rem;
  font-weight: 500;
  width: auto;
}

.panel-subtitle {
  font-size: 0.75rem;
  color: #9ca3af;
}

.panel-body {
  flex: 1;
  background: #020617;
  overflow: hidden;
}

/* 圖表區 */
.chart-body {
  display: flex;
}

.chart-placeholder {
  border-radius: 0.5rem;
  border: 1px dashed #374151;
  background: #020617;
  color: #9ca3af;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  width: 100%;
}

/* 新聞直播 iframe */
.news-live-body iframe {
  width: 100%;
  height: 100%;
}

/* News Tabs */
.news-tab-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.news-tabs {
  display: flex;
  gap: 0.5rem;
}

.news-tab {
  padding: 4px 10px;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 999px;
  font-size: 0.75rem;
  color: #cfd3dc;
  cursor: pointer;
  transition: 0.15s ease;
}

.news-tab.active {
  background: #38bdf8;
  color: #020617;
  border-color: #38bdf8;
}

.news-tab:hover {
  background: #4b5563;
}

/* 新聞文章區 */
.panel-news-article {
  background: #020617;
  border-radius: 0.75rem;
  padding: 1.25rem 1.5rem 1.5rem;
  height: 100%;
}

.news-article-body {
  margin-top: 0.75rem;

  /* ✅ 超出就出現直向捲軸 */
  height: 100%;
  overflow-y: auto;
  padding-right: 4px; /* 可選：避免右邊文字貼太近捲軸 */
}

.news-tip {
  font-size: 0.8rem;
  color: #9ca3af;
  margin-bottom: 0.75rem;
  display: none !important;
}

.news-links {
  list-style: none;
  margin: 0;
  padding: 0;
}

.news-links li + li {
  margin-top: 0.5rem;
}

.news-links a {
  color: #e5e7eb;
  text-decoration: none;
  font-size: 1rem;
}

.news-links a:hover {
  text-decoration: underline;
}

.news-item-meta {
  font-size: 0.8rem;
  color: #9ca3af; /* 淡灰色 */
  margin-bottom: 0.8rem;
}

.news-item-source,
.news-item-time {
  color: #9ca3af;
  font-size: 0.8rem;
}

.news-error {
  font-size: 1rem;
  color: #f97373;
}

/* 右側 ChatGPT 小窗 */
.col-chat {
  order: 2;
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 40;
  justify-content: flex-end;          /* 右側滑入 */
  pointer-events: none;               /* 關閉時不吃點擊 */
  opacity: 0;
  transform: translateX(24px);        /* 稍微偏右一點 */
  transition:
    opacity 0.25s ease-out,
    transform 0.25s ease-out;
  inset: 56px 0 0 0;
  }

.chat-panel {
  background: #020617;
  border-radius: 0.75rem;
  border: 1px solid #1f2937;
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.chat-header {
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid #1f2937;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-title {
  font-size: 1rem;
  font-weight: 500;
}
.chat-subtitle {
  font-size: 0.75rem;
  color: #9ca3af;
}

/* 統一處理所有表單輸入：避免 iOS 自動放大 */
input,
textarea {
  font-size: 16px;   /* 一定要 >= 16px */
}

/* Chat header 右邊的關閉按鈕（所有尺寸都要看到） */
.chat-toggle-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid #4b5563;
  background: #020617;
  color: #e5e7eb;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  display: none;
}


.chat-toggle-btn::after {
  content: "✕";
}

/* Chat body */
.chat-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  justify-content: space-between;
  padding-bottom: 16px;
  overflow-y: auto;
  overflow-x: hidden;        /* 把超出的直接吃掉，避免左右滑 */
}

/* 讓長字、網址可以強制換行 */
.chat-msg,.chat-msg-text,.chat-body {
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.chat-body p{
  text-align: center;
  font-size: 1rem;
  opacity: 60%;
}

.chat-body.collapsed {
  display: none;
}

.chat-messages {
  flex: 1;
  padding: 0.6rem 0.8rem;
  overflow-y: auto;
  font-size: 0.85rem;

  /* 這兩行是關鍵 */
  display: flex;
  flex-direction: column;
}

.chat-msg {
  padding: 0.4rem 0.6rem;
  border-radius: 0.5rem;
  margin-bottom: 0.35rem;
  max-width: 100%;
  white-space: pre-wrap;
  justify-content: flex-end;
}
.chat-msg img{
  max-height: 80px;
  max-width: 200px;
}
#chat-welcome{
  text-align: center;
  font-size: 24px;
 margin: auto 0;
  width: 100%;
}
.chat-msg-bot {
  align-self: flex-start;
}

.chat-msg-user {
  background: #1e293b;
  align-self: flex-end;
}

.chat-input-row {
  border-top: 1px solid #1f2937;
  padding: 0.5rem 0.6rem;
  display: flex;
  gap: 0.5rem;
  align-items: stretch; /* 讓右側 CTA 撐滿高度 */
}

/* 左側整個輸入盒 */
.chat-input-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: 0.75rem;
  border: 1px solid #374151;
  background: #020617;
  overflow: hidden;
}

/* 上排輸入問題 */
#chat-input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: #e5e7eb;
  font-size: 1rem;
  padding: 0.75rem ;
  min-height: 2.1rem;
}

/* 中間分隔線 */
.chat-input-divider {
  height: 1px;
  background: #1f2937;
}

/* 下排容器：左＋上傳圖片，右 Enter 送出 switch */
.chat-input-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem;
  font-size: 0.75rem;
  color: #9ca3af;
  background-color:#111827;
}
.chat-input-bottom div {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

/* 模型選擇 dropdown */
.model-select {
  background: #020617;
  color: #e5e7eb;
  border: 1px solid #4b5563;
  border-radius: 0.45rem;
  font-size: 0.75rem;
  padding: 0.25rem;
  cursor: pointer;
}
.model-select:hover {
  border-color: #9ca3af;
}

/* 左下角：＋ 上傳圖片 */
.chat-plus-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  border: 1px solid #4b5563;
  background: #020617;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: #e5e7eb;
}
.chat-plus-btn:hover {
  border-color: #9ca3af;
}

/* 右下角：Enter 送出 switch */
.enter-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.enter-switch-text {
  font-size: 0.75rem;
}

.enter-switch input {
  display: none;
}

/* switch 外框 */
.enter-switch-pill {
  position: relative;
  width: 2.1rem;
  height: 1.1rem;
  border-radius: 999px;
  background: #111827;
  border: 1px solid #4b5563;
  box-sizing: border-box;
}

/* switch 圓點 */
.enter-switch-thumb {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 999px;
  background: #6b7280;
  transition: transform 0.18s ease, background 0.18s ease;
}

/* 勾選時：switch 開啟 */
.enter-switch input:checked + .enter-switch-pill {
  background: rgba(34, 197, 94, 0.2);
  border-color: #22c55e;
}
.enter-switch input:checked + .enter-switch-pill .enter-switch-thumb {
  transform: translate(1rem, -50%);
  background: #22c55e;
}

/* 右側 CTA 按鈕，整塊撐滿高度 */
.chat-send-btn {
  font-size: 0.85rem;
  padding: 0 0.9rem;
  border-radius: 0.75rem;
  border: none;
  background: #38bdf8;
  color: #020617;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-send-btn:hover {
  background: #0ea5e9;
}

/* ChatGPT 極簡風複製按鈕（白色 + 70% 不透明） */
.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;

  padding: 0;
  background: none;
  border: none;

  color: #ffffff;
  opacity: 0.7;

  cursor: pointer;
  font-size: 0.75rem;

  transition: opacity .2s ease;
}

/* Hover → 亮起 */
.copy-btn:hover {
  opacity: 1;
}

/* SVG icon 白色 */
.copy-svg {
  width: 16px;
  height: 16px;
  color: #ffffff;
}

/* 已複製 → 完全不透明，但仍維持白色極簡風 */
.copy-btn.copied {
  opacity: 1 !important;
  color: #ffffff !important;
}

.copy-btn.copied .copy-svg {
  color: #ffffff !important;
}

/* ===== Chat Tools：上傳圖片 + Enter 切換 ===== */

.chat-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.7rem;
  color: #9ca3af;
}

.chat-upload-btn {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid #374151;
  background: #030712;
  cursor: pointer;
}

.enter-toggle {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
}

.chat-image-hint {
  font-size: 0.7rem;
  color: #9ca3af;
  padding-left: 0.2rem;
}

.chat-image-preview {
  display: none;
}

.chat-image-thumb {
  position: relative;
  display: inline-block;
}

/* 縮成小縮圖，不會佔太高 */
.chat-image-thumb img {
  width: 40px;
  height: 40px;
  border-radius: 999px;         /* 或 8px，看你要圓形還是小膠囊感 */
  object-fit: cover;
  box-shadow: 0 0 3px rgba(0,0,0,0.35);
}

/* 如果一次很多張，讓它可以橫向捲動但高度維持小小一條 */
.chat-image-preview.has-image {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 2px;
}

.chat-image-remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #666666;
  color: white;
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 12px;
  cursor: pointer;
  line-height: 16px;
}

/* Skeleton loading for bot 回覆 */
.chat-msg-loading {
  border-radius: 0.5rem;
  width: 80%;
  display: flex;
  flex-direction: column;
  gap: 6px; /* 原本太大，改成更緊湊 */
  padding: 4px 0;
}

/* 單一骨架線 */
.skeleton-line {
  position: relative;
  overflow: hidden;
  height: 10px; /* 更細緻 */
  border-radius: 6px;
  background: #1f2937;
}


/* 最後一條短一點 */
.skeleton-line:last-child {
  width: 60%;
}

/* 亮光效果 */
.skeleton-line::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.10),
    transparent
  );
  transform: translateX(-100%);
  animation: skeleton-shimmer 1.2s infinite;
}

@keyframes skeleton-shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

@keyframes skeleton-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Bot 回覆區 */
.chat-msg-bot {
  position: relative;
  border-radius: 12px;
  margin-bottom: 12px;
  color: #e5e7eb;
  white-space: pre-wrap;
}

.bot-text {
  font-size: 1rem;
  line-height: 1.55;
}

.chat-body .chat-notice{
  font-size: 0.75rem;
}

/* 複製按鈕 */
.copy-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 6px 12px;
  font-size: 0.75rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: 0.2s ease;
}

.copy-btn:hover {
  background: #475569;
}

.copy-btn .copy-icon {
  font-size: 0.9rem;
}

/* 已複製 → 完全不透明，但仍維持白色極簡風 */
.copy-btn.copied {
  opacity: 1 !important;
  color: #ffffff !important;
}

.copy-btn.copied .copy-svg {
  color: #ffffff !important;
}

/* ---- ChatGPT 風格的小膠囊連結 ---- */
/* 如果你的氣泡 class 叫 .chat-message 或 .message.assistant，都可以保留這種寫法 */
.chat-message .link-chip,
.message.assistant .link-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.75rem;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    transform 0.1s ease;
}

.chat-message .link-chip:hover,
.message.assistant .link-chip:hover {
  background: rgba(255, 255, 255, 0.10);
  border-color: rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
}

.chat-message .link-chip-icon,
.message.assistant .link-chip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.8rem;
  height: 0.8rem;
  font-size: 0.8rem; /* 12px 左右 */
}

.chat-message .link-chip-label,
.message.assistant .link-chip-label {
  max-width: 9rem; /* 控制長度，配合 JS 的 12 字 */
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-capsule {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 36px;
  background: #1f2937;
  border: 1px solid #374151;
  font-size: 0.6rem;
  color: #e5e7eb;
  text-decoration: none;
  margin: 0 4px 2px;
}

.link-capsule:hover {
  background: #374151;
}

.link-capsule .favicon {
  width: 12px;
  height: 12px;
}

@media (prefers-reduced-motion: reduce) {
  .chat-message .link-chip,
  .message.assistant .link-chip {
    transition: none;
  }
}


/* RWD：大窗顯示 */
@media (min-width: 1024px) {
  .mobile{
    display: none;
  }
  .desktop{
    max-width: 480px;
  }

  .col-chat {
    /* 桌機 Chat：固定在右側 */
    position: relative !important;
    inset: auto !important;
    opacity: 1 !important;
    transform: none !important;
    pointer-events: auto !important;
    display: flex !important;
  }

  /* ⭐ 用視窗高度 - header 高度（你 header 大約 48px，可自行微調） */
  .chat-panel {
    height: calc(100dvh - 96px);
    display: flex;
    flex-direction: column;
  }

  .chat-body {
    flex: 1;
    min-height: 0;
  }

  /* 讓訊息區自己捲動，不要再給 100% 高度 */
  .chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  body.chat-overlay-open .col-chat {
    opacity: 1 !important;
    transform: none !important;
    pointer-events: auto !important;
  }

  .ai-toggle-btn {
    display: none !important;
  }
}

/* RWD：小螢幕單欄 */
@media (max-width: 1024px) {
  body{
    height: 100%;
  }
  .row-bottom{
    padding-bottom: 2rem;
  }
  .top-header{
    flex-wrap: wrap;
    gap: 0.5rem;
    position: fixed;
    width: 100%;
    padding: 1.5rem 1.25rem;
    z-index: 10;
  }
  .desktop{
    display: none;
  }

  .panel-news-article{
    padding: 0.75rem 0.9rem;
  }

  /* 小螢幕才顯示 AI 助手按鈕 */
  .ai-toggle-btn {
    display: inline-flex;
  }

  .mobile{
    display: flex;
    width: 100%;
    background: #020617;
    border: 1px solid #1f2937;
    border-radius: 0.75rem;
    padding: 0.25rem 0;
  }
  
  .dashboard {
    display: block;
    height: 100%;
    padding-top: 96px;
  }

  .main-left {
    order: 1;
    height: fit-content;
    gap: 0.75rem;
  }
  .chart-card {
    margin-bottom: 0.75rem;
    padding: 0;
  }
  .col-chat {
    order: 2;
    height: 600px;
  }
  .chat-panel {
    width: 100%;
    max-width: 640px;
    height: 100dvh;
    margin: 0;
    box-shadow: 0 0 40px rgba(0,0,0,0.6);
    border-radius: 0;
    z-index: 999;
  }


  /* 開啟 overlay 時：打開遮罩 + 從右邊滑入 */
  body.chat-overlay-open {
    overflow: hidden;
  }

  body.chat-overlay-open .col-chat {
    pointer-events: auto;
    opacity: 1;
    transform: translateX(0);
  }

  /* Chat header 裡的收合按鈕：只在小螢幕顯示 */
  .chat-toggle-btn {
    display: inline-flex;
  }

  /* TradingView chart container */
  .tv-container {
    width: 100%;
    overflow: hidden;
  }
  .row-top {
    display: block;
    height: fit-content;
    gap: 1rem;
  }
  .panel-news-live{
    width: 100%;
    height: 50vh;
  }

}

/* RWD：手機單欄 */
@media (max-width: 540px) {
  .top-header{
    position: fixed;
    width: 100%;
    z-index: 2;
    padding: 12px 24px;
  }

  .mobile{
    display: block;
  }

  .dashboard{
    padding-top: 72px;
  }

 /* 小螢幕：Chat 變成滿版區塊 */
  .col-chat {
    position: fixed;
    inset: 0;
    z-index: 40;
    padding: 0;
    background: #020617; /* 你也可以改成半透明 overlay */
    height: 100dvh; 
  }

  .chat-panel {
    width: 100%;
    height: 100dvh;
    border-radius: 0;              /* 小窗不要圓角 */
    box-shadow: none;
    z-index: 3;
  }

  /* Chat Header - 收合按鈕變「X」 */
  .chat-toggle-btn {
    display: inline-flex !important;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 600;
    color: #e5e7eb;
    background: transparent;
    border: none;
  }

  .chat-toggle-btn::after {
    content: "✕";
  }
}


/* 有 safe-area 的瀏覽器（iOS Safari）才會吃到這段 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .chat-input-row {
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  }
}