:root {
  /* Brand: Redaxle red on white */
  --blue: #d7322c;        /* primary (brand red) */
  --blue-dark: #b0211c;   /* primary hover */
  --ink: #000000;
  --muted: #6b7280;
  --line: #ececec;
  --bg: #fafafa;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --soft-red: #fdeceb;    /* light red wash for hovers/active */
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: #3c3c3c; border-right: 1px solid var(--line);
  padding: 18px 0; flex-shrink: 0;
}
.brand { font-weight: 800; font-size: 18px; padding: 0 20px 18px; color: var(--ink);
  display: flex; align-items: center; gap: 10px; }
.brand img { height: 30px; width: auto; display: block; }
.brand span { color: var(--blue); }
.brand .wordmark { letter-spacing: .3px; }
.brand .wordmark b { color: var(--blue); }
.nav a {
  display: flex; gap: 10px; align-items: center;
  padding: 11px 20px; color: var(--ink); border-radius: 0;
}
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { background: var(--soft-red); color: var(--blue-dark); font-weight: 600;
  box-shadow: inset 3px 0 0 var(--blue); }
.main { flex: 1; min-width: 0; }
.topbar {
  height: 60px; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 28px;
}
.content { padding: 28px; max-width: 1100px; }
.page-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 22px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--blue); color: #fff; border: 1px solid var(--blue);
  padding: 9px 16px; border-radius: var(--radius); font-weight: 600; cursor: pointer;
  font-size: 14px;
}
.btn:hover { background: var(--blue-dark); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { background: var(--bg); }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* cards / tables */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); }
.card .card-h { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; }
.card .card-b { padding: 20px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
tr:last-child td { border-bottom: none; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.completed { background: #dcfce7; color: var(--green); }
.badge.sent, .badge.viewed { background: #fef3c7; color: var(--amber); }
.badge.draft { background: #f1f5f9; color: var(--muted); }
.badge.voided { background: #fee2e2; color: var(--red); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* forms */
label.fld { display: block; margin-bottom: 14px; }
label.fld span { display: block; font-weight: 600; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: var(--radius); font-size: 14px; font-family: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--soft-red); }

/* auth */
.auth-wrap { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.auth-box { width: 380px; }
.auth-box .brand { justify-content: center; font-size: 24px; padding: 0 0 14px; }
.auth-box .brand img { height: 44px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; margin-bottom: 24px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); }
.stat .n { font-size: 28px; font-weight: 800; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 2px; }

.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 500; }
.flash.err { background: #fee2e2; color: #991b1b; }
.flash.ok { background: #dcfce7; color: #166534; }
.muted { color: var(--muted); }
.right { text-align: right; }
.row { display: flex; gap: 12px; align-items: center; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }

/* prepare / signing canvas */
.editor { display: flex; gap: 20px; align-items: flex-start; }
.tools { width: 240px; flex-shrink: 0; position: sticky; top: 20px; }
.tool-item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: var(--radius); margin-bottom: 8px; cursor: grab; background: #fff; font-weight: 600; }
.tool-item:hover { border-color: var(--blue); background: var(--soft-red); }
.pdf-stage { flex: 1; background: #e9eef3; border-radius: var(--radius); padding: 20px;
  max-height: 80vh; overflow: auto; }
.pdf-page { position: relative; margin: 0 auto 16px; box-shadow: 0 2px 8px rgba(0,0,0,.15); background:#fff; }
.pdf-page canvas { display: block; }
.overlay { position: absolute; inset: 0; }
.fld-box { position: absolute; border: 2px dashed var(--blue); background: rgba(37,99,235,.08);
  border-radius: 4px; cursor: move; font-size: 12px; color: var(--blue-dark);
  display: flex; align-items: center; justify-content: center; user-select: none; }
.fld-box .del { position: absolute; top: -10px; right: -10px; background: var(--red); color: #fff;
  width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 12px; cursor: pointer; }
.fld-box .rs { position: absolute; right: -5px; bottom: -5px; width: 12px; height: 12px;
  background: var(--blue); border-radius: 2px; cursor: nwse-resize; }

/* signing fill field */
.sign-fld { position: absolute; border: 2px solid var(--amber); background: rgba(217,119,6,.08);
  border-radius: 4px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--amber); font-weight: 600; font-size: 12px; overflow: hidden; }
.sign-fld.done { border-color: var(--green); background: rgba(22,163,74,.06); }
.sign-fld img { max-width: 100%; max-height: 100%; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: none;
  align-items: center; justify-content: center; z-index: 50; }
.modal-bg.show { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 480px; max-width: 92vw; overflow: hidden; }
.modal h3 { margin: 0; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal .body { padding: 22px; }
.modal .foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
.sig-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.sig-tabs button { flex: 1; padding: 8px; border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; }
.sig-tabs button.active { border-color: var(--blue); color: var(--blue); font-weight: 600; }
#sigCanvas { border: 1px solid var(--line); border-radius: 8px; width: 100%; touch-action: none; background:#fff; }
