/* ============================================
   GLOBALHIRE@ELAB — Chat (shared)
   Pair chat UI used by admin-chat.html,
   recruiter.html (Messages tab) and
   portal.html (Chat tab). Backed by the `chat`
   edge function + globalhire.chat_* tables.
   ============================================ */

.chat-shell { display: flex; gap: var(--space-5); height: calc(100vh - 220px); min-height: 480px; }
.chat-shell-tab { height: calc(100vh - 250px); min-height: 420px; }

.chat-list-pane {
  width: 300px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--bg-card); border: 1px solid var(--border-default); border-radius: var(--radius-lg); overflow: hidden;
}
.chat-thread-pane {
  flex: 1; display: flex; flex-direction: column;
  background: var(--bg-card); border: 1px solid var(--border-default); border-radius: var(--radius-lg); overflow: hidden;
}
.chat-pane-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border-default); flex-shrink: 0;
}
.chat-pane-title { font-weight: 700; font-size: var(--text-md); color: var(--text-primary); }
.chat-pane-sub { font-size: var(--text-xs); color: var(--text-tertiary); margin-top: 2px; }
.chat-new-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius-md);
  background: var(--primary); color: #fff; font-size: var(--text-xs); font-weight: 600; border: none; cursor: pointer;
}
.chat-new-btn:hover { filter: brightness(1.1); }
.chat-list { flex: 1; overflow-y: auto; }
.chat-conv {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle); cursor: pointer; transition: background var(--duration-fast);
}
.chat-conv:hover { background: var(--bg-hover); }
.chat-conv.active { background: rgba(0,119,182,0.10); border-left: 3px solid var(--primary); }
.chat-conv-avatar {
  width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: var(--text-xs); flex-shrink: 0;
}
.chat-conv-body { flex: 1; min-width: 0; }
.chat-conv-top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.chat-conv-name { font-weight: 600; font-size: var(--text-sm); color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-conv-time { font-size: var(--text-xs); color: var(--text-tertiary); white-space: nowrap; }
.chat-conv-preview { font-size: var(--text-xs); color: var(--text-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-conv-role { font-size: var(--text-2xs); color: var(--secondary); text-transform: uppercase; letter-spacing: 0.05em; }
.chat-unread-badge {
  background: var(--primary); color: #fff; border-radius: 999px; min-width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center; font-size: var(--text-2xs); font-weight: 700; padding: 0 5px;
}
.chat-thread-body { flex: 1; overflow-y: auto; padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-3); background: var(--bg-deep); }
.chat-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--text-tertiary); font-size: var(--text-sm); text-align: center; padding: var(--space-5); }
.chat-msg { max-width: 72%; padding: 10px 14px; border-radius: var(--radius-lg); font-size: var(--text-sm); line-height: 1.5; word-wrap: break-word; white-space: pre-wrap; }
.chat-msg.mine { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.theirs { align-self: flex-start; background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border-default); border-bottom-left-radius: 4px; }
.chat-msg-meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: var(--text-2xs); opacity: 0.75; }
.chat-msg.mine .chat-msg-meta { justify-content: flex-end; }
.chat-composer { display: flex; gap: var(--space-3); padding: var(--space-4); border-top: 1px solid var(--border-default); flex-shrink: 0; }
.chat-composer textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 120px; padding: 10px 14px; border-radius: var(--radius-md);
  border: 1px solid var(--border-default); background: var(--bg-deep); color: var(--text-primary);
  font-family: inherit; font-size: var(--text-sm); outline: none;
}
.chat-composer textarea:focus { border-color: var(--primary); }
.chat-send-btn {
  align-self: flex-end; padding: 10px 18px; border-radius: var(--radius-md); background: var(--primary); color: #fff;
  font-weight: 600; font-size: var(--text-sm); border: none; cursor: pointer;
}
.chat-send-btn:hover { filter: brightness(1.1); }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
/* Email-from-chat */
.chat-thread-head-main { flex: 1; min-width: 0; }
.chat-email-btn {
  flex: 0 0 auto; padding: 6px 12px; border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle); background: var(--bg-elevated);
  color: var(--text-secondary); font-size: 12px; font-weight: 700; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.chat-email-btn:hover { border-color: var(--primary); color: var(--primary); }
