/* =============================================================================
   CHAT — /chat (Components/Pages/Messages/ChatPage.razor), the nav-bar Messages icon and toast.
   Uses the site's colour tokens, so light and dark themes both work.
   ============================================================================= */

a.a88-navbar-circle-link {
    text-decoration: none;
}

/* ── Layout: inbox on the left, conversation on the right ─────────────────── */

.a88-chat {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    height: calc(100vh - var(--a88-header-h) - 36px);
    height: calc(100dvh - var(--a88-header-h) - 36px);
    min-height: 440px;
    background: var(--a88-surface);
    border: 1px solid var(--a88-line);
    border-radius: var(--a88-radius-lg);
    overflow: hidden;
}

.a88-chat-list {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-right: 1px solid var(--a88-line);
}

.a88-chat-list-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .9rem 1rem .4rem;
}

    .a88-chat-list-head h2 {
        margin: 0;
        font-family: var(--a88-font-display);
        font-size: 1.4rem;
    }

.a88-chat-search,
.a88-chat-new {
    padding: .4rem 1rem .6rem;
}

.a88-chat-rows,
.a88-chat-people {
    overflow-y: auto;
    min-height: 0;
}

.a88-chat-rows {
    flex: 1;
}

.a88-chat-people {
    max-height: 260px;
    margin-top: .4rem;
}

.a88-chat-hint {
    padding: 1rem;
    color: var(--a88-text-muted);
    font-size: .9rem;
}

    .a88-chat-hint.centered {
        text-align: center;
        margin: auto;
    }

.a88-chat-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    width: 100%;
    padding: .65rem 1rem;
    background: none;
    border: none;
    text-align: left;
    color: var(--a88-text);
    text-decoration: none;
    cursor: pointer;
}

    .a88-chat-row:hover {
        background: var(--a88-surface-alt);
        color: var(--a88-text);
    }

    .a88-chat-row.active {
        background: rgba(var(--a88-accent-rgb), .12);
    }

.a88-chat-row-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: .15rem;
}

.a88-chat-row-top, .a88-chat-row-bottom {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-width: 0;
}

