/* Chat View */
.chat-view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Chat Top Bar */
.chat-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-topbar .btn-back {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
}

.chat-topbar .btn-back:hover {
  background: var(--hover);
}

.chat-topbar .btn-back svg {
  width: 22px;
  height: 22px;
}

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

.chat-room-name {
  font-weight: 700;
  font-size: 1rem;
  font-family: 'Syne', sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-room-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.chat-users-count {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding: 6px 12px;
  background: var(--card);
  border-radius: var(--radius-sm);
}

.chat-users-count .online-dot {
  width: 7px;
  height: 7px;
}

/* Messages Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
}

/* Date Divider */
.date-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 20px 0 12px;
}

.date-divider::before,
.date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.date-divider span {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  font-family: 'JetBrains Mono', monospace;
}

/* Message Bubbles */
.message {
  display: flex;
  flex-direction: column;
  max-width: 65%;
  animation-duration: 200ms;
  animation-fill-mode: backwards;
}

.message.own {
  align-self: flex-end;
  align-items: flex-end;
  animation-name: slideInRight;
}

.message.other {
  align-self: flex-start;
  align-items: flex-start;
  animation-name: slideInLeft;
}

.message.system {
  align-self: center;
  max-width: 80%;
  animation-name: slideInBottom;
}

.message-username {
  font-size: 0.78rem;
  font-weight: 600;
  margin-bottom: 3px;
  padding-left: 4px;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.92rem;
  line-height: 1.5;
  word-break: break-word;
}

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

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

.message.system .message-bubble {
  background: transparent;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.82rem;
  padding: 4px 0;
  text-align: center;
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 4px;
  font-family: 'JetBrains Mono', monospace;
  cursor: default;
}

.message.own .message-time {
  color: rgba(255, 255, 255, 0.5);
}

/* Grouped messages */
.message.grouped {
  margin-top: -2px;
}

.message.grouped .message-username {
  display: none;
}

.message.grouped.other .message-bubble {
  border-top-left-radius: 4px;
}

.message.grouped.own .message-bubble {
  border-top-right-radius: 4px;
}

/* Message content formatting */
.message-bubble code {
  background: rgba(0, 0, 0, 0.25);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: 'JetBrains Mono', monospace;
}

.message-bubble pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin: 6px 0;
  overflow-x: auto;
}

.message-bubble pre code {
  background: none;
  padding: 0;
}

.message-bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message.own .message-bubble a {
  color: rgba(255, 255, 255, 0.9);
}

/* New Messages Button */
.new-messages-btn {
  position: absolute;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: white;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  display: none;
  align-items: center;
  gap: 6px;
  z-index: 10;
  animation: bounceIn 300ms ease;
  cursor: pointer;
  border: none;
}

.new-messages-btn.visible {
  display: flex;
}

.new-messages-btn svg {
  width: 16px;
  height: 16px;
}

/* Chat Input Bar */
.chat-input-bar {
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  transition: border-color var(--transition);
}

.chat-input-wrap:focus-within {
  border-color: var(--primary);
}

.chat-input-wrap textarea {
  flex: 1;
  resize: none;
  background: transparent;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.5;
  max-height: 120px;
  min-height: 22px;
  overflow-y: auto;
}

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

.btn-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform 100ms ease, opacity var(--transition);
  flex-shrink: 0;
  opacity: 0.4;
  pointer-events: none;
}

.btn-send.active {
  opacity: 1;
  pointer-events: auto;
}

.btn-send:hover {
  background: var(--primary-hover);
}

.btn-send:active {
  transform: scale(0.9);
}

.btn-send svg {
  width: 18px;
  height: 18px;
  color: white;
}

.char-counter {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: 4px;
  font-family: 'JetBrains Mono', monospace;
  height: 16px;
}

.char-counter.warning {
  color: var(--warning);
}

.char-counter.danger {
  color: var(--danger);
}

/* Room Info Panel */
.room-info-panel {
  position: fixed;
  top: 0;
  right: -320px;
  width: 300px;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 100;
  transition: right 250ms ease;
  padding: 24px;
  overflow-y: auto;
}

.room-info-panel.open {
  right: 0;
}

.room-info-panel h3 {
  font-size: 1.1rem;
  margin-bottom: 20px;
}

.room-info-item {
  margin-bottom: 16px;
}

.room-info-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.room-info-value {
  font-size: 0.92rem;
  color: var(--text);
}

.room-info-users-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.room-info-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.room-info-user .avatar {
  width: 28px;
  height: 28px;
  font-size: 0.7rem;
}

.room-info-user span {
  font-size: 0.88rem;
}

.room-info-close {
  position: absolute;
  top: 16px;
  right: 16px;
}

/* Sound Toggle */
.btn-sound {
  position: relative;
}

.btn-sound.muted svg {
  opacity: 0.4;
}

@media (max-width: 768px) {
  .message {
    max-width: 85%;
  }

  .chat-messages {
    padding: 12px;
  }

  .chat-input-bar {
    padding: 8px 12px;
  }

  .room-info-panel {
    width: 100%;
    right: -100%;
  }

  .chat-room-desc {
    display: none;
  }
}
