/* Markdown list styling for chat messages */
.bot-message ul,
.bot-message ol {
    margin-left: 2em;
    margin-bottom: 1em;
    padding-left: 1.5em;
}
.bot-message ul {
    list-style-type: disc;
}
.bot-message ol {
    list-style-type: decimal;
}
.bot-message li {
    margin-bottom: 0.3em;
    line-height: 1.5;
}
:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --primary-light: #60a5fa;
    --accent: #0ea5e9;
    --accent-light: #38bdf8;
    --accent-dark: #0284c7;
    --dark: #111827;
    --light: #f8fafc;
    --grey: #64748b;
    --grey-light: #f1f5f9;
    --success: #10b981;
    --error: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
}

body {
    font-size: 16px;
    line-height: 1.6;
    color: var(--dark);
    background-color: var(--light);
    font-weight: 500;
    overflow: hidden;
}

/* Fix height and overflow issues */
.container {
    height: 100vh;
    overflow: hidden;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Hide header for iframe */
header {
    display: none;
}

/* Fix height and overflow issues */
.main-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* Fix height and overflow issues */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent container overflow */
    max-height: 100%; /* Ensure container doesn't exceed parent */
}

.options {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    background: linear-gradient(to right, var(--primary-dark), var(--primary));
    color: white;
}

.left-group {
    display: flex;
    align-items: center;
    gap: 15px;
}

.connection-status {
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.persona-select-compact {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background-color: rgba(255, 255, 255, 0.95);
    font-size: 0.95rem;
    min-width: 200px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.persona-select-compact:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.2);
}

@media (max-width: 768px) {
    .options {
        flex-direction: column;
        gap: 10px;
    }
    
    .left-group {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        gap: 8px;
    }
    
    .persona-select-compact {
        width: 100%;
        min-width: unset;
    }
    
    #new-chat {
        width: 100%;
    }
}

#persona-select {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background-color: rgba(255, 255, 255, 0.95);
    font-size: 0.95rem;
    min-width: 200px;
    cursor: pointer;
}

/* Fix height and overflow issues */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    min-height: 0; /* Allow content to shrink if needed */
    background-image: 
        linear-gradient(90deg, rgba(37, 99, 235, 0.05) 1px, transparent 1px),
        linear-gradient(180deg, rgba(37, 99, 235, 0.05) 1px, transparent 1px);
    background-size: 100px 100px;
    border: 2px solid var(--primary); /* Add border */
    margin: 10px;  /* Add margin */
    border-radius: 8px;  /* Round corners */
}

/* Enhanced message styling */
.message {
    margin-bottom: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    max-width: 85%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.user-message {
    background: linear-gradient(to right, var(--primary), var(--primary-dark));
    color: white;
    margin-left: auto;
}

.bot-message {
    background: white;
    border: 1px solid var(--grey-light);
    margin-right: auto;
}

/* Fix height and overflow issues */
.input-area {
    flex-shrink: 0; /* Prevent input area from shrinking */
    background: white;
    border-top: 1px solid var(--grey-light);
    padding: 10px;
}

.input-container {
    display: flex;
    gap: 10px;
}

#user-input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid var(--primary);
    border-radius: 8px;
    font-size: 1rem;
    resize: none;
    background-color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#user-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}

#send-btn {
    background: linear-gradient(to right, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0 20px;
    font-weight: 600;
    transition: all 0.3s ease;
}

#send-btn:hover:not([disabled]) {
    background: linear-gradient(to right, var(--accent), var(--accent-dark));
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

#new-chat {
    background: linear-gradient(to right, var(--accent), var(--accent-dark));
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-weight: 600;
}

/* Hide debug panel in iframe */
.debug-panel, #debug-toggle {
    display: none !important;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 16px;
    background-color: var(--bot-bg-color);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    margin-bottom: 15px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: var(--primary-color);
    border-radius: 50%;
    display: inline-block;
    animation: bounce 1.3s ease infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* Debug Panel Styles */
.debug-panel {
    flex: 0 0 300px;
    display: flex;
    flex-direction: column;
    background: #f5f5f5;
    border-left: 1px solid #ddd;
    overflow: hidden;
    max-height: 100%; /* Ensure it doesn't overflow its container */
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: #333;
    color: white;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.debug-content {
    flex: 1;
    overflow-y: auto; /* Changed from 'hidden' to 'auto' to enable vertical scrolling */
    padding: 5px;
    max-height: calc(100vh - 200px); /* Set a reasonable max height */
}

.debug-box {
    padding: 5px;
    margin-bottom: 10px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 100%; /* Ensure it uses full available height */
}

.scroll-box {
    max-height: none;
    height: calc(100% - 10px);
    overflow-y: auto; /* Ensure vertical scrolling is enabled */
}

.debug-actions {
    padding: 10px;
    border-top: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    flex-shrink: 0; /* Prevent footer from shrinking */
}

/* Fix for debug log container */
#debug-log {
    max-height: calc(100vh - 250px); /* Limit height to prevent overflow */
    overflow-y: auto; /* Enable vertical scrolling */
    display: flex;
    flex-direction: column;
}

/* Add nice scrollbar styling for better visibility */
.debug-content::-webkit-scrollbar,
.debug-box::-webkit-scrollbar,
#debug-log::-webkit-scrollbar {
    width: 8px;
}

.debug-content::-webkit-scrollbar-track,
.debug-box::-webkit-scrollbar-track,
#debug-log::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.debug-content::-webkit-scrollbar-thumb,
.debug-box::-webkit-scrollbar-thumb,
#debug-log::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.debug-content::-webkit-scrollbar-thumb:hover,
.debug-box::-webkit-scrollbar-thumb:hover,
#debug-log::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Error message styling */
.error-message {
    background-color: #fff0f0;
    color: #e74c3c;
    border: 1px solid #ffcccc;
    border-left: 4px solid #e74c3c;
    font-size: 0.9em;
    text-align: center;
    margin: 10px auto;
    max-width: 90%;
    padding: 8px 12px;
    border-radius: 6px;
    
    /* Make error messages stand out more distinctly */
    font-weight: bold;
    opacity: 0.9;
    animation: fadeOut 5s forwards; /* Faster fade out for usability */
    position: relative;
    padding-left: 30px; /* Make room for icon */
}

/* Add warning icon to error messages */
.error-message::before {
    content: "⚠️";
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
}

@keyframes fadeOut {
    0% { opacity: 0.9; }
    70% { opacity: 0.9; }
    100% { opacity: 0.5; }
}

@media (max-width: 992px) {
    .main-container {
        flex-direction: column;
    }
    
    .debug-panel {
        flex: 0 0 auto;
        max-height: 400px;
    }
}

/* Responsive adjustments for various screen heights */
@media (max-height: 600px) {
    header {
        margin-bottom: 10px;
        padding-bottom: 5px;
    }
    
    .input-area {
        padding: 8px;
    }
    
    .message {
        margin-bottom: 10px;
        padding: 8px 12px;
    }
}

@media (max-height: 500px) {
    .chat-container {
        min-height: 200px;
    }
    
    .chat-messages {
        min-height: 100px;
    }
}

/* Production-specific styles */
.production .endpoint-toggle {
    display: none !important;
}

.production .tabs {
    display: none !important;
}

.system-message {
    font-size: 0.9em;
    margin-bottom: 20px;
    padding: 10px;
}

.production .system-message pre {
    display: none;
}

/* Location display styles */
.location-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 15px;
    font-size: 0.9em;
    color: var(--text-color);
}

.status-label {
    font-weight: bold;
}

#user-location {
    color: var(--primary-color);
    font-style: italic;
}
