/* ============================================================
   ระบบรับสมัครสอบเข้าโรงเรียนออนไลน์
   Admin Portal Stylesheet
   ============================================================ */

:root {
  --admin-primary: #1e3a8a;
  --admin-primary-hover: #1e40af;
  --admin-sidebar-bg: #0f172a;
  --admin-sidebar-text: #94a3b8;
  --admin-sidebar-hover: #1e293b;
  --admin-topbar-bg: #ffffff;
  --admin-content-bg: #f8fafc;
  --border-color: #e2e8f0;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

body.admin-body {
  font-family: var(--font-family);
  background-color: var(--admin-content-bg);
  color: var(--text-main);
  min-height: 100vh;
}

.admin-wrapper {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.admin-sidebar {
  width: 260px;
  background-color: var(--admin-sidebar-bg);
  color: var(--admin-sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  /* จอใหญ่: ตรึงเมนูข้างไว้กับจอ ไม่เลื่อนตามเนื้อหาที่ยาว */
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  /* ใช้ทั้งแบบตรึงข้างจอ (จอใหญ่) และแบบลิ้นชักเลื่อน (จอเล็ก ≤1024px) */
  transition: transform 0.25s ease;
  z-index: 60;
}

/* ซ่อนปุ่ม ☰ และพื้นหลังทึบไว้ก่อน — จอเล็กจะเปิดใช้ใน media query */
.admin-sidebar-toggle {
  display: none;
}

.admin-sidebar-backdrop {
  display: none;
}

.admin-topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.admin-title-area {
  min-width: 0;
}

.admin-title-area h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-brand {
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid #1e293b;
}

.brand-crest {
  width: 40px;
  height: 40px;
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
  color: #3b82f6;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  font-weight: 700;
  font-size: 1.1rem;
}

.brand-info h3 {
  font-size: 1rem;
  color: #ffffff;
}

.brand-info small {
  font-size: 0.75rem;
  color: #64748b;
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  padding: 1rem 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.sidebar-menu {
  list-style: none;
}

.menu-header {
  padding: 0.75rem 1.5rem 0.25rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  font-weight: 700;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  color: var(--admin-sidebar-text);
  text-decoration: none;
  font-size: 0.95rem;
  transition: all 0.2s;
}

.sidebar-link:hover {
  background-color: var(--admin-sidebar-hover);
  color: #ffffff;
}

.sidebar-link .icon {
  font-size: 1.1rem;
  width: 24px;
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid #1e293b;
  font-size: 0.75rem;
  color: #64748b;
}

/* Main Area */
.admin-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.admin-topbar {
  background-color: var(--admin-topbar-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  /* ตรึงแถบด้านบนไว้ เพื่อให้ปุ่มเมนู/ชื่อผู้ใช้ยังเข้าถึงได้ตอนเลื่อนตารางยาว ๆ */
  position: sticky;
  top: 0;
  z-index: 40;
}

.admin-user-area {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.user-badge {
  text-align: right;
}

.user-name {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
}

.user-role-tag {
  display: inline-block;
  background-color: #dbeafe;
  color: #1e40af;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.admin-content {
  padding: 2rem;
  flex: 1;
}

/* Cards & Grid */
.card {
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
  margin-bottom: 1.5rem;
}

.card-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background-color: #f8fafc;
  border-radius: 10px 10px 0 0;
  /* ให้หัวการ์ดที่มีปุ่ม/ป้ายอยู่ด้วยจัดสองฝั่งอัตโนมัติ และตัดบรรทัดได้บนจอเล็ก */
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 0.75rem;
}

.card-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.card-body {
  padding: 1.5rem;
}

.card-footer {
  padding: 0.75rem 1.5rem;
  background-color: #f8fafc;
  border-top: 1px solid var(--border-color);
  border-radius: 0 0 10px 10px;
}

.stats-grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
}

.stat-card {
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.stat-primary { border-left: 4px solid #2563eb; }
.stat-info { border-left: 4px solid #06b6d4; }
.stat-warning { border-left: 4px solid #f59e0b; }
.stat-success { border-left: 4px solid #10b981; }

.stat-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.stat-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.stat-number {
  display: block;
  font-size: clamp(1.45rem, 1.2rem + 1.4vw, 1.8rem);
  font-weight: 700;
  line-height: 1.1;
}

/* ตัวเลขที่เป็นวันที่/เวลาใน stat card ไม่ต้องใหญ่เท่าตัวเลขสถิติ */
.stat-number-sm {
  font-size: 0.95rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ============================================================
   คอมโพเนนต์เพิ่มเติมของหน้าเจ้าหน้าที่
   (คลาสที่เทมเพลตใช้แต่เดิมไม่มีนิยาม ทำให้เลย์เอาต์เพี้ยน)
   ============================================================ */

/* หัวหน้าแดชบอร์ด: ทักทาย + ปุ่มทางลัด (จอใหญ่เรียงข้างกัน จอเล็กซ้อนลงมา) */
.dashboard-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
}

.welcome-box h1 {
  font-size: clamp(1.2rem, 1.05rem + 1vw, 1.6rem);
  margin-bottom: 0.25rem;
}

.welcome-box p {
  font-size: 0.9rem;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ฟอร์มตัวกรอง/ค้นหา (หน้าผู้สมัคร, การชำระเงิน ฯลฯ) */
.filter-form {
  width: 100%;
}

.filter-form .form-group:last-child {
  margin-bottom: 0;
}

/* ปุ่มเลื่อนหน้าในตาราง */
.pagination-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

/* รายละเอียดในไทม์ไลน์ของใบสมัคร */
.timeline-desc {
  display: block;
  font-size: 0.95rem;
}

.timeline-reason {
  display: block;
  font-size: 0.85rem;
  font-style: italic;
}

/* ฟอร์มเข้าสู่ระบบ */
.login-form {
  width: 100%;
}

/* กลุ่มช่องวัน/เดือน/ปี พ.ศ./เวลา ในกล่องแก้ไขปีการศึกษา
   (ใช้ partial ตัวเดียวกับหน้าสมัคร จึงต้องมีหัวข้อคั่นแต่ละวัน) */
.date-field-group {
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem 0.85rem 0.15rem;
  margin-bottom: 0.85rem;
  background-color: #f8fafc;
}

.date-field-group-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--admin-primary);
  margin-bottom: 0.6rem;
}

.date-field-group .form-group {
  margin-bottom: 0.75rem;
}

.date-field-group .form-group label {
  font-size: 0.85rem;
}

/* ชื่อเรียกปีการศึกษาที่ระบบตั้งให้ (อ่านอย่างเดียว ไม่ใช่ช่องกรอก) */
.year-name-preview {
  padding: 0.55rem 0.75rem;
  border: 1px dashed var(--border-color);
  border-radius: 6px;
  background-color: #f8fafc;
  font-weight: 700;
  color: var(--admin-primary);
}

/* ============================================================
   คู่มือการใช้งาน (Admin Manual) — หน้าอ่านเอกสาร + ระบบค้นหา
   ============================================================ */

.manual-page {
  max-width: 1100px;
}

.manual-header {
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-left: 5px solid var(--admin-primary);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.manual-docid {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #1e40af;
  background-color: #dbeafe;
  border-radius: 9999px;
  padding: 0.15rem 0.6rem;
  margin-bottom: 0.5rem;
}

.manual-header h1 {
  font-size: clamp(1.2rem, 1.05rem + 1vw, 1.55rem);
  margin-bottom: 0.25rem;
}

.manual-subtitle {
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}

.manual-meta {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  font-size: 0.9rem;
  border-top: 1px solid var(--border-color);
  padding-top: 0.85rem;
}

.manual-meta dt {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.manual-meta dd {
  margin: 0;
}

/* ---------- แถบค้นหา ---------- */
.manual-toolbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.manual-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.manual-search-icon {
  position: absolute;
  left: 0.7rem;
  font-size: 1rem;
  pointer-events: none;
}

.manual-search-input {
  padding-left: 2.3rem;
}

.manual-search-clear {
  flex-shrink: 0;
}

.manual-search-help {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.manual-search-help kbd {
  background-color: #f1f5f9;
  border: 1px solid var(--border-color);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 0.3rem;
  font-size: 0.75rem;
}

.manual-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.manual-chip {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: 9999px;
  border: 1px solid var(--border-color);
  background-color: #ffffff;
  color: var(--text-muted);
  cursor: pointer;
}

.manual-chip:hover {
  background-color: #f1f5f9;
}

.manual-chip.is-active {
  background-color: var(--admin-primary);
  border-color: var(--admin-primary);
  color: #ffffff;
}

.manual-result-count {
  margin: 0.6rem 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* ---------- สารบัญ ---------- */
.manual-toc {
  background-color: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.manual-toc h2 {
  font-size: 1.05rem;
  margin-bottom: 0.6rem;
}

.manual-toc-group + .manual-toc-group {
  margin-top: 0.75rem;
}

.manual-toc-group h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.manual-toc ul {
  list-style: none;
}

.manual-toc-link {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem 0.6rem;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-main);
  font-size: 0.92rem;
}

.manual-toc-link:hover {
  background-color: #f1f5f9;
  color: var(--admin-primary);
}

.manual-toc-path {
  font-size: 0.75rem;
  color: var(--text-muted);
  background-color: #f1f5f9;
  border-radius: 4px;
  padding: 0 0.3rem;
}

/* ---------- หัวข้อในคู่มือ ---------- */
.manual-section {
  scroll-margin-top: 1rem;
}

.manual-section-header {
  align-items: flex-start;
}

.manual-section-header h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.1rem;
}

.manual-section-icon {
  font-size: 1.15rem;
  line-height: 1;
}

/* ระยะห่างระหว่างหัวข้อในคู่มือ */
.manual-sections {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.manual-toc-icon {
  flex-shrink: 0;
  width: 1.4rem;
  text-align: center;
}

.manual-toc-title {
  font-weight: 600;
}

.manual-section-num {
  font-size: 0.78rem;
  font-weight: 700;
  color: #ffffff;
  background-color: var(--admin-primary);
  border-radius: 6px;
  padding: 0.1rem 0.4rem;
}

.manual-path code {
  font-size: 0.78rem;
  background-color: #f1f5f9;
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
}

.manual-summary {
  font-size: 1rem;
  margin-bottom: 1rem;
}

.manual-block {
  margin-bottom: 1.25rem;
}

.manual-block h3 {
  font-size: 0.95rem;
  color: var(--admin-primary);
  margin-bottom: 0.45rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border-color);
}

.manual-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0 1.25rem;
}

.manual-list {
  padding-left: 1.15rem;
  font-size: 0.92rem;
}

.manual-list li + li,
.manual-steps li + li {
  margin-top: 0.35rem;
}

.manual-list-check {
  list-style: none;
  padding-left: 0;
}

.manual-list-check li {
  padding-left: 1.4rem;
  position: relative;
}

.manual-list-check li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: var(--success-color, #0e9f6e);
  font-weight: 700;
}

.manual-steps {
  padding-left: 1.35rem;
  font-size: 0.92rem;
}

.manual-step-title {
  display: block;
  font-weight: 700;
}

.manual-step-detail {
  display: block;
  color: var(--text-main);
}

.manual-table {
  margin-bottom: 0;
}

.manual-table th {
  white-space: normal;
}

.manual-table-key {
  font-weight: 600;
  min-width: 12rem;
}

/* ---------- ข้อควรระวัง (แบบ Warning / Caution / Note) ---------- */
.manual-cautions {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.manual-caution {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border-left: 4px solid #94a3b8;
  background-color: #f8fafc;
  font-size: 0.92rem;
}

.manual-caution-tag {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  background-color: #e2e8f0;
  color: #334155;
}

.manual-caution-warning {
  border-left-color: #dc2626;
  background-color: #fef2f2;
}

.manual-caution-warning .manual-caution-tag {
  background-color: #dc2626;
  color: #ffffff;
}

.manual-caution-caution {
  border-left-color: #f59e0b;
  background-color: #fffbeb;
}

.manual-caution-caution .manual-caution-tag {
  background-color: #f59e0b;
  color: #ffffff;
}

.manual-caution-note {
  border-left-color: #2563eb;
  background-color: #eff6ff;
}

.manual-caution-note .manual-caution-tag {
  background-color: #2563eb;
  color: #ffffff;
}

.manual-related a {
  color: var(--admin-primary);
  font-weight: 600;
}

.manual-related-sep {
  color: var(--text-muted);
  margin: 0 0.35rem;
}

.manual-back {
  margin-top: 0.5rem;
  font-size: 0.85rem;
}

.manual-empty {
  padding: 1rem 1.25rem;
  border: 1px dashed var(--border-color);
  border-radius: 10px;
  background-color: #fffbeb;
  font-size: 0.92rem;
}

/* ไฮไลต์คำที่ค้นพบ */
mark.manual-hit {
  background-color: #fde68a;
  color: inherit;
  border-radius: 3px;
  padding: 0 0.1rem;
}

@media (min-width: 900px) {
  .manual-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .manual-grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .manual-toolbar {
    padding: 0.7rem 0.75rem;
  }

  .manual-header {
    padding: 1rem;
  }

  .manual-search-help {
    font-size: 0.75rem;
  }
}

/* ตอนพิมพ์คู่มือ: ซ่อนเครื่องมือค้นหา/สารบัญ/ปุ่ม แล้วให้เนื้อหาเต็มกระดาษ */
@media print {
  .manual-toolbar,
  .manual-toc,
  .manual-back,
  .admin-topbar,
  .admin-sidebar {
    display: none !important;
  }

  .manual-section {
    break-inside: avoid;
    border: 1px solid #94a3b8 !important;
  }

  .manual-caution {
    border: 1px solid #94a3b8;
    border-left-width: 4px;
  }
}

/* ตัวอย่างโลโก้โรงเรียนในหน้าตั้งค่า (ทั้งตัวปัจจุบันและไฟล์ที่เพิ่งเลือก) */
.logo-preview {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 4px;
  background-color: #ffffff;
  flex-shrink: 0;
}

/* ในกล่อง (กว้างไม่เกิน 640px) 4 ช่องเรียงแถวจะบีบจนอ่านไม่ออก — ใช้ 2 คอลัมน์
   แล้วยุบเป็นคอลัมน์เดียวบนมือถือ */
.date-field-group .form-grid-4,
.date-field-group .form-grid-3 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 0.75rem;
}

@media (max-width: 480px) {
  .date-field-group .form-grid-4,
  .date-field-group .form-grid-3 {
    grid-template-columns: 1fr;
  }
}

/* ตัวอย่างข้อความหน้าแรก (Hero) ในหน้าตั้งค่า — ให้เห็นผลก่อนกดบันทึก */
.hero-preview {
  background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
  color: #ffffff;
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
}

.hero-preview-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #bfdbfe;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.hero-preview-badge {
  display: inline-block;
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 9999px;
  padding: 0.2rem 0.8rem;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  overflow-wrap: anywhere;
}

.hero-preview-title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.hero-preview-sub {
  font-size: 0.85rem;
  color: #dbeafe;
  margin-top: 0.35rem;
  overflow-wrap: anywhere;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Data Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th, .table td {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
}

.table th {
  background-color: #f8fafc;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.table tbody tr:hover {
  background-color: #f1f5f9;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-primary { background-color: #dbeafe; color: #1e40af; }
.badge-success { background-color: #d1fae5; color: #065f46; }
.badge-danger { background-color: #fee2e2; color: #991b1b; }
.badge-warning { background-color: #fef3c7; color: #92400e; }
.badge-light { background-color: #f1f5f9; color: #475569; }

/* รายการประกาศผลสอบในหน้าตั้งค่า (เรียงลำดับด้วยปุ่มเลื่อนขึ้น/ลง) */
.ann-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.ann-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ann-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid #e2e8f0;
  border-left: 4px solid #2563eb;
  border-radius: 12px;
  background-color: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.ann-row:hover {
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.1);
  transform: translateY(-1px);
}

/* รายการที่ปิดอยู่ให้ดูจางลง เพื่อแยกออกจากรายการที่แสดงจริงบนหน้าแรก */
.ann-row.is-off {
  border-left-color: #cbd5e1;
  background-color: #f8fafc;
}

.ann-row.is-off .ann-order {
  background-color: #94a3b8;
}

.ann-order {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: #2563eb;
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
}

.ann-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ann-title {
  font-size: 1rem;
  font-weight: 600;
  color: #0f172a;
}

/* รูปย่อของประกาศในหน้ารายการตั้งค่า */
.ann-thumb {
  width: 56px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  flex: 0 0 auto;
}

.ann-thumb-empty {
  width: 56px;
  height: 42px;
  border-radius: 6px;
  border: 1px dashed #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 0.9rem;
  flex: 0 0 auto;
}

.ann-preview {
  font-size: 0.85rem;
  color: #64748b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ann-status { flex: 0 0 auto; }

.ann-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.ann-actions .btn {
  padding: 0.32rem 0.6rem;
  font-size: 0.85rem;
  line-height: 1;
}

.ann-actions .btn[disabled] {
  opacity: 0.3;
  cursor: not-allowed;
  box-shadow: none;
}

@media (max-width: 900px) {
  .ann-row {
    flex-wrap: wrap;
    gap: 10px 12px;
  }
  .ann-order { order: 0; }
  .ann-main { order: 1; flex-basis: calc(100% - 48px); }
  .ann-status { order: 2; }
  .ann-actions {
    order: 3;
    flex-basis: 100%;
    justify-content: flex-start;
    padding-top: 10px;
    border-top: 1px dashed #e2e8f0;
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-family: inherit;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.btn-lg { padding: 0.7rem 1.4rem; font-size: 1.02rem; }
.btn-primary { background-color: #2563eb; color: #ffffff; }
.btn-primary:hover { background-color: #1d4ed8; }
.btn-success { background-color: #059669; color: #ffffff; }
.btn-danger { background-color: #dc2626; color: #ffffff; }
.btn-outline { background-color: #ffffff; border-color: #cbd5e1; color: var(--text-main); }
.btn-outline:hover { background-color: #f8fafc; }
.btn-outline-danger { background-color: #ffffff; border-color: #fca5a5; color: #dc2626; }
.btn-outline-danger:hover { background-color: #fee2e2; }
.btn-outline-primary { background-color: #ffffff; border-color: #93c5fd; color: #2563eb; }
.btn-outline-primary:hover { background-color: #eff6ff; }
.btn-block { width: 100%; }

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.form-control {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
}

.form-control:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.form-grid-5 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

/* 4 คอลัมน์: ช่อง วัน/เดือน/ปี พ.ศ./เวลา (partial thai_datetime_fields)
   เดิมคลาสนี้มีนิยามแค่ใน main.css ซึ่งหน้าจ้าหน้าที่ไม่ได้โหลด ช่องจึงเรียงเป็นคอลัมน์เดียว */
.form-grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

/* Dialog Modals */
.custom-dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  max-width: 500px;
  width: 90%;
  margin: auto;
}

.custom-dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.5);
}

.dialog-content {
  padding: 1.75rem;
}

.dialog-content h3 {
  margin-bottom: 1.25rem;
  font-size: 1.2rem;
}

/* Timeline */
.timeline-list {
  list-style: none;
  border-left: 2px solid var(--border-color);
  padding-left: 1.25rem;
  margin-left: 0.5rem;
}

.timeline-item {
  position: relative;
  margin-bottom: 1.25rem;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -1.65rem;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #2563eb;
  border: 2px solid #ffffff;
}

.timeline-time {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.25rem;
}

/* Login Page */
body.login-body {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background-color: #ffffff;
  border-radius: 14px;
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-crest {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.login-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: #1e3a8a;
}

.login-footer {
  text-align: center;
  margin-top: 1.5rem;
}

/* ช่องรหัสผ่านพร้อมปุ่มแสดง/ซ่อน */
.password-wrap {
  position: relative;
}

.password-wrap .form-control {
  padding-right: 3rem;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 0.5rem;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  color: #64748b;
}

.password-toggle:hover {
  background-color: #f1f5f9;
}

.password-toggle:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.caps-warning {
  margin-top: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #92400e;
  background-color: #fef3c7;
  border-radius: 6px;
  padding: 4px 8px;
  display: inline-block;
}

/* ปุ่มที่กำลังส่งข้อมูล — กันกดซ้ำโดยไม่ใช้ disabled (จะทำให้ค่า name/value หาย) */
.btn.is-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.75;
}

.btn.is-loading::after {
  content: '';
  width: 0.9em;
  height: 0.9em;
  margin-left: 0.5rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  vertical-align: -0.1em;
  animation: btn-spin 0.6s linear infinite;
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* ช่องว่างระหว่างปุ่มบนแถบด้านบนให้อ่านง่าย */
.admin-user-area .btn-sm {
  padding: 0.35rem 0.7rem;
}

/* Alerts */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

.alert-success { background-color: #def7ec; color: #03543f; }
.alert-danger { background-color: #fde8e8; color: #9b1c1c; }
.alert-warning { background-color: #fef3c7; color: #92400e; }
.alert-info { background-color: #e0f2fe; color: #075985; }

/* ============================================================
   RESPONSIVE — รองรับมือถือทุกรุ่น แท็บเล็ต (iPad) และคอมพิวเตอร์

   ลำดับ breakpoint ที่ใช้ทั้งโปรเจกต์ (ใหญ่ → เล็ก)
     1280px  โน้ตบุ๊กเล็ก / แท็บเล็ตนอน
     1024px  iPad นอนตั้ง — เมนูข้างกลายเป็นลิ้นชัก
      900px  แท็บเล็ตตั้ง
      768px  มือถือจอนอน / มือถือจอใหญ่
      600px  มือถือทั่วไป
      480px  มือถือเล็ก
      380px  มือถือจิ๋ว (iPhone SE รุ่นแรก)
   ============================================================ */

/* จอใหญ่: จำกัดความกว้างเนื้อหาไม่ให้ยืดจนอ่านยากบนจอ ultrawide */
@media (min-width: 1600px) {
  .admin-content {
    max-width: 1500px;
    margin: 0 auto;
    width: 100%;
  }
}

/* ---------- ≤1024px : iPad นอนตั้ง — เปลี่ยนเมนูข้างเป็นลิ้นชัก ---------- */
@media (max-width: 1024px) {
  .admin-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: auto;
    width: min(280px, 82vw);
    transform: translateX(-100%);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.35);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* เผื่อขอบล่างบน iPhone ที่มีแถบ home indicator */
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .admin-sidebar.open {
    transform: translateX(0);
  }

  .admin-sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    font-size: 1.15rem;
    line-height: 1;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background-color: #fff;
    color: var(--text-main);
    cursor: pointer;
  }

  .admin-sidebar-toggle:hover {
    background-color: #f1f5f9;
  }

  .admin-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.5);
    z-index: 55;
    border: none;
  }

  .admin-sidebar-backdrop[hidden] {
    display: none;
  }

  /* ล็อกการเลื่อนเนื้อหาขณะเมนูเปิด เพื่อไม่ให้หน้าไหลตามนิ้ว */
  body.sidebar-open {
    overflow: hidden;
  }

  .admin-topbar {
    padding: 0.85rem 1.25rem;
  }

  .admin-content {
    padding: 1.25rem;
  }

  .form-grid-2,
  .form-grid-3 {
    gap: 1rem;
  }

  .table th,
  .table td {
    padding: 0.7rem 0.9rem;
  }
}

/* ---------- ≤900px : แท็บเล็ตตั้ง — ฟอร์มยุบเป็นคอลัมน์เดียว ---------- */
@media (max-width: 900px) {
  /* minmax(320px) ของเดิมล้นจอเมื่อหัก padding แล้ว จึงบังคับเป็นคอลัมน์เดียว */
  .form-grid-2,
  .form-grid-3 {
    grid-template-columns: 1fr;
  }

  .admin-topbar {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .admin-user-area {
    width: 100%;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .admin-content {
    padding: 1rem;
  }

  .content-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.75rem;
  }

  /* แดชบอร์ด: หัวข้อกับปุ่มทางลัดซ้อนกันในแนวตั้ง แล้วปุ่มเต็มความกว้าง */
  .dashboard-header {
    align-items: stretch;
    flex-direction: column;
  }

  .quick-actions .btn {
    flex: 1 1 auto;
  }

  /* ตารางกว้าง: ให้คงความกว้างคอลัมน์ที่อ่านได้ แล้วเลื่อนแนวนอนในกล่องของตัวเอง
     (เงาบอกขอบของ .table-responsive อยู่ใน utilities.css ซึ่งใช้ร่วมกับหน้าบ้าน)
     - หัวตารางห้ามตัดคำ เพราะชื่อคอลัมน์ไทยจะแตกเป็น "เลขที่ / ใบ / สมัคร"
     - ตัวข้อมูลยังตัดบรรทัดได้ตามปกติ */
  .table {
    min-width: 700px;
  }

  .table th {
    white-space: nowrap;
  }

  .custom-dialog {
    width: 94%;
    max-height: 88dvh;
    overflow-y: auto;
  }

  .dialog-content {
    padding: 1.25rem;
  }

  .ann-actions {
    justify-content: flex-start;
  }
}

/* ---------- ≤768px : มือถือจอใหญ่ / จอนอน ---------- */
@media (max-width: 768px) {
  /* สำคัญมากบน iOS: ถ้าช่องกรอกเล็กกว่า 16px เบราว์เซอร์จะซูมเข้าอัตโนมัติ
     ทำให้หน้าจอ "กระโดด" ทุกครั้งที่แตะช่องกรอก */
  .form-control,
  .swal2-input,
  .swal2-textarea,
  .swal2-select,
  select.form-control,
  input.form-control,
  textarea.form-control {
    font-size: 16px;
  }

  .admin-content {
    padding: 0.9rem;
  }

  .card-header,
  .card-body {
    padding: 1rem;
  }

  .card-header h3 {
    font-size: 1.02rem;
  }

  .content-header h1 {
    font-size: 1.3rem;
  }

  .badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.55rem;
  }

  .user-badge {
    text-align: left;
  }

  .user-name {
    font-size: 0.9rem;
  }

  .user-role-tag {
    font-size: 0.7rem;
  }

  .timeline-list {
    padding-left: 0.9rem;
    margin-left: 0.25rem;
  }

  .timeline-time {
    display: block;
  }

  .stats-grid,
  .dashboard-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ---------- ≤600px : มือถือทั่วไป ---------- */
@media (max-width: 600px) {
  .admin-topbar {
    padding: 0.75rem 0.9rem;
  }

  .admin-title-area h2 {
    font-size: 1rem;
  }

  /* ให้ปุ่มบนแถบด้านบนกินเต็มความกว้าง อ่านและแตะง่าย */
  .admin-user-area {
    gap: 0.5rem;
  }

  .admin-user-area .btn {
    padding: 0.5rem 0.7rem;
  }

  .ann-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }

  .ann-toolbar .btn {
    width: 100%;
  }

  /* ปุ่มในแถวประกาศให้แตะง่ายขึ้น */
  .ann-actions .btn {
    flex: 1 1 auto;
    min-height: 40px;
  }

  .table th,
  .table td {
    padding: 0.6rem 0.7rem;
    font-size: 0.9rem;
  }

  .table th {
    font-size: 0.75rem;
  }

  /* ตัวกรอง/ค้นหา: ปุ่มเต็มความกว้าง แตะง่าย */
  .filter-form .text-right,
  .filter-form .d-flex {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: stretch;
    text-align: left;
  }

  .filter-form .text-right .btn,
  .filter-form .d-flex .btn {
    flex: 1 1 auto;
  }

  /* ปุ่มเปลี่ยนหน้า: ให้อยู่คนละบรรทัดกับข้อความจำนวนรายการ */
  .card-footer {
    flex-direction: column;
    align-items: stretch !important;
    gap: 0.6rem;
    text-align: center;
  }

  .pagination-controls {
    justify-content: center;
  }

  .pagination-controls .btn {
    flex: 1 1 auto;
  }

  .stat-card {
    padding: 1.1rem;
  }
}

/* ---------- ≤480px : มือถือเล็ก ---------- */
@media (max-width: 480px) {
  .admin-content {
    padding: 0.75rem;
  }

  .card-header,
  .card-body {
    padding: 0.85rem;
  }

  .content-header h1 {
    font-size: 1.15rem;
  }

  .login-card {
    padding: 1.5rem 1.15rem;
    border-radius: 12px;
  }

  .login-header h1 {
    font-size: 1.2rem;
  }

  .login-crest {
    font-size: 2.4rem;
  }

  .custom-dialog {
    width: 96%;
  }

  .dialog-content {
    padding: 1rem;
  }

  .d-flex.gap-2 {
    flex-wrap: wrap;
  }

  /* ปุ่มคู่ (ยกเลิก/บันทึก) ให้เต็มความกว้างและเรียงลงมา */
  .dialog-content .d-flex.justify-content-end {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .dialog-content .d-flex.justify-content-end .btn {
    width: 100%;
  }
}

/* ---------- ≤380px : มือถือจิ๋ว ---------- */
@media (max-width: 380px) {
  .admin-content {
    padding: 0.6rem;
  }

  .card-header,
  .card-body {
    padding: 0.75rem;
  }

  .admin-sidebar-toggle {
    width: 36px;
    height: 36px;
  }

  .user-role-tag {
    display: none; /* เก็บพื้นที่ให้ชื่อกับปุ่ม */
  }

  .ann-order {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
    font-size: 0.85rem;
  }
}

/* ---------- จอสัมผัส: บังคับขนาดเป้าหมายการแตะ ≥44px ---------- */
@media (pointer: coarse) {
  .btn {
    min-height: 44px;
  }

  .btn-sm {
    min-height: 40px;
  }

  .sidebar-link {
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
  }

  .password-toggle {
    min-width: 44px;
    min-height: 44px;
  }

  /* ตารางที่กดได้ทั้งแถวให้สูงพอแตะ */
  .table tbody tr {
    min-height: 44px;
  }
}

/* ---------- เคารพผู้ใช้ที่ปิดอนิเมชัน ---------- */
@media (prefers-reduced-motion: reduce) {
  .admin-sidebar,
  .btn,
  .ann-row,
  .table tbody tr {
    transition: none !important;
  }

  .btn.is-loading::after {
    animation-duration: 1.5s;
  }
}

/* ---------- รองรับร่องจอ (notch) ของ iPhone ---------- */
@supports (padding: env(safe-area-inset-left)) {
  .admin-content {
    padding-left: max(0.9rem, env(safe-area-inset-left));
    padding-right: max(0.9rem, env(safe-area-inset-right));
    padding-bottom: max(0.9rem, env(safe-area-inset-bottom));
  }
}
