/* 
 * Main CSS for Fix Grade System 
 * โรงเรียนคงคาราม
 */

:root {
  --primary-color: #0d6efd;
  --secondary-color: #6c757d;
  --success-color: #198754;
  --warning-color: #ffc107;
  --danger-color: #dc3545;
  --info-color: #0dcaf0;
  --light-color: #f8f9fa;
  --dark-color: #212529;
  --body-color: #f5f5f5;
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 70px;
  --header-height: 60px;
  --footer-height: 50px;
  --thai-font: "Sarabun", "TH Sarabun New", sans-serif;
}

/* ============= GENERAL STYLES ============= */
body {
  font-family: var(--thai-font);
  background-color: var(--body-color);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.content-wrapper {
  display: flex;
  flex: 1;
}

.page-content {
  flex: 1;
  padding: 20px;
  transition: margin-left 0.3s;
  margin-left: var(--sidebar-width);
  margin-top: var(--header-height);
  margin-bottom: var(--footer-height);
  min-height: calc(100vh - var(--header-height) - var(--footer-height));
}

.sidebar-collapsed .page-content {
  margin-left: var(--sidebar-collapsed-width);
}

/* ============= HEADER STYLES ============= */
.main-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  background-color: white;
  padding: 0 15px;
  z-index: 1000;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  transition: left 0.3s;
  left: var(--sidebar-width);
}

.sidebar-collapsed .main-header {
  left: var(--sidebar-collapsed-width);
}

.header-left {
  display: flex;
  align-items: center;
}

.menu-toggle {
  cursor: pointer;
  padding: 10px;
  margin-right: 15px;
}

.header-search {
  margin-right: auto;
}

.header-right {
  display: flex;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  margin-left: 15px;
}

.user-name {
  margin-right: 10px;
}

.user-avatar {
  width: 35px;
  height: 35px;
  border-radius: 50%;
  object-fit: cover;
  background-color: #eee;
}

/* ============= SIDEBAR STYLES ============= */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background-color: var(--dark-color);
  color: white;
  overflow-y: auto;
  z-index: 1001;
  transition: width 0.3s ease, left 0.3s ease;
}

.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed-width);
}

.sidebar-header {
  padding: 15px;
  display: flex;
  align-items: center;
  height: var(--header-height);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo {
  max-height: 40px;
}

.sidebar-title {
  margin-left: 10px;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.3s;
}

.sidebar-collapsed .sidebar-title {
  opacity: 0;
  display: none;
}

.sidebar-menu {
  padding: 15px 0;
}

.sidebar-menu ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-menu li {
  margin-bottom: 5px;
}

.sidebar-menu a {
  display: flex;
  align-items: center;
  padding: 10px 15px;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  transition: all 0.3s;
}

.sidebar-menu a:hover,
.sidebar-menu a.active {
  color: white;
  background-color: rgba(255, 255, 255, 0.1);
}

.sidebar-menu .menu-icon {
  margin-right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
}

.sidebar-menu .menu-text {
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.3s;
}

.sidebar-collapsed .sidebar-menu .menu-text {
  opacity: 0;
  display: none;
}

.sidebar-menu .menu-badge {
  margin-left: auto;
  opacity: 1;
  transition: opacity 0.3s;
}

.sidebar-collapsed .sidebar-menu .menu-badge {
  opacity: 0;
  display: none;
}

.sidebar-divider {
  height: 1px;
  background-color: rgba(255, 255, 255, 0.1);
  margin: 15px 15px;
}

/* ============= FOOTER STYLES ============= */
.main-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: white;
  padding: 10px 15px;
  text-align: center;
  box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
  color: var(--secondary-color);
  font-size: 14px;
  height: var(--footer-height);
  z-index: 1000;
  transition: left 0.3s;
  left: var(--sidebar-width);
}

.sidebar-collapsed .main-footer {
  left: var(--sidebar-collapsed-width);
}

/* ============= CARD STYLES ============= */
.card {
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
  margin-bottom: 20px;
  background-color: white;
}

