:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --line: #e4e7ec;
  --line-strong: #cfd5df;
  --ink: #1b2430;
  --muted: #6a7686;
  --faint: #97a2b1;
  --brand: #2f6bff;
  --brand-dark: #1e4fd6;
  --brand-soft: #eef3ff;
  --ok: #0d8a52;
  --ok-soft: #e7f6ee;
  --warn: #a55a09;
  --warn-soft: #fdf3e4;
  --radius: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 22px; letter-spacing: -0.2px; }
h3 { font-size: 14px; }
p { margin: 0; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ---------- 登入 ---------- */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #eef3ff 0%, #f4f6f9 45%);
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 28px;
  text-align: center;
}
.login-card h1 { font-size: 18px; margin: 14px 0 4px; }
.login-card .muted { font-size: 13px; margin-bottom: 20px; }
.login-card input { margin-bottom: 12px; text-align: center; }
.error { color: #c0392b; font-size: 13px; min-height: 20px; margin-top: 8px; }

.brand-mark {
  width: 46px; height: 46px;
  margin: 0 auto;
  border-radius: 13px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.5px;
}
.brand-mark.small { width: 34px; height: 34px; border-radius: 10px; font-size: 12px; margin: 0; }

/* ---------- 版面 ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand-name { font-weight: 600; font-size: 14px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  text-align: left;
  background: none;
  border: 0;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: #47515f;
  cursor: pointer;
  font-family: inherit;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: #f3f5f8; }
.nav-item.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }

.sidebar-foot {
  margin-top: auto;
  padding: 12px 8px 4px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.ai-line { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); flex: 0 0 auto; }
.dot.on { background: var(--ok); }
.dot.off { background: #d99a2b; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; font-size: 12px; font-family: inherit; }

.main { flex: 1; min-width: 0; padding: 30px 34px 60px; max-width: 1280px; }

.page-head { margin-bottom: 20px; }
.page-head h1 { margin-bottom: 4px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* ---------- 首頁入口 ---------- */
.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.entry {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color .12s, transform .12s;
}
.entry:hover { border-color: var(--brand); transform: translateY(-1px); }
.entry h3 { font-size: 15px; margin: 8px 0 6px; }
.entry p { font-size: 12.5px; color: var(--muted); line-height: 1.65; }
.entry-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--brand-dark);
  background: var(--brand-soft);
  border-radius: 999px;
  padding: 2px 9px;
}

.notice {
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  color: #46505f;
  line-height: 1.7;
}
.notice strong { display: block; margin-bottom: 2px; color: var(--ink); font-size: 13px; }
.notice.warn { background: var(--warn-soft); border-left-color: #d99a2b; }
.notice.warn strong { color: var(--warn); }

/* ---------- 表單 ---------- */
.field { margin-bottom: 13px; }
.field > label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="text"], input[type="number"], input[type="password"], input[type="search"], textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47,107,255,.12); }
textarea { resize: vertical; line-height: 1.65; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 12.5px;
  color: #4d5766;
  cursor: pointer;
  font-family: inherit;
  transition: all .12s;
}
.chip:hover { border-color: var(--brand); color: var(--brand-dark); }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); font-weight: 600; }

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn.primary { background: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.primary:disabled { background: #9db6f2; cursor: default; }
.btn.ghost { background: #fff; border-color: var(--line-strong); color: #46505f; }
.btn.ghost:hover { border-color: var(--brand); color: var(--brand-dark); }
.btn.sm { padding: 4px 11px; font-size: 12.5px; }
.btn.block { width: 100%; padding: 10px; margin-top: 6px; }

.badge {
  font-size: 11.5px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #f1f3f7;
  color: var(--muted);
  white-space: nowrap;
}
.badge.ai { background: var(--ok-soft); color: var(--ok); }
.badge.demo { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: #fdecec; color: #c0392b; }

.readonly {
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  color: #4d5766;
  line-height: 1.8;
}

.hint { font-size: 12px; color: var(--faint); margin-top: 6px; line-height: 1.6; }

/* ---------- 兩欄 ---------- */
.panel-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 16px;
  align-items: start;
}

/* ---------- 分頁 ---------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 9px 14px;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  margin-bottom: -1px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand-dark); border-bottom-color: var(--brand); font-weight: 600; }

/* ---------- 計算面板 ---------- */
.calc {
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  color: #46505f;
  line-height: 1.9;
  margin: 4px 0 12px;
}
.calc b { color: var(--brand-dark); }
.calc .warnline { color: #b4650a; }

/* ---------- 結果 ---------- */
.result {
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  min-height: 220px;
  font-size: 13.5px;
  line-height: 1.85;
  white-space: pre-wrap;
  word-break: break-word;
  color: #232c38;
}
.result .placeholder { color: var(--faint); }
.result .sec { color: var(--brand-dark); font-weight: 600; }.result .msg { color: #232c38; }

/* ---------- 目標獎勵清單 ---------- */
.targets { display: flex; flex-direction: column; gap: 4px; }
.target {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  font-size: 12.5px;
  color: #4d5766;
  background: #fafbfc;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: all .12s;
}
.target:hover { border-color: var(--line-strong); }
.target.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); font-weight: 600; }
.target .dist { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.target .dist.done { background: var(--ok-soft); color: var(--ok); }
.target .muted-s { color: var(--muted); font-weight: 400; font-size: 11.5px; }

/* ---------- 話術庫 / 範例 ---------- */
.lib-toolbar { display: flex; gap: 8px; margin-bottom: 14px; }
.lib-toolbar input { flex: 1; }

.item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.item-title { font-size: 13.5px; font-weight: 600; }
.item-meta { font-size: 11.5px; color: var(--faint); }
.item-text { font-size: 13px; line-height: 1.8; color: #3a4453; white-space: pre-wrap; }
.item-img-link { display: block; margin-top: 12px; width: fit-content; }
.item-img { display: block; max-width: 300px; max-height: 640px; width: auto; height: auto; border-radius: var(--radius-sm); border: 1px solid var(--line); cursor: zoom-in; }
.item-img:hover { border-color: var(--line-strong); }
.item-foot { display: flex; gap: 6px; margin-top: 10px; }
.empty { text-align: center; color: var(--faint); padding: 40px 0; font-size: 13px; }

/* ---------- 話術庫篩選 ---------- */
.filters {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.filter-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.filter-row:last-child { margin-bottom: 0; }
.filter-label { font-size: 12.5px; color: var(--muted); flex: 0 0 62px; }
.filter-row input { flex: 1; }
.filter-row .chips { flex: 1; }

/* ---------- 後台 ---------- */
.steps { margin: 0; padding-left: 20px; font-size: 13px; color: #46505f; line-height: 2; }
.steps code { background: #eef1f5; border-radius: 4px; padding: 1px 6px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; }

details.raw { margin: 4px 0 12px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); padding: 8px 12px; }
details.raw summary { cursor: pointer; font-size: 12.5px; color: var(--brand-dark); }
details.raw textarea { margin-top: 8px; }

/* ---------- 載入中 ---------- */
.spinner {
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid rgba(255,255,255,.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -2px;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 響應式 ---------- */
@media (max-width: 980px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: row; align-items: center; gap: 10px; padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .sidebar-head { padding: 0; flex: 0 0 auto; }
  .nav { flex-direction: row; gap: 2px; }
  .nav-item { white-space: nowrap; }
  .sidebar-foot { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; align-items: center; gap: 10px; }
  .ai-line { margin: 0; }
  .main { padding: 20px 16px 50px; }
  .panel-grid { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
}
