/* Demo Logo Khăn Giấy 12x12 — Thế Giới Giấy */
:root {
  --brand: #123A6B;
  --brand-2: #1769E0;
  --cyan: #1BA3DC;
  --ink: #14213D;
  --muted: #5B6B82;
  --line: #E1E7EF;
  --bg: #EEF2F7;
  --panel: #FFFFFF;
  --soft: #F4F7FB;
  --accent-bg: #E8F1FD;
  --danger: #C8323C;
  --warn: #B45309;
  --ok: #138A4B;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 38, 74, .06), 0 4px 14px rgba(16, 38, 74, .05);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  font-size: 14px; color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Thanh trên ---------- */
.topbar {
  height: 62px; display: flex; align-items: center; gap: 18px; padding: 0 18px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: relative; z-index: 2;
}
.brand { height: 40px; width: auto; }
.titles h1 { margin: 0; font-size: 17px; font-weight: 700; color: var(--brand); letter-spacing: -.01em; }
.titles p { margin: 1px 0 0; font-size: 12px; color: var(--muted); }
.steps { display: flex; gap: 6px; list-style: none; margin: 0 auto; padding: 0; }
.steps li { display: flex; align-items: center; gap: 7px; padding: 6px 12px 6px 7px; border-radius: 999px; background: var(--soft); color: var(--muted); font-size: 13px; font-weight: 500; }
.steps li b { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: #D6DFEB; color: #fff; font-size: 12px; }
.steps li.done b { background: var(--ok); }
.steps li.active { background: var(--accent-bg); color: var(--brand-2); }
.steps li.active b { background: var(--brand-2); }
.steps li { cursor: pointer; transition: background .15s, box-shadow .15s; }
.steps li:hover { box-shadow: 0 0 0 1.5px #9DBBE8 inset; }
.card.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--brand-2); } 100% { box-shadow: var(--shadow); } }
.top-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn { width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line); background: #fff; display: grid; place-items: center; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:disabled { opacity: .4; cursor: default; }
.ghost-btn { height: 36px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line); background: #fff; font-size: 13px; font-weight: 500; }
.icon-btn:hover:not(:disabled), .ghost-btn:hover { border-color: #b9c7da; background: var(--soft); }

/* ---------- Bố cục 3 cột ---------- */
.layout { display: grid; grid-template-columns: 330px minmax(0, 1fr) 360px; height: calc(100vh - 62px); height: calc(100dvh - 62px); }
.panel { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; scrollbar-width: thin; }
#panelLeft { border-right: 1px solid var(--line); }
#panelRight { border-left: 1px solid var(--line); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-size: 15px; font-weight: 700; color: var(--brand); }
.card h3 { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.card h3.mt { margin-top: 16px; }
.num { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-2); color: #fff; font-size: 13px; flex: none; }
.hint { margin: 10px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.badge { background: var(--accent-bg); color: var(--brand-2); border-radius: 999px; padding: 1px 8px; font-size: 12px; }

/* ---------- Tải logo ---------- */
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  border: 2px dashed #B9C9DE; border-radius: 12px; padding: 18px 12px; background: var(--soft); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--brand-2); background: var(--accent-bg); }
.drop strong { font-size: 14px; color: var(--brand); }
.drop small { color: var(--muted); font-size: 12px; }
.drop-ic { width: 30px; height: 30px; color: var(--brand-2); margin-bottom: 2px; }
.link-btn { background: none; border: 0; padding: 6px 0; color: var(--brand-2); font-weight: 500; font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.compare figure { margin: 0; }
.chk { border-radius: 8px; border: 1px solid var(--line); height: 96px; display: grid; place-items: center; overflow: hidden;
  background: repeating-conic-gradient(#EEF1F5 0 25%, #fff 0 50%) 0 0 / 14px 14px; }
.chk canvas { max-width: 100%; max-height: 100%; display: block; }
.compare figcaption { font-size: 11px; color: var(--muted); text-align: center; margin-top: 4px; }

/* ---------- Điều khiển ---------- */
.switch, .check { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 13px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--brand-2); margin: 0; flex: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .sl { width: 34px; height: 20px; border-radius: 999px; background: #C9D3E0; position: relative; transition: background .15s; flex: none; }
.switch .sl::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .sl { background: var(--brand-2); }
.switch input:checked + .sl::after { transform: translateX(14px); }
.switch input:focus-visible + .sl { outline: 2px solid var(--brand-2); outline-offset: 2px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--soft); border: 1px solid var(--line); color: var(--muted); }
.chip i { width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(0,0,0,.2); display: inline-block; }
.range { display: grid; grid-template-columns: 1fr 100px 30px; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.range input { width: 100%; accent-color: var(--brand-2); }
.range output { font-weight: 600; color: var(--ink); text-align: right; }

.seg { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.seg button.on { background: #fff; color: var(--brand-2); box-shadow: 0 1px 3px rgba(16,38,74,.12); font-weight: 600; }
.seg.small button { padding: 5px 10px; font-size: 12px; }
#segMode { width: 100%; }
#segMode button { flex: 1; }

/* Thẻ màu mực */
.ink-cards { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.ink-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--soft); }
.ink-head { display: flex; align-items: center; gap: 10px; }
.ink-sw { width: 40px; height: 40px; border-radius: 10px; border: 1px solid rgba(0,0,0,.12); position: relative; overflow: hidden; flex: none; }
.ink-sw input { position: absolute; inset: -8px; width: 60px; height: 60px; opacity: 0; cursor: pointer; }
.ink-meta { flex: 1; min-width: 0; }
.ink-meta b { font-size: 13px; }
.ink-meta small { display: block; color: var(--muted); font-size: 11px; }
.hex-in { width: 92px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-family: ui-monospace, Consolas, monospace; text-transform: uppercase; background: #fff; }
.palette { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.palette button { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.15); padding: 0; }
.palette button.on { box-shadow: 0 0 0 2px var(--brand-2); }
.cluster-list { display: flex; flex-direction: column; gap: 6px; }
.cl-row { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 9px; }
.cl-sw { width: 26px; height: 26px; border-radius: 7px; border: 1px solid rgba(0,0,0,.12); padding: 0; }
.cl-info { font-size: 12px; line-height: 1.25; min-width: 0; }
.cl-info b { font-family: ui-monospace, Consolas, monospace; font-weight: 600; }
.cl-info small { color: var(--muted); display: block; }
.cl-row .seg button { padding: 3px 8px; font-size: 11px; }

/* ---------- Khung giữa ---------- */
.stage-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; align-items: flex-start; gap: 12px; padding: 10px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.tb-main { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.cta { flex: none; display: inline-flex; align-items: center; gap: 8px; height: 44px; padding: 0 20px; border: 0; border-radius: 11px;
  background: linear-gradient(135deg, #1769E0, #1BA3DC); color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .02em;
  box-shadow: 0 4px 14px rgba(23,105,224,.35); transition: transform .12s, box-shadow .12s; }
.cta svg { width: 18px; height: 18px; stroke-width: 2.4; }
.cta:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(23,105,224,.45); }
.cta:active { transform: translateY(0); }

/* Popup tải về */
.dl-dialog { max-width: 860px; }
.dl-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.dl-head h2 { margin: 0; }
.dl-all { width: 100%; margin: 14px 0 4px; padding: 14px 16px; border: 0; border-radius: 12px; text-align: left; color: #fff;
  background: linear-gradient(135deg, #123A6B, #1769E0); display: flex; flex-direction: column; gap: 3px; }
.dl-all b { font-size: 16px; }
.dl-all small { font-size: 12px; opacity: .85; }
.dl-all:hover { filter: brightness(1.08); }
.dl-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 12px; }
.dl-grid section { display: flex; flex-direction: column; gap: 7px; }
.dl-grid h3 { margin: 4px 0 2px; font-size: 13px; display: flex; justify-content: space-between; align-items: baseline; }
.dl-grid h3 small { font-weight: 400; color: var(--muted); font-size: 11px; }
.dl-tile { text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; display: flex; flex-direction: column; gap: 2px; }
.dl-tile b { font-size: 13.5px; color: var(--ink); }
.dl-tile small { font-size: 11.5px; color: var(--muted); }
.dl-tile:hover { border-color: var(--brand-2); background: var(--accent-bg); }
.dl-grid .check { margin: 2px 0; font-size: 12px; }
@media (max-width: 720px) { .dl-grid { grid-template-columns: 1fr; } }
.sel { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.sel select, .sel input { height: 32px; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; background: #fff; color: var(--ink); font-size: 13px; }
.sel.mini input { width: 56px; }
.toggles { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.tg { height: 32px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-size: 12px; font-weight: 500; color: var(--muted); }
.tg.on { background: var(--accent-bg); border-color: #BBD3F7; color: var(--brand-2); }
.stage { flex: 1; min-height: 0; position: relative; background:
  radial-gradient(circle at 50% 40%, #F7F9FC 0, #E7ECF3 100%); touch-action: none; }
.stage canvas { position: absolute; inset: 0; display: block; touch-action: none; }
.stage.over { outline: 3px dashed var(--brand-2); outline-offset: -10px; }
.statusbar { display: flex; gap: 16px; align-items: center; padding: 7px 14px; font-size: 12px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); min-height: 34px; flex-wrap: wrap; }
.statusbar .warn { color: var(--warn); font-weight: 500; margin-left: auto; }
#stCursor { font-variant-numeric: tabular-nums; min-width: 150px; }

/* ---------- Cột phải ---------- */
.preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preset { border: 1.5px solid var(--line); border-radius: 10px; background: #fff; padding: 6px 4px 7px; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; transition: border-color .12s, background .12s; position: relative; }
.preset:hover { border-color: #9DBBE8; background: var(--soft); }
.preset.on { border-color: var(--brand-2); background: var(--accent-bg); }
.preset svg { width: 100%; height: auto; aspect-ratio: 1; stroke-width: 1; }
.preset span { font-size: 11px; line-height: 1.25; font-weight: 500; }
.preset .as { position: absolute; top: 4px; right: 5px; font-size: 9px; font-weight: 700; color: var(--warn); }
.inst-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.inst-list button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 5px 10px; font-size: 12px; }
.inst-list button.on { background: var(--brand-2); color: #fff; border-color: var(--brand-2); }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.btn-row button, .quick button, .secondary { flex: 1 1 auto; height: 34px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--line); background: #fff; font-size: 12.5px; font-weight: 500; }
.btn-row button:hover, .quick button:hover, .secondary:hover { border-color: #9DBBE8; background: var(--soft); }
.btn-row button.danger { color: var(--danger); }
button:disabled { opacity: .45; cursor: not-allowed; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.num-in { display: grid; grid-template-columns: auto 1fr auto; align-items: center; border: 1px solid var(--line); border-radius: 9px; background: #fff; padding: 0 8px; height: 38px; gap: 6px; }
.num-in:focus-within { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(23,105,224,.12); }
.num-in span { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.num-in input { border: 0; outline: 0; width: 100%; min-width: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; background: transparent; }
.num-in em { font-style: normal; font-size: 12px; color: var(--muted); }
.rot-row { display: grid; grid-template-columns: 150px 1fr; gap: 10px; align-items: center; }
.rot-row input[type=range] { width: 100%; accent-color: var(--brand-2); }
.quick { display: flex; gap: 5px; margin-top: 8px; flex-wrap: wrap; }
.text-in { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.text-in input { height: 38px; border: 1px solid var(--line); border-radius: 9px; padding: 0 10px; font-size: 14px; color: var(--ink); }
.text-in input:focus { outline: 0; border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(23,105,224,.12); }
.export-block { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.export-block h4 { margin: 0 0 2px; font-size: 13px; display: flex; justify-content: space-between; align-items: baseline; }
.export-block h4 small { font-weight: 400; color: var(--muted); font-size: 11px; }
.export-block .seg { align-self: flex-start; }
.primary { height: 40px; border: 0; border-radius: 10px; background: var(--brand-2); color: #fff; font-weight: 600; font-size: 14px; padding: 0 14px; }
.primary:hover { background: #0F58C4; }
.check-box { margin-top: 12px; border-radius: 10px; padding: 10px 12px; font-size: 12px; line-height: 1.55; background: #EEF9F2; border: 1px solid #BFE5CF; color: #0F5132; }
.check-box.bad { background: #FDF0F0; border-color: #F2C4C4; color: #8A1C1C; }
.check-box b { display: block; margin-bottom: 4px; }
.foot { text-align: center; margin: 0 0 8px; }

/* ---------- Hộp thoại, toast, busy ---------- */
dialog { border: 0; border-radius: 16px; padding: 0; max-width: 640px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(10,25,50,.3); color: var(--ink); }
dialog::backdrop { background: rgba(10,25,50,.45); }
.dlg { padding: 22px 24px; max-height: 85vh; overflow: auto; }
.dlg h2 { margin: 0 0 10px; font-size: 18px; color: var(--brand); }
.dlg h3 { margin: 16px 0 6px; font-size: 14px; }
.dlg ol, .dlg ul { padding-left: 20px; margin: 0; line-height: 1.6; font-size: 13px; }
.dlg pre { white-space: pre-wrap; font-size: 12px; background: var(--soft); padding: 12px; border-radius: 10px; line-height: 1.5; }
.dlg-actions { display: flex; justify-content: flex-end; margin-top: 16px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: #14213D; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; opacity: 0; pointer-events: none; transition: all .2s; max-width: calc(100% - 32px); z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--danger); }
.busy { position: fixed; inset: 0; background: rgba(238,242,247,.7); display: flex; align-items: center; justify-content: center; gap: 12px; z-index: 40; font-weight: 600; color: var(--brand); backdrop-filter: blur(2px); }
.busy[hidden] { display: none; }
.spinner { width: 26px; height: 26px; border-radius: 50%; border: 3px solid #C8D7EE; border-top-color: var(--brand-2); animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; }

/* ---------- Máy tính bảng & điện thoại ---------- */
@media (max-width: 1280px) {
  .layout { grid-template-columns: 300px minmax(0, 1fr) 320px; }
  .steps { display: none; }
}
@media (max-width: 980px) {
  .layout { display: flex; flex-direction: column; height: auto; }
  .panel { overflow: visible; border: 0 !important; }
  .stage-col { order: 0; }
  #panelLeft { order: -1; }
  .stage { flex: none; height: min(100vw, 72vh); }
  .topbar { height: auto; padding: 10px 16px; flex-wrap: wrap; gap: 10px; }
  .titles p { display: none; }
  .top-actions { margin-left: auto; }
  .ghost-btn { display: none; }
  .preset-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 560px) {
  .brand { height: 32px; }
  .titles h1 { font-size: 15px; }
  .panel { padding: 10px 16px; }
  .toolbar { padding: 8px 16px; flex-direction: column; align-items: stretch; }
  .cta { justify-content: center; }
  .preset-grid { grid-template-columns: repeat(3, 1fr); }
  .rot-row { grid-template-columns: 1fr; }
  .statusbar { padding: 7px 16px; }
}
