/* ════════════════════════════════════════════════════════════════
   Nexus Messenger — Chat UI Polish v1.8.2
   Стили для: user-profile-modal, user-picker, typing, group-members,
   avatar-cropper, reactions-popover, unread-divider
   ════════════════════════════════════════════════════════════════ */

/* ─── User Picker Modal ───────────────────────────────────────── */
.nx-picker-modal {
    position: fixed; inset: 0; z-index: 1200;
    display: flex; align-items: center; justify-content: center;
}
.nx-picker-backdrop {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
}
.nx-picker-dialog {
    position: relative;
    width: min(480px, calc(100vw - 32px));
    max-height: 80vh;
    background: var(--bg-overlay, #fff);
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.nx-picker-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid var(--border, #eee);
}
.nx-picker-header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.nx-picker-close {
    background: none; border: none; cursor: pointer;
    font-size: 18px; color: var(--text-secondary, #888);
    padding: 4px 8px; border-radius: 6px;
}
.nx-picker-close:hover { background: var(--bg-hover, #f5f5f5); }
.nx-picker-search {
    margin: 12px 20px;
    padding: 10px 14px;
    background: var(--bg-input, #f5f5f5);
    border: 1px solid var(--border, #ddd);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
}
.nx-picker-search:focus { border-color: var(--accent, #007aff); }
.nx-picker-hint {
    padding: 0 20px 8px;
    font-size: 13px;
    color: var(--text-secondary, #888);
}
.nx-picker-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 8px;
}
.nx-picker-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
}
.nx-picker-item:hover { background: var(--bg-hover, #f5f5f5); }
.nx-picker-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--accent, #007aff);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}
.nx-picker-avatar img { width: 100%; height: 100%; object-fit: cover; }
.nx-picker-info { flex: 1; min-width: 0; }
.nx-picker-name { font-weight: 500; font-size: 14px; }
.nx-picker-username { font-size: 12px; color: var(--text-secondary, #888); }
.nx-picker-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border, #eee);
    display: flex; justify-content: flex-end; gap: 8px;
}
.nx-picker-footer button {
    padding: 8px 16px;
    border: 1px solid var(--border, #ccc);
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

/* ─── User Profile Modal (v1.8.6: centered, modern) ────────── */
.nx-userprofile-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: nx-fade-in 0.18s ease-out;
}
@keyframes nx-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
.nx-up-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(10, 12, 20, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.nx-up-dialog {
    position: relative;
    width: min(440px, calc(100vw - 32px));
    max-height: min(85vh, 720px);
    background: var(--bg-overlay, #ffffff);
    border-radius: 20px;
    box-shadow:
        0 24px 80px -12px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: nx-modal-pop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes nx-modal-pop {
    from { opacity: 0; transform: scale(0.94) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.nx-up-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(10px);
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    color: #fff;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.15s;
}
.nx-up-close:hover {
    background: rgba(0, 0, 0, 0.2);
    transform: rotate(90deg);
}

/* Header with gradient background */
.nx-up-header-bg {
    height: 100px;
    background: linear-gradient(135deg, var(--accent, #007aff) 0%, #5856d6 100%);
    position: relative;
}

.nx-up-content {
    padding: 0 28px 24px;
    text-align: center;
    overflow-y: auto;
    margin-top: -60px;
    position: relative;
}
.nx-up-loading, .nx-up-error {
    padding: 60px 24px;
    color: var(--text-secondary, #888);
    text-align: center;
}
.nx-up-avatar-big {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    margin: 0 auto 16px;
    background: linear-gradient(135deg, var(--accent, #007aff), #5856d6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    font-weight: 600;
    overflow: hidden;
    border: 4px solid var(--bg-overlay, #fff);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}
.nx-up-avatar-big img { width: 100%; height: 100%; object-fit: cover; }
.nx-up-name { font-size: 22px; font-weight: 700; margin-bottom: 4px; color: var(--text-primary, #1d1d1f); }
.nx-up-username { color: var(--text-secondary, #888); font-size: 14px; margin-bottom: 10px; }
.nx-up-status { font-size: 13px; color: var(--text-secondary, #888); display: inline-flex; align-items: center; gap: 6px; }
.nx-up-status.online { color: var(--green, #32d74b); }
.nx-up-status.online::before {
    content: '';
    width: 8px; height: 8px;
    background: var(--green, #32d74b);
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 0 3px rgba(50, 215, 75, 0.2);
}
.nx-up-bio {
    margin: 20px 0;
    padding: 14px 16px;
    background: var(--bg-hover, rgba(0,0,0,0.04));
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    text-align: left;
    color: var(--text-primary, #1d1d1f);
}
.nx-up-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 20px;
}
.nx-up-btn {
    padding: 11px 14px;
    border: 1px solid var(--border, #e0e0e0);
    background: transparent;
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #1d1d1f);
    transition: all 0.15s;
}
.nx-up-btn:hover {
    background: var(--bg-hover, #f5f5f5);
    transform: translateY(-1px);
}
.nx-up-btn.primary {
    background: linear-gradient(135deg, var(--accent, #007aff), #5856d6);
    color: #fff;
    border-color: transparent;
    grid-column: span 2;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}
.nx-up-btn.primary:hover {
    box-shadow: 0 6px 16px rgba(0, 122, 255, 0.4);
}
.nx-up-btn.danger { color: #ff3b30; border-color: #ff3b3033; }
.nx-up-btn.danger:hover { background: #ff3b301a; }
.nx-up-btn.warning { color: #ff9500; border-color: #ff950033; }
.nx-up-btn.warning:hover { background: #ff95001a; }
.nx-up-commons {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border, rgba(0,0,0,0.08));
}
.nx-up-section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary, #888);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
    text-align: left;
}

[data-theme="dark"] .nx-up-dialog {
    background: #1c1c1e;
    box-shadow:
        0 24px 80px -12px rgba(0, 0, 0, 0.7),
        0 0 0 1px rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .nx-up-avatar-big {
    border-color: #1c1c1e;
}
[data-theme="dark"] .nx-up-name {
    color: #f5f5f7;
}
[data-theme="dark"] .nx-up-bio {
    background: rgba(255,255,255,0.05);
    color: #f5f5f7;
}
[data-theme="dark"] .nx-up-btn {
    color: #f5f5f7;
    border-color: rgba(255,255,255,0.15);
}
[data-theme="dark"] .nx-up-btn:hover {
    background: rgba(255,255,255,0.08);
}

/* ─── Typing Indicator ─────────────────────────────────────────── */
.nx-typing-indicator {
    padding: 4px 12px;
    font-size: 12px;
    color: var(--text-secondary, #888);
    font-style: italic;
    display: flex; align-items: center; gap: 6px;
}
.nx-typing-dots {
    display: inline-flex; gap: 2px;
}
.nx-typing-dots span {
    width: 4px; height: 4px; border-radius: 50%;
    background: var(--text-secondary, #888);
    animation: typing-pulse 1.4s infinite ease-in-out;
}
.nx-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.nx-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-pulse {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30%           { opacity: 1;   transform: scale(1); }
}

/* ─── Group Members Tab ────────────────────────────────────────── */
.nx-gm-tabs {
    display: flex;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    gap: 4px;
}
.nx-gm-tab {
    padding: 10px 14px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
}
.nx-gm-tab.active {
    color: var(--accent, #007aff);
    border-bottom-color: var(--accent, #007aff);
    font-weight: 500;
}
.nx-gm-search { padding: 12px 16px; }
.nx-gm-search-input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input, #f5f5f5);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    outline: none;
}
.nx-gm-list { max-height: 400px; overflow-y: auto; padding: 0 8px; }
.nx-gm-loading, .nx-gm-empty, .nx-gm-error {
    padding: 24px; text-align: center; color: var(--text-secondary);
    font-size: 13px;
}
.nx-gm-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
}
.nx-gm-item:hover { background: var(--bg-hover, #f5f5f5); }
.nx-gm-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 13px;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}
.nx-gm-avatar img { width: 100%; height: 100%; object-fit: cover; }
.nx-online-dot {
    position: absolute;
    bottom: 0; right: 0;
    width: 10px; height: 10px;
    background: var(--green, #32d74b);
    border: 2px solid var(--bg-overlay, #fff);
    border-radius: 50%;
}
.nx-gm-info { flex: 1; min-width: 0; }
.nx-gm-name { font-size: 14px; font-weight: 500; }
.nx-gm-role { font-size: 11px; }
.nx-gm-menu {
    background: none; border: none; cursor: pointer;
    padding: 6px 10px; border-radius: 6px;
    color: var(--text-secondary);
}
.nx-gm-menu:hover { background: var(--bg-hover); }
.nx-gm-actions { padding: 12px 16px; border-top: 1px solid var(--border); }

.nx-gm-dropdown {
    position: fixed;
    z-index: 1300;
    background: var(--bg-overlay, #fff);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    min-width: 200px;
    padding: 4px;
}
.nx-gm-dropdown button {
    display: block; width: 100%;
    padding: 8px 12px;
    background: none;
    border: none;
    text-align: left;
    font-size: 13px;
    cursor: pointer;
    border-radius: 6px;
}
.nx-gm-dropdown button:hover { background: var(--bg-hover); }
.nx-gm-dropdown button.danger { color: #ff3b30; }

/* ─── Avatar Cropper ───────────────────────────────────────────── */
.nx-cropper-modal {
    position: fixed; inset: 0; z-index: 1400;
    display: flex; align-items: center; justify-content: center;
}
.nx-cropper-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.7); }
.nx-cropper-dialog {
    position: relative;
    background: var(--bg-overlay, #fff);
    padding: 20px;
    border-radius: 12px;
    text-align: center;
}
.nx-cropper-title { margin-bottom: 16px; font-size: 16px; font-weight: 600; }
.nx-cropper-canvas-wrap {
    position: relative;
    display: inline-block;
    margin: 0 auto 16px;
}
.nx-cropper-canvas {
    cursor: grab;
    background: #000;
    display: block;
}
.nx-cropper-canvas:active { cursor: grabbing; }
.nx-cropper-mask {
    position: absolute; inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at center,
        transparent 199px, rgba(0,0,0,0.5) 201px);
}
.nx-cropper-zoom {
    width: 100%;
    margin: 12px 0;
}
.nx-cropper-buttons {
    display: flex; gap: 12px; justify-content: flex-end;
}
.nx-btn {
    padding: 10px 20px;
    border: 1px solid var(--border);
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
}
.nx-btn.primary { background: var(--accent, #007aff); color: #fff; border-color: transparent; }

/* ─── Reactions Popover ────────────────────────────────────────── */
.nx-msg-reactions {
    display: inline-flex; align-items: center; gap: 4px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.nx-reaction-chip, .nx-reactions-more {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px;
    background: var(--reaction-bg, rgba(0,122,255,0.1));
    border: 1px solid transparent;
    border-radius: 12px;
    font-size: 12px;
    cursor: pointer;
    user-select: none;
    transition: transform 0.1s, background 0.15s;
}
.nx-reaction-chip:hover, .nx-reactions-more:hover {
    background: var(--reaction-hover, rgba(0,122,255,0.2));
    transform: scale(1.05);
}
.nx-reaction-chip.own {
    background: var(--accent, #007aff);
    color: #fff;
}
.nx-reactions-popover {
    position: fixed;
    z-index: 1200;
    background: var(--bg-overlay, #fff);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    max-width: 320px;
    max-height: 400px;
    overflow-y: auto;
    padding: 8px;
}
.nx-rp-loading, .nx-rp-error, .nx-rp-empty {
    padding: 16px; text-align: center; font-size: 13px;
    color: var(--text-secondary);
}
.nx-rp-group { padding: 8px; }
.nx-rp-emoji {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 6px;
    display: flex; align-items: center; gap: 6px;
}
.nx-rp-count {
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--bg-hover);
    padding: 1px 6px;
    border-radius: 10px;
}
.nx-rp-users { display: flex; flex-direction: column; gap: 4px; }
.nx-rp-user {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 6px;
    border-radius: 6px;
    cursor: pointer;
}
.nx-rp-user:hover { background: var(--bg-hover); }
.nx-rp-user img, .nx-rp-user-letter {
    width: 22px; height: 22px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 600;
    overflow: hidden;
    flex-shrink: 0;
}
.nx-rp-user-name { font-size: 13px; }
.nx-rp-more {
    font-size: 11px;
    color: var(--text-secondary);
    padding: 4px 6px;
    text-align: center;
}

/* ─── Unread Divider ───────────────────────────────────────────── */
.nx-unread-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px 0;
    color: var(--accent, #007aff);
    font-size: 12px;
    font-weight: 500;
    position: sticky;
    top: 0;
    background: linear-gradient(180deg,
        var(--chat-bg, transparent) 0%,
        var(--chat-bg, transparent) 80%,
        transparent 100%);
    z-index: 5;
}
.nx-unread-divider::before,
.nx-unread-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--accent-soft, rgba(0,122,255,0.3));
}

/* ─── Dark theme compatibility ─────────────────────────────────── */
[data-theme="dark"] .nx-picker-dialog,
[data-theme="dark"] .nx-up-dialog,
[data-theme="dark"] .nx-reactions-popover,
[data-theme="dark"] .nx-gm-dropdown,
[data-theme="dark"] .nx-cropper-dialog {
    background: #1c1c1e;
    color: #f5f5f7;
}
[data-theme="dark"] .nx-picker-search,
[data-theme="dark"] .nx-gm-search-input {
    background: #2c2c2e;
    color: #f5f5f7;
}

/* ═══════════════════════════════════════════════════════════════
   v1.8.3 additions: animated-emoji, markdown-toolbar, unread-divider
   ═══════════════════════════════════════════════════════════════ */

/* ─── Animated Emoji ───────────────────────────────────────────── */
.nx-anim-emoji {
    display: inline-block;
    width: 1.2em;
    height: 1.2em;
    vertical-align: -0.2em;
    margin: 0 0.05em;
}
.nx-anim-emoji svg {
    width: 100%;
    height: 100%;
    display: block;
}
.nx-anim-emoji.nx-anim-pulse { animation: nx-pulse 1.5s ease-in-out infinite; }
.nx-anim-emoji.nx-anim-flicker { animation: nx-flicker 0.8s ease-in-out infinite; }
.nx-anim-emoji.nx-anim-spin { animation: nx-spin 2s linear infinite; }
.nx-anim-emoji.nx-anim-wiggle { animation: nx-wiggle 0.6s ease-in-out infinite; }
.nx-anim-emoji.nx-anim-bounce { animation: nx-bounce 1.2s ease-in-out infinite; }
.nx-anim-emoji.nx-anim-sparkle { animation: nx-sparkle 1.5s linear infinite; }
.nx-anim-emoji.nx-anim-dart { animation: nx-dart 2s ease-in-out infinite; }
.nx-anim-emoji.nx-anim-launch { animation: nx-launch 2s ease-in-out infinite; }

@keyframes nx-pulse   { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); } }
@keyframes nx-flicker { 0%,100% { opacity: 1; transform: scale(1); }
                        50%     { opacity: 0.85; transform: scale(1.08); } }
@keyframes nx-spin    { from { transform: rotate(0); } to { transform: rotate(360deg); } }
@keyframes nx-wiggle  { 0%,100% { transform: rotate(0); }
                        25%     { transform: rotate(-12deg); }
                        75%     { transform: rotate(12deg); } }
@keyframes nx-bounce  { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes nx-sparkle { 0%,100% { opacity: 1; transform: scale(1) rotate(0); }
                        50%     { opacity: 0.7; transform: scale(1.2) rotate(180deg); } }
@keyframes nx-dart    { 0%,100% { transform: translateX(0); }
                        25%     { transform: translateX(-2px); }
                        75%     { transform: translateX(2px); } }
@keyframes nx-launch  { 0%     { transform: translateY(2px); }
                        50%    { transform: translateY(-2px); }
                        100%   { transform: translateY(2px); } }

/* Отключаем анимации для prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .nx-anim-emoji { animation: none !important; }
}

/* ─── Markdown Toolbar ─────────────────────────────────────────── */
.nx-md-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px 8px;
    background: var(--bg-input, #f5f5f5);
    border-bottom: 1px solid var(--border, #e0e0e0);
    overflow-x: auto;
    scrollbar-width: none;
}
.nx-md-toolbar::-webkit-scrollbar { display: none; }

.nx-md-btn {
    background: none;
    border: none;
    padding: 6px 8px;
    cursor: pointer;
    color: var(--text-secondary, #666);
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.nx-md-btn:hover {
    background: var(--bg-hover, rgba(0,0,0,0.06));
    color: var(--text-primary, #222);
}
.nx-md-btn svg {
    width: 18px;
    height: 18px;
}
.nx-md-btn:focus-visible {
    outline: 2px solid var(--accent, #007aff);
    outline-offset: 1px;
}
.nx-md-divider {
    width: 1px;
    height: 20px;
    background: var(--border, #ddd);
    margin: 0 4px;
    flex-shrink: 0;
}

/* ─── Unread Divider ───────────────────────────────────────────── */
.nx-unread-divider {
    display: flex;
    align-items: center;
    text-align: center;
    padding: 8px 12px;
    margin: 12px 0;
    font-size: 12px;
    font-weight: 500;
    color: var(--accent, #007aff);
    background: var(--bg-soft, rgba(0,122,255,0.08));
    border-radius: 6px;
    position: relative;
    animation: nx-unread-appear 0.3s ease-out;
}
.nx-unread-divider::before,
.nx-unread-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--accent, #007aff);
    opacity: 0.3;
    margin: 0 8px;
}
.nx-unread-divider.nx-unread-fade-out {
    animation: nx-unread-fade 0.4s ease-out forwards;
}
@keyframes nx-unread-appear {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes nx-unread-fade {
    from { opacity: 1; max-height: 50px; margin: 12px 0; padding: 8px 12px; }
    to   { opacity: 0; max-height: 0;    margin: 0;      padding: 0 12px; }
}

[data-theme="dark"] .nx-md-toolbar {
    background: #2a2a2e;
    border-bottom-color: #3a3a3e;
}
[data-theme="dark"] .nx-unread-divider {
    background: rgba(0,122,255,0.12);
}

/* ═══ v1.8.4: Media fallback for 404/deleted files ═══ */
.media-fallback {
    opacity: 0.8;
    padding: 12px 16px;
    background: var(--bg-hover, rgba(0,0,0,0.04));
    border-radius: 8px;
    border: 1px dashed var(--border, #ccc);
    transition: opacity 0.2s;
}
.media-fallback:hover { opacity: 1; }
.media-fallback[data-status="404"], .media-fallback[data-status="410"] {
    background: var(--danger-soft, rgba(255,59,48,0.08));
    border-color: var(--danger, #ff3b30);
    color: var(--danger, #ff3b30);
}
.media-fallback[data-status="404"] .media-file-icon,
.media-fallback[data-status="410"] .media-file-icon {
    opacity: 0.7;
}
[data-theme="dark"] .media-fallback {
    background: rgba(255,255,255,0.05);
    border-color: rgba(255,255,255,0.2);
}
[data-theme="dark"] .media-fallback[data-status="404"],
[data-theme="dark"] .media-fallback[data-status="410"] {
    background: rgba(255,59,48,0.15);
}

/* ═══ v1.8.5: Emoji Picker ═══ */
.nx-emoji-picker {
    position: fixed;
    z-index: 1200;
    width: 340px;
    height: 380px;
    background: var(--bg-overlay, #fff);
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: nx-ep-fade 0.15s ease-out;
}
@keyframes nx-ep-fade {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.nx-ep-search {
    padding: 8px;
    border-bottom: 1px solid var(--border, #e0e0e0);
}
.nx-ep-search-input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input, #f5f5f5);
    border: 1px solid var(--border, #ddd);
    border-radius: 6px;
    font-size: 13px;
    outline: none;
}
.nx-ep-search-input:focus {
    border-color: var(--accent, #007aff);
}
.nx-ep-tabs {
    display: flex;
    gap: 2px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border, #e0e0e0);
    overflow-x: auto;
    scrollbar-width: none;
}
.nx-ep-tabs::-webkit-scrollbar { display: none; }
.nx-ep-tab {
    background: none;
    border: none;
    padding: 6px 10px;
    font-size: 18px;
    cursor: pointer;
    border-radius: 6px;
    flex-shrink: 0;
    line-height: 1;
    transition: background 0.15s;
    opacity: 0.6;
}
.nx-ep-tab:hover { background: var(--bg-hover, rgba(0,0,0,0.05)); opacity: 1; }
.nx-ep-tab.active {
    background: var(--accent-soft, rgba(0,122,255,0.15));
    opacity: 1;
}
.nx-ep-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.nx-ep-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
}
.nx-ep-emoji {
    background: none;
    border: none;
    padding: 6px;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.1s, transform 0.1s;
}
.nx-ep-emoji:hover {
    background: var(--bg-hover, rgba(0,0,0,0.06));
    transform: scale(1.2);
}
.nx-ep-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-secondary, #888);
    font-size: 13px;
}
[data-theme="dark"] .nx-emoji-picker {
    background: #1c1c1e;
    border-color: #3a3a3e;
}
[data-theme="dark"] .nx-ep-search-input {
    background: #2c2c2e;
    color: #f5f5f7;
}

/* ═══ v1.8.6: Admin Modal (storage, library, etc.) ═══ */
.nx-admin-modal {
    position: fixed; inset: 0; z-index: 1100;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    animation: nx-fade-in 0.18s ease-out;
}
.nx-admin-backdrop {
    position: absolute; inset: 0;
    background: rgba(10, 12, 20, 0.6);
    backdrop-filter: blur(8px);
}
.nx-admin-dialog {
    position: relative;
    width: min(880px, calc(100vw - 32px));
    max-height: 90vh;
    background: var(--bg-overlay, #fff);
    border-radius: 16px;
    box-shadow: 0 24px 80px -12px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: nx-modal-pop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.nx-admin-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border, #e0e0e0);
}
.nx-admin-header h2 { margin: 0; font-size: 18px; font-weight: 600; }
.nx-admin-close {
    background: rgba(0,0,0,0.05); border: none;
    width: 32px; height: 32px; border-radius: 50%;
    cursor: pointer; font-size: 14px;
}
.nx-admin-close:hover { background: rgba(0,0,0,0.1); }
.nx-admin-tabs {
    display: flex;
    padding: 0 16px;
    border-bottom: 1px solid var(--border, #e0e0e0);
    gap: 4px;
}
.nx-admin-tab {
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary, #888);
    transition: color 0.15s;
}
.nx-admin-tab.active {
    color: var(--accent, #007aff);
    border-bottom-color: var(--accent, #007aff);
    font-weight: 500;
}
.nx-admin-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}
.nx-admin-loading, .nx-admin-empty, .nx-admin-error {
    padding: 40px; text-align: center; color: var(--text-secondary, #888);
}
.nx-admin-error { color: #ff3b30; }

/* Storage rows */
.nx-storage-intro {
    padding: 12px 16px;
    background: var(--accent-soft, rgba(0,122,255,0.08));
    border-radius: 8px;
    font-size: 13px;
    color: var(--accent, #007aff);
    margin-bottom: 16px;
}
.nx-storage-row {
    display: flex;
    align-items: center;
    padding: 14px;
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 10px;
    margin-bottom: 8px;
    gap: 16px;
}
.nx-storage-row:hover { border-color: var(--accent, #007aff); }
.nx-storage-cat {
    display: flex; align-items: center; gap: 12px;
    flex: 1; min-width: 200px;
}
.nx-storage-icon {
    font-size: 28px;
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-hover, rgba(0,0,0,0.04));
    border-radius: 10px;
    flex-shrink: 0;
}
.nx-storage-cat-name { font-weight: 600; font-size: 14px; }
.nx-storage-cat-exts { font-size: 11px; color: var(--text-secondary, #888); margin-top: 2px; }
.nx-storage-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.nx-storage-mode {
    padding: 8px 12px;
    border: 1px solid var(--border, #ddd);
    border-radius: 6px;
    font-size: 13px;
    background: var(--bg-overlay, #fff);
    color: var(--text-primary, #1d1d1f);
    cursor: pointer;
    min-width: 160px;
}
.nx-storage-size {
    display: flex; align-items: center; gap: 4px;
}
.nx-storage-size-input {
    width: 70px;
    padding: 8px;
    border: 1px solid var(--border, #ddd);
    border-radius: 6px;
    font-size: 13px;
    text-align: right;
}
.nx-storage-size-input:disabled { opacity: 0.5; }
.nx-storage-size-unit { font-size: 12px; color: var(--text-secondary, #888); }
.nx-storage-save {
    padding: 8px 16px;
    background: var(--accent, #007aff);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
}
.nx-storage-save:hover { opacity: 0.9; }
.nx-storage-save:disabled { opacity: 0.5; cursor: wait; }
.nx-storage-status { font-size: 12px; min-width: 80px; }

/* Stats */
.nx-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.nx-stat-card {
    padding: 16px;
    background: var(--bg-hover, rgba(0,0,0,0.03));
    border-radius: 10px;
    text-align: center;
}
.nx-stat-card.warning {
    background: rgba(255, 149, 0, 0.1);
    border: 1px solid rgba(255, 149, 0, 0.3);
}
.nx-stat-value { font-size: 24px; font-weight: 700; color: var(--accent, #007aff); }
.nx-stat-card.warning .nx-stat-value { color: #ff9500; }
.nx-stat-label { font-size: 12px; color: var(--text-secondary, #888); margin-top: 4px; }
.nx-stats-title { font-size: 14px; font-weight: 600; margin: 16px 0 8px; }
.nx-stats-table {
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 8px;
    overflow: hidden;
}
.nx-stats-row {
    display: grid;
    grid-template-columns: 1fr 80px 100px;
    padding: 10px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--border, #e0e0e0);
}
.nx-stats-row:last-child { border-bottom: none; }
.nx-stats-row:hover { background: var(--bg-hover, rgba(0,0,0,0.03)); }
.nx-stats-mode { font-weight: 500; }
.nx-stats-count { color: var(--text-secondary, #888); }
.nx-stats-size { font-family: monospace; text-align: right; }

/* Cleanup */
.nx-cleanup { max-width: 520px; margin: 0 auto; text-align: center; padding: 24px; }
.nx-cleanup h3 { margin: 0 0 12px; font-size: 16px; }
.nx-cleanup-desc {
    font-size: 13px; color: var(--text-secondary, #888);
    line-height: 1.5; margin-bottom: 20px;
}
.nx-cleanup-desc code {
    padding: 2px 6px;
    background: var(--bg-hover, rgba(0,0,0,0.05));
    border-radius: 4px;
    font-size: 12px;
}
.nx-cleanup-result { margin-top: 16px; font-size: 14px; min-height: 24px; }

[data-theme="dark"] .nx-admin-dialog {
    background: #1c1c1e;
    border: 1px solid rgba(255,255,255,0.08);
}
[data-theme="dark"] .nx-storage-mode,
[data-theme="dark"] .nx-storage-size-input {
    background: #2c2c2e;
    color: #f5f5f7;
    border-color: #3a3a3e;
}
[data-theme="dark"] .nx-storage-icon,
[data-theme="dark"] .nx-stat-card {
    background: rgba(255,255,255,0.05);
}
[data-theme="dark"] .nx-admin-close {
    background: rgba(255,255,255,0.1);
    color: #f5f5f7;
}

/* ═══ v1.8.6: Library Modal (Windows Explorer style) ═══ */
.nx-lib-modal {
    position: fixed; inset: 0; z-index: 1100;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    animation: nx-fade-in 0.2s ease-out;
}
.nx-lib-backdrop {
    position: absolute; inset: 0;
    background: rgba(10, 12, 20, 0.6);
    backdrop-filter: blur(8px);
}
.nx-lib-dialog {
    position: relative;
    width: min(1200px, 100%);
    height: min(800px, 90vh);
    background: var(--bg-overlay, #fff);
    border-radius: 16px;
    box-shadow: 0 24px 80px -12px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: nx-modal-pop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.nx-lib-header {
    display: flex; align-items: center; gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border, #e0e0e0);
    flex-shrink: 0;
}
.nx-lib-title { font-size: 18px; font-weight: 600; }
.nx-lib-breadcrumb {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary, #888);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nx-lib-toolbar { display: flex; gap: 6px; }
.nx-lib-btn {
    background: none; border: none;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-primary, #1d1d1f);
    transition: background 0.15s;
}
.nx-lib-btn:hover { background: var(--bg-hover, rgba(0,0,0,0.06)); }
.nx-lib-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}
.nx-lib-sidebar {
    width: 280px;
    border-right: 1px solid var(--border, #e0e0e0);
    overflow-y: auto;
    padding: 8px 0;
    flex-shrink: 0;
}
.nx-lib-tree { padding: 0 4px; }
.nx-lib-tree-node {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.12s;
    user-select: none;
}
.nx-lib-tree-node:hover { background: var(--bg-hover, rgba(0,0,0,0.04)); }
.nx-lib-tree-node.active { background: var(--accent-soft, rgba(0,122,255,0.12)); color: var(--accent, #007aff); }
.nx-lib-tree-icon { font-size: 16px; flex-shrink: 0; }
.nx-lib-tree-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nx-lib-tree-count {
    font-size: 11px;
    padding: 2px 8px;
    background: var(--bg-hover, rgba(0,0,0,0.05));
    border-radius: 10px;
    color: var(--text-secondary, #888);
}
.nx-lib-empty-tree { padding: 24px 16px; text-align: center; color: var(--text-secondary, #888); }
.nx-lib-main {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}
.nx-lib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}
.nx-lib-empty, .nx-lib-loading, .nx-lib-error {
    grid-column: 1 / -1;
    padding: 40px; text-align: center; color: var(--text-secondary, #888);
}
.nx-lib-error { color: #ff3b30; }
.nx-lib-card {
    display: flex;
    gap: 12px;
    padding: 14px;
    background: var(--bg-hover, rgba(0,0,0,0.03));
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
}
.nx-lib-card:hover {
    border-color: var(--accent, #007aff);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.nx-lib-card-icon {
    font-size: 32px;
    width: 48px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.nx-lib-card-body { flex: 1; min-width: 0; }
.nx-lib-card-name {
    font-weight: 600;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nx-lib-card-meta {
    display: flex; gap: 8px;
    font-size: 11px;
    color: var(--text-secondary, #888);
    margin-top: 4px;
}
.nx-lib-card-meta span { padding: 1px 6px; background: var(--bg-overlay, rgba(0,0,0,0.04)); border-radius: 4px; }
.nx-lib-card-comment {
    font-size: 12px;
    color: var(--text-secondary, #888);
    margin-top: 6px;
    line-height: 1.4;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.nx-lib-card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.nx-lib-tag {
    font-size: 10px;
    padding: 2px 8px;
    background: var(--accent-soft, rgba(0,122,255,0.1));
    color: var(--accent, #007aff);
    border-radius: 10px;
}
.nx-lib-card-expires { font-size: 11px; color: #ff9500; margin-top: 4px; }

/* Context menu */
.nx-lib-context {
    position: fixed;
    z-index: 1500;
    background: var(--bg-overlay, #fff);
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    padding: 4px;
    min-width: 180px;
}
.nx-lib-context button {
    display: block; width: 100%;
    padding: 8px 12px;
    background: none; border: none;
    text-align: left;
    font-size: 13px;
    cursor: pointer;
    border-radius: 4px;
    color: var(--text-primary, #1d1d1f);
}
.nx-lib-context button:hover { background: var(--bg-hover, rgba(0,0,0,0.06)); }
.nx-lib-context button.danger { color: #ff3b30; }

/* Add to library / chat picker dialogs */
.nx-addlib-modal {
    position: fixed; inset: 0; z-index: 1300;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    animation: nx-fade-in 0.18s ease-out;
}
.nx-addlib-backdrop {
    position: absolute; inset: 0;
    background: rgba(10, 12, 20, 0.65);
    backdrop-filter: blur(6px);
}
.nx-addlib-dialog {
    position: relative;
    width: min(520px, 100%);
    max-height: 85vh;
    background: var(--bg-overlay, #fff);
    border-radius: 16px;
    box-shadow: 0 24px 80px -12px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: nx-modal-pop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.nx-addlib-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border, #e0e0e0);
}
.nx-addlib-header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.nx-addlib-close {
    background: rgba(0,0,0,0.05);
    border: none;
    width: 28px; height: 28px;
    border-radius: 50%;
    cursor: pointer;
}
.nx-addlib-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}
.nx-addlib-footer {
    display: flex; justify-content: flex-end; gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border, #e0e0e0);
}
.nx-lib-hint {
    font-size: 13px;
    color: var(--text-secondary, #888);
    padding: 10px 12px;
    background: var(--bg-hover, rgba(0,0,0,0.04));
    border-radius: 8px;
    margin-bottom: 12px;
}
.nx-form-group { margin-bottom: 12px; }
.nx-form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-secondary, #888);
}
.nx-form-input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input, #f5f5f5);
    border: 1px solid var(--border, #ddd);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
}
.nx-form-input:focus { border-color: var(--accent, #007aff); }
.nx-form-input[type="checkbox"] { width: auto; }
.nx-lib-btn-primary {
    padding: 10px 20px;
    background: linear-gradient(135deg, var(--accent, #007aff), #5856d6);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}
.nx-lib-btn-primary:hover { opacity: 0.9; }
.nx-lib-btn-cancel {
    padding: 10px 20px;
    background: transparent;
    border: 1px solid var(--border, #ddd);
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    color: var(--text-primary, #1d1d1f);
}

/* Chat picker */
.nx-chatpick-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
}
.nx-chatpick-item:hover { background: var(--bg-hover, rgba(0,0,0,0.04)); }
.nx-chatpick-item input { margin: 0; }

/* Viewer settings */
.nx-viewer-option {
    display: flex;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.15s;
}
.nx-viewer-option:hover { border-color: var(--accent, #007aff); }
.nx-viewer-option input { margin-top: 3px; }
.nx-viewer-title { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.nx-viewer-desc { font-size: 12px; color: var(--text-secondary, #888); line-height: 1.4; }

/* ═══ Viewer modal ═══ */
.nx-viewer-modal {
    position: fixed; inset: 0; z-index: 1400;
    display: flex; align-items: center; justify-content: center;
    animation: nx-fade-in 0.2s ease-out;
}
.nx-viewer-backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
}
.nx-viewer-dialog {
    position: relative;
    width: min(1000px, 95vw);
    height: min(900px, 95vh);
    background: var(--bg-overlay, #fff);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}
.nx-viewer-header {
    display: flex; align-items: center; gap: 16px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border, #e0e0e0);
    flex-shrink: 0;
    background: var(--bg-hover, rgba(0,0,0,0.02));
}
.nx-viewer-title {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nx-viewer-meta {
    display: flex; gap: 8px;
    font-size: 12px;
    color: var(--text-secondary, #888);
}
.nx-viewer-meta span {
    padding: 2px 8px;
    background: var(--bg-overlay, rgba(0,0,0,0.05));
    border-radius: 4px;
}
.nx-viewer-actions { display: flex; gap: 4px; }
.nx-viewer-download, .nx-viewer-close {
    background: none;
    border: none;
    padding: 6px 12px;
    cursor: pointer;
    border-radius: 6px;
    font-size: 14px;
}
.nx-viewer-download:hover, .nx-viewer-close:hover {
    background: var(--bg-hover, rgba(0,0,0,0.08));
}
.nx-viewer-body {
    flex: 1;
    overflow: auto;
    background: var(--bg-input, #f5f5f5);
    position: relative;
}
.nx-viewer-loading, .nx-viewer-error {
    padding: 60px 24px; text-align: center;
    color: var(--text-secondary, #888);
}
.nx-viewer-error { color: #ff3b30; }
.nx-viewer-hint {
    padding: 12px 20px;
    font-size: 13px;
    background: rgba(255, 149, 0, 0.1);
    color: #ff9500;
    text-align: center;
}

.nx-viewer-image-wrap, .nx-viewer-media-wrap, .nx-viewer-audio-wrap {
    display: flex; align-items: center; justify-content: center;
    min-height: 100%;
    padding: 20px;
}
.nx-viewer-image { max-width: 100%; max-height: 100%; object-fit: contain; }
.nx-viewer-video { max-width: 100%; max-height: 100%; border-radius: 8px; }
.nx-viewer-audio-wrap { flex-direction: column; gap: 16px; }
.nx-viewer-audio-name { font-weight: 600; font-size: 16px; }
.nx-viewer-audio { width: 100%; max-width: 500px; }

.nx-viewer-text, .nx-viewer-code {
    margin: 0;
    padding: 24px;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'Menlo', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.6;
    background: var(--bg-overlay, #fff);
    color: var(--text-primary, #1d1d1f);
}
.nx-viewer-md {
    padding: 32px 48px;
    max-width: 860px;
    margin: 0 auto;
    background: var(--bg-overlay, #fff);
    line-height: 1.6;
}
.nx-viewer-md h1, .nx-viewer-md h2, .nx-viewer-md h3 { margin-top: 24px; margin-bottom: 12px; }
.nx-viewer-md pre { background: #2d2d2d; color: #f8f8f2; padding: 16px; border-radius: 8px; overflow-x: auto; }
.nx-viewer-md code { padding: 2px 6px; background: var(--bg-hover, rgba(0,0,0,0.05)); border-radius: 4px; }
.nx-viewer-md pre code { padding: 0; background: none; }
.nx-viewer-md a { color: var(--accent, #007aff); }
.nx-viewer-md table { border-collapse: collapse; width: 100%; }
.nx-viewer-md th, .nx-viewer-md td { border: 1px solid var(--border, #e0e0e0); padding: 8px 12px; }

.nx-pdf-container {
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.nx-pdf-page {
    max-width: 100%;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    border-radius: 4px;
    background: #fff;
}

.nx-viewer-docx {
    padding: 48px 60px;
    max-width: 860px;
    margin: 0 auto;
    background: #fff;
    color: #1d1d1f;
    line-height: 1.6;
    font-family: 'Georgia', serif;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    margin-top: 20px;
    margin-bottom: 20px;
}
.nx-viewer-docx h1, .nx-viewer-docx h2, .nx-viewer-docx h3 { margin-top: 20px; }

.nx-viewer-iframe {
    width: 100%; height: 100%;
    border: none;
    background: #fff;
}

.nx-viewer-minimal {
    padding: 60px 40px;
    text-align: center;
    max-width: 400px;
    margin: 0 auto;
}
.nx-viewer-minimal-icon { font-size: 64px; margin-bottom: 16px; }
.nx-viewer-minimal-name {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    word-break: break-all;
}
.nx-viewer-minimal-type { color: var(--text-secondary, #888); font-size: 13px; margin-bottom: 8px; }
.nx-viewer-minimal-size { color: var(--text-secondary, #888); font-size: 13px; margin-bottom: 16px; }
.nx-viewer-minimal-comment {
    font-size: 14px;
    padding: 12px;
    background: var(--bg-hover, rgba(0,0,0,0.04));
    border-radius: 8px;
    margin-bottom: 20px;
    text-align: left;
}

/* Dark theme */
[data-theme="dark"] .nx-lib-dialog,
[data-theme="dark"] .nx-addlib-dialog,
[data-theme="dark"] .nx-viewer-dialog {
    background: #1c1c1e;
    border: 1px solid rgba(255,255,255,0.08);
}
[data-theme="dark"] .nx-lib-card {
    background: rgba(255,255,255,0.03);
    border-color: rgba(255,255,255,0.08);
}
[data-theme="dark"] .nx-viewer-text,
[data-theme="dark"] .nx-viewer-code,
[data-theme="dark"] .nx-viewer-md {
    background: #1c1c1e;
    color: #f5f5f7;
}
[data-theme="dark"] .nx-form-input {
    background: #2c2c2e;
    color: #f5f5f7;
    border-color: #3a3a3e;
}
[data-theme="dark"] .nx-lib-tree-count {
    background: rgba(255,255,255,0.08);
}

/* ═══ v1.8.6: Voice Recorder Panel ═══ */
.nx-voice-rec-panel {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-overlay, #fff);
    border: 1px solid var(--border, #e0e0e0);
    border-radius: 50px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    z-index: 1500;
    animation: nx-voice-slide 0.22s ease-out;
}
@keyframes nx-voice-slide {
    from { opacity: 0; transform: translate(-50%, 20px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}
.nx-voice-rec-pulse {
    width: 12px; height: 12px;
    background: #ff3b30;
    border-radius: 50%;
    animation: nx-voice-pulse 1s ease-in-out infinite;
    flex-shrink: 0;
}
@keyframes nx-voice-pulse {
    0%, 100% { opacity: 0.8; transform: scale(1); }
    50%      { opacity: 1;   transform: scale(1.3); box-shadow: 0 0 0 6px rgba(255,59,48,0.2); }
}
.nx-voice-rec-info { display: flex; flex-direction: column; gap: 2px; }
.nx-voice-rec-timer { font-family: monospace; font-weight: 600; font-size: 14px; }
.nx-voice-rec-hint { font-size: 11px; color: var(--text-secondary, #888); }
.nx-voice-rec-cancel, .nx-voice-rec-send {
    background: none;
    border: none;
    width: 36px; height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
}
.nx-voice-rec-cancel:hover { background: rgba(255,59,48,0.1); color: #ff3b30; }
.nx-voice-rec-send { background: var(--accent, #007aff); color: #fff; }
.nx-voice-rec-send:hover { background: #0051d0; }

/* ═══ v1.8.6: Media Player (video/audio) ═══ */
.nx-mp-video-wrap, .nx-mp-audio-wrap {
    position: relative;
    width: 100%;
    max-width: 100%;
}
.nx-mp-video {
    position: relative;
    background: #000;
    border-radius: 10px;
    overflow: hidden;
    outline: none;
}
.nx-mp-video-el {
    width: 100%;
    display: block;
    max-height: 70vh;
}
.nx-mp-overlay {
    position: absolute;
    inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.3);
    opacity: 1;
    transition: opacity 0.2s;
    pointer-events: none;
}
.nx-mp-overlay.playing { opacity: 0; }
.nx-mp-big-play {
    pointer-events: auto;
    background: rgba(255,255,255,0.9);
    border: none;
    width: 64px; height: 64px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 22px;
    color: #000;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.nx-mp-controls {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(8px);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    transform: translateY(100%);
    transition: transform 0.2s;
}
.nx-mp-video:hover .nx-mp-controls,
.nx-mp-video:focus-within .nx-mp-controls {
    transform: translateY(0);
}
.nx-mp-btn {
    background: none;
    border: none;
    color: #fff;
    padding: 6px 10px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
    flex-shrink: 0;
}
.nx-mp-btn:hover { background: rgba(255,255,255,0.15); }
.nx-mp-time { font-size: 12px; color: #fff; font-family: monospace; }
.nx-mp-sep { opacity: 0.5; margin: 0 2px; }
.nx-mp-progress {
    flex: 1;
    padding: 0 8px;
}
.nx-mp-progress-bar {
    position: relative;
    height: 5px;
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
    cursor: pointer;
    overflow: hidden;
    transition: height 0.15s;
}
.nx-mp-progress-bar:hover { height: 7px; }
.nx-mp-progress-buf {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    background: rgba(255,255,255,0.4);
    border-radius: 3px;
    width: 0%;
}
.nx-mp-progress-cur {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    background: var(--accent, #007aff);
    border-radius: 3px;
    width: 0%;
    transition: width 0.1s linear;
}
.nx-mp-volume-wrap { display: flex; align-items: center; gap: 4px; }
.nx-mp-vol-slider {
    width: 0;
    opacity: 0;
    transition: width 0.2s, opacity 0.2s;
}
.nx-mp-volume-wrap:hover .nx-mp-vol-slider {
    width: 60px;
    opacity: 1;
}
.nx-mp-speed {
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}

/* Audio player */
.nx-mp-audio {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-hover, rgba(0,0,0,0.04));
    border-radius: 24px;
    max-width: 500px;
}
.nx-mp-audio-play {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--accent, #007aff);
    color: #fff;
    font-size: 14px;
    flex-shrink: 0;
}
.nx-mp-audio-play:hover { background: #0051d0; }
.nx-mp-audio-body { flex: 1; min-width: 0; }
.nx-mp-audio-title {
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 4px;
}
.nx-mp-audio-waveform {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 30px;
    cursor: pointer;
}
.nx-mp-audio-waveform::before {
    /* Линия для случая если нет waveform баров */
    content: '';
    position: absolute;
    top: 50%; left: 0; right: 0;
    height: 3px;
    background: var(--border, #ccc);
    border-radius: 2px;
    z-index: 0;
}
.nx-mp-wave-bar {
    flex: 1;
    background: var(--border, #ccc);
    min-height: 4px;
    border-radius: 1px;
    transition: background 0.15s;
    position: relative;
    z-index: 1;
}
.nx-mp-wave-bar.played {
    background: var(--accent, #007aff);
}
.nx-mp-audio-progress {
    position: absolute;
    top: 50%;
    left: 0;
    height: 3px;
    background: var(--accent, #007aff);
    border-radius: 2px;
    width: 0%;
    transform: translateY(-50%);
    z-index: 0;
}
.nx-mp-audio-times {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: var(--text-secondary, #888);
    font-family: monospace;
    margin-top: 2px;
}
.nx-mp-audio-speed {
    background: var(--bg-overlay, #fff);
    border: 1px solid var(--border, #ddd);
    color: var(--text-primary, #1d1d1f);
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    flex-shrink: 0;
}

[data-theme="dark"] .nx-voice-rec-panel,
[data-theme="dark"] .nx-mp-audio-speed {
    background: #2c2c2e;
    color: #f5f5f7;
    border-color: #3a3a3e;
}
[data-theme="dark"] .nx-mp-audio {
    background: rgba(255,255,255,0.06);
}

/* ═══ v1.8.6: Reply bar text elements ═══ */
.msg-reply-sender {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 2px;
    color: var(--accent, #007aff);
}
.msg-reply-text {
    font-size: 12px;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}