* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --brand: #e53935;
    --brand-soft: rgba(229, 57, 53, 0.12);
    --bg-app: #f4f6f9;
    --bg-panel: #ffffff;
    --bg-rail: #1e2530;
    --bg-chat: #e8ecf1;
    --border: #e4e7ed;
    --text: #1f2937;
    --muted: #6b7280;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);
    --radius: 10px;
    --sent-bg: linear-gradient(135deg, #e53935 0%, #ef5350 100%);
    --recv-bg: #ffffff;
}

html,
body,
#app {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", -apple-system, sans-serif;
    background: var(--bg-app);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.hidden {
    display: none !important;
}

/* —— 登录 —— */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(145deg, #1e2530 0%, #2d3a4f 45%, #e53935 120%);
    padding: 24px;
}

.login-box {
    width: 100%;
    max-width: 400px;
    padding: 40px 36px 32px;
    background: var(--bg-panel);
    border-radius: 16px;
    box-shadow: var(--shadow-md);
}

.login-title {
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    color: var(--brand);
    letter-spacing: 0.02em;
}

.login-subtitle {
    text-align: center;
    color: var(--muted);
    margin: 8px 0 28px;
    font-size: 13px;
}

.login-foot {
    margin-top: 20px;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
}

.login-foot a {
    color: var(--brand);
    text-decoration: none;
}

/* —— 主布局 —— */
.main-container {
    display: flex;
    height: 100vh;
    background: var(--bg-app);
}

/* 左轨：TG 号 */
.account-rail {
    width: 88px;
    flex-shrink: 0;
    background: var(--bg-rail);
    display: flex;
    flex-direction: column;
    color: #e5e7eb;
}

.account-rail-head {
    padding: 14px 8px 10px;
    text-align: center;
    font-size: 11px;
    color: #9ca3af;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    line-height: 1.5;
}

.account-rail-head strong {
    display: block;
    color: #f3f4f6;
    font-size: 12px;
    margin-bottom: 2px;
}

.account-rail-search {
    padding: 8px;
}

.account-rail-search .el-input__wrapper {
    background: rgba(255, 255, 255, 0.08) !important;
    box-shadow: none !important;
}

.account-rail-search .el-input__inner {
    color: #f9fafb !important;
    text-align: center;
    font-size: 12px;
}

.account-rail-body {
    flex: 1;
    min-height: 0;
}

.account-chip {
    width: 100%;
    padding: 10px 6px;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: center;
    color: #d1d5db;
    transition: background 0.15s, color 0.15s;
}

.account-chip:hover {
    background: rgba(255, 255, 255, 0.06);
}

.account-chip.active {
    background: rgba(229, 57, 53, 0.25);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--brand);
}

.account-chip .phone-tail {
    display: block;
    font-weight: 600;
    font-size: 13px;
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    margin-top: 4px;
}

.account-chip .st-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-right: 3px;
    vertical-align: middle;
}

.account-chip .st-dot.online {
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
}

.account-chip .st-dot.offline {
    background: #6b7280;
}

.account-chip .unread-dot {
    display: inline-block;
    min-width: 18px;
    padding: 1px 5px;
    margin-top: 6px;
    background: var(--brand);
    color: #fff;
    border-radius: 9px;
    font-size: 10px;
    font-weight: 600;
}

.account-rail-foot {
    padding: 10px 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 11px;
    color: #9ca3af;
    text-align: center;
}

.account-rail .el-empty__description {
    color: #9ca3af;
    font-size: 11px;
}

body.dark-mode .el-input__wrapper,
body.dark-mode .el-textarea__inner {
    background-color: #374151;
    color: #f3f4f6;
}

/* 会话栏 */
.sidebar {
    width: 300px;
    flex-shrink: 0;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
}

.sidebar-header {
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #fff 0%, #fafbfc 100%);
}

.sidebar-header .brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.sidebar-header .header-actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.sidebar-header .header-actions .el-button {
    margin: 0;
    padding: 5px 9px;
}

