/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
/* Auth Modal Styles */
.auth-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #f4f4f2;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.auth-modal.hidden {
    display: none;
}

.auth-container {
    background: #ffffff;
    border-radius: 12px;
    width: 380px;
    max-width: 92%;
    border: 1px solid #e2e2e0;
    animation: authFadeIn 0.25s ease;
    overflow: hidden;
}

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

.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 28px 28px 0;
    margin-bottom: 24px;
}

.auth-brand-icon {
    width: 28px;
    height: 28px;
    background: #1a1a1a;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.auth-brand-icon svg {
    width: 15px;
    height: 15px;
    stroke: #ffffff;
    fill: none;
}

.auth-brand-name {
    font-size: 15px;
    font-weight: 500;
    color: #1a1a1a;
    letter-spacing: -0.2px;
}

.auth-tabs {
    display: flex;
    padding: 0 28px;
    margin-bottom: 24px;
    border-bottom: 1px solid #ebebeb;
    gap: 0;
}

.auth-tab {
    flex: 1;
    padding: 10px 0;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    font-size: 13px;
    font-weight: 400;
    color: #999;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
    letter-spacing: 0.2px;
    margin-bottom: -1px;
}

.auth-tab:hover {
    color: #1a1a1a;
}

.auth-tab.active {
    color: #1a1a1a;
    font-weight: 500;
    border-bottom-color: #1a1a1a;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 0 28px 28px;
    animation: authFadeIn 0.2s ease;
}

