/* ========================================
   平衡点CRM - 全局样式
   ======================================== */

:root {
    /* 色彩 - 源自 LOGO 品牌色 */
    --primary: #142878;          /* LOGO 深蓝主色 */
    --primary-dark: #0f1f5c;     /* 深蓝 hover */
    --primary-soft: #eef2fb;     /* 浅蓝背景 */
    --primary-hover: #1e3ba0;    /* 深蓝悬停 */
    --accent: #28a0dc;           /* LOGO 天蓝辅助色 */

    /* 覆盖 Bootstrap 默认主色变量 */
    --bs-primary: #142878;
    --bs-primary-rgb: 20, 40, 120;
    --bs-link-color: #142878;
    --bs-link-hover-color: #0f1f5c;
    /* 正文色统一走品牌 token（否则 Bootstrap 默认 #212529 会大面积生效） */
    --bs-body-color: #1e293b;

    --text: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;

    --bg: #f8fafc;
    --bg-panel: #ffffff;
    --bg-soft: #f1f5f9;

    --border: #e2e8f0;
    --border-light: #f1f5f9;

    /* 布局 */
    --sidebar-width: 200px;
    --radius: 10px;
    --radius-sm: 6px;

    /* 阴影 - 多层细腻 */
    --shadow-sm: 0 1px 2px rgba(20, 40, 120, 0.04);
    --shadow: 0 1px 3px rgba(20, 40, 120, 0.06), 0 1px 2px rgba(20, 40, 120, 0.04);
    --shadow-md: 0 4px 12px -2px rgba(20, 40, 120, 0.10), 0 2px 6px -2px rgba(20, 40, 120, 0.05);
    --shadow-lg: 0 12px 28px -6px rgba(20, 40, 120, 0.15), 0 6px 12px -6px rgba(20, 40, 120, 0.08);
    --shadow-primary: 0 6px 16px -4px rgba(20, 40, 120, 0.35);

    /* 动效 */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- 基础 ---------- */
body {
    background-color: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; transition: color 0.15s var(--ease); }
a:hover { color: var(--primary-dark); }

::selection { background: var(--primary); color: #fff; }

/* ---------- 侧边栏 ---------- */
.sidebar {
    min-height: 100vh;
    background: linear-gradient(180deg, #142878 0%, #0f1f5c 100%);
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    z-index: 100;
    transition: transform 0.3s var(--ease);
    box-shadow: 2px 0 16px rgba(20, 40, 120, 0.25);
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed { transform: translateX(-100%); }

.sidebar-logo {
    text-align: center;
    padding: 22px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
}

/* logo.png 是 1181x1181 白底方图，"图标+平衡点"横版组合在画面垂直中央。
   侧边栏窄，用 object-fit:cover 按容器比例裁出中间横条：
   横向完整保留图标+文字，垂直方向裁掉上下多余留白，避免糊成一团。 */
.sidebar-logo img {
    display: block;
    width: 100%;
    height: 52px;
    -o-object-fit: cover;
    object-fit: cover;
    -o-object-position: center center;
    object-position: center center;
    background: #ffffff;
    border-radius: 8px;
    padding: 4px;
}
.sidebar-logo h4 {
    color: #ffffff;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
    margin: 8px 0 0;
}
.sidebar-logo p {
    color: rgba(255, 255, 255, 0.6);
    font-size: 11px;
    margin: 8px 0 0;
    letter-spacing: 1px;
}

.sidebar nav { flex: 1; padding: 12px 0; }

.sidebar a {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    padding: 11px 18px;
    margin: 2px 10px;
    display: flex;
    align-items: center;
    transition: background-color 0.18s var(--ease), color 0.18s var(--ease), border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
    border-left: none;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
}

.sidebar a i {
    font-size: 16px;
    margin-right: 10px;
    width: 18px;
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
    transition: color 0.18s var(--ease);
}

.sidebar a:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.sidebar a:hover i { color: var(--accent); }

.sidebar a.active {
    background: var(--accent);
    color: #ffffff;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(40, 160, 220, 0.35);
}

.sidebar a.active i { color: #ffffff; }

/* ---------- 侧边栏分组菜单（客户管理） ---------- */
.nav-group { margin: 2px 0; }

.nav-group-head {
    display: flex;
    align-items: center;
}

.nav-group-head > a {
    flex: 1;
    min-width: 0;
    margin-right: 0;
}

.sidebar a.module-active {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

.sidebar a.module-active i { color: var(--accent); }

.nav-group-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.45);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    transition: color 0.18s var(--ease);
}

.nav-group-toggle:hover { color: var(--accent); }

.nav-group-toggle i {
    display: inline-block;
    font-size: 12px;
    transition: transform 0.2s var(--ease);
}

.nav-group-toggle[aria-expanded="true"] i { transform: rotate(180deg); }

.sidebar a.nav-sub {
    padding: 8px 18px 8px 40px;
    margin: 1px 10px;
    font-size: 12.5px;
    position: relative;
}

.sidebar a.nav-sub i { font-size: 14px; }

.sidebar a.nav-sub::before {
    content: '';
    position: absolute;
    left: 22px;
    top: 50%;
    width: 10px;
    height: 1px;
    background: rgba(255, 255, 255, 0.25);
}

/* ---------- 主内容区 ---------- */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.3s var(--ease);
}

.main-content.expanded { margin-left: 0; }

/* ---------- 顶部导航 ---------- */
.navbar {
    background: var(--bg-panel);
    box-shadow: 0 1px 0 var(--border);
    padding: 0.75rem 1.5rem;
}

.navbar-brand {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
}

/* ---------- 卡片 ---------- */
.card {
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: box-shadow 0.25s var(--ease), transform 0.25s var(--ease), border-color 0.25s var(--ease);
    margin-bottom: 1.5rem;
}

.card:hover { box-shadow: var(--shadow-md); border-color: var(--border); }

.card-header {
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-light);
    padding: 1rem 1.25rem;
    border-radius: var(--radius) var(--radius) 0 0;
}

.card-header h5, .card-header h6 { margin: 0; font-weight: 600; color: var(--text); }

.card-body { padding: 1.25rem; }

/* ---------- 统计卡片 ---------- */
.stat-card {
    transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
    border-radius: var(--radius);
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* ---------- 按钮 ---------- */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: background-color 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
    border-width: 1px;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-primary);
}

.btn-primary:active { transform: translateY(0); }

.btn-sm { border-radius: 5px; }

/* 覆盖 Bootstrap outline 按钮配色 */
.btn-outline-primary {
    --bs-btn-color: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--primary);
    --bs-btn-hover-border-color: var(--primary);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--primary-dark);
    --bs-btn-active-border-color: var(--primary-dark);
    --bs-btn-disabled-color: var(--primary);
    --bs-btn-disabled-border-color: var(--primary);
    color: var(--primary);
    border-color: var(--primary);
}

