/*******************************
 * Global UI Element Overrides
 *******************************/

/* Hide default Chainlit elements */
.watermark,
#new-chat-button,
#readme-button,
div[data-variant="sidebar"] {
    display: none !important;
}

/*******************************
 * Chat Messages
 *******************************/

/* Message spacing */
.ai-message .message-content {
    margin-bottom: 0.5rem !important;
}

/* Message links styling */
.message-link {
    border-radius: 10px;
    color: #bf202c !important;
    text-decoration: none !important;
    line-height: 1.3 !important;
    padding: 0.1rem 0.4rem !important;
    background-color: rgba(255, 242, 0, 0.3) !important;
    border: 2px solid #bf202c !important;
    font-family: "Montserrat Alternates", sans-serif !important;
    font-weight: normal !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/*******************************
 * Action Buttons
 *******************************/

/* Hide default clipboard buttons */
.ai-message button:first-of-type:not(.message-link),
.ai-message button:nth-of-type(2):not(.message-link),
.ai-message button:nth-of-type(3):not(.message-link) {
    display: none !important;
}

/* Common button styles */
.ai-message button,
aside button {
    font-family: "Montserrat Alternates", sans-serif !important;
    font-weight: 600;
    border: 2px solid #bf202c !important;
    margin-left: 0.5rem;
    margin-right: 0.5rem;
    background-color: rgba(255, 242, 0, 0.3) !important;
    color: #222 !important;
    transition: all 0.3s ease !important;

    /* Dark mode */
    .dark & {
        color: #fff !important;
    }
}

/* Button hover effects */
.ai-message button:hover,
aside button:hover {
    background-color: rgba(255, 242, 0, 0.6) !important;
}

/*******************************
 * Language Switcher
 *******************************/

#language-switcher {
    position: absolute;
    padding: 0.75rem;
    top: -4.5rem;
    right: 1rem; 
    width: 100px;
    z-index: 1000;
}

#language-switcher button {
    background-color: rgba(255, 242, 0, 0.3) !important;
    border-radius: 50%;
    font-family: sans-serif !important;
    height: 32px;
    opacity: 1 !important;
    width: 32px;
}

#language-switcher button:hover {
    background-color: #FFFFFF !important;
    color: #bf202c !important;
}

#language-switcher button:disabled {
    cursor: not-allowed !important;
    background-color: #FFFFFF !important;
    color: #bf202c !important;
}

/*******************************
 * Sidebar Styling
 *******************************/

/* Sidebar container */
aside > div {
    background: linear-gradient(to right, rgba(255, 255, 255, 0.1), rgba(255, 242, 0, 0.2)) !important;
    border: 0 !important;
    position: relative !important;
}

/* Sidebar background image */
aside > div::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background-image: url("sidebar_bg.png") !important;
    background-position: bottom right !important;
    background-repeat: no-repeat !important;
    background-size: 70% !important;
    opacity: 0.2;
    z-index: 0;
}

/* Ensure sidebar content appears above background */
aside > div > * {
    position: relative;
    z-index: 1;
}

/* Sidebar icon color */
aside .icon {
    color: #bf202c;
}

/* Sidebar title styling */
#side-view-title {
    background-image: url("sidebar_title_bg.png") !important;
    background-repeat: no-repeat !important;
    background-size: 10% !important;
    background-position: 1rem center !important;
    color: #333 !important;
    font-family: "Montserrat Alternates", sans-serif !important;
    font-size: 1.1rem !important;
    font-weight: bold !important;
    margin-left: 2rem !important;
    margin-bottom: 1rem !important;
    padding-left: 6rem !important;
}

/* Hide sidebar close button */
#side-view-title > button {
    display: none !important;
}

/* Sidebar content area */
#side-view-content {
    padding-bottom: 2.3rem 0 !important;
}

#side-view-content button {
    zoom: 0.8 !important;
}

/* Debrief section styling */
aside .debrief {
    background-color: #fff !important;
    position: relative;

    .dark & {
        background-color: #000 !important;
        color: #fff !important;
    }
}

aside .debrief button {
    background-color: #fff !important;
    border: 0 !important;
    position: absolute;
    top: 10px;
    right: 0;
    z-index: 1;
}

/*******************************
 * Sidebar Action Buttons
 *******************************/

/* Common positioning for bottom buttons */
aside #reset-button,
aside #print-facts-button,
aside #exit-button,
aside #ai-respond-button {
    zoom: 0.75 !important;
    position: absolute;
    bottom: 1rem;
}

/* Individual button positioning */
aside #reset-button {
    background-color: rgba(191, 32, 44, 0.2) !important;
    right: 5.5rem;
}

