/* ===== 全局样式 ===== */
:root {
    --primary: #2d6a4f;
    --primary-light: #52b788;
    --primary-dark: #1b4332;
    --accent: #d4a373;
    --bg: #f5f3f0;
    --bg-card: #ffffff;
    --text: #1a1a1a;
    --text-light: #6c757d;
    --border: #dee2e6;
    --danger: #e63946;
    --warning: #f4a261;
    --success: #2a9d8f;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 12px;
}

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

body {
    font-family: 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

[dir="rtl"] { direction: rtl; }
[dir="ltr"] { direction: ltr; }

/* ===== 导航栏 ===== */
.navbar {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: white;
    padding: 0 20px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2rem;
    font-weight: 700;
}

.navbar-brand .logo {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.token-badge {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.token-badge .token-icon { font-size: 1rem; }
.token-badge .token-count { font-weight: 700; }

/* ===== 主容器 ===== */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.main-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
    height: calc(100vh - 100px);
}

@media (max-width: 900px) {
    .main-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
}

/* ===== 虚拟人区域 ===== */
.virtual-human-panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

.avatar-display {
    flex: 1;
    background: linear-gradient(180deg, #1a3a2e 0%, #2d6a4f 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 300px;
    color: white;
}

.avatar-circle {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #c9956b);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 5rem;
    box-shadow: 0 0 40px rgba(212,163,115,0.4);
    animation: pulse 3s ease-in-out infinite;
    margin-bottom: 20px;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 40px rgba(212,163,115,0.4); }
    50% { box-shadow: 0 0 60px rgba(212,163,115,0.6); }
}

.avatar-name {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 5px;
}

.avatar-title {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-bottom: 15px;
}

.avatar-status {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.1);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* 虚拟人控制按钮 */
.avatar-controls {
    padding: 15px;
    display: flex;
    gap: 10px;
    justify-content: center;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
}

.ctrl-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.ctrl-btn:hover { background: var(--primary-dark); transform: scale(1.1); }
.ctrl-btn.active { background: var(--danger); }
.ctrl-btn.video-btn { background: var(--accent); }

/* ===== 聊天面板 ===== */
.chat-panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    padding: 15px 20px;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header h3 { font-size: 1rem; font-weight: 600; }

.chat-header .lang-switch {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
}

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

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.92rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

[dir="rtl"] .message.user {
    border-bottom-right-radius: 16px;
    border-bottom-left-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: #f0f7f4;
    color: var(--text);
    border: 1px solid #d4e4dc;
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .message.assistant {
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 4px;
}

.message .translation {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0,0,0,0.1);
    font-size: 0.85rem;
    opacity: 0.8;
    font-style: italic;
}

.message .diagnosis-box {
    margin-top: 10px;
    padding: 10px;
    background: rgba(45,106,79,0.08);
    border-radius: 8px;
    border-right: 3px solid var(--primary);
}

[dir="rtl"] .message .diagnosis-box {
    border-right: none;
    border-left: 3px solid var(--primary);
}

.typing-indicator {
    align-self: flex-start;
    padding: 12px 20px;
    background: #f0f7f4;
    border-radius: 16px;
    display: none;
}

.typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-light);
    margin: 0 2px;
    animation: bounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

/* 聊天输入区 */
.chat-input-area {
    padding: 15px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}

.chat-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: 10px 16px;
    border: 2px solid var(--border);
    border-radius: 24px;
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

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

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s;
}

