.chat-ui {
    --chat-bg: #0f172a;
    --header-bg: #111827;
    --header-text: #f9fafb;
    --subtle-text: #9ca3af;
    --bubble-sent: #3b82f6;
    --bubble-received: #1f2937;
    --text-primary: #ffffff;
    --accent: #22c55e;
    --status-seen: #60a5fa;
    --bubble-radius: 18px;

    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--chat-bg);
    color: var(--text-primary);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    background: var(--header-bg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-header-main {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.chat-header-icon {
    position: relative;
    color: var(--subtle-text);
    transition: color 160ms ease;
}

.chat-unread {
    position: absolute;
    top: -0.35rem;
    right: -0.45rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.05rem;
    height: 1.05rem;
    padding: 0 0.25rem;
    border-radius: 9999px;
    background: var(--accent);
    color: #022c22;
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 1;
}

.chat-header-icon:hover {
    color: var(--header-text);
}

.chat-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.2rem;
    height: 2.2rem;
    overflow: hidden;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.14);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

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

.chat-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.87rem;
    font-weight: 600;
    color: var(--header-text);
}

.chat-subtitle {
    margin-top: 0.1rem;
    font-size: 0.7rem;
    color: var(--subtle-text);
}

.chat-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    color: var(--subtle-text);
}

.chat-header-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.7rem;
    height: 1.7rem;
    border: none;
    background: transparent;
    color: var(--subtle-text);
    transition: color 160ms ease;
}

.chat-header-action:hover {
    color: var(--header-text);
}

.chat-header-action-icon {
    width: 1.05rem;
    height: 1.05rem;
}

.chat-header-action-icon-video {
    width: 1.2rem;
    height: 1.2rem;
}

.chat-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: radial-gradient(circle at top, rgba(255, 255, 255, 0.03), transparent 48%), var(--chat-bg);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.95rem 5rem;
}

.chat-footer {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.7rem 0.8rem 0.8rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: var(--header-bg);
}

.chat-footer-plus,
.chat-footer-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    border-radius: 9999px;
    color: var(--subtle-text);
    background: transparent;
    border: none;
    font-size: 1.1rem;
    line-height: 1;
}

.chat-footer-input-wrap {
    display: flex;
    align-items: center;
    min-width: 0;
    flex: 1;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.45rem 0.8rem;
}

.chat-footer-input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 0.8rem;
}

.chat-footer-input::placeholder {
    color: var(--subtle-text);
}

.chat-footer-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.18rem;
}

/* Composer text shows the sender "typing" during playback. Unlike a single-line
   <input>, this wraps and grows downward as the message exceeds one line. */
.composer-display {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.35;
    min-height: 1.35em;
    /* Grow up to 3 lines, then stop stretching and scroll internally. */
    max-height: calc(1.35em * 3);
    overflow-y: auto;
    scrollbar-width: none; /* Firefox: hide scrollbar but keep scroll */
    cursor: text;
}

.composer-display::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.composer-display.composer-empty {
    color: var(--subtle-text);
}

/* Send button revealed while typing (default/WhatsApp footer). */
.wa-send {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin-left: 8px;
    border: none;
    border-radius: 9999px;
    background: #00a884;
    color: #ffffff;
    cursor: pointer;
}

.wa-send svg {
    width: 18px;
    height: 18px;
    margin-left: 1px;
}

.bubble-row {
    position: relative;
    display: flex;
    margin-bottom: 0.75rem;
    max-width: 100%;
}

.bubble-row-sent {
    justify-content: flex-end;
}

.bubble-row-received {
    justify-content: flex-start;
}

.bubble {
    max-width: 76%;
    border-radius: var(--bubble-radius);
    padding: 0.6rem 0.72rem;
    box-shadow: 0 6px 14px rgba(2, 6, 23, 0.28);
}

.bubble.sent {
    background: var(--bubble-sent);
    border-bottom-right-radius: 6px;
}

.bubble.received {
    background: var(--bubble-received);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom-left-radius: 6px;
}

.bubble-content {
    word-break: break-word;
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--text-primary);
}

/* Only the message text preserves the author's line breaks — keeping pre-wrap
   off the wrapper prevents the template's own whitespace from inflating bubbles. */
.bubble-text {
    white-space: pre-wrap;
}

.bubble-meta {
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.35rem;
}

.bubble-time {
    font-size: 0.62rem;
    color: rgba(255, 255, 255, 0.74);
}

.bubble-status {
    font-size: 0.58rem;
    letter-spacing: -0.05em;
    color: rgba(255, 255, 255, 0.8);
}

