/* AI Chat composer, prompt chips, menus and the inline prompt manager.
   Loaded after insert-panel.css and chart-mobile.css, so these rules win over the
   older composer styles there. One colour channel per control; menus 6px radius with shadow. */

.ip-ai { position: relative; }

/* Prompt chips: quiet text, only while the conversation is empty. */
.ip-ai-chips { flex: none; display: flex; flex-wrap: wrap; gap: 2px 4px; padding: 0 10px 6px; }
.ip-ai-chips[hidden] { display: none; }
.ip-ai-chip {
  max-width: 100%; height: 28px; padding: 0 8px; border: 0; border-radius: 4px; background: none;
  color: var(--text-secondary); font: 400 12px var(--font); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ip-ai-chip:hover { background: var(--hover-neutral); color: var(--text); }

/* Composer: one bordered box with the textarea on top and a control row inside. */
.ip-ai .ip-ai-composer { flex: none; display: block; padding: 6px 10px 10px; border-top: 0; }
.ip-ai-box {
  display: flex; flex-direction: column; border: 1px solid var(--ch-ctrl-line); border-radius: 4px;
  background: var(--surface);
}
.ip-ai-box:focus-within { border-color: var(--primary); }
.ip-ai .ip-ai-composer .ip-ai-box textarea {
  display: block; flex: none; width: 100%; min-height: 0; max-height: none; box-sizing: border-box; resize: none; overflow-y: hidden;
  padding: 8px 10px 4px; border: 0; border-radius: 4px 4px 0 0; background: none; color: var(--text);
  font: 13px/1.5 var(--font);
}
.ip-ai .ip-ai-composer .ip-ai-box textarea:focus { outline: none; border: 0; }
.ip-ai-row { display: flex; align-items: center; gap: 2px; padding: 2px 4px 4px; min-width: 0; }
.ip-ai-grow { flex: 1; }
.ip-ai-box { position: relative; }
.ip-ai-dd { min-width: 0; }
.ip-ai-ddbtn {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%; height: 28px; padding: 0 6px; border: 0; border-radius: 4px;
  background: none; color: var(--text-secondary); font: 400 12px var(--font); cursor: pointer; white-space: nowrap;
}
.ip-ai-ddbtn span { overflow: hidden; text-overflow: ellipsis; }
.ip-ai-ddbtn:hover, .ip-ai-ddbtn[aria-expanded="true"] { background: var(--hover-neutral); color: var(--text); }
.ip-ai-caret { flex: none; }
.ip-ai-ddbtn:focus-visible, .ip-ai-chip:focus-visible, .ip-ai-mi:focus-visible, .ip-ai-icon:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

/* Send: no fill until there is text, then the one accent fill in the view. */
.ip-ai .ip-ai-send {
  flex: none; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 4px; background: none; color: var(--text-tertiary); cursor: default; opacity: 1;
}
.ip-ai .ip-ai-send.ip-ai-send-on { background: var(--primary); color: var(--on-primary); cursor: pointer; }
.ip-ai .ip-ai-send.ip-ai-send-on:hover { background: var(--primary-hover); }

/* Menus open upward from the composer. */
.ip-ai-menu {
  position: absolute; z-index: 30; inset-inline: 0; bottom: calc(100% + 4px);
  padding: 4px; border-radius: 6px; background: var(--surface); box-shadow: var(--shadow-md);
}
.ip-ai-menu[hidden] { display: none; }
.ip-ai-menu-prm { max-height: min(360px, 60vh); overflow-y: auto; }
.ip-ai-mi {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 30px; padding: 4px 8px;
  border: 0; border-radius: 4px; background: none; color: var(--text); font: 400 13px var(--font); text-align: start; cursor: pointer;
}
.ip-ai-mi:hover { background: var(--hover-neutral); }
.ip-ai-mi-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ip-ai-mi-check { display: none; color: var(--text); }
.ip-ai-mi[aria-checked="true"] .ip-ai-mi-check { display: inline-flex; }
.ip-ai-menu .ip-ai-cap { margin: 2px 0 0; padding: 6px 8px 4px; font-size: 12px; color: var(--text-tertiary); white-space: normal; }
.ip-ai-prow { display: flex; align-items: center; gap: 2px; }
.ip-ai-prow .ip-ai-pmain { flex: 1; min-width: 0; }
.ip-ai-manage { margin-top: 2px; color: var(--text-secondary); font-size: 12px; }
.ip-ai-icon {
  flex: none; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 4px; background: none; color: var(--text-tertiary); cursor: pointer;
}
.ip-ai-icon:hover { background: var(--hover-neutral); color: var(--text); }
.ip-ai-icon:disabled { opacity: .35; cursor: default; background: none; }

/* Reply actions: quiet text; paused while a reply streams. */
.ip-msg-acts { display: flex; flex-wrap: wrap; gap: 0 2px; }
.ip-copied { color: var(--text) !important; }
.ip-ai-busy .ip-msg-acts .ip-textbtn { pointer-events: none; opacity: .45; }

/* Inline prompt manager: replaces the chat while open. */
.ip-ai-mgr { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; background: var(--surface); }
.ip-ai-mgr[hidden] { display: none; }
.ip-ai-managing .ip-ai-msgs, .ip-ai-managing .ip-ai-chips, .ip-ai-managing .ip-ai-composer { visibility: hidden; }
.ip-ai-mhead { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 6px; font-size: 13px; }
.ip-ai-mlist { flex: 0 1 auto; min-height: 0; overflow-y: auto; padding: 0 8px; }
.ip-ai-mrow { display: flex; align-items: center; gap: 0; min-height: 36px; padding: 0 0 0 8px; border-radius: 4px; cursor: grab; }
.ip-ai-mrow:hover { background: var(--hover-neutral); }
.ip-ai-mrow.ip-ai-dragging { opacity: .5; }
.ip-ai-mrow.ip-ai-dropat { background: var(--pressed); }
.ip-ai-mlabel { flex: 1; min-width: 0; font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ip-ai-mtag { margin-inline-start: 6px; font-size: 11px; color: var(--text-tertiary); }
.ip-ai-pform { display: flex; flex-direction: column; gap: 6px; padding: 8px; }
.ip-ai-pform input, .ip-ai-pform textarea {
  width: 100%; box-sizing: border-box; padding: 6px 8px; border: 1px solid var(--ch-ctrl-line); border-radius: 4px;
  background: var(--surface); color: var(--text); font: 13px/1.45 var(--font);
}
.ip-ai-pform textarea { resize: vertical; min-height: 90px; }
.ip-ai-pform :is(input, textarea):focus { outline: none; border-color: var(--primary); }
.ip-ai-pacts { display: flex; gap: 4px; }
.ip-ai-mfoot { flex: none; display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 10px 12px; }
.ip-ai-mnote { font-size: 12px; color: var(--text-tertiary); padding: 0 6px; }

@media (max-width: 1199px) {
  .ip-ai .ip-ai-composer .ip-ai-box textarea, .ip-ai-pform :is(input, textarea) { font-size: 16px; line-height: 1.4; }
  .ip-ai .ip-ai-composer { padding: 6px 10px; padding-inline: max(10px, env(safe-area-inset-left, 0px)) max(10px, env(safe-area-inset-right, 0px)); padding-bottom: max(8px, env(safe-area-inset-bottom, 0px)); }
  /* In the phone chart the bottom bar already clears the home indicator. */
  #view-patient-detail:has(.chm-nav:not([data-single])) .ip-ai .ip-ai-composer { padding-bottom: 8px; }
  .ip-ai-ddbtn { height: 36px; font-size: 13px; padding: 0 8px; }
  .ip-ai .ip-ai-send { width: 36px; height: 36px; }
  .ip-ai-mi { min-height: 40px; font-size: 15px; }
  .ip-ai-icon { width: 36px; height: 36px; }
  .ip-ai-chip { height: 36px; font-size: 13px; }
  .ip-ai-mrow { min-height: 44px; }
  .ip-ai-mrow { cursor: default; }
}
