:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #16191d;
  --muted: #646b75;
  --line: #dde1e6;
  --line-strong: #c4cad2;
  --accent: #1f4e8c;
  --accent-hover: #183f72;
  --accent-soft: #e8eff8;
  --good: #1e6b45;
  --bad: #a32a2a;
  --bad-soft: #fbeaea;
  --ok-soft: #e7f3ec;
  --radius: 8px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .4rem; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 1.6rem 0 .6rem; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.mono { font-family: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, monospace; font-size: .88em; }
.break { word-break: break-all; }
.nowrap { white-space: nowrap; }
.hint { color: var(--muted); font-size: .82rem; font-weight: 400; }
.req { color: var(--bad); }
.count { color: var(--muted); font-weight: 500; font-size: .85em; margin-left: .3rem; }

.page { max-width: 1100px; margin: 0 auto; padding: 28px 20px 60px; }
.page.wide { max-width: 1400px; }
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; }
.card.narrow { max-width: 620px; margin: 0 auto 1.5rem; }
.card.login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: .9rem; }
.card h2:first-child, .card h1:first-child { margin-top: 0; }

.head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.head-row.sub { margin: 1.4rem 0 .6rem; align-items: center; }
.head-row.sub h2 { margin: 0; }
.back { display: inline-block; color: var(--muted); font-size: .85rem; margin-bottom: .3rem; }
.back::before { content: "\2190\00a0"; }
.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.actions form { margin: 0; }
.note-text { white-space: pre-line; color: var(--muted); margin: .4rem 0 0; }

label { display: flex; flex-direction: column; gap: .3rem; font-weight: 550; font-size: .9rem; }
label.inline { flex-direction: row; align-items: center; gap: .5rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 450; }
input, select, textarea { font: inherit; font-weight: 400; color: var(--text); background: #fff; border: 1px solid var(--line-strong); border-radius: 6px; padding: .5rem .65rem; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: 1rem; height: 1rem; }
input[type=file] { padding: .35rem; }
label.invalid input, label.invalid select { border-color: var(--bad); }
.err { color: var(--bad); font-size: .82rem; font-weight: 450; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1rem; }
.two-col .span2 { grid-column: span 2; }
form.two-col.stack { display: grid; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 550; font-size: .9rem; padding: .5rem .95rem; border-radius: 6px; border: 1px solid var(--line-strong); background: #fff; color: var(--text); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--bad); border-color: #e2b4b4; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.link.danger { color: var(--bad); }

.flash { padding: .7rem .9rem; border-radius: 6px; margin-bottom: 1rem; background: var(--ok-soft); color: var(--good); border: 1px solid #c3e0cf; }
.flash-error { background: var(--bad-soft); color: var(--bad); border-color: #efc6c6; }
.empty-state { padding: 1.4rem; text-align: center; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface); }

.filters { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; align-items: center; }
.filters input[name=q] { flex: 1; min-width: 220px; max-width: 420px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.grid { width: 100%; border-collapse: collapse; background: var(--surface); }
table.grid th, table.grid td { padding: .55rem .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.grid th { font-size: .78rem; font-weight: 600; color: var(--muted); background: #fafbfc; white-space: nowrap; }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover td { background: #fafbfc; }
table.grid.compact th, table.grid.compact td { padding: .4rem .6rem; font-size: .86rem; }
.card table.grid, h2 + table.grid { border: 1px solid var(--line); border-radius: var(--radius); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions form { display: inline; margin-left: .6rem; }
tr.revoked td { color: var(--muted); }
.tag { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; background: #eef1f4; color: var(--muted); vertical-align: middle; }
.tag-red { background: var(--bad-soft); color: var(--bad); }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin-top: 1rem; }
.kv { margin-right: .5rem; }

.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin-top: 1rem; flex-wrap: wrap; }
.tabs a { padding: .55rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.steps { display: flex; gap: .4rem; list-style: none; padding: 0; margin: .3rem 0 1.2rem; counter-reset: s; font-size: .85rem; }
.steps li { counter-increment: s; color: var(--muted); padding: .25rem .7rem; border-radius: 99px; background: #eef1f4; }
.steps li::before { content: counter(s) ". "; }
.steps li.on { background: var(--accent); color: #fff; }
.steps li.done { background: var(--accent-soft); color: var(--accent); }

.raw { max-height: 420px; overflow: auto; margin-bottom: .4rem; }
.raw-grid td, .raw-grid th { font-size: .8rem; padding: .3rem .55rem; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--line); }
.raw-grid thead th { position: sticky; top: 0; z-index: 1; text-align: center; vertical-align: bottom; }
.raw-grid .rownum { color: var(--muted); text-align: right; background: #fafbfc; position: sticky; left: 0; }
.raw-grid .mapped { background: var(--accent-soft); }
.raw-grid thead th.mapped { background: #d6e3f3; color: var(--accent); }
.raw-grid thead th.conflict { background: var(--bad-soft); color: var(--bad); }
.raw-grid tr.header-row td { color: var(--muted); font-style: italic; text-decoration: line-through; }
.map-tag { font-size: .7rem; font-weight: 600; white-space: normal; max-width: 160px; margin: .15rem auto 0; }
.mapping { margin-top: 1.2rem; }
.map-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin: 1rem 0; }
.map-grid section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 18px 14px; }
.map-row { flex-direction: row; align-items: center; justify-content: space-between; gap: 1rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.map-row:last-child { border-bottom: 0; }
.map-row > span { flex: 1; }
.map-row small { display: block; color: var(--muted); font-weight: 400; font-size: .76rem; }
.map-row select { width: 52%; }

.stats { display: flex; gap: .8rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stats > div { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1.1rem; min-width: 150px; }
.stats b { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-size: .85rem; }
.stats .good b { color: var(--good); }
.stats .bad b { color: var(--bad); }
.commit-box { margin-top: 1.4rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: .9rem; max-width: 640px; }

.preview-bar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .8rem; flex-wrap: wrap; }
.preview-bar form { margin: 0; }
.doc-preview { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1.2rem; align-items: start; }
.props { display: grid; grid-template-columns: auto 1fr; gap: .45rem .9rem; margin: 0 0 1.2rem; font-size: .9rem; }
.props dt { color: var(--muted); }
.props dd { margin: 0; }

.inline-form { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin: 0; }
.inline-form input:not([type=hidden]) { flex: 1; min-width: 140px; }
.media-row { display: flex; gap: 1rem; align-items: flex-start; padding: .8rem 0; border-top: 1px solid var(--line); }
.media-thumb { width: 120px; height: 90px; border: 1px dashed var(--line-strong); border-radius: 6px; display: flex; align-items: center; justify-content: center; background: repeating-conic-gradient(#f2f3f5 0% 25%, #fff 0% 50%) 50% / 14px 14px; flex: none; }
.media-thumb img { max-width: 110px; max-height: 80px; }

@media (max-width: 900px) {
  .map-grid, .split, .two-col { grid-template-columns: 1fr; }
  .two-col .span2 { grid-column: auto; }
  .map-row { flex-direction: column; align-items: stretch; }
  .map-row select { width: 100%; }
  .doc-preview { height: 70vh; }
}
