/* Chat Widget Styles */

.chat-widget {
    position: fixed;
    bottom: 0;
    right: 20px;
    width: 340px;
    max-width: 90vw;
    background-color: #ffffff;
    border: 1px solid #ddd;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease-in-out;
    font-family: 'Open Sans', sans-serif;
}

.chat-widget.minimized {
    transform: translateY(calc(100% - 42px));
}

/* Header */
.chat-header {
    background-color: #f7f7f7;
    color: #555;
    padding: 0 15px;
    height: 42px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ddd;
    user-select: none;
}

.chat-header h5 {
    margin: 0;
    font-size: 15px;
    flex: 1;
}

.chat-header-controls {
    display: flex;
    gap: 5px;
    align-items: center;
}

.chat-control-btn {
    background: none;
    border: none;
    color: #555;
    cursor: pointer;
    padding: 5px 8px;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.chat-control-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.chat-control-btn:active {
    background-color: rgba(0, 0, 0, 0.1);
}

/* Messages Area */
.chat-messages {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    height: 300px;
    background-color: #fdfdfd;
    display: flex;
    flex-direction: column;
}

.chat-message {
    margin-bottom: 15px;
    display: flex;
    max-width: 95%;
}

.chat-message .avatar {
    display: none;
}

.chat-message .message-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.message-header {
    font-size: 13px;
    color: #555;
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 0;
    padding-left: 2px;
}

.message-header .username {
    font-weight: bold;
}

.message-header .timestamp {
    color: #aaa;
    font-size: 11px;
    margin-left: 8px;
}

.message-text {
    font-size: 14px;
    line-height: 1.4;
    background-color: #f1f1f1;
    padding: 8px 12px;
    border-radius: 15px;
    display: inline-block;
    word-wrap: break-word;
    border: 1px solid #eee;
}

.message-delete {
    color: #aaa;
    cursor: pointer;
    margin-left: 10px;
    font-size: 12px;
    display: none;
}

.chat-message:hover .message-delete {
    display: inline;
}

/* Input Area */
.chat-input {
    padding: 6px 15px 10px 15px;
    border-top: 1px solid #ddd;
    background-color: #f7f7f7;
}

.chat-input textarea {
    width: 100%;
    border: 1px solid #ccc;
    border-radius: 18px;
    padding: 8px 15px;
    resize: none;
    box-sizing: border-box;
    font-family: 'Open Sans', sans-serif;
    font-size: 14px;
    height: 34px;
    max-height: 100px;
    overflow: hidden;
    transition: height 0.2s;
}

.chat-input textarea:focus {
    outline: none;
    border-color: #aaa;
}


/* Dark Mode Overrides */
body.dark .chat-widget {
    background-color: #333;
    border-color: #555;
}
body.dark .chat-header {
    background-color: #2a2a2a;
    color: #eee;
    border-bottom-color: #555;
}
body.dark .chat-control-btn {
    color: #eee;
}
body.dark .chat-control-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}
body.dark .chat-control-btn:active {
    background-color: rgba(255, 255, 255, 0.15);
}
body.dark .chat-messages {
    background-color: #2c2c2c;
}
body.dark .message-header .username {
    color: #eee;
}
body.dark .message-text {
    background-color: #444;
    color: #eee;
    border-color: #555;
}
body.dark .chat-input {
    background-color: #2a2a2a;
    border-top-color: #555;
}
body.dark .chat-input textarea {
    background-color: #444;
    border-color: #666;
    color: #eee;
}
body.dark .chat-input textarea:focus {
    border-color: #888;
}

/* Mobile-specific centering */
@media screen and (max-width: 768px) {
    .chat-widget {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }

    .chat-widget.minimized {
        /* Adjust the transform to account for the centering */
        transform: translate(-50%, calc(100% - 42px));
    }
}

/* ========== FRIENDS CHAT STYLES ========== */

/* Friends list view */
#friends-list-view {
    display: flex;
    flex-direction: column;
    height: 400px;
}

