/* ===== Modern School Theme: Blue-Yellow โทนสว่าง ===== */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  /* School Colors - น้ำเงิน–เหลือง โทนสว่าง (Light Blue & Bright Yellow) */
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #60a5fa;
  --primary-pale: #dbeafe;
  --primary-ghost: #eff6ff;
  
  --accent: #eab308;
  --accent-dark: #ca8a04;
  --accent-light: #fde047;
  --accent-pale: #fef9c3;
  --accent-ghost: #fefce8;
  
  /* Neutrals */
  --white: #ffffff;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  
  /* Status */
  --success: #10b981;
  --success-pale: #d1fae5;
  --danger: #ef4444;
  --danger-pale: #fee2e2;
  --warning: #f59e0b;
  --warning-pale: #fef3c7;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  
  /* Radius */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Sarabun', 'TH Sarabun New', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 17px;
  line-height: 1.7;
  color: var(--gray-700);
  background: linear-gradient(160deg, #ffffff 0%, var(--primary-ghost) 40%, var(--accent-ghost) 100%);
  min-height: 100vh;
  letter-spacing: 0.01em;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: all 0.2s ease;
}

a:hover {
  color: var(--primary-dark);
}

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 50%, #93c5fd 100%);
  position: relative;
  overflow: hidden;
}

.header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  opacity: 0.5;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  position: relative;
  z-index: 1;
}

.header-logo-img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  flex-shrink: 0;
}

.header-content {
  flex: 1;
}

.header-title {
  color: var(--white);
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-subtitle {
  color: rgba(255,255,255,0.85);
  font-size: 14px;
  font-weight: 300;
}

.header-badge {
  background: var(--accent);
  color: var(--gray-900);
  padding: 8px 20px;
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 13px;
  box-shadow: var(--shadow-md);
}

/* ===== Container ===== */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

/* ===== Page Header ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-800);
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-title-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  font-size: 24px;
  box-shadow: var(--shadow-md);
}

.page-subtitle {
  color: var(--gray-500);
  font-size: 17px;
  font-weight: 400;
  margin-top: 4px;
}

.page-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ===== Stats Cards ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-100);
  transition: all 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.stat-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}

.stat-icon.blue {
  background: var(--primary-pale);
  color: var(--primary);
}

.stat-icon.yellow {
  background: var(--accent-pale);
  color: var(--accent-dark);
}

.stat-icon.green {
  background: var(--success-pale);
  color: var(--success);
}

.stat-icon.purple {
  background: #f3e8ff;
  color: #7c3aed;
}

.stat-info h3 {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-800);
  line-height: 1;
}

.stat-info p {
  font-size: 16px;
  color: var(--gray-500);
  margin-top: 4px;
}

/* ===== Cards ===== */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-100);
  overflow: hidden;
  margin-bottom: 20px;
}

.card-header {
  background: linear-gradient(90deg, var(--gray-50) 0%, var(--white) 100%);
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-header-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  font-size: 18px;
}

.card-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-700);
}

.card-body {
  padding: 20px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: none;
  font-family: inherit;
  font-size: 17px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  transform: translateY(-1px);
  text-decoration: none;
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: var(--white);
  box-shadow: 0 4px 14px 0 rgba(37, 99, 235, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: var(--white);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.45);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
  color: var(--gray-900);
  box-shadow: 0 4px 14px 0 rgba(234, 179, 8, 0.35);
}

.btn-accent:hover {
  background: linear-gradient(135deg, var(--accent-dark) 0%, var(--accent) 100%);
  box-shadow: 0 6px 20px rgba(234, 179, 8, 0.45);
}

.btn-outline {
  background: var(--white);
  color: var(--gray-700);
  border: 2px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-ghost);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger) 0%, #f87171 100%);
  color: var(--white);
  box-shadow: 0 4px 14px 0 rgba(239, 68, 68, 0.35);
}

