/**
 * 《绛唇解语花》AI 助手样式
 * AI Assistant Styles for Lips Aesthetics Book
 *
 * 优雅设计 - 与主题系统集成
 */

/* ========================================
   AI 触发按钮 - 优雅浮动按钮
   ======================================== */
.ai-trigger-btn {
    position: fixed;
    bottom: 170px;
    right: 30px;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.875rem 1.5rem;
    background: linear-gradient(135deg,
        var(--theme-primary, #B76E79) 0%,
        var(--theme-primary-light, #D4A5A5) 100%);
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 0.9375rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    cursor: pointer;
    box-shadow:
        0 4px 20px rgba(var(--theme-shadow-color, 183, 110, 121), 0.35),
        0 0 0 1px rgba(255, 255, 255, 0.1) inset;
    z-index: 997;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
}

.ai-trigger-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow:
        0 8px 32px rgba(var(--theme-shadow-color, 183, 110, 121), 0.45),
        0 0 0 1px rgba(255, 255, 255, 0.2) inset;
}

.ai-trigger-btn:active {
    transform: translateY(-1px) scale(0.98);
}

.ai-trigger-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 4px;
}

.ai-trigger-icon svg {
    width: 100%;
    height: 100%;
}

.ai-trigger-text {
    font-family: var(--font-sans);
}

/* ========================================
   AI 面板遮罩
   ======================================== */
.ai-assistant-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1998;
    opacity: 0;
    visibility: hidden;
    transition: all 0.35s ease;
}

.ai-assistant-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ========================================
   AI 面板主体
   ======================================== */
