/* Khmer Scribe dashboard — design language adapted from Chamnar.
   Latin = JetBrains Mono, Khmer = Battambang. Both bundled locally. */
@font-face {
  font-family: "JetBrains Mono";
  font-weight: 100 800;
  font-display: swap;
  src: url("../fonts/JetBrainsMono.woff2") format("woff2");
}
@font-face {
  font-family: "Battambang";
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/Battambang-Regular.woff2") format("woff2");
}
@font-face {
  font-family: "Battambang";
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/Battambang-Bold.woff2") format("woff2");
}

:root {
  --bg: #f5f5f7; --card: #fff; --text: #1d1d1f; --muted: #6e6e73;
  --faint: #9a9aa0; --hair: #dcdce1;
  --blue: #0071e3; --blue2: #0a84ff; --green: #34c759; --orange: #ff9500;
  --red: #ff3b30; --purple: #5e5ce6;
  --grad: linear-gradient(90deg, #0a84ff, #5e5ce6);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-s: 0 1px 3px rgba(0, 0, 0, 0.09);
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --kh: "Battambang", serif;
  --ui: "JetBrains Mono", "Battambang", ui-monospace, monospace;
  --h: 40px; --r: 11px;
}
[data-theme="dark"] {
  --bg: #0d0e11; --card: #1a1c20; --text: #e8e8ea; --muted: #9aa0a6;
  --faint: #6b7075; --hair: #2c2f36;
  --shadow: 0 6px 28px rgba(0, 0, 0, 0.55); --shadow-s: 0 1px 3px rgba(0, 0, 0, 0.5);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--ui); background: var(--bg); color: var(--text);
  font-size: 13px; line-height: 1.5; letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}
.khmer, .caption, .transcript, .seg-text, .kh { font-family: var(--kh); }
a { color: var(--blue); text-decoration: none; }

