/* ============================================================
   Rule 官方文档站 — 全站样式
   主题变量 / 布局 / 组件
   图标一律使用 Font Awesome（<i class="fa-solid ...">），禁用 emoji
   ============================================================ */

:root {
    --brand: #e54d42;
    --brand-dark: #c0392b;
    --bg: #f6f8fa;
    --surface: #ffffff;
    --text: #1f2328;
    --muted: #656d76;
    --border: #d9dee3;
    --accent: #0969da;
    --accent-soft: #ddf4ff;
    --code-bg: #f6f8fa;
    --shadow: 0 1px 3px rgba(31,35,40,0.08), 0 4px 12px rgba(31,35,40,0.04);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-width: 268px;
    --header-height: 62px;
    --toc-width: 220px;
}

.dark {
    --bg: #0d1117;
    --surface: #161b22;
    --text: #c9d1d9;
    --muted: #8b949e;
    --border: #30363d;
    --accent: #58a6ff;
    --accent-soft: #1c3450;
    --code-bg: #161b22;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 6px 16px rgba(0,0,0,0.2);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.65;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- 顶部导航 ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    height: var(--header-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 18px;
    color: var(--text);
    white-space: nowrap;
}

.brand .brand-logo {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--brand), var(--brand-dark));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 17px;
    flex: 0 0 auto;
}

.brand:hover { text-decoration: none; }
.brand .brand-sub { font-size: 12px; color: var(--muted); font-weight: 400; }

.header-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    overflow-x: auto;
}

.header-nav a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 13px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    white-space: nowrap;
}

.header-nav a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.header-nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
}

.icon-btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- 页面容器（文档三栏） ---------- */
.docs-layout {
    display: flex;
    max-width: 1440px;
    margin: 0 auto;
    min-height: calc(100vh - var(--header-height));
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 14px;
    flex-shrink: 0;
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
}

.sidebar-search {
    position: relative;
    margin-bottom: 12px;
}

.sidebar-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 13px;
}

.sidebar-search input {
    width: 100%;
    padding: 9px 12px 9px 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    outline: none;
}

.sidebar-search input:focus { border-color: var(--accent); }

.nav-group { margin-bottom: 18px; }

.nav-group-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--muted);
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 7px;
}

.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-list li { margin: 2px 0; }

.nav-link {
    display: block;
    padding: 8px 11px;
    border-radius: 7px;
    color: var(--text);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 9px;
    white-space: nowrap;
    overflow: hidden;
}

.nav-link i { color: var(--muted); font-size: 13px; width: 16px; text-align: center; flex: 0 0 auto; }
.nav-link:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.nav-link:hover i { color: var(--accent); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-link.active i { color: var(--accent); }

.nav-link .nav-count {
    margin-left: auto;
    font-size: 11px;
    color: var(--muted);
    background: var(--bg);
    border-radius: 10px;
    padding: 1px 7px;
    flex: 0 0 auto;
}

.main { flex: 1; min-width: 0; }

.doc-content {
    max-width: 880px;
    margin: 0 auto;
    padding: 36px 40px 90px;
    background: var(--surface);
    min-height: calc(100vh - var(--header-height));
}

.doc-content h1 { font-size: 2em; margin: 0 0 14px; padding-bottom: 14px; border-bottom: 2px solid var(--border); }
.doc-content h2 { font-size: 1.55em; margin: 44px 0 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.doc-content h3 { font-size: 1.25em; margin: 26px 0 12px; }
.doc-content h4 { font-size: 1.1em; margin: 18px 0 10px; }
.doc-content p { margin: 0 0 14px; }
.doc-content ul, .doc-content ol { margin: 0 0 16px; padding-left: 26px; }
.doc-content li { margin: 5px 0; }
.doc-content hr { border: 0; border-top: 1px solid var(--border); margin: 32px 0; }
.doc-content blockquote {
    margin: 0 0 18px;
    padding: 12px 18px;
    border-left: 4px solid var(--brand);
    background: var(--accent-soft);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text);
}

.doc-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0 22px;
    font-size: 14px;
    border: 1px solid var(--border);
}

.doc-content th, .doc-content td { padding: 9px 12px; border: 1px solid var(--border); text-align: left; }
.doc-content th { background: var(--accent-soft); font-weight: 600; }
.doc-content tr:nth-child(even) { background: rgba(128,128,128,0.03); }

