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

:root {
    --bg:           #FFF5F8;
    --bg2:          #FFE8F0;
    --border:       #F0C4D4;
    --text:         #262626;
    --text2:        #9E6070;
    --pink:         #e91e63;
    --hover:        #FCE4EC;
    --msg-in-bg1:   #e91e63;
    --msg-in-bg2:   #c2185b;
    --msg-out:      #6a1b9a;
    --grad:         linear-gradient(135deg, #e91e63 0%, #9c27b0 100%);
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
}

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

/* ── Floating Button ───────────────────────────────── */
.floating-chat-button {
    position: fixed;
    bottom: calc(24px + var(--sab));
    right:  calc(24px + var(--sar));
    width: 60px; height: 60px;
    background: var(--grad);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(233,30,99,0.4);
    z-index: 9998;
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.floating-chat-button:hover  { transform: scale(1.1); box-shadow: 0 6px 20px rgba(233,30,99,0.5); }
.floating-chat-button:active { transform: scale(0.95); }
.floating-chat-button.active { opacity: 0; pointer-events: none; }

.chat-icon { font-size: 28px; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.06)} }

.notification-badge {
    position: absolute; top: -2px; right: -2px;
    background: #FF3B30; color: #fff; font-size: 10px;
    font-weight: 700; padding: 2px 6px;
    border-radius: 10px; min-width: 18px; text-align: center;
    border: 2px solid #fff;
}

/* ── Chat Bubble Teaser ───────────────────────────── */
.chat-teaser {
    position: fixed;
    bottom: calc(94px + var(--sab));
    right: calc(18px + var(--sar));
    z-index: 9997;
    pointer-events: none;
    animation: teaserBlink 1.5s ease-in-out infinite;
}
.chat-teaser-bubble {
    position: relative;
    background: linear-gradient(135deg, #e91e63, #c2185b);
    color: #fff;
    border-radius: 20px;
    padding: 9px 14px 9px 11px;
    box-shadow: 0 5px 18px rgba(233,30,99,0.5);
    overflow: hidden;
    white-space: nowrap;
    pointer-events: auto;
    cursor: pointer;
}
.chat-teaser-bubble::before {
    content: '';
    position: absolute; inset: 0;
    background: repeating-linear-gradient(-45deg, transparent, transparent 6px, rgba(255,255,255,0.08) 6px, rgba(255,255,255,0.08) 8px);
}
.chat-teaser-bubble::after {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 45%;
    background: linear-gradient(180deg, rgba(255,255,255,0.22), transparent);
    border-radius: 20px;
}
.chat-teaser-text { position: relative; line-height: 1.35; }
.chat-teaser-text .line1 { font-size: 12px; font-weight: 700; display: block; }
.chat-teaser-text .line2 { font-size: 11px; font-weight: 600; opacity: 0.92; display: block; }
.chat-teaser-arrow {
    position: absolute;
    bottom: -9px; left: 20px;
    width: 0; height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 10px solid #c2185b;
}
@keyframes teaserBlink {
    0%,100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.15; transform: scale(0.96); }
}
.chat-teaser.hidden { display: none; }

/* ── Chat Container ────────────────────────────────── */
.chat-widget-container {
    position: fixed;
    bottom: calc(24px + var(--sab));
    right:  calc(24px + var(--sar));
    width: 380px;
    height: min(600px, calc(100dvh - 48px));
    background: var(--bg);
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.16);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.28s cubic-bezier(.22,.68,0,1.2);
}
.chat-widget-container.active { display: flex; }
@keyframes slideUp {
    from { opacity:0; transform:translateY(24px) scale(0.94); }
    to   { opacity:1; transform:translateY(0)   scale(1);    }
}

/* ── Header ───────────────────────────────────────── */
.chat-header {
    flex-shrink: 0;
    min-height: 64px;
    background: var(--grad); color: #fff;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 16px;
    border-radius: 16px 16px 0 0;
}
.header-left  { display: flex; align-items: center; gap: 10px; }
.user-avatar  {
    width: 40px; height: 40px; flex-shrink: 0;
    border-radius: 50%; background: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
}
.user-details h2 { font-size: 15px; font-weight: 600; line-height: 1.2; }
.user-details p  { font-size: 12px; opacity: 0.9; margin-top: 2px; }
.status-dot {
    display: inline-block; width: 7px; height: 7px;
    background: #34C759; border-radius: 50%; margin-right: 5px;
    animation: blink 2s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.25} }

