/* ============================================================
   LUNOVA — conversation overlay
   Fixed chat card, message threads, tone bar, composer.
   ============================================================ */

/* Base state (used before the overlay rules take over). */
#chat {
  max-width: 850px;
  min-height: 75vh;
  margin: auto;
  padding: 35px 25px 60px;
}

#chat[hidden] { display: none !important; }

.chat-top {
  display: flex;
  gap: 15px;
  align-items: center;
  justify-content: space-between;
  color: var(--gold);
  font-size: 12px;
}

.chat-top button {
  padding: 10px 15px;
  border: 1px solid #755061;
  border-radius: 20px;
  background: var(--panel);
  color: var(--gold);
}

.chat-person {
  margin: 35px 0 15px;
  text-align: center;
}

.chat-person .avatar-photo {
  width: 112px;
  height: 112px;
  margin: auto;
  border: 2px solid #c19a7b;
  border-radius: 50%;
  object-fit: cover;
}

.chat-person h2 { font-size: 35px; margin: 10px; }

.chat-person p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}

#messages {
  min-height: 200px;
  max-height: 420px;
  padding: 10px 0;
  overflow: auto;
}

.message {
  max-width: 85%;
  margin: 12px 0;
  padding: 16px 20px;
  overflow-wrap: anywhere;
  border: 1px solid #ffffff09;
  border-radius: 15px;
  background: #2b1b26;
  color: #dec9d4;
  font-size: 14px;
  white-space: pre-wrap;
}

.message.user {
  margin-left: auto;
  background: #603148;
  color: #fff1ee;
}

#composer {
  display: flex;
  margin-top: 20px;
  padding: 7px;
  border: 1px solid #765063;
  border-radius: 30px;
  background: #251820;
}

#composer input {
  flex: 1;
  min-width: 0;
  padding: 12px;
  border: 0;
  outline: 0;
  background: transparent;
}

#composer button {
  width: 43px;
  height: 43px;
  border: 0;
  border-radius: 50%;
  background: var(--gold);
  color: #29131f;
  font-size: 24px;
}

/* ---------- overlay layout ---------- */

body:has(#chat:not([hidden])) { overflow: hidden; }

#chat:not([hidden]) {
  position: fixed;
  top: 106px;
  bottom: 16px;
  left: 50%;
  z-index: 12;
  display: flex;
  flex-direction: column;
  width: min(900px, calc(100% - 32px));
  height: calc(100vh - 122px);
  height: calc(100dvh - 122px);
  max-width: none;
  min-height: 0;
  margin: 0;
  padding: 18px 22px max(16px, env(safe-area-inset-bottom));
  overflow: hidden;
  border: 1px solid #805267;
  border-radius: 24px;
  background: #190f17;
  box-shadow: 0 24px 90px #0009;
  color: var(--ink, #f6ece7);
  transform: translateX(-50%);
}

#chat:not([hidden]) .chat-top {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(80px, 1fr) auto minmax(120px, 250px);
  gap: 10px;
  align-items: center;
  margin: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid #ffffff12;
  font-size: 12px;
}

#chat:not([hidden]) .chat-top > a {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

#chat:not([hidden]) .chat-top button {
  min-height: 36px;
  padding: 7px 12px;
  white-space: nowrap;
}

/* ---------- companion header ---------- */

#chat:not([hidden]) .chat-person {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr);
  column-gap: 12px;
  align-items: center;
  margin: 14px 0 10px;
  text-align: left;
}

#chat:not([hidden]) #chat-avatar {
  grid-row: 1 / 3;
  align-self: center;
}

#chat:not([hidden]) .chat-person .avatar-photo {
  width: 48px;
  height: 48px;
  margin: 0;
  object-position: center 18%;
}

#chat:not([hidden]) .chat-person h2 {
  grid-column: 2;
  margin: 0 0 3px;
  font-size: 23px;
  line-height: 1.2;
}

#chat:not([hidden]) .chat-person p {
  display: -webkit-box;
  grid-column: 2;
  margin: 0;
  overflow: hidden;
  color: #bea8b4;
  font-size: 11px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* ---------- tone bar ---------- */

#chat:not([hidden]) #chat-tone-bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  margin: 0 0 10px;
}

#chat:not([hidden]) .chat-tone-label {
  margin-right: 3px;
  color: #c6abb9;
  font-size: 11px;
}

#chat:not([hidden]) #chat-tone-bar button {
  min-height: 31px;
  padding: 5px 13px;
  border: 1px solid #805267;
  border-radius: 20px;
  background: #251820;
  color: #ead2de;
  font-size: 11px;
  line-height: 1.3;
  transition: background .2s, color .2s, border-color .2s;
}

#chat:not([hidden]) #chat-tone-bar button[aria-pressed='true'] {
  border-color: #e7b6c4;
  background: #e7b6c4;
  color: #28121e;
}

/* ---------- thread ---------- */

