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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(to bottom, #1e1e1e 0%, #000000 100%);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin: 0;
}

.chat-container {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    max-height: 100vh;
    background-color: #000000;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.chat-header {
    background-color: #1e1e1e;
    border-bottom: 0.5px solid rgba(255, 255, 255, 0.1);
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

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

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

.contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 18px;
    flex-shrink: 0;
}

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

.contact-name {
    color: #ffffff;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.2;
}

.contact-status {
    color: #8e8e93;
    font-size: 13px;
    line-height: 1.2;
    margin-top: 2px;
}

.api-key-bar {
    background-color: #1e1e1e;
    border-bottom: 0.5px solid rgba(255, 255, 255, 0.1);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.api-key-bar.hidden {
    display: none;
}

.api-key-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.api-key-wrapper input {
    flex: 1;
    padding: 10px 14px;
    background-color: #2c2c2e;
    border: 0.5px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: #ffffff;
    font-size: 15px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    outline: none;
}

.api-key-wrapper input:focus {
    border-color: #007aff;
}

.api-key-wrapper input::placeholder {
    color: #8e8e93;
}

.api-key-wrapper button {
    padding: 10px 20px;
    background-color: #007aff;
    color: #ffffff;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    white-space: nowrap;
    flex-shrink: 0;
}

.api-key-wrapper button:hover {
    background-color: #0051d5;
}

.api-key-wrapper button:active {
    background-color: #0040a8;
}

.api-key-note {
    color: #8e8e93;
    font-size: 12px;
    line-height: 1.4;
    padding: 0 4px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
}

.messages-container::-webkit-scrollbar {
    width: 0;
    background: transparent;
}

.message-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 18px;
    word-wrap: break-word;
    position: relative;
    animation: slideIn 0.3s ease-out;
}

@media (min-width: 768px) {
    .message-bubble {
        max-width: 50%;
    }
}

@media (min-width: 1024px) {
    .message-bubble {
        max-width: 40%;
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-bubble.sent {
    background-color: #007aff;
    color: #ffffff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

.message-bubble.received {
    background-color: #2c2c2e;
    color: #ffffff;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message-text {
    font-size: 17px;
    line-height: 1.4;
    color: inherit;
    white-space: pre-wrap;
    word-break: break-word;
}

.message-time {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 4px;
    text-align: right;
}

.message-bubble.received .message-time {
    color: rgba(255, 255, 255, 0.5);
    text-align: left;
}

.input-container {
    background-color: #1e1e1e;
    border-top: 0.5px solid rgba(255, 255, 255, 0.1);
    padding: 8px 16px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    position: sticky;
    bottom: 0;
    z-index: 100;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background-color: #2c2c2e;
    border-radius: 20px;
    padding: 6px 6px 6px 16px;
    min-height: 44px;
}

.input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #ffffff;
    font-size: 17px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.4;
    padding: 8px 0;
}

.input-wrapper textarea::placeholder {
    color: #8e8e93;
}

.input-wrapper textarea::-webkit-scrollbar {
    width: 0;
    background: transparent;
}

.send-button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #007aff;
    border: none;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s, transform 0.1s;
    padding: 0;
}

.send-button:hover:not(:disabled) {
    background-color: #0051d5;
}

.send-button:active:not(:disabled) {
    transform: scale(0.95);
}

.send-button:disabled {
    background-color: #3a3a3c;
    cursor: not-allowed;
    opacity: 0.5;
}

.send-button svg {
    width: 18px;
    height: 18px;
}

.image-button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: transparent;
    border: none;
    color: #8e8e93;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.2s, transform 0.1s;
    padding: 0;
}

.image-button:hover {
    color: #ffffff;
}

.image-button:active {
    transform: scale(0.95);
}

.image-button svg {
    width: 20px;
    height: 20px;
}

.image-preview-container {
    display: flex;
    gap: 8px;
    padding: 8px 16px 0;
    flex-wrap: wrap;
    max-height: 200px;
    overflow-y: auto;
}

.image-preview-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    background-color: #2c2c2e;
    flex-shrink: 0;
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-image {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.6);
    border: none;
    color: #ffffff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.remove-image:hover {
    background-color: rgba(0, 0, 0, 0.8);
}

.message-image {
    margin-bottom: 8px;
    border-radius: 12px;
    overflow: hidden;
    max-width: 100%;
}

.message-image img {
    width: 100%;
    max-width: 300px;
    height: auto;
    display: block;
    border-radius: 12px;
}

.message-bubble.sent .message-image {
    align-self: flex-end;
}

.message-bubble.received .message-image {
    align-self: flex-start;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background-color: #2c2c2e;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    max-width: 75px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: #8e8e93;
    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;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.welcome-message {
    margin-top: auto;
}

/* Mobile optimizations */
@media (max-width: 500px) {
    .chat-container {
        max-width: 100%;
    }
    
    .message-bubble {
        max-width: 85%;
    }
    
    .input-container {
        padding-left: 12px;
        padding-right: 12px;
    }
}

/* Safe area for notched devices */
@supports (padding: max(0px)) {
    .input-container {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
    
    .chat-header {
        padding-top: max(12px, env(safe-area-inset-top));
    }
}

