/* Signatures admin: all styles. Tokens first, components after, small-screen rules at the end. */
:root {
  --bg: #f4f4f1;
  --surface: #ffffff;
  --ink: #15171b;
  --ink-2: #3b4048;
  --muted: #6a6f78;
  --line: #e3e3de;
  --line-2: #cfcfc8;
  --soft: #f8f8f6;
  --focus: #2457d6;
  --ok: #146c43;   --ok-bg: #e7f3ec;
  --warn: #8f5300; --warn-bg: #fcf1dd;
  --bad: #b42318;  --bad-bg: #fcebe9;
  --info: #1f4fbf; --info-bg: #e8eefc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 22, 26, .05), 0 1px 1px rgba(20, 22, 26, .03);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--ink); text-underline-offset: 2px; }
a:hover { color: var(--ink-2); }
h1 { font-size: 24px; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
p { margin: 0 0 12px; }
code { font-family: var(--mono); font-size: .88em; background: var(--soft); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; }
small, .small { font-size: 13px; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.break { word-break: break-word; overflow-wrap: anywhere; }
.text-bad { color: var(--bad); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1320px; margin: 0 auto; padding: 0 20px; height: 58px; display: flex; align-items: center; gap: 24px; }
.brand-row { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); flex-shrink: 0; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 15px; box-shadow: inset 0 -3px 0 rgba(255,255,255,.18); }
.brand-name { font-weight: 650; font-size: 16px; letter-spacing: -.01em; }
.mainnav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.mainnav::-webkit-scrollbar { display: none; }
.mainnav a { padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; white-space: nowrap; }
.mainnav a:hover { color: var(--ink); background: var(--soft); }
.mainnav a.active { color: var(--ink); background: var(--bg); }
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--bg); border: 1px solid var(--line-2); display: grid; place-items: center; font-weight: 600; font-size: 14px; }
.usermenu .menu { position: absolute; right: 0; top: 42px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(20,22,26,.12); min-width: 230px; padding: 6px; z-index: 30; }
.menu-who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.usermenu .menu a, .usermenu .menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px; text-decoration: none; color: var(--ink); background: none; border: 0; font: inherit; cursor: pointer; }
.usermenu .menu a:hover, .usermenu .menu button:hover, .usermenu .menu a.active { background: var(--soft); }
.usermenu form { margin: 0; }

