/* ── Reset & Variables ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f1ec;
  --bg-card: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6b6560;
  --accent: #c44520;
  --accent-light: #f0d8cf;
  --accent-hover: #a83a1a;
  --border: #d9d4cd;
  --border-light: #e8e4de;
  --success: #2d7a4f;
  --success-light: #d4eddf;
  --warn: #b8860b;
  --warn-light: #fef3cd;
  --font-body: 'Noto Sans TC', 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;
  --radius: 8px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --transition: 0.2s ease;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ────────────────────────────────────────────────────────── */
.site-header {
  background: var(--text);
  color: #fff;
  padding: 0 2rem;
  border-bottom: 4px solid var(--accent);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
}
.logo { display: flex; align-items: center; gap: 0.75rem; }
.logo-icon { font-size: 2rem; line-height: 1; }
.logo h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { font-size: 0.8rem; color: #aaa; font-weight: 300; margin-top: 0.1rem; }
.brand-tag {
  font-size: 0.75rem; font-weight: 500; color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.12em;
  border: 1px solid var(--accent); padding: 0.25rem 0.75rem; border-radius: 3px;
}

/* ── Stepper ───────────────────────────────────────────────────────── */
.stepper-container {
  max-width: 600px;
  margin: 1.75rem auto 0;
  padding: 0 2rem;
}
.stepper {
  display: flex;
  align-items: center;
  gap: 0;
}
.step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  font-size: 0.8rem; font-weight: 700;
  background: var(--border-light); color: var(--text-muted);
  transition: all var(--transition);
}
.step-label {
  font-size: 0.82rem; color: var(--text-muted); font-weight: 500;
  transition: color var(--transition);
}
.step.active .step-num { background: var(--accent); color: #fff; }
.step.active .step-label { color: var(--text); }
.step.current .step-num { box-shadow: 0 0 0 3px var(--accent-light); }
.step-line {
  flex: 1; height: 2px; background: var(--border-light); margin: 0 0.5rem;
}

/* ── Container ─────────────────────────────────────────────────────── */
.container {
  max-width: 1100px;
  margin: 1.5rem auto 2rem;
  padding: 0 2rem;
  flex: 1;
}

/* ── Cards ─────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  animation: fadeIn 0.3s ease-out;
}
.card-error { border-color: var(--accent); background: #fdf5f3; }

/* ── Drop Zone ─────────────────────────────────────────────────────── */
.upload-card { padding: 0; overflow: hidden; }
.drop-zone {
  padding: 3.5rem 2rem; text-align: center; cursor: pointer;
  transition: background var(--transition);
  position: relative;
}
.drop-zone::before {
  content: ''; position: absolute; inset: 8px;
  border: 2px dashed var(--border); border-radius: 6px;
  pointer-events: none; transition: border-color var(--transition);
}
.drop-zone:hover, .drop-zone.drag-over { background: var(--accent-light); }
.drop-zone:hover::before, .drop-zone.drag-over::before { border-color: var(--accent); }
.drop-icon {
  color: var(--text-muted); margin-bottom: 1rem;
  transition: color var(--transition), transform var(--transition);
}
.drop-zone:hover .drop-icon { color: var(--accent); transform: translateY(-4px); }
.drop-text { font-size: 1.2rem; font-weight: 500; margin-bottom: 0.35rem; }
.drop-hint { font-size: 0.85rem; color: var(--text-muted); }

.upload-progress-wrap { padding: 1rem 2rem; background: #fafaf8; }

/* ── Review Section ────────────────────────────────────────────────── */
.section-title { font-size: 1.05rem; font-weight: 600; margin-bottom: 1rem; }

.file-info-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 0.75rem 2rem;
}
.info-item { display: flex; flex-direction: column; gap: 0.15rem; }
.info-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.info-value { font-size: 0.95rem; font-weight: 500; }
.info-value.mono { font-family: var(--font-mono); font-size: 0.88rem; }

.divider { height: 1px; background: var(--border-light); margin: 1.5rem 0; }

.settings-grid { margin-bottom: 1.25rem; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  cursor: pointer;
}
.setting-label { font-size: 0.9rem; font-weight: 500; }
.setting-hint { font-size: 0.78rem; color: var(--text-muted); display: block; margin-top: 0.1rem; }
.setting-select {
  font-family: var(--font-body); font-size: 0.85rem;
  padding: 0.4rem 0.7rem; border: 1px solid var(--border);
  border-radius: 5px; background: #fff; color: var(--text); min-width: 220px;
}

.ocr-info-box {
  background: #f0f4f8; border: 1px solid #c8d6e5; border-radius: 6px;
  padding: 1rem 1.25rem; margin-bottom: 1.5rem;
  font-size: 0.85rem; line-height: 1.6;
}
.ocr-info-box strong { display: block; margin-bottom: 0.3rem; }
.ocr-info-box p { color: var(--text-muted); margin: 0; }

.review-actions {
  display: flex; justify-content: space-between; align-items: center;
}

/* ── Progress ──────────────────────────────────────────────────────── */
.progress-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; }
.progress-header h2 { font-size: 1.15rem; }
.filename-badge {
  font-family: var(--font-mono); font-size: 0.78rem;
  background: var(--border-light); padding: 0.2rem 0.6rem; border-radius: 4px; color: var(--text-muted);
}
.progress-bar-container {
  width: 100%; height: 10px; background: var(--border-light); border-radius: 6px; overflow: hidden;
}
.progress-bar {
  height: 100%; background: var(--accent); border-radius: 6px; transition: width 0.4s ease-out;
}
.progress-text {
  font-size: 0.85rem; color: var(--text-muted); margin-top: 0.75rem;
  font-family: var(--font-mono);
}
.progress-phase {
  font-size: 0.82rem; color: var(--text); margin-top: 0.3rem; font-weight: 500;
}

