* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
}

/* Main Layout - Three Column Grid */
.main-layout {
    display: grid !important;
    grid-template-columns: 320px 1fr 300px;
    grid-template-rows: 1fr;
    grid-template-areas: "sidebar chat right-panel";
    height: 100vh;
    max-height: 100vh;
    gap: 15px;
    padding: 15px;
    overflow: hidden;
}

.sidebar { grid-area: sidebar; }
.chat-area { 
    grid-area: chat; 
    overflow: hidden; /* Allow chat container to handle scrolling internally */
}
.right-panel { grid-area: right-panel; }

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

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

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

/* Left Sidebar Styles */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    min-height: 0; /* Fix for Firefox */
}

.sidebar-section {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.sidebar-section h2, .sidebar-section h3 {
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 16px;
    font-weight: 600;
}

.sidebar-section h2 {
    font-size: 18px;
}

/* Model Selection */
.model-selector-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#model-selector {
    width: 100%;
    padding: 12px;
    border: 2px solid #e1e8ed;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    transition: border-color 0.2s;
}

#model-selector:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.model-details {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 6px;
    margin-top: 8px;
}

.cache-indicator {
    font-size: 18px;
    min-width: 24px;
    text-align: center;
}

.model-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 12px;
    color: #666;
}

/* System Prompt */
#system-prompt {
    width: 100%;
    padding: 12px;
    border: 2px solid #e1e8ed;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    min-height: 80px;
    transition: border-color 0.2s;
}

#system-prompt:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.preset-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 12px;
}

.preset-btn {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.preset-btn:hover {
    background: #3498db;
    color: white;
    border-color: #3498db;
}

/* Inference Parameters */
.param-group {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.param-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.param-item label {
    font-size: 13px;
    font-weight: 500;
    color: #555;
}

.param-item input[type="number"] {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.param-item input[type="range"] {
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
}

.param-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #3498db;
    cursor: pointer;
}

.param-item span {
    font-size: 12px;
    color: #666;
    margin-left: 5px;
}

/* Center Chat Area */
.chat-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    overflow: hidden;
    min-height: 0; /* Fix for Firefox */
}

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

.chat-header h1 {
    font-size: 20px;
    color: #2c3e50;
}

.status-text {
    font-size: 14px;
    color: #666;
}

#chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 0; /* Fix for Firefox flexbox scrolling */
}

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background: #3498db;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: #f8f9fa;
    color: #333;
    border-bottom-left-radius: 4px;
}

.message.system {
    align-self: center;
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
    font-size: 14px;
    font-style: italic;
}

.input-area {
    padding: 20px;
    border-top: 1px solid #e1e8ed;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#user-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e1e8ed;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 60px;
    max-height: 120px;
}

#user-input:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.input-actions {
    display: flex;
    gap: 8px;
}

#send-button, #clear-chat {
    padding: 12px 20px;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

#send-button {
    background: #3498db;
    color: white;
}

#send-button:hover:not(:disabled) {
    background: #2980b9;
}

#send-button:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

#clear-chat {
    background: #6c757d;
    color: white;
}

#clear-chat:hover {
    background: #5a6268;
}

/* Right Panel */
.right-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    min-height: 0; /* Fix for Firefox */
}

.panel-section {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.panel-section h3 {
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 16px;
    font-weight: 600;
}

.cache-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 15px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 6px;
}

.stat-label {
    font-size: 13px;
    color: #666;
    font-weight: 500;
}

.stat-value {
    font-size: 14px;
    font-weight: 600;
    color: #2c3e50;
}

.model-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.model-actions button {
    padding: 10px 16px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #fff;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

#refresh-cache:hover {
    background: #3498db;
    color: white;
    border-color: #3498db;
}

#clear-cache {
    background: #dc3545;
    color: white;
    border-color: #dc3545;
}

#clear-cache:hover {
    background: #c82333;
}

.metrics-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.metric {
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    text-align: center;
}

