:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #6a7686;
  --line: #dde3ea;
  --brand: #1f4e79;
  --brand-2: #2d6aa3;
  --accent: #b8292f;
  --ok: #2e7d4f;
  --warn: #b26a00;
  --chip: #f2f5f8;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 16px rgba(20, 30, 50, .05);
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  display: flex; flex-direction: column;
}
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.spacer { flex: 1; }

/* ---- thanh trên ---- */
.topbar {
  display: flex; align-items: center; gap: 18px; padding: 10px 18px;
  background: var(--brand); color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.logo {
  width: 36px; height: 36px; border-radius: 8px; background: #fff; color: var(--brand);
  display: grid; place-items: center; font-weight: 800; font-family: "Times New Roman", serif; font-size: 22px;
}
.title { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.sub { font-size: 12px; opacity: .8; }
.preset { display: flex; align-items: center; gap: 6px; }
.preset label { font-size: 12px; opacity: .85; }
.preset select {
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.3); color: #fff;
  border-radius: 7px; padding: 6px 8px; min-width: 210px;
}
.preset select option { color: var(--ink); }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.35); }
.topbar .btn.ghost:hover { background: rgba(255,255,255,.12); }
.menu { position: relative; }
.menu-list {
  display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  background: #fff; color: var(--ink); border-radius: 8px; box-shadow: var(--shadow);
  border: 1px solid var(--line); min-width: 230px; padding: 4px;
}
.menu-list.open { display: block; }
.menu-list button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.menu-list button:hover { background: var(--chip); }
.menu-list .danger { color: var(--accent); }