.btn-danger:hover {
  background: linear-gradient(135deg, #dc2626 0%, var(--danger) 100%);
  color: var(--white);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 14px 28px;
  font-size: 16px;
  border-radius: var(--radius);
}

/* ===== Forms ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 16px;
  font-weight: 500;
  color: var(--gray-600);
  display: flex;
  align-items: center;
  gap: 4px;
}

.form-label .required {
  color: var(--danger);
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 17px;
  color: var(--gray-700);
  background: var(--white);
  transition: all 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-pale);
}

.form-control:disabled {
  background: var(--gray-100);
  color: var(--gray-500);
  cursor: not-allowed;
}

.form-control::placeholder {
  color: var(--gray-400);
}

textarea.form-control {
  min-height: 100px;
  resize: vertical;
}

select.form-control {
  cursor: pointer;
}

.form-hint {
  font-size: 16px;
  color: var(--gray-500);
}

.form-hint-danger {
  color: var(--danger);
  font-weight: 600;
}

.form-readonly {
  background: var(--accent-ghost) !important;
  border-color: var(--accent-pale) !important;
  font-weight: 600;
}

/* Column classes */
.col-1 { grid-column: span 1; }
.col-2 { grid-column: span 2; }
.col-3 { grid-column: span 3; }
.col-4 { grid-column: span 4; }
.col-5 { grid-column: span 5; }
.col-6 { grid-column: span 6; }
.col-7 { grid-column: span 7; }
.col-8 { grid-column: span 8; }
.col-9 { grid-column: span 9; }
.col-10 { grid-column: span 10; }
.col-11 { grid-column: span 11; }
.col-12 { grid-column: span 12; }

/* ===== Tables ===== */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1000px;
}

thead {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
}

th {
  padding: 14px 16px;
  text-align: left;
  font-size: 17px;
  font-weight: 600;
  color: var(--white);
  white-space: nowrap;
}

th:first-child {
  border-radius: var(--radius) 0 0 0;
}

th:last-child {
  border-radius: 0 var(--radius) 0 0;
}

tbody tr {
  transition: all 0.15s ease;
}

tbody tr:nth-child(even) {
  background: var(--gray-50);
}

tbody tr:hover {
  background: var(--primary-ghost);
}