.a88-chat-row-name {
    flex: 1;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.a88-chat-row-time {
    font-size: .75rem;
    color: var(--a88-text-muted);
    flex: none;
}

.a88-chat-row-preview {
    flex: 1;
    font-size: .85rem;
    color: var(--a88-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.a88-chat-muted {
    font-size: .8rem;
    flex: none;
}

.a88-chat-row.unread .a88-chat-row-name,
.a88-chat-row.unread .a88-chat-row-preview {
    color: var(--a88-text);
    font-weight: 700;
}

.a88-chat-row.unread .a88-chat-row-time {
    color: var(--a88-accent);
    font-weight: 700;
}

.a88-chat-unread {
    flex: none;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--a88-accent);
    color: #fff;
    font-size: .72rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ── Avatar ───────────────────────────────────────────────────────────────── */

.a88-chat-av {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 44px;
    flex: none;
}

    .a88-chat-av.lg {
        width: 56px;
        height: 56px;
    }

    .a88-chat-av img,
    .a88-chat-av-initial {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        object-fit: cover;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        font-weight: 700;
    }

.a88-chat-av-dot {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #2fbf71;
    border: 2px solid var(--a88-surface);
}

/* ── Thread ───────────────────────────────────────────────────────────────── */

.a88-chat-thread {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--a88-bg);
}

.a88-chat-empty {
    margin: auto;
    padding: 2rem;
    text-align: center;
    color: var(--a88-text-muted);
}

.a88-chat-empty-icon {
    font-size: 3rem;
    margin-bottom: .5rem;
}

.a88-chat-empty h3 {
    color: var(--a88-text);
    font-family: var(--a88-font-display);
}

.a88-chat-thread-head {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .6rem .9rem;
    background: var(--a88-surface);
    border-bottom: 1px solid var(--a88-line);
}

.a88-chat-back {
    display: none;
    font-size: 1.8rem;
    line-height: 1;
    padding: 0 .4rem;
    color: var(--a88-text);
    text-decoration: none;
}

.a88-chat-thread-who {
    display: flex;
    align-items: center;
    gap: .7rem;
    flex: 1;
    min-width: 0;
    color: var(--a88-text);
    text-decoration: none;
}

.a88-chat-thread-name {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}

    .a88-chat-thread-name strong {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .a88-chat-thread-name small {
        color: var(--a88-text-muted);
        min-height: 1.1em;
    }

        .a88-chat-thread-name small.live {
            color: #1f9d5b;
            font-weight: 600;
        }

.a88-chat-iconbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex: none;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--a88-text);
    font-size: 1.25rem;
    cursor: pointer;
}

    .a88-chat-iconbtn:hover {
        background: var(--a88-surface-alt);
    }

.a88-chat-menu-wrap {
    position: relative;
}

.a88-chat-menu {
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 1000;
    min-width: 220px;
    padding: .35rem;
    background: var(--a88-surface);
    border: 1px solid var(--a88-line);
    border-radius: 12px;
    box-shadow: var(--a88-shadow-lg);
}

    .a88-chat-menu a,
    .a88-chat-menu button {
        display: block;
        width: 100%;
        padding: .55rem .75rem;
        border: none;
        border-radius: 8px;
        background: none;
        text-align: left;
        color: var(--a88-text);
        text-decoration: none;
        font-size: .92rem;
        cursor: pointer;
    }

        .a88-chat-menu a:hover,
        .a88-chat-menu button:hover {
            background: var(--a88-surface-alt);
        }

    .a88-chat-menu .danger {
        color: #c62828;
    }

/* ── Messages ─────────────────────────────────────────────────────────────── */

.a88-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 2.4rem 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.a88-chat-older {
    text-align: center;
    margin-bottom: .6rem;
}

.a88-chat-day {
    text-align: center;
    margin: .8rem 0 .4rem;
}

    .a88-chat-day span {
        display: inline-block;
        padding: .15rem .7rem;
        border-radius: 999px;
        background: var(--a88-surface-2);
        color: var(--a88-text-muted);
        font-size: .75rem;
        font-weight: 600;
    }

.a88-chat-msg {
    position: relative;
    display: flex;
    flex-direction: column;
    max-width: 100%;
}

    .a88-chat-msg.mine {
        align-items: flex-end;
    }

    .a88-chat-msg.theirs {
        align-items: flex-start;
    }

.a88-chat-bubble {
    max-width: min(78%, 520px);
    padding: .45rem .7rem .3rem;
    border-radius: 16px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    cursor: pointer;
}

.a88-chat-msg.mine .a88-chat-bubble {
    background: var(--a88-accent);
    color: #fff;
    border-bottom-right-radius: 5px;
}

.a88-chat-msg.theirs .a88-chat-bubble {
    background: var(--a88-surface);
    color: var(--a88-text);
    border: 1px solid var(--a88-line);
    border-bottom-left-radius: 5px;
}

.a88-chat-bubble.deleted {
    background: transparent !important;
    border: 1px dashed var(--a88-line) !important;
    color: var(--a88-text-muted) !important;
}

.a88-chat-deleted-text {
    font-style: italic;
    font-size: .88rem;
}

.a88-chat-text {
    white-space: pre-wrap;
}

    .a88-chat-text.emoji-only {
        font-size: 2.1rem;
        line-height: 1.2;
    }

.a88-chat-photo {
    display: block;
    max-width: 260px;
    width: 100%;
    max-height: 320px;
    margin-bottom: .3rem;
    border-radius: 10px;
    object-fit: cover;
    cursor: zoom-in;
}

.a88-chat-quote {
    display: flex;
    flex-direction: column;
    margin-bottom: .35rem;
    padding: .25rem .5rem;
    border-left: 3px solid var(--a88-gold);
    border-radius: 6px;
    background: rgba(0, 0, 0, .10);
    font-size: .8rem;
}

    .a88-chat-quote span {
        opacity: .85;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 280px;
    }

.a88-chat-meta {
    display: block;
    margin-top: 2px;
    text-align: right;
    font-size: .68rem;
    opacity: .75;
    white-space: nowrap;
}

/* Ticks: one grey = sent, two grey = delivered, two blue = seen */
.a88-tick {
    display: inline-block;
    margin-left: 3px;
    line-height: 1;
}

    .a88-tick svg {
        width: 16px;
        height: 10px;
        fill: none;
        stroke: currentColor;
        stroke-width: 1.6;
        stroke-linecap: round;
        stroke-linejoin: round;
        vertical-align: middle;
    }

    .a88-tick.pending {
        font-size: .65rem;
    }

    .a88-tick.read {
        color: #8fe3ff;
        opacity: 1;
    }

.a88-chat-msg.mine .a88-chat-meta:has(.a88-tick.read) {
    opacity: 1;
}

.a88-chat-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.a88-chat-reaction {
    padding: 0 .4rem;
    border: 1px solid var(--a88-line);
    border-radius: 999px;
    background: var(--a88-surface);
    color: var(--a88-text);
    font-size: .8rem;
    line-height: 1.5;
    cursor: pointer;
}

    .a88-chat-reaction.mine {
        border-color: var(--a88-accent);
        background: rgba(var(--a88-accent-rgb), .15);
    }

/* Action bar: appears on hover (mouse) or when the bubble is tapped (touch) */
.a88-chat-actions {
    display: none;
    position: absolute;
    bottom: calc(100% - 8px);
    z-index: 3;
    padding: 3px;
    gap: 1px;
    background: var(--a88-surface);
    border: 1px solid var(--a88-line);
    border-radius: 999px;
    box-shadow: var(--a88-shadow-sm);
    white-space: nowrap;
}

.a88-chat-msg.mine .a88-chat-actions {
    right: 0;
}

.a88-chat-msg.theirs .a88-chat-actions {
    left: 0;
}

.a88-chat-msg.active .a88-chat-actions {
    display: flex;
}

@media (hover: hover) {
    .a88-chat-msg:hover .a88-chat-actions {
        display: flex;
    }
}

.a88-chat-react-btn,
.a88-chat-act {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--a88-text);
    font-size: 1rem;
    cursor: pointer;
}

    .a88-chat-react-btn:hover,
    .a88-chat-act:hover {
        background: var(--a88-surface-alt);
    }

    .a88-chat-act.danger:hover {
        background: #fdecea;
    }

