/* ============================================
   即时聊天系统 - 完整样式
   ============================================ */

/* ===== CSS 变量 ===== */
:root {
    --primary: #d4a843;
    --primary-dark: #b8923a;
    --primary-light: #f0d080;
    --background: #1a1a1a;
    --background-light: #2a2a2a;
    --background-lighter: #3a3a3a;
    --text: #e0e0e0;
    --text-secondary: #888888;
    --text-dark: #1a1a1a;
    --border: #3a3a3a;
    --success: #4CAF50;
    --danger: #f44336;
    --warning: #FF9800;
    --shadow: 0 4px 20px rgba(0,0,0,0.3);
    --radius: 12px;
    --transition: all 0.3s ease;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--background); }
::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary-dark); }

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--background);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s;
}

.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--background-lighter);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-overlay p {
    margin-top: 16px;
    color: var(--text-secondary);
}

/* ===== Navbar ===== */
.navbar {
    background: var(--background-light);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 64px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    color: var(--primary);
}

.nav-brand .brand-icon { font-size: 28px; }
.nav-brand .brand-name { color: var(--text); }

.nav-menu {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 8px;
    transition: var(--transition);
    font-size: 14px;
    cursor: pointer;
}

.nav-link:hover {
    color: var(--text);
    background: var(--background-lighter);
}

.nav-link.active {
    color: var(--primary);
    background: rgba(212, 168, 67, 0.1);
}

.nav-link.logout-btn {
    color: var(--danger);
}

.nav-link.logout-btn:hover {
    background: rgba(244, 67, 54, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 16px;
    border-left: 1px solid var(--border);
}

.avatar-small {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    object-fit: cover;
}

.user-name {
    font-size: 14px;
    color: var(--text);
}

/* ===== Container ===== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ===== Pages ===== */
.page {
    display: none;
    animation: fadeIn 0.3s ease;
}

.page.active {
    display: block;
}

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

/* ===== Hero ===== */
.hero {
    text-align: center;
    padding: 80px 20px;
    background: linear-gradient(135deg, rgba(212, 168, 67, 0.1), rgba(184, 146, 58, 0.05));
    border-radius: var(--radius);
    margin-bottom: 40px;
    border: 1px solid rgba(212, 168, 67, 0.05);
}

.hero h1 {
    font-size: 48px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero p {
    font-size: 18px;
    color: var(--text-secondary);
    margin: 20px 0 30px;
}

.hero-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ===== Features ===== */
.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}

.feature-card {
    background: var(--background-light);
    padding: 30px;
    border-radius: var(--radius);
    text-align: center;
    transition: var(--transition);
    border: 1px solid transparent;
}

.feature-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow);
    border-color: rgba(212, 168, 67, 0.1);
}

.feature-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 16px;
}

.feature-card h3 {
    color: var(--primary);
    margin-bottom: 10px;
}

.feature-card p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ===== Buttons ===== */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    font-family: var(--font);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: var(--text-dark);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(212, 168, 67, 0.3);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-outline:hover:not(:disabled) {
    background: var(--primary);
    color: var(--text-dark);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: #d32f2f;
}

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

.btn-send {
    padding: 10px 24px;
    border-radius: 20px;
    font-size: 14px;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: var(--transition);
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--background-lighter);
    color: var(--text);
}

.btn-loader {
    display: none;
}

.btn-loading .btn-text {
    display: none;
}

.btn-loading .btn-loader {
    display: inline-block;
    animation: spin 0.8s linear infinite;
}

/* ===== Auth ===== */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 200px);
    padding: 20px;
}

