/* ============================================================
   JinnChat — Chat Page Stylesheet
   ============================================================ */

/* ── Chat layout ─────────────────────────────────────────────── */
.chat-page {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: fixed;
    top: var(--app-top, 0px);
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--app-height, 100dvh);
    width: 100%;
}

/* ── Chat header ─────────────────────────────────────────────── */
.chat-header {
    position: relative;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: rgba(6, 6, 15, 0.85);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    height: 56px;
}

.chat-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-head);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
}

.chat-logo span:first-child {
    font-size: 1.3rem;
}

.chat-header-center {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-dim);
}

#partner-status .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.online {
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
}

.status-dot.offline {
    background: var(--red);
    box-shadow: 0 0 8px var(--red);
}

.status-dot.waiting {
    background: var(--amber);
    box-shadow: 0 0 8px var(--amber);
    animation: pulse 1.5s infinite;
}

.chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50px;
    font-size: 0.8rem;
    white-space: nowrap;
}

.star-chip {
    background: rgba(245, 158, 11, 0.15);
    color: var(--amber);
    border-radius: 20px;
    padding: 1px 6px;
    font-size: 0.72rem;
}

.btn-ghost-xs,
.btn-primary-xs {
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all .2s;
    border: none;
}

.btn-ghost-xs {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
}

.btn-ghost-xs:hover {
    border-color: var(--purple);
    color: var(--text);
}

.btn-primary-xs {
    background: var(--purple-g);
    color: #fff;
}

.btn-primary-xs:hover {
    color: #fff;
}

/* ── Char bar ────────────────────────────────────────────────── */
.char-bar-wrap {
    position: relative;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 20px;
    background: rgba(6, 6, 15, 0.7);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.char-bar-track {
    flex: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    overflow: hidden;
}

.char-bar-fill {
    height: 100%;
    border-radius: 2px;
    background: var(--purple-g);
    transition: width .5s ease, background .5s;
    box-shadow: 0 0 8px rgba(168, 85, 247, 0.6);
}

.char-bar-fill.warning {
    background: linear-gradient(135deg, var(--amber), var(--red));
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}

.char-bar-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 100px;
    text-align: right;
}

/* ── Stages ──────────────────────────────────────────────────── */
.stage {
    flex: 1;
    display: flex;
    /* JS sets display:flex when showing, not display:block */
    flex-direction: column;
    position: relative;
    z-index: 1;
    overflow: hidden;
    min-height: 0;
    /* critical: allows flex children to shrink below content size */
}

/* ── Search / waiting ────────────────────────────────────────── */
#stage-search {
    align-items: center;
    justify-content: center;
    text-align: center;
}

.search-content {
    padding: 40px 20px;
}

.radar-ring {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    border: 2px solid rgba(168, 85, 247, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin: 0 auto 28px;
}

.radar-ring::before,
.radar-ring::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    border: 2px solid rgba(168, 85, 247, 0.15);
    pointer-events: none;
}

.radar-ring::before {
    inset: -22px;
}

.radar-ring::after {
    inset: -44px;
}

.radar-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--purple);
    pointer-events: none;
    animation: radarPulse 2s ease-out infinite;
}

@keyframes radarPulse {
    0% {
        transform: scale(0.8);
        opacity: 1;
    }

    100% {
        transform: scale(1.6);
        opacity: 0;
    }
}

.radar-ghost {
    font-size: 2.4rem;
    animation: float 3s ease-in-out infinite;
    position: relative;
    z-index: 1;
}

.search-title {
    font-family: var(--font-head);
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--purple-g);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
}

.search-sub {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ── Chat window ─────────────────────────────────────────────── */
#stage-chat {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    /* allows inner flex children to scroll */
}

.chat-window {
    padding-bottom: 80px !important;
    flex: 1;
    min-height: 0;
    /* critical: allows overflow-y scroll within flex */
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overscroll-behavior: contain;
    align-items: center;
    /* Center the messages wrapper */
}

.messages-area {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 900px;
    /* Constrain width of messages on laptop */
    gap: 8px;
    /* space between messages */
}

/* ── Message bubbles ─────────────────────────────────────────── */
.message {
    display: flex;
    flex-direction: column;
    max-width: 72%;
    animation: msgSlideIn .25s ease;
}

@keyframes msgSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.mine {
    align-self: flex-end;
    align-items: flex-end;
}

.message.theirs {
    align-self: flex-start;
    align-items: flex-start;
}

