/* ===========================================================================
   Чат-виджет (JivoSite-like)
   =========================================================================== */

/* FAB */
.chat-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: var(--z-chat-fab);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(37,99,235,.4);
  transition: transform .2s, box-shadow .2s;
}
.chat-fab:hover { transform: scale(1.1); box-shadow: 0 6px 24px rgba(37,99,235,.5); }
.chat-fab.active { background: var(--text-muted); box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.chat-fab-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  background: var(--danger);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border: 2px solid #fff;
}

/* Slide animation */
.chat-slide-enter-active, .chat-slide-leave-active { transition: opacity .2s, transform .2s; }
.chat-slide-enter-from, .chat-slide-leave-to { opacity: 0; transform: translateY(20px) scale(.95); }

/* Panel */
.chat-panel {
  position: fixed;
  bottom: calc(1.5rem + 60px + 1rem);
  right: 1.5rem;
  z-index: var(--z-chat-panel);
  width: 400px;
  height: 560px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.chat-panel-header {
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border);
  background: var(--primary);
  color: #fff;
  min-height: 48px;
  flex-wrap: nowrap;
}
.chat-panel-header .chat-panel-title { color: #fff; }
.chat-header-icon { opacity: .8; flex-shrink: 0; }
.chat-panel-title {
  font-weight: 600;
  font-size: .88rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-back-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,.8);
  cursor: pointer;
  padding: .25rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
}
.chat-back-btn:hover { color: #fff; }
.chat-close-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  cursor: pointer;
  padding: .25rem;
  margin-left: auto;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
}
.chat-close-btn:hover { color: #fff; }

.chat-status-pill {
  font-size: .65rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.4;
}
.chat-status--OPEN   { background: rgba(255,255,255,.2); color: #fff; }
.chat-status--TAKEN  { background: var(--warning-bg); color: var(--warning-dark); }
.chat-status--CLOSED { background: rgba(255,255,255,.15); color: rgba(255,255,255,.7); }
/* Variant for room list (white background) */
.chat-status-pill--list.chat-status--OPEN   { background: var(--border-light); color: var(--text-muted); }
.chat-status-pill--list.chat-status--TAKEN  { background: var(--warning-bg); color: var(--warning-dark); }
.chat-status-pill--list.chat-status--CLOSED { background: var(--secondary-bg); color: var(--text-secondary); }

/* Chat badge variants (admin table) */
.badge { display: inline-block; font-size: .7rem; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.badge--warning { background: var(--warning-bg); color: var(--warning-dark); }
.badge--info    { background: #dbeafe; color: #1e40af; }
.badge--default { background: var(--border-light); color: var(--text-muted); }
.badge--muted   { background: var(--secondary-bg); color: var(--text-secondary); }
.badge--group   { background: #10b981; color: #fff; }

/* Плавающая кнопка «наверх» */
.scroll-to-top-btn {
  position: fixed;
  right: 1.25rem;
  bottom: 5rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--primary, #4f46e5);
  color: #fff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .18);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.scroll-to-top-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 22px rgba(0, 0, 0, .22);
}
.scroll-to-top-btn .icon {
  width: 22px;
  height: 22px;
}
@media (max-width: 600px) {
  .scroll-to-top-btn {
    right: 0.75rem;
    bottom: 4.5rem;
    width: 40px;
    height: 40px;
  }
}

/* ── Админ: таблица чатов (Чат-центр) ── */
.admin-chat-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.admin-chat-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: .875rem;
}
.admin-chat-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--secondary-bg, #f3f4f6);
  color: var(--text-secondary, #4b5563);
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  text-align: left;
  padding: .55rem .6rem;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  white-space: nowrap;
  vertical-align: middle;
}
.admin-chat-table tbody td {
  padding: .55rem .6rem;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-chat-table tbody tr:hover {
  background: var(--hover-bg, rgba(99, 102, 241, .04));
}
.admin-chat-col--id       { width: 60px; }
.admin-chat-col--type     { width: 100px; }
.admin-chat-col--title    { width: auto; }
.admin-chat-col--status   { width: 110px; }
.admin-chat-col--assignee { width: 180px; }
.admin-chat-col--last     { width: 170px; }
.admin-chat-col--actions  { width: 320px; }

.admin-chat-td--num { text-align: right; font-variant-numeric: tabular-nums; }
.admin-chat-th--num { text-align: right; }
.admin-chat-td--title { font-weight: 500; }
.admin-chat-td--assignee,
.admin-chat-td--last { color: var(--text-secondary, #4b5563); }

.admin-chat-th--sortable {
  cursor: pointer;
  user-select: none;
}
.admin-chat-th--sortable:hover { background: var(--hover-bg, rgba(99, 102, 241, .06)); }
.admin-chat-sort-ind { font-weight: 700; opacity: .8; }
.admin-chat-th--actions { text-align: right; }
.admin-chat-td--actions { text-align: right; }

.admin-chat-actions {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .35rem;
}
.admin-chat-actions .btn { flex: 0 0 auto; }

@media (max-width: 900px) {
  .admin-chat-table { min-width: 960px; }
}

/* Chat tabs */
.chat-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-light);
  padding: 0 .75rem;
  flex-shrink: 0;
}
.chat-tab {
  flex: 1;
  padding: .5rem .25rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  text-align: center;
  position: relative;
  transition: color .15s, border-color .15s;
}
.chat-tab:hover { color: var(--text-on-light); }
.chat-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.chat-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  font-size: .6rem;
  font-weight: 700;
  background: var(--danger-light);
  color: #fff;
  border-radius: 8px;
  padding: 0 4px;
  margin-left: 4px;
  vertical-align: middle;
}
/* Pool avatar */
.chat-room-avatar--channel { background: #8b5cf6; }
.chat-room-avatar--group { background: var(--success); }
.chat-room-avatar--pool { background: var(--warning); }
.chat-room-pool-label { font-size: .7rem; color: var(--warning); font-style: italic; }

/* Body */
.chat-panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* Welcome / Start form */
.chat-start-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1.25rem;
}
.chat-welcome {
  text-align: center;
  margin-bottom: 1.5rem;
}
.chat-welcome-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary-alpha);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto .75rem;
}
.chat-welcome-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 .35rem;
}
.chat-welcome-text {
  font-size: .85rem;
  color: var(--text-secondary);
  margin: 0;
}
.chat-form-fields {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  flex: 1;
}
.chat-start-btn {
  margin-top: auto;
  padding: .7rem 1rem;
  font-size: .95rem;
}

/* Center state (loading/empty) */
.chat-center-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  padding: 2rem 1rem;
  color: var(--text-secondary);
}
.chat-center-state p { margin: 0; font-size: .9rem; }
.chat-empty { text-align: center; color: var(--text-muted); padding: 2rem 1rem; }
.chat-empty-icon { opacity: .5; color: var(--text-muted, #94a3b8); }

/* Room list */
.chat-room-list {
  flex: 1;
  overflow-y: auto;
  padding-top: .25rem;
}
.chat-room-item {
  display: flex;
  gap: .75rem;
  padding: .75rem 1rem;
  cursor: pointer;
  transition: background .1s;
  border-bottom: 1px solid var(--border);
}
.chat-room-item:hover { background: var(--bg); }
.chat-room-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-alpha);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-room-info { flex: 1; min-width: 0; }
.chat-room-item-top {
  display: flex;
  align-items: center;
  gap: .35rem;
  min-width: 0;
}
.chat-room-title {
  font-weight: 500;
  font-size: .9rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-room-time {
  font-size: .7rem;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.chat-room-bottom {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: 2px;
}
.chat-room-preview {
  font-size: .8rem;
  color: var(--text-secondary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-unread-badge {
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
}

/* Conversation */
.chat-conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-typing-bar {
  font-size: .75rem;
  color: var(--text-secondary);
  padding: .25rem 1rem;
  font-style: italic;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: .75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  background: var(--bg);
}
.chat-messages-start {
  text-align: center;
  font-size: .75rem;
  color: var(--text-secondary);
  padding: .5rem 0 1rem;
  opacity: .6;
}
.chat-loading {
  text-align: center;
  padding: .75rem 0;
}
.chat-date-sep {
  text-align: center;
  padding: .75rem 0 .5rem;
}
.chat-date-sep span {
  font-size: .7rem;
  color: var(--text-secondary);
  background: var(--border-light);
  padding: 2px 10px;
  border-radius: 10px;
}

/* Message */
.chat-msg {
  max-width: 78%;
  align-self: flex-start;
  animation: chatMsgIn .15s ease-out;
  margin-right: auto;        /* mssgr-style: чужие тянуть к левому краю */
}
@keyframes chatMsgIn { from { opacity: 0; transform: translateY(4px); } }
.chat-msg--own {
  align-self: flex-end;
  margin-right: 0;
  margin-left: auto;         /* свои — к правому краю */
}
.chat-msg--pending { opacity: .7; }
.chat-msg--system {
  align-self: center;
  max-width: 85%;
}
.chat-msg--system .chat-msg-bubble {
  background: var(--secondary-bg);
  color: var(--text-muted);
  font-size: .75rem;
  text-align: center;
  padding: .3rem .75rem;
  box-shadow: none;
  border: none;
  border-radius: 12px;
}
.chat-msg-author {
  font-size: .7rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 2px;
  padding-left: .75rem;
}
.chat-msg-bubble {
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
  padding: .5rem .75rem;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  border: 1px solid var(--border-light);
}
.chat-msg--own .chat-msg-bubble {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
  border-color: transparent;
}
.chat-msg--failed .chat-msg-bubble {
  border-color: var(--danger);
  background: var(--danger-bg);
}
.chat-msg-text {
  font-size: .9rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg-file {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .6rem;
  margin-top: .35rem;
  min-width: 200px;
  max-width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border-light, #e2e8f0);
  background: rgba(15, 23, 42, .04);
  color: inherit;
  text-decoration: none;
  transition: background .15s, border-color .15s;
}
.chat-msg-text + .chat-msg-file { margin-top: .5rem; }
.chat-msg-bubble > .chat-msg-file:first-child { margin-top: 0; }
.chat-msg-file:hover { background: rgba(15, 23, 42, .07); border-color: rgba(15, 23, 42, .15); text-decoration: none; }
.chat-msg-file-icon { flex-shrink: 0; color: var(--primary); width: 22px; height: 22px; }
.chat-msg-file-meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.chat-msg-file-name { font-size: .82rem; font-weight: 600; color: var(--text-strong, #0f172a); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-msg-file-size { font-size: .7rem; color: var(--text-secondary, #64748b); }
.chat-msg-file-download { flex-shrink: 0; color: var(--text-secondary, #64748b); width: 16px; height: 16px; }
.chat-msg-file:hover .chat-msg-file-download { color: var(--primary); }
/* Own message (синий фон) — инвертируем цвета карточки */
.chat-msg--own .chat-msg-file {
  background: rgba(255,255,255,.14);
  border-color: rgba(255,255,255,.25);
}
.chat-msg--own .chat-msg-file:hover {
  background: rgba(255,255,255,.22);
  border-color: rgba(255,255,255,.4);
}
.chat-msg--own .chat-msg-file-icon,
.chat-msg--own .chat-msg-file-name { color: #fff; }
.chat-msg--own .chat-msg-file-size,
.chat-msg--own .chat-msg-file-download { color: rgba(255,255,255,.8); }
.chat-msg--own .chat-msg-file:hover .chat-msg-file-download { color: #fff; }
.chat-msg-footer {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-top: .15rem;
}
.chat-msg-time { font-size: .65rem; color: var(--text-secondary); }
.chat-msg--own .chat-msg-time { color: rgba(255,255,255,.65); }
.chat-msg-status { display: inline-flex; }
.chat-msg-error { font-size: .7rem; color: var(--danger); }
.chat-retry-btn {
  background: none; border: none;
  color: var(--primary); cursor: pointer;
  font-size: .7rem; text-decoration: underline; padding: 0;
}

/* Closed bar */
.chat-closed-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .75rem 1rem;
  font-size: .85rem;
  color: var(--text-secondary);
  background: var(--secondary-bg);
  border-top: 1px solid var(--border);
}

/* Input bar */
.chat-input-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: .35rem;
  padding: .6rem .75rem;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.chat-input-row {
  display: flex;
  align-items: center;
  gap: .4rem;
}
.chat-attach-btn.is-disabled { opacity: .5; pointer-events: none; }
.chat-attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  padding: 0;
  flex-shrink: 0;
  border-radius: 50%;
  transition: color .15s, background .15s;
}
.chat-attach-btn:hover { color: var(--primary); background: var(--primary-alpha); }
.chat-input-wrap { flex: 1; position: relative; }
.chat-input {
  width: 100%;
  resize: none;
  min-height: 38px;
  max-height: 100px;
  font-size: .9rem;
  font-family: inherit;
  padding: .45rem .75rem;
  border: 1px solid var(--border-light);
  border-radius: 20px;
  outline: none;
  transition: border-color .15s;
  background: var(--bg);
}
.chat-input:focus { border-color: var(--primary); background: var(--bg-card); }
.chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--border-light);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.chat-send-btn.active, .chat-send-btn:hover:not(:disabled) {
  background: var(--primary);
  color: #fff;
}
.chat-send-btn:disabled { cursor: default; opacity: .5; }

.chat-close-text-btn,
.chat-reopen-text-btn {
  border: 1px solid rgba(255,255,255,.4);
  background: rgba(255,255,255,.15);
  color: #fff;
  font-size: .7rem;
  font-weight: 600;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  margin-left: auto;
}
.chat-close-text-btn:hover,
.chat-reopen-text-btn:hover { background: rgba(255,255,255,.3); }

/* Spinner */
.chat-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: chatSpin .6s linear infinite;
}
.chat-spinner--lg { width: 28px; height: 28px; border-width: 3px; }
.chat-spinner--xs { width: 10px; height: 10px; border-width: 1.5px; }
@keyframes chatSpin { to { transform: rotate(360deg); } }

/* WS reconnect */
.chat-reconnect-bar {
  display: flex; align-items: center; gap: .5rem;
  padding: .4rem .75rem; font-size: .75rem;
  background: var(--warning-bg); color: var(--warning-dark); border-bottom: 1px solid var(--warning-border);
}

/* Room info panel */
.chat-room-info-panel {
  padding: .5rem .75rem; font-size: .78rem;
  background: var(--bg-secondary, #f8fafc); border-bottom: 1px solid var(--border, #e2e8f0);
  max-height: 320px; overflow-y: auto;
}
.chat-room-info-row { padding: .15rem 0; }
.chat-info-label { font-weight: 600; color: var(--text-muted, #64748b); margin-right: .25rem; }
.chat-room-members-list { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .25rem; }
.chat-member-tag {
  display: inline-block; padding: .1rem .4rem; border-radius: 4px;
  background: var(--primary-alpha, rgba(59,130,246,.1)); font-size: .7rem;
}
.chat-panel-title--clickable { cursor: pointer; }
.chat-panel-title--clickable:hover { opacity: .8; }
.chat-chevron-icon { opacity: .5; margin-left: 2px; flex-shrink: 0; }
.chat-member-remove-btn {
  background: none; border: none; cursor: pointer; font-size: .85rem;
  color: var(--danger, #ef4444); padding: 0 0 0 3px; line-height: 1; opacity: .6;
}
.chat-member-remove-btn:hover { opacity: 1; }
.chat-add-member { position: relative; }
.chat-add-member-input {
  width: 100%; padding: .3rem .5rem; border: 1px solid var(--border, #e2e8f0);
  border-radius: 4px; font-size: .75rem;
}
.chat-add-member-dropdown {
  position: static; margin-top: .25rem;
  background: var(--bg-card, #fff); border: 1px solid var(--border, #e2e8f0);
  border-radius: 4px; max-height: 150px; overflow-y: auto; box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.chat-add-member-option {
  padding: .35rem .5rem; cursor: pointer; font-size: .75rem;
}
.chat-add-member-option:hover { background: var(--primary-alpha, rgba(59,130,246,.08)); }

/* New chat steps */
.chat-new-chat-btn {
  margin: .6rem .75rem .5rem;
  width: calc(100% - 1.5rem);
}
.chat-new-chat-steps { padding: .5rem .75rem; display: flex; flex-direction: column; gap: .5rem; }
.chat-step-title { font-size: .85rem; font-weight: 600; margin: 0; }
.chat-step-back-btn {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: none;
  border: none;
  padding: .3rem .5rem;
  margin: 0 0 .25rem;
  font-size: .8rem;
  color: var(--text-muted, #64748b);
  cursor: pointer;
  border-radius: var(--radius, 8px);
}
.chat-step-back-btn:hover { color: var(--text-strong, #0f172a); background: rgba(0,0,0,.04); }
.chat-step-back-btn .icon { width: 14px; height: 14px; }

/* Search */
.chat-search-input {
  width: 100%; padding: .4rem .6rem; border: 1px solid var(--border, #e2e8f0);
  border-radius: var(--radius, 8px); font-size: .8rem; margin-bottom: .5rem;
  background: var(--bg-card, #fff);
}
.chat-search-input:focus { border-color: var(--primary); outline: none; }
/* Поиск в корне списка чатов — с боковыми отступами (внутри шагов мастера */
/* `.chat-new-chat-steps` сам даёт padding, там дополнительные отступы не нужны). */
.chat-room-list > .chat-search-input {
  width: calc(100% - 1.5rem);
  margin: 0 .75rem .5rem;
}

/* Upload progress */
.chat-upload-progress {
  position: relative; height: 28px; background: #f1f5f9;
  border-radius: var(--radius, 8px); overflow: hidden; margin: .25rem 0;
}
.chat-upload-progress-bar {
  position: absolute; top: 0; left: 0; height: 100%;
  background: var(--primary, #3b82f6); transition: width .2s;
}
.chat-upload-progress-text {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; font-size: .7rem; font-weight: 600; color: #334155;
}

/* Pool take bar */
.chat-pool-take-bar {
  display: flex; align-items: center; justify-content: center;
  padding: .75rem; border-top: 1px solid var(--border, #e2e8f0);
  background: var(--bg-card, #fff);
}
.chat-return-pool-btn {
  background: none; border: none; cursor: pointer; padding: 2px 4px;
  color: rgba(255,255,255,.7); border-radius: 4px; line-height: 1;
  transition: color .15s, background .15s;
}
.chat-return-pool-btn:hover {
  color: #fff; background: rgba(255,255,255,.15);
}
.chat-mute-toggle {
  background: none; border: 1px solid var(--border, #e2e8f0);
  cursor: pointer; padding: .25rem .5rem; border-radius: 4px;
  font-size: .72rem; display: inline-flex; align-items: center; gap: .3rem;
  color: var(--text, #1e293b); margin-left: .25rem;
}
.chat-mute-toggle:hover { background: var(--bg-secondary, #f1f5f9); }
.chat-muted-icon {
  opacity: .6; margin-left: 4px; vertical-align: middle;
  color: var(--text-muted, #94a3b8);
}
.chat-add-member-empty {
  padding: .5rem; color: var(--text-muted, #94a3b8);
  font-size: .72rem; text-align: center;
}

/* Char counter */
.chat-char-counter {
  position: absolute; bottom: 2px; right: 6px;
  font-size: .6rem; color: var(--text-muted, #94a3b8);
}
.chat-char-limit { color: var(--danger, #ef4444); font-weight: 600; }

/* Slide-down transition */
.chat-slide-down-enter-active, .chat-slide-down-leave-active { transition: all .2s ease; }
.chat-slide-down-enter-from, .chat-slide-down-leave-to { max-height: 0; opacity: 0; overflow: hidden; }
.chat-slide-down-enter-to, .chat-slide-down-leave-from { max-height: 320px; opacity: 1; }

/* Pool filters (chip bar) */
.chat-pool-filters {
  display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .4rem;
  padding: .25rem .75rem 0; align-items: center;
}
.chat-pool-filter-chip {
  background: var(--bg-card, #fff); border: 1px solid var(--border, #e2e8f0);
  color: var(--text, #1e293b); border-radius: 999px;
  padding: .2rem .6rem; font-size: .7rem; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.chat-pool-filter-chip:hover { background: var(--bg-secondary, #f1f5f9); }
.chat-pool-filter-chip--active {
  background: var(--primary, #3b82f6); border-color: var(--primary, #3b82f6);
  color: #fff;
}
.chat-pool-filter-reset {
  background: none; border: none; cursor: pointer; color: var(--text-muted, #94a3b8);
  padding: .1rem .3rem; display: inline-flex; align-items: center; justify-content: center;
}
.chat-pool-filter-reset:hover { color: var(--danger, #ef4444); }

/* Room item: request type tag + helpers count */
.chat-room-type-tag {
  font-size: .68rem; padding: .08rem .4rem;
  background: var(--primary-alpha, rgba(59,130,246,.12));
  color: var(--primary, #3b82f6); border-radius: 4px;
  font-weight: 500;
}
.chat-room-helpers-count {
  display: inline-flex; align-items: center; gap: 2px;
  font-size: .65rem; color: var(--text-muted, #94a3b8);
  margin-left: auto;
}

/* Helpers block in room info */
.chat-helpers-block { flex-direction: column; align-items: flex-start; gap: .35rem; }
.chat-helpers-hint {
  font-size: .68rem; color: var(--text-muted, #94a3b8); font-style: italic;
}
.chat-helpers-empty {
  font-size: .7rem; color: var(--text-muted, #94a3b8);
}
.chat-helpers-list {
  display: flex; flex-wrap: wrap; gap: .3rem;
}
.chat-helper-tag {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .15rem .4rem; border-radius: 4px;
  background: rgba(34, 197, 94, .12); color: #15803d;
  font-size: .7rem;
}
.chat-helper-remove-btn {
  background: none; border: none; cursor: pointer; font-size: .85rem;
  color: #15803d; padding: 0 0 0 2px; line-height: 1; opacity: .6;
}
.chat-helper-remove-btn:hover { opacity: 1; color: var(--danger, #ef4444); }
.chat-add-helper { width: 100%; }

/* Mobile */
@media (max-width: 640px) {
  .chat-fab { bottom: 1rem; right: 1rem; width: 52px; height: 52px; }
  .chat-panel {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%; height: 100%; max-height: 100%;
    border-radius: 0; border: none;
  }
  .chat-tab { font-size: .65rem; white-space: nowrap; padding: .4rem .25rem; }
  .chat-room-info-panel { max-height: 40vh; }
  .chat-input-bar { padding: .75rem; }
}

/* ── UX полировка по ролям (B2–B8) ────────────────────────────── */

/* B2: «застрявшие» заявки в админке */
.status-badge--stale {
  box-shadow: 0 0 0 1px var(--warning, #f59e0b) inset;
}
.status-badge--critical {
  box-shadow: 0 0 0 2px var(--danger, #ef4444) inset;
}

/* B3: адекватная ширина и высота textarea на планшетах/ноутах */
@media (max-width: 1000px) {
  .modal--admin-order { width: min(920px, 94vw); }
  .modal-form { max-width: 94vw; }
  textarea.form-input.textarea-xxl { min-height: 20rem; }
}

/* B4: таблица заказов в админке — горизонтальный скролл на узких экранах */
@media (max-width: 1100px) {
  .admin-table-region { overflow-x: auto; }
  .admin-orders-table { min-width: 960px; }
}

/* B5: «обязательно» в формах клиента — звёздочка заметнее */
.req-mark {
  color: var(--danger, #ef4444);
  font-weight: 700;
  margin-left: 3px;
  font-size: 1.05em;
}

/* B6: видимый focus-ring для icon-only кнопок по клавиатуре */
.search-clear-btn:focus-visible,
.chat-close-btn:focus-visible,
.chat-back-btn:focus-visible,
.chat-attach-btn:focus-visible,
.chat-step-back-btn:focus-visible,
.doctor-conclusion-remove-x:focus-visible,
.admin-combobox-toggle:focus-visible,
.modal-close:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 6px;
}

/* B8: адекватный touch-target на мобиле для кнопок-фильтров */
@media (max-width: 600px) {
  .filter-btn { min-height: 38px; }
}

/* ── Admin orders: компактный тулбар (поиск сверху, фильтры + иконки) ── */
.admin-orders-toolbar {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  padding: .75rem;
  background: var(--bg-card, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: var(--radius, 8px);
  margin-bottom: 1rem;
}
.admin-orders-toolbar__search {
  flex: none;
  width: 100%;
}
.admin-orders-toolbar__search .form-input {
  width: 100%;
  padding-left: 2.5rem;
}
.admin-orders-toolbar__row {
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-wrap: wrap;
}
.admin-orders-toolbar__select {
  flex: 1 1 150px;
  min-width: 140px;
}
.admin-orders-toolbar__actions {
  display: flex;
  gap: .35rem;
  margin-left: auto;
}
.admin-orders-toolbar__meta {
  margin: 0;
  font-size: .8rem;
  color: var(--text-muted, #6b7280);
}
@media (max-width: 640px) {
  .admin-orders-toolbar__actions { margin-left: 0; }
}

/* ── Admin orders: компактная двухэтажная верстка ячеек ────────── */
.admin-cell-stack {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  line-height: 1.25;
}
.admin-cell-stack__main { font-size: .875rem; color: var(--text, #1e293b); }
.admin-cell-stack__sub  { font-size: .75rem;  color: var(--text-muted, #6b7280); }
.admin-cell-stack__ssub { font-size: .7rem;   color: var(--text-muted, #9ca3af); }
.admin-cell-stack__city {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
}
.admin-cell-stack__city .icon--sm { width: .7rem; height: .7rem; flex-shrink: 0; }

/* В стек-ячейке бейдж статуса идёт как __sub, не растягивается на всю ячейку */
.admin-cell-stack .status-badge {
  align-self: flex-start;
}

/* Икон-кнопки действий: компактный квадратик, не прилипают впритык */
.admin-orders-table--compact .admin-td--actions .btn-icon {
  padding: .35rem .45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.admin-orders-table--compact .admin-td--actions .btn-icon .icon {
  margin: 0;
}

/* ── API-ключи клиники (модалка в кабинете клиента) ────────────── */
.api-keys-intro {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin: 0 0 1rem;
  line-height: 1.5;
}

.api-key-create-form {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  margin-bottom: 0.5rem;
}
.api-key-create-form__input { flex: 1; min-width: 0; }
.api-key-create-form__btn { flex-shrink: 0; align-self: stretch; }

.api-keys-section-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text, #1e293b);
  margin: 1.25rem 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.api-keys-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.api-keys-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  border: 1px dashed #e2e8f0;
  border-radius: var(--radius-sm);
}

.api-key-item {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.75rem 0.875rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
}
.api-key-item--revoked {
  opacity: 0.65;
  background: #f1f5f9;
}

.api-key-item__head {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.api-key-item__prefix {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text, #1e293b);
}
.api-key-item__label {
  color: var(--text-muted);
  font-size: 0.85rem;
}
.api-key-item__head .status-badge { margin-left: auto; }

.api-key-item__meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.api-key-item__meta-row + .api-key-item__meta-row { margin-top: 0.15rem; }

.api-key-item__actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.api-key-item__confirm {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  background: #fef2f2;
  border: 1px solid #fecaca;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
}
.api-key-item__confirm-text {
  flex: 1 1 240px;
  min-width: 220px;
  font-size: 0.8rem;
  color: #991b1b;
  line-height: 1.4;
}

.status-badge--api-active {
  background: #ecfdf5;
  color: #166534;
  border: 1px solid #bbf7d0;
}
.status-badge--api-revoked {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* Блок «только что создан» — показ raw-ключа один раз */
.api-key-just-created {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.api-key-just-created__title {
  font-weight: 600;
  color: #166534;
}
.api-key-just-created__keybox {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  background: #fff;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
}
.api-key-just-created__keybox code {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  color: var(--text, #1e293b);
  word-break: break-all;
  align-self: center;
}
.api-key-just-created__hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.api-key-just-created__dismiss { align-self: flex-start; }

/* Вкладки в модалке API */
.api-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid #e2e8f0;
  margin-bottom: 1rem;
}
.api-tab {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.api-tab:hover { color: var(--text, #1e293b); }
.api-tab--active {
  color: var(--primary, #4338ca);
  border-bottom-color: var(--primary, #4338ca);
}

/* Журнал API-вызовов */
.api-log-toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.api-log-toolbar__select {
  flex: 1;
  min-width: 160px;
  max-width: 320px;
}
.form-label--inline {
  margin: 0;
  white-space: nowrap;
  font-size: 0.85rem;
}

.api-log-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 420px;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  background: #fafbfc;
}
.api-log-row {
  display: grid;
  grid-template-columns: 110px 50px 1fr 100px 70px 110px;
  gap: 0.5rem;
  align-items: center;
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  border-bottom: 1px solid #eef2f7;
}
.api-log-row:last-child { border-bottom: 0; }
.api-log-row:hover { background: #fff; }
.api-log-row__time { color: var(--text-muted); white-space: nowrap; }
.api-log-row__method {
  font-weight: 700;
  color: var(--text, #1e293b);
  text-align: center;
}
.api-log-row__endpoint {
  color: var(--text, #1e293b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.api-log-row__status {
  font-weight: 600;
  text-align: center;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.api-log-row__latency { color: var(--text-muted); text-align: right; }
.api-log-row__key { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.api-log-status--ok { background: #ecfdf5; color: #166534; }
.api-log-status--warn { background: #fff7ed; color: #b45309; }
.api-log-status--throttle { background: #fef3c7; color: #92400e; }
.api-log-status--err { background: #fef2f2; color: #991b1b; }

@media (max-width: 640px) {
  .api-log-row {
    grid-template-columns: 90px 40px 1fr 60px;
    grid-template-areas:
      'time method endpoint status'
      'time method endpoint latency';
  }
  .api-log-row__key { display: none; }
  .api-log-row__latency { grid-area: latency; }
}

