:root {
    --bg-dark: #0f172a;
    --sidebar-bg: #1e293b;
    --chat-bg: #0b1120;
    --card-bg: #334155;
    --border: #334155;
    --border-light: rgba(255, 255, 255, 0.08);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --accent: #10b981;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --bubble-mine: #2563eb;
    --bubble-theirs: #1e293b;
    --danger: #ef4444;
    --warning: #f59e0b;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background-color: var(--bg-dark);
    color: var(--text-main);
}

.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* =========================================================================
   SIDEBAR (CONTACTS & GROUPS)
   ========================================================================= */

.sidebar {
    width: 360px;
    min-width: 320px;
    max-width: 420px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
    z-index: 20;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-light);
}

.user-profile-badge {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-circle {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.user-info-text {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 15px;
    color: #fff;
}

.user-status {
    font-size: 12px;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 4px;
}

.header-action-btns {
    display: flex;
    gap: 6px;
}

.icon-btn-sm {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.2s;
}

.icon-btn-sm:hover {
    color: #fff;
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
}

.sidebar-search-box {
    padding: 12px 16px;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input-wrapper input {
    width: 100%;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px 10px 36px;
    color: #fff;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.search-input-wrapper input:focus {
    border-color: var(--primary);
}

.search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    pointer-events: none;
}

.sidebar-tabs {
    display: flex;
    padding: 0 16px 8px 16px;
    gap: 8px;
    border-bottom: 1px solid var(--border-light);
}

.tab-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 8px 0;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: 0.2s;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.rooms-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.room-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-radius: 12px;
    gap: 12px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 4px;
}

.room-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.room-item.active {
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.room-item-avatar {
    position: relative;
}

.room-item-content {
    flex: 1;
    min-width: 0;
}

.room-item-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}

.room-item-name {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-item-time {
    font-size: 11px;
    color: var(--text-muted);
}

.room-item-snippet {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* =========================================================================
   RIGHT CHAT AREA
   ========================================================================= */

.chat-area {
    flex: 1;
    background: var(--chat-bg);
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 16px;
    font-size: 16px;
    text-align: center;
    padding: 20px;
}

.active-chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow: hidden;
}

.chat-header {
    height: 64px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-title-text {
    font-weight: 700;
    font-size: 16px;
    color: #fff;
}

.chat-subtitle-e2e {
    font-size: 12px;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.call-btn {
    background: #1e293b;
    border: 1px solid var(--border);
    color: #fff;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: 0.2s;
}

.call-btn:hover {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.2);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* MESSAGE BUBBLES */
.msg-row {
    display: flex;
    width: 100%;
}

.msg-row.mine {
    justify-content: flex-end;
}

.msg-row.theirs {
    justify-content: flex-start;
}

.msg-row.sys {
    justify-content: center;
}

.msg-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    word-break: break-word;
    user-select: text;
}

.msg-bubble.mine {
    background: var(--bubble-mine);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg-bubble.theirs {
    background: var(--bubble-theirs);
    color: #e2e8f0;
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

.msg-bubble.sys {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    font-size: 12px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    box-shadow: none;
}

.msg-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    opacity: 0.75;
    margin-top: 4px;
}

.quote-box {
    background: rgba(0, 0, 0, 0.25);
    border-left: 3px solid #60a5fa;
    padding: 6px 8px;
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 12px;
    color: #cbd5e1;
}

/* MEDIA IN BUBBLE */
.msg-media-preview {
    max-width: 320px;
    border-radius: 10px;
    overflow: hidden;
    margin-top: 4px;
}

.msg-media-preview img, .msg-media-preview video {
    width: 100%;
    display: block;
    border-radius: 10px;
}

.msg-file-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.2);
    padding: 10px 14px;
    border-radius: 10px;
    margin-top: 4px;
}

/* REPLY BAR */
.reply-preview-wrapper {
    background: #1e293b;
    border-top: 1px solid var(--border);
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-muted);
}

.activity-status {
    padding: 4px 16px;
    font-size: 12px;
    color: var(--primary);
    font-style: italic;
    min-height: 18px;
}

/* INPUT FOOTER */
.chat-input-footer {
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-shrink: 0;
}

.chat-input-footer textarea {
    flex: 1;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 10px 16px;
    color: #fff;
    font-size: 14px;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.chat-input-footer textarea:focus {
    border-color: var(--primary);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

.icon-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
}

.send-btn {
    background: var(--primary);
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

/* =========================================================================
   ACTION SHEET (ШТОРКА ДЕЙСТВИЙ СООБЩЕНИЯ) & MODALS
   ========================================================================= */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-card {
    background: var(--sidebar-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.action-sheet-modal {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    padding: 20px;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 500px;
    margin: 0 auto;
    animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.action-sheet-btn {
    background: #0f172a;
    border: 1px solid var(--border);
    color: #fff;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: 0.15s;
    text-align: left;
}

.action-sheet-btn:hover {
    background: #1e293b;
    border-color: var(--primary);
}

.action-sheet-btn.danger {
    color: var(--danger);
}

/* =========================================================================
   EASTER EGG ANIMATIONS (/love, /kiss, /biglove, /kat, /shake, etc.)
   ========================================================================= */

.floating-heart {
    position: fixed;
    bottom: 10px;
    animation: floatUp 2.5s ease-in-out forwards;
    pointer-events: none;
    z-index: 9999;
}

@keyframes floatUp {
    0% { transform: translateY(0) scale(0.8); opacity: 1; }
    50% { transform: translateY(-40vh) scale(1.3); opacity: 0.9; }
    100% { transform: translateY(-80vh) scale(1.8); opacity: 0; }
}

.big-secret-heart {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.1);
    font-size: 180px;
    z-index: 9999;
    pointer-events: none;
    animation: pulseHeart 1.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes pulseHeart {
    0% { transform: translate(-50%, -50%) scale(0.1); opacity: 0.3; }
    50% { transform: translate(-50%, -50%) scale(1.4); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(2.2); opacity: 0; }
}

.shake-active {
    animation: screenShake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes screenShake {
    10%, 90% { transform: translate3d(-2px, 0, 0); }
    20%, 80% { transform: translate3d(4px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
    40%, 60% { transform: translate3d(6px, 0, 0); }
}

/* MOBILE RESPONSIVE */
@media (max-width: 768px) {
    .sidebar {
        width: 100vw;
        max-width: 100vw;
        position: absolute;
        inset: 0;
    }
    .sidebar.hidden-mobile {
        transform: translateX(-100%);
    }
    .chat-area {
        width: 100vw;
    }
}