/**
 * Claude AI Chatbot - Custom Styles for Hyvä Theme
 * Scoped CSS - All styles prefixed with .claude-chatbot to avoid conflicts
 * Minimal CSS - Most styling via Tailwind classes from Hyvä
 */

/* Base Container - Fixed positioning */
.claude-chatbot {
    position: fixed;
    z-index: 9999;
}

.claude-chatbot.chatbot-bottom-right { bottom: 20px; right: 20px; }
.claude-chatbot.chatbot-bottom-left { bottom: 20px; left: 20px; }
.claude-chatbot.chatbot-top-right { top: 20px; right: 20px; }
.claude-chatbot.chatbot-top-left { top: 20px; left: 20px; }

/* Chat Toggle Button */
.claude-chatbot .chatbot-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid white;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Attention pulse ring – pure CSS, toggled via Alpine :class */
.claude-chatbot .chatbot-toggle.attention-pulse {
    animation: chatbot-pulse 1.5s ease-in-out 3;
}

@keyframes chatbot-pulse {
    0%, 100% {
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(255, 255, 255, 0.4), 0 0 24px rgba(102, 126, 234, 0.5);
        transform: scale(1.12);
    }
}

.claude-chatbot .chatbot-toggle:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.claude-chatbot .chatbot-toggle .icon {
    width: 24px;
    height: 24px;
}

.claude-chatbot .chatbot-toggle .notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}

/* Chat Window */
.claude-chatbot .chatbot-window {
    position: absolute;
    bottom: 80px; /* Above the button */
    right: 0;
    width: 400px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 100px);
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    display: flex; /* CRITICAL: Enable flexbox layout */
    flex-direction: column;
    overflow: hidden;
    overflow-x: hidden; /* Prevent horizontal scroll */
}

/* Ensure window displays as flex when shown */
.claude-chatbot .chatbot-window[style*="display: flex"] {
    display: flex !important;
}

/* Header */
.claude-chatbot .chatbot-header {
    padding: 16px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.claude-chatbot .avatar-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.claude-chatbot .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.claude-chatbot .status-indicator {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
}

.claude-chatbot .status-indicator.online {
    background: #10b981;
}

.claude-chatbot .status-indicator.offline {
    background: #6b7280;
}

.claude-chatbot .header-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.claude-chatbot .header-status {
    font-size: 13px;
    opacity: 0.9;
    margin: 0;
}

.claude-chatbot .header-button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.claude-chatbot .header-button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Content Area */
.claude-chatbot .chatbot-content {
    flex: 1;
    min-height: 0; /* Critical: allows flex to constrain height */
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #f9fafb;
}

.claude-chatbot .view-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* Conversation view should not scroll - let chatbot-messages handle it */
.claude-chatbot .view-container.conversation-view {
    overflow: hidden;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Critical: allows flex to constrain height */
}

/* Welcome View */
.claude-chatbot .welcome-content {
    text-align: center;
    max-width: 350px;
    margin: 0 auto;
}

.claude-chatbot .welcome-icon {
    color: #667eea;
    margin-bottom: 16px;
}

.claude-chatbot .welcome-title {
    font-size: 24px;
    font-weight: bold;
    color: #111827;
    margin-bottom: 8px;
}

.claude-chatbot .welcome-text {
    color: #6b7280;
    margin-bottom: 24px;
}

.claude-chatbot .action-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.claude-chatbot .back-button,
.claude-chatbot .back-button-small {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    font-weight: 500;
}

/* Help Topics */
.claude-chatbot .section-title {
    font-size: 20px;
    font-weight: bold;
    color: #111827;
    margin-bottom: 8px;
}

.claude-chatbot .section-description {
    color: #6b7280;
    margin-bottom: 20px;
}

.claude-chatbot .topics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
    max-height: 400px; /* Limit height, allow scrolling */
    overflow-y: auto;
}

.claude-chatbot .topic-card {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.claude-chatbot .divider {
    text-align: center;
    color: #9ca3af;
    margin: 16px 0;
    position: relative;
}

.claude-chatbot .divider::before,
.claude-chatbot .divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: #e5e7eb;
}

.claude-chatbot .divider::before { left: 0; }
.claude-chatbot .divider::after { right: 0; }

/* Messages */
.claude-chatbot .chatbot-messages {
    flex: 1;
    min-height: 0; /* Critical: allows flex to constrain height */
    overflow-y: auto;
    overflow-x: hidden; /* No horizontal scroll */
    padding: 16px;
}

.claude-chatbot .date-separator {
    text-align: center;
    color: #6b7280;
    font-size: 12px;
    margin: 16px 0;
}

