/* ============================================================
   Rajdari Resort Web Chat — WhatsApp-Clone Theme
   ============================================================ */

/* --- CSS Variables: WhatsApp Color Palette --- */
:root {
    --wa-green-dark: #075E54;
    --wa-green-header: #075E54;
    --wa-teal: #00A884;
    --wa-teal-hover: #008f72;
    --wa-chat-bg: #EFEAE2;
    --wa-user-bubble: #DCF8C6;
    --wa-bot-bubble: #FFFFFF;
    --wa-timestamp: #667781;
    --wa-tick-read: #53BDEB;
    --wa-input-bg: #F0F2F5;
    --wa-dark-bg: #0b141a;
    --wa-text-primary: #111B21;
    --wa-text-secondary: #667781;
    --wa-border: #E9EDEF;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    width: 100%;
    overflow-x: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 15px;
    color: var(--wa-text-primary);
    -webkit-font-smoothing: antialiased;
    background: var(--wa-dark-bg);
}

/* --- Chat Container (centered card on desktop, full-screen mobile) --- */
#chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    max-width: 100%;       /* phone-first; capped at larger breakpoints */
    margin: 0 auto;
    background: var(--wa-chat-bg);
    position: relative;
    overflow: hidden;
}

/* --- Header Bar --- */
#chat-header {
    background: var(--wa-green-header);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.2);
}

.header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-info h1 {
    font-size: 16px;
    font-weight: 600;
    color: #FFFFFF;
    line-height: 1.2;
}

#status-text {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
}

/* --- Chat Messages Area --- */
#chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 12px 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
    /* WhatsApp-style doodle background */
    background-color: #EFEAE2;
    position: relative;
}

#chat-messages::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("/static/img/wa-doodle.svg");
    background-size: 350px 350px;
    background-repeat: repeat;
    opacity: 0.24;
    pointer-events: none;
    z-index: 0;
}

#chat-messages > * {
    position: relative;
    z-index: 1;
}

#chat-messages::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

/* --- Message Wrappers --- */
.msg-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    margin-bottom: 2px;
}

.msg-wrapper-bot {
    align-self: flex-start;
}

.msg-wrapper-user {
    align-self: flex-end;
}

/* --- Message Bubbles --- */
.msg-bot, .msg-user {
    padding: 6px 12px 4px;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.4;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
}

.msg-bot {
    background: var(--wa-bot-bubble);
    border-radius: 0 8px 8px 8px;
}

.msg-user {
    background: var(--wa-user-bubble);
    border-radius: 8px 0 8px 8px;
}

/* --- Bubble Tails --- */
.msg-bot.has-tail::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 8px 8px 0;
    border-color: transparent var(--wa-bot-bubble) transparent transparent;
}

.msg-user.has-tail::before {
    content: '';
    position: absolute;
    top: 0;
    right: -8px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 0 8px 8px;
    border-color: transparent transparent transparent var(--wa-user-bubble);
}

/* --- Message Text Formatting --- */
.msg-text {
    font-size: 14.5px;
    color: var(--wa-text-primary);
}

.msg-text strong {
    font-weight: 600;
}

.msg-text em {
    font-style: italic;
}

.msg-text a {
    color: var(--wa-teal);
    text-decoration: underline;
}

/* --- Timestamp + Ticks --- */
.msg-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 3px;
    margin-top: 2px;
    min-width: 58px;
    float: right;
    margin-left: 12px;
}

.msg-time {
    font-size: 11px;
    color: var(--wa-timestamp);
    white-space: nowrap;
}

.msg-ticks {
    display: inline-flex;
    align-items: center;
}

.msg-ticks svg {
    width: 16px;
    height: 11px;
}

/* --- Quick Reply Buttons --- */
.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
    padding: 0 2px;
}

.btn-callback {
    background: transparent;
    border: 1px solid var(--wa-teal);
    color: var(--wa-teal);
    border-radius: 18px;
    padding: 7px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
    line-height: 1.3;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-callback:hover {
    background: var(--wa-teal);
    color: #FFFFFF;
}

.btn-callback:active {
    background: var(--wa-teal-hover);
    color: #FFFFFF;
    transform: scale(0.97);
}

.btn-callback:disabled {
    opacity: 0.4;
    cursor: default;
    pointer-events: none;
}

.btn-callback.btn-url::after {
    content: ' ↗';
    font-size: 11px;
}

/* --- Typing Indicator --- */
#typing-indicator {
    padding: 0 12px 4px;
    flex-shrink: 0;
}

.typing-wrapper {
    display: inline-block;
}

.typing-bubble {
    display: inline-flex;
    gap: 5px;
    padding: 12px 18px;
    background: var(--wa-bot-bubble);
    border-radius: 0 8px 8px 8px;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
    position: relative;
}

