/* --- cabinet.css --- */
:root {
    /* --- Светлая тема (Дефолтная) --- */
    --cab-bg: #f1f5f9;
    --cab-card-bg: rgba(255, 255, 255, 0.9);
    --cab-text: #0f172a;
    --cab-text-muted: #475569;
    --cab-accent: #2563eb;
    --cab-accent-hover: #1d4ed8;
    --cab-border: rgba(148, 163, 184, 0.2);
    --cab-gradient: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
    --cab-success: #10b981;
    --cab-shadow: 0 10px 30px rgba(15, 23, 42, 0.05);
    --cab-gold: #f59e0b;
    --chat-bg-custom: #ffffff;
}

/* --- Классическая сепия тема --- */
[data-theme="sepia"],
.theme-sepia {
    --cab-bg: #f3e1c6;
    --cab-card-bg: rgba(255, 250, 240, 0.9);
    --cab-text: #3e2723;
    --cab-text-muted: #6b4a28;
    --cab-accent: #5d4037;
    --cab-accent-hover: #4b3a2a;
    --cab-border: rgba(100, 80, 60, 0.2);
    --cab-gradient: linear-gradient(135deg, #fdf5e6 0%, #f3e1c6 100%);
    --cab-success: #2e7d32;
    --cab-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    --cab-gold: #FFD700;
    --chat-bg-custom: #ffffff;
}

/* --- Тёмная тема --- */
[data-theme="dark"],
.theme-dark {
    --cab-bg: #0f172a;
    --cab-card-bg: rgba(30, 41, 59, 0.95);
    --cab-text: #f8fafc;
    --cab-text-muted: #94a3b8;
    --cab-accent: #8b5cf6;
    --cab-accent-hover: #a78bfa;
    --cab-border: rgba(148, 163, 184, 0.15);
    --cab-gradient: linear-gradient(135deg, #1e293b 0%, #020617 100%);
    --cab-success: #10b981;
    --cab-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    --cab-gold: #fbbf24;
    --chat-bg-custom: #1e293b;
}

/* --- ОСНОВНОЙ ОВЕРЛЕЙ КАБИНЕТА --- */
.cabinet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--cab-bg);
    z-index: 2000;
    /* Выше змейки (1000) */
    display: none;
    overflow-y: auto;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--cab-text);
    opacity: 0;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(5px);
}

.cabinet-overlay.active {
    display: block;
    opacity: 1;
}

/* --- Settings Only Mode --- */
.cabinet-overlay.settings-only {
    background: rgba(0, 0, 0, 0.4) !important;
    /* Slightly lighter dim */
    backdrop-filter: blur(8px) !important;
    /* Increased blur for focus */
}

.cabinet-overlay.settings-only .cabinet-container {
    display: none !important;
}

/* --- ПОРТИРОВАННЫЕ СТИЛИ ШАПКИ ДЛЯ АВТОНОМНОСТИ --- */
.cabinet-overlay .top-bar,
.snake-overlay .top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 25px;
    background: var(--cab-card-bg) !important;
    border-radius: 16px;
    border: 1px solid var(--cab-border);
    box-shadow: var(--cab-shadow);
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 25px;
}

/* Более компактная шапка для змейки */
.snake-overlay .top-bar {
    padding: 4px 15px;
    margin-bottom: 5px;
}

.cabinet-overlay .top-bar-center,
.snake-overlay .top-bar-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-weight: 800;
    color: var(--accent-color);
    font-size: clamp(0.9rem, 2vw, 1.2rem);
    letter-spacing: 0.3px;
    white-space: nowrap;
    padding: 0 10px;
}

.cabinet-overlay .user-pedestal,
.snake-overlay .user-pedestal {
    display: flex;
    align-items: center;
}

.cabinet-overlay .header-btn,
.snake-overlay .header-btn {
    background: rgba(255, 255, 255, 0.95);
    color: var(--cab-accent);
    border: 1px solid rgba(93, 64, 55, 0.15);
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.9em;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
}

.cabinet-overlay .header-btn:hover {
    background: var(--cab-accent);
    color: white;
    border-color: var(--cab-accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(93, 64, 55, 0.25);
}

.cabinet-overlay .header-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(93, 64, 55, 0.2);
}

.cab-exit-btn-power {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    border: 2px solid rgba(255, 255, 255, 0.9);
    background: #ff5c63;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(255, 92, 99, 0.28);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    flex: 0 0 auto;
}

.cab-exit-btn-power:hover {
    background: #e9464f;
    transform: translateY(-1px);
    box-shadow: 0 9px 22px rgba(255, 92, 99, 0.34);
}

.cab-exit-btn-power svg {
    width: 28px;
    height: 28px;
    stroke-width: 2.5;
}

/* --- РАДУЖНАЯ ЗМЕЙКА (КОНТУРНЫЙ ШИММЕР) --- */
.header-avatar.shimmer {
    position: relative;
    z-index: 1;
    overflow: visible !important;
}

.header-avatar.shimmer::after {
    content: '';
    position: absolute;
    inset: -3px;
    padding: 3px;
    border-radius: 11px;
    /* Медленный сепия-круг (3 цвета) */
    background: conic-gradient(from 0deg,
            #5d4037 0deg,
            /* Коричневый */
            #f3e1c6 120deg,
            /* Сепия */
            #ffffff 240deg,
            /* Белый */
            #5d4037 360deg);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
}

.header-avatar.shimmer:hover::after {
    opacity: 1;
    animation: rotate-snake 12s linear infinite;
}

@keyframes rotate-snake {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.cabinet-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    /* Важно для дочерних fixed элементов, хотя fixed обычно от вьюпорта */
}

/* Main Wrapper for Content */
.cab-main-content-wrapper {
    background: white;
    border-radius: 24px;
    padding: 25px 20px;
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--cab-border);
    margin-bottom: 30px;
}

/* Header Compact */
.cabinet-header-compact {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    background: var(--cab-card-bg);
    padding: 15px 25px;
    border-radius: 16px;
    border: 1px solid var(--cab-border);
    box-shadow: var(--cab-shadow);
}

.cabinet-user-info-mini {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.newsletter-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-left: 20px;
    border-left: 1px solid var(--cab-border);
    height: 40px;
}

.admin-gear-btn {
    transition: transform 0.3s ease;
}

.admin-gear-btn:hover {
    transform: rotate(90deg) scale(1.1);
}

.newsletter-modal {
    max-width: 1150px !important;
    padding: 25px !important;
    height: 85vh !important;
}

.newsletter-editor-container {
    display: flex;
    flex-direction: column;
    gap: 0;
    border: 1px solid var(--cab-border);
    border-radius: 8px;
    background: white;
    overflow: hidden;
}

.rich-text-toolbar {
    display: flex;
    gap: 4px;
    padding: 10px;
    background: #f1f3f5;
    border-bottom: 2px solid var(--cab-border);
    flex-wrap: wrap;
    align-items: center;
}

.rte-group {
    display: flex;
    gap: 2px;
    background: #e9ecef;
    padding: 2px;
    border-radius: 4px;
}

