/* CSS Variables for Theming */
:root {
    --bg-color: #ffffff;
    --user-msg-color: #007bff;
    --sky-msg-color: #f0f0f0;
    --accent-color: #ff69b4;
    --text-color: #333333;
    --input-bg: #ffffff;
    --header-bg: #ffffff;
    --shadow: rgba(0, 0, 0, 0.1);
}

/* Modern Minimalist Theme */
.theme-modern {
    --bg-color: #f5f7fa;
    --user-msg-color: #007bff;
    --sky-msg-color: #ffffff;
    --accent-color: #007bff;
    --text-color: #2c3e50;
    --input-bg: #ffffff;
    --header-bg: #ffffff;
    --shadow: rgba(0, 0, 0, 0.08);
}

/* Dark Elegance Theme */
.theme-dark {
    --bg-color: #1a1a2e;
    --user-msg-color: #0f3460;
    --sky-msg-color: #16213e;
    --accent-color: #ff69b4;
    --text-color: #eaeaea;
    --input-bg: #16213e;
    --header-bg: #16213e;
    --shadow: rgba(255, 105, 180, 0.2);
}

/* Warm Intimate Theme */
.theme-warm {
    --bg-color: #fff5f0;
    --user-msg-color: #ff9a8b;
    --sky-msg-color: #ffeaa7;
    --accent-color: #fd79a8;
    --text-color: #5a4a42;
    --input-bg: #ffffff;
    --header-bg: #ffd7ba;
    --shadow: rgba(253, 121, 168, 0.15);
}

/* Sky Pink Theme */
.theme-pink {
    --bg-color: #ffe6f0;
    --user-msg-color: #ff69b4;
    --sky-msg-color: #ffb3d9;
    --accent-color: #ff1493;
    --text-color: #4a0e2e;
    --input-bg: #fff0f8;
    --header-bg: #ffcce6;
    --shadow: rgba(255, 20, 147, 0.2);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: all 0.3s ease;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: var(--input-bg);
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 10px 40px var(--shadow);
    max-width: 500px;
    width: 90%;
    animation: slideIn 0.3s ease;
}

.modal-content.settings-panel {
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-color);
    opacity: 0.6;
    transition: opacity 0.2s;
}

.close-btn:hover {
    opacity: 1;
}

.modal-content h2 {
    color: var(--text-color);
    margin-bottom: 1.5rem;
}

