@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@500;600;700&family=Sarabun:wght@400;500;600;700&display=swap');

/* ============================================================
   โทเค็นดีไซน์ (design tokens)
   โทนสี: ขาวเป็นหลัก — พื้นหลังขาวนวล การ์ดขาวบริสุทธิ์ยกตัวด้วยเงานุ่ม
          ใช้สีแดงเลือดหมูเป็นสีเน้นเฉพาะจุดสำคัญเท่านั้น
   ตัวอักษร: Kanit สำหรับหัวข้อ / Sarabun สำหรับเนื้อหา
   ตั้งใจใช้โทนสว่างคงที่ (ไม่สลับตามธีมมืดของเครื่อง) เพื่อความสม่ำเสมอทุกอุปกรณ์
   ============================================================ */
:root {
  --paper: #fbfbfa;
  --surface: #ffffff;
  --ink: #1f1c1a;
  --ink-mid: #4a443e;
  --ink-soft: #857c72;
  --accent: #7a2331;
  --accent-deep: #5c1723;
  --accent-soft: #a8475a;
  --accent-tint: #fdf6f6;
  --accent-line: #f0dcdd;
  --line: #eceae6;
  --line-soft: #f5f3f0;
  --success: #2f6f52;
  --success-tint: #eef6f1;
  --danger: #a83f27;
  --danger-tint: #fbefeb;

  --shadow-sm: 0 1px 2px rgba(31, 28, 26, 0.04), 0 1px 3px rgba(31, 28, 26, 0.03);
  --shadow-md: 0 1px 2px rgba(31, 28, 26, 0.04), 0 4px 12px rgba(31, 28, 26, 0.05);
  --shadow-lg: 0 2px 4px rgba(31, 28, 26, 0.04), 0 12px 32px rgba(31, 28, 26, 0.07);

  --radius: 14px;
  --radius-sm: 9px;

  --font-display: 'Kanit', sans-serif;
  --font-body: 'Sarabun', sans-serif;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

* { box-sizing: border-box; }

body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  margin: 0;
  padding: 0;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); text-wrap: balance; line-height: 1.35; }

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

:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ==== หัวหน้าเว็บ ==== */
.page-wrap {
  max-width: 500px;
  margin: 0 auto;
  padding: 44px 20px 72px;
}

.page-head { text-align: center; margin-bottom: 28px; }

.page-eyebrow {
  display: block;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-soft);
  margin-bottom: 10px;
}

