:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #17181c; --muted: #6b6f7b; --line: #e3e5ea; --line2: #d3d6de;
  --accent: #2f5bea; --accent-ink: #fff; --danger: #c8372d; --warn: #b7791f; --ok: #1f8a4c;
  --head: 47 91 234; --cols: 124 58 237; --body: 31 138 76; --foot: 107 111 123; --field: 230 126 34;
  --radius: 8px; --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar { height: 52px; display: flex; align-items: center; gap: 16px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 650; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 6px; background: var(--accent); color: #fff; font-size: 15px; }
.file { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.actions { display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border: 1px solid var(--line2); background: var(--panel); border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: #b9bdc8; background: #fafbfc; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: #284fd0; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled) { background: #eef0f4; }
.btn.icon { width: 32px; padding: 0; font-size: 16px; }
.btn.sm { height: 26px; padding: 0 8px; font-size: 12.5px; }
.btn.big { height: 42px; padding: 0 18px; font-size: 15px; }
.btn.danger { color: var(--danger); }

.layout { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(520px, 1.15fr); height: calc(100vh - 52px); }
.viewer { display: flex; flex-direction: column; border-right: 1px solid var(--line); min-width: 0; }
.vbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.pager, .zoom { display: flex; align-items: center; gap: 2px; }
.pager span { min-width: 56px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.zoom { margin-left: auto; }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 5px 10px; cursor: pointer; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line2); }
.seg button.on { background: var(--ink); color: #fff; }

.canvas-wrap { flex: 1; overflow: auto; padding: 18px; position: relative; }
.page-holder { position: relative; margin: 0 auto; width: max-content; box-shadow: 0 1px 3px rgb(0 0 0 / .12), 0 8px 24px rgb(0 0 0 / .06); background: #fff; }
#pageCanvas { display: block; }
#overlay { position: absolute; inset: 0; pointer-events: none; }
.busy { position: absolute; top: 24px; right: 28px; background: var(--ink); color: #fff; padding: 4px 10px; border-radius: 999px; font-size: 12px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 8px 14px; font-size: 12px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.k-head { background: rgb(var(--head) / .35); } .k-cols { background: rgb(var(--cols) / .45); } .k-body { background: rgb(var(--body) / .35); }
.k-foot { background: rgb(var(--foot) / .35); } .k-field { background: rgb(var(--field) / .55); }

.side { display: flex; flex-direction: column; min-width: 0; background: var(--panel); }
.tabs { display: flex; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--line); }
.tabs button { border: 0; background: none; padding: 12px 12px 10px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 550; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: #eef0f4; font-size: 11px; text-align: center; color: var(--muted); }
.panel { flex: 1; overflow: auto; padding: 14px 16px 40px; }

.ptools { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.ptools .muted { margin-left: auto; }
.muted { color: var(--muted); font-size: 12.5px; }
.note { padding: 8px 10px; border-radius: 6px; background: #f6f7f9; color: var(--muted); font-size: 12.5px; margin: 8px 0; }
.note.warn { background: #fff7e8; color: #7a5212; }
.note.ok { background: #ecf7f0; color: #17603a; }

table.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.grid th { position: sticky; top: -14px; background: #f6f7f9; text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 6px 6px; border-bottom: 1px solid var(--line); z-index: 1; white-space: nowrap; }
.grid th.r, .grid td.r input { text-align: right; }
.grid td { padding: 2px 3px; border-bottom: 1px solid #f0f1f4; vertical-align: top; }
.grid tr.dragging { opacity: .4; }
.grid tr.drop-before td { box-shadow: inset 0 2px 0 var(--accent); }
.grid tr.pagebreak td { background: #f6f7f9; color: var(--muted); font-size: 11.5px; padding: 3px 8px; border-bottom: 1px solid var(--line); font-weight: 600; letter-spacing: .02em; }
.grid input, .grid textarea { width: 100%; border: 1px solid transparent; background: transparent; border-radius: 4px; padding: 4px 5px; font-size: 13px; resize: none; line-height: 1.35; font-variant-numeric: tabular-nums; }
.grid input { min-width: 68px; }
.grid td.r input { min-width: 80px; }
.grid textarea { min-width: 180px; overflow: hidden; field-sizing: content; min-height: 27px; }
.grid input:hover, .grid textarea:hover { border-color: var(--line); }
.grid input:focus, .grid textarea:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgb(47 91 234 / .12); }
.grid .bad { border-color: var(--danger) !important; background: #fdf1f0; }
.grid .computed { padding: 4px 6px; text-align: right; color: var(--ok); font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid .computed::after { content: " ƒ"; color: #9aa0ad; font-size: 11px; }
.grid .mismatch { color: var(--warn); }
.handle { cursor: grab; color: #a3a8b4; padding: 5px 2px 0 4px; user-select: none; white-space: nowrap; font-size: 12px; font-variant-numeric: tabular-nums; }
.rowacts { white-space: nowrap; opacity: .35; }
tr:hover .rowacts, tr:focus-within .rowacts { opacity: 1; }
.rowacts button { border: 0; background: none; cursor: pointer; width: 22px; height: 24px; border-radius: 4px; color: var(--muted); }
.rowacts button:hover { background: #eef0f4; color: var(--ink); }
.rowacts button.del:hover { color: var(--danger); }

.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 13px; }
.colgrid { display: grid; grid-template-columns: 1.4fr 1fr 1fr .7fr 1.1fr; gap: 6px 8px; align-items: center; font-size: 13px; }
.colgrid .hd { font-size: 11.5px; color: var(--muted); font-weight: 600; }
select, input[type=number], input[type=text].f { height: 30px; border: 1px solid var(--line2); border-radius: 6px; padding: 0 6px; background: #fff; width: 100%; }
.row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.row label { flex: 1; }
.row > select { flex: 0 0 260px; width: 260px; }
.row > input[type=number] { flex: 0 0 90px; width: 90px; }
.row > input.f { flex: 1; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 7px 0; cursor: pointer; }
.check input { margin-top: 3px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: #f6f7f9; border-radius: 6px; padding: 8px 10px; }
.stat b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11.5px; color: var(--muted); }
.fields { display: grid; grid-template-columns: auto 1fr auto 1.2fr; gap: 6px 10px; align-items: center; font-size: 13px; }
.mono { font-family: var(--mono); font-size: 12px; }
.loglist { list-style: none; padding: 0; margin: 0; }
.loglist li { padding: 7px 0; border-bottom: 1px solid #f0f1f4; font-size: 13px; }
.loglist time { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; margin-right: 6px; }
.loglist .d { color: var(--muted); font-size: 12.5px; white-space: pre-wrap; margin-top: 2px; }
.ver { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid #f0f1f4; }
.ver span { flex: 1; }

.empty { min-height: calc(100vh - 52px); display: grid; place-items: center; padding: 24px; }
.drop { max-width: 720px; background: var(--panel); border: 1.5px dashed var(--line2); border-radius: 14px; padding: 36px 40px; }
.drop.over, body.over .drop { border-color: var(--accent); background: #f5f8ff; }
.drop h1 { font-size: 24px; margin: 0 0 10px; letter-spacing: -.01em; }
.drop p { color: #3f434d; }
.cta { display: flex; gap: 10px; margin: 20px 0 6px; flex-wrap: wrap; }
.facts { margin: 22px 0 0; padding: 18px 0 0; border-top: 1px solid var(--line); list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 22px; font-size: 13px; color: var(--muted); }
.facts b { display: block; color: var(--ink); }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 8px; font-size: 13px; z-index: 20; max-width: 90vw; box-shadow: 0 6px 20px rgb(0 0 0 / .2); }
.toast.err { background: var(--danger); }

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .viewer { height: 70vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .side { min-height: 80vh; }
  .facts { grid-template-columns: 1fr; }
  .file { display: none; }
}

/* validation report (Checks tab + pre-export dialog) */
.issues { list-style: none; margin: 0; padding: 0; }
.issues li { display: flex; gap: 8px; align-items: baseline; padding: 5px 0; border-bottom: 1px solid #f0f1f4; font-size: 12.5px; }
.issues .sev { flex: 0 0 62px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .03em; }
.sev-error .sev { color: var(--danger); } .sev-warn .sev { color: var(--warn); } .sev-info .sev { color: var(--muted); }
.linkish { border: 0; background: none; padding: 0; text-align: left; cursor: pointer; color: inherit; font: inherit; }
.linkish:hover { color: var(--accent); text-decoration: underline; }
.ranlist { list-style: none; margin: 6px 0 10px; padding: 0; font-size: 12.5px; }
.ranlist li { padding: 2px 0; } .ranlist .ran { color: var(--ok); } .ranlist .skipped { color: var(--muted); }
dialog.report { width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; box-shadow: 0 20px 60px rgb(0 0 0 / .25); }
dialog.report::backdrop { background: rgb(20 22 28 / .35); }
dialog.report h2 { margin: 0 0 8px; font-size: 17px; }
.report-body { max-height: 46vh; overflow: auto; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.btn.danger { border-color: var(--danger); }