.rich-text-btn {
    padding: 6px 10px;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #495057;
    transition: all 0.2s;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
}

.rich-text-btn:hover {
    background: #f8f9fa;
    border-color: #adb5bd;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.rich-text-select {
    height: 32px;
    padding: 0 5px;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
}

.rte-color-wrapper {
    position: relative;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rte-color-input {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    cursor: pointer;
    background: none;
}

#newsletter-body-rich {
    padding: 15px;
    min-height: 300px;
    overflow-y: auto;
    outline: none;
    font-family: inherit;
    line-height: 1.5;
}

#newsletter-body-rich:focus {
    background: #fff;
}

#newsletter-users-list {
    flex-grow: 1;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.02);
    border: 1px solid var(--cab-border);
    border-radius: 8px;
    padding: 10px;
}

/* Вкладки для черновиков */
.draft-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--cab-border);
    padding-bottom: 5px;
}

.draft-tab {
    padding: 4px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: 4px;
    background: transparent;
    color: var(--cab-text-muted);
    transition: all 0.2s;
}

.draft-tab.active {
    background: var(--cab-accent);
    color: white;
}

.draft-tab:hover:not(.active) {
    background: rgba(0, 0, 0, 0.05);
}

/* Элемент черновика */
.draft-item {
    position: relative;
    padding: 10px;
    background: white;
    border: 1px solid var(--cab-border);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    transition: transform 0.1s;
}

.draft-item:hover {
    border-color: var(--cab-accent);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.draft-item:active {
    transform: scale(0.98);
}

.draft-item.starred {
    border-left: 4px solid #ffd700;
}

.draft-item.active-draft {
    border-color: var(--cab-accent);
    background: #fffbe6;
    box-shadow: 0 0 0 2px rgba(var(--cab-accent-rgb), 0.2);
}

.draft-item.is-sent {
    background: #f6ffed;
    border-color: #b7eb8f;
}

/* Звездочка */
.draft-star {
    font-size: 1.1rem;
    color: #ced4da;
    cursor: pointer;
    transition: color 0.2s;
}

.draft-star.active {
    color: #ffd700;
}

/* Кнопка удаления */
.draft-delete-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    background: #f8f9fa;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #adb5bd;
    font-size: 0.8rem;
    transition: all 0.2s;
    opacity: 0;
}

.draft-item:hover .draft-delete-btn {
    opacity: 1;
}

.draft-delete-btn:hover {
    background: #ff4d4f;
    color: white;
}

/* Глобальное растягивание */
.newsletter-modal {
    max-width: 1250px !important;
    padding: 25px !important;
    height: 90vh !important;
    display: flex;
    flex-direction: column;
}

.newsletter-editor-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#newsletter-body-rich {
    flex-grow: 1;
    min-height: 200px;
}

/* Полка истории отправок */
.sent-history-shelf {
    background: #f8f9fa;
    border-top: 1px solid var(--cab-border);
    padding: 10px;
    max-height: 120px;
    overflow-y: auto;
    font-size: 0.8rem;
}

.history-log-item {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px dashed rgba(0, 0, 0, 0.05);
}

.history-log-item:last-child {
    border-bottom: none;
}

.history-date {
    font-weight: bold;
    color: var(--cab-accent);
    min-width: 140px;
}

.history-recipients {
    flex-grow: 1;
    color: var(--cab-text-muted);
    padding-left: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#newsletter-users-list::-webkit-scrollbar,
#newsletter-drafts-list::-webkit-scrollbar {
    width: 6px;
}

#newsletter-users-list::-webkit-scrollbar-thumb,
#newsletter-drafts-list::-webkit-scrollbar-thumb {
    background: var(--cab-border);
    border-radius: 10px;
}

/* Переопределение Z-index для SweetAlert2, чтобы он всегда был сверху */
.swal2-container {
    z-index: 30000 !important;
}

/* --- СИСТЕМА ЧАТА (v9) --- */

/* Плавающий виджет (как WhatsApp) */
.chat-floating-widget {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    background: #25d366;
    /* Зеленый чат */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    z-index: 1500;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: none;
    outline: none;
    text-decoration: none;
}

.chat-floating-widget:hover {
    transform: scale(1.1);
}

.chat-floating-widget i {
    font-size: 28px;
    color: white;
}

/* Эффект сияния при новых сообщениях */
@keyframes chat-glow {
    0% {
        box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.4);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(37, 211, 102, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(37, 211, 102, 0);
    }
}

.chat-glow {
    animation: chat-glow 2s infinite;
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4d4f;
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: bold;
    border: 2px solid white;
}

/* Модальное окно чата */
.chat-modal-content {
    display: flex;
    width: 900px;
    height: 600px;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    max-width: 95vw;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* Левая панель - Контакты */
.chat-contacts-panel {
    width: 300px;
    border-right: 1px solid #eee;
    display: flex;
    flex-direction: column;
    background: #f9f9f9;
}

.chat-contacts-header {
    padding: 15px;
    font-weight: bold;
    border-bottom: 1px solid #eee;
    background: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-contacts-list {
    flex: 1;
    overflow-y: auto;
}

.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #f0f0f0;
}

.contact-item:hover {
    background: #f0f0f0;
}

.contact-item.active {
    background: #e6f7ff;
    border-left: 4px solid var(--cab-accent);
}

.contact-avatar {
    width: 45px;
    height: 45px;
    background: #ddd;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: white;
    flex-shrink: 0;
    position: relative;
}

.avatar-status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
    z-index: 5;
    transition: background-color 0.3s, box-shadow 0.3s;
}

.avatar-status-dot.online {
    background: #25d366;
    box-shadow: 0 0 6px rgba(37, 211, 102, 0.6);
}

.avatar-status-dot.offline {
    background: #ff4d4f;
    box-shadow: 0 0 6px rgba(255, 77, 79, 0.4);
}

.contact-info {
    flex: 1;
    min-width: 0;
}

