/* ==========================================================================
   Taht El Doo Newspaper - Modern Custom WhatsApp Web Platform CSS
   Identical WhatsApp Web Aesthetics with Native RTL & Dynamic Multi-Line Engine
   ========================================================================== */

:root {
    /* WhatsApp Dark Theme Colors (Default) */
    --bg-app: #0c1317;
    --bg-header: #111b21;
    --bg-sidebar: #111b21;
    --bg-chat: #0b141a;
    --bg-chat-bar: #202c33;
    --bg-bubble-in: #202c33;
    --bg-bubble-out: #005c4b;
    --bg-hover: #202c33;
    --bg-active: #2a3942;
    --bg-modal: #1f2c34;
    
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --text-muted: #667781;
    
    --border-color: #222d34;
    --accent-green: #00a884;
    --accent-emerald: #25d366;
    --ack-blue: #53bdeb;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 28px rgba(0,0,0,0.6);
    
    --font-ar: 'Cairo', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-pill: 9999px;
}

body.light-theme {
    --bg-app: #eae6df;
    --bg-header: #f0f2f5;
    --bg-sidebar: #ffffff;
    --bg-chat: #efeae2;
    --bg-chat-bar: #f0f2f5;
    --bg-bubble-in: #ffffff;
    --bg-bubble-out: #d9fdd3;
    --bg-hover: #f5f6f6;
    --bg-active: #ebebeb;
    --bg-modal: #ffffff;
    
    --text-primary: #111b21;
    --text-secondary: #667781;
    --text-muted: #8696a0;
    
    --border-color: #e9edef;
    --accent-green: #008069;
    --accent-emerald: #128c7e;
    --ack-blue: #53bdeb;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
    --shadow-lg: 0 12px 28px rgba(0,0,0,0.16);
}

/* ==========================================================================
   Light Mode (White Mode) - Pure Black Chat Message Text (#111b21 / #000000)
   ========================================================================== */
body.light-theme .msg-bubble,
body.light-theme .msg-bubble .msg-text,
body.light-theme .msg-bubble.outgoing,
body.light-theme .msg-bubble.outgoing .msg-text,
body.light-theme .msg-bubble.incoming,
body.light-theme .msg-bubble.incoming .msg-text,
body.light-theme .msg-text {
    color: #111b21 !important; /* Authentic high-contrast black text */
}

body.light-theme .msg-bubble.outgoing {
    background-color: #d9fdd3 !important;
}

body.light-theme .msg-bubble.incoming {
    background-color: #ffffff !important;
}

body.light-theme .msg-bubble .msg-meta,
body.light-theme .msg-bubble.outgoing .msg-meta,
body.light-theme .msg-bubble.incoming .msg-meta,
body.light-theme .msg-bubble.outgoing .msg-meta span,
body.light-theme .msg-bubble.incoming .msg-meta span {
    color: #54656f !important;
}

body.light-theme .msg-bubble .msg-status-icon:not(.read) {
    color: #8696a0 !important;
}

body.light-theme .msg-quoted-snippet {
    background-color: rgba(0, 0, 0, 0.06) !important;
}

body.light-theme .msg-quoted-body {
    color: #3b4a54 !important;
}

body.light-theme .msg-dropdown-trigger {
    background: rgba(0, 0, 0, 0.08) !important;
    color: #111b21 !important;
}

body.light-theme .file-download-link {
    background: rgba(0, 0, 0, 0.05) !important;
    color: #111b21 !important;
}

body.light-theme .voice-time,
body.light-theme .voice-speed-badge {
    color: #54656f !important;
}

body.light-theme .chat-input-bar textarea {
    color: #111b21 !important;
}


/* Base Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-ar);
    -webkit-font-smoothing: antialiased;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-app);
    color: var(--text-primary);
    direction: rtl;
}

/* Layout App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    background-color: var(--bg-app);
}

/* Top App Bar */
.app-header {
    height: 60px;
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 20;
    box-shadow: var(--shadow-sm);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo-wrap {
    position: relative;
    width: 38px;
    height: 38px;
}

.brand-logo {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-sm);
    object-fit: cover;
}

.live-dot {
    position: absolute;
    bottom: -2px;
    left: -2px;
    width: 10px;
    height: 10px;
    background-color: var(--accent-emerald);
    border: 2px solid var(--bg-header);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(37, 211, 102, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(37, 211, 102, 0); }
}

.brand-text h2 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.brand-text span {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Scalable Line Filter Switcher (Scrollable horizontally) */
.lines-bar-container {
    flex: 1;
    max-width: 65%;
    overflow-x: auto;
    padding: 0 12px;
    scrollbar-width: none;
}
.lines-bar-container::-webkit-scrollbar {
    display: none;
}

.lines-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.line-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background-color: var(--bg-chat-bar);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-pill);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.line-pill:hover {
    background-color: var(--bg-hover);
    border-color: var(--accent-green);
}

.line-pill.active {
    background-color: var(--accent-green);
    color: #ffffff;
    border-color: var(--accent-green);
    box-shadow: 0 2px 8px rgba(0, 168, 132, 0.4);
}

.line-pill.active .pill-badge {
    background-color: rgba(255, 255, 255, 0.3);
    color: #ffffff;
}

.pill-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
}

.pill-dot.all-dot {
    background-color: #ffd700;
}

.pill-dot.unread-dot {
    background-color: #25D366;
    box-shadow: 0 0 6px rgba(37, 211, 102, 0.7);
}

.pill-badge {
    background-color: rgba(134, 150, 160, 0.2);
    padding: 1px 7px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 700;
}