/* ── Composer ─────────────────────────────────────────────────────────────── */

.a88-chat-composer {
    display: flex;
    align-items: flex-end;
    gap: .35rem;
    padding: .6rem .7rem;
    background: var(--a88-surface);
    border-top: 1px solid var(--a88-line);
}

.a88-chat-input {
    flex: 1;
    min-width: 0;
    max-height: 140px;
    padding: .55rem .9rem;
    border: 1px solid var(--a88-line);
    border-radius: 20px;
    background: var(--a88-bg);
    color: var(--a88-text);
    font: inherit;
    resize: none;
    outline: none;
}

    .a88-chat-input:focus {
        border-color: var(--a88-accent);
    }

.a88-chat-send {
    flex: none;
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: var(--a88-gold);
    color: var(--a88-on-gold);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity .15s ease;
}

    .a88-chat-send svg {
        width: 20px;
        height: 20px;
        fill: none;
        stroke: currentColor;
        stroke-width: 2;
        stroke-linejoin: round;
    }

.a88-chat-input:placeholder-shown ~ .a88-chat-send {
    opacity: .6;
}

.a88-chat-replybar,
.a88-chat-attach,
.a88-chat-error,
.a88-chat-blocked {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .5rem .9rem;
    background: var(--a88-surface);
    border-top: 1px solid var(--a88-line);
    font-size: .88rem;
}

    .a88-chat-replybar > div {
        display: flex;
        flex-direction: column;
        min-width: 0;
        border-left: 3px solid var(--a88-gold);
        padding-left: .6rem;
    }

    .a88-chat-replybar span {
        color: var(--a88-text-muted);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .a88-chat-replybar button,
    .a88-chat-attach button,
    .a88-chat-error button {
        border: none;
        background: none;
        color: var(--a88-text-muted);
        font-size: 1rem;
        cursor: pointer;
    }

.a88-chat-attach {
    justify-content: flex-start;
}

    .a88-chat-attach img {
        height: 72px;
        max-width: 160px;
        border-radius: 10px;
        object-fit: cover;
    }

    .a88-chat-attach button {
        margin-left: auto;
    }

.a88-chat-error {
    background: #fdecea;
    color: #611a15;
}

.a88-chat-blocked {
    justify-content: center;
    color: var(--a88-text-muted);
}

/* ── Emoji picker ─────────────────────────────────────────────────────────── */

.a88-chat-emoji-wrap {
    position: relative;
    height: 0;
}

    .a88-chat-emoji-wrap .a88-emoji-picker {
        position: absolute;
        left: .7rem;
        bottom: .5rem;
        z-index: 6;
    }

.a88-emoji-picker {
    width: min(340px, calc(100vw - 2rem));
    background: var(--a88-surface);
    border: 1px solid var(--a88-line);
    border-radius: 14px;
    box-shadow: var(--a88-shadow-lg);
    overflow: hidden;
}

.a88-emoji-tabs {
    display: flex;
    border-bottom: 1px solid var(--a88-line);
    background: var(--a88-surface-alt);
}

.a88-emoji-tab {
    flex: 1;
    padding: .4rem 0;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    font-size: 1.15rem;
    cursor: pointer;
}

    .a88-emoji-tab.active {
        border-bottom-color: var(--a88-accent);
        background: var(--a88-surface);
    }

.a88-emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    max-height: 220px;
    overflow-y: auto;
    padding: .4rem;
}

