/* Chat message wrap; lazy media CSS loaded only when preview opened */
.hgai-client .hgai-msg{box-sizing:border-box;max-width:min(89%,850px);min-width:0;overflow-wrap:anywhere}
.hgai-client .hgai-msg-text{white-space:pre-wrap;overflow-wrap:anywhere}
.hgai-client .hgai-attachment{max-width:100%;overflow:hidden}
.hgai-client .hgai-preview-open{background:#eaf2ff;color:#001d6e;border:1px solid #c8dafa;border-radius:9px;padding:10px 13px;cursor:pointer}
.hgai-client .hgai-media-actions{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin:7px 0}
.hgai-client .hgai-media-actions button,.hgai-client .hgai-media-actions a{font:600 12px system-ui;color:#001d6e;background:#eef5ff;border:1px solid #c6d9f0;border-radius:8px;padding:7px 10px;text-decoration:none;cursor:pointer}

/* PATCH 16 — message bookmarks belong to one conversation, no extra chat panels. */
.hgai-client .hgai-message-save{display:inline-flex;align-items:center;margin:7px 0 0;min-height:28px;padding:4px 9px;font:600 11px/1.2 system-ui;color:#173a74;background:#eef5ff;border:1px solid #cfdef5;border-radius:9px;cursor:pointer}
.hgai-client .hgai-message-save[aria-pressed="true"]{background:#e0edff;color:#001d6e;border-color:#7fb5ff}
.hgai-client .hgai-message-save:disabled{opacity:.65;cursor:wait}
.hgai-client [data-saved-list]{display:flex;flex-direction:column;gap:10px;min-width:0}
.hgai-client .hgai-saved-card{min-width:0;max-width:100%;padding:12px;border:1px solid #d5e3fa;border-radius:12px;background:#f8fbff;overflow-wrap:anywhere}
.hgai-client .hgai-saved-card b{display:block;color:#001d6e;font-size:12px;margin-bottom:5px}
.hgai-client .hgai-saved-card p{font-size:13px;line-height:1.5;white-space:pre-wrap;margin:6px 0;overflow-wrap:anywhere}
.hgai-client .hgai-saved-remove{margin-top:8px;border:1px solid #b8d0ef;border-radius:9px;padding:7px 9px;font:600 12px system-ui;color:#001d6e;background:#fff;cursor:pointer}

/* PATCH 21 — canonical message card CSS (replaces contradictory PATCH 18/20 overrides). */
.hgai-client .hgai-msg{box-sizing:border-box;position:relative;display:flex;flex:0 0 auto;flex-direction:column;min-width:0;max-width:min(89%,520px);width:max-content;overflow:visible;overflow-wrap:anywhere}
.hgai-client .hgai-message-box{box-sizing:border-box;position:relative;display:flex;flex-direction:column;min-width:0;max-width:100%;width:100%;gap:0;padding:0 0 8px;overflow:visible;overflow-wrap:anywhere;background:#c4ddff;border:1px solid #a4c9f7;border-radius:16px;color:#001d6e;box-shadow:0 2px 7px #001d6e17}
.hgai-client .hgai-msg-user .hgai-message-box{background:#c4ddff;border-color:#a4c9f7;color:#001d6e}
.hgai-client .hgai-message-box::after{content:"";position:absolute;bottom:0;left:-9px;width:14px;height:17px;clip-path:polygon(100% 0,100% 100%,0 100%);background:#c4ddff}
.hgai-client .hgai-msg-user .hgai-message-box::after{left:auto;right:-9px;clip-path:polygon(0 0,0 100%,100% 100%);background:#c4ddff}
.hgai-client .hgai-msg-head{display:flex;align-items:center;gap:9px;min-width:0;padding:8px 10px;margin:0;background:#001d6e;color:white;border:0;border-radius:14px 14px 0 0}
.hgai-client .hgai-msg-user .hgai-msg-head{background:#a9d2ff;color:#001d6e}
.hgai-client .hgai-msg-avatar{display:grid;place-items:center;flex:0 0 30px;width:30px;height:30px;overflow:hidden;border:2px solid #ffffffa6;border-radius:50%;background:#e8f3ff;color:#001d6e;font:750 13px system-ui}
.hgai-client .hgai-msg-avatar-image{width:100%;height:100%;object-fit:cover;display:block}
.hgai-client .hgai-msg-identity{display:flex;flex:1 1 auto;align-items:center;justify-content:flex-start;gap:8px;min-width:0}
.hgai-client .hgai-msg-name{min-width:0;max-width:100%;overflow-wrap:anywhere;font:750 12px/1.35 system-ui;color:inherit}
.hgai-client .hgai-msg-time{flex:0 0 auto;margin-left:auto;white-space:nowrap;color:#385d96;opacity:.9;font:500 10px/1.35 system-ui}
.hgai-client .hgai-message-box .hgai-msg-text,.hgai-client .hgai-msg-user .hgai-message-box .hgai-msg-text{width:100%;min-width:0;max-width:100%;margin:0;padding:9px 11px 5px;white-space:pre-wrap;overflow-wrap:anywhere;word-break:normal;line-height:1.45;background:transparent;border:0;border-radius:0;color:#092d69}
.hgai-client .hgai-message-box .hgai-attachment{display:block;max-width:100%;min-width:0;overflow:hidden;margin:3px 0;padding:5px 10px 0}
.hgai-client .hgai-message-box .hgai-delivery-state{display:block;text-align:right;color:#385d96;opacity:.8;font-size:10px}
.hgai-client .hgai-message-box .hgai-message-footer{display:flex;align-items:center;flex-wrap:wrap;justify-content:flex-start;flex:0 0 auto;min-height:31px;gap:7px;margin:3px 0 0;padding:5px 10px 0;border:0;background:transparent}
.hgai-client .hgai-message-footer .hgai-message-save,.hgai-client .hgai-message-footer .hgai-message-copy{display:inline-flex;align-items:center;justify-content:center;min-height:28px;margin:0;border:1px solid #e1eaf7;border-radius:9px;background:#fff;color:#001d6e;padding:5px 10px;font:650 11px/1.2 system-ui;cursor:pointer}
.hgai-client .hgai-message-footer .hgai-message-save[aria-pressed=true]{background:#e0edff;border-color:#7fb5ff}
.hgai-client .hgai-message-box.hgai-has-image{width:100%;max-width:100%}
.hgai-client .hgai-message-box.hgai-has-image .hgai-attachment-image{width:100%;min-width:0;max-width:100%;margin:0;padding:0}
.hgai-client .hgai-message-box.hgai-has-image .hgai-open-photo{display:block;width:100%;max-width:100%;margin:0;padding:0;text-align:left}
.hgai-client .hgai-message-box.hgai-has-image .hgai-image-thumb{display:block;width:auto;height:auto;max-width:100%;object-fit:contain}
@media(max-width:650px){.hgai-client .hgai-msg{max-width:94%}.hgai-client .hgai-msg-identity{gap:5px}.hgai-client .hgai-msg-name{font-size:11px}}

/* PATCH 24 — fix image-message right alignment at the OUTER message item.
 * The image width and the text width belong to the same bubble; a wide
 * max-content text must not keep the message row wider than the photo. */
.hgai-client .hgai-msg-user:has(.hgai-message-box.hgai-has-image){width:min(89%,var(--hgai-image-card-width,320px));max-width:min(89%,520px);align-self:flex-end;margin-inline-start:auto;margin-inline-end:0}
@media(max-width:650px){.hgai-client .hgai-msg-user:has(.hgai-message-box.hgai-has-image){width:min(94%,var(--hgai-image-card-width,320px));max-width:94%}}

/* PATCH 22 — message presentation is scoped here; no global override rules. */
.hgai-client .hgai-msg-identity{display:flex;flex-direction:column;align-items:stretch;justify-content:center;gap:3px;min-width:0}
.hgai-client .hgai-msg-name{display:block;align-self:flex-start}
.hgai-client .hgai-msg-time{display:block;align-self:flex-end;margin:0;text-align:right;opacity:.88;color:inherit;font:500 10px/1.3 system-ui}
.hgai-client .hgai-msg-head{min-height:51px}
.hgai-client .hgai-msg .hgai-message-box{background:#c4ddff;color:#001d6e}
.hgai-client .hgai-msg-user .hgai-msg-head{background:#fee2c5;color:#001d6e}
.hgai-client .hgai-msg:not(.hgai-msg-user) .hgai-msg-head{background:#001d6e;color:#fff}
.hgai-client .hgai-msg:not(.hgai-msg-user) .hgai-message-footer{background:#c4ddff;color:#001d6e}
.hgai-client .hgai-msg-user .hgai-message-footer{background:#c4ddff;color:#001d6e}
.hgai-client .hgai-msg-user .hgai-message-box{padding-bottom:0;overflow:visible}
.hgai-client .hgai-msg:not(.hgai-msg-user) .hgai-message-box{padding-bottom:0}
.hgai-client .hgai-message-box .hgai-message-footer{border-radius:0 0 14px 14px;margin:5px 0 0;padding:7px 9px;gap:8px}
.hgai-client .hgai-message-footer .hgai-message-save,.hgai-client .hgai-message-footer .hgai-message-copy{background:#fee2c5;border-color:#e1b990;color:#001d6e}
.hgai-client .hgai-msg-user .hgai-message-footer .hgai-message-save,.hgai-client .hgai-msg-user .hgai-message-footer .hgai-message-copy{background:#001d6e;border-color:#001d6e;color:#fff}
.hgai-client .hgai-message-box.hgai-has-image .hgai-attachment-image{display:flex;justify-content:center;align-items:center;text-align:center}
.hgai-client .hgai-message-box.hgai-has-image .hgai-open-photo{display:flex;justify-content:center;align-items:center;max-width:100%}
.hgai-client .hgai-message-box.hgai-has-image .hgai-image-thumb{display:block;max-width:100%;width:auto;max-height:420px;object-fit:contain;margin-inline:auto}
.hgai-client .hgai-msg-user .hgai-message-box::after{background:#c4ddff}

.hgai-client .hgai-msg-user .hgai-message-footer .hgai-message-save[aria-pressed="true"]{background:#163e94;border-color:#7fb5ff;color:#fff}

/* PATCH 25: Saved reuses the original message-bubble layout with private attachments. */
.hgai-client [data-saved-list] .hgai-msg{max-width:94%;box-sizing:border-box}
.hgai-client [data-saved-list] .hgai-message-box{min-width:0;max-width:100%}
