/* 領収書スプリッター - シンプル&落ち着き重視 */

:root {
  --fg: #222;
  --muted: #666;
  --line: #ddd;
  --bg: #fafafa;
  --card: #fff;
  --accent: #1976d2;
  --accent-hover: #135ba1;
  --danger: #c62828;
  --success: #2e7d32;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-size: 18px;
  font-weight: 600;
  color: var(--fg);
  text-decoration: none;
}

.site-header nav a {
  color: var(--muted);
  text-decoration: none;
  margin-left: 16px;
}

.site-header nav a:hover {
  color: var(--accent);
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 24px 0 40px;
}

h1 {
  font-size: 24px;
  margin: 0 0 16px;
}

h2 {
  font-size: 18px;
  margin: 0 0 8px;
}

.lead {
  color: var(--muted);
  margin-bottom: 24px;
}

/* --- Dropzone --- */

.dropzone-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 48px 24px;
  background: var(--card);
  border: 2px dashed var(--line);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone.dragging {
  border-color: var(--accent);
  background: #f2f8fd;
}

.dropzone.dragging {
  border-style: solid;
}

.dropzone-icon { font-size: 40px; }
.dropzone-text { font-size: 16px; font-weight: 500; }
.dropzone-sub { color: var(--muted); font-size: 13px; }
.dropzone input[type="file"] { display: none; }

/* --- Buttons / actions --- */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin: 24px 0 8px;
}

.primary, button.primary {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  border: none;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow);
}

.primary:hover, button.primary:hover {
  background: var(--accent-hover);
}

.secondary {
  display: inline-block;
  background: #fff;
  color: var(--fg);
  padding: 12px 20px;
  border-radius: 8px;
  border: 1px solid var(--line);
  text-decoration: none;
  font-size: 15px;
}

.link {
  color: var(--muted);
  text-decoration: underline;
  font-size: 14px;
}

.tip {
  margin-top: 16px;
  color: var(--muted);
  font-size: 14px;
}

/* --- Preview --- */

.overlay-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
  overflow: auto;
}

.overlay {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

/* --- Notices --- */

.notice {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 8px;
  padding: 12px 16px;
  margin: 16px 0;
  color: #6d4c00;
}

.error {
  background: #ffebee;
  border: 1px solid #ef9a9a;
  border-radius: 8px;
  padding: 12px 16px;
  margin: 16px 0;
  color: var(--danger);
  font-weight: 500;
}

/* --- Tips (guide page) --- */

.tips {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tips li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: var(--shadow);
}

/* --- Preview: OCR結果テーブル --- */

.table-wrap {
  overflow-x: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.preview-table th,
.preview-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.preview-table th {
  background: #f7f7f7;
  font-weight: 500;
  color: var(--muted);
}

.preview-table td.num,
.preview-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.preview-table tr:last-child td {
  border-bottom: none;
}

/* --- Editable table cells --- */

.preview-table.editable td {
  padding: 6px 10px;
}

.preview-table.editable input,
.preview-table.editable select {
  width: 100%;
  padding: 6px 8px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--fg);
  transition: background 0.1s, border-color 0.1s;
}

.preview-table.editable input:hover,
.preview-table.editable select:hover {
  background: #f5faff;
}

.preview-table.editable input:focus,
.preview-table.editable select:focus {
  outline: none;
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(25,118,210,0.15);
}

.preview-table.editable .amount-input {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.preview-table.editable td.cat-cell {
  display: flex;
  gap: 6px;
  align-items: center;
}

.preview-table.editable .category-free {
  min-width: 120px;
}

.learned-hint {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  padding: 0 2px;
  cursor: help;
}

.learned-reset-form {
  display: inline;
  margin: 0;
}

.learned-reset-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  cursor: pointer;
  line-height: 1;
}

.learned-reset-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.inline-form {
  display: inline-flex;
  gap: 6px;
  margin: 0;
  align-items: center;
}

.inline-form input[type="text"] {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  min-width: 140px;
}

.mini-btn.danger, .secondary.danger {
  color: var(--danger);
  border-color: #f2b8b8;
}

/* --- Raw OCR text (foldable) --- */

.raw-row td {
  padding: 0 12px 8px !important;
  background: transparent !important;
  border-bottom: 1px solid var(--line) !important;
}

.raw-details {
  background: #f7f7f7;
  border-radius: 6px;
  padding: 6px 12px;
}

.raw-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 0;
}

.raw-details summary:hover {
  color: var(--accent);
}

.raw-details pre {
  margin: 8px 0 4px;
  font-size: 12px;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
}

