/* ==========================================================================
   Chat page layout: sidebar + main area + input.
   ========================================================================== */

body {
  display: flex;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition), opacity var(--transition);
  z-index: 100;
}
.sidebar.collapsed {
  margin-left: calc(var(--sidebar-w) * -1);
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.btn-new {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-new:hover {
  background: var(--surface);
  border-color: var(--border2);
}
.btn-new svg {
  flex-shrink: 0;
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}
.btn-icon:hover {
  background: var(--surface);
  color: var(--text);
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.sidebar-list::-webkit-scrollbar {
  width: 4px;
}
.sidebar-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.sidebar-group {
  padding: 8px 8px 4px;
  font-size: 0.72rem;
  color: var(--text3);
  font-weight: 700;
  letter-spacing: 0.06em;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 0.85rem;
  color: var(--text2);
  position: relative;
}
.conv-item:hover {
  background: var(--surface);
}
.conv-item.active {
  background: var(--surface2);
  color: var(--text);
}
.conv-item .conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-item .conv-del {
  opacity: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text3);
  cursor: pointer;
  border-radius: 6px;
  transition: all var(--transition);
  flex-shrink: 0;
}
.conv-item:hover .conv-del {
  opacity: 1;
}
.conv-item .conv-del:hover {
  color: var(--red);
  background: rgba(248, 81, 73, 0.1);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-footer .info {
  font-size: 0.72rem;
  color: var(--text3);
  display: flex;
  align-items: center;
  gap: 6px;
}
.sidebar-footer .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sidebar-footer .dot.on {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}
.sidebar-footer .dot.off {
  background: var(--red);
}

/* Main */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
}

.topbar {
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.topbar .title {
  flex: 1;
  font-family: "Noto Serif SC", serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.04em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Chat area */
.chat-wrap {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.chat-wrap::-webkit-scrollbar {
  width: 6px;
}
.chat-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.chat-wrap::-webkit-scrollbar-thumb:hover {
  background: var(--border2);
}

.chat-inner {
  max-width: var(--chat-max);
  margin: 0 auto;
  padding: 24px 20px 100px;
}

/* Welcome */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 16px;
  animation: fadeIn 0.5s ease;
}
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.welcome .brand {
  font-family: "Noto Serif SC", serif;
  font-size: 1.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.1em;
}
.welcome .sub {
  color: var(--text2);
  font-size: 0.9rem;
  margin-bottom: 12px;
}
.welcome .hints {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
  max-width: 480px;
}
.hint-card {
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text2);
  font-size: 0.85rem;
  line-height: 1.5;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  font-family: inherit;
}
.hint-card:hover {
  border-color: var(--accent-border);
  color: var(--text);
  background: var(--accent-bg);
}

/* Messages */
.msg-row {
  padding: 20px 0;
  animation: msgIn 0.35s ease;
}
.msg-row + .msg-row {
  border-top: 1px solid var(--border);
}
@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.msg-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}
.msg-row.user .msg-avatar {
  background: var(--surface3);
  color: var(--accent2);
}
.msg-row.assistant .msg-avatar {
  background: var(--accent);
  color: var(--bg);
}
.msg-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text2);
}

.msg-body {
  padding-left: 38px;
  line-height: 1.75;
  font-size: 0.92rem;
  color: var(--text);
  word-break: break-word;
}
.msg-body p {
  margin-bottom: 0.6em;
}
.msg-body p:last-child {
  margin-bottom: 0;
}
.msg-body strong {
  color: var(--accent2);
  font-weight: 600;
}
.msg-body h1,
.msg-body h2,
.msg-body h3 {
  color: var(--accent);
  font-family: "Noto Serif SC", serif;
  margin: 1.2em 0 0.5em;
}
.msg-body h1 {
  font-size: 1.25rem;
}
.msg-body h2 {
  font-size: 1.1rem;
}
.msg-body h3 {
  font-size: 1rem;
}
.msg-body ul,
.msg-body ol {
  padding-left: 1.5em;
  margin: 0.5em 0;
}
.msg-body li {
  margin: 0.3em 0;
}
.msg-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.4em 0 0.4em 1em;
  margin: 0.6em 0;
  color: var(--text2);
  background: var(--accent-bg);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.msg-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.8em 0;
  font-size: 0.85rem;
}
.msg-body th,
.msg-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.msg-body th {
  background: var(--surface2);
  font-weight: 600;
}
.msg-body a {
  color: var(--blue);
  text-decoration: none;
}
.msg-body a:hover {
  text-decoration: underline;
}