.a88-emoji-btn {
    padding: .2rem 0;
    border: none;
    border-radius: 8px;
    background: none;
    font-size: 1.4rem;
    line-height: 1.3;
    cursor: pointer;
}

    .a88-emoji-btn:hover {
        background: var(--a88-surface-alt);
    }

/* ── Toast: a message arrived while you are on another page ───────────────── */

.a88-chat-toast {
    position: fixed;
    right: 1.2rem;
    bottom: 1.2rem;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    gap: .15rem;
    max-width: 320px;
    padding: .7rem 1rem;
    border: 1px solid var(--a88-line);
    border-left: 4px solid var(--a88-accent);
    border-radius: 12px;
    background: var(--a88-surface);
    color: var(--a88-text);
    text-align: left;
    box-shadow: var(--a88-shadow-lg);
    cursor: pointer;
}

    .a88-chat-toast span {
        color: var(--a88-text-muted);
        font-size: .88rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

/* Directory card: secondary look for the Message button */
.a88-dir-message {
    background: transparent !important;
    color: var(--a88-accent) !important;
    border: 1.5px solid var(--a88-accent) !important;
}

    .a88-dir-message:hover {
        background: rgba(var(--a88-accent-rgb), .1) !important;
    }

/* ── Group & event chats ─────────────────────────────────────────────────────────────── */

/* Header "who" can be a <button> (group chat opens the members panel): reset the button look. */
button.a88-chat-thread-who {
    background: none;
    border: 0;
    padding: 0;
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.a88-chat-av-icon {
    font-size: 1.1em;
}

/* Name above a message from someone else in a group / event chat */
.a88-chat-sender {
    display: block;
    font-size: .78rem;
    font-weight: 700;
    margin-bottom: .1rem;
}

/* New chat panel: Message | New group tabs, group name, picked people */
.a88-chat-tabs {
    display: flex;
    gap: .4rem;
    margin-bottom: .5rem;
}

    .a88-chat-tabs button {
        flex: 1;
        padding: .35rem .5rem;
        border: 1px solid var(--a88-line);
        border-radius: 999px;
        background: transparent;
        color: var(--a88-text-muted);
        font-size: .85rem;
        font-weight: 600;
        cursor: pointer;
    }

        .a88-chat-tabs button.active {
            background: var(--a88-accent);
            border-color: var(--a88-accent);
            color: #fff;
        }

.a88-chat-new > input {
    margin-bottom: .4rem;
}

.a88-chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .3rem;
    margin-bottom: .4rem;
}

.a88-chat-chip {
    border: 1px solid var(--a88-accent);
    background: rgba(var(--a88-accent-rgb), .1);
    color: var(--a88-accent);
    border-radius: 999px;
    padding: .15rem .6rem;
    font-size: .8rem;
    cursor: pointer;
}

/* Members panel */
.a88-chat-members {
    max-width: 440px;
}

.a88-chat-members-rename {
    display: flex;
    gap: .5rem;
    margin-bottom: .75rem;
}

.a88-chat-member-list {
    max-height: 260px;
    overflow-y: auto;
}

.a88-chat-member {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .35rem 0;
}

.a88-chat-member-name {
    flex: 1;
    min-width: 0;
    color: var(--a88-text);
    text-decoration: none;
    font-weight: 600;
}

.a88-chat-members-add {
    margin-top: .75rem;
}

    .a88-chat-members-add > input {
        margin-bottom: .4rem;
    }

/* "Message seller" (listing page, order page) and "Event chat" (event page) */
.a88-mkt-message-seller,
.a88-event-chat-btn {
    display: block;
    text-align: center;
    width: 100%;
    text-decoration: none;
}

.a88-mkt-message-seller {
    margin-top: .5rem;
}

.a88-event-chat-btn {
    margin-bottom: .75rem;
}

.a88-event-chat-hint {
    color: var(--a88-text-muted);
    font-size: .85rem;
    margin: 0 0 .75rem;
}

/* Marketplace listing card inside a message / above the composer */
.a88-chat-listing {
    display: flex;
    align-items: center;
    gap: .6rem;
    min-width: 220px;
    max-width: 100%;
    margin-bottom: .35rem;
    padding: .4rem;
    border-radius: 10px;
    background: rgba(0, 0, 0, .06);
    color: inherit;
    text-decoration: none;
}

    .a88-chat-listing img,
    .a88-chat-listing-noimg {
        width: 52px;
        height: 52px;
        flex-shrink: 0;
        border-radius: 8px;
        object-fit: cover;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(0, 0, 0, .08);
        font-size: 1.4rem;
    }

.a88-chat-listing-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    font-size: .85rem;
}

    .a88-chat-listing-text strong {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

.a88-chat-listing.gone {
    font-size: .85rem;
    opacity: .8;
}

.a88-chat-attach-listing {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .4rem 1rem;
}

    .a88-chat-attach-listing .a88-chat-listing {
        flex: 1;
        margin: 0;
        background: var(--a88-bg-soft, rgba(0, 0, 0, .05));
    }

/* ── Loading skeletons (Shared/LoadingSkeleton.razor: chatlist, chatthread) ─────────────── */
.a88-chat-thread > .a88-skel-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.a88-chat-skel-list {
    padding: .25rem 0;
}

.a88-chat-skel-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .7rem 1rem;
}