.pill-badge.unread-badge {
    background-color: #25D366;
    color: #ffffff;
    font-weight: 700;
}

.line-pill.active .pill-badge.unread-badge {
    background-color: #ffffff;
    color: #00A884;
}

.line-pill.starred-pill.active {
    background-color: #F59E0B !important;
    border-color: #F59E0B !important;
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4) !important;
}

.line-pill.starred-pill.active .pill-badge {
    background-color: #ffffff !important;
    color: #B45309 !important;
}

#btnAudioToggle {
    position: relative;
    transition: all 0.2s ease;
}

#btnAudioToggle.sound-muted {
    opacity: 0.45;
}

#btnAudioToggle:not(.sound-muted) {
    color: var(--accent-green);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.btn-primary {
    background-color: var(--accent-green);
    color: #ffffff;
}
.btn-primary:hover {
    background-color: #008f6f;
}

.btn-icon {
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 50%;
    background-color: transparent;
    color: var(--text-secondary);
}
.btn-icon:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

/* Chat Layout: Split Screen */
.chat-layout {
    display: flex;
    flex: 1;
    height: calc(100vh - 60px);
    overflow: hidden;
}

/* Chats Sidebar */
.chats-sidebar {
    width: 380px;
    min-width: 320px;
    max-width: 440px;
    background-color: var(--bg-sidebar);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-search {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
}

.search-input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: var(--bg-chat-bar);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    color: var(--text-secondary);
}

.search-input-wrap input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 13px;
}

.chat-filters-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: var(--radius-pill);
    background-color: var(--bg-chat-bar);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-chip:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.filter-chip.active {
    background-color: rgba(0, 168, 132, 0.15);
    border-color: var(--accent-green);
    color: var(--accent-green);
}

.filter-chip .chip-count {
    font-size: 11px;
    padding: 1px 7px;
    border-radius: var(--radius-pill);
    background: rgba(134, 150, 160, 0.18);
    color: var(--text-secondary);
    font-weight: 700;
}

.filter-chip.active .chip-count {
    background: var(--accent-green);
    color: #ffffff;
}

.filter-chip .chip-count.chip-unread-count {
    background: #25D366;
    color: #ffffff;
    font-weight: 700;
    box-shadow: 0 0 6px rgba(37, 211, 102, 0.4);
}

.chip-glow-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #25D366;
    display: inline-block;
    box-shadow: 0 0 6px rgba(37, 211, 102, 0.8);
}

.chip-star-icon {
    font-size: 13px;
    line-height: 1;
}

.filter-chip#chipStarred.active {
    background-color: rgba(245, 158, 11, 0.15);
    border-color: #F59E0B;
    color: #F59E0B;
}

.filter-chip#chipStarred.active .chip-count {
    background: #F59E0B;
    color: #ffffff;
}

.filter-chip .chip-count.chip-starred-count {
    background: #F59E0B;
    color: #ffffff;
    font-weight: 700;
}

.starred-empty-state {
    padding: 40px 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.starred-empty-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(245, 158, 11, 0.14);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #F59E0B;
    margin-bottom: 6px;
    font-size: 28px;
}

.starred-empty-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.starred-empty-desc {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 280px;
    line-height: 1.5;
}

.unread-empty-state {
    padding: 40px 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.unread-empty-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(37, 211, 102, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #25D366;
    margin-bottom: 6px;
}

.unread-empty-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.unread-empty-desc {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 260px;
    line-height: 1.5;
}

.chats-list {
    flex: 1;
    overflow-y: auto;
}

.chats-list::-webkit-scrollbar {
    width: 6px;
}
.chats-list::-webkit-scrollbar-thumb {
    background-color: rgba(134, 150, 160, 0.2);
}

/* Chat Item */
.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid rgba(134, 150, 160, 0.08);
    transition: background 0.15s ease;
    position: relative;
}

.chat-item:hover {
    background-color: var(--bg-hover);
}

.chat-item.active {
    background-color: var(--bg-active);
}

.chat-avatar-wrap {
    position: relative;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

.chat-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: #6b7c85;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    overflow: hidden;
    flex-shrink: 0;
    user-select: none;
    position: relative;
}
.chat-avatar-img, .contact-avatar-img,
.chat-avatar img, .contact-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}
.chat-avatar svg, .contact-avatar svg {
    width: 60%;
    height: 60%;
    fill: #cfd9df;
}
.chat-avatar.default-wa-avatar, .contact-avatar.default-wa-avatar {
    background-color: #6b7c85 !important;
}

/* Colored dot showing which WhatsApp line this chat belongs to */
.line-dot-badge {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--bg-sidebar);
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-header-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}

.chat-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-name.is-phone {
    direction: ltr;
    text-align: right;
    unicode-bidi: isolate;
    font-family: inherit;
    letter-spacing: 0.5px;
}

.chat-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.chat-sub-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-sub-content {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1;
    overflow: hidden;
}

.chat-phone-tag {
    display: inline-flex;
    align-items: center;
    background: rgba(0, 168, 132, 0.14);
    color: var(--accent-emerald);
    font-size: 11px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    letter-spacing: 0.3px;
    flex-shrink: 0;
    line-height: 1.35;
    unicode-bidi: isolate;
}

.chat-last-msg {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    max-width: 220px;
}

.chat-unread-badge {
    background-color: var(--accent-emerald);
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: var(--radius-pill);
    min-width: 18px;
    text-align: center;
}

