/* Facebook Messenger Style Chat UI for Phuket Mobile Repair */
/* Mobile-first design matching Facebook Messenger aesthetic */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    /* Facebook Messenger Colors */
    --messenger-blue: #0084FF;
    --messenger-blue-dark: #0066CC;
    --messenger-gray: #E4E6EB;
    --messenger-gray-dark: #B0B3B8;
    --messenger-bg: #FFFFFF;
    --messenger-bg-light: #F0F2F5;
    --messenger-text: #1C1E21;
    --messenger-text-secondary: #65676B;
    --messenger-border: #E4E6EB;
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 12px;
    --spacing-lg: 16px;
    --spacing-xl: 20px;
    
    /* Safe areas for mobile */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

html {
    height: 100%;
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--messenger-bg-light);
    color: var(--messenger-text);
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
    margin: 0;
    padding: 0;
}

/* Prevent zoom on input focus (iOS) */
input, textarea, select {
    font-size: 16px;
}

/* Main Chat Container - Facebook Messenger Style */
.chat-container {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 100vh;
    height: 100dvh;
    max-width: 100%;
    margin: 0;
    background: var(--messenger-bg);
    position: relative;
    overflow: hidden;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Header - Messenger Style */
.chat-header {
    background: var(--messenger-blue);
    color: white;
    padding: calc(12px + var(--safe-top)) 16px 12px;
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 120;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    max-width: 100%;
}

.avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.header-text {
    flex: 1;
    min-width: 0;
}

.header-text h1 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 2px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-text .status {
    font-size: 13px;
    opacity: 0.9;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Messages Area - Messenger Style */
.chat-messages {
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
    padding-bottom: calc(20px + 70px); /* Space for input area */
    display: flex;
    flex-direction: column;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    position: relative;
    z-index: 1;
    min-height: 0;
    will-change: scroll-position;
    background: var(--messenger-bg-light);
    /* Hide scrollbar */
    -ms-overflow-style: none;
    scrollbar-width: none;
}

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

/* Message Styles - Messenger Bubble Style */
.message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    min-width: 50px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    opacity: 0;
    transform: translateY(10px);
    animation: messageSlideIn 0.3s ease-out forwards;
}

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

.user-message {
    align-self: flex-end;
    margin-left: auto;
    align-items: flex-end;
}

.bot-message {
    align-self: flex-start;
    margin-right: auto;
    align-items: flex-start;
}

.message-content {
    padding: 8px 12px;
    border-radius: 18px;
    line-height: 1.38;
    font-size: 15px;
    position: relative;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

/* User message (sent) - Blue bubble */
.user-message .message-content {
    background: var(--messenger-blue);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Bot message (received) - Gray bubble */
.bot-message .message-content {
    background: var(--messenger-gray);
    color: var(--messenger-text);
    border-bottom-left-radius: 4px;
}

.message-content p {
    margin: 0;
    padding: 0;
}

.message-content p + p {
    margin-top: 4px;
}

.message-time {
    font-size: 11px;
    color: var(--messenger-text-secondary);
    margin-top: 4px;
    padding: 0 8px;
    font-weight: 400;
}

.user-message .message-time {
    align-self: flex-end;
    text-align: right;
    color: rgba(255, 255, 255, 0.7);
}

.bot-message .message-time {
    align-self: flex-start;
    text-align: left;
}

/* Typing Indicator - Messenger Style */
.typing-indicator {
    padding: 8px 16px;
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
    z-index: 10;
    display: flex;
    align-items: center;
}

.typing-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
    background: var(--messenger-gray);
    padding: 8px 12px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--messenger-text-secondary);
    animation: messengerDotPulse 1.4s infinite ease-in-out both;
}

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

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

.typing-dots span:nth-child(3) {
    animation-delay: 0s;
}

@keyframes messengerDotPulse {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Area - Messenger Style */
.chat-input-area {
    background: var(--messenger-bg);
    border-top: 1px solid var(--messenger-border);
    padding: 8px 12px;
    padding-bottom: calc(8px + var(--safe-bottom));
    padding-left: calc(12px + var(--safe-left));
    padding-right: calc(12px + var(--safe-right));
    position: sticky;
    bottom: 0;
    z-index: 150;
    flex-shrink: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.05);
    align-self: end;
}

.chat-form {
    display: flex;
    gap: 8px;
    align-items: center;
    max-width: 100%;
}

.message-input {
    flex: 1;
    border: none;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 15px;
    font-family: inherit;
    outline: none;
    background: var(--messenger-gray);
    color: var(--messenger-text);
    resize: none;
    max-height: 100px;
    min-height: 36px;
    line-height: 1.38;
    transition: background 0.2s ease;
}

.message-input:focus {
    background: var(--messenger-bg);
    box-shadow: 0 0 0 1px var(--messenger-border);
}

.message-input::placeholder {
    color: var(--messenger-text-secondary);
}

.send-button {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 50%;
    background: var(--messenger-blue);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: none;
}

.send-button:hover {
    background: var(--messenger-blue-dark);
    transform: scale(1.05);
}

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

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.send-button svg {
    width: 18px;
    height: 18px;
    transform: rotate(-45deg);
}

/* PWA Install Prompt - Messenger Style */
.pwa-install-prompt {
    background: var(--messenger-bg);
    border-top: 1px solid var(--messenger-border);
    padding: 12px 16px;
    padding-bottom: calc(12px + var(--safe-bottom));
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    animation: slideUp 0.3s ease-out;
    display: none;
}

.pwa-install-prompt.show {
    display: flex;
}

.pwa-prompt-content {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 100%;
}

.pwa-prompt-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.pwa-prompt-text {
    flex: 1;
    min-width: 0;
}

.pwa-prompt-text strong {
    display: block;
    font-size: 15px;
    margin-bottom: 2px;
    color: var(--messenger-text);
    font-weight: 600;
}

.pwa-prompt-text p {
    font-size: 13px;
    color: var(--messenger-text-secondary);
    margin: 0;
}

.pwa-install-btn {
    background: var(--messenger-blue);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s ease;
}

.pwa-install-btn:hover {
    background: var(--messenger-blue-dark);
}

.pwa-dismiss-btn {
    background: transparent;
    border: none;
    color: var(--messenger-text-secondary);
    font-size: 18px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 50%;
    transition: background 0.2s ease;
}

.pwa-dismiss-btn:hover {
    background: var(--messenger-gray);
}

.chat-container.has-pwa-prompt .chat-input-area {
    padding-bottom: calc(8px + var(--safe-bottom) + 70px);
}

.chat-container.has-pwa-prompt .chat-messages {
    padding-bottom: calc(20px + 140px);
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Responsive Design */
@media (max-width: 374px) {
    .message {
        max-width: 85%;
    }
    
    .chat-messages {
        padding: 12px;
        padding-bottom: calc(12px + 70px);
    }
}

@media (min-width: 768px) {
    .chat-container {
        max-width: 600px;
        margin: 0 auto;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    }
    
    .message {
        max-width: 65%;
    }
    
    .chat-messages {
        padding: 20px;
        padding-bottom: calc(20px + 70px);
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    .chat-messages {
        padding-bottom: calc(12px + 70px);
    }
    
    .message-input {
        min-height: 32px;
        font-size: 14px;
    }
    
    .send-button {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }
}

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