/* messages area styles (wave 3, messages builder). Use app.css tokens; keep the restrained house style. */

/* ---------------------------------------------------------------- layout */
.msg-page .page-head { margin-bottom: 18px; }
.msg-layout { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 16px; height: min(800px, calc(100dvh - var(--topbar) - 176px)); min-height: 520px; }
.msg-list, .msg-pane { padding: 0; display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.msg-items { flex: 1; overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.msg-items > .stack { padding: 14px; }
.msg-items .empty { padding: 36px 18px; }
.msg-tabs { margin: 0; padding: 0 8px; flex: none; }
.msg-tabs button { height: 44px; padding: 0 10px; }
.msg-count { font-size: 11.5px; font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.msg-count:empty { display: none; }
.msg-unread { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--brand); color: #fff; font-size: 11px; font-weight: 650; display: inline-grid; place-items: center; font-variant-numeric: tabular-nums; }
.msg-unread:empty { display: none; }
.msg-pane-empty { flex: 1; display: grid; place-items: center; }
.msg-pane-pad { padding: 20px; }

/* ------------------------------------------------------------ list items */
.msg-item { position: relative; display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; transition: background .15s; }
.msg-item:hover { background: var(--surface-2); }
.msg-item[aria-current="true"] { background: var(--surface-2); }
.msg-item[aria-current="true"]::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 2px; border-radius: 0 2px 2px 0; background: var(--ink); }
.msg-item .subj-badge, .msg-item .avatar { flex: none; margin-top: 1px; }
.msg-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.msg-item-main b { font-weight: 550; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.msg-item.unread .msg-item-main > .row b, .msg-item.unread .msg-item-title { font-weight: 700; }
.msg-item-sub { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-item-prev { font-size: 13px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.msg-item-main .msg-item-title { font-weight: 500; font-size: 13px; white-space: normal; overflow: visible; }
.msg-item .nowrap { white-space: nowrap; flex: none; }
.msg-wait { color: var(--warn); font-weight: 600; }
.msg-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); flex: none; display: inline-block; }
.msg-item > .msg-dot { position: absolute; right: 14px; bottom: 16px; }
.msg-office-badge { --h: 0; background: var(--surface-3) !important; color: var(--ink-2) !important; display: inline-grid; place-items: center; }

/* ---------------------------------------------------------------- thread */
.msg-thread { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.msg-head { display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 16px; border-bottom: 1px solid var(--line); flex: none; min-width: 0; }
.msg-who { flex: 1; min-width: 0; line-height: 1.3; }
.msg-who b { display: block; font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-who span { display: block; font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-head-status { flex: none; }
.msg-ctx { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); font-size: 13px; color: var(--ink-2); text-decoration: none; flex: none; min-width: 0; }
.msg-ctx > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-ctx svg { flex: none; color: var(--ink-3); }
a.msg-ctx:hover { color: var(--ink); }
.msg-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 16px 8px; display: flex; flex-direction: column; overscroll-behavior: contain; }
.msg-scroll:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.msg-flow { display: flex; flex-direction: column; }
.msg-private { align-self: center; display: inline-flex; align-items: center; gap: 6px; max-width: 100%; text-align: center; font-size: 12px; color: var(--ink-3); padding: 4px 11px; border: 1px solid var(--line); border-radius: 14px; margin: 0 0 12px; }
.msg-private svg { flex: none; }
.msg-private.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); background: var(--warn-tint); margin: 10px 0 4px; }
.msg-day { align-self: center; font-size: 11.5px; font-weight: 600; color: var(--ink-3); margin: 14px 0 8px; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); }
.msg-sys { align-self: center; display: inline-flex; align-items: flex-start; gap: 6px; max-width: 88%; text-align: left; font-size: 12.5px; color: var(--ink-2); margin: 8px 0 10px; padding: 7px 11px; border-radius: var(--r); background: var(--surface-2); }
.msg-sys svg { flex: none; margin-top: 2px; color: var(--ink-3); }
.msg-sys .faint { white-space: nowrap; }
.msg-row { display: flex; flex-direction: column; align-items: flex-start; max-width: min(78%, 620px); min-width: 0; }
.msg-row.me { align-self: flex-end; align-items: flex-end; }
.msg-row.enter { animation: msgIn .32s var(--ease) both; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } }
.msg-name { font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 8px 4px 4px; }
.msg-b { padding: 9px 13px; border-radius: 14px; border-bottom-left-radius: 5px; font-size: 14px; line-height: 1.55; background: var(--surface-2); border: 1px solid var(--line); overflow-wrap: anywhere; max-width: 100%; }
.msg-row.me .msg-b { background: var(--ink); color: var(--bg); border-color: var(--ink); border-bottom-left-radius: 14px; border-bottom-right-radius: 5px; }
.msg-b p + p { margin-top: 8px; }
.msg-b a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.msg-b .math-block { margin: 6px 0; }
.msg-meta { font-size: 11px; color: var(--ink-3); margin: 3px 5px 6px; font-variant-numeric: tabular-nums; }
.msg-seen { align-self: flex-end; font-size: 11.5px; color: var(--ink-3); margin: -4px 5px 6px; }
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; max-width: 100%; }
.msg-row.me .msg-files { justify-content: flex-end; }
.msg-img { display: block; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); max-width: min(260px, 100%); }
.msg-img img { display: block; max-width: 100%; max-height: 260px; object-fit: cover; }
.msg-file { display: inline-flex; align-items: center; gap: 8px; padding: 8px 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; font-size: 13px; max-width: 100%; }
.msg-file .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; font-weight: 550; }
.msg-file:hover { border-color: var(--ink-3); }