aside #exit-button {
    background-color: rgba(191, 32, 44, 0.2) !important;
    right: 1.4rem;
}

aside #print-facts-button {
    background-color: #f0f0f0 !important;
    right: 12.4rem;
}

aside #ai-respond-button {
    background-color: #f0f0f0 !important;
    right: 21.5rem;
}

/*******************************
 * Switch/Toggle Button Styling
 *******************************/

/* Switch button base styling */
input[type="checkbox"],
.switch,
.toggle,
[role="switch"] {
    background-color: #cccccc !important; /* Grey background (unchecked) */
}

/* Switch button checked state */
input[type="checkbox"]:checked,
.switch:checked,
.toggle:checked,
[role="switch"][aria-checked="true"] {
    background-color: #28a745 !important; /* Green background when checked */
}

/* Switch handles - always white */
input[type="checkbox"]::before,
.switch::before,
.toggle::before,
[role="switch"]::before {
    background-color: #ffffff !important;
}

/* Switch containers */
.switch-container:has(input:checked),
.toggle-container:has(input:checked) {
    background-color: #28a745 !important;
}

.switch-container:has(input:not(:checked)),
.toggle-container:has(input:not(:checked)) {
    background-color: #cccccc !important;
}

/*******************************
 * Tablet & Small Desktop Responsiveness
 *******************************/
@media (min-width: 769px) and (max-width: 1200px) {
    /* Adjust sidebar width for smaller desktop screens */
    aside {
        /* width: 340px !important; */
    }

    /* Adjust title styling */
    #side-view-title {
        font-size: 1rem !important;
        padding-left: 4.5rem !important;
        margin-left: 1rem !important;
        background-size: 2.5rem !important;
    }
    
    /* Adjust button sizes and positions to prevent overlap */
    aside #reset-button,
    aside #print-facts-button,
    aside #exit-button,
    aside #ai-respond-button {
        zoom: 0.7 !important;
    }

    aside #ai-respond-button {
        right: 14.5rem;
    }

    aside #print-facts-button {
        right: 10rem;
    }

    aside #reset-button {
        right: 5.5rem;
    }

    aside #exit-button {
        right: 1rem;
    }
}

/*******************************
 * Mobile Responsiveness
 *******************************/
@media (max-width: 768px) {
    /*
     * The mobile sidebar is a div[role="dialog"], not an <aside> element.
     * These styles target the mobile sidebar specifically for a full-screen, clean look.
     */

    /* Make sidebar full screen */
    div[role="dialog"][data-state="open"] {
        width: auto !important;
        height: 100% !important;
        left: 10% !important;
        right: 0 !important;
        padding: 1rem !important;
        border-radius: 0 !important;
        border: none !important;
    }

    #side-view-content {
        gap: 0 !important;
    }
    
    /* Align title to the left and add space below */
    div[role="dialog"][data-state="open"] #side-view-title {
        padding-left: 3.7rem !important;
        margin-left: 0 !important;
        text-align: left !important;
        margin-bottom: 1rem !important;
    }

    /* Remove backgrounds and borders from all content blocks */
    div[role="dialog"][data-state="open"] .bg-card {
        padding: 0.5rem !important;
    }
    div[role="dialog"][data-state="open"] .debrief {
        background-color: #FFF !important;
        box-shadow: none !important;
        padding: 0.4rem !important;
    }

    /* Clean up inner padding and margins for a seamless look */
    div[role="dialog"][data-state="open"] .bg-card > div[class*="p-"] {
        padding: 0 !important;
    }
    
    div[role="dialog"][data-state="open"] .space-y-4 {
        margin-top: 0 !important;
    }

    div[role="dialog"][data-state="open"] .mt-8 {
        margin-top: 1.5rem !important;
    }

    /* Hide unnecessary elements on mobile */
    button[data-state="closed"] svg[width="24"][height="24"],
    #new-progress-check-button,
    div[role="dialog"][data-state="open"] #ai-respond-button,
    div[role="dialog"][data-state="open"] #print-facts-button,
    div[role="dialog"][data-state="open"] #send-test-email-button {
        display: none !important;
    }

    /* Position remaining buttons at the bottom of the screen */
    div[role="dialog"][data-state="open"] #exit-button,
    div[role="dialog"][data-state="open"] #reset-button {
        position: fixed;
        bottom: 1.5rem;
        zoom: 0.9;
    }

    div[role="dialog"][data-state="open"] #exit-button {
        right: 1.5rem;
    }
    
    div[role="dialog"][data-state="open"] #reset-button {
        right: 6rem;
    }
}

