:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1b2430;
  --muted: #667085;
  --line: #e4e8ee;
  --brand: #0f4c81;
  --brand-2: #0b3a63;
  --accent: #0ea5a4;
  --green: #15803d;
  --red: #b42318;
  --amber: #b45309;
  --radius: 12px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px; line-height: 1.55;
}
a { color: var(--brand); }
h1, h2 { margin: 0 0 12px; line-height: 1.3; }
h2 { font-size: 18px; }
.title { font-size: 21px; margin: 0; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; white-space: nowrap; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 24px; background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 600; }
.brand small { display: block; font-weight: 400; font-size: 12px; opacity: .75; }
.logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: rgba(255,255,255,.15); font-size: 20px; }
.logo.big { width: 56px; height: 56px; font-size: 32px; background: var(--brand); color: #fff; border-radius: 14px; }
.who { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.who .btn.ghost { color: #fff; border-color: rgba(255,255,255,.45); }
.who .btn.ghost:hover { background: rgba(255,255,255,.12); }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 16px 48px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent; cursor: pointer;
  font: inherit; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.primary:disabled { background: #a9b6c4; cursor: not-allowed; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { background: #eef2f6; }
.btn.danger { color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.full { width: 100%; }

label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; margin-bottom: 14px; }
input:not([type=file]) {
  font: inherit; padding: 10px 12px; border: 1px solid #cfd6df; border-radius: 8px; background: #fff;
}
input:focus { outline: 2px solid #9ec5ea; border-color: var(--brand); }

.alert { padding: 10px 14px; border-radius: 8px; margin: 10px 0; font-size: 14px; }
.alert.err { background: #fde8e7; color: var(--red); }
.alert.ok { background: #e3f4e8; color: var(--green); }
.alert.warn { background: #fdf0dd; color: var(--amber); }
.err-text { color: var(--red); }

/* login */
.login { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 400px; padding: 32px; }
.login-head { text-align: center; margin-bottom: 18px; }
.login-head h1 { font-size: 21px; margin: 14px 0 4px; }

/* upload */
.drop {
  position: relative; border: 2px dashed #b9c4d0; border-radius: var(--radius); padding: 28px 16px;
  text-align: center; background: #f9fbfd; cursor: pointer; transition: .15s;
}
.drop.over, .drop:hover { border-color: var(--brand); background: #eef5fc; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.drop .link { color: var(--brand); text-decoration: underline; }
.picked { margin-top: 10px; font-weight: 600; color: var(--brand); word-break: break-all; }
.row { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; margin-top: 16px; }
.row .grow { flex: 1; min-width: 240px; }
.row .btn { margin-bottom: 14px; padding: 11px 20px; }
.row label .small { font-weight: 400; }
.upbox { margin-top: 6px; }
.uprow { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 6px; font-size: 14px; }
.bar { height: 10px; background: #e6ebf1; border-radius: 99px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--accent)); transition: width .3s; }
.bar.sm { height: 6px; margin: 6px 0 2px; width: 160px; max-width: 100%; }
.settings { margin: 10px 0 0; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 13px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: #fafbfd; }
.fname { font-weight: 600; word-break: break-all; }
.act { white-space: nowrap; text-align: right; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; }
.badge.gray { background: #eef1f5; color: #475467; }
.badge.blue { background: #e2eefb; color: var(--brand); }
.badge.green { background: #e3f4e8; color: var(--green); }
.badge.red { background: #fde8e7; color: var(--red); }
.chip { display: inline-block; padding: 3px 10px; border-radius: 99px; background: #eef2f6; font-size: 13px; margin: 0 4px 4px 0; border: 1px solid transparent; font-family: inherit; }
button.chip { cursor: pointer; }
button.chip.on { background: var(--brand); color: #fff; }
.segs img { width: 240px; max-width: 40vw; border-radius: 8px; display: block; border: 1px solid var(--line); }

/* report */
.back { display: inline-block; margin-bottom: 14px; text-decoration: none; }
.dl { display: flex; gap: 8px; flex-wrap: wrap; }
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-top: 6px; }
.meta div { background: #f6f8fb; border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; }
.meta span { font-size: 12px; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  text-align: left; font: inherit; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; border-top: 4px solid var(--accent);
}
.stat:hover { border-color: var(--brand); }
.stat-label { font-weight: 600; }
.stat-label small { margin-left: 6px; color: var(--muted); font-weight: 400; }
.stat-num { font-size: 32px; font-weight: 700; color: var(--brand); line-height: 1.2; }
.filters { display: flex; flex-wrap: wrap; }
.note { margin-top: 8px; }

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .who span { display: none; }
  .wrap { padding: 16px 16px 40px; }
  .card { padding: 16px; }
  .segs img { width: 150px; }
}

/* ---------- v2 ---------- */
.nav { display: flex; gap: 4px; margin-right: auto; margin-left: 24px; }
.nav a { color: rgba(255,255,255,.8); text-decoration: none; padding: 6px 12px; border-radius: 8px; font-size: 14px; }
.nav a:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav a.on { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }
.who small { opacity: .75; }
.step { font-size: 12px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 2px; }
.selbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 4px 0 14px; }
.selbar .chip { margin: 0; background: #e2eefb; color: var(--brand); font-weight: 500; }
.badge.amber { background: #fdf0dd; color: var(--amber); }
code { background: #eef2f6; padding: 1px 6px; border-radius: 4px; font-size: 13px; }

/* class table */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 8px 0 12px; }
.toolbar input[type=search] { min-width: 240px; padding: 8px 12px; }
.toolbar .grow { flex: 1; }
label.inline { flex-direction: row; align-items: center; gap: 6px; margin: 0; font-weight: 400; font-size: 14px; }
.cls td, .cls th { vertical-align: middle; }
.cls tbody tr { cursor: pointer; }
.cls tbody tr.sel { background: #eef6fd; }
.cls .c { width: 60px; text-align: center; }
.cls input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; }
.ex { display: flex; gap: 6px; }
.ex img { width: 96px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }

/* status grid: 20 ช่องต่อแถว */
.grid { display: grid; grid-template-columns: repeat(20, minmax(0, 1fr)); gap: 6px; }
.cell { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 12px; color: var(--muted); text-decoration: none; }
.cell b { position: absolute; top: -7px; right: -5px; background: var(--red); color: #fff; font-size: 10px; min-width: 18px; height: 18px;
  border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }
a.cell[href]:hover { border-color: var(--red); }
.dot { display: inline-block; width: 18px; height: 18px; border-radius: 50%; border: 2px solid #c7cfd9; background: #fff; vertical-align: middle; }
.dot.split { background: #facc15; border-color: #eab308; }
.dot.detecting { background: #facc15; border-color: #2563eb; box-shadow: 0 0 0 0 rgba(37,99,235,.6); animation: pulse 1.2s infinite; }
.dot.clear { background: #22c55e; border-color: #16a34a; }
.dot.found { background: #ef4444; border-color: #dc2626; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(37,99,235,.6); } 70% { box-shadow: 0 0 0 7px rgba(37,99,235,0); } 100% { box-shadow: 0 0 0 0 rgba(37,99,235,0); } }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .dot { width: 14px; height: 14px; }
.clipcard h2 { font-size: 16px; }
.clipcard { scroll-margin-top: 12px; }
.meta small { font-size: 12px; margin-top: 2px; }

@media (max-width: 900px) {
  .grid { grid-template-columns: repeat(10, minmax(0, 1fr)); }
  .nav { margin-left: 8px; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .nav { order: 3; width: 100%; margin: 6px 0 0; }
  .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .ex img { width: 64px; height: 44px; }
}

/* ---------- v3: motion pre-filter ---------- */
.cell em.pk { position: absolute; top: 2px; left: 4px; font-style: normal; font-size: 9px; font-weight: 700; color: #6b7280; }
.motionbar { margin-top: 14px; }
.mbar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: #e6ebf1; margin-bottom: 6px; }
.mbar i { display: block; height: 100%; }
.mbar .d, .k.d { background: #0f4c81; }
.mbar .a, .k.a { background: #f59e0b; }
.mbar .q, .k.q { background: #cbd5e1; }
.k { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin: 0 4px 0 2px; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; white-space: nowrap; }
.tag.d { background: #e2eefb; color: var(--brand); }
.tag.a { background: #fdf0dd; color: var(--amber); }
.tag.q { background: #eef1f5; color: #475467; }