.auth-form.hidden {
    display: none;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group label {
    font-size: 11px;
    font-weight: 500;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.form-group input {
    padding: 10px 12px;
    border: 1px solid #e2e2e0;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    background: #fafaf9;
    font-family: inherit;
    color: #1a1a1a;
}

.form-group input::placeholder {
    color: #c0c0bc;
}

.form-group input:focus {
    border-color: #1a1a1a;
    background: #ffffff;
}

.error-message {
    color: #c0392b;
    font-size: 12px;
    min-height: 18px;
    font-weight: 400;
    padding: 6px 10px;
    border-radius: 6px;
    background: #fdf2f2;
    border-left: 2px solid #c0392b;
    border-radius: 0;
}

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

.auth-submit {
    padding: 11px;
    border: none;
    border-radius: 8px;
    background: #1a1a1a;
    color: #ffffff;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 6px;
    letter-spacing: 0.2px;
    font-family: inherit;
}

.auth-submit:hover {
    background: #333333;
}

.auth-submit:active {
    background: #000000;
}

.user-info {
    text-align: center;
    padding: 24px 28px 28px;
    animation: authFadeIn 0.2s ease;
}

.user-info.hidden {
    display: none;
}

.user-info p {
    margin-bottom: 10px;
    font-size: 14px;
    color: #444;
    line-height: 1.6;
}

.user-info strong {
    font-weight: 500;
    color: #1a1a1a;
}

.user-info .unique-code {
    font-size: 12px;
    color: #888;
    background: #f7f7f5;
    padding: 10px 14px;
    border-radius: 6px;
    margin: 12px 0;
    border-left: 2px solid #1a1a1a;
    border-radius: 0;
    text-align: left;
}

.user-info .unique-code strong {
    font-family: 'Courier New', monospace;
    background: #ffffff;
    padding: 3px 8px;
    display: inline-block;
    margin: 4px 0;
    border: 1px solid #e2e2e0;
    color: #1a1a1a;
    letter-spacing: 1px;
    font-size: 12px;
}

.logout-btn {
    padding: 10px 24px;
    border: 1px solid #e2e2e0;
    border-radius: 8px;
    background: #ffffff;
    color: #c0392b;
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    transition: all 0.2s;
    margin-top: 12px;
    letter-spacing: 0.2px;
    font-family: inherit;
}

.logout-btn:hover {
    background: #fdf2f2;
    border-color: #c0392b;
}
.logout-btn:active {
    transform: translateY(0);
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

:root {
    --primary-color: #4a90d9;
    --primary-hover: #3a7bc8;
    --bg-color: #f5f5f5;
    --sidebar-bg: #ffffff;
    --chat-bg: #ffffff;
    --border-color: #e0e0e0;
    --text-primary: #333333;
    --text-secondary: #666666;
    --sent-msg-bg: #4a90d9;
    --sent-msg-text: #ffffff;
    --received-msg-bg: #e8e8e8;
    --received-msg-text: #333333;
    --online-color: #4caf50;
    --offline-color: #9e9e9e;
    --delivered-color: #4a90d9;
    --read-color: #4caf50;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-color);
    height: 100vh;
    overflow: hidden;
}

/* App Container */
.app {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

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

.sidebar-header h2 {
    font-size: 20px;
    color: var(--text-primary);
}

.new-chat-btn {
    width: 36px;
    height: 36px;
    border-radius: 100%;
    max-width: 37px;
    border: none;
    background: var(--primary-color);
    color: white;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.new-chat-btn:hover {
    background: var(--primary-hover);
}

.invite-panel {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.invite-btn,
.join-chat-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: var(--primary-color);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.invite-btn:disabled,
.join-chat-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

.invite-code-preview {
    font-size: 14px;
    color: var(--text-secondary);
    min-height: 18px;
}

.join-chat-row {
    display: grid;
    gap: 8px;
}

.join-chat-row input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    outline: none;
    background: var(--background);
    color: var(--text-primary);
}

.join-chat-row input:focus {
    border-color: var(--primary-color);
}

/* Chat List */
.chat-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    padding: 15px 20px;
    display: flex;
    align-items: center;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
}

.chat-item:hover {
    background: #f0f0f0;
}

.chat-item.active {
    background: #e3f2fd;
}

.chat-item .avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    margin-right: 15px;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-item .avatar img,
.chat-header .avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-item-info {
    flex: 1;
    min-width: 0;
}

.chat-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.chat-item-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-item-time {
    font-size: 12px;
    color: var(--text-secondary);
}

.chat-item-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 5px;
}

.message-status {
    font-size: 12px;
}

.message-status.sent {
    color: var(--delivered-color);
}

.message-status.delivered {
    color: var(--delivered-color);
}

.message-status.read {
    color: var(--read-color);
}

.unread-badge {
    background: var(--primary-color);
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* Settings Button */
.settings {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
}

.settings-btn {
    width: 100%;
    padding: 12px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    font-size: 14px;
    transition: background 0.2s;
}

.settings-btn:hover {
    background: #f0f0f0;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
}

.chat-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.chat-header .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    margin-right: 12px;
}

.chat-header-text h3 {
    font-size: 16px;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.chat-status {
    font-size: 12px;
    color: var(--online-color);
}

.chat-status.offline {
    color: var(--offline-color);
}

.chat-search-row {
    width: 100%;
    margin-top: 10px;
}

.chat-search-box {
    width: 100%;
    padding: 10px 14px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    font-size: 14px;
}

.chat-search-box::placeholder {
    color: rgba(255, 255, 255, 0.62);
}

.message-highlight {
    background: rgba(255, 236, 96, 0.55);
    border-radius: 2px;
    padding: 0 2px;
}

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

.no-chat-selected {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.message-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    animation: fadeIn 0.3s ease;
}

.message-row.sent {
    justify-content: flex-end;
}

.message-row.received {
    justify-content: flex-start;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease;
}

.message-avatar:hover {
    transform: scale(1.1);
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.message-bubble {
    max-width: 120%;
    padding: 14px 16px;
    border-radius: 20px;
    position: relative;
    display: inline-flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 10px 30px rgba(16, 24, 40, 0.08);
}

.message-attachment {
    width: 100%;
    border-radius: 14px;
    max-height: 320px;
    object-fit: cover;
    background: rgba(255,255,255,0.1);
}

.message-file {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(255,255,255,0.12);
    color: inherit;
    text-decoration: none;
    font-weight: 600;
    max-width: 100%;
    word-break: break-all;
}

.message-file:hover {
    opacity: 0.95;
}

.message-bubble::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    background: inherit;
    bottom: 12px;
    transform: rotate(45deg);
}

.message-row.sent .message-bubble::after {
    right: -6px;
}

.message-row.received .message-bubble::after {
    left: -6px;
}

.message-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    color: inherit;
    font-size: 14px;
    line-height: 1.6;
}

.message-time {
    font-size: 12px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-end;
}

.message-status-icon {
    font-size: 12px;
}

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

/* Input Area */
.input-area {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    flex-wrap: wrap;
}

.reply-preview {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: var(--text-primary);
    margin-bottom: 10px;
}

.reply-preview.hidden {
    display: none;
}

.reply-preview span {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.cancel-reply-btn {
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.emoji-btn,
.file-btn,
.voice-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.13), 0 1.5px 4px rgba(0,0,0,0.08);
    font-size: 20px;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: box-shadow 0.18s, transform 0.15s;
    flex-shrink: 0;
    color: #2d3142;
}

.emoji-btn:hover,
.file-btn:hover,
.voice-btn:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0,0,0,0.10);
    transform: translateY(-1px) scale(1.06);
}

.emoji-btn:active,
.file-btn:active,
.voice-btn:active {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.10);
    transform: scale(0.94);
}

