/* ═══════════════════════════════════════════════════════════════════════
   Плавающий виджет чата. Покрывает все страницы LIMS, кроме /chat.
   Префикс класса cw- (chat-widget), чтобы не конфликтовать с .chat-* со страницы.

   §06 ТЗ: привязан к токенам. Тёмная тема — БЕЗ отдельных переопределений:
   цвета берутся из var(--surface/--surface-2/--line/--ink*), которые сами
   меняются в [data-theme="dark"] (tokens.css) → виджет совпадает по тону со
   всем продуктом. Радиусы — --r-*, тень панели — --shadow-pop.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── FAB кнопка ───────────────────────────────────────────────── */
/* bottom: 100px — FAB чата НАД глобальной кнопкой «наверх» из base.html
   (#scrollToTopBtn, bottom: 30px, 60×60). Единый правый-нижний стек с
   фиксированным шагом, чтобы кнопки не перекрывались. */
.cw-fab {
  position: fixed; right: 20px; bottom: 100px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: #fff;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  box-shadow: 0 6px 18px var(--accent-glow), var(--shadow-md);
  z-index: 300;
  transition: transform var(--m-fast) var(--ease), background var(--m-fast);
}
.cw-fab:hover { background: var(--accent-hover); transform: translateY(-2px); }
.cw-fab:active { transform: scale(.96); }

.cw-fab-badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--r-full);
  background: var(--bad); color: #fff;
  font-size: .7rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg);
}

/* ── Panel ────────────────────────────────────────────────────── */
/* bottom: 170px = bottom FAB (100) + размер FAB (56) + промежуток ~14 */
.cw-panel {
  position: fixed; right: 20px; bottom: 170px;
  width: 380px; height: min(560px, calc(100vh - 200px));
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  z-index: 299;
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: cw-pop-in var(--m-fast) ease-out;
}
@keyframes cw-pop-in {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.cw-view {
  display: flex; flex-direction: column;
  height: 100%; min-height: 0;
}

/* ── Header ───────────────────────────────────────────────────── */
.cw-hd {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  flex-shrink: 0;
}
.cw-hd-title {
  flex: 1; min-width: 0;
  font-weight: 600; font-size: .9rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cw-hd-actions { display: flex; gap: 2px; flex-shrink: 0; }

.cw-icon-btn {
  width: 30px; height: 30px; flex-shrink: 0;
  border: none; background: none; cursor: pointer;
  color: var(--ink-3);
  border-radius: var(--r-sm); padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; text-decoration: none;
  transition: background var(--m-fast), color var(--m-fast);
}
.cw-icon-btn:hover { background: var(--surface-3); color: var(--ink); }

/* ── Channels list ────────────────────────────────────────────── */
.cw-channels-list { flex: 1; overflow-y: auto; padding: .25rem; }
.cw-channel-item {
  display: flex; align-items: center; gap: .55rem;
  width: 100%; padding: .5rem .6rem;
  border: none; background: none; cursor: pointer; color: inherit;
  border-radius: var(--r-sm); text-align: left;
  transition: background var(--m-fast);
  min-width: 0;
}
.cw-channel-item:hover { background: var(--surface-2); }
.cw-channel-icon {
  width: 28px; height: 28px; flex-shrink: 0;
  border-radius: 50%;
  background: var(--surface-3); color: var(--ink-2);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem;
}
.cw-channel-body { flex: 1; min-width: 0; }
.cw-channel-name {
  font-weight: 500; font-size: .85rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cw-channel-sub { font-size: .7rem; color: var(--ink-3); }
.cw-channel-badge {
  flex-shrink: 0; min-width: 18px; padding: 0 .35em;
  border-radius: var(--r-full);
  font-size: .65rem; font-weight: 700; color: #fff;
  background: var(--accent);
  line-height: 1.4; text-align: center;
}

/* ── Messages ─────────────────────────────────────────────────── */
.cw-messages {
  flex: 1; overflow-y: auto;
  padding: .5rem .75rem;
  display: flex; flex-direction: column; gap: .35rem;
}
.cw-empty {
  text-align: center; padding: 2rem 1rem;
  color: var(--ink-3); font-size: .85rem;
}
.cw-msg {
  display: flex; flex-direction: column;
  max-width: 85%;
}
.cw-msg.mine { align-self: flex-end; }
.cw-msg-bubble {
  padding: .35rem .6rem;
  border-radius: var(--r-md);
  font-size: .82rem; line-height: 1.4;
  white-space: pre-wrap; word-wrap: break-word;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.cw-msg.mine .cw-msg-bubble {
  background: var(--accent); color: #fff; border-color: transparent;
}
.cw-msg.deleted .cw-msg-bubble {
  font-style: italic; opacity: .6;
}
.cw-msg-meta {
  font-size: .65rem; color: var(--ink-3);
  margin: 0 .25rem;
}
.cw-msg.mine .cw-msg-meta { text-align: right; }
.cw-mention {
  background: var(--accent-soft); padding: 0 .2em;
  border-radius: 3px; font-weight: 500;
}
.cw-msg.mine .cw-mention { background: rgba(255,255,255,.25); }

.cw-msg-attach {
  margin-top: .25rem;
  display: flex; flex-direction: column; gap: .25rem;
}
.cw-msg-attach img {
  max-width: 220px; max-height: 160px;
  border-radius: var(--r-sm); cursor: zoom-in;
}
.cw-msg-attach-card {
  display: flex; align-items: center; gap: .4rem;
  padding: .35rem .55rem;
  background: rgba(0,0,0,.05);
  border-radius: var(--r-sm); font-size: .75rem;
  text-decoration: none; color: inherit;
}
.cw-msg.mine .cw-msg-attach-card { background: rgba(255,255,255,.15); color: #fff; }
.cw-msg-attach-card:hover { background: rgba(0,0,0,.1); }

.cw-date-sep {
  text-align: center; font-size: .65rem;
  color: var(--ink-3);
  margin: .5rem 0;
  text-transform: uppercase; letter-spacing: .05em;
}

/* ── Composer ─────────────────────────────────────────────────── */
.cw-composer {
  border-top: 1px solid var(--line);
  padding: .4rem .5rem;
  flex-shrink: 0;
  background: var(--surface);
}
.cw-composer.dragover {
  background: var(--accent-soft);
  outline: 2px dashed var(--accent); outline-offset: -4px;
}
.cw-composer-row {
  display: flex; align-items: flex-end; gap: .25rem;
}
#cwTextarea {
  flex: 1; resize: none;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  padding: .35rem .65rem;
  font: inherit; font-size: .82rem; line-height: 1.4;
  max-height: 100px;
  background: var(--surface-2); color: var(--ink);
}
#cwTextarea::placeholder { color: var(--ink-3); }
#cwTextarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
.cw-send-btn {
  width: 32px; height: 32px;
  border-radius: 50%; border: none;
  background: var(--accent); color: #fff;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem;
  transition: background var(--m-fast);
}
.cw-send-btn:hover { background: var(--accent-hover); }

.cw-attach-preview {
  display: flex; align-items: center; gap: .4rem;
  padding: .3rem .5rem; margin-bottom: .25rem;
  background: var(--surface-2);
  border-radius: var(--r-sm); font-size: .75rem;
}
.cw-attach-preview img { max-height: 28px; max-width: 40px; border-radius: 3px; }
.cw-attach-preview-name {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
