/* =================================================================================
   专利对话功能样式
   ================================================================================= */

/* 问一问按钮 */
.ask-patent-btn {
    padding: 5px 10px;
    font-size: 0.8em;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.3s;
    font-weight: 500;
    box-shadow: 0 2px 4px rgba(34, 197, 94, 0.2);
}

.ask-patent-btn:hover {
    background: var(--primary-color-dark);
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(34, 197, 94, 0.3);
}

.ask-patent-btn:active {
    transform: translateY(0);
}

.ask-patent-btn svg {
    width: 16px;
    height: 16px;
}

/* 专利卡片头部布局 */
.patent-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
}

.patent-card-header h5 {
    flex: 1;
    margin: 0;
}

/* 对话弹窗 - 可拖动悬浮窗 */
#patent_chat_modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10000;
    padding: 0;
}

.patent-chat-modal {
    background: white;
    border-radius: 12px;
    width: 800px;
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: modalSlideIn 0.3s ease-out;
    cursor: default;
    position: relative;
}

.patent-chat-modal.dragging {
    transition: none;
    user-select: none;
}

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

.patent-chat-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px;
    border-bottom: 2px solid var(--primary-color);
    background: var(--primary-color);
    color: white;
    border-radius: 12px 12px 0 0;
    cursor: move;
}

.patent-chat-modal .patent-info {
    flex: 1;
}

.patent-chat-modal .patent-chat-title {
    margin: 0 0 5px 0;
    font-size: 1.2em;
    font-weight: 600;
}

.patent-chat-modal .patent-chat-subtitle {
    margin: 0;
    font-size: 0.9em;
    opacity: 0.9;
    font-weight: 400;
}

.patent-chat-modal .close-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 1.5em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    flex-shrink: 0;
}

.patent-chat-modal .close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

.patent-chat-modal .modal-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 20px;
}

/* 对话历史区域 */
.chat-history {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 15px;
    min-height: 300px;
    width: 100%;
    box-sizing: border-box;
}

.chat-message {
    margin-bottom: 15px;
    animation: messageSlideIn 0.3s ease-out;
    max-width: 100%;
    box-sizing: border-box;
}

.chat-message.assistant-message {
    max-width: 100%;
}

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

.chat-message.user-message {
    text-align: right;
    display: flex;
    justify-content: flex-end;
}

.chat-message.user-message .message-content {
    background: var(--primary-color);
    color: white;
    margin-left: auto;
}

.chat-message.assistant-message .message-content {
    background: white;
    border: 1px solid #e0e0e0;
    max-width: 100%;
    width: fit-content;
    min-width: 100px;
}

.chat-message.system-message .message-content {
    background: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    font-size: 0.85em;
    color: #666;
}

.message-role {
    font-weight: 600;
}

.message-time {
    font-size: 0.9em;
    opacity: 0.7;
}

.message-content {
    display: inline-block;
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    box-sizing: border-box;
}

/* Markdown渲染样式 */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
}

.message-content h1 { font-size: 1.5em; }
.message-content h2 { font-size: 1.3em; }
.message-content h3 { font-size: 1.1em; }
.message-content h4 { font-size: 1em; }

.message-content p {
    margin: 8px 0;
}

.message-content ul,
.message-content ol {
    margin: 10px 0;
    padding-left: 24px;
}

.message-content li {
    margin: 5px 0;
}

.message-content code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message-content pre {
    background: #f6f8fa;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 10px 0;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 12px;
    margin: 10px 0;
    color: #666;
    font-style: italic;
}

.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    table-layout: fixed;
    max-width: 100%;
    display: block;
    overflow-x: auto;
}

.message-content table th,
.message-content table td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: break-word;
    hyphens: auto;
    min-width: 50px;
    max-width: 300px;
    vertical-align: top;
}

.message-content table th {
    background: #f6f8fa;
    font-weight: 600;
}

.message-content table thead,
.message-content table tbody {
    display: table;
    width: 100%;
    table-layout: fixed;
}

.message-content table tr {
    display: table-row;
}

.message-content a {
    color: var(--primary-color);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content strong {
    font-weight: 600;
}

.message-content em {
    font-style: italic;
}

.message-content hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 16px 0;
}

/* 流式输出光标动画 */
.blinking-cursor {
    animation: blink 1s infinite;
    font-weight: bold;
    color: var(--primary-color);
}

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

/* 加载动画 */
.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dots span {
    animation: dotPulse 1.4s infinite;
    font-size: 1.5em;
}

.loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dotPulse {
    0%, 60%, 100% {
        opacity: 0.3;
    }
    30% {
        opacity: 1;
    }
}

