:root {
    /* Telegram Web Light Theme Variables (Synced with default.tdesktop-theme) */
    --bg-color: #ffffff;
    /* windowBg */
    --sidebar-bg: #ffffff;
    /* windowBg / dialogsBg */
    --chat-bg: #9ac2de;
    /* Fallback if no pattern */
    --header-bg: #ffffff;
    /* windowBg */
    --input-bg: #f1f1f1;
    /* windowBgOver approx */
    --text-primary: #000000;
    /* windowFg */
    --text-secondary: #999999;
    /* windowSubTextFg */
    --accent-color: #40a7e3;
    /* windowBgActive */
    --message-bg-in: #ffffff;
    /* msgInBg */
    --message-bg-out: #effdde;
    /* msgOutBg */
    --msg-text: #000000;
    /* historyTextInFg */
    --msg-meta: #a0acb6;
    /* msgInDateFg */
    --link-color: #168acd;
    /* windowActiveTextFg */
    --border-color: #e0e0e0;
    /* inputBorderFg */
    --hover-color: #f1f1f1;
    /* windowBgOver */
    --scroll-thumb: rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] {
    /* Premium Dark Theme - Modern Graphite */
    --bg-color: #181818;
    --sidebar-bg: #212121;
    --chat-bg: #0f0f0f;
    --header-bg: #212121;
    --input-bg: #2c2c2e;
    --text-primary: #e0e0e0;
    --text-secondary: #aaaaaa;
    --accent-color: #5288c1;
    --message-bg-in: #2b2b2b;
    --message-bg-out: #3e5a7a;
    /* Muted Blue */
    --msg-text: #e0e0e0;
    --msg-meta: #7a8a9a;
    --link-color: #40c4ff;
    /* Extremely bright/visible blue */
    --border-color: #333333;
    --hover-color: #2c2c2e;
    --scroll-thumb: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .sidebar-header {
    background: linear-gradient(135deg, #212121 0%, #2c2c2e 100%);
}

[data-theme="dark"] .message.incoming {
    background: #2b2b2b;
    border: 1px solid #333;
}

[data-theme="dark"] .message.bugrov-message {
    background: #2b4a6f;
    /* Muted Blue */
    border: 1px solid #3e5a7a;
}

/* Service Message (System) Dark Mode */
[data-theme="dark"] .service-message {
    background-color: rgba(255, 255, 255, 0.1);
    color: #e0e0e0;
    padding: 4px 12px;
    border-radius: 12px;
    display: inline-block;
    margin: 5px auto;
    font-size: 13px;
    text-shadow: none;
}

/* Brighter Sender Names for Dark Mode */
[data-theme="dark"] .message-sender.color1 {
    color: #ff8a80;
}

[data-theme="dark"] .message-sender.color2 {
    color: #b9f6ca;
}

[data-theme="dark"] .message-sender.color3 {
    color: #ffe57f;
}

[data-theme="dark"] .message-sender.color4 {
    color: #82b1ff;
}

[data-theme="dark"] .message-sender.color5 {
    color: #ea80fc;
}

[data-theme="dark"] .message-sender.color6 {
    color: #ff80ab;
}

[data-theme="dark"] .message-sender.color7 {
    color: #80deea;
}

[data-theme="dark"] .message-sender.color8 {
    color: #ffcc80;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 320px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1), width 0.3s ease;
    z-index: 1001;
    /* Above everything on mobile */
}

/* Mobile: Sidebar is absolute overlay */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 80% !important;
        /* Max width on mobile */
        max-width: 320px;
        transform: translateX(-105%);
        /* Hide off-screen left */
        border-right: none;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.2);
    }

    .sidebar.open {
        transform: translateX(0);
    }
}

.sidebar.collapsed {
    width: 0;
    overflow: hidden;
    border: none;
}

.sidebar-header {
    padding: 15px;
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border-bottom: 1px solid var(--border-color);
}

