:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e6e8ec;
  --border-strong: #d4d7dd;
  --text: #17181c;
  --muted: #6b7280;
  --faint: #9ca3af;
  --ink: #17181c;
  --ink-hover: #2b2d33;
  --accent: #2563eb;
  --accent-soft: #eef4ff;
  --good: #16a34a;
  --good-soft: #f0fdf4;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 4px 12px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  font-family: "Noto Sans Thai", -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.55;
}

/* ---------- top bar ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1024px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 0.98rem; white-space: nowrap; }
.brand-mark {
  width: 10px; height: 10px;
  border-radius: 3px;
  background: var(--accent);
  display: inline-block;
}

.steps { display: flex; align-items: center; gap: 4px; }
.step-item {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 10px;
  border-radius: 99px;
  font-size: 0.8rem;
  color: var(--faint);
  font-weight: 500;
}
.step-item .dot {
  width: 20px; height: 20px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  background: #f0f1f3;
  color: var(--faint);
}
.step-item.active { color: var(--text); }
.step-item.active .dot { background: var(--ink); color: #fff; }
.step-item.done { color: var(--muted); }
.step-item.done .dot { background: var(--good-soft); color: var(--good); }
.step-sep { color: var(--border-strong); font-size: 0.75rem; }

@media (max-width: 720px) {
  .step-item span.step-label { display: none; }
  .topbar-inner { padding: 0 16px; }
}

/* ---------- layout ---------- */
#app {
  max-width: 1024px;
  margin: 0 auto;
  padding: 32px 24px 72px;
}
@media (max-width: 720px) { #app { padding: 20px 16px 56px; } }

.step { animation: fadein 0.25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.page-title { font-size: 1.35rem; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.01em; }
.page-desc { color: var(--muted); font-size: 0.9rem; margin: 0 0 24px; }

/* ---------- cards ---------- */
.type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
  position: relative;
}
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-lg); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); }
.card.selected::after {
  content: "";
  position: absolute;
  top: 14px; right: 14px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>') center no-repeat;
}

.card .avatar {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: #f3f4f6;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
  margin-bottom: 10px;
}
.card .label { font-weight: 600; font-size: 0.95rem; margin-bottom: 2px; }
.card .tagline { font-size: 0.82rem; color: var(--muted); margin-bottom: 10px; line-height: 1.45; }
.card .traits { display: flex; flex-wrap: wrap; gap: 5px; }
.card .traits .chip {
  font-size: 0.72rem;
  color: var(--muted);
  background: #f3f4f6;
  border-radius: 99px;
  padding: 3px 9px;
  line-height: 1.4;
}
.card .desc { font-size: 0.84rem; color: var(--muted); margin-top: 4px; }

/* ---------- custom persona ---------- */
.custom-box {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 24px;
}
.custom-box label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 3px; }
.custom-box .hint { font-size: 0.78rem; color: var(--muted); margin-bottom: 10px; }
.custom-box textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.custom-box textarea:focus,
.chat-input-row textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface);
}

/* ---------- buttons ---------- */
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

button {
  font-family: inherit;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--ink-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); }