.page-title {
  color: var(--ink);
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

.page-subtitle {
  color: var(--ink-soft);
  font-size: 14.5px;
  margin: 10px auto 0;
  max-width: 40ch;
}

.page-nav {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

.page-nav a {
  font-size: 13.5px;
  text-decoration: none;
  color: var(--ink-mid);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 16px;
  box-shadow: var(--shadow-sm);
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.page-nav a:hover {
  color: var(--accent);
  border-color: var(--accent-line);
  transform: translateY(-1px);
}

.site-footer {
  text-align: center;
  margin-top: 36px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.site-footer a { color: var(--ink-soft); font-size: 13px; text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

/* ==== การ์ด ==== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 16px;
}

.step-badge {
  font-family: var(--font-display);
  color: var(--accent);
  background: var(--accent-tint);
  border: 1px solid var(--accent-line);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}

.card-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15.5px;
  color: var(--ink);
}

label {
  display: block;
  font-size: 13.5px;
  font-weight: 500;
  margin: 14px 0 6px;
  color: var(--ink-mid);
}
label:first-child { margin-top: 0; }

input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input::placeholder, textarea::placeholder { color: #b8b0a7; }
input:hover, select:hover, textarea:hover { border-color: #dbd7d1; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(168, 71, 90, 0.09);
  outline: none;
}

textarea { resize: vertical; min-height: 78px; }

.dropzone {
  border: 1.5px dashed var(--accent-line);
  border-radius: var(--radius-sm);
  background: var(--accent-tint);
  text-align: center;
  padding: 34px 14px;
  cursor: pointer;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover { border-color: var(--accent-soft); background: #fbf0f1; }
.dropzone small { display: block; color: var(--ink-soft); margin-top: 6px; font-weight: 400; }

/* ==== การ์ดพับ/กาง (accordion) ==== */
.accordion-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  overflow: hidden;
  background: var(--surface);
}

.accordion-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  background: var(--surface);
  color: var(--ink);
  border: none;
  padding: 14px 16px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.accordion-header:hover { background: var(--line-soft); }
.accordion-header::after {
  content: '';
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--ink-soft);
  border-bottom: 1.5px solid var(--ink-soft);
  transform: rotate(-45deg);
  transition: transform 0.2s ease;
}
.accordion-card.open .accordion-header::after { transform: rotate(45deg); }
.accordion-card.open .accordion-header { border-bottom: 1px solid var(--line); }

.accordion-body {
  display: none;
  padding: 16px;
  background: var(--surface);
}

.accordion-card.open .accordion-body { display: block; }

/* ==== ปุ่ม ==== */
.submit-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  margin-top: 14px;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}
.submit-btn:hover {
  background: var(--accent-deep);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.submit-btn:active { transform: translateY(0); }
.submit-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-inline { width: auto; max-width: 220px; padding: 11px 22px; margin-top: 14px; }

.progress-wrap { display: none; margin-top: 18px; }

.progress-track {
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  height: 8px;
}

.progress-bar {
  background: var(--accent);
  height: 100%;
  width: 0%;
  border-radius: 999px;
  font-size: 0;
  transition: width 0.25s ease;
}

.status-text { font-size: 13px; color: var(--ink-soft); margin-top: 8px; }
.result-box { margin-top: 18px; font-size: 14px; }

/* ป้ายผลลัพธ์สำเร็จ/ผิดพลาด */
.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
}
.result-badge--ok { color: var(--success); }
.result-badge--error { color: var(--danger); }
.result-badge::before {
  content: '';
  width: 17px;
  height: 17px;
  border-radius: 50%;
  flex-shrink: 0;
  background: currentColor;
  -webkit-mask: var(--icon) center / 10px no-repeat;
  mask: var(--icon) center / 10px no-repeat;
}
.result-badge--ok::before {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='white' d='M6.2 11.2 2.8 7.8l1.1-1.1 2.3 2.3 5.9-5.9 1.1 1.1z'/%3E%3C/svg%3E");
}
.result-badge--error::before {
  --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath stroke='white' stroke-width='1.8' stroke-linecap='round' d='M4.5 4.5l7 7m0-7-7 7'/%3E%3C/svg%3E");
}

/* ==== ตัวเลือกรอบการส่ง (รอบ 1 / รอบ 2) ==== */
.round-select-card { padding: 6px; }
.round-tabs { display: flex; gap: 4px; background: var(--line-soft); border-radius: 11px; padding: 4px; }
.round-tab {
  flex: 1;
  margin: 0;
  border-radius: 8px;
  padding: 10px 8px;
  text-align: center;
  cursor: pointer;
  font-weight: 500;
  color: var(--ink-soft);
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}
.round-tab input { display: none; }
.round-tab .round-tab-title { display: block; font-family: var(--font-display); font-weight: 600; font-size: 14px; }
.round-tab small { display: block; font-size: 11.5px; margin-top: 1px; }
.round-tab:has(input:checked) {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* แสดง/ซ่อนการ์ดตามรอบที่เลือก */
.round1-mode .round2-only { display: none; }
.round2-mode .round1-only { display: none; }
.round2-mode .step-badge { display: none; }

/* ==== หน้าล็อกอินครู ==== */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px; background: var(--paper);
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 360px;
  box-shadow: var(--shadow-lg);
}
.login-box h2 { color: var(--ink); font-size: 19px; font-weight: 600; margin: 0 0 22px; }
.error {
  color: var(--danger); font-size: 13px;
  background: var(--danger-tint); border-radius: var(--radius-sm);
  padding: 9px 12px; margin: 0 0 14px;
}

/* ==== หน้าแอดมิน ==== */
.admin-wrap { max-width: 1000px; margin: 0 auto; padding: 40px 24px 72px; }
.admin-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 14px; margin-bottom: 24px; flex-wrap: wrap;
}
.admin-header h2 { color: var(--ink); margin: 0; font-size: 22px; font-weight: 600; }
.logout-link { color: var(--ink-soft); font-size: 13.5px; text-decoration: none; }
.logout-link:hover { color: var(--accent); }

.table-scroll {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* หัวหน้ารายละเอียดผลงาน (หน้าให้คะแนน) */
.back-link { display: inline-block; font-size: 13.5px; text-decoration: none; margin-bottom: 18px; }
.back-link:hover { text-decoration: underline; }

.detail-head {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 26px;
  margin-bottom: 28px;
  box-shadow: var(--shadow-sm);
}
.detail-head h2 { margin: 0 0 16px; font-size: 21px; font-weight: 600; }

.meta-list { margin: 0; display: grid; gap: 12px; }
.meta-list > div { display: grid; grid-template-columns: 108px 1fr; gap: 14px; align-items: start; }
.meta-list dt {
  font-family: var(--font-display); font-weight: 500; font-size: 11px;
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-soft);
  padding-top: 3px;
}
.meta-list dd { margin: 0; font-size: 14px; color: var(--ink-mid); }
@media (max-width: 560px) {
  .meta-list > div { grid-template-columns: 1fr; gap: 3px; }
}

.admin-wrap h3 {
  font-size: 13px; font-weight: 500; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--ink-soft); margin: 32px 0 14px;
}

