/* Чат */
.chat-layout {
    display: flex;
    height: calc(100vh - 56px - env(safe-area-inset-top));
    margin-top: calc(56px + env(safe-area-inset-top));
    overflow: hidden;
}

.chat-list {
    width: 320px;
    min-width: 280px;
    border-right: 1px solid var(--border-color);
    background: var(--bg-surface);
    display: flex;
    flex-direction: column;
}

.chat-list-header {
    padding: 14px 16px;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

.chat-list-body {
    overflow-y: auto;
    padding: 10px;
}

.chat-item {
    display: flex;
    gap: 10px;
    padding: 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.chat-item:hover {
    background: var(--bg-card);
}

.chat-item.active {
    background: var(--bg-card);
    border-color: var(--accent-primary);
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-last {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    font-size: 10px;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.chat-unread {
    background: var(--accent-primary);
    color: #fff;
    font-size: 10px;
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    position: relative;
    overflow: hidden;
}

@media (min-width: 901px) {
    .chat-input {
        position: relative;
        bottom: auto;
        left: auto;
        right: auto;
        box-shadow: none;
    }
    
    .chat-window .chat-input {
        position: relative;
        bottom: auto;
        left: auto;
        right: auto;
        box-shadow: none;
    }
    
    .chat-window .chat-messages {
        padding-bottom: 16px;
    }
    
    .chat-reply {
        position: relative;
        bottom: auto;
        left: auto;
        right: auto;
        box-shadow: none;
    }
    
    .chat-input-preview {
        position: relative;
        bottom: auto;
        left: auto;
        right: auto;
        box-shadow: none;
    }
}

.chat-window-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
    flex-shrink: 0;
}

.chat-window .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

@media (max-width: 900px) {
    .chat-window .chat-messages {
        padding-bottom: 80px;
    }
}

@media (min-width: 901px) {
    .chat-window .chat-messages {
        padding-bottom: 16px;
    }
}

.chat-back-btn {
    display: none;
    border: none;
    background: var(--bg-card);
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    align-items: center;
    justify-content: center;
}

.chat-partner {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-partner-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 11px;
    overflow: hidden;
}

.chat-partner-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-partner-name {
    font-size: 14px;
    font-weight: 700;
}

.chat-partner-sub {
    font-size: 11px;
    color: var(--text-secondary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.chat-global .chat-messages {
    padding-bottom: 100px;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

.chat-empty {
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    padding: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.chat-empty::before {
    content: '💬';
    font-size: 48px;
    opacity: 0.5;
}

.chat-message {
    max-width: 75%;
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--bg-card);
    color: var(--text-primary);
    align-self: flex-start;
    position: relative;
    border: 1px solid var(--border-color);
    display: flex;
    gap: 8px;
    animation: messageAppear 0.2s ease-out;
}

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.mine {
    flex-direction: row-reverse;
}

.chat-window .chat-message.mine {
    background: var(--accent-gradient);
    color: #fff;
    align-self: flex-end;
    border-color: transparent;
}

.chat-window .chat-message.mine .chat-message-content {
    align-items: flex-end;
    text-align: right;
}

.chat-window .chat-message.role-master:not(.mine) {
    background: linear-gradient(135deg, rgba(123, 97, 255, 0.12), rgba(123, 97, 255, 0.22));
    border-color: rgba(123, 97, 255, 0.3);
}

.chat-window .chat-message.role-client:not(.mine) {
    background: linear-gradient(135deg, rgba(0, 214, 143, 0.12), rgba(0, 214, 143, 0.22));
    border-color: rgba(0, 214, 143, 0.3);
}

.chat-window .chat-message.mine .chat-message-meta {
    color: rgba(255, 255, 255, 0.7);
}

.chat-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 11px;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-message-content {
    flex: 1;
    min-width: 0;
}

.chat-message-sender {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.chat-message.mine .chat-message-sender {
    display: none;
}


.chat-message-text {
    font-size: 13px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-message-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 10px;
    margin: 8px 0;
    cursor: pointer;
    object-fit: cover;
    display: block;
    transition: var(--transition);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chat-message-image:hover {
    opacity: 0.9;
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.chat-message.has-image {
    padding: 8px;
}

.chat-message.has-image .chat-message-text {
    margin-top: 8px;
}

.chat-message-reply {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    border-left: 2px solid rgba(255, 255, 255, 0.6);
    padding-left: 8px;
    margin-bottom: 6px;
}

.chat-message.mine .chat-message-reply {
    color: rgba(255, 255, 255, 0.85);
}

.chat-message-meta {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 4px;
}

.chat-message:not(.mine) .chat-message-meta {
    color: var(--text-tertiary);
}

.chat-checks {
    letter-spacing: -1px;
}

.chat-input {
    display: flex;
    flex-direction: column;
    padding: 0;
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface);
}

@media (max-width: 900px) {
    .chat-input {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }
    
    .chat-window .chat-input {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }
}

.chat-input-actions {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    width: 100%;
    box-sizing: border-box;
    flex-wrap: nowrap;
}

.chat-window .chat-input-actions {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

.chat-input-file-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    border: none;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    font-size: 16px;
}

.chat-input-file-btn:active {
    transform: scale(0.95);
    background: var(--bg-hover);
}

.chat-input-file-btn:hover {
    background: var(--bg-hover);
}

.chat-input-preview {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.chat-input-preview::-webkit-scrollbar {
    display: none;
}

@media (max-width: 900px) {
    .chat-input-preview {
        position: fixed;
        left: 0;
        right: 0;
        z-index: 101;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    }
    
    .chat-window .chat-input-preview {
        position: relative;
        bottom: auto;
        left: auto;
        right: auto;
        box-shadow: none;
    }
}

.chat-input-preview::-webkit-scrollbar {
    display: none;
}

.chat-input-preview-item {
    position: relative;
    width: 56px;
    height: 56px;
    min-width: 56px;
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-hover);
    flex-shrink: 0;
}

.chat-input-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-input-preview-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: #fff;
    border: 2px solid var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.chat-input-preview-remove:active {
    transform: scale(0.9);
}

.chat-input textarea {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    resize: none;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    padding: 10px 14px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.4;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
    box-sizing: border-box;
    min-width: 0;
    overflow-y: auto;
}

.chat-input textarea:focus {
    border-color: var(--accent-primary);
    background: var(--bg-surface);
}

.chat-input button {
    width: 40px;
    height: 40px;
    min-width: 40px;
    max-width: 40px;
    border-radius: 50%;
    border: none;
    background: var(--accent-gradient);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    font-size: 16px;
    box-shadow: 0 2px 8px rgba(74, 111, 255, 0.3);
}

.chat-input button:active {
    transform: scale(0.95);
    box-shadow: 0 1px 4px rgba(74, 111, 255, 0.2);
}

.chat-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.chat-message-sending {
    opacity: 0.6;
    pointer-events: none;
}

.chat-reply {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    animation: slideDown 0.2s ease-out;
}

@media (max-width: 900px) {
    .chat-reply {
        position: fixed;
        left: 0;
        right: 0;
        z-index: 102;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    }
    
    .chat-window .chat-reply {
        position: relative;
        bottom: auto;
        left: auto;
        right: auto;
        box-shadow: none;
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-reply-text {
    font-size: 12px;
    color: var(--text-secondary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-reply-close {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.chat-global {
    margin-top: calc(56px + env(safe-area-inset-top));
    height: calc(100vh - 56px - env(safe-area-inset-top));
    display: flex;
    flex-direction: column;
    padding-bottom: calc(60px + env(safe-area-inset-bottom));
}

.chat-global .chat-message.mine {
    background: var(--accent-gradient);
    color: #fff;
    align-self: flex-end;
    border-color: transparent;
}

@media (max-width: 900px) {
    .chat-layout {
        flex-direction: column;
    }

    .chat-list {
        width: 100%;
        min-width: 100%;
    }

    .chat-window {
        display: none;
    }

    .chat-layout.chat-open .chat-list {
        display: none;
    }

    .chat-layout.chat-open .chat-window {
        display: flex;
    }

    .chat-back-btn {
        display: inline-flex;
    }
    
    .chat-message {
        max-width: 85%;
    }
    
    .chat-message-image {
        max-height: 250px;
    }
    
    .chat-avatar {
        width: 32px;
        height: 32px;
        font-size: 11px;
    }
    
    .chat-message-avatar {
        width: 24px;
        height: 24px;
        font-size: 10px;
    }
    
    .chat-input-actions {
        gap: 6px;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    }
    
    .chat-input-file-btn,
    .chat-input button {
        width: 38px;
        height: 38px;
        min-width: 38px;
        font-size: 15px;
    }
    
    .chat-input textarea {
        min-height: 38px;
        padding: 9px 12px;
        font-size: 14px;
        border-radius: 19px;
    }
    
    .chat-input-preview {
        padding: 6px 10px;
    }
    
    .chat-input-preview-item {
        width: 50px;
        height: 50px;
        min-width: 50px;
    }
    
    .chat-messages {
        padding: 12px;
        gap: 8px;
        padding-bottom: 100px;
    }
    
    .chat-global .chat-messages {
        padding-bottom: 100px;
    }
    
    .chat-window .chat-messages {
        padding-bottom: 100px;
    }
    
    .chat-message {
        padding: 8px 10px;
        gap: 6px;
    }
    
    .chat-input {
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    }
    
    .chat-layout {
        position: relative;
    }
    
    .chat-list {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1;
    }
    
    .chat-window {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 2;
    }
}

@media (max-width: 360px) {
    .chat-input-actions {
        gap: 5px;
        padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    }
    
    .chat-input-file-btn,
    .chat-input button {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 14px;
    }
    
    .chat-input textarea {
        min-height: 36px;
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .chat-messages {
        padding: 10px;
        gap: 6px;
        padding-bottom: 90px;
    }
    
    .chat-global .chat-messages {
        padding-bottom: 90px;
    }
    
    .chat-message {
        padding: 7px 9px;
        gap: 5px;
    }
}

/* Стили для кнопки входа в общий чат */
.chat-input .auth-btn {
    width: auto;
    min-width: 200px;
    height: 48px;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: var(--transition);
    padding: 0 24px;
    text-decoration: none;
    margin: 0;
}

.chat-input .auth-btn:hover {
    background: var(--accent-gradient-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.chat-input .auth-btn:active {
    transform: translateY(0);
}

@media (max-width: 480px) {
    .chat-input .auth-btn {
        width: 100%;
        min-width: auto;
        height: 44px;
        font-size: 14px;
        padding: 0 20px;
    }
}

