/* 網站後台樣式（admin.looptw.com）—— 深藍品牌色、乾淨、桌機/手機都能看 */
:root {
  --navy: #1e2a4a;
  --navy-2: #2d3d63;
  --accent: #3b82f6;
  --bg: #f4f6fb;
  --card: #ffffff;
  --line: #e4e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --good: #16a34a;
  --warn: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20,30,60,.08), 0 1px 2px rgba(20,30,60,.04);
}
* { box-sizing: border-box; }
/* 讓 hidden 屬性一定生效（蓋過 display:grid/flex 等規則）*/
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; }
.muted { color: var(--muted); }
.err { color: #dc2626; font-size: .9rem; }

/* ── 登入 ── */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--navy), var(--navy-2));
  padding: 1rem;
}
.login-card {
  background: var(--card); padding: 2.5rem 2rem; border-radius: 16px;
  width: 100%; max-width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.3);
  display: flex; flex-direction: column; gap: .75rem; text-align: center;
}
.login-card h1 { color: var(--navy); font-size: 1.5rem; }
.login-card input, .login-card button { padding: .8rem 1rem; border-radius: 10px; font-size: 1rem; }
.login-card input { border: 1px solid var(--line); }
.login-card button {
  background: var(--navy); color: #fff; border: 0; cursor: pointer; font-weight: 600;
  transition: background .15s;
}
.login-card button:hover { background: var(--navy-2); }

