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

:root {
  --primary: #1d4ed8;
  --primary-light: #3b82f6;
  --primary-dark: #1e3a8a;
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --amber: #f59e0b;
  --amber-dark: #b45309;
  --amber-50: #fffbeb;
  --amber-100: #fef3c7;
  --surface: #ffffff;
  --bg: #f1f5f9;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.1), 0 4px 12px rgba(0,0,0,0.05);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.12);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Noto Sans Thai', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 20px;
  width: 100%;
}

/* ===== Background Decoration ===== */
.bg-decoration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.bg-circle {
  position: absolute;
  border-radius: 50%;
  opacity: 0.035;
}

.bg-circle-1 {
  width: 600px;
  height: 600px;
  background: var(--primary);
  top: -200px;
  right: -150px;
  animation: float 20s ease-in-out infinite;
}

.bg-circle-2 {
  width: 400px;
  height: 400px;
  background: var(--amber);
  bottom: -100px;
  left: -100px;
  animation: float 25s ease-in-out infinite reverse;
}

.bg-circle-3 {
  width: 300px;
  height: 300px;
  background: var(--primary-light);
  top: 50%;
  left: 50%;
  animation: float 18s ease-in-out infinite 5s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -30px) scale(1.05); }
  66% { transform: translate(-20px, 20px) scale(0.95); }
}

/* ===== Header ===== */
header {
  position: relative;
  z-index: 1;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
  color: white;
  padding: 48px 0 80px;
  text-align: center;
  overflow: hidden;
}

header::before {
  content: '';
  position: absolute;
  inset: 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.04'%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");
}

.header-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  margin-bottom: 16px;
  border: 1px solid rgba(255,255,255,0.2);
}

.header-icon .material-symbols-rounded {
  font-size: 32px;
}

header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
  position: relative;
}

.subtitle {
  font-size: 0.92rem;
  opacity: 0.8;
  font-weight: 300;
  line-height: 1.7;
  position: relative;
}

/* Stats Cards */
.stats-cards {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 32px;
  position: relative;
}

.stat-card {
  background: rgba(255,255,255,0.12);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--radius-sm);
  padding: 16px 24px;
  min-width: 120px;
  transition: var(--transition);
}

.stat-card:hover {
  background: rgba(255,255,255,0.2);
  transform: translateY(-2px);
}

.stat-card .material-symbols-rounded {
  font-size: 22px;
  opacity: 0.7;
  margin-bottom: 4px;
}

.stat-number {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.78rem;
  opacity: 0.7;
  font-weight: 400;
}

/* ===== Search Section ===== */
.search-section {
  position: relative;
  z-index: 2;
  margin-top: -40px;
}

.search-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xl);
  padding: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  border: 2px solid transparent;
  transition: var(--transition);
}

.search-box:focus-within {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-xl), 0 0 0 4px rgba(59,130,246,0.1);
}

.search-icon {
  padding: 12px;
  color: var(--text-muted);
  font-size: 26px;
  flex-shrink: 0;
}

.search-box input {
  flex: 1;
  padding: 16px 8px;
  border: none;
  font-size: 1.1rem;
  font-family: inherit;
  outline: none;
  background: transparent;
  color: var(--text);
  min-width: 0;
}

.search-box input::placeholder {
  color: var(--text-muted);
  font-weight: 300;
}

.search-clear {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--bg);
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition);
  flex-shrink: 0;
  margin-right: 4px;
}

.search-clear:hover {
  background: #fee2e2;
  color: #dc2626;
}

/* ===== Search Wrapper & Autocomplete ===== */
.search-wrapper {
  position: relative;
}

.autocomplete-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 100;
  margin-top: 4px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border);
  max-height: 420px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.autocomplete-dropdown::-webkit-scrollbar {
  width: 6px;
}

.autocomplete-dropdown::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.autocomplete-list {
  padding: 6px;
}