.contact-name {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-last-msg {
    font-size: 0.8rem;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unread-dot {
    width: 10px;
    height: 10px;
    background: var(--cab-accent);
    border-radius: 50%;
    margin-left: auto;
}

/* Правая панель - Сообщения */
.chat-main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
}

.chat-main-header {
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    font-weight: 600;
}

.chat-messages-area {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #e5ddd5;
    /* Фон как в WhatsApp */
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Пузыри сообщений */
.msg-bubble-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    flex-direction: row-reverse;
    /* Помещает чекбокс вправо от пузыря */
}

.msg-bubble-wrapper.mine {
    justify-content: flex-start;
    /* Выравнивание всего блока вправо */
}

.msg-bubble-wrapper.theirs {
    justify-content: flex-end;
    /* Выравнивание всего блока влево */
}

.msg-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.95rem;
    line-height: 1.45;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.msg-bubble.mine {
    background: #dcf8c6;
    border-bottom-right-radius: 4px;
}

.msg-bubble.theirs {
    background: white;
    border-bottom-left-radius: 4px;
}

.msg-time {
    font-size: 0.7rem;
    color: #999;
    margin-top: 4px;
    text-align: right;
}

/* Область ввода */
.chat-input-area {
    padding: 15px;
    border-top: 1px solid #eee;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: #f0f0f0;
}

.chat-input {
    flex: 1;
    background: white;
    border-radius: 20px;
    padding: 10px 15px;
    border: 1px solid #ddd;
    outline: none;
    max-height: 100px;
    overflow-y: auto;
    font-size: 0.95rem;
}

.chat-input:empty:before {
    content: attr(placeholder);
    color: #aaa;
}

.chat-send-btn {
    background: var(--cab-accent);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    transform: scale(1.1);
}

.chat-mobile-close-btn,
.chat-mobile-thread-close {
    display: none;
}

.chat-emoji-btn {
    font-size: 1.5rem;
    cursor: pointer;
    user-select: none;
    padding: 5px;
}

/* Панель смайликов */
.emoji-picker {
    position: absolute;
    bottom: 80px;
    right: 20px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    z-index: 1600;
}

.emoji-item {
    font-size: 1.5rem;
    cursor: pointer;
    text-align: center;
    transition: transform 0.1s;
}

.emoji-item:hover {
    transform: scale(1.2);
}

/* Адаптивность для мобилок */
@media (max-width: 768px) {
    .chat-modal-content {
        flex-direction: column;
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }

    .chat-contacts-panel {
        width: 100%;
        height: 150px;
    }
}

@media (max-width: 600px) {
    #chat-admin-modal.cab-modal-overlay {
        align-items: stretch !important;
        justify-content: stretch !important;
        padding: 0 !important;
        background: rgba(0, 0, 0, 0.42) !important;
    }

    #chat-admin-modal .chat-modal-layout {
        width: 100vw !important;
        height: 100dvh !important;
        max-width: 100vw !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        overflow: hidden !important;
        position: relative !important;
        display: block !important;
    }

    #chat-admin-modal .chat-contacts-panel,
    #chat-admin-modal .chat-main-panel {
        position: absolute !important;
        inset: 0 !important;
        width: 100% !important;
        height: 100% !important;
        min-height: 100dvh !important;
        border: 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    #chat-admin-modal .chat-contacts-panel {
        z-index: 1 !important;
    }

    #chat-admin-modal .chat-main-panel {
        z-index: 2 !important;
        transform: translateX(100%) !important;
        transition: transform 0.22s ease !important;
        background: #fff !important;
    }

    #chat-admin-modal.mobile-thread-open .chat-main-panel {
        transform: translateX(0) !important;
    }

    #chat-admin-modal .chat-panel-header {
        min-height: 58px !important;
        flex: 0 0 auto !important;
        padding: 10px 14px !important;
        box-sizing: border-box !important;
    }

    #chat-admin-modal .chat-contacts-list,
    #chat-admin-modal .chat-messages-area {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
    }

    #chat-admin-modal .chat-messages-area {
        padding: 16px 14px !important;
    }

    #chat-admin-modal .chat-input-wrapper {
        flex: 0 0 auto !important;
        padding: 10px 12px max(10px, env(safe-area-inset-bottom)) !important;
        box-sizing: border-box !important;
    }

    #chat-admin-modal .chat-search-container {
        flex: 0 0 auto !important;
    }

    .chat-mobile-close-btn,
    .chat-mobile-thread-close {
        width: 38px;
        height: 38px;
        border-radius: 50%;
        border: 0;
        background: transparent;
        color: #111;
        font-size: 30px;
        line-height: 1;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }

    #chat-admin-modal #chat-main-header button[onclick*="closest"] {
        display: none !important;
    }
}

.user-recipient-check:checked+span {
    font-weight: bold;
    color: var(--cab-accent);
}

.cabinet-avatar-small {
    width: 60px;
    height: 60px;
    background: #fff;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    border: none;
    color: var(--cab-accent);
}

.user-rank-mini {
    color: var(--cab-text-muted);
    font-size: 14px;
    margin-top: 2px;
}

.cabinet-actions-row {
    display: flex;
    gap: 10px;
}

/* Actions */
.cabinet-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cab-btn {
    padding: 12px 24px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
}

.cab-btn-primary {
    background: var(--cab-accent);
    color: white;
}

.cab-btn-primary:hover {
    background: var(--cab-accent-hover);
    transform: translateY(-2px);
}

.cab-btn-secondary {
    background: rgba(255, 255, 255, 0.5);
    color: var(--cab-accent);
    border: 1px solid var(--cab-border);
}

.cab-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.8);
}

/* Grid */
.cabinet-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.cab-card {
    background: var(--cab-card-bg);
    padding: 12px;
    border-radius: 14px;
    border: 1px solid var(--cab-border);
    transition: 0.3s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.02);
}

.cab-card:hover {
    border-color: var(--cab-accent);
    transform: translateY(-3px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
}

.cab-card h3 {
    margin: 0 0 10px 0;
    font-size: 15px;
    color: var(--cab-accent);
    display: flex;
    align-items: center;
    gap: 6px;
}

.cab-stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 13px;
}

.cab-stat-label {
    color: var(--cab-text-muted);
}

.cab-stat-value {
    font-weight: 600;
    color: var(--cab-accent);
}

.word-logic-hint {
    cursor: help;
    margin-left: 4px;
    font-size: 14px;
    vertical-align: middle;
    filter: sepia(0.5);
    transition: 0.2s;
}

.word-logic-hint:hover {
    filter: sepia(0);
    transform: scale(1.2);
}

/* Activity Calendar */
.activity-section {
    background: var(--cab-card-bg);
    padding: 20px;
    border-radius: 14px;
    border: 1px solid var(--cab-border);
    box-shadow: var(--cab-shadow);
}

.activity-section h3 {
    margin-top: 0;
    margin-bottom: 10px;
    color: var(--cab-accent);
    font-size: 1.1rem;
}

.activity-grid-placeholder {
    height: 120px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--cab-text-muted);
    border: 1px dashed var(--cab-border);
}

/* Tabs */
.cabinet-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 15px;
    overflow-x: auto;
    padding-bottom: 5px;
}

.cab-tab {
    padding: 6px 14px;
    background: var(--cab-card-bg);
    border: 1px solid var(--cab-border);
    border-radius: 30px;
    color: var(--cab-text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: 0.2s;
    font-weight: 500;
}

.cab-tab.active {
    background: var(--cab-accent);
    color: white;
    border-color: var(--cab-accent);
}

/* --- МОДАЛЬНЫЕ ОКНА (SPA) --- */
.cab-modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(0, 0, 0, 0.5) !important;
    backdrop-filter: blur(8px) !important;
    z-index: 2200 !important;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#cab-edit-name-modal,
#cab-password-modal {
    z-index: 2300 !important;
}

.cab-modal-overlay.active {
    display: flex !important;
    opacity: 1 !important;
}

