:root {
  --navy: #0a2240;
  --navy-2: #12375e;
  --blue: #1264a3;
  --blue-soft: #e9f3fb;
  --cyan: #39b9d6;
  --ink: #172235;
  --muted: #667085;
  --line: #d6dce5;
  --surface: #ffffff;
  --canvas: #eef1f5;
  --danger: #b42318;
  --success: #168255;
  --shadow: 0 16px 45px rgba(18, 35, 55, .14);
  --sheet-scale: .78;
  --sheet-w: 794px;
  --sheet-h: 1123px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

button {
  color: inherit;
}

.app-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px clamp(16px, 3vw, 42px);
  color: white;
  background:
    radial-gradient(circle at 85% -40%, rgba(57, 185, 214, .4), transparent 34%),
    linear-gradient(115deg, #071d35, #0b3157 70%, #0e4269);
  border-bottom: 1px solid rgba(255, 255, 255, .14);
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--navy);
  background: white;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: -.5px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
}

.brand-copy {
  min-width: 150px;
}

.eyebrow {
  display: block;
  margin-bottom: 2px;
  color: #9bddef;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.2px;
}

.brand-copy h1 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -.25px;
}

.project-name {
  width: min(420px, 36vw);
  margin-left: clamp(4px, 2vw, 26px);
}

.project-name span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.project-name input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 9px;
  outline: none;
  padding: 9px 12px;
  color: white;
  background: rgba(255, 255, 255, .08);
  font-size: 13px;
  font-weight: 650;
}

.project-name input:focus {
  border-color: rgba(138, 221, 241, .8);
  background: rgba(255, 255, 255, .13);
}

.save-state {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  color: rgba(255, 255, 255, .75);
  font-size: 11px;
  white-space: nowrap;
}

.save-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #58d7a0;
  box-shadow: 0 0 0 4px rgba(88, 215, 160, .12);
}

.save-state.saving .save-dot {
  background: #ffd166;
  box-shadow: 0 0 0 4px rgba(255, 209, 102, .12);
}

.save-state.error .save-dot {
  background: #ff8b82;
  box-shadow: 0 0 0 4px rgba(255, 139, 130, .12);
}

.header-stats {
  display: flex;
  gap: 7px;
}

.header-stats span {
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 999px;
  color: rgba(255, 255, 255, .77);
  background: rgba(255, 255, 255, .07);
  font-size: 10px;
  white-space: nowrap;
}

.header-stats b {
  color: white;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px clamp(16px, 3vw, 42px);
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 3px 12px rgba(16, 35, 55, .06);
  backdrop-filter: blur(12px);
}

.toolbar-primary,
.toolbar-secondary {
  display: flex;
  align-items: center;
  gap: 7px;
}

.button {
  min-height: 36px;
  border: 1px solid #ccd4df;
  border-radius: 8px;
  padding: 8px 12px;
  color: #29364a;
  background: white;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s, box-shadow .15s;
}

.button:hover {
  border-color: #aeb9c7;
  background: #f8fafc;
}

.button:active {
  transform: translateY(1px);
}

.button-primary {
  color: white;
  border-color: var(--blue);
  background: var(--blue);
  box-shadow: 0 4px 12px rgba(18, 100, 163, .2);
}

.button-primary:hover {
  border-color: #0e548b;
  background: #0e548b;
}

.button-dark {
  color: white;
  border-color: var(--navy);
  background: var(--navy);
}

.button-dark:hover {
  border-color: #07172a;
  background: #07172a;
}

.button-ai {
  color: #075f4b;
  border-color: #9ed8c7;
  background: #eefaf6;
}

.button-ai:hover {
  color: #054d3d;
  border-color: #65bda4;
  background: #e2f7ef;
}

.button:disabled {
  opacity: .58;
  cursor: wait;
  transform: none;
}

.button-quiet {
  border-color: transparent;
  color: var(--muted);
  background: transparent;
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
}

.zoom-control select {
  min-height: 34px;
  border: 1px solid #ccd4df;
  border-radius: 8px;
  padding: 5px 28px 5px 9px;
  color: #29364a;
  background: white;
  font-size: 11px;
  font-weight: 700;
}

main {
  width: min(1260px, calc(100% - 32px));
  margin: 22px auto 80px;
}

.setup-panel {
  display: grid;
  grid-template-columns: minmax(190px, .75fr) minmax(580px, 2.25fr);
  gap: 26px;
  padding: 22px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(20, 39, 61, .05);
}

.setup-copy,
.section-heading > div:first-child {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.step-number {
  flex: 0 0 auto;
  color: var(--blue);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1px;
}

.setup-copy h2,
.section-heading h2 {
  margin: -2px 0 4px;
  font-size: 15px;
  letter-spacing: -.2px;
}

.setup-copy p,
.section-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.field-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-grid label span {
  color: #48566b;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .55px;
  text-transform: uppercase;
}

.field-grid input,
.field-grid textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid #d4dbe5;
  border-radius: 8px;
  outline: none;
  padding: 9px 10px;
  color: #253248;
  background: #fbfcfd;
  font-size: 11.5px;
  font-weight: 600;
  resize: vertical;
}

