:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --border: #dde3ec;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #b91c1c;
  --radius: 12px;
}

* { box-sizing: border-box; }
/* The hidden attribute must win over class rules like display:flex. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
h2 { font-size: 16px; margin: 0 0 14px; display: flex; align-items: center; gap: 10px; }
h3 { margin: 0 0 6px; font-size: 17px; }
.muted, .hint { color: var(--muted); font-size: 12px; font-weight: normal; }
code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ── Top bar ─────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f8fafc; border-color: #c7d0dd; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #1d4ed8; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 4px 6px; font-size: 13px; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }

/* ── Privacy notice ──────────────────────────────────── */
.privacy-banner {
  display: flex; align-items: flex-start; gap: 12px;
  max-width: 1700px; margin: 20px auto 0; padding: 12px 16px;
  background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: var(--radius); color: #065f46;
  margin-left: 20px; margin-right: 20px;
}
@media (min-width: 1741px) { .privacy-banner { margin-left: auto; margin-right: auto; } }
.privacy-icon { font-size: 20px; line-height: 1.2; }
.privacy-text { flex: 1; line-height: 1.45; }
.privacy-close { border: none; background: none; cursor: pointer; color: #047857; font-size: 16px; padding: 0 4px; }
.privacy-close:hover { color: #065f46; }
.page-foot { text-align: center; color: var(--muted); font-size: 12.5px; padding: 6px 20px 26px; }

/* ── Layout ──────────────────────────────────────────── */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 46%);
  gap: 20px; padding: 20px; max-width: 1700px; margin: 0 auto;
}
.left { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.right { min-width: 0; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px;
}
.step {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 700;
}

/* ── Layout tiles ────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
  padding: 12px 8px; border: 2px solid var(--border); border-radius: 10px; background: #fff; cursor: pointer;
}
.tile:hover { border-color: #b6c2d3; }
.tile.on { border-color: var(--accent); background: #f5f8ff; box-shadow: 0 0 0 3px var(--accent-soft); }
.tile-icon { width: 46px; height: 60px; }
.tile-title { font-weight: 600; }
.tile-sub { font-size: 11.5px; color: var(--muted); line-height: 1.3; }
.sub-options { display: none; margin-top: 12px; align-items: center; gap: 10px; }
.sub-options.show { display: flex; }
.sub-options.first-page { flex-wrap: wrap; align-items: baseline; }
.sub-options.first-page .hint { flex-basis: 100%; }
.sub-options.first-page.partial { background: #fffbeb; border: 1px solid #fcd34d; border-radius: 8px; padding: 8px 10px; }
label.inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; }
label.inline select { width: auto; padding: 5px 8px; }
.field-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lbl { font-weight: 600; font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: none; background: #fff; padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
.options-grid { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 12px; }
.check-row { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.check-row input { width: 15px; height: 15px; }

/* ── Forms ───────────────────────────────────────────── */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px 14px; margin-top: 12px; }
.grid3.compact input { max-width: 200px; }
label { display: grid; gap: 4px; font-size: 12.5px; font-weight: 600; color: #334155; }
label input[type=text], label input[type=number], label input[type=date], label select, textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff;
  font-weight: normal; font-size: 14px; width: 100%;
}
label input:focus, label select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
details.sub { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
details.sub summary { cursor: pointer; font-weight: 600; margin-bottom: 10px; }
.card-foot { display: flex; gap: 6px; margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }

/* ── Image drop zones ────────────────────────────────── */
.logo-row, .sig-row { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.drop {
  width: 180px; height: 96px; border: 2px dashed #c3cbd8; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  color: var(--muted); font-size: 13px; cursor: pointer; background: #fafbfd; overflow: hidden;
}
.drop-wide { width: 260px; height: 80px; }
.drop:hover, .drop.over { border-color: var(--accent); background: #f5f8ff; }
.drop img { max-width: 100%; max-height: 100%; object-fit: contain; }
.drop small { font-weight: normal; }

/* ── Checks table ────────────────────────────────────── */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.table-wrap { margin-top: 12px; overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; min-width: 760px; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted);
     background: #f8fafc; padding: 8px 6px; border-bottom: 1px solid var(--border); }
td { padding: 2px 3px; border-bottom: 1px solid #eef1f5; vertical-align: top; }
td input, td textarea {
  width: 100%; border: 1px solid transparent; border-radius: 6px; padding: 6px 6px; background: transparent; font-size: 13.5px;
}
td textarea { resize: vertical; min-height: 32px; line-height: 1.3; }
td input:hover, td textarea:hover { border-color: var(--border); }
td input:focus, td textarea:focus { outline: none; border-color: var(--accent); background: #fff; }
td.num input { text-align: right; }
td .del { border: none; background: none; cursor: pointer; color: #94a3b8; font-size: 16px; padding: 6px 4px; }
td .del:hover { color: var(--danger); }
.col-details { display: none; }
body.show-details .col-details { display: table-cell; }
.empty { padding: 26px; text-align: center; color: var(--muted); }
.table-foot { display: flex; justify-content: space-between; gap: 14px; margin-top: 8px; flex-wrap: wrap; font-size: 13px; }
.table-foot .hint { max-width: 60%; }

/* ── Preview ─────────────────────────────────────────── */
.preview-card { position: sticky; top: 72px; display: flex; flex-direction: column; height: calc(100vh - 92px); padding: 14px; }
.preview-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.preview-head #previewInfo { margin-left: auto; }
.preview-head h2 { margin: 0; }
.preview-frame-wrap { position: relative; flex: 1; min-height: 400px; background: #525659; border-radius: 8px; overflow: hidden; }
/* Rendered pages (pdf.js) — canvases stay in place across updates, so nothing flickers. */
.pdf-scroller { overflow: auto; }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 16px; }
.pdf-page { flex: none; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.45); }
.pdf-page canvas { width: 100%; height: 100%; display: block; }
.zoom { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin-left: 10px; }
.zoom button { border: none; background: #fff; padding: 2px 9px; cursor: pointer; font-size: 13px; border-right: 1px solid var(--border); }
.zoom button:last-child { border-right: none; }
.zoom button:hover { background: #f1f5f9; }
.preview-msg { position: absolute; inset: 0; z-index: 2; display: flex; align-items: center; justify-content: center; color: #fff; padding: 20px; text-align: center; background: rgba(0,0,0,.35); }

/* ── Dialogs ─────────────────────────────────────────── */
dialog { border: none; border-radius: 14px; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.25); width: min(560px, 94vw); max-height: 92vh; }
/* Import dialogs: big enough that the mapping and the Import button are visible without scrolling the page. */
dialog.dlg-paste { width: min(820px, 96vw); }
dialog.dlg-map { width: min(1200px, 96vw); height: min(860px, 92vh); }
dialog.dlg-map .dlg { height: 100%; }
dialog.dlg-map .map-preview-wrap { flex: 1; min-height: 160px; max-height: none; }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.dlg { padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
.dlg textarea { font-family: ui-monospace, Consolas, monospace; font-size: 13px; white-space: pre; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 4px; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px 14px; }
.map-preview-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 8px; max-height: 220px; }
.map-preview { min-width: 0; font-size: 12.5px; }
.map-preview th, .map-preview td { padding: 5px 8px; white-space: nowrap; }
.map-preview th.mapped { color: var(--accent); }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .preview-card { position: static; height: 80vh; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: 1fr; }
  .tile { flex-direction: row; text-align: left; }
  .tile-icon { width: 30px; height: 40px; }
  .table-foot .hint { max-width: none; }
}
