:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #172033;
  --muted: #697386;
  --line: #dce2eb;
  --blue: #2d6cdf;
  --blue-dark: #1f55b6;
  --blue-soft: #edf4ff;
  --green: #17a673;
  --shadow: 0 18px 48px rgba(32, 46, 72, .11);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at 8% 0%, rgba(45, 108, 223, .08), transparent 24rem),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Inter, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1480px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 30px 34px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand h1 {
  margin: 0 0 2px;
  font-size: clamp(22px, 2vw, 29px);
  letter-spacing: -.7px;
}

.brand p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 12px);
  grid-template-rows: repeat(2, 17px);
  gap: 3px;
  padding: 10px;
  border-radius: 13px;
  background: var(--blue);
  box-shadow: 0 8px 20px rgba(45, 108, 223, .28);
}

.brand-mark span {
  border-radius: 2px;
  background: white;
  opacity: .96;
}

.privacy-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 13px;
  border: 1px solid #d9e1ec;
  border-radius: 999px;
  background: rgba(255, 255, 255, .72);
  color: #536071;
  font-size: 13px;
  font-weight: 600;
}

.privacy-pill svg {
  width: 17px;
  fill: var(--green);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(390px, 490px) minmax(520px, 1fr);
  gap: 24px;
}

.controls-panel,
.preview-panel {
  border: 1px solid rgba(215, 222, 233, .9);
  border-radius: 20px;
  background: rgba(255, 255, 255, .88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.controls-panel {
  padding: 24px;
}

.intro-card,
.section-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.intro-card {
  margin-bottom: 17px;
}

.intro-card h2,
.section-heading h2,
.preview-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -.25px;
}

.intro-card p,
.section-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.step-number {
  display: grid;
  flex: 0 0 auto;
  width: 29px;
  height: 29px;
  place-items: center;
  border-radius: 50%;
  background: var(--blue);
  color: white;
  font-size: 13px;
  font-weight: 700;
}

.drop-card {
  position: relative;
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  min-height: 106px;
  padding: 15px 16px;
  border: 1.5px dashed #aeb9c9;
  border-radius: 14px;
  background: var(--surface-soft);
  cursor: pointer;
  transition: border-color .18s, background .18s, transform .18s, box-shadow .18s;
}

.drop-card:hover,
.drop-card:focus-visible,
.drop-card.dragging {
  border-color: var(--blue);
  background: var(--blue-soft);
  outline: none;
  box-shadow: 0 0 0 4px rgba(45, 108, 223, .08);
  transform: translateY(-1px);
}

.drop-card.filled {
  border-style: solid;
  border-color: #80aaf2;
  background: #f2f7ff;
}

.drop-card.warning {
  border-color: #e4a23b;
  background: #fff9ec;
}

.drop-icon {
  display: grid;
  width: 40px;
  height: 46px;
  place-items: center;
  border-radius: 10px;
  background: white;
  color: var(--blue);
  box-shadow: 0 5px 14px rgba(32, 48, 76, .09);
}

.drop-icon svg {
  width: 24px;
  fill: currentColor;
}

.drop-copy {
  min-width: 0;
}

.drop-copy strong,
.drop-copy span,
.drop-copy small {
  display: block;
}

.drop-copy strong {
  margin-bottom: 5px;
  font-size: 14px;
}

.drop-copy span {
  overflow: hidden;
  color: #4f5b6e;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drop-copy small {
  margin-top: 5px;
  color: #8791a1;
  font-size: 11px;
}

.file-check {
  display: none;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: white;
  font-weight: 800;
}

.drop-card.filled .file-check {
  display: grid;
}

.remove-button {
  display: none;
  position: absolute;
  top: 6px;
  right: 7px;
  width: 25px;
  height: 25px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #8791a1;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.drop-card.filled:hover .remove-button,
.remove-button:focus-visible {
  display: block;
}

.remove-button:hover {
  background: #ffecec;
  color: #bd3c3c;
}

.connector-line {
  width: 1px;
  height: 12px;
  margin-left: 29px;
  border-left: 1px dashed #b8c2d0;
}

.settings-card {
  margin-top: 19px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.section-heading {
  margin-bottom: 15px;
}

.setting-row,
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 0;
}

.setting-row + .setting-row,
.setting-row + .toggle-row {
  border-top: 1px solid #edf0f4;
}

.setting-row label,
.toggle-row strong {
  display: block;
  font-size: 13px;
  font-weight: 650;
}

.setting-row small,
.toggle-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.range-control {
  display: flex;
  align-items: center;
  gap: 9px;
}

input[type="range"] {
  width: 112px;
  accent-color: var(--blue);
}

output {
  min-width: 58px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: #465268;
  font-size: 12px;
  text-align: center;
}

.split-control output {
  min-width: 86px;
}

.toggle-row {
  position: relative;
  cursor: pointer;
}

.toggle-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.toggle {
  position: relative;
  width: 43px;
  height: 24px;
  border-radius: 999px;
  background: #c7ced9;
  transition: background .18s;
}

.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 5px rgba(30, 40, 60, .25);
  transition: transform .18s;
}

.toggle-row input:checked + .toggle {
  background: var(--blue);
}

.toggle-row input:checked + .toggle::after {
  transform: translateX(19px);
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 10px;
  margin-top: 20px;
}

.button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  transition: transform .15s, background .15s, border-color .15s, opacity .15s;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.button svg {
  width: 18px;
  fill: currentColor;
}

.button-primary {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: white;
  box-shadow: 0 8px 18px rgba(45, 108, 223, .22);
}

.button-primary:hover:not(:disabled) {
  border-color: var(--blue-dark);
  background: var(--blue-dark);
}

.button-secondary {
  border: 1px solid #cbd3df;
  background: white;
  color: #435068;
}

.button-secondary:hover:not(:disabled) {
  border-color: #9eabba;
  background: #fafbfc;
}

.preview-panel {
  display: flex;
  min-height: 720px;
  flex-direction: column;
  padding: 24px;
  background: rgba(238, 242, 247, .92);
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.25px;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid #d8dfe9;
  border-radius: 999px;
  background: rgba(255, 255, 255, .72);
  color: #6c7686;
  font-size: 11px;
  font-weight: 650;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #aeb6c2;
}

.status-badge.ready {
  color: #147c58;
  border-color: #b7e2d3;
  background: #effbf7;
}

.status-badge.ready .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 166, 115, .12);
}

