/* Communication side (facility page tabs and the pharmacy's Communication portal). Uses the colors from app.css. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.btn-warn { color: var(--warn); border-color: var(--warn); }
.fc-tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; position: sticky; top: calc(4px + var(--safe-top)); z-index: 5; }
.fc-tabs button { border: 0; background: transparent; padding: 9px 4px; border-radius: 9px; font-weight: 600; font-size: .85rem; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 0; white-space: nowrap; }
.fc-tabs button[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.fc-badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: .7rem; font-weight: 700; line-height: 1; }
.fc-badge[hidden] { display: none; }
@media (max-width: 400px) { .fc-tabs button { font-size: .76rem; } }
.comm-list { display: grid; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.comm-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; border-radius: 0; color: inherit; }
.comm-row:last-child { border-bottom: 0; }
.comm-row:hover { background: var(--surface-2); }
.comm-row.unread b { font-weight: 800; }
.comm-row-main { display: grid; gap: 2px; flex: 1; min-width: 0; }
.comm-avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--info-soft); color: var(--info); font-weight: 700; font-size: .8rem; }
.comm-avatar.topic { background: var(--accent-soft); color: var(--warn); }
.comm-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--info); flex: none; }
.comm-chat { min-height: 60vh; }
.comm-chat-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.comm-chat-head h2 { margin: 0; }
.comm-tools { gap: 6px; flex-wrap: wrap; }
.comm-msgs { display: flex; flex-direction: column; gap: 12px; padding: 12px; background: var(--surface-2); border-radius: var(--radius); height: 60vh; min-height: 220px; overflow-y: auto; overscroll-behavior: contain; }
.comm-msgs > * { flex: none; }
.comm-msg { display: flex; flex-direction: column; gap: 3px; max-width: 82%; align-self: flex-start; align-items: flex-start; }
.comm-msg.ours { align-self: flex-end; align-items: flex-end; }
.comm-msg.center { align-self: center; align-items: center; }
/* Who sent it or took action, in bold at the top of each message and update */
.comm-name { display: block; font-size: .8rem; font-weight: 800; margin-bottom: 2px; }
.comm-msg.comm-update { max-width: 88%; }
.comm-msg.comm-update .comm-event { width: 100%; }
.comm-msg.ours .comm-event { border-left-width: 1px; border-right: 4px solid var(--line); }
.comm-msg.ours .comm-event.tone-good { border-right-color: var(--good); }
.comm-msg.ours .comm-event.tone-warn { border-right-color: var(--accent); }
.comm-msg.ours .comm-event.tone-bad { border-right-color: var(--bad); }
.comm-note-bubble { background: var(--surface); color: var(--ink); font-size: .9rem; }
.comm-msg.ours .comm-note-bubble { background: var(--surface); color: var(--ink); border-color: var(--line); }
.comm-who { font-size: .75rem; font-weight: 600; color: var(--muted); padding: 0 4px; }
.comm-time { font-size: .72rem; color: var(--muted); padding: 0 4px; white-space: nowrap; }
.comm-bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 8px 12px; overflow-wrap: anywhere; text-align: left; }
.comm-msg.ours .comm-bubble { background: var(--brand); color: var(--brand-fg); border-color: var(--brand); border-radius: 16px 16px 4px 16px; }
.comm-text { white-space: pre-wrap; }
.comm-photo { display: block; padding: 0; border: 0; background: transparent; margin-bottom: 6px; min-height: 40px; }
.comm-photo img { max-width: min(220px, 100%); max-height: 260px; border-radius: 10px; display: block; }
/* Small notes like "added this patient" */
.comm-note { align-self: center; text-align: center; font-size: .78rem; color: var(--muted); max-width: 92%; display: grid; gap: 1px; }
.comm-note-time { font-size: .7rem; opacity: .85; }
/* Order and approval updates: full-width card, status chip in color first */
.comm-event { display: grid; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: .9rem; text-align: left; }
.comm-event-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.comm-event-text { overflow-wrap: anywhere; line-height: 1.35; }
.comm-chip { display: inline-flex; align-items: center; gap: 5px; font-size: .74rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.comm-chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.comm-event.tone-good { border-left-color: var(--good); background: var(--good-soft, var(--surface)); }
.comm-event.tone-good .comm-chip { background: var(--good); color: #fff; }
.comm-event.tone-warn { border-left-color: var(--accent); background: var(--accent-soft, var(--surface)); }
.comm-event.tone-warn .comm-chip { background: var(--accent); color: #241603; }
.comm-event.tone-bad { border-left-color: var(--bad); background: var(--bad-soft, var(--surface)); }
.comm-event.tone-bad .comm-chip { background: var(--bad); color: #fff; }
.comm-compose { display: flex; gap: 8px; align-items: flex-end; background: var(--bg); padding-top: 4px; }
.comm-compose textarea { flex: 1 1 auto; min-width: 0; width: auto; resize: none; min-height: 42px; }
.comm-compose button { flex: none; min-height: 42px; }
/* Phone: the conversation fills the screen like a text thread. The typing box stays pinned at the bottom and above the keyboard; the tab bar is hidden. */
@media (max-width: 899px) {
  body.comm-chat-open { overflow: hidden; }
  body.comm-chat-open .tabbar { display: none; }
  .comm-chat.comm-full { position: fixed; left: 0; right: 0; top: 0; height: 100dvh; z-index: 700; min-height: 0; margin: 0; background: var(--bg);
    display: flex; flex-direction: column; gap: 6px; padding: calc(8px + var(--safe-top)) var(--gutter-r) calc(6px + var(--safe-bottom)) var(--gutter-l); }
  .comm-chat.comm-full .comm-chat-head { flex: none; }
  .comm-chat.comm-full .comm-msgs { flex: 1 1 auto; height: auto; min-height: 0; }
  .comm-chat.comm-full .comm-compose, .comm-chat.comm-full .error-text { flex: none; }
  .comm-chat.comm-full .error-text:empty { display: none; }
}
.comm-dup { border-color: var(--warn); background: var(--warn-soft); color: var(--ink); }
.fo-set-items { margin: 0; padding-left: 1.4em; }
.fc-order-card ol, .fo-review ol { margin: 0; padding-left: 1.4em; }
.portal-pick { display: grid; grid-template-columns: 1fr; justify-content: stretch; justify-items: start; align-items: start; gap: 4px; text-align: left; width: 100%; padding: 18px; font-size: 1.05rem; }
.portal-pick:hover { border-color: var(--brand); }
#fo-review .facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
#fo-review .facts dd { margin: 0; }
/* Header with the portal switch: on a phone the date and switch go on a second row, so nothing overlaps or gets cut off. */
.topbar-extra { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-label { font-size: .85rem; font-weight: 600; opacity: .85; white-space: nowrap; }
.topbar .brand-text { white-space: nowrap; }
@media (max-width: 640px) {
  .topbar.topbar-wrap { flex-wrap: wrap; row-gap: 8px; }
  .topbar.topbar-wrap .topbar-extra { order: 3; flex: 1 0 100%; }
  .topbar.topbar-wrap .topbar-extra > * { flex: 1 1 0; min-width: 0; }
  .topbar.topbar-wrap .topbar-extra > .topbar-label { flex: none; }
  .topbar.topbar-wrap .topbar-extra input[type="date"] { max-width: none; width: 100%; }
}
/* Pharmacy Messages: sort choice, facility groups, letter headers */
.ca-sort { display: flex; gap: 6px; flex-wrap: wrap; }
.ca-fac { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.ca-fac > summary { display: flex; align-items: center; gap: 8px; padding: 12px; cursor: pointer; min-width: 0; }
.ca-fac[open] > summary { border-bottom: 1px solid var(--line); }
.ca-fac-body { padding: 8px; }
.ca-letter-head { font-size: .78rem; font-weight: 800; color: var(--muted); padding: 4px 4px 0; }

/* Reply, reactions, archive */
.comm-bubble[role="button"] { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.comm-quote { display: flex; flex-direction: column; gap: 1px; text-align: left; font: inherit; font-size: .8rem; color: inherit; background: rgba(127,127,127,.12); border: 0; border-left: 3px solid var(--line); border-radius: 6px; padding: 4px 8px; margin: 2px 0 4px; max-width: 100%; min-width: 0; cursor: pointer; }
.comm-quote.static { cursor: default; }
.comm-quote b { font-weight: 800; }
.comm-quote .ellipsis { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }
.comm-replybar { display: flex; align-items: center; gap: 8px; padding: 4px 6px; background: var(--surface-2); border-radius: var(--radius); }
.comm-replybar[hidden] { display: none; }
.comm-reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: -2px; }
.comm-react { display: inline-flex; align-items: center; gap: 3px; font-size: .9rem; line-height: 1; padding: 3px 7px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface, #fff); color: inherit; cursor: pointer; min-height: 26px; }
.comm-react.mine { border-color: var(--accent, #2563eb); background: rgba(37,99,235,.10); }
.comm-react-pick { justify-content: space-between; gap: 6px; }
.comm-react-btn { font-size: 1.6rem; line-height: 1; width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; padding: 0; }
.comm-react-btn.mine { border-color: var(--accent, #2563eb); background: rgba(37,99,235,.14); }
.comm-msg.flash .comm-bubble { outline: 3px solid var(--accent, #2563eb); outline-offset: 2px; transition: outline-color .6s; }
.fo-set-items .fo-pick-row { list-style: none; margin-left: -1.2em; }
.fo-set-items .fo-pick-note { list-style: none; margin-left: -1.2em; }
