/* ================================================================
   ระบบบันทึกผลการจัดการเรียนรู้ — Modern Professional UI
   ================================================================ */

/* --- Google Fonts (Sarabun สำหรับภาษาไทย) --- */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

/* --- CSS Variables --- */
:root {
  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --primary-light: #eff6ff;
  --success:       #16a34a;
  --success-light: #f0fdf4;
  --danger:        #dc2626;
  --danger-light:  #fef2f2;
  --gray:          #64748b;
  --gray-light:    #f1f5f9;
  --border:        #e2e8f0;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --white:         #ffffff;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:        0 4px 16px rgba(15,23,42,.08);
  --shadow-lg:     0 8px 30px rgba(15,23,42,.12);
  --radius:        14px;
  --radius-sm:     10px;
  --font:          'Sarabun', 'TH Sarabun New', Tahoma, sans-serif;
}

/* ================================================================
   BASE
   ================================================================ */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: var(--font);
  background: #f0f4f8;
  margin: 0;
  color: var(--text);
  font-size: 18px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

h2, h3 { margin: 0 0 4px 0; font-weight: 700; color: var(--text); }
p { margin: 0 0 8px 0; }

/* ================================================================
   LAYOUT
   ================================================================ */
.wrap {
  max-width: 1100px;
  margin: 28px auto;
  padding: 0 20px;
}

/* ================================================================
   CARD
   ================================================================ */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
  border: 1px solid rgba(226,232,240,.6);
}

/* ================================================================
   TOP BAR (index header)
   ================================================================ */
.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.top h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.3px;
}

.top .muted {
  color: var(--text-muted);
  font-size: 15px;
  margin-top: 2px;
}

/* ================================================================
   BUTTONS
   ================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: var(--white);
  text-decoration: none;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 16px;
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .1s;
  white-space: nowrap;
  letter-spacing: .1px;
  box-shadow: 0 1px 3px rgba(37,99,235,.25);
}
.btn:hover {
  background: var(--primary-dark);
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(37,99,235,.35);
  transform: translateY(-1px);
}
.btn:active { transform: translateY(0); }

.btn.gray  { background: var(--gray); box-shadow: 0 1px 3px rgba(100,116,139,.2); }
.btn.gray:hover  { background: #475569; box-shadow: 0 4px 10px rgba(71,85,105,.3); }
.btn.green { background: var(--success); box-shadow: 0 1px 3px rgba(22,163,74,.2); }
.btn.green:hover { background: #15803d; box-shadow: 0 4px 10px rgba(22,163,74,.3); }
.btn.red   { background: var(--danger); box-shadow: 0 1px 3px rgba(220,38,38,.2); }
.btn.red:hover   { background: #b91c1c; box-shadow: 0 4px 10px rgba(220,38,38,.3); }
.btn.full  { width: 100%; justify-content: center; }

/* ================================================================
   TABLE
   ================================================================ */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  font-size: 17px;
}
th, td {
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
  text-align: left;
}
th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
tbody tr:hover { background: #fafbfd; }
tbody tr:last-child td { border-bottom: 0; }

/* ================================================================
   FORM INPUTS
   ================================================================ */
input, textarea, select {
  width: 100%;
  box-sizing: border-box;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-family: var(--font);
  font-size: 17px;
  background: var(--white);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
input::placeholder { color: #aab4c2; }
textarea { min-height: 72px; resize: vertical; }

.label {
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text);
  font-size: 15px;
}

/* ================================================================
   GRIDS
   ================================================================ */
.grid  { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }

/* ================================================================
   CHECKBOX LINE
   ================================================================ */
.checkline {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 8px 0;
}
.checkline input { width: auto; }

/* ================================================================
   MISC
   ================================================================ */
.muted  { color: var(--text-muted); }
.center { text-align: center; }

/* ================================================================
   TOP ACTIONS
   ================================================================ */
.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ================================================================
   LOGIN PAGE
   ================================================================ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(37,99,235,.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(99,102,241,.06) 0%, transparent 50%),
    #f0f4f8;
}

.login-card {
  width: 420px;
  max-width: 100%;
  border-radius: 20px;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(226,232,240,.8);
  padding: 36px 32px 32px;
  background: var(--white);
  border: none;
  margin-bottom: 0;
}

/* Brand badge atop login */
.login-card::before {
  content: '';
  display: block;
  width: 48px;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: 2px;
  margin-bottom: 20px;
}

.login-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}

.login-card .muted {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 20px;
}