.bubble-status.status-seen {
    color: var(--status-seen);
}

.bubble-status {
    display: inline-flex;
    align-items: center;
}

/* Tick glyphs: height-bound so the overlap baked into the SVG path is kept
   (no gap between the two checks like the old "✓✓" text had). */
.bubble-tick {
    height: 0.66rem;
    width: auto;
    display: block;
}

.bubble-reaction {
    position: absolute;
    bottom: -0.62rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.4rem;
    height: 1.15rem;
    border-radius: 9999px;
    padding: 0 0.28rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(15, 23, 42, 0.95);
    font-size: 0.68rem;
    z-index: 2;
}

/* Anchor the reaction to the bubble's near edge, per sender, on every platform. */
.bubble-row-sent .bubble-reaction,
.wa-row-sent .bubble-reaction {
    right: 0.6rem;
    left: auto;
}

.bubble-row-received .bubble-reaction,
.wa-row-received .bubble-reaction {
    left: 0.6rem;
    right: auto;
}

/* Give reacted rows a little extra room so the badge doesn't collide. */
.bubble-row:has(.bubble-reaction),
.wa-row:has(.bubble-reaction) {
    margin-bottom: 1.1rem;
}

/* Per-row sender avatar (Messenger only; hidden elsewhere). */
.row-avatar {
    display: none;
}

/* ----- Group-chat sender label ----- */
.bubble-sender {
    display: block;
    margin-bottom: 0.15rem;
    font-size: 0.7rem;
    font-weight: 700;
    color: #34d399;
}

/* ----- Typing indicator ----- */
.typing-row {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 0.75rem;
}

.typing-bubble {
    display: inline-flex;
    align-items: center;
    padding: 0.6rem 0.8rem;
    border-radius: var(--bubble-radius);
    border-bottom-left-radius: 6px;
    background: var(--bubble-received);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.typing-dots i {
    display: block;
    width: 6px;
    height: 6px;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.55);
    animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dots i:nth-child(2) {
    animation-delay: 0.18s;
}

.typing-dots i:nth-child(3) {
    animation-delay: 0.36s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.55;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ----- System note ----- */
.system-row {
    display: flex;
    justify-content: center;
    margin-bottom: 0.75rem;
}

.system-note {
    max-width: 85%;
    text-align: center;
    padding: 0.3rem 0.75rem;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.68rem;
    line-height: 1.4;
}

/* ----- Image message ----- */
.bubble-media {
    display: block;
}

.bubble-image {
    display: block;
    width: 100%;
    max-width: 220px;
    max-height: 260px;
    border-radius: 12px;
    object-fit: cover;
}

.bubble-video {
    display: block;
    width: 100%;
    max-width: 240px;
    max-height: 280px;
    border-radius: 12px;
    background: #000000;
    object-fit: contain;
}

.bubble-caption {
    display: block;
    margin-top: 0.4rem;
    font-size: 0.82rem;
    line-height: 1.4;
}

/* ----- Voice note ----- */
.voice-note {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 150px;
}

.voice-play {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.65rem;
    height: 1.65rem;
    flex-shrink: 0;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.2);
}

.voice-play svg {
    width: 0.8rem;
    height: 0.8rem;
}

.voice-play {
    border: none;
    cursor: pointer;
    color: #ffffff;
    padding: 0;
}

.voice-play:disabled {
    cursor: default;
    opacity: 0.5;
}

.voice-wave {
    position: relative;
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    height: 1.5rem;
}

.voice-scrub {
    position: absolute;
    left: 0;
    bottom: -3px;
    height: 2px;
    border-radius: 2px;
    background: #ffffff;
    transition: width 120ms linear;
}

.voice-note.is-playing .voice-wave i {
    background: rgba(255, 255, 255, 0.85);
}

.voice-wave i {
    display: block;
    width: 2px;
    height: 35%;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.55);
}

.voice-wave i:nth-child(odd) {
    height: 62%;
}

.voice-wave i:nth-child(3n) {
    height: 90%;
}

.voice-wave i:nth-child(5n) {
    height: 45%;
}

.voice-wave i:nth-child(7n) {
    height: 75%;
}

.voice-duration {
    flex-shrink: 0;
    font-size: 0.66rem;
    color: rgba(255, 255, 255, 0.72);
}

/* ----- File message ----- */
.file-card {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 180px;
}

.file-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.1rem;
    height: 2.1rem;
    flex-shrink: 0;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.16);
    color: #ffffff;
}

.file-icon svg {
    width: 1.1rem;
    height: 1.1rem;
}