.metric-label {
    display: block;
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.metric-value {
    font-size: 16px;
    font-weight: 600;
    color: #2c3e50;
}

/* Tools Panel Styles */
.tools-section {
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
}

.tools-status {
    padding: 8px 12px;
    border-radius: 6px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 12px;
}

.tools-status.enabled {
    background: #d5f5e3;
    color: #27ae60;
    border: 1px solid #c3e6cb;
}

.tools-status.disabled {
    background: #f8d7da;
    color: #dc3545;
    border: 1px solid #f5c6cb;
}

.tools-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 15px;
}

.tool-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #e9ecef;
    transition: all 0.2s ease;
}

.tool-item:hover {
    background: #e9ecef;
    border-color: #dee2e6;
}

.tool-item input[type="checkbox"] {
    margin: 2px 0 0 0;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.tool-label {
    flex: 1;
    font-weight: 600;
    font-size: 14px;
    color: #2c3e50;
    cursor: pointer;
    margin-bottom: 4px;
    display: block;
}

.tool-description {
    font-size: 12px;
    color: #6c757d;
    line-height: 1.4;
    margin-bottom: 4px;
}

.tool-status {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.tool-status.enabled {
    background: #d5f5e3;
    color: #27ae60;
}

.tool-status.disabled {
    background: #f8d7da;
    color: #dc3545;
}

.tools-info {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
}

.tools-info h4 {
    font-size: 14px;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 10px;
}

.tools-description p {
    font-size: 12px;
    color: #6c757d;
    margin-bottom: 10px;
    line-height: 1.4;
}

.tools-description ul {
    margin-left: 20px;
    margin-bottom: 10px;
}

.tools-description li {
    font-size: 12px;
    color: #6c757d;
    margin-bottom: 5px;
    line-height: 1.4;
}

.tool-usage {
    margin-top: 10px;
    padding: 10px;
    background: #e9ecef;
    border-radius: 4px;
    border-left: 4px solid #3498db;
}

.tool-usage h5 {
    font-size: 12px;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 8px;
}

.tool-usage p {
    font-size: 11px;
    color: #6c757d;
    font-style: italic;
    margin-bottom: 4px;
    line-height: 1.4;
}

/* Tool Result Styling in Chat */
.message .tool-result {
    background: #e9ecef;
    border-radius: 4px;
    padding: 8px 12px;
    margin: 8px 0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 11px;
    border-left: 3px solid #3498db;
}

.message .tool-result .tool-result-title {
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 4px;
    font-family: inherit;
}

.message .tool-result .tool-result-content {
    color: #495057;
    white-space: pre-wrap;
    word-break: break-word;
}

.message .tool-result .tool-result-link {
    color: #3498db;
    text-decoration: none;
}

.message .tool-result .tool-result-link:hover {
    text-decoration: underline;
}

/* Utility Classes */
.loading {
    color: #7f8c8d;
    font-style: italic;
}

.error {
    color: #e74c3c;
    background-color: #fadbd8;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 10px;
}

.success {
    color: #27ae60;
    background-color: #d5f5e3;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 10px;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 280px 1fr 280px;
        gap: 12px;
        padding: 12px;
    }
}

@media (max-width: 1024px) {
    .main-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto auto;
        grid-template-areas: 
            "sidebar"
            "chat"
            "right-panel";
        gap: 15px;
        padding: 15px;
    }
    
    .sidebar, .right-panel {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    .main-layout {
        gap: 10px;
        padding: 10px;
    }
    
    .sidebar-section, .panel-section {
        padding: 15px;
    }
    
    .chat-header {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .input-area {
        flex-direction: column;
        gap: 10px;
    }
    
    .preset-buttons {
        grid-template-columns: 1fr 1fr;
    }
    
    .message {
        max-width: 90%;
    }
}

@media (max-width: 480px) {
    .preset-buttons {
        grid-template-columns: 1fr;
    }
    
    .param-item input[type="range"] {
        height: 6px;
    }
    
    .param-item input[type="range"]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }
}
