/*
 * 管理员后台样式：会话、用户列表、结果面板与小档案弹窗。
 * 作者: @ccfork
 */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    height: 100vh;
    overflow: hidden;
    background: linear-gradient(145deg, #fff5f9 0%, #ffe4ef 100%);
    color: #592e3f;
    font-family: -apple-system, "Segoe UI", "Quicksand", system-ui, sans-serif;
}
button, textarea, input, select { font: inherit; }
.admin-shell {
    display: grid;
    width: 100vw;
    height: 100vh;
    grid-template-columns: 1fr;
    background: #ffffffea;
}
.main-panel {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.users-panel,
.chat-panel,
.side-panel {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.users-panel { border-right: 1px dashed #ffcfdf; }
.panel-header,
.chat-header,
.side-header {
    flex-shrink: 0;
    padding: 12px 14px;
    border-bottom: 1px dashed #ffcfdf;
    background: #fff9fb;
}
.panel-header h1,
.side-header h2 {
    color: #b35573;
    font-size: 1.02rem;
}
.panel-sub {
    margin-top: 4px;
    color: #bc6f8c;
    font-size: 0.74rem;
}
.admin-toolbar,
.chat-actions,
.profile-actions,
.import-row,
.clear-row,
.switch-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.admin-toolbar { margin-top: 10px; }
.search-input,
.profile-dialog input,
.profile-dialog textarea,
.import-card textarea,
.question-set-tools select,
.question-set-tools input,
.question-edit-card select,
.question-edit-card textarea,
.question-form input,
.question-form textarea {
    width: 100%;
    border: 1.5px solid #ffc1d4;
    border-radius: 18px;
    outline: none;
    background: #fef6f9;
    color: #673f50;
}
.search-input { padding: 10px 12px; }
.cute-btn,
.icon-btn,
.send-btn,
.action-icon-btn {
    border: none;
    color: #fff;
    background: #ff8aac;
    cursor: pointer;
    box-shadow: 0 2px 4px #ffbbd1;
}
.cute-btn {
    padding: 9px 13px;
    border-radius: 22px;
    font-size: 0.82rem;
    font-weight: 700;
}
.cute-btn.secondary {
    color: #b35573;
    background: #ffe2ec;
    box-shadow: none;
}
.danger-btn {
    color: #fff;
    background: #d85c74;
    box-shadow: 0 2px 4px rgba(216, 92, 116, 0.22);
}
.icon-btn,
.send-btn,
.tool-btn,
.action-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex: 0 0 auto;
}
.tool-btn {
    border: 1px solid #ffd1df;
    color: #b35573;
    background: #fff7fa;
    cursor: pointer;
    box-shadow: none;
}
.action-icon-btn {
    color: #b35573;
    background: #ffe2ec;
    box-shadow: none;
}
.action-icon-btn svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.users-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}
.users-footer {
    flex-shrink: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px dashed #ffcfdf;
    background: #fff9fb;
}
.list-tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 42px;
    border: none;
    border-radius: 22px;
    color: #b35573;
    background: #ffe2ec;
    font-weight: 800;
    cursor: pointer;
}
.list-tool-btn svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.9;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.user-card {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    margin-bottom: 8px;
    padding: 10px;
    border: 1px solid #ffd1df;
    border-radius: 22px;
    background: #fff;
    cursor: pointer;
}
.session-group { margin-bottom: 14px; }
.user-card.active { background: #fff2f7; border-color: #ff8aac; }
.user-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, #ff9fbd, #ff8aac);
    font-weight: 800;
}
.user-main { min-width: 0; }
.user-name {
    color: #673f50;
    font-size: 0.88rem;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.user-meta,
.user-preview,
.user-time,
.presence-line {
    color: #bc6f8c;
    font-size: 0.72rem;
}
.user-preview { margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-badge {
    margin-top: 4px;
    padding: 3px 7px;
    border-radius: 999px;
    color: #fff;
    background: #ff8aac;
    font-size: 0.7rem;
    font-weight: 800;
    text-align: center;
}
.chat-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.chat-user h2 { font-size: 1rem; }
.chat-id-btn {
    border: none;
    color: #b35573;
    background: transparent;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
}
.presence-line {
    padding: 8px 14px 0;
}
.watch-panel {
    flex-shrink: 0;
    margin: 8px 12px 0;
    padding: 8px;
    border: 1px solid #ffd1df;
    border-radius: 18px;
    background: #fff7fa;
}
.watch-panel video {
    display: block;
    width: 100%;
    max-height: min(34vh, 260px);
    border-radius: 14px;
    background: #1b1117;
}
.watch-status {
    color: #bc6f8c;
    font-size: 0.72rem;
}
.watch-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
}
.watch-close-btn {
    flex: 0 0 auto;
    border: none;
    border-radius: 999px;
    padding: 5px 9px;
    color: #b35573;
    background: #ffe2ec;
    font-size: 0.72rem;
    font-weight: 800;
    cursor: pointer;
}
.messages-area {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
}
.message {
    display: flex;
    flex-direction: column;
    max-width: 88%;
    scroll-margin: 80px;
    -webkit-touch-callout: none;
    user-select: none;
}
.message.user { align-self: flex-start; }
.message.admin { align-self: flex-end; }
.message-bubble {
    width: fit-content;
    max-width: 100%;
    padding: 9px 13px;
    border: 1px solid #ffd1df;
    border-radius: 20px 20px 20px 6px;
    background: #fff;
    color: #673f50;
    font-size: 0.88rem;
    line-height: 1.55;
    overflow-wrap: anywhere;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.message-text {
    min-width: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.message.admin .message-bubble {
    margin-left: auto;
    border-color: #ff8aac;
    border-radius: 20px 20px 6px 20px;
    background: #ff8aac;
    color: #fff;
}
.image-bubble,
.message.admin .image-bubble {
    padding: 6px;
    background: #fff;
}
.message-image {
    display: block;
    max-width: min(240px, 62vw);
    max-height: 260px;
    border-radius: 14px;
    object-fit: contain;
    cursor: zoom-in;
}

.message-reply-block {
    display: block;
    width: auto;
    max-width: min(210px, 62vw);
    margin: 0 0 5px;
    padding: 5px 8px;
    border: 0;
    border-left: 2px solid #ff8aac;
    border-radius: 10px;
    color: #7a5364;
    background: #fff1f6;
    text-align: left;
    cursor: pointer;
    line-height: 1.25;
}

.message.admin .message-reply-block {
    border-left-color: #fff;
    color: #fff;
    background: rgba(255, 255, 255, 0.22);
}

.image-bubble .message-reply-block {
    color: #7a5364;
    background: #fff1f6;
}

.message-reply-sender {
    display: block;
    color: #b35573;
    font-size: 0.66rem;
    font-weight: 800;
    line-height: 1.2;
}

.message.admin .message-reply-sender {
    color: #fff;
}

.image-bubble .message-reply-sender {
    color: #b35573;
}

.message-reply-preview {
    display: block;
    overflow: hidden;
    color: inherit;
    font-size: 0.72rem;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-highlight .message-bubble {
    box-shadow: 0 0 0 3px rgba(255, 138, 172, 0.28);
    transform: translateY(-1px);
}
.message-time {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 4px;
    color: #e9a3bd;
    font-size: 0.64rem;
}
.message.admin .message-time {
    justify-content: flex-end;
}
.message-read {
    color: #bc6f8c;
}
.message-recall-label {
    color: #bc6f8c;
    font-weight: 800;
}
.input-area {
    flex-shrink: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px dashed #ffcfdf;
    background: #fff9fb;
}
.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.hidden-file-input { display: none; }
.upload-progress {
    display: grid;
    gap: 5px;
    margin-bottom: 8px;
}
.upload-progress[hidden] { display: none; }
.upload-progress-bar {
    overflow: hidden;
    height: 7px;
    border-radius: 999px;
    background: #ffe2ec;
}
.upload-progress-bar span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: #ff8aac;
    transition: width 0.18s ease;
}
.upload-progress p {
    color: #bc6f8c;
    font-size: 0.72rem;
    font-weight: 800;
}

.reply-draft {
    display: grid;
    grid-template-columns: 4px minmax(0, 1fr) 30px;
    align-items: center;
    gap: 9px;
    margin-bottom: 8px;
    padding: 9px 10px;
    border: 1px solid #ffd1df;
    border-radius: 16px;
    background: #fff7fa;
}

.reply-draft-mark {
    width: 4px;
    height: 34px;
    border-radius: 999px;
    background: #ff8aac;
}

.reply-draft-main {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.reply-draft-main strong {
    color: #b35573;
    font-size: 0.76rem;
}

.reply-draft-main span {
    overflow: hidden;
    color: #7a5364;
    font-size: 0.8rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reply-draft-close {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 50%;
    color: #b35573;
    background: #ffe2ec;
    cursor: pointer;
}
.message-input {
    flex: 1;
    min-height: 44px;
    max-height: 124px;
    padding: 10px 13px;
    border: 1.5px solid #ffc1d4;
    border-radius: 22px;
    outline: none;
    resize: none;
    background: #fef6f9;
    color: #673f50;
    font-size: 0.88rem;
    line-height: 1.5;
}
.side-panel {
    display: none;
    border-left: 1px dashed #ffcfdf;
    background: #fff;
}
.side-panel.active { display: flex; }
.side-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.side-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}
.results-content {
    min-height: 0;
}
.results-empty-shell {
    display: grid;
    min-height: calc(100dvh - 170px);
}
.answer-item,
.import-card,
.question-card {
    margin-bottom: 10px;
    padding: 12px;
    border: 1px solid #ffd1df;
    border-radius: 22px;
    background: #fff7fa;
}
.answer-item strong {
    display: block;
    margin-bottom: 8px;
    color: #673f50;
    font-size: 0.9rem;
    line-height: 1.45;
}
.answer-item p,
.question-card p {
    color: #7a5364;
    font-size: 0.86rem;
    line-height: 1.55;
    white-space: pre-wrap;
}
.field-label {
    display: block;
    margin: 10px 0 6px;
    color: #b35573;
    font-size: 0.78rem;
    font-weight: 800;
}
.question-edit-card {
    display: grid;
    gap: 8px;
}
.question-order {
    display: inline-flex;
    width: fit-content;
    padding: 4px 10px;
    border-radius: 999px;
    color: #fff;
    background: #ff8aac;
    font-size: 0.76rem;
    font-weight: 800;
}
.question-edit-card .field-label:first-child {
    margin-top: 0;
}
.question-edit-card select,
.question-edit-card textarea {
    padding: 10px 12px;
}
.question-edit-text {
    min-height: 86px;
    resize: vertical;
}
.question-edit-options {
    min-height: 112px;
    resize: vertical;
}
.question-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 4px;
}
.profile-modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(89, 46, 63, 0.24);
}
.profile-modal.active { display: flex; }
.profile-dialog {
    width: min(560px, 100%);
    max-height: calc(100dvh - 36px);
    overflow-y: auto;
    padding: 22px;
    border: 1px solid #ffd1df;
    border-radius: 28px;
    background: #ffffff;
    box-shadow: 0 20px 35px rgba(241, 147, 177, 0.28);
}
.profile-dialog h2 {
    color: #b35573;
    font-size: 1.05rem;
}
.profile-dialog .profile-id {
    margin: 6px 0 16px;
    color: #bc6f8c;
    font-size: 0.76rem;
    word-break: break-all;
}
.profile-dialog input,
.profile-dialog textarea {
    width: 100%;
    margin-bottom: 14px;
    padding: 10px 12px;
    border: 1.5px solid #ffc1d4;
    border-radius: 18px;
    outline: none;
    background: #fef6f9;
    color: #673f50;
}
.profile-dialog textarea { min-height: 96px; resize: vertical; }
.profile-dialog input:focus,
.profile-dialog textarea:focus,
.profile-dialog select:focus {
    border-color: #ff8aac;
    background: #fff;
}
.profile-import { margin: 2px 0 16px; }
.profile-danger {
    margin: 0 0 16px;
    padding: 14px;
    border: 1px dashed #ffb4ca;
    border-radius: 18px;
    background: #fff7fa;
}
.profile-section-title {
    margin-bottom: 8px;
    color: #b35573;
    font-size: 0.82rem;
    font-weight: 800;
}
.import-card {
    display: grid;
    gap: 12px;
}
.import-row {
    align-items: stretch;
}
.import-row select {
    min-height: 44px;
    width: min(150px, 100%);
    padding: 0 38px 0 14px;
    border: 1.5px solid #ffc1d4;
    border-radius: 18px;
    outline: none;
    color: #673f50;
    background-color: #fef6f9;
    background-image: linear-gradient(45deg, transparent 50%, #b35573 50%), linear-gradient(135deg, #b35573 50%, transparent 50%);
    background-position: calc(100% - 18px) 19px, calc(100% - 12px) 19px;
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    appearance: none;
}
.import-card textarea {
    min-height: 138px;
    max-height: 240px;
    margin-bottom: 0;
    padding: 12px;
    resize: vertical;
}
.question-set-tools {
    display: grid;
    gap: 12px;
    margin-bottom: 14px;
    padding: 14px;
    border: 1px dashed #ffcfdf;
    border-radius: 18px;
    background: #fff9fb;
}
.question-set-tools select,
.question-set-tools input {
    min-height: 44px;
    padding: 0 12px;
}
.question-set-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.switch-row {
    margin: 12px 0;
    color: #7a5364;
    font-weight: 800;
}
.switch-row input {
    width: 18px;
    height: 18px;
    accent-color: #ff8aac;
}
.question-form {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
}
.question-form input {
    min-height: 44px;
    padding: 0 12px;
}
.clear-row { justify-content: space-between; }
.profile-actions {
    justify-content: flex-start;
    gap: 10px;
}
.clear-row .cute-btn,
.profile-actions .cute-btn,
.import-row .cute-btn {
    min-height: 44px;
}
.clear-check {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: #7a5364;
    font-size: 0.8rem;
    font-weight: 700;
}
.clear-check input {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: #ff8aac;
}
.question-form textarea { min-height: 112px; padding: 12px; resize: vertical; }
.question-list { display: grid; gap: 10px; }
.question-card h3 {
    color: #673f50;
    font-size: 0.9rem;
    margin-bottom: 8px;
}
.empty-state {
    display: grid;
    place-items: center;
    min-height: 180px;
    padding: 24px;
    color: #bc6f8c;
    text-align: center;
}
.message-action-menu {
    position: fixed;
    z-index: 100;
    min-width: 112px;
    padding: 6px;
    border: 1px solid #ffd1df;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 10px 24px rgba(241, 147, 177, 0.28);
}
.message-action-menu button {
    width: 100%;
    border: 0;
    border-radius: 12px;
    padding: 9px 12px;
    color: #b35573;
    background: #fff7fa;
    font-size: 0.82rem;
    font-weight: 800;
    cursor: pointer;
}
.messages-area .empty-state {
    min-height: 100%;
}
.mobile-tabs {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 8px;
    border: 1px solid #ffd1df;
    border-radius: 24px;
    background: #ffffffee;
    box-shadow: 0 8px 20px rgba(241, 147, 177, 0.24);
}
.mobile-tabs button {
    border: none;
    border-radius: 18px;
    padding: 9px 6px;
    color: #b35573;
    background: #ffe2ec;
    font-size: 0.76rem;
    font-weight: 800;
}
.mobile-tabs button.active {
    color: #fff;
    background: #ff8aac;
}
@media (max-width: 899px) {
    .profile-modal { align-items: flex-end; padding: 10px; }
    .profile-dialog {
        max-height: calc(100dvh - 20px);
        padding: 20px 18px;
        border-radius: 26px 26px 18px 18px;
    }
    .import-row,
    .clear-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: center;
    }
    .import-row select,
    .clear-check {
        grid-column: 1 / -1;
        width: 100%;
    }
    .import-row .cute-btn,
    .clear-row .cute-btn {
        width: 100%;
    }
    .users-footer { display: none; }
    .admin-shell.show-users .users-panel,
    .admin-shell.show-chat .chat-panel,
    .admin-shell.show-results .results-panel,
    .admin-shell.show-questionnaire .questionnaire-panel {
        display: flex;
    }
    .admin-shell.show-users .chat-panel,
    .admin-shell.show-users .results-panel,
    .admin-shell.show-users .questionnaire-panel,
    .admin-shell.show-chat .users-panel,
    .admin-shell.show-chat .results-panel,
    .admin-shell.show-chat .questionnaire-panel,
    .admin-shell.show-results .users-panel,
    .admin-shell.show-results .chat-panel,
    .admin-shell.show-results .questionnaire-panel,
    .admin-shell.show-questionnaire .users-panel,
    .admin-shell.show-questionnaire .chat-panel,
    .admin-shell.show-questionnaire .results-panel {
        display: none;
    }
    .admin-shell.show-chat .input-area { margin-bottom: calc(74px + env(safe-area-inset-bottom)); }
    .users-list,
    .messages-area,
    .side-content {
        padding-bottom: 78px;
    }
}
@media (min-width: 900px) {
    .admin-shell {
        grid-template-columns: 320px minmax(0, 1fr);
        max-width: 1500px;
        margin: 0 auto;
        box-shadow: 0 20px 35px rgba(241, 147, 177, 0.18);
    }
    .chat-panel { display: flex; }
    .admin-shell.has-results { grid-template-columns: 320px minmax(0, 1fr) 340px; }
    .admin-shell.has-questionnaire { grid-template-columns: 320px minmax(0, 1fr) 340px; }
    .mobile-tabs { display: none; }
    .message { max-width: 74%; }
}
