* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #121220;
    --bg-secondary: #1c1c35;
    --bg-tertiary: #222240;
    --accent: #e94560;
    --accent-hover: #c73a52;
    --text-primary: #f0f0f8;
    --text-secondary: #9595b0;
    --text-muted: #606080;
    --border: #2e2e50;
    --border-light: #252545;
    --success: #50d070;
    --danger: #ff6b6b;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="midnight"] {
    --bg-primary: #0d0d2b;
    --bg-secondary: #161645;
    --bg-tertiary: #1c1c55;
    --accent: #9b7dff;
    --accent-hover: #7c5cff;
    --text-primary: #f0eeff;
    --text-secondary: #a0a0cc;
    --text-muted: #6565a0;
    --border: #2a2a60;
    --border-light: #222250;
    --success: #7cdd8a;
    --danger: #ff7a8a;
}

[data-theme="midnight"] #sidebar {
    background-image: 
        radial-gradient(ellipse at 20% 50%, rgba(155, 125, 255, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(120, 90, 255, 0.04) 0%, transparent 50%);
}

[data-theme="midnight"] #chat-area {
    background-image: 
        radial-gradient(ellipse at 70% 30%, rgba(155, 125, 255, 0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 30% 90%, rgba(100, 80, 200, 0.03) 0%, transparent 50%);
}

[data-theme="ocean"] {
    --bg-primary: #0c1a2a;
    --bg-secondary: #12253a;
    --bg-tertiary: #162d45;
    --accent: #00d4e8;
    --accent-hover: #00b8cc;
    --text-primary: #e8f4ff;
    --text-secondary: #80b0d0;
    --text-muted: #5080a0;
    --border: #1e3850;
    --border-light: #182e42;
    --success: #50e8a0;
    --danger: #ff8a8a;
}

[data-theme="ocean"] #sidebar {
    background-image: 
        radial-gradient(ellipse at 30% 20%, rgba(0, 212, 232, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(0, 180, 200, 0.05) 0%, transparent 40%),
        repeating-linear-gradient(135deg, transparent 0px, transparent 40px, rgba(0, 212, 232, 0.015) 40px, rgba(0, 212, 232, 0.015) 41px);
}

[data-theme="ocean"] #chat-area {
    background-image: 
        radial-gradient(ellipse at 60% 40%, rgba(0, 200, 220, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse at 20% 80%, rgba(0, 160, 200, 0.04) 0%, transparent 40%);
}

[data-theme="forest"] {
    --bg-primary: #0c1a10;
    --bg-secondary: #132a18;
    --bg-tertiary: #18321e;
    --accent: #6ddb75;
    --accent-hover: #50c05a;
    --text-primary: #e8ffe8;
    --text-secondary: #90c8a0;
    --text-muted: #508060;
    --border: #1e3a25;
    --border-light: #183020;
    --success: #80ee90;
    --danger: #ff8a8a;
}

[data-theme="forest"] #sidebar {
    background-image: 
        radial-gradient(ellipse at 25% 30%, rgba(109, 219, 117, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 75% 70%, rgba(80, 192, 90, 0.05) 0%, transparent 40%),
        repeating-conic-gradient(rgba(109, 219, 117, 0.02) 0deg 3deg, transparent 3deg 6deg);
}

[data-theme="forest"] #chat-area {
    background-image: 
        radial-gradient(ellipse at 50% 50%, rgba(100, 200, 110, 0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(80, 180, 90, 0.03) 0%, transparent 40%);
}

[data-theme="sunset"] {
    --bg-primary: #1a0f0d;
    --bg-secondary: #281815;
    --bg-tertiary: #301e1a;
    --accent: #ffa540;
    --accent-hover: #ff8c00;
    --text-primary: #fff0e8;
    --text-secondary: #d0a090;
    --text-muted: #a07060;
    --border: #3a2520;
    --border-light: #30201a;
    --success: #80e080;
    --danger: #ff7070;
}

[data-theme="sunset"] #sidebar {
    background-image: 
        radial-gradient(ellipse at 20% 40%, rgba(255, 165, 64, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 70%, rgba(255, 140, 0, 0.04) 0%, transparent 40%);
}

[data-theme="sunset"] #chat-area {
    background-image: 
        radial-gradient(ellipse at 60% 30%, rgba(255, 165, 64, 0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 30% 80%, rgba(255, 120, 0, 0.03) 0%, transparent 40%);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

#app {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

#sidebar {
    width: 340px;
    min-width: 340px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

.header-avatar-wrap {
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
}

.avatar-status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--success);
    border: 2px solid var(--bg-secondary);
}

.user-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 180px;
    z-index: 200;
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: menuIn 0.15s ease-out;
}

.user-menu.open {
    display: block;
}

@keyframes menuIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: var(--transition);
}

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

.user-menu-item.danger {
    color: var(--danger);
}

