/**
 * AI Features Styles
 * 
 * 樣式表包含 AI Prompt 分析和商品爬蟲功能
 * 
 * @author iShowPlay Team
 * @version 1.0.0
 * @date 2025-09-09
 */

/* ===========================
   AI Prompt 分析區塊
   =========================== */

.ai-section {
    margin: 2rem auto;
    max-width: 1200px;
    padding: 0 1rem;
}

.ai-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.ai-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.ai-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.ai-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4caf50;
    animation: pulse 2s infinite;
}

.status-indicator.processing {
    background: #ff9800;
    animation: pulse 1s infinite;
}

.status-indicator.error {
    background: #f44336;
    animation: none;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
    }
}

.status-text {
    font-size: 0.875rem;
}

/* AI 對話區域 */
.ai-conversation {
    max-height: 500px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    background: #f8f9fa;
    -webkit-overflow-scrolling: touch; /* iOS 平滑滾動 */
}

.conversation-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    display: flex;
    gap: 1rem;
    animation: fadeIn 0.3s ease-in;
}

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

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.message.ai .message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.message.user .message-avatar {
    background: #e3f2fd;
    color: #2196f3;
}

.message-content {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.message.user .message-content {
    background: #2196f3;
    color: white;
}

.message-text {
    margin: 0;
    line-height: 1.5;
}

.typing-indicator {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* AI 輸入區域 */
.ai-input-area {
    padding: 1rem;
    border-top: 1px solid #e0e0e0;
    background: white;
}

.ai-input-wrapper {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.ai-message-input {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    resize: none;
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.3s;
}

.ai-message-input:focus {
    outline: none;
    border-color: #667eea;
}

.ai-send-btn {
    padding: 0.75rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s;
}

.ai-send-btn:hover {
    transform: scale(1.05);
}

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

/* AI 控制按鈕 */
.ai-controls {
    padding: 1rem;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.ai-controls .btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s;
}

.ai-controls .btn-primary {
    background: #2196f3;
    color: white;
}

.ai-controls .btn-secondary {
    background: #6c757d;
    color: white;
}

.ai-controls .btn-success {
    background: #4caf50;
    color: white;
}

.ai-controls .btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* 平台預覽 */
.platform-preview {
    padding: 1rem;
    border-top: 1px solid #e0e0e0;
    background: #f8f9fa;
}

.platform-preview h4 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    color: #333;
}

.selected-platforms {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.platform-chip {
    padding: 0.5rem 1rem;
    background: white;
    border-radius: 20px;
    border: 1px solid #ddd;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.platform-chip .platform-icon {
    width: 20px;
    height: 20px;
}

/* 商品預覽 */
.products-preview {
    padding: 1rem;
    border-top: 1px solid #e0e0e0;
    background: white;
}

.products-preview h4 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    color: #333;
}

.product-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.product-card {
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.3s;
    background: white;
}

.product-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.product-image {
    position: relative;
    height: 150px;
    background: #f5f5f5;
}

.product-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-platform {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

.product-info {
    padding: 1rem;
}

.product-title {
    margin: 0 0 0.5rem 0;
    font-size: 0.9rem;
    font-weight: 500;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-price {
    color: #e74c3c;
    font-size: 1.1rem;
    font-weight: bold;
    margin: 0 0 0.5rem 0;
}

.product-actions {
    display: flex;
    gap: 0.5rem;
}

.product-actions .btn {
    flex: 1;
    padding: 0.4rem;
    font-size: 0.8rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
}

/* ===========================
   商品爬蟲區塊
   =========================== */

.crawler-section {
    margin: 2rem auto;
    max-width: 1200px;
    padding: 0 1rem;
}

.crawler-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px 8px 0 0;
}

.crawler-header h3 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.crawler-header .badge {
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: normal;
}

.badge-secondary {
    background: #6c757d;
}

.badge-warning {
    background: #ff9800;
}

.badge-success {
    background: #4caf50;
}

.badge-danger {
    background: #f44336;
}

.badge-info {
    background: #2196f3;
}

.crawler-actions {
    display: flex;
    gap: 0.5rem;
}

.crawler-actions .btn {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.3s;
}

.crawler-actions .btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* 爬蟲輸入區 */
.crawler-input-area {
    padding: 1.5rem;
    background: white;
    border: 1px solid #e0e0e0;
    border-top: none;
}

.url-textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    resize: vertical;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.url-preview {
    margin-top: 1rem;
}

.url-list h5 {
    margin: 0 0 1rem 0;
    color: #333;
}

.url-list .list-group {
    list-style: none;
    padding: 0;
    margin: 0;
}

.url-list .list-group-item {
    padding: 0.75rem;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    margin-bottom: 0.5rem;
    border-radius: 6px;
}

.url-text {
    font-size: 0.875rem;
    color: #495057;
}

.remove-url {
    background: transparent;
    border: none;
    color: #dc3545;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
}

.crawler-controls {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* 爬蟲進度條 */
.crawler-progress {
    padding: 1.5rem;
    background: white;
    border: 1px solid #e0e0e0;
    border-top: none;
}

.progress {
    height: 24px;
    background: #e9ecef;
    border-radius: 12px;
    overflow: hidden;
}

.progress-bar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.875rem;
    transition: width 0.3s ease;
}

.crawling-status {
    text-align: center;
}

#crawling-status-text {
    color: #6c757d;
}

/* 爬蟲結果 */
.crawler-results {
    background: white;
    border: 1px solid #e0e0e0;
    border-top: none;
    border-radius: 0 0 8px 8px;
}

.nav-tabs {
    border-bottom: 1px solid #dee2e6;
    display: flex;
    padding: 0 1rem;
    margin: 0;
}

.nav-link {
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: #6c757d;
    cursor: pointer;
    position: relative;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link.active {
    color: #667eea;
}

.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: #667eea;
}

.tab-content {
    padding: 1rem;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.failed-list,
.processing-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.failed-item {
    padding: 1rem;
    border-radius: 6px;
}

.retry-failed-crawl {
    white-space: nowrap;
}

/* 通知樣式 */
.crawler-notifications {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.crawler-notification {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-danger {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

.alert-info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* AI 通知樣式 */
.ai-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 8px;
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 9999;
    transform: translateX(400px);
    transition: transform 0.3s ease-out, opacity 0.3s ease-out;
    pointer-events: none;
    opacity: 0;
}

.ai-notification.show {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

.ai-notification.notification-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.ai-notification.notification-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.ai-notification.notification-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

.ai-notification.notification-info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

.notification-icon {
    font-size: 18px;
    line-height: 1;
}

.notification-message {
    font-size: 14px;
    line-height: 1.4;
}

/* 響應式設計 */
@media (max-width: 768px) {
    .ai-section,
    .crawler-section {
        margin: 1rem auto;
    }

    .message-content {
        max-width: 85%;
    }

    .ai-controls {
        flex-direction: column;
    }

    .ai-controls .btn {
        width: 100%;
    }

    .product-cards,
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .crawler-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .crawler-actions {
        width: 100%;
        justify-content: center;
    }
}