/* =============================================
   ระบบแข่งขัน eBook - Main Stylesheet
   Design: Deep navy + gold accent, Thai judicial feel
   ============================================= */

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

:root {
  --navy:        #0F172A;
  --navy-800:    #1E293B;
  --navy-700:    #334155;
  --navy-600:    #475569;
  --gold:        #D4A017;
  --gold-light:  #F5D35A;
  --gold-pale:   #FDF6DC;
  --teal:        #0E7490;
  --teal-light:  #E0F2FE;
  --green:       #059669;
  --green-light: #D1FAE5;
  --red:         #DC2626;
  --red-light:   #FEE2E2;
  --gray-50:     #F8FAFC;
  --gray-100:    #F1F5F9;
  --gray-200:    #E2E8F0;
  --gray-300:    #CBD5E1;
  --gray-500:    #64748B;
  --gray-700:    #374151;
  --white:       #FFFFFF;

  --font-display: 'Prompt', 'Sarabun', sans-serif;
  --font-body:    'Sarabun', sans-serif;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:  0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:  0 10px 25px rgba(0,0,0,.1), 0 4px 10px rgba(0,0,0,.05);
  --shadow-xl:  0 20px 40px rgba(0,0,0,.12);
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --radius-xl:  24px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--gray-50);
  color: var(--navy);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== NAVBAR ===== */
.navbar {
  background: var(--navy);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 20px rgba(0,0,0,.3);
}
.navbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  height: 64px;
  gap: 24px;
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}
.navbar-brand .brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.navbar-brand .brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  color: var(--white);
  line-height: 1.2;
}
.navbar-brand .brand-sub {
  font-size: 11px;
  color: var(--gold);
  font-weight: 400;
}
.navbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
}
.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,.1);
  color: var(--white);
}
.nav-link.active {
  background: rgba(212,160,23,.2);
  color: var(--gold-light);
}
.navbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}
.user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(255,255,255,.08);
  border-radius: 999px;
  color: rgba(255,255,255,0.9);
  font-size: 13px;
}
.user-avatar {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--gold), var(--teal));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
}
.role-tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
}
.role-admin { background: var(--gold); color: var(--navy); }
.role-judge { background: var(--teal); color: white; }
.btn-logout {
  background: rgba(220,38,38,.15);
  border: 1px solid rgba(220,38,38,.3);
  color: #FCA5A5;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
}
.btn-logout:hover {
  background: rgba(220,38,38,.3);
  color: white;
}

/* ===== PAGE LAYOUT ===== */
.page-wrapper {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px;
}
.page-header {
  margin-bottom: 28px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.2;
}
.page-subtitle {
  font-size: 14px;
  color: var(--gray-500);
  margin-top: 4px;
}

/* ===== CARDS ===== */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  overflow: hidden;
}
.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--navy);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-body { padding: 24px; }