.user-menu-item.danger:hover {
    background: rgba(255, 107, 107, 0.1);
}

.user-menu-section {
    padding: 8px 14px 4px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.theme-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.theme-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--border);
    flex-shrink: 0;
}

.theme-check {
    margin-left: auto;
    color: var(--accent);
    font-weight: 600;
    display: none;
}

.theme-check.active {
    display: inline;
}

.user-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.chat-loading {
    display: inline-flex;
    align-items: center;
    margin-left: 4px;
}

.loading-dots {
    display: flex;
    gap: 3px;
    align-items: center;
}

.loading-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: loadingDot 1.4s infinite both;
}

.loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes loadingDot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

.delete-icon {
    margin: 0 auto 12px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(255, 107, 107, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-search {
    flex: 1;
    position: relative;
}

.header-search .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.header-search #search-input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    transition: var(--transition);
}

.header-search #search-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.15);
}

.header-search #search-results {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 240px;
    overflow-y: auto;
    z-index: 200;
    box-shadow: var(--shadow);
}

.auth-logo svg {
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.avatar-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #ff6b8a);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
}

.avatar-circle:hover {
    transform: scale(1.05);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.3);
}

.avatar-circle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.contact-avatar {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: linear-gradient(135deg, #0f3460, #1a4a7a);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
}

.contact-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-avatar-large {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #ff6b8a);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    font-weight: 700;
    color: white;
    margin: 0 auto 16px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(233, 69, 96, 0.3);
}

.profile-avatar-large img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.partner-avatar-full {
    width: 100%;
    max-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    overflow: hidden;
    border-radius: var(--radius-lg);
}

.partner-avatar-full img {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    border-radius: var(--radius-lg);
}

.partner-avatar-full .avatar-placeholder {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #ff6b8a);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 42px;
    font-weight: 700;
    color: white;
}

.profile-avatar-label {
    display: block;
    text-align: center;
    color: var(--accent);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 8px;
    transition: var(--transition);
}

.profile-avatar-label:hover {
    color: var(--accent-hover);
}

.profile-remove-avatar {
    display: block;
    margin: 0 auto 20px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.profile-remove-avatar:hover {
    color: var(--danger);
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.uid-display {
    font-size: 12px;
    color: var(--text-secondary);
    word-break: break-all;
    padding: 6px 10px;
    background: var(--bg-primary);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
}

.uid-display:hover {
    background: var(--border);
    color: var(--text-primary);
}

#contacts-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.contact-item {
    padding: 12px;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: var(--transition);
    margin-bottom: 2px;
}

.contact-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.contact-item.active {
    background: rgba(233, 69, 96, 0.15);
}

.contact-info {
    flex: 1;
    overflow: hidden;
}

.contact-uid {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
}

.contact-last-msg {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.contact-status.online {
    background: var(--success);
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.5);
}

#chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
}

#chat-header {
    padding: 14px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

#back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: var(--transition);
}

#back-btn:hover {
    background: rgba(233, 69, 96, 0.1);
}

#chat-with {
    font-weight: 600;
    font-size: 15px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    transition: var(--transition);
}

#chat-with:hover {
    color: var(--accent);
}

#chat-status {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 10px;
    background: var(--bg-primary);
    border-radius: 20px;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
}

.message {
    max-width: 65%;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    position: relative;
    word-wrap: break-word;
    animation: messageIn 0.2s ease-out;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.empty-chat {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    padding: 40px 20px;
}

.message.sent {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--accent), #d63d56);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 10px;
    opacity: 0.6;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    justify-content: flex-end;
}

.message-status {
    font-size: 10px;
    opacity: 0.6;
}

.delete-btn {
    background: none;
    border: none;
    color: inherit;
    opacity: 0;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 4px;
    transition: var(--transition);
}

.message:hover .delete-btn {
    opacity: 0.5;
}

.delete-btn:hover {
    opacity: 1 !important;
    color: var(--danger);
    background: rgba(255, 107, 107, 0.1);
}

#input-area {
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    align-items: center;
}

#message-input {
    flex: 1;
    padding: 12px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    transition: var(--transition);
    outline: none;
}

#message-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.15);
}

#message-input:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#send-btn {
    padding: 12px 20px;
    background: linear-gradient(135deg, var(--accent), #d63d56);
    border: none;
    border-radius: var(--radius-xl);
    color: white;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: var(--transition);
    white-space: nowrap;
}

#send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

#send-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(233, 69, 96, 0.4);
}

#send-btn:active:not(:disabled) {
    transform: translateY(0);
}

.auth-logo {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--accent), #ff6b8a);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 800;
    color: white;
    margin: 0 auto 16px;
    letter-spacing: -2px;
    box-shadow: 0 8px 32px rgba(233, 69, 96, 0.3);
}

