/* Chat System Styles for OFFSZN */
:root {
    box-sizing: border-box;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --chat-bg: #000000;
    --chat-sidebar-bg: #000000;
    --chat-border: #262626;
    --chat-hover: #121212;
    --chat-accent: #7c3aed;
    --chat-text: #ffffff;
    --chat-subtext: #8e8e8e;

    /* Updated Colors for Instagram-like feel */
    --chat-bubble-sent: #7209b7;
    /* OFFSZN Purple */
    --chat-bubble-received: #262626;
    /* Dark Grey */
    --chat-bubble-sent-text: #ffffff;
}

.chat-wrapper {
    display: flex;
    height: calc(100vh - 80px);
    /* Subtract Navbar height */
    background: var(--chat-bg);
    margin: 0;
    max-width: none;
    width: 100%;
    font-family: 'Inter', sans-serif;
    overflow: hidden;
    border-left: 1px solid var(--chat-border);
    border-right: 1px solid var(--chat-border);
}

/* =========================================
   SIDEBAR STYLES (Restored)
   ========================================= */
.chat-sidebar {
    width: 350px;
    min-width: 350px;
    background: var(--chat-sidebar-bg);
    border-right: 1px solid var(--chat-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tabs-nav {
    display: flex;
    padding: 0 20px;
    margin-bottom: 0px;
    border-bottom: 1px solid var(--chat-border);
}

.tab-btn {
    background: none;
    border: none;
    color: var(--chat-subtext);
    padding: 12px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    position: relative;
}

.tab-btn.active {
    color: #fff;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 2px;
    background: #fff;
}

.search-bar-container {
    padding: 16px 20px;
}

.search-input-wrapper {
    position: relative;
    background: #262626;
    border-radius: 10px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
}

.search-input-wrapper i {
    color: #8e8e8e;
    margin-right: 10px;
    font-size: 0.9rem;
}

.search-input-wrapper input {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 0.95rem;
    width: 100%;
    outline: none;
}

/* STORIES ROW */
.stories-row {
    display: flex;
    gap: 16px;
    padding: 10px 20px 20px;
    overflow-x: auto;
    scrollbar-width: none;
}

.stories-row::-webkit-scrollbar {
    display: none;
}

.story-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 60px;
    cursor: pointer;
}

.story-ring {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    padding: 2px;
    background: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #333;
    border: 3px solid #000;
    overflow: hidden;
}

.story-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.story-name {
    font-size: 0.75rem;
    color: #ccc;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 60px;
}

/* CHAT LIST */
.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-list::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-list::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 10px;
}

.chat-list::-webkit-scrollbar-thumb:hover {
    background: #444;
}

.chat-item {
    display: flex;
    padding: 12px 20px;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
    overflow: hidden;
}

