/* =========================================================
   CHATS LAYOUT
   ========================================================= */

.crm-layout {
  display: grid;
  grid-template-columns: 390px 1fr;
  gap: 20px;
  min-height: calc(100vh - 130px);
}

/* =========================================================
   PANELS
   ========================================================= */

.chat-list-panel,
.chat-window {
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-header h3 {
  margin: 0;
  font-size: 18px;
}

.panel-header span {
  font-size: 13px;
  color: var(--muted);
}

/* =========================================================
   FILTERS
   ========================================================= */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 16px 8px;
}

/* =========================================================
   CHAT LIST
   ========================================================= */

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 10px;

  padding: 10px 12px 14px;
  max-height: calc(100vh - 250px);
  overflow: auto;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 14px;

  padding: 14px;
  border-radius: 20px;

  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;

  transition: 0.22s ease;
  cursor: pointer;
}

.chat-item:hover,
.chat-item.active {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(99, 102, 241, 0.25);
}

.chat-info {
  flex: 1;
  min-width: 0;
}

.chat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.chat-top h4 {
  margin: 0;
  font-size: 15px;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-time {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.chat-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chat-preview p {
  margin: 0;
  max-width: 220px;

  font-size: 13px;
  color: var(--muted);

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================
   CHAT WINDOW
   ========================================================= */

.chat-window {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-window-header {
  display: flex;
  align-items: center;
  min-height: 92px;

  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.chat-user {
  display: flex;
  align-items: center;
  gap: 14px;

  width: 100%;
  min-width: 0;
}

.chat-user-text {
  min-width: 0;
}

.chat-user-text h3 {
  margin: 0;
  font-size: 18px;
}

/* =========================================================
   MESSAGES
   ========================================================= */

.messages {
  flex: 1;

  display: flex;
  flex-direction: column;
  gap: 16px;

  padding: 22px;
  overflow: auto;

  background:
    linear-gradient(rgba(255, 255, 255, 0.015), rgba(255, 255, 255, 0.015)),
    radial-gradient(circle at top right, rgba(79, 70, 229, 0.09), transparent 25%);
}

.date-divider {
  align-self: center;

  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);

  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.message-row.outgoing {
  justify-content: flex-end;
}

.message-avatar {
  width: 40px;
  height: 40px;

  flex-shrink: 0;
  overflow: hidden;

  display: grid;
  place-items: center;

  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);

  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bubble {
  width: fit-content;
  max-width: 620px;

  padding: 14px 16px;
  border-radius: 20px;

  font-size: 14px;
  line-height: 1.45;

  border: 1px solid var(--line);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);

  word-break: break-word;
}

.incoming .bubble {
  background: rgba(255, 255, 255, 0.05);
  border-top-left-radius: 8px;
}

.outgoing .bubble {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.95), rgba(124, 58, 237, 0.95));
  border: none;
  border-top-right-radius: 8px;
}

.bubble-meta {
  display: block;
  margin-top: 8px;

  font-size: 11px;
  text-align: right;
  opacity: 0.75;
}

/* =========================================================
   COMPOSER
   ========================================================= */

.composer {
  display: flex;
  align-items: center;
  gap: 12px;

  padding: 16px;
  border-top: 1px solid var(--line);

  background: rgba(255, 255, 255, 0.02);
}

.composer-input {
  flex: 1;

  display: flex;
  align-items: center;
  gap: 10px;

  padding: 12px 14px;
  border-radius: 18px;

  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}

.composer-input input {
  width: 100%;

  background: transparent;
  border: none;
  outline: none;

  color: var(--text);
  font-size: 14px;
}

.composer-input input::placeholder {
  color: #7f8aa3;
}

.send-btn {
  width: 52px;
  height: 52px;

  display: grid;
  place-items: center;

  border: none;
  border-radius: 16px;

  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;

  cursor: pointer;
  box-shadow: 0 14px 30px rgba(79, 70, 229, 0.28);
}

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 1180px) {
  .crm-layout {
    grid-template-columns: 340px 1fr;
  }
}

@media (max-width: 960px) {
  .crm-layout {
    grid-template-columns: 1fr;
  }

  .chat-list {
    max-height: 360px;
  }
}

@media (max-width: 640px) {
  .chat-window-header,
  .panel-header,
  .messages,
  .composer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .chat-window-header {
    min-height: auto;
  }

  .chat-user {
    align-items: flex-start;
  }

  .bubble {
    max-width: 88%;
  }

  .chat-preview p {
    max-width: 140px;
  }
}