:root {
    --bg: #f2f4f8;
    --panel: #ffffff;
    --sidebar: #111827;
    --sidebar-soft: #1f2937;
    --text: #1f2937;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #4f46e5;
    --primary-soft: #eef2ff;
    --danger: #dc2626;
    --success: #059669;
    --warning: #d97706;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .05);
    --sidebar-width: 236px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0 0 12px; }

.layout { min-height: 100vh; }

/* 侧边栏 */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    background: var(--sidebar);
    color: #e5e7eb;
    display: flex;
    flex-direction: column;
    z-index: 40;
    transition: transform .2s ease;
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.brand-logo {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff;
    font-weight: 700;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-text strong { font-size: 15px; color: #fff; }
.brand-text span { font-size: 12px; color: #9ca3af; }

.nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: 8px;
    color: #cbd5e1;
    font-size: 14px;
    text-decoration: none;
}
.nav-item:hover { background: var(--sidebar-soft); color: #fff; text-decoration: none; }
.nav-item.active { background: #312e81; color: #fff; }
.nav-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4b5563;
    flex: 0 0 auto;
}
.nav-item.active .nav-dot { background: #a5b4fc; box-shadow: 0 0 0 4px rgba(99, 102, 241, .18); }

.sidebar-footer {
    padding: 14px 18px 20px;
    border-top: 1px solid rgba(255, 255, 255, .06);
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    color: #9ca3af;
}
.sidebar-footer a { color: #a5b4fc; }

/* 主区域 */
.main {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 24px;
    background: rgba(255, 255, 255, .94);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar h1 { font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; }
.user-name { font-weight: 600; }
.icon-btn {
    display: none;
    width: 36px;
    height: 36px;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    font-size: 17px;
    cursor: pointer;
}
.content { padding: 22px 24px 30px; width: 100%; max-width: 1440px; margin: 0 auto; flex: 1; }
.footer { padding: 14px 24px 22px; color: var(--muted); font-size: 12px; text-align: center; }

/* 卡片 */
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 18px;
    overflow: hidden;
}
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--line);
}
.card-header h2 { font-size: 15px; }
.card-header .sub { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 8px; }
.card-body { padding: 18px; }
.card-body.flush { padding: 0; }

/* 统计卡片 */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 26px; line-height: 1.2; }
.stat-hint { font-size: 12px; color: var(--muted); }
.stat-primary { border-top: 3px solid var(--primary); }
.stat-success { border-top: 3px solid var(--success); }
.stat-warning { border-top: 3px solid var(--warning); }
.stat-danger { border-top: 3px solid var(--danger); }

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: #4338ca; border-color: #4338ca; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form { display: inline; }

/* 表单 */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; }
.field .req { color: var(--danger); margin-left: 2px; }
.field input[type="text"],
.field input[type="password"],
.field input[type="number"],
.field input[type="url"],
.field input[type="email"],
.field input[type="datetime-local"],
.field select,
.field textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: #fff;
    font: inherit;
    color: var(--text);
    outline: none;
}
.field textarea { resize: vertical; min-height: 100px; }
.field input:focus, .field select:focus, .field textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
.field-help { font-size: 12px; color: var(--muted); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 14px; }
.check-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; }
.check-item input { accent-color: var(--primary); }

