/* ============================================================
   messages.css — myskillsKenya messaging (Phase 4.2)
   Scoped to the messages page (.msg-*). Uses the existing
   theme tokens so light/dark keep working.
   ============================================================ */

:root {
  --msg-out-bg: #e8f1ff;
  --msg-out-border: #E5E7EB;
  --msg-tick: #2563eb;
  --msg-in-bg: #ffffff;
  --msg-row-hover: rgba(59, 130, 246, 0.06);
  --msg-soft: rgba(148, 163, 184, 0.14);
}

html[data-theme="dark"] {
  --msg-out-bg: #1f2937;
  --msg-out-border: #374151;
  --msg-tick: #60a5fa;
  --msg-in-bg: #111827;
  --msg-row-hover: rgba(147, 197, 253, 0.07);
  --msg-soft: rgba(148, 163, 184, 0.14);
}

/* ---------- PAGE SHELL ---------- */

.msg-page { padding-top: 26px; }

.msg-app {
  display: grid;
  grid-template-columns: 344px 1fr;
  height: calc(100vh - 210px);
  min-height: 560px;
  max-height: 900px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.06);
}

html[data-theme="dark"] .msg-app {
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.4);
}

/* ---------- LEFT SIDEBAR ---------- */

.msg-side {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.msg-side-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 10px;
}

.msg-side-title { display: flex; align-items: center; gap: 10px; }

.msg-side-title h1 {
  margin: 0;
  font-size: 1.22rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
}

.msg-total-badge {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.5;
}

/* icon buttons */
.msg-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  font-size: 1rem;
  line-height: 1;
}

.msg-icon-btn:hover:not(:disabled) {
  background: var(--msg-row-hover);
  color: var(--text);
}

.msg-icon-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* search fields */
.msg-search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 14px 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--background, var(--surface));
  color: var(--muted);
}

.msg-search-field:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.14);
}

.msg-search-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.88rem;
  font-family: inherit;
}

.msg-search-field input::placeholder { color: var(--muted); }

.msg-field-clear {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 2px 4px;
}

.msg-field-clear:hover { color: var(--text); }

/* people (user search) panel */
.msg-people {
  border-bottom: 1px solid var(--border);
  padding-top: 6px;
}

