/* ══════════════════════════════════════════════════════════════
   12Tile Research Admin — Design tokens & components
   ------------------------------------------------------------
   FONTS: this project ships two placeholder font-family names —
   'AppThai' and 'AppEnglish' — see the @font-face block right
   below. Drop your own font files in admin/fonts/ and point the
   src url()s at them; nothing else in this stylesheet needs to
   change. See admin/fonts/README.md for the exact steps.
   ══════════════════════════════════════════════════════════════ */

@font-face {
  font-family: 'AppThai';
  src: url('../fonts/AppThai-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'AppThai';
  src: url('../fonts/AppThai-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'AppEnglish';
  src: url('../fonts/AppEnglish-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'AppEnglish';
  src: url('../fonts/AppEnglish-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Fonts — AppEnglish first so Latin glyphs (numbers, ids) use it,
     AppThai fills in Thai glyphs, then generic fallbacks so the UI
     still looks fine before real font files are added. */
  --font-ui: 'AppEnglish', 'AppThai', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  /* AppThai first — used where numbers should render in the Thai font
     instead of the default English-first stack (see .num-th). */
  --font-ui-th: 'AppThai', 'AppEnglish', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;

  --bg:    #f1f5f9;
  --sur:   #ffffff;
  --sur2:  #f8fafc;
  --bdr:   #e2e8f0;
  --bdr2:  #cbd5e1;
  --acc:   #2563eb;
  --acc2:  #1d4ed8;
  --acc-l: #eff6ff;
  --red:   #dc2626; --red2: #b91c1c; --red-l: #fef2f2;
  --grn:   #16a34a; --grn-l: #f0fdf4;
  --yel:   #d97706; --yel-l: #fffbeb;
  --pur:   #7c3aed; --pur-l: #f5f3ff;
  --cyn:   #0891b2; --cyn-l: #ecfeff;
  --txt:   #0f172a; --sec: #475569; --muted: #94a3b8; --dim: #cbd5e1;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-ui);
  font-size: 16px; line-height: 1.5;
  background: var(--bg); color: var(--txt);
  height: 100vh; display: flex; flex-direction: column; overflow: hidden;
}
code, .mono { font-family: var(--font-mono); }

/* ── AUTH ── */
#auth-wrap {
  position: fixed; inset: 0; background: linear-gradient(135deg, #eff6ff 0%, #f5f3ff 100%);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.auth-box {
  background: var(--sur); border: 1px solid var(--bdr); border-radius: 20px;
  padding: 44px 40px; width: 400px;
  box-shadow: 0 8px 40px rgba(15,23,42,.10);
}
.auth-logo { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; margin-bottom: 32px; }
.logo-img { display: block; }
.logo-img-lg { height: 60px; width: auto; }
.logo-img-sm { height: 36px; width: auto; }
.auth-title { font-size: 20px; font-weight: 700; text-align: center; }
.auth-sub { font-size: 14px; color: var(--muted); text-align: center; margin-top: 3px; }
.auth-hint { font-size: 14px; color: var(--muted); text-align: center; margin-top: 16px; }

/* ── TOPBAR ── */
#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 22px; height: 56px;
  background: var(--sur); border-bottom: 1px solid var(--bdr); flex-shrink: 0; z-index: 10;
}
.logo-text { font-weight: 700; font-size: 17px; }
.logo-sub { font-size: 12px; color: var(--muted); }
.divider-v { width: 1px; height: 22px; background: var(--bdr); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; background: var(--sur2); border: 1px solid var(--bdr); border-radius: 20px; }
.user-avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--acc); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #fff; }
.user-email { font-size: 14px; font-weight: 500; color: var(--sec); }

/* ── LAYOUT ── */
#layout { display: flex; flex: 1; overflow: hidden; }
#sidebar { width: 240px; background: var(--sur); border-right: 1px solid var(--bdr); display: flex; flex-direction: column; flex-shrink: 0; }
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#content { flex: 1; overflow-y: auto; padding: 26px; }
.page { display: none; }
.page.active { display: block; }

/* ── SIDEBAR NAV ── */
.sb-section { padding: 10px 8px; }
.sb-section + .sb-section { border-top: 1px solid var(--bdr); }
.sb-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding: 6px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px; cursor: pointer;
  font-size: 15px; font-weight: 500; color: var(--sec);
  transition: background .12s, color .12s; margin-bottom: 1px;
}
.nav-item:hover { background: var(--sur2); color: var(--txt); }
.nav-item.active { background: var(--acc-l); color: var(--acc); }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; }
.sb-footer { margin-top: auto; padding: 12px; border-top: 1px solid var(--bdr); }

