/*
 * v26 reactions component — loaded globally by the v26 header.
 *
 * Why its own sheet (not base.css): the widget appears on every surface that
 * renders user content (posts, circle feeds, comments, the global messenger
 * popup), plus a "who reacted" dialog and a toast that live on <body>. It is
 * one component with one owner (documentation/reactions/01_plan.md §5.3);
 * keeping it beside base.css (like occasions.css) keeps base.css reviewable.
 *
 * Rules: colour only via theme tokens, structure via --s-* knobs, no
 * hardcoded fallbacks. Zero counts are hidden here ([data-count="0"]), never
 * omitted from the markup — Reactions.js only flips attributes.
 */

.s-react {
    --s-react-h: 2.25rem;
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--s-space-2);
    position: relative;
}

.s-react__main {
    position: relative;
    display: inline-flex;
    align-items: center;
}

/* Trigger: quick reaction, shows MY reaction when I have one */
.s-react__trigger {
    display: inline-flex;
    align-items: center;
    gap: var(--s-space-2);
    min-height: var(--s-react-h);
    padding: 0 var(--s-space-3);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-pill);
    background: var(--bg-primary);
    color: var(--text-secondary);
    font: inherit;
    font-size: var(--s-text-sm);
    cursor: pointer;
    transition: border-color var(--s-transition), background var(--s-transition), color var(--s-transition);
}
.s-react__trigger:hover {
    border-color: var(--brand-primary);
    color: var(--text-primary);
}
.s-react__trigger.is-active {
    border-color: var(--brand-primary);
    background: var(--brand-primary-subtle);
    color: var(--brand-primary);
}
.s-react__emoji {
    font-size: 1.125rem;
    line-height: 1;
}
.s-react__emoji.is-popping {
    animation: s-react-pop 280ms ease-out;
}
@keyframes s-react-pop {
    0%   { transform: scale(1); }
    45%  { transform: scale(1.35); }
    100% { transform: scale(1); }
}

/* "More reactions" — the keyboard/touch equivalent of hover */
.s-react__more {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--s-react-h);
    height: var(--s-react-h);
    margin-left: var(--s-space-1);
    border: 1px solid transparent;
    border-radius: 50%;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 1.125rem;
    cursor: pointer;
    transition: background var(--s-transition), color var(--s-transition);
}
.s-react__more:hover,
.s-react__more[aria-expanded="true"] {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

/* Picker tray */
.s-react__picker {
    position: absolute;
    bottom: calc(100% + var(--s-space-2));
    left: 0;
    z-index: 40;
    display: flex;
    gap: var(--s-space-1);
    padding: var(--s-space-1);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-pill);
    background: var(--bg-elevated);
    box-shadow: var(--shadow-lg);
}
.s-react__picker[hidden] {
    display: none;
}
.s-react__option {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border: 0;
    border-radius: 50%;
    background: transparent;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: transform var(--s-transition), background var(--s-transition);
}
.s-react__option:hover,
.s-react__option:focus-visible {
    transform: translateY(-3px) scale(1.15);
    background: var(--bg-secondary);
}
.s-react__option.is-active {
    background: var(--brand-primary-subtle);
    box-shadow: inset 0 0 0 2px var(--brand-primary);
}

/* Summary: top emoji + total; opens "who reacted" */
.s-react__summary {
    display: inline-flex;
    align-items: center;
    gap: var(--s-space-1);
    min-height: var(--s-react-h);
    padding: 0 var(--s-space-2);
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: var(--s-text-sm);
    cursor: pointer;
    transition: background var(--s-transition), color var(--s-transition);
}
.s-react__summary:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.s-react__summary[data-count="0"] {
    display: none;
}
.s-react__top {
    display: inline-flex;
}
.s-react__top-emoji {
    font-size: 1rem;
    line-height: 1;
}
.s-react__top-emoji + .s-react__top-emoji {
    margin-left: calc(var(--s-space-1) * -0.5);
}
.s-react__top-emoji[hidden] {
    display: none;
}

/* Variants */
.s-react--bar {
    --s-react-h: var(--s-control-h);
}
.s-react--bar .s-react__trigger {
    padding: 0 var(--s-space-4);
}

/* Messenger bubbles (partials/messaging-popup.php via MessagingManager.js):
   WhatsApp-like — chips under the bubble, the react button shows on
   hover/focus (always faintly on touch), picker opens on the bubble's side. */
