.chat-container {
  display: flex;
  height: calc(100vh - var(--ib-topbar-h) - var(--ib-footer-h) - 48px);
  width: 100%;
  background: var(--ib-surface-card);
  border: 1px solid var(--ib-outline-light);
  border-radius: var(--ib-radius-lg);
  overflow: hidden;
  box-shadow: var(--ib-shadow-md);
  position: relative;
}
.chat-sidebar { width: 320px; min-width: 280px; max-width: 400px; border-right: 1px solid var(--ib-outline-light); display: flex; flex-direction: column; background: var(--ib-surface-card); }
.chat-sidebar-tabs { display: flex; border-bottom: 1px solid var(--ib-outline-light); background: var(--ib-surface); }
.tab-btn { flex: 1; padding: 12px 16px; border: none; background: transparent; cursor: pointer; font-size: var(--ib-text-sm); font-weight: 600; color: var(--ib-on-surface-muted); transition: all var(--ib-transition); }
.tab-btn:hover { background: var(--ib-surface-hover); color: var(--ib-on-surface); }
.tab-btn.active { color: var(--ib-primary); background: var(--ib-surface-card); border-bottom: 2px solid var(--ib-primary); }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.connection-status { position: absolute; top: 8px; right: 8px; padding: 4px 12px; border-radius: var(--ib-radius-full); font-size: 11px; font-weight: 600; z-index: 1000; }
.connection-status.connecting { background: var(--ib-warning-bg); color: var(--ib-warning); }
.connection-status.disconnected { background: var(--ib-error-bg); color: var(--ib-error); }

.chat-list { width: 100%; height: 100%; display: flex; flex-direction: column; background: var(--ib-surface-card); }
.chat-list-header { padding: 16px; border-bottom: 1px solid var(--ib-outline-light); display: flex; justify-content: space-between; align-items: center; background: var(--ib-surface); }
.chat-list-header h2 { margin: 0; font-size: var(--ib-text-lg); font-weight: 700; color: var(--ib-on-surface); }
.refresh-btn { background: var(--ib-surface-hover); border: none; font-size: 16px; cursor: pointer; padding: 6px 10px; border-radius: var(--ib-radius-sm); color: var(--ib-on-surface-muted); transition: all var(--ib-transition); }
.refresh-btn:hover { background: var(--ib-primary-light); color: var(--ib-primary); }
.chat-list-loading,.chat-list-error,.chat-list-empty { padding: 24px; text-align: center; color: var(--ib-on-surface-muted); font-size: var(--ib-text-sm); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.chat-list-error { color: var(--ib-error); }
.chat-list-error p { margin: 0; max-width: 240px; line-height: 1.5; }
.chat-list-error .user-list-retry,
.chat-error .user-list-retry { border: 1px solid var(--ib-primary); background: var(--ib-primary); color: #fff; border-radius: var(--ib-radius-sm); padding: 8px 14px; font-size: var(--ib-text-sm); font-weight: 600; cursor: pointer; }
.chat-list-error .user-list-retry:hover,
.chat-error .user-list-retry:hover { background: #b91c1c; }
.chat-list-items { flex: 1; overflow-y: auto; }
.chat-list-item { padding: 12px 16px; border-bottom: 1px solid var(--ib-outline-light); cursor: pointer; display: flex; align-items: center; transition: background var(--ib-transition); }
.chat-list-item:hover { background: var(--ib-surface-hover); }
.chat-list-item.selected { background: var(--ib-primary-light); border-left: 3px solid var(--ib-primary); }
.chat-item-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--ib-secondary); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--ib-text-md); margin-right: 12px; flex-shrink: 0; }
.chat-item-content { flex: 1; min-width: 0; }
.chat-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.chat-item-name { font-weight: 600; color: var(--ib-on-surface); font-size: var(--ib-text-sm); }
.chat-item-time { font-size: 11px; color: var(--ib-on-surface-subtle); white-space: nowrap; }
.chat-item-footer { display: flex; justify-content: space-between; align-items: center; }
.chat-item-preview { font-size: var(--ib-text-xs); color: var(--ib-on-surface-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.chat-item-unread { background: var(--ib-primary); color: white; border-radius: var(--ib-radius-full); padding: 2px 8px; font-size: 10px; font-weight: 700; margin-left: 8px; min-width: 20px; text-align: center; }

.chat-window { flex: 1; display: flex; flex-direction: column; background: var(--ib-surface-card); height: 100%; }
.chat-window-empty { flex: 1; display: flex; align-items: center; justify-content: center; background: var(--ib-surface); }
.empty-state { text-align: center; color: var(--ib-on-surface-muted); }
.empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.chat-window-header { padding: 14px 16px; border-bottom: 1px solid var(--ib-outline-light); display: flex; align-items: center; gap: 12px; background: var(--ib-surface-card); z-index: 10; }
.chat-header-info { display: flex; align-items: center; gap: 12px; flex: 1; }
.chat-header-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--ib-secondary); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--ib-text-sm); }
.chat-header-name { font-weight: 700; font-size: var(--ib-text-md); color: var(--ib-on-surface); margin-bottom: 2px; }
.chat-header-status { font-size: var(--ib-text-xs); }
.chat-header-status.online { color: var(--ib-success); }
.chat-header-status.offline { color: var(--ib-on-surface-subtle); }
.chat-error { padding: 10px 16px; background: var(--ib-error-bg); color: var(--ib-error); display: flex; justify-content: space-between; align-items: center; font-size: var(--ib-text-sm); }
.chat-policy-warning {
  padding: 10px 16px;
  background: #fff7ed;
  color: #9a3412;
  border-bottom: 1px solid #fdba74;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  font-size: var(--ib-text-sm);
  font-weight: 600;
  line-height: 1.4;
}
.chat-policy-warning__dismiss {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
}
.load-more-container { display: flex; justify-content: center; padding: 8px 0; background: var(--ib-surface); border-top: 1px solid var(--ib-outline-light); }
.load-more-btn { border: 1px solid var(--ib-outline); background: var(--ib-surface-card); color: var(--ib-on-surface-muted); border-radius: var(--ib-radius-full); padding: 6px 16px; font-size: var(--ib-text-xs); font-weight: 600; cursor: pointer; transition: all var(--ib-transition); }
.load-more-btn:hover { border-color: var(--ib-primary); color: var(--ib-primary); }
.load-more-btn:disabled { opacity: .5; cursor: not-allowed; }

