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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #dcdde1;
    margin: 0;
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* === ЭКРАН АВТОРИЗАЦИИ === */
.screen {
    background: white;
    width: 90%;
    max-width: 400px;
    padding: 30px 25px;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.screen.active {
    display: block;
}

h2 {
    text-align: center;
    color: #333;
    margin: 0 0 25px 0;
    font-size: 28px;
    font-weight: 700;
}

input {
    width: 100%;
    padding: 14px 16px;
    margin: 10px 0;
    border: 2px solid #e1e1e1;
    border-radius: 12px;
    font-size: 16px;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

input:focus {
    outline: none;
    border-color: #0084ff;
}

button {
    width: 100%;
    padding: 14px;
    background: #0084ff;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    margin-top: 12px;
    transition: background 0.2s, transform 0.1s;
}

button:hover {
    background: #0073e6;
}

button:active {
    transform: scale(0.98);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.toggle-link {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: #0084ff;
    cursor: pointer;
    font-weight: 500;
}

.error {
    color: #ff3b30;
    font-size: 14px;
    text-align: center;
    margin-top: 12px;
    padding: 8px;
    background: #fff5f5;
    border-radius: 8px;
}

.remember-me {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 15px 0;
    font-size: 15px;
    color: #555;
}

.remember-me input {
    width: 20px;
    height: 20px;
    margin: 0;
    cursor: pointer;
}

/* === ОСНОВНОЕ ПРИЛОЖЕНИЕ === */
#chat-app {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: none;
    background: white;
    overflow: hidden;
}

.chat-layout {
    display: flex;
    height: 100%;
}

/* === БОКОВАЯ ПАНЕЛЬ === */
.sidebar {
    width: 320px;
    background: #f0f2f5;
    border-right: 1px solid #e1e1e1;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 100;
}

.my-profile {
    padding: 16px 20px;
    background: white;
    border-bottom: 1px solid #e1e1e1;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
}

.logout-btn {
    background: none;
    color: #ff3b30;
    width: auto;
    padding: 6px 12px;
    margin: 0;
    font-size: 13px;
    font-weight: 600;
}

.users-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.user-item {
    padding: 16px 20px;
    border-bottom: 1px solid #e1e1e1;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.2s;
    background: white;
}

.user-item:hover {
    background: #f5f5f5;
}

.user-item.active {
    background: #e6f2ff;
}

.user-item:active {
    background: #e8e8e8;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ccc;
    flex-shrink: 0;
}

.status-dot.online {
    background: #31a24c;
    box-shadow: 0 0 0 2px rgba(49, 162, 76, 0.2);
}

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

.user-item-name {
    font-weight: 600;
    font-size: 15px;
    color: #111;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-item-status {
    font-size: 13px;
    color: #888;
    margin-top: 2px;
}

/* === ОКНО ЧАТА === */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: white;
    min-width: 0;
}

.chat-header {
    padding: 14px 20px;
    border-bottom: 1px solid #e1e1e1;
    font-weight: 600;
    background: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    z-index: 10;
}

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

.chat-header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

#chat-with {
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#typing-indicator {
    font-size: 13px;
    color: #888;
    font-weight: normal;
    font-style: italic;
    display: none;
}

.call-buttons {
    display: flex;
    gap: 8px;
}

.call-btn {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 18px;
    width: auto;
    margin: 0;
    transition: transform 0.1s;
}

.call-btn.audio {
    background: #2196F3;
}

.call-btn:hover {
    opacity: 0.9;
}

.call-btn:active {
    transform: scale(0.95);
}

.messages-area {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f0f2f5;
    display: flex;
    flex-direction: column;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
}

