/* ============================================================
   ระบบบันทึกคะแนนความสะอาดห้องเรียน
   โรงเรียนพุทธชินราชพิทยา
   Main Stylesheet
   ============================================================ */

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

:root {
  --primary:     #4C0026;
  --primary-dark:#380019;
  --secondary:   #8a2c57;
  --gold:        #FFD34D;
  --gold-dark:   #e6b800;
  --excellent:   #198754;
  --good:        #0d6efd;
  --fair:        #fd7e14;
  --poor:        #dc3545;
  --bg-gradient: linear-gradient(135deg, #4C0026 0%, #8a2c57 60%, #4C0026 100%);
  --card-radius: 18px;
  --shadow:      0 4px 24px rgba(76,0,38,.18);
  --shadow-lg:   0 8px 40px rgba(76,0,38,.28);
}

* { box-sizing: border-box; }

body {
  font-family: 'Sarabun', sans-serif;
  font-size: 16px;
  background: var(--bg-gradient);
  min-height: 100vh;
  color: #2d2d2d;
}

/* ---- Typography ------------------------------------------ */
h1,h2,h3,h4,h5,h6 { font-weight: 700; }
.text-gold { color: var(--gold) !important; }
.text-primary-custom { color: var(--primary) !important; }

/* ---- Layout Wrapper -------------------------------------- */
#app-wrapper {
  display: flex;
  min-height: 100vh;
}
#main-content {
  flex: 1;
  min-width: 0;
  padding: 24px;
  transition: margin-left .25s;
}
@media (max-width: 768px) {
  #main-content { padding: 12px; }
}

/* ---- Navbar ---------------------------------------------- */
.navbar-custom {
  background: var(--primary-dark);
  border-bottom: 3px solid var(--gold);
  padding: 0 1rem;
  min-height: 60px;
  position: sticky;
  top: 0;
  z-index: 1030;
  box-shadow: 0 2px 12px rgba(0,0,0,.3);
}
.navbar-custom .navbar-brand {
  color: var(--gold) !important;
  font-weight: 800;
  font-size: 1.05rem;
  line-height: 1.2;
}
.navbar-custom .nav-link {
  color: rgba(255,255,255,.85) !important;
  font-weight: 500;
  transition: color .2s;
}
.navbar-custom .nav-link:hover { color: var(--gold) !important; }
.navbar-custom .navbar-toggler { border-color: var(--gold); }
.navbar-custom .navbar-toggler-icon {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='%23FFD34D' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}
.navbar-role-badge {
  background: var(--gold);
  color: var(--primary);
  font-size: .75rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 20px;
}

/* ---- Sidebar --------------------------------------------- */
#sidebar {
  width: 250px;
  min-height: calc(100vh - 60px);
  background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  flex-shrink: 0;
  transition: width .25s, transform .25s;
  z-index: 1020;
  border-right: 2px solid rgba(255,211,77,.2);
}
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--secondary); border-radius: 4px; }

.sidebar-header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid rgba(255,211,77,.2);
  text-align: center;
}
.sidebar-header .school-name {
  color: var(--gold);
  font-weight: 800;
  font-size: .9rem;
  line-height: 1.3;
}
.sidebar-header .dept-name {
  color: rgba(255,255,255,.7);
  font-size: .75rem;
}

.sidebar-menu { padding: 8px 0; list-style: none; margin: 0; }
.sidebar-menu .menu-section {
  padding: 12px 16px 4px;
  color: var(--gold);
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: .8;
}
.sidebar-menu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: rgba(255,255,255,.85);
  text-decoration: none;
  font-size: .9rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all .2s;
}
.sidebar-menu a:hover,
.sidebar-menu a.active {
  background: rgba(255,211,77,.1);
  color: var(--gold);
  border-left-color: var(--gold);
}
.sidebar-menu a .bi { font-size: 1rem; flex-shrink: 0; }

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    top: 60px;
    left: 0;
    transform: translateX(-100%);
    height: calc(100vh - 60px);
    z-index: 1040;
    box-shadow: 4px 0 20px rgba(0,0,0,.4);
  }
  #sidebar.show { transform: translateX(0); }
  #sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: 60px;
    background: rgba(0,0,0,.5);
    z-index: 1035;
  }
  #sidebar-backdrop.show { display: block; }
}

