/**
 * Agnes AI for WordPress - 前端样式
 * Version: 1.1.0
 */

/* ===================== 主题变量 ===================== */
.agnes-ai-widget {
    --agnes-primary: #6366f1;
    --agnes-primary-hover: #4f46e5;
    --agnes-primary-light: #eef2ff;
    --agnes-primary-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --agnes-secondary: #64748b;
    --agnes-success: #10b981;
    --agnes-danger: #ef4444;
    --agnes-warning: #f59e0b;
    --agnes-bg: #ffffff;
    --agnes-bg-alt: #f8fafc;
    --agnes-bg-hover: #f1f5f9;
    --agnes-border: #e2e8f0;
    --agnes-text: #1e293b;
    --agnes-text-muted: #64748b;
    --agnes-text-light: #94a3b8;
    --agnes-radius: 16px;
    --agnes-radius-sm: 10px;
    --agnes-radius-xs: 6px;
    --agnes-shadow: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.03);
    --agnes-shadow-md: 0 4px 6px rgba(0,0,0,0.04), 0 2px 4px rgba(0,0,0,0.03);
    --agnes-shadow-lg: 0 10px 25px rgba(0,0,0,0.06), 0 4px 6px rgba(0,0,0,0.03);
    --agnes-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
    --agnes-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    .agnes-ai-widget {
        --agnes-bg: #1e293b;
        --agnes-bg-alt: #0f172a;
        --agnes-bg-hover: #334155;
        --agnes-border: #334155;
        --agnes-text: #f1f5f9;
        --agnes-text-muted: #94a3b8;
        --agnes-text-light: #64748b;
        --agnes-primary-light: #312e81;
    }
}

/* ===================== 容器 ===================== */
.agnes-ai-widget {
    font-family: var(--agnes-font);
    background: var(--agnes-bg);
    border: 1px solid var(--agnes-border);
    border-radius: var(--agnes-radius);
    box-shadow: var(--agnes-shadow-md);
    overflow: hidden;
    margin: 24px 0;
    color: var(--agnes-text);
    line-height: 1.6;
}

.agnes-ai-widget * {
    box-sizing: border-box;
}

/* ===================== 头部 ===================== */
.agnes-ai-header {
    background: var(--agnes-primary-gradient);
    color: #fff;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
}

.agnes-ai-header .dashicons {
    font-size: 22px;
    width: 22px;
    height: 22px;
}

.agnes-ai-header .agnes-ai-clear-btn {
    margin-left: auto;
    background: rgba(255,255,255,0.15);
    color: #fff;
    border: none;
    padding: 6px 14px;
    border-radius: var(--agnes-radius-xs);
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

.agnes-ai-header .agnes-ai-clear-btn:hover {
    background: rgba(255,255,255,0.25);
}

/* ===================== 按钮 ===================== */
.agnes-ai-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--agnes-radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    font-family: var(--agnes-font);
}

.agnes-ai-btn-primary {
    background: var(--agnes-primary);
    color: #fff;
}

.agnes-ai-btn-primary:hover {
    background: var(--agnes-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}

.agnes-ai-btn-secondary {
    background: var(--agnes-bg-alt);
    color: var(--agnes-text);
    border: 1px solid var(--agnes-border);
}

.agnes-ai-btn-secondary:hover {
    background: var(--agnes-bg-hover);
}

.agnes-ai-btn .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
}

.agnes-ai-btn.is-loading {
    opacity: 0.7;
    pointer-events: none;
}

.agnes-ai-btn.is-loading .agnes-ai-btn-text {
    visibility: hidden;
}

.agnes-ai-btn.is-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: agnes-spin 0.6s linear infinite;
}

.agnes-ai-btn-secondary.is-loading::after {
    border-color: rgba(0,0,0,0.2);
    border-top-color: var(--agnes-primary);
}

.agnes-ai-btn { position: relative; }

@keyframes agnes-spin {
    to { transform: rotate(360deg); }
}

/* ===================== Spinner ===================== */
.agnes-ai-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: agnes-spin 0.6s linear infinite;
}

.agnes-ai-spinner-lg {
    width: 40px;
    height: 40px;
    border: 3px solid var(--agnes-border);
    border-top-color: var(--agnes-primary);
    border-radius: 50%;
    animation: agnes-spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

/* ===================== 聊天模块 ===================== */
.agnes-ai-chat-messages {
    padding: 24px;
    max-height: 500px;
    overflow-y: auto;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--agnes-bg-alt);
}

.agnes-ai-chat-messages:empty::before {
    content: '开始对话吧！';
    color: var(--agnes-text-light);
    text-align: center;
    margin: auto;
    font-size: 15px;
}

.agnes-ai-message {
    display: flex;
    gap: 12px;
    max-width: 85%;
    animation: agnes-fade-in 0.3s ease;
}

.agnes-ai-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.agnes-ai-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

.agnes-ai-message-user .agnes-ai-message-avatar {
    background: var(--agnes-primary);
    color: #fff;
}

.agnes-ai-message-assistant .agnes-ai-message-avatar {
    background: var(--agnes-primary-gradient);
    color: #fff;
}

