/* Chat Conversation Styles */

/* Chat Header — grouped bar (back + peer) so RTL/LTR stay compact, no empty gap.
   On phones (<= 600px): full-width edge-to-edge so the header doesn't appear as a
   floating bar in the middle of wider phones (iPhone Plus/Pro Max ≈ 428–430px).
   On tablet/desktop (> 600px): capped at 400px and centered, matching the
   conversation-shell preview width. */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    padding: 10px 14px;
    padding-top: max(10px, env(safe-area-inset-top, 0px));
    min-height: 52px;
    background-color: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.06);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
    z-index: 1000;
    box-sizing: border-box;
}

@media (min-width: 601px) {
    .chat-header {
        width: 400px;
        max-width: 400px;
        margin: 0 auto;
    }
}

.back-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    font-size: 18px;
    color: #64748b;
    cursor: pointer;
    padding: 0;
    border-radius: 50%;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.back-btn:hover {
    background-color: #f1f5f9;
    color: #334155;
}

.chat-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.chat-user-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e2e8f0;
    flex-shrink: 0;
    display: block;
}

.chat-online-dot--header {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.35);
    z-index: 2;
}

[dir='rtl'] .chat-online-dot--header {
    right: auto;
    left: 0;
}

.chat-user-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.user-name {
    font-size: 16px;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-status {
    font-size: 12px;
    font-weight: 500;
    color: #64748b;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.header-logo {
    height: 28px;
    width: auto;
    max-width: 100px;
    object-fit: contain;
}

/* Chat Messages Container — top padding clears fixed header + safe area */
.chat-messages {
    padding: calc(88px + env(safe-area-inset-top, 0px)) 12px calc(112px + env(safe-area-inset-bottom, 0px));
    background-color: #f1f5f9;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Message Styles */
.message {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 10px;
    width: fit-content;
    max-width: calc(100% - 24px);
    animation: messageSlideIn 0.3s ease-out;
    margin-inline: 12px;
    align-self: flex-start;
}

.message.sent {
    flex-direction: row-reverse;
    align-self: flex-end;
}

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

[dir="rtl"] .message.sent {
    align-self: flex-start;
}

[dir="rtl"] .message.received {
    align-self: flex-end;
}

.message-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e9ecef;
    flex-shrink: 0;
    align-self: flex-end;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.message.sent .message-avatar {
    border-color: rgba(233, 30, 99, 0.35);
}

/* Bubble width:
   - Caps at 380px on tablets/large phones so very long messages stay readable.
   - calc(100vw - 96px) reserves safe room for avatar (38px) + gap (10px) +
     side margins (24px) + breathing room, so the bubble never overflows on
     small phones (iPhone SE 320px → ~224px max).
   Result: 280–310px on Plus/Pro Max instead of the old 280px hard cap. */
.message-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    max-width: min(380px, calc(100vw - 96px));
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    line-height: 1.4;
}

.message.sent .message-bubble {
    background-color: #e91e63;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received .message-bubble {
    background-color: #ffffff;
    color: #0f172a;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .message.sent .message-bubble {
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .message.received .message-bubble {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 4px;
}

.message-bubble p {
    margin: 0;
    font-size: 14px;
}

.message-time {
    font-size: 11px;
    color: #6c757d;
    margin-top: 0;
    padding: 0 4px;
    font-weight: 500;
}

.message.sent .message-time {
    align-self: flex-end;
    text-align: end;
}

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

/* Special Offer Card */
.offer-card {
    background-color: #fff;
    border: 2px solid #8e24aa;
    border-radius: 12px;
    padding: 20px;
    margin: 16px 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    animation: cardSlideIn 0.5s ease-out;
}

.offer-header {
    text-align: center;
    margin-bottom: 16px;
}

.offer-title {
    font-size: 18px;
    font-weight: 700;
    color: #8e24aa;
    margin: 0 0 4px 0;
}

.offer-subtitle {
    font-size: 14px;
    color: #6c757d;
    margin: 0;
}

.offer-price {
    text-align: center;
    margin-bottom: 20px;
}

.price-amount {
    font-size: 28px;
    font-weight: 700;
    color: #000;
}

.price-period {
    font-size: 16px;
    color: #6c757d;
    margin-left: 4px;
}

.offer-features {
    margin-bottom: 20px;
}

.feature-item {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    font-size: 14px;
    color: #000;
}

.feature-item:last-child {
    margin-bottom: 0;
}

.feature-item i {
    color: #28a745;
    font-size: 16px;
    width: 16px;
    flex-shrink: 0;
}

.accept-offer-btn {
    width: 100%;
    background-color: #e91e63;
    color: white;
    border: none;
    padding: 14px 20px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color 0.3s ease;
}

.accept-offer-btn:hover {
    background-color: #c2185b;
}

.accept-offer-btn:active {
    transform: scale(0.98);
}

/* Message Input — same edge-to-edge logic as .chat-header above. */
.message-input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
    background-color: #fff;
    border-top: 1px solid #e5e7eb;
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.05);
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    z-index: 1000;
    box-sizing: border-box;
}

@media (min-width: 601px) {
    .message-input-container {
        width: 400px;
        max-width: 400px;
        margin: 0 auto;
    }
}

.message-input {
    display: flex;
    align-items: center;
    gap: 12px;
    background-color: #f8f9fa;
    border-radius: 25px;
    padding: 8px 16px;
    border: 1px solid #e9ecef;
    transition: border-color 0.2s ease;
}

.message-input:focus-within {
    border-color: #e91e63;
    background-color: #fff;
}

.message-input input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    font-size: 14px;
    color: #000;
    padding: 8px 0;
}

.message-input input::placeholder {
    color: #6c757d;
}

.send-btn {
    background-color: #e91e63;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.send-btn:hover {
    background-color: #c2185b;
}

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

/* Animations */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background-color: #e9ecef;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    max-width: 80px;
    align-self: flex-start;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background-color: #6c757d;
    border-radius: 50%;
    animation: typingBounce 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 typingBounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Message Status Indicators */
.message-status {
    font-size: 10px;
    color: #6c757d;
    margin-top: 2px;
    text-align: right;
}

.message-status.delivered {
    color: #28a745;
}

.message-status.read {
    color: #e91e63;
}

/* Responsive Design */
@media (max-width: 480px) {
    .chat-messages {
        padding: calc(72px + env(safe-area-inset-top, 0px)) 10px calc(104px + env(safe-area-inset-bottom, 0px));
        width: 100%;
        overflow-x: hidden;
    }
    
    .message {
        max-width: 92%;
        margin: 0 4px;
    }
    
    .message-bubble {
        padding: 10px 14px;
    }
    
    .offer-card {
        padding: 16px;
        margin: 12px 0;
    }
    
    .offer-title {
        font-size: 16px;
    }
    
    .price-amount {
        font-size: 24px;
    }
    
    .message-input-container {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
        left: 0;
        right: 0;
        width: 100%;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .chat-messages {
        background-color: #1a1a1a;
    }
    
    .message.received .message-bubble {
        background-color: #2a2a2a;
        color: #fff;
    }
    
    .offer-card {
        background-color: #2a2a2a;
        border-color: #8e24aa;
    }
    
    .offer-title {
        color: #8e24aa;
    }
    
    .message-input-container {
        background-color: #1a1a1a;
        border-top-color: #333;
    }
    
    .message-input {
        background-color: #2a2a2a;
        border-color: #333;
    }
    
    .message-input input {
        color: #fff;
    }
}