#password-overlay {
    background: radial-gradient(circle at center, #1a1a1a 0%, #000000 100%) !important;
    backdrop-filter: blur(10px);
}

#password-overlay h2 {
    font-weight: 300;
    letter-spacing: 1px;
    margin-bottom: 30px;
    text-shadow: 0 0 15px rgba(255, 255, 255, 0.2);
}

#access-password {
    transition: all 0.3s ease;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1);
}

#access-password:focus {
    box-shadow: 0 0 0 2px var(--link-color);
    transform: translateY(-1px);
}

/* Toggle Sidebar Button (in Chat Header) */
#sidebar-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    margin-right: 15px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

#sidebar-toggle-btn:hover {
    color: var(--text-primary);
}

.search-bar input {
    width: 100%;
    padding: 10px;
    background-color: var(--input-bg);
    border: none;
    border-radius: 4px;
    color: var(--text-primary);
    outline: none;
}

/* Global Search Toggle */
#global-search-label {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

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

.chat-item {
    display: flex;
    padding: 10px;
    cursor: pointer;
    transition: background-color 0.2s;
}

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

.chat-item.active {
    background-color: #3390ec;
    /* Active blue */
}

.chat-item.active .chat-name,
.chat-item.active .last-message {
    color: white !important;
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: #555;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    margin-right: 10px;
    flex-shrink: 0;
    color: #fff;
    text-transform: uppercase;
}

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

.chat-name {
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.last-message {
    color: var(--text-secondary);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Chat Area */
/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
    min-height: 0;
    z-index: 1;
    /* User requested wallpaper is applied at the end of file */
}

/* Ensure Chat Content is above Canvas */
.chat-header,
.messages-container,
.input-area {
    position: relative;
    z-index: 10;
}


.chat-header {
    padding: 10px 20px;
    background-color: var(--header-bg);
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    height: 56px;
    flex-shrink: 0;
    z-index: 20;
}

.header-tools {
    margin-left: auto;
    display: flex;
    gap: 15px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 18px;
}

.icon-btn:hover {
    color: var(--text-primary);
}

.chat-title {
    font-size: 16px;
    margin-bottom: 2px;
}

.chat-status {
    font-size: 13px;
    color: var(--text-secondary);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    padding-bottom: 60px;
    /* Space for footer */
    /* FIX: Allow shrinking below content size */
    min-width: 0;
    min-height: 0;
    /* Critical for scroll */
    overflow-x: hidden;
    scroll-behavior: smooth;
    position: relative;
    /* Context for scroll measurements */
    animation: fadeInChat 0.4s cubic-bezier(0.1, 0.7, 0.1, 1);
}

@keyframes fadeInChat {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Footer Banner */
.footer-banner {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--bg-color);
    padding: 10px;
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    z-index: 10;
}

.footer-banner a {
    color: var(--link-color);
    text-decoration: none;
}

.info-link-highlight {
    color: #e65100 !important;
    font-weight: bold;
    background: #fff3e0;
    padding: 2px 8px;
    border-radius: 12px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        background: #fff3e0;
    }

    50% {
        background: #ffe0b2;
    }

    100% {
        background: #fff3e0;
    }
}

.messages-container.searching .message:not(.match) {
    opacity: 0.3;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.6);
    border-radius: 10px;
    margin: 20px;
    padding: 20px;
}

/* Message Bubbles - Telegram Desktop Style */
.message {
    max-width: 480px;
    /* PC monitor optimized width */
    width: fit-content;
    margin-bottom: 6px;
    padding: 6px 12px 6px 10px;
    /* Tuned padding */
    border-radius: 12px;
    position: relative;
    word-wrap: break-word;
    /* Legacy support */
    word-break: break-word;
    overflow-wrap: break-word;
    font-size: 15px;
    line-height: 1.5;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    /* Subtle shadow */
}