.chat-header-meta {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-star-badge {
    font-size: 13px;
    line-height: 1;
    display: inline-block;
    filter: drop-shadow(0 1px 2px rgba(245, 158, 11, 0.4));
}

.chat-sub-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-star-btn {
    background: transparent;
    border: none;
    padding: 3px;
    cursor: pointer;
    border-radius: 50%;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s ease;
}

.chat-item:hover .chat-star-btn,
.chat-star-btn.is-starred {
    opacity: 1;
}

.chat-star-btn:hover {
    color: #F59E0B;
    transform: scale(1.15);
}

.chat-star-btn.is-starred {
    color: #F59E0B !important;
}

#btnToggleStarChat {
    color: var(--text-secondary);
    transition: all 0.2s ease;
}
#btnToggleStarChat:hover {
    color: #F59E0B;
}
#btnToggleStarChat.is-starred {
    color: #F59E0B !important;
}
#btnToggleStarChat.is-starred svg {
    fill: #F59E0B !important;
    stroke: #F59E0B !important;
}

@media (hover: none) {
    .chat-star-btn {
        opacity: 0.6;
    }
    .chat-star-btn.is-starred {
        opacity: 1;
    }
}

/* Main Chat Area */
.chat-area {
    flex: 1;
    height: 100%;
    background-color: var(--bg-chat);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Empty State */
.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px;
    color: var(--text-secondary);
}

.empty-icon-wrap {
    width: 100px;
    height: 100px;
    background-color: var(--bg-chat-bar);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 24px;
    color: var(--accent-green);
}

.chat-empty-state h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.chat-empty-state p {
    font-size: 14px;
    max-width: 480px;
    line-height: 1.6;
    margin-bottom: 28px;
}

.security-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
    background-color: rgba(134, 150, 160, 0.08);
    padding: 8px 16px;
    border-radius: var(--radius-pill);
}

/* Active Chat Panel */
.chat-active-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

.chat-topbar {
    height: 60px;
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 10;
}

.chat-contact-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-back-mobile {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #6b7c85;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    overflow: hidden;
    flex-shrink: 0;
    user-select: none;
    position: relative;
}

.contact-details h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.contact-details h3.is-phone {
    direction: ltr;
    text-align: right;
    unicode-bidi: isolate;
    letter-spacing: 0.5px;
}

.contact-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.active-contact-phone {
    font-size: 12px;
    color: var(--accent-emerald);
    background: rgba(0, 168, 132, 0.12);
    padding: 1px 8px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    letter-spacing: 0.4px;
    unicode-bidi: isolate;
}

.active-line-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background-color: rgba(0, 168, 132, 0.15);
    color: var(--accent-green);
}

.active-line-badge .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

/* Messages Body (WhatsApp Wallpaper Texture) */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 32px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background-image: radial-gradient(rgba(134, 150, 160, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-thumb {
    background-color: rgba(134, 150, 160, 0.2);
}

/* Message Bubble */
.msg-bubble {
    max-width: 65%;
    padding: 8px 12px 6px 12px;
    border-radius: 8px;
    font-size: 14.2px;
    line-height: 1.45;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 1px rgba(0,0,0,0.15);
}

.msg-bubble.outgoing {
    align-self: flex-start; /* in RTL: Left is outgoing */
    background-color: var(--bg-bubble-out);
    color: #ffffff;
    border-bottom-left-radius: 2px;
}

.msg-bubble.incoming {
    align-self: flex-end; /* in RTL: Right is incoming */
    background-color: var(--bg-bubble-in);
    color: var(--text-primary);
    border-bottom-right-radius: 2px;
}

.msg-media {
    margin-bottom: 6px;
    border-radius: 6px;
    overflow: hidden;
    max-width: 320px;
}

.msg-media img {
    width: 100%;
    height: auto;
    display: block;
    cursor: pointer;
}

.msg-media audio {
    width: 260px;
}

.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 2px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.65);
}

.msg-bubble.incoming .msg-meta {
    color: var(--text-secondary);
}

.msg-status-icon {
    display: inline-flex;
    align-items: center;
}

.msg-status-icon.read {
    color: var(--ack-blue);
}

/* Message Reaction Badges */
.msg-reaction-pill {
    position: absolute;
    bottom: -11px;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background-color: var(--bg-panel);
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
    padding: 2px 7px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1;
    z-index: 3;
    cursor: pointer;
    user-select: none;
    transition: transform 0.15s ease;
}

.msg-reaction-pill:hover {
    transform: scale(1.15);
}

.msg-bubble.outgoing .msg-reaction-pill {
    left: 8px;
}

.msg-bubble.incoming .msg-reaction-pill {
    right: 8px;
}

.msg-reaction-pill .reaction-count {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 700;
    margin-right: 2px;
}

/* Quick Reaction Picker in Context Menu */
.context-reactions-bar {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 6px 8px;
    margin-bottom: 6px;
    background-color: var(--bg-chat-bar);
    border-radius: var(--radius-sm);
    border-bottom: 1px solid var(--border-color);
    gap: 4px;
}

.reaction-btn {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 8px;
    transition: transform 0.15s ease, background 0.15s ease;
}

.reaction-btn:hover {
    transform: scale(1.3);
    background-color: var(--bg-hover);
}

/* Chat Input Bar */
.chat-input-bar {
    min-height: 62px;
    background-color: var(--bg-chat-bar);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: flex-end;
    padding: 10px 16px;
    gap: 12px;
    z-index: 10;
}

.btn-input-action {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease;
}
.btn-input-action:hover {
    color: var(--text-primary);
}

.input-text-wrap {
    flex: 1;
    background-color: var(--bg-sidebar);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    display: flex;
    align-items: center;
}

.input-text-wrap textarea {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.4;
    max-height: 120px;
}

.btn-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: var(--accent-green);
    border: none;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}
