:root {
  --paper: #f5f2eb;
  --card: #ffffff;
  --ink: #1b2622;
  --muted: #66736e;
  --line: #e3ded3;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe9;
  --warn: #b5651d;
  --warn-soft: #fbeedf;
  --danger: #b23a3a;
  --danger-soft: #f8e4e4;
  --blue-soft: #e5edf7;
  --blue: #2f5f9a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(27,38,34,.04), 0 6px 24px rgba(27,38,34,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 Inter, system-ui, -apple-system, Segoe UI, sans-serif; background: var(--paper); color: var(--ink); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: Fraunces, Georgia, serif; font-weight: 650; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 19px; }
h3 { font-size: 15px; font-family: Inter, sans-serif; font-weight: 600; }
code, pre, textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* Layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: #16201d; color: #cfd8d4; padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { font-family: Fraunces, serif; font-size: 22px; color: #fff; padding: 0 10px 22px; display: flex; align-items: center; gap: 9px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; font-size: 14px; }
.nav-h { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #7d8b86; padding: 14px 10px 6px; }
.nav-sep { height: 1px; background: rgba(255,255,255,.08); margin: 12px 6px; }
.nav .ico { width: 18px; text-align: center; opacity: .8; }
.nav a { display: flex; align-items: center; gap: 10px; color: #cfd8d4; padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; }
.side-foot { margin-top: auto; padding: 10px; font-size: 12px; color: #8a9893; }
.side-foot button { background: none; border: 0; color: #cfd8d4; padding: 0; cursor: pointer; font: inherit; text-decoration: underline; }
.main { padding: 32px 40px 60px; max-width: 1240px; width: 100%; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.head p { margin: 4px 0 0; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: 1fr 1fr; }

/* Cards & tables */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card, .editor > .card + .card { margin-top: 0; }
.card h2 { margin-bottom: 12px; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat .value { font-family: Fraunces, serif; font-size: 30px; font-weight: 650; margin-top: 2px; }
.stat .sub { color: var(--muted); font-size: 12px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #faf8f4; }
.tight td, .tight th { padding: 8px 10px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }
.table-wrap { overflow-x: auto; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eee; color: #555; text-transform: capitalize; }
.b-sent, .b-subscribed, .b-active, .b-completed { background: var(--accent-soft); color: var(--accent); }
.b-sending, .b-scheduled { background: var(--blue-soft); color: var(--blue); }
.b-paused, .b-pending { background: var(--warn-soft); color: var(--warn); }
.b-unsubscribed, .b-draft, .b-cancelled, .b-held { background: #eceae5; color: #6b6760; }
.b-bounced, .b-complained, .b-failed, .b-suppressed, .b-hard_bounce, .b-complaint { background: var(--danger-soft); color: var(--danger); }

/* Forms */
label { display: block; font-size: 12.5px; font-weight: 600; margin: 0 0 6px; }
.field { margin-bottom: 14px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; font-weight: 400; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid #d5cfc3; border-radius: 8px; background: #fff; font: inherit; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; margin: 0 8px 0 0; vertical-align: middle; }
textarea.code { min-height: 520px; line-height: 1.5; tab-size: 2; resize: vertical; background: #fbfaf7; }
.check { display: flex; align-items: center; font-weight: 500; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 15px; border-radius: 8px; border: 1px solid #d5cfc3; background: #fff; color: var(--ink); font: 600 13.5px Inter, sans-serif; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f8f6f1; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #195c4c; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; background: transparent; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }

/* Notices */
.notice { padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: #6d4114; margin-bottom: 16px; border: 1px solid #f0d9bd; }
.notice.info { background: var(--blue-soft); color: #22446e; border-color: #cddcef; }
.notice.err { background: var(--danger-soft); color: #7c2323; border-color: #f0caca; }

/* Editor */
.editor { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.editor .card { position: sticky; top: 16px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.preview-frame { width: 100%; height: 560px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { background: none; border: 0; padding: 9px 12px; font: 600 13px Inter, sans-serif; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-color: var(--accent); }
.save-state { font-size: 12px; color: var(--muted); }
.device-toggle button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Bars */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 8px; }
.bars div { flex: 1; max-width: 32px; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; position: relative; }
.bars div:hover { opacity: 1; }
.meter { height: 8px; background: #eeeae2; border-radius: 99px; overflow: hidden; margin-top: 8px; }
.meter span { display: block; height: 100%; background: var(--accent); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(22,32,29,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 14px; padding: 24px; width: 100%; max-width: 480px; box-shadow: 0 20px 60px rgba(0,0,0,.25); max-height: 90vh; overflow: auto; }
.modal h2 { margin-bottom: 10px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #16201d; color: #fff; padding: 11px 18px; border-radius: 10px; z-index: 60; font-weight: 500; box-shadow: 0 8px 30px rgba(0,0,0,.2); max-width: 90vw; }
.toast.err { background: var(--danger); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 30px; }
.login h1 { margin-bottom: 4px; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; color: var(--muted); }
pre.embed { background: #16201d; color: #d8e3de; padding: 14px; border-radius: 10px; overflow: auto; white-space: pre-wrap; word-break: break-all; }
.muted { color: var(--muted); }
.trunc { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 12px; overflow-x: auto; }
  .brand { padding: 0 10px 0 0; font-size: 18px; }
  .nav { display: flex; gap: 2px; }
  .side-foot { margin: 0 0 0 auto; padding: 0 0 0 8px; white-space: nowrap; }
  .side-foot span { display: none; }
  .main { padding: 20px 16px 40px; }
  .g4 { grid-template-columns: 1fr 1fr; }
  .g3, .g2, .editor, .split { grid-template-columns: 1fr; }
  .editor .card { position: static; }
}

/* ---------- v2 additions ---------- */
.modal.wide { max-width: 760px; }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: color-mix(in srgb, var(--c) 14%, white); color: color-mix(in srgb, var(--c) 80%, black); border: 1px solid color-mix(in srgb, var(--c) 30%, white); white-space: nowrap; }
.chip button { background: none; border: 0; padding: 0 0 0 2px; cursor: pointer; color: inherit; font-size: 14px; line-height: 1; }
.chip-add { width: auto !important; padding: 4px 8px !important; font-size: 12.5px !important; border-style: dashed !important; }
.mini { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 6px; background: #eeeae2; color: #4b5853; margin: 1px 0; white-space: nowrap; }
.mini.off { opacity: .5; text-decoration: line-through; }
.bulkbar { display: flex; align-items: center; gap: 10px; background: var(--accent-soft); border: 1px solid #c9e0d6; border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; }
.li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.li:last-child { border: 0; }
.tabs.big { margin-bottom: 18px; }
.tabs.big button { font-size: 14px; padding: 11px 14px; display: flex; align-items: center; gap: 8px; }
.step-n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 99px; background: #eeeae2; font-size: 12px; font-weight: 700; color: var(--muted); flex: none; }
.tabs .on .step-n { background: var(--accent); color: #fff; }
.seg-toggle { display: inline-flex; background: #eeeae2; border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg-toggle button, .seg-toggle a { border: 0; background: none; padding: 6px 12px; border-radius: 7px; font: 600 13px Inter, sans-serif; color: var(--muted); cursor: pointer; text-decoration: none; }
.seg-toggle .on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.check-row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.check-row > span { width: 24px; height: 24px; border-radius: 99px; display: grid; place-items: center; font-weight: 700; flex: none; }
.check-row.ok > span { background: var(--accent-soft); color: var(--accent); }
.check-row.bad > span { background: var(--danger-soft); color: var(--danger); }
.pv-subject { padding: 8px 12px; background: #faf8f4; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.starter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.starter { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 16px 10px; cursor: pointer; font: 600 13px Inter, sans-serif; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--ink); }
.starter:hover { border-color: var(--accent); background: var(--accent-soft); }
.starter-ico { font-size: 22px; color: var(--accent); }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.tpl-grid .card + .card { margin-top: 0; }
.tpl-thumb { height: 220px; overflow: hidden; border-radius: 8px; border: 1px solid var(--line); margin-bottom: 10px; background: #f4f1ea; position: relative; }
.tpl-thumb iframe { width: 640px; height: 880px; border: 0; transform: scale(.36); transform-origin: 0 0; pointer-events: none; position: absolute; left: 0; top: 0; }
.timeline { display: flex; flex-direction: column; align-items: stretch; }
.tl-wait { align-self: center; padding: 6px 14px; margin: 6px 0; border-radius: 99px; background: #eeeae2; font-size: 12.5px; font-weight: 600; position: relative; }
.tl-step { margin: 0 !important; }
.tl-stats { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); }
.tl-stats b { color: var(--ink); }
.add-step { margin-top: 14px; border-style: dashed; padding: 14px; }
.aud-row { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); align-items: start; }
.aud-l { font-weight: 600; font-size: 13px; padding-top: 6px; }
.aud-count { margin-top: 12px; padding: 10px 14px; background: var(--accent-soft); color: var(--accent); border-radius: 10px; }
table.map td { vertical-align: middle; }
details summary { cursor: pointer; }

/* ---------- block builder ---------- */
.bld { display: grid; grid-template-columns: 170px 1fr 300px; gap: 14px; align-items: start; }
.bld-palette, .bld-panel { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow: auto; }
.bld-h { font-weight: 700; font-size: 13px; margin-bottom: 10px; }
.bld-sub { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; border-top: 1px solid var(--line); padding-top: 14px; }
.bld-blocks { display: grid; gap: 6px; }
.bld-add { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #faf8f4; cursor: grab; font: 500 13px Inter, sans-serif; color: var(--ink); text-align: left; }
.bld-add span { width: 22px; text-align: center; color: var(--accent); font-weight: 700; }
.bld-add:hover { border-color: var(--accent); }
.bld-canvas { border-radius: 12px; padding: 24px 12px; min-height: 500px; border: 1px solid var(--line); overflow: auto; }
.bld-email { margin: 0 auto; max-width: 100%; padding: 12px 0; transition: width .2s; }
.bld-block { position: relative; outline: 1px dashed transparent; outline-offset: -1px; cursor: pointer; }
.bld-block:hover { outline-color: #b9cfc6; }
.bld-block.sel { outline: 2px solid var(--accent); }
.bld-block.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.bld-block.drop-after { box-shadow: 0 3px 0 var(--accent); }
.bld-tools { position: absolute; top: -13px; right: 8px; display: none; gap: 2px; background: var(--accent); border-radius: 6px; padding: 2px 4px; z-index: 5; align-items: center; }
.bld-block:hover .bld-tools, .bld-block.sel .bld-tools { display: flex; }
.bld-tools button, .bld-grip { background: none; border: 0; color: #fff; cursor: pointer; font-size: 12px; padding: 2px 5px; }
.bld-grip { cursor: grab; letter-spacing: -2px; }
.bld-name { color: #fff; font-size: 11px; font-weight: 600; padding: 0 6px 0 2px; font-family: Inter, sans-serif; }
.bld-empty { padding: 60px 20px; text-align: center; color: #8a948f; border: 2px dashed #d5cfc3; border-radius: 10px; margin: 12px; }
[contenteditable]:focus { outline: none; background: rgba(31,111,92,.04); }
.rte-bar { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.rte-bar button { border: 1px solid var(--line); background: #faf8f4; border-radius: 6px; padding: 4px 9px; cursor: pointer; font-size: 13px; }
.bld-panel .field { margin-bottom: 10px; }
.bld-panel label { font-size: 12px; }
.bld-panel input, .bld-panel select, .bld-panel textarea { padding: 7px 9px; font-size: 13px; }

@media (max-width: 1200px) { .bld { grid-template-columns: 150px 1fr; } .bld-panel { grid-column: 1 / -1; position: static; max-height: none; } }
@media (max-width: 960px) {
  .bld { grid-template-columns: 1fr; } .bld-palette { position: static; } .bld-blocks { grid-template-columns: repeat(2, 1fr); }
  .aud-row { grid-template-columns: 1fr; gap: 4px; }
  .grid[style*="340px"] { grid-template-columns: 1fr !important; }
  .side .nav-h, .side .nav-sep { display: none; }
}
