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

:root {
  --brand: #3a5cc4;
  --brand-light: #2f49a0;
  --brand-tint: #eef1fb;
  --accent: #3a5cc4;
  --bg: #f4f6f9;
  --card: #ffffff;
  --border: #e6e8ec;
  --text: #1e2430;
  --muted: #697180;
  --green: #237a49;
  --green-bg: #e7f5ee;
  --amber: #a56a1e;
  --amber-bg: #fbf1e2;
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.05);
  --shadow-hover: 0 4px 14px rgba(20, 30, 50, 0.09);
  --radius: 14px;
  --radius-ctl: 10px;
}

* {
  box-sizing: border-box;
}

::selection {
  background: var(--brand);
  color: #fff;
}

body {
  font-family: "Sarabun", "TH Sarabun New", "Noto Sans Thai", Tahoma, sans-serif;
  font-size: 19px;
  margin: 0;
  padding: 16px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

main {
  max-width: 640px;
  margin: 0 auto;
}

h1 {
  color: var(--brand);
  font-size: 1.4em;
  font-weight: 700;
  letter-spacing: 0.2px;
}

h2 {
  color: var(--text);
  font-size: 1.15em;
  font-weight: 600;
}

h3 {
  color: var(--text);
  font-weight: 600;
}

a {
  color: var(--brand);
  transition: color 0.15s ease;
}

a:hover {
  color: var(--brand-light);
}

/* ---------- App header bar ---------- */
.app-header {
  position: relative;
  background: var(--brand);
  color: #fff;
  padding: 18px 16px;
  margin: -16px -16px 20px;
  box-shadow: 0 1px 3px rgba(20, 30, 50, 0.12);
}

.home-btn {
  position: absolute;
  top: 12px;
  right: 16px;
  color: #fff;
  text-decoration: none;
  font-size: 1.3em;
  line-height: 1;
  opacity: 0.9;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.home-btn:hover {
  opacity: 1;
  color: #fff;
  transform: scale(1.1);
}

.app-header h1 {
  color: #fff;
  font-size: 1.15em;
  margin: 0;
  letter-spacing: 0.3px;
}

.app-header button {
  width: auto;
  padding: 7px 14px;
  font-size: 0.85em;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.6);
  color: #fff;
  box-shadow: none;
}

.app-header button:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ---------- Cards / sections ---------- */
#connection-test,
#login-box,
#course-lookup,
#exam-status-box,
#homework-box,
#written-status-box,
#external-training-box,
#upload-box,
#add-employee-box,
#qna-box,
#editor-name-box,
#search-box,
#selected-employee-box,
#change-password-box,
.course-card,
.qna-card,
.edit-course-row {
  margin-top: 24px;
  padding: 18px;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ---------- Forms ---------- */
input[type="text"],
input[type="password"],
input[type="file"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 1em;
  margin-bottom: 8px;
  border: 1px solid #d9dde3;
  border-radius: var(--radius-ctl);
  font-family: inherit;
  background: #ffffff;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="file"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(58, 92, 196, 0.15);
}

textarea {
  resize: vertical;
}

input[type="checkbox"] {
  accent-color: var(--brand);
  width: auto;
  margin: 0;
}

label {
  font-weight: 600;
  color: var(--text);
}

button {
  width: 100%;
  padding: 11px;
  font-size: 1em;
  font-weight: 500;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-ctl);
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
  box-shadow: none;
}

button:hover {
  background: var(--brand-light);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  background: #eceef2;
  color: #a9afb9;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background: #fff;
  color: var(--brand);
  border: 1px solid #c7d0ea;
  box-shadow: none;
}

.btn-secondary:hover {
  background: var(--brand-tint);
}

.error-text {
  color: #b3261e;
  font-weight: bold;
}

.success-text {
  color: var(--green);
  font-weight: bold;
}

#header-row {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 12px;
}

#header-row h1 {
  margin-right: auto;
}

#header-row button {
  width: auto;
  padding: 8px 14px;
  font-size: 0.9em;
}

#header-row .home-btn {
  position: static;
}

/* ---------- My courses list ---------- */
#my-course-list {
  padding: 0;
  list-style: none;
}

#my-course-list li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s ease, transform 0.1s ease;
}

#my-course-list li:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-1px);
}

#my-course-list a {
  text-decoration: none;
  color: inherit;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.course-name-text {
  font-size: 0.95em;
  font-weight: 600;
}

.course-list-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.course-duration {
  font-size: 0.78em;
  color: var(--muted);
}

