* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f5f5;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 40px);
}

#auth-container {
    background: white;
    border-radius: 8px;
    padding: 40px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    text-align: center;
    margin: auto;
    max-width: 500px;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 400px;
}

.auth-title {
    color: #333;
    font-size: 24px;
    margin-bottom: 10px;
}

.auth-subtitle {
    color: #666;
    margin-bottom: 30px;
    font-size: 14px;
}

#google-signin-button {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 20px;
}

#chatbot-container {
    display: none;
    background: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    flex: 1;
    flex-direction: column;
    min-height: calc(100vh - 40px);
    width: 100%;
}

#chatbot-container.visible {
    display: flex;
}

#auth-container.hidden {
    display: none;
}

.chatbot-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

/* App header for index.html */
.app-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }
.app-header.hidden { display: none; }
.app-header-brand { font-weight: 600; color: #333; }

.chatbot-title {
    color: #333;
    font-size: 20px;
    margin: 0;
    padding-right: 20px;
}

#user-info {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 14px;
    color: #666;
}

.logout-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.logout-btn:hover {
    background: #c82333;
}

#bixie-widget-container {
    display: none;
    width: 100% !important;
    flex: 1 !important;
    min-height: 500px !important;
    height: auto !important;
    background-color: #fff !important;
    border: 1px solid #ddd;
    border-radius: 4px;
}

#error-message {
    display: none;
    background: #f8d7da;
    color: #721c24;
    padding: 12px;
    border-radius: 4px;
    margin: 20px 0;
    border: 1px solid #f5c6cb;
}

#error-message.show {
    display: block;
}

.loading {
    color: #666;
    font-style: italic;
}

/* Widget loading and error states */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    padding: 40px;
    text-align: center;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #4285f4;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-state p {
    margin: 0;
    color: #666;
    font-size: 16px;
}

.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    padding: 40px;
    text-align: center;
    background-color: #fef2f2;
    border-radius: 8px;
    border: 1px solid #fecaca;
}

.error-state p {
    margin: 0;
    color: #dc2626;
    font-size: 16px;
}

.retry-btn {
    background: #4285f4;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    margin-left: 10px;
    transition: background-color 0.3s;
}

.retry-btn:hover {
    background: #357ae8;
}

/* Widget Controls */
.widget-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.widget-type-selector {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-right: 20px;
    font-size: 14px;
}

.widget-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.widget-type-selector input[type="radio"] {
    accent-color: #4285f4;
}

.widget-type-label {
    color: #666;
    font-size: 14px;
    user-select: none;
}

.toggle-slider {
    position: relative;
    display: inline-block;
}