.cab-modal-content {
    background: #fffaf0 !important;
    width: 95% !important;
    max-width: 700px !important;
    max-height: 85vh !important;
    border-radius: 24px !important;
    border: 3px solid var(--cab-accent) !important;
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.5) !important;
    padding: 25px !important;
    transform: translateY(20px);
    transition: transform 0.3s ease;
    text-align: center;
    position: relative;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.cab-modal-overlay.active .cab-modal-content {
    transform: translateY(0);
}

/* Стили для кнопок в настройках внутри модалки */
.cab-settings-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.cab-settings-item {
    display: flex;
    align-items: center;
    padding: 14px 18px;
    background: #fff;
    border: 1px solid var(--cab-border);
    border-radius: 14px;
    cursor: pointer;
    transition: 0.2s;
    text-decoration: none;
    color: var(--cab-text);
    box-sizing: border-box;
}

.cab-settings-item:hover {
    transform: translateY(-2px);
    border-color: var(--cab-accent);
    background: #fffaf5;
}

.cab-settings-item .icon {
    font-size: 1.3em;
    margin-right: 12px;
}

.cab-settings-item .text {
    flex-grow: 1;
    font-weight: 600;
    text-align: left;
}

.cab-settings-item .arrow {
    color: var(--cab-accent);
    opacity: 0.5;
}

.cab-settings-logout {
    margin-top: 10px;
    background: #fff0f0;
    color: #d32f2f;
    border-color: #f8d7da;
}

/* Формы */
.cab-input-group {
    margin-bottom: 20px;
    text-align: left;
}

.cab-input-group label {
    display: block;
    font-size: 0.9rem;
    color: var(--cab-text-muted);
    margin-bottom: 6px;
    font-weight: 600;
}

.cab-input-spa {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--cab-border);
    border-radius: 12px;
    font-size: 1rem;
    box-sizing: border-box;
    outline: none;
    background: white;
}

.cab-input-spa:focus {
    border-color: var(--cab-accent);
    box-shadow: 0 0 0 3px rgba(93, 64, 55, 0.1);
}

/* --- ТАБЛИЦА РЕЙТИНГОВ --- */
.ratings-table-container {
    background: white;
    border-radius: 16px;
    border: 1px solid var(--cab-border);
    overflow-y: auto;
    margin: 10px 0;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    flex-grow: 1;
}

.ratings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    text-align: left;
}

.ratings-table th {
    background: #f8f1e5;
    color: var(--cab-accent);
    padding: 14px 15px;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 1px;
    border-bottom: 2px solid var(--cab-border);
}

.ratings-table td {
    padding: 14px 15px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}

.ratings-table tr:last-child td {
    border-bottom: none;
}

.ratings-table tr:hover {
    background: #fffcf5;
}

.ratings-table tr.top-rank {
    background: rgba(255, 215, 0, 0.03);
}

.ratings-table tr.rank-1 {
    background: rgba(255, 215, 0, 0.08);
}

.ratings-table tr.rank-2 {
    background: rgba(192, 192, 192, 0.08);
}

.ratings-table tr.rank-3 {
    background: rgba(205, 127, 50, 0.08);
}