.btn-send:hover {
    transform: scale(1.05);
    background-color: #008f6f;
}
.btn-send:active {
    transform: scale(0.95);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-card {
    background-color: var(--bg-modal);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    width: 90%;
    max-width: 460px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: modalSlide 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-large {
    max-width: 720px;
}

@keyframes modalSlide {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}
.modal-header h3 {
    font-size: 16px;
    font-weight: 700;
}
.modal-close {
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
}

.modal-body {
    padding: 24px;
}

.form-input {
    width: 100%;
    background-color: var(--bg-chat-bar);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 14px;
    margin: 8px 0 18px 0;
    outline: none;
}
.form-input:focus {
    border-color: var(--accent-green);
}

.btn-block {
    width: 100%;
}

.qr-code-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 260px;
    background: #ffffff;
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 18px;
}

.qr-image {
    max-width: 240px;
    height: auto;
}

.qr-instructions ol {
    padding-right: 20px;
    font-size: 13.5px;
    line-height: 1.8;
    color: var(--text-secondary);
}

/* Lines Table */
.lines-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
.lines-table th, .lines-table td {
    padding: 12px 14px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}
.lines-table th {
    color: var(--text-secondary);
    font-weight: 600;
}

.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 700;
}
.status-badge.connected {
    background-color: rgba(37, 211, 102, 0.2);
    color: var(--accent-emerald);
}
.status-badge.disconnected {
    background-color: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.btn-danger-sm {
    background-color: #ef4444;
    color: #ffffff;
    border: none;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
    font-family: inherit;
}
.btn-danger-sm:hover {
    opacity: 0.9;
}
.btn-cancel-sm {
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    cursor: pointer;
    font-family: inherit;
}
.btn-cancel-sm:hover {
    color: var(--text-primary);
}

.hidden {
    display: none !important;
}

/* Spinners */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(0, 168, 132, 0.2);
    border-top-color: var(--accent-green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px auto;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Toast Messages */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 2000;
}
.toast {
    background-color: var(--bg-modal);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    font-size: 13.5px;
    animation: toastIn 0.3s ease;
}
@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Date Badges */
.chat-date-separator {
    display: flex;
    justify-content: center;
    margin: 14px 0 8px 0;
}
.chat-date-separator span {
    background-color: var(--bg-chat-bar);
    color: var(--text-secondary);
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 14px;
    border-radius: var(--radius-pill);
    box-shadow: 0 1px 2px rgba(0,0,0,0.12);
    border: 1px solid var(--border-color);
}

/* Quoted / Reply Preview inside Message Bubble */
.msg-quoted-snippet {
    background-color: rgba(0, 0, 0, 0.12);
    border-radius: 6px;
    padding: 6px 10px;
    margin-bottom: 6px;
    border-right: 4px solid var(--accent-green);
    cursor: pointer;
    font-size: 12.5px;
}
.dark-theme .msg-quoted-snippet {
    background-color: rgba(255, 255, 255, 0.08);
}
.msg-quoted-sender {
    font-weight: 700;
    font-size: 11.5px;
    color: var(--accent-green);
    margin-bottom: 2px;
}
.msg-quoted-body {
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Reply Preview Bar above Input */
.reply-preview-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-sidebar);
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 18px;
    position: relative;
    animation: slideUp 0.2s ease;
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.reply-preview-border {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    background-color: var(--accent-green);
}
.reply-preview-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
    padding-right: 8px;
}
.reply-sender-name {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-green);
}
.reply-text-snippet {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 600px;
}
.btn-cancel-reply {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-cancel-reply:hover {
    color: #ef4444;
}

/* Message Dropdown Trigger */
.msg-bubble {
    position: relative;
}
.msg-dropdown-trigger {
    position: absolute;
    top: 4px;
    left: 4px; /* In RTL outgoing/incoming */
    background: linear-gradient(135deg, rgba(0,0,0,0.3), rgba(0,0,0,0.6));
    color: #ffffff;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 5;
}
.msg-bubble:hover .msg-dropdown-trigger {
    opacity: 1;
}

/* Message Context Menu */
.msg-context-menu {
    position: fixed;
    background-color: var(--bg-modal);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 1500;
    min-width: 170px;
    padding: 4px 0;
    animation: fadeIn 0.15s ease;
}
.msg-context-menu .menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    text-align: right;
    cursor: pointer;
    transition: background-color 0.15s;
}
.msg-context-menu .menu-item:hover {
    background-color: var(--bg-hover);
}
.msg-context-menu .menu-danger {
    color: #ef4444;
}

/* Floating Scroll to Bottom Button */
.btn-scroll-down {
    position: absolute;
    bottom: 84px;
    left: 24px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background-color: var(--bg-sidebar);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    transition: all 0.2s ease;
}
.btn-scroll-down:hover {
    color: var(--accent-green);
    transform: translateY(-2px);
}
.unread-scroll-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background-color: var(--accent-green);
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
}

