:root {
    --primary-color: #007bff;
    --primary-dark: #0056b3;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --border-color: #dee2e6;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
    --border-radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
}

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

.screen.active {
    display: block;
}

/* Login Screen */
.login-container {
    padding: 2rem;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.app-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.logo-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.app-logo h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.app-logo p {
    opacity: 0.8;
    font-size: 1rem;
}

.login-form {
    background: rgba(255,255,255,0.1);
    padding: 2rem;
    border-radius: var(--border-radius);
    backdrop-filter: blur(10px);
    margin-bottom: 1rem;
}

.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.input-group input {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: var(--border-radius);
    background: rgba(255,255,255,0.9);
    font-size: 16px;
    transition: background 0.3s;
}

.input-group input:focus {
    background: white;
    outline: none;
}

.input-hint {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.8rem;
    opacity: 0.7;
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary:active {
    background: var(--primary-dark);
}

.btn-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.login-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
}

.checkbox-container {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.9rem;
}

.checkbox-container input {
    display: none;
}

.checkmark {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.5);
    border-radius: 3px;
    margin-right: 0.5rem;
    position: relative;
}

.checkbox-container input:checked + .checkmark {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.checkbox-container input:checked + .checkmark::after {
    content: '✓';
    position: absolute;
    color: white;
    font-size: 12px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.error-message {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
    padding: 1rem;
    border-radius: var(--border-radius);
    border: 1px solid rgba(220, 53, 69, 0.2);
    margin-top: 1rem;
    text-align: center;
}

/* Dashboard */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: white;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    height: 60px;
}

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

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

.app-header h2 {
    font-size: 1.2rem;
    font-weight: 600;
}

.operator-name {
    font-size: 0.9rem;
    color: var(--secondary-color);
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: var(--border-radius);
    transition: background 0.3s;
}

.icon-btn:active {
    background: var(--light-color);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-indicator.online {
    background: var(--success-color);
}

.status-indicator.offline {
    background: var(--secondary-color);
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    width: 300px;
    height: 100vh;
    background: white;
    box-shadow: var(--shadow);
    transition: left 0.3s;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.sidebar.active {
    left: 0;
}

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

.sidebar-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.sidebar-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.user-info {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

.user-details {
    flex: 1;
}

.user-details strong {
    display: block;
    margin-bottom: 0.25rem;
}

.status {
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    background: var(--light-color);
    color: var(--secondary-color);
}

.status.online {
    background: #d4edda;
    color: #155724;
}

.sidebar-menu {
    flex: 1;
    padding: 1rem 0;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.3s;
}

.menu-item.active {
    background: var(--light-color);
    border-left: 4px solid var(--primary-color);
}

.menu-item:active {
    background: var(--light-color);
}

.menu-icon {
    margin-right: 1rem;
    font-size: 1.2rem;
    width: 20px;
    text-align: center;
}

.badge {
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.8rem;
    margin-left: auto;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.btn-secondary {
    width: 100%;
    padding: 0.75rem;
    background: var(--light-color);
    color: var(--dark-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background 0.3s;
}

.btn-secondary:active {
    background: var(--border-color);
}

/* Main Content */
.main-content {
    height: calc(100vh - 60px);
    overflow-y: auto;
    background: white;
}

.tab-content {
    display: none;
    height: 100%;
}

.tab-content.active {
    display: block;
}

.tab-header {
    padding: 1.5rem 1rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.tab-header h3 {
    font-size: 1.3rem;
    font-weight: 600;
}

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

.chats-header h3 {
    font-size: 1.3rem;
    font-weight: 600;
}

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

.visitors-list {
    padding: 1rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--secondary-color);
}

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

.empty-state h4 {
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.visitor-card {
    background: white;
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--border-color);
}

.visitor-card:active {
    transform: scale(0.98);
}

.visitor-card.unread {
    border-left: 4px solid var(--primary-color);
    background: #f8f9ff;
}

.visitor-info {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.visitor-name {
    font-weight: 600;
    color: var(--dark-color);
}

.visitor-time {
    font-size: 0.8rem;
    color: var(--secondary-color);
}

.visitor-preview {
    color: var(--secondary-color);
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Chat History Tab */
.history-filters {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.filter-input {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    flex: 1;
    min-width: 120px;
}

.history-list {
    padding: 1rem;
}

/* Settings Tab */
.settings-section {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.settings-section h4 {
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--dark-color);
}

.setting-item {
    margin-bottom: 1rem;
}

.setting-item label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
}

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

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

/* Chat Window */
.chat-window-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    z-index: 2000;
    transform: translateX(100%);
    transition: transform 0.3s;
    display: flex;
    flex-direction: column;
}

.chat-window-overlay.active {
    transform: translateX(0);
}

.chat-window {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: white;
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 1rem;
    background: white;
    border-bottom: 1px solid var(--border-color);
    height: 60px;
}

.chat-user-info {
    flex: 1;
    margin: 0 1rem;
}

.chat-user-info strong {
    display: block;
    margin-bottom: 0.25rem;
}

.visitor-status {
    font-size: 0.8rem;
    color: var(--success-color);
}

.visitor-status.typing {
    color: var(--primary-color);
    font-style: italic;
}

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

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

.message {
    max-width: 85%;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
}

.message.visitor {
    background: white;
    margin-right: auto;
    border-bottom-left-radius: 5px;
    border: 1px solid var(--border-color);
}

.message.operator {
    background: var(--primary-color);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 5px;
}

.system-message {
    text-align: center;
    color: var(--secondary-color);
    margin: 1rem 0;
    font-size: 0.9rem;
}

.system-message p {
    margin-bottom: 0.25rem;
}

.system-message small {
    opacity: 0.7;
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 0.25rem;
    display: block;
}

.typing-indicator {
    padding: 0.5rem 1rem;
    color: var(--secondary-color);
    font-style: italic;
    font-size: 0.9rem;
}

.chat-input-area {
    padding: 1rem;
    background: white;
    border-top: 1px solid var(--border-color);
}

.input-container {
    display: flex;
    gap: 0.5rem;
}

.input-container input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 25px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s;
}

.input-container input:focus {
    border-color: var(--primary-color);
}

.send-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background 0.3s;
}

.send-btn:active {
    background: var(--primary-dark);
}

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

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

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

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        left: -100%;
    }
    
    .visitor-card {
        margin-bottom: 0.5rem;
    }
    
    .history-filters {
        flex-direction: column;
    }
    
    .filter-input {
        min-width: auto;
    }
}

/* Dark Theme Support */
@media (prefers-color-scheme: dark) {
    :root {
        --light-color: #2d3748;
        --dark-color: #f7fafc;
        --border-color: #4a5568;
    }
    
    body {
        background: #1a202c;
        color: #f7fafc;
    }
    
    .app-header,
    .sidebar,
    .visitor-card,
    .chat-header,
    .chat-input-area,
    .settings-section {
        background: #2d3748;
        border-color: #4a5568;
    }
    
    .chat-messages {
        background: #1a202c;
    }
    
    .message.visitor {
        background: #4a5568;
        color: #f7fafc;
        border-color: #4a5568;
    }
    
    .input-container input,
    .setting-input,
    .filter-input {
        background: #4a5568;
        border-color: #718096;
        color: #f7fafc;
    }
    
    .empty-state,
    .visitor-preview,
    .visitor-time {
        color: #a0aec0;
    }
}