:root{--sm-navy:#17375e;--sm-blue:#2563eb;--sm-bg:#f3f6fb;--sm-border:#dce4ef;--sm-muted:#64748b}
*{box-sizing:border-box}
body.school-messages-page{margin:0;background:var(--sm-bg);color:#172033;font-family:Inter,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;min-height:100vh}
.sm-header{display:flex;align-items:center;justify-content:space-between;gap:14px;background:#fff;border-bottom:1px solid var(--sm-border);padding:12px max(16px,calc((100% - 1080px)/2));position:sticky;top:0;z-index:5}
.sm-brand{display:flex;align-items:center;gap:11px;color:inherit;text-decoration:none;min-width:0}.sm-brand img{width:45px;height:45px;object-fit:contain}.sm-brand span{display:flex;flex-direction:column;gap:3px;min-width:0}.sm-brand strong{font-size:.95rem}.sm-brand small{color:var(--sm-muted);font-size:.78rem}.sm-back{color:var(--sm-navy);font-weight:750;text-decoration:none;white-space:nowrap}
.sm-layout{width:min(100% - 28px,1000px);margin:28px auto 60px}.sm-intro{margin-bottom:18px}.sm-kicker{color:var(--sm-blue);font-weight:850;font-size:.72rem;letter-spacing:.12em}.sm-intro h1{font-size:clamp(1.8rem,5vw,2.4rem);margin:7px 0}.sm-intro p{margin:0;color:var(--sm-muted);line-height:1.5}.sm-intro #sm-status{margin-top:12px;font-size:.9rem;color:#475569}.sm-intro #sm-status[data-kind=error]{color:#b91c1c}.sm-intro #sm-status[data-kind=success]{color:#166534}
.sm-workspace{display:grid;grid-template-columns:270px minmax(0,1fr);gap:18px;align-items:start}.sm-controls,.sm-thread{background:#fff;border:1px solid var(--sm-border);border-radius:18px;box-shadow:0 8px 26px rgba(15,23,42,.04)}.sm-controls{padding:16px;display:flex;flex-direction:column;gap:16px;position:sticky;top:86px}.sm-controls label{display:flex;flex-direction:column;gap:8px;font-size:.88rem;font-weight:800}.sm-controls select{width:100%;min-height:47px;border:1px solid #cbd5e1;border-radius:11px;padding:10px;background:#fff;color:#172033;font:inherit;font-weight:500}.sm-refresh{border:1px solid var(--sm-border);border-radius:11px;background:#f8fafc;color:var(--sm-navy);padding:12px;font:inherit;font-weight:750;min-height:45px}
.sm-thread{min-width:0;overflow:hidden}.sm-thread-head{padding:18px 20px;border-bottom:1px solid var(--sm-border);display:flex;justify-content:space-between;align-items:flex-start;gap:12px}.sm-thread-head h2{font-size:1.1rem;margin:0 0 5px}.sm-thread-head p{font-size:.85rem;color:var(--sm-muted);margin:0;line-height:1.45}.sm-secure{font-size:.75rem;color:#166534;background:#ecfdf5;padding:6px 9px;border-radius:999px;white-space:nowrap;font-weight:800}
.sm-message-list{padding:18px;min-height:250px;max-height:52vh;overflow-y:auto;display:flex;flex-direction:column;gap:12px;overscroll-behavior:contain}.sm-empty{color:var(--sm-muted);text-align:center;margin:auto;max-width:280px;line-height:1.6;padding:30px 10px}
.sm-message{max-width:min(88%,520px);padding:12px 14px;border-radius:15px;background:#f1f5f9;align-self:flex-start;overflow-wrap:anywhere}.sm-message.is-mine{align-self:flex-end;background:#e8f1ff;border:1px solid #d6e6ff}.sm-message-meta{font-size:.75rem;font-weight:850;color:var(--sm-navy);margin-bottom:6px;display:flex;justify-content:space-between;gap:12px}.sm-message time{font-weight:500;color:var(--sm-muted);white-space:nowrap}.sm-message-body{white-space:pre-wrap;line-height:1.55;font-size:.94rem}.sm-compose{padding:16px 18px;border-top:1px solid var(--sm-border);background:#fbfcff}.sm-compose label{display:block;font-weight:850;font-size:.9rem;margin-bottom:8px}.sm-compose textarea{width:100%;resize:vertical;min-height:88px;max-height:220px;border:1px solid #cbd5e1;border-radius:12px;padding:12px;font:inherit;line-height:1.5;background:#fff}.sm-compose textarea:focus,.sm-controls select:focus{outline:3px solid #dbeafe;border-color:var(--sm-blue)}.sm-compose-foot{display:flex;justify-content:space-between;align-items:center;gap:12px;margin-top:10px}.sm-compose-foot small{color:var(--sm-muted);line-height:1.4}.sm-compose-foot button{min-height:46px;border:0;border-radius:12px;padding:0 18px;background:var(--sm-navy);color:#fff;font:inherit;font-weight:850;cursor:pointer}.sm-compose-foot button:disabled{opacity:.6;cursor:wait}
.sm-error{background:#fff;border:1px solid #fecaca;border-radius:16px;padding:22px}.sm-error h2{margin-top:0}.sm-error a{display:inline-block;background:var(--sm-navy);color:#fff;text-decoration:none;padding:12px 16px;border-radius:10px;font-weight:800}
@media(max-width:700px){.sm-header{padding:10px 13px;gap:8px}.sm-brand img{width:38px;height:38px}.sm-brand strong{font-size:.8rem}.sm-brand small{font-size:.72rem}.sm-back{font-size:.78rem}.sm-layout{width:calc(100% - 20px);margin:18px auto 36px}.sm-workspace{grid-template-columns:1fr;gap:12px}.sm-controls{position:static;display:grid;grid-template-columns:1fr;gap:12px;padding:13px}.sm-controls label{font-size:.85rem}.sm-controls select{min-height:48px}.sm-refresh{width:100%}.sm-thread-head{padding:15px 14px}.sm-thread-head h2{font-size:1rem}.sm-thread-head p{font-size:.8rem}.sm-message-list{min-height:240px;max-height:48vh;padding:13px}.sm-message{max-width:92%;padding:11px 12px}.sm-message-meta{flex-direction:column;gap:3px}.sm-message time{white-space:normal}.sm-compose{padding:13px}.sm-compose-foot{align-items:stretch;flex-direction:column}.sm-compose-foot button{width:100%;min-height:50px;order:-1}.sm-compose-foot small{font-size:.77rem}.sm-secure{font-size:.68rem}.sm-brand span{max-width:52vw}.sm-brand strong{overflow-wrap:anywhere}}
@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto!important;transition:none!important}}

.sm-live-toast{position:fixed;top:14px;right:14px;z-index:10000;max-width:min(380px,calc(100vw - 28px));padding:13px 16px;border-radius:12px;background:#17375e;color:#fff;box-shadow:0 12px 35px rgba(15,23,42,.24);font-weight:750;line-height:1.45;opacity:0;transform:translateY(-8px);pointer-events:none;transition:opacity .18s ease,transform .18s ease}
.sm-live-toast.is-visible{opacity:1;transform:translateY(0)}
.sm-refresh:disabled{opacity:.75;cursor:wait}
@media(prefers-reduced-motion:reduce){.sm-live-toast{transition:none}}

/* WhatsApp-style continuous chat polish */
.sm-message-list{background-color:#f7f8fa;background-image:radial-gradient(rgba(23,55,94,.045) .7px,transparent .7px);background-size:14px 14px}
.sm-message{box-shadow:0 1px 1px rgba(15,23,42,.06);border-radius:16px 16px 16px 5px}
.sm-message.is-mine{border-radius:16px 16px 5px 16px;background:#d9fdd3;border-color:#c5edbe}
.sm-message-meta{align-items:center}
.sm-message-body{word-break:break-word}
.sm-compose textarea{min-height:52px;max-height:150px;resize:vertical}
.sm-thread{display:flex;flex-direction:column}
.sm-message-list{flex:1}
.sm-controls select,.sm-refresh,.sm-compose-foot button{touch-action:manipulation}
@media(max-width:700px){
 body.school-messages-page{min-height:100dvh;overflow-x:hidden}
 .sm-header{position:sticky;top:0;padding-top:max(8px,env(safe-area-inset-top));}
 .sm-layout{width:100%;margin:0 auto 0;padding-bottom:env(safe-area-inset-bottom)}
 .sm-intro{padding:15px 14px 10px;margin:0}
 .sm-intro h1{font-size:1.65rem;margin:4px 0}
 .sm-intro p{font-size:.84rem}
 .sm-intro #sm-status{font-size:.8rem;margin-top:8px}
 .sm-workspace{width:100%;gap:0;display:flex;flex-direction:column;align-items:stretch}
 .sm-controls{border-radius:0;border-left:0;border-right:0;padding:10px 12px;display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:8px;position:static}
 .sm-controls label{min-width:0;gap:5px;font-size:.78rem}
 .sm-controls select{min-width:0;min-height:44px;padding:8px;font-size:16px}
 #sm-refresh,#sm-enable-notifications{min-height:42px;font-size:.8rem;padding:8px}
 .sm-thread{border-radius:0;border-left:0;border-right:0;border-bottom:0;min-height:0;flex:1}
 .sm-thread-head{padding:12px 13px;align-items:center}
 .sm-thread-head h2{font-size:.95rem}
 .sm-thread-head p{font-size:.76rem}
 .sm-secure{font-size:.64rem;padding:5px 7px}
 .sm-message-list{height:calc(100dvh - 360px);min-height:230px;max-height:none;padding:12px 10px;gap:10px}
 .sm-message{max-width:88%;padding:10px 12px}
 .sm-message-meta{font-size:.68rem;flex-direction:row;gap:8px}
 .sm-message time{font-size:.66rem}
 .sm-message-body{font-size:.9rem;line-height:1.48}
 .sm-compose{position:sticky;bottom:0;z-index:4;display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:end;gap:8px;padding:9px 10px calc(9px + env(safe-area-inset-bottom));background:#f8fafc;border-top:1px solid var(--sm-border)}
 .sm-compose label{grid-column:1/-1;margin:0;font-size:.78rem}
 .sm-compose textarea{grid-column:1;min-width:0;min-height:46px;max-height:130px;padding:11px;border-radius:22px;font-size:16px;resize:vertical}
 .sm-compose-foot{grid-column:2;display:flex;align-items:stretch;justify-content:center;margin:0;gap:0}
 .sm-compose-foot small{display:none}
 .sm-compose-foot button{order:0;width:auto;min-width:72px;min-height:46px;padding:0 13px;border-radius:24px;font-size:.8rem}
 .sm-error{margin:14px;border-radius:14px}
}
@media(max-width:380px){
 .sm-brand small{display:none}
 .sm-brand strong{font-size:.74rem}
 .sm-back{font-size:.72rem}
 .sm-controls{grid-template-columns:1fr}
 .sm-message-list{height:calc(100dvh - 410px)}
}


/* Compact phone layout: reserve the screen for the active conversation and composer. */
@media(max-width:700px){
  .sm-header{gap:8px;min-width:0;}
  .sm-brand{flex:1;min-width:0;}
  .sm-brand span{max-width:none;}
  .sm-back{flex:0 0 auto;}
  .sm-thread{min-width:0;width:100%;}
  .sm-thread-head>div{min-width:0;overflow-wrap:anywhere;}
  .sm-message-list{height:clamp(220px,calc(100dvh - 320px),58dvh);min-height:220px;}
  .sm-compose{position:sticky;bottom:0;}
  .sm-compose textarea{max-height:120px;overflow-y:auto;}
  .sm-compose-foot button{min-height:46px;touch-action:manipulation;}
}
@media(max-width:380px){
  .sm-header{align-items:center;}
  .sm-brand img{width:32px;height:32px;}
  .sm-brand strong{font-size:.72rem;}
  .sm-back{font-size:.7rem;}
  .sm-message-list{height:clamp(200px,calc(100dvh - 350px),55dvh);}
}