/* Floating Emoji Picker Popover */
.emoji-picker-popover {
    position: absolute;
    bottom: 74px;
    right: 18px;
    width: 340px;
    max-height: 360px;
    background-color: var(--bg-modal);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: fadeIn 0.2s ease;
}
.emoji-header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
}
.emoji-header input {
    width: 100%;
    background-color: var(--bg-chat-bar);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    color: var(--text-primary);
    font-size: 12.5px;
    outline: none;
}
.emoji-tabs {
    display: flex;
    gap: 4px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-sidebar);
}
.emoji-tab {
    flex: 1;
    background: transparent;
    border: none;
    font-size: 18px;
    padding: 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s;
}
.emoji-tab.active, .emoji-tab:hover {
    background-color: var(--bg-hover);
}
.emoji-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    padding: 12px;
    overflow-y: auto;
    max-height: 250px;
}
.emoji-grid::-webkit-scrollbar {
    width: 4px;
}
.emoji-btn {
    background: transparent;
    border: none;
    font-size: 22px;
    padding: 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.emoji-btn:hover {
    background-color: var(--bg-hover);
    transform: scale(1.2);
}

/* In-App Image Lightbox */
.lightbox-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: rgba(11, 20, 26, 0.95);
}
.lightbox-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
    background: rgba(0, 0, 0, 0.4);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: #ffffff;
}
.lightbox-title {
    font-size: 15px;
    font-weight: 600;
}
.lightbox-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.lightbox-actions .btn {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
}
.lightbox-actions .btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
}
.lightbox-img-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 24px;
    cursor: zoom-out;
}
#lightboxImg {
    max-width: 90%;
    max-height: 82vh;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
    transition: transform 0.2s ease;
    cursor: default;
}

/* WhatsApp Custom Voice Note Player */
.voice-note-player {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 250px;
    padding: 4px 2px;
}
.voice-play-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: var(--accent-green);
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.15s ease;
}
.voice-play-btn:hover {
    transform: scale(1.08);
}
.voice-track-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.voice-scrubber {
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: rgba(134, 150, 160, 0.4);
    outline: none;
    cursor: pointer;
    accent-color: var(--accent-green);
}
.voice-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-secondary);
}
.voice-speed-badge {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 8px;
    padding: 1px 6px;
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
}
.voice-speed-badge:hover {
    color: var(--text-primary);
    border-color: var(--text-primary);
}
.voice-avatar-badge {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: rgba(0, 168, 132, 0.15);
    color: var(--accent-green);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Forward Modal Chat List */
.forward-chats-list {
    max-height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
}
.forward-chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background-color 0.15s;
}
.forward-chat-item:hover {
    background-color: var(--bg-hover);
}
.forward-chat-item .chat-name {
    font-size: 13.5px;
    font-weight: 600;
}

/* ==========================================================================
   MOBILE UI/UX SYSTEM (iOS & Android Native Experience)
   ========================================================================== */

/* Desktop defaults: mobile-only elements hidden */
.btn-mobile-only {
    display: none;
}
.mobile-menu-dropdown {
    display: none;
}
.mobile-bottom-nav {
    display: none;
}
.mobile-fab {
    display: none;
}
.btn-back-mobile {
    display: none;
}

