/* ========== CHAT LAYOUT ========== */
.chat-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 56px);
  background: var(--bg);
}

/* ========== CHAT SIDEBAR (user list) ========== */
.chat-sidebar {
  width: 320px;
  min-width: 320px;
  background: white;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid #e2e8f0;
}

.chat-sidebar-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #1e293b;
}

.chat-sidebar-header h3 i {
  color: var(--primary);
  margin-right: 6px;
}

#chatNewMsgBtn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: white;
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 0.85rem;
}

#chatNewMsgBtn:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

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

.chat-user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.chat-user-item:hover {
  background: #f1f5f9;
}

.chat-user-item.active {
  background: #fef2f2;
  border-left: 3px solid var(--primary);
  padding-left: 15px;
}

.chat-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  flex-shrink: 0;
  position: relative;
}

.chat-online-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid white;
  position: absolute;
  bottom: -1px;
  right: -1px;
}

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

.chat-user-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-user-role-tag {
  font-size: 0.6rem;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 500;
  text-transform: uppercase;
}

.chat-user-role-tag.admin {
  background: #fef2f2;
  color: var(--primary);
}

.chat-user-role-tag.manager {
  background: #eff6ff;
  color: #2563eb;
}

.chat-user-last-msg {
  font-size: 0.75rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-user-time {
  font-size: 0.65rem;
  color: #94a3b8;
  flex-shrink: 0;
}

.chat-user-unread {
  background: var(--primary);
  color: white;
  font-size: 0.6rem;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  position: absolute;
  top: 8px;
  right: 18px;
}

/* ========== CHAT MAIN AREA ========== */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  gap: 12px;
}

.chat-placeholder-icon {
  font-size: 3rem;
  opacity: 0.3;
}

.chat-placeholder p {
  font-size: 0.95rem;
}

/* ========== CHAT WINDOW ========== */
.chat-window {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-window-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: white;
  border-bottom: 1px solid #e2e8f0;
}

.chat-toggle-users {
  display: none;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  background: #f1f5f9;
  color: #64748b;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.chat-window-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-avatar {
  font-size: 1.6rem;
  color: var(--primary);
  line-height: 1;
}

.chat-window-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1e293b;
}

.chat-window-status {
  font-size: 0.7rem;
  color: #94a3b8;
}

.chat-window-status.online {
  color: #22c55e;
}

.chat-window-status.offline {
  color: #94a3b8;
}

/* ========== MESSAGES AREA ========== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #f8fafc;
}

.chat-msg-date-separator {
  text-align: center;
  font-size: 0.7rem;
  color: #94a3b8;
  padding: 8px 0;
  position: relative;
}

.chat-msg-date-separator::before,
.chat-msg-date-separator::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: #e2e8f0;
}

.chat-msg-date-separator::before { left: 0; }
.chat-msg-date-separator::after { right: 0; }

.chat-msg {
  max-width: 70%;
  padding: 8px 14px;
  border-radius: 14px;
  font-size: 0.85rem;
  line-height: 1.45;
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat-msg.mine {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-msg.theirs {
  align-self: flex-start;
  background: white;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

.chat-msg-time {
  font-size: 0.6rem;
  opacity: 0.65;
}

.chat-msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
}

.chat-msg-status {
  font-size: 0.65rem;
  line-height: 1;
}

.chat-msg-status.delivered {
  color: #22c55e;
}

.chat-msg-status.read {
  color: #22c55e;
}

.chat-msg-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.15);
  border-radius: 8px;
  color: white;
  text-decoration: none;
  font-size: 0.8rem;
}

.chat-msg.theirs .chat-msg-file {
  background: #f1f5f9;
  color: #1e293b;
}

.chat-msg-file i {
  font-size: 1rem;
}

.chat-msg-file:hover {
  opacity: 0.85;
}

/* ========== INPUT AREA ========== */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  background: white;
  border-top: 1px solid #e2e8f0;
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  font-size: 0.85rem;
  background: #f8fafc;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

.chat-input:focus {
  border-color: var(--primary);
  background: white;
}

.chat-file-btn, .chat-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 0.95rem;
  color: #64748b;
  flex-shrink: 0;
}

.chat-file-btn:hover {
  background: #f1f5f9;
  color: var(--primary);
}

.chat-send-btn {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

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

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========== NEW MESSAGE MODAL ========== */
.chat-new-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-new-modal-content {
  background: white;
  border-radius: 16px;
  width: 400px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.chat-new-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
}

.chat-new-modal-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

.chat-new-modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: #f1f5f9;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
}

.chat-new-modal-close:hover {
  background: #e2e8f0;
}

.chat-new-modal-search {
  padding: 12px 20px;
  border-bottom: 1px solid #e2e8f0;
}

.chat-new-modal-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 0.85rem;
  outline: none;
  font-family: inherit;
}

.chat-new-modal-search input:focus {
  border-color: var(--primary);
}

.chat-new-modal-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.chat-new-user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-new-user-item:hover {
  background: #f1f5f9;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .chat-sidebar {
    width: 100%;
    min-width: 0;
  }
  .chat-sidebar.hidden {
    display: none;
  }
  .chat-toggle-users {
    display: flex;
  }
}