.message-list { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; background: var(--ib-surface); display: flex; flex-direction: column; gap: 8px; scroll-behavior: auto; }
.message-list-end { width: 100%; height: 1px; flex: 0 0 1px; }
.message-list-loading,.message-list-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--ib-on-surface-muted); font-size: var(--ib-text-sm); }
.message-item { display: flex; align-items: flex-end; margin-bottom: 4px; }
.message-item.own { justify-content: flex-end; }
.message-item.other { justify-content: flex-start; }
.message-content-wrapper { max-width: 70%; display: flex; flex-direction: column; position: relative; }
.message-bubble { padding: 10px 14px; border-radius: 16px; word-wrap: break-word; position: relative; width: 100%; }
.message-bubble.own-bubble { background: var(--ib-primary); color: white; border-bottom-right-radius: 4px; }
.message-bubble.other-bubble { background: var(--ib-surface-card); color: var(--ib-on-surface); border-bottom-left-radius: 4px; box-shadow: var(--ib-shadow); border: 1px solid var(--ib-outline-light); }
.message-text { font-size: var(--ib-text-sm); line-height: 1.45; white-space: pre-wrap; }
.message-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; gap: 8px; }
.message-time { font-size: 10px; margin-top: 4px; opacity: .7; display: flex; align-items: center; gap: 4px; }
.read-indicator.sent { opacity: .5; }
.message-item.pinned { background-color: var(--ib-primary-light); border-left: 3px solid var(--ib-primary); padding-left: 8px; border-radius: var(--ib-radius-sm); }
.message-deleted-placeholder { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--ib-surface-hover); border-radius: var(--ib-radius-sm); font-style: italic; opacity: .7; font-size: var(--ib-text-sm); }

