/* ============================================================================
   Чати CRM — стікери з Telegram: вибір стікера з вкладками наборів, додавання набору
   за посиланням, анімовані (TGS) і відеостікери (WEBM) у повідомленнях.
   Окремий файл поруч із chat.css; кольори й розміри — токени з app.css (світла й темна теми).
   ========================================================================= */

@layer components {

  /* ─────────────────────── Стікер у повідомленні ─────────────────────── */

  .stk-tgs { position: relative; display: inline-block; vertical-align: top; }
  .stk-tgs > svg { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
  .stk-tgs > .stk-poster { width: 100%; height: 100%; object-fit: contain; }
  .stk-tgs.is-live > .stk-poster { visibility: hidden; }
  .stk-poster--emoji { display: grid; place-items: center; font-size: 56px; line-height: 1; }
  .stk-video, .stk-img { display: block; object-fit: contain; background: transparent; }
  .stk-missing { display: grid; place-items: center; font-size: 40px; opacity: .45; border-radius: var(--r-md); background: var(--bg-sunken); }
  .cm-sticker.stk-missing { width: 96px; height: 96px; }
  /* Емодзі з наборів addemoji (100×100) — менші за стікери. */
  .cm-sticker.stk-small:not(.cm-sticker--sm) { width: 96px; height: 96px; }
  .cm-sticker--sm.stk-tgs .stk-poster--emoji { font-size: 32px; }

  /* ─────────────────────── Вибір стікера ─────────────────────── */

  .stk-backdrop { position: fixed; inset: 0; z-index: 24; }
  .stk-pop {
    position: absolute; left: 16px; bottom: calc(100% - 2px); z-index: 25;
    display: flex; flex-direction: column;
    width: min(440px, calc(100% - 32px));
    height: min(420px, 62vh);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--bg-elevated);
    box-shadow: var(--sh-lg);
    overflow: hidden;
    animation: page-in var(--d-fast) var(--e-out);
  }
  .stk-pop__body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 8px 4px; overscroll-behavior: contain; }
  .stk-pop__title { padding: 4px 6px 6px; font-size: var(--t-2xs); font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); }

  .stk-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px; }
  .stk-grid--emoji { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .stk-cell {
    position: relative; display: grid; place-items: center; min-width: 0;
    aspect-ratio: 1; padding: 6px;
    border-radius: var(--r-sm);
    transition: background var(--d-fast), transform var(--d-fast) var(--e-spring);
  }
  .stk-cell:hover, .stk-cell:focus-visible { background: var(--surface-hover); transform: scale(1.06); }
  .stk-cell:active { transform: scale(.94); }
  .stk-cell__img { width: 100%; height: 100%; min-width: 0; object-fit: contain; pointer-events: none; }
  .stk-cell--ghost { background: var(--bg-sunken); animation: stk-pulse 1.2s ease-in-out infinite; transform: scale(.82); }
  @keyframes stk-pulse { 50% { opacity: .45; } }

  .stk-head { display: flex; align-items: center; gap: 4px; padding: 2px 4px 8px 6px; }
  .stk-head__text { display: flex; flex-direction: column; min-width: 0; flex: 1; font-size: var(--t-sm); line-height: 1.3; }
  .stk-progress { height: 4px; margin: 0 6px 8px; border-radius: var(--r-full); background: var(--bg-sunken); overflow: hidden; }
  .stk-progress > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width var(--d-base) var(--e-out); }
  .stk-empty { padding: 32px 12px; text-align: center; color: var(--ink-3); font-size: var(--t-sm); }

  /* Вкладки наборів унизу — як у Telegram. */
  .stk-tabs {
    display: flex; gap: 2px; padding: 4px 6px;
    border-top: 1px solid var(--line);
    background: var(--bg-sunken);
    overflow-x: auto; scrollbar-width: none;
    flex-shrink: 0;
  }
  .stk-tabs::-webkit-scrollbar { display: none; }
  .stk-tab {
    display: grid; place-items: center; flex-shrink: 0;
    width: 36px; height: 36px; padding: 3px;
    border-radius: var(--r-sm);
    color: var(--ink-3);
    transition: background var(--d-fast), color var(--d-fast);
  }
  .stk-tab:hover { background: var(--surface-hover); color: var(--ink); }
  .stk-tab.is-active { background: var(--accent-soft); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent-line); }
  .stk-tab.is-loading { animation: stk-pulse 1.2s ease-in-out infinite; }
  .stk-tab__img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
  .stk-tab--add { margin-left: auto; position: sticky; right: 0; background: var(--bg-sunken); }
  .stk-tab--add:hover { background: var(--surface-hover); }

  /* ─────────────────────── Додати набір з Telegram ─────────────────────── */

  .stk-add { display: flex; flex-direction: column; gap: 8px; padding: 4px 4px 8px; }
  .stk-add__title { display: flex; align-items: center; gap: 6px; font-weight: 650; font-size: var(--t-md); }
  .stk-add__hint { margin: 0; color: var(--ink-3); font-size: var(--t-sm); line-height: 1.45; }
  .stk-add__form { display: flex; gap: 6px; }
  .stk-add__form .input { flex: 1; min-width: 0; }
  .stk-add__warn, .stk-add__error {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
    padding: 8px 10px; border-radius: var(--r-sm);
    font-size: var(--t-sm); line-height: 1.4;
  }
  .stk-add__warn { background: var(--warn-soft); color: var(--ink-2); }
  .stk-add__error { margin: 0 2px 8px; background: var(--danger-soft); color: var(--danger); }
  .stk-add .stk-add__error { margin: 0; }

  .stk-sets { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
  .stk-sets__row { display: flex; align-items: center; gap: 4px; border-radius: var(--r-sm); }
  .stk-sets__row:hover { background: var(--surface-hover); }
  .stk-sets__open { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 6px; text-align: left; }
  .stk-sets__cover { display: grid; place-items: center; width: 40px; height: 40px; flex-shrink: 0; border-radius: var(--r-sm); background: var(--bg-sunken); }
  .stk-sets__img { width: 34px; height: 34px; object-fit: contain; }
  .stk-sets__text { display: flex; flex-direction: column; min-width: 0; font-size: var(--t-sm); line-height: 1.35; }

  @media (max-width: 640px) {
    .stk-pop { left: 8px; width: calc(100% - 16px); height: min(380px, 56vh); }
    .stk-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .stk-grid--emoji { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  }

  @media (prefers-reduced-motion: reduce) {
    .stk-cell--ghost, .stk-tab.is-loading { animation: none; }
  }
}
