:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #1d2433;
  --muted: #6b7385;
  --line: #e3e7ee;
  --brand: #2563eb;
  --brand-soft: #e8f0fe;
  --side: #121a2b;
  --side-text: #b9c2d6;
  --ok: #15803d; --ok-soft: #e6f6ec;
  --warn: #b45309; --warn-soft: #fdf3e2;
  --bad: #b91c1c; --bad-soft: #fdecec;
  --info: #6d28d9; --info-soft: #f1ebfd;
  --gray-soft: #eef0f4;
  --radius: 12px;
  --gap: 20px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Noto Sans TC", -apple-system, "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 14px; }

/* layout */
.app { display: flex; min-height: 100vh; }
.side {
  width: 220px; flex-shrink: 0; background: var(--side); color: var(--side-text);
  padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
}
.side .logo { color: #fff; font-weight: 700; font-size: 17px; padding: 0 10px 22px; display: flex; gap: 8px; align-items: center; }
.side nav a {
  display: flex; align-items: center; gap: 10px; color: var(--side-text); padding: 9px 12px;
  border-radius: 8px; margin-bottom: 4px; font-size: 14.5px;
}
.side nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.side nav a.on { background: var(--brand); color: #fff; }
.side .bottom { margin-top: auto; font-size: 13px; padding: 0 10px; }
.side .bottom button { background: none; border: 0; color: var(--side-text); cursor: pointer; padding: 0; font: inherit; }
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: var(--gap); flex-wrap: wrap; }
.sub { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

/* blocks */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; margin-bottom: var(--gap); }
.grid { display: grid; gap: var(--gap); margin-bottom: var(--gap); }
.grid > * { min-width: 0; }
.grid > .card { margin-bottom: 0; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: 2fr 1fr; }
.kpis { grid-template-columns: repeat(5, 1fr); }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .val { font-size: 26px; font-weight: 700; margin-top: 4px; }
.kpi .val small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 14px; margin-bottom: var(--gap); font-size: 14px; }
.flash { background: var(--ok-soft); color: var(--ok); border-radius: 10px; padding: 10px 14px; margin-bottom: var(--gap); }
.errors { background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 10px 14px; margin-bottom: var(--gap); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; min-width: 220px; }
.empty { color: var(--muted); text-align: center; padding: 28px 0; }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 500; background: var(--gray-soft); color: var(--muted); }
.b-renew, .b-completed { background: var(--ok-soft); color: var(--ok); }
.b-not_now, .b-do_not_call, .b-failed { background: var(--bad-soft); color: var(--bad); }
.b-more_info, .b-human { background: var(--info-soft); color: var(--info); }
.b-call_later, .b-no_answer, .b-busy, .b-pending { background: var(--warn-soft); color: var(--warn); }
.b-test { background: var(--brand-soft); color: var(--brand); }
.flag { color: var(--warn); font-weight: 600; }

