/* ================================================================
   สไตล์ชีตระบบ Admin โรงเรียนวัดบุญสัมพันธ์
   โทนสี : ฟ้า–เหลือง (ชุดเดียวกับเว็บไซต์หลัก)
   ฟอนต์ : Prompt (หัวข้อ) / Sarabun (เนื้อหา)
   ================================================================ */

/* ---------- ตัวแปรสีหลัก (ชุดเดียวกับ style.css ของเว็บหลัก) ---------- */
:root {
  --blue-dark:   #0d3b8c;
  --blue:        #1565c0;
  --blue-light:  #e9f2fc;
  --yellow:      #ffc107;
  --yellow-soft: #fff6db;
  --text-dark:   #1f2937;
  --text-muted:  #5b6675;
  --white:       #ffffff;
  --danger:      #c62828;
  --success:     #2e7d32;
  --shadow: 0 4px 16px rgba(13, 59, 140, 0.10);
  --radius: 12px;
  --sidebar-w: 260px;      /* ความกว้างแถบเมนูด้านข้าง */
}

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

body {
  font-family: 'Sarabun', sans-serif;
  color: var(--text-dark);
  background: #f3f6fb;
  line-height: 1.7;
  min-height: 100vh;
}

h1, h2, h3, .btn, .sidebar-brand strong { font-family: 'Prompt', sans-serif; }
img { max-width: 100%; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

/* ================================================================
   แถบเมนูด้านข้าง (Sidebar)
   ================================================================ */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--blue-dark);
  color: var(--white);
  overflow-y: auto;
  z-index: 1000;
  transition: transform .3s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,.15);
}
.sidebar-brand img {
  width: 46px; height: 46px;
  object-fit: contain;            /* แสดงเฉพาะตัวโลโก้ ไม่มีกรอบวงกลมรอง */
}
.sidebar-brand strong { display: block; color: var(--yellow); font-size: .95rem; line-height: 1.3; }
.sidebar-brand span   { display: block; font-size: .78rem; color: #cfe0f5; }

.sidebar-nav { padding: 10px 0 24px; }

.nav-group-title {
  padding: 14px 18px 6px;
  font-size: .74rem;
  letter-spacing: .5px;
  color: #9db8dd;
  text-transform: uppercase;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: #dbe6f5;
  font-size: .93rem;
  border-left: 4px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}
.sidebar-nav a:hover {
  background: rgba(255,255,255,.08);
  color: var(--yellow);
  text-decoration: none;
}
.sidebar-nav a.active {
  background: rgba(255,255,255,.12);
  color: var(--yellow);
  border-left-color: var(--yellow);
  font-weight: 600;
}
.nav-icon {
  width: 22px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
}
.nav-icon svg { width: 18px; height: 18px; }
.nav-logout { color: #ffb4a9 !important; }
.nav-logout:hover { color: #ff8a80 !important; }

/* ฉากหลังมืดเมื่อเปิดเมนูบนจอเล็ก */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 900;
}
body.sidebar-open .sidebar-overlay { display: block; }

/* ================================================================
   พื้นที่เนื้อหาหลัก (ขวาของ Sidebar)
   ================================================================ */
.admin-main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* แถบบนของหน้า */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--white);
  padding: 14px 22px;
  box-shadow: 0 2px 8px rgba(13,59,140,.08);
  position: sticky;
  top: 0;
  z-index: 500;
}
.topbar h1 { font-size: 1.15rem; color: var(--blue-dark); flex: 1; }
.topbar-user {
  font-size: .88rem;
  color: var(--text-muted);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.topbar-user svg { width: 16px; height: 16px; }
.topbar-hamburger {
  display: none;
  border: 0;
  background: var(--blue-light);
  color: var(--blue-dark);
  width: 40px; height: 40px;
  border-radius: 8px;
  place-items: center;
}
.topbar-hamburger svg { width: 20px; height: 20px; }

.admin-content { flex: 1; padding: 24px 22px 40px; width: min(1100px, 100%); }

.admin-footer {
  padding: 14px 22px;
  font-size: .82rem;
  color: var(--text-muted);
  border-top: 1px solid #e3e9f2;
  text-align: center;   /* จัดข้อความส่วนท้ายกึ่งกลาง */
}

.content-title {
  font-size: 1.08rem;
  color: var(--blue-dark);
  margin: 6px 0 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--yellow);
  display: inline-block;
}