.claude-chatbot .message-wrapper {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.claude-chatbot .message-bot {
    justify-content: flex-start;
}

.claude-chatbot .message-user {
    justify-content: flex-end;
}

.claude-chatbot .message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.claude-chatbot .message-bubble-wrapper {
    max-width: 70%;
}

.claude-chatbot .message-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

.claude-chatbot .message-content {
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
}

.claude-chatbot .message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    font-size: 11px;
    color: #9ca3af;
}

.claude-chatbot .message-actions {
    display: flex;
    flex-wrap: wrap; /* Allow wrapping to multiple lines */
    gap: 8px;
    margin-top: 8px;
    max-height: 200px; /* Limit height, allow scrolling */
    overflow-y: auto;
}

.claude-chatbot .action-button {
    background: #f3f4f6;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: left;
}

.claude-chatbot .action-button.with-image {
    padding: 8px;
}

.claude-chatbot .action-button:hover {
    background: #e5e7eb;
}

.claude-chatbot .action-image {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.claude-chatbot .action-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.claude-chatbot .action-label {
    font-size: 13px;
    line-height: 1.4;
    word-wrap: break-word;
}

.claude-chatbot .action-price {
    font-size: 12px;
    font-weight: 600;
    color: #059669;
}

.claude-chatbot .retry-button {
    background: transparent;
    border: none;
    color: #667eea;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    padding: 4px;
}

.claude-chatbot .retry-button:hover {
    color: #764ba2;
}

.claude-chatbot .scroll-to-bottom {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Input - Fixed at bottom */
.claude-chatbot .offline-contact-bar {
    background: #fef3c7;
    border-top: 1px solid #f59e0b;
    padding: 12px 16px;
    flex-shrink: 0;
    text-align: center;
}

.claude-chatbot .offline-contact-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.claude-chatbot .offline-contact-buttons .btn-sm {
    font-size: 13px;
    padding: 8px 14px;
    display: inline-flex;
    align-items: center;
}

.claude-chatbot .chatbot-input-wrapper {
    background: white;
    border-top: 1px solid #e5e7eb;
    padding: 16px;
    flex-shrink: 0;
}

.claude-chatbot .quick-replies {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    overflow-x: auto;
}

.claude-chatbot .quick-reply-button {
    background: #f3f4f6;
    border: none;
    padding: 8px 16px;
    border-radius: 16px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}

.claude-chatbot .quick-reply-button:hover {
    background: #e5e7eb;
}

.claude-chatbot .input-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.claude-chatbot .char-counter {
    font-size: 12px;
    color: #6b7280;
}

.claude-chatbot .powered-by {
    text-align: center;
    font-size: 11px;
    color: #9ca3af;
    margin-top: 8px;
}

/* Forms - Scoped to chatbot only */
.claude-chatbot .offline-form {
    margin-bottom: 16px;
}

.claude-chatbot .offline-form .form-submit-sticky {
    position: sticky;
    bottom: 0;
    background: white;
    padding: 12px 0 0;
    z-index: 1;
}

.claude-chatbot .form-group {
    margin-bottom: 16px;
}

.claude-chatbot .form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 6px;
}

.claude-chatbot .required {
    color: #ef4444;
}

.claude-chatbot .form-input {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
}

.claude-chatbot .form-input:focus {
    outline: none;
    border-color: #667eea;
}

.claude-chatbot .char-counter-bottom {
    text-align: right;
    font-size: 12px;
    color: #9ca3af;
    margin-top: 4px;
}

/* Success/Offline Views */
.claude-chatbot .success-content,
.claude-chatbot .leave-message-content {
    text-align: center;
    max-width: 350px;
    margin: 0 auto;
}

.claude-chatbot .success-icon,
.claude-chatbot .offline-icon {
    color: #10b981;
    margin-bottom: 16px;
}

.claude-chatbot .offline-icon {
    color: #6b7280;
}

.claude-chatbot .success-title {
    font-size: 22px;
    font-weight: bold;
    color: #111827;
    margin-bottom: 8px;
}

.claude-chatbot .success-text {
    color: #6b7280;
    margin-bottom: 24px;
}

.claude-chatbot .success-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Glassmorphism Effect - Scoped */
.claude-chatbot .avatar,
.claude-chatbot .header-button {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Typing Indicator Animation */
.claude-chatbot .typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
}

.claude-chatbot .typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.claude-chatbot .typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.claude-chatbot .typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing-bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Custom Scrollbar - Scoped */
.claude-chatbot .chatbot-messages::-webkit-scrollbar,
.claude-chatbot .view-container::-webkit-scrollbar {
    width: 6px;
}

.claude-chatbot .chatbot-messages::-webkit-scrollbar-track,
.claude-chatbot .view-container::-webkit-scrollbar-track {
    background: transparent;
}

.claude-chatbot .chatbot-messages::-webkit-scrollbar-thumb,
.claude-chatbot .view-container::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.claude-chatbot .chatbot-messages::-webkit-scrollbar-thumb:hover,
.claude-chatbot .view-container::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Message links - Scoped */
.claude-chatbot .message-link {
    text-decoration: underline;
    color: inherit;
    word-break: break-all; /* Break long URLs */
    overflow-wrap: break-word;
}

/* ========================================
   OPTIMIZED PRODUCT GRID
   ======================================== */

/* Product Grid Container */
.claude-chatbot .product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 0.75rem;
}

