/* =====================================================
   คลังภาพกิจกรรมโรงเรียน — ธีมสว่าง สะอาด ทางการ
   ===================================================== */
:root {
  --bg: #F5F7FB;
  --surface: #FFFFFF;
  --navy: #1C4B8E;        /* สีหลักของสถาบัน — ปรับตามสีโรงเรียนได้ */
  --navy-dark: #133765;
  --navy-soft: #E8EFF9;
  --gold: #C9A227;        /* ใช้เน้นจุดสำคัญเท่านั้น เช่น วันนี้ในปฏิทิน */
  --text: #1E2733;
  --muted: #64748B;
  --border: #E2E8F2;
  --danger: #C0392B;
  --success: #1E7B4F;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 45, 90, .06), 0 4px 14px rgba(20, 45, 90, .05);
}

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

body {
  font-family: 'IBM Plex Sans Thai', 'Sarabun', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.container { max-width: 1120px; margin: 0 auto; padding: 0 16px; }

/* สำคัญ: element ที่มี attribute hidden ต้องถูกซ่อนจริงเสมอ
   (กัน element ที่ตั้ง display อื่นมาทับ hidden แล้วโผล่ตอนโหลด) */
[hidden] { display: none !important; }

/* ---------- ส่วนหัว ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.site-header .container {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 14px; padding-bottom: 14px; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.brand h1 { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand p { font-size: 12.5px; color: var(--muted); }
.admin-link {
  font-size: 13.5px; color: var(--navy); text-decoration: none;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 16px; white-space: nowrap; transition: background .15s;
}
.admin-link:hover { background: var(--navy-soft); }

/* ---------- แถบเครื่องมือ ---------- */
.toolbar { padding: 22px 0 6px; }
.search-box { position: relative; margin-bottom: 14px; }
.search-box input {
  width: 100%; padding: 12px 16px 12px 44px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font: inherit; font-size: 15px; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.search-box input:focus {
  outline: none; border-color: var(--navy);
  box-shadow: 0 0 0 3px var(--navy-soft);
}
.search-box .icon {
  position: absolute; left: 15px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 17px;
}

.filter-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; flex: 1; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  font-size: 13.5px; padding: 6px 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); cursor: pointer; white-space: nowrap;
  font-family: inherit; transition: all .15s;
}
.chip:hover { border-color: var(--navy); color: var(--navy); }
.chip.active { background: var(--navy); border-color: var(--navy); color: #fff; }

select.year-select {
  font: inherit; font-size: 13.5px; color: var(--text);
  padding: 7px 12px; border: 1px solid var(--border);
  border-radius: 999px; background: var(--surface); cursor: pointer;
}

/* ---------- ปุ่มสลับมุมมอง ---------- */
.view-toggle {
  display: inline-flex; gap: 4px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px;
}
.view-toggle button {
  font: inherit; font-size: 13.5px; padding: 6px 16px;
  border: none; border-radius: 999px; background: transparent;
  color: var(--muted); cursor: pointer; transition: all .15s;
  display: flex; align-items: center; gap: 6px;
}
.view-toggle button.active { background: var(--navy); color: #fff; }

/* ---------- กริดอัลบั้ม ---------- */
.album-grid {
  display: grid; gap: 16px; padding: 18px 0 24px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.album-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  box-shadow: var(--shadow); transition: transform .18s, box-shadow .18s;
  display: flex; flex-direction: column;
}
.album-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 22px rgba(20, 45, 90, .12);
}
.album-card:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
.cover {
  position: relative; aspect-ratio: 16 / 10;
  background: var(--navy-soft); overflow: hidden;
}
.cover .slide {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover; display: block;
  opacity: 0; transition: opacity .5s ease;
}
.cover .slide.active { opacity: 1; }
.album-card:hover .cover .slide.active { transform: scale(1.04); transition: opacity .5s ease, transform .3s; }
.cover-empty {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 30px; opacity: .5;
}
.cover-dots {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 5px; z-index: 2;
  opacity: 0; transition: opacity .2s;
}
.album-card:hover .cover-dots { opacity: 1; }
.cover-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(255, 255, 255, .55);
  box-shadow: 0 0 2px rgba(0, 0, 0, .4); transition: background .2s;
}
.cover-dots span.on { background: #fff; }
.count-badge {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  background: rgba(255, 255, 255, .92); color: var(--text);
  font-size: 12px; font-weight: 500;
  padding: 3px 10px; border-radius: 999px;
}
.card-body { padding: 12px 14px 14px; flex: 1; }
.card-body h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.card-meta { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cat-tag {
  font-size: 11.5px; background: var(--navy-soft); color: var(--navy);
  padding: 2px 9px; border-radius: 999px;
}
.open-link {
  font-size: 13px; color: var(--navy); margin-top: 8px;
  display: inline-flex; align-items: center; gap: 5px;
}

/* ---------- โครงกระดูกตอนโหลด ---------- */
.skeleton { animation: pulse 1.4s ease-in-out infinite; }
.skeleton .cover { background: var(--border); }
.skeleton .line {
  height: 13px; border-radius: 6px; background: var(--border); margin: 10px 14px;
}
.skeleton .line.short { width: 45%; }
@keyframes pulse { 50% { opacity: .55; } }

/* ---------- ปฏิทิน ---------- */
.calendar-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin: 18px 0 40px;
}
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 8px;
}
.cal-title { font-size: 16px; font-weight: 600; }
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-nav button {
  font: inherit; font-size: 13px; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: background .15s;
}
.cal-nav button:hover { background: var(--navy-soft); }
.cal-dow, .cal-grid {
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px;
}
.cal-dow span {
  text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0;
}
.cal-day {
  min-height: 58px; text-align: center; padding: 8px 2px 6px;
  border-radius: 10px; border: 1px solid transparent;
  font-size: 13.5px; color: var(--muted); position: relative;
}
.cal-day.has-event {
  background: var(--navy-soft); border-color: #CBDCF2;
  color: var(--text); font-weight: 500; cursor: pointer;
  transition: transform .12s;
}
.cal-day.has-event:hover { transform: scale(1.05); }
.cal-day.selected { border-color: var(--navy); background: var(--navy); color: #fff; }
.cal-day.selected .dot { background: #fff; }
.cal-day.today .num {
  display: inline-flex; width: 24px; height: 24px; border-radius: 50%;
  align-items: center; justify-content: center;
  border: 2px solid var(--gold);
}
.dots { display: flex; gap: 3px; justify-content: center; margin-top: 4px; height: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--navy); }
.dot.more { width: auto; height: auto; background: none; font-size: 10px; line-height: 6px; color: var(--navy); }

.day-panel { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 14px; }
.day-panel h4 { font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.day-panel .hint { font-size: 13px; color: var(--muted); }
.day-album {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px; cursor: pointer;
  transition: background .15s;
}
.day-album:hover { background: var(--navy-soft); }
.day-album img {
  width: 56px; height: 56px; border-radius: 8px; object-fit: cover;
  background: var(--navy-soft); flex-shrink: 0;
}
.day-album .info { flex: 1; min-width: 0; }
.day-album .info b { font-size: 14px; font-weight: 600; display: block; }
.day-album .info span { font-size: 12.5px; color: var(--muted); }

/* ---------- สถานะว่าง ---------- */
.empty {
  text-align: center; color: var(--muted); padding: 50px 20px;
  font-size: 14.5px; grid-column: 1 / -1;
}
.empty i { font-size: 34px; display: block; margin-bottom: 10px; opacity: .5; }

/* ---------- ส่วนท้าย ---------- */
.site-footer {
  text-align: center; font-size: 12.5px; color: var(--muted);
  padding: 20px 16px 30px;
}

/* =====================================================
   หน้า Admin
   ===================================================== */
.login-card {
  max-width: 380px; margin: 70px auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 30px 28px;
}
.login-card h2 { font-size: 18px; font-weight: 600; margin-bottom: 4px; text-align: center; }
.login-card .sub { font-size: 13px; color: var(--muted); text-align: center; margin-bottom: 20px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 10px 14px; font: inherit; font-size: 14.5px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  color: var(--text);
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px var(--navy-soft);
}

.btn {
  font: inherit; font-size: 14.5px; font-weight: 500;
  padding: 10px 20px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: all .15s; display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { background: var(--navy-soft); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-dark); }
.btn.danger { color: var(--danger); border-color: #F2CFCA; }
.btn.danger:hover { background: #FBEBE8; }
.btn.block { width: 100%; justify-content: center; }
.btn.sm { font-size: 13px; padding: 6px 12px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: wait; }

.admin-section {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin: 18px 0;
}
.admin-section h3 {
  font-size: 15.5px; font-weight: 600; margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.form-grid .full { grid-column: 1 / -1; }

.album-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 8px;
}
.album-row img {
  width: 52px; height: 52px; border-radius: 8px; object-fit: cover;
  background: var(--navy-soft);
}
.album-row .info { flex: 1; min-width: 160px; }
.album-row .info b { font-size: 14px; display: block; }
.album-row .info span { font-size: 12.5px; color: var(--muted); }
.album-row .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.status-pill {
  font-size: 11.5px; padding: 2px 10px; border-radius: 999px;
}
.status-pill.show { background: #E4F3EB; color: var(--success); }
.status-pill.hide { background: #F4F5F7; color: var(--muted); }

/* ---------- Toast แจ้งเตือน ---------- */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(80px);
  background: var(--navy-dark); color: #fff; font-size: 14px;
  padding: 11px 22px; border-radius: 999px; opacity: 0;
  transition: all .3s; z-index: 100; max-width: 90vw; text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
#toast.error { background: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .album-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card-body h3 { font-size: 13.5px; }
  .brand h1 { font-size: 15px; }
  .cal-day { min-height: 50px; }
  .filter-row { align-items: stretch; flex-direction: column; }
  .view-toggle { align-self: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* =====================================================
   นำเข้าหลายอัลบั้ม (Bulk Import)
   ===================================================== */
.section-hint {
  font-size: 13px; color: var(--muted); margin: -6px 0 14px; line-height: 1.6;
}
.section-hint code {
  background: var(--navy-soft); color: var(--navy);
  padding: 1px 7px; border-radius: 6px; font-size: 12px;
}
.bulk-summary {
  font-size: 13.5px; font-weight: 500; margin: 16px 0 10px;
}
.bulk-head, .bulk-row {
  display: grid;
  grid-template-columns: 56px 1fr 148px 130px 100px;
  gap: 8px; align-items: center;
}
.bulk-head {
  font-size: 12px; color: var(--muted); padding: 0 2px 6px;
}
.bulk-row {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 8px; margin-bottom: 6px;
}
.bulk-row.exists { opacity: .55; background: var(--bg); }
.bulk-row input[type="checkbox"] {
  width: 18px; height: 18px; margin: 0 auto; accent-color: var(--navy); cursor: pointer;
}
.bulk-row input:not([type="checkbox"]) {
  width: 100%; padding: 7px 10px; font: inherit; font-size: 13.5px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); min-width: 0;
}
.bulk-row input:focus {
  outline: none; border-color: var(--navy); box-shadow: 0 0 0 2px var(--navy-soft);
}
#btn-bulk-import { margin-top: 10px; }

@media (max-width: 720px) {
  .bulk-head { display: none; }
  .bulk-row {
    grid-template-columns: 40px 1fr 1fr;
    grid-template-areas: "chk name name" "chk date cat" "chk year year";
  }
  .bulk-row > :nth-child(1) { grid-area: chk; }
  .bulk-row > :nth-child(2) { grid-area: name; }
  .bulk-row > :nth-child(3) { grid-area: date; }
  .bulk-row > :nth-child(4) { grid-area: cat; }
  .bulk-row > :nth-child(5) { grid-area: year; }
}

/* =====================================================
   แบ่งหน้า (Pagination)
   ===================================================== */
.pagination {
  display: flex; align-items: center; justify-content: center;
  flex-wrap: wrap; gap: 6px; padding: 4px 0 40px;
}
.page-btn {
  min-width: 38px; height: 38px; padding: 0 12px;
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.page-btn:hover:not(:disabled) { border-color: var(--navy); color: var(--navy); background: var(--navy-soft); }
.page-btn.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.page-btn:disabled { opacity: .4; cursor: default; }
.page-gap { color: var(--muted); padding: 0 2px; }
.page-info {
  font-size: 13px; color: var(--muted); margin-left: 8px;
  width: 100%; text-align: center; margin-top: 4px;
}
@media (min-width: 560px) {
  .page-info { width: auto; margin-top: 0; }
}

/* =====================================================
   แบนเนอร์รูปเด่นประจำสัปดาห์
   ===================================================== */
#featured-banner { margin: 18px 0 6px; }
.fb-label {
  font-size: 14px; font-weight: 600; color: var(--navy);
  display: flex; align-items: center; gap: 6px; margin-bottom: 10px;
}
.fb-label .ti { color: var(--gold); }
.fb-track {
  display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px;
  scroll-snap-type: x mandatory;
}
.fb-track::-webkit-scrollbar { height: 6px; }
.fb-track::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
.fb-card {
  position: relative; flex: 0 0 auto; width: min(78vw, 340px);
  aspect-ratio: 16 / 8; border-radius: 14px; overflow: hidden;
  cursor: pointer; scroll-snap-align: start; box-shadow: var(--shadow);
}
.fb-card img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s; }
.fb-card:hover img { transform: scale(1.04); }
.fb-info {
  position: absolute; inset: auto 0 0 0; padding: 22px 16px 12px;
  background: linear-gradient(transparent, rgba(15,30,55,.82)); color: #fff;
}
.fb-info b { font-size: 16px; font-weight: 600; display: block; }
.fb-info span { font-size: 12.5px; opacity: .9; }

/* =====================================================
   การ์ด: hint บน cover + แถวปุ่ม + ปุ่มถูกใจ
   ===================================================== */
.cover-hint {
  position: absolute; bottom: 8px; right: 8px; z-index: 2;
  background: rgba(15, 30, 55, .72); color: #fff;
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 4px;
  opacity: 0; transform: translateY(4px); transition: all .18s;
}
.cover[role="button"] { cursor: zoom-in; }
.album-card:hover .cover-hint { opacity: 1; transform: translateY(0); }
.cover:focus-visible { outline: 2px solid var(--navy); outline-offset: -2px; }

.card-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.like-btn {
  display: inline-flex; align-items: center; gap: 5px;
  font: inherit; font-size: 13px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 11px; cursor: pointer; transition: all .15s;
}
.like-btn:hover { border-color: #E4A0A0; color: var(--danger); }
.like-btn.liked { color: var(--danger); border-color: #E4A0A0; background: #FCEEEE; }
.like-btn .ti { font-size: 15px; }
.like-count { font-weight: 500; min-width: 8px; }
.card-link {
  flex: 1; font: inherit; font-size: 13px; color: var(--navy);
  background: var(--navy-soft); border: none; border-radius: 8px;
  padding: 7px 10px; cursor: pointer; text-align: center;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  transition: background .15s;
}
.card-link:hover { background: #DCE8F8; }

.status-pill.featured { background: #FBF3D9; color: #9A7B10; }
.btn.active-star { border-color: var(--gold); color: #9A7B10; }
