/* ── Variables ── */
:root {
  --clr-primary: #3b82f6;
  --clr-primary-dark: #2563eb;
  --clr-primary-light: #eff6ff;
  --clr-success: #22c55e;
  --clr-danger: #ef4444;
  --clr-danger-light: #fef2f2;
  --clr-text: #1e293b;
  --clr-muted: #64748b;
  --clr-border: #e2e8f0;
  --clr-bg: #f1f5f9;
  --clr-card: #ffffff;
  --clr-header: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --transition: 180ms ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  color: var(--clr-text);
  background: var(--clr-bg);
  min-height: 100vh;
  line-height: 1.6;
}
img { display: block; max-width: 100%; }
button, select, input { font: inherit; }
a { color: var(--clr-primary); }

/* ── Header ── */
.app-header {
  background: var(--clr-header);
  border-bottom: 1px solid var(--clr-border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.app-title {
  font-size: 1.2rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.app-icon { font-size: 1.4rem; }
.connected-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .9rem;
  color: var(--clr-muted);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--clr-success);
  flex-shrink: 0;
}

/* ── Main ── */
.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

/* ── Views ── */
.view { display: none; }
.view.active { display: block; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 600;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), opacity var(--transition);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: var(--clr-primary);
  color: #fff;
  border-color: var(--clr-primary);
}
.btn-primary:hover:not(:disabled) { background: var(--clr-primary-dark); border-color: var(--clr-primary-dark); }

.btn-outline {
  background: transparent;
  color: var(--clr-primary);
  border-color: var(--clr-primary);
}
.btn-outline:hover:not(:disabled) { background: var(--clr-primary-light); }

.btn-danger {
  background: var(--clr-danger-light);
  color: var(--clr-danger);
  border-color: var(--clr-danger);
}
.btn-danger:hover:not(:disabled) { background: #fee2e2; }

.btn-link {
  background: none;
  border: none;
  color: var(--clr-primary);
  cursor: pointer;
  font-size: .85rem;
  padding: 0;
  text-decoration: underline;
}
.btn-link.btn-danger { color: var(--clr-danger); }

/* ── Drop Zone ── */
.drop-zone {
  border: 2.5px dashed var(--clr-border);
  border-radius: var(--radius);
  background: var(--clr-card);
  padding: 80px 40px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  outline: none;
}
.drop-zone:hover,
.drop-zone:focus,
.drop-zone.drag-over {
  border-color: var(--clr-primary);
  background: var(--clr-primary-light);
}
.drop-zone-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.upload-icon { width: 64px; height: 64px; color: var(--clr-muted); }
.drop-title { font-size: 1.25rem; font-weight: 600; }
.drop-sub { color: var(--clr-muted); font-size: .9rem; }
.drop-hint { font-size: .8rem; color: var(--clr-muted); margin-top: 4px; }

/* ── Processing ── */
.processing-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 80px 24px;
  text-align: center;
}
.processing-title { font-size: 1.1rem; font-weight: 600; color: var(--clr-muted); }

.spinner-ring {
  width: 56px;
  height: 56px;
  border: 4px solid var(--clr-border);
  border-top-color: var(--clr-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 480px;
  text-align: left;
}
.progress-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--clr-card);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: .9rem;
}
.progress-item .pi-icon { flex-shrink: 0; font-size: 1rem; }
.progress-item .pi-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-item .pi-status { font-size: .8rem; color: var(--clr-muted); }
.progress-item.done .pi-status { color: var(--clr-success); }
.progress-item.error .pi-status { color: var(--clr-danger); }

/* ── Confirm toolbar ── */
.confirm-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}
.confirm-title { font-size: 1.2rem; font-weight: 700; }
.confirm-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Receipt cards ── */
.receipt-cards { display: flex; flex-direction: column; gap: 20px; }

.receipt-card {
  background: var(--clr-card);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 220px 1fr;
  overflow: hidden;
}

@media (max-width: 700px) {
  .receipt-card { grid-template-columns: 1fr; }
}

.card-image-wrap {
  position: relative;
  background: #f8fafc;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
}
.card-image-overlay {
  position: absolute;
  inset: 0;
  background: rgba(239,68,68,.1);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 12px;
}
.ocr-error-badge {
  background: var(--clr-danger);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
}

/* ── Card form ── */
.card-form { padding: 24px; display: flex; flex-direction: column; gap: 16px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 500px) { .form-row { grid-template-columns: 1fr; } }

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--clr-muted); }

.input {
  border: 1.5px solid var(--clr-border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: .9rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: #fff;
  color: var(--clr-text);
  width: 100%;
}
.input:focus { outline: none; border-color: var(--clr-primary); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.input-sm { padding: 6px 10px; font-size: .85rem; }

/* ── Tax section ── */
.tax-section { display: flex; flex-direction: column; gap: 8px; }
.tax-section-label { font-size: .8rem; font-weight: 600; color: var(--clr-muted); }
.tax-rows { display: flex; flex-direction: column; gap: 6px; }

.tax-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.tax-row select.input { width: 130px; flex-shrink: 0; }
.tax-field {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tax-label { font-size: .8rem; color: var(--clr-muted); white-space: nowrap; }
.tax-field .input { width: 110px; }
.tax-unit { font-size: .85rem; color: var(--clr-muted); }

/* ── Total row ── */
.form-row-total { justify-content: flex-end; }
.form-group-total { max-width: 200px; }

/* ── Card footer ── */
.card-footer { display: flex; justify-content: flex-end; padding-top: 4px; }

/* ── Success view ── */
.success-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 80px 24px;
  text-align: center;
}
.success-wrap h2 { font-size: 1.5rem; }
.success-icon {
  width: 72px;
  height: 72px;
  background: #dcfce7;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--clr-success);
}
.success-icon svg { width: 40px; height: 40px; stroke-width: 2.5; }
.success-message { color: var(--clr-muted); font-size: .95rem; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}
.modal-box {
  background: var(--clr-card);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-box h3 { font-size: 1.15rem; font-weight: 700; }
.modal-desc { font-size: .9rem; color: var(--clr-muted); line-height: 1.7; }
.modal-desc code {
  background: #f1f5f9;
  border: 1px solid var(--clr-border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: .85rem;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--clr-text);
  color: #fff;
  font-size: .9rem;
  font-weight: 500;
  padding: 12px 24px;
  border-radius: 100px;
  box-shadow: var(--shadow);
  z-index: 300;
  transition: opacity 0.3s;
  white-space: nowrap;
}
.toast.error { background: var(--clr-danger); }
.toast.success { background: #16a34a; }

/* ── Utilities ── */
.hidden { display: none !important; }