/* 表格 */
.table-wrap { width: 100%; overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.table th, table.table td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.table th {
    background: #f9fafb;
    color: var(--muted);
    font-weight: 600;
    font-size: 12px;
    white-space: nowrap;
}
table.table tr:hover td { background: #fafbff; }
table.table td.actions { white-space: nowrap; }
table.table td.actions .btn { margin-right: 4px; }
table.table .cell-ellipsis { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.table .checkbox-cell { width: 34px; }

/* 徽章 */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    line-height: 1.6;
    font-weight: 500;
    white-space: nowrap;
}
.badge-on { background: #ecfdf5; color: #047857; }
.badge-off { background: #f3f4f6; color: #6b7280; }
.badge-role { background: var(--primary-soft); color: var(--primary); }
.badge-warn { background: #fffbeb; color: #b45309; }
.badge-danger { background: #fef2f2; color: #b91c1c; }
.badge-info { background: #eff6ff; color: #1d4ed8; }

/* 提示条 */
.alert {
    padding: 11px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 13px;
    border: 1px solid transparent;
}
.alert-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert-error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.alert-info { background: #eff6ff; color: #1e40af; border-color: #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }

/* 工具栏 */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.filters { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.filters .field { min-width: 140px; }
.filters .field input, .filters .field select { padding: 8px 10px; }
.filters .btn { margin-bottom: 1px; }

/* 分页 */
.pagination { display: flex; gap: 6px; justify-content: flex-end; padding: 14px 18px; flex-wrap: wrap; }
.pagination a, .pagination span {
    min-width: 32px;
    height: 32px;
    padding: 0 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    background: #fff;
    font-size: 12px;
}
.pagination a:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.pagination a.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination-gap { border: 0 !important; background: transparent !important; }

/* 空状态 */
.empty-state { padding: 48px 20px; text-align: center; color: var(--muted); }

/* 仪表盘布局 */
.dashboard-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; }
.chart { display: flex; align-items: flex-end; gap: 12px; height: 170px; padding: 10px 4px 0; }
.chart .bar-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.chart .bar { width: 100%; max-width: 42px; background: linear-gradient(180deg, #818cf8, #4f46e5); border-radius: 6px 6px 2px 2px; min-height: 3px; }
.chart .bar-label { font-size: 11px; color: var(--muted); }
.chart .bar-value { font-size: 11px; color: var(--text); font-weight: 600; }
.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.quick-link {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    background: #fbfcff;
}
.quick-link:hover { border-color: #c7d2fe; background: var(--primary-soft); text-decoration: none; }
.quick-link strong { font-size: 13px; }
.quick-link span { font-size: 11px; color: var(--muted); }

.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.list-plain li:last-child { border-bottom: 0; }
.list-plain .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* 登录页 */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: radial-gradient(circle at 15% 20%, #312e81 0, transparent 42%), radial-gradient(circle at 85% 80%, #1e3a8a 0, transparent 40%), #0f172a;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
    padding: 30px 28px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand .brand-logo { width: 44px; height: 44px; font-size: 20px; }
.login-brand h2 { font-size: 20px; }
.login-brand p { margin: 0; color: var(--muted); font-size: 12px; }
.login-card .field { margin-bottom: 14px; }
.login-card .btn { width: 100%; padding: 11px; font-size: 14px; }
.login-tip { margin-top: 16px; color: var(--muted); font-size: 12px; text-align: center; }

/* 详情信息 */
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 24px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.kv span:first-child { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.ml-auto { margin-left: auto; }
.nowrap { white-space: nowrap; }

/* 编辑器/规则提示 */
.notice {
    border-left: 3px solid var(--primary);
    background: var(--primary-soft);
    padding: 10px 14px;
    border-radius: 0 8px 8px 0;
    color: #3730a3;
    font-size: 12px;
    margin-bottom: 14px;
}
.keyword-hit { background: #fff1f2; color: #be123c; padding: 0 2px; border-radius: 3px; }

/* 侧边栏遮罩 */
.sidebar-mask { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 35; }

@media (max-width: 1100px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: none; }
    .sidebar-mask.open { display: block; }
    .main { margin-left: 0; }
    .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
    .topbar { padding: 12px 16px; }
    .content { padding: 16px; }
    .form-grid { grid-template-columns: 1fr; }
    .check-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kv { grid-template-columns: 1fr; }
    .filters .field { min-width: 120px; flex: 1; }
}
@media (max-width: 520px) {
    .stats { grid-template-columns: 1fr; }
    .check-grid { grid-template-columns: 1fr; }
    .topbar h1 { font-size: 16px; }
    .user-name { display: none; }
    .card-body { padding: 14px; }
}
