/* pickers.css: the emoji picker, the GIF picker and the phone sheet with tabs that holds both (js/ui/emoji-picker.js,
   js/ui/gif-picker.js and js/ui/composer.js; templates t-emoji-picker, t-gif-picker and t-combined-picker). The
   hosts that the pickers mount in are in composer.css and message.css. css/README.md has the map of the stylesheets. */

/* ==== Picker with tabs: emoji and GIF in one sheet on a phone ==== */
/* js/ui/composer.js; t-combined-picker */

.combined-picker {
    display: flex;
    flex-direction: column;
    /* A popover (index.html), shown by composer.js: the top layer puts the sheet above the header and outside every
       clip of the chat column. As a fixed box inside the input box, iOS WebKit painted the header over it and the
       backdrop never dimmed the header (2026-10-17, the full-height tab row was hidden). The same geometry holds in a
       browser without the Popover API, where the sheet stays a fixed box in the input box. */
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    /* The keyboard's height, measured by composer.js, which sets --sheet-height on the input box; half the screen
       before the first measurement (IB-41). The fallback here is for a sheet outside the input box. */
    height: var(--sheet-height, min(50vh, 400px));
    /* A popover gets a border, padding, auto margins, fit-content sizes and system colours from the browser;
       these put them back. */
    margin: 0;
    border: 0;
    padding: 0;
    color: inherit;
    background: var(--bg-sidebar);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24);
    overflow: hidden;
}

.combined-tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 8px 6px;
    background: var(--bg-header);
    flex-shrink: 0;
    border-bottom: 1px solid var(--bg-input);
}

.combined-tab {
    background: transparent;
    border: none;
    padding: 8px 14px;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: 4px;
    transition: background-color 0.15s, color 0.15s;
}

.combined-tab:hover {
    color: var(--text-primary);
    background: var(--bg-input);
}

/* Active tab rides on the root's data-active-tab, flipped client-side (composer.js). */
.combined-picker[data-active-tab="gifs"] .combined-tab[data-combined-tab="gifs"],
.combined-picker[data-active-tab="emoji"] .combined-tab[data-combined-tab="emoji"] {
    color: var(--text-primary);
    background: var(--bg-input);
}

/* The keyboard button and the full-height chevrons, at the right end of the tab row (IB-66). :active, not :hover:
   the sheet exists on phones only. */
.combined-tool {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    background: transparent;
    border: none;
    padding: 0;
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
}

.combined-keyboard {
    margin-left: auto;
}

.combined-tool:active {
    color: var(--text-primary);
    background: var(--bg-input);
}

/* The chevrons point up at half height and down at full height; composer.js flips aria-expanded. */
.combined-size svg {
    transition: transform 0.15s;
}

.combined-size[aria-expanded="true"] svg {
    transform: rotate(180deg);
}

.combined-body {
    flex: 1;
    min-height: 0;
    position: relative;
}

/* Stack panes so inactive ones keep state (search query, scroll position).
   Only the active one is visible. */
.combined-pane {
    position: absolute;
    inset: 0;
    display: none;
}

.combined-picker[data-active-tab="gifs"] .combined-pane[data-combined-pane="gifs"],
.combined-picker[data-active-tab="emoji"] .combined-pane[data-combined-pane="emoji"] {
    display: block;
}

/* The wrapped pickers have their own fixed widths/heights and shadows — strip them
   so they fill our pane cleanly. !important because the phone rule .emoji-picker-container
   .emoji-picker (composer.css) has identical specificity (0,2,0) and loads later. */
.combined-pane .emoji-picker,
.combined-pane .gif-picker {
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

/* ==== Emoji picker ==== */
/* js/ui/emoji-picker.js; t-emoji-picker, t-emoji-section */

.emoji-picker {
    display: flex;
    flex-direction: row;
    width: 460px;
    height: min(450px, calc(100vh - 130px));
    background: var(--bg-sidebar);
    border-radius: 8px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24);
    overflow: hidden;
    z-index: 1000;
}

/* Left sidebar with category icons */
.emoji-sidebar {
    display: flex;
    flex-direction: column;
    width: 40px;
    padding: 6px 4px;
    gap: 2px;
    background: var(--bg-header);
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    flex-shrink: 0;
}

