/* Розділ «Чати». Розкладка: список | листування | клієнт */
.ch-help { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); cursor: default; font-size: 15px; }
.ch-help svg { width: 20px; height: 20px; }

.chats {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: 360px minmax(0, 1fr) 400px;
  background: var(--bg);
}
.cl, .cv { min-height: 0; display: flex; flex-direction: column; }
.cl { border-right: 1px solid var(--line); }
.ci { min-height: 0; overflow-y: auto; background: var(--soft-panel); padding: 16px; position: relative; }

.ic-btn {
  position: relative; width: 36px; height: 36px; border: 0; background: none; border-radius: 6px;
  display: inline-grid; place-items: center; color: var(--accent); flex: none;
}
.ic-btn svg { width: 22px; height: 22px; }
.ic-btn:hover { background: var(--soft-panel); }
.ic-btn.on { background: var(--accent-soft); }
.ic-btn.sm { width: 28px; height: 28px; color: var(--muted); }
.ic-btn.sm svg { width: 16px; height: 16px; }
.ic-count {
  position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; border-radius: 8px; background: var(--accent);
  color: #fff; font-size: 11px; line-height: 16px; text-align: center; padding: 0 4px;
}

/* ----- Список ----- */
.cl-head { border-bottom: 1px solid var(--line); }
.cl-bar { display: flex; align-items: center; gap: 4px; padding: 10px 12px 10px 16px; }
.cl-bar .spacer { flex: 1; }
.cl-view {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--accent);
  font-size: 16px; padding: 6px 4px;
}
.cl-view svg { width: 16px; height: 16px; }
.cl-search {
  display: flex; align-items: center; gap: 8px; margin: 0 12px 10px; padding: 0 6px 0 10px; height: 38px;
  border: 1px solid var(--border); border-radius: 6px; color: var(--muted);
}
.cl-search > svg { width: 18px; height: 18px; flex: none; }
.cl-search input { flex: 1; min-width: 0; border: 0; outline: 0; height: 100%; background: none; }
.cl-list { flex: 1; min-height: 0; overflow-y: auto; }
.cl-empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.cl-row {
  display: flex; gap: 12px; padding: 12px 14px 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; position: relative;
}
.cl-row:hover { background: var(--hover); }
.cl-row.active { background: var(--accent-soft); }
.cl-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.av-wrap { position: relative; flex: none; align-self: flex-start; }
.av-wrap .chb { position: absolute; right: -3px; bottom: -3px; box-shadow: 0 0 0 2px var(--surface); }
.av {
  display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 600; flex: none;
  letter-spacing: .5px; user-select: none;
}
.chb { display: inline-grid; place-items: center; border-radius: 50%; flex: none; }
.chb svg { width: 100%; height: 100%; display: block; }
.cl-main { flex: 1; min-width: 0; }
.cl-top { display: flex; align-items: baseline; gap: 8px; }
.cl-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.cl-time { font-size: 12px; color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.pin-mini svg { width: 13px; height: 13px; color: var(--accent); vertical-align: -2px; }
.cl-prev {
  color: var(--muted); font-size: 13px; margin-top: 3px; overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.35;
}
.cl-row.unread .cl-prev { color: var(--text); }
.prev-you { color: var(--muted); }
.prev-ph { display: inline-flex; align-items: center; gap: 4px; }
.prev-ph svg { width: 14px; height: 14px; }
.cl-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.lbl { display: inline-block; border-radius: 3px; padding: 1px 7px; font-size: 12px; white-space: nowrap; }
.cl-side { display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 8px; flex: none; padding: 1px 0 2px; }
.mgr-mini {
  width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border); color: var(--muted);
  font-size: 9px; display: grid; place-items: center; background: var(--surface);
}
.cl-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); }
.cl-dot.on { background: var(--accent); }
mark { background: #ffe14d; color: inherit; padding: 0 1px; border-radius: 2px; }

/* ----- Спливаючі меню ----- */
.pop-wrap { position: relative; }
.ch-pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 20; min-width: 200px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 10px 28px rgba(0,0,0,.14); padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
}
.ch-pop.right { left: auto; right: 0; }
.ch-pop.wide { min-width: 240px; max-height: 60vh; overflow-y: auto; }
.ch-pop.tpl { top: auto; bottom: calc(100% + 6px); width: 340px; }
.pop-title { font-size: 12px; color: var(--muted); padding: 6px 8px 4px; text-transform: uppercase; letter-spacing: .3px; }
.pop-opt {
  display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; text-align: left;
  padding: 7px 8px; border-radius: 4px; color: var(--text);
}
.pop-opt:hover:not(:disabled) { background: var(--panel); }
.pop-opt:disabled { color: var(--faint); cursor: default; }
.pop-opt.cur { font-weight: 600; color: var(--accent); }
.pop-opt.wrap { white-space: normal; line-height: 1.35; }
.pop-opt .cnt { margin-left: auto; color: var(--muted); font-size: 12px; }
.pop-check { display: flex; align-items: center; gap: 8px; padding: 6px 8px; cursor: pointer; border-radius: 4px; }
.pop-check:hover { background: var(--panel); }
.pop-check input { width: 16px; height: 16px; margin: 0; }