.msg-sticker-label {
    font-size: 14px;
}

.sidebar-header .brand {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
}

.sidebar-header .brand span {
    color: var(--brand);
}

.sidebar-header .desk-version-tag {
    margin-left: 8px;
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
    vertical-align: middle;
}

.sidebar-header .meta {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--muted);
}

.sidebar-header .meta .unread-pill {
    background: var(--brand-soft);
    color: var(--brand);
    padding: 2px 10px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 12px;
}

.sidebar-header .toolbar {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.sidebar-search {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.group-tabs {
    padding: 8px 12px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.contacts-refresh-hint {
    font-size: 12px;
    color: var(--muted, #909399);
    white-space: nowrap;
    flex-shrink: 0;
}

.group-tabs .el-radio-group {
    width: 100%;
}

.group-tabs .el-radio-button {
    flex: 1;
}

.group-tabs .el-radio-button__inner {
    width: 100%;
    border-radius: 8px !important;
}

.contacts-body {
    flex: 1;
    min-height: 0;
    background: #fafbfc;
}

.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid #f0f2f5;
    transition: background 0.12s;
}

.contact-item:hover {
    background: #f3f4f6;
}

.contact-item.active {
    background: var(--brand-soft);
    border-left: 3px solid var(--brand);
    padding-left: 11px;
}

.contact-item.unread .contact-name {
    font-weight: 600;
    color: var(--text);
}

.contact-avatar {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-size: 17px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.contact-body {
    flex: 1;
    min-width: 0;
}

.contact-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
}

.contact-mark-btn {
    flex-shrink: 0;
    border: none;
    background: transparent;
    color: #cbd5e1;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
    cursor: pointer;
    transition: color 0.15s, transform 0.12s;
}

.contact-mark-btn:hover {
    color: #f59e0b;
    transform: scale(1.08);
}

.contact-mark-btn.active {
    color: #f59e0b;
}

.contact-item.marked .contact-name {
    color: var(--text);
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.contact-mark-btn.header {
    font-size: 20px;
}

.header-mark-btn {
    font-weight: 600;
}

.marked-tab-hint {
    margin: 0 12px 8px;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.4;
}

.mark-account-tail {
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: #64748b;
    border-radius: 4px;
    padding: 1px 5px;
    line-height: 1.3;
}

.contact-item.marked .mark-account-tail {
    background: #f59e0b;
}

.contact-name {
    font-size: 15px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.contact-peer-phone {
    font-size: 12px;
    line-height: 1.35;
    color: #059669;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-item.has-peer-phone .contact-message {
    margin-top: 2px;
}

.contact-time {
    font-size: 11px;
    color: var(--muted);
    flex-shrink: 0;
}

.contact-message {
    margin-top: 4px;
    font-size: 13px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.unread-badge {
    flex-shrink: 0;
}

/* 聊天区 */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-chat);
}

.chat-header {
    height: 60px;
    padding: 0 20px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
}

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

.chat-header-info .chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0ea5e9, #06b6d4);
    color: #fff;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-header-title {
    font-size: 16px;
    font-weight: 600;
}

.chat-header-phone {
    font-size: 13px;
    color: #059669;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    margin-top: 3px;
}

.chat-header-phone.muted {
    color: var(--muted);
    font-family: inherit;
    font-size: 12px;
}

.chat-header-sub {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

.chat-messages-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-chat);
    background-image: radial-gradient(circle at 1px 1px, rgba(0, 0, 0, 0.04) 1px, transparent 0);
    background-size: 20px 20px;
}

.chat-messages-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.load-older {
    text-align: center;
    padding: 10px;
}

.msg-row {
    display: flex;
    flex-direction: column;
    padding: 6px 16px 8px;
    position: relative;
    width: 100%;
    box-sizing: border-box;
    flex-shrink: 0;
}

.msg-row.received {
    align-items: flex-start;
}

.msg-row.sent {
    align-items: flex-end;
}

.message-bubble {
    display: inline-block;
    width: fit-content;
    max-width: 100%;
    padding: 8px 12px 6px;
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
    line-height: 1.45;
    font-size: 14px;
    word-break: break-word;
    vertical-align: top;
}

.msg-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.message-bubble.received {
    background: var(--recv-bg);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.message-bubble.sent {
    background: var(--sent-bg);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message-bubble.pending {
    opacity: 0.82;
}

.message-bubble.has-photo {
    padding: 6px 6px 4px;
    overflow: hidden;
}

.message-time {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 2px;
    font-size: 11px;
    margin-top: 6px;
    opacity: 0.75;
    text-align: right;
}

/* 出站消息：单勾已发送，双勾对方已读（类似 Telegram） */
.msg-delivery-ticks {
    display: inline-flex;
    align-items: center;
    margin-left: 5px;
    vertical-align: baseline;
    line-height: 1;
    opacity: 0.82;
    user-select: none;
}

.msg-delivery-ticks.is-read {
    opacity: 1;
}

.msg-delivery-ticks.is-pending {
    opacity: 0.55;
}

.msg-delivery-ticks .msg-tick {
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
}

.msg-delivery-ticks .msg-tick + .msg-tick {
    margin-left: -6px;
}

.message-bubble.sent .msg-delivery-ticks {
    color: rgba(255, 255, 255, 0.9);
}

.message-bubble.sent .msg-delivery-ticks.is-read {
    color: #fff;
}

.chat-composer {
    padding: 10px 14px 14px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
}

.composer-toolbar {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
}

.composer-tool {
    border: none;
    background: #f3f4f6;
    border-radius: 8px;
    width: 36px;
    height: 32px;
    cursor: pointer;
    font-size: 18px;
}

.composer-tool:hover {
    background: #e5e7eb;
}

.emoji-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px;
    margin-bottom: 8px;
    background: #f9fafb;
    border-radius: 10px;
    max-height: 120px;
    overflow-y: auto;
}

.emoji-pick {
    border: none;
    background: transparent;
    font-size: 22px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    border-radius: 8px;
}

.emoji-pick:hover {
    background: #fff;
    box-shadow: var(--shadow-sm);
}

.reply-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    margin-bottom: 8px;
    background: var(--brand-soft);
    border-left: 3px solid var(--brand);
    border-radius: 8px;
    font-size: 13px;
}

.reply-banner-label {
    color: var(--brand);
    font-weight: 600;
    flex-shrink: 0;
}

.reply-banner-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
}

.reply-banner-close {
    border: none;
    background: transparent;
    font-size: 18px;
    cursor: pointer;
    color: var(--muted);
    line-height: 1;
}

.composer-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.composer-att-item {
    position: relative;
    width: 72px;
    height: 72px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: #f3f4f6;
}

.composer-att-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.composer-att-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

.msg-photo-placeholder {
    font-size: 13px;
    color: var(--muted);
    padding: 8px 0 4px;
    min-height: 48px;
}

.msg-photo {
    display: block;
    width: auto;
    height: auto;
    max-width: min(72vw, 320px);
    max-height: 360px;
    border-radius: 10px;
    margin-bottom: 4px;
    object-fit: contain;
    cursor: zoom-in;
    vertical-align: top;
}

.msg-photo.msg-sticker {
    max-width: min(72vw, 200px);
    max-height: 200px;
    background: transparent;
}

.photo-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
    cursor: zoom-out;
}

