* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body, html {
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #f5f5f5;
}

.chat-fullscreen {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    background: white;
}

.chat-interface {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.chat-header {
    background: linear-gradient(135deg, #0084ff 0%, #00c6ff 100%);
    color: white;
    padding: 16px 20px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 10;
}

.header-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.header-info h3 {
    font-size: 18px;
    font-weight: 600;
}

.ai-badge {
    background: rgba(255,255,255,0.2);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    backdrop-filter: blur(5px);
}

.header-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    opacity: 0.9;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4caf50;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.messages-container {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f0f2f5;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 20px;
    animation: fadeIn 0.3s ease;
    word-wrap: break-word;
    position: relative;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
    background: #0084ff;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.ai {
    align-self: flex-start;
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message.agent {
    align-self: flex-start;
    background: #e3f2fd;
    color: #1565c0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message-content {
    font-size: 15px;
    line-height: 1.4;
}

.message-time {
    font-size: 10px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

.agent-name {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #666;
}

.message.agent .agent-name {
    color: #1565c0;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 20px;
    width: fit-content;
    margin-left: 16px;
    margin-bottom: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

.typing-text {
    margin-left: 8px;
    font-size: 13px;
    color: #666;
}

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.chat-input-container {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e0e0e0;
    align-items: flex-end;
}

.chat-input-container textarea {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    resize: none;
    font-family: inherit;
    font-size: 15px;
    max-height: 100px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.3s;
}

.chat-input-container textarea:focus {
    border-color: #0084ff;
}

.chat-input-container textarea:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}

.chat-input-container button {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: #0084ff;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-input-container button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-input-container button:not(:disabled):hover {
    background: #0073e6;
    transform: scale(1.05);
}

.chat-input-container button svg {
    width: 20px;
    height: 20px;
}

/* Name Modal */
.name-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 24px;
    padding: 24px;
    width: 100%;
    max-width: 320px;
    animation: slideUp 0.3s ease;
}

.modal-content h3 {
    margin-bottom: 8px;
    color: #333;
}

.modal-content p {
    color: #666;
    margin-bottom: 20px;
    font-size: 14px;
}

.modal-content input {
    width: 100%;
    padding: 14px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    font-size: 16px;
    margin-bottom: 16px;
    outline: none;
}

.modal-content input:focus {
    border-color: #0084ff;
}

.modal-buttons {
    display: flex;
    gap: 12px;
}

.modal-buttons button {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

#saveNameBtn {
    background: #0084ff;
    color: white;
}

#skipNameBtn {
    background: #f0f0f0;
    color: #666;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Mobile Optimizations */
@media (max-width: 480px) {
    .message {
        max-width: 90%;
    }
    
    .chat-header {
        padding: 12px 16px;
    }
    
    .messages-container {
        padding: 12px;
    }
    
    .chat-input-container {
        padding: 8px 12px;
    }
}

/* iPhone Safe Area Support */
@supports (padding: max(0px)) {
    .chat-header {
        padding-top: max(16px, env(safe-area-inset-top));
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
    
    .chat-input-container {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
}

/* ===== MOBILE FIXES - COMPLETE OVERHAUL ===== */
@media (max-width: 768px) {
    html, body {
        height: 100%;
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
    
    .chat-fullscreen {
        height: 100dvh;
        width: 100vw;
        display: flex;
        flex-direction: column;
        background: white;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    .chat-interface {
        display: flex;
        flex-direction: column;
        height: 100%;
        width: 100%;
    }
    
    .chat-header {
        flex-shrink: 0;
        padding: 12px 16px;
        padding-top: max(12px, env(safe-area-inset-top));
    }
    
    .messages-container {
        flex: 1 1 auto;
        overflow-y: auto;
        padding: 12px 12px 8px 12px;
        min-height: 0;
        height: auto;
    }
    
    .typing-indicator {
        flex-shrink: 0;
        margin: 0 16px 8px 16px;
    }
    
    .chat-input-container {
        flex-shrink: 0;
        display: flex;
        gap: 8px;
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        background: white;
        border-top: 1px solid #e0e0e0;
        width: 100%;
        box-sizing: border-box;
    }
    
    .chat-input-container textarea {
        flex: 1;
        min-width: 0;
        padding: 12px 16px;
        font-size: 16px;
        border: 1px solid #ddd;
        border-radius: 24px;
        background: #f8f9fa;
        resize: none;
        max-height: 100px;
        line-height: 1.4;
    }
    
    .chat-input-container button {
        width: 48px;
        height: 48px;
        flex-shrink: 0;
        border: none;
        border-radius: 50%;
        background: #0084ff;
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }
    
    .chat-input-container button svg {
        width: 22px;
        height: 22px;
        fill: white;
    }
    
    .message {
        max-width: 85%;
        margin-bottom: 4px;
    }
    
    .message.user {
        align-self: flex-end;
    }
    
    .message.ai, .message.agent {
        align-self: flex-start;
    }
}

/* iPhone specific fixes */
@supports (-webkit-touch-callout: none) {
    .chat-fullscreen {
        height: -webkit-fill-available;
    }
    
    .chat-input-container {
        padding-bottom: max(10px, constant(safe-area-inset-bottom));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
}

/* Extra small phones */
@media (max-width: 380px) {
    .chat-input-container {
        padding: 8px 8px;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
    
    .chat-input-container textarea {
        padding: 10px 12px;
        font-size: 15px;
    }
    
    .chat-input-container button {
        width: 42px;
        height: 42px;
    }
}

/* Logo and header styling */
.logo-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-emoji {
    font-size: 24px;
    background: rgba(255, 255, 255, 0.2);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.header-info h3 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

/* If you want to use an image logo instead of emoji */
.logo-image {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}