/* ----- Листування ----- */
.cv-head {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); min-height: 64px;
}
.cv-head:empty { display: none; }
.av-wrap.sm .chb { right: -2px; bottom: -2px; }
.cv-title { min-width: 0; }
.cv-title b { font-size: 18px; font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cv-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.typing { color: var(--accent); }
.cv-head .spacer { flex: 1; }
.cv-actions { display: flex; align-items: center; gap: 4px; }
.mgr-btn { border: 0; background: none; padding: 3px; border-radius: 50%; display: grid; place-items: center; }
.mgr-btn:hover { background: var(--soft-panel); }
.cv-back, .cv-info { display: none; }

.cv-msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 20px 16px; display: flex; flex-direction: column; gap: 4px; }
.cv-empty { margin: auto; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.cv-empty svg { width: 48px; height: 48px; color: var(--faint); }
.day-sep { text-align: center; margin: 10px 0 4px; }
.day-sep span { font-size: 12px; color: var(--muted); background: var(--panel); padding: 3px 10px; border-radius: 10px; }
.msg { display: flex; gap: 10px; align-items: flex-end; max-width: 78%; }
.msg.first { margin-top: 10px; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; }
.msg-av { width: 32px; flex: none; }
.msg-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg.out .msg-body { align-items: flex-end; }
.msg-meta { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; padding: 0 4px; }
.ticks svg { width: 16px; height: 16px; color: var(--accent); }
.bubble {
  padding: 10px 14px; border-radius: 4px; line-height: 1.45; white-space: normal; overflow-wrap: anywhere; font-size: 14.5px;
}
.msg.in .bubble { background: var(--bubble-in); }
.msg.out .bubble { background: var(--bubble-out); }
.msg-imgs { display: grid; gap: 6px; padding: 8px; border-radius: 4px; background: var(--bubble-in); }
.msg.out .msg-imgs { background: var(--bubble-out); }
.msg-imgs.n1 { grid-template-columns: minmax(0, 260px); }
.msg-imgs.n2 { grid-template-columns: repeat(2, minmax(0, 170px)); }
.msg-imgs.n3 { grid-template-columns: repeat(3, minmax(0, 150px)); }
.msg-imgs img { width: 100%; aspect-ratio: 5 / 6; object-fit: cover; border-radius: 3px; cursor: zoom-in; display: block; background: var(--surface); }
.typing-b { display: inline-flex; gap: 4px; padding: 14px 16px; }
.typing-b i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite; }
.typing-b i:nth-child(2) { animation-delay: .2s; }
.typing-b i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.cv-comp { padding: 0 16px 14px; }
.cv-comp:empty { display: none; }
.att-row { display: flex; gap: 8px; flex-wrap: wrap; padding-bottom: 8px; }
.att-row:empty { display: none; }
.att { position: relative; width: 64px; height: 64px; }
.att img { width: 100%; height: 100%; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); }
.att button {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; border: 0;
  background: #2b2f36; color: #fff; display: grid; place-items: center; padding: 0;
}
.att button svg { width: 12px; height: 12px; }
.comp-box { border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.comp-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.comp-box textarea {
  display: block; width: 100%; border: 0; outline: 0; resize: none; padding: 12px 14px 4px; min-height: 52px; max-height: 140px;
  font-size: 15px; line-height: 1.4; background: none;
}
.comp-bar { display: flex; align-items: center; gap: 4px; padding: 4px 6px 6px 8px; }
.comp-bar .spacer { flex: 1; }
.comp-count { font-size: 13px; color: var(--muted); margin-right: 6px; font-variant-numeric: tabular-nums; }
.send-btn {
  width: 44px; height: 38px; border: 0; border-radius: 6px; background: var(--accent); color: #fff;
  display: grid; place-items: center;
}
.send-btn svg { width: 20px; height: 20px; }
.send-btn:disabled { background: var(--panel); color: var(--faint); cursor: default; }

/* ----- Клієнт ----- */
.ci-empty { color: var(--muted); text-align: center; padding: 40px 10px; }
.ci-close { display: none; position: absolute; top: 8px; right: 8px; color: var(--muted); }
.ci-card, .oc { background: var(--surface); border-radius: 8px; box-shadow: 0 1px 3px rgba(20,40,80,.08); padding: 14px 16px; }
.ci-name { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ci-name b { flex: 1; color: var(--accent); font-size: 18px; font-weight: 600; }
.ci-name .ic-btn { color: var(--muted); }
.ci-rows { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 8px 12px; margin: 0; font-size: 14px; }
.ci-rows dt { color: var(--muted); }
.ci-rows dd { margin: 0; overflow-wrap: anywhere; }
.ci-soc { display: flex; flex-wrap: wrap; gap: 8px 14px; border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; align-items: center; }
.soc { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); font-size: 14px; }
.soc a { color: inherit; }
.soc-del { border: 0; background: none; padding: 0; width: 16px; height: 16px; color: var(--faint); display: none; }
.soc-del svg { width: 14px; height: 14px; }
.soc:hover .soc-del { display: inline-grid; }
.soc-add { display: inline-flex; align-items: center; gap: 4px; border: 1px dashed var(--border); background: none; color: var(--accent); border-radius: 14px; padding: 3px 10px; font-size: 13px; }
.soc-add svg { width: 14px; height: 14px; }
.soc-form { width: 100%; display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 8px; }
.soc-form .ci-edit-btns { grid-column: 1 / -1; }
.ci-edit { display: flex; flex-direction: column; gap: 8px; }
.ci-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.ci-field .inp { font-size: 14px; color: var(--text); }
.ci-edit-btns { display: flex; justify-content: flex-end; gap: 8px; }
.ci-edit-btns .btn { height: 34px; }
.ci-docs-h { font-weight: 600; margin: 20px 0 10px; }
.doc-wrap { margin-bottom: 12px; display: inline-block; }
.doc-btn { display: inline-flex; }
.doc-btn .btn:first-child { border-radius: 3px 0 0 3px; font-weight: 600; }
.doc-caret { border-radius: 0 3px 3px 0; padding: 0 10px; border-left: 1px solid rgba(255,255,255,.5) !important; }
.oc { margin-bottom: 12px; cursor: pointer; }
.oc:hover { box-shadow: 0 2px 10px rgba(20,40,80,.14); }
.oc-title { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 10px; }
.oc-title svg { width: 20px; height: 20px; color: var(--accent); }
.oc-num { color: var(--accent); }
.ci-none { color: var(--muted); font-size: 13px; }
.nc-grid { display: flex; flex-direction: column; gap: 10px; }

.lightbox { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 4px; box-shadow: 0 20px 50px rgba(0,0,0,.4); background: var(--surface); }
.lb-close { position: absolute; top: 16px; right: 16px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.9); display: grid; place-items: center; }
.lb-close svg { width: 22px; height: 22px; }

/* ----- Вужчі екрани ----- */
@media (max-width: 1279px) {
  .chats { grid-template-columns: 320px minmax(0, 1fr); }
  .ci { display: none; position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%); z-index: 40; box-shadow: -10px 0 30px rgba(0,0,0,.15); padding-top: 48px; }
  .chats.info-open .ci { display: block; }
  .ci-close { display: inline-grid; }
  .cv-info { display: inline-grid; }
}
@media (max-width: 820px) {
  .chats { grid-template-columns: minmax(0, 1fr); }
  .chats.has-open .cl { display: none; }
  .chats:not(.has-open) .cv { display: none; }
  .cv-back { display: inline-grid; }
  .cv-head { padding: 8px 10px; gap: 8px; flex-wrap: wrap; }
  .cv-actions { width: 100%; justify-content: flex-end; }
  .cv-msgs { padding: 10px 12px; }
  .msg { max-width: 92%; }
  .msg-imgs.n3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cv-comp { padding: 0 10px 10px; }
  .ch-pop.tpl { width: min(340px, calc(100vw - 40px)); }
}
