/**
 * AI 解题模块样式
 */

/* AI解题模态框背景 */
.ai-solver-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    animation: fadeIn 0.3s ease;
}

.ai-solver-modal.show {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* AI解题内容容器 */
.ai-solver-content {
    background: #ffffff;
    border-radius: 16px;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    animation: slideUp 0.3s ease;
    display: flex;
    flex-direction: column;
}

/* 流式渲染光标效果 */
@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.streaming-cursor::after {
    content: '▊';
    animation: blink 1s infinite;
    margin-left: 2px;
    color: #4285f4;
}

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

/* AI解题头部 */
.ai-solver-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.ai-solver-title {
    font-size: 20px;
    font-weight: 700;
    color: #1f2937;
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-solver-close {
    width: 36px;
    height: 36px;
    border: none;
    background: #f3f4f6;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #6b7280;
    transition: all 0.2s ease;
}

.ai-solver-close:hover {
    background: #e5e7eb;
    color: #1f2937;
}

/* AI解题主体区域 */
.ai-solver-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

/* 输入区域 */
.ai-input-group {
    margin-bottom: 16px;
}

.ai-input-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 8px;
}

.ai-input-textarea {
    width: 100%;
    min-height: 80px;
    padding: 12px;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    font-size: 16px;
    font-family: inherit;
    resize: vertical;
    transition: all 0.2s ease;
}

.ai-input-textarea:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.ai-input-textarea::placeholder {
    color: #9ca3af;
}

/* 图片上传区域 */
.ai-image-section {
    margin-bottom: 16px;
}

.ai-camera-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.ai-btn-camera {
    padding: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #ffffff;
    color: #1f2937;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.ai-btn-camera:hover {
    background: #f9fafb;
    border-color: #6366f1;
}

.ai-btn-camera.primary {
    background: linear-gradient(135deg, #6366f1 0%, #818cf8 100%);
    color: white;
    border-color: #6366f1;
}

.ai-btn-camera.primary:hover {
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
}

.ai-btn-camera .icon {
    font-size: 24px;
}

.ai-upload-area {
    display: none;
}

.ai-upload-area input[type="file"] {
    display: none;
}

/* 图片预览 */
.ai-image-preview {
    margin-top: 16px;
    display: none;
}

.ai-image-preview.show {
    display: block;
}

.ai-preview-container {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    background: #f0f0f0;
    max-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-preview-image {
    max-width: 100%;
    max-height: 200px;
    width: auto;
    height: auto;
    display: block;
    border-radius: 12px;
}

.ai-btn-remove-preview {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    line-height: 1;
    transition: all 0.2s ease;
    z-index: 10;
}

.ai-btn-remove-preview:hover {
    background: rgba(0, 0, 0, 0.8);
}

/* 裁剪模态框 */
.ai-crop-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 10001;
}

.ai-crop-modal.show {
    display: block !important;
}

.ai-crop-canvas-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    touch-action: pan-x pan-y pinch-zoom;
    position: relative;
}

.ai-crop-image {
    max-width: none;
    max-height: none;
    touch-action: none;
    cursor: crosshair;
}

.ai-crop-overlay {
    position: absolute;
    border: 3px solid #6366f1;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.65),
                0 0 20px rgba(99, 102, 241, 0.4),
                inset 0 0 0 1px rgba(255, 255, 255, 0.3);
    pointer-events: none;
    z-index: 10;
}

.ai-crop-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.ai-crop-grid-line {
    position: absolute;
    background: rgba(255, 255, 255, 0.4);
}

.ai-crop-grid-line.vertical {
    width: 1px;
    height: 100%;
    top: 0;
}

.ai-crop-grid-line.horizontal {
    width: 100%;
    height: 1px;
    left: 0;
}

.ai-crop-handle {
    position: absolute;
    z-index: 15;
    touch-action: none;
}

.ai-crop-handle.corner {
    width: 56px;
    height: 56px;
    margin: -28px 0 0 -28px;
    cursor: move;
}

.ai-crop-handle.corner::before {
    content: '';
    position: absolute;
    width: 32px;
    height: 32px;
    background: #6366f1;
    border: 4px solid white;
    border-radius: 50%;
    box-shadow: 0 3px 16px rgba(0, 0, 0, 0.5);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.2s ease;
}

.ai-crop-handle.corner:active::before {
    transform: translate(-50%, -50%) scale(1.2);
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.7);
}

.ai-crop-handle.edge {
    cursor: move;
}

.ai-crop-handle.edge::before {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.95);
    border: 3px solid #6366f1;
    border-radius: 20px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.4);
    transition: all 0.2s ease;
}

.ai-crop-handle.edge:active::before {
    background: #6366f1;
    transform: scale(1.15);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

.ai-crop-handle.top, .ai-crop-handle.bottom {
    width: 80px;
    height: 44px;
    margin: -22px 0 0 -40px;
    cursor: ns-resize;
}

.ai-crop-handle.top::before, .ai-crop-handle.bottom::before {
    width: 60px;
    height: 8px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.ai-crop-handle.left, .ai-crop-handle.right {
    width: 44px;
    height: 80px;
    margin: -40px 0 0 -22px;
    cursor: ew-resize;
}

.ai-crop-handle.left::before, .ai-crop-handle.right::before {
    width: 8px;
    height: 60px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.ai-btn-crop-cancel {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 44px;
    height: 44px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    transition: all 0.2s ease;
    z-index: 20;
}

.ai-btn-crop-cancel:hover {
    background: rgba(0, 0, 0, 0.8);
}

.ai-btn-crop-confirm {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #6366f1, #818cf8);
    backdrop-filter: blur(10px);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    transition: all 0.2s ease;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.5);
    z-index: 20;
}

.ai-btn-crop-confirm:hover {
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

/* 错误提示 */
.ai-error {
    display: none;
    padding: 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 10px;
    color: #991b1b;
    font-size: 14px;
    margin-bottom: 16px;
}

.ai-error.show {
    display: block;
}

/* 提交按钮 */
.ai-btn-submit {
    width: 100%;
    padding: 14px;
    border: none;
    background: linear-gradient(135deg, #6366f1 0%, #818cf8 100%);
    color: white;
    font-size: 16px;
    font-weight: 700;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.ai-btn-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

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

.ai-btn-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 加载状态 */
.ai-loading {
    text-align: center;
    padding: 24px;
    display: none;
}

.ai-loading.show {
    display: block;
}

.ai-spinner {
    width: 36px;
    height: 36px;
    margin: 0 auto 12px;
    border: 3px solid #e5e7eb;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.ai-loading-text {
    color: #6b7280;
    font-size: 14px;
}

/* 答案卡片 */
.ai-answer-card {
    display: none;
    animation: slideUp 0.4s ease;
}

.ai-answer-card.show {
    display: block;
}

.ai-answer-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid #e5e7eb;
}

.ai-answer-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #6366f1 0%, #818cf8 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-answer-title {
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
    flex: 1;
}

.ai-btn-view-md {
    padding: 8px 16px;
    background: linear-gradient(135deg, #6366f1 0%, #818cf8 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-btn-view-md:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.ai-answer-content {
    color: #1f2937;
    font-size: 15px;
    line-height: 1.8;
    word-wrap: break-word;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .ai-solver-content {
        width: 95%;
        max-height: 95vh;
    }

    .ai-solver-header {
        padding: 16px;
    }

    .ai-solver-body {
        padding: 16px;
    }

    .ai-solver-title {
        font-size: 18px;
    }
}