td {
  padding: 14px 16px;
  font-size: 17px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

/* ===== M.4: applicants table (public) ===== */
.m4-applicants-table {
  min-width: 1200px; /* ให้คอลัมน์อันดับ 1-5 มีพื้นที่พอ */
}

.m4-applicants-table th.m4-choice-col,
.m4-applicants-table td.m4-choice-col {
  min-width: 160px;       /* ขยายความกว้างคอลัมน์ */
  font-size: 14px;        /* ลดขนาดตัวอักษร */
  line-height: 1.25;
  white-space: nowrap;    /* แสดงบรรทัดเดียว */
}

/* ===== Admin M.1: applicants table ===== */
.admin-applicants-table {
  width: 100%;
  min-width: 0 !important;
  table-layout: fixed;
}

.admin-applicants-table th,
.admin-applicants-table td {
  font-size: 13px;
  white-space: normal;
  word-break: break-word;
  line-height: 1.35;
  padding: 8px 8px;
  vertical-align: top;
  overflow: hidden;
}

.admin-applicants-table th {
  width: auto !important;
}

.admin-applicants-table th:nth-child(1) { width: 4% !important; }
.admin-applicants-table th:nth-child(2) { width: 9% !important; }
.admin-applicants-table th:nth-child(3) { width: 10% !important; }
.admin-applicants-table th:nth-child(4) { width: 10% !important; }
.admin-applicants-table th:nth-child(5) { width: 16% !important; }
.admin-applicants-table th:nth-child(6) { width: 14% !important; }
.admin-applicants-table th:nth-child(7) { width: 12% !important; }
.admin-applicants-table th:nth-child(8) { width: 10% !important; }
.admin-applicants-table th:nth-child(9) { width: 11% !important; }

.admin-applicants-table td:nth-child(5) .font-bold {
  font-size: 16px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.admin-applicants-table .name-line-2 {
  display: block;
}

.admin-applicants-table .actions {
  flex-wrap: wrap;
  gap: 4px;
}

.admin-applicants-table .btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.table-empty {
  text-align: center;
  padding: 60px 20px !important;
  color: var(--gray-400);
}

.table-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
}

.badge-blue {
  background: var(--primary-pale);
  color: var(--primary-dark);
}

.badge-yellow {
  background: var(--accent-pale);
  color: var(--accent-dark);
}

.badge-green {
  background: var(--success-pale);
  color: var(--success);
}

.badge-red {
  background: var(--danger-pale);
  color: var(--danger);
}

/* ===== Alerts ===== */
.alert {
  padding: 16px 20px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 500;
}

.alert-icon {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.alert-success {
  background: var(--success-pale);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-success .alert-icon {
  background: var(--success);
  color: var(--white);
}

.alert-error {
  background: var(--danger-pale);
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-error .alert-icon {
  background: var(--danger);
  color: var(--white);
}

/* ===== Info Box ===== */
.info-box {
  background: var(--accent-ghost);
  border-left: 4px solid var(--accent);
  padding: 14px 18px;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 13px;
  color: var(--gray-600);
  margin-top: 20px;
}

/* ===== Actions ===== */
.actions {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  align-items: center;
}

/* ===== Data Display ===== */
.data-value {
  font-size: 15px;
  color: var(--gray-800);
  font-weight: 500;
}

.data-value.highlight {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
}

.data-value.mono {
  font-family: 'SF Mono', 'Consolas', 'Liberation Mono', Menlo, monospace;
  font-size: 14px;
}

/* ===== Grade Cards ===== */
.grade-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.grade-card {
  background: linear-gradient(135deg, var(--primary-ghost) 0%, var(--white) 100%);
  border: 2px solid var(--primary-pale);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  transition: all 0.3s ease;
}

.grade-card:nth-child(2n) {
  background: linear-gradient(135deg, var(--accent-ghost) 0%, var(--white) 100%);
  border-color: var(--accent-pale);
}

.grade-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.grade-label {
  font-size: 12px;
  color: var(--gray-500);
  font-weight: 500;
  margin-bottom: 8px;
}

.grade-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary-dark);
}

.grade-card:nth-child(2n) .grade-value {
  color: var(--accent-dark);
}

/* ===== เน้นคำว่า "ประเภทห้องเรียน" ทุกหน้า - ตัวใหญ่ชัดเจน ป้องกันสับสน ===== */
.room-type-emphasis {
  font-size: 1.35em;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: var(--primary-dark);
  text-transform: uppercase;
  display: inline;
}

/* เน้นคำว่า "ห้องเรียนปกติ" ในหัวข้อหลัก */
.room-normal-emphasis {
  font-size: 1.25em;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--primary-dark);
  text-transform: uppercase;
  display: inline;
  background: linear-gradient(90deg, var(--primary-pale), var(--accent-pale));
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ===== Section Title ===== */
.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-pale);
}

/* ===== Grade Navigation ===== */
.grade-nav {
  background: var(--gray-100);
  border-bottom: 1px solid var(--gray-200);
}
.grade-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  color: var(--gray-600);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.2s;
}
.grade-nav-btn:hover {
  background: var(--primary-pale);
  border-color: var(--primary-light);
  color: var(--primary);
}
.grade-nav-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--white);
}

/* ===== Utilities ===== */
.text-muted { color: var(--gray-500); }
.text-primary { color: var(--primary); }
.text-accent { color: var(--accent-dark); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-mono { font-family: 'SF Mono', 'Consolas', monospace; }
.font-bold { font-weight: 700; }
.mb-0 { margin-bottom: 0; }
.mb-4 { margin-bottom: 16px; }
.mt-4 { margin-top: 16px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .col-1, .col-2, .col-3, .col-4, .col-5, .col-6 { grid-column: span 6; }
  .col-7, .col-8, .col-9, .col-10, .col-11, .col-12 { grid-column: span 12; }
  .grade-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .header-inner { flex-direction: column; text-align: center; }
  .header-badge { display: none; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .stats-grid { grid-template-columns: 1fr; }
  .col-1, .col-2, .col-3, .col-4, .col-5, .col-6,
  .col-7, .col-8, .col-9, .col-10, .col-11, .col-12 { grid-column: span 12; }
  .grade-grid { grid-template-columns: 1fr 1fr; }
  .container { padding: 16px; }
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.card, .stat-card {
  animation: fadeIn 0.3s ease-out;
}

/* ===== Print ===== */
@media print {
  .header, .btn, .actions, .info-box, .page-actions { display: none !important; }
  body { background: white; }
  .card { box-shadow: none; border: 1px solid #ccc; }
}
