:root {
  --page-width: 894px;
  --page-height: 1280px;
  --ink: #111;
  --panel: #ffffff;
  --panel-border: #d8dde5;
  --app-bg: #eef1f5;
  --control-text: #18202b;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

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

button,
input {
  font: inherit;
}

.generator {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
}

.controls {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 24px;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  color: var(--control-text);
}

.controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 24px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.controls h1,
.signature-pad h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.action-button,
.signature-pad button {
  min-height: 36px;
  border: 1px solid #aeb8c6;
  border-radius: 7px;
  background: #f7f9fc;
  color: #16202c;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.action-button {
  padding: 0 14px;
}

.action-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.fields {
  display: grid;
  gap: 15px;
}

.fields label {
  display: grid;
  gap: 7px;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

.fields input {
  width: 100%;
  min-height: 40px;
  border: 1px solid #bac4d2;
  border-radius: 7px;
  padding: 8px 10px;
  color: #111827;
  background: #fff;
  font-size: 14px;
  outline: none;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
}

.field-icon-button {
  min-height: 40px;
  border: 1px solid #aeb8c6;
  border-radius: 7px;
  background: #f7f9fc;
  color: #16202c;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.field-icon-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.fields input:focus,
.field-icon-button:focus-visible,
.draw-canvas:focus {
  border-color: #355ed8;
  box-shadow: 0 0 0 3px rgba(53, 94, 216, 0.16);
}

.pickup-search {
  display: grid;
  gap: 8px;
}

.address-autocomplete {
  position: relative;
  display: grid;
  gap: 7px;
}

.nearby-button {
  min-height: 40px;
  border: 1px solid #aeb8c6;
  border-radius: 7px;
  background: #f7f9fc;
  color: #16202c;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.address-suggestions {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  display: grid;
  gap: 4px;
  max-height: 220px;
  overflow: auto;
  padding: 6px;
  border: 1px solid #c9d2df;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
}

.address-suggestion {
  display: grid;
  gap: 2px;
  width: 100%;
  border: 0;
  border-radius: 5px;
  padding: 8px;
  background: transparent;
  color: #142033;
  text-align: left;
  cursor: pointer;
}

.address-suggestion:hover,
.address-suggestion:focus-visible {
  background: #f4f7ff;
  outline: none;
}

.address-suggestion-main {
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}

.address-suggestion-meta {
  color: #64748b;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
}

.pickup-status {
  min-height: 18px;
  color: #4b5c72;
  font-size: 12px;
  font-weight: 700;
}

.pickup-origin {
  display: block;
  margin-top: 2px;
  color: #64748b;
  font-weight: 600;
}

.pickup-status.error {
  color: #b42318;
}

.pickup-results {
  display: grid;
  gap: 7px;
  max-height: 248px;
  overflow: auto;
  padding-right: 2px;
}

.pickup-result {
  display: grid;
  gap: 4px;
  width: 100%;
  border: 1px solid #d2d9e4;
  border-radius: 7px;
  padding: 9px 10px;
  background: #fbfcfe;
  color: #142033;
  text-align: left;
  cursor: pointer;
}

.nearby-button:hover,
.nearby-button:focus-visible,
.pickup-result:hover,
.pickup-result:focus-visible {
  border-color: #355ed8;
  background: #f4f7ff;
  outline: none;
}

.pickup-result-main {
  font-size: 13px;
  font-weight: 800;
  line-height: 1.2;
}

.pickup-result-meta,
.pickup-result-kind {
  color: #536276;
  font-size: 12px;
  line-height: 1.25;
}

.pickup-result-kind {
  color: #35517a;
  font-weight: 700;
}

.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: block;
}

.signature-pad {
  margin-top: 28px;
}

.signature-pad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.signature-actions {
  display: flex;
  gap: 8px;
}

.signature-pad button {
  padding: 0 12px;
}

.draw-canvas {
  display: block;
  width: 100%;
  height: 170px;
  border: 1px solid #bac4d2;
  border-radius: 7px;
  background:
    linear-gradient(#fff, #fff) padding-box,
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(20, 29, 42, 0.08) 32px);
  touch-action: none;
  cursor: crosshair;
}

.preview-area {
  min-width: 0;
  padding: 28px;
  overflow: auto;
}

.letter {
  position: relative;
  width: var(--page-width);
  height: var(--page-height);
  overflow: hidden;
  background: #fff;
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.18);
  transform-origin: top left;
}

.letter-header,
.routing,
.content,
.footer {
  position: absolute;
}

.letter-header {
  inset: 0 0 auto 0;
  height: 230px;
}

.brand {
  position: absolute;
  top: 76px;
  left: 60px;
  width: 190px;
}

.post-logo {
  width: 112px;
  height: 75px;
  display: block;
  margin-left: 20px;
  object-fit: contain;
}

.service {
  margin-top: 27px;
  font-size: 17px;
  line-height: 1.24;
}

.service strong,
.service span {
  display: block;
}

.service-banner {
  position: absolute;
  top: 14px;
  right: 19px;
  width: 315px;
  height: auto;
  display: block;
}

.routing-left {
  top: 278px;
  left: 79px;
  color: #161616;
  font-family: "Courier New", Courier, monospace;
  font-size: 17px;
  line-height: 1.4;
  letter-spacing: 0.3px;
}

.routing p {
  margin: 0;
}

.routing-right {
  top: 277px;
  right: 74px;
  width: 395px;
  font-size: 16px;
  line-height: 1.1;
  text-align: center;
  display: grid;
  row-gap: 5px;
  justify-items: end;
}

.routing-right .recipient-line {
  max-width: 180px;
  text-align: right;
}

.routing-right .pickup-line {
  justify-self: end;
  width: auto;
  max-width: 370px;
  font-weight: 400;
  line-height: 1.05;
  text-align: center;
  text-wrap: balance;
}

.routing-right .pickup-line.is-long {
  max-width: 395px;
  font-size: 14px;
  white-space: nowrap;
}

.routing-right .pickup-line.is-very-long {
  max-width: 350px;
  font-size: 14px;
  white-space: normal;
}

.routing-right .postal-city-line {
  margin-top: 5px;
  max-width: 210px;
  text-align: right;
}

.content {
  top: 386px;
  left: 60px;
  width: 770px;
  font-size: 17px;
  line-height: 1.22;
}

.content h2 {
  margin: 0 0 32px;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.1;
}

.content p {
  margin: 0 0 24px;
}

.content strong {
  font-weight: 800;
}

.signature {
  margin-top: 33px;
  margin-left: 35px;
  width: 150px;
  height: 150px;
}

.signature svg,
.signature img {
  display: block;
  width: 100%;
  height: 100%;
}

.signature img {
  object-fit: contain;
  object-position: center;
}

.signature path {
  fill: none;
  stroke: #202020;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.82;
}

.sender {
  margin-top: 24px;
  font-size: 18px;
  line-height: 1.22;
}

.sender p {
  margin: 0;
}

.footer {
  left: 60px;
  right: 52px;
  bottom: 36px;
  color: #111;
  font-size: 10.3px;
  line-height: 1.24;
}

.footer p {
  margin: 0 0 15px;
}

.footer strong {
  font-style: italic;
}

.footer a {
  color: #2869ad;
  text-decoration: underline;
}

@media (max-width: 980px) {
  .generator {
    display: block;
  }

  .controls {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--panel-border);
  }

  .preview-area {
    padding: 0;
  }

  .letter {
    box-shadow: none;
    transform: scale(min(calc(100vw / 894), 1));
  }
}

@media print {
  body {
    background: #fff;
  }

  .controls {
    display: none;
  }

  .generator {
    display: block;
    min-height: auto;
  }

  .preview-area {
    padding: 0;
    overflow: visible;
  }

  .letter {
    box-shadow: none;
    transform: none;
  }
}
