:root {
    --sidebar-width: 340px;
    --header-height: 60px;

    /* Default (Light) Theme Variables */
    --bg-body: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-header: #ffffff;
    --bg-card: #f2f2f2;
    --bg-hover: #f7f7f7;
    --bg-active: #eff3fa;

    --text-primary: #1a1a1a;
    --text-muted: #727272;
    --text-timestamp: #999;

    --border-color: #e6e6e6;

    --scroll-thumb: #dcdcdc;
    --scroll-thumb-hover: #bbb;

    --input-bg: #f0f2f5;

    /* Viber Colors */
    --primary-color: #7360f2;
    --primary-light: #f2f0ff;

    --msg-incoming-bg: #ffffff;
    --msg-incoming-text: #1a1a1a;
    --msg-incoming-border: #f0f0f0;

    --msg-outgoing-bg: #eef0fa;
    --msg-outgoing-text: #000;
}

[data-theme="dark"] {
    /* Dark Theme Variables (Viber-like) */
    --bg-body: #222326;
    --bg-sidebar: #2c2d30;
    --bg-header: #2c2d30;
    --bg-card: #36373a;
    --bg-hover: #3a3b3e;
    --bg-active: #323048;
    /* Slight purple tint for active */

    --text-primary: #e0e0e0;
    --text-muted: #a0a0a0;
    --text-timestamp: #676b70;

    --border-color: #2f3136;

    --scroll-thumb: #424242;
    --scroll-thumb-hover: #555;

    --input-bg: #2a2b2d;

    /* Dark Mode Specific Overrides */
    --primary-light: #2c294b;
    --primary-color: #8b7dff;
    /* Slighly lighter to pop on dark */

    --msg-incoming-bg: #2a2b2d;
    --msg-incoming-text: #e0e0e0;
    --msg-incoming-border: #383838;

    --msg-outgoing-bg: #4b428d;
    --msg-outgoing-text: #ffffff;
}

body,
html {
    height: 100%;
    height: 100dvh;
    margin: 0;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-primary);
    font-size: 14px;
    background-color: var(--bg-body);
}

.emoji-friendly {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
    font-variant-emoji: emoji;
}

.chat-info-name .text-muted,
.chat-info-name .fw-normal {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-variant-emoji: text;
}

.phone-text {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-variant-emoji: text;
}

#app {
    height: 100%;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scroll-thumb);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scroll-thumb-hover);
}

/* Login View */
.login-container {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-card);
}

.login-card {
    width: 100%;
    max-width: 380px;
    border: none;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    background-color: var(--bg-header);
    color: var(--text-primary);
}

/* Main Layout */
.app-container {
    display: flex;
    height: 100vh;
    background-color: var(--bg-body);
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-header);
}

.sidebar-header h5 {
    color: var(--primary-color) !important;
    font-weight: 700;
    font-size: 18px;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid transparent;
    /* Cleaner look */
    cursor: pointer;
    transition: background-color 0.1s;
    position: relative;
    height: 72px;
    /* Fixed height for consistency */
}

.chat-item:hover {
    background-color: var(--bg-hover);
}

.chat-item.active {
    background-color: var(--bg-active);
    /* Light blue/grey active state like Viber */
}

/* Active indicator line */
.chat-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 10px;
    bottom: 10px;
    width: 4px;
    background-color: var(--primary-color);
    border-radius: 0 4px 4px 0;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    /* background-color: #d1d8e6; Removed to prevent conflict */
    color: #555;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 15px;
    flex-shrink: 0;
    text-transform: uppercase;
    user-select: none;
    /* background-image: linear-gradient(135deg, #e6e9f0 0%, #eef1f5 100%); Removed default gradient */
}

.chat-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.chat-info-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-info-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-info-time {
    font-size: 12px;
    color: var(--text-timestamp);
}

.chat-info-preview {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 5px;
}

.badge-platform {
    font-size: 10px;
    padding: 2px 6px;
    background: #f0f0f0;
    color: #666;
    border-radius: 4px;
    font-weight: 500;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-sidebar);
    font-size: 12px;
    color: var(--text-muted);
}