.msg-body pre {
  position: relative;
  margin: 0.8em 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.msg-body pre .code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--surface3);
  font-size: 0.72rem;
  color: var(--text3);
}
.msg-body pre code {
  display: block;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 0.82rem;
  line-height: 1.6;
  background: var(--surface);
}
.msg-body :not(pre) > code {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.84em;
  font-family: "JetBrains Mono", "Fira Code", monospace;
}

.copy-btn {
  border: none;
  background: transparent;
  color: var(--text3);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-family: inherit;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 4px;
}
.copy-btn:hover {
  color: var(--text);
  background: var(--surface);
}
.copy-btn.copied {
  color: var(--green);
}

/* Message actions */
.msg-actions {
  display: flex;
  gap: 2px;
  padding-left: 38px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity var(--transition);
}
.msg-row:hover .msg-actions {
  opacity: 1;
}
.msg-action {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text3);
  cursor: pointer;
  border-radius: 6px;
  transition: all var(--transition);
}
.msg-action:hover {
  background: var(--surface2);
  color: var(--text);
}
.msg-action.active-up {
  color: var(--green);
}
.msg-action.active-down {
  color: var(--red);
}

/* Citations */
.citations {
  margin-top: 10px;
  padding-left: 38px;
}
.cite-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text2);
  font-size: 0.78rem;
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition);
}
.cite-toggle:hover {
  border-color: var(--accent-border);
  color: var(--accent2);
}
.cite-toggle svg {
  transition: transform var(--transition);
}
.cite-toggle.open svg {
  transform: rotate(180deg);
}
.cite-list {
  margin-top: 8px;
  display: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.cite-list.show {
  display: block;
  animation: fadeIn 0.2s ease;
}
.cite-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
  color: var(--text2);
}
.cite-row:last-child {
  border-bottom: none;
}
.cite-num {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent-bg);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
  border: 1px solid var(--accent-border);
}
.cite-file {
  flex: 1;
  color: var(--text);
}
.cite-cat {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  background: var(--surface2);
  color: var(--text3);
}
.cite-score {
  font-size: 0.72rem;
  color: var(--text3);
  font-family: monospace;
}

/* Followup */
.followup-wrap {
  padding-left: 38px;
  margin-top: 10px;
}
.followup-label {
  font-size: 0.8rem;
  color: var(--text2);
  margin-bottom: 8px;
}
.followup-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text2);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
}
.followup-btn:hover {
  border-color: var(--accent-border);
  color: var(--text);
  background: var(--accent-bg);
}

/* Typing indicator */
.typing-dots {
  display: inline-flex;
  gap: 5px;
  padding: 4px 0;
}
.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotBounce 0.7s infinite alternate;
}
.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}
.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes dotBounce {
  from {
    opacity: 0.3;
    transform: translateY(0);
  }
  to {
    opacity: 1;
    transform: translateY(-5px);
  }
}

.cursor-blink::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s step-end infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* Input */
.input-area {
  position: relative;
  max-width: var(--chat-max);
  margin: 0 auto;
  width: 100%;
  padding: 0 20px 20px;
}
.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 8px 8px 18px;
  transition: border-color var(--transition);
}
.input-wrap:focus-within {
  border-color: var(--accent-border);
}
.input-wrap textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 0.92rem;
  resize: none;
  max-height: 160px;
  line-height: 1.6;
  padding: 6px 0;
}
.input-wrap textarea::placeholder {
  color: var(--text3);
}
.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
  background: var(--accent);
  color: var(--bg);
}
.send-btn:hover {
  filter: brightness(1.15);
}
.send-btn.stop {
  background: var(--red);
}
.send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  filter: none;
}
.input-hint {
  text-align: center;
  padding-top: 8px;
  font-size: 0.7rem;
  color: var(--text3);
}