/* Product Card */
.claude-chatbot .product-card {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

.claude-chatbot .product-card:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Product Image */
.claude-chatbot .product-image {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-bottom: 1px solid #e5e7eb;
}

/* Product Info */
.claude-chatbot .product-info {
    padding: 0.75rem;
}

.claude-chatbot .product-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: #1f2937;
    margin: 0 0 0.5rem 0;
    line-height: 1.25;
    max-height: 2.5rem;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.claude-chatbot .product-price {
    font-size: 1rem;
    font-weight: 700;
    color: #059669;
    margin: 0;
}

.claude-chatbot .product-old-price {
    text-decoration: line-through;
    color: #9ca3af;
    font-weight: 400;
    font-size: 0.85rem;
    margin-right: 4px;
}

.claude-chatbot .product-sale-price {
    color: #dc2626;
}

/* Product Actions Grid (Combined View + Cart buttons) */
.claude-chatbot .product-actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    border-top: 1px solid #e5e7eb;
}

/* Product Action Buttons */
.claude-chatbot .product-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    background: white;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.claude-chatbot .product-action-btn:first-child {
    border-right: 1px solid #e5e7eb;
}

.claude-chatbot .product-action-btn:hover {
    background: #f3f4f6;
}

/* View Button */
.claude-chatbot .product-action-btn.view-btn {
    color: #3b82f6;
}

.claude-chatbot .product-action-btn.view-btn:hover {
    background: #dbeafe;
    color: #2563eb;
}

/* Cart Button */
.claude-chatbot .product-action-btn.cart-btn {
    color: #059669;
}

.claude-chatbot .product-action-btn.cart-btn:hover {
    background: #d1fae5;
    color: #047857;
}

/* Other Actions (non-product actions) */
.claude-chatbot .other-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

/* ── Token Usage Badges ───────────────────────────────────────── */

/* Session total – shown in chat header next to the action buttons */
.claude-chatbot .session-token-badge {
    display: flex;
    align-items: center;
    gap: 3px;
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.9);
    border-radius: 999px;
    padding: 2px 7px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: default;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Per-message token count – shown in message-meta below bot bubbles */
.claude-chatbot .message-token-badge {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    color: #b0b7c3;
    font-size: 10px;
    cursor: default;
    white-space: nowrap;
}

/* Responsive Design */
@media (max-width: 640px) {
    .claude-chatbot .product-grid {
        grid-template-columns: 1fr;
    }

    .claude-chatbot .product-actions-grid {
        grid-template-columns: 1fr;
    }

    .claude-chatbot .product-action-btn:first-child {
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
    }

    /* Mobile button: move up to avoid cookie bar / Trusted Shops badge overlap */
    .claude-chatbot.chatbot-bottom-right { bottom: 72px; right: 12px; }
    .claude-chatbot.chatbot-bottom-left  { bottom: 72px; left: 12px; }

    /* Mobile chat window: full viewport width, fixed so it's not clipped */
    .claude-chatbot .chatbot-window {
        position: fixed;
        left: 8px;
        right: 8px;
        bottom: 148px; /* 72px container + 60px button + 16px gap */
        top: 8px;
        width: auto;
        max-width: none;
        height: auto;
        max-height: none;
        border-radius: 12px;
    }
}

/* ========================================
   TRANSITIONS & ANIMATIONS
   ======================================== */

/* Smooth CSS transition for chatbot window close (no Alpine.js conflicts) */
.claude-chatbot .chatbot-window-transition {
    transition: opacity 150ms ease-in, transform 150ms ease-in;
}

/* Scroll to bottom button - smooth CSS transition instead of Alpine x-transition */
.claude-chatbot .scroll-to-bottom {
    transition: opacity 200ms ease-in-out, transform 200ms ease-in-out;
}

/* Alpine.js x-cloak */
[x-cloak] {
    display: none !important;
}