.auth-title {
    font-size: 36px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), #ff6b8a, #ff8fa3);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 32px;
    letter-spacing: -1px;
    line-height: 1.1;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-primary);
    padding: 4px;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: 8px;
    transition: var(--transition);
}

.auth-tab.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px rgba(233, 69, 96, 0.3);
}

.auth-tab:hover:not(.active) {
    color: var(--text-primary);
}

#auth-login-form input,
#auth-register-form input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    margin-bottom: 12px;
    text-align: left;
    outline: none;
    transition: var(--transition);
}

#auth-login-form input:focus,
#auth-register-form input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.15);
}

.auth-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--accent), #d63d56);
    border: none;
    border-radius: var(--radius);
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.auth-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(233, 69, 96, 0.4);
}

.auth-btn:active {
    transform: translateY(0);
}

.logout-btn {
    margin-top: 8px;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.logout-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 32px;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-content h3 {
    color: var(--accent);
    margin-bottom: 16px;
    font-size: 18px;
    font-weight: 700;
}

.modal-content p {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.5;
}

.modal-content input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    margin-bottom: 16px;
    text-align: center;
    outline: none;
    transition: var(--transition);
}

.modal-content input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.15);
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.modal-buttons button {
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

#use-custom-uid {
    background: var(--accent);
    color: white;
}

#use-random-uid {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.error-text {
    color: var(--danger);
    font-size: 12px;
    margin-top: 12px;
    min-height: 18px;
    font-weight: 500;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.image-upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.image-upload-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(233, 69, 96, 0.1);
}

.image-preview {
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.image-preview img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.image-preview-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition);
}

.image-preview-remove:hover {
    color: var(--danger);
    background: rgba(255, 107, 107, 0.1);
}

.image-preview-size {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: auto;
}

.message-image {
    max-width: 280px;
    border-radius: 8px;
    margin-top: 6px;
    cursor: pointer;
    transition: var(--transition);
}

.message-image:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.message.sent .message-image {
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.message.received .message-image {
    border: 2px solid var(--border);
}

.image-viewer {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.image-viewer.open {
    display: flex;
}

.image-viewer img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 4px;
}

.image-viewer-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.image-viewer-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.image-error-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-tertiary);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    z-index: 3000;
    opacity: 0;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(255, 107, 107, 0.3);
    white-space: nowrap;
}

.image-error-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.context-menu {
    display: none;
    position: fixed;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 160px;
    z-index: 500;
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: contextMenuIn 0.15s ease-out;
}

.context-menu.open {
    display: block;
}

@keyframes contextMenuIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: var(--transition);
}

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

.context-menu-item.danger {
    color: var(--danger);
}

.context-menu-item.danger:hover {
    background: rgba(255, 107, 107, 0.1);
}

.context-menu-divider {
    height: 1px;
    background: var(--border);
}

.message .context-trigger {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 24px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .context-trigger {
    opacity: 1;
}

.group-members-list {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
}

.group-search-wrap {
    position: relative;
    margin-bottom: 12px;
}

.group-search-wrap input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.group-search-wrap input:focus {
    border-color: var(--accent);
}

.group-search-results {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 160px;
    overflow-y: auto;
    z-index: 10;
    box-shadow: var(--shadow);
}

.group-search-result {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: var(--transition);
}

.group-search-result:hover {
    background: rgba(233, 69, 96, 0.1);
}

.group-member-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
}

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

.group-member-item.selected {
    background: rgba(233, 69, 96, 0.15);
}

.group-member-check {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
}

.group-member-item.selected .group-member-check {
    background: var(--accent);
    border-color: var(--accent);
}

.group-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(233, 69, 96, 0.15);
    border-radius: 10px;
    font-size: 10px;
    color: var(--accent);
    font-weight: 600;
}

.message-edited {
    font-size: 10px;
    color: var(--text-muted);
    font-style: italic;
}

.create-group-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.create-group-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(233, 69, 96, 0.1);
}

.add-member-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.add-member-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(233, 69, 96, 0.1);
}

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 8px;
}

.typing-dots {
    display: inline-flex;
    gap: 2px;
    align-items: center;
}

.typing-dots span {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typingDot 1.4s infinite both;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

@media (max-width: 768px) {
    #app {
        flex-direction: row;
    }

    #sidebar {
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 10;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    #sidebar.hidden {
        transform: translateX(-100%);
    }

    #chat-area {
        width: 100%;
        height: 100%;
    }

    #back-btn {
        display: block;
    }

    .message {
        max-width: 85%;
    }

    #input-area {
        padding: 12px 16px;
    }

    #message-input {
        padding: 10px 14px;
        font-size: 16px;
    }

    #send-btn {
        padding: 10px 16px;
    }

    #messages {
        padding: 16px;
    }
}

@media (max-width: 480px) {
    .brand-name {
        font-size: 16px;
    }

    #chat-header {
        padding: 12px 16px;
    }

    .modal-content {
        padding: 24px;
        margin: 16px;
    }
}