.emoji-sidebar::-webkit-scrollbar {
    display: none;
}

.emoji-picker .category-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.1rem;
    opacity: 0.5;
    transition: opacity 0.15s, background-color 0.15s;
}

.emoji-picker .category-btn:hover {
    opacity: 1;
    background: var(--bg-input);
}

.emoji-picker .category-btn.active {
    opacity: 1;
    background: var(--bg-input);
}

/* Right scrollable content area */
.emoji-content {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
}

/* Search input */
.emoji-search {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 8px 8px 4px;
    background: var(--bg-sidebar);
    display: flex;
    align-items: center;
    gap: 4px;
}

.emoji-search input {
    flex: 1;
    padding: 6px 10px;
    border: none;
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    box-sizing: border-box;
    min-width: 0;
}

.emoji-search input::placeholder {
    color: var(--text-placeholder);
}

.emoji-search-clear {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0;
}

.emoji-search-clear:hover {
    color: var(--text-primary);
    background: var(--bg-input);
}

/* The ✕ appears only while a query exists — value-driven via :placeholder-shown, same
   pattern as the send button. Requires a non-empty placeholder on the input. */
.emoji-search input:placeholder-shown ~ .emoji-search-clear {
    display: none;
}

/* The search filter (ui/emoji-picker.js): non-matching cells and emptied sections hide
   through attributes the script sets; a reopen clears them. */
.emoji-btn[data-search-miss],
.emoji-section[data-search-empty] {
    display: none;
}

.emoji-content::-webkit-scrollbar {
    width: 8px;
}

.emoji-content::-webkit-scrollbar-track {
    background: transparent;
}

.emoji-content::-webkit-scrollbar-thumb {
    background: var(--bg-header);
    border-radius: 4px;
}

/* Each category section */
.emoji-section {
    /* Skip layout/paint for offscreen sections — with ~1000 cells mounted (hidden)
       this is what keeps the grid cheap. The intrinsic-size estimate only affects
       scrollbar accuracy until a section first renders. */
    content-visibility: auto;
    contain-intrinsic-size: auto 320px;
}

/* Sticky category header */
.emoji-picker .section-header {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 6px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    background: var(--bg-sidebar);
    letter-spacing: 0.02em;
}

/* Emoji grid within each section */
.emoji-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 4px 6px 8px;
    align-content: flex-start;
}

.emoji-btn {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.15s, transform 0.1s;
    flex-shrink: 0;
}

.emoji-btn:hover {
    background: var(--bg-input);
    transform: scale(1.1);
}

/* The cell's image and its glyph take their size from the slot (app.css). */
.emoji-btn .emoji-slot {
    --emoji-size: 40px;
}

.emoji-empty {
    width: 100%;
    text-align: center;
    color: var(--text-placeholder);
    padding: 2rem;
    font-size: 0.875rem;
}

/* Mobile adjustments - match parent's 600px breakpoint */
@media (max-width: 600px) {
    .emoji-sidebar {
        width: 36px;
    }

    .emoji-picker .category-btn {
        width: 28px;
        height: 28px;
    }

    .emoji-btn {
        width: 36px;
        height: 36px;
    }

    .emoji-btn .emoji-slot {
        --emoji-size: 28px;
    }
}

/* ==== GIF picker ==== */
/* js/ui/gif-picker.js; t-gif-picker, t-gif-card, t-gif-folder-tile */

.gif-picker {
    display: flex;
    flex-direction: row;
    width: 500px;
    height: min(460px, calc(100vh - 130px));
    background: var(--bg-sidebar);
    border-radius: 8px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24);
    overflow: hidden;
    z-index: 1000;
}

.gif-sidebar {
    display: flex;
    flex-direction: column;
    width: 40px;
    padding: 6px 4px;
    gap: 2px;
    background: var(--bg-header);
    flex-shrink: 0;
}

.gif-picker .category-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-secondary);
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.15s, background-color 0.15s;
}

.gif-picker .category-btn:hover {
    opacity: 1;
    background: var(--bg-input);
}

.gif-picker .category-btn.active {
    opacity: 1;
    background: var(--bg-input);
    color: var(--text-primary);
}