.msg {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.msg.mine {
    align-self: flex-end;
    background: #0084ff;
    color: white;
    border-bottom-right-radius: 4px;
}

.msg.theirs {
    align-self: flex-start;
    background: white;
    color: black;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.msg-time {
    font-size: 11px;
    opacity: 0.7;
    text-align: right;
    margin-top: 4px;
}

/* Сообщение о звонке */
.call-message {
    align-self: center;
    background: #e3f2fd;
    color: #1976d2;
    padding: 8px 16px;
    border-radius: 12px;
    font-size: 13px;
    text-align: center;
    max-width: 80%;
    margin: 8px 0;
}

.call-message.missed {
    background: #ffebee;
    color: #c62828;
}

.call-message.completed {
    background: #e8f5e9;
    color: #2e7d32;
}

.input-area {
    padding: 12px 16px;
    border-top: 1px solid #e1e1e1;
    display: flex;
    gap: 10px;
    background: white;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.input-area input {
    margin: 0;
    border-radius: 24px;
    padding: 12px 18px;
    font-size: 16px;
    border: 1px solid #e1e1e1;
}

.input-area button {
    width: auto;
    margin: 0;
    border-radius: 50%;
    padding: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

/* === УВЕДОМЛЕНИЕ О ВХОДЯЩЕМ ЗВОНКЕ === */
.incoming-call-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.incoming-call-modal.show {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.incoming-call-content {
    background: white;
    border-radius: 24px;
    padding: 40px 30px;
    text-align: center;
    max-width: 90%;
    width: 350px;
    animation: slideUp 0.3s ease;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.caller-avatar {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 50px;
    margin: 0 auto 20px;
    color: white;
}

.incoming-call-content h3 {
    margin: 0 0 10px 0;
    font-size: 24px;
    color: #333;
}

.incoming-call-content p {
    margin: 0 0 30px 0;
    font-size: 16px;
    color: #666;
}

.call-actions {
    display: flex;
    gap: 12px;
}

.btn-decline {
    background: #ff3b30;
    flex: 1;
    margin: 0;
}

.btn-accept {
    background: #34c759;
    flex: 1;
    margin: 0;
}

/* === ВИДЕО/АУДИО ЗВОНОК === */
.call-overlay {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 320px;
    background: #000;
    border-radius: 16px;
    overflow: hidden;
    display: none;
    z-index: 1000;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.call-overlay.audio-mode {
    height: 180px;
    background: linear-gradient(135deg, #1e3c72, #2a5298);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

video {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

#local-video {
    position: absolute;
    bottom: 10px;
    right: 10px;
    width: 90px;
    height: 70px;
    border: 2px solid white;
    z-index: 10;
    border-radius: 8px;
    object-fit: cover;
}

.call-controls {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 20;
}

.btn-end {
    background: #ff3b30;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    width: auto;
    margin: 0;
}

.audio-call-info {
    text-align: center;
    color: white;
    z-index: 15;
    padding: 20px;
}

.audio-call-info h3 {
    margin: 0 0 8px 0;
    font-size: 20px;
    font-weight: 600;
}

.audio-call-info p {
    margin: 0;
    font-size: 14px;
    opacity: 0.9;
}

.pulse-icon {
    font-size: 50px;
    animation: pulse 1.5s infinite;
    margin-bottom: 10px;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.7;
    }
}

/* === ЗАТЕМНЕНИЕ ФОНА ПРИ ОТКРЫТОМ МЕНЮ === */
.overlay-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.overlay-bg.show {
    display: block;
    opacity: 1;
}

/* === МОБИЛЬНАЯ АДАПТАЦИЯ === */
@media (max-width: 768px) {
    body {
        background: white;
        align-items: flex-start;
    }

    .chat-layout {
        flex-direction: column;
        width: 100%;
    }

    .sidebar {
        width: 85%;
        max-width: 320px;
        height: 100%;
        position: fixed;
        top: 0;
        left: 0;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.2);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .chat-window {
        width: 100%;
    }

    .menu-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        background: #f0f2f5;
        border: none;
        font-size: 22px;
        padding: 8px 12px;
        margin-right: 8px;
        width: 44px;
        height: 44px;
        border-radius: 8px;
        cursor: pointer;
        flex-shrink: 0;
    }

    .chat-header {
        padding: 12px 12px;
    }

    .user-item {
        padding: 14px 16px;
    }

    .msg {
        max-width: 85%;
        font-size: 16px;
        padding: 12px 16px;
    }

    .messages-area {
        padding: 12px;
    }

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

    .call-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        bottom: auto;
        right: auto;
        border-radius: 0;
    }

    .call-overlay.audio-mode {
        height: 100%;
    }

    #local-video {
        bottom: 100px;
        right: 20px;
        width: 100px;
        height: 140px;
    }

    .btn-end {
        position: fixed;
        bottom: 40px;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        top: auto;
        padding: 14px 40px;
        font-size: 16px;
        z-index: 1001;
    }

    .call-buttons {
        gap: 6px;
    }

    .call-btn {
        padding: 6px 10px;
        font-size: 16px;
    }

    input,
    button {
        -webkit-appearance: none;
    }

    .incoming-call-content {
        padding: 30px 20px;
        width: 90%;
    }

    .caller-avatar {
        width: 80px;
        height: 80px;
        font-size: 40px;
    }

    .incoming-call-content h3 {
        font-size: 20px;
    }

    .call-actions {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    h2 {
        font-size: 24px;
    }

    .screen {
        padding: 25px 20px;
        width: 95%;
    }

    input {
        padding: 12px 14px;
        font-size: 16px;
    }

    button {
        padding: 12px;
        font-size: 16px;
    }

    .msg-time {
        font-size: 10px;
    }

    .audio-call-info h3 {
        font-size: 18px;
    }

    .pulse-icon {
        font-size: 40px;
    }
}

/* === Safe Area для iPhone === */
@supports (padding: max(0px)) {
    .input-area {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .chat-header {
        padding-top: max(14px, env(safe-area-inset-top));
    }
}

/* === Анимации === */
@keyframes typingBounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-3px);
    }
}

.typing-dots span {
    display: inline-block;
    animation: typingBounce 1.4s infinite;
}

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

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