#chat:not([hidden]) #messages {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  padding: 12px 5px 12px 0;
  overflow-x: hidden;
  overflow-y: auto;
  border-top: 1px solid #ffffff0d;
  border-bottom: 1px solid #ffffff0d;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

#chat:not([hidden]) #messages .message {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  justify-content: flex-start;
  width: 100%;
  max-width: none;
  margin: 14px 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: #ead5df;
  font-size: 14px;
  white-space: normal;
}

#chat:not([hidden]) #messages .message.user {
  justify-content: flex-end;
  margin-left: 0;
}

#chat:not([hidden]) .chat-message-avatar {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  margin-top: 18px;
  border: 1px solid #a7778e;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 18%;
}

#chat:not([hidden]) .chat-message-content {
  min-width: 0;
  max-width: min(82%, 650px);
}

#chat:not([hidden]) .message.user .chat-message-content {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

#chat:not([hidden]) .chat-message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 3px 5px;
  color: #b49aa8;
  font-size: 10px;
  line-height: 1.4;
}

#chat:not([hidden]) .message.user .chat-message-meta { justify-content: flex-end; }

#chat:not([hidden]) .chat-message-meta time {
  color: #967f8d;
  font-size: 10px;
}

#chat:not([hidden]) .chat-message-bubble {
  max-width: 100%;
  padding: 12px 15px;
  overflow-wrap: anywhere;
  border: 1px solid #8d5d752b;
  border-radius: 16px 16px 16px 4px;
  background: #2b1b26;
  line-height: 1.65;
  white-space: pre-wrap;
}

#chat:not([hidden]) .message.user .chat-message-bubble {
  border-color: #a3638266;
  border-radius: 16px 16px 4px 16px;
  background: #603148;
  color: #fff1ee;
}

#chat:not([hidden]) .chat-message-photo {
  display: block;
  width: min(100%, 280px);
  max-height: 360px;
  margin-top: 10px;
  border-radius: 12px;
  object-fit: cover;
  object-position: top center;
}

/* Plain-text fallback before the thread is decorated. */
#chat:not([hidden]) #messages .message:not(:has(.chat-message-content)) {
  display: block;
  width: auto;
  max-width: 82%;
  padding: 12px 15px;
  border: 1px solid #8d5d752b;
  border-radius: 16px;
  background: #2b1b26;
  white-space: pre-wrap;
}

#chat:not([hidden]) #messages .message.user:not(:has(.chat-message-content)) {
  margin-left: auto;
  background: #603148;
  color: #fff1ee;
}

/* ---------- starters ---------- */

#chat-starters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

#chat-starters:empty { display: none; }

#chat-starters button {
  padding: 9px 14px;
  border: 1px solid #89576e66;
  border-radius: 20px;
  background: #251820;
  color: var(--gold);
  font-size: 11px;
  text-align: left;
  transition: background .2s, border-color .2s;
}

#chat-starters button:hover {
  border-color: #b67892;
  background: #4a283b;
}

.starter-label {
  display: block;
  width: 100%;
  color: #b999a9;
  font-size: 10px;
  letter-spacing: .7px;
}

#chat:not([hidden]) #chat-starters {
  flex: 0 0 auto;
  max-height: 82px;
  margin: 10px 0 0;
  padding: 0 0 2px;
  overflow: auto;
}

#chat:not([hidden]) #chat-starters button {
  max-width: 100%;
  padding: 7px 12px;
  font-size: 11px;
  line-height: 1.35;
}

/* ---------- status + composer ---------- */

#model-chat-status {
  color: #edbfcc;
  font-size: 14px;
  line-height: 1.5;
}

#model-chat-status:empty { display: none; }

#chat:not([hidden]) #model-chat-status {
  flex: 0 0 auto;
  max-height: 3.2em;
  margin: 8px 2px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.5;
}

#chat:not([hidden]) #composer {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  min-height: 58px;
  margin: 10px 0 0;
  padding: 6px 7px 6px 14px;
  border: 1px solid #a36c88;
  border-radius: 19px;
  background: #251820;
}

#chat:not([hidden]) #composer input,
#chat:not([hidden]) #composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 43px;
  max-height: 112px;
  margin: 0;
  padding: 10px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: #fff1ee;
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
}

#chat:not([hidden]) #composer input::placeholder { color: #b396a7; }

#chat:not([hidden]) #composer button {
  flex: 0 0 43px;
  display: grid;
  place-items: center;
  width: 43px;
  height: 43px;
  margin: 0;
  padding: 0;
  border-radius: 13px;
  background: var(--gold);
  color: #29131f;
}

