/* ==========================================================================
   THE EMOJI PICKER (Components/Emoji - CONVERSATION-BUILDER.md section 17 "The emoji picker",
   DATA-STUDIO-UI.md "Property editor - emoji")

   A quiet smiley at the inside end of a field that holds words a person reads (a display
   name, a description, a choice label), and the small dialog it opens: the search, the
   tabs, the person's recent row, the grid, the name of the highlighted emoji and one quiet
   SMS line. It serves the builder AND Data Studio, so it uses the platform's --theme-*
   tokens only (no hex). This stylesheet owns every emj-* class.
   ========================================================================== */

/* ── the host (EmojiField) ──────────────────────────────────────────────── */

.emj-host {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

/* Room for the trigger, so text never runs under it - the field's box is unchanged. */
.emj-host[data-emj-host] > :is(input, textarea) {
    padding-inline-end: 34px;
}

/* Centred by a margin, NEVER a transform: a transformed ancestor would become the containing block of the fixed dialog,
   and a scrolling drawer or dialog body around it would then clip it. */
.emj-host > .emj {
    position: absolute;
    inset-inline-end: 5px;
    top: 50%;
    margin-top: -12px;
}

.emj-host.is-multi > .emj {
    top: 5px;
    margin-top: 0;
}

/* ── the trigger: quiet until the field is hovered or focused, always a tab stop ── */

.emj {
    display: inline-flex;
    align-items: center;
}

.emj-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 24px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--theme-radius-button);
    background: transparent;
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-sm);
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--theme-transition), background var(--theme-transition), color var(--theme-transition);
}

[data-emj-host]:hover .emj-trigger,
[data-emj-host]:focus-within .emj-trigger,
.emj-trigger.is-open,
.emj-trigger:focus-visible {
    opacity: 1;
}

.emj-trigger:hover:not(:disabled),
.emj-trigger:focus-visible,
.emj-trigger.is-open {
    background: var(--theme-background-hover);
    color: var(--theme-text);
    outline: none;
}

.emj-trigger:focus-visible {
    /* --theme-focus-ring is a whole shadow ("0 0 0 3px <colour>") - used as is, never wrapped in another offset. */
    box-shadow: var(--theme-focus-ring);
}

/* A field that cannot be edited offers no picker (hover never brings a dead button back). */
.emj-trigger:disabled {
    visibility: hidden;
    cursor: default;
}

/* A screen with no hover: the trigger shows, softly. */
@media (hover: none) {
    .emj-trigger {
        opacity: .7;
    }
}

/* ── the dialog ───────────────────────────────────────────────────────── */

.emj-pop {
    position: fixed;
    z-index: 1090;
    display: flex;
    flex-direction: column;
    width: min(312px, calc(100vw - 16px));
    max-height: 380px;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-background-raised);
    color: var(--theme-text);
    box-shadow: var(--theme-shadow-lg);
    text-align: start;
    white-space: normal;
}

.emj-pop.is-placed {
    animation: emj-in 120ms ease-out;
}

@keyframes emj-in {
    from {
        opacity: 0;
        translate: 0 4px;
    }

    to {
        opacity: 1;
        translate: 0 0;
    }
}

.emj-search {
    display: block;
    width: calc(100% - 16px);
    margin: 8px 8px 4px;
    padding: 6px 10px;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius-button);
    background: var(--theme-background);
    color: var(--theme-text);
    font: inherit;
    font-size: var(--theme-font-size-sm);
}

.emj-search:focus {
    border-color: var(--theme-primary);
    box-shadow: var(--theme-focus-ring);
    outline: none;
}

/* The tab row scrolls sideways, and a flex item that scrolls may shrink to nothing: in this column the grid
   takes the height and the row's icons were cut in half. flex: none keeps the row its full height. */
.emj-tabs {
    display: flex;
    flex: none;
    gap: 2px;
    padding: 4px 8px 6px;
    border-bottom: 1px solid var(--theme-border-subtle);
    overflow-x: auto;
    scrollbar-width: none;
}

/* The tabs share the row's width, so every category shows with nothing to scroll to (ten tabs at a fixed 30px
   needed 318px of the dialog's 294 and hid the last). Only a screen too narrow for 24px tabs scrolls. */
.emj-tab {
    flex: 1 1 0;
    min-width: 24px;
    height: 32px;
    padding: 0;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: var(--theme-radius-button) var(--theme-radius-button) 0 0;
    background: transparent;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    opacity: .7;
}

.emj-tab:hover,
.emj-tab:focus-visible {
    background: var(--theme-background-hover);
    opacity: 1;
    outline: none;
}

.emj-tab.is-on {
    border-bottom-color: var(--theme-primary);
    opacity: 1;
}

.emj-grid {
    flex: 1 1 auto;
    min-height: 120px;
    padding: 4px 8px 6px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.emj-sec-label {
    padding: 6px 2px 2px;
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-xs);
    font-weight: 600;
}

.emj-row {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
}

.emj-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1;
    min-width: 0;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--theme-radius-button);
    background: transparent;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.emj-cell:hover,
.emj-cell.is-active {
    background: var(--theme-background-hover);
}

.emj-cell.is-active {
    border-color: var(--theme-primary);
}

.emj-empty {
    padding: 18px 6px;
    color: var(--theme-text-muted);
    font-size: var(--theme-font-size-sm);
    text-align: center;
}

.emj-foot {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 10px 8px;
    border-top: 1px solid var(--theme-border-subtle);
    font-size: var(--theme-font-size-xs);
}

.emj-name {
    min-height: 1.3em;
    color: var(--theme-text);
    font-weight: 600;
}

.emj-sms {
    color: var(--theme-text-muted);
}

@media (prefers-reduced-motion: reduce) {
    .emj-trigger {
        transition: none;
    }

    .emj-pop.is-placed {
        animation: none;
    }
}
