/* ============================================================
   GIF picker (gif-picker.js) and GIF messages in the chat
   Same look as the reaction sheet: a bottom sheet on phones, a centred card
   on desktop. Palette: purple #7B1FA2, text #2d3748, focus #1E88E5.
   ============================================================ */

/* --- Composer buttons ---------------------------------------------- */
.btn-gif {
    flex: none;
    min-width: 52px;
    height: 44px;
    padding: 0 16px;
    border: none;
    border-radius: 22px;
    background: #7B1FA2;
    /* white wins over the chat page's `.glass-card * { color }` */
    color: #ffffff !important;
    font-weight: 800;
    font-size: 14px;
    letter-spacing: 0.6px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(123, 31, 162, 0.35);
    transition: background 0.15s ease, transform 0.1s ease;
}

.btn-gif:hover {
    background: #6A1B9A;
}

.btn-gif:active {
    transform: scale(0.96);
}

.btn-gif:focus-visible {
    outline: 2px solid #1E88E5;
    outline-offset: 2px;
}

/* --- Sheet ---------------------------------------------------------- */
/* On a phone the panel docks to the bottom and the conversation stays in view
   above it, so the overlay does not dim: it only catches a tap outside, which
   closes the panel. On desktop the panel is a centred card and gets a dim. */
#gifSheetOverlay {
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: 10002;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

#gifSheetOverlay.is-open {
    opacity: 1;
    visibility: visible;
}

#gifSheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    /* compact: about half the screen, so the conversation stays visible */
    height: 50vh;
    height: min(50dvh, 440px);
    background: #ffffff;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.22);
    z-index: 10003;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 12px calc(12px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
    transform: translateY(100%);
    transition: transform 0.3s ease-out, height 0.25s ease-out;
    visibility: hidden;
    color: #2d3748;
}

#gifSheet.is-open {
    transform: translateY(0);
    visibility: visible;
}

/* the chevron expands the panel to nearly full height */
#gifSheet.is-expanded {
    height: 86vh;
    height: min(86dvh, 680px);
}

/* The page behind the docked panel gets room at the bottom, so the newest
   messages can be scrolled up above it (gif-picker.js sets --gif-panel-h) */
html.gif-panel-open body {
    padding-bottom: var(--gif-panel-h, 0px);
}

/* Header: [ spacer | chevron | close ] - the chevron sits in the middle */
.gif-sheet-header {
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    justify-items: center;
    padding: 6px 0 10px;   /* room under the X so it never crowds the search */
    flex: none;
}

.gif-sheet-spacer {
    width: 44px;
    height: 44px;
}

.gif-sheet-header .gif-sheet-close {
    justify-self: end;
}

.gif-sheet-expand {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 44px;
    border: none;
    border-radius: 22px;
    background: transparent;
    cursor: pointer;
}

.gif-sheet-expand:hover {
    background: rgba(0, 0, 0, 0.05);
}

.gif-sheet-expand svg {
    width: 28px;
    height: 28px;
    fill: none;
    stroke: #6b7280;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.2s ease;
}

/* pointing up = "show more"; flips down once expanded */
#gifSheet.is-expanded .gif-sheet-expand svg {
    transform: rotate(180deg);
}

.gif-sheet-expand:focus-visible {
    outline: 2px solid #1E88E5;
    outline-offset: 2px;
}

/* Visible to assistive technology only (the panel's title) */
.gif-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.gif-sheet-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    /* 44px tap area, but a smaller 36px circle is drawn so it is not heavy */
    background: radial-gradient(circle, rgba(0, 0, 0, 0.06) 0 17.5px, transparent 18px);
    color: #2d3748;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.gif-sheet-close:hover {
    background: radial-gradient(circle, rgba(0, 0, 0, 0.11) 0 17.5px, transparent 18px);
}

/* Search: a full pill with a magnifier inside */
.gif-sheet-searchbox {
    position: relative;
    flex: none;
    margin: 0 0 8px;
}

.gif-sheet-magnifier {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    pointer-events: none;
}

.gif-sheet-magnifier svg {
    display: block;
    width: 20px;
    height: 20px;
    fill: none;
    stroke: #8a9099;
    stroke-width: 2.2;
    stroke-linecap: round;
}

.gif-sheet-search {
    display: block;
    width: 100%;
    height: 44px;
    box-sizing: border-box;
    padding: 0 16px 0 44px;
    border: 1.5px solid #cfd4da;
    border-radius: 22px;
    background: #f4f5f7;
    font-size: 16px; /* 16px: iOS does not zoom the page on focus */
    color: #2d3748;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.gif-sheet-search::placeholder {
    color: #8a9099;
}

