/**
 * ระบบติดตามพัฒนาการด้านการอ่าน สพป.บุรีรัมย์ เขต 4
 * Custom CSS - Modern UI/UX Kanit Font & Theming
 * สีหลัก: น้ำเงิน (#1B4994, #0D2D6C)
 * สีเสริม: ม่วงเข้ม (#4A2C6D), แดง (#D32F2F), ส้ม (#F57C00), เหลือง (#FBC02D), ฟ้าเขียว (#0288D1)
 */

@import url('https://fonts.googleapis.com/css2?family=Kanit:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300&family=Sarabun:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,400;1,700&display=swap');

:root {
  --primary-blue: #1B4994;
  --dark-blue: #0D2D6C;
  --light-blue: #EBF3FF;
  --accent-purple: #4A2C6D;
  --accent-red: #D32F2F;
  --accent-orange: #F57C00;
  --accent-yellow: #FBC02D;
  --accent-cyan: #0288D1;
  --accent-green: #2E7D32;
  --bg-main: #F4F7FC;
  --text-dark: #2C3E50;
  --sidebar-width: 270px;
  --header-height: 70px;
  --border-color: #E2E8F0;
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Kanit', sans-serif;
  background-color: var(--bg-main);
  color: var(--text-dark);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* =========================================================
   1. Header / Navbar
   ========================================================= */
.top-navbar {
  height: var(--header-height);
  background: linear-gradient(135deg, var(--dark-blue) 0%, var(--primary-blue) 100%);
  color: #ffffff;
  position: sticky;
  top: 0;
  z-index: 1040;
  box-shadow: 0 3px 12px rgba(13, 45, 108, 0.25);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: #ffffff;
}

.brand-logo {
  height: 48px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.brand-title-box h1 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.25;
}

.brand-title-box small {
  font-size: 0.8rem;
  color: #BFDBFE;
  font-weight: 300;
}

/* =========================================================
   2. Layout & Sidebar
   ========================================================= */
.app-container {
  display: flex;
  flex: 1;
  position: relative;
}

.app-sidebar {
  width: var(--sidebar-width);
  background: #ffffff;
  border-right: 1px solid var(--border-color);
  min-height: calc(100vh - var(--header-height));
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  z-index: 1030;
  flex-shrink: 0;
}

.sidebar-menu {
  list-style: none;
  padding: 1rem 0.75rem;
  margin: 0;
  flex: 1;
}

.menu-header {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #8C98A4;
  padding: 0.75rem 1rem 0.25rem;
  letter-spacing: 0.5px;
}

.menu-item {
  margin-bottom: 4px;
}

.menu-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.7rem 1rem;
  color: #4B5563;
  text-decoration: none;
  font-weight: 400;
  border-radius: 10px;
  transition: all 0.2s ease;
}

.menu-link i {
  font-size: 1.25rem;
  color: #6B7280;
  transition: color 0.2s;
}

.menu-link:hover {
  background-color: var(--light-blue);
  color: var(--primary-blue);
}

.menu-link:hover i {
  color: var(--primary-blue);
}

.menu-link.active {
  background: linear-gradient(135deg, var(--primary-blue) 0%, #2563EB 100%);
  color: #ffffff !important;
  font-weight: 500;
  box-shadow: 0 4px 10px rgba(27, 73, 148, 0.3);
}

.menu-link.active i {
  color: #ffffff !important;
}

.main-content {
  flex: 1;
  padding: 1.75rem;
  min-width: 0; /* Prevents flex children from causing overflow */
  transition: all 0.3s ease;
}

/* Mobile Sidebar & Toggle */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1025;
}

@media (max-width: 991.98px) {
  .app-sidebar {
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: calc(-1 * var(--sidebar-width));
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  }

  .app-sidebar.show {
    left: 0;
  }

  .sidebar-overlay.show {
    display: block;
  }

  .main-content {
    padding: 1rem;
  }
}

/* =========================================================
   3. Modern Cards & Statistics Widgets
   ========================================================= */
