:root {
  --bg1:#eff6ff; --bg2:#e0e7ff; --card:#fff; --text:#1f2937; --muted:#6b7280;
  --brand:#6366f1; --border:#d1d5db; --ok:#059669; --err:#ef4444;
  --shadow:0 10px 25px rgba(0,0,0,.1);
}

* { margin:0; padding:0; box-sizing:border-box; }
html:focus-within { scroll-behavior:smooth; }
@media (prefers-reduced-motion: reduce) {
  html:focus-within { scroll-behavior:auto; }
  * { animation:none !important; transition:none !important; }
}

body {
  min-height:100vh;
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;
  background:linear-gradient(135deg,var(--bg1) 0%,var(--bg2) 100%);
  padding:20px; color:var(--text);
}
.centered { display:flex; align-items:center; justify-content:center; }

.container { max-width:1200px; margin:0 auto; }
.header { text-align:center; margin-bottom:40px; }
.header h1 { font-size:2.5rem; margin-bottom:10px; }
.muted { color:var(--muted); }
.small { font-size:0.9rem; }

.card {
  background:var(--card); border-radius:16px; box-shadow:var(--shadow); padding:28px; margin-bottom:20px;
}
.card--narrow { width:100%; max-width:520px; }

.section-title { font-size:1.25rem; margin-bottom:20px; }
.section-subtitle { font-size:1.05rem; margin-bottom:16px; }