.paper-stage {
  position: relative;
  display: grid;
  flex: 1;
  min-height: 575px;
  place-items: center;
  overflow: hidden;
  border: 1px solid #d6dde7;
  border-radius: 15px;
  background:
    linear-gradient(45deg, rgba(111, 124, 145, .04) 25%, transparent 25%, transparent 75%, rgba(111, 124, 145, .04) 75%),
    linear-gradient(45deg, rgba(111, 124, 145, .04) 25%, transparent 25%, transparent 75%, rgba(111, 124, 145, .04) 75%),
    #e4e9f0;
  background-position: 0 0, 10px 10px;
  background-size: 20px 20px;
}

.empty-paper,
#pdfPreview {
  width: min(440px, 75%);
  aspect-ratio: 210 / 297;
  border: 0;
  background: white;
  box-shadow: 0 16px 38px rgba(24, 37, 59, .2);
}

.empty-paper {
  display: grid;
  grid-template-columns: var(--left-column, 50%) 1fr;
  grid-template-rows: 1fr 1fr;
}

.empty-cell {
  display: grid;
  place-content: center;
  border: 1px dashed #cad2de;
  color: #8d98a8;
  text-align: center;
}

.empty-cell span {
  font-size: 15px;
  font-weight: 700;
}

.empty-cell small {
  margin-top: 5px;
  font-size: 10px;
}

.empty-cell.muted {
  background: #fbfcfd;
  color: #b2bac5;
}

#pdfPreview {
  display: none;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  background: rgba(235, 239, 245, .78);
  color: #5b6678;
  font-size: 13px;
  font-weight: 650;
  backdrop-filter: blur(3px);
}

.loading-overlay.visible {
  display: flex;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid #cbd6e8;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.layout-legend {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 14px;
  color: #6d788a;
  font-size: 11px;
}

.layout-legend div {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-square {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.legend-square.top {
  background: #7da8f0;
}

.legend-square.bottom {
  background: #b2c6e9;
}

.modal-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(14, 22, 36, .46);
  backdrop-filter: blur(5px);
}

.modal-backdrop.visible {
  display: flex;
}

.modal {
  width: min(420px, 100%);
  padding: 28px;
  border-radius: 18px;
  background: white;
  box-shadow: 0 24px 70px rgba(16, 28, 48, .3);
  text-align: center;
  animation: modal-in .2s ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
}

.modal-icon {
  display: grid;
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  place-items: center;
  border-radius: 16px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 30px;
}

.modal h2 {
  margin: 0;
  font-size: 21px;
}

.modal p {
  margin: 9px auto 21px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 9px;
}

.toast {
  position: fixed;
  z-index: 30;
  right: 24px;
  bottom: 24px;
  max-width: min(420px, calc(100% - 48px));
  padding: 13px 16px;
  border-radius: 10px;
  background: #1f2938;
  color: white;
  box-shadow: 0 12px 30px rgba(20, 28, 40, .25);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: #a73232;
}

@media (max-width: 1050px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    min-height: 680px;
  }
}

