.heritage-ai { position: fixed; z-index: 90; right: max(22px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom)); font-family: var(--sans, system-ui, sans-serif); touch-action: none; }
.heritage-ai.is-dragging { transition: none !important; cursor: grabbing; }
.heritage-ai.is-dragging .heritage-ai-launcher { transform: scale(1.04); transition: none; cursor: grabbing; }
.heritage-ai-launcher { position: relative; width: 82px; height: 82px; padding: 0; overflow: visible; border: 2px solid #d4a359; border-radius: 50%; background: #fff8e8; box-shadow: 0 8px 28px #19130e35; cursor: pointer; transition: transform .25s ease, box-shadow .25s ease; }
.heritage-ai-launcher:hover { transform: translateY(-4px) rotate(-3deg); box-shadow: 0 12px 32px #19130e48; }
.heritage-ai-launcher img { width: 100%; height: 100%; object-fit: contain; border-radius: inherit; pointer-events: none; -webkit-user-drag: none; }
.heritage-ai-launcher > span { position: absolute; right: -6px; bottom: -2px; display: grid; width: 30px; height: 24px; place-items: center; color: #fff8e8; background: #b52128; border: 2px solid #f5dfaa; border-radius: 999px; font: 700 11px/1 system-ui,sans-serif; }
.heritage-ai-bubble { position: absolute; right: 72px; bottom: 72px; width: max-content; max-width: min(260px, calc(100vw - 120px)); padding: 12px 16px; color: #54251b; background: #fffaf0; border: 1px solid #d6a653; border-radius: 18px 18px 4px 18px; box-shadow: 0 6px 24px #19130e24; font: 13px/1.6 system-ui,sans-serif; text-align: left; transform: scale(.12); opacity: 0; transform-origin: bottom right; transition: transform 1.88s ease-in-out, opacity 1.88s ease-in-out; cursor: pointer; }
.heritage-ai-bubble::after { position: absolute; right: 12px; bottom: -7px; width: 12px; height: 12px; background: #fffaf0; border-right: 1px solid #d6a653; border-bottom: 1px solid #d6a653; content: ""; transform: rotate(45deg); }
.heritage-ai.is-left .heritage-ai-bubble { right: auto; left: 72px; border-radius: 18px 18px 18px 4px; transform-origin: bottom left; }
.heritage-ai.is-left .heritage-ai-bubble::after { right: auto; left: 12px; border: 0; border-left: 1px solid #d6a653; border-bottom: 1px solid #d6a653; transform: rotate(-45deg); }
.heritage-ai-bubble.is-visible { opacity: 1; transform: scale(1); }
.heritage-ai-bubble.is-hiding { opacity: 0; transform: scale(.12); }
.heritage-ai-dialog { position: fixed; z-index: 100; inset: 0; display: flex; justify-content: flex-end; align-items: flex-end; padding: 24px; background: #14100e66; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.heritage-ai.is-left .heritage-ai-dialog { justify-content: flex-start; }
.heritage-ai-dialog[hidden] { display: none; }
.heritage-ai-dialog.is-open { animation: heritage-ai-backdrop-in .42s ease both; }
.heritage-ai-dialog.is-closing { animation: heritage-ai-backdrop-out .32s ease both; }
.heritage-ai-panel { display: flex; flex-direction: column; width: min(440px, 100%); height: min(680px, calc(100dvh - 48px)); overflow: hidden; color: #292522; background: #fffaf0; border: 1px solid #d5b879; border-radius: 22px; box-shadow: 0 24px 80px #0005; }
.heritage-ai-dialog.is-open .heritage-ai-panel { animation: heritage-ai-expand-right .72s cubic-bezier(.16,1,.3,1) both; }
.heritage-ai-dialog.is-closing .heritage-ai-panel { animation: heritage-ai-collapse-right .48s cubic-bezier(.55,0,.8,.25) both; }
.heritage-ai.is-left .heritage-ai-dialog.is-open .heritage-ai-panel { animation-name: heritage-ai-expand-left; }
.heritage-ai.is-left .heritage-ai-dialog.is-closing .heritage-ai-panel { animation-name: heritage-ai-collapse-left; }
@keyframes heritage-ai-backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes heritage-ai-backdrop-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes heritage-ai-expand-right { from { opacity: .15; transform: scale(.02); border-radius: 50%; } to { opacity: 1; transform: scale(1); border-radius: 22px; } }
@keyframes heritage-ai-collapse-right { from { opacity: 1; transform: scale(1); border-radius: 22px; } to { opacity: 0; transform: scale(.02); border-radius: 50%; } }
@keyframes heritage-ai-expand-left { from { opacity: .15; transform: scale(.02); border-radius: 50%; } to { opacity: 1; transform: scale(1); border-radius: 22px; } }
@keyframes heritage-ai-collapse-left { from { opacity: 1; transform: scale(1); border-radius: 22px; } to { opacity: 0; transform: scale(.02); border-radius: 50%; } }
.heritage-ai-panel > header { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; color: #fff8e8; background: #34231e; }
.heritage-ai-panel > header strong,.heritage-ai-panel > header small { display: block; }
.heritage-ai-panel > header strong { font: 600 17px/1.5 var(--serif, Georgia,serif); }
.heritage-ai-panel > header small { margin-top: 3px; color: #e3c997; font-size: 11px; }
.heritage-ai-panel > header button { width: 36px; height: 36px; color: inherit; background: transparent; border: 1px solid #ffffff60; border-radius: 50%; font-size: 24px; cursor: pointer; }
.heritage-ai-disclaimer { margin: 0; padding: 9px 18px; color: #766e62; background: #f5eedf; font-size: 11px; }
.heritage-ai-messages { flex: 1; display: flex; flex-direction: column; gap: 12px; overflow: auto; padding: 18px; }
.heritage-ai-message { max-width: 88%; padding: 11px 14px; border-radius: 16px; font-size: 13px; line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }
.heritage-ai-message.is-assistant > p { margin: 0; }
.heritage-ai-message.is-assistant > p + p { margin-top: 9px; }
.heritage-ai-message.is-assistant > h2,.heritage-ai-message.is-assistant > h3,.heritage-ai-message.is-assistant > h4,.heritage-ai-message.is-assistant > h5 { margin: 2px 0 7px; color: #7d3d2c; font: 600 1.08em/1.5 var(--serif, Georgia,serif); }
.heritage-ai-message.is-assistant strong { color: #633a2e; font-weight: 700; }
.heritage-ai-message.is-assistant em { color: #725445; }
.heritage-ai-message.is-assistant code { padding: 1px 5px; color: #703a2e; background: #e6dbc7; border-radius: 5px; font: .92em/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.heritage-ai-message.is-assistant pre { max-width: 100%; margin: 5px 0; padding: 9px 11px; overflow-x: auto; white-space: pre-wrap; background: #e9dfcd; border-radius: 9px; }
.heritage-ai-message.is-assistant pre code { padding: 0; background: transparent; }
.heritage-ai-message.is-assistant ul,.heritage-ai-message.is-assistant ol { margin: 2px 0; padding-left: 1.35em; }
.heritage-ai-message.is-assistant li + li { margin-top: 3px; }
.heritage-ai-message.is-assistant blockquote { margin: 3px 0; padding: 2px 0 2px 10px; color: #735b47; border-left: 2px solid #c99b55; }
.heritage-ai-message.is-assistant { align-self: flex-start; background: #f0e8d8; border-bottom-left-radius: 4px; transform-origin: left center; animation: heritage-ai-message-emerge .38s cubic-bezier(.2,.75,.25,1) both; }
.heritage-ai-message.heritage-ai-suggestions { display: flex; flex-direction: column; gap: 9px; width: min(100%, 360px); max-width: 88%; }
.heritage-ai-suggestions__heading { color: #73543b; font-size: 12px; font-weight: 650; }
.heritage-ai-suggestion-list { display: grid; gap: 7px; }
.heritage-ai-suggestion { width: 100%; padding: 8px 10px; color: #49372d; background: #fffaf0; border: 1px solid #ddcba9; border-radius: 10px; font: inherit; font-size: 12px; line-height: 1.5; text-align: left; cursor: pointer; transition: background-color .18s ease, border-color .18s ease, transform .18s ease; }
.heritage-ai-suggestion:hover { background: #fff4df; border-color: #c89647; transform: translateY(-1px); }
.heritage-ai-suggestion:active { transform: translateY(0); }
.heritage-ai-message__glyph { display: inline; animation: heritage-ai-ink-bloom .2s ease-out both; animation-delay: calc(var(--glyph-index) * 18ms); }
@keyframes heritage-ai-message-emerge { from { opacity: 0; filter: blur(8px); transform: translateX(-16px) scale(.72); } to { opacity: 1; filter: blur(0); transform: translateX(0) scale(1); } }
@keyframes heritage-ai-ink-bloom { from { opacity: 0; filter: blur(12px); transform: scale(.88); text-shadow: 0 0 8px #8d443588; } to { opacity: 1; filter: blur(0); transform: scale(1); text-shadow: 0 0 0 transparent; } }
.heritage-ai-message--pending { color: #8d4435; }
.heritage-ai-message--pending::after { display: inline-block; width: 1.5em; text-align: left; content: ""; animation: heritage-ai-ellipsis 1.2s steps(4, end) infinite; }
@keyframes heritage-ai-ellipsis { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75%,100% { content: "..."; } }
.heritage-ai-message.is-user { align-self: flex-end; color: white; background: #a8322d; border-bottom-right-radius: 4px; }
.heritage-ai-status,.heritage-ai-image-error { min-height: 1.3em; margin: 0; padding: 0 18px; color: #8d4435; font-size: 11px; }
.heritage-ai-panel form { padding: 8px 14px 14px; border-top: 1px solid #e7ddcb; }
.heritage-ai-preview { display: flex; align-items: center; gap: 10px; padding: 7px 0 10px; color: #6e6253; font-size: 11px; }
.heritage-ai-preview[hidden],.heritage-ai-image-error:empty { display: none; }
.heritage-ai-preview img { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; }
.heritage-ai-preview button { margin-left: auto; color: #9b302b; background: none; border: 0; cursor: pointer; }
.heritage-ai-compose { display: flex; align-items: flex-end; gap: 9px; }
.heritage-ai-compose textarea { flex: 1; min-width: 0; max-height: 120px; resize: vertical; padding: 11px; color: #292522; background: #fff; border: 1px solid #d9cbb4; border-radius: 12px; font: 13px/1.5 system-ui,sans-serif; }
.heritage-ai-compose > button { min-height: 42px; padding: 0 15px; color: white; background: #a8322d; border: 0; border-radius: 12px; cursor: pointer; }
.heritage-ai-compose > button:disabled { opacity: .55; cursor: wait; }
.heritage-ai-upload { display: grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center; color: #7c4737; border: 1px solid #d9cbb4; border-radius: 12px; font-size: 22px; cursor: pointer; }
.heritage-ai-upload input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.heritage-ai button:focus-visible,.heritage-ai textarea:focus-visible,.heritage-ai-upload:focus-within { outline: 3px solid #d4a359; outline-offset: 3px; }
.heritage-ai-launcher { -webkit-tap-highlight-color: transparent; user-select: none; }
.heritage-ai-launcher:focus:not(:focus-visible) { outline: none; }
body.heritage-ai-open > *:not(.heritage-ai) { filter: blur(5px); transition: filter .2s ease; }
body.heritage-ai-open { overflow: hidden; }
@media (max-width: 600px) {
  .heritage-ai-dialog { align-items: flex-end; padding: 0; }
  .heritage-ai-panel { width: 100%; height: min(92dvh, 820px); border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .heritage-ai { right: max(14px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); }
  .heritage-ai-launcher { width: 68px; height: 68px; }
  @keyframes heritage-ai-expand-right { from { opacity: .15; transform: scale(.02); border-radius: 50%; } to { opacity: 1; transform: scale(1); border-radius: 20px 20px 0 0; } }
  @keyframes heritage-ai-collapse-right { from { opacity: 1; transform: scale(1); border-radius: 20px 20px 0 0; } to { opacity: 0; transform: scale(.02); border-radius: 50%; } }
  @keyframes heritage-ai-expand-left { from { opacity: .15; transform: scale(.02); border-radius: 50%; } to { opacity: 1; transform: scale(1); border-radius: 20px 20px 0 0; } }
  @keyframes heritage-ai-collapse-left { from { opacity: 1; transform: scale(1); border-radius: 20px 20px 0 0; } to { opacity: 0; transform: scale(.02); border-radius: 50%; } }
}
@media (prefers-reduced-motion: reduce) {
  .heritage-ai-launcher,body.heritage-ai-open > * { transition: none; animation: none !important; }
  .heritage-ai-dialog.is-open .heritage-ai-panel { animation: heritage-ai-expand-reduced .3s ease-out both; }
  .heritage-ai-dialog.is-closing .heritage-ai-panel { animation: heritage-ai-collapse-reduced .24s ease-in both; }
  @keyframes heritage-ai-expand-reduced { from { opacity: .6; transform: scale(.65); } to { opacity: 1; transform: scale(1); } }
  @keyframes heritage-ai-collapse-reduced { from { opacity: 1; transform: scale(1); } to { opacity: .6; transform: scale(.65); } }
}
