:root {
  --navy: #071129;
  --deep: #081b53;
  --blue: #2563eb;
  --cyan: #06b6d4;
  --green: #16a34a;
  --gold: #f59e0b;
  --bg: #eef5fb;
  --card: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #d9e2ee;
  --danger: #dc2626;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "TH Sarabun New", Sarabun, Prompt, system-ui, sans-serif;
  background: radial-gradient(circle at top left, #f7fbff 0, #edf6ff 45%, #eaf5ff 100%);
  color: var(--text);
  font-size: 16.5px;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hide { display: none !important; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.app { min-height: 100vh; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 26px;
}
.login-card {
  width: min(960px, 96vw);
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  background: #fff;
  border-radius: 32px;
  box-shadow: 0 30px 90px rgba(20, 74, 150, .16);
  overflow: hidden;
  border: 1px solid #d7e7f7;
}
.brand-panel {
  background: radial-gradient(circle at 20% 15%, #2f66ff, #0d49cc 25%, #081b53 62%, #051031);
  color: white;
  padding: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.brand-panel img {
  width: 136px;
  filter: drop-shadow(0 0 18px rgba(6, 182, 212, .45)) drop-shadow(0 0 10px rgba(245, 158, 11, .35));
  margin-bottom: 16px;
}
.brand-title {
  font-size: 38px;
  font-weight: 800;
  line-height: 1.05;
  white-space: nowrap;
}
.brand-sub {
  font-size: 22px;
  font-weight: 700;
  color: #7dd3fc;
  margin-top: 8px;
}
.login-panel {
  padding: 46px;
  background: linear-gradient(180deg, #ffffff, #fbfdff);
}
.login-panel h1 {
  font-size: 30px;
  margin: 0 0 6px;
  font-weight: 700;
  text-align: center;
}
.login-panel > p { text-align: center; }

.field { margin: 14px 0; }
.field label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
  color: #334155;
}
.input, .select, .textarea {
  width: 100%;
  border: 1px solid #dbe4f0;
  border-radius: 16px;
  padding: 13px 16px;
  background: #fff;
  outline: none;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 4px rgba(56, 189, 248, .15);
}
.textarea { min-height: 92px; resize: vertical; }

.btn {
  border: 0;
  border-radius: 16px;
  padding: 13px 20px;
  font-weight: 800;
  background: #e2e8f0;
  color: var(--text);
}
.btn.primary {
  background: linear-gradient(135deg, #2f66ff, #19b7e8);
  color: #fff;
  box-shadow: 0 12px 24px rgba(37, 99, 235, .18);
}
.btn.dark { background: var(--navy); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { background: #fee2e2; color: #991b1b; }
.btn:disabled { opacity: .65; cursor: not-allowed; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: linear-gradient(180deg, #ffffff, #f7fbff);
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 2px 14px rgba(15, 23, 42, .05);
  position: sticky;
  top: 0;
  z-index: 5;
}
.top-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.top-left img {
  width: 48px;
  flex: 0 0 auto;
  filter: drop-shadow(0 0 12px rgba(6, 182, 212, .22)) drop-shadow(0 0 4px rgba(245, 158, 11, .18));
}
.top-title {
  font-weight: 800;
  font-size: 24px;
  white-space: nowrap;
  color: var(--deep);
}
.top-sub { font-weight: 700; color: var(--blue); }

.shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 80px);
}
.sidebar {
  background: linear-gradient(180deg, #0b1f5d, #06153d 58%, #04102e);
  color: white;
  padding: 20px 16px;
}
.userbox {
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 20px;
  margin-bottom: 16px;
  background: rgba(255, 255, 255, .06);
}
.navbtn {
  width: 100%;
  border: 0;
  background: transparent;
  color: #dbeafe;
  text-align: left;
  padding: 13px 14px;
  border-radius: 16px;
  margin: 3px 0;
  font-weight: 800;
}
.navbtn:hover, .navbtn.active {
  background: linear-gradient(135deg, #2563eb, #19b7e8);
  color: #fff;
  box-shadow: 0 10px 22px rgba(37, 99, 235, .22);
}
.content { padding: 22px; max-width: 1600px; min-width: 0; }
.page-head {
  border-left: 6px solid var(--blue);
  padding-left: 14px;
  margin-bottom: 20px;
}
.page-title {
  color: var(--deep);
  font-size: 30px;
  font-weight: 800;
  margin: 0 0 4px;
}

.card {
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  border: 1px solid #dce8f5;
  border-radius: 24px;
  box-shadow: 0 12px 30px rgba(26, 65, 128, .06);
  padding: 22px;
  margin-bottom: 18px;
}
.grid { display: grid; gap: 16px; }
.grid4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.kpi {
  border-radius: 24px;
  padding: 20px;
  min-height: 118px;
  color: var(--text);
  border: 1px solid rgba(215, 229, 242, .95);
  box-shadow: 0 14px 30px rgba(31, 78, 150, .08);
  position: relative;
  overflow: hidden;
}
.kpi:before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 7px;
}
.kpi:nth-child(1) { background: linear-gradient(135deg, #fff 0%, #edf6ff 72%, #dceeff 100%); }
.kpi:nth-child(2) { background: linear-gradient(135deg, #fff 0%, #effdf7 72%, #dcfce7 100%); }
.kpi:nth-child(3) { background: linear-gradient(135deg, #fff 0%, #f5f0ff 72%, #ede9fe 100%); }
.kpi:nth-child(4) { background: linear-gradient(135deg, #fff 0%, #fff7ed 72%, #ffedd5 100%); }
.kpi:nth-child(1):before { background: linear-gradient(180deg, #1d4ed8, #60a5fa); }
.kpi:nth-child(2):before { background: linear-gradient(180deg, #16a34a, #86efac); }
.kpi:nth-child(3):before { background: linear-gradient(180deg, #7c3aed, #c4b5fd); }
.kpi:nth-child(4):before { background: linear-gradient(180deg, #f97316, #fdba74); }
.kpi .num {
  color: var(--deep);
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
  margin: 8px 0 4px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid #d7e7f7;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 8px 18px rgba(31, 78, 150, .05);
}
table { width: 100%; border-collapse: collapse; background: white; }
th, td {
  padding: 12px 13px;
  border-bottom: 1px solid #eef2f7;
  text-align: left;
  vertical-align: top;
}
th {
  background: linear-gradient(135deg, #0b3ea8, #1764dd 55%, #20aee8);
  color: #fff;
  font-weight: 800;
  white-space: nowrap;
}
tbody tr:nth-child(even) td { background: #f8fbff; }
tbody tr:hover td { background: #edf6ff; }

.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: end;
}
.toolbar > * { min-width: 190px; flex: 1; }
.section-title {
  font-size: 20px;
  font-weight: 800;
  margin: 0 0 10px;
  color: #0b2b74;
}
.assessment-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.assessment-card {
  border: 1px solid #d7e7f7;
  border-radius: 20px;
  padding: 14px;
  background: linear-gradient(135deg, #ffffff, #f7fbff);
  box-shadow: 0 10px 22px rgba(31, 78, 150, .06);
}
.topic-no { font-size: 14px; font-weight: 800; color: #1d4ed8; }
.topic-text {
  font-size: 17px;
  line-height: 1.45;
  color: #1e293b;
  margin: 5px 0 10px;
}
.score-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}
.score-options input { display: none; }
.score-pill {
  display: block;
  text-align: center;
  border: 1px solid #dbe4f0;
  border-radius: 999px;
  padding: 7px 8px;
  font-size: 15px;
  font-weight: 800;
  color: #334155;
  background: #fff;
}
.score-options input:checked + .score-pill {
  background: linear-gradient(135deg, #1764dd, #20aee8);
  border-color: #2563eb;
  color: #fff;
  box-shadow: 0 8px 16px rgba(37, 99, 235, .16);
}
.upload-card {
  border: 1px dashed #8ec5ff;
  background: linear-gradient(135deg, #ffffff, #edf6ff);
  border-radius: 20px;
  padding: 14px;
  text-align: center;
}
.upload-card label {
  font-size: 17px;
  font-weight: 800;
  color: #1e40af;
}
.upload-card input { margin-top: 8px; background: white; max-width: 100%; }
.score-badge {
  display: inline-block;
  border-radius: 999px;
  background: linear-gradient(135deg, #dbeafe, #cffafe);
  color: #0b3ea8;
  border: 1px solid #bfdbfe;
  padding: 4px 10px;
  font-weight: 800;
  font-size: 14px;
}
.manage-icons {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
}
.icon-btn {
  border: 0;
  background: transparent;
  padding: 4px 7px;
  font-size: 22px;
  border-radius: 10px;
}
.icon-btn:hover {
  transform: translateY(-1px);
  filter: drop-shadow(0 3px 4px rgba(15, 23, 42, .18));
}

.gallery-card {
  border: 1px solid #dbe4f0;
  border-radius: 22px;
  overflow: hidden;
  background: #fff;
}
.imgbox {
  aspect-ratio: 4 / 3;
  background: #f1f5f9;
  display: grid;
  place-items: center;
  border-bottom: 1px solid #e2e8f0;
}
.imgbox img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.caption {
  padding: 10px 12px;
  text-align: center;
  font-weight: 700;
  color: var(--text);
}
.news-head {
  padding: 16px 18px;
  border-radius: 20px;
  background: linear-gradient(135deg, #0b1f5d, #1d4ed8 55%, #20aee8);
  color: white;
  margin-bottom: 14px;
  box-shadow: 0 16px 34px rgba(37, 99, 235, .22);
}
.news-head h2 {
  color: #fff;
  font-size: 21px;
  font-weight: 800;
  line-height: 1.3;
  margin: 0;
}
.news-meta {
  color: #eef7ff;
  font-size: 15px;
  margin-top: 6px;
  font-weight: 600;
}
.report-photo-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.report-photo {
  border: 1px solid #dbe4f0;
  border-radius: 18px;
  overflow: hidden;
  background: #fff;
}
.report-photo .imgbox { border-bottom: 0; }

.alert {
  padding: 12px 14px;
  border-radius: 16px;
  margin: 10px 0;
  font-weight: 700;
}
.alert.ok { background: #dcfce7; color: #166534; }
.alert.err { background: #fee2e2; color: #991b1b; }
.status { min-height: 24px; }
.footer {
  text-align: center;
  color: var(--muted);
  font-weight: 600;
  padding: 20px 10px;
  white-space: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  font-size: clamp(10px, .95vw, 14px);
}
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, .52);
  display: grid;
  place-items: center;
  z-index: 99;
}
.modal-card {
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .35);
  width: min(460px, 92vw);
  padding: 24px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
}

@media (max-width: 980px) {
  .login-card { grid-template-columns: 1fr; }
  .brand-title { font-size: 34px; white-space: normal; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; }
  .grid4, .grid3, .grid2, .assessment-grid, .report-photo-row { grid-template-columns: 1fr; }
  .toolbar > * { min-width: 100%; }
  .top-title { font-size: 22px; white-space: normal; }
  .topbar { align-items: flex-start; }
}

@media print {
  body { background: white; color: #111; font-size: 16pt; }
  .no-print, .topbar, .sidebar, .footer { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; margin: 0; padding: 0; }
  table { font-size: 14pt; }
  thead { display: table-header-group; }
}