.gif-sheet-search:focus {
    border-color: #7B1FA2;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(123, 31, 162, 0.15);
}

.gif-sheet-status {
    flex: none;
    margin: 4px 4px 6px;
    font-size: 14px;
    color: #4a5568;
}

.gif-sheet-status[hidden],
.gif-sheet-more[hidden],
.gif-sheet-preview[hidden] {
    display: none;
}

/* The cards (GIF-y / Naklejki / Memy) sit side by side in a row that scrolls
   sideways and snaps to whole cards, like the emoji picker's categories.
   The browser's own scrollbar is hidden (unreliable on phones): the drawn
   .gif-sheet-pagebar underneath is the one people see. */
.gif-sheet-pager {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.gif-sheet-pager::-webkit-scrollbar {
    display: none;
}

/* one provider, one card: nothing to swipe */
.gif-sheet-pager.is-single {
    overflow-x: hidden;
    scroll-snap-type: none;
}

/* dragging the scrollbar thumb: snapping off so the cards follow smoothly */
.gif-sheet-pager.is-dragging {
    scroll-snap-type: none;
}

/* Each card is one full-width page; it scrolls up and down on its own.
   Two balanced columns of still thumbnails. */
.gif-sheet-results {
    flex: 0 0 100%;
    min-width: 0;
    box-sizing: border-box;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    /* up/down stops here; sideways must pass on to the pager (contain on both
       axes would kill the swipe between cards) */
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    padding: 2px 0 4px;
}

/* the two columns of thumbnails; "Pokaż więcej" follows them inside the scroller */
.gif-sheet-grid {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.gif-sheet-col {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.gif-sheet-item {
    display: block;
    width: 100%;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 10px;
    background: #e9ecef;
    overflow: hidden;
    cursor: pointer;
    line-height: 0;
}

.gif-sheet-item img {
    display: block;
    width: 100%;
    height: auto;
}

.gif-sheet-item[aria-pressed="true"] {
    border-color: #7B1FA2;
    box-shadow: inset 0 0 0 1px #ffffff;
}

.gif-sheet-item:focus-visible,
.gif-sheet-send:focus-visible,
.gif-sheet-cancel:focus-visible,
.gif-sheet-more:focus-visible,
.gif-sheet-close:focus-visible {
    outline: 2px solid #1E88E5;
    outline-offset: 2px;
}

.gif-sheet-more {
    display: block;
    width: 100%;
    margin: 12px 0 6px;
    min-height: 44px;
    border: 1px solid #868F99;
    border-radius: 12px;
    background: #ffffff;
    color: #2d3748;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

/* The chosen picture: a full-screen modal (gif-picker.js puts it on <body>
   so it covers everything), the picture big, then "Wyślij" and "Pomiń" */
.gif-sheet-preview {
    position: fixed;
    inset: 0;
    z-index: 10005;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    box-sizing: border-box;
    padding: calc(16px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
    background: rgba(10, 10, 14, 0.88);
    animation: gifPreviewFade 0.18s ease-out;
}

.gif-sheet-preview-img {
    display: block;
    flex: 0 1 auto;
    min-height: 0;
    /* small pictures are scaled up to a comfortable size; tall ones are
       capped so the buttons always stay on screen */
    width: min(92vw, 520px);
    height: auto;
    max-height: 60vh;
    max-height: 60dvh;
    object-fit: contain;
    border-radius: 18px;
    background: #ffffff;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: gifPreviewPop 0.22s ease-out;
}

.gif-sheet-preview-title {
    margin: 0;
    max-width: min(92vw, 520px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #ffffff;
    font-size: 14px;
    opacity: 0.85;
}

.gif-sheet-preview-title[hidden] {
    display: none;
}

.gif-sheet-preview-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(92vw, 360px);
}

.gif-sheet-send,
.gif-sheet-cancel {
    min-height: 52px;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

.gif-sheet-send {
    border: 2px solid #7B1FA2;
    background: #7B1FA2;
    color: #ffffff;
}

.gif-sheet-cancel {
    border: 2px solid #ffffff;
    background: transparent;
    color: #ffffff;
}

@keyframes gifPreviewFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes gifPreviewPop {
    from { transform: scale(0.94); }
    to { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .gif-sheet-preview,
    .gif-sheet-preview-img { animation: none; }
}
.gif-sheet-attribution {
    flex: none;
    margin: 8px 0 0;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: #4a5568;
}

/* Desktop: the same element becomes a centred card */
@media (min-width: 769px) {
    #gifSheet {
        left: 50%;
        right: auto;
        bottom: auto;
        top: 50%;
        width: 440px;
        max-width: calc(100vw - 32px);
        height: min(78vh, 600px);
        height: min(78dvh, 600px);
        border-radius: 20px;
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
        padding-bottom: 12px;
        transform: translate(-50%, -50%) scale(0.95);
        opacity: 0;
        transition: transform 0.2s ease-out, opacity 0.2s ease-out;
    }

    #gifSheet.is-open {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }

    /* the card has a fixed size, so there is nothing to expand */
    #gifSheet.is-expanded {
        height: min(78vh, 600px);
        height: min(78dvh, 600px);
    }

    .gif-sheet-expand {
        visibility: hidden;
    }

    /* behind a centred card a dim helps; the docked phone panel has none */
    #gifSheetOverlay {
        background: rgba(0, 0, 0, 0.35);
    }

    .gif-sheet-header {
        padding-top: 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #gifSheetOverlay,
    #gifSheet,
    #gifSheet.is-open,
    .gif-sheet-expand svg {
        transition: none;
    }
}

@media (prefers-reduced-motion: reduce) and (min-width: 769px) {
    #gifSheet,
    #gifSheet.is-open {
        transform: translate(-50%, -50%);
    }
}

/* --- A GIF inside a chat bubble ------------------------------------- */
.chat-bubble.has-gif {
    padding: 4px;
}

.chat-bubble.has-gif .chat-time {
    padding: 2px 6px 0;
}

.chat-gif {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 14px;
    background: #e9ecef;
}

.chat-gif-toggle {
    position: relative;
    display: block;
    padding: 0;
    border: none;
    background: none;
    border-radius: 14px;
    cursor: pointer;
    line-height: 0;
}

.chat-gif-toggle:focus-visible {
    outline: 2px solid #1E88E5;
    outline-offset: 2px;
}

/* Reduced motion: a still with a small play badge; tap to animate */
.chat-gif-toggle.is-still::after {
    content: "GIF";
    position: absolute;
    left: 8px;
    bottom: 8px;
    padding: 3px 7px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.72);
    color: #ffffff;
    font-size: 11px;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: 0.5px;
}

/* --- Tap a GIF to zoom ------------------------------------------------ */
.chat-gif-zoom {
    display: block;
    padding: 0;
    border: none;
    background: none;
    border-radius: 14px;
    cursor: zoom-in;
    line-height: 0;
    max-width: 100%;
}

.chat-gif-zoom:focus-visible,
.chat-gif-zoom-badge:focus-visible {
    outline: 2px solid #1E88E5;
    outline-offset: 2px;
}

/* Reduced motion: the picture itself plays/stops on tap, so zooming gets
   its own small button in the corner (a 44px touch target) */
.chat-gif-wrap {
    position: relative;
    display: block;
    max-width: 100%;
}

.chat-gif-zoom-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.62);
    cursor: zoom-in;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-gif-zoom-badge svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: #ffffff;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}

/* --- The zoom modal (gif-lightbox.js) --------------------------------- */
#gifLightbox {
    position: fixed;
    inset: 0;
    z-index: 10004;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 64px 12px 24px;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.88);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    cursor: zoom-out;
}