.ac-section-label {
  padding: 10px 12px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ac-section-label .material-symbols-rounded {
  font-size: 14px;
}

.ac-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.ac-item:hover,
.ac-item.active {
  background: var(--primary-50);
}

.ac-item-code {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-50);
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
  min-width: 75px;
  text-align: center;
  border: 1px solid rgba(29,78,216,0.08);
}

.ac-item.ac-subject .ac-item-code {
  color: var(--amber-dark);
  background: var(--amber-50);
  border-color: rgba(245,158,11,0.1);
  min-width: 85px;
  font-size: 0.73rem;
}

.ac-item-info {
  flex: 1;
  min-width: 0;
}

.ac-item-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ac-item-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.ac-item-badge {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  flex-shrink: 0;
}

.ac-item-badge.pvch {
  background: var(--primary-100);
  color: var(--primary);
}

.ac-item-badge.pvs {
  background: var(--amber-100);
  color: var(--amber-dark);
}

.ac-item-credit {
  font-size: 0.73rem;
  color: var(--text-muted);
  font-weight: 600;
  flex-shrink: 0;
}

.ac-no-result {
  padding: 24px 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.ac-no-result .material-symbols-rounded {
  font-size: 28px;
  display: block;
  margin-bottom: 6px;
  opacity: 0.5;
}

.ac-footer {
  padding: 8px 12px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--bg);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

.ac-footer kbd {
  display: inline-flex;
  align-items: center;
  padding: 1px 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.68rem;
  font-family: inherit;
  margin: 0 2px;
}

/* Filters */
.filters {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.filter-group {
  flex: 1;
}

.filter-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-group label .material-symbols-rounded {
  font-size: 16px;
}

.filter-group select {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  cursor: pointer;
  outline: none;
  color: var(--text);
  transition: var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24'%3E%3Cpath fill='%2394a3b8' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.filter-group select:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

/* Result Stats */
.result-stats {
  text-align: center;
  padding: 20px 0 4px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 400;
}

.result-stats strong {
  color: var(--primary);
  font-weight: 700;
}

/* ===== Results ===== */
.results {
  position: relative;
  z-index: 1;
  margin-top: 8px;
  padding-bottom: 60px;
}

/* Category Header */
.category-group {
  margin-top: 24px;
}

.category-group:first-child {
  margin-top: 0;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 0 10px;
  margin-bottom: 10px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.category-header::after {
  content: '';
  flex: 1;
  height: 2px;
  background: linear-gradient(90deg, var(--border), transparent);
}

.category-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--primary-50);
  border-radius: 8px;
  color: var(--primary);
  flex-shrink: 0;
}

.category-icon .material-symbols-rounded {
  font-size: 18px;
}

.category-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.category-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--border);
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  flex-shrink: 0;
}

/* Result Card */
.result-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
  border: 1px solid transparent;
  cursor: default;
}

.result-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary-100);
  transform: translateY(-1px);
}

.result-code {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-50), var(--primary-100));
  color: var(--primary);
  font-weight: 800;
  font-size: 0.95rem;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  min-width: 72px;
  text-align: center;
  letter-spacing: 0.5px;
  border: 1px solid rgba(29,78,216,0.1);
}

.result-code.pvs {
  background: linear-gradient(135deg, var(--amber-50), var(--amber-100));
  color: var(--amber-dark);
  border-color: rgba(245,158,11,0.15);
}

.result-info {
  flex: 1;
  min-width: 0;
}

.result-name {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 5px;
  line-height: 1.4;
}

.result-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.badge-pvch {
  background: var(--primary-100);
  color: var(--primary);
}

.badge-pvs {
  background: var(--amber-100);
  color: var(--amber-dark);
}

.result-group {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 400;
}

.btn-pdf {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
  transition: var(--transition);
  box-shadow: 0 2px 8px rgba(29,78,216,0.25);
  flex-shrink: 0;
}

.btn-pdf .material-symbols-rounded {
  font-size: 18px;
}

.btn-pdf:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(29,78,216,0.35);
}

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