.message.system {
    align-self: center;
    align-items: center;
    max-width: 90%;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.93rem;
    line-height: 1.5;
    word-break: break-word;
    position: relative;
    font-family: var(--font-body), var(--font-emoji);
}

.mine .message-bubble {
    background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 12px rgba(168, 85, 247, 0.3);
}

.theirs .message-bubble {
    background: var(--surface-h);
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.system .message-bubble {
    background: rgba(6, 182, 212, 0.08);
    border: 1px solid rgba(6, 182, 212, 0.2);
    color: var(--cyan);
    font-size: 0.82rem;
    border-radius: 50px;
    padding: 6px 16px;
    text-align: center;
    font-style: italic;
}

/* Sticker messages */
.message-bubble.sticker {
    background: transparent;
    border: none;
    font-size: 3.5rem;
    padding: 4px;
    font-family: var(--font-emoji);
    line-height: 1.1;
}

.mine .message-bubble.sticker {
    box-shadow: none;
}

.theirs .message-bubble.sticker {
    border: none;
}

.message-time {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 3px;
    padding: 0 4px;
}

/* ── Message wrapper (holds bubble + menu) ───────────────────── */
.msg-wrapper {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 4px;
}

.mine .msg-wrapper {
    flex-direction: row-reverse;
}

.msg-content-wrap {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ── Three-dot menu button ───────────────────────────────────── */
.msg-menu-btn {
    opacity: 0;
    width: 24px;
    height: 24px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity .15s, background .15s;
    margin-top: 4px;
}

.message:hover .msg-menu-btn {
    opacity: 1;
}

.msg-menu-btn:hover {
    background: var(--surface-h);
    color: var(--text);
}

/* ── Context menu ────────────────────────────────────────────── */
.msg-context-menu {
    position: absolute;
    top: 0;
    z-index: 80;
    display: flex;
    flex-direction: column;
    min-width: 130px;
    background: rgba(13, 13, 26, 0.97);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    padding: 4px;
    animation: ctxIn .12s ease;
}

.mine .msg-context-menu {
    right: 100%;
    margin-right: 4px;
}

.theirs .msg-context-menu {
    left: 100%;
    margin-left: 4px;
}

@keyframes ctxIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.82rem;
    cursor: pointer;
    border-radius: 6px;
    white-space: nowrap;
    transition: all .15s;
}

.ctx-item:hover {
    background: var(--surface-h);
    color: var(--text);
}

.ctx-item .fa-flag {
    color: var(--red);
}

.ctx-item .fa-reply {
    color: var(--cyan);
}

.ctx-item .fa-face-smile {
    color: var(--amber);
}

.ctx-item .fa-rotate-left {
    color: var(--text-muted);
}

/* ── Unsent messages ─────────────────────────────────────────── */
.message.unsent .unsent-bubble {
    background: transparent !important;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.84rem;
    box-shadow: none;
}

/* ── Reaction picker ─────────────────────────────────────────── */
.reaction-picker {
    position: absolute;
    bottom: 100%;
    z-index: 85;
    display: flex;
    gap: 2px;
    padding: 6px 8px;
    background: rgba(13, 13, 26, 0.97);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    animation: ctxIn .15s ease;
    margin-bottom: 6px;
}

.mine .reaction-picker {
    right: 0;
}

.theirs .reaction-picker {
    left: 0;
}

.reaction-emoji-btn {
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
    font-family: var(--font-emoji);
    line-height: 1;
}

.reaction-emoji-btn:hover {
    background: var(--surface-h);
    transform: scale(1.3);
}

/* ── Reaction badges on messages ─────────────────────────────── */
.msg-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 2px;
    padding: 0 4px;
}

.reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 7px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all .15s;
    font-family: var(--font-emoji), var(--font-body);
    line-height: 1.3;
}

.reaction-badge:hover {
    background: var(--surface-h);
    border-color: var(--purple);
}

.reaction-badge.mine {
    border-color: rgba(168, 85, 247, 0.4);
    background: rgba(168, 85, 247, 0.1);
}

/* ── Reply preview inside message bubble ─────────────────────── */
.reply-preview {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 6px 10px;
    margin-bottom: 4px;
    background: rgba(255, 255, 255, 0.05);
    border-left: 3px solid var(--purple);
    border-radius: 4px 8px 8px 4px;
    cursor: pointer;
    font-size: 0.78rem;
    line-height: 1.3;
    max-width: 100%;
    transition: background .15s;
}

.reply-preview:hover {
    background: rgba(255, 255, 255, 0.08);
}

.reply-sender {
    color: var(--purple);
    font-weight: 600;
    font-size: 0.72rem;
}

