:root {
  --bg: #FAFAF7;
  --bg-elevated: #FFFFFF;
  --ink: #0F172A;
  --ink-muted: #475569;
  --ink-subtle: #94A3B8;
  --line: #E5E2DA;
  --line-strong: #CFCABC;
  --accent: #E85D3A;
  --accent-ink: #B4431F;
  --accent-soft: #FBE9E1;
  --success: #0F7A4A;
  --success-soft: #E3F3EC;
  --danger: #B42318;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --font-sans: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "游ゴシック", system-ui, sans-serif;
  --font-display: "Space Grotesk", "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Header */
.app-header {
  border-bottom: 1px solid var(--line);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 16px;
  padding-bottom: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--ink);
  color: #FAFAF7;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.02em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-weight: 700; font-size: 15px; color: var(--ink); }
.brand-sub { font-size: 11px; color: var(--ink-subtle); letter-spacing: 0.08em; text-transform: uppercase; font-family: var(--font-display); }
.help-link {
  font-size: 14px;
  color: var(--ink-muted);
  text-decoration: none;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 8px;
  transition: background 120ms ease;
}
.help-link:hover { background: var(--bg); color: var(--ink); }

/* Main */
.app-main { flex: 1; padding: 48px 0 180px; }

/* Step */
.step { margin-bottom: 48px; animation: fadeIn 240ms ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.hidden { display: none !important; }

.step-head { margin-bottom: 24px; }
.step-index {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}
.step-title {
  font-family: var(--font-sans);
  font-size: 32px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
  color: var(--ink);
}
.step-desc {
  font-size: 15px;
  color: var(--ink-muted);
  margin: 0;
  line-height: 1.65;
}

/* Upload actions (camera + library buttons) */
.upload-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.upload-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
  text-align: left;
  user-select: none;
}
.upload-btn:active { transform: scale(0.995); }
.upload-btn svg { flex-shrink: 0; }
.upload-btn-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.upload-btn-text strong { font-size: 16px; font-weight: 700; line-height: 1.3; }
.upload-btn-text span { font-size: 12px; line-height: 1.4; }
.upload-btn-primary {
  background: var(--ink);
  color: #FAFAF7;
  border: 1px solid var(--ink);
  box-shadow: var(--shadow-sm);
}
.upload-btn-primary:hover { background: #1E293B; }
.upload-btn-primary .upload-btn-text span { color: rgba(250, 250, 247, 0.7); }
.upload-btn-secondary {
  background: var(--bg-elevated);
  color: var(--ink);
  border: 1px solid var(--line-strong);
}
.upload-btn-secondary:hover { border-color: var(--accent); }
.upload-btn-secondary .upload-btn-text span { color: var(--ink-muted); }

.dropzone-hint {
  margin-top: 16px;
  font-size: 12px;
  color: var(--ink-subtle);
  text-align: center;
}

/* Invisible overlay for drag & drop */
.dropzone-drop {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: var(--radius-lg);
  transition: background 160ms ease, outline 160ms ease;
}
.dropzone-drop.dragover {
  pointer-events: auto;
  background: rgba(232, 93, 58, 0.08);
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

/* Preview */
.preview-wrap {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.preview-wrap img { width: 100%; display: block; max-height: 360px; object-fit: contain; background: #F5F2EC; }
.preview-retake {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.88);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  backdrop-filter: blur(4px);
}
.preview-retake:hover { background: rgba(15, 23, 42, 1); }

/* OCR Status */
.ocr-status {
  margin-top: 16px;
  padding: 16px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--ink-muted);
}
.ocr-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Form */
.entry-form { display: flex; flex-direction: column; gap: 32px; }
.field-group { border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 24px; margin: 0; background: var(--bg-elevated); box-shadow: var(--shadow-sm); }
.field-group-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0 8px;
  margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.field-row .field { margin-bottom: 0; }
@media (max-width: 480px) { .field-row { grid-template-columns: 1fr; } }

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}
.field .req {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}
.field input,
.field select,
.field textarea {
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 12px 14px;
  width: 100%;
  line-height: 1.5;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
  -webkit-appearance: none;
  appearance: none;
}
.field select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 40px; }
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 0;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(232, 93, 58, 0.16);
}
.field textarea { resize: vertical; min-height: 84px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 14px 20px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
  text-decoration: none;
  line-height: 1.2;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--ink);
  color: #FAFAF7;
}
.btn-primary:hover:not(:disabled) { background: #1E293B; }
.btn-primary .btn-arrow { transition: transform 160ms ease; }
.btn-primary:hover:not(:disabled) .btn-arrow { transform: translateX(2px); }

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
  border-color: var(--line-strong);
}
.btn-ghost:hover:not(:disabled) { color: var(--ink); border-color: var(--ink); background: var(--bg-elevated); }

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-top: 8px;
}
.form-actions .btn-primary { flex: 1; max-width: 280px; }