/* ===== STAT CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 20px;
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.stat-icon.gold  { background: var(--gold-pale); }
.stat-icon.teal  { background: var(--teal-light); }
.stat-icon.green { background: var(--green-light); }
.stat-icon.navy  { background: #EEF2FF; }
.stat-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1;
}
.stat-label { font-size: 13px; color: var(--gray-500); margin-top: 3px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: linear-gradient(135deg, var(--navy-700), var(--navy));
  color: white;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--navy-600), var(--navy-700)); box-shadow: var(--shadow-md); }
.btn-gold {
  background: linear-gradient(135deg, var(--gold), #B8860B);
  color: var(--navy);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
.btn-gold:hover { background: linear-gradient(135deg, var(--gold-light), var(--gold)); }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--gray-300);
  color: var(--gray-700);
}
.btn-outline:hover { border-color: var(--navy-600); color: var(--navy); background: var(--gray-50); }
.btn-danger {
  background: var(--red);
  color: white;
}
.btn-danger:hover { background: #B91C1C; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 20px; }
.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--navy-700);
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--navy);
  background: var(--white);
  transition: var(--transition);
  outline: none;
}
.form-control:focus {
  border-color: var(--navy-700);
  box-shadow: 0 0 0 3px rgba(15,23,42,.08);
}
textarea.form-control { resize: vertical; min-height: 100px; }
.form-hint { font-size: 12px; color: var(--gray-500); margin-top: 4px; }

/* ===== ALERTS ===== */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid transparent;
}
.alert-success { background: var(--green-light); color: #065F46; border-color: #A7F3D0; }
.alert-error   { background: var(--red-light);   color: #7F1D1D; border-color: #FCA5A5; }
.alert-info    { background: var(--teal-light);  color: #0C4A6E; border-color: #BAE6FD; }
.alert-warning { background: var(--gold-pale);   color: #78350F; border-color: #FDE68A; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-unread   { background: var(--gray-100);    color: var(--gray-500); }
.badge-reading  { background: var(--teal-light);  color: var(--teal);     border: 1px solid #BAE6FD; }
.badge-completed{ background: var(--green-light); color: var(--green);    border: 1px solid #A7F3D0; }

/* ===== EBOOK GRID ===== */
.ebooks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
}
.ebook-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: var(--transition);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
}
.ebook-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-3px);
  border-color: var(--gray-300);
}
.ebook-cover {
  height: 160px;
  background: linear-gradient(135deg, var(--navy-800), var(--navy-700));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  position: relative;
  overflow: hidden;
}
.ebook-cover::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 60%, rgba(0,0,0,.3));
}
.ebook-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ebook-rank-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: linear-gradient(135deg, var(--gold), #B8860B);
  color: var(--navy);
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  z-index: 1;
}
.ebook-body { padding: 16px; flex: 1; display: flex; flex-direction: column; }
.ebook-category {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  margin-bottom: 8px;
  color: white;
}
.ebook-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--navy);
  line-height: 1.4;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ebook-author { font-size: 13px; color: var(--gray-500); margin-bottom: 12px; }
.ebook-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  border-top: 1px solid var(--gray-100);
}

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th {
  background: var(--navy);
  color: white;
  padding: 13px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}
.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--gray-50); }

/* ===== LEADERBOARD ===== */
.leaderboard-row-1 td { background: linear-gradient(135deg, rgba(212,160,23,.12), rgba(245,211,90,.08)); }
.leaderboard-row-2 td { background: linear-gradient(135deg, rgba(148,163,184,.1),  rgba(203,213,225,.05)); }
.leaderboard-row-3 td { background: linear-gradient(135deg, rgba(180,83,9,.08),    rgba(217,119,6,.05)); }
.position-badge {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}
.pos-1 { background: linear-gradient(135deg, #D4A017, #F5D35A); color: var(--navy); box-shadow: 0 2px 8px rgba(212,160,23,.4); }
.pos-2 { background: linear-gradient(135deg, #94A3B8, #CBD5E1); color: var(--navy); }
.pos-3 { background: linear-gradient(135deg, #B45309, #D97706); color: white; }
.pos-other { background: var(--gray-100); color: var(--gray-500); }

/* ===== SCORE DOTS ===== */
.score-dots { display: flex; gap: 4px; }
.score-dot {
  width: 20px; height: 20px;
  border-radius: 4px;
  background: var(--gray-200);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--gray-500);
  transition: var(--transition);
}
.score-dot.filled { background: var(--gold); color: var(--navy); }

/* ===== RANKING WIDGET ===== */
.rank-selector {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.rank-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--gray-200);
  background: var(--white);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  color: var(--gray-500);
  display: flex; align-items: center; justify-content: center;
}
.rank-btn:hover { border-color: var(--gold); color: var(--gold); }
.rank-btn.selected {
  background: linear-gradient(135deg, var(--gold), #B8860B);
  border-color: var(--gold);
  color: var(--navy);
  box-shadow: 0 2px 8px rgba(212,160,23,.4);
}
.rank-btn.used-by-other {
  background: var(--gray-100);
  border-color: var(--gray-200);
  color: var(--gray-300);
  cursor: not-allowed;
}

/* ===== PDF VIEWER ===== */
.pdf-viewer-wrap {
  width: 100%;
  height: calc(100vh - 140px);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  background: var(--navy-800);
  position: relative;
}
.pdf-viewer-wrap iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}
.pdf-toolbar {
  background: var(--navy);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  flex-wrap: wrap;
}
.pdf-title { color: white; font-size: 14px; font-weight: 600; flex: 1; min-width: 200px; }
.pdf-meta  { color: rgba(255,255,255,.6); font-size: 12px; }

/* ===== FILTER BAR ===== */
.filter-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 24px;
}
.filter-bar .form-control { max-width: 280px; }
.category-filter {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.cat-chip {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid var(--gray-200);
  background: var(--white);
  color: var(--gray-700);
  transition: var(--transition);
  text-decoration: none;
}
.cat-chip:hover { border-color: var(--navy-600); color: var(--navy); }
.cat-chip.active { background: var(--navy); border-color: var(--navy); color: white; }

/* ===== LOGIN PAGE ===== */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--navy) 0%, #1E3A5F 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box {
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-xl);
}
.login-logo {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo .logo-icon {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  margin: 0 auto 16px;
  box-shadow: 0 8px 24px rgba(212,160,23,.3);
}
.login-logo h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--navy);
}
.login-logo p { font-size: 13px; color: var(--gray-500); margin-top: 4px; }

