:root {
  --chat-max: 880px;
  --side-w: 220px;
}

body {
  height: 100vh;
  margin: 0;
  overflow: hidden;
}

.chat-shell {
  display: flex;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  position: relative;
}

.chat-sidebar {
  position: sticky;
  top: 0;
  z-index: 30;
  width: var(--side-w);
  flex-shrink: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1.15rem 0.9rem;
  background: rgba(255, 255, 255, 0.72);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.chat-sidebar .brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.08rem;
  padding: 0.35rem 0.45rem 0.85rem;
}

.chat-sidebar .brand img {
  border-radius: 7px;
}

.side-history {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: visible;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-right: 0.15rem;
}

.side-history:empty {
  display: none;
}

.side-history-row {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 0.2rem;
  width: 100%;
  border-radius: 10px;
}

.side-history-row:hover,
.side-history-row.is-active {
  background: #fff;
}

.side-history-row:hover .side-history-item,
.side-history-row.is-active .side-history-item {
  border-color: rgba(77, 107, 254, 0.28);
  color: var(--accent-deep);
  background: transparent;
}

.side-history-item {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink-2);
  border-radius: 10px;
  padding: 0.55rem 0.55rem 0.55rem 0.7rem;
  font: inherit;
  font-size: 0.86rem;
  line-height: 1.4;
  cursor: pointer;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: normal;
}

.side-history-more {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  align-self: center;
  margin-right: 0.2rem;
}

.side-history-more-btn {
  appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, background 0.12s ease;
}

.side-history-row:hover .side-history-more-btn,
.side-history-row:focus-within .side-history-more-btn,
.side-history-more.is-open .side-history-more-btn {
  opacity: 1;
  pointer-events: auto;
}

.side-history-more-btn:hover {
  background: rgba(77, 107, 254, 0.1);
  color: var(--accent-deep);
}

.side-history-more-dots,
.side-history-more-dots::before,
.side-history-more-dots::after {
  display: block;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
}

.side-history-more-dots {
  position: relative;
  box-shadow: 0 -5px 0 currentColor, 0 5px 0 currentColor;
}

.side-history-more-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 40;
  min-width: 88px;
  padding: 0.25rem;
  border-radius: 10px;
  background: #fff;
  border: 1px solid rgba(77, 107, 254, 0.22);
  box-shadow: var(--shadow-sm);
}

.side-history-more-menu[hidden] {
  display: none !important;
}

.side-history-delete {
  appearance: none;
  width: 100%;
  border: 0;
  background: transparent;
  color: #dc2626;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 560;
  line-height: 1.3;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}

.side-history-delete:hover {
  background: rgba(220, 38, 38, 0.08);
}

.side-footer {
  margin-top: auto;
  flex-shrink: 0;
  padding-top: 0.55rem;
  border-top: 1px solid var(--line);
}

.side-account {
  display: flex;
  align-items: stretch;
  gap: 0;
  width: 100%;
  min-height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.75);
  overflow: hidden;
  box-sizing: border-box;
}

.side-account:hover {
  border-color: rgba(77, 107, 254, 0.35);
  background: #fff;
}

.side-account-name {
  flex: 1;
  min-width: 0;
  min-height: 0;
  padding: 0 0.75rem 0 0.85rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink-2);
  text-align: left;
  font: inherit;
  font-weight: 560;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-account-name:hover {
  color: var(--accent-deep);
  background: transparent;
  border: 0;
}

.side-settings-btn {
  flex: 0 0 auto;
  width: 40px;
  min-height: 100%;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--ink-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.side-settings-btn:hover {
  color: var(--accent-deep);
  background: rgba(77, 107, 254, 0.08);
  border-left-color: var(--line);
}

.settings-card .settings-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0.35rem 0 0.2rem;
}

.settings-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  box-sizing: border-box;
}

.side-btn,
.ghost-btn,
.primary-btn,
.send-btn,
.side-toggle {
  font: inherit;
  cursor: pointer;
  border: 0;
}

.side-btn {
  width: 100%;
  min-height: 42px;
  padding: 0 0.9rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--line-strong);
  color: var(--ink-2);
  text-align: left;
  font-weight: 500;
}

.side-btn:hover {
  border-color: rgba(77, 107, 254, 0.35);
  color: var(--accent-deep);
  background: #fff;
}