/* Incoming (Left) */
.message.incoming {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-bottom-left-radius: 4px;
    /* Soft tail */
}

/* Outgoing / Bugrov (Right) */
.message.bugrov-message {
    align-self: flex-end;
    background: rgba(223, 253, 206, 0.85);
    /* Glassy Green */
    backdrop-filter: blur(8px);
    border: 1px solid rgba(223, 253, 206, 0.3);
    border-bottom-right-radius: 4px;
    /* Soft tail */
    border-bottom-left-radius: 12px;
    margin-left: auto;
}

/* Grouped Messages */
.message.grouped-message {
    margin-top: 2px !important;
    border-top-left-radius: 4px !important;
    border-top-right-radius: 4px !important;
}

.message:not(.grouped-message) {
    /* Ensure non-grouped messages have standard spacing */
    margin-top: 10px;
}

/* Sender Name Colors */
.message-sender {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 2px;
    display: block;
    cursor: pointer;
    line-height: 1.2;
}

.message.bugrov-message .message-sender {
    color: #559c36 !important;
    /* Greenish name for outgoing */
    display: none;
    /* Usually outgoing messages on TDesktop don't show name unless group? Let's hide it for "Me" behavior or keep it subtle */
}

/* Re-enable name if needed. User asked for "Special color text box". */
.message.bugrov-message .message-sender {
    display: block;
    color: #4b9231 !important;
}


/* Message Content & Meta Layout */
.message-content {
    display: block;
    /* Ensure text breaks to new line if needed */
    clear: both;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
}

.message-meta {
    float: right;
    margin-left: 10px;
    margin-top: 4px;
    font-size: 11px;
    color: #a0acb6;
    /* Incoming meta color */
    position: relative;
    top: 4px;
    /* Slight optical adjustment */
    user-select: none;
    pointer-events: none;
}

.message.bugrov-message .message-meta {
    color: #5eb54c;
    /* Outgoing meta color (Green) */
}



/* Overlapping Read Receipts */
.read-receipt {
    display: inline-block;
    position: relative;
    width: 14px;
    height: 10px;
    margin-left: 3px;
    vertical-align: middle;
}

.check {
    position: absolute;
    bottom: 0;
    font-size: 11px;
    /* Adjust size */
    line-height: 1;
    font-weight: bold;
    color: inherit;
}

.check.first {
    left: 0;
    z-index: 2;
}

.check.second {
    left: 4px;
    /* Slight overlap */
    z-index: 1;
}

.message.bugrov-message .check {
    color: #4b9231;
    /* Green check */
}

/* GLOBAL OVERFLOW PROTECTION */
.reply-preview {
    max-width: 100%;
    overflow: hidden;
}

.reply-text,
.reply-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block;
    font-size: 13px;
    line-height: 1.5;
}

.reply-name {
    color: var(--link-color);
    font-weight: 500;
}

.reply-text {
    color: inherit;
    opacity: 0.8;
}

.message img,
.message video {
    max-width: 100% !important;
    height: auto !important;
}

.modal-content {
    max-width: 95vw !important;
    max-height: 90vh;
    overflow-y: auto;
}

/* Service Message (e.g. "Invited", "Joined") */
.service-message {
    text-align: center;
    margin: 10px auto;
    max-width: 80%;
}

.service-message .content {
    display: inline-block;
    background-color: rgba(0, 0, 0, 0.2);
    color: white;
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 500;
    backdrop-filter: blur(2px);
}

[data-theme="dark"] .service-message .content {
    background-color: rgba(255, 255, 255, 0.1);
    color: #cecece;
}

/* Sticker specifics */

.media-sticker {
    width: 180px;
    height: 180px;
    object-fit: contain;
}

.media-sticker-placeholder {
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
    cursor: default;
}

.message:has(.media-sticker) {
    background: transparent !important;
    box-shadow: none !important;
    padding: 0;
}

/* Highlighted message (from search or reply click) */
.message.highlight {
    animation: flashHighlight 1.5s ease-out;
}