#chat:not([hidden]) button:disabled,
#chat:not([hidden]) #composer input:disabled {
  cursor: wait;
  opacity: .6;
}

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  #chat:not([hidden]) {
    top: 88px;
    bottom: 8px;
    width: calc(100% - 16px);
    height: calc(100vh - 96px);
    height: calc(100dvh - 96px);
    padding: 12px 12px max(12px, env(safe-area-inset-bottom));
    border-radius: 18px;
  }

  #chat:not([hidden]) .chat-top {
    grid-template-columns: minmax(80px, 1fr) auto;
    gap: 7px 8px;
    padding-bottom: 9px;
    font-size: 11px;
  }

  #chat:not([hidden]) .chat-top button {
    min-height: 33px;
    padding: 6px 10px;
    font-size: 11px;
  }

  #chat:not([hidden]) .chat-person {
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 0 10px;
    margin: 11px 0 9px;
  }

  #chat:not([hidden]) .chat-person .avatar-photo { width: 40px; height: 40px; }
  #chat:not([hidden]) .chat-person h2 { font-size: 20px; }
  #chat:not([hidden]) .chat-person p { font-size: 10px; }

  #chat:not([hidden]) .chat-message-content { max-width: 87%; }

  #chat:not([hidden]) .chat-message-avatar {
    flex-basis: 28px;
    width: 28px;
    height: 28px;
  }

  #chat:not([hidden]) #messages .message { gap: 7px; font-size: 13px; }
  #chat:not([hidden]) .chat-message-bubble { padding: 10px 12px; }

  #chat:not([hidden]) #chat-starters {
    flex-wrap: nowrap;
    max-height: 64px;
    padding-bottom: 3px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  #chat:not([hidden]) #chat-starters button {
    flex: 0 0 auto;
    max-width: 90%;
    font-size: 10px;
  }

  #chat:not([hidden]) #composer {
    min-height: 54px;
    margin-top: 8px;
    padding: 5px 6px 5px 12px;
    border-radius: 17px;
  }

  #chat:not([hidden]) #composer button {
    flex-basis: 41px;
    width: 41px;
    height: 41px;
  }

  .message { max-width: 92%; font-size: 13px; }
  #chat { padding: 25px 5% 45px; }
  .chat-top { font-size: 10px; }
}

@media (max-height: 650px) {
  #chat:not([hidden]) .chat-person {
    grid-template-columns: 36px minmax(0, 1fr);
    margin: 7px 0;
  }
  #chat:not([hidden]) .chat-person .avatar-photo { width: 34px; height: 34px; }
  #chat:not([hidden]) .chat-person h2 { margin: 0; font-size: 18px; }
  #chat:not([hidden]) .chat-person p { display: none; }
  #chat:not([hidden]) #chat-avatar { grid-row: 1; }
  #chat:not([hidden]) #chat-tone-bar { margin-bottom: 6px; }
  #chat:not([hidden]) #chat-starters { max-height: 43px; margin-top: 6px; }
  #chat:not([hidden]) #model-chat-status { max-height: 1.5em; margin: 5px 2px; }
}

@media (max-height: 520px) {
  #chat:not([hidden]) {
    padding: 8px 12px max(8px, env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  #chat:not([hidden]) .chat-top {
    grid-template-columns: minmax(48px, 1fr) auto minmax(0, 1fr);
    gap: 6px;
    padding-bottom: 5px;
  }
  #chat:not([hidden]) .chat-top button {
    min-height: 28px;
    padding: 4px 8px;
    font-size: 10px;
  }
  #chat:not([hidden]) .chat-person {
    grid-template-columns: 30px minmax(0, 1fr);
    margin: 6px 0;
  }
  #chat:not([hidden]) .chat-person .avatar-photo { width: 28px; height: 28px; }
  #chat:not([hidden]) .chat-person h2 { font-size: 17px; }
  #chat:not([hidden]) #chat-tone-bar { gap: 6px; margin-bottom: 5px; }
  #chat:not([hidden]) #chat-tone-bar button {
    min-height: 27px;
    padding: 4px 11px;
    font-size: 10px;
  }
  #chat:not([hidden]) #messages { min-height: 48px; padding: 4px 2px 4px 0; }
  #chat:not([hidden]) #chat-starters { display: none; }
  #chat:not([hidden]) #model-chat-status { max-height: 1.5em; margin: 4px 2px; font-size: 11px; }
  #chat:not([hidden]) #composer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    min-height: 46px;
    margin-top: 6px;
    padding: 4px 6px 4px 12px;
    box-shadow: 0 -5px 12px #190f17;
  }
  #chat:not([hidden]) #composer input,
  #chat:not([hidden]) #composer textarea { min-height: 34px; padding: 6px 0; font-size: 13px; }
  #chat:not([hidden]) #composer button { flex-basis: 35px; width: 35px; height: 35px; }
}

@media (max-height: 360px) {
  #chat:not([hidden]) .chat-person { display: none; }
  #chat:not([hidden]) #model-chat-status { margin: 3px 2px; font-size: 10px; }
}

@media (max-height: 320px) {
  #chat:not([hidden]) #chat-tone-bar { display: none; }
}
