/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif; font-size: 14px; color: #333; background: #f0f2f5; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; font-size: 14px; }

/* ===== Layout ===== */
.layout { display: flex; height: 100vh; overflow: hidden; }
/* app-layout: 所有 admin 页面用的外层容器 */
.app-layout { display: flex; height: 100vh; overflow: hidden; }
/* main-content: sidebar 右侧主区域 */
.main-content { flex: 1; display: flex; flex-direction: column; overflow-y: auto; padding: 24px; background: #f0f2f5; gap: 16px; }

/* Sidebar */
.sidebar { width: 220px; background: #001529; color: #a6adb4; flex-shrink: 0; display: flex; flex-direction: column; overflow-y: auto; }
.sidebar-logo { padding: 20px 16px; color: #fff; font-size: 16px; font-weight: 700; border-bottom: 1px solid #0d2137; display: flex; align-items: center; gap: 10px; }
.sidebar-logo span { color: #1890ff; font-size: 22px; }
.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-group { margin-bottom: 4px; }
.nav-group-title { padding: 8px 16px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: #5a6272; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; cursor: pointer; transition: background .15s, color .15s; font-size: 14px; }
.nav-item:hover { background: #0d2137; color: #fff; }
/* nav-link: 实际页面用的导航类名 */
.nav-link { display: block; padding: 9px 16px; font-size: 13px; color: #a6adb4; transition: background .15s, color .15s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-link:hover { background: #0d2137; color: #fff; }
.nav-link.active { background: #1890ff; color: #fff; }
.nav-section-title { padding: 16px 16px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: #5a6272; }
.nav-item.active { background: #1890ff; color: #fff; }
.nav-item .icon { width: 18px; text-align: center; flex-shrink: 0; }
.sidebar-footer { padding: 12px 16px; border-top: 1px solid #0d2137; font-size: 12px; color: #5a6272; }
.sidebar-footer .user-info { color: #a6adb4; margin-bottom: 6px; }
.sidebar-footer .logout-btn { color: #ff4d4f; cursor: pointer; }
.sidebar-footer .logout-btn:hover { color: #ff7875; }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar { height: 56px; background: #fff; border-bottom: 1px solid #e8e8e8; display: flex; align-items: center; padding: 0 24px; gap: 12px; flex-shrink: 0; }
.topbar h2 { font-size: 16px; font-weight: 600; color: #333; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.content { flex: 1; overflow-y: auto; padding: 24px; }

/* ===== Card ===== */
.card { background: #fff; border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,.08); margin-bottom: 16px; }
.card-header { padding: 16px 20px; border-bottom: 1px solid #f0f0f0; display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 16px; border-radius: 6px; border: 1px solid transparent; font-size: 14px; transition: all .2s; white-space: nowrap; }
.btn-primary { background: #1890ff; color: #fff; border-color: #1890ff; }
.btn-primary:hover { background: #40a9ff; border-color: #40a9ff; }
.btn-default { background: #fff; color: #333; border-color: #d9d9d9; }
.btn-default:hover { border-color: #40a9ff; color: #40a9ff; }
.btn-danger { background: #ff4d4f; color: #fff; border-color: #ff4d4f; }
.btn-danger:hover { background: #ff7875; border-color: #ff7875; }
.btn-warning { background: #fa8c16; color: #fff; border-color: #fa8c16; }
.btn-warning:hover { background: #ffa940; }
.btn-sm { padding: 3px 10px; font-size: 12px; }
.btn-link { background: none; border: none; color: #1890ff; padding: 0; }
.btn-link:hover { color: #40a9ff; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 16px; text-align: left; border-bottom: 1px solid #f0f0f0; font-size: 13px; }
th { background: #fafafa; font-weight: 600; color: #555; white-space: nowrap; }
tr:hover td { background: #fafffe; }
.td-actions { display: flex; gap: 6px; align-items: center; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; }
.tag-success { background: #f6ffed; color: #52c41a; border: 1px solid #b7eb8f; }
.tag-warning { background: #fffbe6; color: #faad14; border: 1px solid #ffe58f; }
.tag-error   { background: #fff2f0; color: #ff4d4f; border: 1px solid #ffccc7; }
.tag-default { background: #fafafa; color: #666;    border: 1px solid #d9d9d9; }
.tag-blue    { background: #e6f4ff; color: #1890ff; border: 1px solid #91caff; }

/* ===== Form ===== */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-weight: 500; margin-bottom: 6px; color: #555; }
.form-control { width: 100%; padding: 8px 12px; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 14px; outline: none; transition: border-color .2s; font-family: inherit; }
.form-control:focus { border-color: #1890ff; box-shadow: 0 0 0 2px rgba(24,144,255,.1); }
.form-control.error { border-color: #ff4d4f; }
textarea.form-control { resize: vertical; min-height: 120px; font-family: "SF Mono", "Fira Code", monospace; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-hint { font-size: 12px; color: #999; margin-top: 4px; }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1000; display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.active { display: flex; }
.modal { background: #fff; border-radius: 8px; box-shadow: 0 8px 32px rgba(0,0,0,.15); width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; }
.modal-lg { max-width: 860px; }
.modal-xl { max-width: 1100px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid #f0f0f0; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 20px; color: #999; line-height: 1; padding: 4px; }
.modal-close:hover { color: #333; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 12px 20px; border-top: 1px solid #f0f0f0; display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0; }

/* ===== Pagination ===== */
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 16px; }
.page-btn { min-width: 32px; height: 32px; padding: 0 8px; border: 1px solid #d9d9d9; border-radius: 6px; background: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.page-btn:hover { border-color: #1890ff; color: #1890ff; }
.page-btn.active { background: #1890ff; border-color: #1890ff; color: #fff; }
.page-btn[disabled] { opacity: .4; cursor: not-allowed; }
.page-info { color: #666; font-size: 13px; }

/* ===== Toast ===== */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: 6px; color: #fff; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,.15); display: flex; align-items: center; gap: 8px; animation: slideIn .2s ease; min-width: 200px; }
.toast-success { background: #52c41a; }
.toast-error   { background: #ff4d4f; }
.toast-info    { background: #1890ff; }
@keyframes slideIn { from { transform: translateX(100%); opacity:0; } to { transform: translateX(0); opacity:1; } }

/* ===== Login Page ===== */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #001529 0%, #003a70 100%); }
.login-box { background: #fff; border-radius: 12px; padding: 40px 36px; width: 380px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 22px; font-weight: 700; color: #001529; }
.login-logo p { color: #999; font-size: 13px; margin-top: 6px; }
.login-box .btn-primary { width: 100%; padding: 10px; font-size: 15px; margin-top: 4px; border-radius: 6px; }
.login-error { color: #ff4d4f; font-size: 13px; text-align: center; margin-top: 8px; min-height: 20px; }

/* ===== Status dots ===== */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot-pending  { background: #faad14; }
.dot-running  { background: #1890ff; animation: pulse 1s infinite; }
.dot-done     { background: #52c41a; }
.dot-failed   { background: #ff4d4f; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ===== Progress bar ===== */
.progress-bar { height: 6px; background: #f0f0f0; border-radius: 3px; overflow: hidden; margin: 8px 0; }
.progress-fill { height: 100%; background: #1890ff; border-radius: 3px; transition: width .4s; }
.progress-fill.done { background: #52c41a; }

/* ===== Misc ===== */
.empty-state { text-align: center; padding: 48px 20px; color: #999; }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.text-muted { color: #999; }
.text-danger { color: #ff4d4f; }
.text-success { color: #52c41a; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.w-full { width: 100%; }
.filter-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.filter-bar .form-control { width: auto; min-width: 160px; }

/* ===== Tree nav (template page) ===== */
.template-layout { display: flex; gap: 0; height: calc(100vh - 56px - 48px); }
.tree-panel { width: 240px; flex-shrink: 0; border-right: 1px solid #f0f0f0; overflow-y: auto; background: #fff; border-radius: 8px 0 0 8px; }
.tree-chapter { }
.tree-chapter-title { padding: 10px 16px; font-weight: 600; font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; color: #333; border-bottom: 1px solid #f5f5f5; }
.tree-chapter-title:hover { background: #f9f9f9; }
.tree-section { padding: 8px 16px 8px 28px; font-size: 13px; cursor: pointer; color: #555; border-bottom: 1px solid #f9f9f9; display: flex; align-items: center; justify-content: space-between; }
.tree-section:hover { background: #f0f7ff; color: #1890ff; }
.tree-section.active { background: #e6f4ff; color: #1890ff; font-weight: 500; }
.tree-badges { display: flex; gap: 4px; }
.tree-badge { font-size: 10px; padding: 1px 5px; border-radius: 3px; background: #f0f0f0; color: #666; }
.tree-badge.text { background: #e6f4ff; color: #1890ff; }
.tree-badge.image { background: #f9f0ff; color: #722ed1; }
.editor-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: #fff; border-radius: 0 8px 8px 0; }
.editor-tabs { display: flex; border-bottom: 1px solid #f0f0f0; padding: 0 16px; }
.editor-tab { padding: 12px 16px; font-size: 13px; cursor: pointer; border-bottom: 2px solid transparent; color: #666; }
.editor-tab.active { border-bottom-color: #1890ff; color: #1890ff; font-weight: 500; }
.editor-content { flex: 1; overflow-y: auto; padding: 16px; }
.version-item { display: flex; align-items: center; padding: 8px 0; border-bottom: 1px solid #f5f5f5; gap: 10px; font-size: 13px; }
.version-item:last-child { border-bottom: none; }
