/* =========================================================================
   Messages / Chat — 1-to-1 between project manager & applicant
   ========================================================================= */

.app-main--chat {
  padding: 0 !important;
  height: calc(100vh - var(--app-topbar-h, 64px));
  overflow: hidden;
}

.chat {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100%;
  background: var(--color-white);
}

/* ---------------- Conversation list ---------------- */
.chat__list {
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--color-bg, #f8fafc);
}

.chat__list-head {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-white);
}
.chat__list-title {
  margin: 0;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--color-navy);
}
.chat__list-sub {
  font-size: var(--font-size-xs);
  color: var(--color-text-light);
}

.chat__convos {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.chat__convo {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px var(--space-lg);
  border: none;
  border-bottom: 1px solid var(--color-border);
  background: transparent;
  text-align: left;
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease;
}
.chat__convo:hover { background: var(--color-white); }
.chat__convo--active { background: var(--color-white); box-shadow: inset 3px 0 0 var(--color-orange); }

.chat__convo-avatar {
  flex: 0 0 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--font-weight-bold);
  color: #fff;
  font-size: var(--font-size-sm);
  background: linear-gradient(135deg, var(--color-navy), var(--color-navy-light));
}

.chat__convo-body { flex: 1; min-width: 0; }
.chat__convo-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.chat__convo-name {
  font-weight: var(--font-weight-semibold);
  color: var(--color-navy);
  font-size: var(--font-size-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat__convo-time { font-size: 0.65rem; color: var(--color-text-light); white-space: nowrap; }
.chat__convo-project {
  display: block;
  font-size: 0.68rem;
  color: var(--color-orange);
  font-weight: var(--font-weight-medium);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat__convo-preview {
  display: block;
  font-size: var(--font-size-xs);
  color: var(--color-text-light);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat__convo-badge {
  flex: 0 0 auto;
  min-width: 20px; height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--color-orange);
  color: #fff;
  font-size: 0.68rem;
  font-weight: var(--font-weight-bold);
  display: flex; align-items: center; justify-content: center;
}

.chat__empty-list, .chat__loading {
  padding: var(--space-lg);
  color: var(--color-text-light);
  font-size: var(--font-size-sm);
}

/* ---------------- Thread ---------------- */
.chat__thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background:
    linear-gradient(rgba(248,250,252,0.92), rgba(248,250,252,0.92));
}

.chat__empty {
  margin: auto;
  text-align: center;
  max-width: 320px;
  padding: var(--space-lg);
}
.chat__empty-icon {
  font-size: 2.4rem;
  color: var(--color-orange);
  margin-bottom: var(--space-sm);
}
.chat__empty h3 { color: var(--color-navy); margin: 0 0 6px; }

.chat__pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.chat__pane-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: var(--space-sm) var(--space-lg);
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  z-index: 1;
}
.chat__back {
  display: none;
  border: none;
  background: transparent;
  font-size: 1.4rem;
  color: var(--color-navy);
  cursor: pointer;
  line-height: 1;
}
.chat__pane-avatar {
  flex: 0 0 40px;
  height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: var(--font-weight-bold);
  color: #fff;
  background: linear-gradient(135deg, var(--color-orange), var(--color-orange-light));
}
.chat__pane-info { min-width: 0; }
.chat__pane-name { margin: 0; font-weight: var(--font-weight-bold); color: var(--color-navy); }
.chat__pane-project { margin: 0; font-size: var(--font-size-xs); color: var(--color-text-light); }

.chat__messages {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat__day {
  align-self: center;
  background: rgba(15,23,42,0.06);
  color: var(--color-text-light);
  font-size: 0.65rem;
  font-weight: var(--font-weight-semibold);
  padding: 3px 12px;
  border-radius: 999px;
  margin: 6px 0;
}

.chat__hello {
  margin: auto;
  text-align: center;
  color: var(--color-text-light);
  font-size: var(--font-size-sm);
}

.chat__bubble {
  max-width: 72%;
  padding: 7px 12px 5px;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.chat__bubble-text { font-size: var(--font-size-sm); line-height: 1.4; }
.chat__bubble-time {
  align-self: flex-end;
  margin-top: 2px;
  font-size: 0.6rem;
  opacity: 0.7;
  white-space: nowrap;
}
.chat__bubble--me {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--color-navy), var(--color-navy-light));
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat__bubble--them {
  align-self: flex-start;
  background: var(--color-white);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 4px;
}

/* ---------------- Attachments ---------------- */
.chat__att-img {
  display: block;
  margin-bottom: 4px;
  border-radius: 10px;
  overflow: hidden;
  max-width: 240px;
}
.chat__att-img img {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: cover;
}
.chat__att-file {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.06);
  text-decoration: none;
  color: inherit;
  max-width: 240px;
}
.chat__bubble--me .chat__att-file {
  background: rgba(255, 255, 255, 0.18);
}
.chat__att-icon { font-size: 1.2rem; flex: 0 0 auto; }
.chat__att-name {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------- Attach button ---------------- */
.chat__attach {
  flex: 0 0 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-white);
  color: var(--color-navy);
  font-size: 1.15rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.12s ease;
}
.chat__attach:hover { background: var(--color-bg, #f1f5f9); transform: scale(1.05); }
.chat__attach:disabled { opacity: 0.5; cursor: not-allowed; }
.chat__attach--busy { animation: chat-pulse 0.8s ease-in-out infinite; }
@keyframes chat-pulse { 50% { opacity: 0.4; } }

/* ---------------- Composer ---------------- */
.chat__composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: var(--space-sm) var(--space-lg);
  background: var(--color-white);
  border-top: 1px solid var(--color-border);
}
.chat__input {
  flex: 1;
  resize: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font: inherit;
  font-size: var(--font-size-sm);
  line-height: 1.4;
  max-height: 120px;
  outline: none;
  transition: border-color 0.15s ease;
}
.chat__input:focus { border-color: var(--color-orange); }
.chat__send {
  flex: 0 0 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--color-orange);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s ease, background 0.15s ease;
}
.chat__send:hover { background: var(--color-orange-dark, #c2410c); transform: scale(1.05); }
.chat__send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ---------------- Responsive ---------------- */
@media (max-width: 720px) {
  .chat { grid-template-columns: 1fr; }
  .chat__thread { display: none; }
  .chat[data-state='thread'] .chat__list { display: none; }
  .chat[data-state='thread'] .chat__thread { display: flex; }
  .chat__back { display: inline-flex; }
  .chat__bubble { max-width: 85%; }
}