.message-reactions {
    display: flex;
    margin-top: var(--s-space-1);
}
.message.sent .message-reactions {
    justify-content: flex-end;
}
.message-reactions .s-react {
    --s-react-h: 1.75rem;
    gap: var(--s-space-1);
}
.message-reactions .s-react__trigger {
    padding: 0 var(--s-space-2);
    border-color: transparent;
    background: transparent;
}
/* Even when active: the chip below already shows my reaction. */
.message-reactions .s-react__trigger,
.message-reactions .s-react__more {
    opacity: 0;
    transition: opacity var(--s-transition);
}
.message:hover .message-reactions .s-react__trigger,
.message:hover .message-reactions .s-react__more,
.message-reactions .s-react:focus-within .s-react__trigger,
.message-reactions .s-react:focus-within .s-react__more,
.message-reactions .s-react.is-picking .s-react__more {
    opacity: 1;
}
.message-reactions .s-react__summary {
    border: 1px solid var(--border-primary);
    background: var(--bg-primary);
}
.message.sent .message-reactions .s-react__picker {
    right: 0;
    left: auto;
}
@media (hover: none) {
    .message-reactions .s-react__trigger,
    .message-reactions .s-react__more {
        opacity: 0.6;
    }
}

/* Focus */
.s-react button:focus-visible,
.s-react-dialog button:focus-visible,
.s-react-dialog a:focus-visible {
    outline: 2px solid var(--brand-primary);
    outline-offset: 2px;
}

/* Touch: ≥44px targets (v26 contract) */
@media (pointer: coarse) {
    .s-react {
        --s-react-h: var(--s-control-h);
    }
    .s-react__option {
        width: var(--s-control-h);
        height: var(--s-control-h);
    }
}

/* "Who reacted" dialog (native <dialog>, built by Reactions.js) */
.s-react-dialog {
    width: min(28rem, calc(100vw - 2 * var(--s-gutter)));
    max-height: min(80vh, 36rem);
    margin: auto; /* core/reset.css zeroes the UA's centring margin */
    padding: 0;
    box-sizing: border-box;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    background: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: var(--shadow-xl);
}
.s-react-dialog[open] {
    display: flex;
    flex-direction: column;
}
.s-react-dialog::backdrop {
    background: var(--overlay);
}
.s-react-dialog__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-space-3);
    padding: var(--s-space-3) var(--s-space-4) var(--s-space-3) var(--s-space-5);
    border-bottom: 1px solid var(--border-primary);
}
.s-react-dialog__title {
    margin: 0;
    font-size: var(--s-h3);
}
.s-react-dialog__tabs {
    display: flex;
    gap: var(--s-space-2);
    padding: var(--s-space-3) var(--s-space-5) 0;
    overflow-x: auto;
}
.s-react-dialog__tabs[hidden] {
    display: none;
}
.s-react-dialog__tab {
    flex: none;
    min-height: 2.25rem;
    padding: 0 var(--s-space-3);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: var(--s-text-sm);
    cursor: pointer;
}
.s-react-dialog__tab[aria-selected="true"] {
    border-color: var(--brand-primary);
    background: var(--brand-primary-subtle);
    color: var(--brand-primary);
}
.s-react-dialog__list {
    flex: 1;
    margin: 0;
    padding: var(--s-space-2) var(--s-space-5);
    overflow-y: auto;
    list-style: none;
}
.s-react-dialog__row {
    display: flex;
    align-items: center;
    gap: var(--s-space-3);
    padding: var(--s-space-2) 0;
}
.s-react-dialog__avatar {
    width: 2.25rem;
    height: 2.25rem;
    flex: none;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg-secondary);
}
.s-react-dialog__name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    color: var(--text-primary);
    text-overflow: ellipsis;
    white-space: nowrap;
    text-decoration: none;
}
a.s-react-dialog__name:hover {
    text-decoration: underline;
}
.s-react-dialog__emoji {
    font-size: 1.25rem;
    line-height: 1;
}
.s-react-dialog__note,
.s-react-dialog__status {
    margin: 0;
    padding: 0 var(--s-space-5) var(--s-space-3);
}
.s-react-dialog__status:empty {
    display: none;
}
.s-react-dialog__foot {
    display: flex;
    justify-content: center;
    padding: 0 var(--s-space-5) var(--s-space-4);
}
.s-react-dialog__foot:has([hidden]:only-child) {
    display: none;
}
@media (max-width: 640px) {
    /* Bottom sheet on phones */
    .s-react-dialog {
        width: 100%;
        max-width: 100%;
        margin: auto 0 0;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    }
}

/* Toast (errors, sign-in prompt) */
.s-react-toast {
    position: fixed;
    left: 50%;
    bottom: var(--s-space-5);
    z-index: 1000;
    max-width: calc(100vw - 2 * var(--s-gutter));
    padding: var(--s-space-3) var(--s-space-4);
    border-radius: var(--radius-md);
    background: var(--text-primary);
    color: var(--bg-primary);
    box-shadow: var(--shadow-lg);
    font-size: var(--s-text-sm);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, var(--s-space-3));
    transition: opacity var(--s-transition), transform var(--s-transition);
}
.s-react-toast.is-visible {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, 0);
}
.s-react-toast a {
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
}

@media (prefers-reduced-motion: reduce) {
    .s-react__emoji.is-popping {
        animation: none;
    }
    .s-react__option:hover,
    .s-react__option:focus-visible {
        transform: none;
    }
}