.reply-text {
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}

.mine .reply-preview {
    background: rgba(255, 255, 255, 0.12);
    border-left-color: rgba(255, 255, 255, 0.5);
}

.mine .reply-sender {
    color: rgba(255, 255, 255, 0.85);
}

.mine .reply-text {
    color: rgba(255, 255, 255, 0.7);
}

/* ── Reply bar above input ───────────────────────────────────── */
.reply-bar {
    width: 100%;
    max-width: 900px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: rgba(168, 85, 247, 0.06);
    border-top: 1px solid var(--border);
    border-left: 3px solid var(--purple);
    flex-shrink: 0;
}

.reply-bar-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.reply-bar-label {
    font-size: 0.75rem;
    color: var(--purple);
    font-weight: 600;
}

.reply-bar-text {
    font-size: 0.82rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reply-bar-close {
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
    flex-shrink: 0;
}

.reply-bar-close:hover {
    background: var(--surface-h);
    color: var(--text);
}

/* ── Message highlight (scroll to reply target) ──────────────── */
.msg-highlight {
    animation: msgHighlight 1.5s ease;
}

@keyframes msgHighlight {
    0% {
        background: rgba(168, 85, 247, 0.2);
        border-radius: 12px;
    }

    100% {
        background: transparent;
    }
}

/* ── Typing indicator ────────────────────────────────────────── */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 20px;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    flex-shrink: 0;
}

.typing-indicator span {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: .2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: .4s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-6px);
    }
}

/* ── Input bar ───────────────────────────────────────────────── */
.chat-input-bar {
    position: relative;
    width: 100%;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(6, 6, 15, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.chat-input-bar-inner {
    width: 100%;
    max-width: 900px;
    /* Match messages area constraint */
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-end;
    gap: 6px;
    padding: 8px 10px;
}

.msg-textarea {
    flex: 1;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.93rem;
    resize: none;
    outline: none;
    min-height: 38px;
    max-height: 100px;
    transition: border-color .2s;
    line-height: 1.4;
}

.msg-textarea:focus {
    border-color: var(--purple);
}

.msg-textarea::placeholder {
    color: var(--text-muted);
}

.input-action-btn {
    width: 38px;
    height: 38px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-dim);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
    flex-shrink: 0;
}

.input-action-btn:hover {
    background: var(--surface-h);
    border-color: var(--purple);
    color: var(--purple);
}

.btn-send {
    width: 38px;
    height: 38px;
    background: var(--purple-g);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all .2s;
    box-shadow: 0 0 12px rgba(168, 85, 247, 0.4);
}

.btn-send:hover {
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.6);
    transform: scale(1.05);
}

.btn-next-small {
    width: 38px;
    height: 38px;
    background: rgba(6, 182, 212, 0.1);
    border: 1px solid rgba(6, 182, 212, 0.3);
    border-radius: 10px;
    color: var(--cyan);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all .2s;
}

.btn-next-small:hover {
    background: rgba(6, 182, 212, 0.2);
    box-shadow: 0 0 12px rgba(6, 182, 212, 0.3);
}

.btn-report-session {
    color: rgba(239, 68, 68, 0.6);
    border-color: rgba(239, 68, 68, 0.2);
}

.btn-report-session:hover {
    color: var(--red);
    border-color: var(--red);
}

/* ── Emoji & Sticker pickers ─────────────────────────────────── */
.emoji-picker,
.sticker-picker {
    position: fixed;
    /* fixed so it doesn't depend on parent height */
    bottom: 70px;
    left: 14px;
    z-index: 60;
    background: rgba(13, 13, 26, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px;
}

.emoji-picker {
    width: 340px;
    max-height: 260px;
    overflow-y: auto;
}

.sticker-picker {
    width: 340px;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
}

.emoji-btn {
    font-size: 1.5rem;
    padding: 6px;
    background: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background .15s, transform .15s;
    text-align: center;
    font-family: var(--font-emoji);
    line-height: 1;
}

.emoji-btn:hover {
    background: var(--surface-h);
    transform: scale(1.3);
}

.sticker-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
}

.sticker-btn {
    font-size: 2.2rem;
    padding: 8px 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: all .2s;
    text-align: center;
    line-height: 1;
    font-family: var(--font-emoji);
}

.sticker-btn:hover {
    background: var(--surface-h);
    border-color: var(--purple);
    transform: scale(1.15);
    box-shadow: var(--glow-purple);
}

.sticker-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    display: block;
    text-align: center;
    margin-top: 2px;
}

