/* TSIC Synopsys Insight — 聊天室樣式（無外部資源，深淺色自動切換） */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #dfe3e8;
  --text: #16191d;
  --muted: #6b7280;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --danger: #b42318;
  --warn: #a15c07;
  --warn-bg: #fdf3e3;
  --bubble: #eef1f5;
  --bubble-own: #1f6feb;
  --bubble-own-text: #ffffff;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --panel: #1c2024;
    --border: #2c3238;
    --text: #e8eaed;
    --muted: #9aa4b0;
    --accent: #4b8dff;
    --accent-text: #0d1117;
    --danger: #ff6b60;
    --warn: #e5a53f;
    --warn-bg: #3a2f1c;
    --bubble: #262c33;
    --bubble-own: #2f5fd0;
    --bubble-own-text: #ffffff;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
    "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
}

/* --- 版面 ---------------------------------------------------------------- */

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .who {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

h1.page-title {
  margin: 0 0 4px;
  font-size: 24px;
  letter-spacing: 0.01em;
}

.subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 14px;
}

.section-label {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--bubble);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

/* --- 接關碼 -------------------------------------------------------------- */

.code-value {
  margin: 4px 0 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 42px;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-align: center;
  color: var(--accent);
}

/* --- 我的問題 ------------------------------------------------------------ */

.question-list,
.pair-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.question-card,
.pair-card {
  display: grid;
  gap: 10px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.question-card button,
.pair-card button {
  justify-self: start;
}

.question-body {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.question-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.question-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.question-status.matched .dot {
  background: var(--accent);
}

.question-status.waiting .dot {
  background: var(--warn);
}

.question-card .hint {
  margin: 0;
}

.topic {
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--bubble);
  color: var(--muted);
  font-size: 12px;
}

.partner {
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
  background: var(--bubble);
  border-radius: 0 10px 10px 0;
}

.partner-label {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--muted);
}

.partner-body {
  margin: 0;
  overflow-wrap: anywhere;
}

/* --- 討論串標頭（讓兩個人知道自己為什麼被配在一起）---------------------- */

.pair-header {
  display: grid;
  gap: 8px;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.pair-question {
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--bubble);
  border-left: 3px solid var(--border);
}

.pair-question.mine {
  border-left-color: var(--accent);
}

.pair-question-who {
  margin: 0 0 2px;
  font-size: 12px;
  color: var(--muted);
}

.pair-question-body {
  margin: 0;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.pair-hint {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* --- 表單 ---------------------------------------------------------------- */

.card {
  padding: 20px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: 11px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  resize: none;
}

input:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

button {
  padding: 11px 18px;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button[disabled] {
  opacity: 0.55;
  cursor: default;
}

button.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
  font-weight: 500;
}

.row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.msg-error {
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 14px;
  min-height: 21px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
}

/* --- 聊天室 -------------------------------------------------------------- */

.chat-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: min(80%, 520px);
  align-self: flex-start;
}

.msg .meta {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 12px;
}

.msg .bubble {
  padding: 9px 13px;
  background: var(--bubble);
  border-radius: 14px;
  border-top-left-radius: 4px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.own {
  align-self: flex-end;
}

.msg.own .meta {
  text-align: right;
}

.msg.own .bubble {
  background: var(--bubble-own);
  color: var(--bubble-own-text);
  border-top-left-radius: 14px;
  border-top-right-radius: 4px;
}

.day-sep {
  align-self: center;
  padding: 2px 12px;
  border-radius: 999px;
  background: var(--bubble);
  color: var(--muted);
  font-size: 12px;
}

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
}

.composer textarea {
  flex: 1;
  max-height: 30vh;
  min-height: 44px;
}

.status {
  padding: 6px 16px;
  background: var(--bubble);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.status.error {
  color: var(--danger);
}

.status[hidden] {
  display: none;
}

/* --- 管理頁 -------------------------------------------------------------- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 13px;
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table-scroll {
  overflow-x: auto;
}

/* 概況數字 */
.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
}

/* 配對卡片 */
.pair-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.pair-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 700;
}

.pair-card-head .hint {
  margin: 0;
}

.pair-member {
  display: flex;
  gap: 10px;
  font-size: 14px;
}

.pair-member-nick {
  flex: 0 0 auto;
  min-width: 5em;
  color: var(--muted);
}

.pair-member-body {
  overflow-wrap: anywhere;
}

/* 標籤：一眼看出這組是誰配的 */
.tag {
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--bubble);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.tag-ai {
  background: var(--accent);
  color: var(--accent-text);
}

.tag-leftover {
  background: var(--warn-bg);
  color: var(--warn);
}

.tag-matched {
  color: var(--accent);
}

/* 對話紀錄 */
dialog {
  width: min(640px, 92vw);
  max-height: 80vh;
  padding: 20px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.transcript-body {
  display: grid;
  gap: 10px;
  max-height: 60vh;
  overflow-y: auto;
}

.transcript-line {
  display: grid;
  gap: 2px;
}

.transcript-meta {
  font-size: 12px;
  color: var(--muted);
}

.transcript-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
