* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  background: #f1f5f9;
  color: #111;
}

.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  width: 300px;
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.login-card h1 {
  margin: 0 0 1.5rem;
  text-align: center;
  font-size: 1.2rem;
}

.login-card label {
  display: block;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.login-card input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.login-card button,
.add-row,
#print-button {
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.login-card button {
  width: 100%;
  padding: 10px;
  background: #2ecc71;
  color: white;
}

.login-error { color: #dc2626; font-size: 0.8rem; }

.bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  height: 54px;
  padding: 0 1.5rem;
  background: #1e3a5f;
  color: white;
  font-weight: 700;
}

.controls {
  background: white;
  padding: 0.875rem 1.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.controls .check { margin-left: 0.75rem; }

.file-pick { position: relative; display: inline-block; vertical-align: middle; }
.file-pick input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.file-pick span {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid #64748b;
  border-radius: 6px;
  background: #e8edf2;
  color: #111;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: inset 0 -1px 0 rgba(15, 23, 42, 0.2);
}

.file-pick:hover span { background: #dbe3ea; }
.file-pick:active span { background: #d0d7de; box-shadow: none; }
.file-pick:focus-within span { outline: 2px solid #2563eb; outline-offset: 1px; }

#file-name {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  max-width: min(40rem, 52vw);
  margin-left: 8px;
  vertical-align: middle;
  color: #64748b;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 3px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #334155;
  font-size: 0.8rem;
}

.file-chip .tag {
  flex: none;
  padding: 2px 6px;
  border-radius: 999px;
  background: #cbd5e1;
  color: #1e293b;
  font-size: 0.7rem;
  font-weight: 700;
}

.file-chip.current { background: #e8eef5; }
.file-chip.current .tag { background: #1e3a5f; color: white; }
.file-chip.pending { color: #64748b; background: #f8fafc; }
.file-chip.current.pending .tag { background: #94a3b8; }

.file-chip .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#pdf-button,
#preview-button,
#preview-close {
  margin-left: 0.75rem;
  border-radius: 6px;
  padding: 8px 16px;
  font-weight: 700;
  cursor: pointer;
}

#pdf-button {
  border: none;
  background: #22c55e;
  color: white;
}

#pdf-button:disabled { opacity: 0.7; cursor: wait; }

#preview-button,
#preview-close {
  border: 1px solid #2563eb;
  background: white;
  color: #2563eb;
}

.hint { margin: 0.5rem 0 0; color: #334155; font-size: 0.75rem; }
.hint strong { color: #dc2626; font-weight: 700; }

#preview-bar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 54px;
  padding: 0 1.5rem;
  background: #1e3a5f;
  color: white;
  font-weight: 700;
}

#preview-close { margin-left: 0; }

body.previewing .sheets {
  display: block;
  min-height: 100vh;
  padding: 16px 16px 32px;
  background: #e2e8f0;
}

body.previewing .print-only-page,
.pdf-rendering .print-only-page {
  width: 210mm;
  height: 297mm;
  overflow: hidden;
  box-sizing: border-box;
  margin: 0;
  padding: 15mm 12mm;
  background: white;
}

body.previewing .screen { display: none !important; }

body.previewing .print-only-page {
  height: auto;
  min-height: 297mm;
  overflow: visible;
  margin: 0 auto 16px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.16);
}

.pdf-rendering .sheets {
  display: block;
  position: absolute;
  left: -10000px;
  top: 0;
  width: 210mm;
}

#list { padding: 12px 16px 0; }

.empty {
  margin: 8px 4px 0;
  color: #334155;
}

.sheet {
  background: white;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.order-row {
  display: grid;
  grid-template-columns:
    2.5rem
    minmax(7.5rem, 0.75fr)
    minmax(12rem, 1.7fr)
    minmax(12rem, 1.25fr)
    5.75rem
    9rem
    15rem
    minmax(6rem, 0.6fr)
    4.75rem;
  column-gap: 8px;
  align-items: start;
  min-width: 1180px;
  padding: 10px 12px;
  border-top: 1px solid #e2e8f0;
}

.order-head {
  position: sticky;
  top: 54px;
  z-index: 1;
  border-top: 0;
  background: #f8fafc;
  color: #1e3a5f;
  font-size: 0.75rem;
  font-weight: 700;
}

.order-head .cell { padding-top: 2px; }

.cell::before { content: none; }

.row-index {
  display: block;
  padding-top: 8px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #1e3a5f;
}

.order-row button {
  min-height: 44px;
  background: #e74c3c;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 700;
}

.cell.block > input,
.cell.block > textarea,
.address {
  height: 7.5em;
  min-height: 7.5em;
  box-sizing: border-box;
}

.address {
  display: flex;
  flex-direction: column;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: white;
  overflow: hidden;
}

.address input {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  max-width: none;
  border: 0;
  border-radius: 0;
  padding: 0 8px;
  background: transparent;
}

.address input + input { border-top: 1px solid #e2e8f0; }

.address:focus-within {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
  border-color: #2563eb;
}

.address input:focus {
  outline: none;
  background: #f8fafc;
}

input[type="text"], textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  font: inherit;
  color: #111;
  background: white;
}

input::placeholder, textarea::placeholder { color: #475569; opacity: 1; }

input[type="text"]:focus, textarea:focus {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
  border-color: #2563eb;
}

textarea { min-height: 7.5em; resize: vertical; }
.lead { font-weight: 700; }
.price { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

::selection { background: #dbeafe; }

.add-row {
  display: block;
  margin: 0 1rem 2rem;
  background: #0891b2;
  color: white;
  padding: 8px 12px;
}

.sheets { display: none; }

@media screen and (max-width: 768px) {
  .controls .file-pick,
  .controls #file-name,
  .controls button,
  .controls .check { display: block; width: 100%; margin: 8px 0 0; }
  #file-name { max-width: none; margin-left: 0; }
  #pdf-button, #preview-button, .add-row { min-height: 46px; font-size: 1rem; }
  #list { padding: 8px; }
  .sheet {
    max-height: none;
    overflow: visible;
    background: transparent;
    box-shadow: none;
  }
  .order-head { display: none; }
  .order-row {
    min-width: 0;
    grid-template-columns: 1fr auto;
    row-gap: 8px;
    margin-top: 8px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: white;
  }
  .order-row .cell { grid-column: 1 / -1; }
  .order-row .cell:first-child { grid-column: 1; }
  .order-row .cell:last-child { grid-column: 2; grid-row: 1; }
  .order-row .cell::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    color: #1e3a5f;
    font-size: 0.75rem;
    font-weight: 700;
  }
  .order-row .cell:first-child::before,
  .order-row .cell:last-child::before { content: none; }
}

@page { margin: 15mm 12mm; }

@media print {
  body { background: white; }
  .screen, #preview-bar { display: none !important; }
  .sheets { display: block !important; position: static !important; left: auto !important; width: auto !important; background: white; padding: 0; }
  .print-only-page { width: auto !important; min-height: 250mm; margin: 0; padding: 0; box-shadow: none; }

  .print-only-page {
    display: flex;
    flex-direction: column;
    min-height: 250mm;
    break-after: page;
    page-break-after: always;
  }

  .print-only-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .print-page-body { flex: 1; }
}

.print-only-page { color: #000; }

.print-page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 10pt;
  margin-bottom: 10pt;
  border-bottom: 2px solid #000;
}

.print-page-kicker {
  font-size: 9pt;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #444;
}

.print-page-title {
  font-size: 22pt;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.print-meta-chip {
  font-size: 14pt;
  font-weight: bold;
}

.print-page-body {
  display: flex;
  flex-direction: column;
  gap: 10pt;
}

.print-field {
  border: 1px solid #000;
  border-radius: 10pt;
  padding: 10pt 11pt;
  background: white;
}

.print-field-label {
  font-size: 9pt;
  font-weight: 700;
  margin-bottom: 6pt;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #444;
}

.print-field-value {
  font-size: 14pt;
  line-height: 1.55;
  word-break: break-all;
}

.print-cut-guide .print-field-value { font-size: 18pt; }

.print-field-recipient {
  border-width: 2px;
  border-radius: 12pt;
  padding: 12pt 14pt;
}

.print-cut-guide {
  display: inline-block;
  width: 62%;
  max-width: 280pt;
  border: 1.5px dashed #000;
  border-radius: 8pt;
  padding: 10pt 12pt;
}

.print-recipient-name {
  margin-top: 10pt;
  padding-top: 8pt;
  border-top: 1px solid #000;
  font-size: 19pt;
  font-weight: 700;
}

.print-recipient-phone {
  margin-top: 4pt;
  font-size: 18pt;
}

.print-info-grid {
  display: grid;
  grid-template-columns: 1fr 0.9fr;
  gap: 10pt;
}

.print-field-product {
  border: 2.5px solid #000;
  border-radius: 12pt;
  padding: 12pt 14pt;
}

.print-field-value-product {
  font-size: 18pt;
  line-height: 1.6;
  font-weight: 700;
}

.print-field-value-price {
  font-size: 20pt;
  font-weight: 700;
}

.print-field-value-tracking { min-height: 58pt; }
.print-field-value-memo { min-height: 44pt; }

.print-page-footer {
  text-align: center;
  padding-top: 8pt;
  border-top: 1px solid #ccc;
  margin-top: auto;
}

.print-footer-current { font-size: 18pt; font-weight: bold; }
.print-footer-total { font-size: 12pt; color: #666; }
