/**
 * Chat Widget Styles
 * Bổ sung styling cho chức năng chat realtime
 */


/* ----------------------------------
   Chat Widget System 
   ---------------------------------- */

/* Floating Button for Chat */
.btn-floating-chat {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 5px 20px rgba(59, 130, 246, 0.4);
    position: relative;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: pointer;
}

    .btn-floating-chat:hover {
        transform: scale(1.1) rotate(5deg);
    }

.notification-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* Chat Widget Container */
.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 110px;
    width: 360px;
    height: 500px;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.15);
    z-index: 1000;
    overflow: hidden;
    display: none; /* Hidden by default */
    flex-direction: column;
    transform-origin: bottom right;
    animation: chatPopup 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid rgba(0,0,0,0.05);
}

    .chat-widget.active {
        display: flex;
    }

@keyframes chatPopup {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Minimized State */
.chat-widget.minimized {
    bottom: 0px;
    height: 60px; /* Only header height */
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    transform: translateY(0);
}

/* Views Management */
.chat-view {
    display: none;
    flex-direction: column;
    height: 100%;
}

    .chat-view.active {
        display: flex;
    }

/* Common Header Styles */
.chat-header {
    padding: 15px 20px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    cursor: pointer; /* Click to expand if minimized */
}

.chat-title {
    font-weight: 800;
    font-size: 18px;
}

.chat-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-minimize-chat, .btn-close-chat, .btn-back-chat {
    background: rgba(255,255,255,0.2);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .btn-minimize-chat:hover, .btn-close-chat:hover {
        background: rgba(255,255,255,0.4);
    }

    .btn-minimize-chat:hover, .btn-close-chat:hover {
        background: rgba(255,255,255,0.4);
    }

.btn-back-chat {
    margin-right: 10px;
    background: transparent;
    padding: 0;
    width: auto;
}

/* Chat List Specifics */
.chat-list-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow: hidden;
}

.chat-search {
    padding: 15px;
    border-bottom: 1px solid #f1f5f9;
    position: relative;
}

    .chat-search input {
        width: 100%;
        padding: 10px 15px 10px 40px;
        border: 1px solid #e2e8f0;
        border-radius: 20px;
        background: #f8fafc;
        font-size: 14px;
        outline: none;
    }

    .chat-search i {
        position: absolute;
        left: 28px;
        top: 50%;
        transform: translateY(-50%);
        color: #94a3b8;
    }

.chat-items-container {
    flex-grow: 1;
    overflow-y: auto;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #f1f5f9;
}

    .chat-item:hover {
        background: #f8fafc;
    }

    .chat-item.unread {
        background: #eff6ff;
    }

.chat-item-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 15px;
}

.chat-item-info {
    flex-grow: 1;
    overflow: hidden;
}

.chat-item-name {
    display: block;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 3px;
    font-size: 14px;
}

.chat-item-preview {
    display: block;
    font-size: 13px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item.unread .chat-item-preview {
    font-weight: 600;
    color: #1e293b;
}

.chat-item-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-left: 10px;
    min-width: 40px;
}

.chat-item-time {
    font-size: 11px;
    color: #94a3b8;
    margin-bottom: 5px;
}

.chat-item-badge {
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* Conversation View Specifics (Reuse existing chat styles) */
.teacher-info-chat {
    display: flex;
    align-items: center;
    gap: 8px; /* Adjusted gap */
}

.chat-teacher-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #fff;
    object-fit: cover;
}

.chat-teacher-name {
    font-weight: 700;
    font-size: 15px;
    display: block;
}

.chat-status {
    font-size: 12px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 4px;
}

    .chat-status::before {
        content: "";
        width: 6px;
        height: 6px;
        background: #4ade80;
        border-radius: 50%;
        display: block;
    }

    .chat-status.offline::before {
        background: #ef4444;
    }

.chat-body {
    padding: 20px;
    height: 300px;
    overflow-y: auto;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 15px;
    flex-grow: 1; /* Ensure it fills space */
}

