html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent body scroll */
}

#header {
    padding: 10px;
    background-color: #f0f0f0;
    border-bottom: 1px solid #ccc;
    display: flex;
    align-items: center;
}

#header .header-left {
    text-align: left;
}

#header .header-center {
    text-align: center;
    flex: 1; /* Take up remaining space */
}

.connection-dot {
    position: relative;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: #ff4444;
    transition: background-color 300ms ease-in-out;
    cursor: pointer;
    margin-left: auto; /* Push to the right */
}

.connection-dot[data-state="connected"] {
    background-color: #4CAF50;
    animation: pulse 1.5s infinite; /* Add blinking animation */
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
    }
}

.status-tooltip {
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 300ms ease-in-out;
    pointer-events: none;
}

.connection-dot:hover .status-tooltip,
.connection-dot:focus .status-tooltip {
    opacity: 1;
    visibility: visible;
}

#chat-container {
    flex-grow: 1;
    overflow-y: auto; /* Scrollable chat area */
    padding: 10px;
    border: 1px solid #eee;
    background-color: #f9f9f9;
    display: flex;
    flex-direction: column;
}

.chat-message {
    display: flex;
    margin-bottom: 10px;
    max-width: 80%;
}

.chat-bubble {
    padding: 10px 15px;
    border-radius: 18px;
    word-wrap: break-word;
    white-space: pre-wrap; /* Preserve whitespace and line breaks */
}

.chat-message.user {
    justify-content: flex-end;
    align-self: flex-end;
}

.chat-message.user .chat-bubble {
    background-color: #007bff; /* Blue */
    color: white;
    border-bottom-right-radius: 2px;
}

.chat-message.system {
    justify-content: center;
    align-self: center;
    text-align: center;
    width: 100%;
}

.chat-message.system .chat-bubble {
    background-color: #6c757d; /* Gray */
    color: white;
    font-size: 0.9em;
    border-radius: 5px;
}

.chat-message.assistant {
    justify-content: flex-start;
    align-self: flex-start;
}

.chat-message.assistant .chat-bubble {
    background-color: #e2e6ea; /* Light gray */
    color: #333;
    border-bottom-left-radius: 2px;
}

.chat-message.debug,
.chat-message.tool {
    justify-content: flex-start;
    align-self: flex-start;
    width: 100%;
    margin-bottom: 5px; /* Reduce margin for less prominence */
}

.chat-message.debug .chat-bubble,
.chat-message.tool .chat-bubble {
    background-color: #f0f0f0; /* Subtle background */
    color: #555; /* Softer text color */
    border-radius: 5px;
    font-size: 0.8em; /* Slightly larger font for readability */
    width: 100%;
    padding: 8px 12px; /* Adjusted padding */
    border: 1px solid #e0e0e0; /* Subtle border */
}

.debug-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.debug-content.expanded {
    max-height: 500px; /* Adjust as needed for content */
    transition: max-height 0.5s ease-in;
}

.debug-toggle {
    cursor: pointer;
    color: #666; /* Softer color for the icon */
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    font-size: 0.9em; /* Smaller font for the label next to icon */
}

.debug-toggle i {
    margin-right: 5px;
    transition: transform 0.3s ease-in-out;
}

.debug-toggle.expanded i {
    transform: rotate(90deg); /* Rotate icon when expanded */
}

.debug-json {
    background-color: #333;
    color: #f8f8f2;
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}

.debug-json pre {
    margin: 0;
}

.input-area {
    display: flex;
    padding: 10px;
    border-top: 1px solid #ccc;
    background-color: #f0f0f0;
    align-items: center; /* Vertically align items */
}

#message-input {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    margin: 0 5px; /* Adjust margin for buttons on both sides */
    font-size: 1em;
}

.icon-button {
    padding: 10px; /* Make it square */
    border: none;
    border-radius: 5px;
    background-color: #007bff;
    color: white;
    cursor: pointer;
    font-size: 1.2em; /* Larger icon size */
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0; /* Prevent shrinking on smaller screens */
}

.icon-button:hover {
    background-color: #0056b3;
}

#menu-container {
    padding: 10px;
    border-top: 1px solid #ccc;
    background-color: #f0f0f0;
    display: none; /* Hidden by default */
    flex-direction: column;
    align-items: flex-start;
}

#menu-container.show {
    display: flex;
}

#menu-container button {
    width: 100%;
    padding: 10px 15px;
    margin-bottom: 5px;
    border: none;
    border-radius: 5px;
    background-color: #007bff;
    color: white;
    cursor: pointer;
    font-size: 1em;
    text-align: left;
}

#menu-container button:hover {
    background-color: #0056b3;
}

/* Toggle Switch Styles */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
    margin-left: 10px;
    vertical-align: middle;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #007bff;
}

input:focus + .slider {
    box-shadow: 0 0 1px #007bff;
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Rounded sliders */
.slider.round {
    border-radius: 20px;
}

.slider.round:before {
    border-radius: 50%;
}

.toggle-label {
    vertical-align: middle;
    margin-left: 5px;
    font-size: 0.9em;
    color: #555;
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .chat-message {
        max-width: 95%;
    }
    .input-area {
        flex-direction: row; /* Keep row for input and icons */
        flex-wrap: nowrap; /* Prevent wrapping */
    }
    #message-input {
        margin: 0 5px; /* Keep horizontal margins */
    }
    .icon-button {
        padding: 8px; /* Smaller padding for mobile icons */
        font-size: 1em;
    }
    #menu-container {
        flex-direction: column; /* Stack items vertically on mobile */
        align-items: flex-start;
    }
    #menu-container button {
        width: 100%; /* Full width for buttons on mobile */
        text-align: center;
    }
    #menu-container .switch {
        margin-left: 0; /* Remove left margin for switch on mobile */
        margin-top: 10px; /* Add top margin for spacing */
    }
    #menu-container .toggle-label {
        margin-left: 0; /* Remove left margin for label on mobile */
        margin-top: 5px; /* Add top margin for spacing */
    }
}

/* Desktop adjustments for menu items */
@media (min-width: 601px) {
    #menu-container {
        display: flex;
        flex-direction: row; /* Arrange items horizontally on desktop */
        align-items: center;
        justify-content: flex-start; /* Align items to the start */
        flex-wrap: wrap; /* Allow items to wrap if needed */
    }
    #menu-container button {
        width: auto; /* Auto width for buttons on desktop */
        margin-right: 10px; /* Add some spacing between buttons */
    }
    #menu-container .switch {
        margin-left: 10px; /* Add left margin for switch on desktop */
    }
}

/* ----- Image attachment (multimodal) UI ----- */

/* Preview strip above the input for pending attachments */
.attachment-preview {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
    background-color: #f0f0f0;
    border-top: 1px solid #e0e0e0;
}

.attachment-thumb {
    position: relative;
    width: 56px;
    height: 56px;
    border: 1px solid #ccc;
    border-radius: 6px;
    overflow: hidden;
}

.attachment-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.attachment-remove {
    position: absolute;
    top: -2px;
    right: -2px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    line-height: 16px;
    text-align: center;
    cursor: pointer;
    font-size: 14px;
}

/* Thumbnails rendered inside a chat bubble */
.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.message-attachment-img {
    max-width: 160px;
    max-height: 160px;
    border-radius: 6px;
    cursor: pointer;
    object-fit: cover;
    border: 1px solid rgba(0, 0, 0, 0.1);
}