.chat-item:hover,
.chat-item.active {
    background: var(--chat-hover);
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #333;
    overflow: hidden;
    flex-shrink: 0;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

.chat-name {
    color: #fff;
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.chat-preview {
    color: var(--chat-subtext);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 180px;
}

.unread-dot {
    width: 8px;
    height: 8px;
    background: var(--chat-accent);
    border-radius: 50%;
    margin-left: auto;
}

.delete-chat-btn {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 5;
}

.delete-chat-btn:hover {
    background: #ef4444;
    color: #fff;
}

/* =========================================
   MAIN CHAT AREA (Restored & Updated)
   ========================================= */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #000;
    position: relative;
}

.chat-content-constrained {
    width: 100%;
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    height: 70px;
    border-bottom: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    width: 100%;
}

.chat-header-inner {
    width: 100%;
    max-width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 40px;
    margin: 0;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #333;
    overflow: hidden;
}

.header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-socials {
    display: flex;
    gap: 12px;
    align-items: center;
}

.header-social-link {
    color: var(--chat-subtext);
    font-size: 1.1rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-social-link:hover {
    color: #fff;
    transform: scale(1.1);
}

.header-details h3 {
    margin: 0;
    font-size: 1rem;
    color: #fff;
}

.header-details span {
    font-size: 0.8rem;
    color: #888;
}

.chat-actions {
    display: flex;
    gap: 16px;
}

.action-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
}

/* MESSAGES FEED */
.messages-feed {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.messages-feed::-webkit-scrollbar {
    width: 6px;
}

.messages-feed::-webkit-scrollbar-track {
    background: transparent;
}

.messages-feed::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 10px;
}

.messages-feed::-webkit-scrollbar-thumb:hover {
    background: #444;
}

.messages-feed-inner {
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 20px 0;
    margin: 0;
}

/* =========================================
   NAMESPACED MESSAGE STYLES (oz-*)
   ========================================= */

.oz-message-row {
    display: flex;
    /* direction handled by received/sent */
    max-width: 75%;
    width: fit-content !important;
    position: relative;
    margin-bottom: 4px;
    padding: 0 16px;
    gap: 8px;
    /* Gap between avatar and bubble */
}

/* Alignments */
.oz-message-row.sent {
    align-self: flex-end;
    align-items: flex-end;
    flex-direction: row-reverse;
    /* No avatar usually, but for consistency if added */
}

.oz-message-row.received {
    align-self: flex-start;
    align-items: flex-end;
    /* Avatar at bottom */
    flex-direction: row;
}

.oz-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.oz-msg-body {
    display: flex;
    flex-direction: column;
    /* max-width removed to let oz-bubble handle it */
}

.oz-message-row.sent .oz-msg-body {
    align-items: flex-end;
}

.oz-message-row.received .oz-msg-body {
    align-items: flex-start;
}

.oz-bubble {
    padding: 10px 16px;
    border-radius: 22px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    width: fit-content;

    /* Text wrapping */
    word-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
}

/* SENT BUBBLE - Purple Gradient */
.oz-message-row.sent .oz-bubble {
    background: linear-gradient(135deg, #7c3aed 0%, #5b21b6 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* RECEIVED BUBBLE - Dark Grey */
.oz-message-row.received .oz-bubble {
    background: #262626;
    color: #fff;
    border-bottom-left-radius: 4px;
}

/* Container inside row (for Actions + Bubble) */
.oz-msg-container {
    display: flex;
    align-items: center;
    gap: 8px;
    width: fit-content;
}

.oz-message-row.sent .oz-msg-container {
    flex-direction: row-reverse;
}

/* Time/Date */
.oz-date-header {
    align-self: center;
    font-size: 0.75rem;
    color: #555;
    margin: 20px 0 10px 0;
    font-weight: 500;
}

.oz-time {
    font-size: 0.65rem;
    color: #555;
    margin-top: 2px;
    margin-right: 4px;
}

.oz-message-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.oz-message-row:hover .oz-message-actions {
    opacity: 1;
}

/* MENU CONTAINER & DROPDOWN */
.oz-menu-container {
    position: relative;
    display: flex;
    align-items: center;
}

.oz-msg-menu {
    position: absolute;
    bottom: 125%;
    /* Show above actions for better visibility */
    right: 0;
    background: rgba(26, 26, 26, 0.98);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 30px;
    /* Pill shape menu */
    padding: 2px 4px;
    min-width: unset;
    width: max-content;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 100;
    display: none;
    flex-direction: row;
    /* Horizontal layout */
}

/* For received messages, move menu to the left of the button if preferred */
.oz-message-row.received .oz-msg-menu {
    right: auto;
    left: 0;
}

.oz-msg-menu.active {
    display: flex;
    animation: oz-menu-pop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes oz-menu-pop {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.oz-menu-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.oz-menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.oz-menu-item i {
    font-size: 1rem;
}

/* Helper Elements */
.msg-action-btn {
    background: none;
    border: none;
    color: #8e8e8e;
    font-size: .9rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s, color .2s;
}

.msg-action-btn:hover {
    background: #262626;
    color: #fff;
}

/* =========================================
   INPUT AREA
   ========================================= */
.chat-input-area {
    display: flex;
    flex-direction: column;
    width: 100%;
    position: relative;
    background: #000;
}

.input-container-wrapper {
    width: 100%;
    max-width: 100%;
    padding: 16px 40px;
}

.input-container {
    background: #1a1a1a;
    border-radius: 24px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.input-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0;
    display: flex;
}

.input-btn:hover {
    color: var(--chat-accent);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 0.95rem;
    outline: none;
    resize: none;
    max-height: 150px;
    overflow-y: auto;
    padding: 2px 0;
    line-height: 1.4;
    font-family: inherit;
}

.chat-input::placeholder {
    color: #666;
}

.chat-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #fff;
}

.chat-placeholder i {
    font-size: 4rem;
    margin-bottom: 16px;
    color: #333;
}

/* Emoji Picker & Helpers */
.custom-emoji-picker {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    padding: 10px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 12px;
    max-height: 200px;
    overflow-y: auto;
    width: 280px;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    user-select: none;
}

.custom-emoji-picker span {
    font-size: 1.5rem;
    cursor: pointer;
    text-align: center;
    padding: 5px;
    border-radius: 8px;
    transition: background 0.2s;
}

.custom-emoji-picker span:hover {
    background: #333;
}

.custom-emoji-picker::-webkit-scrollbar {
    width: 6px;
}

.custom-emoji-picker::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 10px;
}

/* Reply Preview */
.reply-preview-container {
    background: #000;
    border-top: 1px solid var(--chat-border);
    padding: 12px 40px;
    display: none;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.reply-preview-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.reply-preview-user {
    font-size: 0.8rem;
    color: #fff;
}

.reply-preview-text {
    color: #666;
}

/* REPLY HEADER Styles */
.oz-reply-header {
    font-size: 0.75rem;
    color: #8e8e8e;
    margin-bottom: 4px;
    font-weight: 500;
}

/* REPLY QUOTE - EXTERNAL STACKED STYLE */
.oz-reply-external {
    margin-bottom: -10px;
    /* Overlap with bubble */
    z-index: 0;
    max-width: 100%;
    transform: scale(0.95);
    /* Slightly smaller */
    transform-origin: inherit;
    /* Scale from left/right depending on flex alignment */
}

/* Ensure scale origin aligns with the side */
.oz-message-row.sent .oz-reply-external {
    transform-origin: bottom right;
    margin-right: 12px;
    /* Align visually with bubble curvature */
}

.oz-message-row.received .oz-reply-external {
    transform-origin: bottom left;
    margin-left: 12px;
}

.reply-quote-container {
    background: rgba(59, 130, 246, 0.15);
    /* More blue-ish per Image 1 */
    border-radius: 18px;
    /* More pill-shaped */
    padding: 8px 16px;
    padding-bottom: 12px;
    margin-bottom: -8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
    position: relative;
    border: 1px solid rgba(59, 130, 246, 0.3);
    transition: background 0.2s;
    z-index: 1;
    max-width: fit-content;
}

.reply-quote-container:hover {
    background: rgba(59, 130, 246, 0.25);
}

/* Highlight animation Instagram-style */
@keyframes oz-flash {
    0% {
        filter: brightness(1.8);
    }

    100% {
        filter: brightness(1);
    }
}

.oz-highlight .oz-bubble {
    animation: oz-flash 1.5s ease-out !important;
}

/* User name in quote */
.reply-quote-user {
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 2px;
}

/* Text in quote */
.reply-quote-text {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Tweaks to main bubble */
.oz-bubble {
    z-index: 2;
    /* Sit on top of reply */
    position: relative;
}


/* Reactions */
.message-reaction-bubble {
    position: absolute;
    bottom: -15px;
    /* Lower per image 1 */
    right: 12px;
    background: #1a1a1a;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    /* Pill shape */
    padding: 2px 8px;
    font-size: 0.9rem;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    z-index: 5;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.oz-message-row.sent .message-reaction-bubble {
    right: auto;
    left: 12px;
}

.reaction-popover {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 100px;
    padding: 6px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    z-index: 100;
    animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(0) scale(0.8);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(-8px) scale(1);
    }
}

.reaction-option {
    font-size: 1.4rem;
    cursor: pointer;
    transition: transform 0.2s;
    line-height: 1;
}

.reaction-option:hover {
    transform: scale(1.2);
}