.cs-chat-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-height: 0 !important;
    max-height: 100vh;
    max-height: 100dvh;
    padding-bottom: 0 !important;
    overflow: hidden;
    background: #f5f7fb;
}

.cs-chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: #fff;
    border-bottom: 1px solid #e8edf5;
    position: sticky;
    top: 0;
    z-index: 2;
}

.cs-chat-header .sub-page-title {
    flex: 1;
}

.cs-chat-status {
    font-size: 12px;
    color: #999;
}

.cs-chat-status.online {
    color: #18a058;
}

.cs-chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 14px 12px;
    display: flex;
    flex-direction: column;
}

.cs-chat-empty {
    text-align: center;
    color: #999;
    font-size: 14px;
    padding: 48px 20px;
}

.cs-chat-msg {
    margin-bottom: 14px;
    max-width: 82%;
    display: flex;
    flex-direction: column;
}

.cs-chat-msg.mine {
    align-self: flex-end;
    text-align: right;
}

.cs-chat-msg.staff {
    align-self: flex-start;
}

.cs-chat-msg-meta {
    font-size: 11px;
    color: #888;
    margin-bottom: 4px;
}

.cs-chat-bubble {
    display: inline-block;
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    text-align: left;
}

.cs-chat-bubble-image {
    padding: 0;
    background: transparent !important;
    border: 0 !important;
}

.cs-chat-msg.mine .cs-chat-bubble-image {
    background: transparent !important;
}

.cs-chat-msg.staff .cs-chat-bubble-image {
    background: transparent !important;
}

.cs-chat-msg.mine .cs-chat-bubble {
    background: #1677ff;
    color: #fff;
}

.cs-chat-msg.staff .cs-chat-bubble {
    background: #fff;
    border: 1px solid #e8edf5;
    color: #222;
}

.cs-chat-time {
    font-size: 11px;
    color: #aaa;
    margin-top: 4px;
}

.cs-chat-compose {
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid #e8edf5;
    z-index: 2;
}

.cs-chat-compose-main {
    flex: 1;
    min-width: 0;
    width: 100%;
}

.cs-chat-input-wrap {
    position: relative;
    width: 100%;
}

.cs-chat-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.cs-chat-tool-btn {
    border: 0;
    background: #f0f4fa;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    font-size: 18px;
    cursor: pointer;
    line-height: 36px;
    padding: 0;
    flex-shrink: 0;
}

.cs-chat-tool-btn:active {
    background: #e3ebf7;
}

.cs-chat-file-input {
    display: none;
}

.cs-chat-emoji-panel {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 2px;
    max-height: 168px;
    overflow-y: auto;
    padding: 8px;
    margin-bottom: 8px;
    background: #f7f9fc;
    border: 1px solid #e8edf5;
    border-radius: 10px;
}

.cs-chat-emoji-btn {
    border: 0;
    background: transparent;
    font-size: 22px;
    line-height: 1.2;
    cursor: pointer;
    padding: 4px 0;
    border-radius: 6px;
}

.cs-chat-emoji-btn:active {
    background: #e8eef8;
}

.cs-chat-paste-uploading {
    font-size: 12px;
    color: #888;
    margin-bottom: 6px;
}

.cs-chat-paste-preview {
    position: relative;
    display: inline-block;
    margin-bottom: 8px;
    max-width: 120px;
}

.cs-chat-paste-preview img {
    display: block;
    max-width: 120px;
    max-height: 90px;
    border-radius: 8px;
    border: 1px solid #d9e2ef;
    background: #fafbfd;
}

.cs-chat-paste-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 50%;
    background: #ff4d4f;
    color: #fff;
    cursor: pointer;
    line-height: 22px;
    font-size: 14px;
    padding: 0;
}

.cs-chat-msg-image {
    display: block;
    max-width: 180px;
    max-height: 180px;
    border-radius: 8px;
}

.cs-chat-bubble-file {
    padding: 0 !important;
    background: transparent !important;
    border: 0 !important;
}

.cs-chat-file-card {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 220px;
    max-width: 280px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid #e8edf5;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    box-sizing: border-box;
}

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

.cs-chat-file-name {
    font-size: 14px;
    color: #222;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cs-chat-file-size {
    font-size: 12px;
    color: #999;
    margin-top: 6px;
}

.cs-chat-file-icon {
    flex-shrink: 0;
    width: 44px;
    height: 52px;
    border-radius: 4px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    padding-bottom: 6px;
    letter-spacing: 0.5px;
    box-sizing: border-box;
}

.cs-chat-file-icon-pdf { background: #e74c3c; }
.cs-chat-file-icon-doc { background: #2b579a; }
.cs-chat-file-icon-xls { background: #1d6f42; }
.cs-chat-file-icon-ppt { background: #d24726; }
.cs-chat-file-icon-zip { background: #f0ad4e; }
.cs-chat-file-icon-txt { background: #6c757d; }
.cs-chat-file-icon-file { background: #1677ff; }

.cs-chat-input {
    width: 100%;
    box-sizing: border-box;
    display: block;
    min-height: min(18vh, 150px);
    height: min(18vh, 150px);
    max-height: min(21vh, 170px);
    resize: none;
    border: 1px solid #d9e2ef;
    border-radius: 10px;
    padding: 12px 88px 12px 12px;
    font-size: 14px;
    line-height: 1.5;
    background: #fafbfd;
}

.cs-chat-send {
    position: absolute;
    right: 8px;
    bottom: 8px;
    border: 0;
    border-radius: 10px;
    background: #1677ff;
    color: #fff;
    font-weight: 600;
    padding: 10px 16px;
    min-width: 64px;
    z-index: 1;
}

.cs-chat-send:disabled {
    opacity: 0.5;
}

@media (min-width: 992px) {
    .cs-chat-page {
        max-height: calc(100vh - 60px);
        max-height: calc(100dvh - 60px);
    }
}