.side-btn-primary {
  background: var(--accent-soft);
  border-color: rgba(77, 107, 254, 0.22);
  color: var(--accent-deep);
  font-weight: 600;
}

.ghost-btn {
  min-height: 36px;
  padding: 0 0.9rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid var(--line-strong);
  color: var(--ink-2);
}

.ghost-btn:hover {
  border-color: rgba(77, 107, 254, 0.35);
  color: var(--accent-deep);
}

.primary-btn {
  min-height: 40px;
  padding: 0 1.1rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.primary-btn:hover {
  background: var(--accent-deep);
}

.chat-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.side-toggle {
  display: none;
  position: fixed;
  top: 0.85rem;
  left: 0.85rem;
  z-index: 25;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line-strong);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.side-backdrop {
  display: none;
}

.chat-main {
  position: relative;
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1;
  background: var(--paper);
}

.chat-welcome {
  text-align: center;
  padding: 18vh 1rem 2rem;
  width: 100%;
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-welcome[hidden] {
  display: none !important;
}

.chat-welcome h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  margin: 0;
}

.chat-messages {
  position: relative;
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.chat-messages[hidden] {
  display: none !important;
}

.chat-canvas {
  position: relative;
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--ink);
  line-height: 1.65;
  overflow: hidden;
}

.chat-canvas.has-html {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  container-type: size;
  background: #f7fafd;
}

.chat-canvas.is-generating {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f7fafd;
  border: 0;
  box-shadow: none;
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
}

.msg-generating {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  margin: 0;
  padding: 0.8rem 1.25rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.2;
  white-space: nowrap;
}

.msg-gen-wave {
  display: inline-flex;
  align-items: flex-end;
  justify-content: center;
  gap: 3px;
  height: 16px;
  flex-shrink: 0;
}

.msg-gen-wave i,
.msg-gen-wave b {
  display: block;
  width: 3px;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transform-origin: center bottom;
  animation: gen-wave 1s ease-in-out infinite;
}

.msg-gen-wave i:nth-child(1),
.msg-gen-wave b:nth-child(1) {
  animation-delay: 0s;
}
.msg-gen-wave i:nth-child(2),
.msg-gen-wave b:nth-child(2) {
  animation-delay: 0.12s;
}
.msg-gen-wave i:nth-child(3),
.msg-gen-wave b:nth-child(3) {
  animation-delay: 0.24s;
}
.msg-gen-wave i:nth-child(4),
.msg-gen-wave b:nth-child(4) {
  animation-delay: 0.36s;
}
.msg-gen-wave i:nth-child(5),
.msg-gen-wave b:nth-child(5) {
  animation-delay: 0.48s;
}

@keyframes gen-wave {
  0%,
  100% {
    transform: scaleY(0.35);
    opacity: 0.45;
  }
  50% {
    transform: scaleY(1);
    opacity: 1;
  }
}

.msg-html-frame {
  display: block;
  position: relative;
  /* 预览固定为正方形：取画布短边，居中 letterbox */
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  min-height: 0;
  flex: 0 0 auto;
  border: 0;
  border-radius: 0;
  background: #f7fafd;
}

.msg-html-frame:fullscreen,
.msg-html-frame:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  aspect-ratio: auto;
}

.msg-html-frame-next {
  position: absolute !important;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(100cqw, 100cqh) !important;
  height: min(100cqw, 100cqh) !important;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1 / 1;
  opacity: 0;
  pointer-events: none;
  z-index: 1;
}

.chat-composer-wrap {
  position: relative;
  z-index: 10;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.55rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--line);
  pointer-events: none;
  box-sizing: border-box;
  overflow: visible;
}

.chat-composer-wrap > * {
  pointer-events: auto;
}

.chat-interact-dock {
  width: min(100%, var(--chat-max));
  margin: 0 0 0.55rem;
  position: relative;
  z-index: 20;
  overflow: visible;
}

.chat-interact-dock[hidden] {
  display: none !important;
}

.chat-interact-row {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  width: 100%;
  overflow: visible;
}

.chat-interact-chips {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: nowrap;
  gap: 0.45rem;
  justify-content: flex-start;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 0.1rem 0;
}

.chat-interact-chips::-webkit-scrollbar {
  display: none;
}

.chat-interact-more-wrap {
  position: relative;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: visible;
}

.chat-interact-more-wrap.is-disabled {
  pointer-events: none;
}

