/* Site Chat — floating toggle middle-left, panel slides in from left */

.site-chat-root {
    --site-chat-width: 360px;
    --site-chat-max-height: 520px;
    --site-chat-toggle-width: 44px;
    --site-chat-toggle-height: 52px;
    --site-chat-toggle-bg: var(--primary-color, #2563eb);
    --site-chat-toggle-color: #ffffff;
    --site-chat-header-bg: var(--primary-color, #2563eb);
    --site-chat-header-text: #ffffff;
    --site-chat-panel-bg: var(--surface, var(--surface-color, #f8fafc));
    --site-chat-panel-text: var(--card-text, var(--text-color, #111827));
    --site-chat-messages-bg: var(--background-color, #ffffff);
    --site-chat-send-bg: var(--primary-color, #2563eb);
    --site-chat-send-text: #ffffff;
    --site-chat-z: 10050;
    --site-chat-admin-offset: 0px;
    position: fixed;
    left: var(--site-chat-admin-offset);
    top: 50%;
    transform: translateY(-50%);
    z-index: var(--site-chat-z);
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 14px;
    pointer-events: none;
}

.site-chat-drawer {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    transform: translateX(calc(-1 * var(--site-chat-width)));
    transition: transform 0.28s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
    border-radius: 0 12px 12px 0;
    overflow: hidden;
    pointer-events: none;
}

.site-chat-root.is-open .site-chat-drawer {
    transform: translateX(0);
    pointer-events: auto;
}

.site-chat-toggle {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    align-self: center;
    flex-shrink: 0;
    z-index: 1;
    pointer-events: auto;
    width: var(--site-chat-toggle-width);
    height: var(--site-chat-toggle-height);
    border: none;
    border-radius: 0 10px 10px 0;
    background: var(--site-chat-toggle-bg);
    color: var(--site-chat-toggle-color);
    cursor: pointer;
    box-shadow: 2px 2px 12px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s, box-shadow 0.15s;
}

.site-chat-toggle:hover {
    filter: brightness(1.08);
    box-shadow: 2px 2px 16px rgba(0, 0, 0, 0.35);
}

.site-chat-toggle-icon {
    font-size: 22px;
    line-height: 1;
    color: var(--site-chat-toggle-color);
}

.site-chat-toggle-img {
    max-width: 70%;
    max-height: 70%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

.site-chat-unread {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background: #dc2626;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

.site-chat-panel {
    position: relative;
    left: auto;
    top: auto;
    flex-shrink: 0;
    z-index: 0;
    width: min(var(--site-chat-width), calc(100vw - var(--site-chat-toggle-width) - var(--site-chat-admin-offset) - 24px));
    height: min(var(--site-chat-max-height), 90vh);
    max-height: min(var(--site-chat-max-height), 90vh);
    transform: none;
    transition: none;
    display: flex;
    flex-direction: column;
    background: var(--site-chat-panel-bg);
    color: var(--site-chat-panel-text);
    border: 1px solid var(--border-color, #d1d5db);
    border-right: none;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
}

.site-chat-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.75rem 0.85rem;
    background: var(--site-chat-header-bg);
    color: var(--site-chat-header-text);
    flex-shrink: 0;
}

.site-chat-title {
    display: block;
    font-size: 15px;
}

.site-chat-subtitle {
    display: block;
    font-size: 11px;
    opacity: 0.9;
    margin-top: 2px;
    line-height: 1.3;
    max-width: 260px;
}

.site-chat-close {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.15rem;
    opacity: 0.85;
}

.site-chat-close:hover {
    opacity: 1;
}

.site-chat-error {
    margin: 0;
    padding: 0.45rem 0.75rem;
    background: #fef2f2;
    color: #991b1b;
    font-size: 13px;
    border-bottom: 1px solid #fecaca;
}

.site-chat-error[hidden] {
    display: none !important;
}

.site-chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 0.65rem 0.75rem;
    background: var(--site-chat-messages-bg);
}

.site-chat-msg {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.65rem;
    align-items: flex-start;
}

.site-chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
    background: #e2e8f0;
}

.site-chat-msg-body {
    flex: 1;
    min-width: 0;
}

.site-chat-msg-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35rem;
    margin-bottom: 0.15rem;
}

.site-chat-msg-user {
    background: none;
    border: none;
    padding: 0;
    font-weight: 600;
    font-size: 13px;
    color: var(--link-color, #2563eb);
    cursor: pointer;
    text-align: left;
}

.site-chat-msg-user:hover {
    text-decoration: underline;
}

.site-chat-msg-user.is-staff {
    color: #b45309;
}

.site-chat-staff-badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: #fef3c7;
    color: #92400e;
    padding: 1px 5px;
    border-radius: 4px;
}

.site-chat-msg-time {
    font-size: 11px;
    color: var(--text-muted, var(--card-muted, #4b5563));
}

.site-chat-msg-text {
    font-size: 14px;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}

.site-chat-msg.is-staff .site-chat-msg-text {
    background: #fffbeb;
    border-left: 3px solid #f59e0b;
    padding: 0.35rem 0.5rem;
    border-radius: 0 6px 6px 0;
}

.site-chat-compose {
    flex-shrink: 0;
    border-top: 1px solid var(--border-color, #d1d5db);
    padding: 0.5rem;
    background: var(--site-chat-panel-bg);
    min-height: 0;
}

.site-chat-input-row {
    display: flex;
    gap: 0.35rem;
    align-items: flex-end;
}

.site-chat-emoji-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

.site-chat-input {
    flex: 1;
    min-height: 36px;
    max-height: 80px;
    resize: vertical;
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 8px;
    padding: 0.4rem 0.5rem;
    font-size: 14px;
    font-family: inherit;
}

.site-chat-send {
    flex-shrink: 0;
    height: 36px;
    padding: 0 0.85rem;
    border: none;
    border-radius: 8px;
    background: var(--site-chat-send-bg);
    color: var(--site-chat-send-text);
    font-weight: 600;
    cursor: pointer;
    font-size: 13px;
}

.site-chat-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.site-chat-emoji-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    max-height: 88px;
    overflow-y: auto;
    margin-bottom: 0.4rem;
    padding: 0.35rem;
    background: #fff;
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 8px;
}

.site-chat-emoji-pick {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 18px;
    border-radius: 4px;
}

.site-chat-emoji-pick:hover {
    background: #e2e8f0;
}

.site-chat-suspended-notice {
    padding: 0.75rem;
    font-size: 13px;
    color: #991b1b;
    background: #fee2e2;
    border-top: 1px solid #fecaca;
}

.site-chat-profile {
    position: fixed;
    left: min(calc(var(--site-chat-admin-offset) + var(--site-chat-width) + var(--site-chat-toggle-width) + 16px), calc(100vw - 220px));
    top: 50%;
    transform: translateY(-50%);
    z-index: calc(var(--site-chat-z) + 2);
    width: 220px;
    padding: 1rem;
    background: #fff;
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.site-chat-profile:not([hidden]) {
    display: block;
    pointer-events: auto;
}

.site-chat-profile-close {
    position: absolute;
    top: 4px;
    right: 8px;
    border: none;
    background: none;
    font-size: 20px;
    cursor: pointer;
    color: #64748b;
}

.site-chat-profile-avatar {
    display: block;
    border-radius: 50%;
    margin-bottom: 0.5rem;
}

.site-chat-profile h3 {
    margin: 0 0 0.65rem;
    font-size: 16px;
}

.site-chat-profile-stats {
    margin: 0;
    font-size: 13px;
}

.site-chat-profile-stats div {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.25rem 0;
    border-bottom: 1px solid #f1f5f9;
}

.site-chat-profile-stats dt {
    color: var(--text-muted, var(--card-muted, #4b5563));
    font-weight: 500;
}

.site-chat-profile-stats dd {
    margin: 0;
    font-weight: 600;
}

body.surf-body .site-chat-panel {
    height: min(var(--site-chat-max-height), 85vh);
    max-height: min(var(--site-chat-max-height), 85vh);
}

/* Admin panel: anchor beside the 260px sidebar */
body.admin-body {
    --site-chat-admin-offset: 260px;
}

@media (max-width: 900px) {
    body.admin-body {
        --site-chat-admin-offset: 0px;
    }
}

@media (max-width: 480px) {
    .site-chat-panel {
        width: calc(100vw - var(--site-chat-toggle-width) - var(--site-chat-admin-offset) - 16px);
        height: min(var(--site-chat-max-height), 85vh);
        max-height: min(var(--site-chat-max-height), 85vh);
    }

    .site-chat-profile {
        left: 50%;
        transform: translate(-50%, -50%);
        top: 30%;
    }
}