.user-cell {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar-mini {
    width: 32px;
    height: 32px;
    background: #fff;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--cab-border);
}

.user-name {
    font-weight: 600;
    color: var(--cab-text);
}

.level-badge {
    background: var(--cab-accent);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 800;
}


.stat-value {
    font-weight: 700;
    color: var(--cab-accent);
}

/* Emoji Picker & Notifications */
.emoji-trigger {
    cursor: pointer;
    font-size: 1.4rem;
    padding: 5px;
    transition: transform 0.2s;
}

.emoji-trigger:hover {
    transform: scale(1.15);
}

.emoji-palette {
    position: absolute;
    bottom: 70px;
    left: 15px;
    background: white;
    border: 1px solid var(--cab-border);
    border-radius: 12px;
    padding: 10px;
    display: none;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
}

.emoji-palette.active {
    display: grid;
}

.emoji-item {
    cursor: pointer;
    font-size: 1.4rem;
    padding: 5px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.emoji-item:hover {
    background: #f0f2f5;
}

@keyframes chatGlow {
    0% {
        filter: drop-shadow(0 0 5px var(--cab-gold));
        transform: scale(1);
    }

    50% {
        filter: drop-shadow(0 0 15px var(--cab-gold));
        transform: scale(1.05);
    }

    100% {
        filter: drop-shadow(0 0 5px var(--cab-gold));
        transform: scale(1);
    }
}

.chat-glow {
    animation: chatGlow 1.5s infinite ease-in-out;
}

/* --- СИСТЕМА ЧАТА (v9) --- */
.chat-floating-widget {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 65px;
    height: 65px;
    background: #25d366;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(37, 211, 102, 0.4);
    cursor: pointer;
    z-index: 2000;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chat-floating-widget:hover {
    transform: scale(1.1) rotate(5deg);
}

.chat-glow {
    animation: chat-glow-pulse 2s infinite;
}

@keyframes chat-glow-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.7);
    }

    70% {
        box-shadow: 0 0 0 20px rgba(37, 211, 102, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(37, 211, 102, 0);
    }
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff3b30;
    color: white;
    border-radius: 50%;
    min-width: 22px;
    height: 22px;
    padding: 2px;
    font-size: 0.75rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

.chat-btn-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ff4d4f;
    color: white;
    border-radius: 10px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    font-size: 10px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

/* Chat Modal Layout */
.chat-modal-layout {
    display: flex !important;
    width: 1150px !important;
    /* Увеличено */
    height: 85vh !important;
    max-width: 95vw !important;
    max-height: 900px !important;
    background: white !important;
    border-radius: 16px !important;
    overflow: visible !important;
    /* ВАЖНО для выноса палитры */
    position: relative !important;
}

.chat-contacts-panel {
    width: 360px !important;
    /* Увеличено */
    border-right: 1px solid var(--cab-border) !important;
    display: flex !important;
    flex-direction: column !important;
    background: #f9f9f9 !important;
}

.chat-main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-panel-header {
    padding: 15px 20px;
    background: #f0f2f5;
    border-bottom: 1px solid var(--cab-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-contacts-list {
    flex: 1;
    overflow-y: auto;
}

.contact-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    cursor: pointer;
    transition: 0.2s;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

.contact-item:hover {
    background: #f0f2f5;
}

.contact-item.active {
    background: #ebebeb;
}

.contact-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: var(--cab-accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-right: 12px;
    flex-shrink: 0;
}

.contact-info {
    flex-grow: 1;
    overflow: hidden;
}

.contact-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--cab-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-last-msg {
    font-size: 0.8rem;
    color: var(--cab-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.unread-badge {
    background: #25d366;
    color: white;
    border-radius: 50%;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 0.7rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* Messages Area */
.chat-messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--chat-bg-custom, #fff);
    transition: background 0.5s ease;
    position: relative;
}

.chat-messages-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: var(--chat-pattern, none);
    opacity: var(--chat-bg-opacity, 0.1);
    pointer-events: none;
}

.msg-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.95rem;
    position: relative;
    line-height: 1.4;
    word-wrap: break-word;
    transition: background 0.2s;
}

.msg-actions {
    position: absolute;
    top: -12px;
    right: 5px;
    display: none;
    gap: 4px;
    z-index: 10;
}

.msg-bubble.mine:hover .msg-actions {
    display: flex;
}

.msg-action-btn {
    background: white;
    border: 1px solid var(--cab-border);
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    color: var(--cab-text);
}

.msg-action-btn:hover {
    background: #f0f0f0;
    transform: scale(1.1);
}

.msg-bubble.is-editing {
    background: #fff9c4 !important;
    outline: 2px solid var(--cab-gold);
}

.msg-bubble.theirs {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--cab-border);
    border-bottom-left-radius: 2px;
}

.msg-bubble.mine {
    align-self: flex-end;
    background: #dcf8c6;
    border-bottom-right-radius: 2px;
}

.msg-time {
    font-size: 0.7rem;
    color: #999;
    margin-top: 4px;
    text-align: right;
}

/* Input Area */
.chat-input-wrapper {
    padding: 12px 15px;
    background: #f0f2f5;
    display: flex;
    align-items: center;
    gap: 10px;
    border-top: 1px solid var(--cab-border);
}

.chat-search-container {
    padding: 8px 12px;
    background: #f9f9f9;
    border-bottom: 1px solid var(--cab-border);
    position: relative;
    display: flex;
    align-items: center;
}

.chat-search-box {
    width: 100%;
    padding: 6px 30px 6px 15px;
    border-radius: 20px;
    border: 1px solid var(--cab-border);
    font-size: 0.85rem;
    outline: none;
    transition: all 0.2s;
}

.chat-search-clear {
    position: absolute;
    right: 22px;
    cursor: pointer;
    color: #999;
    font-size: 1.2rem;
    display: none;
    user-select: none;
}

.chat-search-clear.active {
    display: block;
}

.chat-search-box:focus {
    border-color: var(--cab-accent);
    background: white;
}

.chat-input-field {
    flex: 1;
    background: white;
    border-radius: 25px;
    padding: 10px 18px;
    max-height: 100px;
    overflow-y: auto;
    outline: none;
    font-size: 0.95rem;
    border: 1px solid var(--cab-border);
}

.chat-info-hint {
    font-size: 0.8rem;
    color: var(--cab-text-muted);
    cursor: help;
    padding: 5px;
}

.chat-send-btn {
    background: white;
    color: var(--cab-accent);
    border: 1px solid var(--cab-border);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.2rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.chat-send-btn:hover {
    background: #f0f2f5;
    transform: scale(1.05);
    border-color: var(--cab-accent);
}

.chat-send-btn:active {
    transform: scale(0.95);
}

/* Optimistic UI styles */
.msg-bubble.is-sending {
    opacity: 0.6;
}

.msg-status-label {
    font-size: 0.6rem;
    color: #666;
    font-style: italic;
    margin-right: 5px;
}

/* Theme / Emoji */
.theme-picker-btn,
.emoji-trigger {
    font-size: 1.3rem;
    cursor: pointer;
    user-select: none;
    padding: 4px;
    border-radius: 50%;
    transition: 0.2s;
}

.theme-picker-btn:hover,
.emoji-trigger:hover {
    background: rgba(0, 0, 0, 0.05);
}

.emoji-palette {
    position: absolute;
    bottom: 80px;
    left: 20px;
    background: white;
    border: 1px solid var(--cab-border);
    border-radius: 15px;
    padding: 10px;
    display: none;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    z-index: 1000;
}

.emoji-palette.active {
    display: grid;
}

.emoji-item {
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.2s;
    text-align: center;
}

.emoji-item:hover {
    transform: scale(1.2);
}

.theme-dropdown {
    position: absolute;
    top: 0;
    left: calc(100% + 20px);
    /* Вынос ВПРАВО за пределы окна */
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    padding: 15px;
    display: none;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    z-index: 20000 !important;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.4);
    animation: slideRight 0.3s ease-out;
}

@keyframes slideRight {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.theme-dropdown.active {
    display: grid;
}

.theme-swatch {
    width: 35px;
    height: 35px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

.theme-swatch:hover {
    transform: scale(1.15);
}

/* --- ДЕТАЛЬНЫЕ МОДАЛКИ (Detail Modals) --- */
.cab-card.clickable {
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.cab-card.clickable:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    border-color: var(--cab-accent-light);
}

.detail-modal {
    max-width: 400px !important;
    background: #fff8f0 !important;
}

.details-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 0.95rem;
}

.details-table th {
    text-align: left;
    padding: 12px;
    background: rgba(93, 64, 55, 0.05);
    color: var(--cab-accent);
    border-bottom: 2px solid var(--cab-border);
}

.details-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--cab-border);
}

.details-table tr:last-child td {
    border-bottom: none;
}

.details-table tfoot td {
    padding: 12px;
    background: rgba(93, 64, 55, 0.03);
    font-weight: 700;
    color: var(--cab-accent);
    border-top: 2px solid var(--cab-border);
}

.details-table tr:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* Вкладки в детальной модалке */
.cab-detail-tabs {
    display: flex;
    gap: 10px;
    width: 100%;
    margin-bottom: 5px;
}

.det-tab {
    flex: 1;
    padding: 10px;
    background: rgba(93, 64, 55, 0.05);
    border-radius: 10px 10px 0 0;
    cursor: pointer;
    font-weight: 700;
    color: var(--cab-text-muted);
    transition: all 0.2s;
    text-align: center;
    border-bottom: 2px solid transparent;
}

.det-tab:hover {
    background: rgba(93, 64, 55, 0.1);
}

.det-tab.active {
    background: #fff;
    color: var(--cab-accent);
    border-bottom: 2px solid var(--cab-accent);
}

.cab-modal-header.no-close {
    display: flex;
    justify-content: center;
    padding-bottom: 0;
}

.cab-modal-header.no-close .cab-modal-close {
    display: none;
}

.srs-info-row {
    border: 1px solid var(--cab-border);
    animation: fadeInStat 0.4s ease;
}

@keyframes fadeInStat {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.level-badge {
    background: var(--cab-accent);
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 800;
}

.stat-value {
    font-weight: 700;
    color: var(--cab-accent);
}

/* Archive & Selection Mode */
.contact-item.selection-mode {
    padding-left: 10px;
}

.contact-checkbox-wrapper {
    margin-right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.contact-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--cab-accent);
}

#chat-mass-actions {
    transition: all 0.3s ease;
    border-bottom: 2px solid var(--cab-border);
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#chat-contacts-title {
    transition: color 0.3s;
}

.is-archived-view #chat-contacts-title {
    color: var(--cab-accent);
}