/* Main Chat Area */
.main-chat {
    flex: 1;
    min-width: 0;
    /* Takes remaining width */
    display: flex;
    flex-direction: column;
    background-color: var(--bg-body);
    /* Optional slight pattern */
    background-image: radial-gradient(var(--border-color) 1px, transparent 1px);
    background-size: 20px 20px;
    min-width: 0;
    /* Important */
    position: relative;
}

.chat-header {
    height: var(--header-height);
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-header);
    display: flex;
    align-items: center;
    padding: 0 20px;
    justify-content: space-between;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
    z-index: 10;
    flex-shrink: 0;
}

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

.chat-header h5 {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.messages-area {
    flex: 1;
    padding: 20px 30px;
    overflow-y: auto;
    display: flex;
    flex-direction: column-reverse;
    gap: 6px;
}

/* Messages */
.message-row {
    display: flex;
    flex-direction: column;
    width: 100%;
    margin-bottom: 8px;
    max-width: 1000px;
    margin-left: auto;
    margin-right: auto;
}

.message-bubble {
    padding: 8px 14px;
    border-radius: 18px;
    max-width: 65%;
    position: relative;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.03);
    font-size: 14.5px;
    line-height: 1.45;
    word-wrap: break-word;
    transition: background-color 0.5s ease;
}

/* Quote Button Styles */
.message-quote-btn {
    opacity: 0;
    transition: opacity 0.2s ease;
    position: absolute;
    top: 5px;
    right: 5px;
    color: var(--text-muted);
    background: var(--bg-hover);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    padding: 0;
    border: none;
}

.message-bubble:hover .message-quote-btn {
    opacity: 1;
}

.message-quote-btn:hover {
    background: var(--bg-body);
    color: var(--primary-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Quick Replies Chips */
.quick-replies-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-self: flex-end;
    /* Align to the bottom of the flex row (bubble) */
    align-items: center;
    /* Center align chips vertically relative to each other */
    margin-top: 4px;
    opacity: 1;
    /* More visible */
    padding-left: 10px;
    /* Space for rotation */
    margin-bottom: 2px;
    /* Slight offset from bottom edge */
}

.quick-reply-chip {
    font-size: 0.75rem;
    padding: 4px 10px;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    cursor: pointer;
    color: #495057;
    transition: all 0.2s;
    white-space: nowrap;
    text-align: center;
    /* Center text */
    display: table;
    transform-origin: center center;
    /* Rotate around center */
    box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.05);
    /* Soft shadow */
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

/* Random rotations for "handwritten" feel */
.quick-reply-chip:nth-child(odd) {
    transform: rotate(-2deg);
    margin-left: -2px;
    /* Slight offset */
}

.quick-reply-chip:nth-child(even) {
    transform: rotate(2deg);
    margin-left: 2px;
}

.quick-reply-chip:nth-child(3n) {
    transform: rotate(1deg);
}

.quick-reply-chip:nth-child(5n) {
    transform: rotate(-3deg);
}


.quick-reply-chip:hover {
    transform: scale(1.1) rotate(0deg) !important;
    z-index: 10;
    background-color: var(--bg-hover);
    border-color: var(--primary-color);
    color: var(--primary-color);
    opacity: 1;
}

/* Bottom Quick Replies - auto bubble layout */
.quick-replies-bottom {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
}

.quick-replies-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 6px;
}

.quick-replies-preset-btn {
    font-size: 0.74rem;
    line-height: 1.2;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    background: var(--bg-card);
    padding: 3px 10px;
}

.quick-replies-preset-btn:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background: var(--bg-hover);
}

.quick-replies-grid {
    --qr-gap: 5px;
    --qr-min-height: 160px;
    --qr-font-size: 14.5px;
    --qr-padding-y: 7px;
    --qr-padding-x: 10px;
    --qr-radius: 18px;
    --qr-radius-tail: 4px;
    display: flex;
    flex-wrap: wrap-reverse;
    justify-content: flex-start;
    align-items: flex-start;
    align-content: flex-start;
    gap: var(--qr-gap);
    min-height: var(--qr-min-height);
}

.quick-replies-grid.packery-ready {
    position: relative;
    min-height: calc(var(--qr-min-height) + 20px);
    display: block;
}

