/* ============================================================
   小说人物关系管理器 — PHP 版本样式
   ============================================================ */

/* --- 基础重置 --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: #f5f0e8;
    color: #2d1f0e;
    line-height: 1.6;
    min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; }
ul, ol { list-style: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* --- 布局 --- */
.app-layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 200px;
    background: linear-gradient(180deg, #1a1205 0%, #2d1f0e 100%);
    color: #c9a959;
    display: flex;
    flex-direction: column;
    padding: 20px 12px;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.3s;
    overflow-y: auto;
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 32px; padding-left: 8px; }
.sidebar-logo-icon { font-size: 24px; flex-shrink: 0; }
.sidebar-logo-text { font-size: 16px; font-weight: 700; color: #c9a959; white-space: nowrap; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-link {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 12px;
    border-radius: 8px;
    color: #8b7355;
    transition: all 0.2s;
    font-size: 14px;
    white-space: nowrap;
}
.sidebar-link:hover { background: rgba(201, 169, 89, 0.15); color: #c9a959; }
.sidebar-link.active { color: #c9a959; background: rgba(201, 169, 89, 0.15); border-left: 3px solid #c9a959; }
.sidebar-link-icon { font-size: 18px; flex-shrink: 0; width: 24px; text-align: center; }
.sidebar-link-text { font-size: 14px; white-space: nowrap; }
.sidebar-footer { margin-top: auto; padding-top: 16px; padding-left: 8px; }
.sidebar-footer small { font-size: 11px; color: #5a4020; display: block; line-height: 1.4; }
.main-content { margin-left: 200px; flex: 1; padding: 24px; max-width: 1200px; width: calc(100% - 200px); }
.mobile-menu-btn { display: none; position: fixed; top: 8px; left: 8px; z-index: 200;
    background: #2d1f0e; color: #c9a959; border: none; width: 40px; height: 40px;
    border-radius: 8px; font-size: 20px; }

/* --- 响应式 --- */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; width: 100%; padding: 64px 12px 24px; }
    .mobile-menu-btn { display: flex; align-items: center; justify-content: center; }
    .card-grid { grid-template-columns: 1fr !important; }
}

/* --- 页面标题 --- */
.page-header { margin-bottom: 24px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.page-title { font-size: 24px; font-weight: 700; color: #2d1f0e; }
.page-subtitle { font-size: 14px; color: #8b7355; margin-top: 4px; }

/* --- 按钮 --- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border: none; border-radius: 8px;
    font-size: 14px; font-weight: 500;
    transition: all 0.2s;
}
.btn-primary { background: #c9a959; color: #1a1205; }
.btn-primary:hover { background: #b89330; }
.btn-danger { background: #dc3545; color: #fff; }
.btn-danger:hover { background: #c82333; }
.btn-outline { background: transparent; border: 1px solid #c9a959; color: #c9a959; }
.btn-outline:hover { background: rgba(201, 169, 89, 0.1); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- 卡片 --- */
.card-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 1024px) { .card-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px) { .card-grid { grid-template-columns: 1fr; } }

.card {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    transition: all 0.2s;
}
.card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.12); transform: translateY(-2px); }
.card-img-wrap { position: relative; height: 200px; overflow: hidden; background: linear-gradient(135deg, #2d1f0e, #5a4020); }
.card-img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.card-img-overlay {
    position: absolute; bottom: 0; left: 0; right: 0;
    padding: 20px 16px 12px;
    background: linear-gradient(transparent, rgba(0,0,0,0.75));
    color: #fff;
}
.card-name { font-size: 18px; font-weight: 700; }
.card-meta { font-size: 12px; opacity: 0.85; margin-top: 2px; }
.card-body { padding: 12px 16px 16px; }
.card-text { font-size: 13px; color: #8b7355; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-footer { padding: 0 16px 16px; display: flex; justify-content: space-between; align-items: center; }
.card-edit-btn {
    position: absolute; top: 8px; right: 8px;
    background: rgba(255,255,255,0.9); border: none;
    width: 32px; height: 32px; border-radius: 50%;
    display: none; align-items: center; justify-content: center;
    font-size: 14px; color: #2d1f0e;
}
.card:hover .card-edit-btn { display: flex; }

/* --- 详情页头部 --- */
.detail-header {
    background: linear-gradient(135deg, #2d1f0e, #5a4020);
    border-radius: 12px; padding: 24px; margin-bottom: 24px;
    display: flex; gap: 24px; align-items: flex-start;
    position: relative;
}
.detail-avatar { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; border: 3px solid #c9a959; flex-shrink: 0; }
.detail-info { color: #f5f0e8; flex: 1; }
.detail-name { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
.detail-tags { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.detail-tag {
    font-size: 12px; padding: 2px 10px; border-radius: 12px;
    background: rgba(255,255,255,0.15); color: #e0d5c0;
}
.role-tag { font-weight: 600; }

/* --- 角色定位颜色 --- */
.role-main { background: #e67e22; color: #fff; }
.role-villain { background: #e74c3c; color: #fff; }
.role-support { background: #3498db; color: #fff; }
.role-extra { background: #95a5a6; color: #fff; }
.role-other { background: #7f8c8d; color: #fff; }

/* --- 信息区块 --- */
.section { margin-bottom: 24px; }
.section-title { font-size: 18px; font-weight: 600; margin-bottom: 12px; color: #2d1f0e; padding-bottom: 8px; border-bottom: 2px solid #c9a959; }
.info-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.info-item { }
.info-label { font-size: 12px; color: #8b7355; }
.info-value { font-size: 14px; color: #2d1f0e; }

/* --- 关系/事件列表 --- */
.item-list { display: flex; flex-direction: column; gap: 12px; }
.item-card {
    background: #fff; border-radius: 8px; padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    display: flex; align-items: center; gap: 12px;
}
.item-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.item-avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; }
.item-info { flex: 1; }
.item-name { font-weight: 600; font-size: 14px; }
.item-relation { font-size: 12px; color: #c9a959; }
.item-meta { font-size: 12px; color: #8b7355; }

/* --- 表单 --- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: #5a4020; margin-bottom: 4px; }
.form-input, .form-select, .form-textarea {
    width: 100%; padding: 8px 12px;
    border: 1px solid #d4c5a9; border-radius: 8px;
    background: #fff; color: #2d1f0e;
    font-size: 14px; transition: border-color 0.2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none; border-color: #c9a959; box-shadow: 0 0 0 3px rgba(201,169,89,0.15);
}
.form-textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }

/* --- 模态框 --- */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 1000;
    align-items: center; justify-content: center;
    padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
    background: #fff; border-radius: 12px;
    width: 100%; max-width: 600px; max-height: 85vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #f0e8d5;
    display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 18px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 20px; color: #8b7355; padding: 4px; }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid #f0e8d5; display: flex; gap: 8px; justify-content: flex-end; }

/* --- 搜索栏 --- */
.search-bar { margin-bottom: 20px; }
.search-input {
    width: 100%; max-width: 400px; padding: 10px 16px;
    border: 1px solid #d4c5a9; border-radius: 8px;
    background: #fff; font-size: 14px;
}
.search-input:focus { outline: none; border-color: #c9a959; }

/* --- 时间线 --- */
.timeline { position: relative; padding-left: 32px; }
.timeline::before {
    content: ''; position: absolute; left: 11px; top: 0; bottom: 0;
    width: 2px; background: #c9a959;
}
.timeline-item { position: relative; margin-bottom: 24px; }
.timeline-dot {
    position: absolute; left: -27px; top: 20px;
    width: 12px; height: 12px; border-radius: 50%;
    background: #c9a959; border: 2px solid #fff; box-shadow: 0 0 0 2px #c9a959;
}
.timeline-content {
    background: #fff; border-radius: 8px; padding: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.timeline-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.timeline-time { font-size: 12px; color: #8b7355; margin-bottom: 6px; }
.timeline-desc { font-size: 13px; color: #5a4020; }
.timeline-chars { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.timeline-char-tag { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #f0e8d5; color: #5a4020; }
.timeline-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* --- 徽章 --- */
.badge {
    font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 500;
    display: inline-block;
}
.badge-ai { background: #e8f4fd; color: #2b7de9; }
.badge-closed { background: #e6f4ea; color: #1e8e3e; }
.badge-deduced { background: #fef7e0; color: #b89330; }

/* --- 空状态 --- */
.empty-state {
    text-align: center; padding: 60px 20px; color: #8b7355;
}
.empty-state-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state-title { font-size: 18px; font-weight: 600; margin-bottom: 8px; color: #2d1f0e; }
.empty-state-desc { font-size: 14px; margin-bottom: 20px; }

/* --- Toast --- */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
    padding: 12px 20px; border-radius: 8px; color: #fff; font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transform: translateX(120%); opacity: 0; transition: all 0.3s;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast-success { background: #1e8e3e; }
.toast-error { background: #dc3545; }
.toast-info { background: #2b7de9; }

/* --- 数据管理页 --- */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 32px; }
.stat-card {
    background: #fff; border-radius: 12px; padding: 20px;
    text-align: center; box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.stat-number { font-size: 32px; font-weight: 700; color: #c9a959; }
.stat-label { font-size: 14px; color: #8b7355; margin-top: 4px; }
.settings-section {
    background: #fff; border-radius: 12px; padding: 20px; margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.settings-section-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }

/* --- D3 图谱容器 --- */
.graph-container { position: relative; background: #faf8f3; border-radius: 12px; height: 70vh; border: 1px solid #e0d5c0; overflow: hidden; }
.graph-legend { position: absolute; bottom: 16px; left: 16px; background: rgba(255,255,255,0.9); border-radius: 8px; padding: 12px; font-size: 12px; }
.graph-legend-item { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.graph-legend-dot { width: 12px; height: 12px; border-radius: 50%; }
.graph-tools { position: absolute; bottom: 16px; right: 16px; display: flex; gap: 8px; }
.graph-tool-btn {
    width: 36px; height: 36px; border-radius: 50%;
    background: #fff; border: 1px solid #d4c5a9;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; color: #5a4020;
}
.graph-tool-btn:hover { background: #f0e8d5; }

/* --- AI 结果区域 --- */
.ai-result {
    background: #faf8f3; border: 1px solid #e0d5c0; border-radius: 8px;
    padding: 16px; margin-top: 16px; max-height: 400px; overflow-y: auto;
    white-space: pre-wrap; font-size: 13px; line-height: 1.8;
}
.ai-story-title { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 12px; }
.ai-story-meta { text-align: center; font-size: 12px; color: #8b7355; margin-bottom: 20px; }

/* --- 展开/收起 --- */
.collapsible-header {
    display: flex; align-items: center; justify-content: space-between;
    cursor: pointer; user-select: none;
}
.collapsible-content { display: none; }
.collapsible-content.show { display: block; }

/* --- 技能表 --- */
.skill-item {
    display: flex; gap: 8px; align-items: center; margin-top: 8px;
    padding: 8px 12px; background: #faf8f3; border-radius: 6px;
}
.skill-name { font-weight: 600; font-size: 14px; }
.skill-level { font-size: 12px; color: #c9a959; }
.skill-desc { font-size: 12px; color: #8b7355; }

/* --- 消息框 --- */
.alert {
    padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px;
}
.alert-info { background: #e8f4fd; color: #1a6dd4; border: 1px solid #b8d8f8; }
.alert-success { background: #e6f4ea; color: #1e8e3e; border: 1px solid #b7e1c2; }
.alert-error { background: #fdecea; color: #c62828; border: 1px solid #f5c6cb; }

/* --- 工具类 --- */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mb-4 { margin-bottom: 32px; }
.mt-4 { margin-top: 32px; }
.text-center { text-align: center; }

/* --- 卡片头部 --- */
.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid #e8dfd0;
}
.card-header h3 { font-size: 16px; font-weight: 600; color: #2d1f0e; margin: 0; }

/* --- 表格信息提示 --- */
.form-info {
    background: #fef7e0; border: 1px solid #f0d878; border-radius: 8px;
    padding: 12px 16px; font-size: 13px; color: #5a4020; line-height: 1.7;
}
.form-info ul { margin: 4px 0 0 16px; }
.form-info ul li { margin-bottom: 2px; }

/* --- 确认行 --- */
.confirm-row { transition: background 0.15s; }
.confirm-row:hover { background: #faf7f0; }
.confirm-row input[type="checkbox"] {
    width: 18px; height: 18px; cursor: pointer; accent-color: #c9a959;
}
.text-muted { color: #8b7355; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none; }
.w-full { width: 100%; }

/* --- D3 SVG --- */
.graph-container svg { width: 100%; height: 100%; }

/* --- 图谱加载进度条 --- */
.graph-loading {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(250,248,243,0.85);
    display: flex; align-items: center; justify-content: center;
    z-index: 50;
    transition: opacity 0.4s;
}
.graph-loading-inner {
    background: #fff; border-radius: 12px; padding: 32px 48px;
    text-align: center; box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    min-width: 260px;
}
.graph-loading-title {
    font-size: 15px; font-weight: 600; color: #2d1f0e; margin-bottom: 16px;
}
.graph-progress-track {
    width: 100%; height: 8px; background: #e0d5c0; border-radius: 4px; overflow: hidden;
}
.graph-progress-fill {
    height: 100%; background: linear-gradient(90deg, #c9a959, #e6c873);
    border-radius: 4px; width: 0%;
    transition: width 0.2s ease;
}
.graph-progress-text {
    font-size: 13px; color: #8b7355; margin-top: 8px;
}
.graph-loading.fade-out { opacity: 0; pointer-events: none; }

/* --- 人物显示设置面板 --- */
.visibility-toggle {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; background: #fff; border: 1px solid #d4c5a9;
    border-radius: 8px; font-size: 13px; color: #5a4020; cursor: pointer;
    transition: background 0.15s;
}
.visibility-toggle:hover { background: #f0e8d5; }
.visibility-toggle .arrow { font-size: 10px; transition: transform 0.2s; }
.visibility-toggle.open .arrow { transform: rotate(180deg); }

.visibility-panel {
    background: #fff; border: 1px solid #e0d5c0; border-radius: 10px;
    margin-top: 8px; padding: 14px 16px;
    max-height: 320px; overflow-y: auto;
}
.visibility-panel-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid #f0e8d5;
}
.visibility-panel-header span { font-size: 13px; font-weight: 600; color: #2d1f0e; }
.visibility-panel-header .link-btn {
    font-size: 12px; color: #c9a959; cursor: pointer; background: none; border: none;
}
.visibility-panel-header .link-btn:hover { text-decoration: underline; }

.vis-char-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px; border-radius: 6px; cursor: pointer;
    font-size: 13px; color: #5a4020;
    transition: background 0.1s;
}
.vis-char-item:hover { background: #faf7f0; }
.vis-char-item.hidden-char { opacity: 0.45; }
.vis-char-item input[type="checkbox"] {
    width: 16px; height: 16px; cursor: pointer; accent-color: #c9a959; flex-shrink: 0;
}
.vis-char-dot {
    width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}

/* --- 页面加载动画 --- */
.page-loading {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-height: 300px; color: #8b7355; gap: 16px;
}
.page-loading-spinner {
    width: 36px; height: 36px;
    border: 3px solid #e0d5c0;
    border-top-color: #c9a959;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