.toggle-input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-label {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
    background-color: #ccc;
    border-radius: 24px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.toggle-label:hover {
    background-color: #bbb;
}

.toggle-input:checked + .toggle-label {
    background-color: #4285f4;
}

.toggle-input:checked + .toggle-label:hover {
    background-color: #357ae8;
}

.toggle-button {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    top: 3px;
    background-color: white;
    border-radius: 50%;
    transition: 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-input:checked + .toggle-label .toggle-button {
    transform: translateX(26px);
}

/* Floating Widget Styles */
.floating-widget-wrapper {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 350px;
    max-height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    border: 1px solid #e0e0e0;
    overflow: hidden;
    transition: all 0.3s ease;
}

/* Bot launcher grid */
.bot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.bot-card {
  display: block;
  border: 1px solid #e0e0e0;
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease;
}
.bot-card:focus, .bot-card:hover {
  outline: none;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.bot-card-body { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.bot-card-icon img { width: 48px; height: 48px; object-fit: contain; }
.bot-card-name { font-weight: 600; font-size: 14px; }

/* Header switcher */
.header-left { display: flex; align-items: center; gap: 8px; }
.bot-switcher {
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 6px;
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.bot-switcher .dots { letter-spacing: 2px; }
.current-bot { display: inline-flex; align-items: center; gap: 8px; }
.current-bot .bot-badge { width: 20px; height: 20px; object-fit: contain; }
.current-bot .bot-name { font-weight: 600; }

/* Switcher overlay */
.bot-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.3); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.bot-overlay-panel { background: #fff; border-radius: 10px; padding: 16px; width: min(720px, 92vw); max-height: 80vh; overflow: auto; }
.bot-overlay-panel#launcher-container { margin: 20px auto; max-height: none; }
.overlay-title { margin: 0 0 12px; font-size: 16px; }
.overlay-close { margin-top: 12px; }

.floating-widget-header {
    background: linear-gradient(135deg, #4285f4, #357ae8);
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: grab;
    user-select: none;
}

.floating-widget-header:active {
    cursor: grabbing;
}

.floating-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    font-size: 14px;
}

.floating-badge {
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.floating-controls {
    display: flex;
    gap: 8px;
}

.floating-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    transition: background-color 0.2s;
}

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

.floating-widget-content {
    height: 400px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#bixie-floating-container {
    flex: 1;
    width: 100% !important;
    height: 100% !important;
    border: none;
    background: white;
}

/* Floating widget states */
.floating-widget-wrapper .loading-state,
.floating-widget-wrapper .error-state {
    min-height: 150px;
    padding: 20px;
}

.floating-widget-wrapper .loading-spinner {
    width: 30px;
    height: 30px;
    border-width: 3px;
}

/* Hide/show widget containers based on current type */
.widget-mode-anchored [class*="bixie-floating"],
.widget-mode-anchored [id*="bixie-floating"] {
    display: none !important;
}

/* Hide any floating widget roots when in Anchored mode */
body.widget-mode-anchored [id^="widget-root-"][id$="_floating"] {
    display: none !important;
}
/* Ensure any nested elements inside floating root are hidden too */
body.widget-mode-anchored [id^="widget-root-"][id$="_floating"] * {
    display: none !important;
}
/* Conservative catch-all: hide common floating launcher structures */
body.widget-mode-anchored [id*="_floating"] {
    display: none !important;
}

.widget-mode-floating #bixie-widget-container {
    display: none !important;
}

/* Floating mode message styling */
#floating-mode-message {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    margin: 20px 0;
    color: #6c757d;
}

/* Class-based widget mode visibility to avoid inline styles */
body.widget-mode-floating #bixie-widget-container { display: none; }
body.widget-mode-floating #floating-mode-message { display: block; }
body.widget-mode-anchored #bixie-widget-container { display: block; }
body.widget-mode-anchored #floating-mode-message { display: none; }
body.widget-mode-anchored .floating-widget-wrapper { display: none !important; }

/* Hide floating launcher icon when Anchored mode is selected (specific root variant) */
body.widget-mode-anchored #widget-root-7c2e4f61-a468-4e56-a013-a8fbec3f2064_floating > div > div > div > div.MuiBox-root.hw-foqmuphgd-1l9nd9b {
    display: none !important;
}

/* Tablet and smaller screens */
@media (max-width: 768px) {
    .container {
        max-width: 100%;
        padding: 0 10px;
    }
    
    #auth-container {
        max-width: 100%;
        padding: 30px 20px;
        margin: 20px auto;
        min-height: 300px;
    }
    
    #chatbot-container {
        padding: 15px;
        min-height: calc(100vh - 30px);
    }
    
    #bixie-widget-container {
        min-height: 400px !important;
    }
    
    /* Floating widget adjustments for tablets */
    .floating-widget-wrapper {
        width: 320px;
        max-height: 450px;
        bottom: 10px;
        right: 10px;
    }
    
    .widget-type-selector {
        gap: 10px;
    }
    
    .widget-option {
        font-size: 13px;
    }
}

/* Mobile screens */
@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    .container {
        min-height: calc(100vh - 20px);
    }
    
    #auth-container {
        padding: 25px 15px;
        margin: 10px auto;
        min-height: 250px;
    }
    
    .auth-title {
        font-size: 22px;
    }
    
    .auth-subtitle {
        font-size: 13px;
    }
    
    #google-signin-button {
        margin-top: 25px;
    }
    
    #chatbot-container {
        padding: 10px;
        min-height: calc(100vh - 20px);
    }
    
    .chatbot-header {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
        padding-bottom: 10px;
        margin-bottom: 15px;
    }
    
    .chatbot-title {
        font-size: 18px;
        text-align: center;
    }
    
    #user-info {
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    #bixie-widget-container {
        min-height: 350px !important;
        border-radius: 2px;
    }
    
    /* Floating widget mobile adjustments */
    .floating-widget-wrapper {
        width: calc(100vw - 20px);
        max-height: 70vh;
        bottom: 10px;
        left: 10px;
        right: 10px;
    }
    
    .floating-widget-header {
        padding: 10px 12px;
    }
    
    .floating-title {
        font-size: 13px;
    }
    
    .floating-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    
    .floating-widget-content {
        height: 350px;
    }
    
    .widget-controls {
        flex-direction: column;
        gap: 10px;
    }
    
    .widget-type-selector {
        justify-content: center;
        margin: 0;
    }
}

/* Large screens */
@media (min-width: 1200px) {
    .container {
        max-width: 1400px;
    }
    
    #bixie-widget-container {
        min-height: 700px !important;
    }
    
    /* Enhanced floating widget for large screens */
    .floating-widget-wrapper {
        width: 400px;
        max-height: 600px;
    }
    
    .floating-widget-content {
        height: 500px;
    }
}
#auth-container.hidden {
    display: none;
}

/* Generic hidden utility */
.hidden { display: none !important; }