.cert-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.85em;
  color: var(--brand);
  text-decoration: none;
  font-weight: 600;
}

.cert-link:hover {
  text-decoration: underline;
}

#external-training-list {
  padding: 0;
  list-style: none;
}

#external-training-list li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.status-pill {
  font-size: 0.78em;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 999px;
  white-space: nowrap;
}

.status-pass { background: var(--green-bg); color: var(--green); }
.status-pending { background: var(--amber-bg); color: var(--amber); }
.status-none { background: #eef0f3; color: var(--muted); }

#back-link {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--brand);
  text-decoration: none;
  font-weight: 600;
}

#video-section {
  margin-bottom: 12px;
}

#course-video {
  width: 100%;
  border-radius: var(--radius-ctl);
  background: #101828;
}

.video-placeholder {
  background: linear-gradient(135deg, #101828 0%, #1b2740 100%);
  border-radius: var(--radius-ctl);
  min-height: 150px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #fff;
}

.video-controls {
  align-items: center;
  gap: 8px;
  background: #101828;
  border-radius: 0 0 var(--radius-ctl) var(--radius-ctl);
  padding: 8px 10px;
  margin-top: -4px;
}

.video-control-btn {
  width: auto;
  padding: 6px 10px;
  font-size: 0.9em;
  background: rgba(255, 255, 255, 0.12);
  box-shadow: none;
}

.video-control-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.video-progress-track {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  overflow: hidden;
}

.video-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--brand);
}

.video-time-text {
  color: #fff;
  font-size: 0.8em;
  white-space: nowrap;
}

#pdf-download-link {
  display: block;
  text-decoration: none;
}

.muted {
  color: var(--muted);
  font-size: 0.9em;
}

textarea {
  margin-bottom: 8px;
}

.qna-item {
  background: #f7f8fb;
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  padding: 10px 12px;
  margin-top: 10px;
  font-size: 0.9em;
}

.qna-item .qna-question {
  font-weight: bold;
}

.qna-item .qna-answer {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
  color: var(--green);
}

.qna-item .qna-pending {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.85em;
}

/* ---------- Quiz ---------- */
.quiz-question {
  background: #f7f8fb;
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  padding: 14px;
  margin-bottom: 14px;
  font-size: 0.95em;
}

.quiz-question .q-title {
  font-weight: bold;
  margin-bottom: 8px;
  display: block;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: normal;
  transition: background 0.12s ease;
}

.quiz-option:hover {
  background: var(--brand-tint);
}

.quiz-option input {
  margin: 0;
}

.quiz-result-box {
  padding: 16px;
  border-radius: var(--radius-ctl);
  margin-top: 16px;
  text-align: center;
  font-size: 1.05em;
  font-weight: 700;
}

.quiz-result-pass {
  background: var(--green-bg);
  color: var(--green);
}

.quiz-result-fail {
  background: #fdeceb;
  color: #b3261e;
}

/* ---------- HR: stats + tables (shared by dashboard) ---------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-card .num { font-size: 1.6em; font-weight: 600; color: var(--text); }
.stat-card .label { font-size: 0.78em; color: var(--muted); }

.stat-row .stat-card:nth-child(2) .num { color: var(--green); }
.stat-row .stat-card:nth-child(3) .num { color: var(--amber); }

#position-filter { margin-bottom: 12px; }

#employee-toggle-btn {
  width: auto;
  padding: 9px 16px;
  font-size: 0.9em;
  margin-bottom: 8px;
}

#employee-table-wrap { margin-bottom: 8px; }

table.hr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

table.hr-table th, table.hr-table td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
}

table.hr-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92em;
  background: #f7f8fa;
}

table.hr-table th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

table.hr-table th.sortable:hover {
  background: #eef1f6;
}

table.hr-table tbody tr:hover { background: #f7f9fc; }
table.hr-table tbody tr:last-child td { border-bottom: none; }

.progress-bar {
  background: #e9ecf3;
  border-radius: 999px;
  height: 8px;
  width: 100px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: #2f9e5f;
}

.progress-fill.warn {
  background: var(--brand);
}

/* ---------- Course summary (stacked bars) ---------- */
.course-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 0.82em;
  color: var(--muted);
  margin-bottom: 14px;
}

