/* 微光AI — 经典 QQ 聊天窗口风格 */
:root {
  --footer-bar-h: 34px;
  --qq-title: linear-gradient(180deg, #6eb4ff 0%, #4a9ef5 45%, #3d8ee8 100%);
  --qq-title-border: #2d7ad4;
  --qq-sidebar: #f5f5f5;
  --qq-sidebar-hover: #e8f4ff;
  --qq-sidebar-active: #d6ebff;
  --qq-chat-bg: #f0f0f0;
  --qq-bubble-other: #fff;
  --qq-bubble-self: #9eea6e;
  --qq-bubble-self-border: #7ed456;
  --qq-input-bg: #fff;
  --qq-border: #d4d4d4;
  --qq-text: #333;
  --qq-text-muted: #888;
  --qq-send: linear-gradient(180deg, #5cadff 0%, #3d96f0 100%);
  --qq-window-shadow: 0 8px 32px rgba(0, 40, 100, 0.25), 0 2px 8px rgba(0, 0, 0, 0.12);
  --qq-radius: 6px;
  --font-qq: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* 与官网顶栏、页脚共存：背景与首页一致 */
.page-weiguang {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--color-bg-deep);
  color: var(--color-text);
}

.page-weiguang #bg-canvas,
.page-weiguang .grid-overlay {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.page-weiguang .nav a.active {
  color: var(--color-text);
}

.page-weiguang .nav a.active::after {
  width: 100%;
}

/* 顶栏固定；底栏 fixed 贴视口最底 */
.page-layout {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: var(--header-h, 72px);
  padding-bottom: var(--footer-bar-h);
  box-sizing: border-box;
}

.wg-main {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px 0;
  min-height: 0;
  overflow: hidden;
  font-family: var(--font-qq);
  font-size: 12px;
  color: var(--qq-text);
}

.page-weiguang .site-footer--bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  width: 100%;
  margin: 0;
  padding: 6px 20px;
  border-top: 1px solid var(--color-border);
  background: rgba(5, 8, 16, 0.98);
  box-sizing: border-box;
}

.page-weiguang .site-footer--bar .footer-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 22px;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

.page-weiguang .site-footer--bar .footer-copy,
.page-weiguang .site-footer--bar .footer-mail,
.page-weiguang .site-footer--bar .footer-icp {
  margin: 0;
  font-size: 0.78rem;
  color: var(--color-text-dim);
  white-space: nowrap;
}

.page-weiguang .site-footer--bar .footer-mail:hover,
.page-weiguang .site-footer--bar .footer-icp:hover {
  color: var(--color-primary);
}

/* 主窗口 */
.qq-window {
  --qq-win-min-w: 520px;
  --qq-win-min-h: 380px;
  width: min(920px, 100%);
  height: min(620px, calc(100dvh - var(--header-h, 72px) - var(--footer-bar-h) - 16px));
  min-width: var(--qq-win-min-w);
  min-height: var(--qq-win-min-h);
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--qq-sidebar);
  border: 1px solid var(--qq-title-border);
  border-radius: var(--qq-radius);
  box-shadow: var(--qq-window-shadow);
  overflow: hidden;
  flex-shrink: 0;
}

.qq-window.is-dragged,
.qq-window.is-sized,
.qq-window.is-resizing {
  position: absolute;
  margin: 0;
  z-index: 5;
  max-width: none;
  max-height: none;
}

.qq-window.is-maximized {
  border-radius: 4px;
}

.qq-window.minimized {
  height: 32px !important;
  min-height: 32px !important;
  overflow: hidden;
}

.qq-window.minimized .qq-body,
.qq-window.minimized .qq-resize-handle {
  display: none;
}

.qq-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 16px;
  height: 16px;
  z-index: 8;
  cursor: nwse-resize;
  background: linear-gradient(
    135deg,
    transparent 0 55%,
    rgba(61, 142, 232, 0.45) 55% 70%,
    rgba(45, 122, 212, 0.75) 70% 100%
  );
  border-bottom-right-radius: var(--qq-radius);
}

.qq-window.is-resizing .qq-resize-handle {
  background: linear-gradient(
    135deg,
    transparent 0 50%,
    rgba(45, 122, 212, 0.9) 50% 100%
  );
}

