:root {
  --blue: #0b4fa3; --blue-600: #0a4590; --blue-50: #eef4fc; --blue-100: #dce8f8;
  --ink: #1b2433; --muted: #5b6577; --line: #e3e8ef; --bg: #f4f7fb; --white: #fff;
  --green: #15803d; --green-50: #ecfdf3; --red: #b42318; --red-50: #fef3f2; --amber: #b45309; --amber-50: #fffaeb;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  font-family: "Be Vietnam Pro", "Segoe UI", Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--blue); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); } .small { font-size: .86rem; } .tiny { font-size: .76rem; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; word-break: break-all; }
.hidden { display: none !important; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; } .row.end { justify-content: flex-end; } .row.top { align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 12px; } .g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 760px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }

/* Thanh trên */
.topbar { background: var(--white); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
.topbar .inner { max-width: 1240px; margin: 0 auto; padding: 10px 18px; display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; }
.brand .logo { width: 36px; height: 36px; border-radius: 10px; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 13px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: .74rem; }
.topbar nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; color: var(--ink); padding: 7px 12px; border-radius: 8px; font-size: .92rem; }
.topbar nav a:hover, .topbar nav a.active { background: var(--blue-50); color: var(--blue); }

.container { max-width: 1240px; margin: 0 auto; padding: 22px 18px 60px; }
.narrow { max-width: 760px; }
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card h2 { margin-bottom: 12px; }
.section-title { font-weight: 700; font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 8px; }