/* ===== MY RANKINGS PAGE ===== */
.rankings-slots {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}
.rank-slot {
  background: var(--white);
  border: 2px dashed var(--gray-200);
  border-radius: var(--radius-md);
  padding: 16px 12px;
  text-align: center;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: var(--transition);
  position: relative;
}
.rank-slot.filled {
  border-style: solid;
  border-color: var(--gold);
  background: var(--gold-pale);
}
.rank-slot-number {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
}
.rank-slot.filled .rank-slot-number { color: var(--gold); }
.rank-slot:not(.filled) .rank-slot-number { color: var(--gray-300); }
.rank-slot-title { font-size: 12px; font-weight: 600; color: var(--navy); line-height: 1.3; }
.rank-slot-empty { font-size: 12px; color: var(--gray-400); }
.rank-slot-remove {
  position: absolute;
  top: 6px; right: 6px;
  background: var(--red-light);
  color: var(--red);
  border: none;
  border-radius: 4px;
  width: 22px; height: 22px;
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.rank-slot-remove:hover { background: var(--red); color: white; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--white);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 500px;
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-family: var(--font-display); font-size: 18px; font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--gray-500); font-size: 20px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.modal-close:hover { background: var(--gray-100); color: var(--navy); }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--gray-100);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ===== MISC ===== */
.divider { border: none; border-top: 1px solid var(--gray-200); margin: 20px 0; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.text-small { font-size: 13px; }
.font-bold { font-weight: 700; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-500);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ===== SCORE BAR ===== */
.score-bar-wrap {
  background: var(--gray-100);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
  flex: 1;
  min-width: 60px;
}
.score-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold), var(--gold-light));
  transition: width 0.5s ease;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .navbar-inner { padding: 0 16px; }
  .navbar-nav { display: none; }
  .page-wrapper { padding: 20px 16px; }
  .rankings-slots { grid-template-columns: repeat(3, 1fr); }
  .ebooks-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .page-title { font-size: 20px; }
  .login-box { padding: 32px 24px; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar .form-control { max-width: 100%; }
}
@media (max-width: 480px) {
  .rankings-slots { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ===== PRINT HIDE ===== */
@media print {
  .navbar, .btn, .filter-bar, .rank-selector { display: none !important; }
}

/* Fade in animation */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-up { animation: fadeUp 0.3s ease both; }
