/* ============================================================
   FLOATING BUTTON
   ============================================================ */

.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    background: #166177;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    box-shadow: 0 4px 16px rgba(22, 97, 119, 0.35);
    z-index: 1000;
    transition: background 0.15s;
}
.chat-fab:hover {
    background: #1a7a95;
}
.chat-fab svg {
    width: 22px;
    height: 22px;
    fill: white;
}
.chat-fab .unread-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #f8722d;
    color: white;
    font-size: 10px;
    font-weight: 600;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "IBM Plex Mono", monospace;
}

/* ============================================================
   OVERLAY + PANEL
   ============================================================ */

.chat-overlay {
    position: fixed;
    inset: 0;
    z-index: 999;
    pointer-events: none;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 24px;
}
.chat-overlay.open {
    pointer-events: all;
}

.chat-panel {
    width: 760px;
    height: 560px;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #d0d0d0;
    overflow: hidden;
    display: flex;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    transform: translateY(20px) scale(0.97);
    opacity: 0;
    transition:
        transform 0.2s ease,
        opacity 0.2s ease;
    pointer-events: none;
}
.chat-overlay.open .chat-panel {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}
.chat-panel.expanded {
    width: 95vw;
    height: 90vh;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.chat-sidebar {
    width: 220px;
    flex-shrink: 0;
    background: #f5f5f5;
    border-right: 1px solid #d0d0d0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 12px 14px;
    border-bottom: 4px solid #166177;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar-title {
    font-size: 11px;
    font-weight: 600;
    color: #166177;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.sidebar-actions {
    display: flex;
    gap: 4px;
}
.sidebar-btn {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 2px 5px;
    font-size: 13px;
    border-radius: 3px;
    font-family: inherit;
}
.sidebar-btn:hover {
    color: #1a1a1a;
    background: #d0d0d0;
}

.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
}

.sidebar-section {
    padding: 10px 0 4px;
}
.sidebar-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #888;
    padding: 0 14px 4px;
}

.room-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background 0.1s;
    font-family: "IBM Plex Mono", monospace;
}
.room-item:hover {
    background: rgba(22, 97, 119, 0.06);
}
.room-item.active {
    background: rgba(22, 97, 119, 0.1);
    border-left-color: #166177;
}
.room-item.active .room-name {
    color: #166177;
    font-weight: 600;
}

.room-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.room-dot.blue {
    background: #166177;
}
.room-dot.orange {
    background: #f8722d;
}
.room-dot.red {
    background: #b13b3c;
}
.room-dot.green {
    background: #2d9e6b;
}
.room-dot.muted {
    background: #d0d0d0;
}

.room-name {
    flex: 1;
    font-size: 12px;
    color: #555;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-badge {
    background: #f8722d;
    color: white;
    font-size: 9px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 10px;
    min-width: 16px;
    text-align: center;
}
.room-badge.pending {
    background: #b13b3c;
}

.sidebar-footer {
    border-top: 1px solid #d0d0d0;
    padding: 10px 14px;
}
.my-addr {
    font-size: 10px;
    color: #888;
}
.my-addr span {
    color: #166177;
    font-weight: 500;
}

/* ============================================================
   CHAT MAIN
   ============================================================ */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #ffffff;
}

.chat-header {
    padding: 10px 16px;
    border-bottom: 1px solid #d0d0d0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
}
.chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}
.chat-header-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #166177;
}
.chat-header-name {
    font-size: 13px;
    font-weight: 600;
    color: #1a1a1a;
}
.chat-header-meta {
    font-size: 11px;
    color: #888;
}
.chat-header-right {
    display: flex;
    gap: 2px;
}

.header-btn {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 3px;
    font-size: 13px;
    font-family: inherit;
}
.header-btn:hover {
    color: #1a1a1a;
    background: #ebebeb;
}
.header-btn.close:hover {
    color: #b13b3c;
}

/* ============================================================
   MESSAGES
   ============================================================ */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8f8f8;
}

.msg-system {
    text-align: center;
    font-size: 11px;
    color: #888;
    padding: 4px 0;
}

.msg {
    display: flex;
    gap: 12px;
    position: relative;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background 0.1s;
}
.msg:hover {
    background: rgba(0, 0, 0, 0.02);
}
.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    color: white;
}

