:root {
  --violet: #4b3aa8;
  --violet-dark: #33277a;
  --ink: #1d1b26;
  --muted: #666170;
  --line: #d9d6e2;
  --bg: #efedf4;
  --danger: #b3261e;
  --ok: #1e7b34;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; font: 16px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif; color: var(--ink); background: var(--bg); }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: #1b1730; color: #fff; }
.bar-brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; }
.bar-brand img { height: 32px; width: auto; }
.bar-out { border: 1px solid rgba(255, 255, 255, 0.3); background: transparent; color: #fff; border-radius: 6px; padding: 6px 12px; cursor: pointer; }

main { max-width: 900px; margin: 0 auto; padding: 16px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 14px; }
.narrow { max-width: 440px; margin: 24px auto; }
.center { text-align: center; }
.muted { color: var(--muted); }
h1 { font-size: 22px; margin: 0 0 8px; color: var(--violet-dark); }
h2 { font-size: 18px; margin: 0 0 10px; color: var(--violet-dark); }
.logo { display: block; width: 150px; height: auto; margin: 0 auto 12px; }

label.field { display: flex; flex-direction: column; gap: 4px; margin: 12px 0; font-weight: 600; font-size: 14px; color: var(--muted); }
input[type="email"], input[type="text"], textarea { width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
input:focus, textarea:focus { outline: 2px solid var(--violet); outline-offset: -1px; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 18px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--violet); border-color: var(--violet); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--violet-dark); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-link { border: 0; background: none; color: var(--violet-dark); text-decoration: underline; padding: 0; min-height: 0; cursor: pointer; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }

.est-list { list-style: none; margin: 0; padding: 0; }
.est-item { display: block; width: 100%; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 10px; cursor: pointer; }
.est-item:hover { border-color: var(--violet); }
.est-item .top { display: flex; justify-content: space-between; gap: 10px; font-weight: 700; }
.est-item .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill-wait { background: #fff1d9; color: #8a5300; }
.pill-signed { background: #dff3e4; color: var(--ok); }
.pill-off { background: #eceaf1; color: var(--muted); }

.sums { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; font-variant-numeric: tabular-nums; }
.sums .v { text-align: right; font-weight: 600; }

.consent { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; font-size: 15px; }
.consent input { width: 22px; height: 22px; margin-top: 2px; flex: none; }
.error { color: var(--danger); margin: 8px 0 0; }
.preview-note { background: #fff1d9; border-color: #f0d49e; color: #6b4100; }
.signed-box { background: #dff3e4; border: 1px solid #b6dfc0; color: #174d25; border-radius: 8px; padding: 12px 14px; }

.doc-tools { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 18px 0 8px; }
.preview { overflow: hidden; background: #d6d3de; border-radius: 8px; padding: 8px; }
.preview.full { overflow-x: auto; }
.preview .page { margin-bottom: 8px; }

.flash { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 20; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 8px; background: #1b1730; color: #fff; }
.flash.is-error { background: var(--danger); }

@media (max-width: 600px) {
  main { padding: 10px; }
  .bar-brand span { font-size: 15px; }
  .row { flex-direction: column; }
  .row .btn { width: 100%; }
  .doc-tools { flex-direction: column; align-items: stretch; }
}

@media print {
  body { background: #fff; }
  .bar, .flash, main > :not(.doc-area), .doc-tools { display: none !important; }
  main { padding: 0; max-width: none; }
  .preview { background: none; padding: 0; }
}
