/* ==========================================================================
   ระบบกระดาษคำตอบออนไลน์ - style.css
   ========================================================================== */

:root {
  --blue: #4285F4;
  --red: #EA4335;
  --yellow: #FBBC05;
  --green: #34A853;
  --blue-dark: #2f5fc4;
  --red-dark: #c62f24;
  --yellow-dark: #cf9a04;
  --green-dark: #278a41;
  --text-main: #202124;
  --text-muted: #5f6368;
  --border-color: #e0e0e0;
  --bg-page: #f5f6f8;
  --bg-card: #ffffff;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: 'Sarabun', sans-serif;
  font-size: 16px;
  color: var(--text-main);
  background: var(--bg-page);
  line-height: 1.5;
}

main {
  flex: 1 0 auto;
}

h1, h2, h3, h4 {
  font-weight: 700;
  margin: 0 0 12px 0;
  color: var(--text-main);
}

h1 { font-size: 26px; }
h2 { font-size: 21px; }
h3 { font-size: 18px; }

p { margin: 0 0 12px 0; }

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.text-muted { color: var(--text-muted); font-size: 14px; }

/* ==========================================================================
   Layout
   ========================================================================== */

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  width: 80%;
  margin: 0 auto;
  padding: 14px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.topbar .brand {
  font-weight: 800;
  font-size: 18px;
  color: var(--blue);
}

.topbar nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.topbar nav a {
  color: var(--text-main);
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
}

.topbar nav a:hover {
  background: var(--bg-page);
  text-decoration: none;
}

.page-wrap {
  width: 80%;
  margin: 24px auto;
}

/* ==========================================================================
   Footer (สติ๊กด้านล่างเสมอ)
   ========================================================================== */

.site-footer {
  flex-shrink: 0;
  background: #fff;
  border-top: 1px solid var(--border-color);
  padding: 16px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: #fff;
  background: var(--blue);
  transition: background 0.15s ease, transform 0.05s ease;
  text-decoration: none;
  line-height: 1.2;
}

.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.98); }

.btn-blue { background: var(--blue); }
.btn-blue:hover { background: var(--blue-dark); }

.btn-red { background: var(--red); }
.btn-red:hover { background: var(--red-dark); }

.btn-yellow { background: var(--yellow); color: #4a3b00; }
.btn-yellow:hover { background: var(--yellow-dark); }

.btn-green { background: var(--green); }
.btn-green:hover { background: var(--green-dark); }

.btn-outline {
  background: transparent;
  color: var(--blue);
  border: 2px solid var(--blue);
}
.btn-outline:hover { background: rgba(66,133,244,0.08); }

.btn-lg { padding: 14px 24px; font-size: 17px; border-radius: 10px; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 6px; }

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

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  text-align: center;
  border-top: 4px solid var(--blue);
}
.stat-card .num { font-size: 32px; font-weight: 800; }
.stat-card .label { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

.stat-blue { border-top-color: var(--blue); }
.stat-blue .num { color: var(--blue); }
.stat-red { border-top-color: var(--red); }
.stat-red .num { color: var(--red); }
.stat-yellow { border-top-color: var(--yellow); }
.stat-yellow .num { color: var(--yellow-dark); }
.stat-green { border-top-color: var(--green); }
.stat-green .num { color: var(--green); }

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

/* ==========================================================================
   Forms
   ========================================================================== */

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 15px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: #fff;
  margin-bottom: 16px;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(66,133,244,0.15);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0 16px;
}

.checklist {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  max-height: 260px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.checklist label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  margin-bottom: 8px;
}

.checklist input[type="checkbox"] {
  width: auto;
  margin: 0;
}

/* ==========================================================================
   Table
   ========================================================================== */

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  font-size: 15px;
}

th {
  color: var(--text-muted);
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr:hover td { background: var(--bg-page); }

/* ==========================================================================
   Tags / badges
   ========================================================================== */

.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #eee;
  color: var(--text-muted);
}

.tag-open { background: rgba(52,168,83,0.15); color: var(--green-dark); }
.tag-upcoming { background: rgba(251,188,5,0.2); color: var(--yellow-dark); }
.tag-closed { background: rgba(234,67,53,0.12); color: var(--red-dark); }

/* ==========================================================================
   Alerts (แบนเนอร์ถาวร - ไม่ใช่ SweetAlert)
   ========================================================================== */

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  border: 1px solid transparent;
}

.alert-info { background: rgba(66,133,244,0.08); border-color: rgba(66,133,244,0.3); color: var(--blue-dark); }
.alert-success { background: rgba(52,168,83,0.1); border-color: rgba(52,168,83,0.3); color: var(--green-dark); }
.alert-error { background: rgba(234,67,53,0.1); border-color: rgba(234,67,53,0.3); color: var(--red-dark); }
.alert-warning { background: rgba(251,188,5,0.15); border-color: rgba(251,188,5,0.4); color: var(--yellow-dark); }