.gif-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.gif-search {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 8px;
    background: var(--bg-sidebar);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.gif-search input {
    flex: 1;
    padding: 6px 10px;
    border: none;
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    box-sizing: border-box;
    min-width: 0;
}

.gif-search input::placeholder {
    color: var(--text-placeholder);
}

.gif-search-clear,
.gif-upload-btn {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0;
}

.gif-search-clear:hover,
.gif-upload-btn:hover {
    color: var(--text-primary);
    background: var(--bg-input);
}

.gif-upload-btn.is-busy {
    pointer-events: none;
    cursor: default;
}

.gif-spinner {
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    border: 2px solid var(--bg-input);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* Busy overlay shown while a custom GIF/WebP is uploading & processing.
   Sits below the sticky search bar (z-index 2), so the "+" → spinner swap stays visible. */
.gif-upload-overlay {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(1px);
}

.gif-upload-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.gif-upload-overlay-text {
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
}

.gif-results {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 8px;
}

.gif-results::-webkit-scrollbar {
    width: 8px;
}

.gif-results::-webkit-scrollbar-track {
    background: transparent;
}

.gif-results::-webkit-scrollbar-thumb {
    background: var(--bg-header);
    border-radius: 4px;
}

.gif-section-header {
    padding: 8px 0 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
}

/* CSS masonry — natural packing without JS */
.gif-grid {
    column-count: 2;
    column-gap: 6px;
}

.gif-card {
    break-inside: avoid;
    position: relative;
    margin-bottom: 6px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--bg-input);
    cursor: pointer;
    display: block;
    width: 100%;
}

.gif-card video,
.gif-card img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: var(--bg-input);
}

.gif-fav-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 50%;
    color: white;
    opacity: 0;
    cursor: pointer;
    transition: opacity 0.15s, background-color 0.15s;
    padding: 0;
}

.gif-card:hover .gif-fav-btn {
    opacity: 1;
}

.gif-fav-btn.favorited {
    opacity: 1;
    color: #ffc107;
}

.gif-fav-btn:hover {
    background: rgba(0, 0, 0, 0.75);
}

.gif-empty {
    text-align: center;
    color: var(--text-placeholder);
    padding: 2rem 1rem;
    font-size: 0.875rem;
}

.gif-no-provider {
    padding: 1.25rem 1rem;
    line-height: 1.5;
}

.gif-no-provider p {
    margin: 0 0 0.5rem;
}

.gif-no-provider a {
    color: var(--accent-primary);
    text-decoration: underline;
}

/* Folder / shortcut tiles (Favorites, Server, Browse): Discord-style — a random member GIF
   animating under a blur, with the name on top. */
.gif-tile-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    margin-bottom: 8px;
}

.gif-folder-tile {
    position: relative;
    aspect-ratio: 2 / 1;
    border: none;
    border-radius: 8px;
    overflow: hidden;
    padding: 0;
    background: var(--bg-input);
    cursor: pointer;
}

.gif-folder-tile img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* the scale-up hides the blur's translucent fringe at the tile edges */
    transform: scale(1.15);
    filter: blur(4px) brightness(0.55);
}

.gif-folder-tile span {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 0 10px;
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
    overflow: hidden;
}

.gif-folder-tile:hover img {
    filter: blur(4px) brightness(0.7);
}

/* Back row shown while inside a folder */
.gif-folder-back {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 2px 2px 8px 2px;
    max-width: 100%;
}

.gif-folder-back span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gif-folder-back:hover {
    color: var(--accent-primary);
}

/* Footer link at the bottom of the Favorites tab */
.gif-manage-link {
    display: block;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 10px 0 4px;
    text-decoration: none;
}

.gif-manage-link:hover {
    color: var(--text-primary);
    text-decoration: underline;
}

.gif-attribution {
    flex-shrink: 0;
    padding: 6px 8px;
    text-align: right;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--bg-input);
}

.gif-attribution img {
    height: 16px;
    opacity: 0.6;
    vertical-align: middle;
}

/* Mobile adjustments */
@media (max-width: 600px) {
    .gif-picker {
        width: calc(100vw - 16px);
    }

    .gif-sidebar {
        width: 36px;
    }

    .gif-picker .category-btn {
        width: 28px;
        height: 28px;
    }
}
