/* ═══════════════════════════════════════════════════════════════
   HoboStreamer — Messenger Widget (Facebook Messenger-style DMs)
   Floating widget in bottom-left corner
   ═══════════════════════════════════════════════════════════════ */

/* ── Messenger Toggle Button ──────────────────────────────────── */
.messenger-toggle {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    z-index: 9998;
    transition: transform 0.15s, background 0.15s;
}
.messenger-toggle:hover {
    transform: scale(1.08);
    background: var(--accent-light);
}
.messenger-toggle .msg-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.messenger-toggle .msg-badge:empty,
.messenger-toggle .msg-badge[data-count="0"] {
    display: none;
}

/* ── Messenger Panel ──────────────────────────────────────────── */
.messenger-panel {
    position: fixed;
    bottom: 80px;
    left: 20px;
    width: 380px;
    height: 520px;
    max-height: calc(100vh - 100px);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: msgSlideUp 0.2s ease-out;
}
.messenger-panel.open {
    display: flex;
}
@keyframes msgSlideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Panel Header ─────────────────────────────────────────────── */
.msg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
    min-height: 48px;
    gap: 8px;
}
.msg-header-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--text-primary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.msg-header-actions {
    display: flex;
    gap: 4px;
}
.msg-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.msg-header-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ── Conversation List (inbox view) ───────────────────────────── */
.msg-inbox {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}
.msg-inbox-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 14px;
    gap: 8px;
    padding: 32px;
    text-align: center;
}
.msg-inbox-empty i {
    font-size: 36px;
    opacity: 0.4;
}
.msg-conv-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    gap: 10px;
    cursor: pointer;
    transition: background 0.12s;
    border-bottom: 1px solid var(--border);
    position: relative;
}
.msg-conv-item:hover {
    background: var(--bg-hover);
}
.msg-conv-item.unread {
    background: rgba(192,150,92,0.06);
}
.msg-conv-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    color: #fff;
    background: var(--accent-dark);
    overflow: hidden;
}
.msg-conv-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.msg-conv-avatar.group {
    background: var(--info);
    font-size: 18px;
}
.msg-conv-body {
    flex: 1;
    min-width: 0;
}
.msg-conv-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.msg-conv-preview {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.msg-conv-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}
.msg-conv-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}
.msg-conv-unread {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ── Chat Thread View ─────────────────────────────────────────── */
.msg-thread {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.msg-thread-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 13px;
}
.msg-load-more {
    text-align: center;
    padding: 8px;
}
.msg-load-more button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
}
.msg-load-more button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Message bubbles */
.msg-bubble-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    max-width: 85%;
}
.msg-bubble-row.self {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.msg-bubble-row.other {
    align-self: flex-start;
}
.msg-bubble-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    background: var(--accent-dark);
    overflow: hidden;
}
.msg-bubble-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.msg-bubble {
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.4;
    word-break: break-word;
    position: relative;
}
.msg-bubble-row.self .msg-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.msg-bubble-row.other .msg-bubble {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}
.msg-bubble-sender {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-light);
    margin-bottom: 2px;
}
.msg-bubble-time {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
    text-align: right;
}
.msg-bubble-row.other .msg-bubble-time {
    text-align: left;
}

/* Date separator */
.msg-date-sep {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    padding: 8px 0;
    position: relative;
}
.msg-date-sep::before,
.msg-date-sep::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 30%;
    height: 1px;
    background: var(--border);
}
.msg-date-sep::before { left: 0; }
.msg-date-sep::after { right: 0; }

/* ── Compose Bar ──────────────────────────────────────────────── */
.msg-compose {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-tertiary);
}
.msg-compose input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 14px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
    font-family: var(--font);
}
.msg-compose input:focus {
    border-color: var(--accent);
}
.msg-compose input::placeholder {
    color: var(--text-muted);
}
.msg-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.1s;
}
.msg-send-btn:hover {
    background: var(--accent-light);
}
.msg-send-btn:active {
    transform: scale(0.93);
}

/* ── New Conversation / User Search ───────────────────────────── */
.msg-search-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.msg-search-input-wrap {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.msg-search-input-wrap input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    font-family: var(--font);
}
.msg-search-input-wrap input:focus {
    border-color: var(--accent);
}
.msg-search-input-wrap input::placeholder {
    color: var(--text-muted);
}
.msg-search-selected {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 4px 12px 0;
}
.msg-search-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--accent-dark);
    color: #fff;
    padding: 2px 8px 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}
.msg-search-chip .remove-chip {
    cursor: pointer;
    font-size: 10px;
    opacity: 0.7;
    transition: opacity 0.15s;
}
.msg-search-chip .remove-chip:hover {
    opacity: 1;
}
.msg-search-results {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}
.msg-user-item {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    gap: 10px;
    cursor: pointer;
    transition: background 0.12s;
}
.msg-user-item:hover {
    background: var(--bg-hover);
}
.msg-user-item .msg-conv-avatar {
    width: 36px;
    height: 36px;
    font-size: 14px;
}
.msg-user-item-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}
.msg-user-item-sub {
    font-size: 12px;
    color: var(--text-secondary);
}

/* "Start chat" button at bottom of search */
.msg-search-actions {
    padding: 8px 12px;
    border-top: 1px solid var(--border);
}
.msg-search-actions button {
    width: 100%;
    padding: 10px;
    border-radius: var(--radius);
    border: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}
