:root {
  --bg: #f6f7f9; --card: #fff; --ink: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --brand: #2557d6; --brand-ink: #fff; --ok: #1a7f4b; --warn: #a15c00; --bad: #c0362c;
  --ok-bg: #e5f5ec; --warn-bg: #fff4e0; --bad-bg: #fdecea; --info-bg: #e8effd;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2rem 0 1rem; } h3 { margin: 0 0 .25rem; font-size: 1.02rem; }
code { background: #f0f2f5; padding: 0 .3em; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.danger { color: var(--bad) !important; }

.topbar { display: flex; align-items: center; gap: 2rem; padding: .7rem 1.5rem; background: #141a2b; color: #fff; }
.topbar .brand { color: #fff; font-weight: 700; font-size: 1.1rem; } .topbar .brand span { color: #8fb0ff; font-weight: 500; }
.topbar nav { display: flex; gap: .3rem; flex: 1; }
.topbar nav a { color: #c9d0e0; padding: .35rem .7rem; border-radius: 6px; }
.topbar nav a.on, .topbar nav a:hover { background: #2a3350; color: #fff; text-decoration: none; }
.topbar .logout { margin: 0; } .topbar .logout .muted { color: #8b93a8; } .topbar .link { color: #c9d0e0; }

main { max-width: 1100px; margin: 1.5rem auto 4rem; padding: 0 1.5rem; }
main.wide { max-width: 1400px; } main.narrow { max-width: 420px; margin-top: 10vh; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card.flush { padding: 0; overflow: hidden; } .pad { padding: .9rem 1.2rem; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; } .row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 10rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: stretch; }
@media (max-width: 900px) { .grid2, .editor { grid-template-columns: 1fr; } .topbar { flex-wrap: wrap; gap: .5rem; } }

label { display: flex; flex-direction: column; gap: .25rem; font-weight: 500; font-size: .9rem; }
label.check { flex-direction: row; align-items: center; font-weight: 400; }
input, select, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid #cfd4dc; border-radius: 7px; background: #fff; color: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd0ff; border-color: var(--brand); }
textarea.code { font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
button, .button { font: inherit; font-weight: 500; padding: .5rem .95rem; border-radius: 7px; border: 1px solid #cfd4dc; background: #fff; color: var(--ink); cursor: pointer; display: inline-block; }
button:hover, .button:hover { background: #f3f5f8; text-decoration: none; }
button.primary, .button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.primary:hover, .button.primary:hover { background: #1c47b5; }
button.danger { color: var(--bad); border-color: #efc2bd; }
button.link { border: 0; background: none; padding: 0; color: var(--brand); font-weight: 400; }
form.inline { display: inline; margin: 0; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; background: var(--info-bg); }
.flash.ok { background: var(--ok-bg); color: var(--ok); } .flash.error { background: var(--bad-bg); color: var(--bad); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem 1.2rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
.scroll { overflow-x: auto; max-height: 34rem; overflow-y: auto; } .scroll th { position: sticky; top: 0; }
.clickrow { cursor: pointer; } .clickrow:hover { background: #f7f9fd; }

.pill { display: inline-block; padding: .05rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eef0f3; color: var(--muted); text-transform: capitalize; }
.pill:empty { display: none; }
.pill.big { font-size: .95rem; padding: .25rem .9rem; }
.pill.sending, .pill.pending { background: var(--info-bg); color: var(--brand); }
.pill.completed, .pill.sent { background: var(--ok-bg); color: var(--ok); }
.pill.paused, .pill.skipped { background: var(--warn-bg); color: var(--warn); }
.pill.failed, .pill.cancelled { background: var(--bad-bg); color: var(--bad); }

.bar { height: 6px; background: #e9ecf1; border-radius: 99px; overflow: hidden; min-width: 8rem; margin: .3rem 0; }
.bar.big { height: 10px; margin: 0 0 1rem; } .bar span { display: block; height: 100%; background: var(--brand); transition: width .5s; }
.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: .8rem; margin: 1rem 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; }
.stat b { display: block; font-size: 1.6rem; } .stat span { color: var(--muted); font-size: .85rem; }
.stat.bad b { color: var(--bad); } .stat.warn b { color: var(--warn); }
@media (max-width: 700px) { .stats { grid-template-columns: repeat(2, 1fr); } }

.checks { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .45rem; }
.checks li { padding-left: 1.6rem; position: relative; }
.checks li::before { position: absolute; left: 0; font-weight: 700; }
.checks li.ok::before { content: "✓"; color: var(--ok); } .checks li.bad::before { content: "!"; color: var(--bad); left: .3rem; }
.checks li.warn::before { content: "!"; color: var(--warn); left: .3rem; }
.chip { display: inline-block; margin: .15rem .2rem 0 0; }
.steps ol { margin: .4rem 0 0; } .steps li.done { color: var(--muted); text-decoration: line-through; }

iframe#preview { width: 100%; min-height: 28rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; flex: 1; }
.preview-meta, .subject-preview { background: #fafbfc; border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; font-size: .92rem; }
pre { white-space: pre-wrap; background: #fafbfc; padding: .8rem; border-radius: 8px; border: 1px solid var(--line); }
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); }
.tab { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); padding: .4rem .7rem; }
.tab.on { color: var(--brand); border-bottom-color: var(--brand); }
.help { background: var(--info-bg); padding: .6rem .8rem; border-radius: 8px; }
.filters a { padding: .2rem .6rem; border-radius: 6px; color: var(--muted); } .filters a.on { background: var(--info-bg); color: var(--brand); }
.actions { gap: .5rem; }

.tpl-layout { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 1rem; align-items: start; }
.tpl-layout > .card { margin-bottom: 0; }
.attr-panel-body { gap: .7rem; }
.set-bar select { min-width: 0; }
.attr-panel { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
.attr-head, .attr { display: grid; grid-template-columns: 1.2fr 1fr .8fr; gap: .35rem; }
.attr input { padding: .35rem .45rem; font-size: .88rem; min-width: 0; }
.attr .attr-actions { grid-column: 1 / -1; display: flex; gap: .9rem; font-size: .82rem; margin-top: -.1rem; }
.attr { padding-bottom: .5rem; border-bottom: 1px dashed var(--line); }
.attr.invalid .a-label { border-color: var(--bad); background: var(--bad-bg); }
.chip-btn { font-size: .8rem; padding: .15rem .5rem; margin: 0 .3rem .3rem 0; border-radius: 999px; font-weight: 500; }
.chip-btn.used { opacity: .55; cursor: default; }
@media (max-width: 1100px) { .tpl-layout { grid-template-columns: 1fr; } .attr-panel { position: static; max-height: none; } }

table.mapping th, table.mapping td { padding: .45rem .6rem; }
table.mapping select { min-width: 14rem; }
table.mapping tr.unmapped td { background: var(--bad-bg); }

.ms-button { display: flex; align-items: center; justify-content: center; gap: .6rem; padding: .7rem 1rem; }
.ms-button svg { background: #fff; padding: 2px; border-radius: 2px; }
iframe.import-preview { width: 100%; min-height: 26rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.import-item.invalid { opacity: .75; }
.repl-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: .35rem; align-items: center; }
.repl-row input { min-width: 0; padding: .35rem .45rem; font-size: .88rem; }
.token-row code { font-size: .82rem; }