/* กล่องเน้นบันทึกการปรับปรุงของกลุ่ม (PDCA) */
.note-callout {
  background: var(--accent-tint);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin: 20px 0 0;
}
.note-label {
  display: block;
  font-family: var(--font-display); font-weight: 500; font-size: 11px;
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--accent);
  margin-bottom: 7px;
}
.note-callout p { margin: 0; font-size: 14px; color: var(--ink-mid); }

.submission-table, .score-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}

.submission-table th, .submission-table td,
.score-table th, .score-table td {
  border-bottom: 1px solid var(--line);
  padding: 13px 16px;
  font-size: 14px;
  text-align: left;
}
.submission-table tbody tr:last-child td,
.score-table tbody tr:last-child td { border-bottom: none; }

.submission-table th, .score-table th {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.09em;
  color: var(--ink-soft);
  text-transform: uppercase;
  background: var(--line-soft);
  white-space: nowrap;
}

.submission-table tbody tr, .score-table tbody tr { transition: background 0.12s ease; }
.submission-table tbody tr:hover, .score-table tbody tr:hover { background: var(--line-soft); }

.score-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.score-section h4 {
  margin: 0 0 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-size: 15.5px;
  font-weight: 600;
}
.score-section .table-scroll { border-radius: var(--radius-sm); box-shadow: none; }
/* คอลัมน์หัวข้อเกณฑ์ไม่ควรถูกบีบจนตัดคำ — ให้ตารางเลื่อนแนวนอนแทนบนจอแคบ */
.score-table td:first-child { min-width: 15ch; }
.score-table th:nth-child(2), .score-table td:nth-child(2),
.score-table th:nth-child(3), .score-table td:nth-child(3) { white-space: nowrap; }

.video-embed {
  margin: 0 0 10px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--line-soft);
}
.answers-list { font-size: 14px; line-height: 1.9; padding-left: 20px; }
.answers-list li::marker { color: var(--accent-soft); }

