:root {
  --paper: #f2f2ea;
  --paper-deep: #dfdfd6;
  --ink: #1d1d1b;
  --muted: #595955;
  --line: #b8b8ae;
  --ui-bg: #ecece8;
}

@font-face {
  font-family: "DV-Type";
  src: url("/assets/fonts/1942.ttf") format("truetype");
  font-display: swap;
}

* {
  box-sizing: border-box;
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(400px, 1fr);
  gap: 1.1rem;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.1rem;
}

.panel {
  border: 1px solid #d4d4cc;
  background: #f7f7f3;
  border-radius: 14px;
  padding: 1rem;
}

.panel-header h1 {
  margin: 0 0 0.45rem;
  font-size: 1rem;
  letter-spacing: 0.06em;
}

.panel-header p {
  margin: 0;
  font-size: 0.6rem;
  line-height: 1.55;
  color: #4d4d48;
}

.field-grid {
  margin-top: 0.95rem;
  display: grid;
  gap: 0.75rem;
}

.field {
  display: grid;
  gap: 0.36rem;
}

.field > span,
.checkbox-row > span,
.signature-header > span {
  font-size: 0.52rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

input[type="text"],
input[type="date"],
input[type="file"] {
  width: 100%;
  border: 1px solid #c8c8be;
  background: #fcfcf8;
  border-radius: 7px;
  padding: 0.53rem 0.6rem;
  font-family: "Michroma", sans-serif;
  font-size: 0.62rem;
}

.inline-controls {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.inline-controls input {
  flex: 1;
}

.segmented .mode-btn {
  flex: 1;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

button {
  font-family: "Michroma", sans-serif;
  font-size: 0.56rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid #bdbdaf;
  padding: 0.56rem 0.7rem;
}

.primary-btn {
  background: #181816;
  color: #f0f0ec;
  border-color: #181816;
}

.ghost-btn,
.mode-btn {
  background: #f4f4ef;
  color: #21211e;
}

.mode-btn.active {
  background: #20201d;
  color: #efefe8;
}

.signature-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#signaturePad {
  width: 100%;
  border: 1px solid #c4c4b9;
  background: #f9f9f4;
  border-radius: 7px;
  height: 100px;
  touch-action: none;
}

.actions {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.preview-panel {
  display: grid;
  place-items: center;
}

.id-preview-root {
  width: 100%;
  display: grid;
  place-items: center;
}

.id-card {
  width: min(100%, 660px);
  max-width: 660px;
  aspect-ratio: 1.586;
  background: var(--paper);
  border: 1px solid #b8b8af;
  border-radius: 18px;
  overflow: hidden;
  padding: 4.4% 4.6%;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.08);
  position: relative;
}

.id-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 18px;
  pointer-events: none;
  background: radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.22), transparent 60%);
}

.id-content {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  position: relative;
  z-index: 1;
}

.id-top {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 2.5%;
}

.top-wordmark {
  width: 18.75%;
  max-width: 128px;
  object-fit: contain;
}

.id-tagline {
  font-size: clamp(0.41rem, 0.88vw, 0.6rem);
  letter-spacing: 0.03em;
}

.id-main {
  display: grid;
  grid-template-columns: 44% 1fr;
  gap: 3.2%;
  min-height: 0;
}

.photo-slot {
  border: 1px solid var(--line);
  background: #e8e8df;
  height: 100%;
  align-self: stretch;
  overflow: hidden;
  position: relative;
}

.photo-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 38%;
  display: block;
}

.photo-processed {
  filter: contrast(1.23) saturate(0.68) brightness(1.05) sepia(0.24) hue-rotate(38deg) grayscale(0.3);
}

.photo-slot.empty::after {
  content: "PHOTO";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #6f6f69;
  font-size: 0.58rem;
  letter-spacing: 0.14em;
}

.info-grid {
  border: 1px solid var(--line);
  display: grid;
  grid-template-rows: repeat(5, 1fr);
  height: 100%;
  align-self: stretch;
  min-height: 0;
}

.info-row {
  display: grid;
  grid-template-columns: 37% 1fr;
  border-bottom: 1px solid var(--line);
}

.info-row:last-child {
  border-bottom: none;
}

.info-label {
  border-right: 1px solid var(--line);
  padding: 0.29rem 0.26rem 0.22rem;
  font-size: clamp(0.31rem, 0.56vw, 0.42rem);
  line-height: 1.1;
  text-transform: uppercase;
}

.info-value {
  padding: 0.23rem 0.34rem;
  font-family: "DV-Type", "Courier New", monospace;
  font-size: clamp(0.62rem, 1.35vw, 0.95rem);
  line-height: 1.08;
  display: flex;
  align-items: center;
  overflow: hidden;
  min-height: 0;
}

.signature-value {
  height: 100%;
  padding-top: 0.12rem;
  padding-bottom: 0.12rem;
}

.signature-value img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.id-bottom {
  margin-top: 2%;
  display: flex;
  justify-content: space-between;
  align-items: end;
}