.voice-btn.recording {
    background: #fff0f0;
    box-shadow: 0 4px 14px rgba(255, 71, 87, 0.25);
    color: #ff4757;
    animation: recordPulse 1.2s ease-in-out infinite;
}

@keyframes recordPulse {
    0%, 100% { box-shadow: 0 4px 14px rgba(255, 71, 87, 0.25); }
    50%       { box-shadow: 0 4px 22px rgba(255, 71, 87, 0.50); }
}

@keyframes recordPulse {
    0%, 100% { background: rgba(255, 71, 87, 0.12); }
    50%       { background: rgba(255, 71, 87, 0.25); }
}

.record-indicator {
    position: absolute;
    bottom: 14px;
    left: 140px;
    color: #ff4757;
    font-size: 0.9rem;
    font-weight: 600;
}

.record-indicator.hidden {
    display: none;
}

.emoji-picker {
    position: absolute;
    bottom: 70px;
    left: 15px;
    width: 260px;
    padding: 12px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    z-index: 10;
}

.emoji-picker.hidden {
    display: none;
}

.emoji-item {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: #f9f9f9;
    font-size: 20px;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.2s, transform 0.2s;
}

.emoji-item:hover {
    background: #e8f0ff;
    transform: translateY(-1px);
}

.input-area input {
    flex: 1;
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

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

.input-area input:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}

.input-area button {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}

.input-area button:hover:not(:disabled) {
    background: var(--primary-hover);
}

.input-area button:active:not(:disabled) {
    transform: scale(0.95);
}

.input-area button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 400px;
    max-width: 90%;
    box-shadow: var(--shadow);
    animation: slideIn 0.3s ease;
}

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

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

.modal-header h3 {
    font-size: 18px;
    color: var(--text-primary);
}

.close-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.close-btn:hover {
    background: #f0f0f0;
}

.modal-body {
    padding: 20px;
}

.setting-item {
    margin-bottom: 20px;
}

.setting-item:last-child {
    margin-bottom: 0;
}

.setting-item label {
    display: block;
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.setting-item input[type="text"],
.setting-item select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
}

.avatar-upload {
    display: grid;
    gap: 10px;
}

.avatar-color-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

#avatarColorInput {
    width: 44px;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    padding: 2px;
}

.avatar-color-value {
    font-size: 13px;
    color: var(--text-secondary);
    font-family: 'Courier New', monospace;
}

.avatar-color-preview {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    color: #fff;
    font-size: 24px;
    font-weight: 700;
    display: grid;
    place-items: center;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16);
}

.modal-actions {
    padding: 0 20px 20px;
    display: flex;
    justify-content: flex-end;
}

.settings-save-btn {
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    transition: background 0.2s;
}

.settings-save-btn:hover {
    background: #4c8df3;
}

#avatarSelectButton {
    width: fit-content;
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

#avatarSelectButton:hover {
    background: #f0f0f0;
    transform: translateY(-1px);
}

.avatar-file-name {
    color: var(--text-secondary);
    font-size: 14px;
}