/* ── End stage ───────────────────────────────────────────────── */
#stage-end {
    align-items: center;
    justify-content: center;
    text-align: center;
}

.end-content {
    padding: 40px 24px;
    max-width: 480px;
}

#end-ghost-anim {
    font-size: 4rem;
    display: block;
    margin-bottom: 20px;
    animation: ghostFadeOut 1.5s ease forwards, float 4s ease-in-out 1.5s infinite;
}

@keyframes ghostFadeOut {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.8);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.end-title {
    font-family: var(--font-head);
    font-size: 1.8rem;
    font-weight: 700;
    background: var(--purple-g);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
}

.end-sub {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 32px;
}

/* Star rating */
.rating-section {
    margin-bottom: 28px;
    padding: 20px 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.rating-prompt {
    font-size: 0.95rem;
    color: var(--text-dim);
    margin-bottom: 14px;
}

.rating-prompt strong {
    color: var(--purple);
}

.star-rating {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.star-rating .star {
    font-size: 2.2rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: color .15s, transform .15s;
    line-height: 1;
}

.star-rating .star:hover,
.star-rating .star.filled,
.star-rating .star.hover {
    color: var(--amber);
    transform: scale(1.2);
}

.rating-confirm {
    margin-top: 12px;
    color: var(--green);
    font-size: 0.875rem;
}

.end-actions {
    display: flex;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
}

/* ── Report modal ────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(6, 6, 15, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-card {
    width: 100%;
    max-width: 420px;
    padding: 28px 24px;
    animation: modalIn .25s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-title {
    font-family: var(--font-head);
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.modal-sub {
    color: var(--text-dim);
    font-size: 0.875rem;
    margin-bottom: 16px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.modal-actions .btn-auth,
.modal-actions .btn-ghost-outline {
    flex: 1;
    padding: 10px;
    justify-content: center;
}

.report-feedback {
    margin-top: 12px;
    font-size: 0.875rem;
    color: var(--green);
    text-align: center;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 600px) {

    /* Bulletproof Mobile Layout */
    html {
        overflow: hidden !important;
        height: 100% !important;
    }

    .chat-page {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        height: 100% !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    #stage-chat {
        flex: 1 1 0 !important;
        min-height: 0 !important;
        height: auto !important;
        overflow: visible !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .chat-window {
        flex: 1 1 0 !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        padding: 10px 12px;
        /* input bar: ~38px content + 8px top + env(safe-area-inset-bottom) bottom; add 80px buffer on top */
        padding-bottom: calc(env(safe-area-inset-bottom) + 80px) !important;
    }

    .chat-header {
        padding: 8px 12px;
        height: 48px;
        flex-shrink: 0;
    }

    .chat-logo .brand-name {
        display: none;
    }

    .chat-header-right .user-chip {
        display: none;
    }

    .message {
        max-width: 88%;
    }


    .chat-input-bar {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        flex-shrink: 0 !important;
        width: 100% !important;
        padding: 0 !important;
        background: rgba(6, 6, 15, 0.98) !important;
        z-index: 1000 !important;
        box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.4);
    }

    /* Hide input bar when chat stage is hidden */
    #stage-chat[style*="display: none"] .chat-input-bar,
    #stage-chat[style*="display:none"] .chat-input-bar {
        display: none !important;
    }

    .chat-input-bar-inner {
        display: grid !important;
        grid-template-columns: 38px 38px 1fr 38px 38px !important;
        gap: 4px !important;
        align-items: end !important;
        width: 100% !important;
        padding: 8px !important;
        padding-bottom: max(8px, env(safe-area-inset-bottom)) !important;
        box-sizing: border-box !important;
    }

    .chat-input-bar-inner .btn-send {
        width: 38px;
        height: 38px;
    }

    .chat-input-bar-inner .btn-next-small {
        width: 38px;
        height: 38px;
    }

    .chat-input-bar-inner .input-action-btn {
        width: 38px;
        height: 38px;
    }

    .chat-input-bar-inner .msg-textarea {
        width: 100% !important;
        min-width: 0 !important;
        padding: 7px 10px;
        font-size: 16px;
        /* prevent iOS auto-zoom on focus */
        min-height: 38px;
    }

    .chat-input-bar-inner .btn-report-session {
        display: none !important;
    }

    .emoji-picker {
        width: calc(100vw - 16px);
        left: 8px;
        bottom: 56px;
        max-height: 200px;
    }

    .sticker-picker {
        width: calc(100vw - 16px);
        left: 8px;
        bottom: 56px;
    }

    .sticker-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .end-content {
        padding: 30px 16px;
    }

    .end-title {
        font-size: 1.4rem;
    }

    .char-bar-wrap {
        padding: 4px 12px;
    }

    .msg-menu-btn {
        opacity: 0.5;
    }

    .mine .msg-context-menu,
    .theirs .msg-context-menu {
        z-index: 2000 !important;
        min-width: 160px;
    }

    .reaction-picker {
        position: fixed !important;
        left: 50% !important;
        bottom: 90px !important;
        transform: translateX(-50%) !important;
        right: auto !important;
        z-index: 2000 !important;
    }

    .mine .reaction-picker,
    .theirs .reaction-picker {
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
    }

    .reaction-emoji-btn {
        width: 36px;
        height: 36px;
        font-size: 1.3rem;
    }

    .reply-text {
        max-width: 160px;
    }
}

