body {
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, sans-serif;
    background: #f0f2f5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

#app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Base main-content styling */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 20px 20px 20px 20px; /* Added top padding */
    gap: 20px;
    flex-direction: column;
}

header {
    padding: 10px 20px;
    text-align: right;
    background: transparent;
    margin-top: auto;
}

.system-controls {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

#chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    min-height: 300px;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    min-height: 200px;
}

/* Auto-send toggle button */
.auto-send-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 12px;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
}

.auto-send-toggle:hover {
    background-color: #e0e0e0;
}

.auto-send-toggle.active {
    background-color: #007bff;
    color: white;
    border-color: #0056b3;
}

.auto-send-toggle .auto-send-icon {
    font-size: 16px;
}

.auto-send-toggle .auto-send-text {
    white-space: nowrap;
}

/* Voice controls container */
#voice-controls-container {
    padding: 8px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Voice Input Button */
#voiceInputToggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 16px;
    padding: 6px 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    color: #333;
}

#voiceInputToggle:hover {
    background: #e0e0e0;
    border-color: #ccc;
}

#voiceInputToggle.recording {
    background: #ffebee;
    border-color: #ef9a9a;
    color: #c62828;
}

#voiceInputToggle .voice-icon {
    font-size: 16px;
}

#voiceInputToggle .voice-text {
    white-space: nowrap;
}

/* Auto-send Toggle Button */
#autoSendToggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 16px;
    padding: 6px 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    color: #333;
}

#autoSendToggle:hover {
    background: #e0e0e0;
    border-color: #ccc;
}

#autoSendToggle.active {
    background: #e3f2fd;
    border-color: #90caf9;
    color: #0d47a1;
}

#autoSendToggle .auto-send-icon {
    font-size: 16px;
}

#autoSendToggle .auto-send-text {
    white-space: nowrap;
}

/* TTS Toggle Button */
#ttsToggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 16px;
    padding: 6px 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    color: #333;
}

#ttsToggle:hover {
    background: #e0e0e0;
    border-color: #ccc;
}

#ttsToggle.active {
    background: #e3f2fd;
    border-color: #90caf9;
    color: #0d47a1;
}

#ttsToggle .tts-icon {
    font-size: 16px;
}

#ttsToggle .tts-text {
    white-space: nowrap;
}

/* System messages container */
#system-messages-container {
    padding: 8px 20px;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #e0e0e0 #f8f8f8;
}

#system-messages-container::-webkit-scrollbar {
    width: 6px;
}

#system-messages-container::-webkit-scrollbar-track {
    background: #f8f8f8;
    border-radius: 3px;
}

#system-messages-container::-webkit-scrollbar-thumb {
    background-color: #e0e0e0;
    border-radius: 3px;
}

.system-message {
    padding: 8px 12px 8px 32px;
    margin: 2px 0;
    background: #fff;
    color: #333;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.4;
    border: 1px solid #e0e0e0;
    animation: fadeIn 0.3s ease-in-out;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    position: relative;
}

/* Pulsing animation for system messages */
.system-message.pulse {
    animation: none; /* Remove box-shadow animation */
}

.system-message.pulse .message-text {
    animation: textPulse 1.5s infinite ease-in-out;
    display: inline-block;
}

@keyframes textPulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
    100% {
        opacity: 1;
    }
}

.system-message::before {
    content: '';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ff9800; /* Default color */
}

.system-message.persistent {
    background: #fff;
    border-color: #e0e0e0;
    color: #333;
}

.system-message.persistent::before {
    background-color: #2196f3; /* Blue for persistent messages */
}

.system-message.error {
    border-color: #ffcdd2;
}

.system-message.error::before {
    background-color: #f44336; /* Red for errors */
}

.system-message.success::before {
    background-color: #4caf50; /* Green for success */
}

.system-message.warning::before {
    background-color: #ff9800; /* Orange for warnings */
}

.system-message .spinner {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    margin: 0;
}

.system-message .message-content {
    flex: 1;
    margin-right: 8px;
}