/* 标题栏 */
.qq-titlebar {
  display: flex;
  align-items: center;
  height: 32px;
  padding: 0 8px 0 10px;
  background: var(--qq-title);
  border-bottom: 1px solid var(--qq-title-border);
  flex-shrink: 0;
  user-select: none;
  cursor: move;
}

.qq-titlebar.is-grabbing {
  cursor: grabbing;
}

.qq-titlebar .qq-win-btn {
  cursor: default;
}

.qq-titlebar-logo {
  width: 18px;
  height: 18px;
  margin-right: 8px;
  border-radius: 3px;
  object-fit: contain;
}

.qq-titlebar-name {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 50, 120, 0.4);
}

.qq-titlebar-btns {
  display: flex;
  gap: 2px;
}

.qq-win-btn {
  width: 28px;
  height: 22px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: default;
  border-radius: 3px;
  opacity: 0.9;
}

.qq-win-btn:hover { background: rgba(255, 255, 255, 0.2); }
.qq-win-btn.close:hover { background: #e81123; }

/* 主体 */
.qq-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* 左侧联系人 */
.qq-sidebar {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--qq-sidebar);
  border-right: 1px solid var(--qq-border);
}

.qq-search {
  padding: 8px;
  border-bottom: 1px solid var(--qq-border);
}

.qq-search input {
  width: 100%;
  height: 26px;
  padding: 0 8px 0 28px;
  font-size: 12px;
  border: 1px solid #ccc;
  border-radius: 3px;
  outline: none;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='%23999' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242 1.1a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E") 8px center no-repeat;
}

.qq-search input:focus { border-color: #4a9ef5; }

.qq-groups {
  flex: 1;
  overflow-y: auto;
}

.qq-group-title {
  padding: 6px 10px;
  font-size: 11px;
  color: var(--qq-text-muted);
  background: #ebebeb;
  border-top: 1px solid #e0e0e0;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.qq-group-title::before {
  content: "▼";
  font-size: 8px;
  transition: transform 0.2s;
}

.qq-group.collapsed .qq-group-title::before { transform: rotate(-90deg); }
.qq-group.collapsed .qq-contact-list { display: none; }

.qq-contact-list { list-style: none; }

.qq-contact {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid #eee;
  transition: background 0.15s;
}

.qq-contact:hover { background: var(--qq-sidebar-hover); }
.qq-contact.active { background: var(--qq-sidebar-active); }

.qq-avatar {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  background: linear-gradient(135deg, #7eb8ff, #4a9ef5);
  display: grid;
  place-items: center;
  font-size: 14px;
  color: #fff;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}

.qq-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.qq-contact-info { min-width: 0; flex: 1; }

.qq-contact-name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.qq-contact-preview {
  font-size: 11px;
  color: var(--qq-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.qq-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #52c41a;
  border: 1px solid #fff;
  flex-shrink: 0;
}

.qq-status-dot.offline { background: #bbb; }

/* 右侧聊天区 */
.qq-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--qq-chat-bg);
}

.qq-chat-header {
  height: 52px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(180deg, #fafafa 0%, #f0f0f0 100%);
  border-bottom: 1px solid var(--qq-border);
  flex-shrink: 0;
}

.qq-chat-header .qq-avatar { width: 40px; height: 40px; }

.qq-chat-title h2 {
  font-size: 14px;
  font-weight: 600;
}

.qq-chat-title p {
  font-size: 11px;
  color: var(--qq-text-muted);
  margin-top: 2px;
}

/* 消息区 */
.qq-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  background: var(--qq-chat-bg);
}

.qq-msg-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  align-items: flex-start;
}

.qq-msg-row.self {
  flex-direction: row-reverse;
}

.qq-msg-row .qq-avatar {
  width: 34px;
  height: 34px;
  font-size: 12px;
}

.qq-msg-body { max-width: 68%; }

.qq-msg-name {
  font-size: 11px;
  color: var(--qq-text-muted);
  margin-bottom: 4px;
}

.qq-msg-row.self .qq-msg-name { text-align: right; }

.qq-bubble-typing {
  color: #888;
  font-style: italic;
}

.qq-bubble {
  position: relative;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.qq-msg-row:not(.self) .qq-bubble {
  background: var(--qq-bubble-other);
  border: 1px solid #e5e5e5;
}

.qq-msg-row:not(.self) .qq-bubble::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 10px;
  border: 6px solid transparent;
  border-right-color: #fff;
  filter: drop-shadow(-1px 0 0 #e5e5e5);
}

.qq-msg-row.self .qq-bubble {
  background: var(--qq-bubble-self);
  border: 1px solid var(--qq-bubble-self-border);
}

.qq-msg-row.self .qq-bubble::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 10px;
  border: 6px solid transparent;
  border-left-color: var(--qq-bubble-self);
}

.qq-msg-time {
  font-size: 10px;
  color: #aaa;
  text-align: center;
  margin: 12px 0;
}

/* 输入区 */
.qq-input-area {
  flex-shrink: 0;
  background: #fafafa;
  border-top: 1px solid var(--qq-border);
}

.qq-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid #e8e8e8;
}

.qq-tool-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 3px;
  cursor: pointer;
  font-size: 16px;
  color: #666;
  display: grid;
  place-items: center;
}