.quick-replies-grid--compact {
    --qr-gap: 4px;
    --qr-min-height: 140px;
    --qr-font-size: 13.5px;
    --qr-padding-y: 5px;
    --qr-padding-x: 9px;
    --qr-radius: 14px;
}

.quick-replies-grid--balanced {
    --qr-gap: 5px;
    --qr-min-height: 160px;
    --qr-font-size: 14.5px;
    --qr-padding-y: 7px;
    --qr-padding-x: 10px;
    --qr-radius: 18px;
}

.quick-replies-grid--cozy {
    --qr-gap: 6px;
    --qr-min-height: 186px;
    --qr-font-size: 15px;
    --qr-padding-y: 8px;
    --qr-padding-x: 12px;
    --qr-radius: 20px;
}

.quick-replies-grid--focus {
    --qr-gap: 7px;
    --qr-min-height: 210px;
    --qr-font-size: 15.5px;
    --qr-padding-y: 9px;
    --qr-padding-x: 13px;
    --qr-radius: 22px;
}

.quick-reply-cell {
    border: 1px solid var(--msg-outgoing-border, var(--border-color));
    background: var(--msg-outgoing-bg);
    color: var(--msg-outgoing-text);
    border-radius: var(--qr-radius);
    border-bottom-right-radius: var(--qr-radius-tail);
    padding: var(--qr-padding-y) var(--qr-padding-x);
    text-align: left;
    min-height: 34px;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    width: auto;
    min-width: calc(var(--quick-reply-min-word-ch, 1) * 0.72ch + 2.2rem);
    max-width: var(--quick-reply-width, 20%);
    font-size: var(--qr-font-size);
    line-height: 1.45;
    word-wrap: normal;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.03);
    transition: border-color 0.2s, background-color 0.2s, transform 0.15s ease;
}

.quick-reply-cell:hover {
    border-color: var(--primary-color);
    background: var(--bg-hover);
    transform: translateY(-1px);
}

.quick-reply-cell-text {
    display: block;
    width: 100%;
    overflow: visible;
    text-overflow: clip;
    white-space: pre-wrap;
    word-break: normal;
    overflow-wrap: normal;
    font-size: inherit;
    line-height: inherit;
}

.quick-reply-cell-edit {
    border-style: dashed;
    color: var(--text-muted);
    width: auto;
    max-width: none;
}

.msg-incoming-wrapper {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
}

.highlight-anim {
    animation: flash-highlight 2s ease-out;
}

@keyframes flash-highlight {
    0% {
        background-color: #ffeb3b;
    }

    30% {
        background-color: #ffeb3b;
    }

    100% {
        background-color: inherit;
    }
}

.clickable-quote {
    cursor: pointer;
    transition: background-color 0.2s;
}

.clickable-quote:hover {
    background-color: var(--bg-hover) !important;
}

.msg-incoming {
    align-items: flex-start;
}

.msg-incoming .message-bubble {
    background-color: var(--msg-incoming-bg);
    border: 1px solid var(--msg-incoming-border);
    border-bottom-left-radius: 4px;
    color: var(--msg-incoming-text);
}

.msg-outgoing {
    align-items: flex-end;
}

.msg-outgoing .message-bubble {
    background-color: var(--msg-outgoing-bg);
    border-bottom-right-radius: 4px;
    color: var(--msg-outgoing-text);
    margin-left: auto;
    /* Ensure strict right alignment */
    margin-right: 0;
}

.msg-timestamp {
    display: block;
    text-align: right;
    font-size: 10px;
    color: var(--text-timestamp);
    margin-top: 2px;
    line-height: 1;
}

.msg-outgoing .msg-timestamp {
    color: rgba(0, 0, 0, 0.6);

    padding: 2px 5px;
    border-radius: 8px;
    display: inline-block;
    margin-top: 4px;
}

.empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 16px;
    flex-direction: column;
    gap: 10px;
}

.empty-state i {
    font-size: 48px;
    color: var(--border-color);
}

/* Input Area */
.chat-input-container {
    padding: 15px 20px;
    background-color: var(--bg-header);
    border-top: 1px solid var(--border-color);
}

.chat-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    position: relative;
    /* For absolute positioning context if needed */
}

/* New Input Group wrapper for textarea + badge */
.input-with-badge-wrapper {
    position: relative;
    flex-grow: 1;
    display: flex;
    align-items: flex-end;
}