.bottom-logo {
  width: 26%;
  max-width: 160px;
  object-fit: contain;
  opacity: 0.92;
}

.serial {
  font-size: clamp(0.32rem, 0.62vw, 0.46rem);
  color: #252521;
}

.print-sheet {
  max-width: 8.2in;
  margin: 0 auto;
  padding: 0.25in;
  display: grid;
  gap: 0.22in;
  justify-items: center;
}

.print-cards {
  display: grid;
  grid-template-columns: repeat(2, 3.375in);
  gap: 0.24in;
  align-items: start;
}

.print-card-wrap,
.print-card-back {
  width: 3.375in;
}

.print-card-back .id-card {
  box-shadow: none;
}

.back-face {
  height: 100%;
  display: grid;
  place-items: center;
}

.back-face img {
  width: 74%;
  height: auto;
  object-fit: contain;
}

.photo-cutout-wrap {
  display: grid;
  gap: 0.14in;
  justify-items: center;
}

.photo-cutout {
  width: 1.22in;
  height: 1.48in;
  border: 1px dashed #4a4a46;
  background: #f5f5f1;
  padding: 0.05in;
}

.photo-cutout img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 38%;
  display: block;
}

.print-note {
  font-size: 9.5pt;
  letter-spacing: 0.04em;
  text-align: center;
}

.crop-modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 18, 0.55);
  display: none;
  place-items: center;
  z-index: 20;
  padding: 1rem;
}

.crop-modal.open {
  display: grid;
}

.crop-dialog {
  width: min(560px, 100%);
  border: 1px solid #cfcfc6;
  border-radius: 12px;
  background: #f7f7f3;
  padding: 0.9rem;
}

.crop-header h2 {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.crop-header p {
  margin: 0.35rem 0 0.8rem;
  font-size: 0.52rem;
  color: #4d4d48;
}

.crop-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 1.22 / 1.48;
  border: 1px solid #bebeb3;
  background: #efefe8;
  overflow: hidden;
  touch-action: none;
}

.crop-viewport img {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.crop-actions {
  margin-top: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

.crop-status {
  margin-right: auto;
  font-size: 0.5rem;
  color: #4b4b45;
}

.screen-only {
  display: grid;
}

.print-only {
  display: none;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .id-card {
    width: min(100%, 520px);
  }

  .print-cards {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: letter portrait;
    margin: 0.35in;
  }

  body {
    background: #fff;
  }

  .screen-only {
    display: none !important;
  }

  .print-only {
    display: grid !important;
  }

  .crop-modal {
    display: none !important;
  }

  .id-card {
    box-shadow: none;
    border-radius: 0.11in;
  }

  /* Print sheet only: match preview label size; avoid wrap from vw/clamp inflation */
  /* Print front card only: allow labels to wrap within label column (no spill into value column) */
  .print-card .info-label {
    font-size: 4pt;
    line-height: 1.12;
    white-space: normal;
    /* Wrap at spaces for multi-word labels; avoid mid-word breaks that orphan one letter (e.g. SIGNATURE) */
    overflow-wrap: normal;
    word-wrap: normal;
    word-break: normal;
    letter-spacing: 0.015em;
    text-wrap: pretty;
  }
}
input[type="date"] {
  width: 100%;
  text-align: left;
}
body {
  overflow-x: hidden;
}
@media (max-width: 768px) {
  .preview-panel,
  .id-preview-root {
    width: 100%;
    overflow: hidden;
  }

  .id-card {
    width: 100%;
    max-width: none;
    margin: 0 auto;
    padding: 4.1% 4.2%;
  }

  .id-content {
    grid-template-rows: auto minmax(0, 74%) auto;
    height: 100%;
  }

  .id-main {
    grid-template-columns: 44% 1fr;
    gap: 3%;
    align-items: stretch;
    min-height: 0;
    overflow: hidden;
  }

  .photo-slot,
  .info-grid {
    height: auto;
    min-height: 0;
    align-self: stretch;
  }

  .id-bottom {
    display: flex;
    justify-content: space-between;
    align-items: end;
    margin-top: 4.4%;
    min-height: 9%;
    flex: 0 0 auto;
    position: relative;
    z-index: 2;
  }

  .top-wordmark {
    width: 16.5%;
  }

  .id-tagline {
    font-size: 0.44rem;
  }

  .info-label {
    font-size: 0.27rem;
    line-height: 1.05;
    padding: 0.22rem 0.18rem 0.16rem;
  }

  .info-value {
    font-size: 0.58rem;
    padding: 0.18rem 0.24rem;
  }

  .bottom-logo {
    width: 22%;
  }

  .serial {
    font-size: 0.28rem;
  }

  input,
  select,
  textarea,
  button {
    box-sizing: border-box;
    max-width: 100%;
  }

  input[type="date"] {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    text-align: left;
    -webkit-appearance: none;
    appearance: none;
  }

  .field input[type="date"],
  .form-row input[type="date"],
  .controls input[type="date"] {
    width: 100%;
    max-width: 100%;
  }
}

  .info-row {
    min-height: 0;
  }