.photo-lightbox-img {
    max-width: min(96vw, 1400px);
    max-height: 92vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
    cursor: default;
}

.photo-lightbox-close {
    position: fixed;
    top: 16px;
    right: 20px;
    z-index: 10000;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

.photo-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.28);
}

.composer-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.composer-row .el-textarea__inner {
    border-radius: 12px !important;
    resize: none;
}

.msg-bubble-wrap {
    position: relative;
    width: fit-content;
    max-width: min(78%, 420px);
}

.msg-row.sent .msg-bubble-wrap {
    margin-left: 0;
}

.msg-quote {
    font-size: 12px;
    opacity: 0.85;
    padding: 6px 8px;
    margin-bottom: 6px;
    border-left: 3px solid rgba(0, 0, 0, 0.15);
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-bubble.sent .msg-quote {
    border-left-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.12);
}

.msg-my-reaction {
    margin-left: 6px;
}

.msg-hover-actions {
    display: none;
    gap: 4px;
    margin-top: 4px;
    justify-content: flex-end;
}

.msg-row.received .msg-hover-actions {
    justify-content: flex-start;
}

.msg-bubble-wrap:hover .msg-hover-actions {
    display: flex;
}

.msg-hover-actions button {
    border: none;
    background: rgba(255, 255, 255, 0.95);
    color: var(--muted);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.msg-hover-actions button:hover {
    color: var(--brand);
}

.reaction-bar {
    display: flex;
    gap: 4px;
    padding: 6px 8px;
    margin-bottom: 4px;
    background: #fff;
    border-radius: 24px;
    box-shadow: var(--shadow-md);
    width: fit-content;
}

.msg-row.sent .reaction-bar {
    margin-left: auto;
}

.reaction-btn {
    border: none;
    background: transparent;
    font-size: 22px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    border-radius: 50%;
}

.reaction-btn:hover,
.reaction-btn.active {
    background: #f3f4f6;
    transform: scale(1.08);
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    padding: 32px;
    text-align: center;
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 14px;
    line-height: 1.6;
}

.desk-toast {
    margin-top: 8px;
    font-size: 12px;
    color: #b45309;
}

/* 虚拟列表 */
.vscroll {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
}

.vscroll-phantom {
    width: 100%;
    pointer-events: none;
}

.vscroll-window {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    will-change: transform;
}

.vscroll-item {
    overflow: visible;
    box-sizing: border-box;
}

.vscroll::-webkit-scrollbar {
    width: 6px;
}

.vscroll::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

/* 深色模式 */
body.dark-mode {
    --bg-app: #111827;
    --bg-panel: #1f2937;
    --bg-rail: #0f1419;
    --bg-chat: #17212b;
    --border: #374151;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --recv-bg: #2b3948;
}

body.dark-mode .sidebar-header {
    background: linear-gradient(180deg, #1f2937 0%, #1a2332 100%);
}

body.dark-mode .contacts-body {
    background: #1a2332;
}

body.dark-mode .contact-item:hover {
    background: #253041;
}

body.dark-mode .chat-messages-wrap {
    background-color: var(--bg-chat);
    background-image: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.03) 1px, transparent 0);
}

/* 批量换头像/昵称 */
.profile-batch-hint {
    font-size: 13px;
    line-height: 1.55;
    color: var(--muted);
    white-space: pre-line;
    margin-bottom: 14px;
}

.profile-batch-privacy-block {
    margin-top: 14px;
    padding: 12px;
    border-radius: 8px;
    background: var(--surface-2, rgba(0, 0, 0, 0.04));
    border: 1px solid var(--border, rgba(0, 0, 0, 0.08));
}

.profile-batch-privacy-hint {
    font-size: 12px;
    line-height: 1.5;
    color: var(--muted);
    margin: 0 0 10px;
}

.profile-batch-bio-section {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px dashed var(--border, rgba(0, 0, 0, 0.12));
}

.profile-batch-upload {
    margin-top: 12px;
}

.profile-batch-upload-inner {
    padding: 8px 0;
    font-size: 13px;
    color: var(--muted);
}

.profile-batch-result {
    margin-top: 16px;
}

.profile-batch-ok {
    color: #16a34a;
    font-weight: 600;
}

.profile-batch-fail {
    color: var(--brand);
    font-weight: 600;
}

.profile-batch-pending {
    color: var(--muted);
}

.profile-batch-manual .el-button--small {
    padding: 4px 8px;
}