.course-legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.seg-pass { background: #2f9e5f; }
.seg-fail { background: #c98a2b; }
.seg-none { background: #d7dbe1; }

.course-summary-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.course-summary-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}

.course-summary-name {
  font-weight: 600;
  font-size: 0.92em;
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.course-summary-pct {
  font-weight: 700;
  font-size: 1.15em;
  color: #2f9e5f;
  white-space: nowrap;
  flex-shrink: 0;
}

.course-bar {
  display: flex;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: #eceef3;
}

.course-bar-seg {
  height: 100%;
  transition: width 0.3s ease;
}

.course-summary-counts {
  margin-top: 7px;
  font-size: 0.8em;
  color: var(--muted);
}

.hr-nav-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.hr-nav-row a {
  padding: 8px 14px;
  font-size: 0.85em;
  border: 1px solid #c7d0ea;
  border-radius: var(--radius-ctl);
  text-decoration: none;
  color: var(--brand);
  transition: background 0.15s ease, color 0.15s ease;
}

.hr-nav-row a:hover {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.hr-nav-row a.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  cursor: default;
}

/* ---------- HR: course management ---------- */
.position-checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  margin: 10px 0;
  font-size: 0.85em;
}

.position-checks label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: normal;
}

.assessment-type-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  align-items: center;
  margin: 10px 0;
  font-size: 0.85em;
}

.assessment-type-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: normal;
}

.homework-deadline-row {
  display: flex;
  align-items: center;
  width: 100%;
}

.homework-deadline-row input[type="number"] {
  width: 70px;
  margin-left: 6px;
  display: inline-block;
}

.course-duration-row {
  display: flex;
  align-items: center;
  font-weight: normal;
  font-size: 0.85em;
  margin: 10px 0;
}

.course-duration-row input[type="number"] {
  width: 90px;
  margin-left: 6px;
  margin-bottom: 0;
  display: inline-block;
}

.file-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
  flex-wrap: wrap;
}

.file-row input[type="file"],
.file-row input[type="text"] { flex: 1; margin-bottom: 0; }
.file-row button { width: auto; padding: 8px 14px; }
.file-status { font-size: 0.8em; }
.file-status.ok { color: var(--green); font-weight: 600; }
.file-status.pending { color: var(--amber); }

/* ---------- HR: quiz question management ---------- */
.quiz-admin-section {
  margin-top: 14px;
  border-top: 1px dashed var(--border);
  padding-top: 14px;
}

.quiz-admin-section > button {
  width: auto;
  padding: 8px 14px;
  font-size: 0.9em;
}

.quiz-admin-panel {
  margin-top: 12px;
}

.quiz-admin-item {
  background: #f7f8fb;
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  padding: 10px 12px;
  margin-bottom: 10px;
  font-size: 0.9em;
}

.quiz-admin-question {
  font-weight: bold;
  margin-bottom: 6px;
}

.quiz-admin-item ul {
  margin: 0 0 8px;
  padding-left: 20px;
}

.quiz-admin-item .correct-choice {
  color: var(--green);
  font-weight: 600;
}

.quiz-admin-item button {
  width: auto;
  padding: 6px 12px;
  font-size: 0.85em;
}

.quiz-admin-form {
  background: #f7f8fb;
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  padding: 12px;
}

.quiz-admin-choice-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quiz-admin-choice-row input[type="text"] {
  flex: 1;
}

.quiz-admin-form > button {
  width: auto;
  padding: 8px 14px;
  margin-top: 4px;
}

/* ---------- HR: Q&A admin ---------- */
.qna-meta {
  font-size: 0.8em;
  color: var(--muted);
  margin-bottom: 6px;
}

.qna-answer-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.qna-answer-row textarea { flex: 1; margin-bottom: 0; }
.qna-answer-row button { width: auto; padding: 8px 14px; }

/* ---------- HR: edit status ---------- */
#search-results {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
}

#search-results li {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-ctl);
  margin-bottom: 6px;
  cursor: pointer;
  background: #f7f8fb;
  transition: background 0.12s ease, border-color 0.12s ease;
}

#search-results li:hover {
  background: var(--brand-tint);
  border-color: var(--brand);
}

#selected-employee-box {
  display: none;
}

.edit-course-row .course-name-text {
  font-weight: bold;
  display: block;
  margin-bottom: 8px;
}

.edit-course-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.edit-course-controls select,
.edit-course-controls input[type="number"] {
  width: auto;
  padding: 8px 10px;
  margin-bottom: 0;
}

.edit-course-controls button {
  width: auto;
  padding: 8px 14px;
}

#log-list {
  padding: 0;
  list-style: none;
  font-size: 0.85em;
}

#log-list li {
  padding: 8px 10px;
  border-bottom: 1px dashed var(--border);
}

@media (max-width: 480px) {
  .stat-row { gap: 8px; }
  .stat-card .num { font-size: 1.3em; }
}