.field-grid input:focus,
.field-grid textarea:focus {
  border-color: #6faed7;
  box-shadow: 0 0 0 3px rgba(18, 100, 163, .09);
}

.upload-strip {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  margin: 14px 0 22px;
  padding: 16px 20px;
  border: 1.5px dashed #8db9d8;
  border-radius: 12px;
  color: var(--ink);
  background: linear-gradient(90deg, #f7fbfe, #eef7fc);
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .15s;
}

.upload-strip:hover,
.upload-strip:focus-visible,
.upload-strip.dragover {
  border-color: var(--blue);
  background: #e6f4fb;
  outline: none;
}

.upload-strip.dragover {
  transform: scale(1.005);
}

.upload-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: white;
  background: var(--blue);
  font-size: 21px;
  font-weight: 800;
}

.upload-strip h2 {
  margin: 0 0 3px;
  font-size: 13px;
}

.upload-strip p {
  margin: 0;
  color: var(--muted);
  font-size: 10.5px;
}

.format-chip {
  padding: 6px 9px;
  border: 1px solid #c5deed;
  border-radius: 999px;
  color: var(--blue);
  background: white;
  font-size: 9.5px;
  font-weight: 850;
  letter-spacing: .25px;
  white-space: nowrap;
}

.preview-section {
  padding-top: 2px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: 0 auto 15px;
}

.legend {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
}

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

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

.legend-dot.before {
  background: #95a5b8;
}

.legend-dot.after {
  background: var(--cyan);
}

.pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.sheet-wrap {
  position: relative;
  width: calc(var(--sheet-w) * var(--sheet-scale));
  height: calc(var(--sheet-h) * var(--sheet-scale));
  transition: width .18s, height .18s;
}

.sheet {
  position: absolute;
  inset: 0 auto auto 50%;
  width: var(--sheet-w);
  height: var(--sheet-h);
  overflow: hidden;
  color: #050505;
  background: white;
  box-shadow: var(--shadow);
  transform: translateX(-50%) scale(var(--sheet-scale));
  transform-origin: top center;
  font-family: Arial, Helvetica, sans-serif;
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}

.sheet-controls {
  position: absolute;
  z-index: 12;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  color: white;
  background: rgba(10, 34, 64, .9);
  box-shadow: 0 5px 14px rgba(0, 0, 0, .18);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .15s, transform .15s;
}

.sheet:hover .sheet-controls,
.sheet-controls:focus-within {
  opacity: 1;
  transform: translateY(0);
}

.sheet-controls span {
  padding: 0 7px;
  font-size: 11px;
  font-weight: 800;
}

.sheet-controls button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 5px;
  color: white;
  background: rgba(255, 255, 255, .12);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.sheet-controls button:hover {
  background: rgba(255, 255, 255, .24);
}

.sheet-controls button.delete:hover {
  background: var(--danger);
}

.cover-sheet {
  display: grid;
  place-items: center;
  padding: 90px;
}

.cover-content {
  width: 80%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 54px;
  text-align: center;
  transform: translateY(-10px);
}

.cover-block {
  width: 100%;
}

.cover-block h3 {
  margin: 0 0 9px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.1px;
  text-transform: uppercase;
}

.cover-block p {
  min-height: 22px;
  margin: 0;
  white-space: pre-line;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

[contenteditable="true"] {
  border-radius: 2px;
  outline: none;
}

[contenteditable="true"]:focus {
  box-shadow: 0 0 0 2px rgba(18, 100, 163, .24);
  background: rgba(233, 243, 251, .6);
}

.photo-sheet {
  padding: 15px 11px;
}

.report-grid {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 40px repeat(3, 1fr);
  border: 1.5px solid #0d0d0d;
}

.column-heading {
  display: grid;
  place-items: center;
  border-bottom: 1.5px solid #0d0d0d;
  font-size: 18px;
  font-weight: 800;
}

.column-heading:first-child {
  border-right: 1.5px solid #0d0d0d;
}

.pair-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr 31px;
  border-bottom: 1.5px solid #0d0d0d;
  background: white;
}

.pair-cell.before-cell {
  border-right: 1.5px solid #0d0d0d;
}

.pair-cell.after-cell {
  grid-template-rows: 1fr 31px;
}

.pair-cell.last-row {
  border-bottom: 0;
}

.photo-frame {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 28px 32px 7px;
  background: white;
}

.photo-frame img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: white;
}

.photo-frame.fill img {
  object-fit: cover;
}

.photo-frame.dragover {
  background: #e7f5fb;
  outline: 4px dashed var(--blue);
  outline-offset: -7px;
}

.photo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #8b98a9;
  border: 2px dashed #ccd4df;
  background: #fafbfd;
  font-size: 13px;
  text-align: center;
  cursor: pointer;
}

.photo-placeholder b {
  color: #536176;
  font-size: 14px;
}

.photo-placeholder small {
  font-size: 10px;
}

.photo-actions {
  position: absolute;
  z-index: 5;
  top: 9px;
  right: 9px;
  display: flex;
  gap: 5px;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity .14s, transform .14s;
}