.qq-tool-btn:hover {
  background: #e8e8e8;
}

.qq-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px 10px;
}

.qq-input {
  flex: 1;
  min-height: 72px;
  max-height: 120px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid #ccc;
  border-radius: 3px;
  resize: none;
  outline: none;
  background: var(--qq-input-bg);
}

.qq-input:focus { border-color: #4a9ef5; }

.qq-send {
  width: 72px;
  height: 28px;
  border: 1px solid #2d7ad4;
  border-radius: 3px;
  background: var(--qq-send);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  text-shadow: 0 1px 1px rgba(0, 50, 120, 0.3);
}

.qq-send:hover {
  filter: brightness(1.05);
}

.qq-send:active { filter: brightness(0.95); }

.qq-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* 滚动条 QQ 风格 */
.qq-messages::-webkit-scrollbar,
.qq-groups::-webkit-scrollbar {
  width: 8px;
}

.qq-messages::-webkit-scrollbar-thumb,
.qq-groups::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

/* 代码块与下载 */
.qq-msg-row:not(.self) .qq-bubble {
  max-width: min(92%, 560px);
}

.qq-bubble-text {
  display: block;
  white-space: pre-wrap;
  margin-bottom: 6px;
}

.qq-code-block {
  margin: 8px 0;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  overflow: hidden;
  background: #f6f8fa;
}

.qq-code-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  background: #eaeef2;
  border-bottom: 1px solid #d0d7de;
}

.qq-code-lang {
  font-size: 11px;
  color: #57606a;
  flex: 1;
}

.qq-code-btn {
  border: 1px solid #c9d1d9;
  background: #fff;
  border-radius: 4px;
  padding: 2px 10px;
  font-size: 11px;
  cursor: pointer;
  color: #24292f;
}

.qq-code-btn:hover { background: #f3f4f6; }

.qq-code-btn-run {
  background: #e8f4ff;
  border-color: #7eb8ff;
  color: #1a5fb4;
}

.qq-code-block pre {
  margin: 0;
  padding: 10px;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.45;
  font-family: Consolas, "Courier New", monospace;
}

.qq-code-block code { white-space: pre; }

.qq-downloads {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.qq-download-btn {
  display: inline-block;
  padding: 6px 14px;
  background: linear-gradient(180deg, #5cadff 0%, #3d96f0 100%);
  color: #fff;
  border-radius: 4px;
  font-size: 12px;
  text-decoration: none;
}

.qq-download-btn:hover { filter: brightness(1.05); }

/* 代码运行弹窗 */
.code-run-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.code-run-modal[hidden] { display: none; }

.code-run-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.code-run-panel {
  position: relative;
  width: min(92vw, 900px);
  height: min(80vh, 640px);
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.code-run-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #f0f0f0;
  border-bottom: 1px solid #ddd;
  font-size: 14px;
  font-weight: 600;
}

.code-run-close {
  border: none;
  background: transparent;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  color: #666;
}

.code-run-frame {
  flex: 1;
  width: 100%;
  border: none;
}

@media (max-width: 640px) {
  .qq-sidebar { width: 72px; }
  .qq-contact-info,
  .qq-search input { display: none; }
  .qq-search { padding: 6px; }
  .qq-group-title { font-size: 0; padding: 4px; }
  .qq-group-title::before { margin: 0 auto; }
  .qq-contact { justify-content: center; padding: 8px 4px; }
}