.send-btn:hover { background: var(--primary-dark); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.upload-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: white;
    color: var(--primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s;
}

.upload-btn:hover { border-color: var(--primary-light); background: #f0f7f4; }

/* ===== 侧边栏 ===== */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* TOKEN 卡片 */
.token-card {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: white;
}

.token-card h3 { color: white; }

.token-balance {
    font-size: 2rem;
    font-weight: 700;
    margin: 10px 0;
}

.token-balance .unit { font-size: 0.9rem; opacity: 0.7; font-weight: 400; }

.token-progress {
    height: 6px;
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
    overflow: hidden;
    margin: 10px 0;
}

.token-progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.5s;
}

.token-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: #b88a5f; }
.btn-outline { background: transparent; border: 1px solid rgba(255,255,255,0.4); color: white; }
.btn-outline:hover { background: rgba(255,255,255,0.1); }

/* 望诊上传 */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 25px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.upload-area:hover {
    border-color: var(--primary-light);
    background: #f0f7f4;
}

.upload-area .upload-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.upload-area p { font-size: 0.85rem; color: var(--text-light); }

.image-preview {
    width: 100%;
    max-height: 150px;
    object-fit: cover;
    border-radius: 8px;
    margin-top: 10px;
}

.analysis-result {
    margin-top: 12px;
    padding: 12px;
    background: #f0f7f4;
    border-radius: 8px;
    font-size: 0.85rem;
}

.analysis-result h4 {
    color: var(--primary-dark);
    margin-bottom: 6px;
    font-size: 0.9rem;
}

/* 问诊历史 */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.history-item:hover {
    border-color: var(--primary-light);
    background: #f0f7f4;
}

.history-item .title { font-size: 0.88rem; font-weight: 500; }
.history-item .meta { font-size: 0.78rem; color: var(--text-light); margin-top: 3px; }

/* ===== 登录页 ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    padding: 20px;
}

.login-box {
    background: white;
    border-radius: 20px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.login-box h1 {
    text-align: center;
    color: var(--primary-dark);
    margin-bottom: 8px;
    font-size: 1.5rem;
}

.login-box .subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 30px;
    font-size: 0.9rem;
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text);
}

.form-group input, .form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-group input:focus, .form-group select:focus { border-color: var(--primary-light); }

.btn-full {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

.login-toggle {
    text-align: center;
    margin-top: 20px;
    font-size: 0.88rem;
    color: var(--text-light);
}

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

/* ===== 管理后台 ===== */
.admin-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.sidebar-menu {
    background: var(--primary-dark);
    color: white;
    padding: 20px 0;
}

.sidebar-menu .menu-header {
    padding: 0 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 15px;
}

.sidebar-menu .menu-header h2 { font-size: 1.1rem; }

.sidebar-menu .menu-item {
    padding: 12px 20px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    border-right: 3px solid transparent;
}

[dir="rtl"] .sidebar-menu .menu-item {
    border-right: none;
    border-left: 3px solid transparent;
}

.sidebar-menu .menu-item:hover { background: rgba(255,255,255,0.1); }
.sidebar-menu .menu-item.active { background: rgba(255,255,255,0.15); border-color: var(--accent); }

.admin-content {
    padding: 30px;
    overflow-y: auto;
}

.admin-content h1 { font-size: 1.5rem; margin-bottom: 20px; color: var(--primary-dark); }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.stat-card .stat-label { font-size: 0.82rem; color: var(--text-light); margin-bottom: 8px; }
.stat-card .stat-value { font-size: 1.8rem; font-weight: 700; color: var(--primary-dark); }
.stat-card .stat-icon { font-size: 1.5rem; margin-bottom: 8px; }

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

th, td {
    padding: 12px 16px;
    text-align: right;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}

[dir="ltr"] th, [dir="ltr"] td { text-align: left; }

th { background: var(--bg); font-weight: 600; color: var(--primary-dark); }
tr:hover { background: #f8f9fa; }

/* ===== 视频工作台 ===== */
.studio-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    padding: 20px;
}

.studio-panel {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.material-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    margin-top: 15px;
}

.material-item {
    aspect-ratio: 9/16;
    background: var(--bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: var(--text-light);
    position: relative;
    overflow: hidden;
}

.material-item video, .material-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ===== 通知 ===== */
.toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-dark);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 9999;
    font-size: 0.9rem;
    display: none;
}

.toast.show { display: block; animation: slideDown 0.3s; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

@keyframes slideDown {
    from { transform: translate(-50%, -20px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

/* ===== 加载动画 ===== */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .main-layout { grid-template-columns: 1fr; }
    .admin-layout { grid-template-columns: 1fr; }
    .sidebar-menu { display: none; }
    .studio-layout { grid-template-columns: 1fr; }
}