.msg-people-results {
  max-height: 250px;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.msg-search-hint {
  margin: 8px 8px 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.msg-person {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.msg-person:hover { background: var(--msg-row-hover); }

.msg-person-meta { min-width: 0; flex: 1; }

.msg-person-name {
  display: block;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-person-org {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-person-action {
  flex-shrink: 0;
  padding: 5px 12px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: transparent;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.msg-person-action:hover { background: var(--primary); color: #fff; }

/* avatars */
.msg-avatar {
  position: relative;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
  user-select: none;
}

.msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.msg-avatar--head { width: 38px; height: 38px; font-size: 0.85rem; }

/* ---------- CONVERSATION LIST ---------- */

.msg-conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.msg-conv {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 10px 9px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.msg-conv:hover { background: var(--msg-row-hover); }

.msg-conv.is-active {
  background: rgba(59, 130, 246, 0.12);
}

html[data-theme="dark"] .msg-conv.is-active {
  background: rgba(98, 165, 255, 0.14);
}

.msg-conv-body { flex: 1; min-width: 0; }

.msg-conv-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.msg-conv-name {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-conv-time {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.msg-conv-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}

.msg-conv-preview {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-conv.unread .msg-conv-preview { color: var(--text); font-weight: 600; }

.msg-unread {
  flex-shrink: 0;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.5;
}

.msg-conv-role {
  display: inline-block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.72rem;
}

.msg-list-empty {
  padding: 26px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.86rem;
}

/* ---------- RIGHT PANEL / THREAD ---------- */

.msg-main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--background, var(--surface));
}

.msg-empty {
  margin: auto;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 30px;
}

.msg-empty .msk-empty-cta { margin-top: 14px; }

.msg-thread {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}


/* ---------- THREAD HEADER ---------- */

.msg-thread-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.msg-back-btn {
  display: none;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  margin-left: -4px;
}

.msg-head-meta { flex: 1; min-width: 0; }

.msg-head-name {
  color: var(--text);
  font-size: 0.98rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-head-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.msg-presence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
}

.msg-presence-dot.is-off { background: var(--muted); opacity: 0.6; }

.msg-head-actions { display: flex; gap: 8px; }

.msg-inthread-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.msg-inthread-search input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--background, var(--surface));
  color: var(--text);
  font-size: 0.86rem;
  outline: 0;
}

.msg-inthread-search input:focus { border-color: var(--primary); }

/* ---------- MESSAGE STREAM ---------- */

.msg-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 10px;
  scroll-behavior: smooth;
}

.msg-older-wrap { text-align: center; margin-bottom: 8px; }

.msg-older-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.78rem;
  cursor: pointer;
}

.msg-older-btn:hover { color: var(--text); border-color: var(--primary); }

.msg-day {
  display: flex;
  justify-content: center;
  margin: 14px 0 10px;
}

.msg-day span {
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--msg-soft);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.msg-row {
  display: flex;
  margin-top: 3px;
}

.msg-row--out { justify-content: flex-end; }
.msg-row--in { justify-content: flex-start; }

.msg-bubble {
  position: relative;
  max-width: min(70%, 520px);
  padding: 8px 12px 6px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--msg-in-bg);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg-row--in .msg-bubble { border-bottom-left-radius: 5px; }
.msg-row--out .msg-bubble {
  background: var(--msg-out-bg);
  border-color: var(--msg-out-border);
  border-bottom-right-radius: 5px;
}

.msg-bubble.is-highlight {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.msg-bubble-text { white-space: pre-wrap; }

.msg-bubble-text.is-emoji-only {
  font-size: 1.9rem;
  line-height: 1.3;
}

.msg-bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
}

.msg-bubble-time { color: var(--muted); font-size: 0.66rem; }

.msg-ticks {
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: -0.12em;
}

.msg-ticks.is-read { color: var(--msg-tick); font-weight: 700; }

.msg-stream-foot { display: flex; justify-content: center; padding: 10px; }

.msg-new-pill {
  position: absolute;
  left: 50%;
  bottom: 86px;
  transform: translateX(-50%);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.12);
  z-index: 5;
}

/* ---------- COMPOSER ---------- */

.msg-composer {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.msg-composer-btn { flex-shrink: 0; margin-bottom: 3px; }

.msg-composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 132px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--background, var(--surface));
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  padding: 10px 12px;
  outline: 0;
}

.msg-composer textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.msg-send {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  margin-bottom: 1px;
}

.msg-send:hover { background: var(--primary-dark); }
.msg-send:active { transform: scale(0.95); }
.msg-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- EMOJI PICKER ---------- */

.msg-emoji-pop {
  position: absolute;
  left: 10px;
  bottom: calc(100% + 8px);
  width: 322px;
  max-width: calc(100vw - 40px);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 16px 40px rgba(2, 6, 23, 0.18);
  z-index: 30;
  overflow: hidden;
}

.msg-emoji-search { padding: 10px 10px 6px; }

.msg-emoji-search input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--background, var(--surface));
  color: var(--text);
  font-size: 0.84rem;
  outline: 0;
}

.msg-emoji-search input:focus { border-color: var(--primary); }

.msg-emoji-cats {
  display: flex;
  gap: 2px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}

.msg-emoji-cat {
  flex: 1;
  border: 0;
  background: transparent;
  border-radius: 7px;
  padding: 5px 0;
  font-size: 0.98rem;
  cursor: pointer;
  opacity: 0.65;
  line-height: 1;
}

.msg-emoji-cat:hover { background: var(--msg-row-hover); opacity: 1; }
.msg-emoji-cat.is-active { background: rgba(59, 130, 246, 0.14); opacity: 1; }

.msg-emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 8px;
  max-height: 244px;
  overflow-y: auto;
}

.msg-emoji-cell {
  border: 0;
  background: transparent;
  border-radius: 8px;
  font-size: 1.32rem;
  line-height: 1.5;
  padding: 3px 0;
  cursor: pointer;
}

.msg-emoji-cell:hover { background: var(--msg-row-hover); transform: scale(1.12); }

.msg-emoji-none {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  padding: 18px 0;
}

/* ---------- MOBILE ---------- */

@media (max-width: 860px) {
  .msg-page { padding-top: 14px; }

  .msg-app {
    grid-template-columns: 1fr;
    height: calc(100vh - 150px);
    min-height: 480px;
    max-height: none;
    border-radius: 12px;
  }

  .msg-side { border-right: 0; }

  .msg-main { display: none; }

  .msg-app.is-thread .msg-side { display: none; }
  .msg-app.is-thread .msg-main { display: flex; }

  .msg-back-btn { display: inline-flex; }

  .msg-bubble { max-width: 84%; }

  .msg-people-results { max-height: 210px; }
}

@media (max-width: 480px) {
  .msg-side-top { padding: 12px 12px 8px; }
  .msg-search-field { margin: 4px 10px 8px; }
  .msg-scroll { padding: 12px 10px 8px; }
  .msg-thread-head { padding: 10px 10px; }
  .msg-composer { padding: 8px 8px; }
  .msg-emoji-pop { left: 6px; width: calc(100vw - 32px); }
}