.chat-msg-email { background: transparent; }
.chat-email-card {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  background: var(--bg-elevated); border: 1px dashed var(--border-subtle); max-width: 320px;
}
.chat-email-icon { font-size: 18px; }
.chat-email-meta { flex: 1; min-width: 0; }
.chat-email-subject {
  display: block; font-size: var(--text-xs); font-weight: 700; color: var(--text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-email-to { display: block; font-size: 11px; color: var(--text-tertiary); }
.chat-email-to-label { font-size: 12px; color: var(--text-secondary); margin-bottom: var(--space-2); }
.chat-email-input {
  width: 100%; box-sizing: border-box; padding: 10px 12px; border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle); background: var(--bg-surface);
  color: var(--text-primary); font-size: 14px; margin-bottom: var(--space-2);
}
.chat-email-input:focus { outline: none; border-color: var(--primary); }
.chat-email-body { min-height: 120px; resize: vertical; font-family: inherit; }
.chat-btn {
  padding: 8px 16px; border-radius: var(--radius-md); border: 1px solid var(--border-subtle);
  background: var(--bg-elevated); color: var(--text-secondary); font-size: 13px; font-weight: 700; cursor: pointer;
}
.chat-btn:hover { border-color: var(--border-default); color: var(--text-primary); }
.chat-btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.chat-btn-primary:hover { opacity: .9; color: #fff; }
.chat-btn:disabled { opacity: .5; cursor: default; }
/* Attachment support */
.chat-attach-btn {
  align-self: flex-end; flex: 0 0 auto; width: 44px; height: 44px; border-radius: var(--radius-md);
  border: 1px solid var(--border-default); background: var(--bg-deep); color: var(--text-secondary);
  font-size: 17px; cursor: pointer; display: flex; align-items: center; justify-content: center; line-height: 1;
}
.chat-attach-btn:hover { border-color: var(--primary); color: var(--primary); }
.chat-attach-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-file-card {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius-md);
  background: var(--bg-elevated); border: 1px solid var(--border-default); cursor: pointer; max-width: 320px;
  margin-top: 6px;
}
.chat-file-card:hover { border-color: var(--primary); }
.chat-msg.mine .chat-file-card { background: rgba(255,255,255,0.16); border-color: rgba(255,255,255,0.35); }
.chat-file-icon { font-size: 22px; line-height: 1; }
.chat-file-meta { flex: 1; min-width: 0; }
.chat-file-name { display: block; font-size: var(--text-xs); font-weight: 700; color: inherit; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-msg.mine .chat-file-name { color: #fff; }
.chat-file-size { display: block; font-size: 11px; opacity: 0.7; margin-top: 1px; }
.chat-file-dl { font-size: 11px; font-weight: 700; color: var(--primary); white-space: nowrap; }
.chat-msg.mine .chat-file-dl { color: #fff; }
.chat-thread-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border-default); flex-shrink: 0; }
.chat-thread-head .chat-conv-avatar { width: 34px; height: 34px; }
.chat-thread-title { font-weight: 700; color: var(--text-primary); font-size: var(--text-sm); }
.chat-thread-sub { font-size: var(--text-xs); color: var(--text-tertiary); }
/* New chat modal */
.chat-modal-overlay { position: fixed; inset: 0; background: rgba(4,12,24,0.6); display: none; align-items: center; justify-content: center; z-index: 100; }
.chat-modal-overlay.open { display: flex; }
.chat-modal {
  width: 460px; max-width: 92vw; max-height: 70vh; display: flex; flex-direction: column;
  background: var(--bg-card); border: 1px solid var(--border-default); border-radius: var(--radius-lg); overflow: hidden;
}
.chat-modal-head { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border-default); display: flex; align-items: center; justify-content: space-between; }
.chat-modal-title { font-weight: 700; color: var(--text-primary); }
.chat-modal-close { background: none; border: none; color: var(--text-tertiary); font-size: 18px; cursor: pointer; }
.chat-modal-search { margin: var(--space-4) var(--space-5) 0; }
.chat-modal-search input {
  width: 100%; padding: 9px 14px; border-radius: var(--radius-md); border: 1px solid var(--border-default);
  background: var(--bg-deep); color: var(--text-primary); font-family: inherit; font-size: var(--text-sm); outline: none;
}
.chat-modal-list { flex: 1; overflow-y: auto; padding: var(--space-3) var(--space-2); }
.chat-peer { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); border-radius: var(--radius-md); cursor: pointer; }
.chat-peer:hover { background: var(--bg-hover); }
.chat-peer .chat-conv-avatar { width: 34px; height: 34px; }
.chat-peer-name { font-weight: 600; font-size: var(--text-sm); color: var(--text-primary); }
.chat-peer-role { font-size: var(--text-2xs); color: var(--secondary); text-transform: uppercase; letter-spacing: 0.05em; }