.chat-message {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
}

    .chat-message.received {
        background: #fff;
        align-self: flex-start;
        border-bottom-left-radius: 2px;
        box-shadow: 0 2px 5px rgba(0,0,0,0.05);
        color: #333;
    }

    .chat-message.sent {
        background: #3b82f6;
        color: #fff;
        align-self: flex-end;
        border-bottom-right-radius: 2px;
    }

.chat-time {
    display: block;
    font-size: 10px;
    margin-top: 5px;
    opacity: 0.7;
    text-align: right;
}

.chat-footer {
    padding: 15px;
    background: #fff;
    border-top: 1px solid #f1f5f9;
    display: flex;
    gap: 10px;
    align-items: center;
}

.chat-input {
    flex-grow: 1;
    border: 1px solid #e2e8f0;
    padding: 10px 15px;
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    color: #333;
}

    .chat-input:focus {
        border-color: #3b82f6;
    }

.btn-send-chat {
    background: #3b82f6;
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

    .btn-send-chat:hover {
        background: #2563eb;
    }

/* =========================================
   LIST CHILDREN PAGE ADDITIONS
   ========================================= */

/* Card Styling for List */
.child-card {
    border-radius: 24px;
    transition: all 0.3s ease;
    border: 1px solid rgba(0,0,0,0.04);
}

.shadow-hover:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 30px rgba(0,0,0,0.08) !important;
}

.child-avatar-container {
    width: 100px;
    height: 100px;
    position: relative;
}

.child-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border: 4px solid #fff;
    box-shadow: 0 5px 15px rgba(0,0,0,0.05);
}

.level-badge {
    bottom: 0;
    right: 0;
    font-size: 11px;
    padding: 5px 8px;
    border-radius: 12px;
}

.btn-add-child {
    border-radius: 50px;
    padding: 12px 24px;
    font-weight: 600;
}

.child-add-card {
    transition: all 0.3s ease;
    border-radius: 24px;
}

    .child-add-card:hover {
        background-color: rgba(59, 130, 246, 0.1) !important;
        border-color: #3b82f6 !important;
        transform: translateY(-5px);
    }

    .child-add-card .icon-circle {
        transition: transform 0.3s ease;
    }

    .child-add-card:hover .icon-circle {
        transform: scale(1.1);
        color: #fff;
    }