.agnes-ai-message-bubble {
    padding: 12px 16px;
    border-radius: var(--agnes-radius-sm);
    font-size: 14px;
    line-height: 1.7;
    word-break: break-word;
}

.agnes-ai-message-user .agnes-ai-message-bubble {
    background: var(--agnes-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.agnes-ai-message-assistant .agnes-ai-message-bubble {
    background: var(--agnes-bg);
    border: 1px solid var(--agnes-border);
    border-bottom-left-radius: 4px;
    box-shadow: var(--agnes-shadow);
}

.agnes-ai-message-bubble pre {
    background: var(--agnes-bg-alt);
    border: 1px solid var(--agnes-border);
    border-radius: var(--agnes-radius-xs);
    padding: 12px 16px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 13px;
}

.agnes-ai-message-bubble code {
    background: var(--agnes-bg-alt);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--agnes-mono);
    font-size: 13px;
}

.agnes-ai-message-bubble pre code {
    background: none;
    padding: 0;
}

.agnes-ai-message-bubble h1,
.agnes-ai-message-bubble h2,
.agnes-ai-message-bubble h3,
.agnes-ai-message-bubble h4 {
    margin: 8px 0 4px;
}

.agnes-ai-message-bubble ul,
.agnes-ai-message-bubble ol {
    padding-left: 20px;
    margin: 4px 0;
}

.agnes-ai-message-bubble blockquote {
    border-left: 3px solid var(--agnes-primary);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--agnes-text-muted);
}

.agnes-ai-message-bubble a {
    color: var(--agnes-primary);
}

.agnes-ai-message-bubble p {
    margin: 4px 0;
}

.agnes-ai-message-bubble p:first-child { margin-top: 0; }
.agnes-ai-message-bubble p:last-child { margin-bottom: 0; }

.agnes-ai-typing-cursor {
    display: inline-block;
    width: 2px;
    height: 16px;
    background: var(--agnes-primary);
    animation: agnes-blink 1s infinite;
    vertical-align: text-bottom;
    margin-left: 2px;
}

@keyframes agnes-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

@keyframes agnes-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.agnes-ai-message-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.agnes-ai-message:hover .agnes-ai-message-actions {
    opacity: 1;
}

.agnes-ai-action-btn {
    background: none;
    border: none;
    color: var(--agnes-text-light);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

.agnes-ai-action-btn:hover {
    background: var(--agnes-bg-hover);
    color: var(--agnes-text);
}

.agnes-ai-action-btn .dashicons {
    font-size: 14px;
    width: 14px;
    height: 14px;
}

.agnes-ai-result-error {
    color: var(--agnes-danger);
    font-size: 13px;
}

/* ===================== 输入区 ===================== */
.agnes-ai-chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--agnes-border);
    background: var(--agnes-bg);
}

.agnes-ai-chat-input {
    width: 100%;
    min-height: 44px;
    max-height: 200px;
    padding: 12px 16px;
    border: 1px solid var(--agnes-border);
    border-radius: var(--agnes-radius-sm);
    font-size: 14px;
    font-family: var(--agnes-font);
    resize: none;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--agnes-bg);
    color: var(--agnes-text);
    line-height: 1.5;
}