/* Mobile cabinet polish */
@media (max-width: 600px) {
    .cabinet-overlay .cabinet-container {
        width: 100% !important;
        max-width: none !important;
        min-height: 100dvh !important;
        padding: max(12px, env(safe-area-inset-top)) 10px max(16px, env(safe-area-inset-bottom)) !important;
        box-sizing: border-box !important;
    }

    .cabinet-overlay .top-bar {
        display: grid !important;
        grid-template-columns: minmax(62px, auto) minmax(0, 1fr) auto !important;
        align-items: center !important;
        gap: 8px !important;
        min-height: 58px !important;
        padding: 8px 10px !important;
        margin-bottom: 14px !important;
        border-radius: 14px !important;
        overflow: hidden !important;
    }

    .cabinet-overlay .top-bar>div:first-child {
        min-width: 0 !important;
    }

    .cabinet-overlay .top-bar .header-btn {
        height: 38px !important;
        padding: 0 9px !important;
        border-radius: 12px !important;
        font-size: clamp(0.78rem, 3.2vw, 0.92rem) !important;
        white-space: nowrap !important;
        min-width: 0 !important;
    }

    .cabinet-overlay .top-bar-center {
        position: static !important;
        transform: none !important;
        left: auto !important;
        min-width: 0 !important;
        text-align: center !important;
        justify-self: center !important;
        width: 100% !important;
    }

    .cabinet-overlay .top-bar-center>div {
        font-size: clamp(0.9rem, 4.6vw, 1.25rem) !important;
        line-height: 1.05 !important;
        max-width: 100% !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        letter-spacing: 0 !important;
    }

    .cabinet-overlay .top-bar>.user-pedestal {
        justify-self: end !important;
        min-width: 0 !important;
        gap: 6px !important;
        padding: 0 !important;
        background: transparent !important;
        border: 0 !important;
    }

    .cabinet-overlay .top-bar .cab-header-user-block {
        margin-right: 0 !important;
        gap: 6px !important;
    }

    .cabinet-overlay .top-bar .user-name-container {
        display: none !important;
    }

    .cabinet-overlay .top-bar .header-avatar {
        width: 34px !important;
        height: 34px !important;
        font-size: 18px !important;
        border-radius: 10px !important;
    }

    .cabinet-overlay .cab-exit-btn-power {
        width: 42px !important;
        height: 42px !important;
        border-radius: 12px !important;
        border-width: 2px !important;
        box-shadow: 0 5px 14px rgba(255, 92, 99, 0.24) !important;
    }

    .cabinet-overlay .cab-exit-btn-power svg {
        width: 24px !important;
        height: 24px !important;
    }

    .cab-main-content-wrapper {
        padding: 14px 10px !important;
        border-radius: 18px !important;
    }

    .cabinet-header-compact {
        padding: 12px !important;
        border-radius: 16px !important;
    }

    .cabinet-user-info-mini {
        align-items: center !important;
        gap: 10px !important;
    }

    .cabinet-user-info-mini>div:first-child {
        min-width: 0 !important;
        gap: 10px !important;
    }

    .cabinet-avatar-small {
        width: 54px !important;
        height: 54px !important;
        font-size: 28px !important;
        flex: 0 0 auto !important;
    }

    .cabinet-user-details-compact {
        min-width: 0 !important;
    }

    .cabinet-user-details-compact h2 {
        font-size: clamp(1.15rem, 6vw, 1.55rem) !important;
        line-height: 1.1 !important;
        overflow-wrap: anywhere !important;
    }

    .user-rank-mini {
        font-size: clamp(0.82rem, 3.8vw, 1rem) !important;
        line-height: 1.42 !important;
    }

    .newsletter-controls {
        padding-left: 10px !important;
        gap: 6px !important;
        flex: 0 0 auto !important;
    }

    .newsletter-controls span {
        font-size: clamp(0.76rem, 3.2vw, 0.9rem) !important;
    }

    .cabinet-tabs {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 8px !important;
        overflow: visible !important;
        padding-bottom: 0 !important;
        margin-bottom: 14px !important;
    }

    .cab-tab {
        min-width: 0 !important;
        width: 100% !important;
        padding: 10px 6px !important;
        border-radius: 20px !important;
        font-size: clamp(0.78rem, 3.6vw, 0.95rem) !important;
        line-height: 1.1 !important;
        text-align: center !important;
        justify-content: center !important;
        white-space: normal !important;
    }
}

