:root {
  --ink: #1c2733;
  --muted: #707a85;
  --muted2: #52606d;
  --line: #dfe5ea;
  --line2: #eef1f4;
  --soft: #f1f4f6;
  --bg: #ffffff;
  --side: #1c2733;
  --side-ink: #c6d0da;
  --side-mute: #7d8a98;
  --blue: #2a8fd4;
  --blue-ink: #1c5f8f;
  --blue-soft: #eaf4fb;
  --phone: #2a7fc0;
  --wall: #cfe3d0;
  --in: #ffffff;
  --out: #effdde;
  --tick: #4fae4e;
  --danger: #b42318;
  --danger-soft: #fde8e8;
  --warn-ink: #8a6310;
  --warn-soft: #fdf6e3;
  --warn-line: #f0d58a;
  --viber: #7360f2;
  --telegram: #2aa3de;
  --whatsapp: #25a35a;
  --shadow: 0 14px 40px rgba(28, 39, 51, .22);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.4 'Rubik', system-ui, -apple-system, 'Segoe UI', sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; word-break: break-all; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.wrap { flex-wrap: wrap; }
.ell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* кнопки й поля */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; padding: 0 14px; border: 1px solid var(--line); background: #fff; border-radius: 10px; font-size: 14px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #b9c4ce; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 500; }
.btn.primary:hover { background: #237dbb; }
.btn.danger { color: var(--danger); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { width: 40px; padding: 0; color: var(--muted2); }
.btn.on { background: var(--blue-soft); border-color: var(--blue); color: var(--blue-ink); }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted2); margin-bottom: 12px; }
.input, .field input, .field select, .field textarea { height: 44px; border: 1px solid #cdd5dd; border-radius: 12px; padding: 0 12px; font-size: 15px; color: var(--ink); background: #fff; width: 100%; }
.field textarea { height: auto; padding: 10px 12px; resize: vertical; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid rgba(42, 143, 212, .25); border-color: var(--blue); }
.field input:disabled { background: #f5f7f9; color: var(--muted); border-color: #e6ebef; }
.tag { display: inline-flex; align-items: center; gap: 5px; border-radius: 6px; font-size: 11px; font-weight: 500; padding: 2px 7px; white-space: nowrap; }
.pill { display: inline-block; border-radius: 6px; font-size: 12px; padding: 2px 8px; white-space: nowrap; }
.st-new { background: #e3edfb; color: #1d4f99; }
.st-thinking { background: var(--warn-soft); color: var(--warn-ink); }
.st-ordered { background: #dcf3e8; color: #16704f; }
.st-regular { background: #ece4fa; color: #5b2ea6; }
.st-lost { background: #eceff2; color: #52606d; }
.badge { background: var(--blue); color: #fff; border-radius: 99px; font-size: 11px; font-weight: 500; min-width: 20px; height: 20px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.ok { color: #16704f; } .bad { color: var(--danger); }

/* аватарки */
.av { position: relative; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 500; font-size: 16px; flex: none; background: #8a96a2; }
.av img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.av .mb { position: absolute; right: -2px; bottom: -2px; width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; display: grid; place-items: center; }
.av .mb svg { width: 9px; height: 9px; }
.av.sm { width: 28px; height: 28px; font-size: 11px; }
.av.sm .mb { width: 13px; height: 13px; border-width: 1.5px; right: -3px; bottom: -3px; }
.av.sm .mb svg { width: 7px; height: 7px; }
.av.md { width: 40px; height: 40px; font-size: 15px; }
.av.lg { width: 56px; height: 56px; font-size: 20px; }
.av.xl { width: 88px; height: 88px; font-size: 34px; }
.m-viber { background: var(--viber); } .m-telegram { background: var(--telegram); } .m-whatsapp { background: var(--whatsapp); }
.mdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* каркас */
.app { display: flex; height: 100dvh; overflow: hidden; }
.side { width: 200px; flex: none; background: var(--side); color: var(--side-ink); padding: 18px 12px 12px; display: flex; flex-direction: column; gap: 2px; }
.side .logo { color: #fff; font-weight: 600; font-size: 17px; padding: 0 10px 18px; }
.side .nav { display: flex; justify-content: space-between; align-items: center; padding: 10px; border-radius: 10px; color: var(--side-ink); text-decoration: none; font-size: 14px; border: 0; background: none; text-align: left; width: 100%; }
.side .nav:hover { background: #253241; }
.side .nav.on { background: var(--blue); color: #fff; font-weight: 500; }
.side .nav.on .badge { background: #fff; color: var(--blue); }
.side .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-mute); padding: 18px 10px 6px; }
.side .me { display: flex; align-items: center; gap: 10px; padding: 10px; margin-top: auto; border-top: 1px solid #2c3a48; font-size: 14px; color: #fff; border-radius: 0 0 10px 10px; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; width: 100%; }
.side .me:hover { background: #253241; }
.side .me span small { display: block; font-size: 12px; color: var(--side-mute); }
.main { flex: 1; min-width: 0; display: flex; min-height: 0; }
.bottom { display: none; }

/* чати */
.chats { flex: 1; display: flex; min-width: 0; position: relative; }
.list { width: 380px; flex: none; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: #fff; }
.list-head { padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 8px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--soft); border-radius: 22px; padding: 0 14px; height: 42px; color: var(--muted); }
.search:focus-within { background: #fff; box-shadow: inset 0 0 0 2px var(--blue); }
.search input { border: 0; outline: 0; background: transparent; font-size: 15px; width: 100%; color: var(--ink); }
.srow { display: flex; gap: 8px; }
.srow .search { flex: 1; }
.newbtn { width: 42px; height: 42px; flex: none; border: 0; border-radius: 50%; background: var(--blue-soft); color: var(--blue); display: grid; place-items: center; }
.newbtn:hover { background: #dcecf8; }
.search .clear { border: 0; background: none; color: var(--muted); width: 28px; height: 28px; display: grid; place-items: center; }
.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); background: var(--soft); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; border-radius: 8px; padding: 7px; font-size: 14px; color: var(--muted2); }
.seg button.on { background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .1); font-weight: 500; color: var(--ink); }
.chips { display: flex; gap: 6px; align-items: center; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 0 10px; height: 32px; font-size: 13px; color: var(--muted2); display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.chip.on { border-color: var(--blue); background: var(--blue-soft); color: var(--blue-ink); }
.chip b { color: var(--blue); font-weight: 600; }
select.chip { padding-right: 6px; }
.chip.icon { width: 32px; padding: 0; justify-content: center; color: var(--phone); }
.items { flex: 1; overflow-y: auto; border-top: 1px solid var(--line); overscroll-behavior: contain; }
.sec { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: #eef3f7; padding: 8px 14px; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: #3d5a73; text-align: left; position: sticky; top: 0; z-index: 1; }
.sec .car { transition: transform .15s; color: var(--muted2); display: grid; }
.sec.closed .car { transform: rotate(-90deg); }
.sec .dot { width: 9px; height: 9px; border-radius: 3px; }
.sec .cnt { font-weight: 500; color: var(--muted); }
.sec-body { padding: 2px 6px; }
.item { display: flex; gap: 11px; padding: 8px 10px; border-radius: 10px; cursor: pointer; user-select: none; -webkit-touch-callout: none; }
.item:hover { background: #f5f8fa; }
.item.on { background: var(--blue); color: #fff; }
.item.on .av .mb { border-color: var(--blue); }
.item .top { display: flex; justify-content: space-between; gap: 6px; }
.item .name { font-weight: 500; }
.item .time { font-size: 12px; color: #8a96a2; flex: none; }
.item .time.new { color: var(--blue); }
.item .ph { font-size: 12px; color: var(--phone); }
.item .prev { display: flex; justify-content: space-between; gap: 6px; font-size: 13px; color: var(--muted); margin-top: 1px; }
.item .prev.new { color: var(--ink); }
.item .tags { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.item.on .time, .item.on .ph, .item.on .prev { color: rgba(255, 255, 255, .88); }
.item.on .badge { background: #fff; color: var(--blue); }
.item .pin { color: #8a96a2; display: grid; }
.item.on .pin { color: #fff; }
.empty { padding: 30px 20px; text-align: center; color: var(--muted); font-size: 14px; }
.hint { padding: 8px 14px; font-size: 12px; color: var(--muted); }
.res { display: flex; gap: 11px; padding: 10px 12px; border-bottom: 1px solid var(--line2); cursor: pointer; }
.res:hover { background: #f5f8fa; }
.res.on { background: var(--blue-soft); box-shadow: inset 3px 0 0 var(--blue); }
.res .snip { font-size: 13px; color: var(--muted2); margin-top: 2px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
mark { background: #ffe27a; border-radius: 3px; padding: 0 2px; color: inherit; }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--wall); }
.chat-head { height: 64px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 12px 0 16px; background: #fff; border-bottom: 1px solid var(--line); }
.chat-head .who { flex: 1; min-width: 0; cursor: pointer; }
.chat-head .who b { font-weight: 500; }
.chat-head .sub { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.chat-head .back { display: none; }
.stsel { height: 40px; border: 1px solid var(--warn-line); background: var(--warn-soft); color: var(--warn-ink); border-radius: 10px; padding: 0 8px; font-size: 14px; font-weight: 500; }
.bar { margin: 10px 40px 0; background: rgba(255, 255, 255, .88); border-radius: 10px; padding: 8px 12px; font-size: 13px; color: #3d4a57; display: flex; gap: 8px; align-items: center; }
.bar.find { background: #fff8dc; border: 1px solid var(--warn-line); color: #6b5310; }
.bar b { font-weight: 500; color: var(--warn-ink); }
.bar button { border: 0; background: none; color: inherit; text-decoration: underline; padding: 0; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 40px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 13px; color: #fff; background: rgba(40, 70, 50, .45); padding: 3px 12px; border-radius: 99px; margin: 6px 0; }
.msg { align-self: flex-start; background: var(--in); border-radius: 14px 14px 14px 4px; padding: 7px 12px; max-width: min(62%, 560px); box-shadow: 0 1px 1px rgba(0, 0, 0, .12); word-wrap: break-word; }
.msg .tx { white-space: pre-wrap; }
.msg .t { font-size: 11px; color: #8a96a2; float: right; margin: 6px 0 -4px 10px; }
.msg img { max-width: 100%; border-radius: 8px; display: block; margin-bottom: 4px; }
.out { align-self: flex-end; display: flex; align-items: flex-end; gap: 8px; max-width: min(66%, 600px); }
.out .msg { background: var(--out); border-radius: 14px 14px 4px 14px; max-width: none; align-self: auto; }
.out .msg .t { color: var(--tick); }
.msg .by { font-size: 12px; font-weight: 500; }
.msg .err { font-size: 12px; color: var(--danger); margin-top: 3px; clear: both; }
.msg.hl { box-shadow: 0 0 0 3px #f0b429; }
.composer { padding: 0 40px 14px; display: flex; flex-direction: column; gap: 8px; }
.qr { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.qr button { border: 0; background: rgba(255, 255, 255, .92); border-radius: 99px; padding: 6px 12px; font-size: 13px; color: var(--blue-ink); white-space: nowrap; }
.send-row { display: flex; gap: 8px; align-items: flex-end; }
.inputbox { flex: 1; display: flex; align-items: flex-end; background: #fff; border-radius: 14px; padding: 4px 6px 4px 14px; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.inputbox textarea { flex: 1; border: 0; outline: 0; resize: none; font-size: 15px; padding: 11px 0; max-height: 160px; min-height: 44px; background: transparent; line-height: 1.35; }
.sendbtn { width: 52px; height: 52px; border: 0; border-radius: 50%; background: var(--blue); color: #fff; display: grid; place-items: center; flex: none; }
.sendbtn:disabled { opacity: .6; }
.placeholder { flex: 1; display: grid; place-items: center; color: #3d5a47; font-size: 15px; text-align: center; padding: 20px; }

/* картка клієнта (висувна панель) */
.drawer { width: 330px; flex: none; background: #fbfcfd; border-left: 1px solid var(--line); overflow-y: auto; padding: 18px; display: none; }
.chats.card .drawer { display: block; }
.card h4 { margin: 18px 0 8px; font-size: 12px; font-weight: 600; color: var(--muted2); text-transform: uppercase; letter-spacing: .04em; }
.card .hd { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.stbtns { display: flex; flex-wrap: wrap; gap: 6px; }
.stbtns button { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 5px 11px; font-size: 13px; }
.stbtns button.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.gchips { display: flex; flex-wrap: wrap; gap: 6px; }
.gchips button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 4px 10px; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.gchips button .dot { width: 9px; height: 9px; border-radius: 3px; }
.dlg { display: flex; align-items: center; gap: 10px; padding: 9px 10px; background: #fff; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px; cursor: pointer; font-size: 14px; }

/* клієнти та сторінки */
.page { flex: 1; overflow-y: auto; padding: 20px; min-width: 0; }
.page h1 { margin: 0; font-size: 22px; font-weight: 600; }
.page h2 { margin: 26px 0 10px; font-size: 17px; font-weight: 600; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.tbl { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
.tbl table { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; background: #f6f8fa; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line2); font-size: 14px; vertical-align: middle; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #f7fafc; }
.tbl tr.on td { background: var(--blue-soft); }
.clients { flex: 1; display: flex; min-width: 0; }
.clients .drawer { display: block; }
.box { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.box.click { cursor: pointer; } .box.click:hover { border-color: #b9c4ce; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kv > div { background: var(--soft); border-radius: 10px; padding: 10px 12px; }
.kv .k { font-size: 12px; color: var(--muted); }
pre { background: var(--soft); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 12px; margin: 6px 0 0; max-height: 260px; }
details summary { cursor: pointer; }

/* вхід */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: var(--wall); }
.login form { width: 100%; max-width: 400px; background: #fff; border-radius: 20px; padding: 32px; box-shadow: 0 18px 50px rgba(28, 39, 51, .18); }
.login .brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login .brand span { width: 48px; height: 48px; border-radius: 14px; background: var(--side); color: #fff; display: grid; place-items: center; flex: none; }
.pw { display: flex; align-items: center; border: 1px solid #cdd5dd; border-radius: 12px; padding-right: 4px; background: #fff; }
.pw:focus-within { outline: 2px solid rgba(42, 143, 212, .25); border-color: var(--blue); }
.pw input { border: 0 !important; outline: 0 !important; }
.pw button { width: 40px; height: 40px; border: 0; background: none; color: var(--muted); display: grid; place-items: center; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted2); margin: 4px 0 16px; }
.check input { width: 18px; height: 18px; accent-color: var(--blue); }

/* шари: модальні вікна, меню, спливаючі */
.overlay { position: fixed; inset: 0; background: rgba(28, 39, 51, .55); display: grid; place-items: center; padding: 16px; z-index: 30; }
.modal { background: #fff; border-radius: 20px; width: 100%; max-width: 620px; max-height: 92dvh; overflow-y: auto; box-shadow: 0 24px 60px rgba(0, 0, 0, .3); }
.modal .mh { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid #e6ebef; }
.modal .mh h3 { margin: 0; font-size: 19px; font-weight: 600; flex: 1; }
.modal .mb { padding: 20px; }
.modal .mf { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid #e6ebef; background: #fafbfc; border-radius: 0 0 20px 20px; }
.x { width: 40px; height: 40px; border: 0; background: none; color: var(--muted); display: grid; place-items: center; border-radius: 10px; }
.x:hover { background: var(--soft); }
.menu { position: fixed; z-index: 40; width: 250px; background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; }
.menu button { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; border-radius: 8px; padding: 10px 12px; font-size: 14px; text-align: left; color: var(--ink); }
.menu button:hover { background: var(--blue-soft); }
.menu hr { border: 0; height: 1px; background: #e6ebef; margin: 4px 6px; }
.menu .ic { width: 16px; display: grid; place-items: center; color: var(--phone); flex: none; }
.pop { position: fixed; z-index: 40; width: 330px; background: #fff; border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.pop .ph { padding: 14px 16px 8px; }
.pop .gl { padding: 0 8px 8px; display: flex; flex-direction: column; max-height: 280px; overflow-y: auto; }
.pop .gl label { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px; cursor: pointer; }
.pop .gl label:hover { background: #f5f8fa; }
.pop .gl input { width: 18px; height: 18px; }
.pop .gl .dot { width: 12px; height: 12px; border-radius: 4px; }
.pop .new { border-top: 1px solid #e6ebef; padding: 12px 16px 14px; background: #fafbfc; }
.swatches { display: flex; gap: 7px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; border: 0; padding: 0; }
.swatches button.on { border: 3px solid #fff; box-shadow: 0 0 0 2px currentColor; }
.shield { position: fixed; inset: 0; z-index: 35; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 6px; align-items: center; }
#toast div { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 90vw; font-size: 14px; }
.preview { background: #f1f7f1; border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; }

/* планшет */
@media (max-width: 1150px) {
  .drawer { position: absolute; right: 0; top: 0; bottom: 0; z-index: 5; box-shadow: -8px 0 24px rgba(20, 30, 60, .12); }
  .msgs, .composer { padding-left: 20px; padding-right: 20px; }
  .bar { margin-left: 20px; margin-right: 20px; }
  .clients .drawer { display: none; }
  .clients.sel .drawer { display: block; }
}
/* телефон */
@media (max-width: 760px) {
  .side { display: none; }
  .app { flex-direction: column; }
  .bottom { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--line); background: #fff; padding: 4px 0 calc(6px + env(safe-area-inset-bottom)); flex: none; }
  .bottom button { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px; font-size: 11px; color: var(--muted); position: relative; }
  .bottom button.on { color: var(--blue); font-weight: 500; }
  .bottom .badge { position: absolute; top: 0; left: 55%; height: 18px; min-width: 18px; font-size: 10px; }
  .main { min-height: 0; flex: 1; }
  .list { width: 100%; border-right: 0; }
  .chat { display: none; }
  .chats.open .list { display: none; }
  .chats.open .chat { display: flex; }
  .chats.open ~ .bottom, .app.chatopen .bottom { display: none; }
  .chat-head .back { display: grid; }
  .chat-head { padding: 0 6px; gap: 4px; }
  .chat-head .hide-m { display: none; }
  .msgs, .composer { padding-left: 10px; padding-right: 10px; }
  .bar { margin: 8px 10px 0; }
  .msg { max-width: 85%; }
  .out { max-width: 90%; }
  .drawer { width: 100%; border-left: 0; }
  .page { padding: 14px; }
  .tbl { overflow-x: auto; }
  .tbl table { min-width: 640px; }
  .clients .drawer { position: fixed; inset: 0; z-index: 20; }
  .modal { border-radius: 16px; }
}
