/* ===== БАЗОВЫЕ ПЕРЕМЕННЫЕ ===== */
:root {
    --bg-color: #ffffff;
    --bg-secondary: #f0f0f0;
    --text-color: #000000;
    --text-secondary: #707579;
    --border-color: #e0e0e0;
    --hover-color: #f5f5f5;
    --accent-color: #3390ec;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --chat-item-bg: #ffffff;
    --header-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --bg-secondary: #2b2b2b;
        --text-color: #ffffff;
        --text-secondary: #8a8a8a;
        --border-color: #3a3a3a;
        --hover-color: #2b2b2b;
        --shadow-color: rgba(0, 0, 0, 0.3);
        --chat-item-bg: #1a1a1a;
        --header-bg: #1a1a1a;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
}

#header {
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 16px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
    transition: background-color 0.3s, border-color 0.3s;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-content h1 {
    font-size: 20px;
    font-weight: 600;
}

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

.icon-btn:hover {
    background-color: var(--hover-color);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
    stroke: var(--text-color);
}

#search-container {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

#search-container.hidden {
    display: none;
}

#search-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--bg-secondary);
    color: var(--text-color);
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s, background-color 0.3s;
}

#search-input:focus {
    border-color: var(--accent-color);
}

#search-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#search-close svg {
    width: 18px;
    height: 18px;
    stroke: var(--text-secondary);
}

#main-content {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px;
    background-color: var(--bg-color);
    transition: background-color 0.3s;
}

#main-content::-webkit-scrollbar {
    width: 4px;
}

#main-content::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
}

#chats-list {
    display: flex;
    flex-direction: column;
}

.loading {
    text-align: center;
    padding: 40px 0;
    color: var(--text-secondary);
    font-size: 14px;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 12px; /* было 14px */
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s;
    background-color: var(--chat-item-bg);
    border-radius: 10px; /* было 12px */
    margin: 2px 0; /* было 4px */
}

.chat-item:hover {
    background-color: var(--hover-color);
}

.chat-item:active {
    transform: scale(0.98);
}

.chat-avatar {
    width: 50px; /* было 56px */
    height: 50px; /* было 56px */
    border-radius: 50%;
    background: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px; /* было 22px */
    color: white;
    flex-shrink: 0;
    margin-right: 12px; /* было 14px */
    font-weight: 600;
    overflow: hidden;
}

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

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

.chat-name {
    font-weight: 600;
    font-size: 17px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-preview {
    font-size: 14px; /* было 15px */
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex-shrink: 0;
    margin-left: 8px;
}

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

.chat-badge {
    background-color: var(--accent-color);
    color: white;
    border-radius: 50%;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 500;
    margin-top: 4px;
    min-width: 18px;
    text-align: center;
}

.chat-badge.hidden {
    display: none;
}

.chat-header {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--header-bg);
    min-height: 56px;
    position: relative;
}

.chat-title {
    font-size: 17px;
    font-weight: 600;
    text-align: center;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-avatar-header {
    position: absolute;
    right: 16px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    overflow: hidden;
    cursor: pointer;
    transition: opacity 0.2s;
}

.chat-avatar-header:hover {
    opacity: 0.8;
}

.chat-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg-color);
}

.message {
    max-width: 80%;
    padding: 8px 14px;
    border-radius: 14px;
    word-wrap: break-word;
    position: relative;
}

.message-other {
    background: var(--bg-secondary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message-me {
    background: var(--accent-color);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message-text {
    font-size: 16px;
    line-height: 1.4;
    margin-bottom: 2px;
}

.message-time {
    font-size: 12px;
    opacity: 0.7;
    text-align: right;
    margin-top: 2px;
}

.message-me .message-time {
    color: rgba(255,255,255,0.7);
}

.message-other .message-time {
    color: var(--text-secondary);
}

@media (max-width: 480px) {
    #header {
        padding: 10px 12px;
    }
    .header-content h1 {
        font-size: 18px;
    }
    .chat-item {
        padding: 10px 10px;
        border-radius: 8px;
        margin: 2px 0;
    }
    .chat-avatar {
        width: 44px;
        height: 44px;
        font-size: 16px;
        margin-right: 10px;
    }
    .chat-name {
        font-size: 15px;
    }
    .chat-preview {
        font-size: 13px;
    }
    .chat-header {
        padding: 8px 12px;
        min-height: 50px;
    }
    .chat-title {
        font-size: 16px;
    }
    .chat-avatar-header {
        width: 38px;
        height: 38px;
    }
    .message {
        max-width: 90%;
        padding: 6px 12px;
    }
    .message-text {
        font-size: 15px;
    }
}