.msg-search-actions button:hover {
    background: var(--accent-light);
}
.msg-search-actions button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Group Info View ──────────────────────────────────────────── */
.msg-group-info {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}
.msg-group-name-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    margin-bottom: 16px;
    font-family: var(--font);
}
.msg-group-name-input:focus {
    border-color: var(--accent);
}
.msg-group-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}
.msg-group-member {
    display: flex;
    align-items: center;
    padding: 6px 0;
    gap: 10px;
}
.msg-group-member-name {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
}
.msg-group-member-remove {
    font-size: 12px;
    color: var(--danger);
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.15s;
    background: none;
    border: none;
}
.msg-group-member-remove:hover {
    opacity: 1;
}
.msg-group-add-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    color: var(--accent);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: none;
    border: none;
    transition: color 0.15s;
}
.msg-group-add-btn:hover {
    color: var(--accent-light);
}
.msg-group-add-btn i {
    font-size: 16px;
}
.msg-group-leave {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.msg-group-leave button {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
    width: 100%;
}
.msg-group-leave button:hover {
    background: rgba(231,76,60,0.1);
}

/* ── Scrollbar styling inside messenger ───────────────────────── */
.msg-inbox::-webkit-scrollbar,
.msg-thread::-webkit-scrollbar,
.msg-search-results::-webkit-scrollbar,
.msg-group-info::-webkit-scrollbar {
    width: 6px;
}
.msg-inbox::-webkit-scrollbar-thumb,
.msg-thread::-webkit-scrollbar-thumb,
.msg-search-results::-webkit-scrollbar-thumb,
.msg-group-info::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 480px) {
    .messenger-panel {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    .messenger-toggle {
        bottom: 12px;
        left: 12px;
        width: 46px;
        height: 46px;
        font-size: 20px;
    }
}
@media (max-width: 768px) and (min-width: 481px) {
    .messenger-panel {
        width: min(100%, 360px);
        height: 480px;
        left: 12px;
        bottom: 72px;
    }
}

/* ── Thread dropdown menu ─────────────────────────────────── */
.msg-thread-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 100;
    background: var(--bg-secondary, #1e1e2e);
    border: 1px solid var(--border-color, #333);
    border-radius: 8px;
    padding: 4px;
    min-width: 200px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.msg-thread-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    color: var(--text-primary, #cdd6f4);
    font-size: 13px;
    cursor: pointer;
    border-radius: 6px;
    white-space: nowrap;
}
.msg-thread-dropdown-item:hover {
    background: var(--bg-hover, rgba(255,255,255,0.06));
}
.msg-thread-dropdown-item.danger {
    color: #f38ba8;
}
.msg-thread-dropdown-item.danger:hover {
    background: rgba(243, 139, 168, 0.1);
}

/* ── Blocked bar (replaces compose when blocked) ──────────── */
.msg-blocked-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    color: var(--text-muted, #6c7086);
    font-size: 13px;
    border-top: 1px solid var(--border-color, #333);
}
.msg-unblock-inline {
    background: none;
    border: 1px solid var(--accent, #89b4fa);
    color: var(--accent, #89b4fa);
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
}
.msg-unblock-inline:hover {
    background: rgba(137, 180, 250, 0.1);
}

/* ── Message delete button (hover reveal) ─────────────────── */
.msg-bubble {
    position: relative;
}
.msg-bubble-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(0,0,0,0.5);
    border: none;
    color: #f38ba8;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 10px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.msg-bubble:hover .msg-bubble-delete {
    display: flex;
}
.msg-bubble-delete:hover {
    background: rgba(243, 139, 168, 0.3);
}

/* ── Settings View ────────────────────────────────────────────── */
.msg-settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}
.msg-settings-section {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.msg-settings-section:last-child {
    border-bottom: none;
}
.msg-settings-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.msg-settings-section-title i {
    font-size: 12px;
    color: var(--accent);
}

/* Toggle switch */
.msg-settings-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    cursor: pointer;
    user-select: none;
}
.msg-settings-label {
    font-size: 13px;
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}
.msg-settings-hint {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}
.msg-settings-toggle input[type="checkbox"] {
    display: none;
}
.msg-toggle-slider {
    position: relative;
    width: 38px;
    min-width: 38px;
    height: 20px;
    background: var(--bg-hover);
    border-radius: 10px;
    transition: background 0.2s;
    margin-left: 12px;
}
.msg-toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: transform 0.2s, background 0.2s;
}
.msg-settings-toggle input:checked + .msg-toggle-slider {
    background: var(--accent);
}
.msg-settings-toggle input:checked + .msg-toggle-slider::after {
    transform: translateX(18px);
    background: #fff;
}

/* Volume slider row */
.msg-settings-range-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    transition: opacity 0.2s;
}
.msg-settings-range {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-hover);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
.msg-settings-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}
.msg-settings-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}
.msg-settings-range-val {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 32px;
    text-align: right;
}

/* Blocked users list */
.msg-blocked-list {
    max-height: 160px;
    overflow-y: auto;
}
.msg-blocked-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
}
.msg-blocked-name {
    flex: 1;
    font-size: 13px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.msg-blocked-unblock {
    background: none;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 3px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 11px;
    white-space: nowrap;
}
.msg-blocked-unblock:hover {
    background: rgba(137, 180, 250, 0.1);
}
.msg-settings-empty {
    font-size: 12px;
    color: var(--text-muted);
    padding: 8px 0;
}
.msg-settings-loading {
    text-align: center;
    padding: 12px;
    color: var(--text-muted);
}
.msg-settings-footer {
    padding: 16px;
    display: flex;
    justify-content: center;
}
.msg-settings-test-btn {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s, color 0.15s;
}
.msg-settings-test-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
