/* 請求書・伝票PDFのデータ化の画面。
   見た目の題材は、経理の机の上(紙の書類、帳簿の罫線、朱色の検印、蛍光ペン)。
   文字の大きさ・行の高さ・ボタンの高さは、実在の請求書読み取りサービス11件を測った範囲に合わせている
   (本文16px、行間1.5〜1.8、主ボタン44〜64px、表の行37〜40px、項目の行45px)。 */
:root {
  --ink: #1f2d3a;
  --muted: #5a6975;
  --line: #cfd8de;
  --paper: #ffffff;
  --desk: #eef2f4;        /* 机の色。書類(白)との差で、紙が置いてあるように見せる */
  --hanko: #c8321f;       /* 朱肉 */
  --hanko-pale: #fdeeeb;
  --seal-blue: #24507a;   /* 検算済の印 */
  --marker: #fff27a;      /* 蛍光ペン */
  --ok: #1f6f4a;
  --mincho: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font-family: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--seal-blue); outline-offset: 2px; }

.wrap { width: min(100% - 2rem, 72rem); margin-inline: auto; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- 冒頭:何をする道具か、何が対象外か ---------- */
.desk-head { padding: 2rem 0 1.25rem; }
.desk-head h1 { font-family: var(--mincho); font-weight: 800; font-size: 2.25rem; line-height: 1.3; letter-spacing: 0.06em; }
.lead { margin-top: 0.6rem; max-width: 44rem; font-size: 1.0625rem; }
.scope { margin-top: 0.4rem; max-width: 44rem; font-size: 0.875rem; color: var(--muted); }

main.wrap { padding-bottom: 3rem; }

.banner {
  display: inline-block;
  margin-bottom: 1.25rem;
  padding: 0.1rem 0.4rem;
  background: linear-gradient(transparent 45%, var(--marker) 45%);
  font-size: 0.875rem;
}
.banner-warn { background: var(--hanko-pale); padding: 0.5rem 0.8rem; }

h2 { font-family: var(--mincho); font-weight: 800; font-size: 1.5rem; line-height: 1.4; letter-spacing: 0.04em; }
h3 { font-size: 1rem; font-weight: 700; margin: 1.5rem 0 0.5rem; }

/* ---------- 受け取った書類の一覧 ---------- */
.tray { background: var(--paper); padding: 1.5rem; border-top: 0.3rem double var(--ink); }
.tray-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.25rem 1rem; }
.updated { font-size: 0.8125rem; color: var(--muted); }
.tray-note { margin-top: 0.3rem; font-size: 0.875rem; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 0.75rem; margin: 1.1rem 0 0.75rem; }
.search { flex: 1 1 16rem; }
.search input {
  width: 100%;
  height: 2.75rem;
  padding: 0 0.9rem;
  border: 1px solid var(--muted);
  border-radius: 0;
  background: #fff;
}
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
  height: 2.75rem;
  padding: 0 0.9rem;
  border: 1px solid var(--ink);
  background: #fff;
  cursor: pointer;
}
.chip-count { margin-left: 0.4rem; font-family: var(--mincho); font-weight: 800; }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; font-weight: 700; }

.list-head, .row {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1.6fr) minmax(0, 1fr) 6.5rem 7rem 6.5rem;
  gap: 0.75rem;
  align-items: center;
}
.list-head { padding: 0.4rem 0.6rem; border-bottom: 2px solid var(--ink); font-size: 0.75rem; color: var(--muted); }
.list-head span:nth-child(5) { text-align: right; }

