/* ─── CHAT SCREEN ─── */

.chat-screen {
  animation: screenFadeIn 300ms ease;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-h) - var(--nav-h) - var(--safe-b));
}

.chat-screen.chat-view {
  height: calc(100vh - var(--topbar-h) - var(--nav-h) - var(--safe-b));
}

/* ─── CHAT HEADER ─── */

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px var(--page-pad);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.chat-header-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.chat-header-sub {
  font-size: 11px;
  font-weight: 300;
  color: var(--muted);
}

.chat-back-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-new-btn {
  margin-left: auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
}

.chat-menu-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ─── CONVERSATION LIST ─── */

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px var(--page-pad);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: background 120ms;
}

.conv-item:active {
  background: rgba(255, 255, 255, 0.04);
}

.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.conv-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.conv-avatar-fallback {
  font-size: 18px;
  color: var(--muted);
}

.conv-avatar-sm {
  width: 36px;
  height: 36px;
}

.conv-avatar-sm .conv-avatar-fallback {
  font-size: 14px;
}

.conv-info {
  flex: 1;
  min-width: 0;
}

.conv-top-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 2px;
}

.conv-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-time {
  font-size: 11px;
  font-weight: 300;
  color: var(--muted);
  flex-shrink: 0;
  margin-left: 8px;
}

.conv-bottom-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.conv-preview {
  font-size: 12px;
  font-weight: 300;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.conv-unread {
  background: var(--accent);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
  margin-left: 8px;
}

/* ─── MESSAGES ─── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px var(--page-pad);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}

.msg-mine {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-other {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-sender {
  font-size: 10px;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 2px;
  padding-left: 10px;
}

.msg-bubble {
  padding: 8px 12px;
  border-radius: 16px;
  display: inline-flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
  word-break: break-word;
}

.msg-mine .msg-bubble {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg-other .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.msg-text {
  font-size: 13px;
  font-weight: 400;
  line-height: 1.4;
}

.msg-time {
  font-size: 9px;
  opacity: 0.6;
  flex-shrink: 0;
  white-space: nowrap;
}

/* ─── INPUT BAR ─── */

.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px var(--page-pad);
  border-top: 1px solid var(--border);
  background: rgba(8, 12, 20, 0.9);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  height: 40px;
  padding: 0 14px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}

.chat-input::placeholder {
  color: var(--muted);
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  flex-shrink: 0;
}

.chat-send-btn:active {
  opacity: 0.8;
}

/* ─── EMPTY / LOADING ─── */

.chat-loading {
  text-align: center;
  padding: 40px 0;
  color: var(--muted);
  font-size: 13px;
}

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px var(--page-pad);
  text-align: center;
}

.chat-empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.chat-empty-text {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.chat-empty-sub {
  font-size: 12px;
  font-weight: 300;
  color: var(--muted);
}

.chat-empty-messages {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 40px 0;
}

/* ─── NEW CHAT / NEW GROUP ─── */

.chat-new-options {
  padding: 12px var(--page-pad);
  border-bottom: 1px solid var(--border);
}

.chat-option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 160ms;
}

.chat-option-btn:active {
  border-color: var(--accent);
}

.chat-option-icon {
  font-size: 20px;
}

.chat-search-bar {
  padding: 12px var(--page-pad);
}

.chat-search-input {
  width: 100%;
  height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}

.chat-search-input::placeholder {
  color: var(--muted);
}

.chat-user-results {
  flex: 1;
  overflow-y: auto;
}

.user-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px var(--page-pad);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: background 120ms;
}

.user-result-item:active {
  background: rgba(255, 255, 255, 0.04);
}

.user-result-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-result-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.user-result-email {
  font-size: 11px;
  font-weight: 300;
  color: var(--muted);
}

/* ─── NEW GROUP FORM ─── */

.chat-new-group-form {
  padding: 12px var(--page-pad);
  display: flex;
  flex-direction: column;
  flex: 1;
}

.chat-group-name-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

.chat-group-name-input::placeholder {
  color: var(--muted);
  font-weight: 400;
}

.chat-selected-members {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 0 8px;
  min-height: 0;
}

.selected-member-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 14px;
  background: rgba(79, 140, 255, 0.15);
  border: 1px solid rgba(79, 140, 255, 0.3);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
}

.chip-remove {
  cursor: pointer;
  font-size: 10px;
  opacity: 0.7;
}

.chip-remove:hover {
  opacity: 1;
}

.chat-create-group-btn {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 500;
  border: none;
  margin-top: 12px;
  transition: opacity 160ms;
}

.chat-create-group-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── GROUP INFO ─── */

.group-info-section {
  padding: 20px var(--page-pad);
}

.group-info-name {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
}

.group-info-icon {
  font-size: 28px;
}

.group-members-label {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.group-members-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.group-member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.group-member-name {
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  flex: 1;
}

.group-owner-badge {
  font-size: 10px;
  font-weight: 500;
  color: var(--gold);
  background: rgba(245, 200, 66, 0.12);
  padding: 2px 8px;
  border-radius: 10px;
}

.chat-leave-btn {
  width: 100%;
  height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 77, 109, 0.3);
  background: rgba(255, 77, 109, 0.08);
  color: var(--red);
  font-size: 14px;
  font-weight: 500;
}
