:root {
  --bg: #f4f6f9; --panel: #ffffff; --line: #e3e7ee; --text: #1b2230; --muted: #6b7486;
  --primary: #1f6feb; --primary-soft: #e8f0fe; --green: #1a7f37; --green-soft: #e6f4ea;
  --red: #cf222e; --red-soft: #fdecee; --amber: #9a6700; --amber-soft: #fff5d6;
  --violet: #8250df; --violet-soft: #f1eafd; --gray-soft: #eef0f4;
  --c-sent: #1f6feb; --c-replies: #e0823d; --c-int: #1a7f37; --c-app: #8250df;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; }
h1 { font-size: 22px; margin: 0 0 18px; } h2 { font-size: 16px; margin: 0 0 12px; }
a { color: var(--primary); }

.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 8px 14px; border-radius: 9px; font: inherit; cursor: pointer; }
.btn:hover { border-color: #c4cbd8; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--text); width: 100%; }
textarea { resize: vertical; }
label { display: block; font-weight: 600; font-size: 13px; margin: 12px 0 6px; }
label > input, label > select, label > textarea { margin-top: 6px; font-weight: 400; }
.error { color: var(--red); margin-top: 10px; min-height: 18px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); padding: 28px; border-radius: 16px; width: 100%; max-width: 360px; box-shadow: 0 4px 24px rgba(0,0,0,.06); }
.login-card .btn { width: 100%; margin-top: 18px; padding: 11px; }

/* layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 236px; flex-shrink: 0; background: #111827; color: #d5dbe6; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 800; font-size: 17px; padding: 4px 10px 18px; color: #fff; }
.brand.big { color: var(--text); font-size: 22px; padding: 0 0 10px; }
.sidebar nav a { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-radius: 9px; color: #c3cad6; text-decoration: none; margin-bottom: 2px; }
.sidebar nav a:hover { background: #1f2937; color: #fff; }
.sidebar nav a.active { background: #2b3a55; color: #fff; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.sidebar-foot .btn { color: #c3cad6; border-color: #334155; }
.badge { margin-left: auto; background: var(--red); color: #fff; border-radius: 99px; padding: 1px 8px; font-size: 12px; font-weight: 700; }
.view { flex: 1; padding: 24px 28px; min-width: 0; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 30px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.two { grid-template-columns: 2fr 1fr; }
@media (max-width: 1100px) { .two { grid-template-columns: 1fr; } }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart svg { width: 100%; height: 240px; display: block; }
.chart .tip { position: absolute; pointer-events: none; background: #111827; color: #fff; font-size: 12px; padding: 6px 8px; border-radius: 6px; white-space: nowrap; }

.funnel .row { display: grid; grid-template-columns: 130px 1fr 44px; align-items: center; gap: 8px; margin: 7px 0; font-size: 13px; }
.funnel .bar { height: 10px; background: var(--gray-soft); border-radius: 99px; overflow: hidden; }
.funnel .bar > div { height: 100%; background: var(--primary); border-radius: 99px; }
.funnel .n { text-align: right; font-variant-numeric: tabular-nums; }

.list-item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.list-item:last-child { border-bottom: 0; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--gray-soft); color: var(--muted); white-space: nowrap; }
.st-new { background: var(--gray-soft); color: #4b5563; }
.st-contacted { background: var(--primary-soft); color: var(--primary); }
.st-replied { background: var(--amber-soft); color: var(--amber); }
.st-interested { background: var(--green-soft); color: var(--green); }
.st-applied { background: var(--violet-soft); color: var(--violet); }
.st-hired { background: #d1f5dd; color: #0f5d27; }
.st-not_interested, .st-invalid { background: var(--gray-soft); color: #8a93a3; }
.st-opted_out { background: var(--red-soft); color: var(--red); }

/* CRM */
.crm { display: grid; grid-template-columns: 380px 1fr; gap: 16px; height: calc(100vh - 48px); }
.crm .left { display: flex; flex-direction: column; min-height: 0; padding: 0; }
.crm .filters { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.chip.on { background: var(--text); border-color: var(--text); color: #fff; }
.drivers { overflow-y: auto; flex: 1; }
.drow { display: block; padding: 11px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.drow:hover { background: #f8fafc; }
.drow.sel { background: var(--primary-soft); }
.drow.unread .nm { font-weight: 800; }
.drow .top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.drow .preview { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); display: inline-block; flex-shrink: 0; }
.pager { padding: 8px 12px; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); }

.right { display: flex; flex-direction: column; min-height: 0; padding: 0; }
.dhead { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.dbody { display: grid; grid-template-columns: 1fr 300px; flex: 1; min-height: 0; }
.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; background: #fafbfc; }
.msg { max-width: 75%; padding: 9px 12px; border-radius: 14px; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; }
.msg.in { background: #fff; border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { background: var(--primary); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.out.failed { background: var(--red-soft); color: var(--red); }
.msg.out.queued { background: #c9dafc; color: #233; }
.msg .meta { font-size: 11px; opacity: .7; margin-top: 4px; }
.compose { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.compose textarea { min-height: 42px; }
.info { padding: 14px; overflow-y: auto; }
.info label { margin-top: 10px; }
.kv { font-size: 13px; margin: 4px 0; } .kv b { color: var(--muted); font-weight: 500; }
.empty { display: grid; place-items: center; color: var(--muted); height: 100%; padding: 40px; text-align: center; }
@media (max-width: 1250px) { .dbody { grid-template-columns: 1fr; } .info { border-top: 1px solid var(--line); max-height: 260px; } }

/* import */
.drop { border: 2px dashed #c4cbd8; border-radius: var(--radius); padding: 40px; text-align: center; background: #fff; cursor: pointer; transition: .15s; }
.drop.over { border-color: var(--primary); background: var(--primary-soft); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.progress { height: 8px; background: var(--gray-soft); border-radius: 99px; overflow: hidden; min-width: 120px; }
.progress > div { height: 100%; background: var(--green); }
.sample { background: #fafbfc; border: 1px solid var(--line); border-radius: 10px; padding: 12px; white-space: pre-wrap; }
.vars code { background: var(--gray-soft); padding: 1px 6px; border-radius: 5px; cursor: pointer; margin-right: 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 10px 16px; font-weight: 400; }
.checks label { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; }
.checks input { width: auto; }
.actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: #111827; color: #fff; padding: 12px 14px; border-radius: 10px; max-width: 340px; box-shadow: 0 6px 24px rgba(0,0,0,.2); cursor: pointer; animation: slide .2s ease-out; }
.toast b { display: block; margin-bottom: 2px; }
.toast.err { background: var(--red); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .view { padding: 16px; }
  .crm { grid-template-columns: 1fr; height: auto; }
  .crm .drivers { max-height: 50vh; }
}

/* sending control */
.ctl-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.ctl-status { margin-top: 6px; line-height: 1.6; }
.ctl-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; margin-top: 6px; }
.ctl-foot { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.range { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-weight: 400; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; margin: 0; }
.switch input { display: none; }
.switch span { width: 52px; height: 30px; background: #cbd2dc; border-radius: 99px; position: relative; transition: .2s; flex-shrink: 0; }
.switch span::after { content: ''; position: absolute; width: 24px; height: 24px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { left: 25px; }
.alert { background: var(--red-soft); color: #8a1820; border: 1px solid #f3c2c7; border-radius: 10px; padding: 12px 14px; margin: 12px 0 4px; line-height: 1.5; }
.steps { margin: 8px 0 0; padding-left: 20px; line-height: 1.7; }
.toast.err { max-width: 420px; }
.numtable th { white-space: nowrap; }
.numtable td.acts { text-align: right; min-width: 250px; }
.numtable td.acts .btn { margin: 2px 0 2px 4px; }
@media (min-width: 861px) { .app { background: linear-gradient(to right, #111827 236px, var(--bg) 236px); } }

/* ---- phone layout ---- */
.crm > *, .dbody > *, .grid > * { min-width: 0; }
@media (max-width: 860px) {
  .sidebar { padding: 10px 10px 8px; gap: 6px; }
  .brand { padding: 2px 6px 4px; font-size: 16px; }
  .sidebar nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .sidebar nav a { white-space: nowrap; padding: 8px 11px; margin: 0; font-size: 14px; flex-shrink: 0; }
  .sidebar-foot { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 4px; }
  .sidebar-foot .muted { flex: 1 1 100%; }
  .crm { grid-template-columns: minmax(0, 1fr); }
  .dbody { grid-template-columns: minmax(0, 1fr); }
  .chat { border-right: 0; }
  .msgs { max-height: 60vh; }
  .msg { max-width: 88%; }
  .dhead select { max-width: 60vw; }
  .ctl-head .switch { order: -1; }
  .kpi .value { font-size: 26px; }
  .view { padding: 14px; }
}