.system-message .close-button {
    background: none;
    border: none;
    color: #757575;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
    margin-left: 4px;
    opacity: 0.7;
    transition: all 0.2s;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.system-message .close-button:hover {
    opacity: 1;
    background-color: #f5f5f5;
    color: #333;
}

.system-message .view-results-button {
    margin-left: 8px;
    padding: 2px 10px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    color: #333;
    white-space: nowrap;
}

.system-message .view-results-button:hover {
    background: #e0e0e0;
}

.message {
    margin-bottom: 15px;
    padding: 12px;
    border-radius: 8px;
    max-width: 80%;
}

.message.user {
    background: #e3f2fd;
    margin-left: auto;
    color: #1565c0;
}

.message.assistant {
    background: #f5f5f5;
    margin-right: auto;
    color: #333;
    position: relative;
}

.message.assistant .status {
    font-size: 0.9em;
    color: #666;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #e0e0e0;
    display: none;
}

.message.assistant .status.visible {
    display: block;
}

.message.assistant .status.persistent {
    background: #f8f9fa;
    border-radius: 4px;
    padding: 12px;
    margin-top: 12px;
    border: 1px solid #e0e0e0;
}

.message.assistant .status.persistent .result-content {
    color: #1565c0;
    white-space: pre-line;
    line-height: 1.4;
}

.message.assistant .spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

.message.error {
    background: #ffebee;
    color: #c62828;
    margin: 10px auto;
    text-align: center;
}

.message.system {
    background: #fff3e0;
    color: #e65100;
    margin: 10px auto;
    text-align: center;
    max-width: 100%;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.message.system .spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(230, 81, 0, 0.2);
    border-top: 2px solid #e65100;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 4px;
}

.view-results-button {
    background: rgba(230, 81, 0, 0.1);
    border: 1px solid rgba(230, 81, 0, 0.2);
    color: #e65100;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    margin-left: 8px;
    transition: all 0.2s ease;
}

.view-results-button:hover {
    background: rgba(230, 81, 0, 0.2);
}

#input-container {
    padding: 15px 20px;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    position: relative;
}

/* Button group for send and interrupt buttons */
.button-group {
    display: flex;
    gap: 10px;
    transition: all 0.2s ease;
}

.button-group.hidden {
    opacity: 0;
    transform: translateY(10px);
    height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

/* Interrupt button */
#interrupt-button {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    background-color: #ff4444;
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease, opacity 0.3s ease, transform 0.3s ease;
    margin-left: 8px;
    white-space: nowrap;
    height: 36px;
    min-width: 100px;
    position: relative;
    overflow: hidden;
    opacity: 0;
    transform: translateX(10px);
}

#interrupt-button.visible {
    display: flex !important;
    opacity: 1;
    transform: translateX(0);
}

#interrupt-button:hover:not(:disabled) {
    background-color: #ff2222;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
}

#interrupt-button:active:not(:disabled) {
    transform: translateY(1px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

#interrupt-button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
    box-shadow: none;
}

#interrupt-button .interrupt-icon {
    margin-right: 6px;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
}

#interrupt-button .interrupt-text {
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* Animation for TTS playing state */
#interrupt-button.playing {
    animation: pulse 2s infinite;
}

/* Sleep button styling */
#sleep-button {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f5f5f5;
    color: #666;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    margin-left: 0;
    min-width: 70px;
}

#sleep-button:hover {
    background-color: #e0e0e0;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

#sleep-button:active {
    transform: translateY(1px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

#sleep-button .sleep-icon {
    margin-right: 6px;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
}

#sleep-button .sleep-text {
    font-weight: 600;
    letter-spacing: 0.3px;
}

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

#chatInput {
    flex: 1;
    padding: 14px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 24px;
    font-size: 16px;
    line-height: 1.4;
    background-color: #fff;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    resize: none;
    min-height: 24px;
    max-height: 120px;
    overflow-y: auto;
    display: block;
    width: 100%;
    font-family: inherit;
}

#chatInput:focus {
    outline: none;
    border-color: #0084ff;
    box-shadow: 0 0 0 3px rgba(0, 132, 255, 0.1);
}

#chatInput:disabled {
    background-color: #f8f9fa;
    cursor: not-allowed;
    opacity: 0.8;
}

#chatInput::placeholder {
    color: #9e9e9e;
    opacity: 1;
}

/* Better scrollbar for the input */
#chatInput::-webkit-scrollbar {
    width: 6px;
}

#chatInput::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

#chatInput::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

#chatInput::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

#send-button {
    padding: 12px 24px;
    background: #0084ff;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 132, 255, 0.3);
    flex-shrink: 0;
}

#send-button:hover:not(:disabled) {
    background: #0073e6;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 132, 255, 0.3);
}

#send-button:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 132, 255, 0.3);
}

#send-button:disabled {
    background: #e0e0e0;
    color: #9e9e9e;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    padding: 12px 24px 12px 40px;
}

#send-button .spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
}

/* System message styles */
#input-container {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.03);
}

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

/* Make sure the input and button container stays in a row */
#input-container .input-row {
    display: flex;
    gap: 10px;
    width: 100%;
    align-items: center;
}

.debug-toggle {
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    transition: all 0.2s ease;
}

