/* hotpot-comment-bot 後台 — 手機優先 */
:root {
  --red: #c0392b;
  --red-dark: #96281b;
  --green: #1e8e3e;
  --bg: #f7f5f2;
  --card: #ffffff;
  --text: #2b2b2b;
  --muted: #8a8a8a;
  --line: #eae6e1;
  --warn-bg: #fdeeec;
  /* 三層 sticky（版頭 → 分頁列 → 日期列）的堆疊位置。
     這兩個值由 syncStickyOffsets() 在執行期量測後覆寫——
     寫死 px 會在字級／瀏覽器不同時錯位（原本 .tabs 寫死 53px，
     但版頭實際 59px，捲動時分頁列會壓到版頭 6px）。
     下面的預設值只是 JS 跑起來之前的 fallback。 */
  --topbar-h: 53px;
  --stack-top: 101px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.55;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); margin-top: 10px; }

/* ---- 登入（Origin UI sign-in dialog 風格） ---- */
.login-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 32px 28px; width: 100%; max-width: 380px; text-align: center;
  box-shadow: 0 10px 38px rgba(0,0,0,.10), 0 2px 8px rgba(0,0,0,.04);
}
.login-logo-ring {
  width: 56px; height: 56px; margin: 0 auto 16px; font-size: 26px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.login-logo-ring img { width: 36px; height: 36px; display: block; }
.login-card h1 { font-size: 19px; font-weight: 700; margin-bottom: 6px; letter-spacing: .01em; }
.login-sub { color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.login-label { display: block; text-align: left; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }
.login-label-gap { margin-top: 14px; }
.login-card input {
  width: 100%; padding: 10px 12px; font-size: 15px;
  border: 1px solid #d9d4ce; border-radius: 9px; background: #fff;
  transition: border-color .15s, box-shadow .15s; outline: none;
}
.login-card input::placeholder { color: #b5aea6; }
.login-card input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(192, 57, 43, .12); }
.login-submit { margin-top: 18px; width: 100%; border-radius: 9px; padding: 11px 0; font-size: 15px; }

/* ---- 版頭與分頁 ---- */
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; flex: 1; white-space: nowrap; }
/* 品牌圖示用 ::before：admin.js 以 textContent 改寫版頭文字（店名），寫在元素裡的 <img> 會被清掉 */
.brand::before {
  content: ""; display: inline-block; width: 22px; height: 22px; margin-right: 7px; vertical-align: -5px;
  background: url("/icon.png") center / contain no-repeat;
}
.page-select { max-width: 40%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.tabs { display: flex; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: var(--topbar-h); z-index: 19; }
/* 7 個分頁時字級要收一點，但高度維持 ≥44px 觸控目標 */
.tab { flex: 1; padding: 11px 0; font-size: 14px; border: none; background: none; color: var(--muted); border-bottom: 2.5px solid transparent; white-space: nowrap; }
.tab.active { color: var(--red); border-bottom-color: var(--red); font-weight: 700; }
main { padding: 12px 14px; max-width: 720px; margin: 0 auto; padding-bottom: 60px; }
h2 { font-size: 18px; margin: 6px 0 12px; }
h3 { font-size: 16px; margin: 22px 0 10px; }

/* ---- 按鈕 ---- */
.btn-primary { background: var(--red); color: #fff; border: none; border-radius: 10px; padding: 12px 18px; font-size: 16px; font-weight: 600; cursor: pointer; }
.btn-primary:active { background: var(--red-dark); }
.btn-primary:disabled { opacity: .5; }
.btn-ghost { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: 14px; color: var(--muted); }

/* ---- 總覽 ---- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat-card { background: var(--card); border-radius: 14px; padding: 16px; text-align: center; border: 1px solid var(--line); }
.stat-card.warn { background: var(--warn-bg); border-color: #f5c8c2; }
.stat-num { font-size: 30px; font-weight: 800; color: var(--red); }
.stat-card.warn .stat-num { color: var(--red-dark); }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 2px; }
.dm-grid { grid-template-columns: repeat(3, 1fr); }
.cost-card { background: #edf7ee; border: 1px solid #cde8d2; border-radius: 14px; padding: 16px; margin-top: 12px; }
.cost-num { font-size: 26px; font-weight: 800; color: var(--green); }
.cost-unit { font-size: 14px; color: var(--green); margin-left: 6px; }
.cost-tokens { font-size: 13px; color: var(--muted); margin-left: 8px; }
.cost-card p { margin-top: 6px; font-size: 13px; }

.intent-bars .bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.bar-label { width: 96px; font-size: 13px; text-align: right; flex-shrink: 0; }
.bar-track { flex: 1; background: var(--line); border-radius: 6px; height: 18px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--red); border-radius: 6px; min-width: 4px; }
.bar-count { font-size: 13px; color: var(--muted); width: 30px; }

.trend-chart { display: flex; align-items: flex-end; gap: 2px; height: 110px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.trend-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.trend-bar { background: var(--red); opacity: .82; border-radius: 2px 2px 0 0; min-height: 2px; }
.trend-empty { align-self: center; }

/* ---- 留言 ---- */
/* 手機優先：篩選列是通往內容的路，不該比內容還佔空間。
   實測 375×667 下三排篩選吃掉 48% 畫面，所以壓縮 padding 並讓它可橫向捲動 */
.chips {
  display: flex; gap: 6px; margin-bottom: 8px;
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;   /* 不要被擠扁到字疊在一起 */
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 7px 13px; font-size: 14px; color: var(--muted); white-space: nowrap;
}
.chip.active { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.comment-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.comment-card.complaint { border-color: #f0b4ab; background: var(--warn-bg); }
.comment-head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.badge { border-radius: 6px; padding: 1px 7px; font-size: 12px; font-weight: 600; }
.badge.fb { background: #e7f0fe; color: #1b64c2; }
.badge.ig { background: #fdeef7; color: #c1358c; }
.badge.line { background: #e8f7ea; color: #06a45a; }
.badge.probe { background: #fff3e0; color: #b26a00; font-weight: 600; }
/* native＝LINE 內建自動回應處理的，不是我們送的，樣式要跟 AI 泡泡明顯區隔 */
.bubble.native { background: #f4f6f4 !important; color: var(--muted); border: 1px dashed #cfd8cf; font-size: 13.5px; }
/* 頭像網址會過期（LINE 的尤其），載入失敗時 onerror 直接移除元素，不要留破圖 */
.dm-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--line); }
.badge.intent { background: #f1ede9; color: #6b625a; }
.badge.alert { background: var(--red); color: #fff; }
.comment-msg { margin: 6px 0; word-break: break-word; }
.comment-action { font-size: 13px; color: var(--muted); }
.comment-action b.sent { color: var(--green); }
.comment-action b.err { color: var(--red); }

/* ---- Google 評論 ---- */
.review-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 10px; }
.review-card.sensitive { border-color: #f0b4ab; background: var(--warn-bg); }
.review-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.stars { color: #f5a623; letter-spacing: 1px; font-size: 15px; }
.review-name { font-weight: 600; }
.review-status { margin-left: auto; font-size: 12px; border-radius: 6px; padding: 2px 8px; }
.review-status.ok { background: #edf7ee; color: var(--green); }
.review-status.warn { background: var(--warn-bg); color: var(--red); font-weight: 600; }
.review-status.muted { background: #f1ede9; color: var(--muted); }
.review-text { margin: 8px 0; line-height: 1.6; word-break: break-word; }
.review-alert { font-size: 13px; color: var(--red-dark); background: #fff; border: 1px solid #f0b4ab; border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.review-tools { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.review-tools .btn-ghost { font-size: 13px; padding: 7px 12px; }
.r-text {
  width: 100%; padding: 10px; font-size: 15px; font-family: inherit; line-height: 1.6;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; resize: vertical;
}
.review-foot { display: flex; gap: 8px; justify-content: flex-end; margin: 10px 0 6px; }
.review-foot .btn-primary { padding: 9px 18px; font-size: 15px; }

/* ---- 設定：雙開關 ---- */
.switch-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.switch-info { flex: 1; }
.switch-title { font-size: 15px; font-weight: 600; }
.switch-desc { font-size: 13px; margin-top: 2px; }
.switch-desc.on { color: var(--green); }
.switch-desc.off { color: var(--muted); }

/* ---- 日期選擇 ---- */
/* 「更新於 X 分鐘前 ＋ 重新整理」。整列獨立一行、不塞進 .date-bar——
   手機上那一列已經有下拉選單＋今天＋日期欄＋✕，再多一顆就爆版 */
.fresh-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin: 0 0 8px; min-height: 30px;
}
.fresh-ago { font-size: 13px; color: var(--muted); }
/* 這顆是會被常按的（「有沒有新留言」），所以比 #date-clear 那種偶爾用的大一點。
   手機單手操作，太小會按不到或按到旁邊 */
.fresh-reload { padding: 9px 16px; font-size: 13px; flex-shrink: 0; }
.fresh-reload[disabled] { opacity: .55; }

.date-bar { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; }
.date-bar .chip { padding: 8px 14px; }
.date-input, .plat-select {
  padding: 8px 10px; font-size: 14px; font-family: inherit; min-width: 0;
  border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--text);
}
.date-input { flex: 1; min-width: 0; }   /* 日期欄吃掉剩餘寬度；min-width:0 讓兩個並排時不會撐爆 */
.date-sep { color: var(--muted); flex: none; }
.plat-select { flex-shrink: 0; }
#date-clear { padding: 7px 11px; flex-shrink: 0; }

/* ---- 日期分組 ---- */
.day-group { margin-bottom: 14px; }
.day-head {
  display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none;
  padding: 9px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  /* 捲動時釘在分頁列下方，滑到一半才不會忘記在看哪一天 */
  position: sticky; top: var(--stack-top); z-index: 5;
}
.day-head::-webkit-details-marker { display: none; }
.day-head::before {
  content: '▸'; color: var(--muted); font-size: 12px; transition: transform .15s;
}
.day-group[open] > .day-head::before { transform: rotate(90deg); }
.day-group[open] > .day-head { border-radius: 10px 10px 0 0; }
.day-label { font-weight: 700; font-size: 15px; }
.day-count { font-size: 13px; color: var(--muted); margin-left: auto; }
.day-alert { font-size: 13px; color: var(--red); font-weight: 600; }
.day-group > .comment-card { border-radius: 0; border-top: none; }
.day-group > .comment-card:last-child { border-radius: 0 0 10px 10px; }

/* ---- 文案／知識庫 分段 ---- */
.seg-row { display: flex; gap: 6px; margin: 12px 0; background: #efeae4; border-radius: 999px; padding: 3px; }
.seg { flex: 1; border: none; background: none; border-radius: 999px; padding: 8px 0; font-size: 14px; color: var(--muted); font-family: inherit; }
.seg.active { background: var(--card); color: var(--text); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* ---- 知識庫卡片 ---- */
.kb-card.kb-off { background: #faf8f6; border-style: dashed; }
.kb-tag { font-size: 12px; border-radius: 5px; padding: 2px 7px; background: #f1ede9; color: var(--muted); }
.kb-tag.expired { background: var(--warn-bg); color: var(--red); font-weight: 600; }
.kb-warn { color: var(--red); }
.kb-card .kb-content { width: 100%; min-height: 120px; padding: 10px; font-size: 14.5px; font-family: inherit; line-height: 1.7; border: 1px solid var(--line); border-radius: 10px; resize: vertical; }
.kb-card .date-input { width: 100%; }
.kb-notes-label { color: #8a6d1f !important; }
.kb-card .kb-notes {
  width: 100%; min-height: 64px; padding: 10px; font-size: 14px; font-family: inherit;
  line-height: 1.6; border: 1px dashed #e0d4b4; border-radius: 10px; background: #fffdf6; resize: vertical;
}
.kb-add { width: 100%; padding: 12px; margin-bottom: 20px; }

/* ---- 分平台明細：每個平台一區，區內用 .stat-grid + .stat-card ---- */
/* 品牌名：店名可能很長（何家香香鴛鴦鍋399吃到飽），手機上要截尾不換行。
   min-width:0 是必要的——flex 子元素預設 min-width:auto，不加的話
   它會拒絕縮到內容寬度以下，把旁邊的按鈕擠出畫面 */
.brand { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 營運後台入口：手機上只留圖示。版頭已經有店名＋門市切換＋登出，
   再塞四個字會把店名壓成「店…」——店名比這顆按鈕重要 */
#console-link .link-icon { display: none; }
@media (max-width: 480px) {
  #console-link .link-full { display: none; }
  #console-link .link-icon { display: inline; font-size: 16px; }
  #console-link { padding: 6px 9px; }
}

/* 帳號卡的編輯區 */
.acct-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.acct-pages-edit { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.acct-pages-edit label { display: block; font-size: 13px; padding: 4px 0; }

/* ---- 連接粉專 ---- */
.conn-card { background: var(--card); border: 1px solid var(--line); border-radius: 13px; padding: 15px 16px; margin-bottom: 10px; }
.conn-card.empty { border-style: dashed; text-align: center; padding: 26px 18px; }
.conn-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.conn-name { font-weight: 700; font-size: 15px; }
.conn-meta { font-size: 13px; color: var(--muted); margin-top: 5px; line-height: 1.6; }
.conn-acts { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.conn-hint { font-size: 13px; color: var(--muted); line-height: 1.65; margin-top: 8px; }
.conn-pick { background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.conn-pick.taken { opacity: .55; }
.conn-pick-info { flex: 1; min-width: 0; }
.conn-pick-name { font-weight: 700; font-size: 14px; }
.conn-pick-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
/* Google 商家地點選擇器。刻意不叫 conn-pick——tests/connect-api.test.js 用
   indexOf('conn-pick') 切出 FB 那段原始碼做守門比對，同前綴會讓切片位移 */
.gloc-row { background: var(--card); border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.gloc-row.taken { opacity: .55; }
.gloc-info { flex: 1; min-width: 0; }
.gloc-name { font-weight: 700; font-size: 14px; }
.gloc-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; word-break: break-all; }
.conn-banner { padding: 11px 14px; border-radius: 11px; margin-bottom: 12px; font-size: 14px; line-height: 1.6; }
.conn-banner.ok { background: #e6f6ea; color: #1b6b32; border: 1px solid #cbe8d3; }
.conn-banner.warn { background: var(--warn-bg); color: #8c2d20; border: 1px solid #f2cfca; }

.sec-divider { border: none; border-top: 1px solid var(--line); margin: 22px 0 18px; }

/* ---- 待辦（首頁主角）---- */
.todo-group { margin-bottom: 18px; }
.todo-head { display: flex; align-items: baseline; gap: 7px; margin-bottom: 8px; }
.todo-title { font-size: 15px; font-weight: 700; }
.todo-title.decide { color: var(--red); }
.todo-title.answer { color: #b26a00; }
.todo-count { color: #fff; border-radius: 999px; padding: 0 8px; font-size: 12px; font-weight: 700; }
.todo-count.decide { background: var(--red); }
.todo-count.answer { background: #b26a00; }
.todo-hint { font-size: 12.5px; color: var(--muted); }

.todo-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 13px; margin-bottom: 8px;
}
.todo-card.decide { border-color: #f0c2bb; border-left: 3px solid var(--red); }
.todo-card.answer { border-color: #e8b98a; border-left: 3px solid #b26a00; }
.todo-card.stale { border-left-color: #d8cfc6; }
.todo-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.todo-who { font-weight: 700; font-size: 14px; }
.todo-when { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.todo-when.overdue { background: var(--warn-bg); color: var(--red); font-weight: 700; padding: 1px 7px; border-radius: 5px; }
.todo-when.aging { color: #b26a00; font-weight: 700; }
.todo-text { font-size: 14px; margin-top: 4px; line-height: 1.5; }
.todo-why { font-size: 12.5px; color: #b26a00; margin-top: 4px; }
.todo-draft {
  margin-top: 7px; padding: 8px 10px; background: var(--bg); border-radius: 7px;
  font-size: 13px; line-height: 1.55; color: var(--text);
}
.todo-draft b { color: var(--muted); font-weight: 400; }
.todo-acts { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

.todo-empty { text-align: center; padding: 30px 16px 26px; }
.todo-empty .big { font-size: 34px; display: block; }
.todo-empty .t { font-weight: 700; margin-top: 6px; }
.todo-empty .s { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.55; }

/* ---- 週趨勢 ---- */
.week-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 18px; }
.week-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.week-num { font-size: 24px; font-weight: 800; }
.week-delta { font-size: 12.5px; padding: 1px 8px; border-radius: 5px; font-weight: 700; }
.week-delta.up { background: #e6f6ea; color: var(--green); }
.week-delta.down { background: var(--warn-bg); color: var(--red); }
.week-delta.flat { background: #f1f1f1; color: var(--muted); }
.week-bars { display: flex; align-items: flex-end; gap: 4px; height: 46px; }
.week-bars div { flex: 1; background: #d8cfc6; border-radius: 3px 3px 0 0; min-height: 3px; }
.week-bars div.recent { background: #b8ab9e; }
.week-bars div.now { background: var(--red); }
.week-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 5px; }
.week-note { margin-top: 11px; padding-top: 11px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); line-height: 1.6; }
.week-note b { color: var(--text); }

/* LINE 好友成效 */
.line-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin: 16px 0; }
.line-card h3 { font-size: 14px; margin-bottom: 4px; }
.line-hero { display: flex; align-items: baseline; gap: 10px; margin: 10px 0 4px; }
.line-hero-num { font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
.line-hero-label { font-size: 13px; color: var(--muted); }
.delta { font-size: 14px; font-weight: 700; }
.delta.up { color: #1e8e3e; }
.delta.down { color: var(--red); }
.delta.flat { color: var(--muted); }
.line-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.line-grid div { text-align: center; }
.line-grid b { display: block; font-size: 17px; }
.line-grid small { font-size: 12px; color: var(--muted); }
/* 迷你長條圖：純 CSS，不引外部圖表庫（CSP 也不允許） */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 40px; margin-top: 12px; }
.spark div { flex: 1; background: #06c755; border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.spark div.today { background: var(--red); opacity: 1; }
.spark-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.quota-bar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.quota-bar i { display: block; height: 100%; background: #06c755; }
.quota-bar i.warn { background: var(--red); }

.plat-section { margin-bottom: 16px; }
.plat-section-title { font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.badge.google { background: #fff4e5; color: #b26a00; }
.info-box.subtle { background: var(--surface-2, #faf8f6); border: 1px solid var(--border);
  color: var(--muted); font-size: 13px; line-height: 1.7; margin-top: 16px; }
.info-box.subtle strong { color: var(--text); }
.plat-pending { font-size: 13px; color: var(--muted); background: var(--surface-2, #faf8f6);
  border: 1px dashed var(--border); border-radius: 12px; padding: 12px 14px; line-height: 1.5; }

.stat-sub { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.45; }
.stat-sub.alert { color: var(--red); font-weight: 600; }

/* ---- 面向標籤 ---- */
.aspect-row { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }
.aspect { font-size: 12px; color: #6b625a; background: #f1ede9; border-radius: 5px; padding: 2px 8px; }

/* ---- AI 彙整分析 ---- */
.insight-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 14px 0; }
.insight-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.insight-head > div:first-child { flex: 1 1 100%; margin-bottom: 8px; }
.insight-head .btn-primary { padding: 8px 16px; font-size: 14px; }
.insight-body { white-space: pre-wrap; line-height: 1.75; font-size: 14.5px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
#insight-result .error { font-size: 14px; }

/* ---- 實際送出的回覆 ---- */
.sent-box { margin-top: 8px; border-left: 3px solid #d8e8dc; padding-left: 10px; }
.sent-row { display: flex; gap: 8px; font-size: 14px; line-height: 1.6; margin-bottom: 5px; }
.sent-row:last-child { margin-bottom: 0; }
.sent-label {
  flex-shrink: 0; align-self: flex-start; font-size: 12px; font-weight: 600;
  background: #edf7ee; color: var(--green); border-radius: 5px; padding: 2px 7px; margin-top: 2px;
}
.sent-text { color: #5b5b5b; word-break: break-word; white-space: pre-wrap; }

/* ---- 客訴提醒 ---- */
.tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; margin-left: 3px; padding: 0 4px;
  background: var(--red); color: #fff; border-radius: 999px;
  font-size: 11px; font-weight: 700; vertical-align: 2px;
}
.draft-alert {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--warn-bg); border: 1px solid #f0b4ab; border-radius: 12px;
  padding: 12px 14px; margin-bottom: 14px; font-size: 15px;
}
.draft-alert .btn-primary { margin-left: auto; padding: 8px 14px; font-size: 14px; }

/* ---- 手動回覆 ---- */
.manual-box { margin-top: 10px; }
.manual-open {
  cursor: pointer; list-style: none; font-size: 13.5px; color: var(--muted);
  padding: 7px 12px; border: 1px dashed var(--line); border-radius: 8px; display: inline-block;
}
.manual-open::-webkit-details-marker { display: none; }
.manual-box[open] .manual-open { color: var(--red); border-color: #f0b4ab; border-style: solid; }
.manual-body { margin-top: 10px; padding: 12px; background: #fafafa; border: 1px solid var(--line); border-radius: 10px; }
.manual-body .field-label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
.m-intent { width: 100%; padding: 9px 10px; font-size: 14px; font-family: inherit; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.manual-tools { display: flex; gap: 8px; margin: 10px 0 8px; flex-wrap: wrap; }
.manual-tools .btn-ghost { font-size: 13px; padding: 7px 12px; }
.m-text {
  width: 100%; padding: 10px; font-size: 15px; font-family: inherit; line-height: 1.6;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; resize: vertical;
}
.manual-foot { display: flex; justify-content: flex-end; margin: 10px 0 6px; }
.manual-foot .btn-primary { padding: 9px 18px; font-size: 15px; }

/* ---- 客訴草稿 ---- */
.draft-box { margin-top: 10px; padding: 12px; background: #fffdf6; border: 1px solid #efd9a8; border-radius: 10px; }
.draft-head { font-size: 13px; color: #8a6d1f; margin-bottom: 8px; }
.draft-head b { color: var(--red); }
.draft-text {
  width: 100%; padding: 10px; font-size: 15px; font-family: inherit; line-height: 1.6;
  border: 1px solid #e0d4b4; border-radius: 8px; background: #fff;
  resize: none; overflow: hidden; /* 高度由 autoGrow() 依內容設定 */
}
.draft-readonly { padding: 10px; font-size: 15px; line-height: 1.6; background: #fff; border: 1px solid #e0d4b4; border-radius: 8px; white-space: pre-wrap; }
.draft-foot { display: flex; gap: 8px; justify-content: flex-end; margin: 10px 0 6px; }
.draft-foot .btn-primary { padding: 9px 18px; font-size: 15px; }
.draft-done { margin-top: 8px; font-size: 13px; color: var(--green); }
.draft-done.muted { color: var(--muted); }

/* ---- 文案 ---- */
.rule-locked { background: var(--warn-bg); border: 1px solid #f5c8c2; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; line-height: 1.6; margin-top: 4px; }
.rule-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.rule-head { display: flex; align-items: center; gap: 8px; }
.rule-title { font-weight: 700; flex: 1; }
.rule-desc { font-size: 13px; color: var(--muted); margin: 4px 0 10px; }
.rule-card label.field-label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.rule-card select, .rule-card textarea { width: 100%; padding: 10px; font-size: 15px; border: 1px solid var(--line); border-radius: 10px; font-family: inherit; }
.rule-card textarea { min-height: 74px; resize: vertical; }
.rule-foot { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.rule-foot .btn-primary { padding: 9px 20px; font-size: 15px; margin-left: auto; }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }

/* ---- 私訊 ---- */
.dm-item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; cursor: pointer; }
.dm-item:active { background: #faf7f4; }
.dm-item-head { display: flex; align-items: center; gap: 8px; }
.dm-item-name { font-weight: 700; flex: 1; }
.dm-item-time { font-size: 12px; color: var(--muted); }
.dm-item-preview { font-size: 14px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-item-preview b { color: var(--text); font-weight: 600; }
.badge.paused { background: #fdeeec; color: var(--red-dark); }
/* 廣告來源：用綠色跟平台標籤區隔，老闆掃一眼就知道哪些客人是花錢買來的 */
.badge.ad { background: #edf7ee; color: var(--green); max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.thread-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.thread-name { font-weight: 700; flex: 1; }
.dm-messages { display: flex; flex-direction: column; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; min-height: 200px; max-height: 55dvh; overflow-y: auto; }
.bubble { max-width: 82%; padding: 9px 12px; border-radius: 14px; font-size: 15px; word-break: break-word; }
.bubble .bubble-meta { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.bubble.user { align-self: flex-start; background: #f1ede9; border-bottom-left-radius: 4px; }
.bubble.assistant { align-self: flex-end; background: #fdeeec; border-bottom-right-radius: 4px; }
.bubble.human { align-self: flex-end; background: #e8f5ea; border-bottom-right-radius: 4px; }
.dm-compose { display: flex; gap: 8px; margin-top: 12px; align-items: flex-end; }
.dm-compose textarea { flex: 1; padding: 10px 12px; font-size: 15px; border: 1px solid #d9d4ce; border-radius: 10px; font-family: inherit; resize: none; }
.dm-compose .btn-primary { padding: 10px 18px; font-size: 15px; }

/* ---- 說明摺疊區（預設收起，不佔版面但需要時查得到） ---- */
.howto { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; }
.howto summary { padding: 12px 14px; font-size: 14px; font-weight: 600; cursor: pointer; list-style: none; }
.howto summary::-webkit-details-marker { display: none; }
.howto summary::after { content: '⌄'; float: right; color: var(--muted); font-size: 16px; line-height: 1; }
.howto[open] summary::after { content: '⌃'; }
.howto[open] summary { border-bottom: 1px solid var(--line); }
.howto-body { padding: 12px 14px 14px; font-size: 14px; color: #3a3a3a; }
.howto-body p { margin-bottom: 8px; }
.howto-body ol { margin: 8px 0 8px 20px; }
.howto-body li { margin-bottom: 7px; }
.howto-warn { background: var(--warn-bg); border-radius: 8px; padding: 10px 12px; font-size: 13px; line-height: 1.7; }

/* ---- 設定 ---- */
/* 一張卡＝一個粉專，裡面直向堆疊「粉專名 + 每個開關一列」 */
.page-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.page-card .page-name { margin-bottom: 4px; }
.page-card .switch-row:first-of-type { border-top: none; padding-top: 6px; }
.page-info { flex: 1; }
.page-name { font-weight: 700; }
.page-status { font-size: 13px; margin-top: 2px; }
.page-status.on { color: var(--green); }
.page-status.off { color: var(--muted); }
.toggle { position: relative; width: 52px; height: 30px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 100%; height: 100%; position: absolute; z-index: 2; cursor: pointer; }
.toggle .knob { position: absolute; inset: 0; background: #d5d0ca; border-radius: 999px; transition: .18s; }
.toggle .knob::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; background: #fff; border-radius: 50%; transition: .18s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.toggle input:checked + .knob { background: var(--green); }
/* 未開通的功能：開關撥不動，整列調淡但字仍讀得清楚（那行字正是在解釋為什麼撥不動） */
.toggle input:disabled { cursor: not-allowed; }
.switch-row.locked .switch-title { opacity: .55; }
.switch-row.locked .toggle .knob { background: #e2ddd7; }
.toggle input:checked + .knob::after { left: 25px; }
.info-box { background: var(--card); border: 1px dashed var(--line); border-radius: 12px; padding: 14px; font-size: 14px; margin-top: 18px; }
.info-box p { margin-top: 4px; color: var(--muted); }

/* ---- 帳號 ---- */
.acct-input {
  width: 100%; padding: 10px 12px; font-size: 15px;
  border: 1px solid #d9d4ce; border-radius: 10px; background: #fff;
  font-family: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
.acct-input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(192, 57, 43, .12); }
.acct-reset { flex-shrink: 0; }
#tab-accounts .page-card { align-items: flex-start; }
#tab-accounts .page-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* ---- Toast ---- */
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #2b2b2b; color: #fff; border-radius: 999px; padding: 10px 20px; font-size: 14px; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.err { background: var(--red); }

@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .bar-label { width: 120px; }
}

/* ── 密碼顯示切換 ──────────────────────────────────────────
   由 admin.js 的 enhancePasswordFields() 動態包裝所有 input[type=password]。
   看不到自己打了什麼很難確認（尤其手機），所以每個密碼欄位都給一個切換。 */
.pw-wrap { position: relative; display: block; }
/* 讓文字不會跑到按鈕底下 */
.pw-wrap > input { padding-right: 58px !important; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; cursor: pointer;
  font-size: 13px; color: var(--muted, #7a736c); font-family: inherit;
  padding: 6px 8px; border-radius: 6px; line-height: 1;
  /* 手機好按：視覺小但點擊區夠大 */
  min-width: 44px; min-height: 32px;
}
.pw-toggle:hover { background: rgba(0,0,0,.05); color: var(--text, #2b2b2b); }
.pw-toggle:focus-visible { outline: 2px solid var(--red); outline-offset: 1px; }