.a88-chat-skel-av {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    flex-shrink: 0;
}

.a88-chat-skel-lines {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: .45rem;
}

.a88-chat-skel-thread {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 360px;
}

.a88-chat-skel-head {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .8rem 1rem;
    border-bottom: 1px solid var(--a88-line);
}

.a88-chat-skel-msgs {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: .7rem;
    padding: 1.2rem 1rem;
}

.a88-chat-skel-bubble {
    height: 44px;
    border-radius: 16px;
}

    .a88-chat-skel-bubble.left {
        align-self: flex-start;
    }

    .a88-chat-skel-bubble.right {
        align-self: flex-end;
    }

.a88-chat-skel-composer {
    padding: .7rem 1rem;
    border-top: 1px solid var(--a88-line);
}

    .a88-chat-skel-composer > div {
        height: 42px;
        border-radius: 999px;
    }

/* ── Phones: one pane at a time; the page sits between the header and the bottom tab bar ── */

@media (max-width: 767.98px) {
    .a88-chat {
        grid-template-columns: 1fr;
        height: calc(100dvh - var(--a88-header-h) - 64px - 36px - env(safe-area-inset-bottom, 0px));
        border-radius: var(--a88-radius);
    }

        .a88-chat .a88-chat-thread {
            display: none;
        }

        .a88-chat.has-thread .a88-chat-list {
            display: none;
        }

        .a88-chat.has-thread .a88-chat-thread {
            display: flex;
        }

    .a88-chat-list {
        border-right: none;
    }

    .a88-chat-back {
        display: block;
    }

    .a88-chat-bubble {
        max-width: 86%;
    }

    .a88-chat-toast {
        bottom: calc(64px + 1rem + env(safe-area-inset-bottom, 0px));
        left: 1rem;
        right: 1rem;
        max-width: none;
    }
}