.msg-body {
    flex: 1;
    min-width: 0;
}
.msg-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}
.msg-name {
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.msg-name:hover {
    text-decoration: underline;
}
.msg-time {
    font-size: 11px;
    color: #888;
}

.reply-ref {
    background: #ebebeb;
    border-left: 3px solid #166177;
    padding: 5px 10px;
    border-radius: 0 4px 4px 0;
    font-size: 11px;
    color: #555;
    margin-bottom: 5px;
    cursor: pointer;
    display: block;
}
.reply-ref:hover {
    background: rgba(22, 97, 119, 0.08);
}

.msg-bubble {
    background: #ffffff;
    border: 1px solid #d0d0d0;
    border-radius: 0 8px 8px 8px;
    padding: 8px 12px;
    font-size: 13px;
    color: #1a1a1a;
    line-height: 1.55;
    display: inline-block;
    max-width: 100%;
    word-wrap: break-word;
}

.msg-img {
    max-width: 220px;
    border-radius: 6px;
    border: 1px solid #d0d0d0;
    display: block;
    margin-top: 2px;
}

/* ============================================================
   MESSAGE ACTIONS (always visible, muted until hover)
   ============================================================ */

.msg-actions-inline {
    display: inline-flex;
    gap: 2px;
    margin-left: auto;
}
.msg-action-btn {
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 11px;
    color: #ccc;
    cursor: pointer;
    font-family: "IBM Plex Mono", monospace;
    transition:
        color 0.15s,
        border-color 0.15s;
    line-height: 1;
}
.msg:hover .msg-action-btn {
    color: #999;
    border-color: #d0d0d0;
}
.msg-action-btn:hover {
    border-color: #166177 !important;
    color: #166177 !important;
}

/* ============================================================
   ADDRESS DISPLAY — full on desktop, short on mobile
   ============================================================ */

.addr-short {
    display: none;
}
.addr-full {
    display: inline;
}

@media (max-width: 768px) {
    .addr-short {
        display: inline;
    }
    .addr-full {
        display: none;
    }
}

/* ============================================================
   REACTIONS
   ============================================================ */

.msg-reactions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 6px;
}
.reaction {
    background: #ffffff;
    border: 1px solid #d0d0d0;
    border-radius: 20px;
    padding: 3px 8px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 3px;
    color: #555;
    transition: border-color 0.1s;
    font-family: "IBM Plex Mono", monospace;
}
.reaction:hover {
    border-color: #166177;
    color: #166177;
}
.reaction .r-count {
    font-size: 11px;
}
.reaction-add {
    background: #ffffff;
    border: 1px solid #d0d0d0;
    border-radius: 20px;
    padding: 3px 8px;
    font-size: 12px;
    cursor: pointer;
    color: #888;
    font-family: "IBM Plex Mono", monospace;
}
.reaction-add:hover {
    border-color: #166177;
    color: #166177;
}

/* ============================================================
   EMOJI PICKER
   ============================================================ */

.emoji-picker {
    position: fixed;
    background: #ffffff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    padding: 6px;
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    width: 180px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 1010;
}
.emoji-picker button {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    line-height: 1;
}
.emoji-picker button:hover {
    background: #ebebeb;
}

/* ============================================================
   LOADING STATE
   ============================================================ */

.chat-loading {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f8f8;
    color: #888;
    font-size: 12px;
    font-family: "IBM Plex Mono", monospace;
}

/* ============================================================
   REQUESTS + SENT
   ============================================================ */

.requests-view {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.request-item {
    background: #ffffff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.request-info {
    flex: 1;
}
.request-addr {
    font-size: 12px;
    color: #1a1a1a;
    font-weight: 500;
}
.request-meta {
    font-size: 11px;
    color: #888;
    margin-top: 2px;
}
.request-actions {
    display: flex;
    gap: 6px;
}

.req-btn {
    border: none;
    border-radius: 4px;
    padding: 5px 10px;
    font-family: "IBM Plex Mono", monospace;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
}
.req-btn.accept {
    background: #166177;
    color: white;
}
.req-btn.accept:hover {
    background: #1a7a95;
}
.req-btn.decline {
    background: #ebebeb;
    border: 1px solid #d0d0d0;
    color: #555;
}
.req-btn.decline:hover {
    border-color: #b13b3c;
    color: #b13b3c;
}

.sent-item {
    background: #ffffff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.sent-status {
    font-size: 11px;
    color: #888;
    font-style: italic;
}

/* ============================================================
   REPLY BANNER
   ============================================================ */

.reply-banner {
    padding: 6px 14px;
    background: rgba(22, 97, 119, 0.06);
    border-top: 1px solid rgba(22, 97, 119, 0.2);
    border-bottom: 1px solid rgba(22, 97, 119, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: #166177;
    font-family: "IBM Plex Mono", monospace;
}
.reply-banner-cancel {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}
.reply-banner-cancel:hover {
    color: #b13b3c;
}

/* ============================================================
   INPUT
   ============================================================ */

.chat-input-row {
    display: flex;
    padding: 10px 12px;
    gap: 8px;
    align-items: flex-end;
    background: #ffffff;
}
.chat-input {
    flex: 1;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    padding: 7px 10px;
    font-family: "IBM Plex Mono", monospace;
    font-size: 13px;
    color: #1a1a1a;
    outline: none;
    resize: none;
    line-height: 1.4;
    background: #ffffff;
    transition: border-color 0.15s;
}
.chat-input:focus {
    border-color: #166177;
}
.chat-input::placeholder {
    color: #888;
}

.send-btn {
    background: #f8722d;
    border: none;
    border-radius: 6px;
    padding: 7px 16px;
    font-family: "IBM Plex Mono", monospace;
    font-size: 12px;
    font-weight: 500;
    color: white;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}
.send-btn:hover {
    background: #e66525;
}

/* ============================================================
   MOBILE
   ============================================================ */

@media (max-width: 768px) {
    .chat-overlay {
        padding: 0;
        align-items: stretch;
        justify-content: stretch;
    }
    .chat-panel {
        width: 100% !important;
        height: 100% !important;
        border-radius: 0;
        border: none;
        box-shadow: none;
    }
    .chat-sidebar {
        display: none;
        width: 100%;
        border-right: none;
    }
    .chat-sidebar.mobile-open {
        display: flex;
        position: absolute;
        inset: 0;
        z-index: 10;
    }
    .chat-fab {
        bottom: 16px;
        right: 16px;
    }
}