/* forms */
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--brand); color: #fff; border: 0; border-radius: 8px; padding: 8px 16px; font: inherit; font-size: 14px; cursor: pointer; }
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.ghost { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
input, select, textarea { font: inherit; font-size: 14px; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; color: var(--text); max-width: 100%; }
textarea { width: 100%; min-height: 90px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 13.5px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select { width: 100%; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

/* bars */
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 96px 1fr 44px; gap: 10px; align-items: center; font-size: 13.5px; }
.bar { height: 10px; background: var(--gray-soft); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 999px; background: var(--brand); }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .stack { width: 100%; max-width: 26px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; }
.chart .t { background: #c7d6f7; border-radius: 4px 4px 0 0; }
.chart .a { background: var(--brand); }
.chart .d { font-size: 11px; color: var(--muted); }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* call detail */
.meta { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.meta > div > span:first-child { display: block; color: var(--muted); font-size: 12.5px; margin-bottom: 2px; }
audio { width: 100%; margin-top: 4px; }
.transcript { display: flex; flex-direction: column; gap: 12px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; font-size: 13px; font-weight: 600; color: #fff; background: var(--brand); }
.customer .avatar { background: #64748b; }
.cut { color: var(--warn); font-size: 12px; }

/* playground */
.talk { text-align: center; padding: 26px 0 8px; }
.mic { width: 110px; height: 110px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; font-size: 15px; cursor: pointer; box-shadow: 0 6px 20px rgba(37,99,235,.3); }
.mic.live { background: var(--bad); box-shadow: 0 0 0 10px rgba(185,28,28,.12); }
.mic:disabled { background: #9aa3b5; box-shadow: none; cursor: not-allowed; }
.status-line { margin-top: 14px; color: var(--muted); font-size: 14px; }
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { padding: 6px 0; display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); font-size: 14px; }
.checks li:last-child { border-bottom: 0; }
.live-log { min-height: 160px; max-height: 420px; overflow-y: auto; }

/* login */
.login { max-width: 380px; margin: 12vh auto; }
.login .card { padding: 30px; }
.login .field { margin-bottom: 14px; }

.pager { margin-top: 16px; display: flex; gap: 6px; flex-wrap: wrap; font-size: 14px; }
.pager a, .pager span { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.pager .cur { background: var(--brand); color: #fff; border-color: var(--brand); }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .meta { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .app { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; padding: 12px 16px; }
  .side .logo { padding: 0 0 10px; }
  .side nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .side nav a { margin: 0; padding: 6px 10px; }
  .side .bottom { display: none; }
  .main { padding: 18px 16px 40px; }
  .g2, .g3, .form-grid { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
.btn.on { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }
td .btn + .btn { margin-left: 4px; }
@media (max-width: 820px) {
  table.stack tr:first-child { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { border: 0; padding: 3px 0; white-space: normal; min-width: 0; display: flex; gap: 10px; align-items: flex-start; }
  table.stack td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12.5px; flex: 0 0 64px; white-space: nowrap; padding-top: 2px; }
  table.stack td.empty { display: block; }
}

/* ── 逐字稿樣式 ── */
.turn .ts { cursor: pointer; color: var(--brand); }
.turn .lat { color: var(--muted); font-size: 12px; margin-left: 8px; }
.turn .cut { color: var(--warn); font-size: 12px; margin-left: 8px; }
.turn.playing { background: var(--brand-soft); }

/* 1 置中聊天 */
.tr1 { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.t1 { display: flex; gap: 10px; max-width: 82%; border-radius: 14px; }
.t1.customer { align-self: flex-end; flex-direction: row-reverse; text-align: right; }
.t1.customer .bubble { text-align: left; }
.t1 .who { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.t1 .bubble { display: inline-block; background: var(--gray-soft); border-radius: 14px; padding: 9px 14px; }
.t1.ai .bubble { background: var(--brand-soft); }
.t1.playing { background: none; }
.t1.playing .bubble { outline: 2px solid var(--brand); }

/* 2 全部靠左 */
.tr2 { display: flex; flex-direction: column; }
.t2 { display: flex; gap: 12px; padding: 10px 8px; }
.t2 + .t2 { border-top: 1px solid var(--line); }
.t2 .who { font-size: 13px; display: flex; gap: 10px; align-items: baseline; margin-bottom: 2px; }
.t2 .who .ts { font-size: 12px; }
.t2.customer b { color: #475569; }
.t2.ai b { color: var(--brand); }

/* 3 表格 */
.tr3 td { vertical-align: top; }
.tr3 tr.ai td:nth-child(3) { color: var(--text); }
.tr3 tr.customer td:nth-child(3) { color: #334155; font-weight: 500; }

/* 4 中間時間軸 */
.tr4 { position: relative; display: flex; flex-direction: column; gap: 10px; max-width: 880px; margin: 0 auto; }
.tr4::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--line); transform: translateX(-1px); }
.t4 { display: grid; grid-template-columns: 1fr 64px 1fr; align-items: start; border-radius: 10px; }
.t4 .lane.left { text-align: right; }
.t4 .axis { text-align: center; position: relative; z-index: 1; }
.t4 .axis .ts { background: var(--panel); padding: 2px 6px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; }
.t4 .who { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.t4 .bubble { display: inline-block; text-align: left; background: var(--gray-soft); border-radius: 14px; padding: 9px 14px; }
.t4.ai .bubble { background: var(--brand-soft); }
.t4.playing { background: none; }
.t4.playing .bubble { outline: 2px solid var(--brand); }

/* 5 卡片 */
.tr5 { display: flex; flex-direction: column; gap: 10px; }
.t5 { border: 1px solid var(--line); border-left: 4px solid #94a3b8; border-radius: 10px; padding: 10px 14px; }
.t5.ai { border-left-color: var(--brand); }
.t5 .head { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; font-size: 13px; }
.t5 .head .lat, .t5 .head .cut { margin-left: 0; }

@media (max-width: 820px) {
  .t1 { max-width: 95%; }
  .tr4::before { left: 28px; }
  .t4 { grid-template-columns: 56px 1fr; }
  .t4 .axis { order: -1; }
  .t4 .lane.left { text-align: left; }
  .t4 .lane:empty { display: none; }
}

/* 詳情頁左右兩欄：左資訊＋錄音（捲動時固定），右逐字稿 */
.detail2 { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: var(--gap); align-items: start; }
.detail2 .info { position: sticky; top: 20px; }
.detail2 .info .meta { grid-template-columns: 1fr 1fr; }
.detail2 .talk-col > .card { margin-bottom: 0; min-height: 100%; }
.detail2 .tr1 { max-width: none; }
@media (max-width: 1100px) {
  .detail2 { grid-template-columns: 1fr; }
  .detail2 .info { position: static; }
}
.detail2 .info > .card:last-child { margin-bottom: 0; }

/* 逐字稿區塊：桌機固定高度，對話長時在框內捲動 */
@media (min-width: 1101px) {
  .detail2 .talk-col > .card { display: flex; flex-direction: column; height: calc(100vh - 150px); min-height: 520px; }
  .detail2 .talk-col .scroll { flex: 1; overflow-y: auto; padding-right: 8px; margin-right: -8px; scroll-behavior: smooth; }
}
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-thumb { background: #cfd6e2; border-radius: 999px; }
.scroll::-webkit-scrollbar-track { background: transparent; }

/* 試講紀錄 */
.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form input { flex: 1; min-width: 120px; padding: 4px 8px; font-size: 13px; }
.trend { display: inline-block; margin-left: 4px; font-size: 12px; padding: 1px 6px; border-radius: 999px; }
.trend.up { background: #e7f6ec; color: #1a7f3c; }
.trend.down { background: #fdecec; color: #b42318; }
.stars { color: #f5a524; letter-spacing: 1px; white-space: nowrap; }
.stars i { color: var(--line); font-style: normal; }
.rating { display: inline-flex; flex-direction: row-reverse; gap: 2px; margin-bottom: 10px; }
.rating input { display: none; }
.rating label { font-size: 28px; line-height: 1; color: var(--line); cursor: pointer; margin: 0; }
.rating label:hover, .rating label:hover ~ label, .rating input:checked ~ label { color: #f5a524; }
.snapshot summary { cursor: pointer; color: var(--brand); font-size: 14px; margin-bottom: 6px; }
.snapshot .checks li { gap: 16px; align-items: flex-start; }
.snapshot .checks li > span:first-child { flex: none; color: var(--muted); }
.snapshot .val { white-space: pre-wrap; text-align: right; word-break: break-word; }
