/* assets/css/style.css */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap');

:root {
    --bg-color: #fdf6f8; /* 温馨的淡粉色背景 */
    --primary-color: #ff8fab; /* 活泼的粉色 */
    --secondary-color: #f3d4d4;
    --text-color: #5c5c5c;
    --white-color: #ffffff;
    --ai-bubble-bg: #e9e9eb;
    --user-bubble-bg: #ff8fab;
    --user-bubble-text: #ffffff;
    --border-radius-sm: 8px;
    --border-radius-md: 16px;
}

body {
    font-family: 'Noto Sans SC', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    font-size: 16px;
    line-height: 1.6;
}

/* --- 登录/注册页面样式 --- */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 20px;
    box-sizing: border-box;
}

.auth-box {
    background: var(--white-color);
    padding: 30px 40px;
    border-radius: var(--border-radius-md);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.auth-box h2 {
    color: var(--primary-color);
    margin-bottom: 25px;
}

.input-group {
    margin-bottom: 20px;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.input-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: var(--border-radius-sm);
    box-sizing: border-box;
    transition: border-color 0.3s;
}

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

.auth-box button {
    width: 100%;
    padding: 12px;
    background-color: var(--primary-color);
    color: var(--white-color);
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 1em;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.3s;
}

.auth-box button:hover {
    background-color: #ff749c;
}

.switch-auth {
    margin-top: 20px;
    font-size: 0.9em;
}

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

.message-box {
    margin-top: 15px;
    font-size: 0.9em;
    min-height: 20px;
}

/* --- 聊天界面样式 --- */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 800px;
    margin: 0 auto;
    background-color: var(--white-color);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.05);
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    background-color: var(--white-color);
    border-bottom: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: cover;
}

.character-name {
    margin-left: 15px;
    font-size: 1.2em;
    font-weight: 700;
    color: var(--text-color);
}

.chat-window {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: var(--bg-color);
}

.message-row {
    display: flex;
    margin-bottom: 20px;
    max-width: 85%;
}

.message-content {
    display: flex;
    flex-direction: column;
}

.message-bubble {
    padding: 10px 15px;
    border-radius: var(--border-radius-md);
    word-break: break-word;
}

.message-bubble p {
    margin: 0;
}

.message-bubble em { /* Markdown 斜体 */
    color: #888;
    font-style: italic;
}

/* AI消息 (左侧) */
.ai-message {
    justify-content: flex-start;
}

.ai-message .avatar {
    margin-right: 10px;
}

.ai-message .message-bubble {
    background-color: var(--ai-bubble-bg);
    color: var(--text-color);
    border-top-left-radius: var(--border-radius-sm);
}

/* 用户消息 (右侧) */
.user-message {
    justify-content: flex-end;
    margin-left: auto; /* 关键：推动到右侧 */
}

.user-message .message-bubble {
    background-color: var(--user-bubble-bg);
    color: var(--user-bubble-text);
    border-top-right-radius: var(--border-radius-sm);
}

/* 输入区域 */
.chat-input-area {
    display: flex;
    align-items: flex-end;
    padding: 15px;
    background-color: var(--white-color);
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
    gap: 10px;
}

.input-wrapper {
    flex-grow: 1;
    display: flex;
}

.input-wrapper textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: var(--border-radius-md);
    resize: none;
    font-family: inherit;
    font-size: 1em;
    line-height: 1.5;
    max-height: 120px; /* 限制最大高度 */
    overflow-y: auto;
    transition: border-color 0.3s;
}

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

.action-input-wrapper textarea {
    font-size: 0.9em;
    background-color: #f9f9f9;
}

#send-btn {
    padding: 10px 20px;
    background-color: var(--primary-color);
    color: var(--white-color);
    border: none;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.3s;
    flex-shrink: 0;
}

#send-btn:hover {
    background-color: #ff749c;
}

/* 手机端适配 */
@media (max-width: 600px) {
    .auth-box {
        padding: 20px;
    }
    .chat-header {
        padding: 10px 15px;
    }
    .avatar {
        width: 40px;
        height: 40px;
    }
    .character-name {
        font-size: 1.1em;
    }
    .chat-window {
        padding: 10px;
    }
    .message-row {
        max-width: 90%;
    }
    .chat-input-area {
        padding: 10px;
        flex-wrap: wrap; /* 允许换行 */
    }
    .input-wrapper {
        width: 100%;
    }
    #send-btn {
        width: 100%;
        margin-top: 5px;
    }
}

/* --- chat.php 额外样式 --- */
.chat-header {
    position: relative;
}
.back-btn {
    color: #a0a0a0;
    margin-right: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s;
}
.back-btn:hover {
    color: var(--primary-color);
}
.header-info {
    display: flex;
    flex-direction: column;
}
.character-name {
    margin: 0;
    line-height: 1.2;
}
.show-story-btn {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    font-size: 0.8em;
    padding: 0;
    text-align: left;
}
.show-story-btn:hover {
    color: var(--primary-color);
}
/* 弹窗样式 */
.modal {
    display: none; 
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4);
}
.modal-content {
    background-color: #fefefe;
    margin: 15% auto;
    padding: 20px 30px;
    border: 1px solid #888;
    width: 80%;
    max-width: 600px;
    border-radius: var(--border-radius-md);
    position: relative;
    animation: fadeIn 0.3s;
}
@keyframes fadeIn {
    from {opacity: 0; transform: scale(0.95);}
    to {opacity: 1; transform: scale(1);}
}
.close-btn {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
}
.close-btn:hover,
.close-btn:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}
/* AI回复中的代码块样式 */
.message-bubble pre {
    background-color: #2d2d2d;
    color: #f8f8f2;
    padding: 1em;
    border-radius: var(--border-radius-sm);
    overflow-x: auto;
}
.message-bubble code {
    font-family: 'Courier New', Courier, monospace;
}

/* 弹窗和编辑按钮样式 */
.modal-content .story-text {
    max-height: 60vh;
    overflow-y: auto;
    line-height: 1.7;
}

.user-message .message-content {
    position: relative;
    display: flex;
    align-items: center;
}

.edit-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    margin-left: 8px;
    opacity: 0; /* 默认隐藏 */
    transition: opacity 0.3s;
    color: var(--primary-color);
}

.user-message:hover .edit-btn {
    opacity: 0.7; /* 鼠标悬浮时显示 */
}
.edit-btn:hover {
    opacity: 1;
}

/* 聊天输入区图标按钮 */
.icon-btn {
    background: none;
    border: 1px solid #ddd;
    color: #aaa;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s;
    flex-shrink: 0;
}
.icon-btn:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}
.icon-btn.active {
    background-color: var(--secondary-color);
    color: var(--primary-color);
    border-color: var(--primary-color);
}
/* 系统消息样式 */
.system-message .message-bubble {
    background-color: transparent;
    color: #999;
    font-style: italic;
    width: 100%;
    text-align: center;
    box-shadow: none;
}
.system-message .message-content {
    width: 100%;
}

/* chat.php header actions */
.chat-header {
    justify-content: space-between; /* 让元素两端对齐 */
}
.header-info {
    flex-grow: 1; /* 让中间部分占据多余空间 */
    margin-left: 15px;
}
.header-actions {
    margin-left: auto; /* 把按钮推到最右边 */
}
.header-actions .icon-btn {
    width: 32px;
    height: 32px;
    color: #aaa;
}