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

body {
    font-family: 'SF Pro Display', 'SF Pro Text', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #000000;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin: 0;
    touch-action: pan-y;
    -webkit-text-size-adjust: 100%;
}

.chat-container {
    width: 100%;
    max-width: 393px; /* iPhone 14 Pro width */
    height: 852px; /* iPhone 14 Pro height */
    max-height: 100vh;
    background: #000000;
    border-radius: 0;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* iOS Status Bar */
.chat-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 54px;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 100;
    pointer-events: none;
}

/* Prevent pull-to-refresh on iOS */
.chat-container {
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: auto;
}

.chat-header {
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: white;
    padding: 54px 0 8px 0;
    border-bottom: 0.5px solid rgba(255, 255, 255, 0.1);
}

.header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px 8px 16px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #007AFF 0%, #0051D5 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-info {
    flex: 1;
}

.header-info h1 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 1px;
    letter-spacing: -0.4px;
}

.subtitle {
    font-size: 13px;
    opacity: 0.6;
    font-weight: 400;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 16px;
    background: #000000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    -webkit-overflow-scrolling: touch; /* iOS momentum scrolling */
    overscroll-behavior: contain;
}

.chat-messages::-webkit-scrollbar {
    display: none;
}

.message {
    display: flex;
    flex-direction: column;
    animation: slideIn 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    margin-bottom: 4px;
}

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

.message.sent {
    align-items: flex-end;
}

.message.received {
    align-items: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 20px;
    word-wrap: break-word;
    line-height: 1.35;
    position: relative;
    transform-origin: bottom;
}

.message.sent .message-bubble {
    background: #007AFF;
    color: white;
    border-bottom-right-radius: 6px;
    transform-origin: bottom right;
}

.message.received .message-bubble {
    background: #2C2C2E;
    color: white;
    border-bottom-left-radius: 6px;
    transform-origin: bottom left;
}

.message-bubble p {
    margin: 0;
    font-size: 17px;
    font-weight: 400;
    letter-spacing: -0.4px;
}

/* Message images */
.message-image {
    width: 100%;
    max-width: 250px;
    height: auto;
    border-radius: 12px;
    display: block;
    margin-bottom: 8px;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.05);
}

.message-bubble .message-image + p {
    margin-top: 0;
}

.message-time {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.4);
    margin-top: 3px;
    padding: 0 6px;
    font-weight: 400;
}

.quick-questions {
    padding: 12px 16px 8px 16px;
    background: #000000;
    border-top: 0.5px solid rgba(255, 255, 255, 0.1);
}

.quick-questions-label {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 8px;
    font-weight: 400;
}

.quick-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.quick-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    padding: 7px 12px;
    border-radius: 18px;
    font-size: 15px;
    color: #007AFF;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    font-weight: 400;
    letter-spacing: -0.3px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.quick-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.quick-btn:active {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(0.95);
}

.chat-input-container {
    display: flex;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid rgba(255, 255, 255, 0.1);
    gap: 8px;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    border: 1px solid rgba(255, 255, 255, 0.15);
    outline: none;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    font-size: 17px;
    font-family: 'SF Pro Text', -apple-system, BlinkMacSystemFont, sans-serif;
    color: white;
    letter-spacing: -0.4px;
    min-height: 36px;
    max-height: 100px;
    resize: none;
    line-height: 1.35;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.chat-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.chat-input:focus {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
}

.send-button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #007AFF;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

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

.send-button:hover {
    background: #0051D5;
}

.send-button:active {
    transform: scale(0.85);
    background: #0040AA;
}

.send-button:disabled {
    background: rgba(255, 255, 255, 0.15);
    cursor: not-allowed;
    transform: none;
    opacity: 0.5;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 10px 14px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* Responsive design */
@media (max-width: 393px) {
    body {
        padding: 0;
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
    
    .chat-container {
        max-width: 100vw;
        height: 100vh;
        height: -webkit-fill-available; /* iOS Safari fix */
        max-height: 100vh;
        max-height: -webkit-fill-available;
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    .chat-input-container {
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }
    
    /* iOS keyboard handling */
    .chat-messages {
        padding-bottom: 16px;
    }
}

/* Disable selection on interactive elements */
button, .quick-btn, .send-button {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Smooth animations for iOS */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Fix for iOS bounce effect */
html, body {
    position: fixed;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

body {
    overscroll-behavior: none;
}

/* Tapbacks styling */
.tapback-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.tapback-menu {
    position: fixed;
    background: rgba(28, 28, 30, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 18px;
    padding: 8px;
    display: flex;
    gap: 4px;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5),
                0 0 0 0.5px rgba(255, 255, 255, 0.1);
    opacity: 0;
    transform: scale(0.8) translateY(10px);
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    max-width: calc(100vw - 32px);
    flex-wrap: wrap;
}

.tapback-emoji-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
}

.tapback-emoji-btn:active {
    transform: scale(0.85);
    background: rgba(255, 255, 255, 0.15);
}

/* Tapback container */
.tapback-container {
    display: flex;
    gap: 4px;
    margin-top: 4px;
    flex-wrap: wrap;
    max-width: 200px;
}

.tapback-container.tapback-sent {
    justify-content: flex-end;
}

.tapback-container.tapback-received {
    justify-content: flex-start;
}

.tapback-item {
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 14px;
    padding: 4px 8px;
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    min-width: 32px;
    min-height: 28px;
}

.tapback-item:active {
    transform: scale(0.9) !important;
    background: rgba(255, 255, 255, 0.2);
}

/* Message with tapbacks needs spacing */
.message:has(.tapback-container) {
    margin-bottom: 8px;
}

/* Desktop preview frame */
@media (min-width: 394px) {
    html, body {
        position: static;
        overflow: visible;
        height: auto;
    }
    
    body {
        padding: 20px;
        height: 100vh;
        overscroll-behavior: auto;
    }
    
    .chat-container {
        border-radius: 40px;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8),
                    0 0 0 8px rgba(0, 0, 0, 0.6);
    }
    
    .tapback-emoji-btn:hover {
        background: rgba(255, 255, 255, 0.15);
        transform: scale(1.05);
    }
}