@media (max-width: 768px) {
    /* Full Viewport Lock & Safe Areas */
    body, html {
        height: 100%;
        overflow: hidden;
        overscroll-behavior: none;
        -webkit-tap-highlight-color: transparent;
    }

    .app-container {
        height: 100dvh;
        width: 100vw;
        position: relative;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    /* 1. Mobile App Header */
    .app-header {
        height: 54px;
        padding: 0 12px;
        position: relative;
        flex-shrink: 0;
        z-index: 50;
        background-color: var(--bg-header);
        border-bottom: 1px solid var(--border-color);
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .header-right {
        gap: 10px;
    }

    .brand-logo-wrap {
        width: 34px;
        height: 34px;
    }

    .brand-text h2 {
        font-size: 14.5px;
        font-weight: 700;
        letter-spacing: -0.2px;
    }

    .brand-text span {
        display: none !important;
    }

    /* 2. Floating Story / Category Horizontal Line Bar */
    .lines-bar-container {
        position: absolute;
        top: 54px;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        height: 48px;
        padding: 6px 12px;
        background-color: var(--bg-sidebar);
        border-bottom: 1px solid var(--border-color);
        z-index: 40;
        display: flex;
        align-items: center;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.25s ease;
    }

    .lines-bar {
        display: flex;
        gap: 8px;
        flex-wrap: nowrap;
    }

    .line-pill {
        padding: 5px 12px;
        font-size: 12px;
        border-radius: 20px;
        flex-shrink: 0;
        gap: 6px;
    }

    .line-pill .pill-title {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Hide desktop buttons in header */
    #btnAddLine,
    #btnSavedMessages,
    #btnManageLines,
    #btnToggleTheme,
    #btnLogout {
        display: none !important;
    }

    /* Show mobile menu toggle */
    .btn-mobile-only {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        color: var(--text-primary);
        width: 38px;
        height: 38px;
        border-radius: 50%;
        background: transparent;
        border: none;
        cursor: pointer;
    }
    .btn-mobile-only:active {
        background-color: var(--bg-hover);
    }

    /* Mobile Dropdown Menu Popover */
    .mobile-menu-dropdown {
        position: absolute;
        top: 50px;
        left: 10px;
        background-color: var(--bg-modal);
        border: 1px solid var(--border-color);
        border-radius: 16px;
        box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
        padding: 6px;
        z-index: 1000;
        min-width: 215px;
        display: flex;
        flex-direction: column;
        gap: 3px;
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        transform-origin: top left;
        animation: mobilePopIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    }

    @keyframes mobilePopIn {
        from { opacity: 0; transform: scale(0.92) translateY(-8px); }
        to { opacity: 1; transform: scale(1) translateY(0); }
    }

    .mobile-menu-dropdown.hidden {
        display: none !important;
    }

    .mobile-menu-dropdown .menu-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 14px;
        background: transparent;
        border: none;
        border-radius: 10px;
        color: var(--text-primary);
        font-size: 13.5px;
        font-weight: 600;
        cursor: pointer;
        width: 100%;
        text-align: right;
        transition: background-color 0.15s;
    }

    .mobile-menu-dropdown .menu-item:active {
        background-color: var(--bg-hover);
    }

    .mobile-menu-dropdown .menu-item.menu-danger {
        color: #EF4444;
    }

    /* 3. Sliding Screen Layout (Native WhatsApp Navigation) */
    .chat-layout {
        position: relative;
        flex: 1;
        height: calc(100dvh - 54px - 48px - 58px);
        margin-top: 48px;
        margin-bottom: 58px;
        overflow: hidden;
        display: block !important;
        transition: margin 0.25s cubic-bezier(0.32, 0.72, 0, 1), height 0.25s cubic-bezier(0.32, 0.72, 0, 1);
    }

    .chats-sidebar {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100% !important;
        max-width: 100% !important;
        height: 100%;
        background-color: var(--bg-sidebar);
        border: none;
        z-index: 10;
        display: flex;
        flex-direction: column;
        transform: translateX(0);
        transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.28s ease;
    }

    .chat-area {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100% !important;
        max-width: 100% !important;
        height: 100%;
        background-color: var(--bg-chat);
        z-index: 20;
        display: flex !important;
        flex-direction: column;
        transform: translateX(100%);
        transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
        pointer-events: none;
    }

    /* Active Conversation State on Mobile */
    .app-container.chat-view-active .app-header {
        display: none !important;
    }

    .app-container.chat-view-active .chat-layout {
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        height: 100dvh !important;
    }

    .app-container.chat-view-active .lines-bar-container {
        transform: translateY(-100%);
        opacity: 0;
        pointer-events: none;
    }

    .app-container.chat-view-active .mobile-bottom-nav {
        transform: translateY(100%);
        opacity: 0;
        pointer-events: none;
    }

    .app-container.chat-view-active .mobile-fab {
        transform: scale(0);
        opacity: 0;
        pointer-events: none;
    }

    .app-container.chat-view-active .chats-sidebar {
        transform: translateX(-25%);
        opacity: 0.3;
        pointer-events: none;
    }

    .app-container.chat-view-active .chat-area {
        transform: translateX(0);
        pointer-events: auto;
    }

    .app-container.chat-view-active .chat-empty-state {
        display: none !important;
    }

    /* 4. Mobile Chat Topbar & Back Button */
    .btn-back-mobile {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        border-radius: 50%;
        background: transparent;
        border: none;
        color: var(--text-primary);
        cursor: pointer;
        margin-left: 2px;
        flex-shrink: 0;
        transition: background-color 0.15s, transform 0.15s;
    }

    .btn-back-mobile:active {
        background-color: var(--bg-hover);
        transform: scale(0.92);
    }

    .chat-topbar {
        height: 54px;
        padding: 6px 10px;
        background-color: var(--bg-header);
        border-bottom: 1px solid var(--border-color);
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-shrink: 0;
    }

    .chat-contact-info {
        display: flex;
        align-items: center;
        gap: 8px;
        min-width: 0;
        flex: 1;
    }

    .chat-contact-info .contact-avatar {
        width: 38px !important;
        height: 38px !important;
        flex-shrink: 0;
    }

    .contact-details {
        min-width: 0;
        flex: 1;
    }

    .contact-details h3 {
        font-size: 14.5px;
        font-weight: 700;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .active-line-badge {
        font-size: 10px;
        padding: 1px 6px;
    }

    /* 5. Mobile Message Bubbles & Typography */
    .chat-messages {
        padding: 10px 10px 14px 10px;
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .msg-bubble {
        max-width: 86% !important;
        padding: 7px 11px 5px 11px !important;
        border-radius: 12px !important;
        margin-bottom: 4px;
    }

    .msg-text {
        font-size: 14.5px;
        line-height: 1.45;
    }

    .chat-thumbnail {
        max-width: 100% !important;
        max-height: 280px !important;
        border-radius: 8px;
    }

    /* 6. Mobile Message Input Bar */
    .chat-input-bar {
        padding: 7px 8px calc(7px + env(safe-area-inset-bottom, 0px)) 8px;
        background-color: var(--bg-chat-bar);
        border-top: 1px solid var(--border-color);
        gap: 6px;
        align-items: flex-end;
    }

    .btn-input-action {
        width: 38px;
        height: 38px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        border-radius: 50%;
    }

    .input-text-wrap {
        border-radius: 20px;
        padding: 4px 12px;
        flex: 1;
        min-height: 38px;
        display: flex;
        align-items: center;
    }

    .input-text-wrap textarea {
        font-size: 15px; /* Critical iOS zoom fix */
        line-height: 1.35;
        max-height: 90px;
        padding: 6px 0;
    }

    .btn-send {
        width: 42px;
        height: 42px;
        border-radius: 50%;
        flex-shrink: 0;
        box-shadow: 0 2px 8px rgba(0, 168, 132, 0.4);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .btn-send:active {
        transform: scale(0.92);
    }

    /* Floating Scroll Down button adjustment */
    .btn-scroll-down {
        bottom: calc(70px + env(safe-area-inset-bottom, 0px));
        left: 14px;
        width: 38px;
        height: 38px;
    }

    /* 7. Mobile Bottom Navigation Bar */
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 58px;
        background-color: var(--bg-header);
        border-top: 1px solid var(--border-color);
        display: flex;
        align-items: center;
        justify-content: space-around;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        z-index: 45;
        box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.25);
        transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.25s ease;
    }

    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        background: transparent;
        border: none;
        color: var(--text-secondary);
        font-size: 11px;
        font-weight: 600;
        cursor: pointer;
        padding: 5px 14px;
        transition: color 0.15s ease, transform 0.15s ease;
        position: relative;
    }

    .mobile-nav-item.active {
        color: var(--accent-green);
    }

    .mobile-nav-item:active {
        transform: scale(0.92);
    }

    .nav-icon-wrap {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .nav-badge {
        position: absolute;
        top: -4px;
        left: -8px;
        background-color: var(--accent-emerald);
        color: #ffffff;
        font-size: 10px;
        font-weight: 700;
        padding: 1px 5px;
        border-radius: 10px;
        border: 2px solid var(--bg-header);
        display: none;
    }

    .nav-badge.visible {
        display: block;
    }

    /* 8. Floating Action Button (FAB) */
    .mobile-fab {
        position: fixed;
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
        left: 18px;
        width: 52px;
        height: 52px;
        border-radius: 50%;
        background: linear-gradient(135deg, #00A884 0%, #25D366 100%);
        border: none;
        color: #ffffff;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 16px rgba(0, 168, 132, 0.45);
        cursor: pointer;
        z-index: 48;
        transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.25s ease;
    }

    .mobile-fab:active {
        transform: scale(0.92);
    }

    /* 9. Native Bottom Sheet Modals */
    .modal-overlay {
        align-items: flex-end !important;
        padding: 0 !important;
    }

    .modal-card {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 22px 22px 0 0 !important;
        max-height: 88vh !important;
        margin: 0 !important;
        position: relative;
        animation: sheetSlideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1) !important;
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .modal-card::before {
        content: '';
        display: block;
        width: 42px;
        height: 4px;
        border-radius: 2px;
        background-color: var(--text-secondary);
        opacity: 0.35;
        margin: 8px auto 14px auto;
    }

    @keyframes sheetSlideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    .lines-list-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .lines-table {
        min-width: 520px;
    }
}

/* Saved Messages Styles */
.saved-messages-item {
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 168, 132, 0.04);
}
.saved-messages-item:hover {
    background: rgba(0, 168, 132, 0.08) !important;
}
.saved-messages-item.active {
    background: rgba(0, 168, 132, 0.15) !important;
}
.saved-avatar {
    background: linear-gradient(135deg, #00A884 0%, #06B6D4 100%) !important;
    color: #ffffff !important;
    display: flex;
    align-items: center;
    justify-content: center;
}
.saved-avatar svg {
    width: 22px !important;
    height: 22px !important;
    fill: #ffffff !important;
}
.saved-pin-icon {
    display: inline-flex;
    align-items: center;
    margin-right: 4px;
    font-size: 13px;
    opacity: 0.8;
}
.saved-source-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(245, 158, 11, 0.15);
    color: #F59E0B;
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 6px;
}
.saved-msg-delete-btn {
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s, color 0.2s;
    margin-right: 8px;
}
.saved-msg-delete-btn:hover {
    opacity: 1;
    color: #EF4444;
}
.saved-empty-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
}
.saved-empty-box svg {
    width: 64px;
    height: 64px;
    fill: #00A884;
    margin-bottom: 16px;
    opacity: 0.7;
}
.saved-empty-box h3 {
    color: var(--text-primary);
    font-size: 18px;
    margin-bottom: 8px;
}
.saved-empty-box p {
    max-width: 420px;
    line-height: 1.6;
    font-size: 14px;
}

/* Message Text & Media Styles */
.msg-text {
    font-size: 14.5px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
    user-select: text;
    margin-bottom: 3px;
    color: inherit;
}

.msg-media {
    margin-bottom: 6px;
    border-radius: 6px;
    overflow: hidden;
}

.chat-thumbnail {
    max-width: 320px;
    max-height: 380px;
    width: 100%;
    height: auto;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
    display: block;
    background-color: rgba(0, 0, 0, 0.15);
}

.chat-thumbnail:hover {
    opacity: 0.95;
    transform: scale(1.01);
}

.img-error-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.08);
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 13px;
    text-align: center;
    margin: 4px 0;
}