/* ---------- layout ---------- */
.container { max-width: 1080px; margin: 0 auto; padding: 28px 20px 80px; }
.container.wide { max-width: 1320px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stack > * + * { margin-top: 16px; }
.split { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 20px; align-items: start; }
.tpl-split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.import-split { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.addin-split { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.grid2.top { align-items: start; }
.span2 { grid-column: 1 / -1; }
.grow { flex: 1; min-width: 0; }
.show-sm { display: none; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card.empty { text-align: center; padding: 48px 20px; }
.callout { border-radius: 8px; padding: 12px 14px; margin-top: 14px; }
.callout.warn { background: var(--warn-bg); color: #5c3700; }
.callout p:last-child { margin: 0; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font: 500 14px/1.3 var(--font); text-decoration: none; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--soft); border-color: #bdbdb5; color: var(--ink); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #2c3038; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--soft); border-color: var(--line); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); border-color: #f2c4bf; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 0; }

/* ---------- flashes, badges ---------- */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: #c5e3d1; }
.flash.warn { background: var(--warn-bg); color: #6d4000; border-color: #f2dcb2; }
.flash.bad { background: var(--bad-bg); color: var(--bad); border-color: #f4c9c4; }
.flash.info { background: var(--info-bg); color: var(--info); border-color: #c9d6f6; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--soft); border: 1px solid var(--line); color: var(--ink-2); vertical-align: 1px; }
.badge.ok { background: var(--ok-bg); border-color: #c5e3d1; color: var(--ok); }
.badge.info { background: var(--info-bg); border-color: #c9d6f6; color: var(--info); }
.badge.warn { background: var(--warn-bg); border-color: #f2dcb2; color: var(--warn); }
.badge.bad { background: var(--bad-bg); border-color: #f4c9c4; color: var(--bad); }
.tag { display: inline-block; font-size: 11px; font-weight: 700; width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 4px; background: var(--ink); color: #fff; margin-left: 4px; vertical-align: 1px; }
.req { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 4px; }

/* ---------- forms ---------- */
.form label { display: block; font-weight: 550; font-size: 14px; }
.form label > input, .form label > select, .form label > textarea { margin-top: 6px; }
.form > label, .form > fieldset, .form > .checks, .form > .grid2, .form > div { margin-bottom: 14px; }
.form small { display: block; font-weight: 400; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input:not([type]), select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--surface); color: var(--ink); font: 400 15px/1.4 var(--font);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(36, 87, 214, .15); }
input.narrow { max-width: 140px; }
textarea { resize: vertical; }
textarea.code { font: 13px/1.5 var(--mono); tab-size: 2; white-space: pre; overflow-wrap: normal; overflow-x: auto; background: #fbfbfa; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; padding: 0; margin-bottom: 10px; font-size: 14px; }
.form fieldset + fieldset { margin-top: 22px; }
.auth-card legend { display: block; width: 100%; padding-bottom: 8px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
label.check, label.radio { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; cursor: pointer; padding: 6px 0; }
label.check input, label.radio input { margin: 3px 0 0; width: 16px; height: 16px; accent-color: var(--ink); flex-shrink: 0; }
.checks { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; }
.checks.inline { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 18px; border: 0; padding: 0; margin: 10px 0 14px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding-top: 6px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--bad); }
.field-error { display: block; color: var(--bad); font-size: 13px; font-weight: 400; margin-top: 4px; }
.inline-label { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 550; margin-bottom: 12px; }
.inline-label select { width: auto; flex: 1; max-width: 340px; }
.inline-form { display: flex; gap: 8px; }
.radios { margin-bottom: 10px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th { text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--soft); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table.compact td { padding: 6px 0; font-size: 14px; border: 0; }
.table.compact td:first-child { padding-right: 12px; white-space: nowrap; }
.people-table { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.people-table tbody tr:hover { background: #fbfbf9; }
.people-table tr.inactive td { color: var(--muted); }
.people-table tr.inactive .rowlink { color: var(--muted); }
.col-check { width: 36px; }
.col-check input { width: 16px; height: 16px; accent-color: var(--ink); }
.rowlink { font-weight: 600; text-decoration: none; }
.rowlink:hover { text-decoration: underline; }
.nums { font-size: 13px; }
.num { display: inline-block; margin: 0 10px 2px 0; white-space: nowrap; }
.num b, .kv b { font-weight: 700; margin-right: 3px; }
.status { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line-2); margin-right: 8px; vertical-align: 1px; }
.status.ok { background: #1f9d5c; }

/* ---------- people toolbar ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 220px; max-width: 420px; }
.toolbar select { width: auto; }
.bulkbar { position: sticky; top: 66px; z-index: 10; display: flex; gap: 10px; align-items: center; background: var(--ink); color: #fff; padding: 8px 10px 8px 16px; border-radius: var(--radius); margin-bottom: 12px; flex-wrap: wrap; }
.bulkbar select { width: auto; padding: 6px 10px; font-size: 14px; }
.bulkbar .btn { background: #fff; }

/* ---------- previews ---------- */
.preview-col { position: sticky; top: 78px; }
.preview { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; box-shadow: var(--shadow); }
.preview-label { font-size: 12px; color: var(--muted); padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--soft); }
.preview-frame { display: block; width: 100%; height: 220px; border: 0; background: #fff; }
.preview-tabs { display: inline-flex; gap: 2px; padding: 3px; background: #ebebe6; border-radius: 9px; margin-bottom: 10px; }
.preview-tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font: 500 13px var(--font); color: var(--muted); cursor: pointer; }
.preview-tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.preview-actions { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }

/* ---------- templates ---------- */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.tpl-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.tpl-thumb { height: 150px; border-bottom: 1px solid var(--line); background: #fff; overflow: hidden; pointer-events: none; }
.tpl-thumb iframe { width: 200%; height: 300px; border: 0; transform: scale(.5); transform-origin: 0 0; }
.tpl-meta { padding: 14px 16px 16px; }
.tpl-meta h2 { margin-bottom: 2px; }
.tpl-meta h2 a { text-decoration: none; }
.fields-ref { margin: 4px 0 14px; }
.fields-ref summary { cursor: pointer; font-weight: 550; padding: 4px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 12px var(--mono); padding: 4px 8px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--soft); cursor: pointer; color: var(--ink-2); }
.chip:hover { background: var(--surface); border-color: var(--ink); }

/* ---------- import ---------- */
.dropzone { display: flex !important; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; border: 1.5px dashed var(--line-2); border-radius: var(--radius); padding: 28px 16px; background: var(--soft); cursor: pointer; transition: border-color .12s, background .12s; }
.dropzone:hover, .dropzone.over { border-color: var(--ink); background: #f1f1ed; }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone.has-file { border-style: solid; border-color: #1f9d5c; background: var(--ok-bg); }
.dz-title { font-weight: 600; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 14px 0 !important; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.help h2 { margin-bottom: 6px; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; min-width: 110px; box-shadow: var(--shadow); }
.stat-n { display: block; font-size: 24px; font-weight: 650; line-height: 1.1; }
.stat-l { color: var(--muted); font-size: 13px; }
.stat.bad .stat-n { color: var(--bad); }
.stat.warn .stat-n { color: var(--warn); }
.mapgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin: 12px 0 6px; }
.mapitem { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: var(--soft); }
.mapitem.ignored { opacity: .65; }
.map-head { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-sample { display: block; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 6px; }
.mapitem select { margin-top: 0 !important; font-size: 14px; padding: 6px 8px; }
.import-review .card { margin-bottom: 16px; }
.import-table td { font-size: 14px; }
.kv { display: inline-block; margin: 0 12px 2px 0; }
.kv.changed { background: var(--info-bg); border-radius: 4px; padding: 0 6px; }
.row-error td { background: #fffafa; }
.sticky-actions { position: sticky; bottom: 0; display: flex; gap: 10px; align-items: center; padding: 14px 0; background: linear-gradient(to bottom, rgba(244,244,241,0), var(--bg) 30%); flex-wrap: wrap; }

/* ---------- settings ---------- */
.logo-row { display: flex; gap: 20px; align-items: flex-start; margin-bottom: 8px; flex-wrap: wrap; }
.logo-box { min-width: 220px; min-height: 90px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: #fff; display: grid; place-items: center; }
.logo-box img { max-width: 100%; height: auto; }

/* ---------- checklists and lists ---------- */
.checklist { list-style: none; padding: 0; margin: 0 0 16px; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: 0; }
.checklist .dot { width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0; margin-top: 2px; display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700; }
.checklist li.ok .dot { background: #1f9d5c; }
.checklist li.ok .dot::after { content: "✓"; }
.checklist li.bad .dot { background: var(--bad); }
.checklist li.bad .dot::after { content: "!"; }
.checklist li.warn .dot { background: #d68a00; }
.checklist li.warn .dot::after { content: "!"; }
.steps { padding-left: 20px; margin: 0 0 12px; }
.steps li { margin-bottom: 8px; }
.bullets { padding-left: 18px; margin: 0; }
.bullets li { margin-bottom: 6px; }
.simple-list { list-style: none; padding: 0; margin: 0; }
.simple-list li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.simple-list li:last-child { border: 0; }
.simple-list time { color: var(--muted); white-space: nowrap; }
.code-block { font: 12px/1.5 var(--mono); background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 10px; overflow-x: auto; margin: 8px 0 0; }

/* ---------- sign-in and installer ---------- */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: 0 10px 30px rgba(20,22,26,.06); }
.auth-card.wide { max-width: 640px; }
.auth-card .brand-row { margin-bottom: 22px; }
.auth-card h1 { font-size: 22px; }

/* ---------- small screens ---------- */
@media (max-width: 980px) {
  .split, .tpl-split, .import-split, .addin-split { grid-template-columns: 1fr; }
  .preview-col { position: static; }
  .hide-md { display: none; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  .topbar-inner { gap: 12px; padding: 0 12px; }
  .brand-name { display: none; }
  .container { padding: 20px 14px 60px; }
  h1 { font-size: 21px; }
  .grid2 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .show-sm { display: block; }
  .card { padding: 16px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .table th, .table td { padding: 10px; }
  .toolbar input[type=search] { min-width: 0; max-width: none; width: 100%; flex-basis: 100%; }
  .toolbar select { flex: 1; }
  .bulkbar { top: 62px; }
  .auth-card { padding: 22px; }
}