.debug-toggle:hover {
    background: #e0e0e0;
}

/* Settings toggle button (replacing settings link) */
.settings-toggle {
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 8px 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.settings-toggle:hover {
    background: #e0e0e0;
}

/* Settings modal tabs */
.settings-tabs {
    display: flex;
    margin-top: 10px;
    gap: 8px;
    flex-wrap: wrap;
    margin-right: 30px; /* Make room for close button */
}

.settings-tabs button {
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
    color: #666;
    transition: all 0.2s;
    font-weight: 500;
}

.settings-tabs button.active {
    background: #007bff;
    color: #fff;
    border-color: #0056b3;
}

/* Settings tabs content */
.settings-tab {
    display: none;
    padding: 10px 0;
}

.settings-tab.active {
    display: block;
}

/* Settings modal specific styles */
#settings-modal .modal-content {
    max-width: 700px;
    max-height: 80vh;
}

#settings-modal .modal-header {
    position: relative;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
}

#settings-modal .close-button {
    position: absolute;
    top: 0;
    right: 0;
}

/* Generic modal-body styling for all modals */
.modal-body {
    max-height: calc(80vh - 120px);
    overflow-y: auto;
    padding: 15px;
}

/* Settings modal specific styling (if needed) */
#settings-modal .modal-body {
    max-height: calc(80vh - 120px);
    overflow-y: auto;
    padding: 15px;
}

#settings-modal .settings-actions {
    display: flex;
    justify-content: flex-end;
    padding: 15px;
    border-top: 1px solid #e0e0e0;
    background: #f8f9fa;
    position: sticky;
    bottom: 0;
    margin-top: 20px;
}

/* Settings form styles */
#settings-form label {
    display: block;
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#settings-form .setting-name {
    font-weight: 500;
    flex: 0 0 200px;
}

#settings-form .setting-input {
    flex: 1;
}

#settings-form input[type="text"],
#settings-form input[type="number"] {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 100%;
    box-sizing: border-box;
}

#settings-form input[type="checkbox"] {
    margin-left: 0;
    transform: scale(1.2);
}

#settings-form .settings-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #e0e0e0;
}

#settings-form button {
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 8px 16px;
    cursor: pointer;
}

#settings-form button:hover {
    background: #0056b3;
}

#settings-form button.cancel-btn {
    background: #f5f5f5;
    color: #333;
    border: 1px solid #ddd;
}

#settings-form button.cancel-btn:hover {
    background: #e0e0e0;
}

/* Loading indicator */
.loading-indicator {
    text-align: center;
    padding: 20px;
    color: #666;
}

/* Legacy settings link style (keeping for compatibility) */
.settings-link {
    cursor: pointer;
    font-size: 14px;
    color: #666;
    text-decoration: none;
    transition: all 0.2s ease;
}

.settings-link:hover {
    background: #e0e0e0;
}

.subsystem-toggle {
    display: flex;
    align-items: center;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 10px 16px;
    margin-bottom: 8px;
    cursor: pointer;
    font-size: 14px;
    color: #333;
    transition: all 0.2s ease;
    position: relative;
}

.subsystem-toggle::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 12px;
    flex-shrink: 0;
    background-color: #757575; /* Default color */
}

.subsystem-toggle:hover {
    background: #f8f8f8;
    border-color: #bdbdbd;
}

/* Specific module colors */
.subsystem-toggle[data-module="planner"]::before {
    background-color: #9c27b0; /* Purple for planner */
}

.subsystem-toggle[data-module="code"]::before {
    background-color: #2196f3; /* Blue for code */
}

.subsystem-toggle[data-module="browser"]::before {
    background-color: #4caf50; /* Green for browser */
}

.subsystem-toggle[data-module="terminal"]::before {
    background-color: #ff9800; /* Orange for terminal */
}

.subsystem-toggle[data-module="filesystem"]::before {
    background-color: #f44336; /* Red for filesystem */
}

.subsystem-toggle[data-module="memory"]::before {
    background-color: #673ab7; /* Deep purple for memory */
}
.subsystem-toggle[data-module="tools"]::before {
    background-color: #795548; /* Brown for tools */
}
.subsystem-toggle[data-module="llmClient"]::before {
    background-color: #009688; /* Teal for LLM client */
}
.subsystem-toggle[data-module="scheduler"]::before {
    background-color: #607d8b; /* Blue gray for scheduler */
}

.subsystem-toggle .toggle-arrow {
    margin-left: auto;
    transition: transform 0.2s;
    color: #757575;
    font-size: 16px;
    padding: 4px;
    border-radius: 4px;
}