.doc-content pre {
    position: relative;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 15px 16px;
    overflow-x: auto;
    margin: 0 0 18px;
}

.doc-content code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 90%;
}

.doc-content pre code { background: transparent; padding: 0; font-size: 13px; line-height: 1.65; }
.doc-content :not(pre) > code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border);
    font-size: 88%;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 10px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.doc-content pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }

.anchor { margin-left: 8px; color: var(--muted); font-weight: 400; font-size: .78em; opacity: 0; transition: opacity .15s; text-decoration: none; }
.doc-content h2:hover .anchor, .doc-content h3:hover .anchor, .doc-content h4:hover .anchor { opacity: 1; }

/* 面包屑 */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 18px;
}

.breadcrumb i { font-size: 11px; color: var(--muted); }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .cur { color: var(--text); font-weight: 600; }

/* 模块统计条 */
.doc-meta-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--muted);
    margin: 0 0 8px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.doc-meta-bar span { display: inline-flex; align-items: center; gap: 6px; }
.doc-meta-bar i { color: var(--brand); }

/* 右侧 TOC */
.toc-pane {
    width: var(--toc-width);
    flex-shrink: 0;
    padding: 20px 16px;
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
    display: none;
}

.toc-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 7px;
}

.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list li { margin: 2px 0; }
.toc-list a {
    display: block;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--muted);
    border-left: 2px solid transparent;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.toc-list a:hover { color: var(--accent); text-decoration: none; }
.toc-list a.toc-active { color: var(--accent); border-left-color: var(--brand); font-weight: 600; }
.toc-list li.toc-level-3 a { padding-left: 22px; font-size: 12.5px; }

/* 翻页 */
.doc-pager {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 46px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.doc-pager a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    max-width: 48%;
}

.doc-pager a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.doc-pager .pager-label { font-size: 12px; color: var(--muted); display: block; }
.doc-pager .pager-title { font-size: 14px; font-weight: 600; }
.doc-pager a.next { margin-left: auto; text-align: right; }

/* 返回顶部 */
#backToTop {
    position: fixed;
    right: 26px;
    bottom: 28px;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    z-index: 900;
    font-size: 16px;
}

#backToTop:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* 空状态 */
.empty-state { text-align: center; padding: 80px 20px; color: var(--muted); }
.empty-state i { font-size: 40px; display: block; margin-bottom: 14px; opacity: .5; }

/* 菜单按钮（移动端） */
.menu-toggle { display: none; }

/* ---------- 页脚 ---------- */
.site-footer {
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding: 26px 22px;
    margin-top: 0;
}

.site-footer-inner {
    max-width: 1200px;
    margin: 0 auto;
    text-align: center;
    font-size: 13px;
    color: var(--muted);
}

.site-footer p { margin: 4px 0; }

/* ---------- 侧栏页脚 ---------- */
.sidebar-footer {
    padding: 12px 10px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--muted);
    text-align: center;
}

