.chat-page {
  background: var(--bg);
  height: 100svh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  max-width: 44rem;
  margin: 0 auto;
  padding: 1.6rem 1.5rem 0;
  width: 100%;
}
.topbar-mark {
  font-size: var(--f-1);
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}
.topbar-mark:hover { color: #fff; }
.topbar-link {
  font-size: var(--f--1);
  color: var(--ink-muted);
  text-decoration: none;
  border-bottom: 1px solid var(--hairline);
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}
.topbar-link:hover { color: var(--ink); border-color: var(--ink-faint); }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 44rem;
  width: 100%;
  margin: 0 auto;
  padding: 2.4rem 1.5rem 2rem;
  min-height: 0;
}

.chat-panel {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--hairline);
  border-radius: 16px;
  background: hsla(0, 0%, 100%, 0.022);
  backdrop-filter: blur(14px) saturate(120%);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  box-shadow: 0 24px 80px hsla(0, 0%, 0%, 0.45);
  overflow: hidden;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .chat-panel {
    background: hsla(0, 0%, 8%, 0.82);
  }
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2.9rem 1.4rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scrollbar-gutter: stable;
}

.chat-msg {
  max-width: 88%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: var(--f-0);
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: rise-msg 320ms var(--ease) both;
}
@keyframes rise-msg {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.chat-msg--user {
  align-self: flex-end;
  background: hsla(211, 100%, 62.5%, 0.14);
  border: 1px solid hsla(211, 100%, 62.5%, 0.30);
  color: var(--ink);
  border-bottom-right-radius: 4px;
}
.chat-msg--assistant {
  align-self: flex-start;
  background: hsla(0, 0%, 100%, 0.045);
  border: 1px solid var(--hairline-soft);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.chat-msg--system {
  align-self: center;
  background: hsla(38, 92%, 55%, 0.10);
  border: 1px solid hsla(38, 92%, 55%, 0.32);
  color: var(--warn);
  font-size: var(--f--1);
  text-align: center;
}

.chat-msg--typing {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.85rem 1.05rem;
}
.chat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-faint);
  animation: chat-bounce 1.1s ease-in-out infinite;
}
.chat-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-dot:nth-child(3) { animation-delay: 0.30s; }
@keyframes chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
  padding: 0.9rem 1rem;
  border-top: 1px solid var(--hairline-soft);
  max-height: 6.2rem;
  overflow: hidden;
}

.chat-input {
  flex: 1;
  resize: none;
  max-height: 4.4rem;
  background: hsla(0, 0%, 100%, 0.04);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  color: var(--ink);
  font: inherit;
  font-size: var(--f-0);
  line-height: 1.5;
  transition: border-color 160ms var(--ease), background 160ms var(--ease);
}
.chat-input::placeholder { color: var(--ink-faint); }
.chat-input:focus-visible {
  outline: none;
  border-color: hsla(211, 100%, 62.5%, 0.72);
  background: hsla(0, 0%, 100%, 0.06);
}
.chat-input:disabled { opacity: 0.5; }

.chat-send {
  flex-shrink: 0;
  padding: 0.65rem 0.85rem;
  display: inline-flex;
  font-size: var(--f-0);
  line-height: 1.5;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid hsla(211, 100%, 62.5%, 0.72);
  background: hsla(211, 100%, 62.5%, 0.14);
  color: var(--ink);
  cursor: pointer;
  transition: background 160ms var(--ease), transform 160ms var(--ease), opacity 160ms var(--ease);
}
.chat-send:hover:not(:disabled) { background: hsla(211, 100%, 62.5%, 0.24);}
.chat-send:active:not(:disabled) { transform: translateY(0); }
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-send:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.chat-foot {
  padding: 0 1.1rem 0.35rem;
}

.chat-live {
  position: absolute;
  top: 0.85rem;
  left: 1rem;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: hsla(0, 0%, 5%, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: var(--f--1);
  color: var(--ink-faint);
  line-height: 1.4;
  pointer-events: none;
}
.chat-live-dot {
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-faint);
}
.chat-live--on .chat-live-dot {
  background: var(--good);
  box-shadow: 0 0 0 2px hsla(140, 60%, 50%, 0.18);
}
.chat-live--on #chat-live-label { color: var(--good); font-weight: 500; }

.chat-status {
  display: block;
  font-size: var(--f--1);
  color: var(--ink-faint);
}
.chat-status:empty { display: none; }
.chat-status--error { color: var(--warn); }

.chat-empty {
  max-width: 48ch;
  margin: auto;
  text-align: center;
  color: var(--ink-faint);
  font-size: var(--f--1);
  padding: 2rem 1rem;
}

@media (max-width: 560px) {
  .chat-main { padding: 0.7rem 0.6rem 0.6rem; }
  .chat-panel { border-radius: 14px; }
  .chat-log { padding: 2.6rem 1rem 0.5rem; }
  .chat-msg { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-msg { animation: none; }
  .chat-dot { animation: none; opacity: 0.8; }
}