.auth-card {
    background: var(--background-light);
    padding: 40px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255,255,255,0.03);
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-header h2 {
    color: var(--primary);
    font-size: 28px;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 8px;
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.auth-footer a {
    color: var(--primary);
    text-decoration: none;
    cursor: pointer;
    font-weight: 500;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* ===== Form ===== */
.auth-form {
    width: 100%;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 16px;
    transition: var(--transition);
    font-family: var(--font);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(212, 168, 67, 0.15);
}

.form-input:disabled {
    opacity: 0.6;
}

.form-input.error {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(244, 67, 54, 0.15);
}

.form-hint {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.form-error {
    font-size: 12px;
    color: var(--danger);
    margin-top: 4px;
    display: none;
}

.form-error.show {
    display: block;
}

/* ===== Password Toggle ===== */
.password-wrapper {
    position: relative;
}

.password-wrapper .form-input {
    padding-right: 48px;
}

.password-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 18px;
    padding: 4px;
}

.password-toggle:hover {
    color: var(--text);
}

/* ===== Password Strength ===== */
.password-strength {
    margin-top: 8px;
}

.strength-bar {
    width: 100%;
    height: 4px;
    background: var(--background);
    border-radius: 2px;
    overflow: hidden;
}

.strength-fill {
    height: 100%;
    width: 0%;
    border-radius: 2px;
    transition: width 0.3s ease;
}

.strength-fill.weak { background: var(--danger); width: 33%; }
.strength-fill.medium { background: var(--warning); width: 66%; }
.strength-fill.strong { background: var(--success); width: 100%; }

.strength-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ===== Message ===== */
.message {
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: 8px;
    display: none;
    font-size: 14px;
}

.message.success {
    display: block;
    background: rgba(76, 175, 80, 0.1);
    color: var(--success);
    border: 1px solid var(--success);
}

.message.error {
    display: block;
    background: rgba(244, 67, 54, 0.1);
    color: var(--danger);
    border: 1px solid var(--danger);
}

.message.info {
    display: block;
    background: rgba(33, 150, 243, 0.1);
    color: #2196F3;
    border: 1px solid #2196F3;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    padding: 14px 24px;
    border-radius: 8px;
    background: var(--background-light);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: translateY(100px);
    opacity: 0;
    transition: var(--transition);
    z-index: 200;
    max-width: 400px;
    font-size: 14px;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    border-color: var(--success);
}

.toast.error {
    border-color: var(--danger);
}

.toast.warning {
    border-color: var(--warning);
}

/* ===== Chat ===== */
.chat-container {
    display: flex;
    height: calc(100vh - 160px);
    background: var(--background-light);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

/* Sidebar */
.chat-sidebar {
    width: 320px;
    background: var(--background);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h3 {
    font-size: 18px;
    color: var(--text);
}

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

.search-input {
    width: 100%;
    padding: 10px 16px;
    background: var(--background-light);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
}

.contact-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.contact-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.contact-item:hover {
    background: var(--background-light);
}

.contact-item.active {
    background: rgba(212, 168, 67, 0.1);
}

.contact-item .contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 12px;
    object-fit: cover;
}

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

.contact-item .contact-name {
    font-weight: 500;
    font-size: 14px;
}

.contact-item .contact-last {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.contact-item .contact-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.contact-item .contact-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.contact-item .unread-badge {
    background: var(--primary);
    color: var(--text-dark);
    font-size: 11px;
    font-weight: bold;
    padding: 1px 8px;
    border-radius: 12px;
    min-width: 20px;
    text-align: center;
}

/* Chat Main */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--background);
}

.chat-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--background-light);
}

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

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary);
}

.chat-username {
    font-size: 16px;
    font-weight: 500;
}

.chat-status {
    font-size: 12px;
    color: var(--text-secondary);
    display: block;
}

.chat-status.online { color: var(--success); }
.chat-status.offline { color: var(--text-secondary); }
.chat-status.busy { color: var(--danger); }

.chat-actions {
    display: flex;
    gap: 4px;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.message-item {
    max-width: 70%;
    padding: 10px 16px;
    margin-bottom: 8px;
    border-radius: 12px;
    word-wrap: break-word;
    animation: fadeIn 0.2s ease;
}

.message-item.mine {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: var(--text-dark);
}

.message-item.other {
    align-self: flex-start;
    background: var(--background-lighter);
}

.message-item .message-time {
    font-size: 11px;
    color: var(--text-secondary);
    display: block;
    margin-top: 4px;
}

.message-item.mine .message-time {
    color: rgba(26, 26, 26, 0.6);
}

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

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

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

.chat-input-area {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    align-items: center;
    background: var(--background-light);
}

.chat-input {
    flex: 1;
    padding: 10px 16px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    min-height: 40px;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ===== Profile ===== */
.profile-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 200px);
    padding: 20px;
}

.profile-card {
    background: var(--background-light);
    padding: 40px;
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow);
    text-align: center;
}

.profile-avatar {
    position: relative;
    display: inline-block;
    margin-bottom: 20px;
}

.profile-avatar-img {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid var(--primary);
    object-fit: cover;
}

.btn-avatar-upload {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: var(--primary);
    color: var(--text-dark);
    border: none;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    font-family: var(--font);
}

.btn-avatar-upload:hover {
    background: var(--primary-dark);
}

.profile-info {
    margin: 24px 0;
    text-align: left;
}

.profile-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.profile-item:last-child {
    border-bottom: none;
}

.profile-item label {
    color: var(--text-secondary);
    font-size: 14px;
}

.profile-item span {
    color: var(--text);
    font-size: 14px;
}

.status-badge {
    padding: 2px 12px;
    border-radius: 12px;
    font-size: 12px;
}

.status-badge.online {
    background: rgba(76, 175, 80, 0.2);
    color: var(--success);
}

.status-badge.offline {
    background: rgba(136, 136, 136, 0.2);
    color: var(--text-secondary);
}

.profile-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .nav-brand .brand-name { display: none; }
    .chat-sidebar { width: 60px; min-width: 60px; }
    .chat-sidebar .sidebar-header h3 { display: none; }
    .chat-sidebar .contact-item .contact-info { display: none; }
    .chat-sidebar .contact-item .contact-meta { display: none; }
    .chat-sidebar .search-box { display: none; }
    .chat-sidebar .contact-item { justify-content: center; padding: 12px; }
    .chat-sidebar .contact-item .contact-avatar { margin-right: 0; }
    .hero h1 { font-size: 28px; }
    .auth-card { padding: 24px; margin: 10px; }
    .profile-card { padding: 24px; }
    .features { grid-template-columns: 1fr 1fr; }
    .container { padding: 12px; }
}

@media (max-width: 480px) {
    .nav-menu .nav-link { font-size: 12px; padding: 6px 10px; }
    .chat-container { height: calc(100vh - 120px); border-radius: 0; }
    .features { grid-template-columns: 1fr; }
    .hero { padding: 40px 16px; }
    .toast { right: 16px; left: 16px; bottom: 16px; max-width: none; }
}