:root {
    --bg-color: #fafafe;
    --card-bg: #FFFFFF;
    --primary-color: #4F46E5;
    --primary-hover: #4338CA;
    --text-main: #1E293B;
    --text-sub: #64748B;
    --border-color: #f6f6f6;
    --surface-subtle: #F1F5F9;
    --success-color: #10B981;
    --warning-color: #F59E0B;
    --danger-color: #EF4444;
    --accent-glow: rgba(79, 70, 229, 0.45);
    --card-shadow: 0 25px 70px -10px rgba(0, 0, 0, 0.06);
    --btn-radius: 12px;
    --card-radius: 24px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    -webkit-tap-highlight-color: transparent;
}

/* Top navigation */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto 20px;
    padding: 0 40px 0 30px;
    height: 46px;
    overflow: visible;
}
.logo {
    font-size: 28px;
    font-weight: 800;
    color: var(--text-main);
    text-decoration: none;
    display: flex;
    align-items: center;
}
.logo span { color: var(--primary-color); }

.logo-char {
    height: 70px;
    object-fit: cover;
    object-position: top;
    border-radius: 12px;
    margin-bottom: -14px;
    position: relative;
    z-index: 1;
    margin-right: 10px;
}

/* User area */
.user-area {
    display: flex;
    align-items: center;
    gap: 12px;
}
.login-btn {
    background: rgba(79, 70, 229, 0.06);
    color: var(--primary-color);
    border: 1px solid rgba(79, 70, 229, 0.15);
    padding: 10px 22px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@media (hover: hover) {
    .login-btn:hover {
        background: var(--primary-color);
        color: white;
        box-shadow: 0 8px 16px rgba(79, 70, 229, 0.15);
        transform: translateY(-1.5px);
    }
}
.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    position: relative;
    padding: 6px 12px;
    border-radius: 16px;
    background: #F8FAFC;
    border: 1px solid #F1F5F9;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.user-profile:hover {
    background: #F1F5F9;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}
.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--border-color);
}
.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
}
.profile-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #FFFFFF;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    border: 1px solid #F1F5F9;
    padding: 6px;
    display: none;
    z-index: 100;
    min-width: 160px;
    animation: dropdownFade 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
}
.profile-dropdown::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 0;
    right: 0;
    height: 8px;
    background: transparent;
}
.user-profile:hover .profile-dropdown {
    display: block;
}
.dropdown-item {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}
.dropdown-item.primary {
    color: var(--text-main);
}
.dropdown-item.primary:hover {
    background: #F1F5F9;
}
.dropdown-item.danger {
    color: var(--danger-color);
}
.dropdown-item.danger:hover {
    background: #FEF2F2;
}

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

/* Dialog base */
dialog {
    border: none;
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: var(--card-shadow);
    padding: 0;
    width: calc(100% - 32px);
    max-width: 420px;
    margin: auto;
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;
    opacity: 0;
    transform: scale(0.95);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: visible;
    z-index: 1000;
}
dialog[open] {
    opacity: 1;
    transform: scale(1);
    animation: dialogShow 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
dialog::backdrop {
    background-color: rgba(15, 23, 42, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity 0.3s ease;
}
dialog[open]::backdrop { opacity: 1; }

@keyframes dialogShow {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes successScale {
    from { transform: scale(0); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes checkDraw {
    from { stroke-dashoffset: 24; }
    to { stroke-dashoffset: 0; }
}

/* Dialog interior */
.dialog-content {
    padding: 40px;
    position: relative;
}
.close-dialog-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface-subtle);
    border: none;
    color: var(--text-sub);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    transition: all 0.2s;
    outline: none;
}
.close-dialog-btn:focus { outline: none; }
.close-dialog-btn:focus-visible { outline: none; }
.close-dialog-btn:hover {
    background: var(--border-color);
    color: var(--text-main);
}
.dialog-header {
    text-align: center;
    margin-bottom: 28px;
}
.dialog-logo {
    font-size: 24px;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 8px;
}
.dialog-logo span { color: var(--primary-color); }
.dialog-title {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 8px;
}
.dialog-subtitle {
    font-size: 13px;
    color: var(--text-sub);
    line-height: 1.5;
}

/* Form inputs */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
    text-align: left;
}
.input-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-sub);
    text-transform: uppercase;
}
.input-group input {
    padding: 12px 16px;
    border-radius: var(--btn-radius);
    border: 1.5px solid var(--border-color);
    font-size: 14px;
    color: var(--text-main);
    outline: none;
    background: var(--card-bg);
    transition: all 0.3s;
}
.input-group input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}
.input-group input.error {
    border-color: var(--danger-color);
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.08);
}
.field-error {
    font-size: 11px; color: var(--danger-color); font-weight: 500;
    display: none; margin-top: 2px;
}
.field-error.show { display: block; }

.password-wrapper {
    position: relative;
}
.password-wrapper input {
    width: 100%;
    padding-right: 44px;
}
.toggle-password-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94A3B8;
    border-radius: 8px;
    transition: color 0.2s;
}
.toggle-password-btn:hover {
    color: var(--text-sub);
}

