* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* CSS переменные для светлой темы (по умолчанию) */
:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f8f8;
    --bg-tertiary: #e8e8e8;
    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --text-tertiary: #888888;
    --border-color: #d0d0d0;
    --border-dark: #888888;
    --primary-color: #0088cc;
    --header-bg: #f5f5f5;
    --message-received-bg: #e8e8e8;
    --message-sent-bg: #0088cc;
    --icon-color: #555555;
    --input-bg: #ffffff;
    --input-border: #b0b0b0;
    --search-bg: #f0f0f0;
    --status-online-color: #34a853;
}

/* Переменные для тёмной темы */
body.dark-theme {
    --bg-primary: #0f1419;
    --bg-secondary: #212f3c;
    --bg-tertiary: #1a232f;
    --text-primary: #ffffff;
    --text-secondary: #8a8a8a;
    --text-tertiary: #8e8e93;
    --border-color: #2a3f54;
    --border-dark: #38383a;
    --primary-color: #0088cc;
    --header-bg: #212f3c;
    --message-received-bg: #1d2733;
    --message-sent-bg: #0088cc;
    --icon-color: #8e8e93;
    --input-bg: #1a232f;
    --input-border: #2a3f54;
    --search-bg: #1a232f;
    --status-online-color: #4cd964;
}

body {
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* Анимация эмодзи на странице авторизации */
@keyframes emoji-bounce {
    0%, 100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    50% {
        transform: translateY(-20px) scale(1.1);
        opacity: 0.9;
    }
}

@keyframes emoji-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.screen {
    display: none;
    height: 100vh;
}

.screen.active {
    display: block;
}

/* Auth Styles */
.auth-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 20px;
    background: var(--bg-primary);
}

.auth-header {
    text-align: center;
    margin-bottom: 50px;
}

.auth-logo {
    width: 150px;
    height: 150px;
    margin: 0 auto 10px;
    padding: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: transform;
}

.auth-header h1 {
    font-size: 3em;
    margin-bottom: 5px;
    color: var(--text-primary);
    font-weight: 700;
    letter-spacing: -1px;
    font-family: 'Unbounded', sans-serif;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 1.1em;
    font-weight: 300;
}

.auth-form {
    width: 100%;
    max-width: 400px;
}

.form-group {
    margin-bottom: 20px;
}

.form-group input {
    width: 100%;
    padding: 15px;
    border: 2px solid var(--input-border);
    border-radius: 10px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--primary-color);
}

.btn-primary {
    width: 100%;
    padding: 15px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    cursor: pointer;
    margin-bottom: 15px;
}

.btn-secondary {
    width: 100%;
    padding: 15px;
    background: transparent;
    color: var(--text-primary);
    border: 2px solid var(--text-primary);
    border-radius: 10px;
    font-size: 16px;
    cursor: pointer;
}

/* Main App Styles */
.phone-mockup {
    width: 100vw;
    height: 100vh;
    background: var(--bg-primary);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    height: 60px;
    display: none;
}

.header.active {
    display: flex;
}

.header h2 {
    font-size: 18px;
    font-weight: 600;
}

.icon {
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
}

.content-wrapper {
    flex-grow: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.content-container {
    display: none;
    flex-direction: column;
    flex-grow: 1;
    min-height: 0;
    position: relative;
}

.content-container.active {
    display: flex;
}

/* Stories */
.stories-container {
    padding: 15px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 15px;
    overflow-x: auto;
}

.story-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex-shrink: 0;
}

.story-ring {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid transparent;
    background: linear-gradient(var(--header-bg), var(--header-bg)) padding-box,
                linear-gradient(135deg, #0088cc, #5ac8fa) border-box;
}

.story-photo {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), #00a8e8);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    font-weight: 600;
}

.story-plus {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--header-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid #38383a;
}

