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

:root {
  --brand: #c2410c;
  --brand-dark: #9a3412;
  --brand-light: #ffedd5;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --bg: #f4f5f7;
}

* { font-family: 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif; }
body { background: var(--bg); color: var(--ink); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: #eef2f6; }
::-webkit-scrollbar-thumb { background: #b6c2cf; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ---------- shell ---------- */
.topbar { background: linear-gradient(100deg, var(--brand) 0%, var(--brand-dark) 100%); }
.navlink {
  padding: .45rem .8rem; border-radius: .55rem; font-size: .84rem; font-weight: 500;
  color: rgba(255,255,255,.82); white-space: nowrap; transition: all .15s;
}
.navlink:hover { background: rgba(255,255,255,.16); color: #fff; }
.navlink.active { background: #fff; color: var(--brand-dark); font-weight: 600; }

.card { background: #fff; border: 1px solid var(--line); border-radius: .75rem; }
.card-h { padding: .7rem 1rem; border-bottom: 1px solid var(--line); font-weight: 600; font-size: .9rem; }

/* ---------- KPI ---------- */
.kpi { background: #fff; border: 1px solid var(--line); border-radius: .75rem; padding: .85rem 1rem;
  position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--brand); }
.kpi-label { font-size: .72rem; color: var(--muted); font-weight: 500; }
.kpi-value { font-size: 1.35rem; font-weight: 700; line-height: 1.25; }
.kpi-sub { font-size: .7rem; color: var(--muted); }
.kpi.k-green::before { background: #10b981; }
.kpi.k-amber::before { background: #f59e0b; }
.kpi.k-red::before   { background: #ef4444; }
.kpi.k-violet::before{ background: #8b5cf6; }
.kpi.k-slate::before { background: #64748b; }
.kpi.k-blue::before  { background: #0ea5e9; }

/* ---------- table ---------- */
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .8rem; }
.tbl thead th { position: sticky; top: 0; z-index: 5; background: #f8fafc; color: #475569;
  font-weight: 600; text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tbody td { padding: .45rem .6rem; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.tbl tbody tr:hover { background: #fff7ed; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- pills ---------- */
.pill { display: inline-block; padding: .1rem .45rem; border-radius: 999px; font-size: .68rem;
  font-weight: 600; white-space: nowrap; }
.p-crit { background: #fee2e2; color: #991b1b; }
.p-major{ background: #fef3c7; color: #92400e; }
.p-minor{ background: #e0f2fe; color: #075985; }
.p-ok   { background: #d1fae5; color: #065f46; }
.p-fail { background: #fee2e2; color: #991b1b; }
.p-na   { background: #f1f5f9; color: #64748b; }
.p-gray { background: #f1f5f9; color: #475569; }
.p-photo{ background: #ede9fe; color: #5b21b6; }

.btn { padding: .4rem .85rem; border-radius: .5rem; font-size: .8rem; font-weight: 500;
  transition: .15s; display: inline-flex; align-items: center; gap: .3rem; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: #fff; border: 1px solid var(--line); color: #334155; }
.btn-ghost:hover { background: #f8fafc; }
.btn-danger { background: #fee2e2; color: #991b1b; }
.btn-danger:hover { background: #fecaca; }
.btn-ok { background: #059669; color: #fff; }
.btn-ok:hover { background: #047857; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.inp { border: 1px solid var(--line); border-radius: .5rem; padding: .38rem .6rem;
  font-size: .8rem; background: #fff; width: 100%; }
.inp:focus { outline: 2px solid var(--brand-light); border-color: var(--brand); }
label.fld { display: block; font-size: .72rem; color: var(--muted); font-weight: 500; margin-bottom: .15rem; }

/* ---------- hotspot card ---------- */
.hs-card { background: #fff; border: 1px solid var(--line); border-radius: .75rem; overflow: hidden;
  display: flex; flex-direction: column; transition: box-shadow .15s, transform .15s; }
.hs-card:hover { box-shadow: 0 6px 18px -8px rgba(15,23,42,.25); transform: translateY(-1px); }
.hs-thumb { width: 100%; height: 128px; object-fit: cover; background: #f1f5f9; display: block; }
.hs-noimg { width: 100%; height: 128px; display: flex; align-items: center; justify-content: center;
  background: repeating-linear-gradient(45deg, #f8fafc, #f8fafc 8px, #f1f5f9 8px, #f1f5f9 16px);
  color: #94a3b8; font-size: .72rem; }
.hs-body { padding: .6rem .75rem; flex: 1; display: flex; flex-direction: column; gap: .3rem; }
.hs-title { font-size: .84rem; font-weight: 600; line-height: 1.3; }
.hs-meta { font-size: .68rem; color: var(--muted); }

/* กล่องเปรียบเทียบ ผิด / ถูก */
.cmp { border-radius: .6rem; overflow: hidden; border: 2px solid transparent; }
.cmp.wrong { border-color: #fca5a5; }
.cmp.correct { border-color: #6ee7b7; }
.cmp-h { font-size: .72rem; font-weight: 700; padding: .25rem .5rem; }
.cmp.wrong .cmp-h { background: #fee2e2; color: #991b1b; }
.cmp.correct .cmp-h { background: #d1fae5; color: #065f46; }

/* ---------- checklist row ---------- */
.ck { border: 1px solid var(--line); border-radius: .6rem; background: #fff; padding: .6rem .7rem; }
.ck.is-pass { border-color: #6ee7b7; background: #f0fdf4; }
.ck.is-fail { border-color: #fca5a5; background: #fef2f2; }
.ck.is-na   { border-color: #cbd5e1; background: #f8fafc; opacity: .75; }
.ck-btn { padding: .3rem .6rem; border-radius: .45rem; font-size: .74rem; font-weight: 600;
  border: 1px solid var(--line); background: #fff; color: #475569; }
.ck-btn.on-pass { background: #059669; color: #fff; border-color: #059669; }
.ck-btn.on-fail { background: #dc2626; color: #fff; border-color: #dc2626; }
.ck-btn.on-na   { background: #64748b; color: #fff; border-color: #64748b; }

/* ---------- กล่องเลือกขอบเขต Zone / Type ---------- */
.scope { border: 1px solid var(--line); border-radius: .5rem; overflow: hidden; background: #fff; }
.scope-all {
  display: flex; align-items: center; gap: .45rem; padding: .45rem .6rem;
  background: #fff7ed; border-bottom: 1px solid var(--line);
  font-size: .78rem; font-weight: 600; color: var(--brand-dark); cursor: pointer;
}
.scope-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .1rem; padding: .35rem .4rem; }
.scope-list.is-off { opacity: .45; }
.scope-item {
  display: flex; align-items: center; gap: .4rem; padding: .22rem .35rem;
  border-radius: .35rem; font-size: .78rem; cursor: pointer;
}
.scope-item:hover { background: #fff7ed; }
.scope-list.is-off .scope-item { cursor: not-allowed; }
.scope input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--brand); cursor: pointer; }
.scope-list.is-off input[type="checkbox"] { cursor: not-allowed; }

/* ---------- ตัวเลือกภาษา ---------- */
.langbox { position: relative; }
.langbtn {
  font-size: .72rem; background: rgba(255,255,255,.16); color: #fff;
  padding: .28rem .55rem; border-radius: .45rem; white-space: nowrap;
}
.langbtn:hover { background: rgba(255,255,255,.28); }
.langmenu {
  position: absolute; right: 0; top: calc(100% + .35rem); z-index: 50;
  background: #fff; border: 1px solid var(--line); border-radius: .6rem;
  box-shadow: 0 10px 28px -8px rgba(15,23,42,.35); overflow: hidden; min-width: 148px;
}
.langitem {
  display: block; width: 100%; text-align: left; padding: .5rem .75rem;
  font-size: .82rem; color: #334155;
}
.langitem:hover { background: #fff7ed; }
.langitem.on { background: var(--brand); color: #fff; font-weight: 600; }

/* ---------- วิดีโอสอน ---------- */
.p-vid { background: #fee2e2; color: #b91c1c; }
.vid-wrap {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: #0f172a; cursor: pointer; overflow: hidden;
}
.vid-wrap img { width: 100%; height: 100%; object-fit: cover; transition: opacity .15s; }
.vid-wrap:hover img { opacity: .8; }
.vid-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.vid-play {
  position: absolute; inset: 0; margin: auto; width: 54px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(220,38,38,.92); color: #fff; border-radius: 10px;
  font-size: 18px; pointer-events: none; transition: transform .15s;
}
.vid-wrap:hover .vid-play { transform: scale(1.12); }
@media print { .vid-wrap { display: none; } }

/* ---------- charts ---------- */
.chart-svg { width: 100%; display: block; overflow: visible; }
.chart-svg text { font-size: 11px; fill: #64748b; }
.chart-svg .lbl-strong { fill: #334155; font-weight: 600; }
.bar-rect { transition: opacity .15s; }
.bar-rect:hover { opacity: .78; }

.progress { height: 7px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); }

.spinner { border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%;
  width: 24px; height: 24px; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- quiz ---------- */
.qz-choice { width: 100%; text-align: left; border: 1px solid var(--line); background: #fff;
  border-radius: .6rem; padding: .6rem .8rem; font-size: .84rem; transition: .12s; }
.qz-choice:hover:not(:disabled) { border-color: var(--brand); background: #fff7ed; }
.qz-choice.right { border-color: #059669; background: #d1fae5; font-weight: 600; }
.qz-choice.wrong { border-color: #dc2626; background: #fee2e2; }
.qz-img { width: 100%; max-height: 46vh; object-fit: contain; background: #0f172a; border-radius: .6rem; }

.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(15,23,42,.92);
  display: flex; align-items: center; justify-content: center; padding: 1rem; }
.lightbox img { max-width: 100%; max-height: 88vh; object-fit: contain; }

@media (max-width: 768px) {
  .kpi-value { font-size: 1.1rem; }
  .hide-sm { display: none; }
}
@media print {
  #nav, .no-print { display: none !important; }
  body { background: #fff; }
  .card { border-color: #cbd5e1; break-inside: avoid; }
}
