:root {
    --primary: #2563eb;
    --bg: #f3f4f6;
    --sidebar-bg: #1f2937;
    --text-light: #f9fafb;
}

body { margin: 0; font-family: sans-serif; display: flex; height: 100vh; background-color: var(--bg); }
.container { display: flex; width: 100%; }

/* Sidebar */
.sidebar { width: 250px; background-color: var(--sidebar-bg); color: var(--text-light); padding: 20px; display: flex; flex-direction: column; }
.logo { font-size: 1.5rem; font-weight: bold; margin-bottom: 30px; }
.nav-btn { display: block; width: 100%; padding: 12px; text-align: left; background: none; border: none; color: #9ca3af; cursor: pointer; font-size: 1rem; }
.nav-btn:hover, .nav-btn.active { color: white; background-color: #374151; border-radius: 6px; }
.status-panel { margin-top: auto; font-size: 0.8rem; color: #6b7280; }

/* Main Content */
.main-content { flex: 1; padding: 40px; overflow-y: auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.3s; }

/* Forms & Buttons */
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 8px; font-weight: bold; }
input, textarea { width: 100%; padding: 10px; border: 1px solid #d1d5db; border-radius: 6px; font-family: inherit; }
textarea { resize: vertical; }

button { cursor: pointer; padding: 10px 20px; border-radius: 6px; border: none; font-weight: bold; }
.btn-primary { background-color: var(--primary); color: white; }
.btn-magic { background-color: #7c3aed; color: white; } /* 紫色代表 AI */
.btn-save { background-color: #059669; color: white; } /* 绿色代表保存 */

/* Cards Grid */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; margin-top: 20px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* 新增样式 */

.box {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    border: 1px solid #e5e7eb;
}

.form-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.hint {
    font-size: 0.85rem;
    color: #6b7280;
    margin-bottom: 10px;
}

/* 角色卡片样式 */
.char-card {
    background: white;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.char-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
    padding-bottom: 8px;
}

.char-role-badge {
    font-size: 0.75rem;
    background: #e0e7ff;
    color: #4338ca;
    padding: 2px 6px;
    border-radius: 4px;
}

.char-editor {
    flex: 1;
    font-size: 0.9rem;
    min-height: 150px;
}

/* Modal 弹窗样式 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* 半透明黑色背景 */
    display: flex;
    justify-content: center; /* 水平居中 */
    align-items: center;     /* 垂直居中 */
    z-index: 1000;
}

.modal-box {
    background: white;
    padding: 30px;
    border-radius: 10px;
    width: 500px;
    max-width: 90%;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* =========================================
   📱 移动端适配 (管理界面专用)
   ========================================= */

/* 默认隐藏移动端头部 */
.mobile-header, .sidebar-overlay {
    display: none;
}

/* =========================================
   📱 移动端适配修复版 (覆盖 style.css 底部)
   ========================================= */

/* 默认隐藏移动端头部和遮罩 */
.mobile-header, .sidebar-overlay {
    display: none;
}

/* 当屏幕宽度小于 768px 时触发 */
@media screen and (max-width: 768px) {

    /* 1. 核心布局修复：取消 Flex 横向排列 */
    body {
        overflow-x: hidden; /* 防止横向滚动条 */
    }

    .container {
        display: block !important; /* 强制变为块级布局，上下排列 */
        width: 100%;
        height: auto;
        padding-top: 50px; /* 给顶部的 mobile-header 留出位置 */
    }

    /* 2. 移动端顶部导航条 */
    .mobile-header {
        display: flex;
        align-items: center;
        background: #1f2937;
        color: white;
        padding: 0 15px;
        height: 50px;
        position: fixed; /* 固定在顶部 */
        top: 0; left: 0; right: 0;
        z-index: 200; /* 层级最高 */
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    }

    .hamburger-btn {
        background: none;
        border: none;
        color: white;
        font-size: 1.8rem;
        cursor: pointer;
        padding: 0 15px 0 0;
        margin: 0;
    }

    /* 3. 侧边栏修复：使用百分比位移，彻底消除黑边 */
    .sidebar {
        position: fixed !important;
        top: 0;
        left: 0; /* 基准点设为左侧 0 */
        width: 260px !important;
        height: 100vh;
        z-index: 300; /* 保证在最上层 */

        /* 关键修改：使用 -100% 保证完全移出屏幕，不受 padding 影响 */
        transform: translateX(-100%);
        transition: transform 0.3s ease;

        /* 确保宽度包含 padding，防止撑大 */
        box-sizing: border-box;

        /* 恢复布局 */
        display: flex;
        flex-direction: column;
        background-color: #1f2937; /* 确保背景色不透明 */
    }

    /* 激活状态：滑回屏幕 (位移归零) */
    .sidebar.active {
        transform: translateX(0);
        box-shadow: 5px 0 15px rgba(0,0,0,0.3); /* 加个阴影，更有层次感 */
    }

    /* 隐藏侧边栏里不必要的 Logo (因为顶部栏有了) */
    .sidebar .logo {
        display: none;
    }

    /* 4. 右侧内容区适配 */
    .main-content {
        width: 100% !important;
        padding: 15px !important;
        margin: 0 !important;
        height: auto;
        overflow-y: visible; /* 让 body 滚动，而不是 main-content 滚动 */
    }

    /* 5. 遮罩层 */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 250; /* 在 sidebar 之下，header 之上 */
        backdrop-filter: blur(2px);
    }
    .sidebar-overlay.active {
        display: block;
    }

    /* 6. 表单元素适配 */
    .form-row {
        flex-direction: column;
    }
    .form-row input, .form-row button, .form-row select {
        width: 100% !important;
        margin-bottom: 10px;
    }

    /* 7. 弹窗适配 */
    .modal-box {
        width: 90% !important;
        margin: auto;
    }
}

/* --- 文本截断优化 --- */

/* 限制显示 3 行，多余显示省略号 */
.text-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;   /* 限制行数 */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.5;
    max-height: 4.5em; /* 1.5 * 3 = 4.5 兜底高度 */
    color: #666;
    font-size: 0.85rem;
    margin-top: 4px;
}

/* 核心梗概引用区 (工作台顶部) */
.core-story-box {
    background: #fdf2f8; /* 淡淡的粉色背景，区分于剧情点 */
    border: 1px dashed #f472b6;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 15px;
    font-size: 0.9rem;
    color: #374151;
    max-height: 150px;
    overflow-y: auto; /* 内容太多时内部滚动 */
    white-space: pre-wrap; /* 保留换行符 */
}