/* The Conversations screen (P2-09): the list (centre column), the open conversation and the composer (right
 * column). Loaded after views.css by app/index.html. Nothing inline: the CSP allows stylesheets from this origin
 * only, so every look this screen needs is a class here. */

.conversation-grid {
  display: grid;
  grid-template-columns: minmax(17rem, 24rem) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
.conversation-list-pane { min-width: 0; }
.list-filters { margin: 0 0 .4rem; }

/* ---- the list ---------------------------------------------------------------------------------- */

.conversation-list { display: grid; gap: .5rem; margin: 0; padding: 0; list-style: none; }
.conversation-row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: .55rem;
}
.conversation-row[data-selected="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.conversation-open {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: .25rem;
  justify-items: stretch;
  width: 100%;
  min-height: 44px;
  padding: .65rem .8rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 400;
  text-align: left;
}
.conversation-open:focus-visible { outline-offset: -3px; }
.conversation-name { font-weight: 700; overflow-wrap: anywhere; }
.conversation-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .3rem .5rem;
  color: var(--muted);
  font-size: .88rem;
}
.conversation-preview {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

/* ---- the open conversation ------------------------------------------------------------------- */

.thread-pane { display: grid; gap: .75rem; }
.thread-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; }
.thread-header h2 { margin: 0; font-size: 1.2rem; overflow-wrap: anywhere; }
.thread-badges { display: inline-flex; flex-wrap: wrap; gap: .4rem; }
.thread-back { display: none; }
.thread-status-help { margin: 0; }
.thread-notices { display: grid; gap: .5rem; }
.thread-notices:empty { display: none; }
.thread-notice { margin: 0; }
.thread-notice p { margin: 0 0 .5rem; }

.message-list {
  display: grid;
  gap: .6rem;
  align-content: start;
  max-height: clamp(14rem, 52vh, 38rem);
  margin: 0;
  padding: .15rem;
  overflow-y: auto;
  list-style: none;
}
.message-list:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.message {
  max-width: 92%;
  padding: .55rem .75rem;
  border: 1px solid var(--line);
  border-radius: .6rem;
  background: #f8fafb;
  overflow-wrap: anywhere;
}
.message-patient { justify-self: start; }
.message-staff { justify-self: end; background: #e9f3f7; border-color: #b9d5e1; }
.message-note { justify-self: stretch; max-width: none; background: var(--warn-bg); border: 1px dashed var(--warn-line); }
.message-head { display: flex; flex-wrap: wrap; gap: .2rem .75rem; color: var(--muted); font-size: .85rem; }
.message-who { color: var(--ink); font-weight: 700; }
.message-text { margin: .25rem 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-status { margin: .25rem 0 0; font-size: .85rem; }
.message-hint { margin: .25rem 0 0; color: var(--danger); font-size: .88rem; font-weight: 600; }
.below-cue { justify-self: end; margin: 0; }
.badge-status-queued,
.badge-status-sent { color: var(--ink); background: var(--neutral-bg); }
.badge-status-delivered { color: var(--ok); background: var(--ok-bg); }
.badge-status-failed { color: var(--danger); background: var(--danger-bg); }

/* ---- the composer ------------------------------------------------------------------------------ */

.composer {
  padding: .75rem 0 .25rem;
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.composer-label { margin: 0; font-weight: 700; }
.composer textarea { min-height: 7rem; }
.composer textarea:disabled { color: var(--muted); background: var(--neutral-bg); }
.composer-count { margin: .25rem 0; color: var(--muted); font-size: .9rem; }
.composer-count.over-limit { color: var(--danger); font-weight: 700; }
.composer-status { margin: .25rem 0; font-size: .9rem; font-weight: 600; }
.composer-status:empty { display: none; }
.composer-notice { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: .5rem 0; }
.composer-notice p { margin: 0; }
.composer .field-help { margin: .15rem 0 0; color: var(--muted); font-size: .88rem; }

/* ---- narrow screens: the list or the conversation, one at a time (best effort) ----------------- */

@media (max-width: 900px) {
  .conversation-grid { grid-template-columns: 1fr; }
  .conversations-page[data-open="true"] .conversation-list-pane { display: none; }
  .conversations-page[data-open="false"] .thread-pane { display: none; }
  .thread-back { display: inline-flex; }
}