#gifLightbox.is-open {
    opacity: 1;
    visibility: visible;
}

.gif-lightbox-figure {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    min-height: 0;
    transform: scale(0.92);
    transition: transform 0.2s ease;
}

#gifLightbox.is-open .gif-lightbox-figure {
    transform: scale(1);
}

/* Big, but never wider than the screen or taller than ~75% of it; small
   GIFs are scaled up to a comfortable size and the aspect ratio is kept */
.gif-lightbox-img {
    display: block;
    width: min(92vw, 560px);
    height: auto;
    max-width: 100%;
    max-height: 75vh;
    max-height: 75dvh;
    object-fit: contain;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.gif-lightbox-img[hidden],
.gif-lightbox-missing[hidden],
.gif-lightbox-play[hidden] {
    display: none;
}

.gif-lightbox-missing {
    margin: 0;
    padding: 16px 20px;
    border-radius: 14px;
    background: #ffffff;
    color: #2d3748;
    font-size: 15px;
}

.gif-lightbox-close {
    position: absolute;
    top: max(12px, env(safe-area-inset-top, 0px));
    right: 12px;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: #ffffff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

.gif-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.28);
}

.gif-lightbox-play {
    min-height: 44px;
    padding: 0 22px;
    border: none;
    border-radius: 22px;
    background: #ffffff;
    color: #7B1FA2;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

.gif-lightbox-close:focus-visible,
.gif-lightbox-play:focus-visible {
    outline: 3px solid #1E88E5;
    outline-offset: 2px;
}

/* The page behind the modal does not scroll */
html.gif-lightbox-open,
html.gif-lightbox-open body {
    overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
    #gifLightbox,
    .gif-lightbox-figure {
        transition: none;
    }
}

/* A KLIPY GIF whose picture URL is still being looked up: a box of the final
   size (width + aspect-ratio are set inline), so the chat does not jump when
   the picture arrives. */
.chat-gif-slot {
    display: block;
    max-width: 100%;
    border-radius: 14px;
    background: linear-gradient(110deg, #e9ecef 30%, #f5f6f8 50%, #e9ecef 70%);
    background-size: 200% 100%;
    animation: gifSlotShimmer 1.4s linear infinite;
}

@keyframes gifSlotShimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
    .chat-gif-slot {
        animation: none;
    }
}

/* A GIF that could not be loaded right now: the note plus a retry button */
.chat-gif-failed {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
}

.chat-gif-retry {
    min-height: 44px;
    padding: 0 14px;
    border: 1px solid currentColor;
    border-radius: 22px;
    background: transparent;
    color: inherit !important;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.chat-gif-retry:focus-visible {
    outline: 2px solid #1E88E5;
    outline-offset: 2px;
}

.chat-gif-missing {
    font-size: 13px;
    padding: 6px 10px;
    color: #4a5568;
}

/* --- KLIPY tabs: GIF-y / Naklejki / Memy -------------------------------- */
.gif-sheet-tabs {
    position: relative;
    display: flex;
    flex: none;
    gap: 6px;
    margin: 0 0 8px;
    padding: 4px;
    border-radius: 24px;
    background: rgba(0, 0, 0, 0.05);
}

.gif-sheet-tabs[hidden],
.gif-sheet-tab[hidden] {
    display: none;
}

/* The purple pill under the selected tab; gif-picker.js moves it with
   transform / width, so it glides from one tab to the next */
.gif-sheet-tab-indicator {
    position: absolute;
    top: 4px;
    left: 0;
    height: 44px;
    width: 0;
    border-radius: 22px;
    background: #7B1FA2;
    box-shadow: 0 2px 6px rgba(123, 31, 162, 0.35);
    pointer-events: none;
}

.gif-sheet-tab {
    position: relative;
    z-index: 1;
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    padding: 0 8px;
    border: none;
    border-radius: 20px;
    background: transparent;
    color: #4a5568;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s ease, color 0.15s ease;
}

.gif-sheet-tab[aria-selected="true"] {
    color: #ffffff;   /* the indicator behind it provides the purple */
}

.gif-sheet-tab:focus-visible {
    outline: 2px solid #1E88E5;
    outline-offset: 2px;
}

/* --- Stickers are cut-outs with a transparent background ---------------- */
.gif-sheet-item.is-sticker,
.gif-sheet-preview-img.is-sticker {
    background-color: #f8f9fa;
    background-image:
        linear-gradient(45deg, #e9ecef 25%, transparent 25%, transparent 75%, #e9ecef 75%),
        linear-gradient(45deg, #e9ecef 25%, transparent 25%, transparent 75%, #e9ecef 75%);
    background-size: 16px 16px;
    background-position: 0 0, 8px 8px;
}

/* In the chat a sticker has no bubble around it */
.chat-bubble.has-sticker,
.chat-bubble.has-sticker.from-me,
.chat-bubble.has-sticker.from-them {
    background: transparent;
    box-shadow: none;
    border: none;
}

/* (the "from me" bubble forces white text with !important; a sticker has no
   purple behind it, so the time must be dark) */
.chat-bubble.has-sticker.from-me,
.chat-bubble.has-sticker.from-me *,
.chat-bubble.has-sticker .chat-time {
    color: #2d3748 !important;
}

.chat-gif-zoom.is-sticker .chat-gif,
.chat-gif-wrap.is-sticker .chat-gif {
    background: transparent;
}

@media (prefers-reduced-motion: reduce) {
    .gif-sheet-tab { transition: none; }
}

/* Page scrollbar under the cards: a 24px-tall touch target drawing a 10px bar;
   the thumb is one card wide and is moved by gif-picker.js */
.gif-sheet-pagebar {
    position: relative;
    flex: none;
    height: 24px;
    margin: 4px 4px 0;
    touch-action: none;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.gif-sheet-pagebar[hidden] {
    display: none;
}

.gif-sheet-pagebar::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 10px;
    transform: translateY(-50%);
    border-radius: 5px;
    background: #e9ecef;
    pointer-events: none;
}

.gif-sheet-pagethumb {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 0;
    touch-action: none;
    cursor: grab;
    will-change: transform;
}

.gif-sheet-pagethumb::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 10px;
    transform: translateY(-50%);
    border-radius: 5px;
    background: #7B1FA2;
}

.gif-sheet-pager.is-dragging ~ .gif-sheet-pagebar .gif-sheet-pagethumb {
    cursor: grabbing;
}
