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

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #e4e4e4;
    --text-secondary: #a0a0a0;
    --accent: #64ffda;
    --accent-hover: #4ecdc4;
    --danger: #e94560;
    --message-out: #0f3460;
    --message-in: #16213e;
    --border: #2a2a4e;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

input, textarea {
    font-family: inherit;
    border: none;
    outline: none;
    background: transparent;
    color: inherit;
}

.hidden { display: none !important; }

.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
}

.auth-container {
    margin: auto;
    padding: 2rem;
    width: 100%;
    max-width: 400px;
}

.logo {
    font-size: 2.5rem;
    color: var(--accent);
    text-align: center;
    margin-bottom: 0.5rem;
}

.subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.tab {
    flex: 1;
    padding: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.auth-form input {
    padding: 0.875rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
}

.auth-form input:focus {
    border-color: var(--accent);
}

.btn-primary {
    padding: 0.875rem;
    background: var(--accent);
    color: var(--bg-primary);
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    transition: background 0.2s;
}

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

.btn-secondary {
    padding: 0.875rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 8px;
    font-weight: 500;
}

.error-message {
    padding: 0.75rem;
    background: var(--danger);
    color: white;
    border-radius: 8px;
    text-align: center;
    margin-top: 1rem;
    font-size: 0.9rem;
}

#app {
    flex-direction: row;
}

#dialogs-panel {
    width: 360px;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
}

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

.panel-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 64px;
}

.panel-header h2, .panel-header h3 {
    flex: 1;
    font-size: 1.25rem;
    font-weight: 600;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    transition: background 0.2s;
}

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

.dialogs-list {
    overflow-y: auto;
    flex: 1;
}

.dialog-item {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: background 0.15s;
}

.dialog-item:hover { background: var(--bg-tertiary); }
.dialog-item.active { background: var(--bg-tertiary); border-left: 3px solid var(--accent); }

.dialog-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
    flex-shrink: 0;
    overflow: hidden;
}

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

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

.dialog-name {
    font-weight: 500;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dialog-last {
    color: var(--text-secondary);
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dialog-badge {
    background: var(--accent);
    color: var(--bg-primary);
    border-radius: 10px;
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

#messages-container {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.messages {
    height: 100%;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.message {
    max-width: 70%;
    padding: 0.625rem 0.875rem;
    border-radius: 16px;
    word-wrap: break-word;
    line-height: 1.4;
    position: relative;
    animation: fadeIn 0.2s;
}

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

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

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

.message-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    text-align: right;
}

.message-media {
    max-width: 300px;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    cursor: pointer;
}

.input-area {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: var(--bg-secondary);
}

#message-input {
    flex: 1;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 20px;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}

.modal {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    width: 100%;
    max-width: 400px;
}

.modal h3 { margin-bottom: 1rem; }

.modal input {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

.notifications {
    position: fixed;
    top: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 200;
    pointer-events: none;
}

.notification {
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border-left: 4px solid var(--accent);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    animation: slideIn 0.3s;
    pointer-events: auto;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.notification.error { border-left-color: var(--danger); }

@media (max-width: 768px) {
    #dialogs-panel {
        position: absolute;
        inset: 0;
        width: 100%;
        z-index: 2;
        transform: translateX(0);
        transition: transform 0.3s;
    }

    #dialogs-panel.hidden-mobile {
        transform: translateX(-100%);
    }

    #chat-panel {
        position: absolute;
        inset: 0;
        z-index: 1;
    }

    #back-to-dialogs { display: flex !important; }

    .message { max-width: 85%; }
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }
