/* ═══════════════════════════════════════════════════════════════
   Notes Hub — Collaboration
   ═══════════════════════════════════════════════════════════════ */

.nh-collab-bar {
    --nh-collab-bg: #ffffff;
    --nh-collab-border: #e2e8f0;
    --nh-collab-text: #0f172a;
    --nh-collab-muted: #64748b;
    /*
     * BUGFIX: bridged to theme tokens so accent-color customization
     * (Customizer → noteshub_accent) reaches the collab bar's gradient,
     * status dots, and typing indicator. Falls back to violet if theme
     * tokens aren't defined.
     */
    --nh-collab-accent: var(--nh-primary, #6366f1);
    --nh-collab-accent-2: var(--nh-primary-2, #8b5cf6);
    --nh-collab-online: #10b981;
    --nh-collab-editing: #f59e0b;

    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--nh-collab-bg);
    border: 1px solid var(--nh-collab-border);
    border-radius: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
    color: var(--nh-collab-text);
    margin: 8px 0;
    min-height: 48px;
}

/*
 * BUGFIX: `body.nh-dark` → `html.nh-dark`. The theme toggles `nh-dark` on
 * <html>, so every dark-mode rule in this file was inert for users who
 * toggled dark via the theme button.
 */
html.nh-dark .nh-collab-bar,
body.noteshub-dark-default .nh-collab-bar {
    --nh-collab-bg: #111a2e;
    --nh-collab-border: #1e293b;
    --nh-collab-text: #f8fafc;
    --nh-collab-muted: #94a3b8;
}

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

.nh-collab-avatars {
    display: flex;
    align-items: center;
    /*
     * BUGFIX: removed invalid `gap: -8px`. `gap` accepts only non-negative
     * lengths per the CSS spec — the declaration was dropped by every
     * browser anyway, so removing it is a no-op visually. The overlap
     * comes from `margin-left: -8px` on the individual avatars.
     */
    flex-shrink: 0;
    min-height: 32px;
}

.nh-collab-avatar {
    position: relative;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--nh-collab-bg);
    margin-left: -8px;
    background: var(--nh-collab-border);
    /*
     * BUGFIX: dropped `z-index` from the transition list — z-index is an
     * integer and can't be interpolated, so the timing function had no
     * effect on it. `transform` is what actually animates.
     */
    transition: transform 200ms ease;
    cursor: default;
}

.nh-collab-avatar:first-child {
    margin-left: 0;
}

.nh-collab-avatar:hover {
    transform: translateY(-3px);
    z-index: 10;
}

.nh-collab-avatar img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.nh-collab-avatar-initials {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, var(--nh-collab-accent), var(--nh-collab-accent-2));
}

/* Status dot */
.nh-collab-avatar::after {
    content: '';
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--nh-collab-bg);
    background: var(--nh-collab-online);
}

.nh-collab-avatar.is-editing::after {
    background: var(--nh-collab-editing);
    animation: nh-collab-pulse 1.4s ease-in-out infinite;
}

@keyframes nh-collab-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, .6); }
    50% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
}

/* Overflow chip */
.nh-collab-overflow {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--nh-collab-border);
    color: var(--nh-collab-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    margin-left: -8px;
    border: 2px solid var(--nh-collab-bg);
}

/* ─── Typing indicator ────────────────────────────────── */

.nh-collab-typing {
    flex: 1;
    min-width: 0;
    font-size: 12.5px;
    color: var(--nh-collab-muted);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.nh-collab-typing[hidden] { display: none !important; }

.nh-collab-typing strong {
    color: var(--nh-collab-text);
    font-weight: 800;
    /* Truncate very long display names instead of breaking the layout. */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nh-collab-dots {
    display: inline-flex;
    gap: 3px;
}

.nh-collab-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--nh-collab-accent);
    animation: nh-collab-bounce 1.4s infinite;
}

.nh-collab-dots span:nth-child(2) { animation-delay: .2s; }
.nh-collab-dots span:nth-child(3) { animation-delay: .4s; }

@keyframes nh-collab-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ─── Lock banner ─────────────────────────────────────── */

.nh-collab-lock {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 10px;
    color: #92400e;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 10px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

.nh-collab-lock-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.nh-collab-lock strong {
    font-weight: 800;
    color: #78350f;
}

/* BUGFIX: `body.nh-dark` → `html.nh-dark`. */
html.nh-dark .nh-collab-lock,
body.noteshub-dark-default .nh-collab-lock {
    background: rgba(245, 158, 11, .15);
    border-color: rgba(245, 158, 11, .4);
    color: #fcd34d;
}

html.nh-dark .nh-collab-lock strong,
body.noteshub-dark-default .nh-collab-lock strong {
    color: #fef3c7;
}

/* ─── Live draft preview ──────────────────────────────── */

/*
 * BUGFIX: In the previous version, the light-mode rule referenced
 * var(--nh-collab-bg) and var(--nh-collab-border) but neither variable was
 * declared on .nh-collab-draft or any of its ancestors (they were only on
 * .nh-collab-bar, which is a sibling). The dark-mode block re-declared the
 * variables locally, so the draft looked right in dark mode and had NO
 * background and an invisible border in light mode.
 *
 * Declaring the light-mode values here makes the block self-sufficient.
 */
.nh-collab-draft {
    --nh-collab-bg: #ffffff;
    --nh-collab-border: #e2e8f0;
    --nh-collab-text: #0f172a;
    --nh-collab-muted: #64748b;

    margin-top: 12px;
    padding: 14px 16px;
    background: var(--nh-collab-bg);
    border: 1px dashed var(--nh-collab-border);
    border-radius: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

/* BUGFIX: `body.nh-dark` → `html.nh-dark`. */
html.nh-dark .nh-collab-draft,
body.noteshub-dark-default .nh-collab-draft {
    --nh-collab-bg: #111a2e;
    --nh-collab-border: #1e293b;
    --nh-collab-text: #f8fafc;
    --nh-collab-muted: #94a3b8;
}

.nh-collab-draft-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--nh-collab-muted);
}

.nh-collab-draft-head img {
    width: 20px;
    height: 20px;
    border-radius: 50%;
}

.nh-collab-draft-head strong {
    color: var(--nh-collab-text);
    font-weight: 800;
    text-transform: none;
    letter-spacing: 0;
    font-size: 13px;
}

.nh-collab-draft-body {
    font-size: 13px;
    line-height: 1.55;
    color: var(--nh-collab-muted);
    max-height: 180px;
    overflow-y: auto;
    /*
     * BUGFIX: prevents the draft preview's scroll from chaining to the
     * parent document when the user reaches the top or bottom.
     */
    overscroll-behavior-y: contain;
    white-space: pre-wrap;
    word-break: break-word;
    padding: 10px 12px;
    /*
     * BUGFIX: was hardcoded rgba(99,102,241,.04) — didn't follow the
     * accent-color customization. Now uses the accent token via color-mix,
     * falling back to the original tint on browsers without color-mix
     * support (the `background` shorthand below takes precedence when
     * color-mix is supported).
     */
    background: rgba(99, 102, 241, .04);
    background: color-mix(in srgb, var(--nh-collab-accent, #6366f1) 4%, transparent);
    border-radius: 8px;
    font-family: ui-monospace, SFMono-Regular, monospace;
}

/* ─── Injected presence chips in editor header ────────── */

.nh-collab-presence-inline {
    display: inline-flex;
    align-items: center;
    /* BUGFIX: removed invalid `gap: -6px` (negative gap is not allowed). */
    margin-left: auto;
    margin-right: 8px;
}

.nh-collab-presence-inline .nh-collab-avatar {
    width: 26px;
    height: 26px;
    margin-left: -6px;
    border-width: 2px;
}

/* ─── Mobile ──────────────────────────────────────────── */

@media (max-width: 640px) {
    .nh-collab-bar {
        padding: 8px 10px;
        gap: 8px;
        border-radius: 10px;
    }
    .nh-collab-avatar,
    .nh-collab-overflow {
        width: 28px;
        height: 28px;
    }
    .nh-collab-avatar-initials {
        font-size: 10px;
    }
    .nh-collab-typing {
        font-size: 11.5px;
    }
    .nh-collab-draft {
        padding: 10px 12px;
    }
    .nh-collab-draft-body {
        font-size: 12px;
        max-height: 140px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   Print — hide transient collab chrome
   BUGFIX: previously missing. The collab bar and lock banner are
   live-session UI with no print value.
   ═══════════════════════════════════════════════════════════════ */

@media print {
    .nh-collab-bar,
    .nh-collab-lock {
        display: none !important;
    }
}