:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --sky: #0ea5e9;
  --dark: #1e293b;
  --gray: #64748b;
  --muted: #94a3b8;
  --bg-color: #f8fafc;
  --bg-soft: #eef4ff;
  --white: #ffffff;
  --border: #e2e8f0;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.07);
  --shadow-strong: 0 18px 42px rgba(15, 23, 42, 0.12);
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  font-family: 'Noto Sans Thai', sans-serif;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.10), transparent 22%),
    linear-gradient(180deg, #f8fbff 0%, #f8fafc 100%);
  color: var(--dark);
}

a { color: var(--primary); }
button, input, select { font: inherit; }
.hidden { display: none !important; }
.center { text-align: center; }
.required { color: var(--danger); }
.full-width { width: 100%; }

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 40px 20px 24px;
}
.container.narrow { max-width: 700px; }

.card {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(226, 232, 240, 0.92);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.alert {
  padding: 14px 16px;
  margin-bottom: 18px;
  border-radius: 12px;
  background: #fee2e2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  min-width: 240px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #0f172a;
  color: #fff;
  box-shadow: var(--shadow-strong);
}

.search-card,
.verify-card,
.panel,
.download-panel {
  padding: 22px;
}

.search-card {
  max-width: 100%;
  margin: 0 auto;
}
.search-card h1,
.search-card h2,
.verify-card h2,
.panel h3 {
  margin-top: 0;
}
.subtext {
  color: var(--gray);
  margin: 0 0 14px;
  font-size: 14px;
}
.compact-label { margin-bottom: 6px; }

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
}
.form-control {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: #fff;
  transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.08);
}
.input-lg { padding: 13px 15px; }
.compact-select, .compact-input { width: auto; min-width: 160px; }