.btn-retry-img {
    background: var(--accent-green);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn-retry-img:hover {
    opacity: 0.9;
}

.file-download-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.2);
    padding: 8px 12px;
    border-radius: 6px;
    color: inherit;
    text-decoration: none;
    font-weight: 500;
    transition: background 0.2s;
}

.file-download-link:hover {
    background: rgba(0, 0, 0, 0.35);
}

/* Infinite Scroll Pagination Loader */
.chats-infinite-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 12px;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    transition: opacity 0.2s ease;
}

.chats-infinite-loader.hidden {
    display: none !important;
}

.spinner-sm {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 168, 132, 0.2);
    border-top-color: var(--accent-green);
    border-radius: 50%;
    animation: spinLoader 0.75s linear infinite;
    flex-shrink: 0;
}

@keyframes spinLoader {
    to { transform: rotate(360deg); }
}

.chats-empty-state {
    padding: 30px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13.5px;
}

/* ==========================================================================
   1. WhatsApp Rich Text Formatting, Code & Clickable Links
   ========================================================================== */
.wa-link {
    color: var(--ack-blue, #53bdeb);
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
    cursor: pointer;
    font-weight: 500;
}
.wa-link:hover {
    color: #79d1fa;
}
body.light-theme .wa-link {
    color: #027eb5 !important;
}

.wa-code-block {
    background: rgba(0, 0, 0, 0.28);
    border-radius: 6px;
    padding: 8px 10px;
    margin: 6px 0;
    font-family: 'JetBrains Mono', Consolas, Monaco, monospace;
    font-size: 13px;
    direction: ltr;
    text-align: left;
    overflow-x: auto;
    border: 1px solid rgba(255, 255, 255, 0.08);
}
body.light-theme .wa-code-block {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(0, 0, 0, 0.1);
}

.wa-inline-code {
    background: rgba(0, 0, 0, 0.22);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 13px;
    direction: ltr;
    display: inline-block;
}
body.light-theme .wa-inline-code {
    background: rgba(0, 0, 0, 0.08);
}

/* Rich Link Preview Card */
.wa-link-preview {
    margin-top: 6px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: background 0.15s ease, transform 0.15s ease;
}
.wa-link-preview:hover {
    background: rgba(0, 0, 0, 0.25);
    transform: translateY(-1px);
}
body.light-theme .wa-link-preview {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.08);
}
body.light-theme .wa-link-preview:hover {
    background: rgba(0, 0, 0, 0.08);
}
.wa-preview-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: rgba(0, 168, 132, 0.15);
    color: var(--accent-green);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.wa-preview-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.wa-preview-domain {
    font-weight: 600;
    font-size: 12.5px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wa-preview-url {
    font-size: 11.5px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    direction: ltr;
    text-align: right;
}
.wa-preview-arrow {
    color: var(--text-secondary);
    font-size: 15px;
}

/* ==========================================================================
   2. Typing Status & Online Indicator
   ========================================================================== */
.typing-status {
    font-size: 11.5px;
    color: var(--accent-green);
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-right: 6px;
}
.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: var(--accent-green);
    display: inline-block;
    animation: typingPulse 1.2s infinite ease-in-out;
}
@keyframes typingPulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.15); }
}

