:root {
  --primary: #174b86;
  --primary-dark: #10365f;
  --ui-bg: #e9edf2;
  --paper: #fff;
  --ink: #111;
  --danger: #a52828;
  --page-shadow: 0 9px 28px rgba(17, 29, 43, .18);
}

* { box-sizing: border-box; }

html { background: var(--ui-bg); }

body {
  margin: 0;
  color: var(--ink);
  background: var(--ui-bg);
  font-family: Arial, Helvetica, sans-serif;
}

button {
  border: 1px solid var(--primary-dark);
  border-radius: 6px;
  padding: 9px 14px;
  background: var(--primary);
  color: #fff;
  font: 600 14px/1.2 Arial, sans-serif;
  cursor: pointer;
}

button:hover { filter: brightness(.97); }
button:focus-visible { outline: 3px solid rgba(31, 95, 170, .3); outline-offset: 2px; }
button:disabled { opacity: .48; cursor: not-allowed; }
button.secondary { background: #fff; color: #233447; border-color: #9ca8b5; }
button.danger-outline { background: #fff; color: var(--danger); border-color: #cc8a8a; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px max(14px, calc((100vw - 210mm) / 2));
  border-bottom: 1px solid #c8d0da;
  background: rgba(255,255,255,.96);
  box-shadow: 0 2px 13px rgba(0,0,0,.09);
  backdrop-filter: blur(8px);
}

.brand-block { display: grid; gap: 2px; min-width: 210px; }
.brand-block strong { font-size: 18px; color: #12253a; }
.brand-block span { color: #657385; font-size: 13px; }
.header-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }

.progress-wrap {
  max-width: 1100px;
  margin: 14px auto 4px;
  padding: 0 12px;
}

.step-buttons {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.step-button {
  min-width: 0;
  padding: 7px 5px;
  border-radius: 5px;
  border-color: #aab4bf;
  background: #fff;
  color: #34475b;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.step-button.active { color: #fff; background: var(--primary); border-color: var(--primary-dark); }
.step-button.completed { background: #e7f1e8; color: #285b2c; border-color: #9dc5a2; }

.progress-track { height: 5px; margin-top: 8px; overflow: hidden; border-radius: 999px; background: #ced5dd; }
.progress-bar { height: 100%; width: 0; background: var(--primary); transition: width .25s ease; }
.progress-text { margin-top: 5px; text-align: center; color: #566577; font-size: 13px; }

.permit-app { padding: 12px 8px 24px; }
.permit-section { display: none; }
.permit-section.active { display: block; }

.permit-heading {
  width: min(210mm, calc(100vw - 20px));
  margin: 0 auto 10px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  color: #233447;
}
.permit-heading h1 { margin: 0; font-size: 18px; }
.permit-heading span { font-size: 12px; color: #667486; }

.form-page {
  position: relative;
  container-type: inline-size;
  width: min(210mm, calc(100vw - 20px));
  aspect-ratio: 1241 / 1754;
  margin: 0 auto 18px;
  overflow: hidden;
  background-color: var(--paper);
  background-position: 0 0;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  box-shadow: var(--page-shadow);
}

.form-control {
  position: absolute;
  z-index: 4;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: .1cqw .35cqw;
  border: 0;
  border-radius: 0;
  outline: 0;
  color: #000;
  background: transparent;
  font: 400 1.28cqw/1.15 "Times New Roman", Times, serif;
  resize: none;
  overflow: hidden;
}

.form-control:hover { background: rgba(255, 235, 128, .14); }
.form-control:focus { background: rgba(211, 235, 255, .42); box-shadow: inset 0 0 0 .15cqw rgba(31, 95, 170, .45); }
textarea.form-control { line-height: 1.2; padding: .35cqw .45cqw; }
.form-control.center { text-align: center; }
.form-control.small { font-size: 1.05cqw; }
.form-control.tiny { font-size: .92cqw; }
.form-control.bold { font-weight: 700; }

.check-control,
.radio-control {
  position: absolute;
  z-index: 6;
  display: grid;
  place-items: center;
  margin: 0;
  border: 0;
  outline: 0;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
.check-control:hover,
.radio-control:hover { background: rgba(255, 235, 128, .25); }
.check-control:focus-visible,
.radio-control:focus-visible { box-shadow: inset 0 0 0 .2cqw rgba(31,95,170,.6); }
.check-control:checked::after,
.radio-control:checked::after {
  content: "✓";
  display: block;
  color: #000;
  font: 700 2.05cqw/.9 Arial, sans-serif;
  transform: translateY(-.05cqw);
}
.radio-control:checked::after { content: "●"; font-size: 1.45cqw; }

.signature-block,
.image-block {
  position: absolute;
  z-index: 8;
}

.signature-preview,
.image-preview {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.signature-preview.has-image,
.image-preview.has-image { display: block; }

.signature-name {
  position: absolute;
  z-index: 4;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 37%;
  padding: 0 .3cqw;
  border: 0;
  outline: 0;
  background: transparent;
  color: #000;
  text-align: center;
  font: 400 1.12cqw/1.1 "Times New Roman", Times, serif;
}
.signature-name:focus { background: rgba(211,235,255,.45); box-shadow: inset 0 0 0 .15cqw rgba(31,95,170,.45); }

.upload-button,
.remove-image-button {
  position: absolute;
  z-index: 12;
  top: 0;
  padding: .35cqw .55cqw;
  border-radius: .4cqw;
  border: .1cqw solid #8b99a7;
  background: rgba(255,255,255,.94);
  color: #34475b;
  font: 600 .82cqw/1 Arial, sans-serif;
  box-shadow: 0 .1cqw .35cqw rgba(0,0,0,.12);
}
.upload-button { left: 50%; transform: translateX(-50%); }
.remove-image-button { right: 0; color: #9d2525; }
.signature-file,
.image-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.sketch-block .image-preview { object-fit: contain; background: rgba(255,255,255,.02); }

.bottom-nav {
  position: sticky;
  bottom: 0;
  z-index: 100;
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr minmax(110px, auto);
  align-items: center;
  gap: 12px;
  padding: 10px max(14px, calc((100vw - 210mm) / 2));
  border-top: 1px solid #c8d0da;
  background: rgba(255,255,255,.97);
  box-shadow: 0 -2px 13px rgba(0,0,0,.08);
  backdrop-filter: blur(8px);
}
.bottom-nav__center { text-align: center; color: #687789; font-size: 12px; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 74px;
  z-index: 150;
  max-width: min(390px, calc(100vw - 36px));
  padding: 12px 15px;
  border-radius: 6px;
  color: #fff;
  background: #263544;
  font: 14px/1.35 Arial, sans-serif;
  box-shadow: 0 6px 24px rgba(0,0,0,.24);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

@media (max-width: 860px) {
  .app-header { position: static; align-items: flex-start; flex-direction: column; }
  .header-actions { width: 100%; justify-content: stretch; }
  .header-actions button { flex: 1 1 145px; }
  .step-buttons { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .bottom-nav { position: static; grid-template-columns: 1fr 1fr; }
  .bottom-nav__center { grid-column: 1 / -1; grid-row: 1; }
}

@media (max-width: 520px) {
  .step-buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .permit-heading { align-items: flex-start; flex-direction: column; gap: 3px; }
  .upload-button, .remove-image-button { font-size: 1.15cqw; padding: .45cqw .65cqw; }
}

@page { size: A4 portrait; margin: 0; }

@media print {
  html, body { margin: 0; width: 210mm; background: #fff; }
  .no-print, .permit-heading { display: none !important; }
  .permit-app { padding: 0; }
  .permit-section { display: none !important; }
  body.print-all .permit-section { display: block !important; }
  body:not(.print-all) .permit-section.active { display: block !important; }
  .form-page {
    width: 210mm;
    height: 297mm;
    margin: 0;
    box-shadow: none;
    break-after: page;
    page-break-after: always;
  }
  .permit-section:last-child .form-page:last-child { break-after: auto; page-break-after: auto; }
  .form-control:hover, .form-control:focus, .signature-name:focus { background: transparent; box-shadow: none; }
  .upload-button, .remove-image-button { display: none !important; }
}