/* Buttons */
.auth-submit-btn {
    width: 100%;
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 14px;
    border-radius: var(--btn-radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.2);
    transition: all 0.3s;
}
.auth-submit-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 8px 24px rgba(79, 70, 229, 0.3);
}

.confirm-dialog-body { text-align: center; }
.confirm-dialog-icon {
    width: 56px; height: 56px;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 20px;
    font-size: 24px;
}
.confirm-dialog-actions { display: flex; gap: 12px; margin-top: 24px; }
.confirm-dialog-btn {
    flex: 1; padding: 12px; border-radius: 12px;
    font-size: 14px; font-weight: 600; cursor: pointer;
    border: none; transition: all 0.3s; outline: none;
}
.confirm-dialog-btn:focus { outline: none; box-shadow: none; }
.confirm-dialog-btn.cancel { background: #F1F5F9; color: var(--text-sub); }
.confirm-dialog-btn.cancel:hover { background: #E2E8F0; }
.confirm-dialog-btn.confirm { background: var(--danger-color); color: white; }
.confirm-dialog-btn.confirm:hover { background: #DC2626; }

.btn-full { width: 100%; justify-content: center; }

.agent-select-item {
    display: flex; align-items: center; gap: 10px; padding: 12px;
    border-radius: 14px; cursor: pointer;
    border: 1.5px solid var(--border-color); background: var(--card-bg);
}
.agent-select-item:hover { border-color: var(--primary-color); }
.agent-select-item input { width: 18px; height: 18px; accent-color: var(--primary-color); }
.agent-select-item img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }

.more-dropdown {
    position: absolute; right: 0; top: 100%;
    background: var(--card-bg); border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    padding: 4px; z-index: 10; min-width: 100px;
}

/* Shared chat UI (used by chat.html + group.html) */
.chat-back-link {
    display: flex; align-items: center; gap: 4px;
    font-size: 13px; color: var(--text-sub);
    text-decoration: none; font-weight: 600; flex-shrink: 0;
    padding: 6px 10px; border-radius: 8px; transition: all 0.2s;
}
.chat-back-link:hover { color: var(--primary-color); background: var(--surface-subtle); }

.chat-messages {
    flex: 1; overflow-y: auto; padding: 24px;
    display: flex; flex-direction: column; gap: 16px;
    background: var(--bg-color);
}

.chat-sidebar {
    width: 300px; flex-shrink: 0; border-left: 1px solid var(--border-color);
    padding: 32px 24px; display: flex; flex-direction: column;
    align-items: center; gap: 20px; overflow-y: auto;
}
.chat-input-area { padding: 16px 24px; border-top: 1px solid var(--border-color); display: flex; gap: 12px; align-items: flex-end; flex-shrink: 0; }
.chat-input {
    flex: 1; padding: 12px 16px; border-radius: var(--btn-radius);
    border: 1.5px solid var(--border-color); font-size: 14px;
    font-family: inherit; color: var(--text-main); outline: none;
    background: var(--bg-color); transition: border-color 0.3s;
    resize: none; line-height: 1.5; min-height: 44px;
    max-height: calc(1.5em * 3 + 24px); overflow-y: auto;
}
.chat-input:focus { border-color: var(--primary-color); box-shadow: 0 0 0 4px rgba(79,70,229,0.1); }

.chat-send {
    padding: 12px 20px; border-radius: var(--btn-radius);
    border: none; font-size: 14px; font-weight: 600;
    cursor: pointer; font-family: inherit; transition: all 0.3s;
    margin-bottom: 6px;
}

.emoji-btn { width: 40px; height: 40px; border: none; background: transparent; font-size: 20px; cursor: pointer; border-radius: 8px; transition: background 0.2s; flex-shrink: 0; }
.emoji-btn:hover { background: var(--surface-subtle); }
.emoji-popup {
    position: absolute; bottom: 100%; right: 0; margin-bottom: 8px;
    background: #fff; border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.12); padding: 12px; z-index: 10;
    display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; max-width: 360px;
}
.emoji-popup button { width: 36px; height: 36px; border: none; background: transparent; font-size: 20px; cursor: pointer; border-radius: 8px; transition: background 0.15s, transform 0.15s; }
.emoji-popup button:hover { background: var(--surface-subtle); transform: scale(1.2); }

.upload-btn {
    width: 40px; height: 40px; border: none; background: transparent;
    font-size: 18px; cursor: pointer; border-radius: 8px;
    transition: background 0.2s; flex-shrink: 0; display: flex;
    align-items: center; justify-content: center;
    margin-bottom: 8px;
}
.upload-btn:hover { background: var(--surface-subtle); }
.upload-preview {
    display: flex; gap: 8px; flex-wrap: wrap; padding: 0 24px 0 0;
}
.upload-preview-item {
    position: relative; width: 56px; height: 56px; border-radius: 10px;
    overflow: hidden; border: 1px solid var(--border-color); flex-shrink: 0;
}
.upload-preview-item img { width: 100%; height: 100%; object-fit: cover; }
.upload-preview-item.file {
    width: auto; height: 56px; padding: 8px 12px;
    display: flex; align-items: center; gap: 6px; font-size: 12px;
    color: var(--text-sub); background: var(--surface-subtle);
    box-sizing: border-box;
}
.upload-preview-item.loading {
    width: auto; height: 56px; padding: 8px 12px;
    display: flex; align-items: center; gap: 8px; font-size: 12px;
    color: var(--text-sub); background: var(--surface-subtle);
    box-sizing: border-box;
}
.upload-spinner {
    width: 20px; height: 20px; border: 2px solid var(--border-color);
    border-top-color: var(--primary-color); border-radius: 50%;
    animation: spin 0.6s linear infinite; flex-shrink: 0;
}
.upload-preview-remove {
    position: absolute; top: 2px; right: 2px;
    width: 18px; height: 18px; border-radius: 50%;
    background: rgba(0,0,0,0.5); color: #fff; border: none;
    font-size: 12px; cursor: pointer; display: flex;
    align-items: center; justify-content: center; line-height: 1;
}
.upload-preview-item.file .upload-preview-remove, .upload-preview-item.loading .upload-preview-remove { position: static; background: transparent; color: var(--text-sub); width: auto; height: auto; }
.msg-upload { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.msg-upload img { max-width: 200px; border-radius: 10px; cursor: pointer; border: 1px solid var(--border-color); font-size: 13px;}
.msg-upload a {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 16px; border-radius: 10px;
    background: var(--surface-subtle); border: 1px solid var(--border-color);
    color: var(--text-main); font-size: 13px; font-weight: 500;
    text-decoration: none; max-width: 260px;
}
.msg-upload a svg { flex-shrink: 0; }
.msg-upload a:hover { background: var(--border-color); }

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--btn-radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}
.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-ghost {
    background: rgba(79, 70, 229, 0.06);
    color: var(--primary-color);
    border: 1px solid rgba(79, 70, 229, 0.15);
    border-radius: var(--btn-radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}
.btn-ghost:hover {
    background: var(--primary-color);
    color: white;
}

.btn-action {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(79, 70, 229, 0.06);
    color: var(--primary-color);
    border: 1px solid rgba(79, 70, 229, 0.15);
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-family: inherit;
}
.btn-action:hover { background: var(--primary-color); color: white; }
.btn-action.primary { background: var(--primary-color); color: white; }
.btn-action.primary:hover { background: var(--primary-hover); }

.btn-wechat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 8px 16px;
    background: rgba(7, 193, 96, 0.06);
    color: #07C160;
    border: 1px solid rgba(7, 193, 96, 0.2);
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.3s;
}
.btn-wechat:hover { background: #07C160; color: #fff; }

.btn-add {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.3s;
}
.btn-add:hover { background: var(--primary-hover); }

/* QR code */
.qrcode-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}
.qrcode-placeholder {
    width: 200px;
    height: 200px;
    background: #F8FAFC;
    border-radius: 20px;
    border: 2px dashed var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-sub);
}
.qrcode-placeholder svg { color: var(--text-sub); opacity: 0.5; }
.qrcode-placeholder span { font-size: 13px; font-weight: 500; }
.qrcode-tip { font-size: 14px; color: var(--text-sub); font-weight: 500; }

/* Success icon animation */
.success-icon {
    animation: successScale 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.success-icon .check-path {
    stroke-dasharray: 24;
    stroke-dashoffset: 24;
    animation: checkDraw 0.5s cubic-bezier(0.16, 1, 0.3, 1) 0.2s forwards;
}

/* Tag pill */
.tag-pill {
    border-radius: 100px;
    font-weight: 600;
    background: rgba(79, 70, 229, 0.06);
    color: var(--primary-color);
}

/* Toast notifications */
.toast-container {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    padding: 12px 24px;
    border-radius: var(--btn-radius);
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
    pointer-events: auto;
    max-width: 360px;
    text-align: center;
}
.toast.error { background: var(--danger-color); }
.toast.success { background: var(--success-color); }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(-16px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Responsive */
@media (max-width: 920px) {
    .top-nav { padding: 0 20px; margin: 0 auto 10px;}
    .logo-char { height: 50px; margin-bottom: -12px; margin-right: 10px;}
    .logo { font-size: 20px; }
    .chat-sidebar { display: none; }
    .msg { max-width: 90%; }
    .chat-messages { padding: 16px; }
    .chat-input-area { padding: 12px 16px; }
    .chat-card { max-height: calc(100vh - 100px); }
}

@media (max-width: 480px) {
    dialog {
        width: calc(100% - 24px);
        margin: auto 12px;
        border-radius: 24px;
    }
    .dialog-content { padding: 30px 20px; }
}

@media (max-width: 768px) {
    body { padding: 10px; }
}