/* ================================================================
   การ์ด กล่องเนื้อหา และแดชบอร์ด
   ================================================================ */
.card {
  background: var(--white);
  border: 1px solid #e3e9f2;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 22px;
}
.card-narrow { max-width: 480px; }
.card-title {
  color: var(--blue-dark);
  font-size: 1.05rem;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px dashed #ccd6e4;
}

/* การ์ดตัวเลขบนแดชบอร์ด */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.dash-card {
  background: var(--white);
  border: 1px solid #e3e9f2;
  border-top: 4px solid var(--blue);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  text-align: center;
}
.dash-highlight { border-top-color: var(--yellow); background: var(--yellow-soft); }
.dash-link { transition: transform .15s, box-shadow .15s; }
.dash-link:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(13,59,140,.16);
  text-decoration: none;
}
.dash-icon {
  width: 42px; height: 42px;
  margin: 0 auto 8px;
  border-radius: 12px;
  background: var(--blue-light);
  color: var(--blue);
  display: grid;
  place-items: center;
}
.dash-icon svg { width: 22px; height: 22px; }
.dash-highlight .dash-icon { background: rgba(255,255,255,.65); color: var(--blue-dark); }

.dash-number {
  font-family: 'Prompt', sans-serif;
  font-size: 1.9rem;
  font-weight: 700;
  color: var(--blue-dark);
}
.dash-label { font-size: .88rem; color: var(--text-muted); }

/* ================================================================
   ฟอร์มกรอกข้อมูล
   ================================================================ */
label {
  display: block;
  font-weight: 600;
  font-size: .9rem;
  color: var(--blue-dark);
  margin: 14px 0 5px;
}
input[type="text"], input[type="password"], input[type="date"],
input[type="number"], input[type="url"], input[type="email"],
select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #c5d2e4;
  border-radius: 8px;
  font-family: inherit;
  font-size: .95rem;
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(21,101,192,.15);
}
textarea { min-height: 100px; resize: vertical; }
input[type="file"] { padding: 8px; font-size: .88rem; }
.form-hint { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }

/* แถวฟอร์ม 2 คอลัมน์ (จอเล็กจะเรียงลงมา) */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }

/* ================================================================
   ปุ่มต่าง ๆ
   ================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: 0;
  border-radius: 8px;
  font-size: .92rem;
  font-weight: 500;
  margin-top: 16px;
  transition: filter .15s, transform .1s;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--blue); color: var(--white); }
.btn-yellow  { background: var(--yellow); color: var(--blue-dark); }
.btn-danger  { background: var(--danger); color: var(--white); }
.btn-block   { width: 100%; justify-content: center; }

/* ปุ่มเล็กในตาราง */
.btn-sm { padding: 6px 12px; font-size: .82rem; margin-top: 0; }

/* ================================================================
   ตารางแสดงรายการข้อมูล
   ================================================================ */