.subsystem-toggle:hover .toggle-arrow {
    background: #f0f0f0;
}

.subsystem-toggle.active {
    background: #f8f9ff;
    border-color: #c5cae9;
}

.subsystem-toggle.active .toggle-arrow {
    transform: rotate(180deg);
    color: #3f51b5;
}

.message-count {
    display: none;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    background-color: #f44336;
    color: white;
    border-radius: 10px;
    font-size: 11px;
    font-weight: bold;
    padding: 0 4px;
    margin-left: 5px;
    margin-right: 2px;
}

.planner-toggle::before {
    background-color: #2196f3; /* Blue for planner */
}

.planner-toggle:hover {
    background: #f8f9ff;
}

.coordinator-toggle::before {
    background-color: #4caf50; /* Green for coordinator */
}

.coordinator-toggle:hover {
    background: #f1f8e9;
}

.ego-toggle::before {
    background-color: #ff9800; /* Orange for ego */
}

.ego-toggle:hover {
    background: #fff3e0;
}

.system-error-toggle::before {
    background-color: #f44336; /* Red for system errors */
}

.system-error-toggle:hover {
    background: #ffebee;
}

.status-toggle {
    position: absolute;
    right: 8px;
    bottom: 8px;
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 12px;
    padding: 4px 8px;
    opacity: 0.7;
    border-radius: 4px;
}

.status-toggle:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.05);
}

.has-new {
    animation: pulse 1s infinite;
    position: relative;
}

.has-new::after {
    content: '';
    position: absolute;
    top: -5px;
    right: -5px;
    width: 10px;
    height: 10px;
    background-color: #f44336;
    border-radius: 50%;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.4);
    }
    70% {
        box-shadow: 0 0 0 5px rgba(244, 67, 54, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(244, 67, 54, 0);
    }
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: #fff;
    margin: 10% auto;
    padding: 0;
    width: 80%;
    max-width: 800px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: #333;
}

.close-button {
    background: none;
    border: none;
    color: #666;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.close-button:hover {
    color: #333;
}

#debug-output, 
#planner-output, 
#coordinator-output, 
#ego-output, 
#results-output {
    padding: 20px;
    font-family: monospace;
    font-size: 14px;
    line-height: 1.5;
    overflow-y: auto;
    max-height: calc(80vh - 60px); /* Subtract header height */
    background: #f5f5f5;
    color: #333;
    white-space: pre-wrap;
}

#results-output {
    color: #64b5f6;
}

.subsystem-message {
    margin-bottom: 15px;
    padding: 0;
    border-radius: 6px;
    background-color: #fff;
    border: 1px solid #e0e0e0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.subsystem-header {
    display: flex;
    align-items: center;
    padding: 6px 12px;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.2s ease;
}

.subsystem-header:hover {
    background-color: #f5f5f5;
}

.subsystem-timestamp {
    font-size: 12px;
    color: #666;
    font-weight: bold;
    margin-right: 10px;
}

.subsystem-title {
    font-size: 14px;
    font-weight: bold;
    color: #333;
    flex-grow: 1;
}

.expand-icon {
    font-size: 12px;
    color: #666;
    transition: transform 0.2s ease;
}

.subsystem-message.expanded .expand-icon {
    transform: rotate(180deg);
}

.subsystem-content {
    font-size: 14px;
    padding: 15px;
    border-top: 1px solid #e0e0e0;
}

.subsystem-content.hidden {
    display: none;
}

.subsystem-content pre {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
    overflow-x: auto;
    margin: 10px 0;
}

.subsystem-content strong {
    color: #1565c0;
}

.expand-all-container {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
    padding: 0 10px;
    gap: 8px;
}

.expand-all-button,
.collapse-all-button {
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 12px;
    color: #666;
    transition: all 0.2s ease;
}

.copy-button {
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 12px;
    margin-left: 8px;
}

.copy-button:hover {
    background: #e0e0e0;
}

.filter-input {
    margin-left: auto;
    margin-right: 10px;
    padding: 4px 6px;
    font-size: 12px;
}

.expand-all-button:hover,
.collapse-all-button:hover {
    background: #e0e0e0;
}

#planner-output .subsystem-message {
    border-left: 4px solid #1565c0;
}

#coordinator-output .subsystem-message {
    border-left: 4px solid #2e7d32;
}

#ego-output .subsystem-message {
    border-left: 4px solid #e65100;
}

.no-messages {
    color: #999;
    font-style: italic;
    text-align: center;
    padding: 20px;
}

/* System Error Styling */
.error-message {
    color: #c62828;
    font-weight: bold;
    margin: 8px 0;
}