/* ==========================================================================
   Login pages
   ========================================================================== */

.login-page {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--blue) 0%, var(--green) 100%);
  padding: 20px;
  overflow-y: auto;
  box-sizing: border-box;
  z-index: 1;
}

.login-box {
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.15);
  margin: auto;
}

.login-box h1 {
  text-align: center;
  font-size: 22px;
  margin-bottom: 24px;
}

.login-box .btn { width: 100%; margin-top: 8px; }

/* ==========================================================================
   Landing page (หน้าแรก - เลือกประเภทผู้ใช้งาน)
   ========================================================================== */

.landing-page {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--blue) 0%, var(--green) 100%);
  padding: 20px;
  overflow-y: auto;
  box-sizing: border-box;
  z-index: 1;
  text-align: center;
}

.landing-box {
  background: #fff;
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.15);
  margin: auto;
}

.landing-box h1 {
  font-size: 24px;
  margin-bottom: 8px;
}

.role-cards {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 24px;
}

.role-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 140px;
  padding: 20px 12px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-main);
  font-weight: 700;
  transition: all 0.15s ease;
}

.role-card:hover {
  border-color: var(--blue);
  background: rgba(66,133,244,0.06);
  text-decoration: none;
  transform: translateY(-2px);
}

.role-icon { font-size: 32px; }

/* ==========================================================================
   Answer sheet (กระดาษคำตอบ - bubble sheet)
   หมายเหตุ: ชื่อคลาส .q-row / .choice-group ต้องตรงกับที่ assets/js/exam.js
   ใช้ query จริง (document.querySelectorAll('.q-row'), group.dataset.q ฯลฯ)
   ========================================================================== */

.answer-sheet {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.q-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: #fff;
}

.q-row.answered {
  border-color: rgba(52,168,83,0.4);
  background: rgba(52,168,83,0.04);
}

.q-no {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-page);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1;
}

.choice-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  background: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.12s ease;
  color: var(--text-main);
}

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

.choice-btn.selected {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  transform: scale(1.05);
}

/* ==========================================================================
   หน้าทำข้อสอบ
   ========================================================================== */

.exam-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
}

.exam-topbar h2 {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
}

/* #timer-box คือ wrapper ที่ assets/js/exam.js เติมคลาส .low ให้เมื่อเวลาใกล้หมด
   ตอนนี้เป็นกล่องซ้อนแนวตั้ง: นาฬิกาด้านบน + จำนวนข้อที่ตอบแล้วด้านล่าง ยึดมุมบนขวาด้วยกัน */
#timer-box.timer-stack {
  position: sticky;
  top: 10px;
  align-self: flex-start;
  flex-shrink: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}

.timer-box {
  background: var(--red);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  padding: 8px 18px;
  border-radius: 10px;
  min-width: 100px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.progress-box {
  background: #fff;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 14px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 10px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}

#timer-box.low #timer-display {
  background: var(--yellow-dark);
  animation: timerPulse 1s ease-in-out infinite;
}

@keyframes timerPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.exam-split {
  display: grid;
  grid-template-columns: 15fr 4fr; /* ซ้าย 75% : ขวา 20% ของพื้นที่ทั้งหมด */
  gap: 20px;
  align-items: start;

  /* ขยายพื้นที่เป็น 95% ของหน้าจอ โดยไม่ขึ้นกับกรอบ 10% เดิมของหน้าอื่น ๆ */
  width: 95vw;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  box-sizing: border-box;
  margin-top: 12px;
}

.exam-split.no-pdf {
  grid-template-columns: 1fr;
}

.exam-pdf-pane {
  height: 82vh;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.exam-pdf-pane iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.exam-answer-pane {
  max-height: 82vh;
  overflow-y: auto;
  padding-right: 4px;
}

@media (max-width: 900px) {
  .exam-split,
  .exam-split.no-pdf {
    grid-template-columns: 1fr;
    width: 96vw;
  }
  .exam-pdf-pane {
    height: 60vh;
    margin-bottom: 16px;
  }
  .exam-answer-pane {
    max-height: none;
    overflow-y: visible;
  }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 900px) {
  .topbar-inner,
  .page-wrap {
    width: 92%;
  }
}

@media (max-width: 600px) {
  .topbar-inner,
  .page-wrap {
    width: 94%;
  }
  h1 { font-size: 21px; }
  .btn { padding: 10px 14px; font-size: 14px; }
  .choice-btn { width: 36px; height: 36px; font-size: 13px; }
}

/* ==========================================================================
   Print (หน้ารายงานพิมพ์ใช้ @media print ของตัวเองเพิ่มเติมในไฟล์)
   ========================================================================== */

@media print {
  .topbar, .site-footer, .no-print {
    display: none !important;
  }
  body { background: #fff; }
  .page-wrap { width: 100%; margin: 0; }
}