/* ── PAGE HEADER ── */
.page-header { margin-bottom: 22px; }
.page-header h2 { font-size: 22px; font-weight: 700; }
.page-header p { font-size: 15px; color: var(--sec); margin-top: 3px; }
.page-header-row { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 22px; gap: 12px; flex-wrap: wrap; }

/* ── STAT CARDS ── */
.stat-grid { display: grid; gap: 16px; margin-bottom: 22px; }
.stat-grid-2 { grid-template-columns: repeat(2, 1fr); }
.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stat-grid-4 { grid-template-columns: repeat(4, 1fr); }
.stat-card { background: var(--sur); border: 1px solid var(--bdr); border-radius: 14px; padding: 20px 22px; }
.stat-label { font-size: 12px; font-weight: 700; color: var(--sec); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }
.stat-value { font-size: 30px; font-weight: 700; line-height: 1; margin-bottom: 6px; }
.stat-sub { font-size: 14px; color: var(--muted); }

/* ── CARDS ── */
.card { background: var(--sur); border: 1px solid var(--bdr); border-radius: 14px; padding: 22px; margin-bottom: 18px; }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--bdr); gap: 10px; flex-wrap: wrap; }
.card-title { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.card-action { font-size: 14px; color: var(--acc); cursor: pointer; font-weight: 500; white-space: nowrap; }

/* ── GRID HELPERS ── */
.col2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ── BUTTONS ── */
.btn { padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: 600; font-family: inherit; border: 1px solid transparent; transition: all .15s; display: inline-flex; align-items: center; gap: 6px; }
.btn .ic { width: 14px; height: 14px; }
.btn-p { background: var(--acc); color: #fff; }
.btn-p:hover { background: var(--acc2); }
.btn-d { background: var(--red); color: #fff; }
.btn-d:hover { background: var(--red2); }
.btn-s { background: var(--sur); color: var(--txt); border-color: var(--bdr); }
.btn-s:hover { border-color: var(--bdr2); background: var(--sur2); }
.btn-g { background: var(--grn-l); color: var(--grn); border-color: #bbf7d0; }
.btn-g:hover { background: #bbf7d0; }
.btn-sm { padding: 5px 12px; font-size: 14px; border-radius: 6px; }
.btn-icon { padding: 6px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── FORMS ── */
.fg { margin-bottom: 16px; }
.fg label, label.fg-label { display: block; font-size: 14px; font-weight: 600; color: var(--sec); margin-bottom: 7px; }
input, select, textarea {
  width: 100%; background: var(--sur); border: 1px solid var(--bdr);
  color: var(--txt); padding: 9px 12px; border-radius: 8px;
  font-size: 16px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--acc); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
textarea { resize: vertical; min-height: 70px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.field-err { color: var(--red); font-size: 14px; margin-top: 12px; min-height: 16px; }

/* ── COLOR PICKER ── */
.color-swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.color-swatch {
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; position: relative; flex-shrink: 0;
  transition: transform .1s;
}
.color-swatch:hover { transform: scale(1.08); }
.color-swatch.on { border-color: var(--txt); box-shadow: 0 0 0 2px var(--sur), 0 0 0 4px var(--txt); }
.color-swatch .ic { position: absolute; inset: 0; margin: auto; width: 14px; height: 14px; color: #fff; }

/* ── AVATAR ── */
.avatar { border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; flex-shrink: 0; }
.avatar-round { border-radius: 50%; }

/* ── TABLE ── */
.tbl-wrap { border: 1px solid var(--bdr); border-radius: 12px; overflow: hidden; background: var(--sur); }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; padding: 10px 14px; font-size: 12px; font-weight: 700; color: var(--sec); text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid var(--bdr); background: var(--sur2); }
.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--bdr); font-size: 15px; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: var(--sur2); }

/* ── BADGES ── */
.bdg { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.bdg .ic { width: 10px; height: 10px; }
.bdg-blue { background: var(--acc-l); color: var(--acc); }
.bdg-green { background: var(--grn-l); color: var(--grn); }
.bdg-red { background: var(--red-l); color: var(--red); }
.bdg-yellow { background: var(--yel-l); color: var(--yel); }
.bdg-purple { background: var(--pur-l); color: var(--pur); }
.bdg-gray { background: var(--sur2); color: var(--sec); border: 1px solid var(--bdr); }

/* ── PARTICIPANT GRID / CARD ── */
.p-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-bottom: 22px; }
.p-card {
  background: var(--sur); border: 1px solid var(--bdr); border-radius: 12px;
  padding: 16px; cursor: pointer; transition: border-color .15s, box-shadow .15s;
  border-left: 3px solid var(--dim);
}
.p-card:hover { border-color: var(--acc); box-shadow: 0 2px 12px rgba(37,99,235,.10); }
.p-card-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.p-card-name { font-weight: 700; font-size: 16px; }
.p-card-id { font-size: 12px; color: var(--muted); font-family: var(--font-mono); }
.p-card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.p-card-foot { display: flex; align-items: center; justify-content: space-between; font-size: 14px; color: var(--sec); border-top: 1px solid var(--bdr); padding-top: 10px; }
.p-card-actions { display: flex; gap: 4px; }

/* ── META ITEMS (participant detail) ── */
.p-meta { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.p-meta-item { background: var(--sur2); border: 1px solid var(--bdr); border-radius: 8px; padding: 8px 14px; font-size: 15px; }
.p-meta-item .k { font-size: 12px; color: var(--muted); font-weight: 500; display: block; margin-bottom: 2px; }
.p-meta-item .v { font-weight: 600; color: var(--txt); }

/* ── EXPLORER — Exp × Game grid ── */
.exp-matrix { width: 100%; min-width: 560px; }
.exp-matrix-row { display: grid; grid-template-columns: 118px repeat(6, 1fr); gap: 6px; margin-bottom: 6px; }
.exp-col-head { text-align: center; font-size: 14px; font-weight: 700; color: var(--sec); padding: 7px 4px; background: var(--sur2); border: 1px solid var(--bdr); border-radius: 8px; }
.exp-row-label { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--sec); text-align: center; padding: 4px 6px; }
.exp-row-label .ic { width: 18px; height: 18px; }
.game-logo { height: 26px; width: auto; max-width: 100px; }
.exp-cell {
  background: var(--sur); border: 1.5px solid var(--bdr); border-radius: 10px;
  padding: 10px 6px; cursor: pointer; text-align: center;
  transition: border-color .15s, background .15s, box-shadow .15s;
  min-height: 62px; display: flex; align-items: center; justify-content: center; position: relative;
}
.exp-cell:hover { border-color: var(--acc); background: #f0f6ff; }
.exp-cell.active { border-color: var(--acc); background: var(--acc-l); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.exp-cell.empty-cell { cursor: default; background: var(--sur2); border-style: dashed; border-color: var(--dim); }
.exp-cell.empty-cell:hover { border-color: var(--dim); background: var(--sur2); box-shadow: none; }
.exp-cell-num { font-size: 22px; font-weight: 700; color: var(--acc); display: block; line-height: 1; }
.exp-cell-lbl { font-size: 12px; color: var(--muted); display: block; margin-top: 3px; }
.exp-cell-empty-lbl { font-size: 14px; color: var(--dim); }

/* ── Unlock summary table ── */
.unlock-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.unlock-table th { padding: 6px 10px; background: var(--sur2); border-bottom: 1px solid var(--bdr); text-align: center; font-size: 12px; font-weight: 700; color: var(--sec); }
.unlock-table td { padding: 7px 10px; border-bottom: 1px solid var(--bdr); text-align: center; }
.unlock-table tr:last-child td { border-bottom: none; }
.unlock-table .row-label { text-align: left; font-weight: 600; color: var(--txt); font-size: 14px; display: flex; align-items: center; gap: 6px; }
.unlock-table .row-label .ic { width: 14px; height: 14px; }
.unlock-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.dot-locked   { background: var(--dim); }
.dot-unlocked { background: var(--yel); }
.dot-done     { background: var(--grn); }

/* ── Detail panel ── */
.detail-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.detail-panel-title { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.detail-panel-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }

/* ── Session cards ── */
.sess-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.sess-card { background: var(--sur2); border: 1px solid var(--bdr); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.sess-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.sess-card-title { font-weight: 700; font-size: 16px; color: var(--txt); }
.sess-card-docid { font-size: 12px; color: var(--muted); font-family: var(--font-mono); margin-top: 2px; }
.sess-card-actions { display: flex; gap: 5px; flex-shrink: 0; }
.sess-meta { display: flex; flex-direction: column; gap: 5px; }
.meta-row { display: flex; gap: 8px; font-size: 14px; }
.meta-k { color: var(--muted); min-width: 74px; flex-shrink: 0; }
.meta-v { color: var(--txt); font-weight: 500; }

/* ── Record cards (tiles / meteors / questions) ── */
.session-overview { border-bottom: 1px solid var(--bdr); margin-bottom: 18px; padding-bottom: 16px; }
.section-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; color: var(--txt); }
.rec-summary { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.rec-summary.compact { gap: 10px; margin-bottom: 14px; }
.rec-stat { background: var(--sur2); border: 1px solid var(--bdr); border-radius: 10px; padding: 10px 16px; min-width: 110px; }
.rec-stat .k { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.rec-stat .v { font-size: 20px; font-weight: 700; }
.summary-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 18px; }
.rec-sections { max-height: 55vh; overflow-y: auto; padding-right: 3px; }
.rec-star { border: 1px solid var(--bdr); border-radius: 10px; background: var(--sur); margin-bottom: 12px; overflow: hidden; }
.rec-star-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; cursor: pointer; font-size: 15px; font-weight: 700; color: var(--txt); background: var(--sur2); }
.rec-star-title span { color: var(--muted); font-size: 12px; font-weight: 600; }
.rec-star[open] .rec-star-title { border-bottom: 1px solid var(--bdr); }
.rec-star .rec-section { border-left: none; border-right: none; border-radius: 0; margin-bottom: 0; }
.rec-star .rec-section:last-child { border-bottom: none; }
.rec-section { border: 1px solid var(--bdr); border-radius: 10px; background: var(--sur2); padding: 12px; margin-bottom: 12px; }
.rec-section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 700; color: var(--sec); margin-bottom: 10px; }
.rec-section-title span { color: var(--muted); font-size: 12px; font-weight: 600; }
.rec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; padding: 2px; }
.rec-card { background: var(--sur); border: 1.5px solid var(--bdr); border-radius: 10px; padding: 10px 12px; border-top-width: 3px; }
.rec-card.ok   { border-top-color: var(--grn); }
.rec-card.bad  { border-top-color: var(--red); }
.rec-card.warn { border-top-color: var(--yel); }
.rec-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.rec-card-idx { font-size: 12px; color: var(--muted); font-weight: 600; }
.rec-card-main { font-size: 17px; font-weight: 700; margin-bottom: 6px; word-break: break-word; }
.rec-card-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--sec); margin-top: 2px; }
.rec-card-row .lbl { color: var(--muted); }

/* ── Confirm delete modal ── */
.confirm-icon { width: 46px; height: 46px; border-radius: 50%; background: var(--red-l); color: var(--red); display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.confirm-icon .ic { width: 22px; height: 22px; }
.confirm-msg { font-size: 15px; color: var(--sec); line-height: 1.7; }
.confirm-msg strong { color: var(--txt); }

/* ── Modal ── */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal { background: var(--sur); border: 1px solid var(--bdr); border-radius: 16px; width: 640px; max-width: 95vw; max-height: 85vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(15,23,42,.18); }
.modal-hd { padding: 18px 22px; border-bottom: 1px solid var(--bdr); display: flex; justify-content: space-between; align-items: center; }
.modal-hd h3 { font-size: 17px; font-weight: 700; }
.modal-bd { padding: 20px 22px; overflow-y: auto; flex: 1; }
.modal-ft { padding: 16px 22px; border-top: 1px solid var(--bdr); display: flex; gap: 8px; justify-content: flex-end; }

/* ── Progress bar ── */
.prog-bar { height: 6px; background: var(--bdr); border-radius: 3px; overflow: hidden; flex: 1; }
.prog-fill { height: 100%; border-radius: 3px; }

/* ── Empty / spinner ── */
.empty { padding: 44px 24px; text-align: center; color: var(--muted); }
.empty .ic { width: 30px; height: 30px; margin-bottom: 10px; }
.empty p { font-size: 15px; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--bdr); border-top-color: var(--acc); border-radius: 50%; animation: sp .65s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ── Misc ── */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap6 { gap: 6px; } .gap8 { gap: 8px; } .gap12 { gap: 12px; }
.mb8 { margin-bottom: 8px; } .mb12 { margin-bottom: 12px; } .mb16 { margin-bottom: 16px; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; }
.text-muted { color: var(--muted); font-size: 14px; }
.text-sec { color: var(--sec); font-size: 15px; }
.fw600 { font-weight: 600; } .fw700 { font-weight: 700; }
hr.div { border: none; border-top: 1px solid var(--bdr); margin: 14px 0; }

/* Unlock-levels page ("ปลดล็อคด่าน") writes star numbers (ดาวที่ N)
   in the Thai font instead of the site-wide English-first default. */
.num-th { font-family: var(--font-ui-th); }
/* English-first font, forced explicitly — brand/product name, game
   names, and stat numbers that must never fall back to the Thai font. */
.font-en { font-family: var(--font-ui); }