/* Nút */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--white); color: var(--ink); padding: 9px 16px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #c9d3e0; background: #fafcff; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-600); }
.btn.danger { color: var(--red); border-color: #f2c9c5; } .btn.danger:hover { background: var(--red-50); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--blue); }
.btn.sm { padding: 5px 10px; font-size: .86rem; } .btn.lg { padding: 12px 22px; font-size: 1.02rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--blue); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* Biểu mẫu */
label.f { display: block; font-size: .86rem; font-weight: 600; margin-bottom: 4px; }
label.f .req { color: var(--red); }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; border: 1px solid #cfd8e3; border-radius: 9px; padding: 9px 11px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-100); border-color: var(--blue); }
textarea { min-height: 84px; resize: vertical; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; cursor: pointer; }
.check input { margin-top: 4px; width: 17px; height: 17px; flex: none; accent-color: var(--blue); }
.otp-input { font-size: 1.6rem; letter-spacing: .5em; text-align: center; max-width: 240px; font-weight: 700; }

/* Nhãn trạng thái */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 700; background: #eef1f5; color: #475467; white-space: nowrap; }
.badge.blue { background: var(--blue-50); color: var(--blue); } .badge.green { background: var(--green-50); color: var(--green); }
.badge.red { background: var(--red-50); color: var(--red); } .badge.amber { background: var(--amber-50); color: var(--amber); }

.alert { border-radius: 10px; padding: 12px 14px; margin: 10px 0; background: var(--blue-50); color: #0b3c7a; border: 1px solid var(--blue-100); white-space: pre-line; }
.alert.err { background: var(--red-50); color: var(--red); border-color: #f6d0cc; }
.alert.ok { background: var(--green-50); color: var(--green); border-color: #c4ecd3; }
.alert.warn { background: var(--amber-50); color: var(--amber); border-color: #f8e3b5; }

table.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th, .tbl td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: #f8fbff; }
.table-wrap { overflow-x: auto; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--blue); border-bottom-color: var(--blue); }

/* Bước (stepper) */
.stepper { display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 14px 0; }
.stepper .st { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; font-size: .92rem; }
.stepper .st .n { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #cfd8e3; display: grid; place-items: center; background: #fff; }
.stepper .st.active { color: var(--ink); } .stepper .st.active .n { background: var(--blue); border-color: var(--blue); color: #fff; }
.stepper .st.done .n { background: var(--blue); border-color: var(--blue); color: #fff; }
.stepper .bar { width: 36px; height: 2px; background: #dbe2ea; }
@media (max-width: 640px) { .stepper .st .lbl { display: none; } .stepper .st.active .lbl { display: inline; } }

/* Toast + modal */
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
#toast .t { background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 90vw; white-space: pre-line; }
#toast .t.err { background: var(--red); } #toast .t.ok { background: var(--green); }
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 90; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: min(640px, 100%); max-height: 92vh; overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(980px, 100%); }

/* Người nhận */
.rcp { display: flex; gap: 12px; align-items: stretch; margin-bottom: 12px; }
.rcp .ord { width: 46px; flex: none; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.rcp .ord input { width: 46px; text-align: center; font-weight: 700; padding: 8px 4px; }
.rcp .box { flex: 1; background: #f6f8fb; border-radius: 12px; padding: 12px; border-left: 5px solid var(--c, var(--blue)); }
.rcp .adv { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #d4dbe5; }

/* Trình soạn vị trí ký */
.designer { display: grid; grid-template-columns: 280px 1fr; gap: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; min-height: 70vh; }
.designer .side { border-right: 1px solid var(--line); padding: 12px; overflow: auto; max-height: 80vh; }
.designer .stage { background: #dfe4ea; overflow: auto; max-height: 80vh; padding: 16px; position: relative; }
@media (max-width: 860px) { .designer { grid-template-columns: 1fr; } .designer .side { max-height: none; border-right: 0; border-bottom: 1px solid var(--line); } }
.tool { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 1px solid transparent; border-radius: 10px; background: none; font: inherit; cursor: pointer; text-align: left; }
.tool .ic { width: 34px; height: 34px; border-radius: 9px; background: var(--blue-100); display: grid; place-items: center; font-size: 17px; flex: none; }
.tool:hover { background: var(--blue-50); } .tool.active { border-color: var(--blue); background: var(--blue-50); }
.page-wrap { position: relative; margin: 0 auto 16px; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.page-wrap canvas { display: block; width: 100%; height: 100%; }
.page-wrap .layer { position: absolute; inset: 0; }
.page-wrap .pno { position: absolute; top: -2px; right: -40px; font-size: .75rem; color: #555; }
.page-wrap.placing { cursor: crosshair; }
.fld { position: absolute; border: 1.5px dashed var(--c, var(--blue)); background: color-mix(in srgb, var(--c, #0b4fa3) 14%, transparent); border-radius: 4px; font-size: 10px; color: #111; display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1.1; overflow: hidden; user-select: none; }
.fld.edit { cursor: move; }
.fld .x { position: absolute; top: 0; right: 0; width: 16px; height: 16px; border: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; line-height: 16px; padding: 0; cursor: pointer; border-radius: 0 3px 0 4px; }
.fld .rs { position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; background: var(--c, var(--blue)); cursor: nwse-resize; }
.fld.mine { border-style: solid; background: rgba(255, 213, 79, .35); border-color: #e0a100; animation: pulse 1.6s ease-in-out infinite; }
.fld.mine.filled { animation: none; background: rgba(21, 128, 61, .12); border-color: var(--green); }
.fld input[type=text] { width: 100%; height: 100%; border: 0; background: rgba(255,255,255,.85); padding: 0 3px; font-size: 11px; border-radius: 0; }
.fld input[type=checkbox] { width: 80%; height: 80%; margin: 0; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(224, 161, 0, .25); } }
.legend { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--c); vertical-align: middle; }

/* Ký */
.sigpad { border: 2px dashed #b9c6d6; border-radius: 12px; background: #fff; touch-action: none; width: 100%; height: 220px; display: block; cursor: crosshair; }
.sig-preview { background: repeating-conic-gradient(#f3f5f8 0 25%, #fff 0 50%) 0 0/16px 16px; border: 1px solid var(--line); border-radius: 10px; min-height: 90px; display: grid; place-items: center; padding: 8px; }
.sig-preview img { max-width: 100%; max-height: 140px; }
.font-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.font-pick button { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 12px; font-size: 26px; cursor: pointer; color: #0a2a7a; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.font-pick button.active { border-color: var(--blue); outline: 2px solid var(--blue-100); }
.cam { background: #111; border-radius: 12px; overflow: hidden; position: relative; aspect-ratio: 4/3; max-width: 520px; }
.cam video, .cam img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam .guide { position: absolute; inset: 12% 22%; border: 3px dashed rgba(255,255,255,.7); border-radius: 50%; pointer-events: none; }
.cam .guide.card { inset: 18% 8%; border-radius: 14px; }
.thumbs { display: flex; gap: 10px; flex-wrap: wrap; }
.thumbs .th { width: 150px; } .thumbs .th img { width: 100%; border-radius: 8px; border: 1px solid var(--line); }
.legal-box { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; background: #fbfcfe; }
.legal-box h4 { margin: 12px 0 4px; color: var(--blue); } .legal-box p { margin: 0 0 6px; }
.doc-tile { display: flex; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fff; }
.doc-tile .ic { width: 40px; height: 40px; border-radius: 10px; background: var(--blue-50); color: var(--blue); display: grid; place-items: center; font-weight: 800; flex: none; }
.list-gap > * + * { margin-top: 10px; }
.hero { background: linear-gradient(135deg, #0b4fa3, #1f6fd1); color: #fff; border-radius: 18px; padding: 34px 30px; }
.hero h1 { font-size: 1.9rem; } .hero p { opacity: .92; max-width: 640px; }
.hero .btn { border-color: rgba(255,255,255,.4); }
.feature { display: flex; gap: 12px; } .feature .ic { font-size: 22px; }
.dropzone { border: 2px dashed #b9c6d6; border-radius: 14px; padding: 28px; text-align: center; background: #fafcff; cursor: pointer; }
.dropzone.over { border-color: var(--blue); background: var(--blue-50); }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 12px; font-size: .92rem; } .kv > div:nth-child(odd) { color: var(--muted); }
@media (max-width: 560px) { .kv { grid-template-columns: 1fr; } }
.timeline { border-left: 2px solid var(--line); margin-left: 6px; padding-left: 16px; }
.timeline .ev { position: relative; padding: 6px 0; font-size: .9rem; }
.timeline .ev::before { content: ""; position: absolute; left: -22px; top: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--blue); }
.spinner { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.5); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
.spinner.dark { border-color: #cdd6e2; border-top-color: var(--blue); }
@keyframes spin { to { transform: rotate(360deg); } }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 26px 16px; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(255,255,255,.96); border-top: 1px solid var(--line); padding: 12px 0; margin-top: 18px; z-index: 5; }
