/**
 * 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;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    /* Background color set via inline style from settings - no default here */
    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;
}

/* Custom size variants for launcher */
.forerunner-chatkit-launcher.size-small {
    width: 50px;
    height: 50px;
}

.forerunner-chatkit-launcher.size-medium {
    width: 60px;
    height: 60px;
}

.forerunner-chatkit-launcher.size-large {
    width: 70px;
    height: 70px;
}

/* Default right placement */
.forerunner-chatkit-launcher:not(.forerunner-chatkit-launcher-left) {
    right: 20px;
}

/* Left placement */
.forerunner-chatkit-launcher.forerunner-chatkit-launcher-left {
    left: 20px;
}

.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;
}

/* No overlay mode - transparent background, pointer events only on modal */
.forerunner-chatkit-modal-no-overlay {
    background: transparent;
    pointer-events: none;
}

.forerunner-chatkit-modal-no-overlay .forerunner-chatkit-modal-content {
    pointer-events: all;
}

/* Modal positioning: Above Icon */
.forerunner-chatkit-modal-above-icon {
    align-items: flex-end;
    justify-content: flex-end;
    padding: 0;
}

.forerunner-chatkit-modal-above-icon .forerunner-chatkit-modal-content {
    margin: 0 20px 95px 20px; /* 95px = 60px button + 20px bottom + 15px spacing */
    max-height: calc(100vh - 160px);
}

/* Modal positioning: Bottom Right */
.forerunner-chatkit-modal-bottom-right {
    align-items: flex-end;
    justify-content: flex-end;
    padding: 0;
}

.forerunner-chatkit-modal-bottom-right .forerunner-chatkit-modal-content {
    margin: 0 20px 95px 20px; /* 95px = 60px button + 20px bottom + 15px spacing */
    max-height: calc(100vh - 160px);
}

/* Modal positioning: Bottom Left */
.forerunner-chatkit-modal-bottom-left {
    align-items: flex-end;
    justify-content: flex-start;
    padding: 0;
}

.forerunner-chatkit-modal-bottom-left .forerunner-chatkit-modal-content {
    margin: 0 20px 95px 20px; /* 95px = 60px button + 20px bottom + 15px spacing */
    max-height: calc(100vh - 160px);
}

.forerunner-chatkit-modal-content {
    width: 100%;
    max-width: 500px;
    /* Height set via inline style from settings */
    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: 14px 20px;
    background: white;
    border-bottom: 1px solid #e5e5e5;
    flex-shrink: 0;
    height: 60px; /* Fixed height for calculations */
    box-sizing: border-box;
}

.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 !important;
    height: 32px !important;
    border-radius: 6px !important;
    background: transparent !important;
    border: none !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: #666;
    font-size: 26px !important;
    line-height: 0 !important;
    transition: all 0.2s ease !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif !important;
    padding: 0 !important;
    margin: 0 !important;
}

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

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

/* When header is present, ensure proper spacing */
.forerunner-chatkit-modal-content.has-header .forerunner-chatkit-container {
    height: calc(100% - 60px); /* 60px = header height */
}

/* Fix ChatKit instance height when modal header is present */
.forerunner-chatkit-modal-content.has-header .forerunner-chatkit-container openai-chatkit,
.forerunner-chatkit-modal-content.has-header .forerunner-chatkit-container .forerunner-chatkit-instance {
    height: 100% !important; /* Take full available height of container */
}

/* When header is not present, use full height */
.forerunner-chatkit-modal-content:not(.has-header) .forerunner-chatkit-container {
    height: 100%;
}

/* Ensure modal content uses flexbox properly */
.forerunner-chatkit-modal-content {
    display: flex;
    flex-direction: column;
}

.forerunner-chatkit-modal-content .forerunner-chatkit-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.forerunner-chatkit-modal-content .forerunner-chatkit-container openai-chatkit,
.forerunner-chatkit-modal-content .forerunner-chatkit-container .forerunner-chatkit-instance {
    flex: 1;
    min-height: 0; /* Allow shrinking */
}

