/**
 * Frontend styles for Forerunner OpenAI ChatKit
 * Minimal styles that complement OpenAI's official ChatKit styling
 */

/* Wrapper and container */
.forerunner-chatkit-wrapper {
    width: 100%;
    margin: 20px 0;
}

.forerunner-chatkit-container {
    position: relative;
    width: 100%;
    min-height: 400px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Enhanced Loading Skeleton UI */
.forerunner-chatkit-loading-skeleton {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 400px;
    background: #ffffff;
    padding: 16px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Dark mode skeleton */
.forerunner-chatkit-container[data-theme="dark"] .forerunner-chatkit-loading-skeleton {
    background: #1a1a1a;
}

/* Skeleton Header */
.chatkit-skeleton-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e5e5e5;
    margin-bottom: 16px;
}

.forerunner-chatkit-container[data-theme="dark"] .chatkit-skeleton-header {
    border-bottom-color: #333;
}

.skeleton-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

.forerunner-chatkit-container[data-theme="dark"] .skeleton-circle {
    background: linear-gradient(90deg, #2a2a2a 25%, #333 50%, #2a2a2a 75%);
    background-size: 200% 100%;
}

.skeleton-text {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

.forerunner-chatkit-container[data-theme="dark"] .skeleton-text {
    background: linear-gradient(90deg, #2a2a2a 25%, #333 50%, #2a2a2a 75%);
    background-size: 200% 100%;
}

.skeleton-title {
    width: 120px;
}

.skeleton-short {
    width: 60%;
}

/* Skeleton Messages */
.chatkit-skeleton-messages {
    flex: 1;
    padding: 16px 0;
    overflow: hidden;
}

.skeleton-message {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    animation: fade-in 0.3s ease-in;
}

.skeleton-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

.forerunner-chatkit-container[data-theme="dark"] .skeleton-avatar {
    background: linear-gradient(90deg, #2a2a2a 25%, #333 50%, #2a2a2a 75%);
    background-size: 200% 100%;
}

.skeleton-bubble {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
    border-radius: 16px;
    background: #f5f5f5;
    max-width: 80%;
}

.forerunner-chatkit-container[data-theme="dark"] .skeleton-bubble {
    background: #2a2a2a;
}

/* Skeleton Input */
.chatkit-skeleton-input {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 16px;
    border-top: 1px solid #e5e5e5;
    background: #fafafa;
    border-radius: 0 0 8px 8px;
}

.forerunner-chatkit-container[data-theme="dark"] .chatkit-skeleton-input {
    border-top-color: #333;
    background: #1f1f1f;
}

.skeleton-input-field {
    flex: 1;
    height: 40px;
    border-radius: 20px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

.forerunner-chatkit-container[data-theme="dark"] .skeleton-input-field {
    background: linear-gradient(90deg, #2a2a2a 25%, #333 50%, #2a2a2a 75%);
    background-size: 200% 100%;
}

.skeleton-send-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    background: linear-gradient(90deg, #d0d0d0 25%, #c0c0c0 50%, #d0d0d0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

.forerunner-chatkit-container[data-theme="dark"] .skeleton-send-button {
    background: linear-gradient(90deg, #333 25%, #3a3a3a 50%, #333 75%);
    background-size: 200% 100%;
}

/* Loading Status */
.chatkit-loading-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    color: #666;
    font-size: 13px;
}

.forerunner-chatkit-container[data-theme="dark"] .chatkit-loading-status {
    color: #999;
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e0e0e0;
    border-top-color: #10a37f;
    border-radius: 50%;
    animation: chatkit-spin 0.8s linear infinite;
}

.forerunner-chatkit-container[data-theme="dark"] .loading-spinner {
    border-color: #333;
    border-top-color: #10a37f;
}

/* Animations */
@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

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

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

/* Legacy loading state (fallback) */
.forerunner-chatkit-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 400px;
    color: #666;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.forerunner-chatkit-loading::before {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-right: 10px;
    border: 2px solid #e0e0e0;
    border-top-color: #10a37f;
    border-radius: 50%;
    animation: chatkit-spin 1s linear infinite;
}

/* Error states */
.forerunner-chatkit-error {
    padding: 20px;
    background-color: #fff5f5;
    border: 1px solid #fed7d7;
    border-radius: 8px;
    color: #c53030;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    text-align: center;
}

.forerunner-chatkit-error h4 {
    margin: 0 0 12px 0;
    font-size: 16px;
    font-weight: 600;
}

.chatkit-reload-btn {
    margin-top: 16px;
    padding: 10px 20px;
    background: #10a37f;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    transition: background 0.2s ease;
}

.chatkit-reload-btn:hover {
    background: #0d8c6a;
}

/* Error Toast (non-intrusive notification) */
.chatkit-error-toast {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 20px;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    border-radius: 8px;
    font-size: 13px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    animation: toast-slide-up 0.3s ease-out;
    max-width: 90%;
    text-align: center;
}

.forerunner-chatkit-container[data-theme="dark"] .chatkit-error-toast {
    background: rgba(255, 255, 255, 0.9);
    color: #1a1a1a;
}

@keyframes toast-slide-up {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Floating chat launcher button */
.forerunner-chatkit-launcher {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #10a37f 0%, #0d8c6a 100%);
    border: none;
    box-shadow: 0 4px 12px rgba(16, 163, 127, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: all 0.3s ease;
    z-index: 999998;
}

.forerunner-chatkit-launcher:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(16, 163, 127, 0.5);
}

.forerunner-chatkit-launcher:active {
    transform: scale(0.95);
}

.forerunner-chatkit-launcher svg {
    width: 24px;
    height: 24px;
}

/* Floating chat modal */
.forerunner-chatkit-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    padding: 20px;
}

.forerunner-chatkit-modal.forerunner-chatkit-modal-open {
    display: flex;
}

.forerunner-chatkit-modal-content {
    width: 100%;
    max-width: 500px;
    height: 90vh;
    max-height: 700px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modal-slide-up 0.3s ease-out;
}

@keyframes modal-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.forerunner-chatkit-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: white;
    border-bottom: 1px solid #e5e5e5;
    flex-shrink: 0;
}

.forerunner-chatkit-modal-header h3 {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-weight: 600;
    font-size: 18px;
    color: #1a1a1a;
}

.forerunner-chatkit-modal-close {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 24px;
    line-height: 1;
    transition: all 0.2s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.forerunner-chatkit-modal-close:hover {
    background: #f5f5f5;
    color: #1a1a1a;
}

.forerunner-chatkit-modal .forerunner-chatkit-container {
    flex: 1;
    box-shadow: none;
    border-radius: 0;
    min-height: 0;
    margin: 0;
    overflow: hidden;
}

/* Legacy floating panel styles (kept for backwards compatibility) */
.forerunner-chatkit-floating {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
}

.forerunner-chatkit-panel {
    position: fixed;
    bottom: 100px;
    right: 20px;
    width: 400px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.forerunner-chatkit-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: white;
    border-bottom: 1px solid #e5e5e5;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-weight: 600;
    font-size: 16px;
    color: #1a1a1a;
}

.forerunner-chatkit-close {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    transition: all 0.2s ease;
}

.forerunner-chatkit-close:hover {
    background: #f5f5f5;
    color: #1a1a1a;
}

.forerunner-chatkit-panel .forerunner-chatkit-container {
    flex: 1;
    box-shadow: none;
    border-radius: 0;
}

/* Consent gate */
.forerunner-chatkit-consent {
    padding: 40px 20px;
    background: white;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 500px;
    margin: 20px auto;
}

.forerunner-chatkit-consent-content h3 {
    margin: 0 0 16px 0;
    font-size: 20px;
    font-weight: 600;
    color: #1a1a1a;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.forerunner-chatkit-consent-content p {
    margin: 0 0 16px 0;
    font-size: 14px;
    line-height: 1.6;
    color: #666;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.forerunner-chatkit-consent-content a {
    color: #10a37f;
    text-decoration: none;
}

.forerunner-chatkit-consent-content a:hover {
    text-decoration: underline;
}

.forerunner-chatkit-consent-accept {
    padding: 12px 24px;
    background: #10a37f;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.forerunner-chatkit-consent-accept:hover {
    background: #0d8c6a;
}

.forerunner-chatkit-consent-accept:active {
    transform: scale(0.98);
}

/* ChatKit instance - hide header when requested */
.hide-chatkit-header::part(header) {
    display: none !important;
}

/* Fallback: If ::part() doesn't work, try to hide via height adjustment */
.hide-chatkit-header {
    --chatkit-header-height: 0px;
}

/* Additional CSS variable overrides for hiding header */
openai-chatkit.hide-chatkit-header {
    --header-height: 0;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .forerunner-chatkit-modal-content {
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }
    
    .forerunner-chatkit-modal {
        padding: 0;
    }
    
    .forerunner-chatkit-panel {
        width: calc(100vw - 40px);
        height: calc(100vh - 140px);
    }
    
    .forerunner-chatkit-floating {
        bottom: 16px;
        right: 16px;
    }
    
    .forerunner-chatkit-launcher {
        width: 56px;
        height: 56px;
        bottom: 16px;
        right: 16px;
    }
    
    .forerunner-chatkit-launcher svg {
        width: 22px;
        height: 22px;
    }
}