/* ---- Cards ----------------------------------------------- */
.card {
  border: none;
  border-radius: var(--card-radius) !important;
  box-shadow: var(--shadow);
  background: #fff;
}
.card-header-custom {
  background: linear-gradient(90deg, var(--primary) 0%, var(--secondary) 100%);
  color: #fff;
  border-radius: var(--card-radius) var(--card-radius) 0 0 !important;
  padding: 14px 20px;
  font-weight: 700;
}
.card-stat {
  background: #fff;
  border-radius: var(--card-radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: transform .2s, box-shadow .2s;
  border-left: 5px solid var(--primary);
}
.card-stat:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}
.card-stat .stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}
.card-stat .stat-label {
  font-size: .85rem;
  color: #6c757d;
  margin-top: 4px;
}
.card-stat .stat-icon {
  font-size: 2.5rem;
  opacity: .15;
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
}
.card-stat { position: relative; overflow: hidden; }

/* Color variants */
.card-stat.cs-gold    { border-left-color: var(--gold); }
.card-stat.cs-gold    .stat-value { color: var(--gold-dark); }
.card-stat.cs-success { border-left-color: var(--excellent); }
.card-stat.cs-success .stat-value { color: var(--excellent); }
.card-stat.cs-danger  { border-left-color: var(--poor); }
.card-stat.cs-danger  .stat-value { color: var(--poor); }
.card-stat.cs-info    { border-left-color: #0dcaf0; }
.card-stat.cs-info    .stat-value { color: #087990; }

/* ---- Buttons --------------------------------------------- */
.btn-gold {
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%);
  color: var(--primary);
  font-weight: 700;
  border: none;
  border-radius: 10px;
  padding: 10px 24px;
  box-shadow: 0 2px 8px rgba(255,211,77,.4);
  transition: all .2s;
}
.btn-gold:hover {
  background: linear-gradient(135deg, #ffe066 0%, var(--gold) 100%);
  color: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(255,211,77,.5);
}
.btn-primary-custom {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-weight: 600;
}
.btn-primary-custom:hover {
  background: var(--primary-dark);
  color: #fff;
}
.btn-score {
  min-width: 52px;
  min-height: 52px;
  font-size: 1.3rem;
  font-weight: 800;
  border-radius: 12px;
  border: 2px solid #dee2e6;
  background: #f8f9fa;
  color: #495057;
  transition: all .15s;
  cursor: pointer;
}
.btn-score.selected {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(76,0,38,.3);
}
.btn-score:hover:not(.selected) {
  border-color: var(--secondary);
  background: rgba(138,44,87,.08);
}

/* ---- Score Badges ---------------------------------------- */
.badge { font-size: .78rem; padding: 4px 10px; border-radius: 20px; font-weight: 600; }
.badge-excellent { background: #d1e7dd; color: #0a3622; }
.badge-good      { background: #cfe2ff; color: #084298; }
.badge-fair      { background: #fff3cd; color: #664d03; }
.badge-poor      { background: #f8d7da; color: #58151c; }

/* Score colors */
.score-excellent { color: var(--excellent) !important; }
.score-good      { color: var(--good) !important; }
.score-fair      { color: var(--fair) !important; }
.score-poor      { color: var(--poor) !important; }

/* ---- Page Header ----------------------------------------- */
.page-header {
  background: rgba(255,255,255,.05);
  border-radius: var(--card-radius);
  padding: 16px 20px;
  margin-bottom: 20px;
  border-left: 4px solid var(--gold);
  backdrop-filter: blur(4px);
}
.page-header h4 {
  color: #fff;
  margin: 0;
  font-weight: 700;
}
.page-header .breadcrumb {
  background: none;
  padding: 0;
  margin: 0;
}
.page-header .breadcrumb-item,
.page-header .breadcrumb-item a { color: rgba(255,255,255,.7); font-size: .85rem; }
.page-header .breadcrumb-item.active { color: var(--gold); }

/* ---- Tables ---------------------------------------------- */
.table-custom thead th {
  background: linear-gradient(90deg, var(--primary) 0%, var(--secondary) 100%);
  color: #fff;
  font-weight: 600;
  border: none;
  padding: 12px 14px;
  white-space: nowrap;
}
.table-custom tbody tr:hover { background: rgba(76,0,38,.04); }
.table-custom td { vertical-align: middle; padding: 10px 14px; }

/* ---- Ranking Table --------------------------------------- */
.rank-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: .9rem;
}
.rank-1 { background: linear-gradient(135deg,#FFD700,#FFA500); color: #fff; }
.rank-2 { background: linear-gradient(135deg,#C0C0C0,#A0A0A0); color: #fff; }
.rank-3 { background: linear-gradient(135deg,#CD7F32,#8B4513); color: #fff; }
.rank-other { background: #e9ecef; color: #6c757d; }

/* ---- Check Form ------------------------------------------ */
.eval-item-card {
  background: #fff;
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  border: 2px solid transparent;
  transition: border-color .2s;
}
.eval-item-card.has-score { border-color: var(--primary); }
.eval-item-title {
  font-weight: 700;
  color: var(--primary);
  font-size: .95rem;
  margin-bottom: 8px;
}
.eval-item-desc { color: #6c757d; font-size: .82rem; margin-bottom: 10px; }
.score-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Total Score Display --------------------------------- */
#total-score-display {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: #fff;
  border-radius: var(--card-radius);
  padding: 20px;
  text-align: center;
  position: sticky;
  top: 80px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
}
#total-score-num {
  font-size: 3.5rem;
  font-weight: 900;
  color: var(--gold);
  line-height: 1;
}
#total-score-label { font-size: .9rem; opacity: .9; }
#total-score-status { font-size: 1rem; font-weight: 700; margin-top: 6px; }
#score-progress { height: 8px; border-radius: 4px; margin-top: 10px; }

/* ---- Progress Bar ---------------------------------------- */
.progress-custom { height: 10px; border-radius: 10px; background: rgba(255,255,255,.2); }
.progress-custom .progress-bar { border-radius: 10px; background: var(--gold); }

/* ---- Photo Upload ---------------------------------------- */
.photo-upload-area {
  border: 2px dashed var(--secondary);
  border-radius: 14px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  background: rgba(138,44,87,.03);
}
.photo-upload-area:hover { border-color: var(--primary); background: rgba(76,0,38,.06); }
.photo-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.photo-preview-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.photo-preview-item img { width: 100%; height: 100%; object-fit: cover; }
.photo-preview-item .remove-photo {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  background: rgba(220,53,69,.9);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: .7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Room Grid (Today's Check) --------------------------- */
.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
}
.room-card {
  background: #fff;
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  cursor: pointer;
  transition: all .2s;
  border: 2px solid transparent;
  text-decoration: none;
  display: block;
  color: inherit;
}
.room-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.room-card.checked {
  background: linear-gradient(135deg, #d1e7dd, #a8d5b5);
  border-color: #198754;
}
.room-card.checked .room-name { color: #0a3622; }
.room-card.unchecked { border-color: #dee2e6; }
.room-card.unchecked:hover { border-color: var(--primary); }
.room-name { font-weight: 700; font-size: .9rem; color: var(--primary); }
.room-score { font-size: .75rem; color: #6c757d; margin-top: 2px; }
.room-icon { font-size: 1.2rem; margin-bottom: 4px; }

/* ---- Dashboard Hero (Public) ----------------------------- */
.hero-section {
  background: rgba(255,255,255,.06);
  backdrop-filter: blur(8px);
  border-radius: 24px;
  padding: 40px 32px;
  text-align: center;
  border: 1px solid rgba(255,211,77,.2);
  margin-bottom: 28px;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
}
.hero-title { color: var(--gold); font-size: 1.8rem; font-weight: 900; line-height: 1.2; }
.hero-subtitle { color: rgba(255,255,255,.8); font-size: 1rem; }
.hero-school { color: #fff; font-size: 1.1rem; font-weight: 700; }
.hero-dept { color: rgba(255,211,77,.7); font-size: .85rem; }

/* ---- Alert Toast ----------------------------------------- */
.toast-container { z-index: 9999; }
.toast { border-radius: 14px; font-family: 'Sarabun', sans-serif; }

/* ---- Alert Inline ---------------------------------------- */
.alert { border-radius: 12px; border: none; font-weight: 500; }
.alert-photo-required {
  background: linear-gradient(90deg, #fff3cd, #ffeeba);
  color: #856404;
  border-left: 4px solid #ffc107;
  border-radius: 10px;
  padding: 12px 16px;
}

/* ---- Print Styles ---------------------------------------- */
@media print {
  body { background: #fff !important; font-size: 14px; }
  #sidebar, #navbar, .btn, .no-print, .navbar-custom { display: none !important; }
  #main-content { padding: 0 !important; margin: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #ccc !important; }
  .page-break { page-break-before: always; }
  .table th, .table td { padding: 6px 8px !important; }
}
@page { size: A4; margin: 15mm; }

/* ---- Utility --------------------------------------------- */
.fw-800 { font-weight: 800; }
.rounded-18 { border-radius: 18px !important; }
.bg-gradient-primary {
  background: var(--bg-gradient) !important;
}
.text-shadow { text-shadow: 0 2px 4px rgba(0,0,0,.3); }
.glass-card {
  background: rgba(255,255,255,.08);
  backdrop-filter: blur(8px);
  border-radius: var(--card-radius);
  border: 1px solid rgba(255,255,255,.12);
  color: #fff;
}

/* ---- Responsive Overrides -------------------------------- */
@media (max-width: 576px) {
  .hero-title { font-size: 1.3rem; }
  .card-stat .stat-value { font-size: 1.6rem; }
  #total-score-num { font-size: 2.5rem; }
  .btn-score { min-width: 44px; min-height: 44px; font-size: 1.1rem; }
  .room-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
}

/* ---- QR Code --------------------------------------------- */
.qr-container {
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  display: inline-block;
  box-shadow: var(--shadow);
}

/* ---- Scrollbar ------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,.05); }
::-webkit-scrollbar-thumb { background: var(--secondary); border-radius: 4px; }

/* ---- Loading Spinner ------------------------------------- */
.spinner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(76,0,38,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.spinner-overlay .spinner-border { width: 3rem; height: 3rem; color: var(--gold); }

/* ---- Level Section Header -------------------------------- */
.level-section-header {
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  color: #fff;
  border-radius: 12px;
  padding: 10px 18px;
  margin-bottom: 12px;
  margin-top: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---- Award Card ------------------------------------------ */
.award-card {
  background: linear-gradient(135deg, #fff9e6, #fff3cd);
  border: 2px solid var(--gold);
  border-radius: var(--card-radius);
  padding: 20px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(255,211,77,.3);
}
.award-card .trophy { font-size: 3rem; line-height: 1; margin-bottom: 8px; }
.award-card .award-title { font-weight: 800; color: var(--primary); font-size: 1rem; }
.award-card .award-room { font-size: 1.4rem; font-weight: 900; color: var(--gold-dark); }
.award-card .award-score { color: var(--secondary); font-weight: 600; }

/* ---- Report Styles --------------------------------------- */
.report-wrapper {
  background: #fff;
  padding: 30px 40px;
  max-width: 800px;
  margin: 0 auto;
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
}
.report-header { text-align: center; margin-bottom: 20px; border-bottom: 3px double var(--primary); padding-bottom: 16px; }
.report-header .school-name { font-size: 1.2rem; font-weight: 800; color: var(--primary); }
.report-header .report-title { font-size: 1rem; font-weight: 700; color: var(--secondary); }
.report-header .report-period { font-size: .9rem; color: #666; }
.report-signature { margin-top: 40px; display: grid; grid-template-columns: repeat(3,1fr); gap: 20px; text-align: center; }
.report-signature .sig-line { border-top: 1px solid #333; margin: 40px 10px 6px; }
.report-signature .sig-title { font-weight: 700; font-size: .85rem; }
.report-signature .sig-detail { font-size: .75rem; color: #666; }
