/* ============================================================
   Chat Page — full-page chat layout
   ============================================================ */

/* ── Body override: make section fill remaining height ─────── */
.chat-page-body #wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.chat-section {
  flex: 1;
  padding: 0 0 48px;
  background: var(--bg);
}

/* ── Page title bar ────────────────────────────────────────── */
.chat-page-title {
  background: linear-gradient(135deg, var(--bg-6) 0%, #1a5c3f 100%);
  padding: 28px 0;
  position: relative;
  overflow: hidden;
}

.chat-page-title::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 85% 50%, rgba(245,91,36,0.14) 0%, transparent 55%);
  pointer-events: none;
}

.chat-page-title__heading {
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
  position: relative;
}

.chat-page-title__breadcrumb {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255,255,255,0.55);
  position: relative;
}

.chat-page-title__breadcrumb a {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  transition: color 0.2s;
}

.chat-page-title__breadcrumb a:hover { color: var(--primary); }

.chat-page-title__breadcrumb .icon {
  font-size: 9px;
  opacity: 0.5;
}

.chat-page-title__back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.85);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
  position: relative;
  white-space: nowrap;
}

.chat-page-title__back:hover {
  background: rgba(255,255,255,0.18);
  color: #fff;
}

/* ── Main layout ───────────────────────────────────────────── */
.chat-section .container {
  padding-top: 32px;
}

.chat-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  height: calc(100vh - 280px);
  min-height: 540px;
}

/* ── Sidebar ───────────────────────────────────────────────── */
.chat-sidebar {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
  flex-shrink: 0;
}

.chat-sidebar__title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.chat-sidebar__count {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.chat-sidebar__search {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 16px 12px;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid transparent;
  transition: border-color 0.2s;
  flex-shrink: 0;
}

.chat-sidebar__search:focus-within {
  border-color: var(--primary);
  background: #fff;
}

.chat-sidebar__search .icon {
  font-size: 15px;
  color: var(--text-3);
  flex-shrink: 0;
}

.chat-sidebar__search input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
}

.chat-sidebar__search input::placeholder { color: var(--text-3); }

/* ── Conversation list ─────────────────────────────────────── */
.chat-conv-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.chat-conv-list::-webkit-scrollbar { width: 4px; }
.chat-conv-list::-webkit-scrollbar-track { background: transparent; }
.chat-conv-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.chat-conv-empty {
  padding: 48px 20px;
  text-align: center;
}

.chat-conv-empty__icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.chat-conv-empty__icon .icon {
  font-size: 24px;
  color: var(--text-3);
}

.chat-conv-empty p {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.chat-conv-empty span {
  font-size: 12px;
  color: var(--text-2);
}

/* ── Conversation item ─────────────────────────────────────── */
.chat-conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid #f5f5f5;
  position: relative;
}

.chat-conv-item:hover { background: var(--bg); }

.chat-conv-item.active {
  background: rgba(245,91,36,0.06);
}

.chat-conv-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
}

.chat-conv-item__avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-6);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

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

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

.chat-conv-item__name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.chat-conv-item__preview {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-conv-item__meta {
  font-size: 11px;
  color: var(--text-3);
  text-align: right;
  flex-shrink: 0;
}

.chat-conv-item__unread {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

/* ── Main chat panel ───────────────────────────────────────── */
.chat-main {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Empty state */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
}

.chat-empty__icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.chat-empty__icon .icon {
  font-size: 36px;
  color: var(--text-3);
}

.chat-empty h5 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.chat-empty p {
  font-size: 14px;
  color: var(--text-2);
  max-width: 280px;
  margin: 0;
}

/* Active conversation wrapper */
.chat-conversation {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ── Conversation header ───────────────────────────────────── */
.chat-conv-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  background: #fff;
}

.chat-back-btn {
  display: none;
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg);
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  flex-shrink: 0;
  transition: background 0.15s;
}

.chat-back-btn:hover { background: var(--line); }
.chat-back-btn .icon { font-size: 16px; }

.chat-conv-header__avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--bg-6);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

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

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

.chat-conv-header__name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-conv-header__status {
  font-size: 12px;
  color: var(--secondary);
  display: flex;
  align-items: center;
  gap: 5px;
}

.chat-conv-header__status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
}

/* ── Messages area ─────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  background: var(--bg);
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

/* Day separator */
.chat-day-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
}

.chat-day-sep::before,
.chat-day-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.chat-day-sep span {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  padding: 0 4px;
}

/* Bubbles */
.chat-bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-bubble-wrap.is-me {
  flex-direction: row-reverse;
}

.chat-bubble-wrap__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-6);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 4px;
}

.chat-bubble {
  max-width: 68%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
}

.chat-bubble-wrap:not(.is-me) .chat-bubble {
  background: #fff;
  color: var(--text);
  border-radius: 4px 16px 16px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

.chat-bubble-wrap.is-me .chat-bubble {
  background: var(--bg-6);
  color: #fff;
  border-radius: 16px 4px 16px 16px;
}

.chat-bubble__time {
  font-size: 10px;
  margin-top: 4px;
  display: block;
  opacity: 0.55;
  text-align: right;
}

/* Typing indicator */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: #fff;
  border-radius: 4px 16px 16px 16px;
  width: fit-content;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}

.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  animation: chat-bounce 1.2s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: 0.18s; }
.chat-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes chat-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

/* ── Input row ─────────────────────────────────────────────── */
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: #fff;
  flex-shrink: 0;
}

.chat-input-wrap {
  flex: 1;
  background: var(--bg);
  border: 1.5px solid transparent;
  border-radius: 12px;
  padding: 2px 4px;
  transition: border-color 0.2s, background 0.2s;
}

.chat-input-wrap:focus-within {
  border-color: var(--bg-6);
  background: #fff;
}

#cp-input {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  font-size: 14px;
  line-height: 1.5;
  font-family: inherit;
  color: var(--text);
  padding: 8px 12px;
  max-height: 100px;
  overflow-y: auto;
  display: block;
}

#cp-input::placeholder { color: var(--text-3); }

.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: var(--bg-6);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.18s, transform 0.12s;
}

.chat-send-btn:hover:not(:disabled) {
  background: #1a6040;
  transform: scale(1.05);
}

.chat-send-btn:disabled {
  background: var(--line);
  cursor: not-allowed;
  transform: none;
}

.chat-send-btn svg {
  width: 17px;
  height: 17px;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 991px) {
  .chat-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: unset;
  }

  .chat-sidebar {
    height: 420px;
  }

  .chat-main {
    height: 520px;
  }

  .chat-back-btn { display: flex; }
}

@media (max-width: 767px) {
  .chat-section .container { padding-top: 20px; }

  .chat-sidebar { height: 360px; }
  .chat-main { height: 480px; }

  .chat-page-title { padding: 20px 0; }
  .chat-page-title__heading { font-size: 18px; }
  .chat-page-title__back span { display: none; }
}
