/* ============================================
   CSS Variables (Light & Dark Mode)
   ============================================ */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --accent-primary: #0066ff;
    --accent-hover: #0052cc;
    --border-color: #dee2e6;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1d21;
        --bg-secondary: #24272b;
        --text-primary: #e9ecef;
        --text-secondary: #adb5bd;
        --accent-primary: #4d9fff;
        --accent-hover: #66b3ff;
        --border-color: #343a40;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    }
}

/* ============================================
   Reset & Base Styles
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: none;
}

/* ============================================
   Chat Container
   ============================================ */
.chat-container {
    position: relative;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    background-color: var(--bg-secondary);
}

/* ============================================
   Loading & Error States
   ============================================ */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 20px;
    color: var(--text-secondary);
    animation: fadeIn 0.4s ease-in;
}

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

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px 24px;
    text-align: center;
    gap: 24px;
    max-width: 520px;
    margin: 0 auto;
}

.error-icon {
    font-size: 56px;
}

.error-state h2 {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
}

.error-state p {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.7;
}

.error-button {
    display: inline-block;
    padding: 14px 28px;
    background-color: var(--accent-primary);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 102, 255, 0.3);
}

.error-button:hover {
    background-color: var(--accent-hover);
    transform: translateY(-2px);
}

/* ============================================
   Chatwoot Widget Overrides
   ============================================ */
/* Hide the launcher bubble completely */
#woot--bubble-iframe,
.woot--bubble-holder,
.woot-widget-holder .woot--bubble-holder,
[class*="bubble"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Force fullscreen widget */
#woot-widget-holder,
#cw-widget-holder,
.woot-widget-holder {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 0 !important;
    z-index: 999 !important;
    border: none !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    transform: none !important;
    background-color: var(--bg-secondary) !important;
}

/* Remove Chatwoot's hide/minimize class effects */
#woot-widget-holder.woot--hide,
#cw-widget-holder.woot--hide,
.woot-widget-holder.woot--hide,
#woot-widget-holder.woot--minimize,
#cw-widget-holder.woot--minimize,
.woot-widget-holder.woot--minimize,
#woot-widget-holder.woot-widget-bubble,
#cw-widget-holder.woot-widget-bubble,
.woot-widget-holder.woot-widget-bubble {
    visibility: visible !important;
    opacity: 1 !important;
    display: block !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    transform: none !important;
    transition: none !important;
}

/* Prevent widget from collapsing to corner */
#woot-widget-holder[data-minimized="true"],
#cw-widget-holder[data-minimized="true"],
.woot-widget-holder[data-minimized="true"] {
    width: 100vw !important;
    height: 100vh !important;
    top: 0 !important;
    left: 0 !important;
    transform: none !important;
}

/* Remove border radius from widget iframe and zoom out */
#woot-widget-holder iframe,
#cw-widget-holder iframe,
.woot-widget-holder iframe {
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    outline: none !important;
    -webkit-tap-highlight-color: transparent;
    /* Zoom out to show more content - JavaScript will set exact scale */
    transform-origin: top left !important;
}

/* Adjust container to accommodate zoomed iframe - JavaScript will set exact size */
#woot-widget-holder,
#cw-widget-holder,
.woot-widget-holder {
    overflow: hidden !important;
}

/* Hide "Powered by Chatwoot" branding - best effort */
#woot-widget-holder footer,
.woot-widget-holder footer,
#woot-widget-holder [class*="footer"],
.woot-widget-holder [class*="footer"],
#woot-widget-holder [class*="powered"],
.woot-widget-holder [class*="powered"],
#woot-widget-holder [class*="brand"],
.woot-widget-holder [class*="brand"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    overflow: hidden !important;
}

/* Widget container */
#chatwoot-widget-container {
    width: 100%;
    height: 100%;
    position: relative;
    background-color: var(--bg-secondary);
}

/* Smooth transitions for widget appearance */
#woot-widget-holder,
#cw-widget-holder,
.woot-widget-holder {
    transition: opacity 0.3s ease-in;
    animation: fadeInWidget 0.5s ease-in;
}

@keyframes fadeInWidget {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Improve iframe rendering quality */
#woot-widget-holder iframe,
#cw-widget-holder iframe,
.woot-widget-holder iframe {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 768px) {
    .chat-container {
        height: 100vh;
        height: -webkit-fill-available;
    }

    #woot-widget-holder,
    .woot-widget-holder {
        height: 100vh !important;
        height: -webkit-fill-available !important;
    }
}

/* ============================================
   Iframe Embedding Support
   ============================================ */
html.iframe-embed,
html.iframe-embed body {
    overflow: hidden;
}

html.iframe-embed .chat-container {
    height: 100vh;
    height: -webkit-fill-available;
}

/* ============================================
   Scrollbar Styling
   ============================================ */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 3px;
}
