@import url("document-fonts.css");

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 0;
}

body {
  color: #000;
  background: #e6e7e9;
  font-family: "Instruction Serif", "Noto Serif CJK JP", "Yu Mincho", serif;
  font-size: 8pt;
  font-weight: 400;
  letter-spacing: 0;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.page-viewport {
  width: 100%;
  margin: 0 auto;
  position: relative;
}

.paper {
  width: 210mm;
  height: 297mm;
  padding: 19.05mm 17.755mm 0;
  margin: 0;
  background: #fff;
  transform-origin: top left;
  position: absolute;
  top: 0;
  left: 0;
}

/* The source sheet has 13 columns and 39 equal-height rows from B2:N40. */
.instruction-table {
  display: grid;
  grid-template-columns: repeat(3, 9fr) repeat(10, 8fr);
  grid-template-rows: repeat(28, 5.53968mm) calc(5.53968mm + var(--notes-extra-height, 0px)) repeat(10, 5.53968mm);
  width: 174.49mm;
  border-top: 0.25mm solid #000;
  border-left: 0.25mm solid #000;
}

.cell {
  margin: 0;
  min-width: 0;
  min-height: 0;
  border-right: 0.25mm solid #000;
  border-bottom: 0.25mm solid #000;
}

.label,
.driver-sign-label,
.title-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.label,
.confirmation-heading {
  font-family: "Instruction Sans", "Noto Sans CJK JP", sans-serif;
  font-size: 8pt;
  font-weight: 700;
  line-height: 1.5;
}

.value {
  display: flex;
  align-items: center;
}

.content {
  width: 100%;
  padding: 0.6mm 0.55mm;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.title-cell {
  grid-area: 1 / 1 / 3 / 14;
  font-family: "Instruction Sans", "Noto Sans CJK JP", sans-serif;
  font-size: 14pt;
  font-weight: 700;
  line-height: 1;
}

.separator {
  display: grid;
  grid-template-columns: repeat(3, 9fr) repeat(10, 8fr);
  grid-column: 1 / 14;
  min-height: 0;
}

.separator i {
  border-right: 0.25mm solid #000;
  border-bottom: 0.25mm solid #000;
}

.separator-first { grid-row: 3; }
.separator-second { grid-row: 8; }
.company-label { grid-area: 4 / 1 / 6 / 4; }
.company-value { grid-area: 4 / 4 / 6 / 8; }
.office-label { grid-area: 4 / 8 / 6 / 10; }
.office-value { grid-area: 4 / 10 / 6 / 14; }
.manager-label { grid-area: 6 / 1 / 8 / 4; }
.manager-value { grid-area: 6 / 4 / 8 / 8; }
.created-label { grid-area: 6 / 8 / 8 / 10; }
.created-value { grid-area: 6 / 10 / 8 / 14; }
.itinerary-label { grid-area: 9 / 1 / 15 / 4; }
.itinerary-value { grid-area: 9 / 4 / 15 / 14; }
.driver-label { grid-area: 15 / 1 / 17 / 4; }
.driver-value { grid-area: 15 / 4 / 17 / 14; }
.vehicle-label { grid-area: 17 / 1 / 20 / 4; }
.vehicle-value { grid-area: 17 / 4 / 20 / 14; }
.client-label { grid-area: 20 / 1 / 23 / 4; }
.client-value { grid-area: 20 / 4 / 23 / 14; }
.safety-label { grid-area: 23 / 1 / 34 / 4; }
.attractions-value { grid-area: 23 / 4 / var(--safety-divider-row, 29) / 14; }
.notes-value { grid-area: var(--safety-divider-row, 29) / 4 / 34 / 14; }
.confirmation-heading { grid-area: 34 / 1 / 35 / 14; }
.manager-sign-label { grid-area: 35 / 1 / 38 / 4; }
.manager-sign-value { grid-area: 35 / 4 / 38 / 8; }
.driver-sign-label { grid-area: 35 / 8 / 38 / 10; }
.driver-sign-value { grid-area: 35 / 10 / 38 / 14; }
.instruction-date-label { grid-area: 38 / 1 / 40 / 4; }
.instruction-date-value { grid-area: 38 / 4 / 40 / 8; }
.confirmation-date-label { grid-area: 38 / 8 / 40 / 10; }
.confirmation-date-value { grid-area: 38 / 10 / 40 / 14; }

.date-value {
  font-size: 7.7pt;
  line-height: 1.5;
}

.vehicle-value .content {
  padding-left: 1.8mm;
}

.notes-content {
  text-align: center;
  white-space: normal;
}

.dispatch-notes {
  margin-top: 1.8mm;
  white-space: pre-wrap;
}

.safety-reminder {
  margin-top: 3.5mm;
}

.notes-value.is-compact .notes-content {
  line-height: 1.15;
}

.notes-value.is-compact .dispatch-notes {
  margin-top: 0.6mm;
  text-align: left;
  white-space: normal;
}

.notes-value.is-compact .safety-reminder {
  margin-top: 0.6mm;
}

.confirmation-heading {
  display: flex;
  align-items: center;
  padding-left: 0.6mm;
}

.driver-sign-label {
  line-height: 1.5;
}

.document-attribution {
  max-height: 40mm;
  margin-top: 4mm;
  color: #4b4b4b;
  font-family: "Instruction Sans", "Noto Sans CJK JP", sans-serif;
  font-size: 6.5pt;
}

.document-attribution .content {
  padding: 0;
  white-space: normal;
}

.google-maps-brand {
  display: inline-flex;
  padding: 10px 10px 5px;
}

.google-maps-brand img {
  display: block;
  width: auto;
  height: 18px;
}

.document-providers,
.document-legal {
  display: flex;
  flex-wrap: wrap;
  gap: 2mm 4mm;
  overflow-wrap: anywhere;
}

.document-providers:empty {
  display: none;
}

.document-legal {
  margin-top: 2mm;
}

.document-attribution a {
  color: inherit;
}

[hidden] {
  display: none !important;
}

.print-ready .document-attribution {
  display: none !important;
}

.native-print-loading {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  gap: 12px;
  padding: 24px;
  color: #263c35;
  background: #f3f6f4;
  font: 14px/1.5 system-ui, sans-serif;
  text-align: center;
}

.native-print-loading strong {
  font-size: 18px;
}

.native-print-spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto 8px;
  border: 3px solid #dce6e1;
  border-top-color: #187b61;
  border-radius: 50%;
  animation: native-print-spin 900ms linear infinite;
}

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

.native-print-toolbar {
  position: fixed;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 1;
  display: flex;
  gap: 8px;
}

.native-print-toolbar button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 64px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid #c5d6ce;
  border-radius: 6px;
  color: #1a493b;
  background: #fff;
  font: 16px/1.5 system-ui, sans-serif;
  box-shadow: 0 2px 8px rgb(0 0 0 / 12%);
}

@media (prefers-reduced-motion: reduce) {
  .native-print-spinner { animation: none; }
}

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

@media print {
  .native-print-loading,
  .native-print-toolbar,
  .document-attribution {
    display: none !important;
  }

  html,
  body,
  .page-viewport {
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    background: #fff;
  }

  .paper {
    position: static;
    width: 210mm;
    height: 297mm;
    transform: none !important;
    break-inside: avoid;
    break-after: avoid;
  }

  /* AirPrint may reserve browser margins; only the actual document needs height. */
  .native-print-mode,
  .native-print-mode body,
  .native-print-mode .page-viewport,
  .native-print-mode .paper {
    height: auto !important;
    min-height: 0 !important;
  }
}
