:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #16181d;
  --ink-2: #4a5160;
  --ink-3: #7b8394;
  --line: #e3e6eb;
  --line-2: #eef0f3;
  --accent: #2456d6;
  --accent-ink: #ffffff;
  --accent-soft: #e9effd;
  --good: #1a7f4b;
  --good-soft: #e3f4ea;
  --warn: #9a6200;
  --warn-soft: #fdf1dc;
  --bad: #c0352b;
  --bad-soft: #fbe7e5;
  --info: #2456d6;
  --info-soft: #e9effd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: -apple-system, "Segoe UI", system-ui, Roboto, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--line-2); padding: 1px 5px; border-radius: 4px; }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- page (the frame itself: tbcrm.css + shell.js) */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .grow { flex: 1; }
.sub { color: var(--ink-3); font-size: 13px; }

/* ---------------------------------------------------------------- controls */
button, .btn {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 7px 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover { border-color: #c8cdd6; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--bad); }
button.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--line-2); }
button.small { padding: 4px 9px; font-size: 12.5px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; margin: 0; }
input[type=color] { padding: 2px; height: 34px; width: 52px; }
textarea { resize: vertical; min-height: 90px; }
textarea.code { font-family: var(--mono); font-size: 12.5px; min-height: 420px; white-space: pre; }
[hidden] { display: none !important; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
label.field .hint { font-size: 12px; color: var(--ink-3); margin-top: 4px; font-weight: normal; }
label.check { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; cursor: pointer; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row .grow { flex: 1; min-width: 160px; }
.row > select, .row > input[type=number] { width: auto; }
.nowrap { white-space: nowrap; }
input.short { width: 110px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
@media (max-width: 700px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- panels and tables */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card-head .grow { flex: 1; }
.card-head select, .card-head input { width: auto; min-width: 180px; }
.title-input { font-size: 20px; font-weight: 700; border-color: transparent; background: transparent; padding: 4px 8px; margin-left: -8px; }
.title-input:hover { border-color: var(--line); }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .03em; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
td { padding: 10px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f9fafb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
.empty { padding: 40px 20px; text-align: center; color: var(--ink-3); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 14px; color: var(--ink-3); font-size: 13px; }
.truncate { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
button.chip { border: 0; cursor: pointer; padding: 4px 11px; }
button.chip.on { outline: 2px solid currentColor; }

.notice { border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; background: var(--info-soft); color: #1d3f9b; }
.notice.warn { background: var(--warn-soft); color: #6d4600; }
.notice.bad { background: var(--bad-soft); color: #8d241c; }
.notice.good { background: var(--good-soft); color: #145c37; }
.notice ul { margin: 6px 0 0; padding-left: 20px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.tile .value { font-size: 24px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .note { font-size: 12px; color: var(--ink-3); }
.progress { height: 8px; background: var(--line-2); border-radius: 99px; overflow: hidden; margin: 6px 0 4px; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 9px 14px; color: var(--ink-3); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------------------------------------------------------------- modal, toast */
.backdrop { position: fixed; inset: 0; background: rgba(16, 19, 24, .45); display: grid; place-items: start center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal.wide { max-width: 900px; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; flex: 1; }
.modal-body { padding: 18px 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--line); }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #16181d; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 420px; }
.toast.bad { background: var(--bad); }
.toast.good { background: var(--good); }

/* ---------------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 360px; }
.login .brand { color: var(--ink); padding: 0 0 18px; }

/* ---------------------------------------------------------------- editor */
.editor { display: grid; grid-template-columns: 250px minmax(300px, 1fr) minmax(360px, 640px); gap: 16px; align-items: start; }
.editor .col { min-width: 0; }
.editor .sticky { position: sticky; top: 12px; }
@media (max-width: 1280px) { .editor { grid-template-columns: 230px 1fr; } .editor .preview-col { grid-column: 1 / -1; } }
@media (max-width: 760px) { .editor { grid-template-columns: 1fr; } }
.blocks { display: flex; flex-direction: column; gap: 6px; }
.block-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; }
.block-item:hover { border-color: #c8cdd6; }
.block-item.on { border-color: var(--accent); background: var(--accent-soft); }
.block-item .kind { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--ink-3); width: 62px; flex: none; }
.block-item .summary { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.block-item .moves { display: flex; gap: 2px; }
.block-item .moves button { padding: 1px 6px; font-size: 12px; }
.add-menu { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.add-menu button { justify-content: center; font-weight: 500; font-size: 12.5px; }
.preview-frame { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.preview-tools { display: flex; gap: 6px; margin-bottom: 8px; align-items: center; }
.preview-tools .grow { flex: 1; }
.preview-frame.mobile { width: 390px; max-width: 100%; display: block; margin: 0 auto; }
.item-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 10px; background: #fbfbfc; }
.item-card .row { margin-bottom: 8px; }
.image-field { display: flex; gap: 6px; }
.image-field img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); flex: none; }
.help { font-size: 12px; color: var(--ink-3); line-height: 1.5; }
.saved { font-size: 12px; color: var(--ink-3); }

/* ---------------------------------------------------------------- images */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.thumb { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.thumb .pic { height: 130px; background: #eef0f3; display: grid; place-items: center; }
.thumb .pic img { max-width: 100%; max-height: 130px; display: block; }
.thumb .meta { padding: 8px 10px; font-size: 12px; color: var(--ink-3); }
.thumb .meta .name { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumb.pick { cursor: pointer; }
.thumb.pick:hover { border-color: var(--accent); }

.checklist { display: grid; gap: 6px; }
.checklist label { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; }
.checklist .count { margin-left: auto; color: var(--ink-3); font-size: 12px; }
.mapping td { padding: 6px 10px; }
.mapping select { min-width: 150px; }
.result-list { margin: 0; padding-left: 18px; }
.kbd { font-family: var(--mono); font-size: 12px; }

/* ---------------------------------------------------------------- additions */
.filter-row { margin-bottom: 12px; }
.cards { align-items: start; }
.condition { margin-bottom: 8px; flex-wrap: nowrap; }
.condition > select, .condition > input { width: auto; min-width: 0; flex: 1; }
.condition > button { flex: none; }
@media (max-width: 700px) { .condition { flex-wrap: wrap; } }
.who-input { width: 190px; padding: 4px 8px; font-size: 12.5px; }
.form-frame { height: 640px; }
.code-small { font-family: var(--mono); font-size: 12px; min-height: 0; }
.code-block { font-family: var(--mono); font-size: 12px; background: #0f1218; color: #d6dbe4; padding: 12px 14px; border-radius: 8px; overflow-x: auto; white-space: pre; }
.step { position: relative; }
.step-no { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.step .row.sub { gap: 6px; }
a.btn { color: var(--ink); text-decoration: none; }
a.btn.small { padding: 4px 9px; font-size: 12.5px; }
.qr { display: grid; place-items: center; margin: 6px 0 12px; }
.qr img { border: 1px solid var(--line); border-radius: 8px; image-rendering: pixelated; }
.code-input { font-family: var(--mono); font-size: 20px; letter-spacing: .25em; max-width: 220px; }
.recovery { font-size: 15px; line-height: 1.7; columns: 2; }
.setup-2fa { max-width: 460px; }
