:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1c1917;
  --ink-2: #57534e;
  --muted: #8a847c;
  --line: #e7e4de;
  --line-2: #d6d2ca;
  --accent: #e8461e;
  --accent-ink: #ffffff;
  --accent-soft: #fdeee8;
  --ok: #15803d;
  --ok-soft: #e9f7ee;
  --warn: #b45309;
  --warn-soft: #fef6e7;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --agent: #6d28d9;
  --agent-soft: #f1ebfd;
  --sidebar: #1c1917;
  --sidebar-ink: #d6d3d1;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(28, 25, 23, .06), 0 2px 8px rgba(28, 25, 23, .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #1d1b18;
    --surface-2: #232019;
    --ink: #f0ede8;
    --ink-2: #c4bfb7;
    --muted: #8f897f;
    --line: #2e2b26;
    --line-2: #3d3932;
    --accent-soft: #3a1e14;
    --ok: #4ade80;
    --ok-soft: #13271a;
    --warn: #fbbf24;
    --warn-soft: #2d2410;
    --danger: #f87171;
    --danger-soft: #2f1616;
    --agent: #a78bfa;
    --agent-soft: #241b38;
    --sidebar: #0d0c0b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
code, kbd { font-family: var(--mono); font-size: .9em; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
kbd { opacity: .7; font-size: 11px; margin-left: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.warn-text { color: var(--warn); }
.ok-text { color: var(--ok); }
.danger { color: var(--danger) !important; }
[hidden] { display: none !important; }

/* layout */
.shell { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-ink); padding: 20px 12px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; line-height: 1.05; font-size: 15px; padding: 0 8px; }
.logo-mark { width: 34px; height: 34px; color: #a8a29e; flex: none; }
.sidebar ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sidebar ul a { display: block; padding: 8px 12px; border-radius: 6px; text-decoration: none; }
.sidebar ul a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar ul a[aria-current] { background: rgba(255, 255, 255, .1); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.logout { margin-top: auto; padding: 0 12px; }
.logout .link { color: var(--sidebar-ink); }
.main { padding: 28px 32px 64px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 12px; flex-wrap: wrap; }
.lede { margin: 0 0 20px; max-width: 70ch; }
.back { text-decoration: none; color: var(--muted); font-size: 13px; }
.back:hover { color: var(--ink); }
.stack { display: grid; gap: 14px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 16px 0; }
.actions { display: flex; gap: 8px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* controls */
label { display: grid; gap: 4px; font-weight: 600; font-size: 13px; color: var(--ink-2); }
label .muted, label .small { font-weight: 400; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-radius: 6px; padding: 7px 10px; width: 100%; min-width: 0; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }
input[type=file] { padding: 5px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
.inline-form input:not([type=file]) { width: 220px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; cursor: pointer; }
.btn { display: inline-flex; align-items: center; gap: 4px; font: inherit; font-weight: 600; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); border-radius: 6px; padding: 7px 14px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.07); border-color: var(--accent); }
.btn-small { padding: 3px 10px; font-size: 12px; }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: progress; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--ink-2); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; }
.seg button, .seg label { border: 0; background: var(--surface); color: var(--ink-2); font: inherit; font-size: 12px; font-weight: 600; padding: 4px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.seg > * + * { border-left: 1px solid var(--line-2) !important; }
.seg button[aria-pressed=true], .seg label:has(input:checked) { background: var(--ink); color: var(--bg); }
.seg label input { position: absolute; opacity: 0; pointer-events: none; }
.chip { font-family: var(--mono); font-size: 12px; border: 1px solid var(--line-2); background: var(--surface-2); color: var(--ink-2); border-radius: 99px; padding: 1px 8px; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.field-error { color: var(--danger); font-weight: 400; font-size: 12px; }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card.narrow { max-width: 640px; margin-bottom: 16px; }
details.card > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 12px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h2 { margin: 0; }
details.card > summary::after { content: "Edit"; margin-left: auto; font-size: 12px; color: var(--muted); text-decoration: underline; }
details.card[open] > summary { margin-bottom: 16px; }
details.card[open] > summary::after { content: "Close"; }
.flash { background: var(--ok-soft); color: var(--ok); border-radius: 6px; padding: 8px 12px; margin: 0 0 14px; }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-ok { background: var(--ok-soft); color: var(--ok); }
.flash-warn { background: var(--warn-soft); color: var(--warn); }
.sync-actions { align-items: center; margin: 4px 0 12px; }
#sync-result .flash { margin: 0 0 12px; }
.empty { text-align: center; padding: 56px 16px; border: 1px dashed var(--line-2); border-radius: var(--radius); }
.empty p { margin: 0 0 8px; }
.empty-inline { padding: 16px 0; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 1px 7px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); vertical-align: 1px; }
.badge-agent { background: var(--agent-soft); color: var(--agent); border-color: transparent; }
.badge-draft { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-sent { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
.facts dt { font-weight: 600; color: var(--ink-2); }
.facts dd { margin: 0; }

/* tables */
.table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-title { font-weight: 600; text-decoration: none; }
.row-title:hover { color: var(--accent); }
.status-select { width: auto; padding: 2px 6px; font-size: 12px; font-weight: 600; }
.status-active { color: var(--ok); }
.status-unsubscribed { color: var(--muted); }
.status-bounced, .status-complained { color: var(--danger); }
.subs { margin-top: 24px; }
.subs-filter { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.subs-filter h2 { margin: 0 auto 0 0; }
.subs-filter input { width: 260px; }
.subs-filter select { width: auto; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 0; }
.pager .muted { margin-right: auto; }
.htmx-request .table, .htmx-request.table { opacity: .6; transition: opacity .2s; }

/* dialogs & menus */
.dialog { border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.dialog::backdrop { background: rgba(20, 18, 16, .45); }
.dialog h2 { font-size: 18px; }
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-items { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 30px rgba(0, 0, 0, .12); padding: 4px; min-width: 190px; display: grid; }
.menu-items a, .menu-items button { display: block; width: 100%; text-align: left; padding: 7px 10px; border-radius: 5px; border: 0; background: none; font: inherit; color: var(--ink); text-decoration: none; cursor: pointer; }
.menu-items a:hover, .menu-items button:hover { background: var(--surface-2); }

/* editors */
.main:has(.editor-page) { padding: 0; }
.editor-page { display: flex; flex-direction: column; height: 100vh; }
.editor-head { display: flex; align-items: center; gap: 10px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--surface); flex: none; }
.editor-head .spacer { flex: 1; }
.saved-note { color: var(--ok); font-weight: 600; transition: opacity .6s; }
.editor-grid { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.15fr); flex: 1; min-height: 0; }
.editor-form { display: flex; flex-direction: column; gap: 12px; padding: 16px 20px; overflow: auto; border-right: 1px solid var(--line); }
.editor-form .field-name input { font-weight: 600; }
.body-head { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.body-head .label { font-weight: 600; font-size: 13px; color: var(--ink-2); }
textarea.code { font-family: var(--mono); font-size: 12.5px; line-height: 1.55; tab-size: 2; flex: 1; min-height: 340px; resize: vertical; white-space: pre; overflow: auto; background: var(--surface-2); }
.help summary { cursor: pointer; font-weight: 600; font-size: 13px; color: var(--ink-2); }
.help ul { padding-left: 18px; margin: 8px 0 0; }
.help li { margin-bottom: 4px; }
.tag-list { list-style: none; padding: 0 !important; display: flex; flex-wrap: wrap; gap: 6px; }
.editor-side { display: flex; flex-direction: column; min-height: 0; overflow: auto; background: var(--bg); }

.preview { display: flex; flex-direction: column; flex: 1 0 auto; min-height: 420px; }
.preview-bar { display: flex; align-items: center; gap: 14px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; position: sticky; top: 0; z-index: 2; }
.preview-status { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.preview-status.is-warn { color: var(--warn); font-weight: 600; }
.preview-notes:empty { display: none; }
.preview-notes { padding: 8px 16px; background: var(--warn-soft); color: var(--warn); font-size: 12px; border-bottom: 1px solid var(--line); }
.preview-notes p { margin: 0; }
.preview-stage { flex: 1; padding: 20px; display: flex; justify-content: center; background: repeating-conic-gradient(var(--bg) 0 25%, var(--surface-2) 0 50%) 0 0 / 16px 16px; }
.preview-frame-wrap { width: 100%; max-width: 100%; transition: max-width .25s ease; background: #fff; border-radius: 6px; box-shadow: 0 2px 16px rgba(0, 0, 0, .12); overflow: hidden; display: flex; }
.preview[data-device=mobile] .preview-frame-wrap { max-width: 375px; border-radius: 22px; border: 8px solid #1c1917; }
.preview iframe { width: 100%; min-height: 640px; border: 0; display: block; background: #fff; }
.preview.is-dark iframe { filter: invert(1) hue-rotate(180deg); }
.preview.is-loading .preview-status::before { content: "Rendering… "; }

.test-send, .attachments-card { margin: 0 16px 16px; }
.test-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.test-form input[type=email] { flex: 1; min-width: 200px; }
.test-form .check { flex-basis: 100%; }
#test-result .flash { margin: 12px 0 0; }

/* templates grid */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.tpl-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.tpl-thumb { display: block; height: 220px; overflow: hidden; position: relative; background: #fff; border-bottom: 1px solid var(--line); }
.tpl-thumb iframe { width: 640px; height: 880px; border: 0; transform: scale(.4); transform-origin: 0 0; pointer-events: none; }
.tpl-thumb::after { content: ""; position: absolute; inset: 0; }
.tpl-body { padding: 12px 14px; }
.tpl-body h2 { font-size: 14px; margin: 0 0 4px; }
.tpl-body h2 a { text-decoration: none; }
.tpl-body p { margin: 0 0 2px; }

/* images */
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.image-card { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.image-thumb { display: flex; align-items: center; justify-content: center; height: 150px; background: repeating-conic-gradient(var(--bg) 0 25%, var(--surface-2) 0 50%) 0 0 / 14px 14px; }
.image-thumb img { max-width: 100%; max-height: 150px; object-fit: contain; }
.image-card figcaption { padding: 8px 10px; display: grid; gap: 4px; }
.image-actions { display: flex; justify-content: space-between; align-items: center; }

/* login */
.bare-main { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.login-logo { display: flex; align-items: center; gap: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 20px; font-size: 16px; }
.login-logo .logo-mark { color: var(--ink-2); }

@media (max-width: 1000px) {
  .editor-page { height: auto; }
  .editor-grid { grid-template-columns: 1fr; }
  .editor-form { border-right: 0; border-bottom: 1px solid var(--line); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  .sidebar ul { display: flex; flex-wrap: wrap; }
  .logout { margin: 0 0 0 auto; }
  .main { padding: 20px 16px 48px; }
  .editor-head { flex-wrap: wrap; padding: 10px 16px; }
  .table { display: block; overflow-x: auto; }
  .inline-form input:not([type=file]) { width: 100%; }
}

/* agent & history */
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line-2)); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.actions.wrap { flex-wrap: wrap; margin-top: 14px; }
.badge-unlocked { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.agent-state { color: var(--ink-2); }
.agent-state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); margin-right: 4px; }
.agent-state.is-open { color: var(--agent); border-color: color-mix(in srgb, var(--agent) 40%, var(--line-2)); }
.agent-state.is-open::before { background: var(--agent); }
.agent-items { min-width: 280px; }
.menu-note { margin: 4px 8px 8px; color: var(--ink-2); line-height: 1.45; }
.editor-flash { margin: 0; border-radius: 0; }
.conflict { background: var(--warn-soft); color: var(--ink); border-bottom: 1px solid var(--line); padding: 12px 20px; display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.conflict p { margin: 0; max-width: 75ch; }
.agent-notes textarea { margin-top: 8px; font-size: 13px; }
.agent-notes[open] { background: var(--agent-soft); border-radius: 6px; padding: 8px 10px; }

.history { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
.rev-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
.rev-list li + li { border-top: 1px solid var(--line); }
.rev-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; text-decoration: none; }
.rev-item:hover { background: var(--surface-2); }
.rev-item.is-selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.rev-diff { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.rev-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.field-diff + .field-diff { margin-top: 16px; }
.field-diff h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 6px; }
.diff { margin: 0; font: 12px/1.55 var(--mono); background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 0; overflow-x: auto; }
.dl { display: block; padding: 0 12px; white-space: pre; }
.dl-add { background: var(--ok-soft); color: var(--ok); }
.dl-del { background: var(--danger-soft); color: var(--danger); }
.dl-skip { color: var(--muted); font-style: italic; }
.diff-inline del { background: var(--danger-soft); color: var(--danger); padding: 1px 4px; border-radius: 3px; margin-right: 6px; }
.diff-inline ins { background: var(--ok-soft); color: var(--ok); padding: 1px 4px; border-radius: 3px; text-decoration: none; }
@media (max-width: 720px) {
  .history { grid-template-columns: 1fr; }
  .rev-list { position: static; max-height: 240px; }
}

/* sending */
.badge-sending { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge-paused { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-cancelled { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.send-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.send-main { display: grid; gap: 16px; }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; }
.checklist .small { color: var(--ink-2); font-weight: 400; overflow-wrap: anywhere; }
.check-mark { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.is-ok .check-mark { background: var(--ok-soft); color: var(--ok); }
.is-warn .check-mark { background: var(--warn-soft); color: var(--warn); }
.is-block .check-mark { background: var(--danger-soft); color: var(--danger); }
.confirm-send input { max-width: 200px; font-size: 18px; font-variant-numeric: tabular-nums; }
.send-preview { padding: 0; overflow: hidden; position: sticky; top: 16px; }
.send-preview .facts { padding: 14px 18px; border-bottom: 1px solid var(--line); }
.send-frame { display: block; width: 100%; height: 70vh; border: 0; background: #fff; }
.send-progress { margin-bottom: 20px; }
.progress-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.progress-head .spacer { flex: 1; }
.progress-bar { height: 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: var(--accent); transition: width .6s ease; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; margin: 16px 0 8px; }
.stat-grid div { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; }
.stat-grid dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-grid dd { margin: 2px 0 0; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-grid .is-bad dd { color: var(--danger); }
.rstatus { font-size: 12px; font-weight: 600; }
.rstatus-sent { color: var(--ok); }
.rstatus-failed, .rstatus-complaint, .rstatus-bounce { color: var(--danger); }
.rstatus-queued, .rstatus-sending, .rstatus-skipped, .rstatus-manual { color: var(--muted); }
.public-card h1 { font-size: 22px; margin: 0 0 10px; }
.public-card p { line-height: 1.55; }
@media (max-width: 900px) {
  .send-grid { grid-template-columns: 1fr; }
  .send-preview { position: static; }
}

/* engagement (chart colors validated for CVD + contrast in both modes) */
:root { --series-1: #2a78d6; --series-2: #eb6834; }
@media (prefers-color-scheme: dark) { :root { --series-1: #3987e5; --series-2: #d95926; } }
.engagement { margin-bottom: 20px; }
.engagement h2 { margin-top: 0; }
.engagement-off { margin: 0 0 20px; }
.stat-grid-lead dd { font-size: 26px; }
.stat-grid-lead span { display: block; margin-top: 2px; }
.sub-head { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 20px 0 8px; }
.timeline { margin: 18px 0 0; }
.timeline figcaption { margin-bottom: 8px; }
.tl-plot { position: relative; height: 120px; border-bottom: 1px solid var(--line-2); padding-top: 14px; }
.tl-max { position: absolute; top: 0; left: 0; font-variant-numeric: tabular-nums; }
.tl-bars { display: flex; align-items: flex-end; gap: 2px; height: 100%; }
.tl-bar { flex: 1; height: 100%; display: flex; align-items: flex-end; min-width: 0; cursor: default; }
.tl-bar i { display: block; width: 100%; background: var(--series-1); border-radius: 2px 2px 0 0; min-height: 0; }
.tl-bar:hover i { filter: brightness(1.15); }
.tl-bar:hover { background: var(--surface-2); }
.tl-bar.is-day { box-shadow: inset 1px 0 0 var(--line); }
.tl-bar.is-future i { opacity: 0; }
.tl-axis { display: flex; justify-content: space-between; padding-top: 4px; }
.links-table .link-url { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.links-table .link-url a { color: var(--ink); }
.meter { display: inline-block; width: 60px; height: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; margin-right: 8px; vertical-align: middle; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--series-1); }
.tag-opened, .tag-clicked { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.tag-opened::before, .tag-clicked::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 0; }
.tag-opened::before { background: var(--series-1); }
.tag-clicked::before { background: var(--series-2); }
.stats-summary { margin: 0 0 20px; }
.trend-card { margin-bottom: 20px; }
.trend-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.trend-head h2 { margin: 0; }
.legend { list-style: none; display: flex; gap: 14px; margin: 0; padding: 0; color: var(--ink-2); }
.legend li { display: flex; align-items: center; gap: 6px; }
.key { width: 14px; height: 2px; border-radius: 2px; display: inline-block; }
.key-1 { background: var(--series-1); }
.key-2 { background: var(--series-2); }
.trend { display: block; width: 100%; height: auto; margin: 10px 0 4px; overflow: visible; }
.trend .grid { stroke: var(--line); stroke-width: 1; }
.trend .tick, .trend .end-label { font: 11px var(--sans, system-ui); fill: var(--muted); }
.trend .end-label { fill: var(--ink-2); font-weight: 600; }
.trend .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.trend .line-1 { stroke: var(--series-1); }
.trend .line-2 { stroke: var(--series-2); }
.trend .dot { stroke: var(--surface); stroke-width: 2; }
.trend .dot-1 { fill: var(--series-1); }
.trend .dot-2 { fill: var(--series-2); }
.trend .hit { fill: transparent; }
.trend .hover-rule { stroke: var(--line-2); stroke-width: 1; opacity: 0; }
.trend .pt:hover .hover-rule { opacity: 1; }
.trend .pt:hover .dot { r: 6; }
.stats-table .num div { font-weight: 400; }
.track-opts { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; min-width: 0; }
.track-opts legend { padding: 0; margin-bottom: 4px; font-weight: 600; font-size: 13px; color: var(--ink-2); }
.track-opts .check { align-items: flex-start; }
.track-opts .check input { margin-top: 3px; }
.track-opts .check .small { display: block; overflow-wrap: anywhere; }
@media (max-width: 720px) {
  /* Wide tables scroll sideways instead of clipping their last columns. */
  .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table th, .table td { white-space: nowrap; }
  .links-table .link-url { max-width: 200px; }
}
.trend-scroll { overflow-x: auto; }
.trend-scroll .trend { min-width: 520px; }

/* phase 6: scheduling, seeds, attachments */
.badge-scheduled { background: var(--agent-soft); color: var(--agent); border-color: transparent; }
.danger-text { color: var(--danger); }
.when-opts { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; }
.when-opts legend { margin-bottom: 6px; }
.when-later { display: flex; flex-basis: 100%; flex-wrap: wrap; align-items: center; gap: 8px; }
.when-opts.js:not(.is-later) .when-later { display: none; }
.when-later input[type="datetime-local"] { width: auto; }
.scheduled-when { font-size: 22px; font-weight: 600; margin: 12px 0 2px; }
.attach-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.attach-list li { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.attach-list a { overflow-wrap: anywhere; }
.attach-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.attach-form input[type="file"] { flex: 1 1 200px; min-width: 0; }
.attachments-card h2 { margin-top: 0; }
.seeds-card p { margin: 0 0 6px; }
.seed-list { margin: 0; padding-left: 18px; }
