:root {
  --bg: #f6f4f1;
  --panel: #ffffff;
  --ink: #1f1d1a;
  --muted: #6b665e;
  --line: #e4dfd7;
  --accent: #b4532a;
  --accent-ink: #ffffff;
  --ok: #2f7d4f;
  --warn: #a86a00;
  --bad: #b3261e;
  --chip: #f1ece4;
  --new: #fff1d6;
  --ok-soft: #9cc9ad;
  --ok-bg: #f1f8f3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514; --panel: #1f1e1c; --ink: #ece8e2; --muted: #a39d93; --line: #34312d;
    --accent: #e07a4b; --accent-ink: #1a1a1a; --ok: #6cc28f; --warn: #e3b04b; --bad: #ef7b72;
    --chip: #2a2825; --new: #3a3020; --ok-soft: #3f7a58; --ok-bg: #1d2a22; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; text-decoration: none; color: var(--ink); }
.brand span { color: var(--accent); }
#nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
#nav a { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; }
#nav a.active, #nav a:hover { background: var(--chip); color: var(--ink); }
.me { color: var(--muted); display: flex; gap: 10px; align-items: center; }
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 22px 0 10px; }
.sub { color: var(--muted); margin: 0 0 16px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); }
.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=email], input[type=date], input[type=number], input[type=search], select, textarea {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
textarea { width: 100%; min-height: 70px; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; z-index: 2; background: var(--panel); }
.table-wrap { overflow: auto; max-height: calc(100vh - 150px); border: 1px solid var(--line); border-radius: var(--radius); }
.sec-row td { background: var(--chip); font-weight: 700; }
.thumb { width: 56px; height: 56px; object-fit: contain; border-radius: 6px; background: #fff; border: 1px solid var(--line); }
.thumb.big { width: 150px; height: 150px; }
.mcard { display: flex; gap: 6px; margin-top: 2px; } .mcard figure { margin: 0; text-align: center; } .mcard .thumb { width: 72px; height: 72px; } .mcard figcaption { font-size: 11px; color: var(--muted, #777); }
.chip { display: inline-block; padding: 2px 8px; border-radius: 99px; background: var(--chip); font-size: 12px; margin: 1px 2px 1px 0; }
.chip.new { background: var(--new); }
.chip.ok { color: var(--ok); }
.chip.warn { color: var(--warn); }
.chip.bad { color: var(--bad); }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }
.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a { padding: 5px 10px; border: 1px solid var(--line); border-radius: 99px; text-decoration: none; color: var(--ink); background: var(--panel); }
.tabs a.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.summary { background: var(--panel); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; }
.jobs { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }
.job { display: grid; grid-template-columns: 150px 1fr; gap: 14px; }
.job.done { opacity: .72; }
.job .meta { display: grid; gap: 4px; min-width: 0; }
.job .title { font-weight: 600; }
.kv { display: grid; grid-template-columns: 92px 1fr; gap: 2px 8px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.drop { border: 1.5px dashed var(--line); border-radius: 8px; padding: 8px; text-align: center; color: var(--muted); cursor: pointer; font-size: 12px; position: relative; }
.drop.over { border-color: var(--accent); background: var(--chip); }
.drop.has { border-style: solid; border-color: var(--ok); color: var(--ok); }
.drop input { display: none; }
.drops { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; margin-top: 6px; }
.files { display: grid; gap: 3px; margin-top: 6px; }
.files a { font-size: 12px; }
.progress { height: 3px; background: var(--accent); width: 0; transition: width .2s; position: absolute; left: 0; bottom: 0; }
details summary { cursor: pointer; color: var(--muted); }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; z-index: 50; }
#toast.show { opacity: 1; }
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--panel); color: var(--ink); width: min(640px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }
#modal-body { padding: 18px; display: grid; gap: 10px; }
#modal-body label { display: grid; gap: 4px; }
/* file viewer */
body.viewer-open { overflow: hidden; }
.viewer { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; }
.viewer-panel { width: min(1100px, 100%); height: min(88vh, 900px); background: var(--panel); border-radius: 12px; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; border: 1px solid var(--line); }
.viewer-head { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.viewer-tabs { display: flex; gap: 4px; flex-wrap: wrap; min-width: 0; }
.vtab { border: 1px solid var(--line); background: var(--panel); padding: 4px 10px; border-radius: 99px; cursor: pointer; font-size: 13px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vtab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.viewer-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.viewer-actions a.btn { text-decoration: none; color: inherit; }
.viewer-stage { position: relative; min-height: 0; display: grid; place-items: center; overflow: hidden; }
.viewer-stage.image { background: #ffffff; }
.viewer-body { display: grid; grid-template-columns: minmax(0, 1fr) auto; min-height: 0; }
.viewer-stage.stl { cursor: grab; background: radial-gradient(circle at 50% 40%, #f7f7f7, #d9d9d9); }
.viewer-stage.stl[data-bg="dark"] { background: radial-gradient(circle at 50% 40%, #4a4a4a, #1c1c1c); }
.viewer-stage.stl[data-bg="white"] { background: #ffffff; }
.viewer-stage.bail-hover, .viewer-stage.bail-hover canvas { cursor: move; }
.viewer-stage.bail-drag, .viewer-stage.bail-drag canvas { cursor: grabbing; }
.vbail { position: absolute; left: 12px; bottom: 12px; width: min(340px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow: auto; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 4px 18px rgba(0,0,0,.18); padding: 10px 12px; font-size: 13px; cursor: default; }
.vbail-title { display: flex; flex-direction: column; gap: 2px; }
.vbail-hint { margin: 6px 0 8px; color: var(--muted); font-size: 12px; }
.vbail-row { display: grid; grid-template-columns: 74px minmax(0, 1fr) 62px; align-items: center; gap: 6px; margin: 3px 0; }
.vbail-row b { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.vbail-hang { margin-top: 6px; font-size: 12px; color: var(--muted); }
.vbail-hang.vbad { color: var(--bad); }
.vbail-msg { margin-top: 6px; font-size: 12px; }
.vbail-msg:empty { display: none; }
.vbail-msg.vbad { color: var(--bad); }
/* 10/11: 🖍 Khoanh lỗi */
.vmark-ops { display: flex; flex-wrap: wrap; gap: 4px 10px; margin: 6px 0; }
.vmark-li { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 2px 0; font-size: 12px; }
.rv-fixsup { margin-top: 6px; display: grid; gap: 6px; }
.rv-fixsup .rv-fixprev { font-size: 12px; color: var(--muted); }
.rv-fixsup .rv-fixmarks { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.rv-fixsup img { height: 64px; border: 1px solid var(--line); border-radius: 4px; }
.rv-fiximgs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.rv-fiximgs img { height: 70px; border: 1px solid var(--line); border-radius: 4px; }
.vbail-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.viewer-side { width: 300px; border-left: 1px solid var(--line); overflow-y: auto; padding: 10px 14px 16px; display: grid; align-content: start; gap: 10px; font-size: 13px; }
.viewer-side[hidden] { display: none; }
.viewer-side h3 { margin: 4px 0 2px; font-size: 17px; font-weight: 600; }
.viewer-side section { display: grid; gap: 8px; }
.viewer-side section[hidden] { display: none; }
.viewer-side details { border-top: 1px solid var(--line); padding-top: 6px; }
.viewer-side summary { font-size: 14px; color: var(--ink); padding: 4px 0; }
.vside-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.vside-tab { border: 0; background: none; color: var(--muted); padding: 6px 8px; cursor: pointer; border-bottom: 2px solid transparent; }
.vside-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.vrow { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0 5px 8px; font-variant-numeric: tabular-nums; }
.vrow span { color: var(--muted); }
.vrow b { font-weight: 600; text-align: right; }
.vchips { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 0; }
.vchip { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 3px 10px; cursor: pointer; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.vchip i { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); display: inline-block; }
.vchip.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.vfield { display: grid; grid-template-columns: 96px minmax(0, 1fr); align-items: center; gap: 8px; padding: 4px 0 4px 8px; color: var(--muted); }
.vfield input[type=range] { width: 100%; accent-color: var(--accent); }
.vfield input[type=color] { width: 44px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }
.vradio { display: flex; align-items: center; gap: 8px; padding: 4px 0 4px 8px; cursor: pointer; }
.vradio input { accent-color: var(--accent); }
.vnote { margin: 4px 0 0 8px; font-size: 12px; color: var(--muted); }
.vok { color: var(--ok); }
.vbad { color: var(--bad); }
.vanim { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.vanim select { padding: 2px 6px; }
.viewer-actions svg { vertical-align: -3px; }
.viewer-stage.stl:active { cursor: grabbing; }
.viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
/* image viewer: the picture always fits the stage (absolute box), zoom / pan with transform */
.viewer-imgbox { position: absolute; inset: 0; overflow: hidden; touch-action: none; user-select: none; }
.viewer-stage .viewer-imgbox img, .viewer-stage.image .viewer-imgbox img { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; object-fit: contain; transform-origin: 50% 50%; display: block; }
.viewer-zoom { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 4px; align-items: center; background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; z-index: 2; }
.viewer-zoom-pct { min-width: 44px; text-align: center; font-size: 12px; font-variant-numeric: tabular-nums; }
.viewer-stage canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; touch-action: none; }
.viewer-msg { color: var(--muted); padding: 24px; text-align: center; }
.viewer-foot { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 13px; font-variant-numeric: tabular-nums; }
@media (max-width: 760px) {
  .viewer { padding: 0; }
  .viewer-panel { height: 100%; border-radius: 0; }
  .viewer-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .viewer-side { width: auto; max-height: 45vh; border-left: 0; border-top: 1px solid var(--line); }
}
.empty { padding: 30px; text-align: center; color: var(--muted); }
.edit { cursor: pointer; border-bottom: 1px dotted var(--muted); }
@media (max-width: 640px) {
  main { padding: 12px; }
  .jobs { grid-template-columns: 1fr; }
  .job { grid-template-columns: 1fr; }
  .thumb.big { width: 100%; height: 220px; }
  th { top: 0; }
}

/* column filters (Google Sheets style) */
.th { display: inline-flex; align-items: center; gap: 4px; }
.fbtn { border: 0; background: transparent; color: var(--muted); padding: 2px; border-radius: 4px; cursor: pointer; display: inline-flex; }
.fbtn:hover { background: var(--chip); color: var(--ink); }
th.filtered { color: var(--accent); }
th.filtered .fbtn { color: var(--accent); background: var(--new); }
.fpop { position: absolute; z-index: 60; width: 300px; max-width: calc(100vw - 16px); background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 6px 0; font-size: 14px; }
.fpop .fitem { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 16px; cursor: pointer; }
.fpop .fitem:hover { background: var(--chip); }
.fpop hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.fpop details { padding: 2px 16px 6px; }
.fpop summary { cursor: pointer; padding: 6px 0; font-weight: 500; list-style: none; display: block; }
.fpop summary::-webkit-details-marker { display: none; }
.fpop summary::before { content: "▸ "; color: var(--muted); }
.fpop details[open] > summary::before { content: "▾ "; }
.fpop .fcond, .fpop .ftext, .fpop .fsearch { width: 100%; margin-top: 6px; }
.fpop .fsel { margin-top: 2px; font-size: 13px; gap: 4px; }
.fpop .flist { max-height: 230px; overflow: auto; margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; }
.fpop .fval { display: flex; gap: 8px; align-items: center; padding: 3px 4px; cursor: pointer; border-radius: 6px; }
.fpop .fval:hover { background: var(--chip); }
.fpop .fv { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fpop .fbtns { justify-content: flex-end; padding: 8px 16px 4px; }
/* add-ons folded under their order */
tr.addon-sum td { background: var(--bg); color: var(--muted); font-size: 12px; cursor: pointer; padding: 4px 8px; }
tr.addon-sum:hover td { color: var(--ink); }
tr.addon-sum .caret { display: inline-block; width: 14px; color: var(--ink); }
tr.addon td { background: var(--bg); }
/* help */
.help-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--accent); border-radius: 99px; padding: 4px 10px 4px 6px; cursor: pointer; font-weight: 600; }
.help-btn:hover { border-color: var(--accent); }
dialog.wide { width: min(1040px, 96vw); }
dialog.wide video { width: 100%; max-height: 70vh; background: #000; border-radius: 8px; }
.chapters { display: flex; flex-wrap: wrap; gap: 6px; }
/* review & export */
.scope .row + .row { margin-top: 8px; }
.steps { display: flex; gap: 10px; margin: 14px 0; flex-wrap: wrap; }
.steps .step { flex: 1; min-width: 220px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); text-decoration: none; color: var(--ink); font-weight: 600; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.steps .step.active { border-color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
.rv-progress { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--chip); margin: 4px 0 6px; }
.rv-progress span { display: block; height: 100%; }
.rv-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.rv-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.rv-tools { margin-bottom: 12px; }
.rv-list { display: grid; gap: 12px; }
.rv-order { padding: 12px 14px; border-left: 5px solid var(--line); }
.rv-order.st-blocked { border-left-color: var(--bad); }
.rv-order.st-review { border-left-color: var(--warn); }
.rv-order.st-ready { border-left-color: var(--ok-soft); }
.rv-order.approved { border-left-color: var(--ok); background: var(--ok-bg); }
.rv-order.selected { outline: 2px solid var(--accent, #2563eb); outline-offset: -2px; }
.rv-head .rvsel { width: 18px; height: 18px; margin: 0 2px 0 0; }
.rv-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.rv-name { font-size: 15px; }
.rv-line { display: grid; grid-template-columns: 124px 124px 124px 1fr; gap: 12px; padding: 10px 0 6px; border-top: 1px dashed var(--line); align-items: start; }
.rv-fig { margin: 0; text-align: center; }
/* 30/10: tab Sẵn sàng — STL thumbnail corner tag: Auto STL (auto-approve rule) vs Cần xem */
.rv-fig { position: relative; }
.rv-tag { position: absolute; top: 4px; right: 4px; z-index: 1; padding: 1px 7px; border-radius: 99px; font-size: 11px; font-weight: 700; line-height: 16px; color: var(--bg); pointer-events: auto; cursor: help; white-space: nowrap; }
.rv-tag.auto { background: var(--ok); }
.rv-tag.look { background: var(--warn); }
.rv-stlf { gap: 6px; flex-wrap: wrap; margin: 6px 0 2px; }
.rv-stlf .chip { text-decoration: none; cursor: pointer; border: 1px solid transparent; }
.rv-stlf .chip.on { outline: 2px solid currentColor; outline-offset: -1px; font-weight: 700; }
.rv-stlf .chip:not(.ok):not(.warn) { color: var(--ink); }
.rv-fig img, .rv-empty, .rv-stl { width: 124px; height: 124px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #fff; display: flex; align-items: center; justify-content: center; }
.rv-fig figcaption { font-size: 11px; color: var(--muted); margin-top: 3px; }
.rv-empty { color: var(--muted); font-size: 12px; background: var(--bg); }
.rv-empty.bad { color: var(--bad); border-color: var(--bad); font-weight: 600; }
.rv-stl { flex-direction: column; gap: 2px; text-decoration: none; background: linear-gradient(160deg, #f4efe8, #e3d7c6); color: #3b2a1e; font-weight: 800; font-size: 22px; }
.rv-stl small { font-weight: 600; font-size: 12px; color: var(--accent); }
.rv-info { display: grid; gap: 4px; min-width: 0; align-content: start; }
.rv-engrave b { font-size: 16px; padding: 1px 8px; background: var(--new); border-radius: 6px; }
.rv-issues { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.rv-addons { font-size: 12px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 6px; }
@media (max-width: 760px) {
  .rv-line { grid-template-columns: repeat(3, 1fr); }
  .rv-info { grid-column: 1 / -1; }
  .rv-fig img, .rv-empty, .rv-stl { width: 100%; height: auto; aspect-ratio: 1; }
}
.nowrap { white-space: nowrap; }

.selc { width: 28px; text-align: center; }
.selc input { width: 16px; height: 16px; cursor: pointer; }
tr.selected td { background: var(--ok-bg); }
.bulkbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 10px;
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: 0 2px 10px rgba(0,0,0,.08); }
.bulkbar[hidden] { display: none; }
/* Đơn hàng uses the whole screen width so every column fits without sideways scrolling. */
main:has(#items-table) { max-width: none; padding: 12px 16px; }
main:has(#items-table) .table-wrap { max-height: calc(100vh - 140px); }
#items-table { font-size: 13px; }
#items-table th, #items-table td { padding: 6px; }
#items-table td.pname { min-width: 220px; white-space: normal; overflow-wrap: anywhere; }
#items-table td.pname > div { max-width: 380px; }
#items-table td.qcell { font-size: 12px; }
#items-table td.qcell .edit { width: clamp(150px, 15vw, 280px); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; overflow-wrap: anywhere; white-space: normal; }
/* copy-link button next to every design link */
.cpy { border: 0; background: transparent; color: var(--muted); padding: 2px 3px; margin-left: 2px; border-radius: 4px; cursor: pointer;
  display: inline-flex; vertical-align: middle; }
.cpy:hover { color: var(--ink); background: var(--chip); }
.cpy.copied { color: var(--ok); }
/* Nhận file hàng loạt */
.dropzone { margin-top: 12px; border: 2px dashed var(--line); border-radius: 12px; padding: 28px 16px; text-align: center; background: var(--bg); }
.dropzone.over { border-color: var(--accent, #b4532a); background: var(--ok-bg); }
.dropzone .btn { margin: 6px 4px 0; }
tr.muted-row td { opacity: .6; }

.pvc { position: relative; }
.pvedit { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 2px; font-size: 13px; vertical-align: top; }
.pvedit:hover { color: var(--accent); }

.applyfor { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 8px 0; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.applyfor b { margin-right: 4px; }

/* Việc Tự Tâm: day tabs with a Done tick; finished days go grey into the Done folder */
.daytab { display: inline-flex; align-items: center; gap: 4px; }
.daytab.isdone a { background: #e5e5e5; color: #888; border-color: #ddd; text-decoration: line-through; }
.daytab.isdone a.active { background: #bbb; color: #fff; }
.donefolder { margin: 6px 0; } .donefolder summary { cursor: pointer; color: #888; }
/* 13/10 (Tuan): the picture viewer shows the whole image (a 1024 px AI photo overflowed the stage and was cut off) */
.viewer-stage.image img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; display: block; }

/* Đơn hàng: order number box, Risk column, order detail (13/10) */
.order-box { display: inline-block; font: inherit; font-weight: 600; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); cursor: pointer; white-space: nowrap; box-shadow: 0 1px 0 rgba(0,0,0,.04); }
.order-box:hover { border-color: var(--accent); }
.risk-cell { text-align: center; }
.risk-ic { display: inline-flex; cursor: help; }
.risk-ic.med { color: #f1c21b; }
.risk-ic.high { color: #e5484d; }
.od-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 24px; min-width: min(860px, 86vw); }
.od-grid h3 { margin: 0 0 8px; font-size: 15px; }
.od-row { display: grid; grid-template-columns: 120px 1fr; gap: 8px; align-items: center; margin-bottom: 6px; font-size: 13px; }
.od-row span { color: var(--muted); }
.od-row input { width: 100%; }
.risk-bar { position: relative; height: 6px; border-radius: 3px; margin: 12px 0 4px; background: linear-gradient(90deg, #2e9b5f 0 33%, #f1c21b 33% 66%, #e5484d 66%); }
.risk-bar span { position: absolute; top: -4px; width: 4px; height: 14px; background: #1a1a1a; border-radius: 2px; transform: translateX(-50%); }
.risk-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.risk-facts { margin: 10px 0; padding-left: 18px; font-size: 13px; display: grid; gap: 4px; }
.risk-facts li.neg { color: #c4302b; }
.risk-facts li.pos { color: #2e7d4f; }
@media (max-width: 760px) { .od-grid { grid-template-columns: 1fr; min-width: 0; } }
#modal:has(.od-grid) { width: min(1000px, 96vw); max-width: 96vw; }
#modal .od-grid { min-width: 0; }

/* 16/10: STL check picture under each finished line */
tr.stl-rev-row td { border-top: 0; padding-top: 0; }
img.stl-rev { display: block; width: 100%; max-width: 1100px; height: auto; border-radius: 6px; background: #fff; border: 1px solid var(--line, #ddd); }

/* 16/10: casting spec tags on each line */
.spec-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.spec-chips .chip { font-weight: 600; }
.sc-line.l13 { background: #e6f0ff; color: #1d4ed8; }
.sc-line.l30 { background: #ede4ff; color: #6d28d9; }
.sc-line.l16 { background: #ffe9f1; color: #be185d; }
.sc-line.lkc { background: #e7f7f7; color: #0f766e; }
.sc-form.relief { background: #fff4dc; color: #a16207; }
.sc-form.fig { background: #e6f0ff; color: #1d4fa3; }   /* 23/10: blue = Tượng 3D, amber = Phù Điêu Relief (same as Studio) */
.sc-size { background: #e8f8ee; color: #15803d; }
.sc-g { background: #fdeee4; color: #c2410c; }
.sc-fl { background: #eef2ff; color: #3730a3; text-decoration: none; }   /* 30/10: when the customer made the First Look */
.sc-fl.bad { background: #fde8e8; color: #b91c1c; }

body.hide-stl-rev tr.stl-rev-row { display: none; }
/* 30/10: Thư viện — several check pictures (one per file kind) side by side */
.stl-rev-list { display: flex; flex-wrap: wrap; gap: 10px; }
.stl-rev-list figure { margin: 0; flex: 1 1 480px; max-width: 1100px; }
.stl-rev-list figcaption { margin: 2px 0 4px; }

.btn.xf.filtered { background: var(--accent-soft, #e6f0ff); border-color: var(--accent, #2563eb); color: var(--accent, #2563eb); }
.btn.xf svg { vertical-align: -2px; }
/* 18/10: basecost column (Đơn hàng) */
.costc { font-size: 12px; line-height: 1.35; }
.costc b { font-variant-numeric: tabular-nums; }
.chip.cost-pl { background: #fff4e0; color: #8a5200; border-color: #f0d2a0; }
.chip.cost-ver { background: #eef2ff; color: #2f3f9e; border-color: #c5cdf5; }

/* 29/10: approvals recorded on the order page, sent with Publish */
.pendbox { position: fixed; right: 18px; bottom: 18px; z-index: 900; background: var(--card, #fff); border: 2px solid var(--ok, #2e7d32);
  border-radius: 10px; padding: 12px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.18); min-width: 220px; }

/* 30/10: product main image beside the Preview */
.pvc { white-space: nowrap; }
.pv-main { display: inline-block; margin-left: 4px; vertical-align: top; }
.pv-main img.thumb { outline: 1px dashed var(--line, #ccc); }

/* 30/10: Duyệt & xuất — compact cards: pictures | product + casting facts | customer input */
.rv-line { grid-template-columns: auto minmax(260px, 1.3fr) minmax(220px, 1fr); gap: 14px; padding: 10px 0 8px; }
.rv-figs { display: flex; gap: 8px; }
.rv-fig img, .rv-empty, .rv-stl { width: 104px; height: 104px; }
.rv-stl { font-size: 19px; }
.rv-title { font-weight: 700; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rv-meta { font-size: 12px; color: var(--muted); }
.rv-meta b { color: var(--text, inherit); }
.rv-facts { display: flex; flex-wrap: wrap; gap: 4px; }
.rv-facts a.chip { text-decoration: none; }
.rv-cust { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; min-width: 0; align-self: start; }
.rv-cust-h { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 3px; }
.rv-cust dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; margin: 0; }
.rv-cust dt { color: var(--muted); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv-cust dd { margin: 0; font-weight: 600; word-break: break-word; }
.rv-cust .rv-engrave b { font-size: 14px; }
.rv-cphotos { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.rv-cphotos img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
@media (max-width: 1100px) {
  .rv-line { grid-template-columns: auto 1fr; }
  .rv-cust { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  .rv-line { grid-template-columns: 1fr; }
  .rv-figs { display: grid; grid-template-columns: repeat(3, 1fr); }
  .rv-fig img, .rv-empty, .rv-stl { width: 100%; height: auto; aspect-ratio: 1; }
}

/* 30/10: API credits in the header */
.credits { display: inline-flex; gap: 4px; cursor: pointer; }
.credits .chip { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* 3/11 Cần sửa (Duyệt đơn) */
.rv-fixdlg{position:fixed;inset:0;background:rgba(0,0,0,.35);display:flex;align-items:flex-start;justify-content:center;z-index:1000;padding:8vh 16px}
.rv-fixdlg .modal{width:min(560px,100%);max-height:80vh;overflow:auto}
.rv-fixpick{display:flex;flex-direction:column;gap:6px}
.rv-fixitem{display:flex;gap:10px;align-items:center;text-align:left;padding:8px;border:1px solid var(--line,#ddd);border-radius:8px;background:var(--card,#fff);cursor:pointer;font:inherit}
.rv-fixitem:hover{border-color:var(--accent,#b5532a)}
.rv-fixitem img{width:56px;height:56px;object-fit:contain;flex:none}
.rv-fixline{outline:2px solid var(--bad,#c0392b);outline-offset:2px;border-radius:6px}
.rv-fixnote{grid-column:1/-1;color:var(--bad,#c0392b);margin-bottom:4px}
.rv-order.st-fix{border-left-color:var(--bad,#c0392b)}
/* 5/11 Đã sửa + chọn nhiều dòng */
.rv-order.st-fixed{border-left-color:var(--ok,#2e7d4f)}
.rv-fixline.done{outline-color:var(--ok,#2e7d4f)}
.rv-fixline.done .rv-fixnote{color:var(--ok,#2e7d4f)}
.rv-fixitem{flex-direction:column;align-items:stretch;cursor:default}
.rv-fixitem.on{border-color:var(--bad,#c0392b)}
.rv-fixhead{display:flex;gap:10px;align-items:center;cursor:pointer}
.rv-fixhead input{flex:none;width:18px;height:18px}
.rv-fixitem textarea{width:100%;margin-top:6px;font:inherit}

/* 6/11: Check list QA on approved orders */
.rv-qa { border-left: 3px solid var(--line, #ddd); padding: 4px 8px; margin: 4px 0 6px; display: grid; gap: 4px; }
/* 9/11 (anh Tuân): Duyệt & xuất — "Mở ảnh kiểm tra STL": 3 views (Trước / Sau / Nghiêng) left of each line, the page moves right */
/* 10/11: views grow with the screen (110 → 180 px), the list moves right to make room */
main:has(.rv-list.shots) { --shot: clamp(110px, 9.5vw, 180px); max-width: none; padding-left: calc(3 * var(--shot) + 12px + 56px); padding-right: 24px; }
/* 10/11: the views sit level with the line's own pictures (top of .rv-figs); the picture row is as tall as the views */
.rv-list.shots .rv-figs { position: relative; }
.rv-list.shots .rv-figs:has(.rv-shots) { min-height: calc(var(--shot) + 20px); }
.rv-shots { position: absolute; right: calc(100% + 33px); top: 0; display: flex; gap: 6px; }
.rv-shots figure { margin: 0; text-align: center; cursor: zoom-in; }
.rv-shot { width: var(--shot, 110px); height: var(--shot, 110px); border: 1px solid var(--line); border-radius: 8px; background: #fff; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.rv-shot img { width: 100%; height: 100%; object-fit: contain; display: block; }
.rv-shots figcaption { font-size: 11px; color: var(--muted); margin-top: 3px; }
.rv-shot-err { width: calc(3 * var(--shot, 110px) + 12px); padding: 8px; border: 1px dashed var(--line); border-radius: 8px; background: var(--bg); }
#rv-shots.on { outline: 2px solid var(--accent); outline-offset: -1px; font-weight: 600; }
@media (max-width: 1100px) {
  main:has(.rv-list.shots) { padding-left: 20px; }
  .rv-list.shots .rv-figs:has(.rv-shots) { min-height: 0; }
  .rv-shots { position: static; grid-column: 1 / -1; }
}

/* 18/11 per-line Cần sửa buttons */
.rv-linebtns{float:right;display:inline-flex;gap:6px;margin-left:8px}

/* 18/11 💬 chat per Cần sửa line */
.rv-chat{grid-column:1/-1;border:1px solid var(--line,#ddd);border-radius:10px;background:var(--card,#fff);color:var(--text,#222);margin:6px 0 8px;padding:8px}
.rv-chat-log{max-height:420px;overflow:auto;display:flex;flex-direction:column;gap:8px;padding:4px}
.rv-chat-msg{max-width:78%;padding:6px 10px;border-radius:10px;background:#f4f1ec}
.rv-chat-msg.me{align-self:flex-end;background:#e7f0ff}
.rv-chat-text{white-space:normal;line-height:1.4}
.rv-chat-files{display:flex;gap:6px;flex-wrap:wrap;margin-top:6px}
.rv-chat-files img{height:110px;border-radius:6px;border:1px solid #ddd}
.rv-chat-files .rv-stl{width:90px;height:110px}
.rv-chat-in{margin-top:6px}
.rv-chat-in textarea{width:100%;box-sizing:border-box}

.rv-steps{list-style:none;margin:6px 0;padding:0;display:grid;gap:2px}
.rv-steps li{color:#999}.rv-steps li.ok{color:var(--ok,#2e7d4f)}.rv-steps li.now{color:inherit;font-weight:600}
.rv-steps .spin{display:inline-block;animation:rvspin 1.2s linear infinite}
@keyframes rvspin{to{transform:rotate(360deg)}}

/* 19/11 4 ảnh Cần sửa / Đã sửa */
.rv-img4{grid-column:1/-1;margin:6px 0;padding:6px;border-radius:8px;border:1px solid var(--line,#ddd)}
.rv-img4 summary{cursor:pointer}
.rv-img4.bad{border:2px solid #c0392b;background:#fdecea}
.rv-img4-bad{color:#c0392b;font-weight:700}
.rv-img4-row{display:flex;gap:8px;flex-wrap:wrap;margin-top:6px}
.rv-img4-row .rv-fig{width:150px}.rv-img4-row img{width:150px;height:150px;object-fit:contain;background:#fff;border-radius:6px;border:1px solid #eee}

/* 19/11 người phụ trách */
.own-chip{border:1px solid var(--own);color:var(--own)}
.own-chip.on{background:var(--own);color:#fff}
