:root{
  --bg:#EEF3F8; --rail:#F6F8FA; --panel:#FFFFFF; --line:#EAEEF2; --soft:#F1F4F7; --soft2:#E3E8EE;
  --text:#17212B; --text2:#3B4652; --muted:#6B7785; --faint:#8996A3;
  --accent:#2F80E0; --accent-ink:#1F6FD1; --accent-soft:#E7F1FC;
  --chat:#E9EFF5; --out:#E3F2EE; --out-meta:#3F6E62; --tick:#0E7C66;
  --red:#E5484D; --red-ink:#C2373C; --red-soft:#FDECEC; --orange:#F08A24; --orange-soft:#FFF1DE; --orange-ink:#8A4B00;
  --green:#1F9D6B; --green-soft:#E3F5EC; --green-ink:#146B49;
  --tg:#2AA0DD; --tg-soft:#E2F3FB; --tg-ink:#1A7FB3; --max:#7B5CE6; --max-soft:#EFEAFD; --max-ink:#5A43C4;
  --yellow-soft:#FFF4CF; --yellow-ink:#5C4A10;
  --shadow:0 12px 32px rgba(23,33,43,.18);
}
*{box-sizing:border-box}
html,body{height:100%}
body{margin:0;background:var(--bg);color:var(--text);font:14px/1.45 Inter,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;-webkit-font-smoothing:antialiased}
button,input,textarea,select{font:inherit;color:inherit}
button{cursor:pointer}
a{color:var(--accent-ink)}
a:hover{color:#174F96}
[hidden]{display:none!important}
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)}
svg{flex-shrink:0}