.banner { padding: 7px 18px; background: #fff5d6; color: #6b4b00; font-size: 13px; }
.banner.err { background: #fde8e8; color: #8a1c1c; }

/* ---- nút ---- */
.btn {
  border: 1px solid var(--line); background: #fff; padding: 7px 13px; border-radius: 7px;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #b9c3cf; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.icon { padding: 7px 10px; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
.link { border: 0; background: none; color: var(--brand-2); cursor: pointer; padding: 2px 4px; font-size: 13px; }
.link:hover { text-decoration: underline; }

/* ---- bố cục ---- */
.layout {
  flex: 1; min-height: 0; display: grid; gap: 12px; padding: 12px;
  grid-template-columns: minmax(280px, 340px) minmax(380px, 1fr) minmax(300px, 360px);
}
.panel {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 700; }
.count {
  display: inline-block; min-width: 22px; padding: 0 6px; margin-left: 4px; border-radius: 10px;
  background: var(--chip); color: var(--muted); font-size: 12px; text-align: center;
}

/* ---- file ---- */
.drop {
  margin: 12px 14px 6px; border: 1.5px dashed #b9c6d4; border-radius: 9px; padding: 14px;
  text-align: center; color: var(--ink); background: #f8fafc; cursor: pointer; transition: .15s;
}
.drop.over { border-color: var(--brand-2); background: #eaf2fb; }
.drop-icon { font-size: 22px; color: var(--brand-2); line-height: 1; margin-bottom: 4px; }
.list-tools { display: flex; align-items: center; padding: 6px 14px; border-bottom: 1px solid var(--line); }
.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.file-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.file-list li {
  display: grid; grid-template-columns: auto 1fr auto; gap: 4px 8px; align-items: center;
  padding: 9px 14px; border-bottom: 1px solid #f0f2f5; cursor: pointer;
}
.file-list li:hover { background: #f8fafc; }
.file-list li.active { background: #eaf2fb; box-shadow: inset 3px 0 0 var(--brand-2); }
.fname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fmeta { grid-column: 2 / 4; display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.fact { display: flex; gap: 2px; opacity: .55; }
.file-list li:hover .fact { opacity: 1; }
.fact button { border: 0; background: none; cursor: pointer; padding: 2px 5px; border-radius: 5px; font-size: 13px; }
.fact button:hover { background: var(--chip); }
.chip {
  display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 600;
  background: var(--chip); color: var(--muted);
}
.chip.xong { background: #e3f3e9; color: var(--ok); }
.chip.loi { background: #fde8e8; color: var(--accent); }
.chip.dang_xu_ly, .chip.dang_in { background: #e6f0fb; color: var(--brand-2); }
.chip.hang_doi { background: #fff4dc; color: var(--warn); }
.chip.da_in { background: #ece8fb; color: #5a3fb0; }
.ferr { grid-column: 2 / 4; font-size: 12px; color: var(--accent); }
.empty-list { padding: 24px 14px; text-align: center; color: var(--muted); font-size: 13px; }
.out-dir { padding: 10px 14px; border-top: 1px solid var(--line); }
.out-dir code {
  flex: 1; font-size: 12px; background: var(--chip); padding: 3px 6px; border-radius: 5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---- xem trước ---- */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 5px 12px; cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--brand-2); color: #fff; }
.pv-body { flex: 1; min-height: 0; position: relative; background: #525659; }
.pv-body iframe { width: 100%; height: 100%; border: 0; display: block; }
.pv-empty {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  background: #f4f6f9; color: var(--ink); padding: 20px;
}
.pv-paper {
  width: 110px; height: 150px; margin: 0 auto 14px; background: #fff; border-radius: 3px;
  box-shadow: var(--shadow); padding: 22px 14px 0 20px; display: flex; flex-direction: column; gap: 9px;
}
.pv-paper span { height: 4px; background: #dfe5ec; border-radius: 2px; }
.pv-paper span.short { width: 55%; }
.report { border-top: 1px solid var(--line); padding: 8px 14px; max-height: 34%; overflow: auto; }
.report summary { cursor: pointer; font-weight: 600; padding: 2px 0; }
.report ul { margin: 6px 0; padding-left: 18px; }
.report li { margin: 2px 0; }
.report .warn li { color: var(--warn); }

/* ---- tùy chọn ---- */
.settings-form { overflow: auto; flex: 1; padding: 4px 0 12px; }
.grp { border-bottom: 1px solid #f0f2f5; }
.grp > summary {
  list-style: none; cursor: pointer; padding: 10px 14px; font-weight: 600; display: flex; align-items: center; gap: 8px;
}
.grp > summary::-webkit-details-marker { display: none; }
.grp > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
.grp[open] > summary::before { transform: rotate(90deg); }
.grp .fields { padding: 0 14px 10px; display: grid; gap: 8px; }
.f { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; }
.f label { font-size: 13px; }
.f .hint { grid-column: 1 / -1; font-size: 11.5px; color: var(--muted); margin-top: -4px; }
.f input[type=number], .f input[type=text], .f select {
  width: 92px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff;
}
.f input[type=text] { width: 150px; }
.f select { width: 150px; }
.f input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand-2); }

/* ---- thanh hành động ---- */
.actionbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 18px;
  background: #fff; border-top: 1px solid var(--line);
}
.progress-wrap { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.progress { width: 220px; height: 6px; background: var(--chip); border-radius: 4px; overflow: hidden; flex: none; }
.progress .bar { height: 100%; width: 0; background: var(--brand-2); transition: width .3s; }
#progText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- hộp thoại ---- */
dialog { border: 0; border-radius: 12px; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 23, 35, .45); }
.dlg { padding: 20px 22px; width: 400px; max-width: 92vw; display: grid; gap: 12px; }
.dlg h3 { margin: 0; }
.dlg p { margin: -6px 0 0; }
.dlg label { display: grid; gap: 4px; font-size: 13px; }
.dlg label.chk { display: inline-flex; }
.dlg input[type=number], .dlg input[type=text], .dlg select {
  padding: 7px 8px; border: 1px solid var(--line); border-radius: 7px; width: 100%;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.toast {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 9px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 50; max-width: 80vw;
}
.toast.err { background: var(--accent); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr 1fr; }
  .preview { grid-column: 1 / -1; grid-row: 1; min-height: 60vh; }
  .sub { display: none; }
}
@media (max-width: 700px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .preset select { min-width: 140px; }
}

.actionbar .digital {
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; font-weight: 600; font-size: 13px;
}
.actionbar .digital:has(input:checked) { background: #fff4dc; border-color: #f0c36a; color: #7a4b00; }

.workers { margin-top: 8px; }
.workers select { padding: 3px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 13px; }

.banner .btn-inline {
  display: inline-block; margin: 0 4px; padding: 2px 10px; border-radius: 6px;
  background: #8a1c1c; color: #fff; text-decoration: none; font-weight: 600;
}
