/* ============================================
   Property Search Chat Widget
   Bootstrap 5.3 dark mode compatible
   ============================================ */

/* --- Floating trigger button --- */
.chat-widget-btn {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 1050;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--bs-primary);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,.25);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform .2s, box-shadow .2s;
}
.chat-widget-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.chat-widget-btn .bi { font-size: 1.5rem; }

/* Unread badge */
.chat-widget-btn .chat-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--bs-danger);
    border: 2px solid var(--bs-body-bg);
    display: none;
}

/* --- Chat panel --- */
.chat-widget-panel {
    position: fixed;
    bottom: 5.5rem;
    right: 1.25rem;
    z-index: 1050;
    width: 370px;
    max-width: calc(100vw - 2rem);
    height: 480px;
    max-height: calc(100vh - 7rem);
    border-radius: .75rem;
    overflow: hidden;
    display: none;
    flex-direction: column;
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
.chat-widget-panel.open {
    display: flex;
}

/* --- Header --- */
.chat-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .625rem 1rem;
    background-color: var(--bs-primary);
    color: #fff;
    flex-shrink: 0;
}
.chat-widget-header h6 {
    margin: 0;
    font-size: .9rem;
    font-weight: 600;
}
.chat-widget-header .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
    padding: .25rem;
}

/* --- Messages area --- */
.chat-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: .75rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

/* Individual message bubble */
.chat-msg {
    max-width: 85%;
    padding: .5rem .75rem;
    border-radius: .75rem;
    font-size: .85rem;
    line-height: 1.45;
    word-wrap: break-word;
}
.chat-msg a {
    word-break: break-all;
}
.chat-msg-user {
    align-self: flex-end;
    background-color: var(--bs-primary);
    color: #fff;
    border-bottom-right-radius: .2rem;
}
.chat-msg-assistant {
    align-self: flex-start;
    background-color: var(--bs-secondary-bg);
    color: var(--bs-body-color);
    border-bottom-left-radius: .2rem;
}

/* Typing indicator */
.chat-typing {
    align-self: flex-start;
    padding: .5rem .75rem;
    font-size: .8rem;
    color: var(--bs-secondary-color);
    font-style: italic;
    display: none;
}
.chat-typing.show { display: block; }
.chat-typing span {
    display: inline-block;
    animation: chatDots 1.4s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chatDots {
    0%, 80%, 100% { opacity: .3; }
    40% { opacity: 1; }
}

/* --- Input area --- */
.chat-widget-input {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem;
    border-top: 1px solid var(--bs-border-color);
    background-color: var(--bs-body-bg);
    flex-shrink: 0;
}
.chat-widget-input input {
    flex: 1;
    border: 1px solid var(--bs-border-color);
    border-radius: 1rem;
    padding: .4rem .75rem;
    font-size: .85rem;
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    outline: none;
}
.chat-widget-input input:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 2px rgba(var(--bs-primary-rgb), .2);
}
.chat-widget-input button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--bs-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}
.chat-widget-input button:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* --- Dark mode adjustments --- */
[data-bs-theme='dark'] .chat-widget-btn {
    background: #4da3ff;
    color: #000;
    box-shadow: 0 4px 16px rgba(77,163,255,.4), 0 0 0 2px rgba(77,163,255,.25);
}
[data-bs-theme='dark'] .chat-widget-btn:hover {
    box-shadow: 0 6px 24px rgba(77,163,255,.5), 0 0 0 3px rgba(77,163,255,.3);
}
[data-bs-theme='dark'] .chat-widget-panel {
    border: 1px solid rgba(255,255,255,.15);
    box-shadow: 0 8px 30px rgba(0,0,0,.6);
}
[data-bs-theme='dark'] .chat-widget-header {
    background-color: #2563b8;
}
[data-bs-theme='dark'] .chat-msg-user {
    background-color: #2563b8;
    color: #fff;
}
[data-bs-theme='dark'] .chat-msg-assistant {
    background-color: var(--bs-tertiary-bg);
    color: var(--bs-emphasis-color);
    border: 1px solid rgba(255,255,255,.08);
}
[data-bs-theme='dark'] .chat-msg-assistant a {
    color: #6cb4ff;
}
[data-bs-theme='dark'] .chat-widget-input {
    border-top: 1px solid rgba(255,255,255,.12);
}
[data-bs-theme='dark'] .chat-widget-input input {
    background-color: var(--bs-tertiary-bg);
    border-color: rgba(255,255,255,.15);
    color: var(--bs-emphasis-color);
}
[data-bs-theme='dark'] .chat-widget-input input::placeholder {
    color: var(--bs-secondary-color);
}
[data-bs-theme='dark'] .chat-widget-input input:focus {
    border-color: #4da3ff;
    box-shadow: 0 0 0 2px rgba(77,163,255,.3);
}
[data-bs-theme='dark'] .chat-widget-input button {
    background: #4da3ff;
    color: #000;
}
[data-bs-theme='dark'] .chat-typing {
    color: var(--bs-secondary-color);
}

/* --- Mobile: full-width panel --- */
@media (max-width: 480px) {
    .chat-widget-panel {
        width: calc(100vw - 1rem);
        right: .5rem;
        bottom: 4.5rem;
        height: calc(100vh - 6rem);      /* fallback */
        height: calc(100dvh - 6rem);     /* modern browsers */
        border-radius: .5rem;
    }
    /* When keyboard is open: use actual visual viewport height from JS */
    .chat-widget-panel.chat-keyboard-open {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: calc(var(--chat-vh, 100vh) * 1px);
        border-radius: 0;
        max-height: none;
    }
    .chat-widget-btn {
        bottom: .75rem;
        right: .75rem;
        width: 50px;
        height: 50px;
    }
    /* Hide the toggle button when keyboard is open (panel is fullscreen) */
    .chat-widget-btn.chat-keyboard-hide { display: none; }
}
