/* --- EXACT TELEGRAM DARK MODE THEME --- */
:root {
    --bg-main: #0e1621;
    --panel-bg: #17212b;
    --border-color: #242f3d;
    --text-primary: #f5f5f5;
    --text-secondary: #7f91a4;
    --input-placeholder: #7f91a4;

    /* Bubble Colors */
    --bubble-sent: #2b5278;
    --bubble-received: #182533;
    --bubble-sent-text: #ffffff;
    --bubble-received-text: #ffffff;
}

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

img.emoji {
    height: 1.3em;
    width: 1.3em;
    margin: 0 .05em 0 .1em;
    vertical-align: -0.2em;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
    background-color: #0e1621;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 20px;
    color: var(--text-primary);
    overflow: hidden;
}

.chat-card {
    width: 100%;
    max-width: 440px;
    height: 88vh;
    background: var(--bg-main);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    border-radius: 28px;
    border: 1px solid var(--border-color);
}

/* Top Header Bar */
.header-bar {
    background: #131b2c; /* Matches screenshot slate color */
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.profile-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-wrapper {
    position: relative;
    width: 42px;
    height: 42px;
}

.avatar-container {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #f8f1e9;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.avatar {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
}

.status-indicator {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 14px;
    height: 14px;
    background-color: #10b981;
    border: 3px solid #131b2c; /* Match header bar to cut out */
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.6);
    transition: all 0.3s ease;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.title {
    font-size: 16px;
    font-weight: 600;
    color: #ffffff;
}

.subtitle {
    font-size: 13px;
    color: #94a3b8;
    margin-top: 2px;
}

/* Chat Workspace */
.chat-viewport {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background-color: var(--bg-main);
}

.chat-viewport::-webkit-scrollbar {
    width: 6px;
}
.chat-viewport::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

/* Bubbles */
.msg-wrapper {
    max-width: 80%;
    display: flex;
    flex-direction: column;
    position: relative;
    margin-bottom: 2px;
}

.msg-wrapper.sent {
    align-self: flex-end;
}

.msg-wrapper.received {
    align-self: flex-start;
}

.bubble {
    padding: 6px 12px 8px 12px;
    font-size: 15px;
    line-height: 1.35;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    position: relative;
    border-radius: 12px;
    display: inline-block;
    min-width: 60px;
    max-width: 100%;
    transition: background-color 0.5s ease;
}

.msg-wrapper.received .bubble.highlight-flash {
    background-color: #2b445e !important; /* Brighter slate for received */
}

.msg-wrapper.sent .bubble.highlight-flash {
    background-color: #3e73a3 !important; /* Brighter blue for sent */
}

/* In-Bubble Reply Box */
.reply-box {
    background: rgba(0, 0, 0, 0.15);
    border-left: 2px solid #5288c1;
    border-radius: 4px;
    padding: 4px 8px;
    margin-bottom: 4px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    max-width: 100%;
}
.reply-box .reply-author {
    font-size: 12px;
    font-weight: 600;
    color: #5288c1;
}
.msg-wrapper.received .reply-box .reply-author {
    color: #539be2;
}
.reply-box .reply-text {
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.9;
}

/* Reply Button Overlay */
.reply-btn-overlay {
    position: absolute;
    right: 100%;
    margin-right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.4);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    color: #fff;
    z-index: 10;
}
.reply-btn-overlay svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}
.msg-wrapper:hover .reply-btn-overlay {
    opacity: 1;
}
.msg-wrapper.sent .reply-btn-overlay {
    right: auto;
    left: 100%;
    margin-right: 0;
    margin-left: 12px;
}

/* Telegram Tails */
.msg-wrapper.received .bubble {
    background: var(--bubble-received);
    color: var(--bubble-received-text);
    border-bottom-left-radius: 6px;
}
.msg-wrapper.received:last-of-type .bubble, 
.msg-wrapper.received + .msg-wrapper.sent .bubble {
    border-bottom-left-radius: 0;
}
.msg-wrapper.received .bubble::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: -8px;
    width: 8px;
    height: 12px;
    background: var(--bubble-received);
    mask-image: radial-gradient(circle at top left, transparent 8px, black 8px);
    -webkit-mask-image: radial-gradient(circle at top left, transparent 8px, black 8px);
    display: none;
}
.msg-wrapper.received:last-of-type .bubble::before,
.msg-wrapper.received + .msg-wrapper.sent .bubble::before {
    display: block;
}

.msg-wrapper.sent .bubble {
    background: var(--bubble-sent);
    color: var(--bubble-sent-text);
    border-bottom-right-radius: 6px;
}
.msg-wrapper.sent:last-of-type .bubble {
    border-bottom-right-radius: 0;
}
.msg-wrapper.sent .bubble::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: -8px;
    width: 8px;
    height: 12px;
    background: var(--bubble-sent);
    mask-image: radial-gradient(circle at top right, transparent 8px, black 8px);
    -webkit-mask-image: radial-gradient(circle at top right, transparent 8px, black 8px);
    display: none;
}
.msg-wrapper.sent:last-of-type .bubble::after {
    display: block;
}

.timestamp {
    font-size: 11px;
    color: #7aa2ce;
    float: right;
    margin-left: 10px;
    margin-top: 6px;
    user-select: none;
    line-height: 1;
    display: flex;
    align-items: center;
}
.msg-wrapper.received .timestamp {
    color: #7f91a4;
}

