:root {
    --wy-ai-gap: 10px;
    --wy-ai-toggle-size: 50px;
    --wy-ai-panel-width: 400px;
    --wy-ai-panel-height: min(78vh, 780px);
    --wy-ai-panel-right: calc(var(--wy-ai-gap) + var(--wy-ai-toggle-size) + 6px);
    --wy-ai-reserve-right: calc(var(--wy-ai-panel-width) + var(--wy-ai-panel-right) + 6px);
}

/* 当 AI 面板展开时，给页面右侧预留空间，避免覆盖中间操作区 */
body.wy-ai-open {
    padding-right: var(--wy-ai-reserve-right);
}

.wy-ai-toggle {
    position: fixed;
    right: var(--wy-ai-gap);
    top: 50%;
    transform: translateY(-50%);
    z-index: 9999;
    border: none;
    border-radius: 12px;
    width: var(--wy-ai-toggle-size);
    height: var(--wy-ai-toggle-size);
    padding: 0;
    cursor: pointer;
    color: #ffffff;
    background: linear-gradient(135deg, #111827, #4f46e5);
    box-shadow: 0 12px 24px rgba(2, 6, 23, 0.35);
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    white-space: pre-line;
    line-height: 1.1;
}

.wy-ai-panel {
    position: fixed;
    right: var(--wy-ai-panel-right);
    top: 50%;
    transform: translateY(-50%);
    width: var(--wy-ai-panel-width);
    max-width: calc(100vw - 28px);
    height: var(--wy-ai-panel-height);
    z-index: 9999;
    background: rgba(255,255,255,0.96);
    border: 1px solid rgba(148,163,184,0.45);
    border-radius: 16px;
    box-shadow: 0 26px 70px rgba(2, 6, 23, 0.42);
    overflow: hidden;
    display: none;
    backdrop-filter: blur(8px);
}

.wy-ai-panel.show { display: flex; flex-direction: column; }

.wy-ai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(248,250,252,0.92);
    border-bottom: 1px solid rgba(226,232,240,0.9);
}

.wy-ai-title {
    font-size: 13px;
    font-weight: 800;
    color: #111827;
    letter-spacing: 0.02em;
}
.wy-ai-subtitle {
    margin-left: 6px;
    font-size: 12px;
    font-weight: 700;
    color: #4f46e5;
}

.wy-ai-actions { display: flex; gap: 8px; align-items: center; }

.wy-ai-btn {
    border: 1px solid rgba(148,163,184,0.55);
    background: #ffffff;
    color: #111827;
    border-radius: 10px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
}
.wy-ai-btn:hover { background: rgba(79,70,229,0.06); }

.wy-ai-body {
    flex: 1 1 auto;
    padding: 10px 10px 12px;
    overflow-y: auto;
    background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(249,250,251,0.96));
}

.wy-ai-msg {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
    align-items: flex-start;
}
.wy-ai-msg .role {
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 900;
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid rgba(226,232,240,0.9);
    background: rgba(255,255,255,0.9);
    color: #111827;
}
.wy-ai-msg.user .role { background: rgba(79,70,229,0.10); border-color: rgba(79,70,229,0.22); color: #3730a3; }
.wy-ai-msg.assistant .role { background: rgba(34,197,94,0.10); border-color: rgba(34,197,94,0.22); color: #166534; }
.wy-ai-msg .content {
    font-size: 13px;
    line-height: 1.55;
    color: #111827;
    white-space: pre-wrap;
    word-break: break-word;
}

.wy-ai-footer {
    border-top: 1px solid rgba(226,232,240,0.9);
    background: rgba(255,255,255,0.96);
    padding: 10px;
}

.wy-ai-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.wy-ai-textarea {
    flex: 1 1 auto;
    min-height: 42px;
    max-height: 120px;
    resize: vertical;
    border: 1px solid rgba(148,163,184,0.55);
    border-radius: 12px;
    padding: 8px 10px;
    outline: none;
    font-size: 13px;
    line-height: 1.45;
    background: #ffffff;
}
.wy-ai-textarea:focus { border-color: rgba(79,70,229,0.65); box-shadow: 0 0 0 2px rgba(79,70,229,0.16); }

.wy-ai-send {
    flex: 0 0 auto;
    border: none;
    border-radius: 12px;
    padding: 10px 12px;
    cursor: pointer;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #ffffff;
    font-weight: 800;
    font-size: 13px;
    box-shadow: 0 10px 18px rgba(79, 70, 229, 0.26);
}
.wy-ai-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

.wy-ai-hint {
    margin-top: 8px;
    font-size: 11px;
    color: #6b7280;
}

/* 窄屏：不预留右侧空间，面板改为覆盖式（避免把内容挤太窄） */
@media (max-width: 1100px) {
    body.wy-ai-open { padding-right: 0; }
    :root {
        --wy-ai-panel-width: min(360px, calc(100vw - 28px));
        --wy-ai-panel-right: var(--wy-ai-gap);
        --wy-ai-reserve-right: 0px;
    }
}
