:root {
  --bg: #f5f3ef;
  --card: #ffffff;
  --ink: #1d2228;
  --muted: #5b6470;
  --line: #e2ddd5;
  --brand: #b3202c;
  --brand-dark: #8e1822;
  --ok: #1f7a4d;
  --ok-bg: #e7f4ec;
  --warn-bg: #fff5dd;
  --err: #a1262c;
  --err-bg: #fbeaea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 20, .06), 0 4px 16px rgba(20, 20, 20, .04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--brand); }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, Consolas, monospace; word-break: break-all; }
.center { text-align: center; }

/* top bar */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); margin-bottom: 24px; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--brand);
  clip-path: polygon(50% 0, 61% 30%, 90% 22%, 76% 50%, 100% 62%, 66% 68%, 70% 100%, 50% 80%, 30% 100%, 34% 68%, 0 62%, 24% 50%, 10% 22%, 39% 30%); }
.brand-name { font-weight: 700; }
.brand-sub { font-size: .8rem; color: var(--muted); }
.nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.nav a { text-decoration: none; font-weight: 600; }
.footer { color: var(--muted); font-size: .8rem; padding: 32px 16px 40px; text-align: center; }

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.card.narrow { max-width: 420px; margin: 40px auto; }
.card.center { max-width: 620px; margin: 40px auto; padding: 40px 28px; }
.intro { max-width: 820px; margin: 0 auto 16px; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 700; color: var(--brand); margin: 0 0 4px; }

/* agreement text */
.agreement { max-width: 820px; margin-left: auto; margin-right: auto; font-size: .95rem; }
.agreement h2 { text-align: center; font-size: 1.3rem; margin-bottom: 1rem; }
.agreement h3 { font-size: 1rem; margin: 1.5rem 0 .5rem; padding-top: .75rem; border-top: 1px solid var(--line); }
.agreement table { width: 100%; border-collapse: collapse; margin: .5rem 0 1rem; font-size: .92rem; }
.agreement td { border: 1px solid var(--line); padding: 7px 10px; vertical-align: top; }
.agreement td:first-child { background: #faf8f5; width: 35%; }
.agreement ul { padding-left: 1.25rem; }
.agreement li { margin-bottom: .35rem; }

/* language */
.en-sub { display: block; font-size: .82em; font-weight: 400; color: var(--muted); margin-top: 2px; }
h2 .en-sub { font-size: .7em; }
.lang-tabs { max-width: 820px; margin: 0 auto 12px; display: flex; gap: 8px; }
.lang-tab { font: inherit; font-weight: 600; padding: 8px 18px; border-radius: 999px; border: 1px solid #cfc8bd; background: #fff; color: var(--ink); cursor: pointer; }
.lang-tab.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.agreement[hidden] { display: none; }
.sign-page[data-ui-lang="en"] [data-l="vi"], .sign-page[data-ui-lang="vi"] [data-l="en"] { display: none; }
.agreement + .agreement { margin-top: 20px; }

/* sign */
.sign-box { max-width: 820px; margin-left: auto; margin-right: auto; border-top: 4px solid var(--brand); }
.pad-wrap { position: relative; border: 2px dashed #c9c2b7; border-radius: 8px; background: #fffdf9; touch-action: none; }
#pad { display: block; width: 100%; height: 180px; cursor: crosshair; }
.pad-hint { position: absolute; left: 16px; bottom: 12px; color: #b3aca2; pointer-events: none; font-size: .9rem; }
.pad-wrap.has-ink .pad-hint { display: none; }
.client-error { color: var(--err); font-weight: 600; }
.fine { font-size: .8rem; color: var(--muted); margin-top: 12px; }
.tick { width: 64px; height: 64px; line-height: 64px; margin: 0 auto 12px; border-radius: 50%; background: var(--ok-bg); color: var(--ok); font-size: 2rem; font-weight: 700; }

/* forms */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=tel], input[type=date], input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%; font: inherit; padding: 10px 12px; border: 1px solid #cfc8bd; border-radius: 8px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(179, 32, 44, .35); border-color: var(--brand); }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--brand); flex: none; }
.req { color: var(--brand); }
fieldset { border: 0; padding: 0; margin: 0 0 12px; }
legend { font-weight: 700; font-size: 1.05rem; margin-bottom: 12px; padding-top: 4px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.span-2 { grid-column: span 2; }
.form-grid fieldset + fieldset { border-top: 1px solid var(--line); padding-top: 16px; }

/* buttons */
.btn { display: inline-block; font: inherit; font-weight: 600; padding: 10px 18px; border-radius: 8px; border: 1px solid #cfc8bd;
  background: #fff; color: var(--ink); text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--ink); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { color: var(--err); }
.btn-sm { padding: 6px 12px; font-size: .9rem; }
.btn-block { width: 100%; padding: 14px; font-size: 1.05rem; margin-top: 8px; }
.btn-link { background: none; border: 0; color: var(--brand); font: inherit; font-size: .9rem; cursor: pointer; padding: 6px 0; text-decoration: underline; }
.btn[disabled] { opacity: .6; cursor: wait; }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }
.actions.left { justify-content: flex-start; }
form.inline { display: inline; margin: 0; }

/* flash */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border: 1px solid transparent; }
.flash ul { margin: 0; padding-left: 1.2rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok); border-color: #c6e5d2; }
.flash-error { background: var(--err-bg); color: var(--err); border-color: #f0c8c8; }
.flash-warn { background: var(--warn-bg); color: #6b4e00; border-color: #f0dfa8; }

/* admin */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar h1 { margin: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; padding: 6px 10px; }
.table-card { padding: 0; overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.list th, table.list td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #faf8f5; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; text-transform: capitalize; vertical-align: middle; }
.badge-sent { background: #eef1f6; color: #3b4a63; }
.badge-viewed { background: var(--warn-bg); color: #6b4e00; }
.badge-signed { background: var(--ok-bg); color: var(--ok); }
.badge-void { background: #eee; color: #777; }
.two-col { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 20px; align-items: start; }
.two-col .agreement { margin: 0; max-width: none; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-size: .85rem; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0 0 8px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 15px; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }

@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 18px 16px; }
  .card.center { padding: 28px 18px; }
  .grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .agreement td:first-child { width: 40%; }
}
