:root {
  --bg: #f4f6f9; --card: #ffffff; --ink: #1c2430; --muted: #6b7684; --line: #e1e6ec;
  --primary: #1f5fbf; --primary-ink: #ffffff; --secondary: #e8eef8; --danger: #c0392b;
  --ok: #1f8a4c; --warn: #c98a00; --bad: #c0392b; --radius: 10px;
  --draft: #6b7684; --processing: #1f5fbf; --done: #1f8a4c; --waiting: #6b7684; --failed: #c0392b;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
.container { max-width: 1240px; margin: 0 auto; padding: 0 1.25rem; }
.muted { color: var(--muted); }
.strong { font-weight: 600; }
.center { text-align: center; }
.inline { display: inline; }

.topbar { background: #101828; color: #fff; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { color: #fff; font-weight: 600; letter-spacing: .2px; }
.brand:hover { text-decoration: none; }
.brand-mark { background: var(--primary); padding: 2px 7px; border-radius: 6px; font-size: .85em; margin-right: .35rem; }
.nav { display: flex; gap: .75rem; align-items: center; }
.nav .muted { color: #b9c2d0; }
.footer { padding: 2rem 1.25rem; font-size: .85rem; }

main.container { padding-top: 1.5rem; padding-bottom: 2rem; }
.crumbs { font-size: .9rem; color: var(--muted); margin-bottom: .75rem; }
.crumbs span { color: var(--ink); }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.h-file { word-break: break-all; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.card-narrow { max-width: 420px; margin: 3rem auto; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 1.25rem; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1.25rem; }
@media (max-width: 900px) { .grid-2, .grid-main { grid-template-columns: 1fr; } }

.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th, .table td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table thead th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table tbody tr:last-child td { border-bottom: 0; }
.empty { color: var(--muted); padding: 1rem; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

.btn { display: inline-block; border: 1px solid transparent; border-radius: 8px; padding: .5rem .9rem; font: inherit; font-weight: 600; cursor: pointer; background: var(--secondary); color: var(--primary); line-height: 1.2; }
.btn:hover { text-decoration: none; filter: brightness(.96); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-secondary { background: var(--secondary); color: var(--primary); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.topbar .btn-ghost { color: #fff; border-color: #3a4a63; }
.btn-danger-ghost { background: transparent; border-color: var(--line); color: var(--danger); }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-lg { padding: .7rem 1rem; font-size: 1.05rem; }
.btn-sm { padding: .2rem .5rem; font-size: .85rem; }

.form-row { margin-bottom: .9rem; }
.form-row label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.form-row-inline { display: flex; align-items: center; gap: .4rem; }
.form-row-inline label { margin: 0; font-weight: 400; }
.input { width: 100%; padding: .55rem .7rem; border: 1px solid #c9d2dd; border-radius: 8px; font: inherit; }
.input:focus { outline: 2px solid #9db8e8; border-color: var(--primary); }
.field-error { color: var(--danger); font-size: .85rem; margin-top: .25rem; }
.doc-error { white-space: pre-wrap; }

.flashes { margin-bottom: 1rem; }
.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: .5rem; border: 1px solid; font-size: .93rem; }
.flash-success { background: #e9f7ef; border-color: #b9e4c9; color: #1a6b3c; }
.flash-error { background: #fdecea; border-color: #f5c2bd; color: #8f2318; }
.flash-info { background: #eaf1fb; border-color: #c6d8f3; color: #1c4a8f; }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: #fff; vertical-align: middle; }
.badge-draft, .badge-waiting { background: var(--waiting); }
.badge-processing { background: var(--processing); }
.badge-done { background: var(--done); }
.badge-failed { background: var(--failed); }

.progress-card { padding: 1rem 1.25rem; }
.progress-head { display: flex; justify-content: space-between; margin-bottom: .5rem; }
.progress { height: 10px; background: #e6ebf2; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--done); transition: width .4s ease; }
.progress-bar.is-active { background: repeating-linear-gradient(45deg, var(--processing) 0 10px, #4d84d6 10px 20px); background-size: 28px 28px; animation: stripes 1s linear infinite; }
@keyframes stripes { to { background-position: 28px 0; } }

.row-processing { background: #eef4fd; }
.row-failed { background: #fff5f4; }
.table-docs td { white-space: nowrap; }
.table-docs td:nth-child(2) { white-space: normal; overflow-wrap: anywhere; min-width: 160px; }

.dropzone { display: block; border: 2px dashed #c9d2dd; border-radius: var(--radius); padding: 1.25rem; text-align: center; cursor: pointer; margin-bottom: .75rem; background: #fafbfd; }
.dropzone.is-over { border-color: var(--primary); background: #eef4fd; }
.dropzone input { display: none; }
.dropzone-text { display: block; font-weight: 600; margin-bottom: .25rem; }
.side .card { margin-bottom: 1rem; }

/* result viewer */
.viewer { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(360px, .9fr); gap: 1.25rem; align-items: start; }
@media (max-width: 1000px) { .viewer { grid-template-columns: 1fr; } }
.viewer-pages { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow: auto; }
.page { margin: 0 0 1rem; }
.page figcaption { font-size: .8rem; margin-bottom: .25rem; }
.page-inner { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.page-inner img { display: block; width: 100%; height: auto; }
.overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.overlay polygon { fill: rgba(31, 95, 191, .08); stroke: rgba(31, 95, 191, .55); stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: auto; cursor: pointer; transition: fill .15s, stroke .15s; }
.overlay polygon.is-hot, .overlay polygon:hover { fill: rgba(255, 190, 0, .35); stroke: #d48a00; stroke-width: 2.5; }
.viewer-fields .card { margin-bottom: 1rem; }
.legend { font-size: .85rem; margin-bottom: .75rem; }
.legend .conf { margin-right: .35rem; }
.table-fields th { width: 42%; font-weight: 600; color: var(--muted); font-size: .85rem; }
.table-fields td.value { white-space: pre-wrap; word-break: break-word; }
.table-fields .conf-cell { width: 60px; text-align: right; }
tr.field.is-hot, tr.field:hover { background: #fff8e1; cursor: default; }
td.field.is-hot { outline: 2px solid #d48a00; outline-offset: -2px; }
.conf { display: inline-block; font-size: .75rem; font-weight: 600; padding: .05rem .45rem; border-radius: 999px; }
.conf-high { background: #e3f4ea; color: #16673a; }
.conf-mid { background: #fff3d6; color: #8a5a00; }
.conf-low { background: #fde5e2; color: #8f2318; }
.conf-none { background: #eef1f5; color: var(--muted); }
.scroll-x { overflow-x: auto; }
.table-items td, .table-items th { white-space: nowrap; }
.table-items td:nth-child(2) { white-space: normal; min-width: 180px; }
.pre { white-space: pre-wrap; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; background: #f7f9fc; padding: .75rem; border-radius: 8px; max-height: 360px; overflow: auto; margin: .5rem 0 0; }
details.card summary { cursor: pointer; font-weight: 600; }

/* ---------- manual ---------- */
.manual .card { margin-bottom: 1rem; }
.manual .card h2 { margin-top: 0; }
.manual ul { margin: 0.5rem 0 0; padding-left: 1.25rem; }
.manual li { margin: 0.35rem 0; }
.manual .badge, .manual .conf { vertical-align: middle; }
.table-manual th { width: 9rem; text-align: left; vertical-align: top; white-space: nowrap; }
