/* Capsim Quiz — base styles (mobile-first) */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #e3e6ea;
  --text: #1a1d21;
  --muted: #5f6874;
  --accent: #1f5fd0;
  --accent-soft: #e8f0fe;
  --ok: #17803d;
  --warn: #b45309;
  --err: #b42318;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1c2024;
    --surface-2: #22272c;
    --border: #2c3238;
    --text: #eef1f4;
    --muted: #9aa4b0;
    --accent: #6ea8fe;
    --accent-soft: #1e2b40;
    --ok: #4ade80;
    --warn: #fbbf24;
    --err: #f87171;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans Thai", "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 42rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.hero { margin-bottom: 1.75rem; }

.eyebrow {
  margin: 0;
  font-size: .8125rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: .25rem 0 .5rem;
  font-size: 2rem;
  line-height: 1.2;
  letter-spacing: -.02em;
}

h2 {
  margin: 0 0 .5rem;
  font-size: 1.0625rem;
}

.lede {
  margin: 0;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.125rem 1.25rem;
  margin-bottom: 1rem;
}

.card p { margin: 0; }

code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .1rem .35rem;
  font-size: .9em;
}

/* --- status (หน้าแรก) --- */

.status {
  display: flex;
  align-items: center;
  gap: .625rem;
  font-weight: 600;
}

.dot {
  width: .625rem;
  height: .625rem;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.status--loading .dot { animation: pulse 1.2s ease-in-out infinite; }
.status--ok    .dot { background: var(--ok); }
.status--ok    .status__text { color: var(--ok); }
.status--warn  .dot { background: var(--warn); }
.status--warn  .status__text { color: var(--warn); }
.status--err   .dot { background: var(--err); }
.status--err   .status__text { color: var(--err); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .3; }
}

.detail {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .25rem 1rem;
  margin: .875rem 0 0;
  padding-top: .875rem;
  border-top: 1px solid var(--border);
  font-size: .875rem;
}

.detail dt { color: var(--muted); }
.detail dd { margin: 0; word-break: break-word; }

.foot {
  margin-top: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: .8125rem;
}

.foot p { margin: 0; }

/* ============================================================
   หน้าสอบ (Milestone 2)
   ============================================================ */

/* --- แถบโลโก้คู่ (ลูกค้า | ผู้ให้บริการ) --- */

.brandbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.brandbar__logo {
  /* กำหนดความสูงอย่างเดียว ปล่อยความกว้างตามสัดส่วนจริงของโลโก้
     max-width กันโลโก้แนวนอนยาวๆ ดันจอมือถือแตก */
  height: 2rem;
  width: auto;
  max-width: 40vw;
  object-fit: contain;
}

.brandbar__sep {
  width: 1px;
  align-self: stretch;
  min-height: 1.75rem;
  background: var(--border);
}

/* --- แถบบนสุด: คลาส + ชื่อผู้เรียน --- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.topbar__class {
  margin: 0;
  font-size: .8125rem;
  color: var(--muted);
}

.topbar__name {
  margin: 0;
  font-weight: 600;
}

/* --- ปุ่ม --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-height: 2.875rem;
  padding: .625rem 1.125rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}

.btn:hover:not(:disabled) { background: var(--surface-2); }

.btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn--primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }

.btn--link {
  min-height: auto;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  font-weight: 400;
  font-size: .8125rem;
  text-decoration: underline;
}

.btn--link:hover:not(:disabled) { background: none; color: var(--text); }

.btn--block { width: 100%; }

/* --- ฟอร์ม --- */

.field { margin-bottom: 1rem; }

.field__label {
  display: block;
  margin-bottom: .375rem;
  font-size: .875rem;
  font-weight: 600;
}

.field__hint {
  margin: .375rem 0 0;
  font-size: .8125rem;
  color: var(--muted);
}

.input {
  width: 100%;
  min-height: 2.875rem;
  padding: .625rem .875rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* --- ข้อความแจ้งเตือน --- */

.msg {
  margin: 0 0 1rem;
  padding: .75rem 1rem;
  border-radius: 10px;
  font-size: .9375rem;
}

.msg--err  { background: color-mix(in srgb, var(--err) 12%, transparent);  color: var(--err); }
.msg--info { background: var(--accent-soft); color: var(--accent); }

/* --- รายการรอบสอบ --- */

.quizcard {
  display: block;
  width: 100%;
  text-align: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.125rem 1.25rem;
  margin-bottom: .875rem;
  font: inherit;
  color: inherit;
}

button.quizcard { cursor: pointer; }
button.quizcard:hover { border-color: var(--accent); }

.quizcard--disabled {
  opacity: .7;
  cursor: default;
}

.quizcard__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .75rem;
}

.quizcard__title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
}

.quizcard__note {
  margin: .375rem 0 0;
  font-size: .875rem;
  color: var(--muted);
}