.row-item { border-bottom: 1px solid var(--line); }
.row {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.4rem 0.6rem;
  border: 0;
  background: transparent;
  text-align: left;
  font-size: 0.875rem;
  cursor: pointer;
}
.row:hover { background: var(--desk); }
.row[aria-pressed="true"] { background: linear-gradient(transparent 12%, var(--marker) 12%, var(--marker) 88%, transparent 88%); }
.row-vendor { display: grid; min-width: 0; font-weight: 700; font-size: 0.9375rem; }
.row-vendor small { font-weight: 400; font-size: 0.75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-number, .row-date { overflow-wrap: anywhere; }
.row-total { text-align: right; font-weight: 700; white-space: nowrap; }
.row.is-unsupported .row-vendor, .row.is-unsupported .row-total { color: var(--muted); }
.row-note { white-space: nowrap; }
.fixed { margin-left: 0.4rem; padding: 0 0.3rem; border: 1px solid var(--seal-blue); color: var(--seal-blue); font-size: 0.75rem; }

/* 判定は、判子の形。言葉でも読める */
.status {
  justify-self: start;
  padding: 0.05rem 0.5rem;
  border: 1.5px solid currentColor;
  border-radius: 999px;
  font-family: var(--mincho);
  font-weight: 800;
  font-size: 0.8125rem;
  white-space: nowrap;
}
.status-ok { color: var(--seal-blue); }
.status-check { color: var(--hanko); }
.status-unsupported { color: var(--muted); border-style: dashed; }

.empty { padding: 1.25rem 0.6rem; color: var(--muted); }
.tray-total { margin-top: 0.75rem; font-size: 0.875rem; }

/* ---------- 選んだ書類:元の書類と、読み取った内容を並べる ---------- */
.detail { margin-top: 1.5rem; padding: 1.5rem; background: var(--paper); border-top: 0.3rem double var(--ink); scroll-margin-top: 0.5rem; }
.detail:focus { outline: none; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; min-height: 4.5rem; }
.detail-file { font-size: 0.8125rem; color: var(--muted); overflow-wrap: anywhere; }

.stamp {
  flex: none;
  display: grid;
  place-items: center;
  width: 4.75rem;
  height: 4.75rem;
  border: 3px solid currentColor;
  border-radius: 50%;
  outline: 1px solid currentColor;
  outline-offset: -7px;
  font-family: var(--mincho);
  font-weight: 800;
  font-size: 1rem;
  transform: rotate(-12deg);
}
.stamp-ok { color: var(--seal-blue); }
.stamp-check { color: var(--hanko); }
.stamp-unsupported { color: var(--muted); border-style: dashed; }
.stamp.is-in { animation: stamp 0.28s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes stamp { from { opacity: 0; transform: rotate(-12deg) scale(1.8); } to { opacity: 1; transform: rotate(-12deg) scale(1); } }

/* 読み取りの進み具合。どこまで進んで、どこで止まったか */
.stages { display: flex; flex-wrap: wrap; gap: 0.25rem 0; margin-top: 0.75rem; font-size: 0.8125rem; }
.stages li { display: flex; align-items: center; color: var(--muted); }
.stages li::before { content: ""; width: 0.6rem; height: 0.6rem; margin-right: 0.35rem; border-radius: 50%; border: 1.5px solid currentColor; }
.stages li + li { margin-left: 0.5rem; }
.stages li + li::before { margin-left: 0; }
.stages li:not(:last-child)::after { content: ""; width: 1.5rem; height: 1.5px; margin-left: 0.5rem; background: var(--line); }
.stages .is-done { color: var(--ink); }
.stages .is-done::before { background: var(--ink); border-color: var(--ink); }
.stages .is-stopped { color: var(--hanko); font-weight: 700; }
.stages .is-stopped::before { border-radius: 0; transform: rotate(45deg); background: var(--hanko); border-color: var(--hanko); }

.pair { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.5rem; margin-top: 1.25rem; }
.pair > * { min-width: 0; }

.paper { position: relative; border: 1px solid var(--line); box-shadow: 3px 4px 0 rgba(31, 45, 58, 0.12); background: #fff; }
.paper img { display: block; width: 100%; height: auto; }
.marks { position: absolute; inset: 0; }
.mark {
  position: absolute;
  border: 1.5px solid var(--seal-blue);
  background: rgba(36, 80, 122, 0.07);
  animation: mark-in 0.3s ease-out backwards;
}
@keyframes mark-in { from { opacity: 0; transform: scaleX(0.6); } to { opacity: 1; transform: none; } }
.paper.is-focusing .mark { opacity: 0.25; }
.paper.is-focusing .mark.is-on { opacity: 1; border-width: 2.5px; border-color: var(--hanko); background: rgba(255, 242, 122, 0.45); }
.original figcaption { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.25rem 1rem; margin-top: 0.5rem; font-size: 0.8125rem; color: var(--muted); }
.original a { color: var(--seal-blue); }

.read h3:first-child { margin-top: 0; }
.read-note { font-size: 0.8125rem; color: var(--muted); }

.fields { margin-top: 0.5rem; border-top: 2px solid var(--ink); }
.field {
  display: grid;
  grid-template-columns: 8.5rem minmax(0, 1fr);
  align-items: center;
  gap: 0 0.75rem;
  min-height: 2.8rem;
  padding: 0.2rem 0;
  border-bottom: 1px solid var(--line);
}
.field-label { font-size: 0.875rem; color: var(--muted); }
.field .missing { grid-column: 2; font-size: 0.75rem; color: var(--hanko); }
.field .missing.is-optional { color: var(--muted); }

.read input, .read select {
  width: 100%;
  height: 2.25rem;
  padding: 0 0.5rem;
  border: 1px solid transparent;
  border-bottom-color: var(--line);
  border-radius: 0;
  background: transparent;
  font-size: 0.9375rem;
}
.read input:hover, .read select:hover { border-color: var(--line); background: #fff; }
.read input:focus, .read select:focus { border-color: var(--seal-blue); background: #fff; outline: 2px solid var(--seal-blue); outline-offset: 0; }

.items { border-top: 2px solid var(--ink); }
.item {
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr) 5.5rem 5.5rem 6rem 4.5rem;
  gap: 0.3rem;
  align-items: center;
  min-height: 2.5rem;
  border-bottom: 1px solid var(--line);
}
.item-head { min-height: 1.9rem; font-size: 0.75rem; color: var(--muted); }
.item-head span:nth-child(n+3) { text-align: right; padding-right: 0.5rem; }
.item-qty { display: flex; align-items: center; }
.item-qty small { flex: none; margin-right: 0.3rem; font-size: 0.75rem; color: var(--muted); }
.item-qty input, .item-price input, .item-amount input { text-align: right; }

.sign { font-weight: 700; text-align: center; }
.sign-ok { color: var(--ok); }
.sign-ng { color: var(--hanko); }
.sign-na { color: var(--muted); }

.checks { border-top: 2px solid var(--ink); }
.checks li {
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr) auto;
  gap: 0.3rem 0.75rem;
  align-items: baseline;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9375rem;
}
.check-detail { font-size: 0.875rem; white-space: nowrap; }
.checks .is-ng { background: var(--hanko-pale); }
.checks .is-ng .check-detail { color: var(--hanko); font-weight: 700; }

.issues { margin-top: 1.5rem; padding: 0.9rem 1rem; border: 1px solid var(--line); }
.issues h3 { margin: 0 0 0.3rem; }
.issues li { padding-left: 1.1em; text-indent: -1.1em; font-size: 0.9375rem; }
.issues li::before { content: "・"; }
.issues .is-none { color: var(--muted); }
.issues.has-issues { border: 2px solid var(--hanko); }
.issues.has-issues h3 { color: var(--hanko); }

.edited { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin-top: 1rem; font-size: 0.875rem; }

.unsupported { padding: 1.25rem; border: 2px dashed var(--muted); }
.unsupported h3 { margin: 0 0 0.75rem; font-size: 1.125rem; }
.unsupported dl div { padding: 0.6rem 0; border-top: 1px solid var(--line); }
.unsupported dt { font-size: 0.8125rem; color: var(--muted); }

/* ---------- ボタン ---------- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: 0 1.5rem;
  border: 0;
  border-radius: 2px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
.button:hover { background: #111b24; }
.button-plain {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 1rem;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: #fff;
  color: var(--ink);
  font-size: 0.9375rem;
  text-decoration: none;
  cursor: pointer;
}
.button-plain:hover { background: var(--desk); }

/* ---------- CSV ---------- */
.export { margin-top: 1.5rem; padding: 1.5rem; background: var(--paper); border-top: 0.3rem double var(--ink); }
.export-note { margin-top: 0.3rem; font-size: 0.875rem; color: var(--muted); }
.export-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 1rem 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); }
.preview { border-collapse: collapse; font-size: 0.8125rem; white-space: nowrap; }
.preview th, .preview td { height: 2.3rem; padding: 0 0.7rem; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; }
.preview th { background: var(--desk); font-weight: 700; }
.preview tr:last-child td { border-bottom: 0; }

.site-footer { padding: 1.5rem 0 2rem; font-size: 0.8125rem; color: var(--muted); }

/* ---------- 広い画面:元の書類を左、読み取った内容を右 ---------- */
@media (min-width: 60rem) {
  .pair { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; }
  .original { position: sticky; top: 1rem; }
}

/* ---------- 狭い画面 ---------- */
@media (max-width: 48rem) {
  .desk-head { padding: 1.5rem 0 1rem; }
  .desk-head h1 { font-size: 1.75rem; }
  h2 { font-size: 1.3125rem; }
  .tray, .detail, .export { padding: 1.1rem 0.9rem; }
  .list-head { display: none; }
  .rows { border-top: 2px solid var(--ink); }
  .row {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "status vendor total" "number number note";
    gap: 0.2rem 0.6rem;
    padding: 0.6rem 0.4rem;
  }
  .row .status { grid-area: status; }
  .row-vendor { grid-area: vendor; }
  .row-total { grid-area: total; }
  .row-number { grid-area: number; font-size: 0.75rem; color: var(--muted); }
  .row-date { display: none; }
  .row-note { grid-area: note; justify-self: end; font-size: 0.75rem; }
  .row-note::before { content: "確認事項 "; color: var(--muted); }
  .stages li:not(:last-child)::after { width: 0.6rem; margin-left: 0.3rem; }
  .stages li + li { margin-left: 0.3rem; }
  .field { grid-template-columns: 6.5rem minmax(0, 1fr); }
  /* 明細は2段にする:上に品名と金額、下に数量・単価・税率 */
  .item-head { display: none; }
  .item {
    grid-template-columns: 1.5rem minmax(0, 1fr) minmax(0, 1fr) 4.5rem;
    grid-template-areas: "sign name name amount" ". qty price rate";
    padding: 0.35rem 0;
  }
  .item .sign { grid-area: sign; }
  .item-name { grid-area: name; }
  .item-amount { grid-area: amount; }
  .item-qty { grid-area: qty; }
  .item-price { grid-area: price; }
  .item-rate { grid-area: rate; }
  .item-qty::before { content: "数量"; flex: none; margin-right: 0.2rem; font-size: 0.75rem; color: var(--muted); }
  .item-price { display: flex; align-items: center; }
  .item-price::before { content: "単価"; flex: none; margin-right: 0.2rem; font-size: 0.75rem; color: var(--muted); }
  .checks li { grid-template-columns: 1.5rem minmax(0, 1fr); }
  .check-detail { grid-column: 2; white-space: normal; }
  .export-actions > * { flex: 1 1 100%; }
  .button { min-height: 3.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  .stamp.is-in, .mark { animation: none; }
}

/* スマートフォンでは、押す部品・入力欄の高さを44px以上にそろえる */
@media (max-width: 48rem) {
  button, select, a.button,
  input:not([type="radio"]):not([type="checkbox"]):not([type="hidden"]) { min-height: 2.75rem; }
}