.typing-bubble::before {
    content: '';
    position: absolute;
    top: 0;
    left: -8px;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 8px 8px 0;
    border-color: transparent var(--wa-bot-bubble) transparent transparent;
}

.typing-bubble .dot {
    width: 8px;
    height: 8px;
    background: #90949c;
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-bubble .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-bubble .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* --- Input Area --- */
#chat-input-area {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    gap: 8px;
    background: var(--wa-input-bg);
    flex-shrink: 0;
    border-top: 1px solid var(--wa-border);
}

.input-wrapper {
    flex: 1;
    background: #FFFFFF;
    border-radius: 24px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    min-height: 44px;
}

#message-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    font-family: inherit;
    color: var(--wa-text-primary);
    background: transparent;
    padding: 10px 0;
}

#message-input::placeholder {
    color: var(--wa-text-secondary);
}

#send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--wa-teal);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

#send-btn:hover {
    background: var(--wa-teal-hover);
}

#send-btn:active {
    transform: scale(0.93);
}

/* --- Gallery Strip (inline in chat) --- */
.msg-wrapper-bot .gallery-strip {
    max-width: none;
    width: calc(100vw - 40px);
    max-width: 460px;
}

.gallery-strip {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 6px 0;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.gallery-strip::-webkit-scrollbar {
    display: none;
}

.gallery-strip img {
    width: 150px;
    height: 112px;
    object-fit: cover;
    border-radius: 8px;
    scroll-snap-align: start;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

.gallery-strip img:hover {
    opacity: 0.85;
}

/* --- Gallery Lightbox --- */
#gallery-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
}

.gallery-viewer {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 90vw;
    max-height: 90vh;
}

#gallery-main-img {
    max-width: 90vw;
    max-height: 75vh;
    object-fit: contain;
    border-radius: 4px;
}

#gallery-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: #FFFFFF;
    font-size: 36px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.gallery-nav {
    display: flex;
    align-items: center;
    gap: 24px;
}

.gallery-nav button {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #FFFFFF;
    font-size: 28px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.gallery-nav button:hover {
    background: rgba(255, 255, 255, 0.3);
}

#gallery-counter {
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    min-width: 50px;
    text-align: center;
}

/* --- Date Separator (like WhatsApp "TODAY") --- */
.date-separator {
    align-self: center;
    background: rgba(255, 255, 255, 0.85);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    color: var(--wa-text-secondary);
    margin: 8px 0;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.1);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* --- Utility --- */
.hidden {
    display: none !important;
}

/* ============================================================
   RESPONSIVE  —  phone-first, scaling up to tablet & desktop
   ============================================================ */

/* --- Tiny phones (≤360px): tighten type & spacing --- */
@media (max-width: 360px) {
    html, body { font-size: 14px; }
    #chat-header { padding: 8px 12px; gap: 10px; }
    .header-avatar { width: 36px; height: 36px; }
    .header-info h1 { font-size: 15px; }
    .msg-text { font-size: 14px; }
    .btn-callback { padding: 6px 12px; font-size: 12.5px; }
    .gallery-strip img { width: 130px; height: 98px; }
}

/* --- Phones (default = full screen). Just ensure full width. --- */
@media (max-width: 599px) {
    #chat-container { width: 100%; max-width: 100%; }
    body { background: var(--wa-chat-bg); }
}

/* --- Tablets & up: float the chat as a centered card --- */
@media (min-width: 600px) {
    body {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 20px;
        background: linear-gradient(135deg, #075E54 0%, #0b141a 100%);
    }

    #chat-container {
        max-width: 600px;
        height: min(calc(100dvh - 40px), 900px);
        border-radius: 14px;
        box-shadow: 0 12px 44px rgba(0, 0, 0, 0.45);
    }

    .msg-wrapper { max-width: 80%; }

    .msg-wrapper-bot .gallery-strip { width: 100%; }
    .gallery-strip { max-width: 100%; }
    .gallery-strip img { width: 168px; height: 126px; }
}

/* --- Desktop --- */
@media (min-width: 1024px) {
    #chat-container {
        max-width: 640px;
        height: min(94dvh, 880px);
    }
    .msg-wrapper { max-width: 75%; }
}

/* --- Large desktop --- */
@media (min-width: 1440px) {
    #chat-container { max-width: 680px; }
    html, body { font-size: 16px; }
}

/* --- Short / landscape screens: compact header & input --- */
@media (max-height: 480px) {
    #chat-header { padding: 6px 12px; }
    .header-avatar { width: 32px; height: 32px; }
    #chat-input-area { padding: 4px 6px; }
    .input-wrapper { min-height: 38px; }
    #send-btn { width: 38px; height: 38px; }
}
