:root {
    --primary-color: #4F46E5;
    --primary-hover: #4338ca;
    --bg-color: #F3F4F6;
    --white: #ffffff;
    --text-dark: #1F2937;
    --text-gray: #6B7280;
    --border-color: #E5E7EB;
    --success-color: #10B981;
    --error-color: #EF4444;
    --warning-color: #F59E0B;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    height: 100vh;
    overflow: hidden;
    color: var(--text-dark);
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* Auth Screen */
#auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-card {
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    width: 100%;
    max-width: 420px;
    overflow: hidden;
}

/* Auth Tabs */
.auth-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.auth-tab {
    flex: 1;
    padding: 16px;
    background: none;
    border: none;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-gray);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
}

.auth-tab:hover {
    color: var(--text-dark);
    background-color: #F9FAFB;
}

.auth-tab.active {
    color: var(--primary-color);
}

.auth-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background-color: var(--primary-color);
}

/* Auth Form */
.auth-form {
    padding: 30px;
}

.auth-header {
    margin-bottom: 25px;
    text-align: center;
}

.logo-circle {
    width: 60px;
    height: 60px;
    background: rgba(79, 70, 229, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 15px;
    color: var(--primary-color);
    font-size: 24px;
}

.auth-header h2 {
    margin: 0 0 8px;
    font-size: 22px;
    font-weight: 600;
}

.auth-header p {
    margin: 0;
    color: var(--text-gray);
    font-size: 14px;
}

.form-group {
    margin-bottom: 18px;
    text-align: left;
}

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

.input-wrapper {
    position: relative;
}

.input-wrapper i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-gray);
    font-size: 14px;
    pointer-events: none;
}

.input-wrapper input {
    width: 100%;
    padding: 12px 12px 12px 36px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.input-wrapper input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.input-wrapper input::placeholder {
    color: #9CA3AF;
}

/* Error Message */
.error-message {
    background-color: #FEF2F2;
    border: 1px solid #FEE2E2;
    color: var(--error-color);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
}

/* Password Strength */
.password-strength {
    margin-top: 8px;
}

.strength-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
}

.strength-segment {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: #E5E7EB;
    transition: background 0.2s;
}

.strength-text {
    font-size: 11px;
    font-weight: 500;
}

/* Primary Button */
.primary-btn {
    width: 100%;
    padding: 12px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.primary-btn:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.primary-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.primary-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-loading {
    display: flex;
    align-items: center;
}

/* Auth Switch Link */
.auth-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-gray);
}

.auth-switch a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* Chat Screen */
#chat-screen {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--white);
}

.chat-header {
    padding: 15px 20px;
    background-color: var(--white);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.agent-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-wrapper {
    position: relative;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.status-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #9CA3AF;
    border: 2px solid var(--white);
}

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

.agent-details {
    display: flex;
    flex-direction: column;
}

#agent-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-dark);
}

.agent-role {
    font-size: 12px;
    color: var(--text-gray);
}

.queue-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-gray);
    background: rgba(79, 70, 229, 0.08);
    border-radius: 999px;
    padding: 4px 12px;
    margin-top: 6px;
    width: fit-content;
}

.queue-indicator i {
    color: var(--primary-color);
}

/* Header Actions & User Menu */
.header-actions {
    position: relative;
}

.user-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--white);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    min-width: 180px;
    overflow: hidden;
    z-index: 100;
}

.user-menu-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-dark);
}

.user-menu-header i {
    font-size: 18px;
    color: var(--primary-color);
}

.user-menu button {
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    text-align: left;
    font-size: 14px;
    color: var(--text-gray);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
}

.user-menu button:hover {
    background-color: #F9FAFB;
    color: var(--error-color);
}

/* Messages Container */
#messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: #F9FAFB;
}

.welcome-message {
    text-align: center;
    color: var(--text-gray);
    font-size: 13px;
    margin-bottom: 10px;
}

.message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    box-shadow: var(--shadow-sm);
}

.message.sent {
    align-self: flex-end;
    background-color: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background-color: var(--white);
    color: var(--text-dark);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
}

.message p {
    margin: 0;
}

.message img {
    max-width: 100%;
    border-radius: 8px;
    display: block;
}

.message-time {
    display: block;
    font-size: 10px;
    margin-top: 6px;
    opacity: 0.7;
}

.message.sent .message-time {
    text-align: right;
}

/* Typing Indicator */
.typing-indicator {
    padding: 10px 20px;
    background: transparent;
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background-color: var(--text-gray);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
    opacity: 0.6;
}

