:root {
  --paper: #f3f5f8; --panel: #fff; --ink: #18212d; --muted: #5d6877; --faint: #8993a1; --line: #dce1e8; --line-soft: #eaeef3;
  --brand: #2347c5; --brand-soft: #e8edfb; --brand-ink: #fff;
  --ok: #17794f; --ok-soft: #e2f4ea; --warn: #9a6200; --warn-soft: #fcf0d6; --bad: #b83227; --bad-soft: #fbe6e3; --info-soft: #e8edfb;
  --radius: 8px; --font: "Avenir Next", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 var(--font); background: var(--paper); color: var(--ink); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 650; } h2 { font-size: 16px; font-weight: 650; } h3 { font-size: 14px; font-weight: 650; }
p { margin: 0 0 10px; } a { color: var(--brand); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12.5px; } .mono { font-family: var(--mono); font-size: 12.5px; }
.right { text-align: right; } .nowrap { white-space: nowrap; }

/* shell */
.shell { display: grid; grid-template-columns: 216px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { font-size: 17px; font-weight: 750; letter-spacing: -0.02em; color: var(--brand); padding: 2px 10px 16px; display: flex; align-items: center; gap: 8px; }
.brand svg { flex: none; }
.side a.nav { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; font-weight: 500; }
.side a.nav:hover { background: var(--paper); }
.side a.nav.on { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
.side .spacer { flex: 1; }
.side .who { font-size: 12px; color: var(--muted); padding: 8px 10px; word-break: break-all; }
.badge-n { background: var(--brand); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 650; min-width: 20px; text-align: center; }
.main { padding: 28px 36px 60px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumb { color: var(--muted); text-decoration: none; font-size: 13px; display: inline-block; margin-bottom: 6px; }
.crumb:hover { color: var(--brand); }

/* controls */
button, .btn { font: inherit; font-weight: 600; border-radius: 6px; padding: 7px 14px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; line-height: 1.3; }
button:hover, .btn:hover { border-color: #c2cad5; background: #fafbfc; }
button.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.primary:hover { background: #1c3ba8; border-color: #1c3ba8; }
button.danger { color: var(--bad); } button.danger:hover { background: var(--bad-soft); border-color: #eab5af; }
button.ghost { border-color: transparent; background: transparent; padding: 5px 8px; color: var(--muted); } button.ghost:hover { background: var(--paper); color: var(--ink); }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
input[type=checkbox], input[type=radio] { width: auto; }
label.f { display: block; margin-bottom: 14px; font-weight: 600; font-size: 13px; }
label.f > span.hint { display: block; font-weight: 400; color: var(--muted); font-size: 12.5px; margin: 1px 0 5px; }
label.f > :is(input, select, textarea) { margin-top: 5px; font-weight: 400; }
label.f > span.hint + :is(input, select, textarea) { margin-top: 0; }
label.chk { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; margin-bottom: 10px; }
.row { display: flex; gap: 12px; } .row > * { flex: 1; min-width: 0; } .row.auto > * { flex: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; } .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

/* surfaces */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.card > h2 { margin-bottom: 4px; } .card > .sub { color: var(--muted); margin-bottom: 14px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line-soft); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { font-size: 12px; font-weight: 600; padding: 1px 9px; border-radius: 10px; background: var(--line-soft); color: var(--muted); white-space: nowrap; display: inline-block; }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); } .pill.info { background: var(--info-soft); color: var(--brand); }
.notice { border-radius: 6px; padding: 10px 14px; margin-bottom: 16px; background: var(--info-soft); color: #1c3a96; }
.notice.warn { background: var(--warn-soft); color: #6b4500; } .notice.bad { background: var(--bad-soft); color: #8a241b; } .notice.ok { background: var(--ok-soft); color: #0f5a39; }
.empty { text-align: center; padding: 42px 20px; color: var(--muted); } .empty h3 { color: var(--ink); margin-bottom: 6px; } .empty .actions { justify-content: center; margin-top: 14px; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--muted); padding: 9px 14px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; } tbody tr.click:hover td { background: #fafbfd; }
.tbl-wrap { overflow-x: auto; }
td.ai-cell { max-width: 320px; font-size: 13px; color: #2a3646; } td.ai-cell.err { color: var(--bad); } td.ai-cell.none { color: var(--faint); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat .l { color: var(--muted); font-size: 12.5px; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 8px; }
.bars .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; gap: 2px; height: 100%; min-width: 0; }
.bars .b { background: var(--brand); border-radius: 3px 3px 0 0; min-height: 0; } .bars .b.r { background: #17794f; }
.bars-x { display: flex; gap: 4px; font-size: 11px; color: var(--faint); margin-top: 4px; } .bars-x span { flex: 1; text-align: center; overflow: hidden; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 10px; } .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.meter { height: 6px; border-radius: 3px; background: var(--line-soft); overflow: hidden; } .meter > div { height: 100%; background: var(--brand); }

/* sequence thread (campaign builder) */
.thread { position: relative; padding-left: 34px; }
.thread::before { content: ""; position: absolute; left: 11px; top: 14px; bottom: 14px; width: 2px; background: var(--line); }
.t-item { position: relative; margin-bottom: 10px; }
.t-dot { position: absolute; left: -34px; top: 14px; width: 24px; height: 24px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; box-shadow: 0 0 0 4px var(--paper); }
.t-wait { position: relative; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.t-wait::before { content: ""; position: absolute; left: -29px; top: 50%; width: 12px; height: 12px; margin-top: -6px; border-radius: 50%; background: var(--paper); border: 2px solid var(--line); }
.t-wait input { width: 64px; padding: 4px 8px; }
.step { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.step .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; }
.step textarea { min-height: 150px; font-size: 14px; }
.vars { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 2px; }
.var { font-family: var(--mono); font-size: 12px; background: var(--paper); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; cursor: pointer; color: #34425a; }
.var:hover { border-color: var(--brand); color: var(--brand); } .var.ai { background: var(--brand-soft); border-color: #cdd8f7; color: var(--brand); }
.preview { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; white-space: pre-wrap; font-size: 14px; line-height: 1.55; }
.preview .subj { font-weight: 650; padding-bottom: 8px; margin-bottom: 10px; border-bottom: 1px solid var(--line-soft); }

/* unibox */
.ub { display: grid; grid-template-columns: 340px 1fr; gap: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); height: calc(100vh - 210px); min-height: 480px; overflow: hidden; }
.ub-list { border-right: 1px solid var(--line); overflow-y: auto; }
.ub-item { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer; display: block; }
.ub-item:hover { background: #fafbfd; } .ub-item.on { background: var(--brand-soft); }
.ub-item .nm { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; } .ub-item.unread .nm { color: #000; } .ub-item.unread .nm::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); flex: none; margin-top: 6px; }
.ub-item .sn { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 2px 0 4px; }
.ub-view { display: flex; flex-direction: column; min-width: 0; }
.ub-head { padding: 14px 20px; border-bottom: 1px solid var(--line-soft); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ub-msgs { flex: 1; overflow-y: auto; padding: 18px 20px; background: #fafbfc; }
.msg { max-width: 82%; margin-bottom: 14px; padding: 10px 14px; border-radius: 10px; background: #fff; border: 1px solid var(--line); white-space: pre-wrap; word-wrap: break-word; }
.msg.out { margin-left: auto; background: var(--brand-soft); border-color: #cdd8f7; }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.ub-reply { border-top: 1px solid var(--line); padding: 12px 16px; background: #fff; } .ub-reply textarea { min-height: 80px; margin-bottom: 8px; }

/* modal + toast */
.scrim { position: fixed; inset: 0; background: rgba(20, 28, 40, .45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; padding: 22px 24px; box-shadow: 0 12px 40px rgba(0, 0, 0, .22); } .modal.wide { max-width: 760px; }
.modal h2 { margin-bottom: 14px; font-size: 18px; } .modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 6px; max-width: 380px; box-shadow: 0 4px 16px #0003; }
.toast.bad { background: var(--bad); }
@media (prefers-reduced-motion: no-preference) { .toast { animation: tin .18s ease-out; } @keyframes tin { from { transform: translateY(6px); opacity: 0; } } }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .box { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 30px; width: 100%; max-width: 400px; }
.auth .brand { padding: 0 0 6px; font-size: 22px; } .auth p.lead { color: var(--muted); margin-bottom: 20px; }

.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } } @media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; } .tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 9px 14px; color: var(--muted); margin-bottom: -1px; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); } .tabs button:hover { background: none; color: var(--ink); }
.check-row { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--line-soft); } .check-row:last-child { border: 0; }
.days { display: flex; gap: 6px; flex-wrap: wrap; } .days label { border: 1px solid var(--line); border-radius: 6px; padding: 5px 11px; cursor: pointer; font-weight: 500; user-select: none; } .days input { display: none; } .days label:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 650; }
.score { font-size: 38px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; } .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 8px; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 4px 8px; } .side .spacer, .side .who { display: none; } .main { padding: 18px 16px 50px; }
  .grid2, .grid3, .row { grid-template-columns: 1fr; flex-direction: column; } .ub { grid-template-columns: 1fr; height: auto; } .ub-list { max-height: 260px; border-right: 0; border-bottom: 1px solid var(--line); }
}