@keyframes flashHighlight {
    0% {
        background-color: rgba(51, 144, 236, 0.4);
        transform: scale(1.02);
    }

    50% {
        background-color: rgba(51, 144, 236, 0.2);
        transform: scale(1.01);
    }

    100% {
        transform: scale(1);
    }
}

/* Round Video Messages - Enforced Circle */
/* Round Video Messages - Strict Styling */
/* Date Header */
.date-header {
    position: relative;
    z-index: 1;
    margin: 10px auto;
    width: fit-content;
    background-color: rgba(65, 159, 217, 0.4);
    color: #fff;
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
    backdrop-filter: blur(2px);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

[data-theme="dark"] .date-header {
    background-color: rgba(0, 0, 0, 0.5);
    color: #cecece;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Floating Date Header (JS Controlled) */
.floating-date-header {
    position: fixed;
    /* Changed to fixed to be relative to viewport */
    top: 65px;
    /* Adjust below header */
    left: 0;
    right: 0;
    margin: 0 auto;
    /* Center perfectly */
    width: fit-content;
    z-index: 50;
    pointer-events: none;
    background-color: rgba(65, 159, 217, 0.6);
    color: #fff;
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
    backdrop-filter: blur(4px);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    transition: opacity 0.2s, top 0.2s;
    display: none;
}

[data-theme="dark"] .floating-date-header {
    background-color: rgba(30, 30, 30, 0.7);
    color: #ddd;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Chat Background (Replaces TWallpaper) */
/* Chat Background (Replaces TWallpaper) */
.chat-area {
    background-color: var(--chat-bg);
    /* Ensure base color */
    background-image: url('../images/animals.png');
    background-repeat: repeat;
    background-size: 400px;
    /* Adjust pattern size */
    background-position: center;
    background-attachment: initial;
    /* Scroll with content? No, usually pattern is static or scrolls. */
}

/* Dark theme blend mode */
[data-theme="dark"] .chat-area {
    background-blend-mode: soft-light;
}

/* Round Video Messages - Strict Styling */
.media-container.round-container {
    width: 240px;
    height: 240px;
    border-radius: 50%;
    overflow: hidden;
    /* Critical for cutting off corners */
    display: inline-block;
    position: relative;
    background-color: #000;
}

.media-round-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Critical for filling circle */
    border-radius: 50%;
    /* Double ensurance */
}

/* Sender Name Colors */
/* Custom colors for users to be distinct */
.message-sender.color1 {
    color: #c03d33;
}

.message-sender.color2 {
    color: #4fad2d;
}

.message-sender.color3 {
    color: #d09306;
}

.message-sender.color4 {
    color: #358cd4;
}

/* Telegram Blue */
.message-sender.color5 {
    color: #8544d6;
}

.message-sender.color6 {
    color: #cd4073;
}

.message-sender.color7 {
    color: #2996ad;
}

.message-sender.color8 {
    color: #ce671b;
}

/* Special Bugrov Styling (Message Bubble) */
/* This class is applied to the .message DIV, not just the name */
/* FAB Stack - Bottom Right Container */
.fab-stack {
    position: fixed;
    bottom: 30px;
    right: 20px;
    display: flex;
    flex-direction: column-reverse;
    /* Stack from bottom up */
    gap: 15px;
    z-index: 900;
    pointer-events: none;
    /* Allow clicking through container */
}

/* Ensure buttons are clickable */
.fab-stack>* {
    pointer-events: auto;
}

/* FAB Container for Analytics/Calendar/etc */
.fab-container {
    position: fixed;
    bottom: 90px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    z-index: 890;
    pointer-events: none;
    /* Allow clicking through container */
}

/* Common FAB styles */
.fab {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--bg-color);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    border: none;
    transition: transform 0.2s, opacity 0.2s;
    font-size: 20px;
    position: relative;
    /* For badge */
}

[data-theme="dark"] .fab {
    background-color: #2c2c2e;
    color: #fff;
}

.fab:hover {
    transform: scale(1.1);
    background-color: var(--hover-color);
}

/* Scroll badge inside fab */
.scroll-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--accent-color);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.modal-content {
    background-color: var(--bg-color);
    color: var(--text-primary);
    padding: 20px;
    border-radius: 12px;
    min-width: 300px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .modal-content {
    background-color: #212121;
    border: 1px solid #333;
}

.modal-header {
    font-size: 18px;
    margin-bottom: 15px;
    font-weight: 500;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

input[type="date"],
input[type="text"],
input[type="password"] {
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px;
    border-radius: 6px;
    outline: none;
}

[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="password"] {
    background-color: #121212;
    /* Darker inset */
    border-color: #333;
    color: #fff;
}

.btn {
    background-color: var(--link-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    float: right;
}

/* Smart Media Grid */
.media-grid-group {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    border-radius: 12px;
    overflow: hidden;
    max-width: 480px;
}

.media-grid-item {
    flex: 1 1 auto;
    /* Grow to fill */
    position: relative;
    max-height: 320px;
    min-width: 120px;
    /* Prevent too narrow */
    cursor: zoom-in;
}

.media-grid-item img,
.media-grid-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Grid logic for 2 items */
.media-grid-group[data-count="2"] .media-grid-item {
    width: 50%;
}

/* Grid logic for 3 items: 1 big, 2 small, or 3 row */
.media-grid-group[data-count="3"] .media-grid-item:first-child {
    width: 100%;
}

/* Scroll To Bottom Button */
.scroll-bottom-btn {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: rgba(51, 144, 236, 0.9);
    /* Default Blue */
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    border: none;
    z-index: 900;
    transition: transform 0.2s, opacity 0.2s;
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

.scroll-bottom-btn.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

[data-theme="dark"] .scroll-bottom-btn {
    background-color: rgba(62, 136, 247, 0.9);
}

.scroll-bottom-btn:hover {
    transform: scale(1.1);
}

.scroll-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: #ff3b30;
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: bold;
    display: none;
    /* Hide for archive viewer */
}

/* Toggle Theme Button */
.theme-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    color: var(--text-secondary);
    padding: 5px;
    border-radius: 50%;
    transition: background 0.2s;
}

.theme-toggle-btn:hover {
    background-color: var(--hover-color);
    color: var(--accent-color);
}

/* Media */
.media-container {
    margin-top: 5px;
}

.media-photo {
    max-width: 200px;
    /* Small default size */
    max-height: 200px;
    width: auto;
    height: auto;
    border-radius: 4px;
    display: block;
    cursor: zoom-in;
    object-fit: contain;
}

/* Chat Area Background - Removing redundant definition to let gradient show */
/* .chat-area { ... } */

/* Reply Preview Block (Telegram Style) */
.reply-preview {
    border-left: 2px solid var(--link-color);
    /* Standard accent line */
    padding-left: 10px;
    margin-top: 2px;
    margin-bottom: 4px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    border-radius: 2px;
}

.reply-name {
    color: var(--link-color);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reply-text {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.8;
}

[data-theme="dark"] .reply-name {
    color: var(--link-color);
}

[data-theme="dark"] .reply-text {
    color: #e0e0e0;
    /* Better visibility in dark mode */
}

.reply-preview:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

/* Lightbox - Z-Index Fix */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    /* Ensure it is top-most level */
    cursor: zoom-out;
}

.lightbox img {
    max-width: 90%;
    max-height: 90%;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

/* Highlight */
.highlight-text {
    background: #ffc107;
    color: black;
    border-radius: 2px;
}

/* Sticky Player (Top Bar style) */
.sticky-player {
    position: relative;
    width: 100%;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 15px;
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 100;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    animation: playerSlideDown 0.3s ease;
}

@keyframes playerSlideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.player-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.player-controls button {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--accent-color);
    transition: transform 0.1s;
    padding: 0;
}

.player-controls button:active {
    transform: scale(0.9);
}

.player-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.player-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.player-waveform {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-right: 15px;
    opacity: 0.5;
}

.player-waveform .bar {
    width: 2px;
    background: var(--accent-color);
    border-radius: 1px;
}

.close-player {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
    opacity: 0.6;
    padding: 5px;
}

.close-player:hover {
    opacity: 1;
    color: #ff3b30;
}


/* Analytics */
.stat-card {
    background: var(--input-bg);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 10px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.bar-chart-row {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
    font-size: 12px;
}

.bar-label {
    width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bar-container {
    flex: 1;
    background: rgba(0, 0, 0, 0.1);
    height: 8px;
    border-radius: 4px;
    margin: 0 10px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: var(--accent-color);
}

.bar-value {
    width: 40px;
    text-align: right;
}

/* Mobile Responsive Styles */
/* Mobile Responsive Styles */

/* Base Logic for touch devices */
@media (hover: none) and (pointer: coarse) {

    /* Prevent pull-to-refresh */
    body {
        overscroll-behavior-y: contain;
    }

    /* Better tap targets */
    button,
    .icon-btn,
    .chat-item,
    .media-grid-item {
        touch-action: manipulation;
    }
}

/* Valid for all mobile/tablet sizes */
@media (max-width: 1024px) {

    /* Modals centered and smaller */
    .modal-content {
        width: 90%;
        max-width: 600px;
        margin: auto;
    }

    /* Scroll fix */
    .chat-area,
    .messages-container {
        -webkit-overflow-scrolling: touch;
    }
}

/* Tablet (481px - 1024px) */
@media (min-width: 481px) and (max-width: 1024px) {
    .sidebar {
        width: 280px;
        /* Slightly narrower sidebar */
        flex-shrink: 0;
    }

    .message {
        max-width: 65%;
    }

    .media-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

/* Phone (max-width: 480px) */
@media (max-width: 480px) {

    /* 1. Sidebar - Overlay Drawer Style */
    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 1000;
        width: 85%;
        max-width: 320px;
        transform: translateX(-100%);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
        transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Sidebar Overlay Backdrop */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        /* Below sidebar, above content */
        display: none;
        animation: fadeIn 0.3s;
    }

    .sidebar-overlay.active {
        display: block;
    }

    @keyframes fadeIn {
        from {
            opacity: 0;
        }

        to {
            opacity: 1;
        }
    }

    /* 2. Messages & Chat Area */
    .message {
        max-width: 92%;
        /* Wider messages on phone */
        font-size: 14px;
    }

    .message-meta {
        font-size: 10px;
    }

    .chat-area {
        width: 100%;
        min-width: 100%;
    }

    /* 3. Global Overflow Fixes */
    .message-content img,
    .message-content video,
    .media-round-video {
        max-width: 100% !important;
        height: auto !important;
        border-radius: 8px;
    }

    .media-container.round-container {
        max-width: 160px;
        max-height: 160px;
        width: 100%;
        aspect-ratio: 1/1;
    }

    /* 4. UI Elements */
    .fab-container {
        right: 15px;
        bottom: 90px;
        /* Higher to avoid footer */
        flex-direction: row;
        /* Maybe row on mobile? Or stick to column. Let's keep column to match desktop logic but adjust position */
        flex-direction: column;
    }

    .footer-banner {
        flex-direction: column;
        gap: 5px;
        padding-bottom: env(safe-area-inset-bottom, 10px);
    }

    /* Full screen modals */
    .modal-content {
        width: 100% !important;
        height: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .media-grid {
        grid-template-columns: repeat(2, 1fr);
        /* 2 columns */
        gap: 8px;
    }

    /* Sticky Player Compact */
    /* Sticky Player Compact (Top) */
    .sticky-player {
        padding: 5px 10px;
        gap: 10px;
    }

    .player-controls button {
        font-size: 16px;
    }

    .player-waveform {
        display: none;
        /* Hide waveform on mobile to save space */
    }

    /* Search Bar */
    #search-bar-chat {
        flex-wrap: wrap;
    }

    #msg-search-input {
        min-width: 150px;
    }
}

/* Modal Overlay */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    /* Darker backdrop */
    z-index: 20000;
    /* Above sidebar and everything else */
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s;
}

/* Fix: Force visibility when display is set inline */
.modal[style*="display: flex"],
.modal[style*="display: block"] {
    opacity: 1 !important;
    visibility: visible !important;
}

.modal.active {
    opacity: 1;
    visibility: visible;
    display: flex;
}

/* Sidebar Open Adjustments for Desktop Gallery */
@media (min-width: 769px) {
    body.sidebar-open .media-gallery-modal {
        left: 320px !important;
        width: calc(100% - 320px) !important;
    }
}

/* Animation Keyframes */
@keyframes modalFadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

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

.modal.active .modal-content {
    animation: modalFadeInScale 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Info Modal Styles - Higher Contrast Theme Support */
.abbrev-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 15px;
    background: #f5f5f5;
    /* Static light for now, or themed below */
    padding: 18px;
    border-radius: 12px;
    font-size: 14px;
    color: #333;
    border: 1px solid #ddd;
}

[data-theme="dark"] .abbrev-grid {
    background: #111111 !important;
    /* Pure black inset for dark theme */
    color: #e0e0e0 !important;
    border-color: #333 !important;
}

.abbrev-grid strong {
    color: var(--link-color);
}

.investigation-card {
    text-decoration: none;
    color: inherit;
    display: block;
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

[data-theme="dark"] .investigation-card {
    background: #1e1e1e;
    border-color: #333;
    color: #e0e0e0;
}

.investigation-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}


.investigation-card-container {
    margin-bottom: 20px;
}

.investigation-content {
    padding: 15px;
}


.investigation-title {
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 5px;
    color: var(--link-color);
}

.investigation-desc {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0;
}

.investigation-meta {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    opacity: 0.7;
}

/* Voice Message Waveform Styles */
.voice-message-container {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(0, 0, 0, 0.05);
    padding: 8px 15px;
    border-radius: 22px;
    width: fit-content;
    margin: 5px 0;
}

[data-theme="dark"] .voice-message-container {
    background: rgba(255, 255, 255, 0.1);
}

.voice-waveform {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 24px;
    min-width: 100px;
}

.voice-waveform .bar {
    width: 2px;
    background: var(--link-color);
    border-radius: 1px;
    opacity: 0.5;
}

.voice-msg-btn {
    background: var(--link-color);
    color: white;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    flex-shrink: 0;
    transition: transform 0.1s;
}

.voice-msg-btn:active {
    transform: scale(0.9);
}

.voice-duration {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 35px;
}

.media-tab.active {
    color: var(--accent-color);
    border-bottom: 2px solid var(--accent-color);
}

/* Theme Settings Styles */
.theme-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}

.theme-option {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.theme-option.active {
    border-color: var(--accent-color);
    transform: scale(1.1);
}

.theme-option::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40%;
    height: 40%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0;
}

.theme-option.active::after {
    opacity: 1;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked+.slider {
    background-color: var(--accent-color);
}

input:checked+.slider:before {
    transform: translateX(16px);
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Pattern Grid */
.pattern-grid {
    grid-template-columns: repeat(4, 1fr) !important;
}

.pattern-option {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    background-size: cover;
    background-position: center;
    background-color: #ddd;
    /* Fallback */
    transition: transform 0.1s;
}

.pattern-option:hover {
    transform: scale(1.05);
}

.pattern-option.active {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px var(--bg-color), 0 0 0 4px var(--accent-color);
}