/* 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) {
    /* Only remove border-radius for CENTER position on mobile */
    .forerunner-chatkit-modal-center .forerunner-chatkit-modal-content {
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }
    
    .forerunner-chatkit-modal-center {
        padding: 0;
    }
    
    /* Keep border-radius for corner/above positions on mobile */
    .forerunner-chatkit-modal-above-icon .forerunner-chatkit-modal-content,
    .forerunner-chatkit-modal-bottom-right .forerunner-chatkit-modal-content,
    .forerunner-chatkit-modal-bottom-left .forerunner-chatkit-modal-content {
        border-radius: 12px;
        width: 90%;
        max-width: 400px;
    }
    
    .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;
    }
    
    .forerunner-chatkit-launcher:not(.forerunner-chatkit-launcher-left) {
        right: 16px;
    }
    
    .forerunner-chatkit-launcher.forerunner-chatkit-launcher-left {
        left: 16px;
    }
    
    .forerunner-chatkit-launcher svg {
        width: 22px;
        height: 22px;
    }
    
    /* Adjust modal positioning on mobile */
    .forerunner-chatkit-modal-above-icon .forerunner-chatkit-modal-content {
        margin: 0 0 90px 0; /* 90px = 56px button (mobile) + 16px bottom + 18px spacing */
    }
    
    .forerunner-chatkit-modal-bottom-right .forerunner-chatkit-modal-content {
        margin: 0 15px 90px 0; /* Add 15px right padding on mobile */
    }
    
    .forerunner-chatkit-modal-bottom-left .forerunner-chatkit-modal-content {
        margin: 0 0 90px 15px; /* Add 15px left padding on mobile */
    }
}

/* ==================================================================
   CUSTOM CSS INJECTION POINT
   ==================================================================
   
   Use this section to add your own custom styles.
   These styles will override the defaults above.
   
   AVAILABLE CSS CLASSES FOR CUSTOMIZATION:
   
   FLOATING LAUNCHER BUTTON:
   - .forerunner-chatkit-launcher              Main launcher button
   - .forerunner-chatkit-launcher-left         Left-side placement
   - .forerunner-chatkit-launcher-right        Right-side placement (default)
   - .forerunner-chatkit-launcher.size-small   Small button (50px)
   - .forerunner-chatkit-launcher.size-medium  Medium button (60px, default)
   - .forerunner-chatkit-launcher.size-large   Large button (70px)
   - .forerunner-chatkit-launcher:hover        Hover state
   - .forerunner-chatkit-launcher:active       Active/clicked state
   - .forerunner-chatkit-launcher svg          Icon inside button
   
   FLOATING MODAL:
   - .forerunner-chatkit-modal                     Modal overlay
   - .forerunner-chatkit-modal-open                When modal is open
   - .forerunner-chatkit-modal-no-overlay          No dark background
   - .forerunner-chatkit-modal-center              Centered position
   - .forerunner-chatkit-modal-bottom-right        Bottom right position
   - .forerunner-chatkit-modal-bottom-left         Bottom left position
   - .forerunner-chatkit-modal-content             Modal content box
   - .forerunner-chatkit-modal-content.has-header  When header is shown
   - .forerunner-chatkit-modal-header              Header bar
   - .forerunner-chatkit-modal-header h3           Header title
   - .forerunner-chatkit-modal-close               Close button
   
   CHAT CONTAINER:
   - .forerunner-chatkit-container            Main chat container (inline or modal)
   - .forerunner-chatkit-instance             The openai-chatkit web component
   - .forerunner-chatkit-wrapper              Wrapper for inline chats
   
   LOADING & ERROR STATES:
   - .forerunner-chatkit-loading-skeleton     Loading animation
   - .forerunner-chatkit-loading              Legacy loading state
   - .forerunner-chatkit-error                Error message box
   - .chatkit-error-toast                     Toast notification
   
   CONSENT GATE (GDPR):
   - .forerunner-chatkit-consent              Consent gate wrapper
   - .forerunner-chatkit-consent-content      Content area
   - .forerunner-chatkit-consent-accept       Accept button
   
   EXAMPLE CUSTOMIZATIONS:
   
   1. Change launcher button to square with custom color:
      .forerunner-chatkit-launcher {
          border-radius: 12px !important;
          background-color: #ff6b6b !important;
      }
   
   2. Add custom shadow to launcher:
      .forerunner-chatkit-launcher {
          box-shadow: 0 8px 24px rgba(255, 107, 107, 0.5) !important;
      }
   
   3. Customize modal chat window:
      .forerunner-chatkit-modal-content {
          background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
          border: 3px solid #ffffff !important;
      }
   
   4. Change header colors:
      .forerunner-chatkit-modal-header {
          background: #1a1a1a !important;
          border-bottom: 2px solid #10a37f !important;
      }
      .forerunner-chatkit-modal-header h3 {
          color: #ffffff !important;
      }
   
   5. Custom launcher icon size:
      .forerunner-chatkit-launcher svg {
          width: 28px !important;
          height: 28px !important;
      }
   
   6. Pulse animation on launcher:
      @keyframes launcher-pulse {
          0%, 100% { transform: scale(1); }
          50% { transform: scale(1.05); }
      }
      .forerunner-chatkit-launcher {
          animation: launcher-pulse 2s ease-in-out infinite;
      }
   
   ================================================================== */