.setting-item input[type="text"]:focus,
.setting-item select:focus {
    border-color: var(--primary-color);
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: 0.3s;
    border-radius: 26px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle input:checked + .slider {
    background-color: var(--primary-color);
}

.toggle input:checked + .slider:before {
    transform: translateX(24px);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* Logout sidebar button */
.logout-sidebar-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 14px;
    width: 100%;
    transition: background 0.2s;
    margin-bottom: 4px;
}

.logout-sidebar-btn:hover {
    background: rgba(231, 76, 60, 0.1);
}

/* Delete chat button */
.delete-chat-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 4px 6px;
    border-radius: 6px;
    opacity: 0.6;
    transition: opacity 0.2s, background 0.2s;
    flex-shrink: 0;
    margin-left: auto;
    align-self: center;
}

.chat-item:hover .delete-chat-btn {
    display: flex;
    align-items: center;
}

.delete-chat-btn:hover {
    opacity: 1;
    background: rgba(231, 76, 60, 0.15);
}

/* Search box */
.search-box {
    width: 100%;
    padding: 8px 12px;
    margin-top: 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

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

/* Message reactions */
.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
    padding: 4px;
}

.reaction-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 14px;
    padding: 2px 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

.reaction-item:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(1.1);
}

/* Message status icons */
.message-status-icon {
    font-size: 12px;
    margin-left: 4px;
    opacity: 0.8;
}

/* Edited message indicator */
.message-edited {
    font-size: 12px;
    opacity: 0.7;
    display: block;
    margin-top: 2px;
}

/* Message context menu */
.message-context-menu {
    animation: slideUp 0.2s ease-out;
}

/* Message content wrapper for reactions */
.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Settings button secondary */
.settings-btn-secondary {
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: white;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s;
    font-size: 14px;
    margin-right: 8px;
}

.settings-btn-secondary:hover {
    background: #f5f5f5;
}

/* Sidebar header adjustments */
.sidebar-header {
    padding: 12px 8px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 18px;
    color: var(--text-primary);
    width: 100%;
}

.sidebar-header .new-chat-btn {
    width: 100%;
}

/* Modal adjustments */
.modal-actions {
    gap: 8px;
    flex-wrap: wrap;
}

/* Unread badge */
.unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    background: var(--primary-color);
    color: white;
    border-radius: 10px;
    font-size: 12px;
    font-weight: bold;
    padding: 0 6px;
    margin-left: auto;
}

/* Copyright Watermark */
.copyright-watermark {
    position: fixed;
    bottom: 0;
    right: 0;
    padding: 8px 12px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.25);
    background: rgba(0, 0, 0, 0.15);
    font-family: monospace;
    letter-spacing: 0.5px;
    user-select: none;
    pointer-events: none;
    z-index: 1;
    border-top-left-radius: 4px;
    font-weight: 500;
    transition: color 0.3s ease;
}

.copyright-watermark:hover {
    color: rgba(255, 255, 255, 0.35);
}

.chat-search-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
}
.chat-search-clear {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: #999;
    padding: 4px 6px;
}

/* Reply quote inside message bubble */
.message-reply-quote {
    border-left: 3px solid rgba(255, 255, 255, 0.6);
    padding: 6px 10px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.12);
    margin-bottom: 6px;
}

.reply-to-name {
    font-size: 12px;
    font-weight: 700;
    opacity: 0.9;
    margin-bottom: 2px;
}

.reply-to-text {
    font-size: 12px;
    opacity: 0.75;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}


/* Search navigation */
.search-counter {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 2px 6px;
    white-space: nowrap;
}

.search-nav-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    padding: 3px 6px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.search-nav-btn:hover {
    background: rgba(0,0,0,0.08);
    color: var(--primary-color);
}

/* Active search highlight (текущее найденное) */
.message-highlight-active {
    background: rgba(255, 180, 0, 0.85) !important;
    border-radius: 2px;
    padding: 0 2px;
    outline: 2px solid rgba(255, 140, 0, 0.7);
}


/* ========== АДАПТИВНОСТЬ ДЛЯ ТЕЛЕФОНОВ ========== */