/* Position the sender dropdown as a left fill of the input area */
.input-sender-dropdown {
    position: absolute !important;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 5;
    display: flex;
}

.input-sender-dropdown .btn-sender-fill {
    height: 100%;
    border-top-left-radius: 20px;
    border-bottom-left-radius: 20px;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    margin-right: 4px;
    /* Slight gap or 0 */
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 0.8rem;
    box-shadow: inset -1px 0 2px rgba(0, 0, 0, 0.1);
}

.input-sender-dropdown .btn-sender-fill:hover {
    filter: brightness(1.1);
}

/* Adjust textarea to make room for the badge */
.message-input {
    flex-grow: 1;
    border: none;
    background-color: var(--input-bg);
    border-radius: 20px;
    padding: 12px 15px 12px 75px;
    /* Adjusted padding for the fill button */
    resize: none;
    min-height: 44px;
    max-height: 150px;
    font-size: 14px;
    line-height: 1.4;
    outline: none;
    box-shadow: none;
}

.message-input:focus {
    background-color: var(--bg-body);
    /* Slightly lighter on focus if needed */
    box-shadow: 0 0 0 1px var(--border-color);
}

.template-btn {
    border-radius: 50%;
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    background: transparent;
    border: none;
    transition: background 0.2s;
}

.template-btn:hover {
    background: var(--bg-hover);
    color: var(--primary-color);
}

.send-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--primary-color);
    font-size: 20px;
}

.send-btn:hover {
    color: #5c4cbc;
    transform: scale(1.1);
}

/* Templates Panel */
.templates-panel {
    width: 320px;
    background-color: var(--bg-hover);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.templates-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-header);
    font-weight: 600;
}

.templates-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.template-item {
    background: var(--bg-header);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    color: var(--text-primary);
}

.template-item:hover {
    border-color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.template-actions {
    position: absolute;
    top: 5px;
    right: 5px;
    opacity: 0;
    transition: opacity 0.2s;
}

.template-item:hover .template-actions {
    opacity: 1;
}

.template-content {
    white-space: pre-wrap;
    line-height: 1.35;
}

.template-content.collapsed {
    position: relative;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    padding-right: 0.25rem;
}

.template-content.collapsed::after {
    content: "…";
    position: absolute;
    right: 0;
    bottom: 0;
    padding-left: 0.35rem;
    color: var(--text-muted);
    background: linear-gradient(to right, rgba(255, 255, 255, 0), var(--bg-header) 45%);
}

.template-expand-toggle {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.template-expand-toggle:hover {
    color: var(--primary-color);
}


/* Mobile Optimization */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 70px;
    }

    /* Minimalist sidebar (Avatar only) */
    .chat-info,
    .sidebar-footer {
        display: none !important;
    }

    /* Dynamic Sidebar Header */
    .sidebar-header {
        justify-content: center;
        padding: 0;
        cursor: pointer;
        position: relative;
    }

    /* Default collapsed state items hidden */
    .sidebar-header h5 span,
    .sidebar-header .dropdown,
    .sidebar-header .header-controls {
        display: none;
    }

    .sidebar-header h5 i {
        margin: 0 !important;
    }

    /* Expanded Sidebar Header State (Overlay) */
    .header-expanded.sidebar-header {
        position: absolute;
        top: 0;
        left: 0;
        width: 300px;
        height: auto;
        min-height: var(--header-height);
        z-index: 1100;
        background: var(--bg-header);
        box-shadow: 4px 4px 12px rgba(0, 0, 0, 0.15);
        padding: 0 16px;
        justify-content: space-between;
        align-items: center;
        border-radius: 0 0 8px 0;
        border-right: 1px solid var(--border-color);
        border-bottom: 1px solid var(--border-color);
    }

    .header-expanded.sidebar-header h5 span,
    .header-expanded.sidebar-header .dropdown,
    .header-expanded.sidebar-header .header-controls {
        display: block;
    }

    .header-expanded.sidebar-header .header-controls {
        display: flex;
        align-items: center;
    }

    /* Search Expansion on Mobile */
    .search-wrapper {
        z-index: 1000;
    }

    /* If search is NOT collapsed (i.e. isExpanded), make it float wider */
    .search-wrapper:not(.collapsed) {
        position: absolute;
        top: 60px;
        left: 5px;
        width: 280px;
        background: var(--bg-header);
        padding: 8px;
        border-radius: 8px;
        box-shadow: 2px 4px 12px rgba(0, 0, 0, 0.15);
        border: 1px solid var(--border-color);
    }

    .chat-item {
        justify-content: center;
        padding: 10px 5px;
        position: relative;
    }

    .avatar {
        margin: 0;
        width: 48px;
        height: 48px;
    }

    /* Unread badge on avatar for mobile */
    .chat-item .badge.bg-danger {
        position: absolute;
        top: 5px;
        right: 5px;
        font-size: 10px;
        padding: 3px 6px;
        border: 2px solid white;
    }

    /* Active indicator */
    .chat-item.active::before {
        left: 0;
        height: 100%;
        width: 4px;
        border-radius: 0 4px 4px 0;
        border: none;
        background-color: var(--primary-color);
    }

    /* Slide-out Templates Panel (Drawer) */
    .templates-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 85%;
        max-width: 340px;
        z-index: 1050;
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.15);
        border-left: none;
        animation: slideInRight 0.3s ease-out;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
    }

    to {
        transform: translateX(0);
    }
}

