/* QChat Emoji Picker
   Picker uses local raster flag fallbacks for Windows/Chrome while keeping Unicode in textareas.
   A non-interactive mirror paints flag images over regional-letter glyphs; encryption/search/copy stay normal text. */

.qchat-emoji-toggle {
    width: 44px;
    min-width: 44px;
}

.qchat-emoji-toggle i {
    pointer-events: none;
}

.qchat-emoji-picker {
    position: fixed;
    z-index: 10050;
    width: min(340px, calc(100vw - 16px));
    height: min(430px, calc(100vh - 16px));
    max-width: calc(100vw - 16px);
    max-height: min(430px, calc(100vh - 16px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 14px;
    background: var(--bs-body-bg, #fff);
    color: var(--bs-body-color, #212529);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
    opacity: 0;
    transform: none;
    transform-origin: left bottom;
    pointer-events: none;
    transition: opacity 120ms ease;
}

.qchat-emoji-picker.qchat-emoji-picker-open {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

.qchat-emoji-picker.d-none {
    display: none !important;
}

.qchat-emoji-picker-header {
    flex: 0 0 auto;
    padding: 8px 8px 4px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(10px);
}

.qchat-emoji-category-tabs {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 2px;
    overflow: hidden;
    scrollbar-width: none;
    width: 100%;
    max-width: 100%;
}

.qchat-emoji-category-tabs::-webkit-scrollbar {
    display: none;
}

.qchat-emoji-category-tab {
    width: auto;
    min-width: 0;
    height: 30px;
    min-height: 30px;
    max-width: 30px;
    max-height: 30px;
    flex: 1 1 0;
    border: 0;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

.qchat-emoji-category-tab:hover,
.qchat-emoji-category-tab:focus-visible,
.qchat-emoji-category-tab.active {
    background: rgba(0, 0, 0, 0.08);
    outline: none;
}

.qchat-emoji-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px;
}

.qchat-emoji-section {
    margin-bottom: 10px;
}

.qchat-emoji-section-title {
    font-size: 0.8rem;
    color: var(--bs-secondary-color, #6c757d);
    margin: 2px 0 8px;
}

.qchat-emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-auto-rows: 34px;
    gap: 4px;
    align-items: center;
    justify-content: start;
    width: auto;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
}

.qchat-emoji-btn {
    width: 100%;
    min-width: 0;
    max-width: 34px;
    height: 34px;
    min-height: 34px;
    max-height: 34px;
    flex: 0 0 34px;
    border: 0;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    background: transparent;
    cursor: pointer;
    color: inherit;
    line-height: 1;
    font-size: 24px;
    font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
    font-variant-emoji: emoji;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.qchat-emoji-btn:hover,
.qchat-emoji-btn:focus-visible {
    background: rgba(0, 0, 0, 0.08);
    outline: none;
}

.qchat-emoji-btn img {
    display: block;
    width: 25px;
    height: 25px;
    object-fit: contain;
    pointer-events: none;
}

.qchat-emoji-static-shell {
    display: grid;
    width: 25px;
    height: 25px;
    place-items: center;
    pointer-events: none;
}

.qchat-emoji-static-shell > * {
    grid-area: 1 / 1;
}

/* Static picker cells must never reflow or animate while assets load. */
.qchat-emoji-static-image-shell {
    width: 25px;
    min-width: 25px;
    max-width: 25px;
    height: 25px;
    min-height: 25px;
    max-height: 25px;
    overflow: visible;
}

.qchat-emoji-static-image {
    display: block;
    width: 25px;
    min-width: 25px;
    max-width: 25px;
    height: 25px;
    min-height: 25px;
    max-height: 25px;
    object-fit: contain;
    pointer-events: none;
    animation: none !important;
    transition: none !important;
    transform: none !important;
}

.qchat-emoji-static-image-shell.qchat-emoji-static-image-ready > .qchat-emoji-static-native-fallback {
    visibility: hidden;
}

.qchat-emoji-static-raster {
    display: block;
    width: 25px;
    height: 25px;
    max-width: 25px;
    max-height: 25px;
    object-fit: contain;
    pointer-events: none;
    opacity: 0;
}

.qchat-emoji-static-raster.qchat-emoji-static-raster-ready {
    opacity: 1;
}

.qchat-emoji-static-shell.qchat-emoji-static-shell-ready > .qchat-emoji-native {
    visibility: hidden;
}

.qchat-emoji-flag-image {
    display: block;
    width: 28px;
    height: 28px;
    object-fit: contain;
    pointer-events: none;
}

.qchat-emoji-flag-fallback[hidden] {
    display: none !important;
}

.qchat-emoji-toggle:disabled,
.qchat-emoji-toggle.disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.qchat-emoji-fallback {
    display: none;
    font-size: 22px;
    line-height: 1;
    pointer-events: none;
}

.qchat-emoji-btn.qchat-emoji-img-failed img {
    display: none;
}

.qchat-emoji-btn.qchat-emoji-img-failed .qchat-emoji-fallback {
    display: inline;
}

.qchat-emoji-empty {
    padding: 24px 8px;
    text-align: center;
    color: var(--bs-secondary-color, #6c757d);
    font-size: 0.9rem;
}

.qchat-emoji-search-wrap {
    flex: 0 0 auto;
    padding: 8px 10px 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(10px);
}

.qchat-emoji-search {
    width: 100%;
    min-height: 36px;
    border: 1px solid rgba(0, 0, 0, 0.14);
    border-radius: 10px;
    padding: 7px 11px;
    background: var(--bs-body-bg, #fff);
    color: var(--bs-body-color, #212529);
    outline: none;
    font-size: 0.92rem;
}

.qchat-emoji-search:focus {
    border-color: rgba(13, 110, 253, 0.55);
    box-shadow: 0 0 0 0.16rem rgba(13, 110, 253, 0.16);
}

.qchat-emoji-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10040;
    background: transparent;
}

.qchat-emoji-backdrop.d-none {
    display: none !important;
}

/* Dark theme friendliness. Project already has dark.css, so keep this generic. */
[data-theme="dark"] .qchat-emoji-picker,
.dark .qchat-emoji-picker,
body.dark .qchat-emoji-picker {
    border-color: rgba(255, 255, 255, 0.14);
    background: #1f232a;
    color: #f1f3f5;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.48);
}

[data-theme="dark"] .qchat-emoji-picker-header,
[data-theme="dark"] .qchat-emoji-search-wrap,
[data-theme="dark"] .qchat-emoji-section-title,
.dark .qchat-emoji-picker-header,
.dark .qchat-emoji-search-wrap,
.dark .qchat-emoji-section-title,
body.dark .qchat-emoji-picker-header,
body.dark .qchat-emoji-search-wrap,
body.dark .qchat-emoji-section-title {
    background: rgba(31, 35, 42, 0.9);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .qchat-emoji-search,
.dark .qchat-emoji-search,
body.dark .qchat-emoji-search {
    background: #15181d;
    color: #f1f3f5;
    border-color: rgba(255, 255, 255, 0.16);
}

/* Mobile: bottom sheet, so it does not jump outside the viewport above the keyboard/input area. */
/* The picker must never create a horizontal scrollbar.
   Desktop is wider; mobile remains bounded by the viewport. */
@media (max-width: 576px) {
    .qchat-emoji-toggle {
        width: 42px;
        min-width: 42px;
        padding-left: 0;
        padding-right: 0;
    }

    .qchat-emoji-picker {
        left: 8px !important;
        right: 8px !important;
        bottom: 70px !important;
        top: auto !important;
        width: auto !important;
        height: min(430px, calc(100vh - 92px));
        max-width: none;
        border-radius: 14px;
        transform-origin: center bottom;
    }

    .qchat-emoji-grid {
        grid-template-columns: repeat(8, minmax(0, 1fr));
        grid-auto-rows: 34px;
        gap: 4px;
        justify-content: start;
    }

    .qchat-emoji-btn {
        width: 34px;
        min-width: 34px;
        max-width: 34px;
        height: 34px;
        min-height: 34px;
        max-height: 34px;
    }

    .qchat-emoji-btn img {
        width: 26px;
        height: 26px;
    }
}

@media (max-width: 380px) {
    .qchat-emoji-grid {
        grid-template-columns: repeat(7, minmax(0, 1fr));
    }
}


/* Force emoji-capable fonts inside form controls. Android/Chromium can otherwise
   render regional-indicator flag sequences as plain country-code letters because
   button controls inherit the UI sans-serif font instead of the color emoji font. */
.qchat-emoji-native,
.qchat-emoji-btn .qchat-emoji-native {
    display: inline-block;
    font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif !important;
    font-variant-emoji: emoji;
    font-size: 24px;
    line-height: 1;
    font-weight: 400;
    letter-spacing: 0;
    white-space: nowrap;
}


/* v7: Windows Chrome renders regional-indicator flag pairs in <textarea> as
   letters (UA/US/GB). Keep real Unicode in the textarea and paint only a
   non-interactive raster mirror over those glyph positions. The mirror is
   mounted under <body>, not inside Bootstrap's .input-group, so it can never
   participate in composer flex sizing or make the toolbar jump/blink. */
.qchat-composer-flag-overlay {
    position: fixed;
    z-index: 1000;
    overflow: hidden;
    pointer-events: none;
    user-select: none;
    background: transparent;
    contain: layout paint;
}

.qchat-composer-flag-overlay[hidden] {
    display: none !important;
}

.qchat-composer-flag-overlay-surface {
    position: absolute;
    box-sizing: border-box;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: normal;
    color: transparent;
    background: transparent;
    pointer-events: none;
}

.qchat-composer-flag-slot {
    position: relative;
    display: inline-block;
    color: transparent;
    white-space: nowrap;
    vertical-align: baseline;
    isolation: isolate;
}

.qchat-composer-flag-image {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 1em;
    height: 0.68em;
    max-width: none;
    object-fit: fill;
    transform: translate(-52%, -50%);
    vertical-align: middle;
    border-radius: 1px;
    pointer-events: none;
}

/* v10: the flag mirror sits above the native textarea, so Chrome's native caret can
   disappear exactly at a mirrored flag. Draw a zero-width caret proxy inside the
   flag slot; it never participates in composer layout or changes the real value. */
.qchat-composer-flag-caret {
    position: absolute;
    top: 50%;
    width: 1.5px;
    height: 1.08em;
    transform: translateY(-50%);
    z-index: 4;
    border-radius: 1px;
    pointer-events: none;
    animation: qchat-composer-caret-blink 1s steps(1, end) infinite;
}

.qchat-composer-flag-caret-before { left: -1px; }
.qchat-composer-flag-caret-after { right: -2px; }

@keyframes qchat-composer-caret-blink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .qchat-composer-flag-caret { animation: none; }
}


/* QChat emoji dark-theme parity v26
 * The application uses body.dark-theme/body.auto-theme, not the older .dark
 * aliases above. Keep the picker one continuous dark surface: header and search
 * footer must not look like light/grey cards pasted onto the popup. */
body.dark-theme .qchat-emoji-picker {
    background: #0d1117 !important;
    color: #c9d1d9 !important;
    border-color: #30363d !important;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.58) !important;
}
body.dark-theme .qchat-emoji-picker-header,
body.dark-theme .qchat-emoji-body,
body.dark-theme .qchat-emoji-search-wrap {
    background: #0d1117 !important;
    border-color: #30363d !important;
    backdrop-filter: none !important;
}
body.dark-theme .qchat-emoji-section-title {
    background: transparent !important;
    color: #8b949e !important;
}
body.dark-theme .qchat-emoji-search {
    background: #0d1117 !important;
    color: #c9d1d9 !important;
    border-color: #30363d !important;
}
body.dark-theme .qchat-emoji-category-tab:hover,
body.dark-theme .qchat-emoji-category-tab:focus-visible,
body.dark-theme .qchat-emoji-category-tab.active,
body.dark-theme .qchat-emoji-btn:hover,
body.dark-theme .qchat-emoji-btn:focus-visible {
    background: rgba(255, 255, 255, 0.08) !important;
}

@media (prefers-color-scheme: dark) {
    body.auto-theme .qchat-emoji-picker {
        background: #0d1117 !important;
        color: #c9d1d9 !important;
        border-color: #30363d !important;
        box-shadow: 0 18px 50px rgba(0, 0, 0, 0.58) !important;
    }
    body.auto-theme .qchat-emoji-picker-header,
    body.auto-theme .qchat-emoji-body,
    body.auto-theme .qchat-emoji-search-wrap {
        background: #0d1117 !important;
        border-color: #30363d !important;
        backdrop-filter: none !important;
    }
    body.auto-theme .qchat-emoji-section-title {
        background: transparent !important;
        color: #8b949e !important;
    }
    body.auto-theme .qchat-emoji-search {
        background: #0d1117 !important;
        color: #c9d1d9 !important;
        border-color: #30363d !important;
    }
    body.auto-theme .qchat-emoji-category-tab:hover,
    body.auto-theme .qchat-emoji-category-tab:focus-visible,
    body.auto-theme .qchat-emoji-category-tab.active,
    body.auto-theme .qchat-emoji-btn:hover,
    body.auto-theme .qchat-emoji-btn:focus-visible {
        background: rgba(255, 255, 255, 0.08) !important;
    }
}

/* QChat Noto Animated Emoji v365: same-origin WebP proxy with native/static fallback. */
.qchat-emoji-animated-image {
    display: block;
    width: 25px;
    height: 25px;
    object-fit: contain;
    pointer-events: none;
}
.qchat-emoji-animation-fallback[hidden] {
    display: none !important;
}

/* QChat v368: one-at-a-time animated preview for emoji-picker hover/long-press. */
.qchat-emoji-animation-preview {
    position: fixed;
    z-index: 10970;
    display: grid;
    width: 84px;
    height: 84px;
    place-items: center;
    padding: 10px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.22);
    pointer-events: none;
    overflow: hidden;
}
.qchat-emoji-animation-preview[hidden] {
    display: none !important;
}
.qchat-emoji-animation-preview > * {
    grid-area: 1 / 1;
}
.qchat-emoji-animation-preview-image {
    display: block;
    width: 64px;
    height: 64px;
    object-fit: contain;
    pointer-events: none;
}
.qchat-emoji-animation-preview-fallback {
    font-size: 48px;
    line-height: 1;
}
body.dark-theme .qchat-emoji-animation-preview {
    background: rgba(13, 17, 23, 0.97);
    border-color: #30363d;
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.5);
}
@media (prefers-color-scheme: dark) {
    body.auto-theme .qchat-emoji-animation-preview {
        background: rgba(13, 17, 23, 0.97);
        border-color: #30363d;
        box-shadow: 0 10px 32px rgba(0, 0, 0, 0.5);
    }
}
@media (prefers-reduced-motion: reduce) {
    .qchat-emoji-animation-preview-image {
        display: none !important;
    }
    .qchat-emoji-animation-preview-fallback {
        display: inline-block !important;
    }
}


/* Keep iOS draft images in the same layout coordinate space as the textarea.
   Explicit rules prevent fallback to the desktop fixed overlay. */
.qchat-composer-emoji-anchor {
    position: relative !important;
}
.qchat-composer-emoji-anchor > .qchat-composer-flag-overlay.qchat-composer-emoji-anchored {
    position: absolute !important;
    margin: 0 !important;
    right: auto !important;
    bottom: auto !important;
    align-self: auto !important;
    pointer-events: none !important;
}

/* Retain focus-safe input sizing even when zoom changes media-query matches.
   This does not restrict the user's pinch zoom. */
@supports (-webkit-touch-callout: none) {
    #messageInput.qchat-message-textarea,
    #profileBlogInput.qchat-message-textarea {
        font-size: 16px !important;
    }
}