.story-name {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Chat List Tabs */
.chat-list-tabs {
    display: flex;
    gap: 20px;
    padding: 15px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
}

.chat-list-tab {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    padding-bottom: 4px;
    border-bottom: 2px solid transparent;
}

.chat-list-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* Search */
.search-input-container {
    padding: 15px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
}

.search-box {
    display: flex;
    align-items: center;
    background: var(--bg-tertiary);
    border-radius: 10px;
    padding: 0 12px;
    border: 1px solid var(--border-color);
    gap: 12px;
}

.search-input {
    width: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    padding: 12px 0;
    font-size: 16px;
}

.search-input::placeholder {
    color: var(--text-secondary);
}

/* Chat List */
.chat-list {
    flex-grow: 1;
    overflow-y: auto;
    list-style: none;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.chat-item-photo {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), #00a8e8);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white !important;
    font-weight: 600;
    margin-right: 15px;
}

.chat-item-info {
    flex-grow: 1;
}

.chat-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.chat-item-title {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-grow: 1;
}

.name {
    font-weight: 500;
}

.time {
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
    margin-left: 12px;
}

.chat-item-message p {
    color: var(--text-secondary);
    font-size: 14px;
}

.unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background-color: #e8e8e8;
    color: #666666;
    border-radius: 11px;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

/* Тёмная тема для badge */
body.dark-theme .unread-badge {
    background-color: #ffffff;
    color: #000000;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    padding: 15px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    height: 60px;
}

.chat-header-info {
    flex-grow: 1;
    text-align: center;
}

.chat-header-info h3 {
    font-size: 16px;
    font-weight: 600;
}

.chat-header-info span {
    color: var(--text-secondary);
    font-size: 13px;
}

/* Chat Content */
.chat-content {
    flex-grow: 1;
    min-height: 0;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-primary);
}

.chat-message-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    margin-bottom: 8px;
}

.chat-message-container.sent {
    align-items: flex-end;
}

.sent-message-wrapper {
    display: flex;
    justify-content: flex-end;
    min-width: 80px;
}

.chat-message-container.received {
    align-items: flex-start;
}

.chat-message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    max-width: 100%;
    min-width: 60px;
    font-size: 16px;
    line-height: 1.4;
    word-wrap: break-word;
    word-break: break-all;
    position: relative;
    padding-bottom: 20px;
}

.chat-message-container.received .chat-message-bubble {
    background: var(--message-received-bg);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
}

.chat-message-container.sent .chat-message-bubble {
    background: var(--primary-color);
    border-bottom-right-radius: 4px;
    color: white;
}

.chat-message-time {
    font-size: 11px;
    color: inherit;
    white-space: nowrap;
    position: absolute;
    bottom: 4px;
    right: 8px;
}

.chat-message-container.received .chat-message-time {
    color: var(--text-secondary);
}

.chat-message-container.sent .chat-message-time {
    color: rgba(255, 255, 255, 0.7);
}

.chat-input-container {
    padding: 15px;
    background: var(--header-bg);
    border-top: 1px solid #2a3f54;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    flex-grow: 0;
}

.file-input-label {
    cursor: pointer;
    color: var(--primary-color);
    font-size: 20px;
    flex-shrink: 0;
}

.chat-input-field {
    flex-grow: 1;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 12px 16px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
}

.chat-input-field:focus {
    border-color: var(--primary-color);
}

.chat-input-field::placeholder {
    color: var(--text-secondary);
}

/* Profile */
.profile-header {
    display: flex;
    align-items: center;
    padding: 15px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    gap: 15px;
}

.profile-pic {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #78909c, #607d8b);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white !important;
    font-weight: 600;
    font-size: 20px;
}

.profile-info h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 5px;
}

.profile-info p {
    color: var(--text-secondary);
    font-size: 14px;
}

.settings-section {
    list-style: none;
    background: var(--bg-tertiary);
    margin: 10px 0;
    border-radius: 0;
}

.settings-list-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

.settings-list-item:last-child {
    border-bottom: none;
}

.settings-list-item .icon {
    width: 24px;
    text-align: center;
    font-size: 18px;
    margin-right: 15px;
}

/* Кнопки действия (Выйти, Редактировать, Написать сообщение) */
#logout-btn,
#edit-profile-btn,
#message-btn {
    justify-content: flex-start !important;
    gap: 3px;
}