/* ---------- nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
[data-theme="dark"] .nav {
  background: rgba(20, 21, 25, 0.82); border-bottom-color: rgba(255, 255, 255, 0.08);
}
.nav-in {
  max-width: 1180px; margin: 0 auto; padding: 0 22px; height: 58px;
  display: flex; align-items: center; gap: 14px;
}
.logo { width: 34px; height: 34px; border-radius: 9px; display: block;
  box-shadow: 0 2px 10px rgba(10, 132, 255, 0.35); }
.brand { display: flex; align-items: baseline; gap: 7px; }
.brand h1 { margin: 0; font-size: 16px; font-weight: 800; letter-spacing: -0.02em; }
.brand .kh { font-size: 13px; color: var(--muted); font-weight: 700; }
.navlinks { display: flex; gap: 4px; align-items: center; margin-left: 8px; }
.nav-item {
  display: inline-flex; align-items: center; height: 34px; padding: 0 14px;
  border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 13px;
  cursor: pointer; border: 0; background: transparent; font-family: var(--ui);
}
.nav-item:hover { background: #ececf0; color: var(--text); }
.nav-item.active { background: #e8effc; color: var(--blue); }
[data-theme="dark"] .nav-item:hover { background: #22252b; color: var(--text); }
[data-theme="dark"] .nav-item.active { background: #1e2a44; color: var(--blue2); }
.sp { flex: 1; }

/* ---------- buttons ---------- */
button, .btn, .btn-p, .btn-g, .btn-d, .btn-primary, .btn-danger {
  font-family: var(--ui); font-weight: 700; font-size: 13px; height: var(--h);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 0; border-radius: var(--r); padding: 0 16px; cursor: pointer;
  transition: 0.15s; white-space: nowrap; letter-spacing: -0.01em; text-decoration: none;
  color: var(--text); background: #ececef;
}
.btn-p, .btn-primary { background: var(--blue); color: #fff; }
.btn-p:hover, .btn-primary:hover { background: #0062c4; }
.btn-g, .btn:not(.btn-primary):not(.btn-danger) { background: #ececef; color: var(--text); }
.btn-g:hover, .btn:not(.btn-primary):not(.btn-danger):hover { background: #e2e2e6; }
.btn-d, .btn-danger { background: #fdeceb; color: var(--red); }
.btn-d:hover, .btn-danger:hover { background: #fbddda; }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12px; }
.btn-block { width: 100%; }
.iconbtn { width: 34px; padding: 0; justify-content: center; }
[data-theme="dark"] .btn-g, [data-theme="dark"] .btn:not(.btn-primary):not(.btn-danger) { background: #2a2d33; color: var(--text); }
[data-theme="dark"] .btn-g:hover { background: #343841; }
[data-theme="dark"] .btn-p, [data-theme="dark"] .btn-primary { background: var(--blue2); }
[data-theme="dark"] .btn-d, [data-theme="dark"] .btn-danger { background: #3a1e1c; color: #ff6b60; }

/* ---------- inputs ---------- */
.input, input, textarea, select {
  font-family: var(--ui); font-size: 14px; height: var(--h); padding: 0 13px;
  border: 1.5px solid var(--hair); border-radius: var(--r); background: #fff;
  color: var(--text); width: 100%;
}
textarea { height: auto; padding: 11px 13px; line-height: 1.6; }
.input:focus, input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}
[data-theme="dark"] .input, [data-theme="dark"] input,
[data-theme="dark"] textarea, [data-theme="dark"] select { background: #141518; color: var(--text); }

/* ---------- layout ---------- */
.wrap { max-width: 1180px; margin: 26px auto; padding: 0 22px; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.view-head h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; margin: 0; }
.muted { color: var(--muted); margin: 2px 0 0; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar .input { width: auto; }
#search { min-width: 260px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- cards ---------- */
.card {
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow);
  border: 1px solid rgba(0, 0, 0, 0.04); padding: 18px; margin-bottom: 16px;
}
[data-theme="dark"] .card { border-color: rgba(255, 255, 255, 0.06); }
.card-title { font-weight: 800; font-size: 14px; margin-bottom: 14px; letter-spacing: -0.01em; }

/* ---------- kpi ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid rgba(0, 0, 0, 0.04);
  border-radius: 18px; padding: 16px 18px; box-shadow: var(--shadow); }
[data-theme="dark"] .kpi { border-color: rgba(255, 255, 255, 0.06); }
.kpi .label { font-size: 11px; color: var(--faint); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em; }
.kpi .value { font-size: 26px; font-weight: 800; margin-top: 6px; line-height: 1;
  font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- charts ---------- */
.chart { width: 100%; }
.chart-empty { color: var(--muted); font-size: 13px; padding: 10px 0; }
.hbar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.hbar-label { width: 130px; font-size: 13px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; flex: none; }
.hbar-track { flex: 1; background: rgba(10, 132, 255, 0.1); border-radius: 99px;
  height: 20px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 99px; background: var(--grad); }
.hbar-val { width: 54px; text-align: right; font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums; flex: none; }

/* ---------- recent ---------- */
.recent { display: flex; flex-direction: column; gap: 2px; }
.recent-item { display: flex; align-items: center; gap: 12px; padding: 10px 8px;
  border-radius: 12px; cursor: pointer; }
.recent-item:hover { background: rgba(10, 132, 255, 0.07); }
.recent-item img { width: 44px; height: 56px; border-radius: 8px; object-fit: cover;
  background: var(--hair); flex: none; }
.recent-item .cap { flex: 1; min-width: 0; overflow: hidden; }
.recent-item .meta { font-size: 12px; color: var(--muted); }

/* ---------- table ---------- */
.table-wrap { background: var(--card); border: 1px solid rgba(0, 0, 0, 0.04);
  border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
[data-theme="dark"] .table-wrap { border-color: rgba(255, 255, 255, 0.06); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th, .table td { text-align: left; padding: 13px 14px;
  border-bottom: 1px solid #ececee; font-size: 13px; vertical-align: middle; }
[data-theme="dark"] .table th, [data-theme="dark"] .table td { border-bottom-color: #2c2f36; }
.table th { color: var(--faint); font-weight: 700; font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.05em; }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: rgba(10, 132, 255, 0.06); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .thumb { width: 40px; height: 52px; border-radius: 7px; object-fit: cover; background: var(--hair); }
.table .cap { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-del { border: none; background: transparent; color: var(--faint); cursor: pointer;
  font-size: 15px; padding: 4px; height: auto; }
.row-del:hover { color: var(--red); }

/* ---------- audio status badge ---------- */
.audio-status { display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 9px; border-radius: 980px; margin-top: 4px; }
.as-ready { background: rgba(52, 199, 89, 0.15); color: #248a3d; }
.as-processing, .as-downloading, .as-queued { background: rgba(10, 132, 255, 0.14); color: var(--blue); }
.as-error { background: rgba(255, 59, 48, 0.14); color: var(--red); }
.as-none { background: rgba(128, 128, 128, 0.14); color: var(--muted); }

/* ---------- live banner + dataset ---------- */
.live-banner { display: flex; align-items: center; gap: 9px;
  background: rgba(10, 132, 255, 0.1); color: var(--blue);
  border: 1px solid rgba(10, 132, 255, 0.28); border-radius: 14px;
  padding: 10px 14px; font-weight: 700; font-size: 13px; margin-bottom: 16px; }
[data-theme="dark"] .live-banner { color: var(--blue2); }
.live-banner .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--blue2);
  animation: pulse 1.8s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(10, 132, 255, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(10, 132, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(10, 132, 255, 0); }
}
.live-count { margin-left: auto; font-weight: 600; opacity: 0.8; }
.dataset-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.dataset-stats .d { background: rgba(10, 132, 255, 0.07); border-radius: 12px; padding: 12px 14px; }
.dataset-stats .dv { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.dataset-stats .dl { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(2px); z-index: 100; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(580px, 95vw);
  background: var(--card); border-left: 1px solid var(--hair);
  box-shadow: -24px 0 64px rgba(0, 0, 0, 0.3); z-index: 110; overflow-y: auto;
  padding: 24px; animation: slideIn 0.22s ease; }
@keyframes slideIn { from { transform: translateX(28px); opacity: 0.4; } }
.drawer-head { display: flex; gap: 14px; margin-bottom: 16px; }
.drawer-head img { width: 92px; height: 120px; border-radius: 12px; object-fit: cover;
  background: var(--hair); flex: none; }
.drawer h2 { font-size: 16px; margin: 0 0 6px; line-height: 1.5; font-weight: 800; }
.drawer .sub { font-size: 12.5px; color: var(--muted); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700;
  padding: 5px 11px; border-radius: 980px; border: 1px solid var(--hair); background: var(--card); }
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--hair); margin: 16px 0 14px; }
.tab { border: 0; background: none; font-weight: 700; color: var(--muted);
  padding: 8px 10px; cursor: pointer; border-bottom: 2px solid transparent; height: auto; border-radius: 0; }
.tab.active { color: var(--blue); border-color: var(--blue); }
.tabpane { display: none; }
.tabpane.active { display: block; }
.transcript { line-height: 2; font-size: 15px; white-space: pre-wrap; }
.cues { display: flex; flex-direction: column; gap: 2px; }
.cue { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--hair); }
.cue .t { color: var(--blue); font-size: 12px; font-variant-numeric: tabular-nums; flex: none; width: 58px;
  font-family: var(--mono); }
.field-label { font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--faint); margin: 14px 0 7px; }
.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.close-x { position: absolute; top: 18px; right: 18px; background: var(--bg); color: var(--muted);
  width: 32px; height: 32px; border-radius: 9px; font-size: 18px; }
.seg-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--hair); }
.seg-row audio { height: 34px; flex: none; width: 190px; }
.seg-row .seg-text { flex: 1; font-size: 14px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; }
.goalbar { height: 14px; border-radius: 999px; background: rgba(10, 132, 255, 0.12); overflow: hidden; }
.goalbar-fill { height: 100%; width: 0; border-radius: 999px; background: var(--grad); transition: width 0.6s; min-width: 2px; }

/* ---------- empty ---------- */
.empty { text-align: center; padding: 70px 20px; }
.empty-logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 16px;
  box-shadow: 0 10px 30px rgba(10, 132, 255, 0.3); }
.empty h2 { margin: 0 0 6px; font-size: 20px; font-weight: 800; }

/* ---------- misc ---------- */
.hint { font-size: 12px; color: var(--muted); margin: 2px 0 10px; line-height: 1.6; }
code { font-family: var(--mono); font-size: 12px; background: rgba(128,128,128,0.12);
  padding: 1px 6px; border-radius: 6px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  z-index: 300; background: rgba(20, 21, 25, 0.94); color: #fff; padding: 11px 18px;
  border-radius: 12px; font-size: 13px; font-weight: 600; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; }
#toast.on, #toast:not(.hidden) { opacity: 1; transform: translateX(-50%) translateY(0); }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: #c7c7cc; border-radius: 8px; border: 3px solid var(--bg); }
.hidden { display: none !important; }
