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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f0f2f5;
    color: #111;
}

/* Login Screen */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
    background: white;
    padding: 3rem;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    text-align: center;
    min-width: 350px;
}

.login-box h1 {
    margin-bottom: 2rem;
    color: #333;
}

.btn-primary {
    background: #667eea;
    color: white;
    border: none;
    padding: 12px 32px;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-primary:hover {
    background: #5568d3;
}

.error-message {
    color: #e74c3c;
    margin-top: 1rem;
    font-size: 14px;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-header {
    background: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h1 {
    font-size: 20px;
    color: #333;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info span {
    font-weight: 500;
    color: #667eea;
}

.btn-secondary {
    background: #e0e0e0;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

.btn-secondary:hover {
    background: #d0d0d0;
}

/* Chat Layout */
.chat-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.panel {
    background: white;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
}

.panel-chat {
    width: 70%;
    border-right: 1px solid #e0e0e0;
}

.panel-accordion {
    width: 30%;
    border-right: none;
    overflow-y: auto;
}

.panel-header {
    padding: 1rem;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f9f9f9;
}

.panel-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.badge {
    background: #667eea;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
}

/* Accordion Styles */
.accordion-section {
    border-bottom: 1px solid #e0e0e0;
}

.accordion-header {
    padding: 1rem;
    background: #f9f9f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
}

.accordion-header:hover {
    background: #f0f0f0;
}

.accordion-header h2 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.accordion-arrow {
    font-size: 12px;
    transition: transform 0.3s;
    margin-left: 0.5rem;
}

.accordion-section.active .accordion-arrow {
    transform: rotate(-180deg);
}

.accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.accordion-section.active .accordion-content {
    max-height: calc(100vh - 300px);
    overflow-y: auto;
}

/* Conversation List */
.conversation-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    padding: 1rem;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.2s;
}

.conversation-item:hover {
    background: #f9f9f9;
}

.conversation-item.active {
    background: #e3f2fd;
    border-left: 3px solid #667eea;
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.conversation-phone {
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.conversation-time {
    font-size: 12px;
    color: #888;
}

.conversation-preview {
    font-size: 13px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
}

.unread-badge {
    background: #f44336;
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: bold;
}

.not-answered {
    font-size: 14px;
    margin-left: 4px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.status-badge {
    background: #4caf50;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
}

.status-badge.waiting {
    background: #ff9800;
}

/* Chat Area */
.chat-header {
    padding: 1rem;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f9f9f9;
}

.chat-info h2 {
    font-size: 16px;
    margin-bottom: 4px;
}

.chat-phone {
    font-size: 12px;
    color: #888;
}

.chat-actions {
    display: flex;
    gap: 0.5rem;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s;
}

.btn-assign {
    background: #4caf50;
    color: white;
}

.btn-assign:hover {
    background: #45a049;
}

.btn-release {
    background: #ff9800;
    color: white;
}

.btn-release:hover {
    background: #fb8c00;
}

.btn-close {
    background: #f44336;
    color: white;
}

.btn-close:hover {
    background: #e53935;
}

.btn-auto {
    background: #2196f3;
    color: white;
}

.btn-auto:hover {
    background: #1e88e5;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #e5ddd5;
}

.message {
    max-width: 60%;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    word-wrap: break-word;
}

.message.user {
    background: white;
    margin-right: auto;
    border-bottom-left-radius: 2px;
}

.message.operator, .message.bot, .message.model, .message.tool {
    background: #dcf8c6;
    margin-left: auto;
    border-bottom-right-radius: 2px;
}

.message.system {
    background: #e3f2fd;
    margin: 0 auto;
    font-style: italic;
    border-radius: 8px;
}

.message-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
    font-size: 11px;
    color: #666;
}

.message-origin {
    font-weight: 600;
}

.message-time {
    opacity: 0.7;
}

.message-text {
    font-size: 14px;
    line-height: 1.4;
}

.message-link {
    color: #667eea;
    text-decoration: none;
    cursor: pointer;
}

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

/* Message Input */
.message-input {
    padding: 1rem;
    background: #f9f9f9;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 0.5rem;
}

#input-text {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    resize: none;
}

#input-text:focus {
    outline: none;
    border-color: #667eea;
}

.btn-send {
    background: #667eea;
    color: white;
    border: none;
    padding: 0.75rem 2rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.3s;
}

.btn-send:hover {
    background: #5568d3;
}

.btn-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 2rem;
    color: #888;
    font-size: 14px;
}

/* Image Popup */
.image-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.image-popup img {
    max-width: 90%;
    max-height: 90%;
}

.close-popup {
    position: absolute;
    top: 20px;
    right: 20px;
    background: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

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

/* Responsive */
@media (max-width: 768px) {
    .chat-layout {
        flex-direction: column;
    }
    
    .panel-chat,
    .panel-accordion {
        width: 100%;
        height: 50%;
    }
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

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

.modal-header h2 {
    font-size: 20px;
    color: #333;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #888;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s;
}

.close-btn:hover {
    background: #f0f0f0;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.config-section {
    margin-bottom: 2rem;
}

.config-section h3 {
    font-size: 16px;
    margin-bottom: 0.5rem;
    color: #333;
}

.config-description {
    font-size: 14px;
    color: #666;
    margin-bottom: 1rem;
    line-height: 1.5;
}

.config-textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    min-height: 150px;
}

.config-textarea:focus {
    outline: none;
    border-color: #667eea;
}

.config-actions {
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.config-status {
    font-size: 14px;
    color: #4caf50;
}

/* Tabs */
.tabs-container {
    display: flex;
    background: white;
    border-bottom: 2px solid #e0e0e0;
    padding: 0 2rem;
    gap: 1rem;
}

.tab-button {
    background: none;
    border: none;
    padding: 1rem;
    font-size: 14px;
    cursor: pointer;
    color: #666;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
    font-weight: 500;
}

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

.tab-button.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

/* Admin Tabs */
.admin-tab {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

.admin-header {
    margin-bottom: 2rem;
}

.admin-header h2 {
    color: #333;
    margin-bottom: 1rem;
}

.search-users {
    margin-bottom: 1rem;
}

.search-input {
    width: 100%;
    max-width: 400px;
    padding: 0.75rem;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
}

.search-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.admin-content {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Prompts Container - Two Panel Layout */
/* Higher specificity to override .admin-tab padding and ensure flex layout.
   The prompts container uses a two-column layout with internal padding in child elements,
   so it needs padding: 0 unlike other admin tabs. */
.admin-tab.prompts-container {
    display: flex;
    padding: 0;
    overflow: hidden;
}

.prompts-sidebar {
    width: 33%;
    background: white;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.prompts-sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e0e0e0;
    background: #f9f9f9;
}

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

.prompts-list {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.btn-create-prompt {
    width: calc(100% - 3rem);
    margin: 1rem 1.5rem;
    padding: 0.75rem 1rem;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-create-prompt:hover {
    background: #5568d3;
}

.prompt-list-item {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.2s;
    background: white;
}

.prompt-list-item:hover {
    background: #f9f9f9;
}

.prompt-list-item.active {
    background: #e3f2fd;
    border-left: 3px solid #667eea;
}

.prompt-list-item-name {
    font-weight: 600;
    font-size: 14px;
    color: #333;
    margin-bottom: 0.25rem;
}

.prompt-list-item-preview {
    font-size: 12px;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.prompts-editor {
    width: 67%;
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.prompts-editor-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e0e0e0;
    background: #f9f9f9;
}

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

.prompts-editor-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 1.5rem;
}

.prompt-textarea {
    width: 100%;
    padding: 1rem;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-family: monospace;
    font-size: 14px;
    resize: none;
    flex: 1;
    margin-bottom: 1rem;
}

.prompt-textarea:focus {
    outline: none;
    border-color: #667eea;
}

.prompt-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.prompt-actions button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

.btn-save-prompt {
    background: #4caf50;
    color: white;
}

.btn-save-prompt:hover {
    background: #45a049;
}

.prompt-status {
    font-size: 14px;
    color: #4caf50;
}

/* Users List */
.users-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.users-section {
    background: white;
    border-radius: 6px;
    padding: 1rem;
    border-left: 4px solid #667eea;
}

.users-section h3 {
    color: #333;
    margin-bottom: 1rem;
    font-size: 14px;
}

.user-item {
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.user-item.unapproved {
    border-left: 4px solid #ff9800;
    background: #fff3e0;
}

.user-item.approved {
    border-left: 4px solid #4caf50;
}

.user-info-section {
    flex: 1;
}

.user-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 0.25rem;
}

.user-email {
    font-size: 13px;
    color: #666;
}

.user-roles {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.role-badge {
    background: #667eea;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.role-badge.admin {
    background: #ff9800;
}

.role-badge.operator {
    background: #2196f3;
}

.remove-role-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 12px;
}

.remove-role-btn:hover {
    opacity: 0.7;
}

.user-actions {
    display: flex;
    gap: 0.5rem;
}

.user-actions button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.3s;
    white-space: nowrap;
}

.btn-approve {
    background: #4caf50;
    color: white;
}

.btn-approve:hover {
    background: #45a049;
}

.btn-reject {
    background: #f44336;
    color: white;
}

.btn-reject:hover {
    background: #da190b;
}

.btn-make-admin {
    background: #ff9800;
    color: white;
}

.btn-make-admin:hover {
    background: #e68900;
}

.btn-make-operator {
    background: #2196f3;
    color: white;
}

.btn-make-operator:hover {
    background: #0b7dda;
}