/* 1. Sidebar Toolbar & Search */
.search-wrapper {
    position: relative;
    padding: 5px 15px;
    min-height: 50px;
    display: flex;
    align-items: center;
    background: var(--bg-header);
    z-index: 10;
}

.toolbar-actions button {
    transition: all 0.2s ease;
    border: 1px solid transparent !important;
}

.toolbar-actions button:hover {
    background-color: var(--bg-hover) !important;
    color: var(--primary-color) !important;
}

/* Search Expansion Animation */
.search-expanded-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: var(--bg-header);
    overflow: hidden;
    transition: width 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    z-index: 20;
    opacity: 0;
    pointer-events: none;
}

.search-expanded-overlay.active {
    width: 100%;
    opacity: 1;
    pointer-events: auto;
    padding: 6px 12px;
}

.search-expanded-overlay .input-group-text,
.search-expanded-overlay .btn {
    background-color: transparent !important;
    border-color: var(--border-color) !important;
}

.search-expanded-overlay input {
    border-color: var(--border-color) !important;
    box-shadow: none !important;
}

/* 2. Main Chat Header Mobile Optimize */
.chat-header {
    height: auto !important;
    min-height: var(--header-height);
    flex-wrap: wrap;
    padding: 10px 15px !important;
    gap: 10px;
}

.chat-header .header-actions {
    margin-left: auto;
}

.chat-header h5 {
    font-size: 15px;
    white-space: normal;
    /* Allow wrapping */
}

/* Chat Header Search Overlay */
.chat-search-overlay {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    width: 0;
    height: 40px;
    background: var(--bg-header);
    z-index: 20;
    transition: width 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    border-radius: 6px;
}

.chat-search-overlay.active {
    width: 300px;
    /* Fixed width expansion */
    opacity: 1;
    pointer-events: auto;
}

/* Mobile adjust */
@media (max-width: 768px) {
    .chat-search-overlay.active {
        width: 260px;
        /* Slightly smaller on mobile*/
    }
}

.hover-opacity-100 {
    transition: opacity 0.2s;
}

.group-hover-actions:hover .hover-opacity-100 {
    opacity: 1 !important;
}

/* Platform Short Code Badges */
.badge-sms {
    background-color: #FFC107 !important;
    color: #000 !important;
}

.badge-instagram {
    background-color: #E1306C !important;
    color: #fff !important;
}

.badge-facebook {
    background-color: #4267B2 !important;
    color: #fff !important;
}

.badge-unknown,
.badge-secondary {
    background-color: #6c757d !important;
    color: #fff !important;
}

.badge-danger {
    background-color: #e91e63 !important;
    /* Pink for platform warning */
    color: #fff !important;
}

/* Failed outgoing message styling */
.msg-outgoing.msg-failed .message-bubble {
    background-color: #fff0f0;
    border: 1px solid #ffcccc;
    color: var(--msg-outgoing-text);
}

