/* ============================================
   CUSTOMER COMMUNICATION ROOM - STYLES
   Dark theme with modern aesthetics
   ============================================ */

/* CSS Variables */
:root {
    --bg-primary: #0f0f12;
    --bg-secondary: #1a1a21;
    --bg-tertiary: #242430;
    --bg-hover: #2a2a38;
    
    --text-primary: #f0f0f5;
    --text-secondary: #9898a8;
    --text-muted: #6a6a78;
    
    --accent-primary: #00d4aa;
    --accent-secondary: #00b894;
    --accent-glow: rgba(0, 212, 170, 0.2);
    
    --admin-bubble: #2d5a7b;
    --customer-bubble: #00d4aa;
    --customer-text: #0f0f12;
    
    --border-color: #2a2a38;
    --error-color: #ff6b6b;
    --warning-color: #ffc107;
    
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
}

/* App Container */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg-secondary);
}

@media (min-width: 840px) {
    #app {
        margin: 20px auto;
        height: calc(100vh - 40px);
        height: calc(100dvh - 40px);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-lg);
        overflow: hidden;
    }
}

/* States */
.state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 24px;
    text-align: center;
}

.state.hidden {
    display: none;
}

/* Loading State */
.loader {
    width: 48px;
    height: 48px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loading-state p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Invalid State */
.error-icon {
    color: var(--error-color);
    margin-bottom: 16px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

#invalid-state h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

#invalid-state p {
    color: var(--text-secondary);
    max-width: 300px;
    font-size: 0.95rem;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1rem;
}

.status-dot {
    width: 10px;
    height: 10px;
    background: var(--accent-primary);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--accent-glow);
    animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
    0%, 100% { box-shadow: 0 0 8px var(--accent-glow); }
    50% { box-shadow: 0 0 16px var(--accent-glow), 0 0 24px var(--accent-glow); }
}

.connection-status {
    font-size: 0.8rem;
    color: var(--accent-primary);
    padding: 4px 10px;
    background: var(--accent-glow);
    border-radius: var(--radius-full);
}

.connection-status.disconnected {
    color: var(--error-color);
    background: rgba(255, 107, 107, 0.2);
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: var(--bg-secondary);
    scroll-behavior: smooth;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 100%;
}

/* Message Bubbles */
.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: messageIn 0.3s ease;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.admin {
    align-self: flex-start;
}

.message.customer {
    align-self: flex-end;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.admin .message-bubble {
    background: var(--admin-bubble);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message.customer .message-bubble {
    background: var(--customer-bubble);
    color: var(--customer-text);
    border-bottom-right-radius: 4px;
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

.message.customer .message-time {
    text-align: right;
}

/* Empty State */
.empty-messages {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-muted);
    padding: 40px 20px;
    text-align: center;
}

.empty-messages svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-messages p {
    font-size: 0.95rem;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    width: fit-content;
    margin-top: 8px;
}

.typing-indicator.hidden {
    display: none;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Chat Footer */
.chat-footer {
    padding: 16px 20px;
    background: var(--bg-tertiary);
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    transition: border-color var(--transition-fast);
}

.input-wrapper:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    max-height: 150px;
    min-height: 24px;
    line-height: 1.5;
    padding: 4px 0;
}

#message-input::placeholder {
    color: var(--text-muted);
}

#message-input:focus {
    outline: none;
}

#send-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--accent-primary);
    color: var(--bg-primary);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

#send-button:hover:not(:disabled) {
    background: var(--accent-secondary);
    transform: scale(1.05);
}

#send-button:active:not(:disabled) {
    transform: scale(0.95);
}

#send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input-hint {
    display: flex;
    justify-content: flex-end;
    padding-top: 8px;
}

#char-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

#char-count.warning {
    color: var(--warning-color);
}

#char-count.error {
    color: var(--error-color);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--bg-hover);
}

/* Utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Mobile Adjustments */
@media (max-width: 480px) {
    .chat-header {
        padding: 14px 16px;
    }
    
    .messages-container {
        padding: 16px;
    }
    
    .message {
        max-width: 90%;
    }
    
    .chat-footer {
        padding: 12px 16px;
    }
}

/* System Message */
.system-message {
    text-align: center;
    padding: 8px 16px;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 8px 0;
}

/* Date Separator */
.date-separator {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 16px 0;
}

.date-separator::before,
.date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.date-separator span {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}