/* ── 頂欄 ── */
.topbar {
  background: var(--navy); color: #fff; padding: .6rem 1rem;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 1.15rem; }
.brand span { color: #9db2e0; font-weight: 400; }
.tabs { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.tab {
  background: transparent; color: #c7d2ea; border: 0; padding: .5rem .8rem;
  border-radius: 8px; cursor: pointer; font-size: .95rem; display: flex; align-items: center; gap: .35rem;
}
.tab:hover { background: rgba(255,255,255,.08); color: #fff; }
.tab.active { background: rgba(255,255,255,.15); color: #fff; font-weight: 600; }
.badge {
  background: #ef4444; color: #fff; border-radius: 999px;
  font-size: .7rem; padding: .05rem .4rem; min-width: 1.1rem; text-align: center;
}
.topbar-right { display: flex; gap: .5rem; align-items: center; }
.topbar-right select {
  background: var(--navy-2); color: #fff; border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px; padding: .4rem .6rem;
}
.ghost {
  background: transparent; color: #c7d2ea; border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px; padding: .4rem .7rem; cursor: pointer; font-size: .85rem;
}
.ghost:hover { background: rgba(255,255,255,.1); color: #fff; }

main { padding: 1.25rem; max-width: 1200px; margin: 0 auto; }

/* ── 概況卡片 ── */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat {
  background: var(--card); border-radius: var(--radius); padding: 1.1rem;
  box-shadow: var(--shadow);
}
.stat .k { color: var(--muted); font-size: .85rem; margin-bottom: .35rem; }
.stat .v { font-size: 1.9rem; font-weight: 700; color: var(--navy); line-height: 1; }
.stat .sub { color: var(--muted); font-size: .78rem; margin-top: .35rem; }

/* ── 今天發生什麼（摘要列）── */
.today-bar {
  background: linear-gradient(135deg, #eaf1fe, #f4f7fe);
  border: 1px solid #dbe4f5; border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: .85rem 1.1rem; margin-bottom: 1.25rem;
  color: var(--navy); font-weight: 600; font-size: .95rem; line-height: 1.5;
}

/* ── 卡片同比變化（較昨日同時）── */
.delta { font-size: .75rem; margin-top: .45rem; font-weight: 600; }
.delta.up { color: var(--good); }
.delta.down { color: #dc2626; }
.delta.flat, .delta.new { color: var(--muted); font-weight: 500; }
.delta-sub { color: var(--muted); font-weight: 400; }

/* ── 面板 ── */
.panel {
  background: var(--card); border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow); margin-bottom: 1.25rem;
}
.panel h2 { font-size: 1.05rem; color: var(--navy); margin-bottom: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; }
.grid-2 .panel { margin-bottom: 0; }

/* ── 轉換漏斗 ── */
.funnel-step { margin-bottom: 1rem; }
.funnel-step:last-child { margin-bottom: 0; }
.funnel-track { background: #eef1f7; border-radius: 8px; overflow: hidden; }
.funnel-bar {
  background: linear-gradient(90deg, var(--navy), var(--accent));
  min-width: 2.5rem; height: 2.2rem; border-radius: 8px;
  display: flex; align-items: center; justify-content: flex-end;
  transition: width .4s ease;
}
.funnel-v { color: #fff; font-weight: 700; font-size: .95rem; padding: 0 .7rem; }
.funnel-label { display: flex; justify-content: space-between; align-items: center; margin-top: .35rem; font-size: .9rem; color: var(--text); }
.funnel-rate { color: var(--accent); font-weight: 600; font-size: .82rem; }

/* ── 客戶旅程 ── */
.journey-list { display: flex; flex-direction: column; gap: .5rem; }
.journey-step { display: flex; align-items: center; gap: .7rem; }
.journey-idx {
  width: 1.6rem; height: 1.6rem; flex-shrink: 0; border-radius: 50%;
  background: var(--navy); color: #fff; display: grid; place-items: center;
  font-size: .75rem; font-weight: 700;
}
.journey-main { min-width: 0; }
.journey-path { font-weight: 600; color: var(--navy); font-size: .9rem; word-break: break-all; }
.journey-sub { color: var(--muted); font-size: .78rem; }

/* ── 橫條列表（來源/裝置/頁面共用）── */
.bar-row { margin-bottom: .7rem; }
.bar-row:last-child { margin-bottom: 0; }
.bar-label { display: flex; justify-content: space-between; font-size: .9rem; margin-bottom: .25rem; }
.bar-label .name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 75%; }
.bar-label .num { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-track { background: #eef1f7; border-radius: 6px; height: 8px; overflow: hidden; }
.bar-fill { background: linear-gradient(90deg, var(--accent), #60a5fa); height: 100%; border-radius: 6px; }
.empty { color: var(--muted); font-size: .9rem; padding: 1rem 0; text-align: center; }

/* ── 每日趨勢柱狀圖 ── */
.trend { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 1rem; }
.trend .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: .3rem; min-width: 0; }
.trend .col .b { width: 70%; max-width: 28px; background: var(--accent); border-radius: 4px 4px 0 0; transition: height .3s; }
.trend .col .d { font-size: .65rem; color: var(--muted); white-space: nowrap; transform: rotate(-45deg); transform-origin: center; margin-top: .3rem; }
.trend .col:hover .b { background: var(--navy); }

/* ── 表格 ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; min-width: 640px; }
th, td { text-align: left; padding: .65rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; }
tr:hover td { background: #f9fafd; }
.status-pill { font-size: .75rem; padding: .15rem .5rem; border-radius: 999px; border: 1px solid var(--line); background: #fff; }
select.status-sel { padding: .25rem .4rem; border-radius: 6px; border: 1px solid var(--line); }
.note-input { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: .3rem .4rem; font-size: .85rem; font-family: inherit; }

/* ── LINE 收件匣 ── */
.line-layout { display: grid; grid-template-columns: 300px 1fr; gap: 1.25rem; }
.line-list .conv {
  padding: .7rem; border-radius: 10px; cursor: pointer; border: 1px solid transparent;
  display: flex; gap: .6rem; align-items: center;
}
.line-list .conv:hover { background: #f3f6fc; }
.line-list .conv.active { background: #eaf1fe; border-color: #cfe0fd; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: #d5def0; flex-shrink: 0; object-fit: cover; display: grid; place-items: center; color: var(--navy); font-weight: 700; }
.conv-meta { min-width: 0; flex: 1; }
.conv-meta .nm { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta .lt { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 未讀：徽章 + 整列微高亮 + 名字加粗 */
.conv-unread {
  display: inline-block; min-width: 1.1rem; height: 1.1rem; line-height: 1.1rem;
  text-align: center; background: #ef4444; color: #fff; border-radius: 999px;
  font-size: .7rem; padding: 0 .35rem; margin-left: .4rem; vertical-align: middle;
}
.conv.has-unread { background: #fbfdff; }
.conv.has-unread .nm { font-weight: 700; color: var(--navy); }
.thread-body { min-height: 300px; max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; padding: .5rem 0; }
.msg { max-width: 75%; padding: .55rem .8rem; border-radius: 12px; font-size: .9rem; line-height: 1.4; word-break: break-word; }
.msg.in { align-self: flex-start; background: #eef1f7; border-bottom-left-radius: 3px; }
.msg.out { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.msg .t { display: block; font-size: .68rem; opacity: .7; margin-top: .25rem; }
/* 對話標頭：標題 + AI 狀態 + 交還按鈕 */
.thread-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.thread-head h2 { margin: 0; }
.thread-meta { display: flex; align-items: center; gap: .5rem; }
.ai-badge { font-size: .8rem; padding: .2rem .6rem; border-radius: 999px; font-weight: 600; }
.ai-badge.on { background: #dcfce7; color: #15803d; }
.ai-badge.off { background: #fef3c7; color: #b45309; }
.ghost-dark { background: var(--navy); color: #fff; border: 0; border-radius: 8px; padding: .35rem .7rem; cursor: pointer; font-size: .8rem; }
.ghost-dark:hover { background: var(--navy-2); }

/* 客戶檔案（長期記憶）面板 */
.profile-box { background: #f4f7fe; border: 1px solid #dbe4f5; border-radius: 10px; padding: .5rem .8rem; margin-bottom: .75rem; }
.profile-box summary { cursor: pointer; font-weight: 600; color: var(--navy); font-size: .9rem; }
.profile-text { margin-top: .5rem; font-size: .85rem; color: var(--text); white-space: pre-wrap; line-height: 1.6; }

/* 對話氣泡的發話者標籤 */
.msg .who { display: block; font-size: .68rem; font-weight: 700; opacity: .75; margin-bottom: .2rem; }

.reply-form { display: flex; gap: .5rem; margin-top: .75rem; }
.reply-form input { flex: 1; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 10px; font-size: .9rem; }
.reply-form button { background: var(--navy); color: #fff; border: 0; border-radius: 10px; padding: 0 1.2rem; cursor: pointer; font-weight: 600; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: .7rem 1.2rem; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 50; font-size: .9rem;
}

/* ── 手機 ── */
@media (max-width: 720px) {
  .line-layout { grid-template-columns: 1fr; }
  .topbar { gap: .5rem; }
  .tabs { order: 3; width: 100%; }
  .stat .v { font-size: 1.5rem; }
}

/* ── 多站管理（2026-11-01 新增）── */
.stat .unit { font-size: .9rem; color: var(--muted); }
.site-switch, .seg { display: inline-flex; background: rgba(255,255,255,.1); border-radius: 10px; padding: 3px; gap: 2px; }
.site-switch button, .seg button {
  background: transparent; border: 0; color: #c7d2ea; padding: .35rem .8rem; border-radius: 8px;
  cursor: pointer; font-size: .85rem; font-family: inherit;
}
.site-switch button.active { background: #fff; color: var(--navy); font-weight: 700; }
.seg { background: #eef1f7; }
.seg button { color: var(--muted); }
.seg button.active { background: #fff; color: var(--navy); font-weight: 700; box-shadow: var(--shadow); }

.site-tag { font-size: .72rem; font-weight: 700; padding: .1rem .5rem; border-radius: 999px; white-space: nowrap; }
.site-tag.zhijian { background: #e0ecff; color: #1d4ed8; }
.site-tag.detavela { background: #fde7d9; color: #b4471a; }

.compare { min-width: 520px; }
.compare tr.click { cursor: pointer; }
.red { color: #dc2626; }
.note { color: var(--muted); font-size: .8rem; margin-top: .75rem; line-height: 1.5; }
.warn-bar {
  background: #fff7e6; border: 1px solid #fcd9a0; color: #92400e; border-radius: var(--radius);
  padding: .75rem 1rem; margin-bottom: 1.25rem; font-size: .88rem; line-height: 1.6;
}

/* 統一收件匣 */
.inbox-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chk { font-size: .85rem; display: inline-flex; align-items: center; gap: .35rem; cursor: pointer; }
.inbox-item { border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; margin-bottom: .6rem; background: #fff; }
.inbox-item.pending { border-left: 4px solid #dc2626; }
.inbox-item.bulk { opacity: .6; }
.ii-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-size: .9rem; }
.ii-head .kind { font-size: .8rem; color: var(--muted); }
.ii-name { color: var(--navy); }
.ii-sub { font-size: .8rem; }
.ii-time { font-size: .78rem; margin-left: auto; }
.wait { font-size: .75rem; font-weight: 700; padding: .1rem .5rem; border-radius: 999px; background: #fef3c7; color: #b45309; }
.wait.late { background: #fee2e2; color: #b91c1c; }
.wait.ok { background: #dcfce7; color: #15803d; }
.ii-text { margin-top: .45rem; font-size: .88rem; white-space: pre-wrap; word-break: break-word; line-height: 1.55; }
.ii-meta { margin-top: .35rem; font-size: .8rem; word-break: break-all; }
.ii-actions { display: flex; gap: .5rem; align-items: center; margin-top: .6rem; flex-wrap: wrap; }
.ii-actions .note-input { flex: 1; min-width: 160px; }
a.ghost-dark { text-decoration: none; display: inline-block; }
.journey-step.act .journey-path { color: var(--accent); }

@media (max-width: 720px) {
  .ii-time { margin-left: 0; }
  .line-layout { grid-template-columns: 1fr; }
}