.search-input-group {
  display: flex;
  gap: 10px;
}
.search-input-group .form-control { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 12px;
  padding: 11px 16px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 22px rgba(15, 23, 42, 0.08);
}
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-primary { background: linear-gradient(135deg, #2563eb, #1d4ed8); color: #fff; }
.btn-primary:hover { background: linear-gradient(135deg, #1d4ed8, #1e40af); }
.btn-success { background: linear-gradient(135deg, #10b981, #059669); color: #fff; }
.btn-success:hover { background: linear-gradient(135deg, #059669, #047857); }
.btn-danger { background: linear-gradient(135deg, #ef4444, #dc2626); color: #fff; }
.btn-danger:hover { background: linear-gradient(135deg, #dc2626, #b91c1c); }
.btn-outline { background: #fff; color: var(--dark); border: 1px solid #cbd5e1; }
.btn-outline:hover { background: #f8fafc; }
.btn-sky { background: linear-gradient(135deg, #0ea5e9, #0284c7); color: #fff; }
.btn-sky:hover { background: linear-gradient(135deg, #0284c7, #0369a1); }
.btn-linkish { color: var(--primary); font-weight: 500; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.public-stats {
  max-width: 100%;
  margin: 0 0 18px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 1024px) {
  .public-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .public-stats {
    grid-template-columns: 1fr;
  }
}
.stat-card {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 252, 0.98));
  border: 1px solid rgba(226, 232, 240, 0.96);
  border-radius: 18px;
  box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease;
}
.stat-card::before {
  content: '';
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, rgba(255,255,255,.35), rgba(255,255,255,.05));
}
.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-strong);
}
.icon-wrapper {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.stat-purple { background: linear-gradient(180deg, #ffffff 0%, #faf5ff 100%); }
.stat-primary { background: linear-gradient(180deg, #ffffff 0%, #eff6ff 100%); }
.stat-success { background: linear-gradient(180deg, #ffffff 0%, #ecfdf5 100%); }
.stat-warning { background: linear-gradient(180deg, #ffffff 0%, #fffbeb 100%); }
.stat-purple::before { background: linear-gradient(90deg, #a855f7, #9333ea); }
.stat-primary::before { background: linear-gradient(90deg, #3b82f6, #2563eb); }
.stat-success::before { background: linear-gradient(90deg, #34d399, #10b981); }
.stat-warning::before { background: linear-gradient(90deg, #fbbf24, #f59e0b); }
.stat-purple .icon-wrapper { background: #f3e8ff; color: #9333ea; }
.stat-primary .icon-wrapper { background: #dbeafe; color: #2563eb; }
.stat-success .icon-wrapper { background: #d1fae5; color: #10b981; }
.stat-warning .icon-wrapper { background: #fef3c7; color: #d97706; }
.value { font-size: 24px; font-weight: 700; line-height: 1.1; }
.label { font-size: 13px; color: var(--gray); }

.course-details {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #dbeafe;
  border-radius: 14px;
  background: linear-gradient(180deg, #f8fbff 0%, #eff6ff 100%);
}
.course-details p { margin: 0 0 4px; font-size: 14px; }
.course-details p:last-child { margin-bottom: 0; }

.result-container {
  width: 100%;
  max-width: 100%;
  margin: 0;
}
.result-card {
  position: relative;
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.result-card::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  border-radius: 18px 0 0 18px;
  background: linear-gradient(180deg, #2563eb, #60a5fa);
}
.result-name { font-size: 17px; font-weight: 700; padding-left: 4px; }
.result-meta { color: var(--gray); font-size: 13px; margin-top: 5px; padding-left: 4px; }
.cert-link { margin-top: 12px; }
.empty-box {
  padding: 22px;
  text-align: center;
  color: var(--gray);
  border: 1px dashed #cbd5e1;
  border-radius: 16px;
  background: rgba(255,255,255,.72);
}

.section-title,
.table-header h3,
.section-toolbar h3 {
  margin: 0;
  font-size: 18px;
}
.section-toolbar,
.actions-row,
.table-header,
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.section-toolbar { justify-content: space-between; margin-bottom: 16px; }
.section-toolbar.right-only { justify-content: flex-end; }
.actions-row { margin-top: 14px; }
.actions-row.right { justify-content: flex-end; }
.header-actions { justify-content: flex-end; }
.status-text { margin-top: 14px; font-weight: 600; }

.table-container { overflow: hidden; }
.table-header {
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #fbfdff 0%, #f8fafc 100%);
}
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}
th {
  background: #f8fafc;
  color: var(--gray);
  font-weight: 600;
  white-space: nowrap;
}
tr:hover td { background: #f8fbff; }

.badge {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}
.badge.success { background: #d1fae5; color: #065f46; }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.gray { background: #e2e8f0; color: #334155; }
.code-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  background: #f1f5f9;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.profile-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}
.profile-avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid #cbd5e1;
  flex-shrink: 0;
}

.page-public { justify-content: space-between; }
.public-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.public-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(10px);
}
.public-topbar-inner {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.public-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
}
.public-brand-logo {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18);
}
.public-brand-title {
  font-size: 16px;
  font-weight: 700;
}
.public-brand-subtitle {
  font-size: 12px;
  color: #cbd5e1;
}
.public-topbar-badge,
.user-profile,
.panel-badge {
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 600;
}
.public-topbar-badge {
  background: rgba(59, 130, 246, 0.18);
  color: #dbeafe;
  border: 1px solid rgba(147, 197, 253, 0.22);
}
.public-container {
  padding-top: 18px;
}
.public-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 28px;
  margin-bottom: 24px;
  background:
    radial-gradient(circle at top right, rgba(59, 130, 246, 0.16), transparent 28%),
    linear-gradient(135deg, #ffffff 0%, #eff6ff 100%);
  border: 1px solid #dbeafe;
}
.public-hero-copy h1 {
  margin: 8px 0 10px;
  font-size: 28px;
  line-height: 1.3;
}
.public-hero-copy p {
  margin: 0;
  max-width: 720px;
  color: var(--gray);
}
.hero-kicker,
.panel-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #2563eb;
}
.public-hero-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}
.hero-tag {
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,.88);
  border: 1px solid #dbeafe;
  color: #1d4ed8;
  font-weight: 600;
  white-space: nowrap;
}
.public-panel {
  margin-bottom: 16px;
}
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.panel-heading-tight {
  margin-bottom: 12px;
}
.panel-heading h2,
.panel-heading h3,
.panel-heading .section-title {
  margin: 4px 0 0;
}
.panel-badge {
  background: #eef2ff;
  color: #3730a3;
}
.section-heading-inline {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.section-caption {
  font-size: 13px;
  color: var(--gray);
}
.public-section-block {
  margin-bottom: 14px;
}
.public-footer {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  padding: 16px 20px 22px;
}
.public-footer a { text-decoration: none; font-weight: 600; }

.public-main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 16px;
  align-items: start;
}
.public-column-right {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.compact-panel {
  min-height: 100%;
}
.public-results-section {
  border: 1px solid #dbe4f0;
  border-radius: 18px;
  background: rgba(255, 255, 255, .94);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.public-results-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: linear-gradient(180deg, #fbfdff 0%, #f8fafc 100%);
}
.public-results-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.public-results-close {
  width: 34px;
  height: 34px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #fff;
  color: #475569;
  font-size: 16px;
  cursor: pointer;
}
.public-results-close:hover {
  background: #f8fafc;
}
.public-results-list {
  max-height: 360px;
  overflow: auto;
}
.public-result-item {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid #eef2f7;
}
.public-result-item:last-child {
  border-bottom: none;
}
.public-result-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.public-result-name {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
}
.public-result-code {
  margin-top: 4px;
  color: var(--gray);
  font-size: 12px;
}
.public-result-status {
  display: flex;
  align-items: center;
}
.public-result-actions {
  display: flex;
  justify-content: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.no-margin {
  margin: 0;
}
.public-result-empty {
  padding: 18px 16px;
}
.public-accordion .accordion-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.accordion-heading-wrap {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex: 1;
  width: 100%;
}
.accordion-title {
  display: block;
  margin-top: 2px;
}
.accordion-icon {
  flex: 0 0 auto;
  color: #64748b;
  font-size: 20px;
  line-height: 1;
  transition: transform .2s ease;
}
#recentActivityToggle[aria-expanded="true"] .accordion-icon {
  transform: rotate(180deg);
}
.accordion-panel {
  margin-top: 12px;
}
#publicDownloadedList {
  font-size: 13px;
}
#publicDownloadedList .table-wrap {
  max-height: 312px;
  overflow: auto;
}
#publicDownloadedList table {
  font-size: 13px;
}
#publicDownloadedList table th,
#publicDownloadedList table td {
  padding-top: 10px;
  padding-bottom: 10px;
  font-size: 13px;
  vertical-align: top;
}
#publicDownloadedList .pagination-row,
#publicDownloadedList .pagination-controls .btn {
  font-size: 13px;
}
.admin-login-btn {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  border: none;
  border-radius: 999px;
  padding: 11px 16px;
  cursor: pointer;
  background: #cbd5e1;
  color: #334155;
  box-shadow: var(--shadow-strong);
}

.dashboard-layout {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 260px;
  background: #0f172a;
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 40;
}
.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  font-weight: 700;
  font-size: 18px;
}
.sidebar-logo { font-size: 22px; }
.sidebar-menu {
  list-style: none;
  padding: 16px 0;
  margin: 0;
}
.sidebar-menu li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  color: #cbd5e1;
  cursor: pointer;
}
.sidebar-menu li:hover { background: #1e293b; color: #fff; }
.sidebar-menu li.active { background: var(--primary); color: #fff; }
.sidebar-menu li.danger { margin-top: 8px; color: #fca5a5; }
.sidebar-footer {
  margin-top: auto;
  padding: 18px 20px;
  font-size: 12px;
  color: #94a3b8;
  border-top: 1px solid rgba(255,255,255,.1);
}

.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 28px;
}
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.top-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.top-header h1 { margin: 0; font-size: 24px; }
.user-profile {
  background: #eef2ff;
  color: #3730a3;
}
.mobile-toggle {
  display: none;
  background: transparent;
  border: none;
  font-size: 24px;
  cursor: pointer;
}
.view-section { display: none; }
.view-section.active { display: block; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .52);
}
.modal-dialog {
  position: relative;
  z-index: 1;
  width: calc(100% - 24px);
  max-width: 420px;
  margin: 7vh auto 0;
  padding: 24px;
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 24px 48px rgba(15, 23, 42, .24);
}
.modal-dialog.small { max-width: 400px; }
.modal-dialog.large { max-width: 760px; }
.close-btn {
  position: absolute;
  top: 10px;
  right: 14px;
  border: none;
  background: transparent;
  font-size: 28px;
  cursor: pointer;
  color: var(--muted);
}
.error-text {
  margin-top: 12px;
  color: #b91c1c;
  font-size: 14px;
}

.form-grid {
  display: grid;
  gap: 16px;
}
.form-grid.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.two-col.uneven { grid-template-columns: 1fr 2fr; }

.verify-title { text-align: center; }
.verify-details {
  text-align: left;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  line-height: 1.7;
}
.verify-details p { margin: 0 0 8px; }
.verify-details p:last-child { margin-bottom: 0; }
.verify-success {
  margin-top: 18px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid #86efac;
  background: #dcfce7;
  color: #166534;
  font-weight: 600;
  text-align: center;
}

.pagination-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.pagination-controls {
  display: flex;
  gap: 8px;
}

@media (max-width: 900px) {
  .form-grid.two-col,
  .form-grid.two-col.uneven,
  .search-input-group {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .public-main-grid {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    flex-direction: column;
    align-items: flex-start;
  }

  .public-results-head,
  .public-result-top,
  .accordion-heading-wrap {
    flex-direction: column;
    align-items: flex-start;
  }

  .public-results-actions {
    width: 100%;
    justify-content: space-between;
  }

  .public-results-list,
  #publicDownloadedList .table-wrap {
    max-height: none;
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .main-content {
    margin-left: 0;
    padding: 16px;
  }
  .mobile-toggle { display: inline-block; }
  .container { padding: 24px 14px 20px; }
  .public-topbar-inner { padding: 10px 14px; }
  .public-brand-subtitle,
  .public-topbar-badge { display: none; }
  .search-card,
  .download-panel { padding: 18px; }
  .table-header,
  th, td { padding-left: 12px; padding-right: 12px; }
}

.search-card h1,
.search-card h2 {
  font-size: 18pt;
}
