:root {
  --bg: #f6f6f4;
  --panel: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --line: #deded8;
  --accent: #2f5fd0;
  --danger: #b3261e;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; }
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 12px; }
button:disabled { opacity: 0.5; cursor: wait; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; }
input, textarea { font: inherit; width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
textarea { resize: vertical; margin-top: 8px; }
.error { color: var(--danger); }

.login { min-height: 100vh; display: grid; place-items: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 28px; width: min(360px, 92vw); display: grid; gap: 14px; }
.login-card h1 { font-size: 1.2rem; margin: 0; }
.login-card label { display: grid; gap: 4px; font-size: 0.9rem; }

.app { display: grid; grid-template-columns: 260px 1fr; grid-template-rows: auto 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.spacer { flex: 1; }
.sidebar { padding: 12px; border-right: 1px solid var(--line); background: var(--panel); display: grid; align-content: start; gap: 10px; }
.task-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.task-list button { width: 100%; text-align: left; border-color: transparent; background: none; }
.task-list li.active button { background: #e8eefc; border-color: #c5d3f5; }
.main { padding: 16px 24px 64px; max-width: 1240px; }
.empty { color: var(--muted); }

.task-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.task-head h2 { flex: 1; margin: 0; font-size: 1.2rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin: 14px 0; }
.card h3 { margin: 0 0 10px; font-size: 1rem; }
.actions { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.status { color: var(--muted); margin: 0; font-size: 0.9rem; }
.status.error { color: var(--danger); }

.dropzone { border: 2px dashed var(--line); border-radius: 8px; padding: 18px; text-align: center; color: var(--muted); }
.dropzone:focus, .dropzone.over { border-color: var(--accent); outline: none; background: #f0f4fe; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.thumb { position: relative; }
.thumb img, .thumbs a img { height: 84px; border: 1px solid var(--line); border-radius: 4px; display: block; }
.thumb button { position: absolute; top: 2px; right: 2px; padding: 0 6px; line-height: 1.2; }

.turn { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 10px; }
.sent-note { color: var(--muted); font-size: 0.9rem; white-space: pre-wrap; }
.reply { overflow-wrap: anywhere; }
.reply.live { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.reply table { border-collapse: collapse; margin: 8px 0; display: block; overflow-x: auto; }
.reply th, .reply td { border: 1px solid var(--line); padding: 4px 8px; vertical-align: top; }
.reply pre { position: relative; background: #f1f1ee; border-radius: 6px; padding: 12px; overflow-x: auto; white-space: pre-wrap; }
.reply pre .copy { position: absolute; top: 6px; right: 6px; font-size: 0.8rem; padding: 2px 8px; }

.stepper { list-style: none; display: flex; gap: 6px; margin: 12px 0; padding: 0; }
.stepper-item { flex: 1; }
.stepper-item button { width: 100%; display: flex; align-items: center; gap: 8px; text-align: left; padding: 8px 10px; }
.stepper-item button:disabled { cursor: not-allowed; }
.stepper-item .dot { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--line); font-size: 0.8rem; flex: none; }
.stepper-item.current button { border-color: var(--accent); background: #e8eefc; font-weight: 600; }
.stepper-item.current .dot { background: var(--accent); color: #fff; }
.stepper-item.done .dot { background: #2e7d32; color: #fff; }
.stepper-label { font-size: 0.85rem; line-height: 1.25; }
.hint { margin: 0 0 12px; color: var(--muted); }
.previous { margin-bottom: 12px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.previous summary { cursor: pointer; font-weight: 600; }
.followup { margin-top: 18px; padding-top: 12px; border-top: 1px dashed var(--line); }
.followup h4 { margin: 0 0 4px; font-size: 0.95rem; }
.nav { display: flex; align-items: center; gap: 8px; margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--line); }

.capture-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.capture-message { color: var(--muted); font-size: 0.9rem; }
.capture-message.error { color: var(--danger); }

.reply th:first-child, .reply td:first-child { min-width: 2.6em; }

.answer-cell { min-width: 13em; }
.answer-cell .choice-group { display: flex; gap: 6px; }
.answer-cell .choice { padding: 2px 14px; }
.answer-cell .choice[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.answer-cell textarea, .answer-cell input.detail { width: 100%; margin-top: 4px; padding: 4px 6px; }
.answer-cell textarea { margin-top: 0; }

.errors { margin: 14px 0; }
.errors h4 { margin: 0 0 6px; font-size: 0.95rem; }
.error-table-wrap { overflow-x: auto; margin-bottom: 8px; }
.error-table { border-collapse: collapse; width: 100%; }
.error-table th, .error-table td { border: 1px solid var(--line); padding: 4px 6px; text-align: left; vertical-align: middle; }
.error-table th { font-size: 0.85rem; }
.error-table td.stt { width: 3em; text-align: center; }
.error-table input, .error-table select { width: 100%; padding: 4px 6px; margin: 0; }
.error-table td:nth-child(3), .error-table td:nth-child(4) { width: 7em; }
.error-table .remove { padding: 0 8px; }

/* Nút và chữ chỉ dùng cho một loại thiết bị */
.only-mobile { display: none; }

/* ---------- Điện thoại ---------- */
@media (max-width: 760px) {
  html, body { overflow-x: hidden; }
  .only-mobile { display: inline-block; }
  .desktop-only { display: none; }

  /* minmax(0, 1fr): cột không bị nội dung rộng đẩy ra quá màn hình */
  .app { grid-template-columns: minmax(0, 1fr); }
  .topbar { position: sticky; top: 0; z-index: 5; padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
  .topbar strong { font-size: 0.95rem; }
  #who { display: none; }
  .sidebar { display: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .app.show-tasks .sidebar { display: grid; }
  .main { padding: 10px 12px 72px; min-width: 0; max-width: none; }
  .card { padding: 12px; min-width: 0; }

  /* Cỡ chữ ô nhập từ 16px để iPhone không tự phóng to trang khi chạm vào */
  input, textarea, select { font-size: 16px; }
  button { min-height: 44px; }
  .copy, .remove, .thumb button, .answer-cell .choice { min-height: 0; }
  .task-list button { min-height: 44px; }

  .task-head { flex-wrap: wrap; }
  .task-head h2 { flex-basis: 100%; font-size: 1.05rem; }
  .task-head button { flex: 1; }

  /* Thanh bước: một hàng cuộn ngang, chỉ giữ chữ của bước đang mở */
  .stepper { flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px; }
  .stepper-item { flex: 0 0 auto; }
  .stepper-item button { width: auto; padding: 6px 10px; }
  .stepper-item:not(.current) .stepper-label { display: none; }

  .dropzone { padding: 22px 12px; }
  .dropzone .link { display: inline-block; padding: 10px 18px; border: 1px solid var(--accent); border-radius: 8px; text-decoration: none; }
  .thumb img, .thumbs a img { height: 72px; }
  .actions { flex-wrap: wrap; }
  .actions .primary { flex: 1 1 100%; }
  .nav .spacer { display: none; }
  .nav .primary { width: 100%; }

  /* Bảng nhiều cột thành từng thẻ: mỗi hàng là một thẻ, mỗi ô có nhãn cột phía trên */
  .reply table, .reply thead, .reply tbody, .reply tr, .reply th, .reply td,
  .error-table, .error-table thead, .error-table tbody, .error-table tr, .error-table td { display: block; }
  .reply table, .error-table { width: auto; overflow-x: visible; border: 0; }
  .reply thead, .error-table thead { position: absolute; left: -9999px; }
  .reply tr, .error-table tr { border: 1px solid var(--line); border-radius: 8px; margin: 8px 0; padding: 6px 10px; background: var(--panel); }
  .reply td, .error-table td { border: 0; padding: 4px 0; min-width: 0; width: auto; }
  .reply td:first-child, .error-table td:first-child { font-weight: 600; }
  .reply td:not(:first-child)::before, .error-table td:not(:first-child)::before {
    content: attr(data-label); display: block; font-size: 0.75rem; font-weight: 400; color: var(--muted);
  }
  /* Nhãn Turn nằm cùng dòng với số turn cho thẻ bớt cao */
  .reply td[data-label="Turn"]::before, .error-table td[data-label="Turn"]::before { display: inline; margin-right: 8px; }
  .error-table td.stt { text-align: left; }
  .error-table td.remove-cell { text-align: right; }
  .error-table td.remove-cell::before { display: none; }
  .answer-cell { min-width: 0; }
  .answer-cell .choice { padding: 10px 22px; min-height: 44px; }

  .reply pre { padding-top: 40px; }
  .reply pre .copy { top: 8px; right: 8px; padding: 6px 12px; }
}