.message-input-container { border-top: 1px solid var(--ib-outline-light); background: var(--ib-surface-card); padding: 12px 16px; }
.message-input-previews { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.message-input-preview { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; border: 1px solid var(--ib-outline-light); background: var(--ib-surface); }
.message-input-preview__img { width: 100%; height: 100%; object-fit: cover; display: block; }
.message-input-preview__file { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; padding: 4px; gap: 2px; }
.message-input-preview__icon { font-size: 18px; line-height: 1; }
.message-input-preview__name { font-size: 9px; color: var(--ib-on-surface-muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-input-preview__remove { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border: none; border-radius: 50%; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.message-input-attach-error { font-size: 12px; color: var(--ib-danger, #c0392b); margin-bottom: 6px; }
.message-input-form { display: flex; align-items: flex-end; gap: 8px; }
.message-input-attach { position: relative; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--ib-outline); background: var(--ib-surface); display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; font-size: 16px; }
.message-input-attach input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.message-input-textarea { flex: 1; border: 1px solid var(--ib-outline); border-radius: var(--ib-radius-full); padding: 10px 16px; font-size: var(--ib-text-sm); font-family: inherit; resize: none; overflow-y: auto; max-height: 120px; outline: none; transition: border-color var(--ib-transition), box-shadow var(--ib-transition); }
.message-input-textarea:focus { border-color: var(--ib-primary); box-shadow: var(--ib-focus-ring); }
.message-input-send { width: 40px; height: 40px; border-radius: 50%; background: var(--ib-primary); color: white; border: none; cursor: pointer; font-size: 16px; display: flex; align-items: center; justify-content: center; transition: all var(--ib-transition); }
.message-input-send:hover { background: var(--ib-primary-dark); }
.message-input-send:disabled { background: var(--ib-on-surface-subtle); cursor: not-allowed; }
.message-input-footer { display: flex; justify-content: space-between; margin-top: 4px; padding: 0 4px; }
.message-input-hint,.message-input-count { font-size: 10px; color: var(--ib-on-surface-subtle); }
.message-attachments { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.message-attachment-image { display: block; border-radius: 8px; overflow: hidden; max-width: 240px; }
.message-attachment-image img { display: block; width: 100%; max-height: 200px; object-fit: cover; }
.message-attachment-file { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; background: rgba(0,0,0,.08); color: inherit; text-decoration: none; font-size: 12px; max-width: 100%; }
.own-bubble .message-attachment-file { background: rgba(255,255,255,.18); }
.message-attachment-file__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.user-list { display: flex; flex-direction: column; height: 100%; background: var(--ib-surface-card); }
.user-list .user-list-header { padding: 16px 16px 12px; border-bottom: 1px solid var(--ib-outline-light); background: var(--ib-surface); }
.user-list .user-list-header h2 { margin: 0; font-size: var(--ib-text-lg); font-weight: 700; color: var(--ib-on-surface); }
.user-list .user-list-subtitle { margin: 4px 0 0; font-size: var(--ib-text-xs); color: var(--ib-on-surface-muted); }
.user-list .user-list-filters { padding: 12px; border-bottom: 1px solid var(--ib-outline-light); display: flex; flex-direction: column; gap: 8px; }
.user-list .filter-select,
.user-list .search-input { flex: 1; padding: 9px 12px; border: 1px solid var(--ib-outline); border-radius: var(--ib-radius-sm); font-size: var(--ib-text-sm); background: #fff; color: var(--ib-on-surface); }
.user-list .filter-select:focus,
.user-list .search-input:focus { outline: none; border-color: var(--ib-primary); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12); }
.user-list .search-group { display: flex; gap: 8px; }
.user-list .search-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; border: none; border-radius: var(--ib-radius-sm); background: var(--ib-primary); color: #fff; cursor: pointer; transition: background 0.2s ease; }
.user-list .search-btn:hover { background: #b91c1c; }
.user-list-items { flex: 1; overflow-y: auto; }
.user-list-item { width: 100%; text-align: left; border: none; background: transparent; padding: 12px 16px; border-bottom: 1px solid var(--ib-outline-light); cursor: pointer; display: flex; align-items: center; gap: 12px; transition: background var(--ib-transition); }
.user-list-item:hover { background: var(--ib-surface-hover); }
.user-item-avatar { width: 42px; height: 42px; border-radius: 50%; background: linear-gradient(135deg, var(--ib-primary), #a11c1c); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--ib-text-sm); flex-shrink: 0; }
.user-item-content { flex: 1; min-width: 0; }
.user-item-name { font-weight: 600; font-size: var(--ib-text-sm); color: var(--ib-on-surface); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-item-role { font-size: 11px; font-weight: 600; color: var(--ib-primary); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
.user-item-email { font-size: var(--ib-text-xs); color: var(--ib-on-surface-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.user-item-action { color: var(--ib-on-surface-subtle); flex-shrink: 0; }
.user-list-loading,.user-list-empty,.user-list-error { padding: 28px 20px; text-align: center; color: var(--ib-on-surface-muted); font-size: var(--ib-text-sm); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.user-list-spinner { width: 28px; height: 28px; border: 3px solid var(--ib-outline-light); border-top-color: var(--ib-primary); border-radius: 50%; animation: chat-spin 0.8s linear infinite; }
@keyframes chat-spin { to { transform: rotate(360deg); } }
.user-list-error { color: var(--ib-error); }
.user-list-error p { margin: 0; max-width: 240px; line-height: 1.5; }
.user-list-retry,.pagination-btn { border: 1px solid var(--ib-outline); background: #fff; color: var(--ib-on-surface); border-radius: var(--ib-radius-sm); padding: 8px 14px; font-size: var(--ib-text-sm); font-weight: 600; cursor: pointer; transition: all 0.2s ease; }
.user-list-retry { border-color: var(--ib-primary); background: var(--ib-primary); color: #fff; }
.user-list-retry:hover { background: #b91c1c; }
.pagination-btn:hover:not(:disabled) { border-color: var(--ib-primary); color: var(--ib-primary); }
.pagination-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.user-list-pagination { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--ib-outline-light); background: var(--ib-surface); }
.pagination-info { font-size: var(--ib-text-xs); color: var(--ib-on-surface-muted); font-weight: 600; }

.user-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--ib-secondary); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--ib-text-sm); flex-shrink: 0; }
.user-info { flex: 1; min-width: 0; }
.user-name { font-weight: 600; font-size: var(--ib-text-sm); color: var(--ib-on-surface); }
.user-role { font-size: var(--ib-text-xs); color: var(--ib-on-surface-muted); }

@media (max-width: 768px) {
  .chat-container { height: calc(100vh - var(--ib-topbar-h) - var(--ib-footer-h)); border-radius: 0; border: none; flex-direction: column; }
  .chat-sidebar {
    width: 100%;
    max-width: none;
    min-width: 0;
    flex: 0 0 40%;
    border-right: none;
    border-bottom: 1px solid var(--ib-outline-light);
    overflow-y: auto;
  }
  .chat-main { flex: 1; min-height: 0; }
}