/* ===== Subject Results ===== */
.subject-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-bottom: 6px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: var(--transition);
  border: 1px solid transparent;
  border-left: 3px solid var(--amber);
  animation: fadeInUp 0.3s ease forwards;
}

.subject-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--amber-100);
  border-left-color: var(--amber);
  transform: translateY(-1px);
}

.subject-code {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--amber-dark);
  background: var(--amber-50);
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  min-width: 90px;
  text-align: center;
  letter-spacing: 0.3px;
  border: 1px solid rgba(245,158,11,0.12);
}

.subject-info {
  flex: 1;
  min-width: 0;
}

.subject-name-th {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.subject-name-en {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 2px;
}

.subject-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.subject-credit {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-50);
  padding: 2px 8px;
  border-radius: 4px;
}

.subject-dept {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.dept-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 0 8px;
  margin-top: 20px;
}

.dept-header:first-child {
  margin-top: 0;
}

.dept-header .dept-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--amber-50), var(--amber-100));
  border-radius: 10px;
  color: var(--amber-dark);
  flex-shrink: 0;
}

.dept-header .dept-icon .material-symbols-rounded {
  font-size: 20px;
}

.dept-header .dept-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
}

.dept-header .dept-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.dept-header .dept-count {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--border);
  padding: 2px 10px;
  border-radius: 20px;
  font-weight: 600;
}

/* Result type tabs */
.result-tabs {
  display: flex;
  gap: 4px;
  margin: 16px 0 8px;
  padding: 4px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.result-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}

.result-tab:hover {
  background: var(--surface);
  color: var(--text);
}

.result-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.result-tab .material-symbols-rounded {
  font-size: 18px;
}

.result-tab .tab-count {
  font-size: 0.75rem;
  background: var(--primary-100);
  color: var(--primary);
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 700;
}

.result-tab.active .tab-count {
  background: var(--primary);
  color: white;
}

/* stat-subjects card */
.stat-subjects .material-symbols-rounded {
  color: #10b981;
}

/* Subject Actions */
.subject-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-find-page {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  background: linear-gradient(135deg, var(--amber-dark), var(--amber));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 2px 8px rgba(245,158,11,0.25);
}

.btn-find-page .material-symbols-rounded {
  font-size: 17px;
}

.btn-find-page:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(245,158,11,0.35);
}

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

.btn-find-page:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

.btn-page-found {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 2px 8px rgba(124,58,237,0.25);
}

.btn-page-found .material-symbols-rounded {
  font-size: 17px;
}

.btn-page-found:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(124,58,237,0.35);
  color: white;
}

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

.spinning {
  animation: spin 1s linear infinite;
}

/* Load More */
.load-more-wrapper {
  text-align: center;
  padding: 20px 0;
}
.btn-load-more {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 24px;
  background: var(--bg-card);
  color: var(--primary);
  border: 1.5px solid var(--primary);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-load-more:hover {
  background: var(--primary);
  color: #fff;
}

/* ===== Subject Detail Panel ===== */
.subject-card {
  cursor: pointer;
  transition: var(--transition);
}

.subject-card:hover {
  background: var(--primary-50);
}

.subject-card-active {
  background: var(--primary-50) !important;
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.subject-detail {
  background: linear-gradient(135deg, #f8fafc, #f0f4ff);
  border: 1px solid var(--primary-100);
  border-top: 2px solid var(--primary-light);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  margin-top: -1px;
  margin-bottom: 8px;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from { opacity: 0; max-height: 0; }
  to { opacity: 1; max-height: 2000px; }
}

.detail-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  color: var(--primary);
  font-weight: 500;
}

.detail-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  color: #dc2626;
  font-size: 0.9rem;
}

.detail-content {
  padding: 20px;
}

.detail-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.detail-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

.detail-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
}

.detail-name {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.detail-name-en {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-style: italic;
  width: 100%;
}

.detail-badges {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.detail-credit {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  background: var(--amber-50);
  color: var(--amber-dark);
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--amber-100);
}

.detail-credit .material-symbols-rounded {
  font-size: 16px;
}

.detail-page-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
  color: white;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  transition: var(--transition);
}