.modal-content input[type="password"] {
    width: 100%;
    padding: 0.8rem;
    border: 2px solid var(--accent-color);
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 1rem;
    background-color: var(--bg-color);
    color: var(--text-color);
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

.modal-buttons button {
    flex: 1;
    padding: 0.8rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-buttons button:first-child {
    background-color: var(--accent-color);
    color: white;
}

.modal-buttons button:last-child {
    background-color: #ddd;
    color: #333;
}

.modal-buttons button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.error-message {
    color: #e74c3c;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

/* Settings Panel */
.settings-section {
    margin-bottom: 2rem;
}

.settings-section h3 {
    color: var(--text-color);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
}

.theme-option {
    cursor: pointer;
    text-align: center;
    transition: transform 0.2s;
}

.theme-option:hover {
    transform: scale(1.05);
}

.theme-preview {
    width: 100%;
    height: 80px;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    border: 3px solid transparent;
    transition: border-color 0.2s;
}

.theme-option:hover .theme-preview {
    border-color: var(--accent-color);
}

.modern-preview {
    background: linear-gradient(135deg, #f5f7fa 0%, #007bff 100%);
}

.dark-preview {
    background: linear-gradient(135deg, #1a1a2e 0%, #ff69b4 100%);
}

.warm-preview {
    background: linear-gradient(135deg, #fff5f0 0%, #ff9a8b 100%);
}

.pink-preview {
    background: linear-gradient(135deg, #ffe6f0 0%, #ff69b4 100%);
}

.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.color-picker-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.color-picker-item label {
    font-size: 0.9rem;
    color: var(--text-color);
}

.color-picker-item input[type="color"] {
    width: 100%;
    height: 40px;
    border: 2px solid var(--accent-color);
    border-radius: 8px;
    cursor: pointer;
}

.btn-primary, .btn-danger {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
}

.btn-primary {
    background-color: var(--accent-color);
}

.btn-danger {
    background-color: #e74c3c;
}

.btn-primary:hover, .btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

/* Chat Container */
.chat-container {
    max-width: 900px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 40px var(--shadow);
}

/* Header */
.chat-header {
    background-color: var(--header-bg);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px var(--shadow);
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.sky-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-color), var(--user-msg-color));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
}

.header-info h1 {
    font-size: 1.5rem;
    color: var(--text-color);
}

.status-indicator {
    font-size: 0.9rem;
    color: #27ae60;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.mode-label {
    font-size: 0.9rem;
    color: var(--text-color);
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.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: 0.4s;
    border-radius: 24px;
}

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

input:checked + .slider {
    background-color: var(--accent-color);
}

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

.voice-toggle {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.3s;
    margin-right: 8px;
}

.voice-toggle:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.voice-toggle.active {
    background-color: rgba(74, 144, 226, 0.2);
}

.settings-icon {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    transition: transform 0.3s;
}

.settings-icon:hover {
    transform: rotate(90deg);
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    background-color: var(--bg-color);
}

.welcome-message {
    text-align: center;
    padding: 2rem;
    color: var(--text-color);
    opacity: 0.6;
}

.message {
    display: flex;
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease;
}

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

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

.message-bubble {
    max-width: 70%;
    padding: 0.8rem 1.2rem;
    border-radius: 18px;
    box-shadow: 0 2px 8px var(--shadow);
    word-wrap: break-word;
}

.message.user .message-bubble {
    background-color: var(--user-msg-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.sky .message-bubble {
    background-color: var(--sky-msg-color);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
}

.message-image {
    max-width: 100%;
    border-radius: 12px;
    margin-top: 0.5rem;
}

/* Input Container */
.input-container {
    background-color: var(--input-bg);
    padding: 1rem 1.5rem;
    box-shadow: 0 -2px 10px var(--shadow);
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    position: relative;
}

.character-counter {
    position: absolute;
    top: 0.5rem;
    right: 5rem;
    font-size: 0.8rem;
    color: var(--text-color);
    opacity: 0.6;
}

.character-counter.warning {
    color: #f39c12;
    opacity: 1;
}

.character-counter.danger {
    color: #e74c3c;
    opacity: 1;
    font-weight: bold;
}

#messageInput {
    flex: 1;
    padding: 0.8rem;
    border: 2px solid var(--accent-color);
    border-radius: 12px;
    font-size: 1rem;
    resize: none;
    max-height: 120px;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: inherit;
}

#messageInput:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 105, 180, 0.2);
}

.send-button {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-color), var(--user-msg-color));
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-button:hover:not(:disabled) {
    transform: scale(1.1);
    box-shadow: 0 4px 15px var(--shadow);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.send-icon {
    display: inline-block;
    transform: rotate(0deg);
}

/* Scrollbar Styling */
.messages-container::-webkit-scrollbar {
    width: 8px;
}

.messages-container::-webkit-scrollbar-track {
    background: var(--bg-color);
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--accent-color);
    border-radius: 4px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--user-msg-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .chat-container {
        max-width: 100%;
    }
    
    .header-right {
        gap: 0.5rem;
    }
    
    .mode-label {
        display: none;
    }
    
    .message-bubble {
        max-width: 85%;
    }
}

/* Delete Message Button */
.message {
    position: relative;
}

.delete-message-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.message:hover .delete-message-btn {
    opacity: 1;
}

.delete-message-btn:hover {
    background: rgba(255, 0, 0, 0.9);
}

.save-message-btn {
    position: absolute;
    top: 5px;
    right: 35px;
    background: rgba(0, 128, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.message:hover .save-message-btn {
    opacity: 1;
}

.save-message-btn:hover {
    background: rgba(0, 128, 0, 0.9);
}

/* Photo Request Container */
.photo-request-container {
    display: flex;
    gap: 10px;
    padding: 10px 20px;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    align-items: center;
}

.photo-request-container input {
    flex: 1;
    padding: 10px 15px;
    border: 2px solid var(--border-color);
    border-radius: 25px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
}

.photo-request-container input:focus {
    border-color: var(--accent-color);
}

.request-photo-btn {
    padding: 10px 20px;
    background: linear-gradient(135deg, #ff69b4, #ff1493);
    color: white;
    border: none;
    border-radius: 25px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.request-photo-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(255, 105, 180, 0.4);
}

.request-photo-btn:active {
    transform: translateY(0);
}


/* API Credentials Management */
.settings-note {
    color: var(--text-color);
    opacity: 0.7;
    font-size: 14px;
    margin-bottom: 15px;
}

#apiCredentialsList {
    margin: 15px 0;
}

.service-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 10px;
}

.service-info h4 {
    margin: 0 0 5px 0;
    color: var(--text-color);
}

.service-type {
    display: inline-block;
    padding: 2px 8px;
    background: var(--accent-color);
    color: white;
    border-radius: 12px;
    font-size: 12px;
    margin-right: 8px;
}

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
}

.status-connected {
    background: #4caf50;
    color: white;
}

.status-failed {
    background: #f44336;
    color: white;
}

.status-unknown {
    background: #9e9e9e;
    color: white;
}

.service-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

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

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

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--accent-color);
}

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

.btn-danger-small {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 5px;
}

.btn-danger-small:hover {
    opacity: 0.7;
}

.no-services, .auth-required {
    text-align: center;
    padding: 20px;
    color: var(--text-color);
    opacity: 0.6;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-color);
    font-weight: 500;
}

.form-group input, .form-group select {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 14px;
}

.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--accent-color);
}


/* Manual Image Generation */
.manual-image-container {
    display: none;
    gap: 10px;
    padding: 10px 20px;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    align-items: flex-start;
}

.manual-image-container textarea {
    flex: 1;
    padding: 10px 15px;
    border: 2px solid var(--accent-color);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--text-color);
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    min-height: 60px;
}

.manual-image-container textarea:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(255, 105, 180, 0.1);
}

.generate-image-btn {
    padding: 10px 20px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.generate-image-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 105, 180, 0.3);
}

.generate-image-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}