/* ── Results ───────────────────────────────────────────────────────── */
.results-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem;
}
.results-header h2 { font-size: 1.15rem; }
.results-actions { display: flex; gap: 0.5rem; }
.results-summary { display: flex; gap: 1.25rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.stat-pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.82rem; padding: 0.35rem 0.8rem;
  background: var(--border-light); border-radius: 20px;
  color: var(--text-muted); font-weight: 500;
}
.stat-pill .val { color: var(--text); font-family: var(--font-mono); }

/* ── Table ─────────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border: 1px solid var(--border); border-radius: 6px; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
thead { background: #f8f6f3; border-bottom: 2px solid var(--border); }
th {
  text-align: left; padding: 0.65rem 0.85rem;
  font-weight: 600; font-size: 0.78rem;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); white-space: nowrap;
}
td { padding: 0.6rem 0.85rem; border-top: 1px solid var(--border-light); vertical-align: middle; }
tbody tr:hover { background: #fafaf8; }
td.thumb-cell img {
  width: 120px; height: auto; border-radius: 4px;
  border: 1px solid var(--border-light); display: block;
}

.type-tag {
  display: inline-block; font-size: 0.78rem; font-weight: 500;
  padding: 0.15rem 0.55rem; border-radius: 4px; white-space: nowrap;
}
.type-tag.繳費通知單 { background: #fce8b2; color: #7c5e00; }
.type-tag.收執聯     { background: #d4eddf; color: #1a5c32; }
.type-tag.存查聯     { background: #d6e4f0; color: #1a3e5c; }
.type-tag.default    { background: var(--border-light); color: var(--text-muted); }

/* ── Confidence Badges ─────────────────────────────────────────────── */
.conf-badge {
  display: inline-block; font-family: var(--font-mono); font-size: 0.75rem;
  font-weight: 600; padding: 0.12rem 0.45rem; border-radius: 4px;
}
.conf-high { background: var(--success-light); color: var(--success); }
.conf-mid  { background: var(--warn-light); color: var(--warn); }
.conf-low  { background: #fde8e8; color: #b91c1c; }

.name-cell { font-weight: 500; }
.name-cell.undetected { color: var(--text-muted); font-weight: 400; font-style: italic; }

.dl-links { display: flex; gap: 0.5rem; }
.dl-links a {
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-size: 0.78rem; font-family: var(--font-mono);
  padding: 0.2rem 0.5rem; border: 1px solid var(--border); border-radius: 4px;
  text-decoration: none; color: var(--text); transition: all var(--transition);
}
.dl-links a:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

/* ── OCR Debug Panel ───────────────────────────────────────────────── */
.ocr-debug-toggle {
  margin-top: 1.5rem; border: 1px solid var(--border); border-radius: 6px;
  overflow: hidden;
}
.ocr-debug-toggle summary {
  padding: 0.75rem 1rem; cursor: pointer;
  font-size: 0.88rem; font-weight: 500;
  background: #f8f6f3; user-select: none;
}
.ocr-debug-toggle summary:hover { background: var(--border-light); }
.ocr-debug-content { padding: 1rem; }
.debug-card {
  margin-bottom: 1rem; border: 1px solid var(--border-light);
  border-radius: 5px; overflow: hidden;
}
.debug-title {
  font-size: 0.8rem; font-weight: 600; padding: 0.4rem 0.75rem;
  background: #f8f6f3; border-bottom: 1px solid var(--border-light);
  font-family: var(--font-mono);
}
.debug-table { width: 100%; font-size: 0.78rem; border-collapse: collapse; }
.debug-table th, .debug-table td {
  padding: 0.35rem 0.6rem; text-align: left; border: 1px solid var(--border-light);
}
.debug-table th {
  background: #fafaf8; font-weight: 600; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.04em;
}

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-family: var(--font-body); font-size: 0.9rem; font-weight: 500;
  padding: 0.55rem 1.25rem; border: none; border-radius: 6px;
  cursor: pointer; transition: all var(--transition);
}
.btn-lg { padding: 0.7rem 1.75rem; font-size: 1rem; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border-light); }

/* ── Footer ────────────────────────────────────────────────────────── */
.site-footer {
  text-align: center; padding: 1.5rem; font-size: 0.78rem;
  color: var(--text-muted); border-top: 1px solid var(--border); margin-top: 2rem;
}

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .header-inner { flex-direction: column; gap: 0.75rem; text-align: center; }
  .results-header { flex-direction: column; align-items: flex-start; }
  .container { padding: 0 1rem; margin: 1rem auto; }
  .card { padding: 1.25rem; }
  .drop-zone { padding: 2.5rem 1.25rem; }
  td.thumb-cell img { width: 80px; }
  .file-info-grid { grid-template-columns: 1fr; }
  .review-actions { flex-direction: column; gap: 0.75rem; }
  .setting-row { flex-direction: column; align-items: flex-start; }
  .setting-select { min-width: 100%; }
  .stepper-container { padding: 0 1rem; }
  .step-label { font-size: 0.72rem; }
}

/* ── Animations ────────────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
.processing .progress-header h2 { animation: pulse 1.5s ease-in-out infinite; }
