/* =====================================================================
   PrepMode EduTech - messages.css v2: the Messages page (js/messages.js, database file 154)
   v2 (25 Nov): every class renamed ms- -> msg-. The Students page (app.js/app.css) already uses ms-, and v1 pushed its student list off screen.
   Uses the portal's own colours (--brand is each institute's colour). Approved designs: canvas "PrepMode Messages — designs".
   ===================================================================== */
.msg-body { min-width: 0; }
.msg-wrap { display: grid; grid-template-columns: 320px minmax(0, 1fr) 280px; height: calc(100vh - 210px); min-height: 520px; background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; position: relative; }
/* list */
.msg-list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--rule); }
.msg-list-top { padding: 14px 14px 10px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--rule-2); }
.msg-search { width: 100%; min-height: 42px; border: 1px solid var(--field); border-radius: 10px; padding: 9px 12px; font: inherit; }
.msg-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.msg-chip { border: 1px solid var(--rule); background: var(--surface); color: var(--slate); border-radius: 999px; padding: 6px 12px; font: 500 12px var(--font); cursor: pointer; min-height: 32px; }
.msg-chip[aria-pressed=true] { background: var(--ink); color: #fff; border-color: var(--ink); }
.msg-items { overflow-y: auto; flex: 1 1 auto; }
.msg-item { display: flex; gap: 12px; align-items: flex-start; width: 100%; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--rule-2); background: none; text-align: left;
  font: inherit; color: inherit; cursor: pointer; }