#chat-view {
    display: none;
    flex-direction: column;
    height: 400px;
}

/* Friends list header with search */
.friends-header {
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #ddd;
    justify-content: flex-end;
}

#friends-list-view.search-mode .friends-header {
    justify-content: flex-start;
}

#friend-search-input {
    flex: 1;
    border: 1px solid #ccc;
    border-radius: 18px;
    padding: 6px 12px;
    font-size: 13px;
    font-family: 'Open Sans', sans-serif;
}

#friend-search-input:focus {
    outline: none;
    border-color: #50ca59;
}

#friends-list-view:not(.search-mode) #friend-search-input {
    display: none;
}

#add-friend-btn {
    background: none;
    border: none;
    font-size: 20px;
    color: #50ca59;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

#add-friend-btn:hover {
    opacity: 0.7;
}

#add-friend-btn .label {
    font-size: 12px;
    font-weight: 600;
    color: #50ca59;
}

/* Search results */
#friend-search-results {
    padding: 10px;
    overflow-y: auto;
    flex: 1;
}

.search-result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;
    gap: 10px;
}

.user-email {
    font-size: 14px;
    color: #333;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.send-request-btn {
    background-color: #50ca59;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 12px;
    cursor: pointer;
}

.send-request-btn:hover {
    background-color: #3da647;
}

.status-label {
    font-size: 12px;
    color: #999;
}

.search-hint, .error-msg {
    text-align: center;
    color: #999;
    font-size: 13px;
    padding: 20px;
}

.error-msg {
    color: #e74c3c;
}

/* Hide search when not in search mode */
#friends-list-view:not(.search-mode) #friend-search-results {
    display: none;
}

#friends-list-view.search-mode #friends-list-container,
#friends-list-view.search-mode #pending-requests-container {
    display: none;
}

/* Pending requests */
#pending-requests-container {
    border-bottom: 1px solid #ddd;
    background-color: #f9f9f9;
}

.requests-header {
    padding: 8px 15px;
    font-size: 12px;
    font-weight: bold;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pending-request-item {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
}

.pending-request-item .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin-right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #fff;
    font-size: 13px;
    flex-shrink: 0;
}

.request-info {
    flex: 1;
}

.request-name {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
}

.request-actions {
    display: flex;
    gap: 8px;
}

.accept-btn, .decline-btn {
    padding: 5px 12px;
    border: none;
    border-radius: 12px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
}

.accept-btn {
    background-color: #1cc88a;
    color: white;
}

.accept-btn:hover {
    background-color: #17a673;
}

.decline-btn {
    background-color: #e74c3c;
    color: white;
}

.decline-btn:hover {
    background-color: #c0392b;
}

/* Friends list container */
#friends-list-container {
    flex: 1;
    overflow-y: auto;
    padding: 5px 0;
}

.friend-item {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s;
    position: relative;
}

.friend-item:hover {
    background-color: #f5f5f5;
}

.friend-item.editing-nickname {
    background-color: #f0f8ff;
}

.friend-main {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 12px;
}

.friend-item .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #fff;
    font-size: 14px;
    flex-shrink: 0;
}

.friend-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.friend-name {
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

.friend-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ccc;
}

.friend-status.online {
    background-color: #1cc88a;
}

.friend-status.offline {
    background-color: #ccc;
}

.unread-badge {
    background-color: #e74c3c;
    color: white;
    font-size: 11px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    margin-right: 8px;
}

.friend-actions {
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    gap: 5px;
    margin-left: auto;
}

.friend-item:hover .friend-actions,
.friend-item.editing-nickname .friend-actions {
    opacity: 1;
}

.rename-friend-btn,
.remove-friend-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rename-friend-btn {
    color: #3498db;
}

.remove-friend-btn {
    color: #e74c3c;
    font-size: 18px;
}

.rename-friend-btn:hover,
.remove-friend-btn:hover {
    opacity: 0.7;
}