/* ==========================================================================
   3. In-Chat Search Bar
   ========================================================================== */
.chat-search-bar {
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 16px;
    animation: slideDownSearch 0.2s ease;
    z-index: 10;
}
@keyframes slideDownSearch {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}
.search-bar-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: var(--bg-sidebar);
    border-radius: var(--radius-sm);
    padding: 4px 12px;
    border: 1px solid var(--border-color);
}
.search-bar-inner input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 13.5px;
}
.search-count {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}
.btn-search-nav, .btn-search-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease, background 0.15s ease;
}
.btn-search-nav:hover:not(:disabled), .btn-search-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}
.btn-search-nav:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Search Highlights inside Message Bubbles */
.msg-search-highlight {
    background-color: #ffd000 !important;
    color: #000000 !important;
    border-radius: 2px;
    padding: 1px 2px;
}
.msg-search-current {
    background-color: #ff9800 !important;
    color: #ffffff !important;
    box-shadow: 0 0 8px rgba(255, 152, 0, 0.8);
    font-weight: bold;
}

/* ==========================================================================
   4. Quick Replies Popover (⚡ / Shortcut)
   ========================================================================== */
.quick-replies-popover {
    position: absolute;
    bottom: 68px;
    right: 16px;
    width: 360px;
    max-width: calc(100vw - 32px);
    background-color: var(--bg-modal);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 50;
    overflow: hidden;
    animation: popoverFadeIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes popoverFadeIn {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.quick-replies-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(245, 158, 11, 0.08);
}
.quick-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-weight: 600;
    font-size: 13.5px;
    color: var(--text-primary);
}
.btn-add-quick {
    background: var(--accent-green);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    cursor: pointer;
    transition: opacity 0.15s ease;
}
.btn-add-quick:hover {
    opacity: 0.9;
}
.quick-replies-list {
    max-height: 260px;
    overflow-y: auto;
    padding: 6px 0;
}
.quick-reply-item {
    padding: 8px 14px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 3px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: background 0.15s ease;
}
.quick-reply-item:hover, .quick-reply-item.active {
    background-color: var(--bg-hover);
}
.quick-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.quick-shortcut-tag {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 11px;
    font-weight: 700;
    background: rgba(0, 168, 132, 0.18);
    color: var(--accent-green);
    padding: 2px 7px;
    border-radius: var(--radius-pill);
}
.quick-item-title {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-primary);
}
.quick-item-snippet {
    font-size: 11.5px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

/* ==========================================================================
   5. Multi-Select Messages Bar & Checkboxes
   ========================================================================== */
.multi-select-bar {
    position: sticky;
    bottom: 0;
    width: 100%;
    background-color: var(--bg-header);
    border-top: 1px solid var(--border-color);
    padding: 10px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.2);
    z-index: 40;
    animation: slideUpMulti 0.2s ease;
}
@keyframes slideUpMulti {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.multi-select-info {
    display: flex;
    align-items: center;
    gap: 12px;
}
.btn-close-multi {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 50%;
}
.btn-close-multi:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}
.multi-count-label {
    font-weight: 600;
    font-size: 13.5px;
    color: var(--text-primary);
}
.multi-select-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-multi-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: var(--bg-active);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}
.btn-multi-action:hover {
    background-color: var(--bg-hover);
    transform: translateY(-1px);
}
.btn-multi-action.danger {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.3);
    background-color: rgba(239, 68, 68, 0.1);
}
.btn-multi-action.danger:hover {
    background-color: rgba(239, 68, 68, 0.2);
}

/* Checkbox inside Message Bubble for Multi-select */
.msg-checkbox-wrap {
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
    cursor: pointer;
}
.msg-checkbox-wrap input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-green);
    cursor: pointer;
}
.msg-bubble.multi-selected {
    outline: 2px solid var(--accent-green) !important;
    outline-offset: 2px;
}

/* ==========================================================================
   6. Swipe-to-Reply on Mobile
   ========================================================================== */
.msg-bubble.swipe-ready {
    box-shadow: 0 0 10px rgba(0, 168, 132, 0.5) !important;
}


