:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #4338ca;
  --brand-ink: #ffffff;
  --brand-soft: #eef2ff;
  --danger: #b91c1c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
input, textarea, select { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- shared ---------- */
.logo { display: inline-flex; align-items: center; gap: 10px; background: none; border: 0; font-weight: 700; font-size: 17px; padding: 0; letter-spacing: -.01em; }
.logo-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; }
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #fff; padding: 9px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: #c7cbd4; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover:not(:disabled) { background: #3730a3; }
.btn.ghost { background: transparent; border-color: var(--brand); color: var(--brand); }
.link { background: none; border: 0; color: var(--brand); font-weight: 600; padding: 0; font-size: 14px; }
.link:hover { text-decoration: underline; }
.spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; }
.spinner.dark { border-color: rgba(0,0,0,.15); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }
.error { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; padding: 10px 14px; border-radius: 10px; margin: 12px 16px; font-size: 14px; }
.error button { background: none; border: 0; color: inherit; }
.bar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 12px 20px; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.crumb { color: var(--muted); font-size: 14px; padding-left: 16px; border-left: 1px solid var(--line); }
.bar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.select-wrap select { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; font-weight: 500; font-size: 14px; }

/* ---------- home ---------- */
.home { max-width: 1120px; margin: 0 auto; padding: 0 20px 60px; }
.home-top { padding: 22px 0; }
.hero { text-align: center; padding: 48px 0 36px; }
.hero h1 { font-size: clamp(30px, 5vw, 48px); letter-spacing: -.03em; margin: 0 0 14px; line-height: 1.1; }
.hero p { color: var(--muted); font-size: 18px; max-width: 640px; margin: 0 auto 22px; line-height: 1.55; }
.entries { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.entry { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 26px 24px; box-shadow: var(--shadow); transition: transform .15s, border-color .15s; display: flex; flex-direction: column; }
.entry:hover { transform: translateY(-2px); border-color: var(--brand); }
.entry-n { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 700; display: grid; place-items: center; margin-bottom: 16px; }
.entry h2 { margin: 0 0 8px; font-size: 20px; letter-spacing: -.01em; }
.entry p { margin: 0 0 18px; color: var(--muted); line-height: 1.5; flex: 1; }
.entry-cta { color: var(--brand); font-weight: 600; }
.home-templates { margin-top: 48px; }
.home-templates h3 { font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.home-templates .tpl-row { flex-wrap: wrap; }
.home-foot { margin-top: 48px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- upload ---------- */
.upload-body { max-width: 860px; margin: 0 auto; padding: 28px 20px 60px; }
.upload-body h1 { font-size: 30px; letter-spacing: -.02em; margin: 14px 0 8px; }
.lead { color: var(--muted); line-height: 1.55; margin: 0 0 22px; }
.back { background: none; border: 0; color: var(--muted); padding: 0; }
.dz-grid { display: grid; gap: 18px; }
.dz-grid.two { grid-template-columns: 1fr 1fr; }
.step-label { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.dropzone { border: 2px dashed #c7cbd4; border-radius: 16px; background: #fff; padding: 44px 20px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone.has-file { border-style: solid; border-color: #16a34a; background: #f0fdf4; }
.dz-icon { width: 46px; height: 46px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; margin: 0 auto 12px; font-size: 20px; font-weight: 700; }
.has-file .dz-icon { background: #dcfce7; color: #16a34a; }
.dz-label { font-weight: 600; word-break: break-all; }
.dz-hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
.upload-actions { margin-top: 22px; display: flex; justify-content: flex-end; }

/* ---------- workspace ---------- */
.workspace { min-height: 100vh; display: flex; flex-direction: column; }
.split { display: grid; grid-template-columns: minmax(360px, 460px) 1fr; flex: 1; min-height: 0; }
.left { border-right: 1px solid var(--line); background: var(--bg); padding: 16px; height: calc(100vh - 59px); overflow-y: auto; position: sticky; top: 59px; }
.right { padding: 16px 20px 40px; min-width: 0; }
.mobile-tabs { display: none; }
.tip.warn { background: #fffbeb; color: #92400e; }
.tip { background: var(--brand-soft); color: #312e81; border-radius: 10px; padding: 10px 12px; font-size: 13.5px; line-height: 1.45; margin-bottom: 12px; }

.form { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; background: none; border: 0; padding: 12px 14px; text-align: left; }
.card-toggle { display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 0; flex: 1; min-width: 0; text-align: left; }
.card-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; color: var(--muted); background: #f3f4f6; border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.chev { background: none; border: 0; font-size: 18px; color: var(--muted); width: 26px; padding: 0; }
.card-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.card-body.grid2, .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field span { font-size: 12px; font-weight: 500; color: var(--muted); }
.field input, .field textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; font-size: 14px; }
.field textarea { resize: vertical; line-height: 1.45; }
.field input:focus, .field textarea:focus, select:focus { outline: 2px solid #c7d2fe; border-color: var(--brand); }
.items { display: flex; flex-direction: column; gap: 10px; }
.row-item { display: flex; gap: 8px; align-items: flex-end; }
.row-item .field:first-child { flex: 0 0 34%; }
.row-item .field.wide { flex: 1; }
.row-item .field:only-of-type { flex: 1; }
.entry-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fafafa; }
.entry-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 14px; }
.item-controls { display: flex; gap: 2px; align-items: center; }
.icon-btn { width: 28px; height: 28px; border-radius: 7px; border: 1px solid transparent; background: none; color: var(--muted); font-size: 13px; }
.icon-btn:hover:not(:disabled) { background: #f3f4f6; color: var(--ink); }
.icon-btn.danger:hover:not(:disabled) { color: var(--danger); background: #fef2f2; }
.add-btn { border: 1px dashed #c7cbd4; background: #fff; border-radius: 8px; padding: 8px; color: var(--brand); font-weight: 600; font-size: 14px; }
.add-btn:hover { border-color: var(--brand); }
.add-section select { width: 100%; border: 1px dashed var(--brand); color: var(--brand); background: #fff; padding: 11px; border-radius: var(--radius); font-weight: 600; }

/* templates */
.tpl-strip { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; }
.tpl-strip-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.tpl-strip-head h3 { margin: 0; font-size: 14px; }
.tpl-row { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 4px; }
.tpl-card { flex: none; background: none; border: 0; padding: 0; text-align: center; }
.tpl-card .thumb { border: 2px solid var(--line); border-radius: 8px; transition: border-color .15s; }
.tpl-card:hover .thumb { border-color: #a5b4fc; }
.tpl-card.active .thumb { border-color: var(--brand); box-shadow: 0 0 0 3px #e0e7ff; }
.tpl-card.static .thumb { border-width: 1px; box-shadow: var(--shadow); }
.tpl-name { font-size: 12.5px; font-weight: 600; margin-top: 6px; }
.thumb { overflow: hidden; background: #fff; position: relative; }
.thumb-inner { pointer-events: none; background: #fff; }
.word-thumb { width: 96px; height: 136px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; background: #eff6ff; }
.word-thumb span { width: 36px; height: 36px; border-radius: 6px; background: #2b579a; color: #fff; font-weight: 700; display: grid; place-items: center; }
.word-thumb small { font-size: 10px; color: var(--muted); padding: 0 6px; word-break: break-all; line-height: 1.2; max-height: 3.6em; overflow: hidden; }
.tpl-note { margin-top: 10px; font-size: 13px; color: #374151; background: #f9fafb; border-radius: 8px; padding: 8px 10px; line-height: 1.5; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; border: 1px solid rgba(0,0,0,.1); }

/* preview */
.preview { display: flex; flex-direction: column; align-items: center; }
.paper-wrap { position: relative; }
.paper { position: relative; transform-origin: top left; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.08), 0 12px 32px rgba(0,0,0,.08); }
.page-break { position: absolute; left: 0; right: 0; border-top: 2px dashed #a5b4fc; pointer-events: none; }
.page-break span { position: absolute; right: 8px; top: 4px; font: 600 11px Inter, sans-serif; color: #6366f1; background: #fff; padding: 1px 6px; border-radius: 4px; }
.page-note { margin-top: 10px; color: var(--muted); font-size: 13px; }
.preview-busy { position: absolute; top: 10px; right: 10px; background: #fff; border-radius: 50%; padding: 8px; box-shadow: var(--shadow); display: flex; }
.preview-busy .spinner { border-color: rgba(0,0,0,.1); border-top-color: var(--brand); }
.docx-host .docx-page { width: auto !important; box-shadow: none; }
.docx-loading { padding: 60px; text-align: center; color: var(--muted); font-family: Inter, sans-serif; }

@media (max-width: 960px) {
  .entries { grid-template-columns: 1fr; }
  .dz-grid.two { grid-template-columns: 1fr; }
  .split { grid-template-columns: 1fr; }
  .left { position: static; height: auto; border-right: 0; }
  .mobile-tabs { display: flex; gap: 6px; padding: 10px 16px 0; }
  .mobile-tabs button { flex: 1; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px; font-weight: 600; }
  .mobile-tabs button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
  .split.show-edit .right { display: none; }
  .split.show-preview .left { display: none; }
  .crumb { display: none; }
  .bar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .bar-actions { margin-left: 0; width: 100%; }
  .bar-actions .btn { flex: 1; justify-content: center; padding: 9px 8px; }
  .right { padding: 16px; }
}
@media (max-width: 480px) {
  .card-body.grid2, .grid2 { grid-template-columns: 1fr; }
  .row-item { flex-wrap: wrap; }
  .row-item .field:first-child { flex: 1 1 100%; }
}

/* template-first editing */
.source-pick { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; border-radius: 8px; padding: 7px 10px; }
.source-pick.linked { background: #f0fdf4; color: #166534; }
.source-pick.unlinked { background: #f5f7ff; color: #4338ca; }
.source-pick select { border: 1px solid var(--line); border-radius: 7px; padding: 5px 8px; background: #fff; font-size: 12.5px; max-width: 100%; }
.badge.empty-badge { background: #eef2ff; color: #4338ca; }
.unplaced { background: #fffbeb; border: 1px solid #fde68a; border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.unplaced-head { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: #78350f; }
.unplaced-head b { font-size: 14px; }
.unplaced-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #fff; border: 1px solid #fde68a; border-radius: 8px; padding: 8px 10px; }
.unplaced-row > div { min-width: 0; }
.unplaced-title { font-weight: 600; font-size: 14px; }
.unplaced-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unplaced-row select { border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; background: #fff; font-size: 13px; flex: none; max-width: 48%; }
.photo-row { display: flex; align-items: center; gap: 10px; }
.photo-thumb { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); flex: none; }
.photo-thumb.empty { display: grid; place-items: center; font-size: 10px; color: var(--muted); background: #f3f4f6; }
.photo-row .add-btn { padding: 7px 12px; }
.danger-link { color: var(--danger); }

/* manual spacing / page breaks */
.paper .rv.live .rv-pb { overflow: hidden; position: relative; background: repeating-linear-gradient(135deg, #f8fafc 0 8px, #eef2ff 8px 16px); }
.paper .rv.live .rv-pb span { display: block; position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; font: 600 11px Inter, sans-serif; color: #6366f1; }
.paper .rv.live .rv-pb[style*="height: 0px"] span { display: none; }
.space-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.space-row select { border: 1px solid var(--line); border-radius: 7px; padding: 4px 6px; background: #fff; font-size: 12.5px; color: var(--ink); }
.space-row select.on { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.marker-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.marker-btns button { border: 1px dashed #c7cbd4; background: #fff; border-radius: 7px; padding: 4px 8px; font-size: 12px; color: var(--brand); font-weight: 600; }
.marker-btns button:hover { border-color: var(--brand); }
.item-spacing { margin-top: 4px; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.row-side .space-row select { font-size: 11.5px; padding: 3px 4px; }
.docx-host .docx-pb { height: auto !important; border-top: 2px dashed #a5b4fc; margin: 10pt 0 6pt; position: relative; }
.docx-host .docx-pb::after { content: "Page break: what follows starts on a new page"; position: absolute; right: 0; top: -9px; background: #fff; padding: 0 6px; font: 600 11px Inter, sans-serif; color: #6366f1; }
.empty-note { margin-top: 10px; max-width: 640px; text-align: center; font-size: 12.5px; color: #4338ca; background: #eef2ff; border-radius: 8px; padding: 6px 10px; }

/* ads */
.ad-wrap { width: 100%; margin: 18px auto; text-align: center; min-height: 90px; }
.ad-label { display: block; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: #9ca3af; margin-bottom: 4px; }
.ad-placeholder { display: grid; place-items: center; min-height: 100px; border: 1px dashed #cbd5e1; border-radius: 10px; background: repeating-linear-gradient(45deg, #f8fafc 0 10px, #f1f5f9 10px 20px); color: #94a3b8; font-size: 12px; }
.ad-home { max-width: 970px; margin: 36px auto 0; }
.ad-upload { margin-top: 28px; }
.ad-editor { max-width: 820px; margin: 0 auto 16px; }
.right > .ad-editor:last-child { margin-top: 20px; }

/* footer + static pages */
.site-foot { display: flex; flex-wrap: wrap; gap: 10px 18px; justify-content: space-between; align-items: center; max-width: 1120px; margin: 28px auto 0; padding: 18px 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.site-foot nav { display: flex; gap: 16px; flex-wrap: wrap; }
.site-foot a { color: var(--muted); text-decoration: none; }
.site-foot a:hover { color: var(--brand); text-decoration: underline; }
.static-page { min-height: 100vh; display: flex; flex-direction: column; }
.static-body { max-width: 760px; margin: 0 auto; padding: 32px 20px 20px; line-height: 1.65; flex: 1; }
.static-body h1 { font-size: 32px; letter-spacing: -.02em; margin: 0 0 12px; }
.static-body h2 { font-size: 19px; margin: 28px 0 6px; }
.static-body a { color: var(--brand); }
.static-body .muted { color: var(--muted); font-size: 14px; }
