/* css/student-chat.css - the student's Messages page (app/student/chat): one private conversation with DSP staff.
 * Three parts that read as one: a compact header, the scrolling history, and the composer. The panel is given exactly the height left on the
 * screen by js/support-student.js (--sc-h, also above a phone keyboard), so only the history scrolls and the composer never leaves the screen. */
.sc {
    --sc-h: calc(100vh - var(--topbar-h) - var(--bottomnav-h));
    display: flex; flex-direction: column; width: 100%; height: var(--sc-h); min-height: 0; margin: 0 auto; padding: 0; /* style.css gives every section 90px of padding */
    background: var(--c-surface); overflow: hidden;
}
.sc, .sc * { min-width: 0; box-sizing: border-box; }
.sc [hidden] { display: none !important; }
.sc-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* header */
.sc-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--c-border); background: var(--c-surface); }
.sc-mark { flex: none; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--c-primary); color: var(--c-text-on-primary, #fff); font-size: 1rem; }
.sc-id { flex: 1; }
.sc-id h1 { margin: 0; font-size: 1.02rem; line-height: 1.25; letter-spacing: -0.005em; color: var(--c-text); }
.sc-id p { margin: 1px 0 0; font-size: 0.78rem; line-height: 1.3; color: var(--c-text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-icon { flex: none; display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: none; color: var(--c-text-secondary); font-size: 1.05rem; cursor: pointer; }
.sc-icon:hover { background: var(--c-primary-soft); color: var(--c-primary); }
.sc-icon:focus-visible, .sc-send:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.sc-icon:disabled { opacity: 0.55; cursor: progress; }
.sc-icon.is-spinning i { animation: sc-spin 0.8s linear infinite; }
@keyframes sc-spin { to { transform: rotate(360deg); } }

/* history */
.sc-list { flex: 1; display: flex; flex-direction: column; gap: 6px; padding: 12px; overflow-y: auto; overscroll-behavior: contain; background: #f3f6f8; scroll-behavior: auto; }
.sc-list:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--c-focus); }
.sc-day { align-self: center; margin: 8px 0 4px; padding: 2px 10px; border-radius: 999px; background: #e3e9ee; color: var(--c-text-secondary); font-size: 0.72rem; font-weight: 600; }
.chat-msg { max-width: min(75%, 520px); padding: 8px 12px 6px; border-radius: 16px; font-size: 0.95rem; line-height: 1.42; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.chat-msg.student { align-self: flex-end; background: var(--c-primary); color: #fff; border-bottom-right-radius: 5px; }
.chat-msg.staff { align-self: flex-start; background: #fff; color: var(--c-text); border: 1px solid var(--c-border); border-bottom-left-radius: 5px; }
.chat-msg + .chat-msg.student:not(:first-child), .chat-msg.student + .chat-msg.student { margin-top: 0; }
.chat-msg small { display: block; margin-top: 3px; font-size: 0.68rem; line-height: 1.2; text-align: right; opacity: 0.72; font-variant-numeric: tabular-nums; }
.chat-msg .chat-image { display: block; margin: 0 0 6px; }
.chat-msg .chat-image img { max-width: 100%; height: auto; max-height: 260px; border-radius: 10px; }
.chat-msg.is-sending { opacity: 0.7; }

/* empty, loading, load error */
.sc-empty { margin: auto; max-width: 320px; padding: 16px; text-align: center; color: var(--c-text-secondary); }
.sc-empty i { display: grid; place-items: center; width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 50%; background: var(--c-primary-soft); color: var(--c-primary); font-size: 1.4rem; }
.sc-empty h2 { margin: 0 0 4px; font-size: 1.05rem; color: var(--c-text); }
.sc-empty p { margin: 0; font-size: 0.9rem; line-height: 1.45; }
.sc-empty .sc-retry { margin-top: 12px; min-height: 44px; padding: 0 16px; border: 1px solid var(--c-border-strong); border-radius: 10px; background: var(--c-surface); color: var(--c-primary); font: 600 0.9rem var(--font-sans); cursor: pointer; }
.sc-skeleton { display: grid; gap: 10px; }
.sc-skeleton span { height: 38px; width: 58%; border-radius: 16px; background: #e3e9ee; animation: sc-pulse 1.3s ease-in-out infinite; }
.sc-skeleton span:nth-child(2) { justify-self: end; width: 44%; }
@keyframes sc-pulse { 50% { opacity: 0.5; } }

/* composer */
.sc-composer { flex: none; padding: 8px 10px 8px; border-top: 1px solid var(--c-border); background: var(--c-surface); }
.sc-error { margin: 0 0 6px; padding: 7px 10px; border-radius: 10px; background: var(--c-danger-bg); color: #8a1a10; font-size: 0.85rem; }
.sc-error:empty { display: none; }
.sc-composer .chat-attach { margin-bottom: 8px; }
.sc-box { display: flex; align-items: flex-end; gap: 6px; padding: 4px 4px 4px 2px; border: 1px solid var(--c-border-strong); border-radius: 24px; background: #fff; transition: border-color 0.15s ease, box-shadow 0.15s ease; }
.sc-box:focus-within { border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-soft); }
.sc-attach { width: 44px; height: 44px; }
.sc-box textarea { flex: 1; align-self: center; min-height: 24px; max-height: 140px; margin: 0; padding: 10px 2px; border: 0; outline: 0; resize: none; background: transparent; color: var(--c-text); font: inherit; font-size: 1rem; line-height: 1.4; overflow-y: auto; }
.sc-box textarea::placeholder { color: var(--c-text-muted); }
.sc-send { flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 44px; height: 44px; padding: 0; border: 0; border-radius: 22px; background: var(--c-primary); color: #fff; font: 650 0.92rem var(--font-sans); cursor: pointer; }
.sc-send:hover:not(:disabled) { background: var(--c-primary-hover); }
.sc-send:disabled { background: #c5d3da; cursor: not-allowed; }
.sc-send.is-busy { cursor: progress; }
.sc-send-text { display: none; }
.sc-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 5px 6px 0; font-size: 0.7rem; line-height: 1.3; color: var(--c-text-muted); }
.sc-foot span { display: none; }
.sc-foot small { margin-left: auto; font-variant-numeric: tabular-nums; }

/* phones: the panel is the page */
@media (max-width: 768px) {
    body.chat-page.student-app .main-content { padding: 0 0 var(--bottomnav-h); }
    body.chat-page.student-app .main-content { padding-bottom: 0; }   /* the panel is sized to end exactly above the navigation */
    body.chat-page.student-app .app-bottomnav { bottom: var(--kb, 0px); }   /* lifted above a phone keyboard, never hidden */
    body.chat-page.student-app #chatAlert { margin: 8px 12px 0; }
    .chat-msg { max-width: 86%; }
}
@media (max-width: 359px) {
    .sc-head { padding: 8px; gap: 8px; }
    .sc-list { padding: 10px 8px; }
    .sc-id p { display: none; }
}

/* tablet and desktop: a centred conversation with a readable width */
@media (min-width: 640px) {
    .sc-send { padding: 0 18px; }
    .sc-send-text { display: inline; }
    .sc-foot span { display: inline; }
}
@media (min-width: 769px) {
    body.chat-page.student-app .main-content { padding: var(--s-4) var(--gutter); }
    body.chat-page.student-app .main-content > .sc { max-width: 860px; border: 1px solid var(--c-border); border-radius: 16px; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.05); }
    .sc-head { padding: 12px 16px; }
    .sc-list { padding: 16px 20px; }
    .sc-composer { padding: 10px 16px 12px; }
}

@media (prefers-reduced-motion: reduce) { .sc-skeleton span, .sc-icon.is-spinning i { animation: none; } .sc-box { transition: none; } }

/* the site-wide offline / update notices float above the bottom navigation, which is where the composer is: on this page they sit under the top bar instead */
body.chat-page .pwa-stack { bottom: auto; top: calc(var(--topbar-h) + 8px); }