.detail-page-badge:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(124,58,237,0.3);
  color: white;
}

.detail-page-badge .material-symbols-rounded {
  font-size: 16px;
}

.detail-sections {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-section {
  background: white;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.detail-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary-dark);
  background: var(--primary-50);
  border-bottom: 1px solid var(--border);
}

.detail-section-title .material-symbols-rounded {
  font-size: 18px;
  color: var(--primary-light);
}

.detail-section-body {
  padding: 12px 16px;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
}

.detail-section-body .text-muted {
  color: var(--text-muted);
}

/* ===== Filter Tools ===== */
.filter-tools {
  display: flex;
  align-items: flex-end;
  flex-shrink: 0;
}

.btn-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 12px 18px;
  background: linear-gradient(135deg, #db2777, #ec4899);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 2px 8px rgba(219,39,119,0.25);
  white-space: nowrap;
  height: 46px;
}

.btn-tool .material-symbols-rounded {
  font-size: 18px;
}

.btn-tool:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(219,39,119,0.35);
}

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

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 440px;
  padding: 28px;
  position: relative;
  animation: modalSlideUp 0.3s ease;
}

@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  transition: var(--transition);
}

.modal-close:hover {
  background: var(--bg);
  color: var(--text);
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.modal-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.modal-icon.pink {
  background: #fce7f3;
  color: #db2777;
}

.modal-icon .material-symbols-rounded {
  font-size: 26px;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.modal-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  text-align: center;
  transition: var(--transition);
}

.upload-area:hover {
  border-color: var(--primary-light);
  background: var(--primary-50);
}

.upload-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.upload-label .material-symbols-rounded {
  font-size: 32px;
}

.upload-label.has-file {
  color: #059669;
  font-weight: 600;
  flex-direction: row;
  padding: 16px;
}

.upload-label.has-file .material-symbols-rounded {
  font-size: 22px;
}

.pdf-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--primary-50);
  border-radius: 8px;
  font-size: 0.88rem;
  color: var(--primary-dark);
}

.pdf-page-count {
  font-weight: 700;
}

.form-field label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-field input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  transition: var(--transition);
}

.form-field input[type="text"]:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.btn-split {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #db2777, #ec4899);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 2px 12px rgba(219,39,119,0.3);
}

.btn-split .material-symbols-rounded {
  font-size: 20px;
}

.btn-split:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(219,39,119,0.4);
}

.btn-split:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Footer Sync & Counter ===== */
.footer-sync {
  font-size: 0.82rem;
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-top: 4px;
}

.footer-counter {
  margin-top: 8px;
  opacity: 0.7;
}