/* ── общие элементы ── */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;border:0;border-radius:999px;padding:9px 14px;font-weight:600;font-size:13px;background:var(--soft);color:var(--text);white-space:nowrap;min-height:36px}
.btn:hover{background:var(--soft2)}
.btn:disabled{opacity:.5;cursor:default}
.btn.primary{background:var(--accent);color:#fff}
.btn.primary:hover{background:var(--accent-ink)}
.btn.blue{background:var(--accent-soft);color:var(--accent-ink)}
.btn.danger{background:var(--red-soft);color:var(--red-ink)}
.btn.ghost{background:transparent}
.btn.big{padding:12px 20px;font-size:15px;min-height:46px}
.icon-btn{width:36px;height:36px;border-radius:50%;border:0;background:var(--soft);display:inline-flex;align-items:center;justify-content:center;color:#4C5866}
.icon-btn:hover{background:var(--soft2)}
.icon-btn.primary{background:var(--accent);color:#fff}
.input,.textarea,.select{width:100%;border:1.5px solid transparent;background:var(--soft);border-radius:12px;padding:10px 13px;outline:none}
.input:focus,.textarea:focus,.select:focus{border-color:var(--accent);background:#fff}
.textarea{resize:vertical;min-height:80px}
.field{display:flex;flex-direction:column;gap:6px}
.field>span{font-size:12px;font-weight:600;color:var(--muted)}
.field small{color:var(--muted);font-size:12px}
.check{display:flex;gap:10px;align-items:flex-start;cursor:pointer}
.check input{width:18px;height:18px;margin:2px 0 0;accent-color:var(--accent)}
.check small{display:block;color:var(--muted);font-size:12px}
.pill{display:inline-flex;align-items:center;gap:5px;font-size:12px;font-weight:700;padding:2px 9px;border-radius:999px;white-space:nowrap}
.pill.red{background:var(--red);color:#fff}
.pill.green{background:var(--green-soft);color:var(--green-ink)}
.pill.orange{background:var(--orange-soft);color:var(--orange-ink)}
.pill.grey{background:var(--soft2);color:#4C5866}
.pill.yellow{background:var(--yellow-soft);color:var(--yellow-ink)}
.pill.tg{background:var(--tg-soft);color:var(--tg-ink)}
.pill.max{background:var(--max-soft);color:var(--max-ink)}
.dot{width:9px;height:9px;border-radius:50%;display:inline-block;flex-shrink:0}
.muted{color:var(--muted)}
.err{color:var(--red-ink);font-size:13px}
.card{background:#fff;border-radius:16px;padding:14px 16px}
.section-label{font-size:11px;font-weight:700;letter-spacing:.08em;color:var(--muted);text-transform:uppercase}
.empty{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;color:var(--muted);text-align:center;padding:40px 20px;height:100%}
.empty svg{color:#B4C0CC}
.spinner{width:22px;height:22px;border:3px solid var(--soft2);border-top-color:var(--accent);border-radius:50%;animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* ── вход ── */
.login{min-height:100vh;min-height:100dvh;display:flex;align-items:center;justify-content:center;padding:24px 16px}
.login form{width:100%;max-width:380px;background:#fff;border-radius:24px;padding:30px 28px;display:flex;flex-direction:column;gap:16px;box-shadow:0 1px 2px rgba(23,33,43,.06)}
.login .logo{width:52px;height:52px;border-radius:50%;background:var(--accent);display:flex;align-items:center;justify-content:center;color:#fff}
.login h1{margin:0;font-size:24px;font-weight:800}

/* ── каркас ── */
.shell{display:flex;height:100vh;height:100dvh;overflow:hidden}
.rail{width:72px;flex-shrink:0;background:var(--rail);border-right:1px solid var(--line);display:flex;flex-direction:column;align-items:center;padding:16px 0;gap:6px}
.rail .logo{width:42px;height:42px;border-radius:50%;background:var(--accent);display:flex;align-items:center;justify-content:center;color:#fff;margin-bottom:14px}
.rail a{position:relative;width:48px;height:48px;border-radius:14px;display:flex;align-items:center;justify-content:center;color:var(--muted)}
.rail a:hover{background:var(--soft)}
.rail a.on{background:var(--accent-soft);color:var(--accent-ink)}
.rail .badge{position:absolute;top:4px;right:3px;min-width:18px;height:18px;padding:0 4px;border-radius:999px;background:var(--red);color:#fff;font-size:11px;font-weight:700;display:flex;align-items:center;justify-content:center;border:2px solid var(--rail)}
.rail .warn{position:absolute;top:10px;right:10px;width:10px;height:10px;border-radius:50%;background:var(--orange);border:2px solid var(--rail)}
.rail .grow{flex-grow:1}
.rail .me{width:38px;height:38px;border-radius:50%;background:#F2A65A;color:#fff;font-weight:700;font-size:14px;display:flex;align-items:center;justify-content:center;margin-top:8px;border:0}
.main{flex:1;min-width:0;display:flex;overflow:hidden}

/* ── список чатов ── */
.list{width:340px;flex-shrink:0;background:#fff;border-right:1px solid var(--line);display:flex;flex-direction:column;min-height:0}
.list-head{padding:18px 16px 10px;display:flex;flex-direction:column;gap:12px}
.list-head .row{display:flex;justify-content:space-between;align-items:center;gap:8px}
.list-head h2{margin:0;font-size:22px;font-weight:800}
.search{display:flex;align-items:center;gap:8px;background:var(--soft);border-radius:999px;padding:0 14px;color:var(--muted)}
.search input{border:0;background:transparent;outline:none;padding:10px 0;flex:1;min-width:0;color:var(--text)}
.tabs{display:flex;gap:6px;flex-wrap:wrap}
.tab{border:0;background:var(--soft);color:var(--text2);padding:7px 12px;border-radius:999px;font-weight:600;font-size:13px}
.tab.on{background:var(--accent);color:#fff}
.tab.on.red{background:var(--red)}
.chats{overflow-y:auto;flex:1;min-height:0}
.chat-row{display:flex;gap:12px;padding:10px 16px;cursor:pointer;width:100%;border:0;background:transparent;text-align:left}
.chat-row:hover{background:#F7F9FB}
.chat-row.on{background:var(--accent-soft)}
.chat-row .body{flex:1;min-width:0;display:flex;flex-direction:column;gap:3px}
.chat-row .top,.chat-row .bot{display:flex;justify-content:space-between;align-items:center;gap:6px}
.chat-row .name{font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.chat-row .time{font-size:12px;color:var(--muted);flex-shrink:0}
.chat-row .preview{font-size:14px;color:var(--text2);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.chat-row .typing{color:var(--accent-ink);font-style:italic}
.ava{position:relative;flex-shrink:0}
.ava .circle{width:48px;height:48px;border-radius:50%;color:#fff;font-weight:700;display:flex;align-items:center;justify-content:center;font-size:16px}
.ava .net{position:absolute;right:-2px;bottom:-2px;width:18px;height:18px;border-radius:50%;border:2px solid #fff;display:flex;align-items:center;justify-content:center}
.chat-row.on .ava .net{border-color:var(--accent-soft)}
.ava.sm .circle{width:42px;height:42px;font-size:15px}
.ava.lg .circle{width:72px;height:72px;font-size:24px}
.more-row{padding:12px;text-align:center}

/* ── переписка ── */
.conv{flex:1;min-width:0;display:flex;flex-direction:column;background:#fff}
.conv-head{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:10px 18px;border-bottom:1px solid var(--line);min-height:64px}
.conv-head .who{display:flex;align-items:center;gap:12px;min-width:0}
.conv-head .who .t{display:flex;flex-direction:column;gap:2px;min-width:0}
.conv-head .who .n{display:flex;align-items:center;gap:8px;font-weight:700;font-size:16px;min-width:0}
.conv-head .who .n span:first-child{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.conv-head .who .sub{font-size:13px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.conv-head .acts{display:flex;gap:6px;align-items:center;flex-shrink:0}
.back{display:none}
.feed{flex:1;min-height:0;overflow-y:auto;background:var(--chat);padding:14px 22px 18px;display:flex;flex-direction:column;gap:7px}
.day{align-self:center;font-size:12px;font-weight:600;color:#fff;background:rgba(23,33,43,.32);padding:3px 12px;border-radius:999px;margin:6px 0}
.banner{align-self:center;display:flex;align-items:center;gap:8px;background:var(--yellow-soft);border-radius:999px;padding:6px 14px;font-size:12px;color:var(--yellow-ink);text-align:center}
.msg{display:flex;flex-direction:column;max-width:min(520px,78%);position:relative}
.msg.in{align-self:flex-start}
.msg.out{align-self:flex-end}
.bubble{background:#fff;border-radius:18px 18px 18px 6px;padding:8px 13px;font-size:14px;line-height:1.45;overflow-wrap:anywhere;white-space:pre-wrap}
.msg.out .bubble{background:var(--out);border-radius:18px 18px 6px 18px}
.msg.out.pending .bubble{background:rgba(227,242,238,.6)}
.msg.out.failed .bubble{background:#FBEDED;box-shadow:inset 0 0 0 1.5px #F2B8BA}
.msg.deleted .bubble{opacity:.6}
.msg.deleted .text{text-decoration:line-through}
.bubble .from{display:block;font-size:11px;font-weight:700;color:var(--out-meta);white-space:normal}
.msg.in .bubble .from{color:var(--muted)}
.bubble .meta{float:right;margin:6px 0 -4px 10px;font-size:11px;color:var(--faint);display:inline-flex;gap:4px;align-items:center;white-space:nowrap;line-height:1}
.msg.out .bubble .meta{color:var(--out-meta)}
.tick{color:var(--tick);font-weight:700}
.tick.grey{color:var(--faint)}
.quote{border-left:3px solid var(--tick);background:rgba(14,124,102,.07);border-radius:6px;padding:4px 8px;font-size:12px;color:var(--out-meta);margin-bottom:4px;white-space:normal;max-height:4.4em;overflow:hidden}
.msg.in .quote{border-color:var(--accent);background:var(--accent-soft);color:var(--accent-ink)}
.fwd{font-size:12px;color:var(--muted);font-style:italic;display:block;white-space:normal}
.photo{display:block;max-width:100%;max-height:320px;border-radius:12px;margin:-3px -8px 6px;cursor:zoom-in;background:var(--soft)}
.media-video{max-width:100%;max-height:320px;border-radius:12px;display:block;margin-bottom:6px;background:#000}
audio{width:260px;max-width:100%;display:block;margin-bottom:4px;height:40px}
.file{display:flex;align-items:center;gap:10px;background:rgba(23,33,43,.05);border-radius:12px;padding:8px 10px;text-decoration:none;color:var(--text);margin-bottom:4px;white-space:normal}
.file .ic{width:36px;height:36px;border-radius:10px;background:#fff;display:flex;align-items:center;justify-content:center;color:var(--accent-ink);font-size:10px;font-weight:800}
.file .fn{font-weight:600;font-size:13px;overflow-wrap:anywhere}
.file .fs{font-size:12px;color:var(--muted)}
.file-note{font-size:12px;color:var(--muted);font-style:italic;display:block;white-space:normal}
.call{display:flex;align-items:center;gap:8px;font-weight:600}
.call.missed{color:var(--red-ink)}
.msg-err{font-size:12px;color:var(--red-ink);margin-top:4px;display:flex;flex-wrap:wrap;gap:8px;align-items:center;justify-content:flex-end}
.msg-err button{border:0;background:transparent;color:var(--accent-ink);font-weight:700;padding:2px 0;font-size:12px}
.msg-acts{position:absolute;top:-14px;display:none;gap:2px;background:#fff;border-radius:999px;box-shadow:0 4px 14px rgba(23,33,43,.14);padding:3px}
.msg.in .msg-acts{left:8px}
.msg.out .msg-acts{right:8px}
.msg:hover .msg-acts,.msg:focus-within .msg-acts{display:flex}
.msg-acts button{border:0;background:transparent;border-radius:999px;padding:4px 9px;font-size:12px;font-weight:600;color:var(--text2)}
.msg-acts button:hover{background:var(--soft)}
.typing-line{align-self:flex-start;font-size:13px;color:var(--accent-ink);font-style:italic;padding-left:4px}
.load-older{align-self:center}

.composer{padding:10px 14px 12px;display:flex;flex-direction:column;gap:8px;border-top:1px solid var(--line);background:#fff}
.composer .bar{display:flex;align-items:center;gap:10px;background:var(--soft);border-radius:12px;padding:6px 8px 6px 12px;font-size:13px}
.composer .bar .q{flex:1;min-width:0;border-left:3px solid var(--accent);padding-left:8px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.composer .row{display:flex;gap:8px;align-items:flex-end}
.composer textarea{flex:1;resize:none;border:0;background:var(--soft);border-radius:22px;padding:11px 16px;font-size:15px;max-height:180px;min-height:44px;outline:none;line-height:1.4}
.composer textarea:focus{background:#EDF1F5}
.composer .send{width:46px;height:46px}
.composer .note{font-size:12px;color:var(--muted);display:flex;gap:6px;align-items:center;flex-wrap:wrap}
.composer .note .pill{font-weight:600}
.drop{position:absolute;inset:0;background:rgba(47,128,224,.12);border:2px dashed var(--accent);border-radius:12px;display:flex;align-items:center;justify-content:center;font-weight:700;color:var(--accent-ink);pointer-events:none}

/* ── карточка клиента ── */
.side{width:300px;flex-shrink:0;background:var(--rail);border-left:1px solid var(--line);padding:18px 16px;display:flex;flex-direction:column;gap:12px;overflow-y:auto}
.side .head{display:flex;flex-direction:column;align-items:center;gap:6px;padding:6px 0 4px;text-align:center}
.side .head b{font-size:17px;font-weight:800;overflow-wrap:anywhere}
.side .kv{display:flex;justify-content:space-between;gap:10px;font-size:13px}
.side .kv span:first-child{color:var(--muted)}
.side .kv span:last-child{text-align:right;overflow-wrap:anywhere}
.link-danger{border:0;background:transparent;color:var(--red-ink);font-weight:600;font-size:13px;padding:4px 2px;text-align:left}

/* ── страницы: каналы, сотрудники, настройки ── */
.page{flex:1;overflow-y:auto;padding:28px 32px 48px}
.page-inner{max-width:1080px;margin:0 auto;display:flex;flex-direction:column;gap:18px}
.page h1{margin:0;font-size:26px;font-weight:800}
.page-head{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap}
.lead{color:var(--muted);margin:-8px 0 0;max-width:720px}
.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(320px,1fr));gap:14px}
.ch-card{background:#fff;border-radius:18px;padding:16px;display:flex;flex-direction:column;gap:12px}
.ch-card .top{display:flex;gap:12px;align-items:center}
.ch-card .logo{width:46px;height:46px;border-radius:14px;display:flex;align-items:center;justify-content:center;color:#fff;font-weight:800;font-size:13px;flex-shrink:0}
.ch-card .ttl{font-weight:700;font-size:16px;overflow-wrap:anywhere}
.ch-card .sub{font-size:13px;color:var(--muted)}
.ch-card .facts{display:flex;flex-direction:column;gap:5px;font-size:13px;color:var(--text2);background:var(--rail);border-radius:12px;padding:10px 12px}
.ch-card .facts .reason{color:var(--orange-ink)}
.ch-card .acts{display:flex;gap:6px;flex-wrap:wrap}
.add-card{border:2px dashed #CBD5DF;background:transparent;border-radius:18px;min-height:160px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;color:var(--accent-ink);font-weight:700}
.add-card:hover{background:#fff}
table.t{width:100%;border-collapse:collapse;background:#fff;border-radius:16px;overflow:hidden}
table.t th,table.t td{text-align:left;padding:12px 14px;border-bottom:1px solid var(--line);font-size:14px;vertical-align:middle}
table.t th{font-size:12px;color:var(--muted);font-weight:600;background:var(--rail)}
table.t tr:last-child td{border-bottom:0}
.table-wrap{overflow-x:auto;border-radius:16px}
.two{display:grid;grid-template-columns:1fr 1fr;gap:14px}
.stack{display:flex;flex-direction:column;gap:12px}
.alert-row{display:flex;justify-content:space-between;gap:10px;padding:8px 0;border-bottom:1px solid var(--line);font-size:13px}
.alert-row:last-child{border-bottom:0}

/* ── окна ── */
.overlay{position:fixed;inset:0;background:rgba(23,33,43,.38);display:flex;align-items:center;justify-content:center;padding:16px;z-index:50}
.modal{background:#fff;border-radius:22px;width:100%;max-width:460px;max-height:calc(100dvh - 32px);overflow-y:auto;padding:22px;display:flex;flex-direction:column;gap:14px;box-shadow:var(--shadow)}
.modal.wide{max-width:620px}
.modal-head{display:flex;justify-content:space-between;align-items:center;gap:10px}
.modal-head h3{margin:0;font-size:19px;font-weight:800}
.modal-foot{display:flex;justify-content:flex-end;gap:8px;flex-wrap:wrap}
.seg{display:flex;background:var(--soft);border-radius:999px;padding:4px;gap:4px}
.seg button{flex:1;border:0;background:transparent;border-radius:999px;padding:8px 12px;font-weight:600;font-size:13px;color:var(--text2)}
.seg button.on{background:#fff;color:var(--text);box-shadow:0 1px 3px rgba(23,33,43,.12)}
.pick{display:grid;grid-template-columns:1fr 1fr;gap:10px}
.pick button{border:2px solid var(--line);background:#fff;border-radius:16px;padding:14px;display:flex;flex-direction:column;align-items:center;gap:8px;font-weight:700}
.pick button.on{border-color:var(--accent);background:var(--accent-soft)}
.qr-box{display:flex;flex-direction:column;align-items:center;gap:12px;text-align:center}
.qr-box img{width:240px;height:240px;border-radius:16px;background:#fff;border:1px solid var(--line)}
.steps{margin:0;padding-left:20px;color:var(--text2);font-size:13px;display:flex;flex-direction:column;gap:4px;text-align:left}
.lightbox{position:fixed;inset:0;background:rgba(10,14,20,.86);display:flex;align-items:center;justify-content:center;z-index:60;padding:20px;cursor:zoom-out}
.lightbox img{max-width:100%;max-height:100%;border-radius:8px}
#toasts{position:fixed;left:50%;bottom:24px;transform:translateX(-50%);display:flex;flex-direction:column;gap:8px;z-index:80;align-items:center;width:calc(100% - 32px);max-width:480px;pointer-events:none}
.toast{background:var(--text);color:#fff;border-radius:14px;padding:10px 16px;font-size:14px;box-shadow:var(--shadow);pointer-events:auto}
.toast.bad{background:var(--red-ink)}

/* ── узкие экраны ── */
@media (max-width:1180px){ .side{display:none} }
@media (max-width:820px){
  .shell{flex-direction:column-reverse}
  .rail{width:100%;height:60px;flex-direction:row;justify-content:space-around;padding:0 8px;border-right:0;border-top:1px solid var(--line);gap:0;padding-bottom:env(safe-area-inset-bottom)}
  .rail .logo,.rail .grow{display:none}
  .rail .me{margin:0}
  .list{width:100%;border-right:0}
  .main.has-chat .list{display:none}
  .main:not(.has-chat) .conv{display:none}
  .back{display:inline-flex}
  .feed{padding:12px 10px 14px}
  .msg{max-width:88%}
  .conv-head{padding:8px 10px}
  .conv-head .acts .btn span.long{display:none}
  .wait-pill{display:none!important}
  .page{padding:20px 16px 40px}
  .two{grid-template-columns:1fr}
  .grid{grid-template-columns:1fr}
}