/* Bottom bar: legal links on the left, usage disclaimer on the right. */
.footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 24px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
.footer-bar .site-footer {
  border-top: none;
  padding: 0;
  text-align: left;
}
.footer-bar .input-hint {
  padding-top: 0;
  text-align: right;
}

.suggestions-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 0 4px 44px;
}
.suggestion-btn {
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  color: var(--accent2);
  padding: 8px 14px;
  border-radius: 18px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  line-height: 1.4;
}
.suggestion-btn:hover {
  background: rgba(212, 160, 84, 0.16);
  border-color: var(--accent);
  color: var(--accent);
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 90;
}
.overlay.show {
  display: block;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }
  .sidebar.collapsed {
    margin-left: 0;
    transform: translateX(-100%);
    opacity: 1;
  }
  .sidebar:not(.collapsed) {
    transform: translateX(0);
  }
  .welcome .hints {
    grid-template-columns: 1fr;
  }
  .welcome .brand {
    font-size: 1.5rem;
  }
  .chat-inner {
    padding: 16px 14px 90px;
  }
  .input-area {
    padding: 0 12px 12px;
  }
  .msg-body {
    padding-left: 0;
    margin-top: 8px;
  }
  .msg-actions {
    padding-left: 0;
  }
  .citations {
    padding-left: 0;
  }
  .followup-wrap {
    padding-left: 0;
  }
  .suggestions-wrap {
    padding-left: 0;
  }
  /* 16px keeps iOS Safari from auto-zooming when the field gains focus. */
  .input-wrap textarea {
    font-size: 16px;
  }
  .input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .topbar {
    padding-top: env(safe-area-inset-top);
    height: calc(48px + env(safe-area-inset-top));
  }
  /* Stack legal links + disclaimer, centered, on small screens. */
  .footer-bar {
    justify-content: center;
    gap: 4px;
  }
  .footer-bar .site-footer,
  .footer-bar .input-hint {
    flex-basis: 100%;
    text-align: center;
  }
}

/* ---------------------------------------------------------------
 * 2.3 商用上线：推荐卡片 + 广告位 + AIGC 标识 + Footer
 * --------------------------------------------------------------- */

.recommend-rail {
  margin: 16px 0 8px 48px;
  padding: 12px 14px;
  background: var(--bg-soft, rgba(212, 160, 84, 0.05));
  border: 1px solid var(--border-light, rgba(212, 160, 84, 0.15));
  border-radius: 10px;
  font-size: 0.88rem;
}

.recommend-title {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted, #6d6b66);
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 0.82rem;
}

.recommend-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.recommend-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--bg-default, #fff);
  border: 1px solid var(--border-light, #e3dfd6);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.recommend-card:hover {
  border-color: #d4a054;
  transform: translateY(-1px);
}

.recommend-cover {
  width: 100%;
  height: 96px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg-soft, #f5efe4);
  color: #a87a2f;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.3rem;
}

.recommend-cover.placeholder {
  border: 1px dashed rgba(212, 160, 84, 0.35);
}

.recommend-item-title {
  font-weight: 600;
  color: var(--text-strong, #2a2a2a);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.recommend-item-sub {
  font-size: 0.78rem;
  color: var(--text-muted, #6d6b66);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.recommend-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--text-muted, #6d6b66);
}

.recommend-tag {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(212, 160, 84, 0.14);
  color: #8a6a2e;
}

.recommend-price {
  color: #a87a2f;
  font-weight: 600;
}

.recommend-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 1px 8px;
  font-size: 0.68rem;
  background: rgba(212, 160, 84, 0.9);
  color: #fff;
  border-radius: 999px;
}

.recommend-disclaimer {
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--text-muted, #8a8a8a);
}

.ad-frame {
  width: 100%;
  border: 0;
  min-height: 90px;
  border-radius: 8px;
  background: transparent;
}

@media (max-width: 640px) {
  .recommend-rail {
    margin-left: 0;
  }
}

/* Site is light-only; the dark/light theme toggle is hidden. */
#btnTheme {
  display: none;
}