@media (max-width: 650px) {
  .app-shell {
    padding: 16px 12px 24px;
  }

  .app-header {
    align-items: flex-start;
  }

  .privacy-pill {
    display: none;
  }

  .controls-panel,
  .preview-panel {
    padding: 18px;
    border-radius: 16px;
  }

  .drop-card {
    grid-template-columns: 43px 1fr auto;
  }

  .range-control {
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
  }

  .action-row,
  .modal-actions {
    grid-template-columns: 1fr;
  }

  .layout-legend {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .empty-paper,
  #pdfPreview {
    width: 88%;
  }
}


/* Ajuste opcional para a primeira página que chega fisicamente em A4 */
.crop-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 10px;
  padding: 11px 12px;
  border: 1px solid #cfe0fb;
  border-radius: 11px;
  background: #f5f9ff;
}

.crop-notice[hidden] {
  display: none;
}

.crop-notice strong,
.crop-notice small {
  display: block;
}

.crop-notice strong {
  color: #2a4772;
  font-size: 12px;
}

.crop-notice small {
  margin-top: 3px;
  color: #6a7890;
  font-size: 10.5px;
  line-height: 1.35;
}

.crop-adjust-button {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid #9ebef1;
  border-radius: 8px;
  background: white;
  color: var(--blue-dark);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.crop-adjust-button:hover {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.crop-modal {
  width: min(760px, 100%);
  padding: 25px;
  text-align: left;
}

.crop-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.crop-modal-header h2 {
  margin-top: 0;
}

.crop-modal-header p {
  max-width: 620px;
  margin: 7px 0 0;
}

.modal-close {
  display: grid;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: white;
  color: #697386;
  cursor: pointer;
  font-size: 23px;
  line-height: 1;
}

.modal-close:hover {
  background: #f3f5f8;
}

.crop-editor {
  display: grid;
  grid-template-columns: 215px 1fr;
  gap: 24px;
  margin-top: 21px;
}

.crop-diagram-wrap {
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.4;
  text-align: center;
}

.crop-diagram {
  position: relative;
  width: 170px;
  aspect-ratio: 210 / 297;
  margin: 0 auto 10px;
  overflow: hidden;
  border: 1px solid #b9c5d5;
  background:
    linear-gradient(to right, transparent calc(50% - .5px), #d7deea calc(50% - .5px), #d7deea calc(50% + .5px), transparent calc(50% + .5px)),
    linear-gradient(to bottom, transparent calc(50% - .5px), #d7deea calc(50% - .5px), #d7deea calc(50% + .5px), transparent calc(50% + .5px)),
    #fbfcfe;
  box-shadow: 0 9px 22px rgba(29, 43, 68, .12);
}

.diagram-label {
  position: absolute;
  z-index: 1;
  color: #9aa4b2;
  font-size: 9px;
  font-weight: 700;
  pointer-events: none;
}

.diagram-label-top {
  top: 6px;
  right: 7px;
}

.crop-box {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  width: 50%;
  height: 50%;
  place-items: center;
  border: 2px solid var(--blue);
  background: rgba(45, 108, 223, .13);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .5);
  color: var(--blue-dark);
  font-size: 9px;
  font-weight: 800;
  transition: width .08s, height .08s, left .08s, top .08s;
}

.crop-controls {
  min-width: 0;
}

.crop-preset-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.crop-preset {
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid #ccd5e2;
  border-radius: 9px;
  background: white;
  color: #4c596d;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.crop-preset:hover,
.crop-preset.active {
  border-color: #8ab0ee;
  background: var(--blue-soft);
  color: var(--blue-dark);
}

.crop-control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-top: 1px solid #edf0f4;
}

.crop-control-row > span {
  font-size: 12px;
  font-weight: 700;
}

.crop-control-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 400;
}

.crop-range-control input[type="range"] {
  width: 145px;
}

.crop-range-control output {
  min-width: 52px;
}

.crop-modal-actions {
  width: min(360px, 100%);
  margin: 22px 0 0 auto;
}

@media (max-width: 650px) {
  .crop-notice {
    align-items: flex-start;
    flex-direction: column;
  }

  .crop-editor {
    grid-template-columns: 1fr;
  }

  .crop-diagram {
    width: 145px;
  }

  .crop-control-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .crop-range-control {
    width: 100%;
    align-items: center;
    flex-direction: row;
  }

  .crop-range-control input[type="range"] {
    flex: 1;
    width: auto;
  }
}