.btn {
  background:var(--brand); color:#fff; border:none; padding:10px 16px; border-radius:10px;
  font-weight:600; cursor:pointer; transition:.2s ease; display:inline-flex; align-items:center; gap:8px;
}
.btn:hover { filter:brightness(1.05); }
.btn:disabled { background:#9ca3af; cursor:not-allowed; }
.btn--outline { background:transparent; color:var(--brand); border:1px solid var(--brand); }
.btn--outline:hover { background:var(--brand); color:#fff; }
.btn--block { width:100%; }
.btn--success { background:var(--ok) !important; border-color:var(--ok) !important; }

.err { color:var(--err); margin-top:10px; text-align:center; min-height:20px; }
.hint { font-size:.9rem; color:var(--muted); margin-top:12px; text-align:center; }
.footer { margin-top:18px; text-align:center; color:#9ca3af; font-size:.9rem; }

/* ===== Login form alignment ===== */
.form { display: grid; gap: 12px; }
.label { font-size: 0.95rem; color: var(--text); }
.field { position: relative; width: 100%; }
.input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 1rem;
  outline: none;
  background: #fff;
}
.field--with-addon .input { padding-right: 86px; }
.input-addon {
  position: absolute;
  right: 6px; top: 50%; transform: translateY(-50%);
  background: transparent; color: var(--brand);
  border: 1px solid var(--brand); padding: 6px 10px; border-radius: 8px;
  font-weight: 600; cursor: pointer;
}
.input-addon:hover { background: var(--brand); color: #fff; }

/* ===== Upload / App styles ===== */
.upload-area {
  border:2px dashed #d1d5db; border-radius:12px; padding:40px; text-align:center;
  cursor:pointer; transition:all .2s ease; background: #fff;
}
.upload-area:hover { border-color:var(--brand); background-color:#f8fafc; }
.upload-area.dragover { border-color:var(--brand); background-color:#eef2ff; outline:none; }
.upload-area:focus { box-shadow:0 0 0 4px rgba(99,102,241,.25); }
.upload-icon { width:48px; height:48px; margin:0 auto 16px; opacity:.4; }
.upload-title { font-size:18px; margin-bottom:8px; color:#4b5563; }
.upload-subtitle { font-size:14px; color:#9ca3af; }
.file-input { display:none; }

.file-info {
  background:#f9fafb; padding:16px; border-radius:8px; display:flex; justify-content:space-between; align-items:center; margin-top:16px;
}
.file-details { display:flex; align-items:center; gap:8px; }
.file-actions { display:flex; gap:8px; }

.content-area {
  display:grid; grid-template-columns:1fr 1fr; gap:20px; margin-top:20px;
}
.image-preview-area {
  background:#f9fafb; border:2px dashed #d1d5db; border-radius:12px; padding:20px;
  display:flex; flex-direction:column; align-items:center; justify-content:center; min-height:400px;
}
.image-preview {
  max-width:100%; max-height:500px; object-fit:contain; border-radius:8px; box-shadow:0 4px 6px rgba(0,0,0,.1);
}
.image-info { margin-top:12px; text-align:center; color:#6b7280; font-size:14px; }

.results-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; }
.results-text {
  background:#f9fafb; border-radius:8px; padding:20px; min-height:350px; font-family:'Courier New',monospace; font-size:14px; line-height:1.6;
  color:#374151; white-space:pre-wrap; border:1px solid #e5e7eb; overflow-y:auto;
}
.text-error { color:var(--err); }

.loading { display:flex; align-items:center; gap:12px; padding:16px; color:#6b7280; }
.spinner {
  width:28px; height:28px; border:3px solid #e5e7eb; border-top:3px solid var(--brand); border-radius:50%;
  animation:spin 1s linear infinite;
}
@keyframes spin { 0%{transform:rotate(0)} 100%{transform:rotate(360deg)} }

.model-meta { margin-top:10px; }

.new-upload-btn { margin-top:20px; display:flex; justify-content:center; }

.noscript {
  max-width:720px; margin:20px auto; background:#fff5f5; border:1px solid #fecaca; color:#7f1d1d; padding:12px 16px; border-radius:8px;
}

.hidden { display:none !important; }

/* Responsive */
@media (max-width: 768px) {
  .content-area { grid-template-columns:1fr; gap:16px; }
  body { padding:10px; }
  .card { padding:20px; }
}
/* === Polished pill tabs for OCR mode === */
.mode {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  background: rgba(99,102,241,.10);
  border: 1px solid #c7d2fe;
  border-radius: 12px;
  overflow: hidden;            /* 讓指示條圓角貼齊 */
  box-shadow: 0 6px 16px rgba(17,24,39,.06);
  backdrop-filter: saturate(140%) blur(6px);
  isolation: isolate;          /* 提升混合效果 */
  min-width: 310px;
}

.mode__indicator {
  position: absolute;
  z-index: 0;
  top: 0; left: 0;
  width: 50%; height: 100%;    /* 永遠覆蓋一半 */
  background: linear-gradient(135deg,#6366f1,#8b5cf6);
  box-shadow: 0 10px 24px rgba(99,102,241,.35), inset 0 0 0 1px rgba(255,255,255,.28);
  border-radius: inherit;
  transform: translateX(0%);
  transition: transform .28s cubic-bezier(.22,.61,.36,1);
}
.mode.is-json .mode__indicator {
  transform: translateX(100%);
}

.mode__btn {
  position: relative;
  z-index: 1;
  appearance: none;
  border: 0;
  background: transparent;
  padding: 12px 14px;
  font-weight: 700;
  letter-spacing: .1px;
  color: #4338ca;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  transition: transform .18s ease, color .18s ease;
}
.mode__btn:hover { transform: translateY(-1px); }
.mode__btn.is-active { color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,.06); }
.mode__btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(99,102,241,.38);
  border-radius: 8px;
}

.mode__icon { font-size: 1.05rem; opacity: .95; }

/* 小尺寸時自動收斂間距 */
@media (max-width: 430px) {
  .mode { min-width: 0; }
  .mode__btn { padding: 10px 10px; font-size: .95rem; }
}


/* ==== PDF preview ==== */
.pdf-preview {
  width: 100%;
  height: 500px;
  border: none;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0,0,0,.1);
}
@media (max-width: 768px) {
  .pdf-preview { height: 420px; }
}

/* ==== Batch list ==== */
.batch-list { margin-top: 12px; display: grid; gap: 8px; }
.batch-item { display: flex; justify-content: space-between; gap: 10px; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 8px; padding: 10px 12px; }
.batch-item__name { font-weight: 600; }
.batch-item__meta { color: var(--muted); }

/* ==== Table / badges ==== */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px; border-bottom: 1px solid #e5e7eb; text-align: left; vertical-align: top; }
.table thead th { background: #f3f4f6; color: #374151; font-weight: 700; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge--ok { background: #d1fae5; color: #065f46; }
.badge--err { background: #fee2e2; color: #991b1b; }

.codeblock {
  font-family: 'Courier New', monospace;
  white-space: pre-wrap;
  background: #f9fafb;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  max-height: 260px;
  overflow: auto;
}

/* small button variant inside table */
.btn--sm { padding: 6px 10px; border-radius: 8px; font-size: .9rem; }

/* ==== Batch list ==== */
.batch-list { margin-top: 12px; display: grid; gap: 8px; }
.batch-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 12px;
}
.batch-item__left { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.batch-item__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.batch-item__meta { color: var(--muted); font-size: 0.9rem; }
.batch-item__right { display: flex; align-items: center; gap: 8px; }

.mode-select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

/* ==== Table / badges （若未加入可一併保留）==== */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px; border-bottom: 1px solid #e5e7eb; text-align: left; vertical-align: top; }
.table thead th { background: #f3f4f6; color: #374151; font-weight: 700; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge--ok { background: #d1fae5; color: #065f46; }
.badge--err { background: #fee2e2; color: #991b1b; }

.codeblock {
  font-family: 'Courier New', monospace;
  white-space: pre-wrap;
  background: #f9fafb;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  max-height: 260px;
  overflow: auto;
}

/* small button variant inside table */
.btn--sm { padding: 6px 10px; border-radius: 8px; font-size: .9rem; }

/* ==== PDF preview ==== */
.pdf-preview {
  width: 100%;
  height: 500px;
  border: none;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0,0,0,.1);
}
@media (max-width: 768px) { .pdf-preview { height: 420px; } }

/* ==== PDF preview ==== */
.pdf-preview {
  width: 100%;
  height: 500px;
  border: none;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0,0,0,.1);
}
@media (max-width: 768px) { .pdf-preview { height: 420px; } }

/* ==== Unified list styles (reusing batch styles) ==== */
.batch-list { margin-top: 12px; display: grid; gap: 8px; }
.batch-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 12px;
  transition: background .15s ease, border-color .15s ease;
}
.batch-item.is-selected { background: #eef2ff; border-color: #c7d2fe; }
.batch-item__left { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.batch-item__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.batch-item__meta { color: var(--muted); font-size: 0.9rem; }
.batch-item__right { display: flex; align-items: center; gap: 8px; }
.mode-select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background:#e5e7eb; color:#374151; }

/* OK/ERR variants (reuse) */
.badge--ok { background: #d1fae5; color: #065f46; }
.badge--err { background: #fee2e2; color: #991b1b; }

.codeblock {
  font-family: 'Courier New', monospace;
  white-space: pre-wrap;
  background: #f9fafb;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  max-height: 260px;
  overflow: auto;
}

/* Small button variant */
.btn--sm { padding: 6px 10px; border-radius: 8px; font-size: .9rem; }


/* ==== CSP-safe utility classes ==== */
.util-mt-12 { margin-top: 12px; }
.util-mt-10 { margin-top: 10px; }
.util-mt-14 { margin-top: 14px; }
.util-my-10 { margin-top: 10px; margin-bottom: 10px; }
.text-center { text-align: center; }
.file-actions-wrap { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-status { margin-top: 4px; display: flex; align-items: center; gap: 8px; }


/* ==== PDF preview ==== */
.pdf-preview {
  width: 100%;
  height: 500px;
  border: none;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0,0,0,.1);
}
@media (max-width: 768px) { .pdf-preview { height: 420px; } }

/* ==== Unified list styles ==== */
.batch-list { margin-top: 12px; display: grid; gap: 8px; }
.batch-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 12px;
  transition: background .15s ease, border-color .15s ease;
}
.batch-item.is-selected { background: #eef2ff; border-color: #c7d2fe; }
.batch-item__left { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.batch-item__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.batch-item__meta { color: var(--muted); font-size: 0.9rem; }
.batch-item__right { display: flex; align-items: center; gap: 8px; }

.mode-select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background:#e5e7eb; color:#374151; }
.badge--ok { background: #d1fae5; color: #065f46; }
.badge--err { background: #fee2e2; color: #991b1b; }

.codeblock {
  font-family: 'Courier New', monospace;
  white-space: pre-wrap;
  background: #f9fafb;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  max-height: 260px;
  overflow: auto;
}

/* Small button variant */
.btn--sm { padding: 6px 10px; border-radius: 8px; font-size: .9rem; }
