/* FlashChat demo1.0 - estilos extraidos del HTML principal */
:root {
    --font-scale: 1;
    --base-size: 0.94rem;
    --title-size: 1.08rem;
    --small-size: 0.82rem;
    --nav-rail-width: 92px;
    --sidebar-layout-width: 420px;
}

* { 
    -webkit-tap-highlight-color: transparent; 
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-overflow-scrolling: touch;
}

html, body { 
    height: 100%;
    width: 100%;
    overflow: hidden;
    position: relative;
    --keyboard-offset: 0px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #0f172a;
    touch-action: manipulation;
    overscroll-behavior: none;
}
body.settings-open {
    overflow: hidden;
}

html {
    font-size: calc(16px * var(--font-scale, 1));
}

#app {
    width: 100%;
    height: 100%;
    height: var(--app-height, 100dvh);
    display: flex;
    overflow: hidden;
    position: relative;
}

@supports (padding-top: env(safe-area-inset-top)) {
    #app {
        padding-top: env(safe-area-inset-top);
        padding-bottom: 0; 
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

#sidebar {
    width: 100%;
    height: 100%;
    background: transparent;
    display: flex;
    flex-direction: row;
    position: absolute;
    z-index: 20;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: visible;
}

#sidebarMain {
    flex: none;
    min-width: 0;
    height: 100%;
    background: #1e293b;
    display: flex;
    flex-direction: column;
    position: relative;
    width: calc(100% - var(--nav-rail-width));
    max-width: calc(100% - var(--nav-rail-width));
    margin-left: var(--nav-rail-width);
    z-index: 3;
    transition: transform 0.24s ease;
}

#chatArea {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    z-index: 1;
}

#activeChat {
    flex: 1 1 auto;
    min-height: 0;
}

.nav-rail {
    width: var(--nav-rail-width);
    min-width: var(--nav-rail-width);
    flex-shrink: 0;
    background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
    border-right: 1px solid rgba(255,255,255,0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    padding: calc(16px + env(safe-area-inset-top)) 10px calc(16px + env(safe-area-inset-bottom));
    gap: 18px;
    z-index: 17030;
    box-shadow: 14px 0 30px rgba(2, 6, 23, 0.4);
}

.nav-rail-brand {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-align: center;
}

.nav-rail-bolt {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255,255,255,0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 22px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.2);
}

.nav-rail-title {
    font-size: 18px;
    line-height: 1.1;
    font-weight: 800;
    color: #fff;
}

.nav-rail-id {
    font-size: 11px;
    line-height: 1.4;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    color: rgba(219, 234, 254, 0.88);
    word-break: break-all;
}

.nav-rail-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.nav-rail-btn {
    width: 46px;
    height: 46px;
    border-radius: 16px;
    border: none;
    background: rgba(30, 64, 175, 0.45);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.18s ease, background 0.18s ease;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
}

.nav-rail-btn:hover,
.nav-rail-btn:active {
    background: rgba(30, 64, 175, 0.8);
    transform: translateY(-1px);
}
.feature-disabled-control,
[aria-disabled="true"].nav-rail-btn,
[aria-disabled="true"].btn-round {
    opacity: 0.62;
    filter: saturate(0.72);
    cursor: not-allowed;
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.2);
}
[aria-disabled="true"].nav-rail-btn:hover,
[aria-disabled="true"].nav-rail-btn:active,
[aria-disabled="true"].btn-round:hover,
[aria-disabled="true"].btn-round:active {
    transform: none;
}

.sidebar-topbar {
    display: none;
    align-items: center;
    justify-content: stretch;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    gap: 12px;
    padding: 10px 12px;
    background: #1e293b;
    border-bottom: 1px solid #334155;
    flex-shrink: 0;
    min-height: 60px;
    color: #f8fafc;
}

.sidebar-topbar-spacer,
.settings-header-spacer {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.sidebar-topbar-btn {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.32);
    background: rgba(37, 99, 235, 0.18);
    color: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    justify-self: start;
    transition: background 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
}

.sidebar-topbar-btn:active {
    transform: scale(0.97);
}

.sidebar-topbar-copy {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    justify-self: center;
    text-align: center;
}

.sidebar-topbar-title {
    font-size: 1.25rem;
    line-height: 1.2;
    font-weight: 800;
    color: inherit;
    width: 100%;
    text-align: center;
}

.sidebar-mobile-actions {
    flex-shrink: 0;
    width: 40px;
    justify-self: end;
    justify-content: flex-end;
}

.sidebar-topbar-plus {
    justify-self: end;
    background: rgba(37, 99, 235, 0.88);
    border-color: rgba(96, 165, 250, 0.42);
    color: #ffffff;
}

.sidebar-topbar-plus:hover,
.sidebar-topbar-plus:active {
    background: #1d4ed8;
}


@media (min-width: 768px) {
    #sidebar {
        width: 420px;
        position: relative;
        transform: none !important;
        border-right: 1px solid #334155;
        overflow: visible;
    }

    #sidebarMain {
        position: relative;
        left: auto;
        top: auto;
        bottom: auto;
        transform: none !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        box-shadow: none;
    }
}

@media (min-width: 1024px) {
    #sidebar {
        width: 460px;
    }
}

@media (max-width: 767px) {
    :root {
        --nav-rail-width: 90px;
    }

    #sidebar {
        flex: 0 0 100%;
        width: 100%;
        max-width: 100%;
        z-index: 60;
        transform: none !important;
        overflow: visible;
        pointer-events: none;
    }

    #chatArea {
        flex: 0 0 calc(100% - var(--nav-rail-width));
        width: calc(100% - var(--nav-rail-width));
        margin-left: var(--nav-rail-width);
    }

    #sidebar.chat-open-mobile + #chatArea {
        flex: 1 1 100%;
        width: 100%;
        margin-left: 0;
        position: relative;
        z-index: 17040;
    }

    #sidebar.chat-open-mobile {
        flex-basis: 0;
        width: 0;
        min-width: 0;
        max-width: 0;
        z-index: 10;
    }

    #sidebar.chat-open-mobile.rail-open {
        flex-basis: 100%;
        width: 100%;
        min-width: 100%;
        max-width: 100%;
    }

    .nav-rail {
        width: var(--nav-rail-width);
        min-width: var(--nav-rail-width);
        transform: none !important;
        transition: none;
        pointer-events: auto;
    }

    #sidebarMain {
        position: absolute;
        left: var(--nav-rail-width);
        top: 0;
        bottom: 0;
        width: calc(100vw - var(--nav-rail-width));
        max-width: calc(100vw - var(--nav-rail-width));
        margin-left: 0;
        transform: translateX(0);
        opacity: 1;
        pointer-events: auto;
        transition: transform 0.24s ease, opacity 0.24s ease;
        box-shadow: 18px 0 34px rgba(2, 6, 23, 0.34);
        z-index: 17020;
    }

    #sidebar.chat-open-mobile #sidebarMain {
        transform: translateX(calc(-100% - var(--nav-rail-width) - 24px));
        opacity: 0;
        pointer-events: none;
    }

    #sidebar.chat-open-mobile.rail-open #sidebarMain {
        transform: translateX(0);
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-topbar {
        display: none;
    }

    .sidebar-rail-overlay {
        display: block;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: var(--nav-rail-width);
        background: rgba(15, 23, 42, 0.45);
        backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.24s ease;
        z-index: 17010;
    }

    #sidebar.chat-open-mobile.rail-open .sidebar-rail-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    #sidebar.chat-open-mobile .nav-rail {
        transform: translateX(calc(-100% - 16px)) !important;
        opacity: 0;
        pointer-events: none;
    }

    #sidebar.chat-open-mobile.rail-open .nav-rail {
        transform: translateX(0) !important;
        opacity: 1;
        pointer-events: auto;
    }

    #sidebar.sidebar-hidden {
        transform: none !important;
    }
}

.sidebar-hidden {
    transform: translateX(-100%);
}

#messagesContainer {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
    position: relative;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    scroll-padding-bottom: calc(180px + env(safe-area-inset-bottom));
}

@media (min-width: 768px) {
    #messagesContainer {
        padding: 16px 20px;
    }
}

.message-bubble p { font-size: var(--base-size); }
#messageInput { font-size: var(--base-size); }
.contact-name { font-size: var(--base-size); }
.contact-preview { font-size: var(--small-size); }
#chatName { font-size: var(--title-size); }
.menu-item { font-size: var(--base-size); }
.mode-option { font-size: var(--small-size); }

.pinned-message {
    flex-shrink: 0;
    background: rgba(59, 130, 246, 0.1);
    border-bottom: 2px solid #3b82f6;
    padding: 12px 16px;
    display: none;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    position: relative;
}