.ai-assistant-panel {
    position: fixed;
    top: 0;
    right: -480px;
    width: 450px;
    max-width: 100vw;
    height: 100vh;
    background: linear-gradient(180deg, #FDFBFB 0%, #F8F5F5 100%);
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.12);
    z-index: 1999;
    display: flex;
    flex-direction: column;
    transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.ai-assistant-panel.active {
    right: 0;
}

/* ========================================
   AI 面板头部 - 优雅渐变
   ======================================== */
.ai-panel-header {
    padding: 1.5rem;
    background: linear-gradient(135deg,
        var(--theme-primary, #B76E79) 0%,
        var(--theme-primary-light, #D4A5A5) 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

/* 装饰性背景 */
.ai-panel-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 200px;
    height: 200px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
    pointer-events: none;
}

.ai-panel-header::after {
    content: '';
    position: absolute;
    bottom: -60%;
    left: -10%;
    width: 150px;
    height: 150px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 50%;
    pointer-events: none;
}

.ai-panel-title {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 0.875rem;
    font-size: 1.1875rem;
    font-weight: 500;
    letter-spacing: 0.03em;
}

.ai-panel-title .ai-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border-radius: 10px;
    padding: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ai-panel-title .ai-icon svg {
    width: 100%;
    height: 100%;
}

.ai-panel-actions {
    position: relative;
    z-index: 1;
    display: flex;
    gap: 0.625rem;
}

.ai-settings-btn,
.ai-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    color: white;
    cursor: pointer;
    transition: all 0.25s ease;
}

.ai-settings-btn:hover,
.ai-close-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.ai-close-btn {
    font-size: 1.625rem;
    line-height: 1;
}

/* ========================================
   设置视图
   ======================================== */
.ai-settings-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 1.75rem;
}

.ai-settings-content h3 {
    font-size: 1.375rem;
    font-weight: 600;
    color: var(--text-dark, #3D3D3D);
    margin-bottom: 0.625rem;
    letter-spacing: 0.02em;
}

.ai-settings-desc {
    font-size: 0.9375rem;
    color: var(--text-medium, #6B6B6B);
    margin-bottom: 1.75rem;
    line-height: 1.7;
}

.ai-form-group {
    margin-bottom: 1.5rem;
}

.ai-form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-dark, #374151);
    margin-bottom: 0.625rem;
    letter-spacing: 0.01em;
}

.ai-select,
.ai-input {
    width: 100%;
    padding: 0.875rem 1.125rem;
    border: 2px solid var(--theme-border, #E8D5D5);
    border-radius: 12px;
    font-size: 0.9375rem;
    background: white;
    color: var(--text-dark, #1f2937);
    transition: all 0.25s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.ai-select:focus,
.ai-input:focus {
    outline: none;
    border-color: var(--theme-primary, #B76E79);
    box-shadow:
        0 0 0 4px rgba(var(--theme-shadow-color, 183, 110, 121), 0.1),
        0 2px 8px rgba(0, 0, 0, 0.04);
}

.ai-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.ai-input-wrapper .ai-input {
    padding-right: 3.5rem;
}

.ai-toggle-visibility {
    position: absolute;
    right: 0.875rem;
    padding: 0.5rem;
    background: none;
    border: none;
    color: var(--text-light, #9ca3af);
    cursor: pointer;
    transition: color 0.2s ease;
    border-radius: 6px;
}

.ai-toggle-visibility:hover {
    color: var(--theme-primary, #B76E79);
    background: rgba(var(--theme-shadow-color, 183, 110, 121), 0.08);
}

.ai-provider-link {
    margin-bottom: 1.75rem;
}

.ai-provider-link a {
    font-size: 0.875rem;
    color: var(--theme-primary, #B76E79);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    transition: all 0.2s ease;
}

.ai-provider-link a:hover {
    color: var(--theme-primary-dark, #8B5A5A);
}

.ai-settings-actions {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.ai-btn {
    flex: 1;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    border: none;
    letter-spacing: 0.02em;
}

.ai-btn-primary {
    background: linear-gradient(135deg,
        var(--theme-primary, #B76E79) 0%,
        var(--theme-primary-light, #D4A5A5) 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(var(--theme-shadow-color, 183, 110, 121), 0.25);
}

.ai-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(var(--theme-shadow-color, 183, 110, 121), 0.35);
}

.ai-btn-secondary {
    background: white;
    color: var(--theme-primary, #B76E79);
    border: 2px solid var(--theme-primary, #B76E79);
}

.ai-btn-secondary:hover {
    background: var(--theme-blush, #F5E6E8);
}

.ai-test-result {
    padding: 1rem 1.25rem;
    border-radius: 10px;
    font-size: 0.875rem;
    text-align: center;
    font-weight: 500;
}

.ai-test-success {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    color: #065f46;
}

.ai-test-error {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    color: #991b1b;
}

.ai-test-loading {
    background: linear-gradient(135deg, var(--theme-blush, #F5E6E8) 0%, var(--theme-nude, #E8D5D5) 100%);
    color: var(--theme-primary-dark, #8B5A5A);
}

/* ========================================
   聊天视图
   ======================================== */
.ai-chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: linear-gradient(180deg, #FDFBFB 0%, #F8F5F5 100%);
}

.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* 自定义滚动条 */
.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: var(--theme-nude, #E8D5D5);
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--theme-primary-light, #D4A5A5);
}

.ai-welcome-message,
.ai-message {
    display: flex;
    gap: 0.875rem;
    align-items: flex-start;
    animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-avatar {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 700;
    background: linear-gradient(135deg,
        var(--theme-primary, #B76E79) 0%,
        var(--theme-primary-light, #D4A5A5) 100%);
    color: white;
    box-shadow: 0 3px 12px rgba(var(--theme-shadow-color, 183, 110, 121), 0.25);
}

.ai-message-user .ai-avatar {
    background: linear-gradient(135deg,
        var(--theme-primary-dark, #8B5A5A) 0%,
        var(--theme-primary, #B76E79) 100%);
}

.ai-message-content {
    flex: 1;
    background: white;
    border-radius: 16px;
    padding: 1.125rem 1.25rem;
    box-shadow:
        0 2px 12px rgba(0, 0, 0, 0.06),
        0 0 0 1px rgba(0, 0, 0, 0.02);
    position: relative;
}

/* 消息气泡尖角 */
.ai-message-assistant .ai-message-content::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 14px;
    width: 12px;
    height: 12px;
    background: white;
    transform: rotate(45deg);
    box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.04);
}

.ai-message-user .ai-message-content {
    background: linear-gradient(135deg,
        var(--theme-primary, #B76E79) 0%,
        var(--theme-primary-light, #D4A5A5) 100%);
    color: white;
    box-shadow: 0 3px 15px rgba(var(--theme-shadow-color, 183, 110, 121), 0.2);
}

.ai-message-user .ai-message-content::before {
    display: none;
}

.ai-message-content p {
    margin: 0;
    line-height: 1.7;
    font-size: 0.9375rem;
}

.ai-message-content p + p {
    margin-top: 0.625rem;
}

/* ========================================
   AI Markdown 样式
   ======================================== */
.ai-message-content .ai-heading {
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--text-dark, #1a1a2e);
    margin: 1.125rem 0 0.625rem;
    padding-bottom: 0.375rem;
    border-bottom: 1px solid var(--theme-border, #E8D5D5);
}

.ai-message-content .ai-heading:first-child {
    margin-top: 0;
}

.ai-message-content h3.ai-heading {
    font-size: 1.125rem;
}

.ai-message-content h4.ai-heading {
    font-size: 1rem;
}

.ai-message-content strong {
    font-weight: 600;
    color: var(--theme-primary-dark, #8B5A5A);
}

.ai-message-content em {
    font-style: italic;
    color: var(--text-medium, #4b5563);
}

.ai-message-content .ai-code-block {
    background: linear-gradient(135deg, #1e1e2e 0%, #2d2d3f 100%);
    color: #cdd6f4;
    border-radius: 10px;
    padding: 1rem 1.25rem;
    margin: 0.875rem 0;
    overflow-x: auto;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.8125rem;
    line-height: 1.6;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.ai-message-content .ai-inline-code {
    background: var(--theme-blush, #F5E6E8);
    color: var(--theme-primary-dark, #8B5A5A);
    padding: 0.1875rem 0.5rem;
    border-radius: 5px;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 0.875em;
}

.ai-message-content .ai-list {
    margin: 0.625rem 0;
    padding-left: 1.75rem;
}

.ai-message-content .ai-list li {
    margin: 0.375rem 0;
    line-height: 1.7;
}

.ai-message-content ul.ai-list {
    list-style-type: disc;
}

.ai-message-content ul.ai-list li::marker {
    color: var(--theme-primary, #B76E79);
}

.ai-message-content ol.ai-list {
    list-style-type: decimal;
}

/* ========================================
   书籍内容链接样式
   ======================================== */
.ai-message-content .ai-book-link {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    background: linear-gradient(135deg,
        var(--theme-blush, #F5E6E8) 0%,
        var(--theme-nude, #E8D5D5) 100%);
    color: var(--theme-primary-dark, #8B5A5A);
    text-decoration: none;
    border-radius: 20px;
    font-size: 0.8125rem;
    font-weight: 500;
    margin: 0.25rem 0.25rem 0.25rem 0;
    transition: all 0.25s ease;
    border: 1px solid rgba(var(--theme-shadow-color, 183, 110, 121), 0.15);
}

.ai-message-content .ai-book-link:hover {
    background: linear-gradient(135deg,
        var(--theme-primary, #B76E79) 0%,
        var(--theme-primary-light, #D4A5A5) 100%);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(var(--theme-shadow-color, 183, 110, 121), 0.25);
}

.ai-message-content .ai-book-link::before {
    content: '📖';
    font-size: 0.75rem;
}

.ai-book-suggestions {
    margin-top: 1rem;
    padding-top: 0.875rem;
    border-top: 1px dashed var(--theme-border, #E8D5D5);
}

.ai-book-suggestions-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--theme-primary, #B76E79);
    margin-bottom: 0.625rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.ai-book-suggestions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.ai-message-error .ai-message-content {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    color: #991b1b;
    border: 1px solid #fca5a5;
}

/* ========================================
   打字指示器
   ======================================== */
.ai-typing-indicator {
    display: flex;
    gap: 5px;
    padding: 0.375rem 0;
}

.ai-typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--theme-primary-light, #D4A5A5);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.ai-typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ========================================
   输入区域
   ======================================== */
.ai-chat-input-area {
    padding: 1.25rem;
    background: white;
    border-top: 1px solid var(--theme-border, #E8D5D5);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.04);
}

.ai-quick-questions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.ai-quick-btn {
    padding: 0.5rem 1rem;
    background: var(--theme-blush, #F5E6E8);
    border: 1px solid transparent;
    border-radius: 20px;
    font-size: 0.8125rem;
    color: var(--theme-primary-dark, #8B5A5A);
    cursor: pointer;
    transition: all 0.25s ease;
    font-weight: 500;
}

.ai-quick-btn:hover {
    background: var(--theme-nude, #E8D5D5);
    color: var(--theme-primary-dark, #8B5A5A);
    border-color: var(--theme-primary-light, #D4A5A5);
    transform: translateY(-1px);
}

.ai-input-container {
    display: flex;
    gap: 0.875rem;
    align-items: flex-end;
}

.ai-chat-input {
    flex: 1;
    padding: 1rem 1.125rem;
    border: 2px solid var(--theme-border, #E8D5D5);
    border-radius: 14px;
    font-size: 0.9375rem;
    resize: none;
    max-height: 120px;
    line-height: 1.6;
    transition: all 0.25s ease;
    background: #FDFBFB;
}

.ai-chat-input:focus {
    outline: none;
    border-color: var(--theme-primary, #B76E79);
    background: white;
    box-shadow: 0 0 0 4px rgba(var(--theme-shadow-color, 183, 110, 121), 0.1);
}

.ai-chat-input::placeholder {
    color: var(--text-light, #9B9B9B);
}

.ai-send-btn {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg,
        var(--theme-primary, #B76E79) 0%,
        var(--theme-primary-light, #D4A5A5) 100%);
    border: none;
    border-radius: 14px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
    box-shadow: 0 4px 15px rgba(var(--theme-shadow-color, 183, 110, 121), 0.3);
}

.ai-send-btn:hover:not(:disabled) {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 20px rgba(var(--theme-shadow-color, 183, 110, 121), 0.4);
}

.ai-send-btn:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
}

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

/* ========================================
   响应式设计
   ======================================== */
@media (max-width: 768px) {
    .ai-assistant-panel {
        width: 100%;
        right: -100%;
    }

    .ai-trigger-btn {
        bottom: 140px;
        right: 20px;
    }

    .ai-trigger-text {
        display: none;
    }

    .ai-trigger-btn {
        border-radius: 50%;
        width: 56px;
        height: 56px;
        padding: 0;
        justify-content: center;
    }

    .ai-trigger-icon {
        width: 32px;
        height: 32px;
        padding: 5px;
    }

    .ai-chat-messages {
        padding: 1rem;
    }

    .ai-message-content {
        padding: 1rem;
    }

    .ai-quick-questions {
        gap: 0.375rem;
    }

    .ai-quick-btn {
        padding: 0.4375rem 0.875rem;
        font-size: 0.75rem;
    }
}

/* ========================================
   打印样式
   ======================================== */
@media print {
    .ai-assistant-panel,
    .ai-assistant-overlay,
    .ai-trigger-btn {
        display: none !important;
    }
}