/* NEW: Button View Detail Styling */
.btn-view-detail {
    background: linear-gradient(135deg, #FF9200 0%, #FF9200 100%);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 14px;
    font-weight: 600;
    box-shadow: 0 8px 16px rgba(59, 130, 246, 0.25);
    transition: all 0.3s ease;
    font-size: 15px;
    position: relative;
    overflow: hidden;
}

    .btn-view-detail::after {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: linear-gradient(rgba(255,255,255,0.2), transparent);
        opacity: 0;
        transition: opacity 0.3s;
    }

    .btn-view-detail:hover {
        transform: translateY(-3px);
        box-shadow: 0 12px 24px rgba(59, 130, 246, 0.35);
        color: white;
    }

        .btn-view-detail:hover::after {
            opacity: 1;
        }

    .btn-view-detail:active {
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(59, 130, 246, 0.3);
    }

/* EMPTY STATE STYLES */
.empty-state-container {
    background: #fff;
    border-radius: 24px;
    padding: 60px 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    border: 2px dashed #e2e8f0;
    max-width: 800px;
    margin: 40px auto;
}

.empty-state-icon {
    width: 120px;
    height: 120px;
    background: #f8fafc;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    margin-bottom: 24px;
}

    .empty-state-icon i {
        color: #cbd5e1;
    }


/* Responsive adjustments for Widget */
/* Responsive */
@media (max-width: 1400px) {
    /* Item 3 spans full width on tablet/mobile */
    .stat-card:nth-child(3) {
        grid-column: span 2;
    }
}
/* Tablet (Portrait/Landscape) & Mobile below Desktop breakpoint */
@media (max-width: 992px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    /* Item 3 spans full width on tablet/mobile */
    .stat-card:nth-child(3) {
        grid-column: span 2;
    }

    .child-info-card {
        padding: 20px;
    }


    .child-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .course-card-horizontal {
        gap: 15px;
    }

    .course-thumb-wrapper-h {
        width: 120px;
    }
}

@media (max-width: 768px) {
    .child-info-card {
        flex-direction: column;
        text-align: center;
        gap: 15px;
        padding: 20px;
    }

    .child-meta {
        align-items: center;
    }

    .course-card-horizontal {
        flex-direction: column;
    }

    .course-thumb-wrapper-h {
        width: 100%;
        height: 180px;
    }

    .course-thumb-h {
        width: 100%;
        height: 100%;
    }

    .progress-h {
        max-width: 100%;
    }

    .chat-widget {
        width: 90%;
        right: 5%;
        bottom: 90px;
        height: 60vh;
    }

    /* Stats Grid adjustment for mobile */
    /* Inherits 2 columns from max-width: 992px query above, 
       but ensure gap/padding is optimal */

    .stat-card {
        padding: 15px;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
        font-size: 20px;
        margin-bottom: 10px;
    }

    .stat-number {
        font-size: 24px;
    }

    .stat-label {
        font-size: 12px;
    }

    .stat-item-sidebar {
        padding: 10px 5px !important;
    }
}


/* ===============================================
   CHAT WIDGET ENHANCEMENTS
   =============================================== */

/* Loading state */
.chat-loading {
    text-align: center;
    padding: 20px;
    color: #999;
    font-size: 14px;
}

.chat-loading-more {
    text-align: center;
    padding: 10px;
    color: #0d6efd;
    font-size: 13px;
    background: #e7f1ff;
    border-radius: 8px;
    margin: 10px;
    animation: fadeIn 0.3s;
    font-weight: 500;
}

.chat-loading-more::after {
    content: '...';
    animation: dots 1.5s infinite;
}

.chat-loading::after {
    content: '...';
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Empty states */
.chat-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #999;
    font-size: 14px;
}

.search-empty-state {
    text-align: center;
    padding: 20px;
    color: #999;
    font-size: 13px;
}

/* ===============================================
   TYPING INDICATOR
   =============================================== */

.typing-indicator {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    gap: 5px;
    background: #f0f0f0;
    border-radius: 18px;
    width: fit-content;
    margin: 5px 10px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    display: inline-block;
    animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* ===============================================
   ONLINE STATUS INDICATOR
   =============================================== */

/* Online indicator - đặt trên avatar */
/* Avatar wrapper cần relative positioning */
.chat-item {
    position: relative;
}

.chat-avatar-wrapper {
    position: relative;
    display: inline-block;
    margin-right: 12px;
}

.chat-item-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

/* Status dot bằng HTML element */
.chat-status-dot {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #fff;
    bottom: 0;
    right: 16px;
    z-index: 10;
}

.chat-status-dot.online {
    background: #4CAF50;
}

.chat-status-dot.offline {
    background: #999;
}

/* Wrapper cho avatar để chứa status dot */
.chat-item-avatar-wrapper {
    position: relative;
    display: inline-block;
}

/* Online indicator - Green dot */
.chat-item.online .chat-item-avatar::before {
    content: '' !important;
    position: absolute !important;
    width: 12px !important;
    height: 12px !important;
    background: #4CAF50 !important;
    border-radius: 50% !important;
    border: 2px solid #fff !important;
    bottom: -2px !important;
    right: -2px !important;
    display: block !important;
    z-index: 999 !important;
}

/* Offline indicator - Gray dot */
.chat-item:not(.online) .chat-item-avatar::before {
    content: '' !important;
    position: absolute !important;
    width: 12px !important;
    height: 12px !important;
    background: #999 !important;
    border-radius: 50% !important;
    border: 2px solid #fff !important;
    bottom: -2px !important;
    right: -2px !important;
    display: block !important;
    z-index: 999 !important;
}

.chat-status {
    font-size: 12px;
/*    color: #4CAF50;*/
}

/*.chat-status.offline {
    color: #999;
}*/

/* ===============================================
   MESSAGE READ STATUS
   =============================================== */

.chat-message.sent {
    position: relative;
}

/*.chat-message.sent::after {
    content: '✓';
    position: absolute;
    right: 10px;
    bottom: 5px;
    font-size: 12px;
    color: #999;
}*/

/*.chat-message.sent.read::after {
    content: '✓';
    color: #ffffff;
    position: absolute;
    right: 10px;
    bottom: 5px;
    font-size: 12px;
}*/

/* ===============================================
   UNREAD BADGE
   =============================================== */

.chat-item-badge {
    background: #f44336;
    color: white;
    font-size: 11px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #f44336;
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    display: none;
}

.notification-badge:empty {
    display: none;
}

/* ===============================================
   SEARCH RESULTS
   =============================================== */

.chat-search-results {
    margin: 0 16px;
    max-height: 300px;
    overflow-y: auto;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-top: 10px;
}

.search-result-item {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
}

.search-result-item:hover {
    background: #f5f5f5;
}

.search-result-item::before {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    background: #ccc;
    border-radius: 50%;
    border: 2px solid #fff;
    left: 48px;
    top: 38px;
    display: none;
}

.search-result-item.online::before {
    background: #4CAF50;
    display: block;
}

.search-result-item {
    position: relative;
}

.search-result-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 10px;
    object-fit: cover;
    position: relative !important;
    display: inline-block;
}

/* Online indicator cho search results */
.search-result-item.online .search-result-avatar::before {
    content: '' !important;
    position: absolute !important;
    width: 10px !important;
    height: 10px !important;
    background: #4CAF50 !important;
    border-radius: 50% !important;
    border: 2px solid #fff !important;
    bottom: -2px !important;
    right: -2px !important;
    display: block !important;
    z-index: 999 !important;
}

/* Offline indicator cho search results */
.search-result-item:not(.online) .search-result-avatar::before {
    content: '' !important;
    position: absolute !important;
    width: 10px !important;
    height: 10px !important;
    background: #999 !important;
    border-radius: 50% !important;
    border: 2px solid #fff !important;
    bottom: -2px !important;
    right: -2px !important;
    display: block !important;
    z-index: 999 !important;
}

.search-result-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.search-result-name {
    font-weight: 500;
    font-size: 14px;
    color: #333;
}

.search-result-email {
    font-size: 12px;
    color: #999;
}

/* ===============================================
   CHAT MESSAGE ENHANCEMENTS
   =============================================== */

.chat-message {
    max-width: 70%;
    word-wrap: break-word;
    margin-bottom: 10px;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message p {
    margin: 0;
    line-height: 1.4;
}


/* ===============================================
   SCROLLBAR STYLING
   =============================================== */

.chat-body::-webkit-scrollbar,
.chat-items-container::-webkit-scrollbar,
.chat-search-results::-webkit-scrollbar {
    width: 6px;
}

.chat-body::-webkit-scrollbar-track,
.chat-items-container::-webkit-scrollbar-track,
.chat-search-results::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-body::-webkit-scrollbar-thumb,
.chat-items-container::-webkit-scrollbar-thumb,
.chat-search-results::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.chat-body::-webkit-scrollbar-thumb:hover,
.chat-items-container::-webkit-scrollbar-thumb:hover,
.chat-search-results::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ===============================================
   RESPONSIVE ADJUSTMENTS
   =============================================== */

@media (max-width: 768px) {
    .chat-widget {
        width: 100%;
        height: 100%;
        right: 0;
        bottom: 0;
        border-radius: 0;
    }

    .chat-message {
        max-width: 80%;
    }

    .typing-indicator {
        margin: 5px;
    }
}

/* ===============================================
   ACCESSIBILITY
   =============================================== */

.chat-item:focus,
.search-result-item:focus,
.btn-send-chat:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ===============================================
   ERROR STATES
   =============================================== */

.chat-error {
    background: #ffebee;
    color: #c62828;
    padding: 10px 15px;
    border-radius: 4px;
    margin: 10px;
    font-size: 13px;
    text-align: center;
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@keyframes dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* ===============================================
   LOADING SPINNER
   =============================================== */

.chat-spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