.msg-item:hover { background: var(--paper); }
.msg-item.on { background: var(--brand-soft); }
.msg-item:focus-visible, .msg-pick-i:focus-visible, .msg-chip:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: -3px; }
.msg-item-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.msg-item-top { display: flex; justify-content: space-between; gap: 8px; }
.msg-item-top b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-item.unread .msg-item-top b { font-weight: 700; }
.msg-item-top small { color: #667085; font-size: 12px; white-space: nowrap; }
.msg-item-sub { font-size: 12px; color: color-mix(in srgb, var(--brand) 75%, var(--ink)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-item-last { font-size: 13px; color: var(--slate); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-item.unread .msg-item-last { color: var(--ink); }
.msg-count { flex: none; align-self: center; min-width: 22px; height: 22px; border-radius: 999px; background: var(--brand); color: var(--brand-ink); font: 700 12px/22px var(--font); text-align: center; padding: 0 6px; }
.msg-list-h { display: flex; justify-content: space-between; padding: 16px 14px 6px; font-size: 12px; font-weight: 600; color: var(--slate); text-transform: uppercase; letter-spacing: .04em; }
.msg-list-h small { text-transform: none; letter-spacing: 0; font-weight: 500; color: #667085; }
.msg-none { padding: 18px 14px; color: var(--slate); font-size: 14px; }
/* avatars and dots */
.msg-av-wrap { position: relative; flex: none; display: inline-flex; }
.msg-av { width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font: 600 13px var(--font); color: var(--ink); flex: none; }
.msg-av.sq { border-radius: 10px; }
.msg-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.msg-av-wrap .msg-dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border: 2px solid #fff; }
.msg-dot.on { background: #12B76A; } .msg-dot.busy { background: #F79009; } .msg-dot.off { background: #FFC857; } .msg-dot.none { display: none; }
/* chat */
.msg-chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper); }
.msg-chat-h { display: flex; align-items: center; gap: 12px; padding: 12px 18px; background: var(--surface); border-bottom: 1px solid var(--rule); }
.msg-chat-t { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.msg-chat-t b { font-size: 16px; }
.msg-chat-t small { color: var(--slate); font-size: 12px; }
.msg-st.ok { color: var(--ok); } .msg-st.off { color: var(--warn-ink); } .msg-st.busy { color: var(--warn-ink); }
.msg-back, .msg-info, .msg-round { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--field); background: var(--surface); color: var(--slate); display: inline-flex; align-items: center;
  justify-content: center; cursor: pointer; flex: none; font: 700 14px var(--font); }
.msg-back .ico, .msg-round .ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.msg-back, .msg-info { display: none; }
.msg-banner { display: flex; gap: 8px; align-items: center; margin: 12px 18px 0; padding: 9px 12px; border-radius: 10px; background: var(--brand-soft);
  color: color-mix(in srgb, var(--brand) 80%, var(--ink)); font-size: 13px; }
.msg-banner .ico { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; }
.msg-scroll { flex: 1 1 auto; overflow-y: auto; padding: 8px 18px 16px; }
.msg-pad { padding: 18px; }
.msg-older { display: block; margin: 6px auto; }
.msg-msgs { display: flex; flex-direction: column; gap: 2px; }
.msg-day { text-align: center; margin: 14px 0 8px; } .msg-day span { font-size: 12px; color: #667085; background: var(--paper); padding: 0 8px; }
.msg-msg { display: flex; flex-direction: column; align-items: flex-start; max-width: 74%; margin-top: 10px; }
.msg-msg.cont { margin-top: 2px; }
.msg-msg.mine { align-self: flex-end; align-items: flex-end; }
.msg-from { font-size: 12px; font-weight: 600; color: var(--slate); margin: 0 0 3px 4px; }
.msg-b-row { display: flex; align-items: center; gap: 4px; position: relative; max-width: 100%; }
.msg-msg.mine .msg-b-row { flex-direction: row-reverse; }
.msg-b { background: var(--surface); border: 1px solid var(--rule); border-radius: 14px 14px 14px 4px; padding: 9px 13px; min-width: 0; overflow-wrap: anywhere; display: flex; flex-direction: column; gap: 6px; }
.msg-msg.mine .msg-b { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); border-radius: 14px 14px 4px 14px; }
.msg-msg.mine .msg-b a { color: inherit; text-decoration: underline; }
.msg-b.file-only { padding: 4px; }
.msg-b.gone { background: transparent !important; border: 1px dashed var(--field) !important; color: var(--slate) !important; }
.msg-text { white-space: pre-wrap; }
.msg-unsent { font-size: 13px; }
.msg-meta { font-size: 11px; color: #667085; margin: 3px 4px 0; }
.msg-opt { width: 30px; height: 30px; border-radius: 50%; border: 0; background: none; color: #98A2B3; cursor: pointer; opacity: 0; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.msg-opt .ico { width: 16px; height: 16px; fill: currentColor; }
.msg-msg:hover .msg-opt, .msg-opt:focus-visible, .msg-opt[aria-expanded=true] { opacity: 1; }
@media (hover: none) { .msg-opt { opacity: .7; } }
.msg-menu { position: absolute; top: 100%; z-index: 30; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; box-shadow: 0 12px 30px rgba(16, 24, 40, .14);
  padding: 6px; display: flex; flex-direction: column; min-width: 190px; }
.msg-msg.mine .msg-menu { right: 0; } .msg-msg:not(.mine) .msg-menu { left: 0; }
.msg-menu-i { border: 0; background: none; text-align: left; padding: 10px 12px; border-radius: 8px; font: inherit; color: var(--ink); cursor: pointer; }
.msg-menu-i:hover, .msg-menu-i:focus-visible { background: var(--rule-2); } .msg-menu-i.bad { color: var(--danger); }
.msg-photo { border: 0; padding: 0; background: var(--rule-2); border-radius: 11px; overflow: hidden; cursor: pointer; display: block; position: relative; width: 240px; min-height: 120px; }
.msg-img { display: block; width: 100%; max-height: 320px; object-fit: cover; }
.msg-photo-l { position: absolute; left: 8px; bottom: 8px; background: rgba(16, 24, 40, .65); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.msg-photo.bad::after { content: "Photo couldn't load. Tap to open."; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--slate); font-size: 12px; }
.msg-pdf { display: flex; gap: 10px; align-items: center; border: 1px solid var(--rule); background: var(--surface); border-radius: 10px; padding: 8px 12px; cursor: pointer; text-align: left; font: inherit; color: var(--ink); }
.msg-pdf-ic { width: 34px; height: 42px; border-radius: 6px; background: #FEF3F2; color: var(--danger); font: 700 10px var(--font); display: flex; align-items: center; justify-content: center; flex: none; }
.msg-pdf b { display: block; font-size: 13px; } .msg-pdf small { color: #667085; font-size: 12px; }
/* the "can't reply now" card */
.msg-away { display: flex; gap: 14px; margin: 16px auto 4px; max-width: 540px; background: var(--surface); border: 1px solid var(--rule); border-radius: 16px; padding: 16px 18px; }
.msg-away-ic { flex: none; width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: #FFF6DD; color: var(--warn-ink); }
.msg-away-ic .ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
.msg-away b { font-size: 15px; } .msg-away p { margin: 4px 0 0; color: var(--slate); }
.msg-note { font-style: italic; }
.msg-urgent { font-size: 13px; }
/* writing */
.msg-comp { background: var(--surface); border-top: 1px solid var(--rule); padding: 10px 14px; }
.msg-comp-row { display: flex; gap: 10px; align-items: flex-end; }
.msg-input { flex: 1 1 auto; min-height: 44px; max-height: 160px; resize: none; border: 1px solid var(--field); border-radius: 22px; padding: 11px 16px; font: inherit; line-height: 1.4; }
.msg-input:focus { outline: 3px solid color-mix(in srgb, var(--brand) 30%, transparent); border-color: var(--brand); }
.msg-send { flex: none; }
.msg-attach-chip { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; color: var(--slate); }
.msg-attach-chip .ico { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; vertical-align: -2px; }
.msg-ro { background: var(--surface); border-top: 1px solid var(--rule); padding: 16px; text-align: center; color: var(--slate); font-size: 14px; }
.msg-empty { margin: auto; text-align: center; color: var(--slate); padding: 30px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.msg-empty-ic { width: 44px; height: 44px; fill: none; stroke: var(--field); stroke-width: 1.6; }
/* side panel */
.msg-side { border-left: 1px solid var(--rule); padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; background: var(--surface); }
.msg-side-x { display: none; }
.msg-side-h { font-size: 12px; font-weight: 600; color: var(--slate); letter-spacing: .04em; text-transform: uppercase; margin-bottom: 10px; }
.msg-people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; font-size: 13px; }
.msg-people li { display: flex; justify-content: space-between; gap: 8px; }
.msg-people small { display: block; color: #667085; font-size: 12px; }
.msg-people em { font-style: normal; color: #667085; white-space: nowrap; }
.msg-side-p { margin: 0 0 4px; font-size: 13px; }
.msg-side-foot { margin-top: auto; font-size: 12px; color: #667085; line-height: 1.5; }
.msg-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: 13px; }
/* dialogs */
.msg-shade { position: fixed; inset: 0; background: rgba(16, 24, 40, .55); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.msg-dlg { background: var(--surface); border-radius: 18px; width: min(480px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(16, 24, 40, .35); }
.msg-dlg.wide { width: min(620px, 100%); }
.msg-dlg-h { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 8px; }
.msg-dlg-b { padding: 4px 20px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.msg-dlg-f { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; border-top: 1px solid var(--rule-2); flex-wrap: wrap; }
.msg-dlg-b > input[type=search] { min-height: 44px; border: 1px solid var(--field); border-radius: 10px; padding: 9px 12px; font: inherit; }
.msg-x { width: 40px; height: 40px; border: 0; background: var(--rule-2); border-radius: 50%; font-size: 20px; color: var(--slate); cursor: pointer; flex: none; }
.msg-x.small { width: 28px; height: 28px; font-size: 16px; }
.msg-field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; }
.msg-field input, .msg-field textarea, .msg-field select { min-height: 42px; border: 1px solid var(--field); border-radius: 10px; padding: 9px 12px; font: inherit; font-weight: 400; }
.msg-field-l { margin: 0; font-weight: 500; font-size: 14px; }
.msg-pick-g h3 { font-size: 12px; font-weight: 600; color: var(--slate); text-transform: uppercase; letter-spacing: .04em; margin: 8px 0 4px; }
.msg-pick-i { display: flex; gap: 12px; align-items: center; width: 100%; min-height: 56px; border: 0; background: none; padding: 8px 6px; border-radius: 10px; cursor: pointer; text-align: left; font: inherit; color: inherit; }
.msg-pick-i:hover { background: var(--paper); }
.msg-pick-m { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; } .msg-pick-m small { color: var(--slate); font-size: 12px; }
.msg-pick-st { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--slate); white-space: nowrap; }
.msg-pick-note { background: var(--paper); border-radius: 10px; padding: 10px 12px; font-size: 12px; color: var(--slate); margin: 8px 0 0; }
.msg-checks { display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow-y: auto; }
.msg-check, .msg-radio { display: flex; gap: 10px; align-items: center; padding: 8px 4px; font-size: 14px; cursor: pointer; }
.msg-check small { display: block; color: #667085; font-size: 12px; }
.msg-check input, .msg-radio input { width: 18px; height: 18px; accent-color: var(--brand); }
.msg-radios { display: flex; flex-direction: column; }
/* switches */
.msg-sw { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; position: relative; }
.msg-sw-i { position: absolute; opacity: 0; width: 44px; height: 26px; margin: 0; cursor: pointer; }
.msg-sw-t { width: 44px; height: 26px; border-radius: 999px; background: var(--field); position: relative; transition: background .15s; flex: none; }
.msg-sw-t::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.msg-sw-i:checked + .msg-sw-t { background: var(--brand); }
.msg-sw-i:checked + .msg-sw-t::after { transform: translateX(18px); }
.msg-sw-i:focus-visible + .msg-sw-t { outline: 3px solid color-mix(in srgb, var(--brand) 40%, transparent); outline-offset: 2px; }
/* reply hours, settings, safety */
.msg-h-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
.msg-h-col { display: flex; flex-direction: column; gap: 0; }
.msg-h-row { display: grid; grid-template-columns: 110px 70px minmax(0, 1fr); gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--rule-2); }
.msg-h-row.head { color: var(--slate); font-size: 12px; font-weight: 600; border-bottom-color: var(--rule); padding-top: 0; }
.msg-h-times { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.msg-h-times input { min-height: 40px; border: 1px solid var(--field); border-radius: 8px; padding: 6px 10px; font: inherit; }
.msg-h-off { display: inline-flex; gap: 6px; align-items: center; color: var(--warn-ink); font-weight: 600; }
.msg-h-who { margin: 0 0 8px; }
.msg-h-week .msg-field { margin-top: 12px; }
.msg-away-list { display: flex; flex-direction: column; gap: 8px; }
.msg-away-i { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--paper); font-size: 13px; }
.msg-away-i small { display: block; color: var(--slate); font-size: 12px; }
.link-btn.bad { color: var(--danger); }
.msg-prev-wrap { background: var(--ink); color: #fff; border-color: var(--ink); }
.msg-prev-h { font-size: 12px; font-weight: 600; color: #98A2B3; letter-spacing: .04em; text-transform: uppercase; }
.msg-prev-card { margin-top: 12px; background: #fff; color: var(--ink); border-radius: 12px; padding: 12px 14px; }
.msg-prev-card p { margin: 4px 0 0; color: var(--slate); font-size: 13px; }
.msg-set-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--rule-2); }
.msg-set-row small { display: block; color: var(--slate); font-size: 13px; margin-top: 2px; }
.msg-closed-add { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 12px; align-items: end; }
.msg-closed-add .btn { grid-column: 1 / -1; justify-self: start; }
.msg-staff { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.msg-warn { background: #FFFAEB; color: var(--warn-ink); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.msg-rep { border: 1px solid var(--rule); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.msg-rep.open { border-color: #FDA29B; }
.msg-rep-top { display: flex; justify-content: space-between; } .msg-rep-top small { color: #667085; }
.msg-rep-q { margin: 6px 0; } .msg-rep .muted { margin: 0; }
.msg-find { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; } .msg-find small { color: var(--slate); font-weight: 400; }
.msg-log { display: flex; flex-direction: column; } .msg-log-i { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 9px 0; border-top: 1px solid var(--rule-2); font-size: 13px; }
.msg-log-i small { color: #667085; } .msg-log-i span small { display: block; color: var(--slate); }
.msg-tr-list { display: flex; flex-direction: column; gap: 10px; }
.msg-tr { border-bottom: 1px solid var(--rule-2); padding-bottom: 8px; } .msg-tr p { margin: 4px 0 0; white-space: pre-wrap; }
.msg-tr-h { display: flex; gap: 8px; align-items: center; } .msg-tr-h small { color: #667085; }
.msg-tr-orig { color: var(--slate); font-size: 13px; font-style: italic; }
.msg-tag { font-size: 11px; font-weight: 600; background: var(--rule-2); border-radius: 999px; padding: 1px 8px; color: var(--slate); }
.msg-tag.bad { background: #FEF3F2; color: var(--danger); }
/* narrower screens: the side panel slides in; on phones one column at a time */
@media (max-width: 1280px) {
  .msg-wrap { grid-template-columns: 300px minmax(0, 1fr); }
  .msg-info { display: inline-flex; }
  .msg-side { position: absolute; top: 0; right: 0; bottom: 0; width: 300px; z-index: 20; box-shadow: -12px 0 30px rgba(16, 24, 40, .12); transform: translateX(105%); transition: transform .2s; }
  .msg-wrap.side-open .msg-side { transform: none; }
  .msg-side-x { display: block; align-self: flex-end; width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--rule-2); font-size: 18px; cursor: pointer; }
}
@media (max-width: 860px) {
  .msg-wrap { grid-template-columns: minmax(0, 1fr); height: auto; min-height: 60vh; }
  .msg-wrap.has-chat { height: calc(100vh - 140px); height: calc(100dvh - 140px); min-height: 420px; }
  .page:has(.msg-wrap.has-chat) > .msg-head { display: none; }
  .msg-wrap.has-chat .msg-list { display: none; }
  .msg-wrap:not(.has-chat) .msg-chat { display: none; }
  .msg-back { display: inline-flex; }
  .msg-msg { max-width: 86%; }
  .msg-scroll { padding: 6px 12px 12px; } .msg-banner { margin: 10px 12px 0; } .msg-chat-h { padding: 10px 12px; }
  .msg-h-grid { grid-template-columns: minmax(0, 1fr); }
  .msg-h-row { grid-template-columns: 90px 56px minmax(0, 1fr); }
  .msg-send { padding-left: 14px; padding-right: 14px; }
}
@media (prefers-reduced-motion: reduce) { .msg-side, .msg-sw-t, .msg-sw-t::after { transition: none; } }