.header-actions { display: flex; gap: 8px; flex-shrink: 0; }
.header-button {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.header-button:hover  { background: rgba(255,255,255,0.3); }
.header-button:active { background: rgba(255,255,255,0.4); }
.close-button { font-size: 22px; color: #fff; font-weight: 300; line-height: 1; }

/* ── Messages ─────────────────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 16px;
    background: var(--bg);
    background-image: radial-gradient(circle at 20% 80%, rgba(233,30,99,0.06) 0%, transparent 50%),
                      radial-gradient(circle at 80% 20%, rgba(156,39,176,0.06) 0%, transparent 50%);
    display: flex; flex-direction: column; gap: 10px;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.message { display: flex; animation: msgIn 0.28s cubic-bezier(.34,1.56,.64,1); }
@keyframes msgIn { from{opacity:0;transform:translateY(10px) scale(0.94)} to{opacity:1;transform:translateY(0) scale(1)} }
.message.bot  { justify-content: flex-start; }
.message.user { justify-content: flex-end; }

.message-content {
    max-width: 78%;
    padding: 11px 16px;
    border-radius: 22px;
    font-size: 14px; line-height: 1.55;
    word-break: break-word;
    overflow-wrap: anywhere;
    font-weight: 500;
}
.message.bot .message-content {
    background: linear-gradient(135deg, #f8bbd0 0%, #f48fb1 100%);
    color: #880e4f;
    border-radius: 20px 20px 20px 4px;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 4px 14px rgba(233,30,99,0.15), 0 1px 3px rgba(0,0,0,0.06);
    position: relative;
    overflow: hidden;
    letter-spacing: 0.01em;
}
.message.bot .message-content::before {
    content: '';
    position: absolute; inset: 0;
    background: repeating-linear-gradient(-45deg, transparent, transparent 7px, rgba(255,255,255,0.07) 7px, rgba(255,255,255,0.07) 9px);
    pointer-events: none;
}
.message.bot .message-content::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 45%;
    background: linear-gradient(180deg, rgba(255,255,255,0.18) 0%, transparent 100%);
    border-radius: 20px 20px 0 0;
    pointer-events: none;
}
.message.user .message-content {
    background: linear-gradient(135deg, #6a1b9a 0%, #4a148c 100%);
    color: #fff;
    border-radius: 20px 20px 4px 20px;
    font-weight: 500;
    box-shadow: 0 4px 14px rgba(106,27,154,0.3);
}

/* ── Typing ───────────────────────────────────────── */
.typing-indicator { display: none; justify-content: flex-start; padding: 4px 0; }
.typing-indicator.active { display: flex; }
.typing-dots {
    background: linear-gradient(135deg, #f8bbd0 0%, #f48fb1 100%);
    border-radius: 20px 20px 20px 4px;
    padding: 12px 16px;
    display: flex; gap: 5px;
    box-shadow: 0 4px 14px rgba(233,30,99,0.2);
}
.typing-dot  { width: 7px; height: 7px; border-radius: 50%; background: #880e4f; animation: bounce 1.4s infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100%{transform:translateY(0);opacity:.5} 30%{transform:translateY(-6px);opacity:1} }

/* ── Welcome Screen ───────────────────────────────── */
.welcome-screen { text-align: center; padding: 16px 12px; }
.welcome-screen h3 { font-size: 17px; font-weight: 700; color: #c2185b; margin-bottom: 6px; }
.welcome-screen p  { font-size: 13px; color: var(--text2); line-height: 1.55; margin-bottom: 16px; }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quick-action-btn {
    padding: 12px 8px;
    background: #fff;
    border: 1.5px solid #F48FB1;
    border-radius: 16px; cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-height: 70px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    box-shadow: 0 2px 8px rgba(233,30,99,0.1);
}
.quick-action-btn:hover  { background: #FCE4EC; border-color: var(--pink); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(233,30,99,0.2); }
.quick-action-btn:active { transform: scale(0.97); }
.quick-action-btn strong { display: block; font-size: 22px; margin-bottom: 5px; }
.quick-action-btn span   { display: block; font-size: 11px; color: #ad1457; font-weight: 600; line-height: 1.3; }

/* ── Image Preview Bar ────────────────────────────── */
.image-preview-bar { display: none; padding: 8px 16px; background: var(--bg2); border-top: 1px solid var(--border); align-items: center; gap: 10px; flex-shrink: 0; }
.image-preview-bar.active { display: flex; }
.image-preview-thumb  { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; border: 2px solid var(--pink); flex-shrink: 0; }
.image-preview-name   { flex: 1; font-size: 12px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.image-preview-remove { width: 26px; height: 26px; background: #ff3b30; color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 15px; flex-shrink: 0; touch-action: manipulation; }

/* ── Composer ─────────────────────────────────────── */
.chat-composer {
    flex-shrink: 0;
    padding: 10px 12px;
    padding-bottom: calc(10px + var(--sab));
    border-top: 1px solid var(--border);
    background: var(--bg);
    display: flex; align-items: flex-end; gap: 8px;
}
.composer-input-wrapper { flex: 1; min-width: 0; }
.composer-input {
    width: 100%;
    min-height: 40px; max-height: 120px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.4;
    outline: none; resize: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--bg2);
    color: var(--text);
    transition: border-color 0.18s, background 0.18s;
}
.composer-input:focus      { border-color: var(--pink); background: #fff; }
.composer-input::placeholder { color: var(--text2); }

.attach-button {
    width: 40px; height: 40px; flex-shrink: 0;
    background: var(--hover); border: 1px solid var(--border);
    color: var(--text2); border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.18s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.attach-button:hover  { background: #ebebeb; color: var(--pink); border-color: var(--pink); }
.attach-button:active { transform: scale(0.93); }

.send-button {
    width: 42px; height: 42px; flex-shrink: 0;
    background: var(--grad); color: #fff;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: transform 0.18s, opacity 0.18s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.send-button:hover  { transform: scale(1.08); }
.send-button:active { transform: scale(0.93); }
.send-button.disabled       { opacity: 0.35; cursor: not-allowed; }
.send-button.disabled:hover { transform: scale(1); }

/* ── Image bubble ─────────────────────────────────── */
.message-image { max-width: 190px; width: 100%; border-radius: 12px; margin-bottom: 4px; cursor: pointer; display: block; }
.message-image:hover { opacity: 0.88; }

/* ── Chat Footer ──────────────────────────────────── */
.chat-footer {
    flex-shrink: 0;
    padding: 8px 16px;
    text-align: center; font-size: 11px;
    color: var(--text2);
    background: var(--bg2);
    border-top: 1px solid var(--border);
}
.chat-footer a { color: var(--pink); text-decoration: none; }

/* ── Tablet landscape (601–900px) ─────────────────── */
@media (min-width: 601px) and (max-width: 900px) {
    .chat-widget-container { width: 360px; height: min(580px, calc(100dvh - 40px)); bottom: calc(20px + var(--sab)); right: calc(20px + var(--sar)); }
}

/* ── Tablet portrait (481–600px) ──────────────────── */
@media (min-width: 481px) and (max-width: 600px) {
    .chat-widget-container { width: calc(100vw - 32px); max-width: 400px; height: min(560px, calc(100dvh - 36px)); bottom: calc(16px + var(--sab)); right: calc(16px + var(--sar)); border-radius: 14px; }
    .floating-chat-button  { bottom: calc(20px + var(--sab)); right: calc(20px + var(--sar)); }
}

/* ── Mobile ≤480px — full screen ──────────────────── */
@media (max-width: 480px) {
    .chat-widget-container { top:0;bottom:0;left:0;right:0;width:100%;height:100%;max-height:100dvh;border-radius:0;animation:mobileSlideUp 0.3s cubic-bezier(.22,.68,0,1.1); }
    @keyframes mobileSlideUp { from{transform:translateY(100%)} to{transform:translateY(0)} }
    .chat-header    { border-radius:0; min-height:calc(60px + var(--sat)); padding-top:var(--sat); padding-left:calc(14px + var(--sal)); padding-right:calc(14px + var(--sar)); }
    .chat-messages  { padding: 14px 12px; }
    .chat-composer  { padding:10px 12px; padding-left:calc(10px + var(--sal)); padding-right:calc(10px + var(--sar)); padding-bottom:calc(10px + var(--sab)); }
    .composer-input { font-size: 16px; }
    .attach-button  { width: 42px; height: 42px; }
    .send-button    { width: 44px; height: 44px; }
    .header-button  { width: 40px; height: 40px; }
    .message-content { font-size: 15px; max-width: 82%; }
    .quick-action-btn { padding: 14px 8px; min-height: 72px; }
    .floating-chat-button { bottom:calc(20px + var(--sab)); right:calc(16px + var(--sar)); width:58px;height:58px; }
    .chat-footer    { padding-bottom: calc(8px + var(--sab)); }
}

/* ── Very small phones ≤360px ─────────────────────── */
@media (max-width: 360px) {
    .welcome-screen h3 { font-size:15px; } .welcome-screen p { font-size:12px; }
    .quick-action-btn strong { font-size:20px; } .quick-action-btn span { font-size:10px; }
    .message-content { font-size:14px; } .user-details h2 { font-size:14px; }
}

/* ── Landscape mobile ─────────────────────────────── */
@media (max-width: 480px) and (orientation: landscape) {
    .chat-widget-container { height: 100dvh; }
    .chat-messages  { padding: 10px 12px; gap: 8px; }
    .chat-composer  { padding-top: 6px; padding-bottom: calc(6px + var(--sab)); }
    .welcome-screen { padding: 10px; }
    .welcome-screen p { margin-bottom: 10px; }
}