@media (max-width: 768px) {

    /* Скрываем сайдбар когда открыт чат */
    .app {
        position: relative;
        overflow: hidden;
    }

    .sidebar {
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 100;
        transition: transform 0.3s ease;
    }

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

    .chat-area {
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 50;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .chat-area.active-mobile {
        transform: translateX(0);
    }

    /* Кнопка "назад" в шапке чата */
    .back-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border: none;
        background: none;
        color: var(--text-primary);
        font-size: 22px;
        cursor: pointer;
        margin-right: 8px;
        flex-shrink: 0;
    }

    .chat-header {
        flex-direction: column;
        align-items: flex-start;
        padding: 10px 12px;
        gap: 8px;
    }

    .chat-header-info {
        width: 100%;
    }

    .chat-search-row {
        width: 100%;
        display: flex;
        align-items: center;
        gap: 4px;
        margin-top: 0;
    }

    .chat-search-box {
        flex: 1;
        min-width: 0;
        font-size: 13px;
        padding: 8px 10px;
    }

    /* Сообщения */
    .messages {
        padding: 12px;
    }

    .message-bubble {
        max-width: 85vw;
    }

    /* Поле ввода */
    .input-area {
        padding: 8px 10px;
        gap: 6px;
    }

    .emoji-btn,
    .file-btn,
    .voice-btn {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    .input-area input {
        font-size: 15px;
        padding: 10px 12px;
    }

    /* Сайдбар — шапка */
    .sidebar-header {
        padding: 12px;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
    }

    .sidebar-header h2 {
        font-size: 18px;
    }

    .search-box {
        width: 100%;
    }

    .new-chat-btn {
        width: 38px;
        height: 38px;
    }

    /* Элементы чата в списке */
    .chat-item {
        padding: 12px 14px;
    }

    /* Настройки внизу сайдбара */
    .settings {
        padding: 10px 12px;
    }

    /* Модалки */
    .modal-content {
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
    }

    /* Аватар сообщения — меньше */
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 13px;
    }

    /* Убираем водяной знак на мобиле */
    .copyright-watermark {
        display: none;
    }

    /* invite panel */
    .invite-panel {
        padding: 10px 12px;
    }
}