/* Twemoji Rendering */
img.emoji {
    height: 1.2em;
    width: 1.2em;
    margin: 0 .05em 0 .1em;
    vertical-align: -0.2em;
}

/* Input Deck */
.input-deck {
    padding: 20px 26px 26px 26px;
    background: rgba(6, 8, 19, 0.3);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

/* Reply Preview Bar */
.reply-preview {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.04);
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: 20px 20px 0 0;
    position: relative;
    cursor: pointer;
}
.reply-preview-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
}
.reply-preview-icon svg {
    fill: #5288c1;
}
.reply-preview-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-left: 2px solid #5288c1;
    padding-left: 8px;
    overflow: hidden;
}
.reply-preview-title {
    font-size: 13px;
    font-weight: 600;
    color: #5288c1;
}
.reply-preview-text {
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.reply-cancel-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    margin-left: 12px;
    color: var(--text-secondary);
}
.reply-cancel-btn:hover {
    background: rgba(255,255,255,0.1);
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 6px 6px 6px 18px;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.input-wrapper:focus-within {
    background: rgba(255, 255, 255, 0.06);
    border-color: #5288c1;
    box-shadow: 0 0 20px rgba(82, 136, 193, 0.15);
}

.attach-btn, .smiley-btn, .action-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}
.attach-btn:hover, .smiley-btn:hover, .action-btn:hover {
    color: var(--text-primary);
}
.action-btn.send-btn {
    background: linear-gradient(135deg, #00c6fb 0%, #005ea3 100%);
    color: white;
    border: none;
    border-radius: 15px;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 198, 251, 0.3);
    margin-left: 6px;
}
.action-btn.send-btn:hover {
    transform: scale(1.03) translateY(-1px);
    box-shadow: 0 6px 18px rgba(0, 198, 251, 0.4);
}
.action-btn.send-btn:active {
    transform: scale(0.98);
}

.attach-btn svg, .smiley-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}
.action-btn.send-btn svg {
    width: 18px;
    height: 18px;
    fill: white;
    transform: translateX(1px);
}

.input-wrapper input {
    flex: 1;
    min-width: 0; /* Prevents flex from pushing buttons off-screen */
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    padding: 0 16px;
    outline: none;
}
.input-wrapper input::placeholder {
    color: var(--input-placeholder);
}

/* File Preview */
.file-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--panel-bg);
    padding: 8px 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 13px;
    border: 1px solid var(--border-color);
}
.remove-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}
.remove-btn:hover { color: #fca5a5; }

/* Media in bubbles */
.bubble img, .bubble video, .bubble lottie-player {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    display: block;
    margin-bottom: 4px;
}
/* For stickers, we don't want background bubbles */
.msg-wrapper.received.is-sticker .bubble, .msg-wrapper.sent.is-sticker .bubble {
    background: transparent;
    box-shadow: none;
    padding: 0;
}
.msg-wrapper.received.is-sticker .bubble::before, .msg-wrapper.sent.is-sticker .bubble::after {
    display: none;
}
.msg-wrapper.is-sticker .timestamp {
    background: transparent;
    padding: 0;
}

.system-pill {
    background: rgba(30, 41, 59, 0.8);
    color: #cbd5e1;
    font-size: 12px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 12px;
    margin: 16px auto;
    width: fit-content;
    text-align: center;
    backdrop-filter: blur(4px);
}
.system-pill.error-pill {
    background: rgba(239, 68, 68, 0.3);
}

/* Media Menu (Emoji, GIF, Sticker) */
.media-menu {
    position: absolute;
    bottom: 85px;
    left: 10px;
    right: 10px;
    height: 350px;
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 100;
}
.media-menu.open {
    display: flex;
}

.media-tabs {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border-color);
    background: var(--panel-bg);
    padding: 0 16px;
    height: 48px;
    flex-shrink: 0;
}
.media-tabs-group {
    display: flex;
    gap: 24px;
    height: 100%;
}
.media-tab {
    display: flex;
    align-items: center;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    transition: 0.2s;
    position: relative;
    border-bottom: 2px solid transparent;
}
.media-tab.active {
    color: #5288c1;
    border-bottom: 2px solid #5288c1;
}
.media-backspace {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 50%;
    margin-right: -8px;
}
.media-backspace:hover {
    background: rgba(255, 255, 255, 0.05);
}

.media-content {
    flex: 1;
    overflow-y: auto;
    position: relative;
    background: var(--bg-main);
}
.media-content::-webkit-scrollbar { width: 4px; }
.media-content::-webkit-scrollbar-thumb { background: var(--border-color); }

/* GIF/Sticker Grid */
.gif-grid, .sticker-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 4px;
}
.gif-grid img, .gif-grid video, .sticker-grid img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
    background: var(--bg-main);
}
.sticker-grid img {
    object-fit: contain;
}
.search-bar {
    padding: 10px;
    background: var(--panel-bg);
    border-bottom: 1px solid var(--bg-main);
}
.search-bar input {
    width: 100%;
    padding: 8px 12px;
    border-radius: 20px;
    border: none;
    background: var(--bg-main);
    color: var(--text-primary);
    outline: none;
}
