.haven-product {
  --haven-bg: #06101e;
  --haven-panel: #0b192b;
  --haven-line: rgba(143, 181, 229, .17);
  --haven-text: #eef7ff;
  --haven-muted: #9eb2ca;
  position: relative;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--haven-line);
  border-radius: 24px;
  color: var(--haven-text);
  background:
    radial-gradient(circle at 82% 0%, rgba(73, 126, 211, .17), transparent 36%),
    radial-gradient(circle at 16% 100%, rgba(52, 121, 150, .1), transparent 34%),
    linear-gradient(165deg, #091626, var(--haven-bg) 62%);
  box-shadow: 0 24px 72px rgba(0, 0, 0, .35);
}
.haven-product[hidden] { display: none; }
.haven-product * { box-sizing: border-box; }
.haven-chat-main {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
}
.haven-chat {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: clamp(24px, 4vw, 58px) clamp(16px, 7vw, 110px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-color: rgba(97, 145, 202, .38) transparent;
}
.haven-message { display: flex; }
.haven-message.user { justify-content: flex-end; }
.haven-bubble {
  max-width: min(76%, 780px);
  padding: 13px 17px;
  border: 1px solid var(--haven-line);
  border-radius: 20px;
  background: rgba(15, 34, 57, .82);
  line-height: 1.58;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.haven-message.user .haven-bubble {
  border-top-right-radius: 7px;
  border-color: rgba(103, 173, 247, .28);
  background: linear-gradient(145deg, #1d5f99, #184b78);
}
.haven-message.mira .haven-bubble { border-top-left-radius: 7px; }
.haven-sources {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--haven-line);
}
.haven-sources strong { color: #b9d9fb; font-size: .76rem; }
.haven-sources a { color: #82c4ff; font-size: .82rem; }
.haven-image-card {
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--haven-line);
  border-radius: 16px;
  background: rgba(5, 15, 27, .7);
}
.haven-image-card img { display: block; width: min(100%, 680px); height: auto; object-fit: contain; background: #040b14; }
.haven-image-card figcaption { padding: 9px 11px; color: var(--haven-muted); font-size: .76rem; }
.haven-attachment-tray {
  display: flex;
  gap: 7px;
  overflow: auto;
  padding: 4px clamp(14px, 4vw, 54px);
}
.haven-attachment-tray[hidden] { display: none; }
.haven-attachment-tray button {
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--haven-line);
  border-radius: 999px;
  color: var(--haven-text);
  background: var(--haven-panel);
  white-space: nowrap;
}
.haven-status { min-height: 22px; padding: 0 clamp(18px, 5vw, 66px); color: var(--haven-muted); font-size: .82rem; }
.haven-composer {
  position: relative;
  display: grid;
  grid-template-columns: 42px 42px minmax(160px, 1fr) 42px auto;
  grid-template-areas:
    "attach emoji input mic send"
    "action action action action action";
  align-items: flex-end;
  gap: 7px;
  margin: 0 clamp(12px, 4vw, 58px) 16px;
  padding: 8px;
  border: 1px solid var(--haven-line);
  border-radius: 19px;
  background: rgba(10, 25, 43, .96);
  box-shadow: 0 14px 36px rgba(0, 0, 0, .25);
}
.haven-composer textarea {
  grid-area: input;
  width: 100%;
  min-width: 0;
  max-height: 150px;
  padding: 10px 8px;
  border: 0;
  outline: 0;
  resize: none;
  color: var(--haven-text);
  background: transparent;
  font: inherit;
}
#havenAttach,
#havenEmoji,
#havenMic {
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
}
#havenAttach { grid-area: attach; }
#havenEmoji { grid-area: emoji; }
#havenMic { grid-area: mic; }
#havenSend {
  grid-area: send;
  width: auto;
  min-width: 0;
  height: 42px;
}
#havenStop,
#havenRetry {
  grid-column: 1 / -1;
  grid-row: 2;
  justify-self: end;
  width: auto;
  min-width: 64px;
  height: 42px;
}
.haven-product button { cursor: pointer; font: inherit; }
.haven-icon-button,
.haven-composer > button:not(.haven-primary) {
  min-width: 42px;
  min-height: 42px;
  padding: 8px;
  border: 1px solid var(--haven-line);
  border-radius: 13px;
  color: var(--haven-text);
  background: rgba(16, 35, 58, .9);
}
.haven-icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.haven-primary {
  min-height: 42px;
  padding: 9px 17px;
  border: 1px solid rgba(119, 184, 255, .5);
  border-radius: 13px;
  color: white;
  background: linear-gradient(135deg, #1b75ca, #429ff5);
  font-weight: 750;
}
.haven-product button:hover,
.haven-product button:focus-visible { border-color: #68b2f7; outline: none; box-shadow: 0 0 0 3px rgba(79, 160, 235, .13); }
.haven-product button:disabled { cursor: default; opacity: .55; }
.haven-emoji-picker {
  position: absolute;
  z-index: 20;
  left: clamp(56px, 8vw, 110px);
  bottom: 82px;
  width: min(330px, calc(100% - 24px));
  max-height: 330px;
  overflow: auto;
  border: 1px solid var(--haven-line);
  border-radius: 16px;
  background: #0c1a2b;
  box-shadow: 0 22px 54px rgba(0, 0, 0, .5);
}
.haven-emoji-picker[hidden] { display: none; }
.haven-emoji-picker .emoji-fallback { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; padding: 10px; }
.haven-emoji-picker .emoji-fallback button { min-height: 40px; padding: 6px; border: 1px solid var(--haven-line); border-radius: 10px; background: #11243c; font-size: 1.2rem; }
@media(max-width:640px) {
  .haven-product { border-radius: 16px; }
  .haven-chat { padding: 18px 10px; }
  .haven-bubble { max-width: 90%; padding: 11px 13px; }
  .haven-composer { grid-template-columns: 36px 36px minmax(0,1fr) 36px auto; gap: 4px; margin: 0 7px 8px; padding: 6px; }
  .haven-icon-button,
  .haven-composer > button:not(.haven-primary) { min-width: 36px; width: 36px; min-height: 40px; padding: 7px; }
  #havenAttach,
  #havenEmoji,
  #havenMic { width: 36px; min-width: 36px; height: 40px; min-height: 40px; }
  #havenSend { height: 40px; }
  #havenStop,
  #havenRetry { height: 40px; }
  .haven-primary { min-height: 40px; padding: 8px 10px; }
  .haven-status { padding: 0 10px; }
  .haven-emoji-picker { left: 7px; bottom: 72px; width: calc(100% - 14px); }
}
@media(max-width:390px) {
  .haven-composer { grid-template-columns: 34px 34px minmax(0,1fr) 34px auto; gap: 3px; }
  .haven-composer textarea { min-height: 38px; padding-block: 7px; }
  .haven-icon-button,
  .haven-composer > button:not(.haven-primary) { min-width: 34px; width: 34px; }
  #havenAttach,
  #havenEmoji,
  #havenMic { width: 34px; min-width: 34px; }
  #havenRetry { overflow: hidden; font-size: 0; }
  #havenRetry::before { content: "↻"; font-size: 1.15rem; line-height: 1; }
  .haven-primary { padding-inline: 8px; }
  .haven-emoji-picker { bottom: calc(100% + 8px); }
}
@media(prefers-reduced-motion:reduce) { .haven-product * { scroll-behavior: auto !important; transition: none !important; } }