.file-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
    font-size: 0.8rem;
    font-weight: 600;
}

.file-size {
    font-size: 0.66rem;
    color: rgba(255, 255, 255, 0.66);
}

#chat-preview,
#capture-preview {
    height: 100%;
}

#chat-preview .chat-ui,
#capture-preview .chat-ui {
    border-radius: 2rem;
    overflow: hidden;
}

.device-status-bar.statusbar-whatsapp,
.device-status-bar.statusbar-imessage,
.device-status-bar.statusbar-telegram,
.device-status-bar.statusbar-messenger,
.device-status-bar.statusbar-instagram {
    border-radius: 9999px;
    padding: 0.22rem 0.45rem;
}

.device-status-bar.statusbar-whatsapp {
    background: var(--wa-header-bg);
}

.device-status-bar.statusbar-imessage {
    background: #000000;
}

.device-status-bar.statusbar-telegram {
    background: #17212b;
}

.device-status-bar.statusbar-messenger {
    background: #000000;
}

.device-status-bar.statusbar-instagram {
    background: #000000;
}

/* Reply quote + forwarded label (Premium message features). */
.bubble-forwarded {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
    font-size: 0.72rem;
    font-style: italic;
    opacity: 0.7;
}
.bubble-forwarded svg {
    width: 13px;
    height: 13px;
}
.bubble-reply {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-bottom: 5px;
    padding: 5px 9px;
    border-left: 3px solid var(--accent, #8aa0b6);
    border-radius: 6px;
    background: rgba(127, 127, 127, 0.16);
    font-size: 0.78rem;
    line-height: 1.25;
    overflow: hidden;
}
.bubble-reply-name {
    font-weight: 600;
    opacity: 0.95;
    color: var(--accent, inherit);
}
.bubble-reply-text {
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* On-screen mobile keyboard (shown while the sender types). iOS-style light grey. */
.mobile-keyboard {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px 3px 7px;
    background: #d1d5db;
    user-select: none;
}
.kbd-row {
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 0 2px;
}
.kbd-key {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 30px;
    border-radius: 5px;
    background: #ffffff;
    color: #111827;
    font-size: 0.82rem;
    font-weight: 400;
    line-height: 1;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.28);
}
.kbd-key.kbd-on {
    background: #9aa3af;
    color: #ffffff;
    transform: translateY(1px);
    box-shadow: none;
}
.kbd-key.kbd-mod {
    flex: 1.4 1 0;
    background: #aab0ba;
    color: #1f2937;
    font-size: 0.72rem;
}
.kbd-key.kbd-space {
    flex: 5 1 0;
    font-size: 0.72rem;
    color: #6b7280;
}
.kbd-key.kbd-return,
.kbd-key.kbd-num {
    flex: 1.7 1 0;
}

/* Call log bubble (sent / received / missed). */
.call-card {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 140px;
    padding: 2px 4px;
}
.call-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 9999px;
    background: rgba(255, 255, 255, 0.14);
}
.call-icon svg {
    width: 18px;
    height: 18px;
}
.call-meta {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.call-title {
    font-weight: 600;
    font-size: 0.84rem;
}
.call-sub {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    opacity: 0.78;
}
.call-arrow {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
}
.call-card.call-missed .call-icon,
.call-card.call-missed .call-sub,
.call-card.call-missed .call-arrow {
    color: #f87171;
    opacity: 1;
}
.call-card.call-missed .call-icon {
    background: rgba(248, 113, 113, 0.18);
}

/* Chat intro (date separator + encryption notice) shown at the top of a thread. */
.chat-intro {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 4px 0 10px;
}
.chat-day-sep {
    text-align: center;
}
.chat-day-sep span {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 7px;
    background: rgba(0, 0, 0, 0.4);
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.66rem;
    font-weight: 600;
}

/* Free-tier preview watermark: a repeating diagonal "Chatmation" tiled across
   the chat so screenshots are covered (not just a corner badge). mix-blend-mode
   keeps it visible over any platform wallpaper (light or dark). */
.cm-watermark-tile {
    position: absolute;
    inset: 0;
    z-index: 40;
    pointer-events: none;
    background-repeat: repeat;
    background-image: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='210'%20height='130'%3E%3Ctext%20x='8'%20y='70'%20transform='rotate(-28%20105%2065)'%20fill='%23ffffff'%20font-family='Instrument%20Sans,Arial,sans-serif'%20font-size='15'%20font-weight='700'%3Echatmation.io%3C/text%3E%3C/svg%3E");
    mix-blend-mode: difference;
    opacity: 0.28;
}