:root{font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#183b33;background:#f3f5ef;font-synthesis:none;line-height:1.5;color-scheme:light}
*{box-sizing:border-box}body{margin:0}button,input,textarea,select{font:inherit;max-width:100%}button,a,input,select,textarea{touch-action:manipulation}button{min-height:44px;border:1px solid #9baea3;border-radius:10px;padding:10px 14px;background:#fff;color:#183b33;cursor:pointer}button:disabled{opacity:.55;cursor:wait}button[type=submit]{background:#175b47;color:white;border-color:#175b47}button:hover{filter:brightness(.96)}:focus-visible{outline:3px solid #bd7610;outline-offset:3px}input,select,textarea{width:100%;border:1px solid #9baea3;border-radius:8px;background:white;color:#183b33;padding:12px;min-height:44px}textarea{resize:vertical}label{display:block;font-weight:600;margin:12px 0 6px}h1,h2,p{overflow-wrap:anywhere}h1{font-size:1.65rem;letter-spacing:-.04em}h2{font-size:1.2rem}ul,ol{padding:0;list-style:none}main{max-width:1120px;margin:auto;padding:16px}.topbar{background:#123d35;color:white;display:flex;flex-wrap:wrap;gap:12px;align-items:center;justify-content:space-between;padding:16px}.brand{color:white;text-decoration:none;font-weight:800;letter-spacing:.04em}.brand span{font-weight:500;letter-spacing:0;margin-left:10px}.pill{font-size:.75rem;border:1px solid #75958a;border-radius:30px;padding:4px 10px}#status{margin:0 0 16px;min-height:24px;font-size:.9rem}#status.error{color:#a12417}.account{display:flex;gap:8px;flex-wrap:wrap;align-items:center;border-bottom:1px solid #c8d4c9;padding-bottom:16px}.account>span{margin-right:auto;font-weight:600}.section-head{display:flex;gap:12px;align-items:center;justify-content:space-between}.section-head h2{flex:1;min-width:0}.chat-layout{display:grid;gap:20px}#login{max-width:500px;margin:32px auto;background:white;border-radius:16px;padding:24px}.notice{border-left:4px solid #b97e1d;padding:12px;background:#fff4d9;font-size:.9rem}.hint{font-size:.8rem;color:#4e665c}fieldset{border:1px solid #b7c5b9;border-radius:8px;margin:16px 0}#participants label{display:flex;gap:10px;align-items:center;min-height:44px;font-weight:400;margin:0}#participants input{width:22px;min-height:22px}.chats li{margin-bottom:8px}.chats button{width:100%;display:flex;align-items:center;justify-content:space-between;text-align:left;gap:12px;overflow-wrap:anywhere}.chats button[aria-current=true]{border:2px solid #175b47;background:#e8f1e9}.badge{border-radius:40px;background:#175b47;color:white;min-width:26px;text-align:center;padding:2px 6px;font-size:.8rem}#conversation-panel{min-width:0}#messages{display:flex;flex-direction:column;gap:12px;max-height:55dvh;min-height:150px;overflow-y:auto;overscroll-behavior:contain;padding:8px 2px}#messages li{align-self:flex-start;max-width:88%;padding:12px 14px;border:1px solid #d8e1d5;border-radius:12px;background:white;overflow-wrap:anywhere;white-space:pre-wrap}#messages li.mine{align-self:flex-end;background:#e0eddc}#messages small{display:block;color:#4e665c;font-size:.75rem;margin-bottom:4px}#composer{border-top:1px solid #c8d4c9;margin-top:12px}.compose-actions{display:flex;gap:12px;align-items:center;justify-content:space-between;margin:8px 0 16px}#notifications-panel{background:white;border-radius:12px;padding:16px;margin-top:16px}#notifications button{width:100%;text-align:left;margin-bottom:6px}#new-form{padding:16px;background:#e7eee3;border-radius:12px}#mark-read{font-size:.85rem;width:100%}[hidden]{display:none!important}
@media(max-width:699px){body.conversation-open #chat-list-panel{display:none}.topbar .pill{display:none}main{padding:12px}#messages{max-height:48dvh}}
@media(min-width:700px){.chat-layout{grid-template-columns:minmax(240px,1fr) minmax(0,2fr)}#conversation-panel{border-left:1px solid #c8d4c9;padding-left:20px}#back{display:none}.topbar{padding:18px max(24px,calc((100vw - 1088px)/2))}}

/* La conversazione occupa il viewport mobile, con lo storico scorrevole. */
html { -webkit-text-size-adjust: 100%; }
body { overflow-wrap: anywhere; }
main, .chat-layout, #chat-list-panel { min-width: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button, .file-download { min-height: 44px; }
#demo-login button { width: 100%; margin-top: 20px; }
#messages img {
  display: block;
  max-width: 100%;
  max-height: 38dvh;
  width: auto;
  height: auto;
  border-radius: 8px;
  margin-top: 8px;
  object-fit: contain;
}
.file-download {
  display: flex;
  align-items: center;
  color: #124c3c;
  font-weight: 600;
  white-space: normal;
}
#attachment-form {
  border: 1px solid #9baea3;
  border-radius: 10px;
  background: #fff;
  padding: 12px;
  flex-shrink: 0;
}
#attachment-form input { padding: 8px; font-size: .875rem; }
#attachment-form .compose-actions { margin-bottom: 0; }
#upload-status { margin: 4px 0 0; font-size: .875rem; }
#upload-status:empty { display: none; }
#composer label { margin: 4px 0; }
#composer textarea { display: block; max-height: 20dvh; }
.compose-actions { margin: 8px 0; }
#mark-read { margin: 4px 0; }

@media (max-width: 699px) {
  body.conversation-open { height: 100dvh; overflow: hidden; }
  body.conversation-open .topbar { display: none; }
  body.conversation-open main {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: max(6px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  body.conversation-open #status { margin: 0; font-size: .75rem; min-height: 18px; }
  body.conversation-open #workspace { display: flex; flex: 1; flex-direction: column; min-height: 0; }
  body.conversation-open .account { flex-shrink: 0; gap: 4px; padding-bottom: 4px; }
  body.conversation-open .account > span { font-size: .75rem; max-width: 34%; }
  body.conversation-open .account button { font-size: .8rem; padding: 8px; }
  body.conversation-open .chat-layout { display: flex; flex: 1; min-height: 0; }
  body.conversation-open #conversation-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
  body.conversation-open .section-head { flex-shrink: 0; gap: 8px; }
  body.conversation-open .section-head h2 { margin: 6px 0; font-size: 1rem; }
  body.conversation-open #messages { flex: 1; min-height: 60px; max-height: none; margin: 4px 0; }
  body.conversation-open #messages li { max-width: 92%; padding: 8px 12px; }
  body.conversation-open #composer { flex-shrink: 0; margin-top: 4px; }
  body.conversation-open #composer label { font-size: .8rem; }
  body.conversation-open #composer textarea { min-height: 44px; padding: 8px; }
  body.conversation-open #mark-read { font-size: .75rem; padding: 6px; flex-shrink: 0; }
  body.conversation-open #notifications-panel { max-height: 24dvh; overflow: auto; flex-shrink: 0; margin-top: 4px; padding: 8px; }
  body.conversation-open #notifications-panel h2 { margin: 0; }
  body.conversation-open #notifications-panel p { display: none; }
}

@media (max-width: 699px) and (max-height: 560px) {
  body.conversation-open .account, body.conversation-open #status, body.conversation-open #mark-read { display: none; }
  body.conversation-open #attachment-form { max-height: 45dvh; overflow-y: auto; }
}