/* --- ГЛОБАЛЬНАЯ АДАПТАЦИЯ КАБИНЕТА ПОД СЕМЕЙСТВА ТЕМ TriLingva --- */
[data-theme="dark"] .cab-main-content-wrapper,
.theme-dark .cab-main-content-wrapper {
    background: var(--cab-card-bg, rgba(30, 41, 59, 0.95)) !important;
    border-color: var(--cab-border, rgba(148, 163, 184, 0.15)) !important;
    color: var(--cab-text, #f8fafc) !important;
    box-shadow: var(--cab-shadow, 0 10px 30px rgba(0, 0, 0, 0.4)) !important;
}

[data-theme="sepia"] .cab-main-content-wrapper,
.theme-sepia .cab-main-content-wrapper {
    background: var(--cab-card-bg, rgba(255, 250, 240, 0.9)) !important;
    border-color: var(--cab-border, rgba(100, 80, 60, 0.2)) !important;
    color: var(--cab-text, #3e2723) !important;
    box-shadow: var(--cab-shadow, 0 10px 30px rgba(0, 0, 0, 0.1)) !important;
}

[data-theme="dark"] .draft-item,
.theme-dark .draft-item {
    background: var(--paper-color, #0f172a) !important;
    border-color: var(--cab-border) !important;
    color: var(--cab-text) !important;
}

[data-theme="sepia"] .draft-item,
.theme-sepia .draft-item {
    background: var(--paper-color, #faf3e0) !important;
    border-color: var(--cab-border) !important;
    color: var(--cab-text) !important;
}

[data-theme="dark"] .newsletter-editor-container,
.theme-dark .newsletter-editor-container,
[data-theme="dark"] #newsletter-body-rich,
.theme-dark #newsletter-body-rich {
    background: var(--paper-color, #0f172a) !important;
    color: var(--cab-text) !important;
}

[data-theme="sepia"] .newsletter-editor-container,
.theme-sepia .newsletter-editor-container,
[data-theme="sepia"] #newsletter-body-rich,
.theme-sepia #newsletter-body-rich {
    background: var(--paper-color, #faf3e0) !important;
    color: var(--cab-text) !important;
}

[data-theme="dark"] .rich-text-toolbar,
.theme-dark .rich-text-toolbar {
    background: #1e293b !important;
    border-bottom-color: var(--cab-border) !important;
}

[data-theme="sepia"] .rich-text-toolbar,
.theme-sepia .rich-text-toolbar {
    background: #faf3e0 !important;
    border-bottom-color: var(--cab-border) !important;
}

[data-theme="dark"] .rich-text-btn,
.theme-dark .rich-text-btn {
    background: #0f172a !important;
    border-color: var(--cab-border) !important;
    color: var(--cab-text) !important;
}

[data-theme="sepia"] .rich-text-btn,
.theme-sepia .rich-text-btn {
    background: #faf3e0 !important;
    border-color: var(--cab-border) !important;
    color: var(--cab-text) !important;
}

/* ========================================================================
   ПОЛНАЯ ТЁМНАЯ И СЕПИЯ ТЕМА ДЛЯ МОДАЛОК, НАСТРОЕК, РЕЙТИНГОВ, ЧАТА
   ======================================================================== */

/* --- Модальное окно (фон контента) --- */
[data-theme="dark"] .cab-modal-content,
.theme-dark .cab-modal-content {
    background: #1e293b !important;
    color: var(--cab-text) !important;
    border-color: var(--cab-accent) !important;
}

[data-theme="sepia"] .cab-modal-content,
.theme-sepia .cab-modal-content {
    background: #faf3e0 !important;
    color: var(--cab-text) !important;
}

/* --- Детальная модалка (Словари/Прохождение) --- */
[data-theme="dark"] .detail-modal,
.theme-dark .detail-modal {
    background: #1e293b !important;
}

[data-theme="sepia"] .detail-modal,
.theme-sepia .detail-modal {
    background: #faf3e0 !important;
}

/* --- Пункты настроек --- */
[data-theme="dark"] .cab-settings-item,
.theme-dark .cab-settings-item {
    background: rgba(30, 41, 59, 0.8) !important;
    border-color: var(--cab-border) !important;
    color: var(--cab-text) !important;
}

[data-theme="dark"] .cab-settings-item:hover,
.theme-dark .cab-settings-item:hover {
    background: rgba(139, 92, 246, 0.15) !important;
    border-color: var(--cab-accent) !important;
}

[data-theme="sepia"] .cab-settings-item,
.theme-sepia .cab-settings-item {
    background: rgba(250, 243, 224, 0.8) !important;
    border-color: var(--cab-border) !important;
    color: var(--cab-text) !important;
}

[data-theme="sepia"] .cab-settings-item:hover,
.theme-sepia .cab-settings-item:hover {
    background: rgba(93, 64, 55, 0.08) !important;
}

/* --- Кнопка Выйти в настройках --- */
[data-theme="dark"] .cab-settings-logout,
.theme-dark .cab-settings-logout {
    background: rgba(244, 67, 54, 0.12) !important;
    color: #ef5350 !important;
    border-color: rgba(244, 67, 54, 0.25) !important;
}

[data-theme="sepia"] .cab-settings-logout,
.theme-sepia .cab-settings-logout {
    background: rgba(211, 47, 47, 0.06) !important;
    color: #c62828 !important;
    border-color: rgba(211, 47, 47, 0.15) !important;
}

/* --- Поля ввода --- */
[data-theme="dark"] .cab-input-spa,
.theme-dark .cab-input-spa {
    background: #0f172a !important;
    color: var(--cab-text) !important;
    border-color: var(--cab-border) !important;
}

[data-theme="dark"] .cab-input-spa:focus,
.theme-dark .cab-input-spa:focus {
    border-color: var(--cab-accent) !important;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2) !important;
}

[data-theme="sepia"] .cab-input-spa,
.theme-sepia .cab-input-spa {
    background: #fdf5e6 !important;
    color: var(--cab-text) !important;
    border-color: var(--cab-border) !important;
}

/* --- Таблица рейтингов --- */
[data-theme="dark"] .ratings-table-container,
.theme-dark .ratings-table-container {
    background: #0f172a !important;
    border-color: var(--cab-border) !important;
}

[data-theme="dark"] .ratings-table th,
.theme-dark .ratings-table th {
    background: rgba(139, 92, 246, 0.15) !important;
    color: var(--cab-accent) !important;
    border-bottom-color: var(--cab-border) !important;
}

[data-theme="dark"] .ratings-table td,
.theme-dark .ratings-table td {
    border-bottom-color: rgba(148, 163, 184, 0.1) !important;
    color: var(--cab-text) !important;
}

[data-theme="dark"] .ratings-table tr:hover,
.theme-dark .ratings-table tr:hover {
    background: rgba(139, 92, 246, 0.08) !important;
}

[data-theme="sepia"] .ratings-table-container,
.theme-sepia .ratings-table-container {
    background: #fdf5e6 !important;
    border-color: var(--cab-border) !important;
}

[data-theme="sepia"] .ratings-table th,
.theme-sepia .ratings-table th {
    background: rgba(93, 64, 55, 0.08) !important;
}

[data-theme="sepia"] .ratings-table tr:hover,
.theme-sepia .ratings-table tr:hover {
    background: rgba(93, 64, 55, 0.04) !important;
}

/* --- Мини-аватар в рейтинге --- */
[data-theme="dark"] .user-avatar-mini,
.theme-dark .user-avatar-mini {
    background: #1e293b !important;
    border-color: var(--cab-border) !important;
}

/* --- Emoji палитра --- */
[data-theme="dark"] .emoji-palette,
.theme-dark .emoji-palette {
    background: #1e293b !important;
    border-color: var(--cab-border) !important;
}

[data-theme="dark"] .emoji-item:hover,
.theme-dark .emoji-item:hover {
    background: rgba(139, 92, 246, 0.15) !important;
}

[data-theme="sepia"] .emoji-palette,
.theme-sepia .emoji-palette {
    background: #faf3e0 !important;
    border-color: var(--cab-border) !important;
}

/* --- Вкладки в детальной модалке --- */
[data-theme="dark"] .det-tab,
.theme-dark .det-tab {
    background: rgba(139, 92, 246, 0.08) !important;
    color: var(--cab-text-muted) !important;
}

[data-theme="dark"] .det-tab:hover,
.theme-dark .det-tab:hover {
    background: rgba(139, 92, 246, 0.15) !important;
}

[data-theme="dark"] .det-tab.active,
.theme-dark .det-tab.active {
    background: #1e293b !important;
    color: var(--cab-accent) !important;
}

/* --- SRS инфо-строка --- */
[data-theme="dark"] .srs-info-row,
.theme-dark .srs-info-row {
    background: rgba(139, 92, 246, 0.08) !important;
    color: var(--cab-accent) !important;
}

/* --- Details-table заголовки и строки --- */
[data-theme="dark"] .details-table th,
.theme-dark .details-table th {
    background: rgba(139, 92, 246, 0.1) !important;
}

[data-theme="dark"] .details-table tfoot td,
.theme-dark .details-table tfoot td {
    background: rgba(139, 92, 246, 0.06) !important;
}

[data-theme="dark"] .details-table tr:hover,
.theme-dark .details-table tr:hover {
    background: rgba(139, 92, 246, 0.06) !important;
}

/* --- Карточки профиля пользователя из лидерборда --- */
[data-theme="dark"] .cab-card,
.theme-dark .cab-card {
    background: var(--cab-card-bg) !important;
    border-color: var(--cab-border) !important;
    color: var(--cab-text) !important;
}

[data-theme="sepia"] .cab-card,
.theme-sepia .cab-card {
    background: var(--cab-card-bg) !important;
    border-color: var(--cab-border) !important;
    color: var(--cab-text) !important;
}

/* --- Хедер кабинета (шапка с кнопкой назад) --- */
[data-theme="dark"] .cabinet-overlay .header-btn,
.theme-dark .cabinet-overlay .header-btn {
    background: rgba(30, 41, 59, 0.9) !important;
    color: var(--cab-accent) !important;
    border-color: var(--cab-border) !important;
}

[data-theme="dark"] .cabinet-overlay .header-btn:hover,
.theme-dark .cabinet-overlay .header-btn:hover {
    background: var(--cab-accent) !important;
    color: white !important;
}

/* --- Компакт-хедер профиля --- */
[data-theme="dark"] .cabinet-header-compact,
.theme-dark .cabinet-header-compact {
    background: var(--cab-card-bg) !important;
    border-color: var(--cab-border) !important;
}

[data-theme="sepia"] .cabinet-header-compact,
.theme-sepia .cabinet-header-compact {
    background: var(--cab-card-bg) !important;
    border-color: var(--cab-border) !important;
}

/* --- Чат: Контакт-лист, хедер, сообщения --- */
[data-theme="dark"] .chat-contacts-panel,
[data-book-theme="dark"] .chat-contacts-panel,
.theme-dark .chat-contacts-panel {
    background: #0f172a !important;
    border-color: var(--cab-border) !important;
}

[data-theme="dark"] .chat-main-panel,
[data-book-theme="dark"] .chat-main-panel,
.theme-dark .chat-main-panel {
    background: #1e293b !important;
}

[data-theme="dark"] .chat-panel-header,
[data-book-theme="dark"] .chat-panel-header,
.theme-dark .chat-panel-header {
    background: rgba(30, 41, 59, 0.95) !important;
    border-color: var(--cab-border) !important;
    color: #f8fafc !important;
}

[data-theme="dark"] .contact-item,
[data-book-theme="dark"] .contact-item,
.theme-dark .contact-item {
    border-color: var(--cab-border) !important;
    color: #f8fafc !important;
}

[data-theme="dark"] .contact-item:hover,
[data-theme="dark"] .contact-item.active,
[data-book-theme="dark"] .contact-item:hover,
[data-book-theme="dark"] .contact-item.active,
.theme-dark .contact-item:hover,
.theme-dark .contact-item.active {
    background: rgba(139, 92, 246, 0.1) !important;
}

[data-theme="dark"] .chat-search-box,
[data-book-theme="dark"] .chat-search-box,
.theme-dark .chat-search-box {
    background: #0f172a !important;
    color: #f8fafc !important;
    border-color: var(--cab-border) !important;
}

[data-theme="dark"] .chat-input-field,
[data-book-theme="dark"] .chat-input-field,
.theme-dark .chat-input-field {
    background: #0f172a !important;
    color: #f8fafc !important;
    border-color: var(--cab-border) !important;
}

[data-theme="dark"] .chat-input-wrapper,
[data-book-theme="dark"] .chat-input-wrapper,
.theme-dark .chat-input-wrapper {
    background: rgba(30, 41, 59, 0.95) !important;
    border-color: var(--cab-border) !important;
}

[data-theme="dark"] .chat-messages-area,
[data-book-theme="dark"] .chat-messages-area,
.theme-dark .chat-messages-area {
    background: #1e293b !important;
}

/* --- Dark Theme overrides for chat bubbles --- */
[data-theme="dark"] .msg-bubble.theirs,
[data-book-theme="dark"] .msg-bubble.theirs,
.theme-dark .msg-bubble.theirs {
    background: #334155 !important;
    border-color: #475569 !important;
    color: #f8fafc !important;
}

[data-theme="dark"] .msg-bubble.mine,
[data-book-theme="dark"] .msg-bubble.mine,
.theme-dark .msg-bubble.mine {
    background: #065f46 !important;
    border-color: #064e3b !important;
    color: #f8fafc !important;
}

[data-theme="dark"] .msg-time,
[data-book-theme="dark"] .msg-time,
.theme-dark .msg-time {
    color: #94a3b8 !important;
}

[data-theme="dark"] .msg-status-label,
[data-book-theme="dark"] .msg-status-label,
.theme-dark .msg-status-label {
    color: #94a3b8 !important;
}

[data-theme="dark"] .msg-action-btn,
[data-book-theme="dark"] .msg-action-btn,
.theme-dark .msg-action-btn {
    background: #1e293b !important;
    border-color: #334155 !important;
    color: #f8fafc !important;
}

[data-theme="dark"] .msg-action-btn:hover,
[data-book-theme="dark"] .msg-action-btn:hover,
.theme-dark .msg-action-btn:hover {
    background: #334155 !important;
}

[data-theme="dark"] .msg-bubble.is-editing,
[data-book-theme="dark"] .msg-bubble.is-editing,
.theme-dark .msg-bubble.is-editing {
    background: #713f12 !important;
    outline-color: #ca8a04 !important;
}

/* --- Sepia чат --- */
[data-theme="sepia"] .chat-contacts-panel,
.theme-sepia .chat-contacts-panel {
    background: #faf3e0 !important;
}

[data-theme="sepia"] .chat-main-panel,
.theme-sepia .chat-main-panel {
    background: #fdf5e6 !important;
}

[data-theme="sepia"] .chat-search-box,
.theme-sepia .chat-search-box,
[data-theme="sepia"] .chat-input-field,
.theme-sepia .chat-input-field {
    background: #fdf5e6 !important;
    color: #3e2723 !important;
}

[data-theme="sepia"] .chat-panel-header,
.theme-sepia .chat-panel-header {
    background: #faf3e0 !important;
    border-color: rgba(100, 80, 60, 0.2) !important;
    color: #3e2723 !important;
}

[data-theme="sepia"] .contact-item,
.theme-sepia .contact-item {
    border-color: rgba(100, 80, 60, 0.2) !important;
    color: #3e2723 !important;
}

/* --- Кнопки кабинета --- */
[data-theme="dark"] .cab-btn,
.theme-dark .cab-btn {
    background: rgba(30, 41, 59, 0.8) !important;
    color: var(--cab-text) !important;
    border-color: var(--cab-border) !important;
}

[data-theme="dark"] .cab-btn:hover,
.theme-dark .cab-btn:hover {
    background: rgba(139, 92, 246, 0.2) !important;
    border-color: var(--cab-accent) !important;
}

[data-theme="dark"] .cab-btn-primary,
.theme-dark .cab-btn-primary {
    background: var(--cab-accent) !important;
    color: white !important;
}

[data-theme="dark"] .cab-btn-secondary,
.theme-dark .cab-btn-secondary {
    background: rgba(148, 163, 184, 0.1) !important;
    color: var(--cab-text-muted) !important;
}

/* --- Newsletter controls border --- */
[data-theme="dark"] .newsletter-controls,
.theme-dark .newsletter-controls {
    border-left-color: var(--cab-border) !important;
}

/* --- User card from leaderboard (popup profile) --- */
[data-theme="dark"] .user-profile-card,
.theme-dark .user-profile-card {
    background: #1e293b !important;
    color: var(--cab-text) !important;
    border-color: var(--cab-border) !important;
}

[data-theme="sepia"] .user-profile-card,
.theme-sepia .user-profile-card {
    background: #faf3e0 !important;
    color: var(--cab-text) !important;
}