.profile-list-item-left h4 {
    font-weight: 500;
    margin-bottom: 2px;
}

.profile-list-item-left p {
    color: var(--text-secondary);
    font-size: 13px;
}

/* Sidebar */
.sidebar {
    background: var(--header-bg);
    width: 320px;
    max-width: 85%;
    position: absolute;
    top: 0;
    left: -320px;
    bottom: 0;
    transition: left 0.3s;
    z-index: 200;
    overflow-y: auto;
}

.sidebar.open {
    left: 0;
}

.sidebar-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 199;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
}

.sidebar-profile-pic {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #78909c, #607d8b);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white !important;
    font-weight: 600;
    margin-right: 15px;
}

.sidebar-list {
    list-style: none;
}

.sidebar-list-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    gap: 20px;
    font-size: 16px;
    color: var(--text-primary);
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-list-item .icon {
    width: 24px;
    text-align: center;
    font-size: 18px;
}

/* Loading */
.loading {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
}

/* Online status */
.status-online {
    color: var(--status-online-color) !important;
}

.status-offline {
    color: var(--text-secondary) !important;
}

/* Добавляем в конец файла */

/* Стили для сообщений с аватарами */
.message-sender-info {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), #00a8e8);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white !important;
    font-weight: 600;
    font-size: 12px;
    flex-shrink: 0;
}

.chat-message-container.received .message-avatar {
    display: none;
}

.message-content {
    flex: 1;
    max-width: 100%;
}

.sender-name {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
}

/* Убираем треугольники у сообщений для более современного вида */
.chat-message-container.received .chat-message-bubble,
.chat-message-container.sent .chat-message-bubble {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 18px;
}

/* Адаптивность для маленьких экранов */
@media (max-width: 480px) {
    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 10px;
    }

    .sender-name {
        font-size: 11px;
    }
}

.send-button {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.send-button:disabled {
    color: var(--text-secondary);
    cursor: not-allowed;
}

.send-button:not(:disabled):hover {
    background: rgba(0, 136, 204, 0.1);
}

/* Индикатор отправки */
.sending {
    opacity: 0.7;
}

.loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: var(--text-secondary);
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #0088cc;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Скрытый телефон - замазанный блок */
.hidden-phone {
    background: linear-gradient(90deg, #cccccc 0%, #999999 50%, #cccccc 100%);
    background-size: 200% 100%;
    color: transparent;
    border-radius: 4px;
    padding: 4px 8px;
    display: inline-block;
    min-width: 120px;
    font-size: 14px;
    letter-spacing: 2px;
    user-select: none;
}

.error-message {
    background: #ff3b30 !important;
}

/* Стиль для временных сообщений */
.chat-message-container .temp-message {
    opacity: 0.7;
}

/* Contacts Screen */
#screen-contacts .profile-header {
    border-bottom: 1px solid var(--border-color);
}

.contact-item {
    display: flex !important;
    align-items: center;
    padding: 12px 20px;
    justify-content: space-between;
}

.contact-avatar {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    margin-right: 12px;
}

.contact-info {
    flex-grow: 1;
}

.contact-info h4 {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 4px;
}

.contact-info p {
    font-size: 12px;
    margin: 0;
}

.btn-start-chat {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 16px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    transition: background-color 0.2s;
}

.btn-start-chat:hover {
    background: rgba(0, 136, 204, 0.1);
}

/* Settings Screen */
#screen-settings .settings-section {
    margin-top: 20px;
}

.settings-group-title {
    padding: 15px 20px 10px 20px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.settings-list-item {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
}

.settings-left {
    flex: 1;
}

.settings-left h4 {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 4px;
}

.settings-left p {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    transition: 0.3s;
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    top: 4px;
    background-color: var(--input-bg);
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #34c759;
    border-color: #34c759;
}

input:checked + .slider:before {
    transform: translateX(22px);
}

/* Badge */
.badge {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

/* Animations */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes slideDown {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}