/* ---------- 首页（门户）组件 ---------- */
.hero {
    position: relative;
    overflow: hidden;
    padding: 90px 24px 70px;
    text-align: center;
    background: linear-gradient(150deg, #1a1c23 0%, #262a35 55%, #2e2430 100%);
    color: #fff;
}

.dark .hero { background: linear-gradient(150deg, #0d1117 0%, #161b22 55%, #1c1630 100%); }

.hero-grid-bg {
    position: absolute;
    inset: 0;
    opacity: .16;
    background-image:
        linear-gradient(rgba(255,255,255,.35) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.35) 1px, transparent 1px);
    background-size: 46px 46px;
    mask-image: radial-gradient(ellipse at 50% 0%, #000 30%, transparent 78%);
    -webkit-mask-image: radial-gradient(ellipse at 50% 0%, #000 30%, transparent 78%);
    pointer-events: none;
}

.hero-inner { position: relative; max-width: 980px; margin: 0 auto; }

.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    border: 1px solid rgba(255,255,255,.25);
    border-radius: 30px;
    font-size: 13px;
    color: #ffd9d5;
    background: rgba(229,77,66,.16);
    margin-bottom: 22px;
}

.hero h1 {
    font-size: clamp(30px, 5vw, 52px);
    font-weight: 800;
    margin: 0 0 18px;
    letter-spacing: .5px;
    line-height: 1.2;
}

.hero h1 .brand-red { color: #ff6a5e; }

.hero p.lead {
    font-size: clamp(15px, 2vw, 18px);
    color: rgba(255,255,255,.78);
    max-width: 720px;
    margin: 0 auto 34px;
    line-height: 1.8;
}

.hero-ctas {
    display: flex;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
}

.hero-btn {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 13px 26px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    transition: transform .15s, box-shadow .15s;
}

.hero-btn:hover { text-decoration: none; transform: translateY(-2px); }

.hero-btn.primary { background: var(--brand); color: #fff; box-shadow: 0 8px 24px rgba(229,77,66,.35); }
.hero-btn.primary:hover { background: var(--brand-dark); }

.hero-btn.ghost { background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.25); }
.hero-btn.ghost:hover { background: rgba(255,255,255,.16); }

.hero-scroll {
    display: block;
    margin: 44px auto 0;
    color: rgba(255,255,255,.5);
    font-size: 14px;
}

/* 区块 */
.section { max-width: 1200px; margin: 0 auto; padding: 64px 24px; }
.section-title {
    text-align: center;
    font-size: 30px;
    font-weight: 800;
    margin: 0 0 10px;
}

.section-sub {
    text-align: center;
    color: var(--muted);
    font-size: 15px;
    margin: 0 0 40px;
}

.section.alt { background: var(--surface); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }

/* 产品卡 */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 18px;
}

.product-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 26px 24px;
    box-shadow: var(--shadow);
    transition: transform .18s, box-shadow .18s;
}

.product-card:hover { transform: translateY(-4px); box-shadow: 0 12px 30px rgba(31,35,40,.12); }

.product-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 23px;
    color: #fff;
    margin-bottom: 16px;
}

.product-icon.c1 { background: linear-gradient(135deg,#e54d42,#c0392b); }
.product-icon.c2 { background: linear-gradient(135deg,#0969da,#0550ae); }
.product-icon.c3 { background: linear-gradient(135deg,#1a7f37,#116329); }
.product-icon.c4 { background: linear-gradient(135deg,#9a6700,#7d4e00); }

.product-card h3 { margin: 0 0 8px; font-size: 19px; }
.product-card .tag { font-size: 12px; color: var(--muted); margin-bottom: 10px; display: block; }
.product-card p { font-size: 14px; color: var(--text); margin: 0 0 14px; line-height: 1.7; }

.feature-list { list-style: none; margin: 0; padding: 0; }
.feature-list li { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; color: var(--text); margin: 6px 0; }
.feature-list i { color: var(--brand); margin-top: 3px; flex: 0 0 auto; font-size: 12px; }

/* 能力矩阵 */
.matrix-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.matrix-item {
    display: flex;
    gap: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.matrix-item i {
    font-size: 22px;
    color: var(--brand);
    flex: 0 0 auto;
    margin-top: 2px;
}

.matrix-item h4 { margin: 0 0 6px; font-size: 15px; }
.matrix-item p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.7; }

/* 架构图容器 */
.diagram-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 26px;
    overflow-x: auto;
}

.diagram-box svg { display: block; width: 100%; height: auto; max-width: 1100px; margin: 0 auto; }

/* 入口大卡 */
.entry-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 18px;
}

.entry-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 26px;
    box-shadow: var(--shadow);
    transition: transform .18s, border-color .18s;
    text-decoration: none;
    color: var(--text);
}

.entry-card:hover { transform: translateY(-4px); border-color: var(--brand); text-decoration: none; }

.entry-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--accent-soft);
    color: var(--accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.entry-card h3 { margin: 0; font-size: 18px; }
.entry-card p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.7; }
.entry-card .entry-more { font-size: 13px; color: var(--accent); font-weight: 600; margin-top: auto; }

/* 快速链接 */
.quick-links {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
}

.quick-links a {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text);
}

.quick-links a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.quick-links i { color: var(--accent); font-size: 13px; }

/* 响应式 */
@media (min-width: 1240px) {
    .toc-pane { display: block; }
}

@media (max-width: 1060px) {
    .toc-pane { display: none; }
}

@media (max-width: 900px) {
    .menu-toggle { display: inline-flex; }
    .header-nav { display: none; }
    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        z-index: 800;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: var(--shadow);
    }
    .sidebar.open { transform: translateX(0); }
    .doc-content { padding: 26px 18px 70px; }
    .doc-pager { flex-direction: column; }
    .doc-pager a { max-width: 100%; }
}

@media (max-width: 480px) {
    .brand .brand-sub { display: none; }
}