.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  font-size: .92rem;
}
.data-table th {
  background: var(--blue-light);
  color: var(--blue-dark);
  font-family: 'Prompt', sans-serif;
  font-weight: 600;
  font-size: .86rem;
  padding: 11px 12px;
  text-align: left;
  white-space: nowrap;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #edf1f7;
  vertical-align: middle;
}
.data-table tr:hover td { background: #f7fafe; }
.data-table .cell-actions { white-space: nowrap; display: flex; gap: 6px; }

/* ภาพขนาดเล็กในตาราง */
.thumb        { width: 90px;  border-radius: 6px; display: block; }
.thumb-tall   { width: 60px;  border-radius: 6px; display: block; }   /* ภาพกิจกรรมแนวตั้ง */
.thumb-logo   { width: 60px;  object-fit: contain; }   /* แสดงเฉพาะตัวโลโก้ */
.thumb-tall   { width: 54px;  aspect-ratio: 3/4; object-fit: cover; object-position: top; border-radius: 8px; border: 1px solid #dde6f2; background: var(--blue-light); }

/* ป้ายสถานะ แสดง/ซ่อน */
.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: .78rem; font-weight: 600; }
.badge-on  { background: #e8f5e9; color: var(--success); }
.badge-off { background: #fce4e4; color: var(--danger); }

/* ================================================================
   ข้อความแจ้งผล (Flash Message)
   ================================================================ */
.flash {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 18px;
  font-size: .92rem;
  border: 1px solid transparent;
}
.flash-success { background: #e8f5e9; color: var(--success); border-color: #c8e6c9; }
.flash-error   { background: #fce4e4; color: var(--danger);  border-color: #f5c6c6; }

/* ภาพตัวอย่างก่อนบันทึก (Preview) */
.img-preview {
  max-width: 260px;
  margin-top: 10px;
  border-radius: 8px;
  border: 1px solid #e3e9f2;
  display: none;              /* ซ่อนไว้ก่อน JavaScript จะแสดงเมื่อเลือกไฟล์ */
}
.img-preview.show { display: block; }

/* ================================================================
   หน้าล็อกอิน
   ================================================================ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--blue-dark), var(--blue));
  padding: 20px;
}
.login-box {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0,0,0,.25);
  border-top: 5px solid var(--yellow);
  padding: 34px 30px;
  width: min(400px, 100%);
  text-align: center;
}
.login-logo { width: 84px; height: 84px; object-fit: contain; margin-bottom: 10px; }
.login-box h1 { color: var(--blue-dark); font-size: 1.25rem; }
.login-sub { color: var(--text-muted); font-size: .85rem; margin-bottom: 16px; }
.login-box form { text-align: left; }
.login-back { margin-top: 18px; font-size: .85rem; }

/* บรรทัดผู้พัฒนาระบบ ท้ายกล่องเข้าสู่ระบบ */
.login-dev {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed #dde6f2;
  font-size: .82rem;
  color: var(--text-muted);
}

/* ช่องรหัสผ่านพร้อมปุ่มเปิด/ปิดการแสดงรหัส (รูปดวงตา) */
.password-wrap { position: relative; }
.password-wrap input { padding-right: 46px; }   /* เว้นที่ให้ปุ่มดวงตาด้านขวา */
.pw-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 1.05rem;
  line-height: 1;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  transition: background .15s;
}
.pw-toggle svg { width: 19px; height: 19px; }
.pw-toggle:hover { background: var(--blue-light); }
.pw-toggle.active { background: var(--yellow-soft); }

/* ================================================================
   Responsive : จอเล็ก Sidebar ยุบเป็นแฮมเบอร์เกอร์
   ================================================================ */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }            /* ซ่อน Sidebar ไว้นอกจอ */
  body.sidebar-open .sidebar { transform: translateX(0); }
  .admin-main { margin-left: 0; }
  .topbar-hamburger { display: grid; }
  .dash-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .admin-content { padding: 16px 14px 32px; }
  .dash-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .dash-number { font-size: 1.5rem; }
  .topbar h1 { font-size: 1rem; }
  .topbar-user { display: none; }
}

/* ลดการเคลื่อนไหว สำหรับผู้ใช้ที่ตั้งค่า Reduce Motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ================================================================
   หน้า "หัวข้อแต่ละส่วน" : กล่องแต่ละส่วน ตัวเลือกไอคอน และตัวอย่างผลลัพธ์
   ================================================================ */
.section-fieldset {
  border: 1px solid #dde6f2;
  border-radius: 10px;
  padding: 4px 18px 16px;
  margin-top: 18px;
}
.section-fieldset legend {
  font-family: 'Prompt', sans-serif;
  font-weight: 600;
  font-size: .95rem;
  color: var(--blue-dark);
  padding: 0 8px;
}

/* ตัวเลือกไอคอน : กดเลือกจากภาพจริง */
.icon-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.icon-choice { position: relative; cursor: pointer; margin: 0; }
.icon-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.icon-choice span {
  width: 44px; height: 44px;
  border: 1.5px solid #c5d2e4;
  border-radius: 10px;
  background: var(--white);
  color: var(--text-muted);
  display: grid;
  place-items: center;
  transition: border-color .15s, background .15s, color .15s;
}
.icon-choice span svg { width: 21px; height: 21px; }
.icon-choice:hover span { border-color: var(--blue); color: var(--blue); }
.icon-choice input:checked + span {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--white);
  box-shadow: 0 3px 10px rgba(21,101,192,.35);
}

/* กล่องตัวอย่างผลลัพธ์ : จำลองหัวข้อแบบเดียวกับหน้าเว็บจริง
   (ข้อความบรรทัดบน / เส้นคั่น 2 ข้างมีไอคอนตรงกลางบรรทัดล่าง) */
.section-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 14px 16px;
  background: var(--blue-light);
  border-radius: 10px;
  font-family: 'Prompt', sans-serif;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--blue-dark);
}
.section-preview .preview-divider {
  display: flex;
  align-items: center;
  gap: 9px;
  width: min(100%, 280px);
}
.section-preview .pline {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: var(--yellow);
}
.section-preview .preview-icon { display: grid; place-items: center; }
.section-preview .preview-icon svg { width: 20px; height: 20px; }
.section-preview.preview-hidden {
  color: var(--text-muted);
  font-weight: 400;
  font-style: italic;
}
.section-preview.preview-hidden .pline { background: #ccd6e4; }
.section-preview.preview-hidden .preview-icon { opacity: .35; }

/* ================================================================
   แถบแท็บสลับหมวดการจัดการ (หน้ากลุ่มงานภายใน)
   ================================================================ */
.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.admin-tabs a {
  background: var(--white);
  border: 1.5px solid #dbe6f5;
  color: var(--blue-dark);
  font-family: 'Prompt', sans-serif;
  font-weight: 500;
  font-size: .9rem;
  padding: 9px 18px;
  border-radius: 30px;
  transition: background .2s, color .2s, border-color .2s;
}
.admin-tabs a:hover { border-color: var(--yellow); text-decoration: none; }
.admin-tabs a.active {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--white);
  font-weight: 600;
}

