/* ==========================================================
   MAXZEETON.NG — SHARED CHAT (WhatsApp-style)
   Used by /admin/messages, /teacher/messages and /student/messages.
   Self-contained: brand colour comes from whichever page token exists.
   ========================================================== */

.ct {
  --ct-brand: var(--ts-brand, var(--brand, #E8192C));
  --ct-brand-dark: var(--ts-brand-dark, #C5141F);
  --ct-card: #FFFFFF;
  --ct-bg: #F3F4F8;
  --ct-bdr: #E8E9EE;
  --ct-t1: #0D1117;
  --ct-t2: #4B5563;
  --ct-t3: #8A91A0;
  --ct-blue: #0369A1;
  font-family: 'Outfit', system-ui, sans-serif;
  color: var(--ct-t1);
  position: relative;
  background: var(--ct-card);
  border: 1px solid var(--ct-bdr);
  border-radius: 16px;
  overflow: hidden;
  min-width: 0;
}
.ct *, .ct *::before, .ct *::after { box-sizing: border-box; }
.ct [hidden] { display: none !important; }
.ct button { font: inherit; cursor: pointer; }
body.ct-lock { overflow: hidden; }

/* ---------- panes (teacher / admin) ---------- */
.ct--panes { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: clamp(480px, calc(100vh - 210px), 820px); }
.ct--panes .ct-list-pane { border-right: 1px solid var(--ct-bdr); }
.ct--panes .ct-thread-pane, .ct--panes .ct-empty-thread { grid-column: 2; grid-row: 1; }

/* ---------- dialog (student) ---------- */
.ct--dialog { display: block; }
.ct--dialog .ct-empty-thread { display: none; }

.ct-list-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.ct--panes .ct-list-pane { height: 100%; }
.ct-list-head { padding: 14px 14px 10px; display: grid; gap: 10px; border-bottom: 1px solid var(--ct-bdr); }
.ct-list-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ct-list-title h2 { margin: 0; font-family: 'Syne', sans-serif; font-size: 18px; }
.ct-new { border: 0; background: var(--ct-brand); color: #fff; border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 600; display: inline-flex; gap: 6px; align-items: center; }
.ct-new:hover { background: var(--ct-brand-dark); }
.ct-search { position: relative; display: block; }
.ct-search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ct-t3); font-size: 13px; }
.ct-search input { width: 100%; border: 1px solid var(--ct-bdr); border-radius: 999px; background: var(--ct-bg); padding: 9px 12px 9px 34px; font: inherit; font-size: 14px; color: var(--ct-t1); }
.ct-search input:focus { outline: 2px solid var(--ct-brand); outline-offset: 1px; background: #fff; }

.ct-list { overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; }
.ct--dialog .ct-list { max-height: none; overflow: visible; }

.ct-item { display: flex; width: 100%; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--ct-bdr); background: var(--ct-card); text-align: left; color: inherit; }
.ct-item:hover { background: #F8F8FB; }
.ct-item.is-active { background: #FFF0F2; }
.ct-item-body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.ct-item-top, .ct-item-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.ct-item-top strong { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-item-top time { font-size: 11.5px; color: var(--ct-t3); flex: none; }
.ct-item-preview { font-size: 13px; color: var(--ct-t2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ct-item.has-unread .ct-item-preview { color: var(--ct-t1); font-weight: 600; }
.ct-item.has-unread .ct-item-top time { color: var(--ct-brand); font-weight: 600; }
.ct-badge { flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--ct-brand); color: #fff; font-size: 11.5px; line-height: 20px; text-align: center; font-weight: 700; }
.ct-role { justify-self: start; font-size: 10.5px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: var(--ct-t3); }

.ct-avatar { flex: none; width: 42px; height: 42px; border-radius: 50%; color: #fff; display: inline-grid; place-items: center; font-weight: 700; font-size: 16px; font-family: 'Syne', sans-serif; }
.ct-avatar--lg { width: 38px; height: 38px; font-size: 15px; }

.ct-empty, .ct-empty-thread { display: grid; gap: 6px; justify-items: center; align-content: center; text-align: center; color: var(--ct-t2); padding: 40px 20px; font-size: 14px; }
.ct-empty i, .ct-empty-thread i { font-size: 34px; color: var(--ct-t3); margin-bottom: 6px; }
.ct-empty strong, .ct-empty-thread strong { color: var(--ct-t1); font-size: 15px; }
.ct-empty-thread { background: var(--ct-bg); }
.ct--panes .ct-empty-thread { height: 100%; }

.ct-skel { height: 58px; margin: 10px 14px; border-radius: 12px; background: linear-gradient(90deg, #F0F1F5 25%, #E6E8EE 50%, #F0F1F5 75%); background-size: 200% 100%; animation: ct-shimmer 1.4s infinite; }
.ct-skel--msg { height: 120px; margin: 16px; }
@keyframes ct-shimmer { to { background-position: -200% 0; } }

/* ---------- thread ---------- */
.ct-thread-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--ct-bg); position: relative; }
.ct--panes .ct-thread-pane { height: 100%; }
.ct-thread-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--ct-card); border-bottom: 1px solid var(--ct-bdr); flex: none; }
.ct-thread-who { min-width: 0; display: grid; }
.ct-thread-who strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-thread-who span { font-size: 12px; color: var(--ct-t3); }
.ct-back { border: 0; background: none; width: 36px; height: 36px; border-radius: 50%; color: var(--ct-t2); font-size: 16px; }
.ct-back:hover { background: var(--ct-bg); }
.ct--panes .ct-back { display: none; }

.ct-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 14px 6px; overscroll-behavior: contain; }
.ct-earlier { display: block; margin: 0 auto 10px; border: 1px solid var(--ct-bdr); background: var(--ct-card); border-radius: 999px; padding: 6px 14px; font-size: 12.5px; color: var(--ct-t2); }
.ct-msgs { display: flex; flex-direction: column; gap: 3px; }
.ct-day { align-self: center; margin: 10px 0 6px; }
.ct-day span { display: inline-block; background: #E4E6ED; color: var(--ct-t2); font-size: 11.5px; padding: 3px 12px; border-radius: 999px; }
.ct-msg { display: flex; max-width: 100%; }
.ct-msg.mine { justify-content: flex-end; }
.ct-msg:not(.cont) { margin-top: 6px; }
.ct-bubble { max-width: min(78%, 520px); padding: 7px 11px 5px; border-radius: 14px; font-size: 14.5px; line-height: 1.4; overflow-wrap: anywhere; box-shadow: 0 1px 1px rgba(13, 17, 23, .06); }
.ct-msg.theirs .ct-bubble { background: #fff; border-top-left-radius: 4px; }
.ct-msg.mine .ct-bubble { background: var(--ct-brand); color: #fff; border-top-right-radius: 4px; }
.ct-msg.cont.theirs .ct-bubble { border-top-left-radius: 14px; }
.ct-msg.cont.mine .ct-bubble { border-top-right-radius: 14px; }
.ct-text { white-space: pre-wrap; }
.ct-meta { display: block; text-align: right; font-size: 10.5px; margin-top: 2px; opacity: .75; }
.ct-tick { font-size: 10px; margin-left: 2px; }
.ct-tick.seen { color: #A7F3D0; opacity: 1; }
.ct-jump { position: absolute; right: 16px; bottom: 96px; border: 0; background: var(--ct-t1); color: #fff; border-radius: 999px; padding: 7px 14px; font-size: 12.5px; box-shadow: 0 4px 14px rgba(0, 0, 0, .25); z-index: 2; }

.ct-compose { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 8px; align-items: end; padding: 10px 12px calc(6px + env(safe-area-inset-bottom)); background: var(--ct-card); border-top: 1px solid var(--ct-bdr); flex: none; }
.ct-compose textarea { resize: none; border: 1px solid var(--ct-bdr); border-radius: 20px; padding: 10px 14px; font: inherit; font-size: 16px; line-height: 1.35; max-height: 132px; background: var(--ct-bg); color: var(--ct-t1); }
.ct-compose textarea:focus { outline: 2px solid var(--ct-brand); outline-offset: 1px; background: #fff; }
.ct-send { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--ct-brand); color: #fff; font-size: 15px; }
.ct-send:disabled { background: #D0D3DB; cursor: not-allowed; }
.ct-send:not(:disabled):hover { background: var(--ct-brand-dark); }
.ct-compose-foot { grid-column: 1 / -1; display: flex; justify-content: space-between; min-height: 0; font-size: 12px; color: var(--ct-t3); }
[data-ct-error] { color: #B91C1C; }

/* ---------- picker ---------- */
.ct-picker { position: fixed; inset: 0; z-index: 5100; display: grid; place-items: center; padding: 16px; }
.ct-picker-overlay { position: absolute; inset: 0; background: rgba(13, 17, 23, .5); }
.ct-picker-card { position: relative; width: min(460px, 100%); max-height: min(640px, calc(100dvh - 32px)); display: flex; flex-direction: column; gap: 10px; background: var(--ct-card); border-radius: 16px; padding: 16px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.ct-picker-head { display: flex; align-items: center; justify-content: space-between; font-family: 'Syne', sans-serif; font-size: 17px; }
.ct-x { border: 0; background: none; font-size: 18px; color: var(--ct-t2); width: 34px; height: 34px; border-radius: 50%; }
.ct-x:hover { background: var(--ct-bg); }
.ct-picker-msg { margin: 0; min-height: 0; font-size: 13px; color: var(--ct-t2); }
.ct-picker-msg:empty { display: none; }
.ct-picker-list { overflow-y: auto; flex: 1; min-height: 120px; border: 1px solid var(--ct-bdr); border-radius: 12px; }
.ct-picker-list .ct-item:last-child { border-bottom: 0; }

/* ---------- responsive ---------- */
@media (max-width: 899px) {
  .ct--panes { display: block; height: auto; min-height: 60vh; }
  .ct--panes .ct-list-pane { height: auto; border-right: 0; }
  .ct--panes .ct-list { max-height: none; overflow: visible; }
  .ct--panes .ct-empty-thread { display: none; }
  .ct--panes .ct-back { display: inline-grid; place-items: center; }
  .ct-thread-pane { position: fixed !important; inset: 0; z-index: 5000; height: auto !important; }
}
@media (min-width: 900px) {
  .ct--dialog.ct--thread-open::before { content: ''; position: fixed; inset: 0; background: rgba(13, 17, 23, .5); z-index: 4990; }
  .ct--dialog .ct-thread-pane { position: fixed; z-index: 5000; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(560px, 94vw); height: min(720px, 88vh); border-radius: 16px; overflow: hidden; box-shadow: 0 24px 60px rgba(0, 0, 0, .35); }
}
@media (max-width: 899px) {
  .ct--dialog .ct-thread-pane { position: fixed; inset: 0; z-index: 5000; height: auto; }
}
@media (prefers-reduced-motion: reduce) { .ct-skel { animation: none; } }

/* ---------- student Messages page: Chats / Announcements tabs ---------- */
.sm-tabs { display: flex; gap: 6px; border-bottom: 1px solid #E8E9EE; }
.sm-tab { position: relative; border: 0; background: none; padding: 10px 14px; font: inherit; font-size: 14px; font-weight: 600; color: #4B5563; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 6px; }
.sm-tab.active { color: #E8192C; border-bottom-color: #E8192C; }
.sm-tab-badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: #E8192C; color: #fff; font-size: 11.5px; line-height: 20px; text-align: center; }
.sm-tab-badge[hidden] { display: none !important; }
.sm-panel { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.sm-panel[hidden] { display: none !important; }

/* While a full-screen chat is open, lift the page section above the fixed site navbar (z-index 900) so the thread header is not covered. */
body.ct-lock > section.section { z-index: 5000 !important; }
