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

:root {
    --primary-color: #007aff;
    --bg-color: #000000;
    --sidebar-bg: #1c1c1e;
    --card-bg: #2c2c2e;
    --text-color: #ffffff;
    --text-muted: #8e8e93;
    --border-color: #38383a;
    --hover-color: #3a3a3c;
    --danger-color: #ff453a;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* 侧边栏 */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

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

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

.sidebar-section {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-section h3 {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.sidebar-footer {
    margin-top: auto;
    border-bottom: none;
    border-top: 1px solid var(--border-color);
}

.character-list {
    max-height: calc(100vh - 350px);
    overflow-y: auto;
}

.character-item {
    padding: 12px;
    margin-bottom: 4px;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.15s;
}

.character-item:hover {
    background: var(--hover-color);
}

.character-item.active {
    background: var(--hover-color);
}

.avatar-small {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--border-color);
    flex-shrink: 0;
}

.avatar-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-muted);
    flex-shrink: 0;
}

.character-item-info h4 {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.character-item-info p {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
}

/* 主内容区 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-color);
}

/* 欢迎页 */
.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.welcome-content {
    text-align: center;
}

.welcome-content h2 {
    font-size: 20px;
    font-weight: 400;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.welcome-desc {
    font-size: 14px;
    color: var(--text-muted);
    opacity: 0.7;
}

/* 聊天界面 */
.chat-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

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

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

.character-info img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
}

.character-info h2 {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 2px;
}

.text-muted {
    color: var(--text-muted);
    font-size: 13px;
}

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

/* 聊天消息区 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.message {
    max-width: 70%;
    padding: 8px 14px;
    border-radius: 18px;
    line-height: 1.3;
    font-size: 15px;
    animation: fadeIn 0.2s ease;
    display: inline-block;
    word-wrap: break-word;
    align-self: flex-start;
}

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

.message-assistant {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 6px;
}

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

.message-time {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
    text-align: right;
    opacity: 0.6;
}

/* 输入区 */
.chat-input-area {
    padding: 12px 20px;
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    padding: 10px 16px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--text-color);
    font-size: 15px;
    resize: none;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
    max-height: 120px;
    line-height: 1.4;
}

#messageInput:focus {
    border-color: var(--primary-color);
}

#messageInput::placeholder {
    color: var(--text-muted);
}

.btn-send {
    padding: 10px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: opacity 0.15s;
    white-space: nowrap;
}

.btn-send:hover {
    opacity: 0.9;
}

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

/* 按钮 */
.btn-primary {
    padding: 10px 20px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: opacity 0.15s;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-secondary {
    padding: 10px 20px;
    background: transparent;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s;
}

.btn-secondary:hover {
    background: var(--hover-color);
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 8px 12px;
    text-align: left;
    width: 100%;
    border-radius: 6px;
    font-size: 14px;
    transition: background 0.15s;
}

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

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-color);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

.btn-danger:hover {
    color: var(--danger-color);
}

.btn-block {
    width: 100%;
    margin-bottom: 8px;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

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

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--sidebar-bg);
    border-radius: 12px;
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.2s ease;
}

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

.modal-large {
    max-width: 560px;
}

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

.modal-header h2 {
    font-size: 17px;
    font-weight: 600;
}

.modal-body {
    padding: 24px;
}

/* 表单 */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

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

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

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 14px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
}

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

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group small {
    display: block;
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 12px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
}

/* 加载提示 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-spinner {
    text-align: center;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* 动作和心理活动样式 */
.action-text {
    font-style: italic;
    color: #5ac8fa;
}

.thought-text {
    color: #ff9500;
    font-style: italic;
}

.message-assistant .action-text {
    color: #34c759;
}

.message-assistant .thought-text {
    color: #ff9500;
}

.message div {
    line-height: 1.6;
    word-wrap: break-word;
}

/* 通知提示 */
.notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    background: var(--card-bg);
    color: var(--text-color);
    border-radius: 8px;
    font-size: 13px;
    z-index: 3000;
    animation: fadeIn 0.2s ease;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
}

.notification.hide {
    animation: fadeOut 0.2s ease forwards;
}

@keyframes fadeOut {
    to { opacity: 0; transform: translateX(-50%) translateY(-10px); }
}

/* 响应式 */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        z-index: 100;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.3);
    }

    .sidebar.open {
        left: 0;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .message {
        max-width: 85%;
    }
}

/* 滚动条 */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
