/*
 * discussion_chat.css — Reusable WhatsApp-style discussion/chat interface
 * -------------------------------------------------------------------------
 * Used by:
 *   - Activity Groups module  (activity_group_detail.php — Discussions tab)
 *   - LMS Class Discussions   (TODO — see project memory)
 *
 * HTML structure expected:
 *   .dc-chat-wrap
 *     .dc-chat-sidebar (or .ag-chat-sidebar)
 *       .ag-chat-sidebar-header
 *       .ag-chat-threads
 *     .dc-chat-view (or .ag-chat-view)
 *       .ag-chat-empty-state
 *       .ag-chat-view-header
 *         .ag-chat-back-btn
 *         .ag-chat-view-title
 *       .ag-chat-messages
 *         .ag-chat-date-sep
 *         .ag-chat-bubble-wrap .ag-bubble-mine | .ag-bubble-theirs
 *           .ag-chat-bubble
 *       .ag-chat-input-bar
 *         .ag-chat-input-row
 *           textarea
 *           button.ag-chat-send-btn
 *
 * All selectors use .ag- prefix (Activity Groups origin).
 * When reusing for LMS, add .ag- classes to your markup or alias them here.
 */

/* ── Outer wrapper ─────────────────────────────────────────── */
.ag-chat-wrap {
    display: flex;
    height: 520px;
    border: 1px solid #e0e0e0;
    border-radius: 0 0 6px 6px;
    overflow: hidden;
    background: #f0f2f5;
    position: relative;
}

/* ── LEFT: Thread list sidebar ─────────────────────────────── */
.ag-chat-sidebar {
    width: 270px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e0e0e0;
    background: #fff;
}

.ag-chat-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid #eee;
    font-weight: 600;
    font-size: 13px;
    background: #fafafa;
    flex-shrink: 0;
}

.ag-new-disc-btn { font-size: 11px; }

/* Thread list (scrollable) */
.ag-chat-threads { flex: 1; overflow-y: auto; }

/* Individual thread row */
.ag-chat-thread-item {
    padding: 12px 14px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background .12s;
    border-left: 3px solid transparent;
}

.ag-chat-thread-item:hover { background: #f7f9ff; }

.ag-chat-thread-item.active {
    background: #eef2ff;
    border-left-color: #0d6efd;
}

.ag-thread-title {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    line-height: 1.3;
    margin-bottom: 3px;
}

.ag-thread-meta { font-size: 11px; color: #999; }

/* ── RIGHT: Chat view panel ────────────────────────────────── */
.ag-chat-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #f0f2f5;
}

/* Chat header (shown when a thread is open) */
.ag-chat-view-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.ag-chat-view-title { flex: 1; min-width: 0; }

.ag-chat-view-title .dc-title,
#ag_chat_title_text {
    font-size: 14px;
    font-weight: 700;
    color: #222;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ag-chat-view-title .dc-subtitle,
#ag_chat_subtitle {
    font-size: 11px;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Back button — hidden on desktop, shown on mobile */
.ag-chat-back-btn {
    display: none;
    background: none;
    border: none;
    padding: 0 6px 0 0;
    font-size: 17px;
    cursor: pointer;
    color: #555;
    line-height: 1;
    flex-shrink: 0;
}

/* Empty state (no thread selected yet) */
.ag-chat-empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 8px;
    color: #bbb;
    font-size: 13px;
}

.ag-chat-empty-state i { font-size: 40px; }
.ag-chat-empty-state p { margin: 0; }

/* ── Messages area ─────────────────────────────────────────── */
.ag-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Date separator */
.ag-chat-date-sep {
    text-align: center;
    margin: 10px 0 6px;
}

.ag-chat-date-sep span {
    background: #dde0e5;
    color: #666;
    font-size: 10px;
    padding: 2px 10px;
    border-radius: 10px;
}

/* No messages yet */
.ag-chat-no-msgs {
    text-align: center;
    color: #bbb;
    padding: 40px 0;
}

.ag-chat-no-msgs i { font-size: 32px; display: block; margin-bottom: 8px; }
.ag-chat-no-msgs p { margin: 0; }

/* Loading spinner */
.ag-chat-loading {
    text-align: center;
    color: #aaa;
    padding: 40px 0;
    font-size: 22px;
}

/* ── Message bubbles ───────────────────────────────────────── */
.ag-chat-bubble-wrap {
    display: flex;
    margin-bottom: 3px;
}

.ag-bubble-mine   { justify-content: flex-end; }
.ag-bubble-theirs { justify-content: flex-start; }

.ag-chat-bubble {
    max-width: 68%;
    border-radius: 12px;
    padding: 7px 11px;
    font-size: 13px;
    line-height: 1.45;
    word-break: break-word;
    position: relative;
}

/* Own messages — green (WhatsApp style) */
.ag-bubble-mine .ag-chat-bubble {
    background: #dcf8c6;
    color: #222;
    border-bottom-right-radius: 3px;
}

/* Others' messages — white */
.ag-bubble-theirs .ag-chat-bubble {
    background: #fff;
    color: #222;
    border-bottom-left-radius: 3px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}

.ag-bubble-name {
    font-size: 10px;
    font-weight: 700;
    color: #0d6efd;
    margin-bottom: 2px;
}

.ag-bubble-time {
    font-size: 10px;
    color: #aaa;
    text-align: right;
    margin-top: 3px;
}

/* ── Reply input bar ───────────────────────────────────────── */
.ag-chat-input-bar {
    padding: 8px 12px;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.ag-chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.ag-chat-input-row textarea {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 7px 14px;
    font-size: 13px;
    resize: none;
    line-height: 1.4;
    max-height: 80px;
    overflow-y: auto;
    transition: border-color .15s;
    font-family: inherit;
}

.ag-chat-input-row textarea:focus {
    outline: none;
    border-color: #0d6efd;
}

.ag-chat-send-btn {
    background: #0d6efd;
    color: #fff;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s;
}

.ag-chat-send-btn:hover    { background: #0b5ed7; }
.ag-chat-send-btn:disabled { opacity: .6; cursor: not-allowed; }

/* ── Mobile: one panel at a time ──────────────────────────── */
@media (max-width: 767px) {
    .ag-chat-wrap {
        height: calc(100vh - 220px);
        min-height: 380px;
    }

    .ag-chat-sidebar {
        width: 100%;
        border-right: none;
        position: absolute;
        inset: 0;
        z-index: 1;
    }

    .ag-chat-view {
        position: absolute;
        inset: 0;
        z-index: 2;
        display: none;
    }

    /* JS adds/removes these classes */
    .ag-mobile-hidden              { display: none !important; }
    .ag-chat-view.ag-mobile-visible { display: flex !important; }

    .ag-chat-back-btn { display: inline-flex; }

    .ag-chat-view-header { flex-direction: row; align-items: center; }

    #ag_chat_subtitle,
    .ag-chat-view-title .dc-subtitle { display: none; }

    .ag-chat-bubble { max-width: 85%; }
}