/* 输入区域 */
.chat-input-area {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input-area textarea {
    flex: 1;
    min-height: 60px;
    max-height: 150px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95em;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.3s;
}

.chat-input-area textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-input-area button {
    padding: 12px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 500;
    transition: all 0.3s;
    white-space: nowrap;
}

.chat-input-area button:hover:not(:disabled) {
    background: var(--primary-color-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(34, 197, 94, 0.3);
}

.chat-input-area button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 配置栏 - 服务商和模型选择 */
.chat-config-bar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 15px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 15px;
    border: 1px solid #e9ecef;
}

.chat-config-bar .config-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-config-bar label {
    font-size: 0.85em;
    color: #495057;
    min-width: 60px;
    font-weight: 500;
}

.chat-config-bar .provider-select,
.chat-config-bar .model-select {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #ced4da;
    border-radius: 5px;
    font-size: 0.85em;
    background: white;
    cursor: pointer;
    transition: all 0.3s;
}

.chat-config-bar .provider-select:focus,
.chat-config-bar .model-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.15);
}

/* 上下文选项样式 */
.chat-config-bar .context-options {
    flex-wrap: wrap;
}

.chat-config-bar .checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.85em;
    color: #495057;
    min-width: auto;
    font-weight: normal;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.chat-config-bar .checkbox-label:hover {
    background-color: rgba(34, 197, 94, 0.1);
}

.chat-config-bar .checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.chat-config-bar .context-info {
    font-size: 0.8em;
    color: #6c757d;
    background: #e9ecef;
    padding: 3px 8px;
    border-radius: 4px;
    margin-left: auto;
}

.chat-config-bar .context-info.warning {
    color: #856404;
    background: #fff3cd;
}

/* 深度思考按钮 - 与搜索按钮样式一致 */
.thinking-btn {
    position: relative;
    transition: all 0.2s ease;
}

.thinking-btn:hover {
    background: var(--primary-color-hover-bg);
    color: var(--primary-color);
}

.thinking-btn.active {
    background-color: var(--primary-color);
    color: white;
}

.thinking-btn.thinking-only {
    background-color: var(--warning-color);
    color: white;
    cursor: default;
}

.thinking-btn svg {
    width: 20px;
    height: 20px;
    transition: all 0.2s ease;
}

.thinking-btn.active svg {
    animation: pulse-glow 1.5s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% {
        filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.5));
    }
    50% {
        filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.8));
    }
}

/* 深度思考内容容器 */
.thinking-container {
    margin-bottom: 10px;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    overflow: hidden;
}

.thinking-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    cursor: pointer;
    font-size: 0.85em;
    color: #166534;
    transition: all 0.3s;
}

.thinking-header:hover {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%);
}

.thinking-header svg {
    width: 14px;
    height: 14px;
    color: #22C55E;
}

.thinking-title {
    font-weight: 500;
}

.thinking-toggle-icon {
    margin-left: auto;
    font-size: 0.8em;
    transition: transform 0.3s;
}

.thinking-content {
    padding: 12px;
    background: #f0fdf4;
    border-top: 1px solid #bbf7d0;
    font-size: 0.9em;
    color: #166534;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
}

.thinking-text {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.response-content {
    padding: 0;
}

/* 输入按钮组 */
.input-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-buttons .stop-btn {
    background: #e74c3c !important;
}

.input-buttons .stop-btn:hover {
    background: #c0392b !important;
}

/* 操作按钮组 */
.chat-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.chat-actions button {
    padding: 6px 12px;
    font-size: 0.85em;
    background: #6c757d !important;
    color: white !important;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s;
}

.chat-actions button:hover {
    background: #5a6268 !important;
    color: white !important;
}

/* 响应式设计 */
@media (max-width: 768px) {
    #patent_chat_modal {
        padding: 10px;
        /* 移动端保持居中 */
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
    }
    
    .patent-chat-modal {
        max-height: 90vh;
        border-radius: 8px;
        width: 95vw;
        /* 移动端禁用拖动 */
        cursor: default !important;
    }
    
    .patent-chat-modal .modal-header {
        padding: 15px;
        cursor: default !important;
    }
    
    .patent-chat-modal .patent-chat-title {
        font-size: 1em;
    }
    
    .patent-chat-modal .modal-body {
        padding: 15px;
    }
    
    .chat-history {
        min-height: 200px;
    }
    
    .message-content {
        max-width: 90%;
    }
    
    .chat-input-area {
        flex-direction: column;
    }
    
    .chat-input-area button {
        width: 100%;
    }
    
    .ask-patent-btn {
        font-size: 0.8em;
        padding: 5px 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .thinking-btn,
    .thinking-btn svg {
        animation: none !important;
        transition: none !important;
    }
}

/* 滚动条样式 */
.chat-history::-webkit-scrollbar {
    width: 8px;
}

.chat-history::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.chat-history::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.chat-history::-webkit-scrollbar-thumb:hover {
    background: #555;
}
