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

/* โทนสีนาวี + ทอง (เข้ากับโลโก้โรงเรียน) */
:root {
  --primary: #1b3a6b;
  --primary-dark: #102a52;
  --navy-deep: #0b1f3f;
  --gold: #d4a62a;
  --gold-soft: #f6e7b8;
  --accent: #d64545;
  --warn: #e0a526;
  --bg: #f2f4f8;
  --card: #fff;
  --text: #16243a;
  --muted: #64718a;
  --line: #dce2ec;
  --p1: #e3f4ea;
  --p2: #fdf3dc;
  --p3: #e6eefb;
  --none: #fbe6e6;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Sarabun', 'Tahoma', sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
}
a { color: var(--primary-dark); }
h1, h2, h3, h4 { margin: 0 0 .6em; line-height: 1.3; color: var(--navy-deep); }
.card > h2:first-child { padding-left: 10px; border-left: 4px solid var(--gold); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.1rem; }

/* ---------- layout ---------- */
.topbar {
  background: linear-gradient(90deg, var(--navy-deep), var(--primary));
  border-bottom: 3px solid var(--gold);
  box-shadow: 0 2px 10px rgba(11,31,63,.25);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}
.topbar .brand { font-weight: 700; font-size: 1.1rem; margin-right: auto; color: #fff; text-decoration: none; display: flex; align-items: center; gap: 10px; }
.topbar .brand img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.school-logo { display: block; width: 140px; height: 140px; margin: 0 auto 12px; border-radius: 16px; object-fit: cover; border: 3px solid var(--gold); box-shadow: 0 4px 14px rgba(11,31,63,.3); }
.container.narrow .card { border-top: 4px solid var(--gold); }
.site-footer { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 16px; color: var(--muted); font-size: .875rem; }
.site-footer img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px; }
.topbar nav a {
  color: #fff; text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: .95rem;
}
.topbar nav a:hover { background: rgba(255,255,255,.12); }
.topbar nav a.active { background: rgba(212,166,42,.22); color: var(--gold-soft); box-shadow: inset 0 -2px 0 var(--gold); }
.topbar .brand img { border: 1px solid rgba(212,166,42,.6); }
.container { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }
.container.narrow { max-width: 520px; padding-top: 48px; }
.container.mid { max-width: 900px; }
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  margin-bottom: 20px;
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.row > .field { flex: 1 1 160px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; }

/* ---------- stat tiles ---------- */
.stat { background: var(--card); border-radius: 12px; padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.08); border-left: 5px solid var(--primary); }
.stat .num { font-size: 1.8rem; font-weight: 700; }
.stat .label { color: var(--muted); font-size: .9rem; }
.stat.warn { border-color: var(--warn); }
.stat.danger { border-color: var(--accent); }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; margin-bottom: 4px; font-size: .95rem; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], input[type=file], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
textarea { min-height: 140px; }
.field { margin-bottom: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }

.btn {
  display: inline-block;
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  line-height: 1.3;
}
.btn { transition: background .15s, box-shadow .15s, transform .05s; box-shadow: 0 1px 2px rgba(11,31,63,.2); }
.btn:hover { background: var(--primary-dark); box-shadow: 0 3px 8px rgba(11,31,63,.25); }
.btn:active { transform: translateY(1px); }
.btn-sm { padding: 5px 10px; font-size: .875rem; }
.btn-danger { background: var(--accent); }
.btn-danger:hover { background: #b93636; }
.btn-warn { background: var(--warn); color: #3b2a12; }
.btn-warn:hover { background: #c98f17; }
.btn-gold { background: var(--gold); color: var(--navy-deep); }
.btn-gold:hover { background: #bf931f; }
.btn-light { background: #e8ecf3; color: var(--text); box-shadow: none; }
.btn-light:hover { background: #d9dfea; box-shadow: none; }
.btn-block { width: 100%; padding: 12px; font-size: 1.05rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; }

/* ---------- alerts / badges ---------- */
.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; }
.alert-success { background: #e3f6ec; color: #1d6b45; }
.alert-danger { background: #fde8e8; color: #9b2c2c; }
.alert-warning { background: #fff4e0; color: #8a5a00; }
.alert-info { background: #e6eefb; color: var(--primary); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #e9eef2; white-space: nowrap; }
.badge-ok { background: #d4f2e2; color: #1d6b45; }
.badge-warn { background: #ffe9c7; color: #8a5a00; }
.badge-no { background: #fbd5d5; color: #9b2c2c; }
.badge-info { background: #d6e8f8; color: #1f5a8a; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--primary); color: #fff; font-weight: 600; font-size: .92rem; white-space: nowrap; }
thead th:first-child { border-top-left-radius: 8px; }
thead th:last-child { border-top-right-radius: 8px; }
tbody tr:not(.p1):not(.p2):not(.p3):not(.none):hover td { background: #f5f7fb; }
tr.p1 td { background: var(--p1); }
tr.p2 td { background: var(--p2); }
tr.p3 td { background: var(--p3); }
tr.none td { background: var(--none); }
td.over { color: var(--accent); font-weight: 700; }
.bar { height: 8px; background: #e9eef2; border-radius: 4px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--primary); }
.bar > span.full { background: var(--accent); }

/* ---------- student page ---------- */
select.choice { max-width: 100%; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }
.choice-info { margin-top: 6px; padding: 8px 12px; border-left: 3px solid var(--gold); background: #f7f9fc; border-radius: 0 8px 8px 0; font-size: .92rem; line-height: 1.6; overflow-wrap: anywhere; }
.choice-box { border: 2px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.choice-box .rank { display: inline-block; background: var(--primary); color: #fff; border-radius: 999px; padding: 1px 10px; font-weight: 700; margin-bottom: 6px; }
.choice-box .rank { background: var(--gold); color: var(--navy-deep); }
.result-big { text-align: center; padding: 24px 16px; border-radius: 12px; background: linear-gradient(135deg, var(--navy-deep), var(--primary)); color: #fff; border: 2px solid var(--gold); }
.result-big .muted, .result-big div { color: #e8edf6; }
.result-big .subject { color: var(--gold-soft); }
.result-big .subject { font-size: 1.4rem; font-weight: 700; margin: 6px 0; }
.instructions { white-space: pre-line; }
.info-list { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; font-weight: 600; }

/* ---------- SweetAlert2 ---------- */
.swal2-popup { font-family: 'Sarabun', 'Tahoma', sans-serif !important; border-radius: 14px !important; }
.swal2-popup:not(.swal2-toast) { border-top: 5px solid var(--gold) !important; }
.swal2-title { color: var(--navy-deep) !important; }
.swal2-html-container ol { text-align: left; margin: 8px 0 0; padding-left: 22px; }

/* ---------- print ---------- */
@media print {
  body { background: #fff; font-size: 14px; }
  .topbar, .no-print, .alert, .site-footer { display: none !important; }
  .container { max-width: none; padding: 0; }
  .card { box-shadow: none; padding: 0; margin: 0; }
  .page-break { page-break-after: always; }
  th { background: #eee !important; color: #000 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  th, td { border: 1px solid #999; padding: 4px 6px; }
}

@media (max-width: 600px) {
  .card { padding: 16px; }
  h1 { font-size: 1.3rem; }
}
