/* Reset & base */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f4f6fb;
  color: #1f2937;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: #6b7280; }
hr { border: none; border-top: 1px solid #e5e7eb; margin: 1rem 0; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.2rem;
  width: 100%;
}

/* Topbar */
.topbar {
  background: #1a2960;
  color: #fff;
  padding: 0.8rem 0;
}
.topbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}
.topbar a { color: #fff; }
.brand {
  font-size: 1.15rem;
  font-weight: 700;
}
nav {
  display: flex;
  gap: 1rem;
  align-items: center;
}
nav a { padding: 4px 8px; border-radius: 4px; }
nav a:hover { background: rgba(255,255,255,0.1); text-decoration: none; }
.user-name { opacity: 0.8; font-size: 0.9rem; }
button.link {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px 8px;
  font: inherit;
}
button.link.danger { color: #dc2626; }

main {
  flex: 1;
  padding: 2rem 0;
}

/* Buttons */
.btn-primary, .btn-secondary {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font: inherit;
  text-decoration: none;
  margin-right: 6px;
}
.btn-primary { background: #1a2960; color: #fff; }
.btn-primary:hover { background: #0f1e4a; text-decoration: none; }
.btn-secondary { background: #fff; color: #1a2960; border: 1px solid #1a2960; }
.btn-secondary:hover { background: #f4f6fb; text-decoration: none; }
.btn-mini {
  padding: 4px 10px;
  font-size: 0.85rem;
  border-radius: 5px;
  border: 1px solid #d1d5db;
  background: #fff;
  cursor: pointer;
  font: inherit;
  margin-right: 4px;
}
.btn-primary.btn-mini { background: #1a2960; color: #fff; border-color: #1a2960; }

/* Cards */
.card {
  background: #fff;
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  margin: 1rem 0;
}
.card.narrow { max-width: 460px; margin: 2rem auto; }

/* Forms */
form label {
  display: block;
  margin: 0.8rem 0;
  font-weight: 600;
  font-size: 0.9rem;
}
form input[type=text],
form input[type=email],
form input[type=password],
form input[type=number],
form input[type=date],
form select,
form textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font: inherit;
  background: #fff;
  margin-top: 4px;
}
form input:focus, form select:focus, form textarea:focus {
  outline: 2px solid #1a2960;
  outline-offset: -1px;
}
label.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 1.6rem;
  font-weight: 500;
}
label.checkbox input { width: auto; margin: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
@media (max-width: 700px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* Tables */
.table {
  width: 100%;
  background: #fff;
  border-collapse: collapse;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  margin: 1rem 0;
}
.table th, .table td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}
.table th { background: #f8fafc; font-size: 0.85rem; color: #64748b; text-transform: uppercase; letter-spacing: 0.5px; }
.table tr:last-child td { border-bottom: none; }

.info-table { width: 100%; }
.info-table th, .info-table td { padding: 8px 12px; text-align: left; }
.info-table th { color: #64748b; width: 140px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 0.8rem;
  background: #e5e7eb;
  color: #374151;
}
.badge.enrolled { background: #dbeafe; color: #1e40af; }
.badge.completed { background: #d1fae5; color: #065f46; }
.badge.failed { background: #fee2e2; color: #991b1b; }

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-weight: 500;
}
.alert.success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert.error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert.info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* Hero */
.hero {
  text-align: center;
  padding: 3rem 1rem;
  background: linear-gradient(135deg, #1a2960, #2c4cb3);
  color: #fff;
  border-radius: 14px;
  margin-bottom: 2rem;
}
.hero h1 { font-size: 2.4rem; margin: 0 0 0.5rem; }
.hero p { font-size: 1.1rem; opacity: 0.9; }
.cta { margin-top: 1.5rem; }
.cta .btn-primary { background: #fff; color: #1a2960; }
.cta .btn-primary:hover { background: #f4f6fb; }
.cta .btn-secondary { background: transparent; color: #fff; border-color: #fff; }

/* Features */
.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.2rem;
  margin-bottom: 2rem;
}
.feature {
  background: #fff;
  padding: 1.5rem;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.feature h3 { margin-top: 0; }

.verify-box {
  background: #fff;
  padding: 1.5rem;
  border-radius: 10px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.verify-box form {
  display: flex;
  gap: 8px;
  max-width: 500px;
  margin: 0 auto;
}
.verify-box input { flex: 1; padding: 9px 12px; border: 1px solid #d1d5db; border-radius: 6px; font: inherit; }

/* Course grid */
.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}
.course-card {
  background: #fff;
  padding: 1.5rem;
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  display: block;
  color: inherit;
  border: 1px solid transparent;
  transition: border-color 0.2s, transform 0.2s;
}
.course-card:hover { border-color: #1a2960; text-decoration: none; transform: translateY(-2px); }
.course-card h3 { margin-top: 0; color: #1a2960; }
.course-card .meta {
  margin-top: 1rem;
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
  color: #6b7280;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.8rem;
  margin: 1rem 0 2rem;
  background: #fff;
  padding: 1rem 1.5rem;
  border-radius: 10px;
}

.progress-box {
  background: #fff;
  padding: 1.5rem;
  border-radius: 10px;
  margin-top: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.progress-box ul { list-style: none; padding: 0; }
.progress-box li {
  padding: 12px 0;
  border-bottom: 1px solid #f1f5f9;
}
.progress-box li:last-child { border-bottom: none; }

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1rem 0;
}

/* Settings box on quiz-edit */
.settings-box {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 1rem 1.5rem;
  margin: 1rem 0;
  background: #f8fafc;
}
.settings-box legend { padding: 0 8px; font-weight: 700; color: #1a2960; }
.settings-box small { display: block; margin-top: 4px; font-weight: normal; }

/* Quiz progress (one-at-a-time mode) */
.quiz-progress { margin: 1rem 0; }
.progress-track {
  background: #e5e7eb;
  border-radius: 99px;
  height: 10px;
  overflow: hidden;
}
.progress-fill {
  background: linear-gradient(90deg, #1a2960, #2c4cb3);
  height: 100%;
  border-radius: 99px;
  transition: width 0.3s;
}
.progress-text {
  margin-top: 6px;
  font-weight: 600;
  color: #1a2960;
  text-align: center;
}
.quiz-nav {
  margin-top: 1.5rem;
  display: flex;
  justify-content: center;
  gap: 1rem;
}
.quiz-nav button:disabled {
  background: #cbd5e1 !important;
  color: #64748b !important;
  cursor: not-allowed;
}

/* Quiz blocks */
.question-block {
  padding: 1rem;
  background: #f8fafc;
  border-radius: 8px;
  margin: 1rem 0;
}
.qb-single { padding: 1.5rem; font-size: 1.1rem; }
.choices { margin-top: 8px; }
.choice-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  cursor: pointer;
  font-weight: normal;
}
.choice-row input[type=radio] { margin: 0; }
.choice-row input[type=text] { flex: 1; }

.attendance-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* Quiz result */
.big-result { text-align: center; padding: 2rem; }
.big-result.pass { background: #ecfdf5; border: 2px solid #10b981; }
.big-result.fail { background: #fef2f2; border: 2px solid #ef4444; }
.score-num { font-size: 3rem; font-weight: 700; color: #1a2960; }
.score-pct { font-size: 1.6rem; color: #6b7280; margin-bottom: 1rem; }

.cert-verify-ok { border: 2px solid #10b981; }
.cert-verify-fail { border: 2px solid #ef4444; }

/* Footer */
footer {
  background: #1f2937;
  color: #d1d5db;
  padding: 1.5rem 0;
  margin-top: auto;
  text-align: center;
  font-size: 0.9rem;
}