.msg-outgoing.msg-failed .msg-timestamp {
    color: #d1baba !important;
}

.msg-outgoing.msg-failed .msg-status i {
    color: #dc3545 !important;
}

/* Sender Dropdown Columns */
.sender-dropdown-menu {
    width: auto !important;
    /* Allow shrinking to content */
    padding: 0;
    overflow: hidden;
    min-width: 140px;
    /* Minimum width for 2 compact columns */
}

.sender-columns-container {
    display: flex;
    flex-direction: row;
    background-color: #fff;
    justify-content: center;
}

.sender-column {
    display: flex;
    flex-direction: column;
    min-width: 60px;
    /* Minimal width for just badges */
    padding: 0 4px;
    /* Slight horizontal padding */
}

/* Border between columns */
.sender-column:first-child {
    border-right: 1px solid var(--border-color);
}

.sender-column-header {
    padding: 10px 0;
    background-color: #f8f9fa;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 40px;
}

.sender-column-list {
    padding: 4px 0;
    max-height: 250px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sender-column-list .dropdown-item {
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    border-radius: 8px;
    margin: 2px 0;
}

.sender-column-list .dropdown-item:active,
.sender-column-list .dropdown-item.active {
    background-color: var(--bs-primary-bg-subtle, #e9ecef);
    color: inherit;
}

/* Platform badges */
.badge-viber {
    background-color: #7360f2 !important;
    color: #fff !important;
}

.badge-telegram {
    background-color: #24A1DE !important;
    color: #fff !important;
}

.badge-whatsapp {
    background-color: #25D366 !important;
    color: #fff !important;
}

.badge-rozetka {
    background-color: #00a046 !important;
    color: #fff !important;
}

/* Dark theme adjustments */
[data-theme="dark"] .badge-viber {
    background-color: #8b7dff !important;
    color: #fff !important;
}

[data-theme="dark"] .badge-telegram {
    background-color: #40b3e6 !important;
    color: #fff !important;
}

/* Mobile adjustment for message bubbles to allow up to 340px media */
@media (max-width: 768px) {
    .message-bubble {
        max-width: 88%;
    }
}

/* Changelog Widget */
.changelog-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 320px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1050;
    transition: all 0.3s ease;
    cursor: pointer;
    display: none;
    flex-direction: column-reverse;
    flex-direction: column;
}

.changelog-header {
    padding: 10px 15px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    font-weight: 600;
    user-select: none;
}

.changelog-content {
    background: var(--bg-body);
    padding: 0 15px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
    opacity: 0;
}

/* Collapsed state (3 lines with fade) */
.changelog-widget:not(.expanded) .changelog-content {
    max-height: 4.5em;
    /* Approx 3 lines line-height 1.5 */
    padding: 10px 15px;
    opacity: 0.8;
    mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
}

.changelog-widget.expanded .changelog-content {
    max-height: 400px;
    /* Enough for content */
    padding: 10px 15px;
    opacity: 1;
    mask-image: none;
    -webkit-mask-image: none;
}

/* Integrated Changelog in Templates Panel */
.templates-list-content {
    flex: 1;
    overflow-y: auto;
}

.changelog-integrated {
    border-top: 1px solid var(--border-color);
    background: var(--bg-card);
    flex-shrink: 0;
}

.changelog-integrated .changelog-header {
    background: transparent;
    border-bottom: none;
    padding: 10px 15px;
    cursor: pointer;
}

.changelog-integrated .changelog-content {
    background: transparent;
    border-top: 1px solid var(--border-color);
    transition: max-height 0.3s ease;
    overflow-y: auto;
    /* Internal scroll if too long */
}

/* Adjust integrated collapsed state */
.changelog-integrated:not(.expanded) .changelog-content {
    max-height: 0;
    padding: 0 15px;
    border-top: none;
    opacity: 0;
}

.changelog-integrated.expanded .changelog-content {
    max-height: 250px;
    /* Limit height inside panel */
    padding: 10px 15px;
    border-top: 1px solid var(--border-color);
    opacity: 1;
}

.drag-over-target {
    border-left: 3px solid var(--primary-color) !important;
    background-color: #e9ecef !important;
    transform: translateX(2px);
    transition: all 0.1s ease;
}