/* =====================================================================
   ระบบแฟ้มสะสมผลงานนักเรียน — สไตล์มินิมอล โทนสีน้ำเงินตามรูปตัวอย่าง
   ===================================================================== */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Thai:wght@300;400;500;600;700&display=swap');

:root {
  /* โทนสีจากรูป (น้ำเงินเข้มสุด -> ฟ้าอ่อนสุด) */
  --navy:      #0d47a1;   /* จากรูป 988 น้ำเงินเข้ม */
  --blue:      #1e88e5;   /* น้ำเงินสด */
  --blue-mid:  #90caf9;   /* ฟ้ากลาง */
  --blue-soft: #e3f2fd;   /* ฟ้าอ่อนมาก (พื้นหลัง) */
  --slate:     #35576f;   /* จากรูป 990 น้ำเงินอมเทา */
  --slate-mid: #7aa8cc;
  --sky:       #9dd4ff;
  --cream:     #f6f7f0;   /* ครีมอ่อนจากรูป 990 */

  --ink:       #1b2430;
  --muted:     #5b6b7b;
  --line:      #e2e8f0;
  --white:     #ffffff;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 2px 10px rgba(13, 71, 161, .08);
  --shadow-lg: 0 8px 30px rgba(13, 71, 161, .12);
  --font: 'IBM Plex Sans Thai', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-weight: 400;
  color: var(--ink);
  background: var(--blue-soft);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  /* จัด layout ให้ footer ชิดล่างเสมอ (sticky footer) */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
/* ให้ส่วนเนื้อหาหลักดันฟุตเตอร์ลงล่างเมื่อเนื้อหาสั้น */
body > .section:last-of-type,
body > .container { }
.site-footer { margin-top: auto; }

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

.container { max-width: 1140px; margin: 0 auto; padding: 0 20px; }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--navy);
  color: #cfe4ff;
  font-size: .82rem;
}
.topbar .container {
  display: flex; justify-content: space-between; align-items: center;
  height: 38px;
}
.topbar a { color: #fff; font-weight: 500; }

/* ---------- Header / Nav ---------- */
.site-header {
  background: var(--white);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50;
}
.site-header .container {
  display: flex; align-items: center; justify-content: space-between;
  height: 68px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  width: 42px; height: 42px; border-radius: 10px;
  background: linear-gradient(135deg, var(--navy), var(--blue));
  color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 1.1rem;
}
.brand b { font-size: 1.02rem; font-weight: 600; color: var(--ink); display: block; }
.brand span { font-size: .76rem; color: var(--muted); font-weight: 300; }

.nav { display: flex; gap: 4px; align-items: center; }
.nav a {
  color: var(--ink); font-size: .9rem; font-weight: 500;
  padding: 8px 14px; border-radius: 8px; text-decoration: none;
}
.nav a:hover { background: var(--blue-soft); color: var(--navy); }
.nav a.active { background: var(--navy); color: #fff; }
.burger { display: none; font-size: 1.6rem; line-height: 1; background: none; border: 0;
  color: var(--navy); cursor: pointer; padding: 4px 8px; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 9px; border: 0;
  font-family: var(--font); font-weight: 600; font-size: .9rem;
  cursor: pointer; text-decoration: none; transition: .15s;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--navy); text-decoration: none; }
.btn-ghost { background: var(--blue-soft); color: var(--navy); }
.btn-ghost:hover { background: var(--blue-mid); text-decoration: none; }
.btn-slate { background: var(--slate); color: #fff; }
.btn-slate:hover { background: #294455; text-decoration: none; }
.btn-danger { background: #e53935; color: #fff; }
.btn-sm { padding: 6px 12px; font-size: .82rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(135deg, var(--navy) 0%, var(--blue) 55%, var(--slate-mid) 100%);
  color: #fff; padding: 60px 0;
}
.hero .container { max-width: 780px; text-align: center; }
.hero .kicker {
  display: inline-block; background: rgba(255,255,255,.15);
  padding: 5px 14px; border-radius: 20px; font-size: .8rem; margin-bottom: 16px;
}
.hero h1 { font-size: 2.4rem; font-weight: 700; margin-bottom: 12px; letter-spacing: -.5px; }
.hero p { font-size: 1.05rem; font-weight: 300; opacity: .95; margin-bottom: 26px; }
.hero .actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------- Sections ---------- */
.section { padding: 46px 0; }
.section-label {
  color: var(--blue); font-weight: 600; font-size: .82rem;
  letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px;
}
.section h2 { font-size: 1.6rem; font-weight: 600; margin-bottom: 6px; }
.section .lead { color: var(--muted); font-weight: 300; margin-bottom: 26px; }

/* ---------- Cards grid ---------- */
.grid { display: grid; gap: 18px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.card {
  background: var(--white); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
  transition: .18s;
}
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.card .tag {
  display: inline-block; background: var(--blue-soft); color: var(--navy);
  font-size: .74rem; font-weight: 600; padding: 3px 10px; border-radius: 20px; margin-bottom: 10px;
}
.card h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: 6px; }
.card p { color: var(--muted); font-size: .9rem; font-weight: 300; }

/* ---------- Stat cards ---------- */
.stat {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; text-align: center; box-shadow: var(--shadow);
}
.stat .num { font-size: 2rem; font-weight: 700; color: var(--navy); }
.stat .lbl { color: var(--muted); font-size: .86rem; font-weight: 300; }

/* ---------- Forms ---------- */
.form-card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; box-shadow: var(--shadow); max-width: 100%;
}
.form-row { display: grid; gap: 16px; margin-bottom: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.field label {
  display: block; font-size: .86rem; font-weight: 500; margin-bottom: 6px; color: var(--ink);
}
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-family: var(--font); font-size: .92rem;
  background: #fbfcfe; transition: .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--blue); background: #fff;
  box-shadow: 0 0 0 3px rgba(30,136,229,.12);
}
.field textarea { resize: vertical; min-height: 80px; }
.fieldset-title {
  font-weight: 600; color: var(--navy); font-size: 1rem;
  margin: 26px 0 14px; padding-bottom: 8px; border-bottom: 2px solid var(--blue-soft);
}
.fieldset-title:first-child { margin-top: 0; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, var(--navy), var(--slate)); }
.auth-box {
  background: #fff; border-radius: 18px; padding: 36px; width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.auth-box h1 { font-size: 1.4rem; text-align: center; margin-bottom: 4px; }
.auth-box .sub { text-align: center; color: var(--muted); font-size: .88rem; margin-bottom: 24px; font-weight: 300; }

/* ---------- Table ---------- */
.table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th { background: var(--navy); color: #fff; font-weight: 500; font-size: .85rem; padding: 12px 14px; text-align: left; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: .9rem; }
.table tr:hover td { background: var(--blue-soft); }

/* ---------- Alert ---------- */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 18px; font-size: .9rem; }
.alert-ok { background: #e6f4ea; color: #1b5e20; border: 1px solid #a5d6a7; }
.alert-err { background: #fdecea; color: #b71c1c; border: 1px solid #ef9a9a; }
.alert-info { background: var(--blue-soft); color: var(--navy); border: 1px solid var(--blue-mid); }

/* ---------- Term pills ---------- */
.term-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; }
.term-tabs a {
  padding: 8px 16px; border-radius: 20px; background: #fff; border: 1px solid var(--line);
  font-size: .86rem; font-weight: 500; color: var(--muted); text-decoration: none;
}
.term-tabs a.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.term-tabs a.open::after { content: '● เปิด'; color: #2e7d32; font-size: .7rem; margin-left: 6px; }

/* ---------- Footer ---------- */
.site-footer { background: var(--navy); color: #cfe0f5; padding: 22px 0; margin-top: auto; }
.site-footer .copy { font-size: .8rem; text-align: center; }

/* ---------- Profile view ---------- */
.profile-head { display: flex; gap: 24px; align-items: center; }
.profile-photo {
  width: 120px; height: 150px; border-radius: 10px; object-fit: cover;
  border: 3px solid var(--white); box-shadow: var(--shadow); background: var(--blue-soft);
}
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 30px; }
.info-item { display: flex; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: .92rem; }
.info-item .k { color: var(--muted); min-width: 140px; font-weight: 300; }
.info-item .v { font-weight: 500; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .container { padding: 0 14px; }
  .grid-3, .grid-4, .grid-2 { grid-template-columns: 1fr; }
  .form-row.cols-2, .form-row.cols-3 { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr; }
  .site-footer .cols { grid-template-columns: 1fr; }

  .hero { padding: 40px 0; }
  .hero h1 { font-size: 1.7rem; }
  .hero p { font-size: .96rem; }
  .section { padding: 32px 0; }
  .section h2 { font-size: 1.35rem; }
  .profile-head { flex-direction: column; text-align: center; }
  .form-card { padding: 18px; }

  /* hamburger dropdown nav */
  .burger { display: block; }
  .site-header .container { position: relative; }
  .nav {
    display: none; position: absolute; top: 68px; left: 0; right: 0;
    background: #fff; flex-direction: column; gap: 2px; padding: 8px;
    box-shadow: var(--shadow-lg); border-bottom: 1px solid var(--line); z-index: 60;
  }
  .nav.open { display: flex; }
  .nav a { padding: 12px 14px; font-size: .95rem; }

  /* tables scroll horizontally on small screens */
  .table { display: block; overflow-x: auto; white-space: nowrap; }
}
/* touch-friendly tap targets */
@media (max-width: 760px) {
  .btn { padding: 12px 18px; }
  .btn-sm { padding: 8px 13px; }
  .field input, .field select, .field textarea { font-size: 16px; } /* กัน iOS ซูมอัตโนมัติ */
}

/* ---------- Gallery (รูปกิจกรรม/เกียรติบัตร/ผลงาน) ---------- */
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 760px) { .gallery { grid-template-columns: repeat(2, 1fr); } }
.gallery-item {
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
  background: #fff; box-shadow: var(--shadow);
}
.gallery-item .thumb {
  width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block;
  background: linear-gradient(135deg, var(--blue-soft), var(--blue-mid));
}
.gallery-item .meta { padding: 11px 13px; }
.gallery-item .meta .k-type {
  font-size: .7rem; font-weight: 600; color: var(--blue);
  text-transform: uppercase; letter-spacing: .5px;
}
.gallery-item .meta b { display: block; font-size: .92rem; margin: 2px 0; }
.gallery-item .meta p { font-size: .8rem; color: var(--muted); font-weight: 300; }
.gallery-item .meta .del { margin-top: 8px; }

/* print gallery: 2 คอลัมน์ต่อแถว มีรูป+รายละเอียด */
.print-gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.print-gallery .pg-card { border: 1px solid #bbb; border-radius: 8px; overflow: hidden; page-break-inside: avoid; }
.print-gallery .pg-card img { width: 100%; height: 150px; object-fit: cover; display: block; }
.print-gallery .pg-card .cap { padding: 8px 10px; font-size: 11.5px; }
.print-gallery .pg-card .cap b { display: block; margin-bottom: 2px; }

/* =====================================================================
   สไตล์สำหรับพิมพ์ (print) — A4, ขาวสะอาด
   ===================================================================== */
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; font-size: 12px; }
  .topbar, .site-header, .site-footer, .no-print, .btn, .nav, .term-tabs { display: none !important; }
  .container { max-width: 100%; padding: 0; }
  .card, .form-card, .table { box-shadow: none; border: 1px solid #999; }
  .print-header { display: block !important; text-align: center; margin-bottom: 16px; border-bottom: 2px solid #000; padding-bottom: 10px; }
  .fieldset-title { border-color: #000; }
  a { color: #000; text-decoration: none; }
  .profile-photo { border-color: #ccc; }
}
.print-header { display: none; }

/* =====================================================================
   EduCare Hub — เช็คชื่อโฮมรูม / สถิติ
   ===================================================================== */
.form-row.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .form-row.cols-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .form-row.cols-4 { grid-template-columns: 1fr; } }

/* ตารางเช็คชื่อ */
.att-table td { vertical-align: middle; }
.att-table tr:hover td { background: #f7fafd; }

/* ปุ่มเลือกสถานะแบบ pill (radio ซ่อน) */
.status-pick { display: flex; gap: 4px; flex-wrap: wrap; }
.status-pick label { position: relative; cursor: pointer; user-select: none; }
.status-pick label input { position: absolute; opacity: 0; width: 0; height: 0; }
.status-pick label span {
  display: inline-block; padding: 6px 12px; border: 1.5px solid var(--line);
  border-radius: 16px; font-size: .84rem; color: var(--muted); transition: .12s; background: #fff;
}
.status-pick label:hover span { border-color: var(--c); color: var(--c); }
.status-pick label input:checked + span {
  background: var(--c); border-color: var(--c); color: #fff; font-weight: 600;
}
.status-pick label input:focus-visible + span { box-shadow: 0 0 0 3px rgba(30,136,229,.25); }

@media (max-width: 760px) {
  .att-table .status-pick label span { padding: 8px 12px; font-size: .9rem; }
}

/* ---------- Modal / ป็อปอัป ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(13, 25, 45, .55);
  display: none; align-items: flex-start; justify-content: center;
  z-index: 200; padding: 30px 16px; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 640px; padding: 26px 26px 24px; position: relative;
  animation: modalpop .16s ease; margin: auto 0;
}
.modal.modal-sm { max-width: 460px; }
@keyframes modalpop { from { transform: translateY(-10px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal .modal-close {
  position: absolute; top: 10px; right: 14px; border: 0; background: none;
  font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px;
}
.modal .modal-close:hover { color: var(--ink); }
.modal .fieldset-title:first-child { margin-top: 0; }
body.modal-open { overflow: hidden; }
@media (max-width: 760px) { .modal { padding: 20px 16px; } }

/* ---------- Nav dropdown (แยกงานแนะแนว / งานดูแล) ---------- */
.menu { position: relative; }
.menu-toggle {
  font-family: var(--font); color: var(--ink); font-size: .9rem; font-weight: 500;
  padding: 8px 14px; border-radius: 8px; background: none; border: 0; cursor: pointer;
}
.menu-toggle:hover { background: var(--blue-soft); color: var(--navy); }
.submenu {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; min-width: 200px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 70;
}
.menu.open .submenu { display: block; }
.submenu a { display: block; padding: 9px 12px; border-radius: 7px; font-size: .9rem; color: var(--ink); }
.submenu a:hover { background: var(--blue-soft); color: var(--navy); text-decoration: none; }
.submenu a.active { background: var(--navy); color: #fff; }

/* ---------- Bottom nav (มือถือ) ---------- */
.bottomnav { display: none; }
body.has-bottomnav { padding-bottom: 0; }

@media (max-width: 760px) {
  /* เมนูใน hamburger: submenu แสดงแบบ inline + แบ่งกลุ่มชัด */
  .nav { gap: 0; padding: 6px 8px 10px; border-radius: 0 0 14px 14px; }
  .nav > a { border-radius: 8px; }
  .menu { width: 100%; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 4px; }
  .menu-toggle {
    width: 100%; text-align: left; font-weight: 600; color: var(--navy);
    display: flex; justify-content: space-between; align-items: center;
  }
  .menu .submenu { position: static; display: block; box-shadow: none; border: 0; padding: 2px 0 4px 10px; min-width: 0; }
  .menu .submenu a { color: var(--muted); font-weight: 500; }
  .menu .submenu a.active { color: #fff; }
  .menu:not(.open) .submenu { display: none; }

  .bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 90;
    background: #fff; border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom, 0);
    box-shadow: 0 -2px 12px rgba(13,71,161,.08);
  }
  .bottomnav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 8px 4px 7px; font-size: .68rem; color: var(--muted); text-decoration: none;
  }
  .bottomnav a .bn-i { font-size: 1.25rem; line-height: 1; }
  .bottomnav a.active { color: var(--navy); font-weight: 600; }
  .bottomnav a.active .bn-i { transform: translateY(-1px); }
  body.has-bottomnav { padding-bottom: 60px; }
}

/* ---------- Behavior score ---------- */
.score-badge {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-width: 54px; padding: 4px 10px; border-radius: 20px; font-weight: 700; font-size: .95rem; color: #fff;
}
.score-ring {
  --p: 100; --c: #2e7d32;
  width: 120px; height: 120px; border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), #eef2f7 0);
  display: grid; place-items: center;
}
.score-ring .inner {
  width: 92px; height: 92px; border-radius: 50%; background: #fff;
  display: grid; place-items: center; text-align: center;
}
.score-ring .inner b { font-size: 1.8rem; color: var(--ink); line-height: 1; }
.score-ring .inner span { font-size: .72rem; color: var(--muted); }

/* ---------- Sub-tabs (ใช้ซ้ำ term-tabs) ---------- */
.chip { display:inline-block; padding:2px 10px; border-radius:12px; font-size:.74rem; font-weight:600; }

/* ---------- Behavior preset chips (ครูกดเลือก) ---------- */
.preset-wrap { display:flex; flex-direction:column; gap:6px; max-height:240px; overflow-y:auto; padding-right:2px; }
.preset-chip {
  display:flex; align-items:center; justify-content:space-between; gap:10px; width:100%;
  padding:9px 12px; border-radius:10px; border:1.5px solid var(--line); background:#fff;
  font-family:var(--font); font-size:.9rem; cursor:pointer; text-align:left; transition:.12s;
}
.preset-chip span { flex:1; }
.preset-chip b { font-weight:700; padding:1px 8px; border-radius:10px; color:#fff; font-size:.82rem; }
.preset-chip.pos b { background:#2e7d32; }
.preset-chip.neg b { background:#e53935; }
.preset-chip.pos:hover { border-color:#2e7d32; background:#f2faf3; }
.preset-chip.neg:hover { border-color:#e53935; background:#fdf3f3; }
.preset-chip.sel { border-color:var(--navy); box-shadow:0 0 0 2px rgba(13,71,161,.18); background:var(--blue-soft); }

/* ---------- Ticket thread ---------- */
.bubble { border:1px solid var(--line); border-radius:12px; padding:12px 14px; margin-bottom:10px; background:#fff; }
.bubble.staff { background: var(--blue-soft); border-color: var(--blue-mid); }
.bubble .who { font-size:.78rem; color:var(--muted); margin-bottom:4px; }