/* เปรียบเทียบวิดีโอ ก่อน/หลัง แก้ไข */
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin-bottom: 8px; }
.compare-label {
  font-family: var(--font-display); font-weight: 500; font-size: 11px;
  letter-spacing: 0.09em; color: var(--ink-soft); text-transform: uppercase; margin-bottom: 10px;
}
.compare-meta { font-size: 12.5px; color: var(--ink-soft); }
.video-embed--empty {
  display: flex; align-items: center; justify-content: center;
  min-height: 320px; padding: 20px; text-align: center; font-size: 13.5px;
  color: var(--ink-soft); background: var(--paper);
  border: 1px dashed var(--line); border-radius: var(--radius-sm);
}
@media (max-width: 700px) {
  .compare-grid { grid-template-columns: 1fr; }
}

/* ปุ่ม action ในตาราง */
.table-actions { white-space: nowrap; }
.table-actions a { margin-right: 14px; text-decoration: none; font-weight: 500; }
.table-actions a:hover { text-decoration: underline; }
.inline-delete { display: inline; margin: 0; }
.btn-delete-btn {
  background: none; border: none; padding: 0;
  color: var(--ink-soft); font-family: inherit; font-size: 14px;
  cursor: pointer; transition: color 0.15s ease;
}
.btn-delete-btn:hover { color: var(--danger); text-decoration: underline; }

.round-badge {
  display: inline-block; white-space: nowrap;
  font-size: 12px; font-weight: 500; padding: 4px 11px; border-radius: 999px;
}
.round-badge--yes { background: var(--success-tint); color: var(--success); }
.round-badge--no { background: var(--line-soft); color: var(--ink-soft); border: 1px solid var(--line); }

.export-link {
  display: inline-block; background: var(--surface); color: var(--ink-mid);
  border: 1px solid var(--line);
  padding: 9px 17px; border-radius: var(--radius-sm); font-size: 13.5px;
  text-decoration: none; font-weight: 500;
  box-shadow: var(--shadow-sm);
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.export-link:hover { color: var(--accent); border-color: var(--accent-line); transform: translateY(-1px); }

/* ==== หน้าจัดการระบบ (manage.php) ==== */
.flash-ok {
  color: var(--success); font-size: 13px;
  background: var(--success-tint); border-radius: var(--radius-sm);
  padding: 9px 12px; margin: 0 0 14px;
}

/* การ์ดตัวเลขสรุปสถานะระบบ */
.stat-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px; margin-bottom: 18px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat-value {
  font-family: var(--font-display); font-size: 26px; font-weight: 600;
  color: var(--ink); line-height: 1.2;
}
.stat-label { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }

/* ฟอร์มย่อยในช่องตาราง (ตั้งรหัสผ่านใหม่) */
.inline-form { display: flex; gap: 6px; margin: 0; align-items: center; }
.inline-input {
  width: 150px; margin: 0 !important; padding: 6px 10px !important;
  font-size: 13px !important;
}
.btn-small {
  background: var(--surface); border: 1px solid var(--line);
  color: var(--ink-mid); font-family: inherit; font-size: 13px;
  padding: 6px 12px; border-radius: var(--radius-sm); cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.btn-small:hover { color: var(--accent); border-color: var(--accent-line); }

/* ปุ่มที่หน้าตาเหมือนลิงก์ (ใช้ในตาราง) */
.btn-link {
  background: none; border: none; padding: 0; margin-right: 14px;
  color: var(--ink-soft); font-family: inherit; font-size: 14px;
  cursor: pointer; transition: color 0.15s ease;
}
.btn-link:hover { color: var(--accent); text-decoration: underline; }

/* ฟอร์มในกล่องการ์ด (เพิ่มบัญชี / เปลี่ยนรหัสผ่าน) */
.panel-form {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 24px 26px;
  box-shadow: var(--shadow-sm); max-width: 460px; margin-bottom: 8px;
}
.checkbox-label {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 13.5px; color: var(--ink-mid); font-weight: 400;
  margin-top: 14px; cursor: pointer;
}
.checkbox-label input[type="checkbox"] { width: auto; margin: 2px 0 0; flex-shrink: 0; }
.muted-note {
  font-size: 12.5px; color: var(--ink-soft); line-height: 1.65;
  margin: 14px 0 18px;
}
