.chat-page {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 0, rgba(218, 205, 234, .5), transparent 28%),
    var(--bg);
}

.chat-shell {
  display: flex;
  position: relative;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  flex-direction: column;
  background:
    linear-gradient(rgba(248, 246, 251, .92), rgba(248, 246, 251, .98)),
    radial-gradient(circle at 20% 18%, rgba(219, 204, 235, .48), transparent 30%);
}

.chat-header {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding: max(15px, env(safe-area-inset-top)) 17px 13px;
  border-bottom: 1px solid rgba(111, 91, 127, .08);
  background: rgba(248, 246, 251, .78);
  box-shadow: 0 10px 30px rgba(59, 44, 70, .025);
  backdrop-filter: blur(20px);
}

.chat-header__button {
  display: grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(105, 82, 123, .08);
  border-radius: 50%;
  color: #6f5c7d;
  background: rgba(255,255,255,.66);
}

.chat-header__button svg {
  width: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.chat-header__button:active { transform: scale(.96); }

.session-overlay {
  position: absolute;
  z-index: 7;
  inset: 0;
  background: rgba(42, 31, 49, .22);
  backdrop-filter: blur(2px);
}

.session-drawer {
  position: absolute;
  z-index: 8;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(86vw, 330px);
  padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  transform: translateX(105%);
  transition: transform .24s ease;
  background: rgba(250, 248, 252, .97);
  box-shadow: -18px 0 45px rgba(56, 39, 68, .14);
  backdrop-filter: blur(22px);
}

.session-drawer.is-open { transform: translateX(0); }
.session-drawer__header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; }
.session-drawer__header strong { display: block; color: #51465a; font-size: 18px; }
.session-status { display: block; margin-top: 4px; color: #9b909f; font-size: 9px; }
.session-close { width: 34px; height: 34px; border: 0; border-radius: 50%; color: #75647f; background: #eee8f2; font-size: 22px; }
.session-new { width: 100%; padding: 11px; border: 0; border-radius: 12px; color: white; background: linear-gradient(145deg, #846c9b, #5d496d); }
.session-list { display: flex; overflow-y: auto; gap: 7px; max-height: calc(100% - 110px); margin-top: 14px; flex-direction: column; }
.session-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; padding: 10px; border: 1px solid rgba(105,83,121,.07); border-radius: 12px; background: rgba(255,255,255,.72); }
.session-item.is-active { border-color: rgba(112,86,132,.3); background: #f0eaf4; }
.session-item__select { overflow: hidden; padding: 0; border: 0; color: #554a5c; background: transparent; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.session-item__actions { display: flex; gap: 3px; }
.session-item__actions button { width: 28px; height: 28px; padding: 0; border: 0; border-radius: 8px; color: #807286; background: rgba(255,255,255,.8); font-size: 12px; }
.session-fallback { margin-top: 14px; color: #938797; font-size: 11px; line-height: 1.6; }

.chat-companion {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.chat-avatar {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  width: 43px;
  height: 43px;
  overflow: hidden;
  place-items: end center;
  border: 2px solid rgba(255,255,255,.9);
  border-radius: 50%;
  color: rgba(255,255,255,.92);
  background: linear-gradient(145deg, #9178a9, #554365);
  box-shadow: 0 7px 18px rgba(79, 58, 95, .18);
  font-family: "Songti SC", "STSong", serif;
  font-size: 10px;
}

.chat-avatar > span:last-child { position: relative; z-index: 2; padding-bottom: 4px; }

.chat-avatar__moon {
  position: absolute;
  top: 7px;
  left: 11px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #f5edfb;
  box-shadow: 0 0 13px rgba(241,226,255,.55);
}

.chat-avatar__moon::after {
  position: absolute;
  top: -2px;
  left: 6px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #685379;
  content: "";
}

.chat-companion__copy { min-width: 0; }
.chat-companion h1 { font-family: "Songti SC", "STSong", serif; font-size: 16px; font-weight: 600; letter-spacing: .12em; }
.chat-companion p { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: #918797; font-size: 9px; white-space: nowrap; }

.online-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #68be8e;
  box-shadow: 0 0 0 3px rgba(104,190,142,.1);
}

.message-list {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1 1 auto;
  padding: 18px 17px 24px;
  scroll-behavior: smooth;
  scrollbar-width: none;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

.message-list::-webkit-scrollbar { display: none; }

.message-list__content {
  display: flex;
  min-height: 100%;
  justify-content: flex-end;
  flex-direction: column;
}

.conversation-note {
  display: flex;
  align-items: center;
  align-self: center;
  gap: 6px;
  margin: 3px 0 23px;
  padding: 7px 11px;
  border: 1px solid rgba(111, 87, 130, .07);
  border-radius: 999px;
  color: #a198a6;
  background: rgba(255,255,255,.53);
  font-size: 9px;
}

.conversation-note svg { width: 12px; fill: #8a739e; }

.time-divider {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 22px;
  color: #aaa2af;
  font-size: 9px;
  text-align: center;
}

.time-divider::before,
.time-divider::after { height: 1px; flex: 1; background: linear-gradient(90deg, transparent, rgba(118,98,132,.1)); content: ""; }
.time-divider::after { background: linear-gradient(90deg, rgba(118,98,132,.1), transparent); }

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 17px;
}

.message-row--ai { padding-right: 52px; }
.message-row--user { justify-content: flex-end; padding-left: 52px; }
.message-row--last { margin-bottom: 0; }

.message-avatar {
  display: grid;
  flex: 0 0 auto;
  width: 27px;
  height: 27px;
  place-items: center;
  border: 1.5px solid rgba(255,255,255,.9);
  border-radius: 50%;
  color: white;
  background: linear-gradient(145deg, #927aa9, #5c486b);
  box-shadow: 0 5px 13px rgba(67,48,81,.13);
  font-family: "Songti SC", "STSong", serif;
  font-size: 9px;
}

.message-group { max-width: 100%; }

.message-bubble {
  padding: 11px 14px;
  border: 1px solid rgba(105, 83, 121, .065);
  border-radius: 18px;
  background: rgba(255,255,255,.9);
  box-shadow: 0 9px 25px rgba(59, 43, 70, .05);
}

.message-bubble p { color: #4f4854; font-size: 13px; line-height: 1.7; }
.message-bubble p + p { margin-top: 7px; }

.message-group time {
  display: block;
  margin-top: 5px;
  padding: 0 4px;
  color: #ada5b1;
  font-size: 8px;
}

.message-row--ai .message-bubble { border-bottom-left-radius: 5px; }
.message-row--user .message-bubble { border: 0; border-bottom-right-radius: 5px; background: linear-gradient(135deg, #836b99, #655274); box-shadow: 0 10px 25px rgba(79,58,94,.14); }
.message-row--user .message-bubble p { color: rgba(255,255,255,.94); }
.message-row--user time { color: #a79eaa; text-align: right; }

.composer {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex: 0 0 auto;
  padding: 11px 14px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(105, 83, 121, .08);
  background: rgba(255,255,255,.88);
  box-shadow: 0 -12px 32px rgba(54,39,66,.035);
  backdrop-filter: blur(20px);
}

.composer button {
  display: grid;
  flex: 0 0 auto;
  width: 41px;
  height: 41px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
}

.composer button svg {
  width: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.55;
}

.composer__voice { color: #786587; background: #eee8f3; }
.composer__field { display: flex; min-width: 0; min-height: 43px; align-items: flex-end; flex: 1; border: 1px solid rgba(105,83,121,.08); border-radius: 21px; background: #f7f5f8; }

.composer textarea {
  min-width: 0;
  min-height: 41px;
  max-height: 96px;
  resize: none;
  flex: 1;
  padding: 11px 5px 10px 14px;
  border: 0;
  outline: 0;
  color: #4e4753;
  background: transparent;
  font-size: 12px;
  line-height: 1.55;
}

.composer textarea::placeholder { color: #aaa2ae; }
.composer .composer__mood { width: 38px; height: 41px; color: #a096a5; background: transparent; }
.composer__send { color: white; background: linear-gradient(145deg, #846c9b, #5d496d); box-shadow: 0 8px 19px rgba(74,53,89,.19); }
.composer button:active { transform: scale(.96); }

@media (max-width: 359px) {
  .chat-header { grid-template-columns: 38px 1fr 38px; padding-right: 13px; padding-left: 13px; }
  .chat-header__button { width: 38px; height: 38px; }
  .chat-companion { gap: 8px; }
  .chat-avatar { width: 39px; height: 39px; }
  .message-list { padding-right: 13px; padding-left: 13px; }
  .message-row--ai { padding-right: 35px; }
  .message-row--user { padding-left: 35px; }
  .composer { gap: 6px; padding-right: 10px; padding-left: 10px; }
  .composer button { width: 39px; height: 39px; }
}

@media (min-width: 521px) {
  .chat-shell { height: calc(100vh - 44px); height: calc(100dvh - 44px); }
}