.agnes-ai-chat-input:focus {
    border-color: var(--agnes-primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.agnes-ai-chat-input::placeholder {
    color: var(--agnes-text-light);
}

.agnes-ai-chat-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.agnes-ai-chat-toolbar .agnes-ai-btn {
    margin-left: auto;
}

/* ===================== 图像/视频表单 ===================== */
.agnes-ai-image-form,
.agnes-ai-video-form {
    padding: 24px;
    background: var(--agnes-bg);
}

.agnes-ai-prompt-input {
    width: 100%;
    min-height: 80px;
    padding: 12px 16px;
    border: 1px solid var(--agnes-border);
    border-radius: var(--agnes-radius-sm);
    font-size: 14px;
    font-family: var(--agnes-font);
    resize: vertical;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--agnes-bg);
    color: var(--agnes-text);
    line-height: 1.5;
}

.agnes-ai-prompt-input:focus {
    border-color: var(--agnes-primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

.agnes-ai-prompt-input::placeholder {
    color: var(--agnes-text-light);
}

.agnes-ai-image-options,
.agnes-ai-video-options {
    display: flex;
    gap: 12px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.agnes-ai-option-group {
    flex: 1;
    min-width: 120px;
}

.agnes-ai-option-group label {
    display: block;
    font-size: 13px;
    color: var(--agnes-text-muted);
    margin-bottom: 4px;
    font-weight: 500;
}

.agnes-ai-option-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--agnes-border);
    border-radius: var(--agnes-radius-xs);
    font-size: 14px;
    background: var(--agnes-bg);
    color: var(--agnes-text);
    cursor: pointer;
    outline: none;
}

.agnes-ai-option-group select:focus {
    border-color: var(--agnes-primary);
}

/* ===================== 上传区域 ===================== */
.agnes-ai-upload-area {
    margin-top: 12px;
}

.agnes-ai-preview-list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.agnes-ai-preview-item {
    position: relative;
    width: 72px;
    height: 72px;
    border-radius: var(--agnes-radius-xs);
    overflow: hidden;
    border: 2px solid var(--agnes-border);
}

.agnes-ai-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.agnes-ai-preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.agnes-ai-preview-remove:hover {
    background: var(--agnes-danger);
}

/* ===================== 结果区域 ===================== */
.agnes-ai-image-result,
.agnes-ai-video-result {
    padding: 0 24px 24px;
    background: var(--agnes-bg);
}

.agnes-ai-result-loading {
    text-align: center;
    padding: 40px 20px;
    color: var(--agnes-text-muted);
}

.agnes-ai-result-loading p {
    margin-top: 8px;
    font-size: 14px;
}

/* ===================== 图片结果卡片 ===================== */
.agnes-ai-image-card {
    border: 1px solid var(--agnes-border);
    border-radius: var(--agnes-radius-sm);
    overflow: hidden;
    box-shadow: var(--agnes-shadow);
    animation: agnes-fade-in 0.3s ease;
}

.agnes-ai-image-wrapper {
    width: 100%;
    background: var(--agnes-bg-alt);
    display: flex;
    justify-content: center;
}

.agnes-ai-image-wrapper img {
    max-width: 100%;
    height: auto;
    display: block;
}

.agnes-ai-image-meta {
    padding: 12px 16px;
    background: var(--agnes-bg);
}

.agnes-ai-image-prompt-text {
    font-size: 13px;
    color: var(--agnes-text-muted);
    margin-bottom: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agnes-ai-image-actions {
    display: flex;
    gap: 8px;
}

.agnes-ai-image-actions .agnes-ai-btn {
    padding: 6px 14px;
    font-size: 13px;
}

/* ===================== 视频结果卡片 ===================== */
.agnes-ai-video-card {
    border: 1px solid var(--agnes-border);
    border-radius: var(--agnes-radius-sm);
    overflow: hidden;
    box-shadow: var(--agnes-shadow);
    animation: agnes-fade-in 0.3s ease;
}

.agnes-ai-video-wrapper {
    width: 100%;
    background: #000;
}

.agnes-ai-video-wrapper video {
    width: 100%;
    display: block;
}

.agnes-ai-video-meta {
    padding: 12px 16px;
    background: var(--agnes-bg);
}

.agnes-ai-video-prompt-text {
    font-size: 13px;
    color: var(--agnes-text-muted);
    margin-bottom: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agnes-ai-video-actions {
    display: flex;
    gap: 8px;
}

.agnes-ai-video-actions .agnes-ai-btn {
    padding: 6px 14px;
    font-size: 13px;
}

/* ===================== 视频进度条 ===================== */
.agnes-ai-video-progress {
    padding: 30px 20px;
    text-align: center;
}

.agnes-ai-progress-bar {
    width: 100%;
    height: 8px;
    background: var(--agnes-bg-alt);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.agnes-ai-progress-fill {
    height: 100%;
    background: var(--agnes-primary-gradient);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.agnes-ai-progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--agnes-text-muted);
}

.agnes-ai-progress-status {
    font-weight: 500;
}

/* ===================== 错误提示 ===================== */
.agnes-ai-error-box {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    padding: 16px 20px;
    border-radius: var(--agnes-radius-sm);
    margin: 24px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.agnes-ai-error-box .dashicons {
    color: var(--agnes-danger);
    flex-shrink: 0;
}

/* ===================== 响应式 ===================== */
@media (max-width: 768px) {
    .agnes-ai-widget {
        margin: 16px 0;
        border-radius: 12px;
    }

    .agnes-ai-header {
        padding: 12px 16px;
        font-size: 15px;
    }

    .agnes-ai-chat-messages,
    .agnes-ai-image-form,
    .agnes-ai-video-form,
    .agnes-ai-image-result,
    .agnes-ai-video-result {
        padding: 16px;
    }

    .agnes-ai-chat-input-area {
        padding: 12px 16px;
    }

    .agnes-ai-image-options,
    .agnes-ai-video-options {
        flex-direction: column;
        align-items: stretch;
    }

    .agnes-ai-option-group {
        width: 100%;
    }

    .agnes-ai-message {
        max-width: 95%;
    }

    .agnes-ai-message-avatar {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }

    .agnes-ai-chat-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .agnes-ai-chat-toolbar .agnes-ai-btn {
        width: 100%;
        margin-left: 0;
    }

    .agnes-ai-image-actions,
    .agnes-ai-video-actions {
        flex-wrap: wrap;
    }
}

/* ===================== 工具类 ===================== */
.agnes-ai-hidden {
    display: none !important;
}

.agnes-ai-fade-in {
    animation: agnes-fade-in 0.3s ease;
}

/* ===================== 滚动条美化 ===================== */
.agnes-ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.agnes-ai-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.agnes-ai-chat-messages::-webkit-scrollbar-thumb {
    background: var(--agnes-border);
    border-radius: 3px;
}

.agnes-ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--agnes-text-light);
}
