/**
 * Support Chat – layout and theme-aware styles.
 * Load after themes.css so CSS variables are available.
 */

/* --- Layout: fit beside sidebar (no horizontal overflow) --- */
.body-wrapper .container-fluid {
    min-width: 0;
}
.chat-container {
    min-width: 0;
}
.chat-window {
    min-width: 0;
}

/* --- Chat container --- */
.chat-container {
    height: calc(100vh - 100px);
    background: var(--bs-body-bg, #fff);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--bs-border-color, #dfe5ef);
}

/* --- Left sidebar (user list) --- */
.chat-sidebar {
    width: 320px;
    border-right: 1px solid var(--bs-border-color, #dfe5ef);
    display: flex;
    flex-direction: column;
    background: var(--bs-body-bg, #fff);
}

.chat-sidebar .p-3.border-bottom {
    border-bottom-color: var(--bs-border-color, #dfe5ef) !important;
}

.user-list {
    overflow-y: auto;
    flex: 1;
}

/* --- User item --- */
.user-item {
    padding: 15px;
    border-bottom: 1px solid var(--bs-border-color-translucent, #f5f5f5);
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
}

.user-item:hover {
    background: var(--bs-tertiary-bg, #f9f9f9);
}

.user-item.active {
    background: var(--bs-light-primary, #ecf2ff);
    border-left: 3px solid var(--bs-primary, #5D87FF);
}

.user-item .last-msg,
.user-item .last-time {
    color: var(--bs-secondary-color);
}

.user-item .fw-bold.text-dark {
    color: var(--bs-emphasis-color, #2A3547);
}

/* --- Avatar & indicators --- */
.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bs-light-primary, #e6f0ff);
    color: var(--bs-primary, #5D87FF);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
    position: relative;
    flex-shrink: 0;
}

.online-dot {
    width: 12px;
    height: 12px;
    background: #13deb9;
    border: 2px solid var(--bs-body-bg, #fff);
    border-radius: 50%;
    position: absolute;
    bottom: -2px;
    right: -2px;
    display: none;
}

.unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    font-size: 10px;
    padding: 4px 6px;
    display: none;
    box-shadow: 0 2px 4px rgba(220, 53, 69, 0.3);
}

/* --- Right side (chat window) --- */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bs-body-bg, #fff);
}

.chat-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--bs-border-color, #dfe5ef);
    background: var(--bs-body-bg, #fff);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-history-box {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bs-tertiary-bg, #f8f9fa);
    display: flex;
    flex-direction: column;
}

/* --- Message bubbles --- */
.chat-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    margin-bottom: 10px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

.chat-bubble.received {
    align-self: flex-start;
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--bs-border-color, #dfe5ef);
    color: var(--bs-body-color);
    border-bottom-left-radius: 2px;
}

.chat-bubble.sent {
    align-self: flex-end;
    background: var(--bs-primary, #5D87FF);
    color: #fff;
    border-bottom-right-radius: 2px;
    margin-right: 5px;
}

.message-time {
    font-size: 10px;
    margin-top: 4px;
    opacity: 0.7;
    text-align: right;
}

/* --- Input area --- */
.chat-input-area {
    padding: 15px;
    background: var(--bs-body-bg, #fff);
    border-top: 1px solid var(--bs-border-color, #dfe5ef);
}

/* --- Empty state --- */
.no-chat-selected {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--bs-secondary-color, #999);
}

.no-chat-selected h5 {
    color: var(--bs-heading-color, #2A3547);
}

/* ========== Dark theme overrides (chat-specific) ========== */
[data-bs-theme="dark"] .chat-container {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

[data-bs-theme="dark"] .user-item:hover,
[data-bs-theme="dark"] .user-item.bg-light-info {
    background: var(--bs-tertiary-bg) !important;
}

[data-bs-theme="dark"] .user-item.active {
    background: var(--bs-primary-bg-subtle) !important;
    border-left-color: var(--bs-primary) !important;
}

[data-bs-theme="dark"] .chat-bubble.received {
    background: var(--bs-secondary-bg) !important;
    border-color: var(--bs-border-color) !important;
    color: var(--bs-body-color) !important;
}

[data-bs-theme="dark"] .chat-bubble.sent {
    background: var(--bs-primary) !important;
    color: #fff !important;
}

/* ========== Responsive ========== */

/* Tablet: narrower sidebar, tighter padding */
@media (max-width: 992px) {
    .chat-container {
        height: calc(100vh - 90px);
    }
    .chat-sidebar {
        width: 260px;
        min-width: 260px;
    }
    .user-item {
        padding: 12px 15px;
    }
    .user-avatar {
        width: 36px;
        height: 36px;
        font-size: 13px;
    }
    .chat-header {
        padding: 12px 15px;
    }
    .chat-history-box {
        padding: 15px;
    }
    .chat-bubble {
        max-width: 85%;
        padding: 10px 14px;
        font-size: 13px;
    }
    .chat-input-area {
        padding: 12px 15px;
    }
    .chat-input-area .form-control {
        font-size: 16px; /* avoid zoom on focus on iOS */
    }
}

/* Mobile: single-panel view (list or conversation) */
@media (max-width: 767px) {
    .chat-container {
        position: relative;
        height: calc(100vh - 115px);
        /* height: calc(100dvh - 60px); */
        border-radius: 8px;
        flex-direction: row;
    }
    .chat-sidebar {
        width: 100%;
        min-width: 0;
        flex: 1 1 auto;
        border-right: none;
        transition: transform 0.25s ease, opacity 0.25s ease;
    }
    .chat-window {
        width: 100%;
        min-width: 0;
        flex: 1 1 auto;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        z-index: 2;
        box-shadow: -4px 0 12px rgba(0, 0, 0, 0.1);
    }
    .chat-container.mobile-conversation-open .chat-sidebar {
        transform: translateX(-100%);
        opacity: 0;
        pointer-events: none;
    }
    .chat-container.mobile-conversation-open .chat-window {
        transform: translateX(0);
    }
    .user-item {
        padding: 14px 12px;
    }
    .chat-back-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        min-width: 40px;
        height: 40px;
        /* margin: -8px 0 -8px -8px; */
        padding: 0;
        color: var(--bs-body-color);
        text-decoration: none !important;
        border: none;
        box-shadow: none;
    }
    .chat-back-btn:hover,
    .chat-back-btn:focus {
        color: var(--bs-primary);
        text-decoration: none;
    }
    .chat-back-btn .ti {
        text-decoration: none;
    }
    .chat-header {
        padding: 12px 10px 12px 0;
    }
    .chat-history-box {
        padding: 12px;
    }
    .chat-bubble {
        max-width: 90%;
        padding: 10px 12px;
        font-size: 14px;
    }
    .message-time {
        font-size: 9px;
    }
    .chat-input-area {
        padding: 10px 12px;
    }
    .no-chat-selected {
        padding: 1rem;
        text-align: center;
    }
    .no-chat-selected .fs-8 {
        font-size: 2.5rem !important;
    }
    .no-chat-selected h5 {
        font-size: 1.1rem;
    }
    .no-chat-selected p {
        font-size: 0.9rem;
    }
}

/* Extra small: reduce avatar and touch targets already good */
@media (max-width: 400px) {
    .chat-sidebar {
        width: 100%;
    }
    .user-avatar {
        width: 32px;
        height: 32px;
        font-size: 12px;
    }
}