/* ================================================================
   หน้า "หน้าตาเว็บไซต์" : ช่องเลือกสี และกล่องตัวอย่างผลลัพธ์
   ================================================================ */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}
.theme-item label { margin-top: 0; }

.theme-color-row { display: flex; align-items: center; gap: 10px; }
.theme-picker {
  width: 52px;
  height: 42px;
  padding: 2px;
  border: 1.5px solid #cfdcee;
  border-radius: 10px;
  background: var(--white);
  cursor: pointer;
  flex: 0 0 auto;
}
.theme-hex { flex: 1; text-transform: lowercase; }

/* ---------- กล่องตัวอย่างผลลัพธ์ ---------- */
.theme-preview {
  --blue-dark: #0d3b8c; --blue: #1565c0; --blue-light: #e9f2fc;
  --yellow: #ffc107; --yellow-soft: #fff6db; --badge-color: #0d3b8c;
  --font-head: 'Prompt', sans-serif; --font-body: 'Sarabun', sans-serif;
  --radius: 12px;

  border: 1px solid #dde6f2;
  border-radius: 12px;
  overflow: hidden;
  font-family: var(--font-body);
}

.theme-preview .tp-header {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--blue-dark);
  padding: 14px 18px;
}
.theme-preview .tp-logo {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--yellow);
  flex: 0 0 auto;
}
.theme-preview .tp-en {
  display: block;
  font-family: var(--font-head);
  color: var(--yellow);
  font-size: .95rem;
}
.theme-preview .tp-th { color: #fff; font-size: .8rem; }

.theme-preview .tp-announce {
  background: var(--yellow);
  color: var(--blue-dark);
  font-family: var(--font-head);
  font-weight: 600;
  text-align: center;
  padding: 8px;
  font-size: .9rem;
}

.theme-preview .tp-body { background: var(--blue-light); padding: 20px 18px; }
.theme-preview .tp-title {
  font-family: var(--font-head);
  color: var(--blue-dark);
  font-size: 1.1rem;
  text-align: center;
  margin-bottom: 4px;
  padding-bottom: 10px;
  border-bottom: 3px solid var(--yellow);
  width: fit-content;
  margin-inline: auto;
}

.theme-preview .tp-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 18px;
}
.theme-preview .tp-card {
  background: #fff;
  border-top: 4px solid var(--yellow);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 4px 14px rgba(13, 59, 140, .1);
}
.theme-preview .tp-card.tp-soft { background: var(--yellow-soft); }
.theme-preview .tp-card strong {
  display: block;
  font-family: var(--font-head);
  color: var(--blue-dark);
  margin-bottom: 6px;
}
.theme-preview .tp-card p { color: #5b6675; font-size: .9rem; line-height: 1.7; margin-bottom: 10px; }
.theme-preview .tp-btn {
  display: inline-block;
  background: var(--blue);
  color: #fff;
  font-family: var(--font-head);
  font-size: .85rem;
  padding: 7px 18px;
  border-radius: 8px;
}
.theme-preview .tp-badge {
  display: inline-block;
  background: var(--badge-color);
  color: #fff;
  font-family: var(--font-head);
  font-size: .82rem;
  padding: 6px 14px;
  border-radius: 8px;
}