.btn-outline-primary:hover {
    background-color: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* ---------- 表单 ---------- */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
    background-color: var(--bg-panel);
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(20, 40, 120, 0.12);
}

.form-label { font-weight: 500; color: var(--text); margin-bottom: 0.4rem; font-size: 0.9rem; }

.input-group-text {
    background: var(--bg-soft);
    border-color: var(--border);
    color: var(--text-muted);
}

/* ---------- 表格 ---------- */
.table { margin-bottom: 0; }

.table th {
    background: var(--bg-soft);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 0.85rem 1rem;
    white-space: nowrap;
}

.table td {
    padding: 0.85rem 1rem;
    vertical-align: middle;
    border-color: var(--border-light);
}

.table-hover tbody tr {
    transition: background 0.15s var(--ease);
}

.table-hover tbody tr:hover {
    background: var(--primary-soft);
}

/* ---------- 徽章 ---------- */
.badge { font-weight: 500; padding: 0.4em 0.75em; border-radius: 6px; font-size: 0.75rem; }

.badge-normal { background: #64748b; }
.badge-important { background: #f59e0b; }
.badge-vip { background: #8b5cf6; }

/* 警告黄底徽章强制深色文字：Bootstrap 默认白字压黄底对比度仅 1.6:1，不可读 */
.badge.bg-warning { color: #212529 !important; }

/* 编辑等黄色描边按钮：黄字白底对比度 1.6:1，改深琥珀保证可读 */
.btn-outline-warning {
    --bs-btn-color: #b45309;
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: #b45309;
    --bs-btn-hover-border-color: #b45309;
    --bs-btn-active-bg: #92400e;
    --bs-btn-active-border-color: #92400e;
    color: #b45309;
    border-color: #d97706;
}

/* ---------- 提醒列表 ---------- */
.reminder-list li {
    padding: 8px 0;
    border-bottom: 1px solid var(--border-light);
}
.reminder-list li:last-child { border-bottom: none; }

/* ---------- 空状态 ---------- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-light);
}
.empty-state i { font-size: 2.5rem; margin-bottom: 0.75rem; display: block; opacity: 0.5; }
.empty-state p { margin: 0; font-size: 0.9rem; }

/* ---------- 分页 ---------- */
.pagination .page-link {
    border-radius: var(--radius-sm);
    margin: 0 2px;
    color: var(--primary);
    border: 1px solid var(--border);
    transition: background-color 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.pagination .page-link:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
}

.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
}

/* ---------- 加载遮罩 ---------- */
.loading-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(2px);
}

.loading-spinner {
    width: 44px; height: 44px;
    border: 3px solid var(--bg-soft);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ---------- 移动端菜单按钮 ---------- */
.menu-toggle {
    display: none;
    position: fixed;
    left: calc(12px + env(safe-area-inset-left));
    top: calc(12px + env(safe-area-inset-top));
    z-index: 101;
    background: var(--primary);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1.1rem;
}

/* ---------- 响应式 ---------- */
/* ≤1200：13寸笔记本半屏/分屏场景，收窄内容区左右留白，给表格与工具栏让出空间 */
@media (max-width: 1200px) {
    .main-content > .px-4,
    .main-content > .px-4.py-3 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
}

/* ≤992：平板竖屏及以下，侧栏收进抽屉（汉堡按钮唤出），主内容区占满全宽。
   原 768 断点上移，覆盖 769–992 的"无人管"区间 */
@media (max-width: 992px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
    /* 汉堡按钮 fixed 于左上角(宽约44px)，顶栏内容左移避让，防止压住页面标题 */
    .main-content .navbar .container-fluid { padding-left: 3.5rem; }
}

/* ≤768：手机端进一步收紧 */
@media (max-width: 768px) {
    /* 顶栏只留"☰ + 标题 + 角色 + 退出"，姓名收起，避免顶栏挤成两行 */
    .navbar .user-name-text { display: none; }
    .navbar .btn { min-height: 38px; }
}

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: var(--bg-soft); }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ---------- 动画 ---------- */
.fade-in {
    animation: fadeIn 0.3s var(--ease);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Alert 优化 ---------- */
.alert {
    border-radius: var(--radius-sm);
    border: none;
    box-shadow: var(--shadow-sm);
}

/* ---------- Modal 优化 ---------- */
.modal-content {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.modal-header {
    border-bottom: 1px solid var(--border-light);
    padding: 1rem 1.25rem;
}

.modal-footer {
    border-top: 1px solid var(--border-light);
    padding: 1rem 1.25rem;
}

/* ========================================
   兼容性与排版修复（跨浏览器：Chrome/Edge/Firefox/Safari）
   ======================================== */

/* ---------- 表格：中文正常换行，数字/编码不被拆成竖排 ---------- */
.table td {
    word-break: normal;          /* 默认：英文/数字不在词中断 */
    overflow-wrap: break-word;   /* 仅当长单词溢出列宽时才在词内断行 */
    vertical-align: middle;
}

/* 表头保持不换行 */
.table th { white-space: nowrap; }

/* 时间、金额、徽章、操作按钮组这类短内容不换行，避免视觉碎片化 */
.table td .badge,
.table td .btn,
.table td .btn-group { white-space: nowrap; }

/* 链接（客户名、订单号）保持单行，列宽随内容撑开，避免被挤压竖排 */
.table td > a { white-space: nowrap; }

/* 有横向滚动容器时，给表格一个最小宽度：窄屏横向滚动，
   而不是把列压到每个字一行。各页面列数不同，统一给一个安全下限。 */
.table-responsive .table { min-width: 900px; }
@media (max-width: 1200px) {
    .table-responsive .table { min-width: 760px; }
}

/* 数据单元格最小宽度：保证每个文本列至少能放下 2 个汉字，
   避免 4 个字的产品名/行业名被压成一列一个字。 */
.table-responsive .table td { min-width: 3.5rem; }
.table-responsive .table th { min-width: 3.5rem; }

/* ---------- 客户详情等"键值表"：标签列固定宽度不竖排 ---------- */
.table-borderless td.text-muted {
    white-space: nowrap;
    width: 110px;
    color: var(--text-muted);
}
/* 键值表的值列：长邮箱/链接仅在溢出列宽时才断词，
   避免电话号码这类完整串被拆成两行；默认不在单词中间断行。 */
.table-borderless td:last-child {
    overflow-wrap: break-word;
}

/* ---------- 统计卡片：大数字紧凑一行，不换行、不截断 ---------- */
.stat-card h3, .stat-card h4, .stat-card .stat-number {
    white-space: nowrap;
    font-size: 1.5rem;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}
@media (max-width: 768px) {
    .stat-card h3 { font-size: 1.25rem; }
}

/* ---------- 订单步骤条：当前节点高亮样式 ---------- */
.step-circle {
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fff;
    font-weight: 600;
    -webkit-transition: background-color 0.2s var(--ease);
    transition: background-color 0.2s var(--ease);
}
.step-circle.done    { background-color: #198754; }  /* 已完成-绿 */
.step-circle.current { background-color: #ffc107; }  /* 当前进行中-黄 */
.step-circle.todo    { background-color: #adb5bd; }  /* 未开始-灰 */
.step-line           { flex-grow: 1; border-top: 2px solid #adb5bd; margin-top: -1.25rem; }
.step-line.done      { border-top-color: #198754; }
.step-line.current   { border-top-color: #ffc107; }

/* ---------- 卡片 hover 阴影在不支持 transform 的旧内核上退化不报错 ---------- */
@supports not (transform: translateY(0)) {
    .card:hover { transform: none; }
}

/* 操作列：按钮横排不换行，紧凑间距，表头也不折 */
td.actions-cell {
    white-space: nowrap;
    min-width: 168px;
    text-align: center;
}
td.actions-cell .btn {
    margin-right: 4px;
    padding: 4px 12px;
    font-size: 13px;
    line-height: 1.5;
    min-height: 32px;
}
td.actions-cell .btn:last-child { margin-right: 0; }

/* 操作列吸附右侧：横向滚动时按钮始终可见，白底+左侧阴影区分 */
.table-responsive { overflow-x: auto; overscroll-behavior-x: contain; }
.table-responsive .actions-cell {
    position: sticky;
    right: 0;
    background: #fff;
    box-shadow: -6px 0 8px -6px rgba(0, 0, 0, 0.15);
    z-index: 2;
}
thead th.actions-header {
    position: sticky;
    right: 0;
    z-index: 3;
    background: var(--bg-soft);
}

/* 表格单元格默认不换行：防止中文短词被压成竖排单字。
   表格整体变宽后由 .table-responsive 提供横向滚动。
   长文本列（客户名/备注）由模板用 .text-wrap 或 text-truncate 自行处理。 */
.table td, .table th { white-space: nowrap; }
.table td.wrap, .table th.wrap { white-space: normal; }

/* 长文本列限宽省略：客户名等长内容截断，悬停 title 显示完整内容，
   避免单列过宽把表格撑出横向滚动导致 sticky 操作列遮盖相邻列 */
.table td.cell-ellipsis {
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table .badge { white-space: nowrap; }

.table .badge { margin-right: 6px; }

/* ========================================
   全局排版统一 (v2)
   ======================================== */

/* 页面标题 */
.navbar-brand.h4, .navbar-brand.mb-0 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* 卡片标题 */
.card-header h5, .card-header h6 {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: -0.005em;
}

/* 表格表头统一 */
.table thead th {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom-width: 1px;
    padding: 0.7rem 0.75rem;
}
.table tbody td {
    font-size: 0.875rem;
    padding: 0.65rem 0.75rem;
    vertical-align: middle;
}

/* 数字列右对齐 */
.table td.num, .table th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* 按钮统一紧凑 */
.btn {
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding: 0.375rem 0.85rem;
}
.btn-sm { font-size: 0.8125rem; padding: 0.25rem 0.7rem; }

/* 表单标签 */
.form-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.35rem;
}
.form-control, .form-select {
    font-size: 0.875rem;
    padding: 0.45rem 0.75rem;
}

/* badge 统一 */
.badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.35em 0.65em;
    letter-spacing: 0.02em;
}

/* 卡片统一间距 */
.card {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.25rem;
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-light);
    padding: 0.9rem 1.1rem;
}
.card-body { padding: 1.1rem; }

/* 列表页工具栏间距 */
.page-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

/* ========================================
   细节打磨 (v3)
   ======================================== */

/* 表格行 hover 更柔和 */
.table-hover tbody tr:hover > * {
    background-color: var(--primary-soft) !important;
}
.table > :not(caption) > * > * {
    padding: 0.65rem 0.75rem;
}

/* 紧凑表格：列多的列表页（如订单）缩小横向 padding，避免整体溢出 */
.table.table-compact > :not(caption) > * > * {
    padding: 0.65rem 0.45rem;
}

/* 链接下划线动画 */
.main-content a:not(.btn):not(.nav-link) {
    text-decoration: none;
}
.main-content a:not(.btn):not(.nav-link):hover {
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* 按钮过渡更顺滑 */
.btn {
    transition: background-color 0.18s var(--ease), color 0.18s var(--ease), border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.btn-outline-primary:hover,
.btn-outline-warning:hover,
.btn-outline-danger:hover,
.btn-outline-secondary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

/* 输入框 focus 统一品牌色 */
.form-control:focus, .form-select:focus, .select2-selection--single:focus {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 0.15rem rgba(20, 40, 120, 0.12) !important;
}

/* 键盘可达性：全局焦点环（仅键盘 Tab 触发，鼠标点击不出现） */
:focus-visible {
    outline: 2px solid #2f5bd7;
    outline-offset: 2px;
}
.btn:focus-visible, .page-link:focus-visible, .nav-group-toggle:focus-visible {
    outline: 2px solid #2f5bd7;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(47, 91, 215, 0.25);
}

/* 侧边栏菜单 hover/active 过渡 */
.sidebar nav a {
    transition: background-color 0.18s var(--ease), color 0.18s var(--ease), border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
    border-left: 3px solid transparent;
}
.sidebar nav a:hover {
    background: rgba(255,255,255,0.08);
    padding-left: calc(1.25rem - 3px);
}
.sidebar nav a.active {
    background: rgba(255,255,255,0.12);
    border-left-color: var(--accent);
}

/* 卡片 hover 微浮起 */
.card {
    transition: box-shadow 0.25s var(--ease), transform 0.25s var(--ease);
}
.card.clickable:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* 空状态居中 */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}
.empty-state i {
    font-size: 2.5rem;
    opacity: 0.4;
    margin-bottom: 0.5rem;
}
.empty-state p {
    margin: 0;
    font-size: 0.95rem;
}

/* 分页按钮统一 */
.pagination .page-link {
    font-size: 0.85rem;
    color: var(--text);
    border: 1px solid var(--border);
    margin: 0 2px;
    min-width: 36px;
    text-align: center;
}
.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
}
.pagination .page-link:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
}

/* 数字列右对齐 + 等宽数字 */
td:nth-child(even) { font-variant-numeric: tabular-nums; }
td:has(> .badge) { white-space: nowrap; }

/* 滚动条美化 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* 快速筛选按钮组 */
.btn-group-sm .btn { font-size: 0.82rem; }

/* Alert 圆角 */
.alert { border-radius: var(--radius-sm); border: none; }

/* 页头标题与工具栏间距 */
.main-content > .px-4.py-3 > .card:first-child { margin-top: 0.5rem; }

/* ========================================
   栅格与纵向节奏 (v4)
   ======================================== */

/* row 栅格内的卡片去掉自身 margin-bottom：行间距统一由 row 的 g-*/mb-* 管理，
   消除"卡片 margin + row margin 叠加"造成的区块间距忽大忽小（统计页 44~84px 跳动） */
.row > [class*="col"] > .card { margin-bottom: 0; }

/* 长表单提交栏吸底：填表过程中保存按钮始终可达，不随内容滚出首屏 */
.form-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    background: var(--bg-panel);
    border-top: 1px solid var(--border-light);
    padding: 0.75rem 1.1rem;
    margin: 1rem -1.1rem -1.1rem;
    border-radius: 0 0 var(--radius) var(--radius);
}

/* ========================================
   列表工具栏组件 (v4)
   ======================================== */
/* 统一拼法：筛选控件在左（等宽分布）、主操作在右。
   所有列表页共用；配合 templates/_macros.html 的 list_toolbar/toolbar_actions 宏使用。
   手机端筛选控件换行为两列、主操作独占一行 */
.list-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.65rem 0.75rem;
    margin-bottom: 1.25rem;
}
/* 直接作为工具栏内容的 GET 表单：摊平自身盒子，让控件直接参与 flex 布局 */
.list-toolbar > form { display: contents; }
/* 筛选控件等宽伸缩；按钮保持固有尺寸 */
.list-toolbar .form-control,
.list-toolbar .form-select,
.list-toolbar .input-group { flex: 1 1 180px; min-width: 0; }
.list-toolbar .btn { flex: 0 0 auto; }
.list-toolbar .form-check { margin-bottom: 0; }
/* 右侧主操作区 */
.toolbar-actions {
    margin-left: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}
@media (max-width: 768px) {
    .list-toolbar .form-control,
    .list-toolbar .form-select,
    .list-toolbar .input-group { flex: 1 1 150px; }
    .toolbar-actions { margin-left: 0; width: 100%; }
    .toolbar-actions .btn { flex: 1 1 auto; }
}

/* KPI 卡：手机端 2×2 网格兜底（模板用 col-6 时此规则自动生效，防止单列堆叠） */
@media (max-width: 768px) {
    .stat-card .card-body { padding: 0.85rem 0.9rem; }
    .stat-card h3 { font-size: 1.35rem; }
}

/* ---------- 交互与移动端基础（Web Interface Guidelines） ---------- */
button, a, input, select, textarea {
    touch-action: manipulation;
}

html {
    -webkit-tap-highlight-color: transparent;
}

.sidebar {
    overscroll-behavior: contain;
    padding-bottom: env(safe-area-inset-bottom);
}

.reg-table-wrap {
    overscroll-behavior-x: contain;
}