.alert {
  background: var(--danger-light);
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  margin: 0 0 16px 0;
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert::before { content: '⚠'; font-size: 16px; }

/* Login input group spacing */
.login-card .label { margin-top: 14px; margin-bottom: 5px; }
.login-card input { margin-bottom: 0; }

.login-term {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}
.login-term input { width: 100%; box-sizing: border-box; }

/* Remember me box */
.remember-box {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 16px;
  padding: 13px 14px;
  border: 1.5px solid #dbeafe;
  border-radius: var(--radius-sm);
  background: #eff6ff;
  color: #1e40af;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.remember-box:hover { background: #dbeafe; border-color: #93c5fd; }
.remember-box input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--primary);
  flex-shrink: 0;
  cursor: pointer;
}
.remember-box b { font-weight: 600; font-size: 15px; }
.remember-box small { color: #3b82f6; font-size: 13px; font-weight: 400; display: block; margin-top: 2px; }

/* Login submit button */
.login-card .btn.full {
  margin-top: 18px;
  padding: 12px 18px;
  font-size: 17px;
  border-radius: var(--radius-sm);
  letter-spacing: .2px;
}

/* ================================================================
   TERM / CHIP NAV
   ================================================================ */
.term-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.chips {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.chip {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  border: 1.5px solid var(--border);
  transition: background .15s, border-color .15s, color .15s;
}
.chip:hover { background: #e0e7ff; border-color: #c7d2fe; color: var(--primary-dark); text-decoration: none; }
.chip.active { background: var(--primary); color: var(--white); border-color: var(--primary); box-shadow: 0 2px 8px rgba(37,99,235,.25); }

/* ================================================================
   INFO BOX (form.php)
   ================================================================ */
.info-box {
  background: #eff6ff;
  border: 1.5px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  margin: 10px 0 16px 0;
  color: #1e40af;
  font-size: 15px;
}

/* ================================================================
   PRINT PAGE (screen preview)
   ================================================================ */
.print-page {
  background: var(--white);
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  padding: 12mm;
  box-sizing: border-box;
  font-size: 20px;
}

.line {
  border-bottom: 1px dotted #333;
  min-width: 90px;
  display: inline-block;
  padding: 0 5px;
}

.signature {
  display: flex;
  justify-content: space-between;
  margin-top: 18px;
}
.signature > div { width: 32%; text-align: center; }

/* ================================================================
   OFFICIAL PRINT TEMPLATE
   ================================================================ */
.print-body {
  background: #fff !important;
  color: #000 !important;
  font-family: "TH Sarabun New", "TH SarabunPSK", Tahoma, sans-serif !important;
  font-size: 20px !important;
  line-height: 1.2 !important;
}

.print-toolbar {
  position: sticky;
  top: 0;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  padding: 10px;
  text-align: center;
  z-index: 10;
}

.official-page {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  background: #fff;
  box-sizing: border-box;
  padding: 10mm 14mm 10mm 14mm;
  font-family: "TH Sarabun New", "TH SarabunPSK", Tahoma, sans-serif;
  font-size: 20px;
  line-height: 1.2;
  color: #000;
}

.official-header-box {
  border: 2px solid #111;
  padding: 9px 14px 10px 14px;
  margin: 0 auto 14px auto;
  width: 174mm;
  box-sizing: border-box;
}

.official-title {
  text-align: center;
  font-weight: bold;
  font-size: 25px;
  margin: 0 0 6px 0;
}

.header-row {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  margin: 5px 0;
  overflow: hidden;
}
.header-row-last { margin-bottom: 0; }
.ml-gap { margin-left: 8mm; }

.dotline {
  display: inline-block;
  border-bottom: 1.6px dotted #222;
  min-height: 18px;
  line-height: 18px;
  text-align: center;
  padding: 0 2px;
  vertical-align: bottom;
  white-space: nowrap;
  overflow: hidden;
}
.w-code    { width: 25mm; }
.w-subject { width: 76mm; text-align: left; }
.w-credit  { width: 17mm; }
.w-unit    { width: 16mm; }
.w-topic   { width: 122mm; text-align: left; }
.w-hour    { width: 20mm; }
.w-period  { width: 24mm; }
.w-week    { width: 18mm; }

.section       { margin-top: 8px; }
.first-section { margin-top: 0; }
.sec-title {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 20px;
  margin: 0 0 3px 0;
}
.sec-title b    { font-weight: bold; }
.inline-title   { white-space: nowrap; flex-wrap: nowrap; }

.check-row {
  position: relative;
  display: block;
  padding-left: 6mm;
  margin: 3px 0;
  font-size: 20px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
}
.indent { margin-left: 14mm; }

.print-check {
  position: absolute;
  left: 0; top: 0.6mm;
  width: 4mm; height: 4mm;
  border: 1.3px solid #000;
  box-sizing: border-box;
  display: inline-block;
  text-align: center;
  font-size: 0;
  line-height: 0;
}
.print-check.checked::after {
  content: "✓";
  position: absolute;
  left: 0; top: -0.5mm;
  width: 4mm; height: 4mm;
  line-height: 4mm;
  text-align: center;
  font-size: 13px;
  font-family: Arial, Tahoma, sans-serif;
  font-weight: bold;
  color: #000;
}

.w-reason   { width: 58mm; text-align: left; }
.w-total    { width: 18mm; }
.w-long     { width: 120mm; text-align: left; }
.w-suggest  { width: 96mm; text-align: left; }
.w-suggest2 { width: 92mm; text-align: left; }
.w-count    { width: 26mm; }
.w-percent  { width: 30mm; }
.blank-dot-line {
  border-bottom: 1.6px dotted #222;
  width: 128mm;
  margin-left: 32mm;
  height: 16px;
  display: block;
}

.assessment-row {
  display: flex !important;
  align-items: baseline !important;
  white-space: nowrap !important;
  overflow: visible !important;
  padding-left: 0 !important;
}
.assessment-row .print-check {
  position: static !important;
  display: inline-block !important;
  vertical-align: middle !important;
  flex: 0 0 auto;
  margin-right: 2mm;
  width: 4mm !important; height: 4mm !important;
  line-height: 0 !important; font-size: 0 !important;
}
.assessment-row .print-check.checked::after {
  position: static !important;
  display: inline-block !important;
  width: 4mm; height: 4mm;
  line-height: 4mm;
  font-size: 13px;
  font-family: Arial, Tahoma, sans-serif;
  font-weight: bold;
  color: #000;
}
.assessment-label { flex: 0 0 auto; white-space: nowrap; margin-right: 2mm; }
.assessment-row .w-count { flex: 0 0 26mm; min-width: 26mm; }
.assessment-row > span.คน { flex: 0 0 auto; margin: 0 1mm; }
.percent-label { flex: 0 0 auto; white-space: nowrap; margin-left: 3mm; margin-right: 2mm; }
.assessment-row .w-percent { flex: 0 0 30mm; min-width: 30mm; }

.teacher-sign {
  width: 83mm;
  margin-left: auto;
  margin-top: 10px;
  text-align: center;
  font-size: 20px;
}
.w-sign     { width: 48mm; }
.name-line  { margin-top: 4px; min-height: 18px; }
.dash-sep   { border-top: 2px dashed #222; margin: 10px 0; }
.approve-block  { font-size: 20px; }
.approve-title  { font-weight: bold; margin-bottom: 6px; }
.dept-sign      { text-align: center; margin-top: 22px; }
.w-deptsign     { width: 54mm; }
.bottom-sep     { margin-top: 12px; }
.bottom-signs   { display: flex; justify-content: space-between; margin-top: 24px; font-size: 20px; }
.bottom-sign-box { width: 86mm; text-align: center; }
.w-bottomsign   { width: 58mm; }

/* subject-row */
.subject-row {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  width: 100%;
}
.subject-row .w-code   { flex: 0 0 23mm; width: 23mm; }
.subject-row .w-subject { flex: 1 1 auto; width: auto; min-width: 70mm; text-align: left; padding-left: 4px; }
.subject-row .credit-label { flex: 0 0 auto; margin-left: 3mm; white-space: nowrap; }
.subject-row .w-credit { flex: 0 0 18mm; width: 18mm; text-align: center; }

/* ================================================================
   PRINT MEDIA — ห้ามแก้ไข
   ================================================================ */
@page { size: A4 portrait; margin: 0; }

@media print {
  html, body {
    width: 210mm; height: 297mm;
    margin: 0 !important; padding: 0 !important;
    background: #fff !important;
  }
  body { background: #fff; }
  .no-print { display: none !important; }
  .official-page {
    margin: 0 !important;
    width: 210mm;
    min-height: 297mm;
    padding: 10mm 14mm 10mm 14mm !important;
    box-shadow: none !important;
    page-break-after: always;
    break-after: page;
  }
  .official-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }
  .official-header-box, .section, .approve-block, .bottom-signs { break-inside: avoid; }
  .dotline, .blank-dot-line {
    border-bottom: 1.6px dotted #222 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .dash-sep { border-top: 2px dashed #222 !important; }
  .print-check {
    border: 1.3px solid #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .print-check.checked::after { color: #000 !important; }
  .check-row { white-space: nowrap !important; overflow: hidden !important; }
  .assessment-row { display: flex !important; overflow: visible !important; padding-left: 0 !important; }
  .assessment-row .print-check { position: static !important; display: inline-block !important; }
  .card { box-shadow: none; border-radius: 0; }
  .wrap { max-width: none; margin: 0; padding: 0; }
  .print-page { box-shadow: none; margin: 0; padding: 9mm; width: auto; min-height: auto; }
}

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 800px) {
  .grid, .grid2    { grid-template-columns: 1fr; }
  .top             { display: block; }
  .top-actions     { justify-content: flex-start; margin-top: 12px; }
}

@media (max-width: 640px) {
  .login-term      { grid-template-columns: 1fr; }
  .login-card      { padding: 28px 20px 24px; }
  .wrap            { padding: 0 14px; }
  .card            { padding: 18px 16px; }
}