.footer-counter img {
  height: 18px;
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  width: 80px;
  height: 80px;
  background: var(--bg);
  border-radius: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.empty-state .empty-icon .material-symbols-rounded {
  font-size: 36px;
  color: var(--text-muted);
}

.empty-state h3 {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 600;
}

.empty-state p {
  font-size: 0.92rem;
}

/* ===== Loading ===== */
.loading {
  text-align: center;
  padding: 40px;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

/* ===== Footer ===== */
footer {
  margin-top: auto;
  position: relative;
  z-index: 1;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: var(--text-muted);
  padding: 32px 0;
  text-align: center;
}

.footer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: white;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.footer-brand .material-symbols-rounded {
  font-size: 22px;
  color: var(--primary-light);
}

footer p {
  font-size: 0.85rem;
}

footer a {
  color: white;
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
}

footer a:hover {
  color: #fde047;
  text-decoration: underline;
}

.footer-note {
  font-size: 0.78rem;
  color: #fde047;
  font-weight: 700;
  opacity: 1;
}

.footer-note a {
  color: #fde047;
  font-weight: 700;
}

.footer-note a:hover {
  color: white;
}

/* ===== Highlight ===== */
mark {
  background: linear-gradient(120deg, #fef08a 0%, #fde047 100%);
  color: inherit;
  padding: 1px 3px;
  border-radius: 3px;
  font-weight: 700;
}

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

.result-card {
  animation: fadeInUp 0.3s ease forwards;
}

.category-group:nth-child(1) .result-card { animation-delay: 0s; }
.category-group:nth-child(2) .result-card { animation-delay: 0.03s; }
.category-group:nth-child(3) .result-card { animation-delay: 0.06s; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  header {
    padding: 36px 0 72px;
  }

  header h1 {
    font-size: 1.6rem;
  }

  .subtitle {
    font-size: 0.82rem;
  }

  .header-icon {
    width: 52px;
    height: 52px;
    border-radius: 16px;
  }

  .header-icon .material-symbols-rounded {
    font-size: 26px;
  }

  .stats-cards {
    gap: 8px;
  }

  .stat-card {
    padding: 12px 16px;
    min-width: 90px;
  }

  .stat-number {
    font-size: 1.4rem;
  }

  .search-section {
    margin-top: -32px;
  }

  .search-box input {
    font-size: 1rem;
    padding: 14px 4px;
  }

  .filters {
    flex-wrap: wrap;
    gap: 10px;
  }

  .filter-group {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
  }

  .filter-tools {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .btn-tool {
    flex: 1;
    justify-content: center;
  }

  .result-card {
    flex-wrap: nowrap;
    gap: 10px;
    padding: 12px 14px;
  }

  .result-code {
    min-width: 54px;
    padding: 6px 8px;
    font-size: 0.78rem;
  }

  .result-info {
    min-width: 0;
  }

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

  .btn-pdf {
    padding: 8px 12px;
    font-size: 0.78rem;
    gap: 4px;
  }

  .btn-pdf .material-symbols-rounded {
    font-size: 16px;
  }

  /* Subject cards */
  .subject-card {
    gap: 10px;
    padding: 10px 12px;
  }

  .subject-code {
    min-width: 72px;
    padding: 5px 8px;
    font-size: 0.75rem;
  }

  .subject-name-th {
    font-size: 0.85rem;
  }

  .subject-name-en {
    font-size: 0.72rem;
  }

  .subject-actions {
    flex-shrink: 0;
  }

  .subject-actions .btn-pdf,
  .subject-actions .btn-find-page,
  .subject-actions .btn-page-found {
    padding: 7px 10px;
    font-size: 0.72rem;
    gap: 3px;
  }

  .subject-actions .btn-pdf .material-symbols-rounded,
  .subject-actions .btn-find-page .material-symbols-rounded,
  .subject-actions .btn-page-found .material-symbols-rounded {
    font-size: 14px;
  }

  .category-header {
    position: static;
  }
}

@media (max-width: 480px) {
  header h1 {
    font-size: 1.35rem;
  }

  .stat-card {
    padding: 10px 12px;
    min-width: 80px;
  }

  .stat-number {
    font-size: 1.2rem;
  }

  /* Cards: stack vertically on very small screens */
  .result-card {
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px;
  }

  .result-code {
    min-width: auto;
  }

  .result-info {
    flex: 1 1 calc(100% - 80px);
  }

  .btn-pdf {
    width: 100%;
    justify-content: center;
    padding: 10px;
    font-size: 0.8rem;
  }

  .subject-card {
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px;
  }

  .subject-code {
    min-width: auto;
  }

  .subject-info {
    flex: 1 1 calc(100% - 90px);
  }

  .subject-actions {
    width: 100%;
  }

  .subject-actions .btn-pdf,
  .subject-actions .btn-find-page,
  .subject-actions .btn-page-found {
    flex: 1;
    justify-content: center;
    padding: 8px;
    font-size: 0.75rem;
  }

  .stat-label {
    font-size: 0.7rem;
  }

  .stat-card .material-symbols-rounded {
    font-size: 18px;
  }
}