.card-header {
  border-bottom: 1px solid #eee;
  padding: 15px 20px;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-body {
  padding: 20px;
}

.card-footer {
  border-top: 1px solid #eee;
  padding: 15px 20px;
}

/* ============= STATS CARD STYLES ============= */
.stats-card {
  border-left: 4px solid var(--primary-color);
  transition: transform 0.3s;
}

.stats-card:hover {
  transform: translateY(-5px);
}

.stats-card.border-primary {
  border-left-color: var(--primary-color);
}

.stats-card.border-success {
  border-left-color: var(--success-color);
}

.stats-card.border-warning {
  border-left-color: var(--warning-color);
}

.stats-card.border-danger {
  border-left-color: var(--danger-color);
}

.stats-card.border-info {
  border-left-color: var(--info-color);
}

.stats-card .icon {
  font-size: 2rem;
  color: rgba(0, 0, 0, 0.15);
}

.stats-card .count {
  font-size: 2rem;
  font-weight: bold;
}

.stats-card .title {
  color: var(--secondary-color);
  font-size: 0.9rem;
}

/* ============= TABLE STYLES ============= */
.table-responsive {
  overflow-x: auto;
}

.table {
  width: 100%;
  margin-bottom: 0;
}

.data-table th {
  background-color: #f8f9fa;
  font-weight: 600;
}

.data-table th,
.data-table td {
  padding: 12px 15px;
  vertical-align: middle;
}

.data-table tr:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

/* ============= FORM STYLES ============= */
.form-control:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

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

.form-label {
  margin-bottom: 0.5rem;
  font-weight: 500;
}

.help-text {
  font-size: 0.85rem;
  color: var(--secondary-color);
  margin-top: 0.25rem;
}

/* ============= BUTTON STYLES ============= */
.btn {
  border-radius: 4px;
  padding: 0.375rem 1rem;
  font-weight: 500;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon i {
  margin-right: 0.5rem;
}

/* ============= BADGE STYLES ============= */
.badge {
  padding: 0.35em 0.65em;
  font-weight: 600;
  border-radius: 4px;
}

.badge-pending {
  background-color: var(--warning-color);
  color: #212529;
}

.badge-in-progress {
  background-color: var(--info-color);
  color: #212529;
}

.badge-approved {
  background-color: var(--primary-color);
  color: white;
}

.badge-completed {
  background-color: var(--success-color);
  color: white;
}

.badge-rejected {
  background-color: var(--danger-color);
  color: white;
}

/* ============= ALERT STYLES ============= */
.alert {
  border-radius: 4px;
  margin-bottom: 20px;
}

/* ============= UTILS ============= */
.cursor-pointer {
  cursor: pointer;
}

.text-sm {
  font-size: 0.85rem;
}

.text-lg {
  font-size: 1.25rem;
}

.bg-light-hover:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

/* ============= RESPONSIVE STYLES ============= */
@media (max-width: 991.98px) {
  :root {
    --sidebar-width: 220px;
  }

  .stats-card .icon {
    font-size: 1.5rem;
  }

  .stats-card .count {
    font-size: 1.5rem;
  }
}

/* สไตล์สำหรับมือถือ */
@media (max-width: 767.98px) {
  /* การตั้งค่า sidebar สำหรับมือถือ */
  .sidebar {
    position: fixed;
    top: 0;
    left: -280px; /* เริ่มต้นอยู่นอกหน้าจอ */
    bottom: 0;
    width: 280px;
    z-index: 1050;
    transition: left 0.3s ease;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
  }

  .sidebar.show {
    left: 0;
  }

  /* ส่วนของเนื้อหาบนมือถือ */
  .main-header,
  .main-footer,
  .page-content {
    margin-left: 0 !important;
    left: 0 !important;
    width: 100%;
  }

  .page-content {
    padding: 15px;
  }

  .card-header,
  .card-body,
  .card-footer {
    padding: 15px;
  }

  /* ปุ่ม hamburger บนมือถือ */
  .menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    cursor: pointer;
  }

  /* ข้อความในเมนูต้องแสดงบนมือถือ */
  .sidebar-menu .menu-text {
    display: block !important;
    opacity: 1 !important;
    white-space: normal; /* ให้ข้อความขึ้นบรรทัดใหม่ได้ */
    line-height: 1.4;
    width: calc(100% - 40px); /* หักพื้นที่ไอคอน */
  }

  /* ชื่อโรงเรียนในเมนูต้องแสดงบนมือถือ */
  .sidebar-title {
    display: block !important;
    opacity: 1 !important;
  }

  /* badge ต้องแสดงบนมือถือ */
  .sidebar-menu .menu-badge {
    display: inline-block !important;
    opacity: 1 !important;
  }

  /* รายการเมนูบนมือถือ */
  .sidebar-menu a {
    white-space: normal;
    padding: 12px 15px;
    line-height: 1.4;
  }

  /* ครอบคลุมหน้าจอด้วย overlay */
  body.mobile-sidebar-open::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1040;
  }
}