/* ===== ТЕМА: НОЧЬ ===== */
body.theme-night {
    background: #1a1a2e;
    color: #e0e0ff;
}
body.theme-night .sidebar { background: #16213e; border-color: #0f3460; }
body.theme-night .chat-header { background: #16213e; border-color: #0f3460; color: #e0e0ff; }
body.theme-night .messages { background: #1a1a2e; }
body.theme-night .input-area { background: #16213e; border-color: #0f3460; }
body.theme-night .input-area input { background: #0f3460; color: #e0e0ff; border-color: #2a2a5e; }
body.theme-night .input-area input::placeholder { color: #6666aa; }
body.theme-night .chat-item { color: #e0e0ff; }
body.theme-night .chat-item:hover { background: #0f3460; }
body.theme-night .chat-item.active { background: #0f3460; border-left: 3px solid #7c83fd; }
body.theme-night .chat-item .chat-name { color: #ffffff !important; forced-color-adjust: none; }
body.theme-night .chat-item .chat-preview { color: #8888cc; }
body.theme-night .chat-item .chat-time { color: #6666aa; }
body.theme-night .message-bubble { background: #16213e; color: #c8c8e8; }
body.theme-night .message-bubble.sent { background: #7c83fd; color: #ffffff; }
body.theme-night #currentChatName { color: #ffffff !important; forced-color-adjust: none; }
body.theme-night .chat-status { color: #7c83fd; }
body.theme-night .sidebar-header h2 { color: #e0e0ff; }
body.theme-night .settings-btn { color: #8888cc; }
body.theme-night .settings-btn:hover { background: #0f3460; color: #e0e0ff; }
body.theme-night .new-chat-btn { background: #7c83fd; color: #ffffff; }
body.theme-night #sendBtn { background: #7c83fd; color: #ffffff; }
body.theme-night .modal-content { background: #16213e; color: #e0e0ff; border-color: #0f3460; }
body.theme-night .modal-header { border-color: #0f3460; }
body.theme-night .modal-header h3 { color: #e0e0ff; }
body.theme-night .setting-item label { color: #8888cc; }
body.theme-night .setting-item input,
body.theme-night .setting-item select { background: #0f3460; color: #e0e0ff; border-color: #2a2a5e; }
body.theme-night .settings-btn-secondary { background: #0f3460; color: #e0e0ff; border-color: #2a2a5e; }
body.theme-night .settings-btn-secondary:hover { background: #1a1a5e; color: #ffffff; }
body.theme-night .settings-save-btn { background: #7c83fd; color: #ffffff; }
body.theme-night .logout-sidebar-btn { color: #8888cc; }
body.theme-night .logout-sidebar-btn:hover { background: #0f3460; color: #e0e0ff; }
body.theme-night .search-box { background: #0f3460; color: #e0e0ff; border-color: #2a2a5e; }
body.theme-night .invite-panel { border-color: #0f3460; }
body.theme-night .invite-btn { background: #0f3460; color: #e0e0ff; border-color: #2a2a5e; }
body.theme-night .join-chat-btn { background: #7c83fd; color: #ffffff; }
body.theme-night #joinCodeInput { background: #0f3460; color: #e0e0ff; border-color: #2a2a5e; }
body.theme-night .message-time { color: #6666aa; }
body.theme-night .message-sender { color: #8888cc; }
body.theme-night .no-chat-selected { color: #6666aa; }
body.theme-night .close-btn { color: #8888cc; }
body.theme-night .close-btn:hover { background: #0f3460; color: #e0e0ff; }

/* ===== ТЕМА: ТЁПЛЫЙ ===== */
body.theme-warm {
    background: #fdf6ec;
    color: #3d2b1f;
}
body.theme-warm .sidebar { background: #fff8f0; border-color: #ede0cc; }
body.theme-warm .chat-header { background: #fff8f0; border-color: #ede0cc; color: #3d2b1f; }
body.theme-warm .messages { background: #fdf6ec; }
body.theme-warm .input-area { background: #fff8f0; border-color: #ede0cc; }
body.theme-warm .input-area input { background: #fdf6ec; color: #3d2b1f; border-color: #ede0cc; }
body.theme-warm .input-area input::placeholder { color: #b8a090; }
body.theme-warm .chat-item { color: #3d2b1f; }
body.theme-warm .chat-item:hover { background: #f5e8d8; }
body.theme-warm .chat-item.active { background: #f5e8d8; border-left: 3px solid #c0784a; }
body.theme-warm .chat-item .chat-name { color: #3d2b1f; }
body.theme-warm .chat-item .chat-preview { color: #8b6a52; }
body.theme-warm .chat-item .chat-time { color: #b8a090; }
body.theme-warm .message-bubble { background: #ede0cc; color: #3d2b1f; }
body.theme-warm .message-bubble.sent { background: #c0784a; color: #ffffff; }
body.theme-warm #currentChatName { color: #3d2b1f; }
body.theme-warm .chat-status { color: #7a9e4e; }
body.theme-warm .sidebar-header h2 { color: #3d2b1f; }
body.theme-warm .settings-btn { color: #8b6a52; }
body.theme-warm .settings-btn:hover { background: #f5e8d8; color: #3d2b1f; }
body.theme-warm .new-chat-btn { background: #c0784a; color: #ffffff; }
body.theme-warm #sendBtn { background: #c0784a; color: #ffffff; }
body.theme-warm .modal-content { background: #fff8f0; color: #3d2b1f; border-color: #ede0cc; }
body.theme-warm .modal-header { border-color: #ede0cc; }
body.theme-warm .modal-header h3 { color: #3d2b1f; }
body.theme-warm .setting-item label { color: #8b6a52; }
body.theme-warm .setting-item input,
body.theme-warm .setting-item select { background: #fdf6ec; color: #3d2b1f; border-color: #ede0cc; }
body.theme-warm .settings-btn-secondary { background: #f5e8d8; color: #3d2b1f; border-color: #ede0cc; }
body.theme-warm .settings-btn-secondary:hover { background: #ede0cc; color: #1f1008; }
body.theme-warm .settings-save-btn { background: #c0784a; color: #ffffff; }
body.theme-warm .logout-sidebar-btn { color: #8b6a52; }
body.theme-warm .logout-sidebar-btn:hover { background: #f5e8d8; color: #3d2b1f; }
body.theme-warm .search-box { background: #fdf6ec; color: #3d2b1f; border-color: #ede0cc; }
body.theme-warm .invite-panel { border-color: #ede0cc; }
body.theme-warm .invite-btn { background: #f5e8d8; color: #3d2b1f; border-color: #ede0cc; }
body.theme-warm .join-chat-btn { background: #c0784a; color: #ffffff; }
body.theme-warm #joinCodeInput { background: #fdf6ec; color: #3d2b1f; border-color: #ede0cc; }
body.theme-warm .message-time { color: #b8a090; }
body.theme-warm .message-sender { color: #8b6a52; }
body.theme-warm .no-chat-selected { color: #b8a090; }
body.theme-warm .close-btn { color: #8b6a52; }
body.theme-warm .close-btn:hover { background: #f5e8d8; color: #3d2b1f; }

/* ===== ТЕМА: ЛЕСНОЙ ===== */
body.theme-forest {
    background: #f0f4f0;
    color: #1b4332;
}
body.theme-forest .sidebar { background: #f8fff8; border-color: #c8dcc8; }
body.theme-forest .chat-header { background: #f8fff8; border-color: #c8dcc8; color: #1b4332; }
body.theme-forest .messages { background: #f0f4f0; }
body.theme-forest .input-area { background: #f8fff8; border-color: #c8dcc8; }
body.theme-forest .input-area input { background: #f0f4f0; color: #1b4332; border-color: #c8dcc8; }
body.theme-forest .input-area input::placeholder { color: #95b8a8; }
body.theme-forest .chat-item { color: #1b4332; }
body.theme-forest .chat-item:hover { background: #d8e8d8; }
body.theme-forest .chat-item.active { background: #d8e8d8; border-left: 3px solid #2d6a4f; }
body.theme-forest .chat-item .chat-name { color: #1b4332; }
body.theme-forest .chat-item .chat-preview { color: #52796f; }
body.theme-forest .chat-item .chat-time { color: #95b8a8; }
body.theme-forest .message-bubble { background: #d8e8d8; color: #1b4332; }
body.theme-forest .message-bubble.sent { background: #2d6a4f; color: #ffffff; }
body.theme-forest #currentChatName { color: #1b4332; }
body.theme-forest .chat-status { color: #40916c; }
body.theme-forest .sidebar-header h2 { color: #1b4332; }
body.theme-forest .settings-btn { color: #52796f; }
body.theme-forest .settings-btn:hover { background: #d8e8d8; color: #1b4332; }
body.theme-forest .new-chat-btn { background: #2d6a4f; color: #ffffff; }
body.theme-forest #sendBtn { background: #2d6a4f; color: #ffffff; }
body.theme-forest .modal-content { background: #f8fff8; color: #1b4332; border-color: #c8dcc8; }
body.theme-forest .modal-header { border-color: #c8dcc8; }
body.theme-forest .modal-header h3 { color: #1b4332; }
body.theme-forest .setting-item label { color: #52796f; }
body.theme-forest .setting-item input,
body.theme-forest .setting-item select { background: #f0f4f0; color: #1b4332; border-color: #c8dcc8; }
body.theme-forest .settings-btn-secondary { background: #d8e8d8; color: #1b4332; border-color: #c8dcc8; }
body.theme-forest .settings-btn-secondary:hover { background: #c8dcc8; color: #0d2b1e; }
body.theme-forest .settings-save-btn { background: #2d6a4f; color: #ffffff; }
body.theme-forest .logout-sidebar-btn { color: #52796f; }
body.theme-forest .logout-sidebar-btn:hover { background: #d8e8d8; color: #1b4332; }
body.theme-forest .search-box { background: #f0f4f0; color: #1b4332; border-color: #c8dcc8; }
body.theme-forest .invite-panel { border-color: #c8dcc8; }
body.theme-forest .invite-btn { background: #d8e8d8; color: #1b4332; border-color: #c8dcc8; }
body.theme-forest .join-chat-btn { background: #2d6a4f; color: #ffffff; }
body.theme-forest #joinCodeInput { background: #f0f4f0; color: #1b4332; border-color: #c8dcc8; }
body.theme-forest .message-time { color: #95b8a8; }
body.theme-forest .message-sender { color: #52796f; }
body.theme-forest .no-chat-selected { color: #95b8a8; }
body.theme-forest .close-btn { color: #52796f; }
body.theme-forest .close-btn:hover { background: #d8e8d8; color: #1b4332; }

/* ===== ТЕМА: МОНОХРОМ ===== */
body.theme-mono {
    background: #111111;
    color: #e0e0e0;
}
body.theme-mono .sidebar { background: #1c1c1c; border-color: #2a2a2a; }
body.theme-mono .chat-header { background: #1c1c1c; border-color: #2a2a2a; color: #e0e0e0; }
body.theme-mono .messages { background: #111111; }
body.theme-mono .input-area { background: #1c1c1c; border-color: #2a2a2a; }
body.theme-mono .input-area input { background: #222222; color: #e0e0e0; border-color: #333333; }
body.theme-mono .input-area input::placeholder { color: #555555; }
body.theme-mono .chat-item { color: #e0e0e0; }
body.theme-mono .chat-item:hover { background: #222222; }
body.theme-mono .chat-item.active { background: #252525; border-left: 3px solid #e0e0e0; }
body.theme-mono .chat-item .chat-name { color: #ffffff !important; forced-color-adjust: none; }
body.theme-mono .chat-item .chat-preview { color: #888888; }
body.theme-mono .chat-item .chat-time { color: #555555; }
body.theme-mono .message-bubble { background: #2a2a2a; color: #c8c8c8; }
body.theme-mono .message-bubble.sent { background: #e0e0e0; color: #111111; }
body.theme-mono #currentChatName { color: #ffffff !important; forced-color-adjust: none; }
body.theme-mono .chat-status { color: #888888; }
body.theme-mono .sidebar-header h2 { color: #e0e0e0; }
body.theme-mono .settings-btn { color: #888888; }
body.theme-mono .settings-btn:hover { background: #222222; color: #e0e0e0; }
body.theme-mono .new-chat-btn { background: #e0e0e0; color: #111111; }
body.theme-mono #sendBtn { background: #e0e0e0; color: #111111; }
body.theme-mono #sendBtn svg { stroke: #111111; }
body.theme-mono .modal-content { background: #1c1c1c; color: #e0e0e0; border-color: #2a2a2a; }
body.theme-mono .modal-header { border-color: #2a2a2a; }
body.theme-mono .modal-header h3 { color: #e0e0e0; }
body.theme-mono .setting-item label { color: #888888; }
body.theme-mono .setting-item input,
body.theme-mono .setting-item select { background: #222222; color: #e0e0e0; border-color: #333333; }
body.theme-mono .settings-btn-secondary { background: #222222; color: #e0e0e0; border-color: #333333; }
body.theme-mono .settings-btn-secondary:hover { background: #333333; color: #ffffff; }
body.theme-mono .settings-save-btn { background: #e0e0e0; color: #111111; }
body.theme-mono .logout-sidebar-btn { color: #888888; }
body.theme-mono .logout-sidebar-btn:hover { background: #222222; color: #e0e0e0; }
body.theme-mono .search-box { background: #222222; color: #e0e0e0; border-color: #333333; }
body.theme-mono .invite-panel { border-color: #2a2a2a; }
body.theme-mono .invite-btn { background: #222222; color: #e0e0e0; border-color: #333333; }
body.theme-mono .join-chat-btn { background: #e0e0e0; color: #111111; }
body.theme-mono #joinCodeInput { background: #222222; color: #e0e0e0; border-color: #333333; }
body.theme-mono .message-time { color: #555555; }
body.theme-mono .message-sender { color: #888888; }
body.theme-mono .no-chat-selected { color: #555555; }
body.theme-mono .close-btn { color: #888888; }
body.theme-mono .close-btn:hover { background: #222222; color: #e0e0e0; }
body.theme-mono .emoji-btn,
body.theme-mono .file-btn,
body.theme-mono .voice-btn { color: #888888; }


/*  Универсальный принудительный белый цвет для названий чатов */
.theme-night .chat-name,
.theme-mono .chat-name,
[data-theme="night"] .chat-name,
[data-theme="monochrome"] .chat-name {
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important; /* Для Safari / iOS / WebKit-артефактов */
}

/*  Принудительный override системной тёмной темы ОС/браузера */
@media (prefers-color-scheme: dark) {
    .theme-night .chat-name,
    .theme-mono .chat-name {
        color: #ffffff !important;
    }
}

/*  Страховка: если чат-элемент оборачивается в другой контейнер */
.sidebar .chat-name,
.chat-list .chat-name {
    color: inherit; /* Сброс возможных глобальных переопределений */
}