.error-location {
    color: #616161;
    font-style: italic;
    margin-bottom: 8px;
}

.error-stack {
    background-color: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 8px;
    font-family: monospace;
    font-size: 12px;
    white-space: pre-wrap;
    overflow-x: auto;
    margin-top: 8px;
}

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

/* Responsive styles */
/* Main content layout - mobile first */
.main-content {
    display: flex;
    flex: 1;
    overflow: auto;
    padding: 20px 10px 10px; /* Added top padding */
    gap: 10px;
    flex-direction: column;
}

/* Main content layout - desktop */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 20px 20px 20px 20px; /* Added top padding */
    gap: 20px;
}

/* Chat panel takes 50% width */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    min-width: 0; /* Prevents flex items from overflowing */
    overflow: hidden;
}

/* Canvas panel takes 50% width */
.canvas-panel {
    flex: 1;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    min-width: 0; /* Prevents flex items from overflowing */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Settings page token count styling */
.token-count {
    font-size: 0.85em;
    color: #666;
    font-weight: normal;
    margin-left: 8px;
}

/* Settings page details/summary styling */
#stats details {
    margin-bottom: 15px;
}

#stats details summary {
    cursor: pointer;
    padding: 5px 0;
}

#stats details summary:hover {
    background-color: #f5f5f5;
}

/* Canvas content area */
#canvas-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    /* Ensure scrollbar appears when content overflows */
    height: 100%;
    max-height: 100%;
}

/* Placeholder for empty canvas */
.canvas-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #666;
    padding: 20px;
    text-align: center;
}

.canvas-placeholder p {
    margin: 10px 0;
    line-height: 1.5;
}

.canvas-placeholder p:first-child {
    font-size: 1.2em;
    font-weight: 500;
    color: #555;
}

.canvas-placeholder small {
    color: #999;
    font-size: 0.9em;
}

.canvas-placeholder p small {
    font-size: 0.85em;
    color: #888;
}

/* Responsive styles */
/* Mobile-first responsive styles for system-controls */
@media (max-width: 600px) {
    .system-controls {
        flex-direction: column;
        width: 100%;
    }
    
    .system-controls button,
    .system-controls a {
        width: 100%;
        margin-bottom: 5px;
        justify-content: center;
    }
}

@media (min-width: 769px) {
    .main-content {
        flex-direction: row;
        padding: 20px 20px 20px; /* Added top padding */
        gap: 20px;
    }
    
    .chat-panel,
    .canvas-panel {
        flex: 1;
        min-height: 300px;
        max-height: calc(100vh - 120px);
        display: flex;
        flex-direction: column;
    }
}

@media (max-width: 768px) {
    .main-content {
        padding: 20px 10px 10px; /* Added top padding */
    }
    
    .chat-panel,
    .canvas-panel {
        max-width: 100%;
        width: 100%;
        margin-bottom: 10px;
        min-height: 300px;
        max-height: none;
    }
    
    #messages {
        max-height: none;
        flex: 1;
        padding: 10px;
    }
    
    #input-container {
        padding: 10px;
    }
    
    #input-container .input-row {
        flex-wrap: wrap;
    }
    
    #chatInput {
        width: 100%;
        margin-bottom: 8px;
    }
    
    .button-group {
        width: 100%;
        display: flex;
        gap: 8px;
    }
    
    #send-button {
        flex: 1;
    }
    
    #interrupt-button {
        flex: 1;
    }
    
    .header-buttons {
        flex-wrap: wrap;
        justify-content: flex-start;
        padding: 8px;
    }
    
    .subsystem-toggle {
        margin-bottom: 4px;
    }
    
    .debug-toggle {
        margin-bottom: 8px;
    }
}

@media (max-width: 768px) {
    .message {
        max-width: 90%;
    }

    .modal-content {
        width: 95%;
        height: 95vh;
        max-height: 95vh;
    }

    #debug-output,
    #results-output {
        max-height: calc(95vh - 60px);
    }
}

/* Floating button to jump back to the chat input */
#scroll-to-input {
    position: fixed;
    bottom: 80px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #0084ff;
    color: #fff;
    border: none;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    z-index: 1000;
}

#scroll-to-input.visible {
    display: flex;
}

/* Settings page tab buttons */
.settings-tabs button {
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 12px;
    color: #666;
    margin-left: 8px;
    transition: all 0.2s ease;
}
.settings-tabs button:hover {
    background: #e0e0e0;
}
.settings-tabs button.active {
    background: #007bff;
    color: #fff;
    border-color: #0056b3;
}
.settings-tab { display: none; }
.settings-tab.active { display: block; }