/* ============= PRINT STYLES ============= */
@media print {
  body {
    background-color: white;
  }

  .sidebar,
  .main-header,
  .main-footer,
  .no-print {
    display: none !important;
  }

  .page-content {
    margin: 0 !important;
    padding: 0 !important;
  }

  .card {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}

/* ============= LANDING PAGE STYLES ============= */
.landing-page {
  background-color: white;
}

.hero-section {
  background: linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.6)),
    url("../images/school.jpg");
  background-size: cover;
  background-position: center;
  color: white;
  text-align: center;
  padding: 100px 0;
}

.hero-title {
  font-size: 2.5rem;
  font-weight: bold;
  margin-bottom: 20px;
}

.hero-subtitle {
  font-size: 1.2rem;
  margin-bottom: 30px;
}

.feature-section {
  padding: 60px 0;
}

.feature-card {
  text-align: center;
  padding: 30px;
  transition: transform 0.3s;
}

.feature-card:hover {
  transform: translateY(-10px);
}

.feature-icon {
  font-size: 2.5rem;
  color: var(--primary-color);
  margin-bottom: 20px;
}

.feature-title {
  font-size: 1.25rem;
  font-weight: bold;
  margin-bottom: 15px;
}

.feature-description {
  color: var(--secondary-color);
}

.cta-section {
  background-color: var(--light-color);
  padding: 60px 0;
  text-align: center;
}

.cta-title {
  font-size: 2rem;
  font-weight: bold;
  margin-bottom: 20px;
}

.cta-description {
  margin-bottom: 30px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

/* ============= LOGIN PAGE STYLES ============= */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0143a3, #0273d4);
}

.login-box {
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  width: 400px;
  max-width: 100%;
}

.login-header {
  background-color: #f8f9fa;
  padding: 20px;
  text-align: center;
  border-bottom: 1px solid #eee;
}

.login-logo {
  max-height: 70px;
  margin-bottom: 10px;
}

.login-title {
  font-size: 1.25rem;
  font-weight: bold;
  margin-bottom: 0;
}

.login-body {
  padding: 30px;
}

.login-footer {
  padding: 15px;
  text-align: center;
  background-color: #f8f9fa;
  border-top: 1px solid #eee;
  font-size: 0.9rem;
  color: var(--secondary-color);
}

/* 
 * เพิ่ม CSS ต่อไปนี้ที่ท้ายไฟล์ style.css
 * เพื่อแก้ไขปัญหา sidebar บน mobile
 */

/* ============= SIDEBAR MOBILE FIX ============= */
@media (max-width: 767.98px) {
  /* แก้ไขปัญหาข้อความในเมนูที่ไม่แสดงหรือแสดงไม่ครบ */
  .sidebar-menu .menu-text {
    display: block !important;
    opacity: 1 !important;
    transition: none !important; /* ยกเลิก transition บน mobile */
    visibility: visible !important;
  }

  .sidebar-title {
    display: block !important;
    opacity: 1 !important;
    transition: none !important; /* ยกเลิก transition บน mobile */
    visibility: visible !important;
  }

  .sidebar-menu .menu-badge {
    display: inline-block !important;
    opacity: 1 !important;
    transition: none !important;
    visibility: visible !important;
  }

  /* บังคับให้ sidebar แสดงอย่างถูกต้องโดยไม่ต้อง refresh */
  .sidebar.show .menu-text,
  .sidebar.show .sidebar-title,
  .sidebar.show .menu-badge {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
  }

  /* ปรับแต่ง animation ของ sidebar ให้ทำงานได้ดีขึ้น */
  .sidebar {
    transition: left 0.3s ease !important;
    will-change: left;
  }
}

/* ============= SIDEBAR PC FIX ============= */
/* แก้ไขปัญหา sidebar บน PC */
@media (min-width: 768px) {
  /* ทำให้การเปลี่ยนแปลง sidebar มีความเสถียรมากขึ้น */
  .sidebar {
    transition: width 0.3s ease;
    will-change: width;
  }

  .sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
  }

  /* ปรับให้ header และ footer เปลี่ยนแปลงตาม sidebar อย่างราบรื่น */
  .main-header,
  .main-footer,
  .page-content {
    transition: margin-left 0.3s ease, left 0.3s ease;
    will-change: margin-left, left;
  }
}