.pinned-message.active { display: flex; }
.pinned-message::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: #3b82f6; }
.pinned-icon { color: #3b82f6; font-size: 20px; }
.pinned-content { flex: 1; min-width: 0; }
.pinned-name { font-size: var(--small-size); color: #3b82f6; font-weight: 600; margin-bottom: 2px; }
.pinned-text { font-size: var(--small-size); color: #e2e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinned-close { color: #94a3b8; cursor: pointer; padding: 4px; }
.pinned-close:hover { color: #ef4444; }

.mode-selector {
    flex-shrink: 0;
    width: 100%;
    background: #1e293b;
    border-top: 1px solid #334155;
    padding: 8px 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.mode-selector::-webkit-scrollbar { display: none; }

body.keyboard-open #messagesContainer {
    scroll-padding-bottom: calc(110px + env(safe-area-inset-bottom));
}

.mode-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    background: #0f172a;
    color: #94a3b8;
    touch-action: manipulation;
}

.mode-option:active { transform: scale(0.95); }
.mode-option.active { border-color: currentColor; background: rgba(255,255,255,0.1); }
.mode-option.normal { color: #60a5fa; }
.mode-option.normal.active { background: rgba(59, 130, 246, 0.2); }
.mode-option.ghost { color: #c084fc; }
.mode-option.ghost.active { background: rgba(168, 85, 247, 0.2); }
.mode-option.burn { color: #fb923c; }
.mode-option.burn.active { background: rgba(251, 146, 60, 0.2); }
.mode-option.boomerang { color: #4ade80; }
.mode-option.boomerang.active { background: rgba(74, 222, 128, 0.2); }
.mode-option.shake { color: #f87171; }
.mode-option.shake.active { background: rgba(248, 113, 113, 0.2); }
.mode-option.voice-expire { color: #facc15; }
.mode-option.voice-expire.active { background: rgba(250, 204, 21, 0.2); }

.input-area {
    flex-shrink: 0;
    width: 100%;
    background: #1e293b;
    border-top: 1px solid #334155;
    padding: 8px;
    position: relative;
    z-index: 1005; /* Encima del overlay */
    padding-bottom: max(8px, env(safe-area-inset-bottom));
}

@media (max-width: 767px) {
    body.composer-focus .mode-selector {
        display: none;
    }

    body.composer-focus .input-area {
        padding-top: 6px;
        padding-bottom: max(6px, env(safe-area-inset-bottom));
    }
}

@media (min-width: 768px) {
    .input-area {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    width: 100%;
    margin: 0;
}

#messageInput {
    flex: 1 1 auto;
    width: 100%;
    background: #0f172a;
    border: 1px solid #475569;
    border-radius: 22px;
    padding: 10px 14px;
    color: white;
    line-height: 22px;
    max-height: min(160px, 32vh);
    min-height: 44px;
    height: 44px;
    resize: none;
    outline: none;
    -webkit-appearance: none;
    font-family: inherit;
    overflow-y: auto;
}

@media (min-width: 768px) {
    .input-wrapper { gap: 12px; }
    #messageInput { padding: 12px 18px; min-height: 48px; height: 48px; border-radius: 24px; }
}

#messageInput:focus { border-color: #3b82f6; background: #1e293b; }

.btn-round {
    width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center;
    justify-content: center; border: none; cursor: pointer; flex-shrink: 0; transition: all 0.15s ease;
    -webkit-touch-callout: none;
}
@media (min-width: 768px) { .btn-round { width: 48px; height: 48px; } }
.btn-round:active { transform: scale(0.92); opacity: 0.8; }
.btn-round.recording { background: #ef4444 !important; color: white !important; animation: pulse-red 1s infinite; }
.btn-round.feature-disabled-control {
    background: rgba(51, 65, 85, 0.72) !important;
    color: #94a3b8 !important;
}

.gif-menu {
    position: absolute; bottom: calc(100% + 10px); left: 8px; width: 320px;
    max-width: calc(100vw - 16px);
    background: #1e293b; border: 1px solid #334155; border-radius: 16px; padding: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5); display: none; z-index: 1000;
}
.gif-menu.active { display: block; animation: popIn 0.2s ease; }

.gif-search-box { position: relative; margin-bottom: 8px; }
.gif-search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #94a3b8; }
.gif-search-box input {
    width: 100%; background: #0f172a; border: 1px solid #475569; border-radius: 12px;
    padding: 8px 12px 8px 36px; color: white; font-size: 14px; outline: none; transition: border-color 0.2s;
}
.gif-search-box input:focus { border-color: #3b82f6; }

.gif-grid { 
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; 
    max-height: 220px; overflow-y: auto; 
}
.gif-item img { 
    width: 100%; height: 80px; object-fit: contain; background: transparent;
    border-radius: 8px; cursor: pointer; transition: transform 0.2s; 
}
.gif-item:hover img { transform: scale(1.1); background: rgba(59, 130, 246, 0.2); }

.reactions-container { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.reaction {
    display: inline-flex; align-items: center; gap: 2px; padding: 2px 6px;
    background: rgba(255,255,255,0.1); border-radius: 12px; font-size: var(--small-size);
    cursor: pointer; transition: all 0.2s; user-select: none;
}
.reaction:hover { transform: scale(1.1); }
.reaction.me { background: #3b82f6; color: white; }

.voice-message { display: flex; align-items: center; gap: 12px; min-width: 200px; }
.voice-wave-container { flex: 1; height: 40px; display: flex; align-items: center; cursor: pointer; }
.voice-wave-canvas { width: 100%; height: 100%; border-radius: 8px; }
.speed-control { display: flex; gap: 4px; margin-top: 4px; justify-content: center; }
.speed-btn {
    padding: 2px 6px; border-radius: 10px; font-size: 10px; background: rgba(255,255,255,0.1);
    color: #94a3b8; border: none; cursor: pointer; transition: all 0.2s;
}
.speed-btn.active { background: #3b82f6; color: white; }

.swipe-cancel-area {
    position: absolute; top: -60px; left: 50%; transform: translateX(-50%);
    background: #ef4444; color: white; padding: 8px 16px; border-radius: 30px;
    font-size: 12px; font-weight: bold; display: none; align-items: center;
    gap: 8px; z-index: 100; animation: slideDown 0.2s ease; white-space: nowrap;
}
.swipe-cancel-area.active { display: flex; }

.voice-expire-bar {
    position: absolute; bottom: 0; left: 0; height: 3px;
    background: linear-gradient(90deg, #f59e0b, #ef4444); border-radius: 0 0 0 12px;
}

.mention {
    background: rgba(59, 130, 246, 0.2); color: #3b82f6; font-weight: 600;
    padding: 2px 4px; border-radius: 12px; cursor: pointer; transition: all 0.2s;
}
.mention:hover { background: rgba(59, 130, 246, 0.3); }
.mention.self-mention { background: rgba(59, 130, 246, 0.3); border: 1px solid #3b82f6; }

.mention-badge {
    background: #3b82f6; color: white; font-size: 10px; padding: 2px 6px;
    border-radius: 10px; margin-left: 4px;
}

.mention-menu {
    position: absolute; background: #1e293b; border: 1px solid #334155; border-radius: 12px;
    max-height: 200px; overflow-y: auto; width: 200px; z-index: 1000;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5); display: none; bottom: calc(100% + 8px); left: 0;
}
.mention-menu.active { display: block; }
.mention-item { padding: 10px 12px; cursor: pointer; display: flex; align-items: center; gap: 8px; transition: background 0.2s; }
.mention-item:hover { background: rgba(255,255,255,0.1); }
.mention-item.selected { background: rgba(59, 130, 246, 0.3); }

.contact-dnd { position: relative; }
.dnd-icon {
    position: absolute; bottom: -2px; right: -2px; background: #ef4444; color: white;
    width: 16px; height: 16px; border-radius: 50%; display: flex; align-items: center;
    justify-content: center; font-size: 8px; border: 2px solid #1e293b;
}

.recording-indicator {
    display: none; align-items: center; justify-content: center; gap: 12px;
    color: #ef4444; font-weight: 600; padding: 8px; font-size: var(--base-size);
    background: rgba(239, 68, 68, 0.1); border-radius: 12px; margin: 0 12px 8px; position: relative;
}
.recording-indicator.active { display: flex; }
.recording-dot { width: 12px; height: 12px; background: #ef4444; border-radius: 50%; animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.5; transform: scale(1.2); } }

.reply-preview {
    background: rgba(59, 130, 246, 0.1); border-left: 3px solid #3b82f6; padding: 8px 12px;
    margin: 0 12px 8px; border-radius: 0 8px 8px 0; display: none; position: relative;
}
.reply-preview.active { display: block; }
.edit-preview {
    background: rgba(168, 85, 247, 0.1);
    border-left-color: #a855f7;
}
.reply-preview .reply-name { color: #3b82f6; font-weight: 600; margin-bottom: 2px; font-size: var(--small-size); }
.edit-preview .reply-name { color: #c084fc; }
.reply-preview .reply-text { color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: var(--small-size); }
.reply-preview button { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: #94a3b8; background: none; border: none; cursor: pointer; }
.message-edited-label { color: #cbd5e1; font-weight: 700; letter-spacing: 0.02em; }

/* -- ZONA DE MENSAJES Y BURBUJAS -- */
.message-bubble {
    width: fit-content; max-width: min(90%, 500px); min-width: 60px; word-wrap: break-word;
    overflow-wrap: anywhere; hyphens: auto; position: relative; cursor: pointer; 
    
    /* Bloqueo total de selecciÃ³n para que no estorbe al mantener pulsado ni salte el tooltip nativo */
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-touch-callout: none !important;
}

/* 2. Z-INDEX CORREGIDO: Mensaje y MenÃº siempre arriba, Input abajo */
.message-bubble.highlighted {
    position: relative;
    z-index: 10004 !important;
    box-shadow: 0 0 0 2px #3b82f6, 0 10px 30px rgba(0,0,0,0.6) !important;
    transform: scale(1.02);
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.message-pop.menu-target {
    position: relative;
    z-index: 10003 !important;
}

.message-bubble.has-reply { padding-top: 8px; }
.quoted-content {
    background: rgba(255,255,255,0.1); border-left: 2px solid rgba(255,255,255,0.3);
    padding: 4px 8px; margin-bottom: 6px; border-radius: 0 4px 4px 0; opacity: 0.9;
}

@media (min-width: 768px) { .message-bubble { max-width: min(75%, 600px); } }
@media (min-width: 1024px) { .message-bubble { max-width: min(65%, 550px); } }

.message-pop { 
    animation: messagePop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1); 
    will-change: transform;
}
@keyframes messagePop { 0% { transform: scale(0.3) translateY(10px); opacity: 0; } 100% { transform: scale(1) translateY(0); opacity: 1; } }

.shake { animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes shake { 10%, 90% { transform: translate3d(-1px, 0, 0); } 20%, 80% { transform: translate3d(2px, 0, 0); } 30%, 50%, 70% { transform: translate3d(-4px, 0, 0); } 40%, 60% { transform: translate3d(4px, 0, 0); } }

.ghost-text { filter: blur(5px); transition: filter 0.2s; user-select: none; }
.ghost-text:hover, .ghost-text:active { filter: blur(0); }

.burn-bar {
    position: absolute; bottom: 0; left: 0; height: 3px;
    background: linear-gradient(90deg, #f59e0b, #ef4444); animation: burn 10s linear forwards; border-radius: 0 0 0 12px;
}
@keyframes burn { from { width: 100%; } to { width: 0%; } }
@keyframes boomerang { 0% { transform: translateX(0); } 30% { transform: translateX(18px); } 60% { transform: translateX(-8px); } 80% { transform: translateX(6px); } 100% { transform: translateX(0); } }
.boomerang-anim { animation: boomerang 0.7s ease forwards; }

.chat-image { max-width: 100%; max-height: 200px; border-radius: 12px; cursor: pointer; display: block; object-fit: cover; }
@media (min-width: 768px) { .chat-image { max-height: 300px; } }

.chat-sticker {
    max-width: 160px; max-height: 160px; object-fit: contain; 
    background: transparent; border-radius: 0; cursor: pointer; display: block;
}
@media (min-width: 768px) { .chat-sticker { max-width: 200px; max-height: 200px; } }

.file-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 18px;
    background: rgba(15, 23, 42, 0.42);
    border: 1px solid rgba(148, 163, 184, 0.18);
    backdrop-filter: blur(10px);
    min-width: min(280px, 72vw);
    max-width: min(360px, 82vw);
}
.file-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(59, 130, 246, 0.18);
    color: #93c5fd;
    flex-shrink: 0;
}
.file-card-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.file-card-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: #f8fafc;
    word-break: break-word;
}
.file-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    color: #94a3b8;
    font-size: 0.72rem;
}
.file-card-meta span {
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(51, 65, 85, 0.75);
}
.file-card-cta {
    font-size: 0.76rem;
    font-weight: 700;
    color: #bfdbfe;
    margin-top: 2px;
}

.date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 16px 0 14px;
}
.date-separator span {
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 700;
    color: #cbd5e1;
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid rgba(148, 163, 184, 0.16);
    backdrop-filter: blur(10px);
}

.image-preview-container { flex-shrink: 0; background: #1e293b; border-top: 1px solid #334155; padding: 8px 12px; display: none; }
.image-preview-container.active { display: block; }
.preview-box { position: relative; display: inline-block; margin-right: 8px; margin-bottom: 8px;}
.preview-box img { max-height: 60px; border-radius: 8px; border: 2px solid #3b82f6; }

.preview-box button {
    position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; background: #ef4444;
    color: white; border: none; border-radius: 50%; cursor: pointer; display: flex; align-items: center;
    justify-content: center; font-size: 11px; box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

#imageModal {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.95); z-index: 3000;
    align-items: center; justify-content: center; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#imageModal.active { display: flex; }
#imageModal img { max-width: 100%; max-height: 100%; object-fit: contain; }

input[type="file"] { display: none; }

.typing-bubble span {
    display: inline-block; width: 6px; height: 6px; background: #64748b;
    border-radius: 50%; margin: 0 1px; animation: typing 1.4s infinite ease-in-out both;
}
.typing-bubble span:nth-child(1) { animation-delay: -0.32s; }
.typing-bubble span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing { 0%, 80%, 100% { transform: scale(0.6); } 40% { transform: scale(1); } }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #475569; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #64748b; }

@keyframes pulse-red { 0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); } 50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); } }

.chat-header {
    flex-shrink: 0; background: #1e293b; border-bottom: 1px solid #334155; padding: 10px 12px;
    display: flex; align-items: center; gap: 10px; z-index: 5; padding-top: max(10px, env(safe-area-inset-top));
}
@media (min-width: 768px) {
    .chat-header { padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
}

.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; }

.message-menu {
    position: fixed; background: #1e293b; border-radius: 16px; padding: 6px 0; display: none;
    flex-direction: column; box-shadow: 0 15px 50px rgba(0,0,0,0.6); z-index: 10006;
    border: 1px solid #334155; min-width: 220px; width: min(280px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
    max-height: min(70vh, 420px);
    overflow-y: auto;
    transform-origin: top left;
}
.message-menu.active { 
    display: flex; 
    animation: menuPop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); 
}
@keyframes menuPop {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.message-menu-preview {
    padding: 14px 16px 12px;
    border-bottom: 1px solid #334155;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.82), rgba(15, 23, 42, 0.3));
}
.message-menu-preview.hidden { display: none; }
.menu-preview-media {
    width: 100%;
    max-height: 220px;
    border-radius: 18px;
    object-fit: cover;
    display: block;
    background: rgba(15, 23, 42, 0.45);
}
.menu-preview-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: #93c5fd;
    font-size: 0.76rem;
    font-weight: 700;
}
.menu-preview-topline span:last-child {
    color: #94a3b8;
    font-weight: 600;
}
.menu-preview-title {
    color: #f8fafc;
    font-weight: 800;
    line-height: 1.4;
    word-break: break-word;
}
.menu-preview-body {
    color: #cbd5e1;
    font-size: 0.84rem;
    line-height: 1.55;
    word-break: break-word;
}
.menu-preview-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.menu-preview-meta span {
    border-radius: 999px;
    background: rgba(51, 65, 85, 0.72);
    color: #cbd5e1;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 4px 8px;
}
.menu-section {
    padding: 6px 0;
    border-top: 1px solid rgba(51, 65, 85, 0.75);
}
#messageMenu .menu-section:nth-child(3) {
    border-top: 0;
}

.reaction-row {
    display: flex; gap: 8px; padding: 8px 16px 12px; border-bottom: 1px solid #334155;
    margin-bottom: 4px; justify-content: flex-start; overflow-x: auto; flex-wrap: nowrap;
}
.reaction-btn {
    width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center;
    justify-content: center; font-size: 20px; cursor: pointer; transition: transform 0.1s;
    background: transparent; border: none;
}
.reaction-btn:hover, .reaction-btn:active { background: rgba(255,255,255,0.1); transform: scale(1.2); }
.reaction-btn-more { font-size: 18px; font-weight: 800; color: #cbd5e1; }

.menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: calc(100% - 12px);
    margin: 0 6px;
    padding: 12px 14px;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.15s;
    color: #e2e8f0;
    background: transparent;
    border: none;
    text-align: left;
}
.menu-item-content {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.menu-item-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.menu-item-copy span {
    font-weight: 700;
}
.menu-item-copy small {
    color: #94a3b8;
    font-size: 0.72rem;
    line-height: 1.35;
}
.menu-item:hover { background: rgba(255,255,255,0.1); }
.menu-item.delete { color: #ef4444; }

.message-menu.mobile-sheet {
    width: calc(100vw - 24px) !important;
    max-width: calc(100vw - 24px);
    left: 12px !important;
    right: 12px;
    top: auto !important;
    border-radius: 22px 22px 16px 16px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    transform-origin: bottom center;
}

.menu-overlay {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(3px);
    z-index: 10000; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.menu-overlay.active { opacity: 1; pointer-events: auto; }

.swipe-action-icon {
    position: absolute; width: 36px; height: 36px; background: #334155; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; color: white;
    opacity: 0; transform: scale(0.5); transition: opacity 0.2s, transform 0.2s; z-index: 10;
}
.swipe-action-icon.active { background: #3b82f6; transform: scale(1); }

.search-container { padding: 8px 12px; background: #1e293b; border-bottom: 1px solid #334155; display: none; }
.search-container.active { display: block; }
.search-input { width: 100%; background: #0f172a; border: 1px solid #475569; border-radius: 20px; padding: 8px 16px; color: white; outline: none; }
.avatar-media-shell {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: inherit;
    overflow: hidden;
}
.avatar-media-shell[data-avatar-format="svg"] {
    padding: 14%;
    background:
        radial-gradient(circle at top, rgba(255, 255, 255, 0.22), transparent 48%),
        rgba(15, 23, 42, 0.18);
}
.avatar-media {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
    display: block;
}
.avatar-media-shell[data-avatar-format="svg"] .avatar-media,
.incoming-call-avatar .avatar-media-shell[data-avatar-format="svg"] .avatar-media,
.call-avatar-fallback .avatar-media-shell[data-avatar-format="svg"] .avatar-media {
    object-fit: contain;
    border-radius: 22%;
    background: rgba(255, 255, 255, 0.06);
}
.settings-side-panel {
    display: none;
}

.settings-modal {
    display: none;
    position: fixed;
    inset: 0 0 calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom)) 0;
    background: rgba(2, 6, 23, 0.72);
    z-index: 13050;
    align-items: stretch;
    justify-content: flex-end;
    padding: 0;
    backdrop-filter: blur(10px);
}
.settings-modal.active { display: flex; }
.settings-content {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.96));
    width: 100vw;
    max-width: 100vw;
    height: 100%;
    max-height: none;
    overflow-y: auto;
    border-left: 1px solid rgba(51, 65, 85, 0.95);
    box-shadow: -24px 0 60px rgba(2, 6, 23, 0.35);
}
.settings-header {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 16px 18px;
    border-bottom: 1px solid #334155;
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    align-items: center;
    gap: 12px;
    background: rgba(15, 23, 42, 0.96);
    backdrop-filter: blur(16px);
    color: #f8fafc;
}
.settings-header-copy {
    display: flex;
    align-items: center;
    justify-content: center;
    justify-self: center;
    min-width: 0;
    width: 100%;
    text-align: center;
    color: inherit;
}
.settings-modal-title {
    margin: 0;
    font-size: 1.25rem;
    line-height: 1.2;
    font-weight: 800;
    color: #f8fafc;
    width: 100%;
    text-align: center;
}
.settings-header-copy > div,
.settings-header-title-wrap {
    min-width: 0;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.settings-header-subtitle {
    display: none;
    margin-top: 4px;
    color: #94a3b8;
    font-size: 0.82rem;
    line-height: 1.45;
}
.settings-mobile-back {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid #334155;
    background: rgba(15, 23, 42, 0.92);
    color: #cbd5e1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.settings-mobile-back:active {
    transform: scale(0.97);
}
.settings-mobile-back.hidden {
    visibility: hidden;
    pointer-events: none;
}
.settings-overview-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 10px 0 4px;
}
.settings-overview-item {
    width: 100%;
    min-height: 64px;
    border-radius: 22px;
    border: 1px solid rgba(51, 65, 85, 0.92);
    background: rgba(15, 23, 42, 0.84);
    color: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    text-align: left;
    font-size: 0.96rem;
    font-weight: 700;
    transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}
.settings-overview-item span {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}
.settings-overview-item i:last-child {
    color: #94a3b8;
}
.settings-overview-item:active {
    transform: scale(0.985);
}
.settings-overview-item:hover {
    background: rgba(59, 130, 246, 0.16);
    color: #bfdbfe;
    border-color: rgba(96, 165, 250, 0.65);
}
.settings-section {
    display: none;
    padding: 18px 24px;
    border-bottom: 1px solid #334155;
}
.settings-section.active {
    display: block;
}
.emergency-stack {
    gap: 16px;
}
.emergency-card {
    background: rgba(15, 23, 42, 0.72);
    border: 1px solid #334155;
    border-radius: 22px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.emergency-status-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}
.emergency-status-box {
    border-radius: 18px;
    border: 1px solid #334155;
    background: rgba(2, 6, 23, 0.72);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.emergency-status-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
}
.emergency-status-value {
    font-size: 0.95rem;
    color: #f8fafc;
}
.emergency-contacts-list,
.emergency-relay-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.emergency-contact-item {
    border-radius: 18px;
    border: 1px solid #334155;
    background: rgba(2, 6, 23, 0.72);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.emergency-contact-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.emergency-contact-copy strong {
    color: #f8fafc;
    font-size: 0.95rem;
}
.emergency-contact-copy span {
    color: #94a3b8;
    font-size: 0.78rem;
    line-height: 1.4;
}
.emergency-contact-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.emergency-contact-btn {
    min-width: 42px;
    height: 42px;
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(15, 23, 42, 0.9);
    color: #e2e8f0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
.emergency-contact-btn:active {
    transform: scale(0.97);
}
.emergency-contact-btn.primary {
    padding: 0 14px;
    min-width: auto;
    color: #bfdbfe;
    border-color: rgba(96, 165, 250, 0.35);
}
.emergency-contact-btn.favorite {
    color: #fde68a;
    border-color: rgba(250, 204, 21, 0.3);
}
.emergency-relay-target {
    border-radius: 18px;
    border: 1px solid #334155;
    background: rgba(2, 6, 23, 0.72);
    padding: 12px 14px;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
}
.emergency-relay-entry {
    border-radius: 18px;
    border: 1px solid #334155;
    background: rgba(2, 6, 23, 0.74);
    padding: 12px 14px;
}
.emergency-relay-entry.outgoing {
    border-color: rgba(59, 130, 246, 0.42);
    background: rgba(30, 64, 175, 0.18);
}
.emergency-relay-entry-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: #94a3b8;
    font-size: 0.72rem;
    margin-bottom: 6px;
}
.emergency-relay-entry-body {
    color: #f8fafc;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}
.emergency-code-area,
.emergency-message-input {
    width: 100%;
    border-radius: 18px;
    border: 1px solid #334155;
    background: rgba(2, 6, 23, 0.82);
    color: #e2e8f0;
    padding: 14px 16px;
    resize: vertical;
    outline: none;
}
.emergency-code-area {
    min-height: 120px;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.78rem;
    line-height: 1.45;
    word-break: break-all;
}
.emergency-message-input {
    min-height: 86px;
    font-size: 0.95rem;
}
.emergency-messages-list {
    min-height: 110px;
    max-height: 260px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.emergency-message-item {
    border-radius: 18px;
    border: 1px solid #334155;
    background: rgba(2, 6, 23, 0.74);
    padding: 12px 14px;
}
.emergency-message-item.me {
    border-color: rgba(59, 130, 246, 0.4);
    background: rgba(30, 64, 175, 0.18);
}
.emergency-message-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.72rem;
    color: #94a3b8;
    margin-bottom: 6px;
}
.emergency-message-body {
    color: #f8fafc;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}
.emergency-compose-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
}
.emergency-advanced {
    border: 1px solid #334155;
    border-radius: 18px;
    background: rgba(2, 6, 23, 0.56);
    overflow: hidden;
}
.emergency-advanced summary {
    list-style: none;
    cursor: pointer;
    padding: 14px 16px;
    color: #cbd5e1;
    font-weight: 700;
}
.emergency-advanced summary::-webkit-details-marker {
    display: none;
}
.emergency-advanced-body {
    padding: 0 16px 16px;
}
.emergency-qr-shell {
    margin-top: 4px;
    border-radius: 22px;
    border: 1px solid #334155;
    background: rgba(2, 6, 23, 0.68);
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.emergency-qr-box {
    min-width: 220px;
    min-height: 220px;
    border-radius: 22px;
    background: #ffffff;
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.emergency-qr-box > div,
.emergency-qr-box canvas,
.emergency-qr-box img {
    max-width: 100%;
    height: auto;
}
.emergency-scan-modal {
    position: fixed;
    inset: 0;
    z-index: 2600;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(2, 6, 23, 0.84);
    backdrop-filter: blur(18px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}
.emergency-scan-modal.active {
    opacity: 1;
    pointer-events: auto;
}
.emergency-scan-sheet {
    width: min(100%, 420px);
    border-radius: 28px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    background: rgba(15, 23, 42, 0.96);
    box-shadow: 0 28px 90px rgba(2, 6, 23, 0.45);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.emergency-scan-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}
.emergency-scan-header h3 {
    margin: 0;
    color: #f8fafc;
    font-size: 1.2rem;
    font-weight: 800;
}
.emergency-scan-header p {
    margin: 6px 0 0;
    color: #94a3b8;
    font-size: 0.84rem;
    line-height: 1.5;
}
.emergency-scan-close {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(30, 41, 59, 0.92);
    color: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.emergency-scan-video-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 24px;
    overflow: hidden;
    background: #020617;
    border: 1px solid rgba(148, 163, 184, 0.16);
}
.emergency-scan-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.emergency-scan-target {
    position: absolute;
    inset: 18%;
    border: 3px solid rgba(96, 165, 250, 0.92);
    border-radius: 28px;
    box-shadow:
        0 0 0 999px rgba(2, 6, 23, 0.32),
        0 0 0 1px rgba(255, 255, 255, 0.12) inset;
}
.emergency-scan-status {
    min-height: 50px;
    border-radius: 18px;
    border: 1px solid rgba(148, 163, 184, 0.16);
    background: rgba(15, 23, 42, 0.82);
    color: #bfdbfe;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    font-size: 0.9rem;
    font-weight: 600;
}
.emergency-scan-status[data-tone="green"] {
    color: #86efac;
}
.emergency-scan-status[data-tone="yellow"] {
    color: #fde68a;
}
.emergency-scan-status[data-tone="red"] {
    color: #fca5a5;
}
.settings-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; }
.settings-stack { display: flex; flex-direction: column; gap: 14px; padding: 12px 0; }
.settings-label-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.settings-caption { font-size: 0.78rem; color: #94a3b8; line-height: 1.5; }
.settings-segment { display: flex; gap: 10px; flex-wrap: wrap; }
.settings-pill {
    border: 1px solid #334155;
    background: #0f172a;
    color: #cbd5e1;
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 0.84rem;
    font-weight: 700;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.settings-pill.active {
    background: rgba(59, 130, 246, 0.16);
    color: #bfdbfe;
    border-color: rgba(96, 165, 250, 0.65);
}
.settings-pill:active { transform: scale(0.98); }
.settings-range-wrap { display: flex; flex-direction: column; gap: 10px; }
.settings-range {
    width: 100%;
    appearance: none;
    height: 8px;
    border-radius: 999px;
    background: linear-gradient(90deg, #2563eb, #60a5fa);
    outline: none;
}
.settings-range::-webkit-slider-thumb {
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #1d4ed8;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
}
.settings-range::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #1d4ed8;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
}
.settings-range-scale { display: flex; justify-content: space-between; color: #94a3b8; font-size: 0.74rem; }
.settings-preview-box {
    background: rgba(15, 23, 42, 0.72);
    border: 1px solid #334155;
    border-radius: 18px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.settings-select-wrap {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.settings-select-label {
    font-size: 0.78rem;
    color: #94a3b8;
    font-weight: 700;
}
.settings-select {
    width: 100%;
    min-height: 52px;
    border-radius: 18px;
    border: 1px solid #334155;
    background: rgba(15, 23, 42, 0.92);
    color: #e2e8f0;
    padding: 0 16px;
    outline: none;
    font-size: 0.95rem;
    font-weight: 600;
    appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, #94a3b8 50%),
        linear-gradient(135deg, #94a3b8 50%, transparent 50%);
    background-position:
        calc(100% - 24px) calc(50% - 3px),
        calc(100% - 18px) calc(50% - 3px);
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
}
.settings-select:focus {
    border-color: rgba(96, 165, 250, 0.85);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}
.profile-settings-card {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 10px 0 4px;
}
.profile-settings-top {
    display: flex;
    gap: 18px;
    align-items: flex-start;
}
.profile-avatar-picker {
    position: relative;
    width: 92px;
    height: 92px;
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
}
.profile-avatar-core {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 2rem;
    font-weight: 800;
    overflow: hidden;
    box-shadow: 0 18px 34px rgba(37, 99, 235, 0.22);
}
.profile-avatar-edit {
    position: absolute;
    right: -4px;
    bottom: -4px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #0f172a;
    border: 2px solid #1d4ed8;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #bfdbfe;
    box-shadow: 0 8px 16px rgba(2, 6, 23, 0.3);
}
.profile-settings-fields {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.profile-name-input {
    width: 100%;
    min-height: 52px;
    border-radius: 18px;
    border: 1px solid #334155;
    background: rgba(15, 23, 42, 0.92);
    color: #e2e8f0;
    padding: 0 16px;
    outline: none;
    font-size: 0.98rem;
    font-weight: 700;
}
.profile-name-input:focus {
    border-color: rgba(96, 165, 250, 0.85);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}
.profile-id-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    width: fit-content;
    max-width: 100%;
    padding: 10px 14px;
    border-radius: 999px;
    border: 1px solid #334155;
    background: rgba(15, 23, 42, 0.72);
    color: #94a3b8;
    font-size: 0.78rem;
}
.profile-id-chip code {
    color: #dbeafe;
    font-size: 0.76rem;
    word-break: break-all;
}
.profile-settings-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.profile-qr-card {
    border-radius: 28px;
    border: 1px solid #334155;
    background: rgba(15, 23, 42, 0.68);
    padding: 28px 22px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
    text-align: center;
    margin-top: 4px;
}
.profile-qr-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.profile-qr-avatar {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 800;
    overflow: hidden;
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.05), 0 14px 28px rgba(37, 99, 235, 0.22);
}
.profile-qr-header strong {
    font-size: 1.35rem;
    line-height: 1.1;
}
.profile-qr-subtitle {
    color: #94a3b8;
    font-size: 0.84rem;
}
.profile-qr-caption {
    color: #94a3b8;
    font-size: 0.82rem;
    line-height: 1.55;
    max-width: 420px;
}
.profile-qr-shell {
    background: #ffffff;
    border-radius: 24px;
    padding: 18px 18px 14px;
    box-shadow: 0 18px 38px rgba(2, 6, 23, 0.22);
    flex-shrink: 0;
}
#settingsProfileQRCode {
    display: flex;
    align-items: center;
    justify-content: center;
}
#settingsProfileQRCode img,
#settingsProfileQRCode canvas {
    display: block;
    max-width: 100%;
}
#qr-container.scanning {
    box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.45), 0 18px 34px rgba(37, 99, 235, 0.18);
}
@media (min-width: 768px) {
    .settings-modal {
        inset: 0 0 0 var(--sidebar-layout-width);
        background: rgba(2, 6, 23, 0.58);
    }
    .settings-content {
        width: calc(100vw - var(--sidebar-layout-width));
        max-width: calc(100vw - var(--sidebar-layout-width));
        overflow-y: auto;
        overflow-x: hidden;
        padding-bottom: 28px;
        scrollbar-gutter: stable;
    }
    body.settings-open #sidebar {
        filter: none;
        opacity: 1;
        pointer-events: auto;
    }
    body.settings-open #searchContainer,
    body.settings-open #contactsList,
    body.settings-open #sidebarStatusBar {
        display: none !important;
    }
    body.settings-open #settingsSidebarPanel {
        display: flex;
        flex: 1;
        min-height: 0;
    }
    body.settings-open #sidebarMain {
        background: #1e293b;
        padding: 18px;
        overflow-y: auto;
        overflow-x: hidden;
    }
    body.settings-open .settings-section.active {
        display: block;
        overflow-y: auto;
        min-height: calc(100vh - 110px);
        padding-bottom: 28px;
    }
    #settingsSectionOverview,
    #settingsMobileBackBtn,
    .settings-header-subtitle {
        display: none !important;
    }
    .settings-side-panel {
        display: none;
        flex-direction: column;
        gap: 14px;
        height: 100%;
        overflow-y: auto;
        padding-bottom: 22px;
        min-height: 0;
    }
    .settings-side-header {
        padding: 18px 18px 8px;
    }
    .settings-side-topline {
        display: flex;
        align-items: center;
        gap: 10px;
        margin-bottom: 8px;
    }
    .settings-side-icon {
        width: 34px;
        height: 34px;
        border-radius: 12px;
        background: rgba(59, 130, 246, 0.12);
        color: #60a5fa;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: inset 0 0 0 1px rgba(96, 165, 250, 0.14);
    }
    .settings-side-header h2 {
        color: #f8fafc;
        font-size: 1.2rem;
        font-weight: 800;
    }
    .settings-side-header p {
        color: #94a3b8;
        font-size: 0.85rem;
        line-height: 1.5;
    }
    .settings-side-profile-card {
        border: none;
        background: rgba(15, 23, 42, 0.74);
        border-radius: 24px;
        padding: 18px;
        display: flex;
        align-items: center;
        gap: 14px;
        cursor: pointer;
        box-shadow: inset 0 0 0 1px rgba(51, 65, 85, 0.9);
        text-align: left;
    }
    .settings-side-avatar {
        width: 62px;
        height: 62px;
        border-radius: 50%;
        background: linear-gradient(135deg, #2563eb, #1d4ed8);
        color: #ffffff;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.35rem;
        font-weight: 800;
        overflow: hidden;
        flex-shrink: 0;
    }
    .settings-side-profile-copy {
        min-width: 0;
        display: flex;
        flex-direction: column;
        gap: 4px;
    }
    .settings-side-profile-copy strong {
        color: #f8fafc;
        font-size: 1.02rem;
        font-weight: 800;
    }
    .settings-side-profile-copy span {
        color: #94a3b8;
        font-size: 0.77rem;
        font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
        word-break: break-all;
    }
    .settings-side-group {
        background: rgba(15, 23, 42, 0.74);
        border-radius: 24px;
        box-shadow: inset 0 0 0 1px rgba(51, 65, 85, 0.9);
        overflow: hidden;
    }
    .settings-side-item {
        width: 100%;
        border: none;
        background: transparent;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 18px;
        color: #e2e8f0;
        font-size: 0.98rem;
        font-weight: 700;
        cursor: pointer;
        transition: background 0.18s ease, color 0.18s ease;
    }
    .settings-side-item + .settings-side-item {
        border-top: 1px solid rgba(51, 65, 85, 0.9);
    }
    .settings-side-item span {
        display: inline-flex;
        align-items: center;
        gap: 10px;
    }
    .settings-side-item i:last-child {
        color: #94a3b8;
    }
    .settings-side-item.active {
        background: rgba(37, 99, 235, 0.16);
        color: #bfdbfe;
    }
    .settings-side-item.active i:last-child {
        color: #bfdbfe;
    }
    .settings-content {
        overflow-y: auto;
        overflow-x: hidden;
    }
}
@media (min-width: 1024px) {
    :root {
        --sidebar-layout-width: 460px;
    }
}
@media (min-width: 1200px) {
    .settings-header,
    .settings-section {
        padding-left: 32px;
        padding-right: 32px;
    }
}
@media (max-width: 767px) {
    .emergency-status-grid,
    .emergency-compose-row {
        grid-template-columns: 1fr;
    }
    .settings-modal {
        inset: 0 0 calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom)) 0;
    }
    .profile-settings-top,
    .profile-qr-card {
        flex-direction: column;
        align-items: stretch;
    }
    .profile-avatar-picker {
        align-self: center;
    }
    .profile-qr-shell {
        align-self: center;
    }
    .settings-section {
        padding: 16px 18px 22px;
        min-height: calc(100dvh - 88px);
        border-bottom: none;
    }
    #settingsSectionOverview.active {
        display: block;
    }
    .settings-header {
        padding: 14px 16px;
    }
    #sidebar.chat-open-mobile + #chatArea,
    #sidebar.chat-open-mobile + #chatArea #activeChat,
    #sidebar.chat-open-mobile + #chatArea #emptyState {
        min-height: 100dvh;
    }
}

.security-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 0;
}

.security-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

@media (min-width: 640px) {
    .security-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.security-card {
    background: rgba(15, 23, 42, 0.72);
    border: 1px solid #334155;
    border-radius: 20px;
    padding: 16px;
}

.security-card.compact {
    padding: 14px;
}

.security-card-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.security-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    margin-bottom: 10px;
    border: 1px solid transparent;
}

.security-badge.good {
    background: rgba(16, 185, 129, 0.14);
    color: #a7f3d0;
    border-color: rgba(16, 185, 129, 0.34);
}

.security-badge.warn {
    background: rgba(59, 130, 246, 0.12);
    color: #bfdbfe;
    border-color: rgba(96, 165, 250, 0.35);
}

.security-badge.danger {
    background: rgba(239, 68, 68, 0.14);
    color: #fecaca;
    border-color: rgba(248, 113, 113, 0.34);
}

.security-badge.info {
    background: rgba(99, 102, 241, 0.14);
    color: #c7d2fe;
    border-color: rgba(129, 140, 248, 0.32);
}

.security-badge.neutral {
    background: rgba(71, 85, 105, 0.28);
    color: #cbd5e1;
    border-color: rgba(100, 116, 139, 0.35);
}

.security-title {
    color: #f8fafc;
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.35;
}

.security-body {
    color: #cbd5e1;
    font-size: 0.9rem;
    line-height: 1.6;
    margin-top: 8px;
}

.security-label {
    display: block;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    font-weight: 800;
    margin-bottom: 8px;
}

.security-code {
    display: block;
    width: 100%;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid #334155;
    background: rgba(2, 6, 23, 0.5);
    color: #e2e8f0;
    font-size: 0.87rem;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    line-height: 1.55;
    word-break: break-all;
    white-space: normal;
}

.security-card-footer {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.security-btn,
.security-icon-btn {
    border: 0;
    cursor: pointer;
    font-weight: 700;
    transition: transform 0.18s ease, opacity 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.security-btn {
    border-radius: 14px;
    padding: 10px 14px;
    background: #2563eb;
    color: #fff;
}

.security-btn.secondary {
    background: rgba(30, 41, 59, 0.92);
    border: 1px solid #334155;
    color: #cbd5e1;
}

.security-btn.danger {
    background: #dc2626;
}

.security-btn:disabled {
    opacity: 0.46;
    cursor: not-allowed;
}

.security-icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 14px;
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid #334155;
    color: #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.security-btn:active,
.security-icon-btn:active {
    transform: scale(0.98);
}

.security-facts {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.security-fact {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: 18px;
    border: 1px solid #334155;
    background: rgba(15, 23, 42, 0.6);
}

.security-fact-icon {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    flex-shrink: 0;
    background: rgba(59, 130, 246, 0.14);
    color: #93c5fd;
    display: flex;
    align-items: center;
    justify-content: center;
}

.security-fact-title {
    color: #e2e8f0;
    font-size: 0.88rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.security-fact-body {
    color: #94a3b8;
    font-size: 0.82rem;
    line-height: 1.5;
}

.privacy-shield {
    position: fixed;
    inset: 0;
    z-index: 15050;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at top, rgba(59, 130, 246, 0.14), transparent 34%),
        rgba(2, 6, 23, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.privacy-shield.active {
    display: flex;
}

.privacy-shield-card {
    width: min(100%, 320px);
    padding: 24px 22px;
    border-radius: 24px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: rgba(15, 23, 42, 0.9);
    box-shadow: 0 24px 80px rgba(2, 6, 23, 0.45);
    text-align: center;
}

.privacy-shield-icon {
    width: 62px;
    height: 62px;
    margin: 0 auto 14px;
    border-radius: 20px;
    background: rgba(59, 130, 246, 0.16);
    color: #bfdbfe;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
}

.privacy-shield-card h3 {
    color: #f8fafc;
    font-size: 1.1rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.privacy-shield-card p {
    color: #cbd5e1;
    font-size: 0.92rem;
    line-height: 1.55;
}

.privacy-shield-btn {
    margin-top: 18px;
    width: 100%;
    border: 0;
    border-radius: 14px;
    padding: 12px 16px;
    background: #2563eb;
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.privacy-shield-btn:active {
    transform: scale(0.99);
}

.toggle { width: 50px; height: 28px; background: #475569; border-radius: 14px; position: relative; cursor: pointer; transition: all 0.3s; }
.toggle.active { background: #3b82f6; }
.toggle::after { content: ''; position: absolute; width: 24px; height: 24px; background: white; border-radius: 50%; top: 2px; left: 2px; transition: all 0.3s; }
.toggle.active::after { left: 24px; }

@keyframes highlight { 0%, 100% { background: transparent; } 50% { background: rgba(59, 130, 246, 0.3); } }
.highlight-message { animation: highlight 2s ease; }

.forward-modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 1500; align-items: flex-end; justify-content: center; }
.forward-modal.active { display: flex; }
.forward-content { background: #1e293b; border-radius: 20px 20px 0 0; width: 100%; max-width: 500px; max-height: 70vh; overflow-y: auto; border: 1px solid #334155; animation: slideUp 0.3s ease; }

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.forward-header { padding: 20px; border-bottom: 1px solid #334155; display: flex; justify-content: space-between; align-items: center; }

#toast {
    position: fixed; top: max(16px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
    background: rgba(30, 41, 59, 0.95); backdrop-filter: blur(10px); color: white; padding: 12px 20px;
    border-radius: 50px; box-shadow: 0 10px 40px rgba(0,0,0,0.4); z-index: 3000; display: none;
    align-items: center; gap: 10px; border: 1px solid rgba(255,255,255,0.1); max-width: 90%;
}

#connCount, #p2pStatus, #statusText {
    color: #e2e8f0;
    font-weight: 600;
}

#addModal > div { max-height: 90vh; overflow-y: auto; margin: 16px; width: calc(100% - 32px); }
@media (min-width: 640px) { #addModal > div { max-width: 400px; margin: auto; } }
@media (max-height: 500px) and (orientation: landscape) {
    .chat-header { padding-top: 8px; padding-bottom: 8px; }
    #messagesContainer { padding: 8px; }
    .input-area { padding: 6px 12px; }
    .mode-selector { padding: 6px 12px; }
    .pinned-message { padding: 8px 12px; }
}

.loading-spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: #fff; animation: spin 1s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.tab-btn { transition: all 0.2s ease; }
.tab-btn:hover { color: white; }
#qr-video {
    background: #020617;
    transform: none;
}

.group-sender { font-size: 11px; color: #93c5fd; font-weight: bold; margin-bottom: 2px; }

.blocked-banner { display:none; text-align:center; padding:10px; background:#ef444420; color:#f87171; font-size:13px; font-weight:bold; }
.blocked-banner.active { display:block; }
#addModal { z-index: 14050 !important; }

body.theme-light {
    background: #eef4ff;
    color: #0f172a;
}

body.theme-light #app,
body.theme-light #chatArea,
body.theme-light #messagesContainer,
body.theme-light .empty-state {
    background: #f8fbff;
}

body.theme-light #sidebar {
    background: #dbeafe;
}

body.theme-light #sidebarMain,
body.theme-light .sidebar-topbar,
body.theme-light .search-container,
body.theme-light .chat-header,
body.theme-light .input-area,
body.theme-light .mode-selector,
body.theme-light .settings-content,
body.theme-light .settings-header,
body.theme-light .settings-section,
body.theme-light .gif-menu,
body.theme-light .mention-menu,
body.theme-light .message-menu,
body.theme-light .image-preview-container,
body.theme-light .pinned-message,
body.theme-light #addModalInner {
    background: #ffffff !important;
    border-color: #cbd5e1 !important;
}

body.theme-light .sidebar-topbar,
body.theme-light .settings-header {
    color: #0f172a !important;
}

body.theme-light .nav-rail {
    background: linear-gradient(180deg, #60a5fa 0%, #3b82f6 100%);
    border-right-color: rgba(37, 99, 235, 0.18);
}

body.theme-light .nav-rail-btn {
    background: rgba(255,255,255,0.68);
    color: #1d4ed8;
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.14);
}

body.theme-light .nav-rail-btn:hover,
body.theme-light .nav-rail-btn:active {
    background: #eff6ff;
}

body.theme-light .sidebar-topbar-title,
body.theme-light #settingsHeaderTitle,
body.theme-light .settings-modal-title,
body.theme-light .sidebar-topbar-copy,
body.theme-light .settings-header-copy {
    color: #0f172a !important;
}

body.theme-light .sidebar-topbar-plus {
    background: #2563eb;
    border-color: rgba(37, 99, 235, 0.35);
    color: #ffffff !important;
}

body.theme-light .emergency-card,
body.theme-light .emergency-status-box,
body.theme-light .emergency-code-area,
body.theme-light .emergency-message-input,
body.theme-light .emergency-message-item,
body.theme-light .emergency-advanced,
body.theme-light .emergency-contact-item,
body.theme-light .emergency-relay-target,
body.theme-light .emergency-relay-entry {
    background: #ffffff !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

body.theme-light .emergency-advanced summary {
    color: #0f172a !important;
}

body.theme-light .emergency-contact-copy strong,
body.theme-light .emergency-relay-entry-body {
    color: #0f172a !important;
}

body.theme-light .emergency-contact-copy span,
body.theme-light .emergency-relay-entry-meta {
    color: #475569 !important;
}

body.theme-light .emergency-contact-btn {
    background: #f8fafc !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

body.theme-light .emergency-contact-btn.favorite {
    color: #b45309 !important;
}

body.theme-light .emergency-qr-shell,
body.theme-light .emergency-scan-sheet,
body.theme-light .emergency-scan-status {
    background: #ffffff !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

body.theme-light .emergency-scan-header h3,
body.theme-light .emergency-scan-header p {
    color: #0f172a !important;
}

body.theme-light .emergency-scan-close {
    background: #f8fafc !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

body.theme-light .btn-round:not(#sendButton) {
    background: #e2e8f0 !important;
    color: #334155 !important;
    border-color: #cbd5e1 !important;
}

body.theme-light #messageInput,
body.theme-light .search-input,
body.theme-light .gif-search-box input,
body.theme-light #settingsModal select,
body.theme-light #addModal input {
    background: #f8fafc !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

body.theme-light .message-bubble.bg-slate-700 {
    background: #e2e8f0 !important;
    color: #0f172a !important;
}

body.theme-light .message-bubble.bg-slate-700 .quoted-content {
    background: rgba(15, 23, 42, 0.05);
    border-left-color: rgba(15, 23, 42, 0.18);
}

body.theme-light .message-bubble.bg-slate-700 .group-sender {
    color: #2563eb;
}

body.theme-light .reaction {
    background: rgba(15, 23, 42, 0.08);
    color: #0f172a;
}

body.theme-light .mode-option {
    background: #e2e8f0;
    color: #475569;
}

body.theme-light .mode-option.active {
    background: #dbeafe;
}

body.theme-light .toggle {
    background: #cbd5e1;
}

body.theme-light .toggle.active {
    background: #3b82f6;
}

body.theme-light .text-slate-100,
body.theme-light .text-slate-200,
body.theme-light .text-slate-300,
body.theme-light .contact-name,
body.theme-light #settingsModal h3,
body.theme-light #settingsModal h4,
body.theme-light #settingsModal .settings-item span,
body.theme-light #addModal h3,
body.theme-light #addModal label {
    color: #0f172a !important;
}

body.theme-light .text-slate-400,
body.theme-light .text-slate-500,
body.theme-light .contact-preview {
    color: #64748b !important;
}

body.theme-light .border-slate-700,
body.theme-light .border-slate-800 {
    border-color: #cbd5e1 !important;
}

body.theme-light .bg-slate-900,
body.theme-light .bg-slate-800 {
    background: #ffffff !important;
}

body.theme-light .bg-slate-700 {
    background: #e2e8f0 !important;
}

body.theme-light .settings-pill {
    background: #f8fbff;
    color: #1e293b;
    border-color: #cbd5e1;
}

body.theme-light .settings-pill.active {
    background: rgba(59, 130, 246, 0.12);
    color: #1d4ed8;
    border-color: rgba(37, 99, 235, 0.4);
}

body.theme-light .settings-preview-box,
body.theme-light .message-menu-preview,
body.theme-light .date-separator span,
body.theme-light .file-card,
body.theme-light .menu-item:hover {
    background: rgba(239, 246, 255, 0.96);
}

body.theme-light .settings-range-scale,
body.theme-light .settings-caption,
body.theme-light .menu-item-copy small,
body.theme-light .menu-preview-topline span:last-child,
body.theme-light .menu-preview-body,
body.theme-light .file-card-meta,
body.theme-light .security-fact-body,
body.theme-light .security-label {
    color: #64748b;
}

body.theme-light .privacy-shield {
    background:
        radial-gradient(circle at top, rgba(37, 99, 235, 0.1), transparent 34%),
        rgba(241, 245, 249, 0.92);
}

body.theme-light .privacy-shield-card {
    background: rgba(255, 255, 255, 0.94);
    border-color: rgba(148, 163, 184, 0.3);
    box-shadow: 0 24px 80px rgba(148, 163, 184, 0.24);
}

body.theme-light .privacy-shield-card h3 {
    color: #0f172a;
}

body.theme-light .privacy-shield-card p {
    color: #475569;
}

body.theme-light .security-card,
body.theme-light .security-fact {
    background: rgba(248, 250, 252, 0.92);
    border-color: #cbd5e1;
}

body.theme-light .security-title,
body.theme-light .security-fact-title {
    color: #0f172a;
}

body.theme-light .security-body,
body.theme-light .security-code,
body.theme-light .security-icon-btn,
body.theme-light .security-btn.secondary {
    color: #1e293b;
}

body.theme-light .security-code,
body.theme-light .security-btn.secondary,
body.theme-light .security-icon-btn {
    background: #ffffff;
    border-color: #cbd5e1;
}

body.theme-light .security-fact-icon {
    background: rgba(37, 99, 235, 0.1);
    color: #2563eb;
}

body.theme-light .menu-preview-title,
body.theme-light .file-card-title {
    color: #0f172a;
}

body.theme-light .menu-preview-meta span,
body.theme-light .file-card-meta span {
    background: #eff6ff;
    color: #334155;
}

body.theme-light #connCount,
body.theme-light #p2pStatus,
body.theme-light #statusText {
    color: #0f172a;
}

.onboarding-overlay {
    position: fixed;
    inset: 0;
    z-index: 16000;
    display: none;
    pointer-events: auto;
}

.onboarding-overlay.active {
    display: block !important;
}

.onboarding-spotlight {
    position: fixed;
    left: 0;
    top: 0;
    width: 120px;
    height: 80px;
    border-radius: 24px;
    border: 2px solid rgba(96, 165, 250, 0.92);
    background: rgba(59, 130, 246, 0.08);
    box-shadow: 0 0 0 9999px rgba(2, 6, 23, 0.76), 0 0 0 10px rgba(59, 130, 246, 0.12);
    transition: left 0.28s ease, top 0.28s ease, width 0.28s ease, height 0.28s ease, border-radius 0.28s ease;
    pointer-events: none;
}

.onboarding-spotlight::after {
    content: '';
    position: absolute;
    inset: -10px;
    border-radius: inherit;
    border: 1px solid rgba(147, 197, 253, 0.55);
    animation: onboardingPulse 1.6s ease-in-out infinite;
}

.onboarding-card {
    position: fixed;
    left: 16px;
    top: 16px;
    width: min(360px, calc(100vw - 32px));
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.98), rgba(15, 23, 42, 0.98));
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 24px;
    box-shadow: 0 22px 60px rgba(2, 6, 23, 0.58);
    padding: 20px;
    color: white;
    transition: left 0.28s ease, top 0.28s ease;
}

.onboarding-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.onboarding-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.16);
    color: #bfdbfe;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    padding: 6px 12px;
}

.onboarding-close {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    border: 1px solid rgba(71, 85, 105, 0.9);
    background: rgba(15, 23, 42, 0.9);
    color: #cbd5e1;
}

.onboarding-title {
    margin-top: 14px;
    font-size: 26px;
    line-height: 1.1;
    font-weight: 900;
}

.onboarding-text {
    margin-top: 10px;
    color: #cbd5e1;
    font-size: 14px;
    line-height: 1.6;
}

.onboarding-hint {
    margin-top: 14px;
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.82);
    border: 1px solid rgba(59, 130, 246, 0.22);
    color: #93c5fd;
    font-size: 13px;
    line-height: 1.5;
    padding: 12px 14px;
}

.onboarding-progress {
    display: flex;
    gap: 8px;
    margin-top: 18px;
}

.onboarding-progress span {
    flex: 1;
    height: 6px;
    border-radius: 999px;
    background: rgba(71, 85, 105, 0.7);
    overflow: hidden;
}

.onboarding-progress span.active {
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
}

.onboarding-actions {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin-top: 18px;
}

.onboarding-btn {
    flex: 1;
    min-height: 46px;
    border-radius: 16px;
    font-weight: 800;
    font-size: 14px;
    border: 1px solid rgba(71, 85, 105, 0.9);
    background: rgba(15, 23, 42, 0.86);
    color: #e2e8f0;
}

.onboarding-btn.primary {
    background: linear-gradient(90deg, #2563eb, #1d4ed8);
    border-color: transparent;
    color: white;
    box-shadow: 0 14px 30px rgba(29, 78, 216, 0.32);
}

@keyframes onboardingPulse {
    0%, 100% { opacity: 0.45; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.03); }
}

@media (max-width: 767px) {
    .onboarding-card {
        width: calc(100vw - 24px);
        left: 12px;
        right: 12px;
        top: auto;
        bottom: 12px;
        max-height: min(56vh, 420px);
        overflow-y: auto;
        padding: 18px;
        border-radius: 22px;
    }

    .onboarding-title {
        font-size: 22px;
    }
}

:root {
    --brand-accent: #2563eb;
    --brand-accent-2: #60a5fa;
    --brand-bg: #0f172a;
    --brand-bg-rgb: 15, 23, 42;
    --brand-surface: #1e293b;
    --brand-surface-rgb: 30, 41, 59;
    --brand-surface-2: #162236;
    --brand-border: #334155;
    --brand-text: #f8fafc;
    --brand-text-muted: #94a3b8;
    --brand-accent-soft: rgba(37, 99, 235, 0.18);
    --brand-accent-soft-strong: rgba(37, 99, 235, 0.34);
    --brand-accent-shadow: rgba(37, 99, 235, 0.28);
    --brand-accent-text: #bfdbfe;
    --brand-on-accent: #ffffff;
    --brand-nav-button-bg: rgba(30, 64, 175, 0.45);
    --brand-nav-button-bg-strong: rgba(30, 64, 175, 0.8);
}

.brand-color-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.brand-color-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border-radius: 18px;
    border: 1px solid var(--brand-border);
    background: rgba(var(--brand-surface-rgb), 0.92);
}

.brand-color-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--brand-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.brand-color-input-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand-color-input {
    width: 48px;
    height: 48px;
    border: none;
    padding: 0;
    border-radius: 16px;
    background: transparent;
    cursor: pointer;
    overflow: hidden;
}

.brand-color-input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.brand-color-input::-webkit-color-swatch,
.brand-color-input::-moz-color-swatch {
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
}

.brand-color-value {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.78rem;
    color: var(--brand-text);
    word-break: break-all;
}

.brand-preview-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px;
    border-radius: 24px;
    border: 1px solid var(--brand-border);
    background: linear-gradient(135deg, rgba(var(--brand-surface-rgb), 0.98), rgba(var(--brand-bg-rgb), 0.96));
    box-shadow: 0 20px 44px rgba(var(--brand-bg-rgb), 0.32);
}

.brand-preview-icon-shell {
    width: 78px;
    height: 78px;
    border-radius: 24px;
    padding: 10px;
    flex-shrink: 0;
    background: rgba(var(--brand-bg-rgb), 0.82);
    border: 1px solid var(--brand-border);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.brand-preview-icon-image {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 0;
    object-fit: contain;
    background: transparent;
}

.brand-preview-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

html,
body {
    background: var(--brand-bg);
    color: var(--brand-text);
}

#chatArea,
#messagesContainer,
.empty-state {
    background: var(--brand-bg) !important;
}

#sidebarMain,
.sidebar-topbar,
.search-container,
.chat-header,
.input-area,
.mode-selector,
.settings-content,
.settings-header,
.settings-section,
.gif-menu,
.mention-menu,
.message-menu,
.image-preview-container,
.forward-content,
.profile-qr-card,
.settings-preview-box,
.profile-id-chip,
.security-card,
.security-fact,
.file-card,
#addModalInner {
    border-color: var(--brand-border) !important;
}

#sidebarMain,
.sidebar-topbar,
.search-container,
.chat-header,
.input-area,
.mode-selector,
.gif-menu,
.mention-menu,
.message-menu,
.image-preview-container,
.forward-content,
.profile-qr-card,
.settings-preview-box,
.profile-id-chip,
.security-card,
.security-fact,
.file-card,
#addModalInner {
    background: var(--brand-surface) !important;
}

.settings-content {
    background: linear-gradient(180deg, rgba(var(--brand-bg-rgb), 0.98), rgba(var(--brand-surface-rgb), 0.96)) !important;
}

.settings-header {
    background: rgba(var(--brand-bg-rgb), 0.96) !important;
}

.nav-rail {
    background: linear-gradient(180deg, var(--brand-accent) 0%, var(--brand-accent-2) 100%) !important;
}

.nav-rail-btn {
    background: var(--brand-nav-button-bg) !important;
}

.nav-rail-btn:hover,
.nav-rail-btn:active {
    background: var(--brand-nav-button-bg-strong) !important;
}

.nav-rail-bolt,
.profile-avatar-core,
.profile-qr-avatar,
.settings-side-avatar {
    background: linear-gradient(135deg, var(--brand-accent), var(--brand-accent-2)) !important;
    box-shadow: 0 18px 34px var(--brand-accent-shadow);
}

.profile-avatar-edit {
    border-color: var(--brand-accent) !important;
    color: var(--brand-accent-text) !important;
}

.settings-pill.active,
.brand-preset-pill.active,
.reaction.me,
.speed-btn.active,
.toggle.active,
.swipe-action-icon.active,
.security-btn:not(.secondary),
#sendButton,
.bg-blue-600 {
    background: var(--brand-accent) !important;
    color: var(--brand-on-accent) !important;
}

.reply-preview,
.mention.self-mention {
    background: var(--brand-accent-soft) !important;
    border-color: var(--brand-accent) !important;
}

.pinned-message::before {
    background: var(--brand-accent) !important;
}

.pinned-icon,
.pinned-name,
.reply-preview .reply-name,
.group-sender,
.file-card-icon,
.text-blue-100,
.text-blue-200,
.text-blue-300,
.text-blue-400,
.text-blue-500,
.text-blue-600 {
    color: var(--brand-accent-text) !important;
}

.border-blue-400,
.border-blue-500,
.border-l-blue-500 {
    border-color: var(--brand-accent) !important;
}

.hover\:bg-blue-500:hover,
.bg-blue-700 {
    background: var(--brand-accent-2) !important;
}

.search-input,
.gif-search-box input,
#messageInput,
.profile-name-input,
.settings-select,
.settings-pill,
.btn-round:not(#sendButton),
.security-btn.secondary,
.security-icon-btn,
.profile-id-chip {
    background: var(--brand-surface-2) !important;
    border-color: var(--brand-border) !important;
}

.search-input,
.gif-search-box input,
#messageInput,
.profile-name-input,
.settings-select,
.security-btn.secondary,
.security-icon-btn {
    color: var(--brand-text) !important;
}

#messageInput:focus,
.search-input:focus,
.gif-search-box input:focus,
.profile-name-input:focus,
.settings-select:focus {
    border-color: var(--brand-accent) !important;
    box-shadow: 0 0 0 3px var(--brand-accent-soft) !important;
}

.settings-range {
    background: linear-gradient(90deg, var(--brand-accent), var(--brand-accent-2)) !important;
}

.settings-range::-webkit-slider-thumb,
.settings-range::-moz-range-thumb {
    border-color: var(--brand-accent) !important;
    box-shadow: 0 4px 16px var(--brand-accent-shadow) !important;
}

.settings-caption,
.settings-range-scale,
.profile-qr-subtitle,
.profile-qr-caption,
.contact-preview,
.text-slate-400,
.text-slate-500 {
    color: var(--brand-text-muted) !important;
}

@media (max-width: 640px) {
    .brand-color-grid {
        grid-template-columns: 1fr;
    }

    .brand-preview-card {
        flex-direction: column;
        align-items: flex-start;
    }
}

.feedback-modal {
    position: fixed;
    inset: 0;
    z-index: 1400;
    display: none;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(8px);
}

.feedback-modal.hidden { display: none; }
.feedback-modal:not(.hidden) { display: flex; }

#groupModal,
#forwardModal,
#drawModal,
#callModal,
#addModal,
#imageModal,
#issueReportModal,
#transferReceiveModal,
#transferSendModal,
#permissionsModal,
#qrAcceptModal,
#contactActionsModal,
[data-modal-root="true"] {
    z-index: 19000 !important;
}

#toast {
    z-index: 19500 !important;
}

.feedback-sheet {
    width: min(100%, 520px);
    border-radius: 24px;
    background: #0f172a;
    border: 1px solid #334155;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.feedback-header,
.feedback-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.feedback-header strong {
    color: #f8fafc;
    display: block;
    margin-bottom: 4px;
}

.feedback-header p,
.feedback-meta {
    color: #94a3b8;
    font-size: 0.82rem;
    line-height: 1.45;
}

.feedback-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.feedback-textarea {
    width: 100%;
    min-height: 132px;
    resize: vertical;
    border-radius: 16px;
    border: 1px solid #334155;
    background: #020617;
    color: #e2e8f0;
    padding: 14px 16px;
    outline: none;
}

.feedback-textarea:focus {
    border-color: #3b82f6;
}

@media (max-width: 767px) {
    .profile-settings-top {
        flex-direction: column;
        align-items: stretch;
    }

    .profile-avatar-picker {
        margin: 0 auto;
    }

    .profile-settings-actions {
        flex-direction: column;
    }

    .profile-settings-actions .security-btn {
        width: 100%;
    }

    .feedback-modal {
        padding: 12px;
    }

    .feedback-sheet {
        border-radius: 22px 22px 18px 18px;
        padding-bottom: calc(18px + env(safe-area-inset-bottom));
        max-height: calc(100vh - 24px);
        overflow-y: auto;
    }

    .feedback-footer {
        flex-direction: column;
    }

    .feedback-footer .security-btn {
        width: 100%;
    }
}

.chat-gif {
    max-width: 160px;
    max-height: 160px;
    object-fit: contain;
    background: transparent;
    border-radius: 18px;
    cursor: default;
    display: block;
}

@media (min-width: 768px) {
    .chat-gif {
        max-width: 200px;
        max-height: 200px;
    }
}

.brand-color-grid,
.brand-color-card,
.brand-preview-card,
#brandPresetButtons {
    display: none !important;
}

html,
body {
    background: #0f172a !important;
    color: #f8fafc !important;
}

#chatArea,
#messagesContainer,
.empty-state {
    background: #0f172a !important;
}

#sidebarMain,
.sidebar-topbar,
.search-container,
.chat-header,
.input-area,
.mode-selector,
.settings-content,
.settings-header,
.settings-section,
.gif-menu,
.mention-menu,
.message-menu,
.image-preview-container,
.forward-content,
.profile-qr-card,
.settings-preview-box,
.profile-id-chip,
.security-card,
.security-fact,
.file-card,
#addModalInner {
    background: #1e293b !important;
    border-color: #334155 !important;
}

.settings-content,
.settings-header,
.nav-rail,
.profile-avatar-core,
.profile-qr-avatar,
.settings-side-avatar,
.onboarding-card,
.onboarding-progress span.active,
.onboarding-btn.primary,
.nav-rail-bolt {
    background-image: none !important;
}

.settings-content,
.settings-header {
    background: #0f172a !important;
}

.nav-rail {
    background: #1d4ed8 !important;
}

.nav-rail-btn {
    background: rgba(30, 64, 175, 0.78) !important;
    box-shadow: none !important;
}

.nav-rail-btn:hover,
.nav-rail-btn:active {
    background: rgba(30, 64, 175, 0.92) !important;
}

.nav-rail-bolt,
.profile-avatar-core,
.profile-qr-avatar,
.settings-side-avatar {
    background: #2563eb !important;
    box-shadow: none !important;
}

.settings-pill.active,
.reaction.me,
.speed-btn.active,
.toggle.active,
.swipe-action-icon.active,
.security-btn:not(.secondary),
#sendButton,
.bg-blue-600 {
    background: #2563eb !important;
    color: #ffffff !important;
}

.hover\:bg-blue-500:hover,
.bg-blue-700 {
    background: #1d4ed8 !important;
}

.settings-range {
    background: #cbd5e1 !important;
}

.settings-range::-webkit-slider-thumb,
.settings-range::-moz-range-thumb {
    border-color: #2563eb !important;
    box-shadow: none !important;
}

body.theme-light {
    background: #eef4ff !important;
    color: #0f172a !important;
}

body.theme-light #app,
body.theme-light #chatArea,
body.theme-light #messagesContainer,
body.theme-light .empty-state,
body.theme-light .settings-content,
body.theme-light .settings-header {
    background: #f8fbff !important;
}

body.theme-light .nav-rail {
    background: #bfdbfe !important;
}

body.theme-light .nav-rail-btn {
    background: #ffffff !important;
    color: #1d4ed8 !important;
    box-shadow: none !important;
}

body.theme-light .nav-rail-btn:hover,
body.theme-light .nav-rail-btn:active {
    background: #eff6ff !important;
}

body.theme-light .privacy-shield {
    background: rgba(241, 245, 249, 0.94) !important;
}
