/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --error-color: #ef4444;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --border-color: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
}

/* Screen Management */
.screen {
    display: none;
    height: 100vh;
}

.screen.active {
    display: flex;
}

/* Login Screen */
#loginScreen {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    flex-direction: column;
    position: relative;
}

/* Back to Apps Link - hidden when header is present */
.back-to-apps {
    display: none;
}

/* Header positioning in login screen */
#loginScreen #levocraft-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
}

/* Footer positioning in login screen */
#loginScreen #levocraft-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding-bottom: 1rem;
}

.login-container {
    background: var(--bg-primary);
    padding: 2.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    margin: 5rem 1rem 12rem 1rem;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

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

.btn-icon {
    background: transparent;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: var(--bg-tertiary);
}

/* Error Messages */
.error-message {
    color: var(--error-color);
    font-size: 0.9rem;
    margin-top: 1rem;
    text-align: center;
    display: none;
}

.error-message.active {
    display: block;
}

/* App Screen */
#appScreen {
    flex-direction: column;
}

/* Header */
.app-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    box-shadow: var(--shadow-sm);
}

.header-content {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

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

.user-display {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Main Container */
.app-container {
    display: flex;
    height: calc(100vh - 73px);
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* Conversations Sidebar */
.conversations-sidebar {
    width: 350px;
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    color: var(--text-primary);
}

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

/* Search Box */
.search-box {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.search-box input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.9rem;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.conversation-item:hover {
    background: var(--bg-secondary);
}

.conversation-item.active {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--primary-color);
}

.conversation-contact {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.conversation-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
}

.conversation-badge.mine {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.conversation-badge.assigned {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #3b82f6;
}

.conversation-badge.closed {
    background: #f3f4f6;
    color: #6b7280;
    border: 1px solid #d1d5db;
}

.conversation-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Messages Area */
.messages-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    position: relative;
}

.no-data {
    display: none;
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
}

.no-data.active {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.empty-state h2 {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    font-size: 1.1rem;
}

.conversation-view {
    display: none;
    flex-direction: column;
    height: 100%;
}

.conversation-view.active {
    display: flex;
}

.conversation-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
}

.contact-info h3 {
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.message-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    display: flex;
    margin-bottom: 0.5rem;
}

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

.message.inbound {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 1rem;
    position: relative;
}

.message.outbound .message-bubble {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 0.25rem;
}

.message.inbound .message-bubble {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-bottom-left-radius: 0.25rem;
    box-shadow: var(--shadow-sm);
}

.message-text {
    word-wrap: break-word;
    margin-bottom: 0.25rem;
}

.message-meta {
    font-size: 0.75rem;
    opacity: 0.7;
    display: flex;
    gap: 0.5rem;
}

/* Message Input */
.message-input-area {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    flex-shrink: 0;
}

#sendMessageForm {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

#messageInput {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    min-height: 80px;
    max-height: 150px;
}

#sendMessageForm .btn {
    align-self: flex-end;
    padding: 0.5rem 1.5rem;
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#sendMessageForm .btn {
    padding: 0.75rem 2rem;
    white-space: nowrap;
}

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

.loading-spinner.active {
    display: flex;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

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

.conversations-list::-webkit-scrollbar-track,
.messages-container::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

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

.conversations-list::-webkit-scrollbar-thumb:hover,
.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Variable Tags */
.variable-tag {
    display: inline-block;
    background: #fef3c7;
    color: #92400e;
    padding: 0.15rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.85rem;
    font-family: 'Courier New', monospace;
    font-weight: 600;
    border: 1px solid #fbbf24;
    margin: 0 0.25rem;
}

/* Assignment Badges */
.assignment-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.assignment-badge.assigned {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #3b82f6;
}

.assignment-badge.closed {
    background: #f3f4f6;
    color: #6b7280;
    border: 1px solid #d1d5db;
}

.assignment-badge.unassigned {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fbbf24;
}

/* Small Buttons */
.btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    border: none;
    cursor: pointer;
    border-radius: 0.375rem;
    font-weight: 500;
    transition: all 0.2s;
}

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

.btn-sm.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-sm.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-sm.btn-secondary:hover {
    background: #475569;
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .conversations-sidebar {
        width: 100%;
        height: 40%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .messages-area {
        height: 60%;
    }

    .message-bubble {
        max-width: 85%;
    }

    .header-content h1 {
        font-size: 1.25rem;
    }

    .user-display {
        display: none;
    }

    .login-container {
        padding: 2rem;
    }
}

@media (max-width: 480px) {
    body {
        overflow-x: hidden;
    }

    .app-header {
        padding: 0.75rem 1rem;
    }

    .sidebar-header,
    .conversation-item {
        padding: 0.75rem 1rem;
    }

    .message-input-area {
        padding: 0.75rem 1rem;
    }

    #sendMessageForm .btn {
        padding: 0.75rem 1.25rem;
    }

    .login-container {
        padding: 1.5rem;
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .login-header h1 {
        font-size: 1.5rem;
    }

    .back-to-apps {
        position: static;
        display: block;
        text-align: center;
        margin-bottom: 1rem;
    }

    #loginScreen {
        padding: 1rem;
    }
}

/* Contact Name Display */
.contact-name {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: normal;
    margin-top: 0.25rem;
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-content form {
    padding: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.modal-actions .btn {
    width: auto;
    min-width: 100px;
}