.chat-interact-more-menu {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  z-index: 30;
  pointer-events: auto;
  padding-bottom: 0.45rem;
}

.chat-interact-more-menu[hidden] {
  display: none !important;
}

.chat-interact-more-wrap:hover:not(.is-disabled) .chat-interact-more-menu,
.chat-interact-more-wrap.is-open .chat-interact-more-menu {
  display: flex !important;
}

.chat-interact-chip {
  appearance: none;
  border: 1px solid rgba(77, 107, 254, 0.28);
  background: rgba(255, 255, 255, 0.94);
  color: var(--accent-deep);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 560;
  line-height: 1.3;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  width: max-content;
  max-width: none;
  flex: 0 0 auto;
  flex-shrink: 0;
  box-sizing: border-box;
}

.chat-interact-chip:hover {
  border-color: rgba(77, 107, 254, 0.45);
  background: #fff;
}

.chat-interact-chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.chat-interact-more-btn {
  appearance: none;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid rgba(77, 107, 254, 0.28);
  background: rgba(255, 255, 255, 0.94);
  color: var(--accent-deep);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  flex-shrink: 0;
}

.chat-interact-more-btn:hover:not(:disabled) {
  border-color: rgba(77, 107, 254, 0.45);
  background: #fff;
}

.chat-interact-more-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.chat-interact-more-dots,
.chat-interact-more-dots::before,
.chat-interact-more-dots::after {
  display: block;
  width: 3.5px;
  height: 3.5px;
  border-radius: 50%;
  background: currentColor;
}

.chat-interact-more-dots {
  position: relative;
  box-shadow: -6px 0 0 currentColor, 6px 0 0 currentColor;
}

.chat-composer {
  width: min(100%, var(--chat-max));
  margin: 0;
  display: flex;
  align-items: flex-end;
  gap: 0.65rem;
  padding: 0.5rem 0.75rem;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  box-sizing: border-box;
}

.chat-composer textarea {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  font: inherit;
  font-size: 1rem;
  line-height: 22px;
  height: 40px;
  min-height: 40px;
  max-height: 140px;
  padding: 9px 4px;
  margin: 0;
  box-sizing: border-box;
  color: var(--ink);
  vertical-align: middle;
}

.chat-composer textarea::placeholder {
  color: var(--muted-2);
  line-height: 22px;
  vertical-align: middle;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 8px 18px var(--accent-glow);
}

.send-btn:disabled {
  opacity: 0.4;
  box-shadow: none;
  cursor: not-allowed;
}

.send-btn svg {
  width: 18px;
  height: 18px;
}

.chat-hint {
  width: min(100%, var(--chat-max));
  margin: 0.45rem 0 0;
  min-height: 1.2em;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

.auth-dialog {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: calc(100vw - 2rem);
}

.auth-dialog::backdrop {
  background: rgba(26, 35, 50, 0.35);
  backdrop-filter: blur(4px);
}

.auth-card {
  position: relative;
  width: min(100%, 400px);
  margin: auto;
  padding: 1.5rem 1.35rem 1.25rem;
  border-radius: 20px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.auth-card h2 {
  margin: 0;
  font-size: 1.35rem;
}

.auth-sub {
  margin: -0.35rem 0 0.2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.88rem;
  color: var(--ink-2);
}

.auth-card label[hidden],
.auth-check[hidden],
[hidden] {
  display: none !important;
}

.auth-card input[type="text"],
.auth-card input[type="password"],
.auth-card input:not([type]) {
  min-height: 42px;
  padding: 0 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  font: inherit;
}

.auth-check {
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem !important;
  font-size: 0.84rem !important;
}

.auth-check a {
  color: var(--accent-deep);
}

.auth-error {
  margin: 0;
  color: #c0392b;
  font-size: 0.88rem;
}

.auth-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.35rem;
}

.auth-close {
  position: absolute;
  top: 0.55rem;
  right: 0.7rem;
  border: 0;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

@media (max-width: 860px) {
  .side-toggle {
    display: grid;
    place-items: center;
  }

  .chat-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }

  body.side-open .chat-sidebar {
    transform: translateX(0);
  }

  .side-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 28;
    background: rgba(26, 35, 50, 0.28);
  }

  .side-backdrop[hidden] {
    display: none !important;
  }

  .chat-main {
    padding-top: 0;
  }

  .chat-composer-wrap {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}