/* Done */
.done-card {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 48px 32px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.done-check {
  width: 72px;
  height: 72px;
  margin: 0 auto 24px;
  color: var(--success);
}
.done-check svg { width: 100%; height: 100%; }
.done-check circle { stroke: var(--success); stroke-width: 2; }
.done-check path { stroke: var(--success); stroke-width: 3; }
.done-title { font-size: 28px; font-weight: 700; margin: 0 0 8px; letter-spacing: -0.01em; }
.done-desc { font-size: 15px; color: var(--ink-muted); margin: 0 0 32px; }
.done-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.done-actions .btn { min-width: 140px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #FAFAF7;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: var(--shadow-md);
  z-index: 100;
  max-width: calc(100vw - 48px);
  animation: toastIn 220ms ease;
}
.toast.toast-error { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Batch list */
.batch { margin-top: 24px; }
.batch-head { margin-bottom: 24px; animation: fadeIn 240ms ease; }
.batch-title {
  font-family: var(--font-sans);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
  color: var(--ink);
}
#cards-container { display: flex; flex-direction: column; gap: 16px; }

.card-item {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: border-color 160ms ease, opacity 200ms ease;
  animation: fadeIn 240ms ease;
}
.card-item[data-status="submitted"] { opacity: 0.75; border-color: #CDEBD9; background: #F4FBF7; }
.card-item[data-status="failed"] { border-color: #F6C9C2; }
.card-item[data-status="pending_ocr"] { border-color: var(--line-strong); }

.card-item-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.card-thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
  border: 1px solid var(--line);
}
.card-head-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}
.card-badge {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
  align-self: flex-start;
  letter-spacing: 0.06em;
}
.card-head-company {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.card-head-name {
  font-size: 12px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}
.card-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.card-status-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.card-status-pill:empty { display: none; }
.pill-busy { background: #EFF4F9; color: #3F5875; }
.pill-busy::before {
  content: "";
  width: 10px;
  height: 10px;
  border: 1.5px solid #B8C6D7;
  border-top-color: #3F5875;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
.pill-ready { background: #E8EDE4; color: #4D5A43; }
.pill-warn { background: #FDF2E2; color: #8A5D0B; }
.pill-success { background: var(--success-soft); color: var(--success); }
.pill-error { background: #FCE6E3; color: var(--danger); }

.card-remove {
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.card-remove:hover { background: #FCE6E3; border-color: var(--danger); color: var(--danger); }
.card-remove:disabled { opacity: 0.35; cursor: not-allowed; }

.card-item-body { padding: 16px; }
.card-item[data-status="submitted"] .card-item-body { display: none; }
.card-form .field-group { box-shadow: none; border-radius: 10px; padding: 16px; margin-bottom: 12px; }
.card-form .field-group:last-child { margin-bottom: 0; }
.card-form .field-group-title { margin-bottom: 12px; font-size: 11px; }
.card-form .field { margin-bottom: 12px; }
.card-form .field-row { margin-bottom: 12px; gap: 12px; }

/* Batch bar */
.batch-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 12px 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  animation: slideUp 240ms ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.batch-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.batch-bar-info {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  min-width: 0;
}
.batch-bar-count {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
}
.batch-bar-status {
  font-size: 12px;
  color: var(--ink-muted);
}
.batch-bar .btn-primary { padding: 14px 22px; white-space: nowrap; }

/* Done list */
.done-list {
  list-style: none;
  padding: 0;
  margin: 0 0 32px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  max-height: 320px;
  overflow-y: auto;
}
.done-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 10px;
  font-size: 14px;
  border: 1px solid var(--line);
}
.done-list li.fail {
  background: #FDF0EE;
  border-color: #F6C9C2;
  color: var(--danger);
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.done-list li a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.done-list li a:hover { text-decoration: underline; }
.done-tick {
  font-size: 11px;
  font-weight: 700;
  color: var(--success);
  background: var(--success-soft);
  padding: 2px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Footer */
.app-footer {
  border-top: 1px solid var(--line);
  padding: 24px 0;
  font-size: 12px;
  color: var(--ink-subtle);
  text-align: center;
}
.footer-sep { margin: 0 8px; }

@media (max-width: 480px) {
  .app-main { padding: 32px 0 160px; }
  .step-title { font-size: 26px; }
  .batch-title { font-size: 22px; }
  .done-card { padding: 32px 24px; }
  .done-title { font-size: 22px; }
  .form-actions .btn-primary { max-width: none; }
  .card-item-head { padding: 10px 12px; gap: 10px; }
  .card-thumb { width: 48px; height: 48px; }
  .card-status-pill { font-size: 10px; padding: 3px 8px; }
  .card-item-body { padding: 12px; }
  .batch-bar .btn-primary { padding: 12px 16px; font-size: 14px; }
  .batch-bar .btn-arrow { display: none; }
  .batch-bar-count { font-size: 18px; }
  .upload-btn { padding: 16px; }
  .upload-btn-text strong { font-size: 15px; }
  .upload-btn-text span { font-size: 11px; }
}