.badge {
  flex: none;
  padding: .1875rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge--open      { background: var(--accent-soft); color: var(--accent); }
.badge--submitted { background: color-mix(in srgb, var(--ok) 14%, transparent);   color: var(--ok); }
.badge--locked    { background: var(--surface-2); color: var(--muted); }
.badge--waiting   { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }

/* --- แถบความคืบหน้า --- */

.progress {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.progress__track {
  flex: 1;
  height: .375rem;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width .2s ease;
}

.progress__label {
  flex: none;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* --- การ์ดคำถาม --- */

.qcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.qcard__domain {
  margin: 0 0 .5rem;
  font-size: .75rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.qcard__stem {
  margin: 0 0 1.25rem;
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.55;
}

.choices {
  display: grid;
  gap: .625rem;
}

.choice {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  width: 100%;
  padding: .875rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  text-align: start;
  line-height: 1.5;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.choice:hover { border-color: var(--accent); }

.choice__key {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: .875rem;
  font-weight: 700;
}

.choice--selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.choice--selected .choice__key {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* --- ปุ่มเดินหน้า/ถอยหลัง --- */

.qnav {
  display: flex;
  gap: .75rem;
}

.qnav .btn { flex: 1; }

.savehint {
  margin: .875rem 0 0;
  text-align: center;
  font-size: .8125rem;
  color: var(--muted);
  min-height: 1.25rem;
}

.savehint--ok  { color: var(--ok); }
.savehint--err { color: var(--err); }

/* --- หน้าตรวจทานก่อนส่ง --- */

.reviewgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3rem, 1fr));
  gap: .5rem;
  margin: 1rem 0 1.25rem;
}

.reviewcell {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.reviewcell:hover { border-color: var(--accent); }

.reviewcell--done {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.reviewcell--blank {
  border-style: dashed;
  border-color: var(--warn);
  color: var(--warn);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0 0 1rem;
  font-size: .8125rem;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
}

.legend i {
  width: .75rem;
  height: .75rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.legend .is-done  { background: var(--accent-soft); border-color: var(--accent); }
.legend .is-blank { border-style: dashed; border-color: var(--warn); }

/* --- หน้าส่งเสร็จ --- */

.done {
  text-align: center;
  padding: 2rem 1.25rem;
}

.done__mark {
  width: 3.5rem;
  height: 3.5rem;
  margin: 0 auto 1rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--ok) 16%, transparent);
  color: var(--ok);
  font-size: 1.75rem;
}

.done h2 { margin-bottom: .5rem; }

.done p { color: var(--muted); }

.stack { display: grid; gap: .75rem; }

/* ============================================================
   หน้าผู้ดูแลระบบ (Milestone 3)
   ============================================================ */

.wrap--wide { max-width: 68rem; }

.adminbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.adminbar__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
}

.crumb {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: 1rem;
  font-size: .875rem;
  color: var(--muted);
}

/* --- แท็บ --- */

.tabs {
  display: flex;
  gap: .25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  flex: none;
  padding: .625rem .875rem;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.tab:hover { color: var(--text); }

.tab--active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* --- ตาราง --- */

.tablewrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

th, td {
  padding: .625rem .75rem;
  text-align: start;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: .8125rem;
  position: sticky;
  top: 0;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg); }

tfoot td {
  background: var(--surface-2);
  font-weight: 600;
  border-top: 2px solid var(--border);
  border-bottom: none;
}

td.wrap-cell {
  white-space: normal;
  min-width: 18rem;
  max-width: 30rem;
}

.num { font-variant-numeric: tabular-nums; }

/* --- กล่องวางข้อมูล --- */

.textarea {
  width: 100%;
  min-height: 9rem;
  padding: .75rem .875rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: .8125rem;
  line-height: 1.6;
  resize: vertical;
}

.textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .625rem;
  align-items: center;
  margin-bottom: 1rem;
}

.toolbar--end { justify-content: flex-end; }

.grow { flex: 1; }

/* --- สรุปตัวเลข --- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .875rem 1rem;
}

.stat__label {
  margin: 0 0 .25rem;
  font-size: .75rem;
  color: var(--muted);
}

.stat__value {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

/* --- จุดสถานะในตารางติดตาม --- */

.pill {
  display: inline-block;
  padding: .125rem .5rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}

.pill--submitted   { background: color-mix(in srgb, var(--ok) 14%, transparent);   color: var(--ok); }
.pill--in_progress { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.pill--not_started { background: var(--surface-2); color: var(--muted); }
.pill--draft       { background: var(--surface-2); color: var(--muted); }
.pill--open        { background: var(--accent-soft); color: var(--accent); }
.pill--closed      { background: color-mix(in srgb, var(--err) 12%, transparent);  color: var(--err); }

/* --- ตัวอย่างโลโก้ --- */

.logobox {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--bg);
  margin-bottom: .75rem;
  min-height: 4.5rem;
}

.logobox img {
  height: 2.5rem;
  width: auto;
  max-width: 50%;
  object-fit: contain;
}

.logobox__empty { color: var(--muted); font-size: .875rem; }

.muted { color: var(--muted); }
.small { font-size: .8125rem; }

.hidden { display: none !important; }