.card-modern {
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  transition: transform 0.2s, box-shadow 0.2s;
}

.card-modern:hover {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
}

.stat-card {
  border-radius: 14px;
  padding: 1.25rem 1.5rem;
  color: #ffffff;
  position: relative;
  overflow: hidden;
  box-shadow: 0 6px 16px rgba(0,0,0,0.12);
  height: 100%;
}

.stat-card.bg-blue {
  background: linear-gradient(135deg, #1B4994 0%, #3B82F6 100%);
}

.stat-card.bg-purple {
  background: linear-gradient(135deg, #4A2C6D 0%, #7C3AED 100%);
}

.stat-card.bg-red {
  background: linear-gradient(135deg, #D32F2F 0%, #EF4444 100%);
}

.stat-card.bg-orange {
  background: linear-gradient(135deg, #F57C00 0%, #FB923C 100%);
}

.stat-card.bg-yellow {
  background: linear-gradient(135deg, #D97706 0%, #FBBF24 100%);
  color: #ffffff;
}

.stat-card.bg-cyan {
  background: linear-gradient(135deg, #0288D1 0%, #38BDF8 100%);
}

.stat-card.bg-green {
  background: linear-gradient(135deg, #2E7D32 0%, #4ADE80 100%);
}

.stat-card .stat-icon {
  position: absolute;
  right: 15px;
  bottom: 10px;
  font-size: 3.5rem;
  opacity: 0.25;
}

.stat-card .stat-num {
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 0.25rem;
}

.stat-card .stat-label {
  font-size: 0.95rem;
  font-weight: 400;
  opacity: 0.9;
}

/* =========================================================
   4. Criteria Badges (4 Reading Assessment Levels)
   ========================================================= */
.badge-criteria {
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.45em 0.85em;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.badge-fluent {
  background-color: #E8F5E9;
  color: #2E7D32;
  border: 1px solid #A5D6A7;
}

.badge-spell-short {
  background-color: #E1F5FE;
  color: #0288D1;
  border: 1px solid #81D4FA;
}

.badge-spell-long {
  background-color: #FFF3E0;
  color: #E65100;
  border: 1px solid #FFCC80;
}

.badge-cannot {
  background-color: #FFEBEE;
  color: #C62828;
  border: 1px solid #FFCDD2;
}

.badge-pending {
  background-color: #FEF3C7;
  color: #92400E;
  border: 1px solid #FDE68A;
}

/* =========================================================
   5. Tables & Overflow
   ========================================================= */
.table-responsive-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.table-custom {
  width: 100%;
  margin-bottom: 0;
  background-color: #ffffff;
  border-collapse: collapse;
}

.table-custom thead th {
  background-color: #F8FAFC;
  color: #475569;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.9rem 1rem;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

.table-custom tbody td {
  padding: 0.85rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.92rem;
}

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

/* =========================================================
   6. Skeleton Loading & Spinner
   ========================================================= */
.skeleton {
  background: linear-gradient(90deg, #f0f3f8 25%, #e2e8f0 50%, #f0f3f8 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: 6px;
  display: inline-block;
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.loading-spinner-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(3px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}

.loading-spinner-overlay.active {
  display: flex;
}

.spinner-brand {
  width: 50px;
  height: 50px;
  border: 4px solid #E2E8F0;
  border-top-color: var(--primary-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* =========================================================
   7. Footer
   ========================================================= */
.app-footer {
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  padding: 1.25rem 2rem;
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.footer-dev {
  display: flex;
  align-items: center;
  gap: 10px;
}

.footer-logo {
  height: 42px;
  width: auto;
  object-fit: contain;
}

.footer-text {
  font-size: 0.9rem;
  color: #4B5563;
  margin: 0;
}

.footer-text strong {
  color: var(--dark-blue);
  font-weight: 600;
}

/* =========================================================
   8. Buttons & Modals Customization
   ========================================================= */
.btn-primary-custom {
  background: linear-gradient(135deg, var(--primary-blue) 0%, #2563EB 100%);
  color: #ffffff;
  border: none;
  box-shadow: 0 3px 8px rgba(27, 73, 148, 0.25);
  font-weight: 500;
}

.btn-primary-custom:hover {
  background: linear-gradient(135deg, var(--dark-blue) 0%, var(--primary-blue) 100%);
  color: #ffffff;
  box-shadow: 0 5px 12px rgba(13, 45, 108, 0.35);
}

.btn-purple {
  background-color: var(--accent-purple);
  color: #ffffff;
  border: none;
}
.btn-purple:hover {
  background-color: #3b2257;
  color: #ffffff;
}

.modal-content {
  border-radius: 16px;
  border: none;
  box-shadow: 0 15px 35px rgba(0,0,0,0.15);
}

.modal-header {
  border-bottom: 1px solid var(--border-color);
  background-color: #F8FAFC;
  border-radius: 16px 16px 0 0;
  padding: 1.2rem 1.5rem;
}

.modal-title {
  font-weight: 600;
  color: var(--dark-blue);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  border-top: 1px solid var(--border-color);
  padding: 1rem 1.5rem;
}

/* =========================================================
   9. Word-by-Word Assessment Styles
   ========================================================= */
.ring-active {
  box-shadow: 0 0 0 3px #1B4994 !important;
  transform: scale(1.15);
  z-index: 2;
  font-weight: 700 !important;
}

#mwaWordChipsContainer .btn {
  width: 32px;
  height: 32px;
  font-size: 0.8rem;
  transition: all 0.15s ease-in-out;
}

.mwa-choice-btn {
  transition: all 0.18s ease-in-out;
  cursor: pointer;
}

.mwa-choice-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1) !important;
}

.mwa-choice-btn:active {
  transform: scale(0.98);
}

/* TH Sarabun Font for Test Words and Official Documents */
.font-sarabun,
.test-word-sarabun,
#mwaWordText {
  font-family: 'TH Sarabun New', 'TH Sarabun PSK', 'Sarabun', 'Angsana New', sans-serif !important;
  letter-spacing: normal !important;
}

#mwaWordText {
  font-size: 5rem !important;
  font-weight: 700 !important;
  line-height: 1.2 !important;
}

@media (max-width: 576px) {
  #mwaWordText {
    font-size: 3.8rem !important;
  }
}

/* =========================================================
   10. Printable Reports Styles (@media print & preview)
   ========================================================= */
#printableReportArea {
  display: none;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 12mm 10mm 12mm 10mm;
  }

  body,
  .print-page,
  .print-table,
  .print-table th,
  .print-table td,
  .print-signature-box {
    font-family: 'TH Sarabun New', 'TH Sarabun PSK', 'Sarabun', 'Angsana New', sans-serif !important;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 13pt !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Hide everything on screen except print container */
  .top-navbar,
  .app-sidebar,
  .main-content,
  .modal,
  .modal-backdrop,
  .btn,
  #confirmAlertBox,
  #schoolConfirmationBadgeBox,
  .nav-pills,
  footer {
    display: none !important;
  }

  #printableReportArea {
    display: block !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
  }

  .print-page {
    width: 100% !important;
    background: #ffffff !important;
    color: #000000 !important;
    page-break-after: always;
  }

  .print-page:last-child {
    page-break-after: auto;
  }

  .print-table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin-top: 10px !important;
    margin-bottom: 15px !important;
  }

  .print-table th,
  .print-table td {
    border: 1px solid #222222 !important;
    padding: 6px 8px !important;
    font-size: 11pt !important;
    vertical-align: middle !important;
    color: #000000 !important;
  }

  .print-table th {
    background-color: #f0f3f8 !important;
    font-weight: 600 !important;
    text-align: center !important;
  }

  .print-signature-box {
    margin-top: 30px !important;
    page-break-inside: avoid !important;
  }

  .print-badge {
    border: 1px solid #333 !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
    font-weight: 500 !important;
    font-size: 10pt !important;
    display: inline-block !important;
  }
}