/* --- Duplicate row highlight --- */

.preview-table tr.dup-row td {
  background: #fff8e1;
}

.mini-btn.danger:hover, .secondary.danger:hover {
  background: #fff0f0;
  border-color: var(--danger);
}

/* --- View switcher (A/G) --- */

.view-switcher {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 12px 0 20px;
  font-size: 14px;
}

.view-switcher > span {
  color: var(--muted);
  margin-right: 8px;
}

.view-tab {
  padding: 6px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  transition: border-color 0.1s, background 0.1s;
}

.view-tab:hover {
  border-color: var(--accent);
  color: var(--fg);
}

.view-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* --- A モード: カード形式 (画像＋編集フォーム を横並び) --- */

.cards-wrap {
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin-top: 16px;
}

.card {
  display: grid;
  /* 番号 40px / 画像=残りぜんぶ / フォーム 280px固定 の3列
     minmax(0, 1fr) は grid track が画像の naturalWidth に潰されるのを防ぐ */
  grid-template-columns: 40px minmax(0, 1fr) 280px;
  gap: 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  box-shadow: var(--shadow);
  align-items: start;
}

.card.dup-card {
  background: #fff8e1;
  border-color: #ffe082;
}

.card-num {
  font-size: 24px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}

.card-image {
  width: 100%;
  /* ビューポート高の 80% まで＝画面いっぱいに近く。細部の目視確認が主目的 */
  max-height: 80vh;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: zoom-in;
  transition: box-shadow 0.1s;
}

.card-image:hover {
  box-shadow: 0 0 0 2px var(--accent);
}

.card-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-fields label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.card-fields input,
.card-fields select {
  padding: 8px 10px;
  font-size: 15px;
  font-family: inherit;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--fg);
  background: #fff;
}

.card-fields input:focus,
.card-fields select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(25,118,210,0.15);
}

@media (max-width: 900px) {
  .card {
    grid-template-columns: 1fr;
  }
  .card-num {
    text-align: left;
  }
  .card-image {
    max-height: 60vh;
  }
}

/* --- Focus-following sticky image (Gモード) --- */

.focus-image-wrap {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(250, 250, 250, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: 12px 0 8px;
  margin: 0 -24px 20px;
  padding-left: 24px;
  padding-right: 24px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.focus-images {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  max-height: 380px;
}

.focus-center {
  max-height: 380px;
  max-width: 60%;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: #fff;
  cursor: zoom-in;
  transition: box-shadow 0.1s;
}

.focus-center:hover {
  box-shadow: 0 0 0 3px var(--accent);
}

.focus-side {
  max-height: 300px;
  max-width: 24%;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}

.focus-side:hover {
  border-color: var(--accent);
  transform: scale(1.03);
}

.focus-caption {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.caption-hint {
  font-size: 11px;
  opacity: 0.7;
}

/* --- Receipt thumbnail + expand modal --- */

.receipt-thumb {
  display: block;
  width: 48px;
  height: 72px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: zoom-in;
  transition: transform 0.1s, border-color 0.1s;
  background: #eee;
}

.receipt-thumb:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
}

.modal-body {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  margin: 0;
  z-index: 1;
  text-align: center;
}

.modal-body img {
  max-width: 90vw;
  max-height: 82vh;
  border-radius: 6px;
  background: #000;
  cursor: zoom-out;
}

.modal-body figcaption {
  color: #fff;
  margin-top: 8px;
  font-size: 14px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.preview-table tr.suspect td {
  background: #fff8e1;
}

.mini-btn {
  background: #fff;
  color: var(--fg);
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  font-size: 12px;
  cursor: pointer;
}

.mini-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* --- Choose page: 分割案の選択 --- */

.choose-form { }

.choose-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.choose-card {
  display: block;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.1s, box-shadow 0.1s;
}

.choose-card:hover {
  border-color: #8bb3d9;
}

.choose-card.selected {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(25, 118, 210, 0.15);
}

.choose-card input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choose-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
  font-size: 13px;
}

.count-pill {
  background: var(--accent);
  color: #fff;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
  flex: none;
}

.candidate-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  background: #000;
}

/* --- Download form: 選択チェックボックス --- */

.download-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.checkopt {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.1s;
}

.checkopt:hover {
  border-color: var(--accent);
}

.checkopt input[type="checkbox"] {
  margin-top: 3px;
  transform: scale(1.2);
}

.checkopt span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.checkopt small {
  color: var(--muted);
  font-size: 12px;
}

.download-form .primary {
  align-self: flex-start;
}