.photo-frame:hover .photo-actions,
.photo-actions:focus-within {
  opacity: 1;
  transform: translateY(0);
}

.photo-actions button {
  height: 26px;
  border: 0;
  border-radius: 5px;
  padding: 0 8px;
  color: white;
  background: rgba(10, 34, 64, .88);
  font-size: 9px;
  font-weight: 800;
  cursor: pointer;
}

.photo-actions button:hover {
  background: rgba(10, 34, 64, 1);
}

.photo-actions button.remove:hover {
  background: var(--danger);
}

.pair-label-wrap,
.after-spacer {
  display: flex;
  align-items: center;
  font-size: 15px;
}

.pair-label-wrap {
  min-width: 0;
  gap: 6px;
  padding: 0 7px 0 11px;
}

.pair-label {
  min-width: 0;
  flex: 1;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
}

.recognise-row {
  width: 23px;
  height: 23px;
  flex: 0 0 23px;
  display: grid;
  place-items: center;
  border: 1px solid #7bcab4;
  border-radius: 5px;
  color: #08725a;
  background: #effaf6;
  font-size: 11px;
  font-weight: 900;
  cursor: pointer;
}

.recognise-row:hover {
  color: white;
  background: #08725a;
}

.recognise-row:disabled {
  opacity: .55;
  cursor: wait;
}

.ai-result {
  flex: 0 0 auto;
  padding: 2px 5px;
  border-radius: 4px;
  color: #16614f;
  background: #e7f7f1;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 7px;
  font-weight: 900;
  letter-spacing: .25px;
  text-transform: uppercase;
}

.ai-result.low {
  color: #8a3f0a;
  background: #fff1dc;
}

.ai-result.high {
  color: #075f4b;
  background: #dff6ed;
}

.page-number {
  position: absolute;
  bottom: 3px;
  left: 0;
  right: 0;
  color: #687384;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 9px;
  text-align: center;
}

.empty-pages {
  width: min(640px, 100%);
  padding: 60px 25px;
  border: 1px dashed #b9c4d1;
  border-radius: 14px;
  color: var(--muted);
  background: rgba(255, 255, 255, .65);
  text-align: center;
}

.empty-pages h3 {
  margin: 0 0 5px;
  color: var(--ink);
  font-size: 16px;
}

.empty-pages p {
  margin: 0;
  font-size: 12px;
}

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 24px;
  max-width: min(440px, calc(100% - 32px));
  padding: 10px 14px;
  border-radius: 9px;
  color: white;
  background: #15263a;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .22);
  font-size: 11.5px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity .18s, transform .18s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1020px) {
  .app-header {
    flex-wrap: wrap;
  }

  .project-name {
    width: min(460px, calc(100% - 230px));
  }

  .save-state {
    margin-left: 0;
  }

  .header-stats {
    margin-left: auto;
  }

  .toolbar {
    align-items: flex-start;
  }

  .toolbar-primary {
    flex-wrap: wrap;
  }

  .setup-panel {
    grid-template-columns: 1fr;
    gap: 18px;
  }
}

@media (max-width: 760px) {
  main {
    width: min(100% - 20px, 1260px);
    margin-top: 12px;
  }

  .project-name {
    order: 4;
    width: 100%;
    margin: 0;
  }

  .save-state {
    margin-left: auto;
  }

  .header-stats {
    width: 100%;
    margin-left: 56px;
  }

  .toolbar {
    position: static;
    flex-direction: column;
  }

  .toolbar-primary,
  .toolbar-secondary {
    width: 100%;
    flex-wrap: wrap;
  }

  .toolbar-secondary {
    justify-content: flex-end;
  }

  .field-grid {
    grid-template-columns: 1fr 1fr;
  }

  .upload-strip {
    grid-template-columns: auto 1fr;
  }

  .format-chip {
    display: none;
  }

  .section-heading {
    align-items: flex-end;
  }

  .legend {
    display: none;
  }
}

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

  .setup-panel {
    padding: 16px;
  }

  .upload-strip {
    padding: 14px;
  }

  .upload-strip p {
    display: none;
  }

  .button {
    flex: 1 1 auto;
  }
}

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

@media print {
  body {
    background: white;
  }

  .app-header,
  .toolbar,
  .setup-panel,
  .upload-strip,
  .section-heading,
  .toast {
    display: none !important;
  }

  main,
  .preview-section {
    width: auto;
    margin: 0;
    padding: 0;
  }

  .pages {
    display: block;
  }

  .sheet-wrap {
    width: 210mm !important;
    height: 297mm !important;
    break-after: page;
    page-break-after: always;
  }

  .sheet-wrap:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .sheet {
    position: relative;
    inset: auto;
    width: 210mm;
    height: 297mm;
    box-shadow: none;
    transform: none;
  }

  .sheet-controls,
  .photo-actions,
  .recognise-row,
  .ai-result,
  .page-number {
    display: none !important;
  }

  [contenteditable="true"]:focus {
    box-shadow: none;
    background: transparent;
  }
}
