/* assets/css/chat-interface.css */

/* Touch-friendly improvements */
* {
    -webkit-tap-highlight-color: rgba(67, 97, 238, 0.2);
    -webkit-touch-callout: none;
}

button, select, input[type="checkbox"], input[type="range"] {
    touch-action: manipulation; /* Improves touch responsiveness */
}

.web-chat-section {
    padding: 4rem 0;
}

.chat-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
    background-color: var(--bg-light);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: var(--box-shadow);
}

/* API Key Section */
.api-key-section {
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.api-key-section label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.api-key-input-wrapper {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

#apiKeyInput {
    flex-grow: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-family: inherit;
}

#apiKeyInput:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.2);
}

.api-key-status {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-light);
}

.api-key-status.saved {
    color: var(--success-color);
    font-weight: 600;
}

/* Chat Interface */
.chat-interface {
    display: flex;
    flex-direction: column;
    height: 60vh; /* Adjust height as needed */
    min-height: 400px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1rem;
    background-color: var(--bg-color);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    max-width: 80%;
    word-wrap: break-word;
    line-height: 1.5;
}

.message.user {
    background-color: var(--primary-color);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 0;
}

.message.bot {
    background-color: var(--bg-light);
    color: var(--text-color);
    align-self: flex-start;
    border-bottom-left-radius: 0;
    white-space: pre-wrap; /* Preserve whitespace and newlines */
}

.message.system {
    background-color: transparent;
    color: var(--text-light);
    font-style: italic;
    text-align: center;
    font-size: 0.9rem;
    align-self: center;
    max-width: 100%;
}

.message.error {
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
    align-self: stretch;
    max-width: 100%;
}

.message.thinking p::after {
    content: '';
    display: inline-block;
    width: 5px;
    height: 5px;
    background-color: currentColor;
    border-radius: 50%;
    margin-left: 5px;
    animation: typing-dots 1s infinite step-end;
}

@keyframes typing-dots {
    0%, 20% { opacity: 0; }
    40% { opacity: 0.5; }
    60% { opacity: 1; }
}

.chat-input-area {
    display: flex;
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-light);
    gap: 0.5rem;
}

#userInput {
    flex-grow: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    resize: none;
    font-family: inherit;
    background-color: var(--input-bg);
    color: var(--text-color);
}

#userInput:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.2);
}

#sendMessageBtn {
    min-width: 80px;
}

/* Chat Settings */
.chat-settings {
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.chat-settings h3 {
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.setting-group label {
    font-weight: 600;
    color: var(--text-color);
}

.setting-group small {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
    margin-top: 0.25rem;
}

.setting-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-family: inherit;
}

.setting-group input[type="range"] {
    width: calc(100% - 50px);
}

.setting-group span {
    display: inline-block;
    min-width: 40px;
    text-align: right;
    font-weight: 600;
}

/* Rate Limit Indicator */
.rate-limit-indicator {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    text-align: center;
    font-weight: 600;
    font-size: 0.95rem;
    transition: color 0.3s ease;
    margin-top: 0.5rem;
}

/* Responsive adjustments */
@media (min-width: 992px) {
    .chat-container {
        grid-template-columns: 3fr 1fr; /* Main chat area and settings sidebar */
        gap: 2rem;
    }
    
    .api-key-section {
        grid-column: 1 / -1; /* Span across both columns */
    }

    .chat-interface {
        grid-column: 1 / 2;
        height: 70vh; /* Taller on larger screens */
    }

    .chat-settings {
        grid-column: 2 / 3;
        border-top: none;
        padding-top: 0;
        border-left: 1px solid var(--border-color);
        padding-left: 2rem;
    }
}

@media (max-width: 768px) {
    .chat-container {
        padding: 1rem;
    }
    
    .chat-interface {
        height: 50vh;
        min-height: 400px;
    }
    
    .message {
        max-width: 90%;
        font-size: 0.9rem;
    }
    
    .chat-settings {
        padding: 1rem;
    }
    
    .setting-group {
        margin-bottom: 1rem;
    }
    
    .setting-group label {
        font-size: 0.9rem;
    }
    
    .setting-group small {
        font-size: 0.75rem;
    }
    
    #userInput {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 80px;
    }
    
    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
    
    .api-key-input-wrapper {
        flex-direction: column;
    }
    
    .api-key-input-wrapper input {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .api-key-input-wrapper button {
        width: 100%;
    }
    
    #agentSettings {
        margin-left: 0 !important;
        padding: 0.75rem !important;
    }
    
    .modal-content {
        max-width: 95% !important;
        margin: 1rem !important;
        max-height: 90vh !important;
    }
}

@media (max-width: 480px) {
    .chat-interface {
        height: 60vh;
    }
    
    .chat-messages {
        padding: 0.75rem;
    }
    
    h3 {
        font-size: 1.1rem;
    }
    
    select, input[type="number"], input[type="password"] {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}