/* ── Optimistic send states ─────────────────────────────────── */
.message.sending .message-bubble {
    opacity: 0.65;
}

.message-time.sending-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-style: italic;
}

.sending-dots {
    display: inline-flex;
    gap: 2px;
    align-items: center;
}

.sending-dots span {
    display: inline-block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingBounce 1.2s ease-in-out infinite;
}

.sending-dots span:nth-child(1) {
    animation-delay: 0s;
}

.sending-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.sending-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

.message-time.sent-label {
    color: rgba(168, 85, 247, 0.7);
}

.message.mine.send-failed .message-bubble {
    background: linear-gradient(135deg, #7a3070 0%, #4a1a6a 100%) !important;
    box-shadow: 0 2px 12px rgba(239, 68, 68, 0.25) !important;
}

.message-time.send-failed-label {
    color: var(--red) !important;
    font-size: 0.68rem;
    margin-top: 3px;
    padding: 0 4px;
}

/* ── Light mode (chat page) ─────────────────────────────────── */
body.light-mode .chat-header {
    background: rgba(255, 255, 255, 0.95);
    border-bottom-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .chat-logo {
    color: var(--text);
}

body.light-mode .char-bar-wrap {
    background: rgba(248, 249, 255, 0.9);
    border-bottom-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .char-bar-track {
    background: rgba(0, 0, 0, 0.08);
}

body.light-mode .chat-input-bar {
    background: rgba(255, 255, 255, 0.97);
    border-top-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .msg-textarea {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.15);
    color: var(--text);
}

body.light-mode .msg-textarea:focus {
    border-color: var(--purple);
}

body.light-mode .msg-textarea::placeholder {
    color: var(--text-muted);
}

body.light-mode .input-action-btn {
    background: rgba(255, 255, 255, 0.8);
    border-color: rgba(0, 0, 0, 0.12);
    color: var(--text-dim);
}

body.light-mode .input-action-btn:hover {
    background: rgba(255, 255, 255, 0.95);
    border-color: var(--purple);
}

body.light-mode .theirs .message-bubble {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(0, 0, 0, 0.12);
    color: var(--text);
}

body.light-mode .emoji-picker,
body.light-mode .sticker-picker {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(0, 0, 0, 0.12);
}

body.light-mode .sticker-btn {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .sticker-btn:hover {
    background: rgba(168, 85, 247, 0.08);
}

body.light-mode .user-chip {
    background: rgba(255, 255, 255, 0.8);
    border-color: rgba(0, 0, 0, 0.12);
}

body.light-mode .rating-section {
    background: rgba(255, 255, 255, 0.85);
    border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .modal-overlay {
    background: rgba(243, 244, 248, 0.6);
}

body.light-mode .modal-card {
    background: rgba(255, 255, 255, 0.97);
    border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .msg-context-menu,
body.light-mode .reaction-picker {
    background: rgba(255, 255, 255, 0.97);
    border-color: rgba(0, 0, 0, 0.12);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

body.light-mode .ctx-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

body.light-mode .reaction-badge {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .reaction-badge.mine {
    background: rgba(168, 85, 247, 0.08);
    border-color: rgba(168, 85, 247, 0.3);
}

body.light-mode .reply-preview {
    background: rgba(0, 0, 0, 0.04);
}

body.light-mode .reply-preview:hover {
    background: rgba(0, 0, 0, 0.07);
}

body.light-mode .mine .reply-preview {
    background: rgba(255, 255, 255, 0.15);
}

body.light-mode .reply-bar {
    background: rgba(168, 85, 247, 0.04);
    border-top-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .reaction-emoji-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}