.btn-secondary:not(:disabled):hover { background: #f3f4f6; }
.btn-danger { background: var(--surface); color: var(--bad); border: 1px solid #f3c6c6; }
.btn-danger:not(:disabled):hover { background: var(--bad-soft); }

/* ---------- chat ---------- */
.chat-shell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.chat-meta-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: #f3f4f6;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}
.chat-title { font-weight: 600; font-size: 0.92rem; line-height: 1.3; }
.chat-sub { font-size: 0.78rem; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  background: #f3f4f6;
  color: var(--muted);
}
.badge.easy { background: var(--good-soft); color: var(--good); }
.badge.medium { background: var(--warn-soft); color: var(--warn); }
.badge.hard { background: var(--bad-soft); color: var(--bad); }

/* mood meter */
.mood-box { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.mood-label { font-size: 0.72rem; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.mood-label b { font-weight: 600; }
.mood-track { display: flex; gap: 3px; }
.mood-seg {
  width: 13px; height: 6px;
  border-radius: 3px;
  background: #eceef1;
  transition: background 0.3s;
}
.mood-seg.on.lv-low { background: #22c55e; }
.mood-seg.on.lv-mid { background: #f59e0b; }
.mood-seg.on.lv-high { background: #ef4444; }
.mood-value.lv-low { color: var(--good); }
.mood-value.lv-mid { color: var(--warn); }
.mood-value.lv-high { color: var(--bad); }

.chat-window {
  padding: 20px 18px;
  min-height: 340px;
  max-height: 52vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #fbfbfc;
}

.msg { max-width: 76%; display: flex; flex-direction: column; gap: 3px; }
.msg .who { font-size: 0.72rem; color: var(--faint); padding: 0 4px; }
.msg .bubble {
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.55;
  font-size: 0.92rem;
  white-space: pre-wrap;
  width: fit-content;
  max-width: 100%;
}
.msg.customer { align-self: flex-start; }
.msg.customer .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
}
.msg.officer { align-self: flex-end; align-items: flex-end; }
.msg.officer .bubble {
  background: var(--ink);
  color: #fff;
  border-top-right-radius: 4px;
}

.msg details.reasoning { margin-top: 2px; padding: 0 4px; }
.msg details.reasoning summary {
  font-size: 0.72rem;
  color: var(--faint);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.msg details.reasoning summary::-webkit-details-marker { display: none; }
.msg details.reasoning summary:hover { color: var(--muted); }
.msg details.reasoning .reasoning-body {
  margin-top: 4px;
  font-size: 0.78rem;
  color: var(--muted);
  background: #f3f4f6;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  white-space: pre-wrap;
}

.typing { display: flex; align-items: center; gap: 8px; padding: 4px; align-self: flex-start; }
.typing .t-dots { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; border-top-left-radius: 4px; padding: 12px 14px; }
.typing .t-dots i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--faint);
  animation: bounce 1.2s infinite;
}
.typing .t-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing .t-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* Blinking cursor while response text is streaming in */
.bubble.streaming::after {
  content: '▋';
  display: inline;
  margin-left: 1px;
  font-size: 0.8em;
  opacity: 0.5;
  animation: blink-cursor 0.8s step-end infinite;
}
@keyframes blink-cursor { 50% { opacity: 0; } }

.resolved-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 18px;
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--good-soft);
  border: 1px solid #bbe7c9;
  color: #166534;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
}

.chat-input-row {
  display: flex;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
.chat-input-row textarea {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 11px 12px;
  font-family: inherit;
  font-size: 0.92rem;
  resize: none;
  min-height: 46px;
  max-height: 140px;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.chat-toolbar { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; gap: 10px; flex-wrap: wrap; }
.chat-toolbar .hint { font-size: 0.78rem; color: var(--faint); }
.chat-toolbar .toolbar-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- evaluation ---------- */
.eval-grid { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: start; }
@media (max-width: 720px) { .eval-grid { grid-template-columns: 1fr; } }

.eval-score-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 18px;
  text-align: center;
  box-shadow: var(--shadow);
}
.score-ring { position: relative; width: 120px; height: 120px; margin: 0 auto 10px; }
.score-ring svg { transform: rotate(-90deg); }
.score-ring .num {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.7rem; line-height: 1;
}
.score-ring .num small { font-size: 0.7rem; font-weight: 500; color: var(--faint); margin-top: 3px; }
.eval-summary { font-size: 0.85rem; color: var(--muted); margin: 0; text-align: center; }

.eval-sections { display: flex; flex-direction: column; gap: 12px; }
.eval-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.eval-section h4 {
  margin: 0 0 10px;
  font-size: 0.88rem;
  font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.eval-section h4 .ico {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.eval-section.strengths h4 .ico { background: var(--good); }
.eval-section.weak h4 .ico { background: var(--bad); }
.eval-section.missed h4 .ico { background: var(--warn); }
.eval-section.suggest h4 .ico { background: var(--accent); }
.eval-section ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 0.87rem; display: flex; flex-direction: column; gap: 6px; }

/* ---------- misc ---------- */
.error-banner {
  background: var(--bad-soft);
  border: 1px solid #f3c6c6;
  color: #b42318;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.86rem;
}

.spinner {
  display: inline-block;
  width: 13px; height: 13px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 7px;
  vertical-align: -2px;
}
.btn-secondary .spinner { border-color: var(--border-strong); border-top-color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }
