/* Messages — a coaching student and the instructor. Mine in ink, theirs on
 * the card surface: no hue, as every colour here already means something. */

/* The tab bar takes a fifth tab, and tabs/rail rows an unread count. */
.tabbar.has-5 { grid-template-columns: repeat(5, 1fr); }
.tab-icon, .rl-icon { position: relative; }
.nav-count {
  position: absolute; top: -5px; right: -9px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--red); color: var(--on-red);
  font-size: 10.5px; font-weight: 800; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px var(--surface);
}
.nav-count:empty { display: none; }
.rl-icon .nav-count { top: -6px; right: -6px; }

.msg-page { max-width: 720px; margin: 0 auto; }

.msg-note {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px; padding: 10px 14px; border-radius: 12px;
  background: var(--sunken); border: 1px solid var(--border); color: var(--ink-mid); font-size: .86rem; line-height: 1.5;
}

/* ── The inbox ── */
.msg-inbox { overflow: hidden; }
.msg-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-top: 1px solid var(--border); text-decoration: none; color: var(--ink);
}
.msg-row:first-child { border-top: 0; }
.msg-row:hover { background: var(--sunken); }
.mr-who { min-width: 0; }
.mr-name { font-weight: 700; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mr-last { font-size: .84rem; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-row.is-unread .mr-name, .msg-row.is-unread .mr-last { color: var(--ink); font-weight: 750; }
.mr-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.mr-when { font-size: .74rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.mr-count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--red); color: var(--on-red);
  font-size: 11px; font-weight: 800; line-height: 20px; text-align: center;
}

/* ── A thread ── */
/* The thread is exactly the screen's height (between the top bar and the tab
   bar): only the messages scroll, the page itself doesn't. */
body.is-chat { overflow: hidden; }
body.is-chat .main { min-height: 0; }
body.is-chat .view { padding-bottom: 0; }
.msg-thread {
  display: flex; flex-direction: column;
  height: calc(100dvh - var(--top-h) - var(--safe-t) - var(--tab-h) - var(--safe-b) - 16px);
}
@media (min-width: 900px) { .msg-thread { height: calc(100dvh - var(--top-h) - var(--safe-t) - 24px); } }
body.is-chat.kb-open .tabbar { display: none; }
body.is-chat.kb-open .msg-thread { height: calc(var(--vvh, 100dvh) - var(--top-h) - var(--safe-t) - 16px); }
body.is-chat.kb-open .msg-composer { padding-bottom: 6px; }
.msg-thread .msg-note { flex: none; margin-bottom: 8px; padding: 8px 12px; font-size: .8rem; }
/* A Compass session about to start: Join, impossible to miss. */
.msg-live {
  flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 10px; padding: 12px 14px;
  background: var(--red-bg); border: 1.5px solid var(--red-ln); border-radius: 14px;
}
.msg-live[hidden] { display: none; }
.msg-live-icon {
  flex: none; width: 40px; height: 40px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--red); color: var(--on-red);
}
.msg-live-icon svg { width: 20px; height: 20px; }
.msg-live-main { flex: 1; min-width: 0; }
.msg-live-title { font-weight: 800; font-size: .95rem; line-height: 1.3; }
.msg-live-sub { font-size: .8rem; color: var(--ink-soft); margin-top: 2px; }
.msg-live-join { flex: none; padding-left: 18px; padding-right: 18px; font-weight: 800; }
.msg-live-tip { flex-basis: 100%; margin-top: -4px; font-size: .78rem; color: var(--ink-soft); text-align: right; }
@media (max-width: 380px) {
  .msg-live-join { width: 100%; }
  .msg-live-tip { text-align: center; }
}
.msg-more { align-self: center; margin-bottom: 8px; flex: none; }
.msg-list {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 2px; padding: 0 2px 12px;
}
.msg-empty { margin: auto; max-width: 340px; text-align: center; color: var(--ink-soft); font-size: .92rem; line-height: 1.6; padding: 40px 0; }
.msg-day {
  align-self: center; margin: 14px 0 8px; font-size: .72rem; font-weight: 700; letter-spacing: .04em; color: var(--ink-soft);
}
.msg-item { display: flex; flex-direction: column; align-items: flex-start; max-width: min(78%, 520px); margin-top: 6px; }
/* On a wide screen the two sides stay close enough to read as one
   conversation: a narrower column, and bubbles no wider than a phone's. */
@media (min-width: 900px) {
  .msg-thread { max-width: 640px; }
  .msg-item { max-width: min(72%, 440px); }
}
.msg-item.is-mine { align-self: flex-end; align-items: flex-end; }
.msg-bubble {
  padding: 9px 13px; border-radius: 18px 18px 18px 6px;
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  font-size: .95rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; cursor: pointer;
  -webkit-user-select: text; user-select: text;
}
.msg-item.is-mine .msg-bubble { background: var(--ink); border-color: var(--ink); color: var(--on-ink); border-radius: 18px 18px 6px 18px; }
/* Dark: the bright ink would glare; a step softer. */
html[data-theme="dark"] .msg-item.is-mine .msg-bubble { background: var(--ink-mid); border-color: var(--ink-mid); }
.text-link { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.msg-meta { display: flex; gap: 6px; padding: 3px 6px 0; font-size: .68rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
/* Files: photos as pictures, a PDF as a card. */
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.msg-item.is-mine .msg-files { justify-content: flex-end; }
.msg-photo { display: block; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); background: var(--sunken); }
.msg-photo img { display: block; max-width: min(240px, 60vw); max-height: 280px; width: auto; height: auto; }
.msg-pdf {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px 10px 10px; min-width: 200px; max-width: 280px;
  border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); text-decoration: none;
}
.msg-pdf:hover { border-color: var(--line-2); }
.msg-pdf-icon, .msg-chip-pdf {
  flex: none; width: 36px; height: 36px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--sunken); border: 1px solid var(--border); color: var(--ink-mid); font-size: .66rem; font-weight: 800; letter-spacing: .04em;
}
.msg-pdf-text { display: flex; flex-direction: column; min-width: 0; }
.msg-pdf-text b { font-size: .86rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-pdf-text span { font-size: .74rem; color: var(--ink-soft); }

/* Replying: the quote above a message, and the bar above the composer. */
.msg-quote {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px; max-width: 100%;
  margin-bottom: -6px; padding: 6px 12px 12px; border: 0; border-radius: 14px 14px 4px 4px;
  background: var(--sunken); color: var(--ink-soft); font-size: .78rem; text-align: left; line-height: 1.35;
  border-left: 3px solid var(--line-2);
}
.msg-item.is-mine .msg-quote { align-items: flex-end; text-align: right; border-left: 0; border-right: 3px solid var(--line-2); }
.msg-quote-who { font-weight: 750; color: var(--ink-mid); }
.msg-quote-text { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.msg-item.is-flash .msg-bubble { box-shadow: 0 0 0 3px var(--red-mid); transition: box-shadow .3s; }
.msg-replybar-main { display: flex; gap: 6px; min-width: 0; }
.msg-replybar-text { font-weight: 500; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Reactions: under a message, and the row to choose one. */
.msg-reacts { display: flex; gap: 4px; margin-top: -6px; padding: 0 6px; position: relative; z-index: 1; }
.msg-react {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 1px 7px;
  font-size: .85rem; line-height: 1.4; box-shadow: var(--shadow-1); cursor: default;
}
.msg-react.is-mine { border-color: var(--red-ln); background: var(--red-bg); cursor: pointer; }
/* The bar of actions: above a message (below it at the top of the list) —
   on a long press, or while the pointer is over it on a computer. The bar's
   own padding bridges the gap, so moving onto it keeps it open. */
.msg-item { position: relative; }
.msg-tools { display: none; position: absolute; bottom: 100%; z-index: 6; padding-bottom: 4px; }
.msg-item:not(.is-mine) .msg-tools { left: 0; }
.msg-item.is-mine .msg-tools { right: 0; }
.msg-item.is-below .msg-tools { bottom: auto; top: 100%; padding: 4px 0 0; }
.msg-item.is-tools .msg-tools { display: block; }
@media (hover: hover) and (pointer: fine) { .msg-item:hover .msg-tools { display: block; } }
.msg-tools-in {
  display: flex; align-items: center; gap: 1px; padding: 3px; border-radius: 999px; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-2);
}
.msg-tool {
  width: 34px; height: 34px; border: 0; border-radius: 50%; background: none; color: var(--ink-mid);
  display: inline-flex; align-items: center; justify-content: center; font-size: 1.15rem; line-height: 1;
}
.msg-tool:hover { background: var(--sunken); }
.msg-tool.is-on { background: var(--red-bg); }
.msg-tool span { display: inline-flex; }
.msg-tool svg { width: 17px; height: 17px; }
.msg-tools-sep { width: 1px; height: 20px; margin: 0 3px; background: var(--border); }
.msg-item.is-tools .msg-bubble { box-shadow: 0 0 0 2px var(--line-2); }
/* On a touch screen a long press opens the bar, not the phone's text menu. */
@media (pointer: coarse) { .msg-bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; } }

/* The bubble, with a small pen beside it once edited. */
.msg-line { display: flex; align-items: center; gap: 6px; max-width: 100%; }
.msg-item.is-mine .msg-line { flex-direction: row-reverse; }
.msg-pen { flex: none; color: var(--ink-soft); opacity: .7; display: inline-flex; }
.msg-pen svg { width: 13px; height: 13px; }

/* "edited": there, but it shouldn't draw the eye. */
.msg-edited { opacity: .75; font-style: italic; }

.msg-composer { flex: none; margin: 0 -4px; padding: 8px 4px 10px; background: var(--paper); border-top: 1px solid var(--border); }
@media (min-width: 900px) { .msg-composer { padding-bottom: 18px; } }
.msg-thread .msg-closed { flex: none; margin-bottom: 10px; }
.msg-editbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 4px 6px 8px; font-size: .8rem; font-weight: 650; color: var(--ink-mid);
}
.msg-compose-row { display: flex; align-items: flex-end; gap: 6px; }
.msg-attach { flex: none; color: var(--ink-soft); }
.msg-attach:disabled { opacity: .35; cursor: default; }
.msg-tray { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 2px 8px; }
.msg-chip {
  display: flex; align-items: center; gap: 8px; padding: 5px 4px 5px 5px; max-width: 100%;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
}
.msg-chip img { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; flex: none; }
.msg-chip-name { font-size: .8rem; font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-chip-size { font-size: .72rem; color: var(--ink-soft); }
.msg-chip-x { width: 30px; height: 30px; }
.msg-chip-x svg { width: 16px; height: 16px; }
.msg-send.is-busy { animation: msg-pulse 1s ease-in-out infinite; }
@keyframes msg-pulse { 50% { opacity: .5; } }
textarea.input.msg-input {
  flex: 1; min-height: 44px; max-height: 160px; padding: 10px 16px; resize: none; border-radius: 22px; line-height: 1.45;
  overflow-y: hidden;
}
.msg-send {
  flex: none; width: 44px; height: 44px; border: 0; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--red); color: var(--on-red); transition: opacity .15s;
}
.msg-send svg { width: 20px; height: 20px; }
.msg-send:disabled { opacity: .35; cursor: default; }
.msg-closed { margin-top: 8px; padding: 12px 14px; border-radius: 12px; background: var(--sunken); color: var(--ink-soft); font-size: .86rem; text-align: center; }

.msg-actions { display: flex; flex-direction: column; gap: 10px; }
.msg-actions .btn span { display: inline-flex; }
.msg-actions .btn svg { width: 18px; height: 18px; }

/* Admin → a student: the Messages switch. */
.st-msg {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 14px; padding: 10px 12px; border-radius: 12px; background: var(--sunken);
}
.st-msg-text { display: flex; flex-direction: column; min-width: 0; }
.st-msg-text b { font-size: .9rem; }
.st-msg-text span { font-size: .8rem; color: var(--ink-soft); }
.st-msg-act { display: flex; align-items: center; gap: 10px; flex: none; }