.friend-inline-editor {
    width: 100%;
    display: none;
}

.friend-nickname-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.friend-nickname-editor .editor-count {
    font-size: 11px;
    color: #999;
    text-align: right;
}

.friend-nickname-editor .editor-count.over-limit {
    color: #e74c3c;
    font-weight: 600;
}

.friend-nickname-editor input {
    width: 100%;
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
}

.friend-nickname-editor .editor-actions {
    display: flex;
    gap: 8px;
}

.friend-nickname-editor .editor-actions button {
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
}

.save-nickname-btn {
    border: none;
    background-color: #3498db;
    color: white;
}

.save-nickname-btn:hover {
    background-color: #2c80ba;
}

.cancel-nickname-btn {
    background-color: transparent;
    border: 1px solid #ccc;
    color: #666;
}

.friend-nickname-editor .editor-hint {
    font-size: 11px;
    color: #777;
}

.friend-nickname-editor .editor-error {
    font-size: 11px;
    color: #e74c3c;
    min-height: 14px;
}

.empty-state {
    text-align: center;
    color: #999;
    font-size: 13px;
    padding: 30px 20px;
}

/* Chat view */
.chat-view-header {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid #ddd;
    background-color: #f7f7f7;
}

#back-to-friends-list {
    background: none;
    border: none;
    font-size: 20px;
    color: #555;
    cursor: pointer;
    padding: 5px;
    margin-right: 10px;
}

#back-to-friends-list:hover {
    opacity: 0.7;
}

#current-chat-name {
    font-size: 15px;
    font-weight: bold;
    color: #333;
}

#friend-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    background-color: #fdfdfd;
}

/* Sent vs received messages */
.chat-message.sent,
.chat-message.received {
    flex-direction: row;
}

.chat-message.sent {
    justify-content: flex-end;
}

.chat-message.received {
    justify-content: flex-start;
}

.chat-message.sent .message-content {
    align-items: flex-end;
}

.chat-message.received .message-content {
    align-items: flex-start;
}

.chat-message.sent .message-text {
    background-color: #50ca59;
    color: white;
    border-color: #50ca59;
}

/* Dark mode for friends chat */
body.dark #friends-list-view,
body.dark #chat-view {
    background-color: #2c2c2c;
}

body.dark .friends-header {
    border-bottom-color: #555;
}

body.dark #friend-search-input {
    background-color: #444;
    border-color: #666;
    color: #eee;
}

body.dark #add-friend-btn {
    color: #5fdb6a;
}

body.dark .search-result-item {
    border-bottom-color: #555;
}

body.dark .user-email {
    color: #eee;
}

body.dark #pending-requests-container {
    background-color: #333;
    border-bottom-color: #555;
}

body.dark .requests-header {
    color: #aaa;
}

body.dark .pending-request-item {
    border-bottom-color: #555;
}

body.dark .request-name {
    color: #eee;
}

body.dark .friend-item {
    border-bottom-color: #555;
}

body.dark .friend-item:hover {
    background-color: #3a3a3a;
}

body.dark .friend-item.editing-nickname {
    background-color: #39424a;
}

body.dark .friend-name {
    color: #eee;
}

body.dark .friend-nickname-editor input {
    background-color: #444;
    border-color: #666;
    color: #eee;
}

body.dark .friend-nickname-editor .editor-count {
    color: #bbb;
}

body.dark .friend-nickname-editor .editor-hint {
    color: #bbb;
}

body.dark .cancel-nickname-btn {
    border-color: #777;
    color: #ddd;
}

body.dark .save-nickname-btn {
    background-color: #2c7cb0;
}

body.dark .chat-view-header {
    background-color: #2a2a2a;
    border-bottom-color: #555;
}

body.dark #back-to-friends-list,
body.dark #current-chat-name {
    color: #eee;
}

body.dark #friend-chat-messages {
    background-color: #2c2c2c;
}

body.dark .chat-message.sent .message-text {
    background-color: #3da647;
    border-color: #3da647;
}
