:root {
  --navy: #0b2545;
  --navy-2: #13315c;
  --ink: #17212f;
  --muted: #5b6b7f;
  --line: #dfe5ec;
  --line-2: #eef2f6;
  --bg: #f2f4f7;
  --card: #ffffff;
  --amber: #f0a92e;
  --amber-2: #fff4dd;
  --green: #14805e;
  --red: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 51, .06), 0 8px 24px rgba(16, 32, 51, .05);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

/* ---------------- top bar ---------------- */
.topbar {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 22px;
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-mark {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #f6b73c, #e08a12);
  color: #2a1a00;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .2px;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 15px; letter-spacing: .2px; }
.brand-text span { font-size: 11.5px; color: #b9c6d8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.top-actions { display: flex; align-items: center; gap: 8px; }

.save-box { display: flex; align-items: center; gap: 6px; }

.save-box input {
  width: 190px;
  height: 34px;
  border-radius: 7px;
  border: 1px solid #2c4a73;
  background: #15335b;
  color: #fff;
  padding: 0 10px;
  font-size: 12.5px;
}
.save-box input::placeholder { color: #8fa4c0; }
.save-box input:focus { outline: 2px solid #3f6ba3; outline-offset: 0; }

.select-compact {
  height: 34px;
  max-width: 190px;
  border-radius: 7px;
  border: 1px solid #2c4a73;
  background: #15335b;
  color: #fff;
  padding: 0 8px;
  font-size: 12.5px;
}

/* ---------------- buttons ---------------- */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  background: #fff;
  color: var(--navy);
  height: 34px;
  padding: 0 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #f4f7fb; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }

.btn.primary {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
  height: 40px;
  padding: 0 20px;
}
.btn.primary:hover { background: var(--navy-2); }

.btn.ghost {
  background: transparent;
  border-color: currentColor;
  color: inherit;
}
.topbar .btn.ghost { color: #dbe5f2; border-color: #3d5c85; }
.topbar .btn.ghost:hover { background: #17375f; }

.btn.small { height: 28px; padding: 0 10px; font-size: 12px; border-color: var(--line); background: #fff; }

/* ---------------- layout ---------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(380px, .95fr);
  gap: 18px;
  padding: 18px 22px 26px;
  max-width: 1640px;
  margin: 0 auto;
  align-items: start;
}

.form-col { min-width: 0; display: flex; flex-direction: column; gap: 14px; }

.intro {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 2px 2px 0;
}
.intro h1 { margin: 0 0 3px; font-size: 19px; letter-spacing: -.2px; color: var(--navy); }
.intro p { margin: 0; color: var(--muted); font-size: 12.5px; max-width: 620px; }

.intro-badge {
  display: inline-flex; align-items: center; gap: 7px;
  background: #fff; border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 12px;
  font-size: 11.5px; color: var(--muted); white-space: nowrap;
}
.intro-badge .dot { background: var(--green); }
.intro-badge.busy .dot { background: var(--amber); animation: pulse 1s infinite; }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }

@keyframes pulse { 50% { opacity: .35; } }

/* ---------------- form cards ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line-2);
  cursor: pointer;
  user-select: none;
}
.card-head .idx {
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--amber-2);
  color: #8a5a00;
  display: grid; place-items: center;
  font-size: 11.5px; font-weight: 700;
}
.card-head h2 { margin: 0; font-size: 13.5px; letter-spacing: .1px; }
.card-head .te { color: var(--muted); font-size: 11.5px; margin-left: 4px; }
.card-head .chev { margin-left: auto; color: var(--muted); font-size: 12px; transition: transform .15s; }
.card.collapsed .chev { transform: rotate(-90deg); }
.card.collapsed .card-body { display: none; }

.card-body {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 14px;
  padding: 16px;
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.w1 { grid-column: span 1; }
.field.w2 { grid-column: span 2; }
.field.w3 { grid-column: span 3; }
.field.w4 { grid-column: span 4; }

.field label {
  font-size: 11.5px;
  font-weight: 600;
  color: #33475f;
  display: flex; align-items: baseline; gap: 6px;
}
.field label .te { font-weight: 400; color: #8394a8; font-size: 10.5px; }
.field label .req { color: var(--red); font-weight: 700; }

.field input[type="text"],
.field input[type="email"],
.field input[type="tel"],
.field select {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfe;
  padding: 0 10px;
  font-size: 13px;
  color: var(--ink);
  transition: border-color .12s, box-shadow .12s, background .12s;
}
.field input:hover, .field select:hover { border-color: #c8d2de; }
.field input:focus, .field select:focus {
  outline: none;
  border-color: #3f6ba3;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(63, 107, 163, .12);
}
.field input.bad { border-color: #d6615a; background: #fff6f5; }
.field .msg { font-size: 10.5px; color: var(--red); min-height: 0; }

.field input::placeholder { color: #a7b3c2; }

/* switch */
.switch { display: flex; align-items: center; gap: 10px; height: 36px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 38px; height: 22px; border-radius: 999px;
  background: #d7dee7; position: relative; transition: background .15s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s;
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch .switch-label { font-size: 12.5px; color: #33475f; }

.section-note {
  grid-column: span 4;
  font-size: 11.5px;
  color: #6b7c90;
  background: #f8fafc;
  border: 1px dashed #d9e2ec;
  border-radius: 7px;
  padding: 8px 10px;
}

/* ---------------- footer actions ---------------- */
.foot-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  position: sticky;
  bottom: 10px;
}
.foot-actions .hint { font-size: 11px; color: var(--muted); margin-left: auto; }

/* ---------------- preview ---------------- */
.preview-col {
  position: sticky;
  top: 80px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 108px);
  min-height: 520px;
}

.preview-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-2);
}
.preview-head strong { font-size: 13px; }
.preview-head #previewMeta { color: var(--muted); font-size: 11.5px; margin-left: 8px; }

.preview-frame { position: relative; flex: 1; background: #e9edf2; min-height: 0; }
.preview-frame iframe { width: 100%; height: 100%; border: 0; display: none; background: #e9edf2; }
.preview-frame.has-pdf iframe { display: block; }

.preview-empty {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #7d8fa5; text-align: center; padding: 30px; gap: 10px;
}
.preview-frame.has-pdf .preview-empty { display: none; }
.empty-icon { font-size: 34px; color: #b9c6d5; }
.preview-empty p { margin: 0; font-size: 12.5px; line-height: 1.6; }

.preview-foot { border-top: 1px solid var(--line-2); padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.legend { font-size: 10.8px; color: var(--muted); display: flex; gap: 7px; align-items: flex-start; }
.legend .dot { background: var(--amber); margin-top: 5px; flex: none; }
.page-count { font-size: 11px; color: var(--muted); white-space: nowrap; }

.warn {
  margin: 10px 14px 0;
  border: 1px solid #f0d7a4;
  background: #fffaf0;
  color: #7a5410;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 11.8px;
}
.warn b { font-weight: 700; }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #10243f; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 12.5px; box-shadow: 0 8px 30px rgba(0,0,0,.25); z-index: 50;
  max-width: 90vw;
}
.toast.err { background: #7f1d1d; }

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .preview-col { position: relative; top: 0; height: 620px; }
  .save-box input { width: 140px; }
}

@media (max-width: 720px) {
  .topbar { height: auto; padding: 10px 12px; flex-wrap: wrap; }
  .top-actions { flex-wrap: wrap; }
  .layout { padding: 12px; }
  .card-body { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field.w3, .field.w4 { grid-column: span 2; }
  .intro { flex-direction: column; gap: 10px; }
}

.style-pick { display: flex; align-items: center; gap: 7px; font-size: 11px; color: #b9c6d8; white-space: nowrap; }
.style-pick select { height: 34px; max-width: 178px; background: #15335b; color: #fff; border: 1px solid #2c4a73; border-radius: 7px; padding: 0 8px; }
@media (max-width: 1240px) { .style-pick span { display: none; } }

/* ---------- aadhaar / pan upload ---------- */
.scan-body { display: block; padding: 14px 16px; }
.drop-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.drop {
  border: 1.5px dashed #cbd6e2;
  border-radius: 10px;
  padding: 13px 14px;
  display: flex; flex-direction: column; gap: 2px;
  cursor: pointer; background: #fbfcfe;
  transition: border-color .15s, background .15s;
}
.drop:hover { border-color: #3f6ba3; background: #f4f9ff; }
.drop b { font-size: 12.5px; color: #17212f; }
.drop span { font-size: 11px; color: var(--muted); }
.drop-icon {
  width: 26px; height: 26px; border-radius: 50%;
  background: #eaf2fb; color: #2e5a8a;
  display: grid; place-items: center; font-size: 14px; margin-bottom: 3px;
  align-self: flex-start;
}
.scanning .drop { pointer-events: none; opacity: .6; }
.scan-status { margin-top: 10px; font-size: 12px; display: flex; gap: 8px; align-items: center; color: #33475f; flex-wrap: wrap; }
.scan-ok { color: #136c4a; font-weight: 600; }
.scan-bad { color: var(--red); }
.scan-src { font-size: 11px; color: var(--muted); }
.spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid #cbd6e2; border-top-color: #2e5a8a;
  display: inline-block; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.pct { margin-left: auto; color: var(--muted); font-size: 11px; }
.scan-result { margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.scan-chip {
  background: #f7fafc; border: 1px solid #e3eaf2; border-radius: 8px;
  padding: 7px 9px; display: flex; flex-direction: column; gap: 1px; min-width: 0;
}
.scan-chip span { font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .35px; }
.scan-chip b { font-size: 12px; font-weight: 600; color: #17212f; word-break: break-word; }
.scan-hint { grid-column: 1 / -1; font-size: 11px; color: var(--muted); }
.auto-badge {
  margin-left: auto; font-size: 9.5px; font-weight: 700; letter-spacing: .4px;
  text-transform: uppercase; background: #e8f5ee; color: #136c4a;
  border-radius: 999px; padding: 2px 7px; white-space: nowrap;
}
.input-group {
  display: flex; align-items: stretch;
  border: 1px solid var(--line); border-radius: 7px; background: #fbfcfe; overflow: hidden;
  height: 36px;
}
.input-group:focus-within { border-color: #3f6ba3; background: #fff; box-shadow: 0 0 0 3px rgba(63,107,163,.12); }
.input-prefix {
  display: flex; align-items: center; padding: 0 9px;
  background: #eef3f8; border-right: 1px solid var(--line);
  font-size: 12.5px; font-weight: 600; color: #33475f;
}
.input-group input { flex: 1; min-width: 0; border: 0 !important; border-radius: 0 !important; background: transparent !important; box-shadow: none !important; height: 34px !important; }
@media (max-width: 720px) {
  .drop-row, .scan-result { grid-template-columns: 1fr; }
}

.scan-raw {
  margin: 8px 0 0; padding: 8px 10px; max-height: 180px; overflow: auto;
  background: #f7fafc; border: 1px solid #e3eaf2; border-radius: 7px;
  font-size: 10.5px; line-height: 1.45; color: #33475f; white-space: pre-wrap; word-break: break-word;
}

.sig-box { grid-column: 1 / -1; background: #fff; border: 1px solid #e3eaf2; border-radius: 8px; padding: 10px; display: flex; align-items: center; justify-content: center; }
.sig-box img { max-width: 100%; max-height: 110px; }

.sig-tools { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.sig-tools .btn.small { border-color: var(--line); }

.scan-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.scan-actions .scan-hint { margin: 0; }

/* ---------------- mobile layout ---------------- */
.only-mobile { display: none !important; }
.preview-mobile-tip { display: none; }

@media (max-width: 720px) {
  .only-mobile { display: inline-flex !important; }

  .topbar {
    height: 56px;
    padding: 0 12px;
    gap: 8px;
    flex-wrap: nowrap;
    align-items: center;
  }
  .brand { gap: 8px; min-width: 0; }
  .brand-mark { width: 30px; height: 30px; border-radius: 7px; font-size: 12px; }
  .brand-text strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand-text span { display: none; }
  #menuBtn { margin-left: auto; }

  .top-actions {
    display: none;
    position: absolute;
    left: 0; right: 0; top: 56px;
    background: var(--navy);
    padding: 10px 12px 14px;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    box-shadow: 0 14px 26px rgba(8, 22, 40, .38);
    z-index: 30;
  }
  .topbar.open .top-actions { display: flex; }
  .top-actions .style-pick { width: 100%; }
  .style-pick select { max-width: none; width: 100%; height: 38px; }
  .top-actions .save-box { width: 100%; }
  .save-box input { width: 100%; flex: 1; height: 38px; }
  .top-actions .select-compact { width: 100%; max-width: none; height: 38px; }
  .top-actions #newBtn { width: 100%; height: 38px; }

  .layout { padding: 10px 10px 86px; gap: 10px; }
  .intro h1 { font-size: 17px; }
  .intro p { font-size: 12px; line-height: 1.5; }
  .intro-badge { display: none; }

  .card-head { padding: 11px 12px; }
  .card-head .te { display: none; }
  .card-head h2 { font-size: 13px; }
  .card-body {
    display: flex !important;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
  }
  .card-body > * { width: 100% !important; min-width: 0; grid-column: auto !important; }
  .switch { height: auto; min-height: 40px; align-items: center; }
  .switch .switch-label { flex: 1; line-height: 1.35; font-size: 12.5px; white-space: normal; }
  .field input, .field select, .field textarea { min-height: 42px; font-size: 14px; }
  .field label { font-size: 11.5px; }

  .drop { padding: 10px 12px; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 0; }
  .drop-icon { width: 26px; height: 26px; margin: 0 8px 0 0; font-size: 12px; }
  .drop b { font-size: 12px; }
  .drop span:not(.drop-icon) { flex-basis: 100%; font-size: 10.5px; padding-left: 34px; margin-top: -1px; }
  .drop-icon { flex: 0 0 26px; }
  .scan-actions .btn { width: 100%; min-height: 40px; }
  .scan-actions .scan-hint { display: none; }

  .sig-tools .btn { flex: 1; }
  .sig-box img { max-height: 92px; }

  .preview-col { height: auto; min-height: 0; }
  .preview-head { padding: 10px 12px; }
  .preview-head #previewMeta { display: none; }
  .preview-frame { min-height: 120px; }
  .preview-frame iframe { display: none !important; }
  .preview-frame.has-pdf .preview-empty { display: none; }
  .preview-frame.has-pdf .preview-mobile-tip { display: block; }
  .preview-mobile-tip {
    position: absolute; inset: 0;
    padding: 18px 16px;
    font-size: 12.5px; line-height: 1.55; color: #41586f;
    background: #f6f9fc;
  }
  .preview-foot { padding: 8px 12px; }
  .legend { display: none; }

  .foot-actions {
    position: sticky;
    bottom: 8px;
    padding: 10px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .foot-actions .hint { display: none; }
  .foot-actions .btn.primary { flex: 1; }
  .foot-actions #jumpPreview { order: 3; }
}