/* book hint (never presented as the teacher) */
.msg-hint { border: 1px dashed var(--line-2); border-radius: var(--r-lg); padding: 12px 14px; margin: 0 0 14px; font-size: 13.5px; background: var(--surface); }
.msg-hint .eyebrow { display: flex; align-items: center; gap: 6px; }
.msg-hint h3 { font-size: 14px; margin: 6px 0 8px; }
.msg-hint-body blockquote { margin: 6px 0; padding: 6px 12px; border-left: 2px solid var(--ink-3); background: var(--surface-2); border-radius: 0 8px 8px 0; font-family: var(--font-read); line-height: 1.6; }
.msg-hint-body ul { margin: 6px 0; padding-left: 18px; }
.msg-hint-body p + p { margin-top: 6px; }
.msg-hint.staff { padding: 0; }
.msg-hint.staff summary { cursor: pointer; padding: 9px 12px; display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); list-style: none; }
.msg-hint.staff summary::-webkit-details-marker { display: none; }
.msg-hint.staff .msg-hint-body { padding: 0 12px 10px; }

/* composer */
.msg-compose { border-top: 1px solid var(--line); padding: 10px 12px 8px; display: flex; flex-direction: column; gap: 8px; flex: none; background: var(--surface); }
.msg-compose-row { display: flex; align-items: flex-end; gap: 6px; }
.msg-compose-row textarea { flex: 1; min-height: 40px; max-height: 168px; resize: none; line-height: 1.45; }
.msg-compose-row .btn { height: 40px; }
.msg-compose-row .iconbtn { height: 40px; width: 36px; flex: none; }
.msg-compose-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 11.5px; color: var(--ink-3); flex-wrap: wrap; }
.msg-compose-foot > span { display: inline-flex; align-items: center; gap: 5px; }
.msg-compose-foot .textlink { font-size: 12px; }
.msg-filebox { display: flex; flex-wrap: wrap; gap: 6px; }
.msg-chipfile { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; padding: 4px 4px 4px 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-size: 12.5px; }
.msg-chipfile img { width: 30px; height: 30px; border-radius: 6px; object-fit: cover; }
.msg-chipfile .nm { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.msg-chipfile .iconbtn { width: 26px; height: 26px; }
.msg-preview { border: 1px solid var(--line); border-radius: var(--r); padding: 8px 12px; background: var(--surface-2); font-size: 14px; overflow-x: auto; }
.msg-preview .eyebrow { display: block; margin-bottom: 4px; }

/* new question */
.msg-new { flex: 1; overflow-y: auto; padding: 20px 22px; min-height: 0; }
.msg-new-head { display: flex; align-items: flex-start; gap: 10px; }
.msg-new-head h2 { font-size: 18px; }
.msg-new-form { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.msg-new-form textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.msg-attach-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.msg-route { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 14px; margin-top: 6px; min-height: 52px; }
.msg-route-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.msg-route-line .label { margin-right: 2px; }
.msg-route .chip.ink svg, .msg-route .chip.outline svg { width: 13px; height: 13px; }
.msg-finding { animation: msgPulse 1.6s var(--ease) infinite alternate; }
@keyframes msgPulse { from { opacity: .45; } to { opacity: 1; } }
.msg-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.msg-pick .chip { height: 32px; }
.msg-new-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px;  border-top: 1px solid var(--line); padding-top: 14px; margin-top: 6px; }
.msg-new-foot p { display: inline-flex; align-items: center; gap: 6px; flex: 1 1 auto; min-width: 0; }
.msg-new-foot .row { flex: none; }

/* ------------------------------------------------------- embeddable box */
.msg-ask { padding: 16px; }
.msg-ask-head { display: flex; gap: 11px; align-items: flex-start; }
.msg-ask-head h3 { font-size: 14.5px; line-height: 1.3; }
.msg-ask-mark { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); flex: none; }
.msg-ask form { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.msg-ask textarea { resize: none; min-height: 60px; }
.msg-ask-foot { display: flex; align-items: center; gap: 2px; }
.msg-ask-foot .iconbtn { width: 34px; height: 34px; }
.msg-ask-private { flex: 1; display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; min-width: 0; }
.msg-ask-done { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0 2px; }
.msg-ask-done > svg { color: var(--ok); flex: none; margin-top: 2px; }
.msg-ask-earlier { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.msg-ask-earlier .eyebrow { margin-bottom: 4px; }
.msg-ask-earlier a { display: flex; align-items: center; gap: 8px; padding: 6px 0; text-decoration: none; font-size: 13px; min-width: 0; }
.msg-ask-earlier .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.msg-ask-earlier a:hover .nm { text-decoration: underline; text-underline-offset: 2px; }

/* --------------------------------------------------------- home cards */
.msg-slot { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .2s; }
.msg-slot:hover { border-color: var(--line-2); box-shadow: var(--sh-2); }
.msg-slot .card-head { margin-bottom: 4px; }
.msg-slot .card-head h3 { display: inline-flex; align-items: center; gap: 8px; }
.msg-slot-v { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.msg-slot-v .v { font: 700 30px/1 var(--font-display); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------- administrators */
.msg-routing .pick { align-items: flex-start; }
.msg-routing .pick input { margin-top: 2px; }
.msg-case { padding: 0; display: flex; flex-direction: column; height: min(760px, calc(100dvh - var(--topbar) - 200px)); min-height: 460px; overflow: hidden; }
.msg-case > div { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.msg-quote { margin: 0; padding: 8px 12px; border-left: 2px solid var(--ink-3); background: var(--surface-2); border-radius: 0 8px 8px 0; font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ----------------------------------------------------------- small screens */
@media (max-width: 980px) {
  .msg-layout { grid-template-columns: minmax(0, 1fr); height: auto; min-height: 0; }
  .msg-layout[data-view="list"] .msg-pane { display: none; }
  .msg-layout[data-view="thread"] .msg-list { display: none; }
  .msg-page.in-thread { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .msg-page.in-thread .msg-page-head { display: none; }
  .msg-layout[data-view="thread"] { height: calc(100dvh - var(--topbar) - 84px - env(safe-area-inset-bottom)); min-height: 420px; }
  .msg-layout[data-view="thread"] .msg-pane { border-radius: var(--r-lg); }
  .msg-row { max-width: 88%; }
  .msg-new { padding: 16px; }
  .msg-head { padding: 10px 10px 10px 8px; gap: 8px; }
  .msg-head .avatar { width: 30px; height: 30px; font-size: 11px; }
  .msg-case { height: 70dvh; }
}
@media (max-width: 680px) {
  .msg-page-head .actions { width: 100%; }
  .msg-page-head .actions .btn { flex: 1; justify-content: center; }
  .msg-new-foot { flex-direction: column; align-items: stretch; }
  .msg-new-foot .row { justify-content: space-between; }
  .msg-compose-foot > span { display: none; }
}
.msg-route .chip { white-space: normal; height: auto; min-height: 24px; padding: 3px 9px; max-width: 100%; line-height: 1.35; }
.msg-pick .chip { height: auto; min-height: 32px; white-space: normal; text-align: left; }
.msg-ask-about { display: flex; align-items: center; gap: 7px; margin-top: 10px; padding: 6px 10px; border-radius: var(--r); background: var(--surface-2); font-size: 12.5px; color: var(--ink-2); }
.msg-ask-about svg { flex: none; color: var(--ink-3); }
.msg-ask-gap { flex: 1; }
