:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #1b1e28; --muted: #6b7080; --line: #e3e5ea;
  --accent: #2456d6; --accent-ink: #fff; --accent-soft: #e8eefc;
  --ok: #157a46; --ok-soft: #e3f4ea; --bad: #b42318; --bad-soft: #fde8e6; --warn: #9a5b00; --warn-soft: #fff3dc;
  --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
.shell { display: flex; min-height: 100vh; }
.side { width: 210px; background: #171a23; color: #c9ccd6; padding: 16px 10px; flex-shrink: 0; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; font-weight: 700; color: #fff; font-size: 16px; padding: 4px 8px 18px; }
.logo { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; }
nav a { display: block; padding: 8px 10px; border-radius: 6px; color: inherit; text-decoration: none; margin-bottom: 2px; }
nav a:hover { background: #232734; }
nav a.active { background: #2b3040; color: #fff; }
main { flex: 1; padding: 24px 28px 60px; min-width: 0; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.bar .grow { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.stat b { display: block; font-size: 26px; }
.stat span { color: var(--muted); }
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
button:hover, .btn:hover { border-color: #c3c7d1; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--bad); }
button.small { padding: 3px 8px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); width: 100%; }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox] { width: auto; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 3px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form .full { grid-column: 1 / -1; }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; background: var(--panel); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: #f8f9fc; }
td input, td select { padding: 4px 6px; min-width: 70px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: #eef0f4; color: var(--muted); }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); } .pill.acc { background: var(--accent-soft); color: var(--accent); }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0 6px; }
.step { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 12px 14px; }
.step.done { border-color: #b9e0c8; background: #f6fcf8; }
.step h3 { margin: 0 0 4px; font-size: 14px; } .step p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 16px; }
.kv div small { display: block; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; }
.modal { position: fixed; inset: 0; background: rgba(15, 18, 28, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-box { background: #fff; border-radius: 10px; width: min(640px, 100%); max-height: 90vh; overflow: auto; padding: 20px; }
.modal-box.wide { width: min(1000px, 100%); }
.hidden { display: none !important; }
.toast { position: fixed; bottom: 18px; right: 18px; background: #171a23; color: #fff; padding: 10px 14px; border-radius: 8px; z-index: 60; max-width: 420px; }
.toast.err { background: var(--bad); }
.section-title { display: flex; align-items: baseline; gap: 8px; }
.muted { color: var(--muted); }
.right { text-align: right; }
iframe.pdf { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 6px; }

/* Template editor */
.editor { display: grid; grid-template-columns: 220px 1fr 270px; gap: 14px; align-items: start; }
.editor > * { min-width: 0; }
.editor .panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; }
.editor .panel h4 { margin: 4px 0 8px; font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.ph-list button { width: 100%; justify-content: flex-start; margin-bottom: 4px; font-size: 12.5px; padding: 5px 8px; }
.stage-wrap { overflow: auto; background: #dfe2e8; border-radius: var(--radius); padding: 18px; min-height: 300px; }
.stage { position: relative; margin: 0 auto; box-shadow: 0 2px 12px rgba(0,0,0,.18); background: #fff; }
.stage canvas { display: block; }
.el { position: absolute; border: 1px dashed rgba(36, 86, 214, .55); cursor: move; white-space: pre; overflow: visible; user-select: none; }
.el.sel { border: 1.5px solid var(--accent); background: rgba(36, 86, 214, .06); z-index: 5; }
.el .h { display: none; } .el.sel .h { display: block; }
.el .h { position: absolute; right: -5px; bottom: -5px; width: 10px; height: 10px; background: var(--accent); border-radius: 2px; cursor: nwse-resize; }
.el.img { display: grid; place-items: center; font-size: 11px; color: var(--accent); background: rgba(36,86,214,.05); }
.el.img img { max-width: 100%; max-height: 100%; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 6px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.tpl-grid .card canvas { width: 100%; border: 1px solid var(--line); border-radius: 4px; margin-bottom: 8px; }
@media (max-width: 900px) {
  .shell { flex-direction: column; } .side { width: auto; height: auto; position: static; }
  nav { display: flex; flex-wrap: wrap; } .editor { grid-template-columns: 1fr; } .steps { grid-template-columns: 1fr; }
  main { padding: 16px; } .form { grid-template-columns: 1fr; }
}

/* Sign-in, user box, help card */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: min(420px, 100%); padding: 24px; }
.auth .form { grid-template-columns: 1fr; }
.brand.dark { color: var(--ink); padding: 0; }
.side { display: flex; flex-direction: column; }
.side nav { flex: 1; }
.me { border-top: 1px solid #2b3040; padding: 12px 8px 0; font-size: 13px; }
.me .muted { color: #8b90a0; }
button.ghost { background: transparent; color: inherit; border-color: #3a3f50; }
.auth button.ghost { border-color: var(--line); }
.howto ol { margin: 8px 0 12px; padding-left: 20px; color: var(--muted); }
.howto li { margin-bottom: 3px; }
