:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #0f172a; --ink-2: #334155; --muted: #64748b; --line: #e6e8ee; --line-2: #eef0f4;
  --brand: #4f46e5; --brand-2: #4338ca; --brand-ink: #fff; --brand-soft: #eef2ff; --brand-line: #c7d2fe;
  --red: #dc2626; --red-soft: #fef2f2; --red-line: #fecaca;
  --green: #15803d; --green-soft: #ecfdf3; --amber: #b45309; --amber-soft: #fffbeb; --orange: #c2410c; --orange-soft: #fff4ed;
  --side: #0f172a; --side-ink: #cbd5e1; --side-on: #1e293b;
  --radius: 12px; --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);
  font-size: 14.5px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 1rem/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; font-feature-settings: "cv11", "ss01"; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-2); }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; margin: 0 0 1rem; display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
h2 { font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em; margin: 1.75rem 0 .75rem; }
h3 { font-size: .95rem; font-weight: 650; margin: 0 0 .6rem; }
.muted { color: var(--muted); } .small { font-size: .84rem; } .pad { padding: 16px; }
.ic { flex: none; }

/* shell */
body.app { display: grid; grid-template-columns: 232px 1fr; }
.side { position: sticky; top: 0; height: 100vh; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 18px 12px; gap: 8px; }
.side .brand { display: flex; align-items: center; gap: 10px; color: #fff; padding: 4px 10px 18px; font-size: 1rem; letter-spacing: -.01em; }
.side .brand b { font-weight: 700; }
.logo { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; font-weight: 800; font-size: .95rem; box-shadow: 0 4px 12px rgba(99, 102, 241, .45); }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side nav a, .side .me a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 9px; color: var(--side-ink); font-weight: 500; }
.side nav a:hover, .side .me a:hover { background: var(--side-on); color: #fff; }
.side nav a.on { background: var(--side-on); color: #fff; box-shadow: inset 3px 0 0 #818cf8; }
.side .me { display: flex; align-items: center; gap: 4px; border-top: 1px solid #1e293b; padding-top: 12px; }
.side .me a { flex: 1; min-width: 0; }
.side .me a span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 9px; background: transparent; color: var(--side-ink); cursor: pointer; }
.icon-btn:hover { background: var(--side-on); color: #fff; }
main { padding: 28px 36px 64px; max-width: 1240px; width: 100%; margin: 0 auto; min-width: 0; }
.inline { display: inline; margin: 0; }
.empty { color: var(--muted); padding: 40px 24px; text-align: center; background: var(--panel); border: 1px dashed #d5d9e2; border-radius: var(--radius); }

/* avatars */
.av { display: inline-grid; place-items: center; flex: none; width: 38px; height: 38px; border-radius: 50%; font-weight: 650; font-size: .82rem; color: #fff; background: #94a3b8; letter-spacing: .02em; }
.av.sm { width: 28px; height: 28px; font-size: .72rem; background: #6366f1; }
.av.c0 { background: #6366f1; } .av.c1 { background: #0ea5e9; } .av.c2 { background: #10b981; } .av.c3 { background: #f59e0b; }
.av.c4 { background: #ec4899; } .av.c5 { background: #8b5cf6; } .av.c6 { background: #14b8a6; } .av.c7 { background: #f97316; }

/* forms */
input, select, textarea, button, .btn { font: inherit; }
input:not([type=checkbox]):not([type=file]), select, textarea { width: 100%; padding: 9px 12px; border: 1px solid #d8dce4; border-radius: var(--radius-sm); background: #fff; color: var(--ink); transition: border-color .15s, box-shadow .15s; }
input[type=file] { width: 100%; padding: 18px; border: 1.5px dashed #c9cfda; border-radius: var(--radius); background: #fafbfc; cursor: pointer; }
select { appearance: none; padding-right: 34px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .15); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); }
label { display: block; font-weight: 550; color: var(--ink-2); font-size: .92rem; }
label > input, label > select, label > textarea { margin-top: 6px; font-weight: 400; font-size: 1rem; }
label.check { display: flex; gap: 10px; align-items: center; font-weight: 500; margin: 6px 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; }
label.check:has(input:checked) { border-color: var(--brand-line); background: var(--brand-soft); }
label.short { display: flex; align-items: center; gap: 8px; font-weight: 450; white-space: nowrap; color: var(--muted); }
label.short input { width: 72px; margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px 18px; margin: 0; }
legend { font-weight: 650; padding: 0 6px; color: var(--ink); }
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border: 1px solid #d8dce4; border-radius: var(--radius-sm); background: #fff; color: var(--ink); font-weight: 550; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s; box-shadow: var(--shadow); }
button:hover, .btn:hover { background: #f8fafc; border-color: #c5cbd6; color: var(--ink); }
button.primary, .btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); box-shadow: 0 1px 2px rgba(79, 70, 229, .3); }
button.primary:hover, .btn.primary:hover { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
button.danger { color: var(--red); border-color: var(--red-line); }
button.danger:hover { background: var(--red-soft); }
button.link { background: none; border: 0; padding: 0; color: var(--brand); box-shadow: none; font-weight: 500; }
button.link.danger { color: var(--red); }
button.small { padding: 6px 12px; font-size: .88rem; }
button:disabled { opacity: .55; cursor: default; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row input { width: auto; flex: 1; min-width: 200px; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.head h1 { margin: 0; }

/* cards and layout */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 14px 0; box-shadow: var(--shadow); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card.narrow { max-width: 580px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid2 > .card { margin: 0; }
.grid2.wide-left { grid-template-columns: 3fr 2fr; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.steps .step { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: end; margin-top: 12px; }
.steps-list { list-style: none; padding: 0; margin: 0 0 18px; display: flex; flex-wrap: wrap; gap: 8px; }
.steps-list li { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-size: .9rem; }
body.bare main { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; background: radial-gradient(1200px 600px at 50% -10%, #e0e7ff, transparent), var(--bg); }
.auth { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px; box-shadow: var(--shadow-lg); }
.auth .brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 24px; font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; }
.auth .brand .logo { width: 44px; height: 44px; border-radius: 12px; font-size: 1.25rem; }
.auth .brand b { color: var(--brand); }
.auth button.primary { width: 100%; padding: 11px; }
.flash { background: var(--brand-soft); border: 1px solid var(--brand-line); color: #3730a3; padding: 11px 16px; border-radius: var(--radius-sm); margin-bottom: 18px; font-weight: 500; }
.flash.error { background: var(--red-soft); border-color: var(--red-line); color: #991b1b; }
.pager { margin: 16px 0; display: flex; gap: 14px; align-items: center; color: var(--muted); }

/* tables */
table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
th { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: #fafbfc; border-bottom-color: var(--line); }
tbody tr { transition: background .1s; }
tbody tr:hover { background: #fafbff; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.clip { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr.dim td { color: var(--muted); }
td a { font-weight: 550; }
.card table { border: 0; box-shadow: none; border-radius: 0; }
.card table th { background: transparent; }
.counts { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin: 14px 0 22px; }
.counts > div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.counts dt { color: var(--muted); font-size: .8rem; font-weight: 500; }
.counts dd { margin: 4px 0 0; font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.counts dd small { font-size: .8rem; color: var(--muted); font-weight: 500; letter-spacing: 0; }

/* pills */
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: .74rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: #f1f5f9; color: var(--ink-2); vertical-align: middle; line-height: 1.3; }
.pill.red, .s-do_not_contact { background: var(--red-soft); color: var(--red); }
.s-not_interested { background: #f1f5f9; color: #475569; }
.s-hot { background: var(--orange-soft); color: var(--orange); }
.s-hot::before { content: "●"; font-size: .6rem; }
.s-interested { background: var(--green-soft); color: var(--green); }
.s-nurture { background: var(--amber-soft); color: var(--amber); }
.s-wrong_number { background: #f1f5f9; color: var(--muted); }
.c-draft { background: #f1f5f9; color: var(--muted); }
.c-running { background: var(--green-soft); color: var(--green); }
.c-running::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.6s infinite; }
.c-scheduled { background: var(--brand-soft); color: var(--brand); }
.c-paused { background: var(--amber-soft); color: var(--amber); }
.c-stopped { background: var(--red-soft); color: var(--red); }
.c-completed { background: #f1f5f9; color: var(--ink-2); }
@keyframes pulse { 50% { opacity: .35; } }

/* template editor */
.meta { display: block; margin-top: 4px; font-weight: 450; }
.meta.warn { color: var(--amber); }
.previews .pv { background: #f1f5f9; border-radius: 16px 16px 16px 4px; padding: 11px 14px; margin: 12px 0; white-space: pre-wrap; max-width: 92%; }
.previews .pv b { display: block; font-size: .74rem; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .04em; }
.warnbox { background: var(--amber-soft); color: var(--amber); border: 1px solid #fde68a; padding: 9px 12px; border-radius: var(--radius-sm); margin: 10px 0; font-size: .9rem; }
.qr-list { list-style: none; padding: 0; margin: 0; }
.qr-list li { border-bottom: 1px solid var(--line-2); padding: 12px 0; }
.qr-list li:first-child { padding-top: 0; }
.qr-list li:last-child { border-bottom: 0; }
.qr-list p { margin: 4px 0; white-space: pre-wrap; color: var(--ink-2); }

/* inbox */
main:has(.inbox) { max-width: none; padding: 0; }
.inbox { display: grid; grid-template-columns: 360px 1fr 300px; height: 100vh; }
.convs { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.convs-head { padding: 18px 16px 8px; }
.convs-head h1 { font-size: 1.25rem; margin: 0 0 12px; }
.filters { display: flex; gap: 6px; padding: 0 16px 12px; overflow-x: auto; scrollbar-width: none; flex-wrap: wrap; }
.filters button { padding: 5px 11px; font-size: .8rem; border-radius: 999px; box-shadow: none; font-weight: 550; color: var(--ink-2); background: #f1f5f9; border-color: transparent; }
.filters button:hover { background: #e2e8f0; }
.filters button.on { background: var(--ink); color: #fff; }
.filters .n:not(:empty) { margin-left: 4px; font-weight: 700; color: var(--brand); }
.filters button.on .n { color: #a5b4fc; }
#conv-search { margin: 0; padding-left: 36px; background: #f8fafc url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 12px center; }
.conv-list { list-style: none; margin: 0; padding: 0 8px 8px; overflow-y: auto; flex: 1; border-top: 1px solid var(--line-2); }
.conv-list li.c { padding: 12px 10px; border-radius: 10px; cursor: pointer; display: grid; grid-template-columns: auto 1fr auto; gap: 1px 12px; margin-top: 4px; }
.conv-list li.c:hover { background: #f8fafc; }
.conv-list li.c.on { background: var(--brand-soft); }
.conv-list .av { grid-row: span 3; align-self: start; }
.conv-list .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-list li.unread .who { font-weight: 700; }
.conv-list li.unread .t { color: var(--brand); font-weight: 600; }
.conv-list li.unread .snip { color: var(--ink); }
.conv-list .t { font-size: .76rem; color: var(--muted); white-space: nowrap; }
.conv-list .snip { grid-column: 2 / -1; color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-list .tags { grid-column: 2 / -1; display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.conv-list .tags:empty { display: none; }
.conv-list .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); display: inline-block; margin-left: 6px; vertical-align: middle; }
.thread { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.thread .th-head { padding: 14px 20px; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.thread .th-head .grow { flex: 1; min-width: 0; }
.thread .th-head h2 { margin: 0; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.msgs { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 68%; padding: 10px 14px; border-radius: 18px; overflow-wrap: anywhere; box-shadow: var(--shadow); }
.msg .mb { white-space: pre-wrap; }
.msg.in { background: var(--panel); align-self: flex-start; border-bottom-left-radius: 6px; }
.msg.out { background: linear-gradient(135deg, #4f46e5, #6366f1); color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; }
.msg .mt { display: block; font-size: .72rem; opacity: .75; margin-top: 5px; }
.msg.out.bad { background: #fff; color: var(--ink); border: 1px solid var(--red-line); }
.msg.out.bad .mt { color: var(--red); opacity: 1; }
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 12px 16px; }
.composer textarea { min-height: 70px; border-radius: 12px; }
.composer .row { margin-top: 10px; justify-content: space-between; }
.composer select { width: auto; }
.optedout { padding: 14px 20px; background: var(--red-soft); color: #991b1b; border-top: 1px solid var(--red-line); font-weight: 500; }
.details { border-left: 1px solid var(--line); background: var(--panel); padding: 20px 18px; overflow-y: auto; }
.details h3 { margin-top: 22px; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.details h3:first-of-type { margin-top: 0; }
.details dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: .9rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }
.details ul.plain { list-style: none; padding: 0; margin: 0; font-size: .9rem; }
.notes { list-style: none; padding: 0; margin: 10px 0 0; }
.notes li { background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; font-size: .9rem; white-space: pre-wrap; }
.notes li .mt { display: block; color: var(--muted); font-size: .74rem; margin-top: 4px; }
.back, .details-btn { display: none; }

@media (max-width: 1180px) {
  .details-btn { display: inline-flex; }
  .inbox { grid-template-columns: 320px 1fr; }
  .details { display: none; }
  .inbox.show-details .details { display: block; position: fixed; right: 0; top: 0; bottom: 0; width: min(340px, 100vw); z-index: 20; box-shadow: var(--shadow-lg); }
}
@media (max-width: 900px) {
  body.app { display: block; }
  .side { position: sticky; top: 0; z-index: 10; height: auto; flex-direction: row; align-items: center; padding: 8px 10px; gap: 4px; overflow-x: auto; scrollbar-width: none; }
  .side .brand { padding: 0 6px 0 2px; }
  .side .brand > span:last-child { display: none; }
  .side nav { flex-direction: row; flex: none; }
  .side nav a { padding: 8px 10px; gap: 8px; }
  .side nav a span { display: none; }
  .side nav a.on span { display: inline; }
  .side .me { border: 0; padding: 0; margin-left: auto; }
  .side .me a span:last-child { display: none; }
  .inbox { height: calc(100vh - 54px); }
}
@media (max-width: 760px) {
  main { padding: 18px 16px 48px; }
  .grid2, .grid2.wide-left { grid-template-columns: 1fr; }
  .inbox { grid-template-columns: 1fr; }
  .inbox .thread { display: none; }
  .inbox.open .convs { display: none; }
  .inbox.open .thread { display: flex; }
  .back { display: inline-flex; }
  .msgs { padding: 16px; }
  .msg { max-width: 86%; }
  table { display: block; overflow-x: auto; }
  .counts { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 901px) { body.app { background: linear-gradient(to right, var(--side) 232px, var(--bg) 232px); } }
.card td:first-child { white-space: nowrap; }