.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Input Area */
.input-area {
    padding: 15px 20px;
    background: var(--white);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
    align-items: center;
}

.input-area .input-wrapper {
    flex: 1;
}

.input-area .input-wrapper i {
    display: none;
}

.input-area input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    background-color: #F9FAFB;
    font-size: 14px;
    transition: all 0.2s;
}

.input-area input:focus {
    outline: none;
    background-color: var(--white);
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
}

.icon-btn, .send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn {
    background-color: transparent;
    color: var(--text-gray);
}

.icon-btn:hover {
    background-color: #F3F4F6;
    color: var(--primary-color);
}

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

.send-btn:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
    transition: opacity 0.3s, transform 0.3s;
}

.toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
}

.toast.success {
    background-color: #ECFDF5;
    color: #065F46;
    border: 1px solid #A7F3D0;
}

.toast.error {
    background-color: #FEF2F2;
    color: #991B1B;
    border: 1px solid #FECACA;
}

.toast.info {
    background-color: #EFF6FF;
    color: #1E40AF;
    border: 1px solid #BFDBFE;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #9CA3AF;
}

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

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

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.message {
    animation: fadeIn 0.3s ease-out;
}

.auth-card {
    animation: fadeIn 0.4s ease-out;
}

/* Focus visible styles for accessibility */
button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Loading state */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Connection status indicator */
.connection-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-gray);
}

.connection-status.connected::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--success-color);
}

.connection-status.disconnected::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--error-color);
    animation: pulse 1.5s infinite;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-gray);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    margin: 0;
    font-size: 14px;
}

/* Responsive */
@media (max-width: 480px) {
    .auth-card {
        max-width: 100%;
        border-radius: 12px;
    }
    
    .auth-form {
        padding: 20px;
    }
    
    .message {
        max-width: 85%;
    }
    
    .chat-header {
        padding: 12px 16px;
    }
    
    .input-area {
        padding: 12px 16px;
    }
}

/* Print styles */
@media print {
    #auth-screen {
        display: none;
    }
    
    .input-area,
    .chat-header .header-actions {
        display: none;
    }
}

/* Lightbox */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
    cursor: zoom-out;
}

.lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
}

.lightbox-content img {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
    position: absolute;
    top: -40px;
    right: 0;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: background 0.2s;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Message Image Hover */
.message img {
    cursor: zoom-in;
    transition: transform 0.2s, box-shadow 0.2s;
}

.message img:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Read Status Icons */
.read-status {
    font-size: 10px;
    margin-left: 4px;
    opacity: 0.7;
}

.message.sent .read-status {
    color: rgba(255, 255, 255, 0.8);
}

/* Deleted Message */
.message.deleted {
    opacity: 0.6;
}

.deleted-message {
    font-style: italic;
    color: var(--text-gray);
}

/* Character Counter */
.char-counter {
    font-size: 11px;
    color: var(--text-gray);
    text-align: right;
    margin-top: 4px;
}

.char-counter.warning {
    color: var(--warning-color);
}

.char-counter.error {
    color: var(--error-color);
}

/* File Preview */
.file-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--bg-color);
    border-radius: 8px;
    margin-bottom: 10px;
}

.file-preview img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
}

.file-preview-info {
    flex: 1;
}

.file-preview-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dark);
}

.file-preview-size {
    font-size: 11px;
    color: var(--text-gray);
}

.file-preview-remove {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    color: var(--text-gray);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-preview-remove:hover {
    background: var(--border-color);
    color: var(--error-color);
}

/* Skeleton Loading */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-message {
    height: 60px;
    margin-bottom: 12px;
    border-radius: 16px;
}

.skeleton-message:nth-child(odd) {
    width: 70%;
    margin-left: auto;
}

.skeleton-message:nth-child(even) {
    width: 60%;
}

/* Improved Accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #0000EE;
        --text-dark: #000000;
        --text-gray: #333333;
        --border-color: #000000;
    }
    
    .message.sent {
        border: 2px solid white;
    }
    
    .message.received {
        border: 2px solid var(--text-dark);
    }
}

/* Focus Styles */
a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* Skip Link */
.skip-link {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-color);
    color: white;
    padding: 10px 20px;
    border-radius: 0 0 8px 8px;
    z-index: 9999;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
}

/* Better Touch Targets */
@media (pointer: coarse) {
    .icon-btn,
    .send-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    .auth-tab {
        min-height: 48px;
    }
    
    .primary-btn {
        min-height: 48px;
    }
}

