/* ============================================================
   森创MES云平台 · 工业风视觉基线（P1）+ 移动端 H5 适配层
   Bootstrap 5 基础上：设计令牌 + 直角/描边/状态色工业风
   移动端优先（320px–430px），向上兼容桌面
   ============================================================ */

/* ---------- 0. 设计令牌（工业风基线） ---------- */
:root {
    /* 中性钢色 */
    --ink: #101820;
    --ink-2: #24303C;
    --ink-3: #4A5662;
    --muted: #66707A;
    --steel: #16212B;       /* 深色导航底 */
    --steel-2: #1E2C38;     /* 导航选中底 */
    --steel-line: #2C3B49;  /* 导航分割线 */
    --line: #D3DAE1;        /* 面板描边 */
    --line-strong: #AFBAC5; /* 控件描边 */
    --line-soft: #E6EBEF;   /* 行分割线 */
    --bg: #EDF1F4;          /* 工作面背景 */
    --panel-2: #F7F9FA;     /* 次级底色 */
    /* 主色：工业蓝 */
    --primary: #1A5C96;
    --primary-2: #0F466F;
    --primary-soft: #E7F0F8;
    --accent: #4C9BE8;      /* 深色导航上的强调色 */
    /* 状态四色：正常 / 进行中 / 异常 / 停用 */
    --ok: #1F7A45;   --ok-soft: #E6F4EC;
    --run: #B06E00;  --run-soft: #FDF3E1;
    --err: #B42318;  --err-soft: #FBEAE8;
    --off: #66707A; --off-soft: #EEF1F3;
    --r: 2px;
    --mono: "Cascadia Mono", Consolas, "Roboto Mono", monospace;
    /* Bootstrap 主色/链接色对齐工业蓝（链接、复选框等随之统一） */
    --bs-primary: #1A5C96;
    --bs-primary-rgb: 26, 92, 150;
    --bs-link-color: #1A5C96;
    --bs-link-hover-color: #0F466F;
}

/* ---------- 1. 全局基础与浏览器样式统一 ---------- */

/* 禁止横屏转动 / 字体缩放时的文本抖动，统一各品牌浏览器文本缩放行为 */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh; /* 修复移动端地址栏收起/展开导致的 100vh 抖动 */
    background-color: var(--bg);
    font-size: 16px; /* ≥16px：避免 iOS Safari 聚焦输入框时自动放大页面 */
    line-height: 1.45;
    overflow-x: hidden; /* 兜底禁止横向滚动 */
}

/* 去除移动端浏览器点按高亮（各品牌差异来源之一） */
* {
    -webkit-tap-highlight-color: transparent;
    tap-highlight-color: transparent;
}

/* 触控优化：
   1) touch-action: manipulation 消除 300ms 点击延迟与双击缩放
   2) 原生控件去除系统默认外观（appearance），统一各品牌浏览器显示 */
a,
button,
[role="button"],
label,
input,
select,
textarea,
.form-check-input,
.btn,
.nav-link {
    touch-action: manipulation;
}

input,
select,
textarea,
button {
    font: inherit;
    font-size: 16px;
    color: inherit;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
    -webkit-appearance: none;
    appearance: none;
}

/* select 保留自绘下拉箭头，保证去除原生外观后仍可辨识 */
select.form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right .75rem center;
    background-size: 16px 12px;
}

/* 安全区适配（刘海屏 / 底部手势条） */
.app-content {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}

/* ---------- 2. 按钮尺寸基线（桌面紧凑、手机保持 44px 触控热区） ---------- */

.btn {
    min-height: 38px;
    border-radius: var(--r); /* 工业风：直角按钮 */
    font-weight: 600;
    letter-spacing: .02em;
}

/* 紧凑组件：小按钮、分段切换、表格操作不被全局最小高度撑大 */
.btn-sm,
.seg.btn-group > .btn,
.admin-actions .btn {
    min-height: 0;
}

@media (max-width: 991.98px) {
    /* 手机上普通按钮保持 44px 触控热区，紧凑组件除外 */
    .btn:not(.btn-sm):not(.btn-close) {
        min-height: 44px;
    }
}

/* 关闭按钮通过 padding 扩大点击热区，视觉大小不变 */
.btn-close {
    padding: .625rem;
    background-position: center;
}

.form-control,
.form-select {
    min-height: 44px;
    border-radius: var(--r);
    border-color: var(--line-strong);
}

/* 聚焦：工业蓝描边 + 3px 光晕 */
.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 92, 150, .12);
}

.form-control-lg,
.form-select-lg {
    min-height: 50px;
}

/* 紧凑控件：与 .btn-sm 统一为 31px，保证筛选条内输入框/下拉/按钮同高对齐 */
.form-control-sm,
.form-select-sm {
    height: 31px;
    min-height: 31px;
    padding-top: .25rem;
    padding-bottom: .25rem;
}

/* 筛选条按钮禁止文字换行，避免小屏宽度不足时图标/文字竖排，把按钮撑得比输入框高 */
.filter-form .btn {
    white-space: nowrap;
}

/* 分页：工业风直角、紧凑尺寸，激活页用主色 */
.pagination {
    --bs-pagination-border-radius: 0;
    --bs-pagination-active-bg: var(--primary);
    --bs-pagination-active-border-color: var(--primary);
}
.page-link {
    border-radius: 0;
    font-weight: 600;
    padding: .3rem .65rem;
}
.page-link:focus {
    box-shadow: 0 0 0 3px rgba(26, 92, 150, .12);
}

textarea.form-control {
    min-height: 44px;
}

/* 开关（admin 表单）加大到符合触控标准 */
.form-switch .form-check-input {
    width: 2.75em;
    height: 1.375em;
    margin-top: 0;
    cursor: pointer;
}

.form-check-input {
    width: 1.25rem;
    height: 1.25rem;
    margin-top: 0;
    flex-shrink: 0;
}

/* ---------- 3. 顶栏 + 抽屉导航（替代桌面端固定侧边栏） ---------- */

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    background-color: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: .5rem;
    min-height: 56px;
    padding: .375rem .75rem;
    padding-top: calc(.375rem + env(safe-area-inset-top));
}

/* 汉堡菜单按钮：44×44 热区 */
.topbar-btn {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: #212529;
    border-radius: var(--r);
    flex-shrink: 0;
}

.topbar-btn:active {
    background-color: rgba(26, 92, 150, .12);
}

.topbar-title {
    font-weight: 700;
    letter-spacing: .01em;
    font-size: 1.0625rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    font-size: .8125rem;
    color: #6c757d;
    min-width: 0;
    max-width: 40%; /* 给页面标题留出空间，姓名过长时在内部省略 */
    flex: 0 1 auto;
    overflow: hidden;
    white-space: nowrap;
}

/* 姓名过长：单行省略，不撑破顶栏 */
.user-chip .user-name {
    display: inline-block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 角色徽章始终完整显示，只压缩姓名 */
.user-chip .badge {
    flex-shrink: 0;
}

.topbar-logout {
    width: 44px;
    height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* 抽屉导航宽度：小屏不超过 85% 视口 */
.offcanvas.app-drawer {
    --bs-offcanvas-width: min(85vw, 320px);
    background-color: var(--steel);
    color: #fff;
}

.app-drawer .drawer-brand {
    font-weight: 600;
    letter-spacing: 1px;
    padding: .875rem .875rem;
    border-bottom: 1px solid var(--steel-line);
}

/* 品牌区：LOGO 为白底无透明通道，放在深色抽屉上时用白色圆角底衬托 */
.app-drawer .brand-link {
    color: #fff;
    min-width: 0;
}

.app-drawer .brand-logo-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    background: #fff;
    border-radius: var(--r);
    padding: 2px;
    height: 34px;
    width: 34px;
}

.app-drawer .brand-logo {
    display: block;
    max-height: 100%;
    max-width: 100%;
    height: auto;
    width: auto;
    object-fit: contain;
}

/* 品牌文字：名称 + 英文副标（工业风标识） */
.app-drawer .brand-text {
    margin-left: .5rem;
    min-width: 0;
}

.app-drawer .brand-name {
    display: block;
    font-size: 1.02rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-drawer .brand-sub {
    display: block;
    margin-top: 1px;
    font-size: .5625rem;
    font-weight: 600;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: #6F7E8C;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 430px) {
    .app-drawer .brand-logo-wrap {
        height: 28px;
        width: 28px;
        border-radius: 6px;
    }

    .app-drawer .brand-name {
        font-size: .98rem;
        letter-spacing: .5px;
    }

    .app-drawer .brand-sub {
        font-size: .5rem;
        letter-spacing: .12em;
    }
}

/* 登录页品牌区 */
.login-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .6rem;
}

.login-brand-logo {
    height: 40px;
    width: auto;
    max-width: 72px;
    object-fit: contain;
    border-radius: var(--r);
    border: 1px solid var(--line);
    padding: 2px;
    background: #fff;
}

.login-brand-name {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: .04em;
}

.app-drawer .nav-link {
    color: #fff;
    border-radius: var(--r);
    padding: .8125rem .875rem; /* 行高 ≈48px，满足触控标准 */
    margin-bottom: .125rem;
    display: flex;
    align-items: center;
    min-height: 48px;
}

/* 用 active / :active 替代桌面端 hover 反馈 */
.app-drawer .nav-link:active {
    background-color: rgba(255, 255, 255, .14);
}

/* 选中态：钢色底 + 左侧 3px 强调条（inset 阴影不占布局） */
.app-drawer .nav-link.active {
    background-color: var(--steel-2);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--accent);
}

.app-drawer .nav-link.text-white-50 {
    color: rgba(255, 255, 255, .65) !important;
    font-size: .9375rem;
    min-height: 44px;
    padding: .5625rem .875rem;
}

.app-drawer .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
    margin-right: .5rem;
}

/* ---------- 4. 桌面端（≥ lg / 992px）：同一个抽屉转为固定侧边栏 ---------- */
/* 说明：窄屏保持原有的顶栏 + 抽屉导航；宽屏仅用媒体查询改变同一份 DOM 的定位，
   不新增第二套导航，保证两种形态行为与选中态逻辑完全一致。 */

@media (min-width: 992px) {
    /* 宽屏无需汉堡按钮，导航常驻可见 */
    .app-topbar .topbar-btn {
        display: none;
    }

    /* 抽屉 -> 固定左侧栏：取消位移与隐藏，改为常驻 */
    .offcanvas.app-drawer {
        --bs-offcanvas-width: 260px;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 260px;
        transform: none;
        visibility: visible;
        border-right: 1px solid rgba(0, 0, 0, .15);
    }

    /* 侧边栏常驻时不需要关闭按钮 */
    .app-drawer .drawer-brand .btn-close {
        display: none;
    }

    .app-drawer .offcanvas-body {
        padding: .75rem;
        overflow-y: auto;
    }

    /* 桌面端补上鼠标悬停反馈（触摸端仍由 :active 承担） */
    .app-drawer .nav-link:hover {
        background-color: rgba(255, 255, 255, .1);
    }

    .app-drawer .nav-link.active:hover {
        background-color: var(--steel-2);
    }

    /* 内容区让出侧边栏宽度 */
    .app-wrapper {
        margin-left: 260px;
    }

    /* 宽屏内容不再贴边，保留舒适阅读宽度 */
    .app-wrapper .app-content {
        padding: 1.25rem 1.5rem 0;
        max-width: 1200px;
    }
}

/* ---------- 5. 页面内容区 ---------- */

.app-content {
    padding: .875rem .875rem 0;
}

@media (min-width: 576px) {
    .app-content {
        padding: 1rem 1rem 0;
    }
}

/* 登录等未认证页面容器 */
.auth-wrap {
    padding: 1.5rem 1rem calc(2rem + env(safe-area-inset-bottom));
}

/* ---------- 6. 数据展示：表格转移动端列表 ---------- */

/* 通用记录列表（装配看板 / 换件历史 / 追溯结果 / 后台数据） */
.record-list {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.record-item {
    background-color: #fff;
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: .625rem .75rem;
}

.record-item.is-active {
    border-color: rgba(31, 122, 69, .45);
    background-color: var(--ok-soft);
}

.record-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .375rem;
    font-size: .9375rem;
}

.record-note {
    margin-top: .25rem;
    font-size: .8125rem;
    color: #6c757d;
    word-break: break-all;
}

/* 追溯查询：现役部件（正常色系）与安装历史（中性灰）分块区分 */
.trace-block {
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: .625rem .75rem;
    margin-bottom: .75rem;
}

.trace-block:last-child {
    margin-bottom: 0;
}

.trace-block-title {
    display: flex;
    align-items: center;
    gap: .375rem;
    font-weight: 700;
    font-size: .9375rem;
    margin-bottom: .5rem;
}

.trace-block-active {
    border-color: rgba(31, 122, 69, .45);
    background-color: var(--ok-soft);
}

.trace-block-active .trace-block-title {
    color: var(--ok);
}

.trace-block-history {
    border-color: var(--line-strong);
    background-color: #F5F7F9;
}

.trace-block-history .trace-block-title {
    color: var(--muted);
}

/* 现役条目更紧凑：只留头部标识，无明细行 */
.trace-active-item {
    padding: .5rem .625rem;
}

/* 工位装配看板条目 */
.slot-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    background-color: #fff;
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: .625rem .75rem;
    min-height: 56px;
}

.slot-item .slot-seq {
    width: 1.75rem;
    height: 1.75rem;
    flex-shrink: 0;
    border-radius: var(--r);
    background-color: var(--off-soft);
    color: var(--muted);
    font-size: .8125rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.slot-item.is-done .slot-seq {
    background-color: var(--ok);
    color: #fff;
}

.slot-item .slot-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: .125rem;
}

.slot-item .slot-name {
    font-size: .9375rem;
    font-weight: 500;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .375rem;
}

.slot-item .slot-comp {
    font-size: .8125rem;
    color: #6c757d;
    word-break: break-all;
}

/* 换件位置选择列表（整行可点，热区 ≥48px） */
.pick-list {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.pick-item {
    display: flex;
    align-items: center;
    gap: .625rem;
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: .625rem .75rem;
    min-height: 48px;
    cursor: pointer;
}

.pick-item:has(.form-check-input:checked) {
    border-color: var(--primary);
    background-color: var(--primary-soft);
}

.pick-item .pick-main {
    flex: 1;
    min-width: 0;
    font-size: .9375rem;
}

/* 长部件码省略显示，不挤占整行操作区域 */
.pick-item .badge {
    max-width: 45%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* 后台管理数据卡片 */
.data-card {
    background-color: #fff;
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: .75rem .875rem;
}

.data-card + .data-card {
    margin-top: .5rem;
}

.data-card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .375rem;
}

.data-card-meta {
    margin-top: .25rem;
    font-size: .8125rem;
    color: #6c757d;
    word-break: break-all;
}

.data-card-actions {
    display: flex;
    gap: .5rem;
    margin-top: .625rem;
}

/* 按钮按内容宽度伸展，避免 4 个操作在小屏被压成竖排文字 */
.data-card-actions .btn {
    flex: 1 1 auto;
    white-space: nowrap;
}

/* 首页统计卡片图标：小屏下适当缩小，避免拥挤 */
.stat-icon {
    font-size: 1.75rem;
    flex-shrink: 0;
}

.min-w-0 {
    min-width: 0;
}

/* 兜底：仍保留 table 的场景，允许容器内横向滑动，不撑破页面 */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* 表格：工业风紧凑基线（表头小号大写、浅灰底、细分割线） */
.table {
    font-size: .8125rem;
}

.table th {
    font-size: .6875rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #5A6672;
    background-color: #F2F5F7;
}

.table th,
.table td {
    border-color: var(--line-soft);
}

.table thead th {
    border-bottom-color: var(--line);
}

/* ---------- 7. 表单与按钮的移动端优化 ---------- */

/* 主操作按钮仅在手机上通栏；桌面保持常规尺寸 */
@media (max-width: 991.98px) {
    .btn-block-mobile {
        width: 100%;
    }
}

/* 表单项间距：留白略大于桌面，避免小屏拥挤 */
.form-label {
    margin-bottom: .375rem;
    font-size: .9375rem;
}

/* 扫码输入：等宽字体，强化"数据录入"属性 */
.scan-input {
    font-family: var(--mono);
    font-size: 1.0625rem;
    letter-spacing: .08em;
}

/* ---------- 8. 极小屏（320px）微调 ---------- */

@media (max-width: 360px) {
    .user-chip .user-name {
        display: none; /* 顶栏只留角色徽章，避免 320px 下溢出 */
    }

    .slot-item {
        gap: .5rem;
        padding: .5rem .625rem;
    }

    .record-head,
    .slot-item .slot-name {
        font-size: .875rem;
    }
}

/* ---------- 9. 键盘可访问性（触摸为主，不放弃键盘） ---------- */

.btn:focus-visible,
.nav-link:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.form-check-input:focus-visible,
.topbar-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ============================================================
   10. 工业风组件基线（P1）：卡片 / 徽章 / 按钮 / 提示 / 脚标
   ============================================================ */

/* 卡片：直角、1px 描边、无投影；卡片头为浅灰"面板头" */
.card {
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: none;
}

.card-header {
    padding: .625rem .875rem;
    background-color: #FBFCFD;
    border-bottom: 1px solid var(--line);
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: .04em;
    color: var(--ink-2);
}

.card-header .bi {
    color: var(--primary-2);
}

.card-title {
    font-weight: 700;
}

/* 返修"确认换件"卡片头：琥珀软底，替代亮黄 */
.card-header.text-bg-warning {
    background-color: var(--run-soft) !important;
    color: #6B4A00 !important;
    border-bottom: 1px solid #EAD8B7;
}

/* 徽章：直角 + 状态软底色 */
.badge {
    border-radius: var(--r);
    font-weight: 700;
    letter-spacing: .02em;
}

.badge.text-bg-success { background-color: var(--ok-soft) !important; color: var(--ok) !important; }
.badge.text-bg-warning { background-color: var(--run-soft) !important; color: var(--run) !important; }
.badge.text-bg-danger { background-color: var(--err-soft) !important; color: var(--err) !important; }
.badge.text-bg-secondary { background-color: var(--off-soft) !important; color: var(--off) !important; }
.badge.text-bg-info { background-color: var(--primary-soft) !important; color: var(--primary-2) !important; }

/* 待装配：中性描边徽章（派生展示态，区别于停用灰） */
.badge.badge-pending {
    background-color: var(--panel-2);
    color: var(--ink-2);
    border: 1px solid var(--line-strong);
}
.badge.text-bg-primary { background-color: var(--primary) !important; color: #fff !important; }
.badge.text-bg-dark { background-color: var(--steel) !important; color: #fff !important; }
.badge.text-bg-light {
    background-color: #fff !important;
    color: var(--ink-2) !important;
    border: 1px solid var(--line-strong);
}

/* 四态徽章前置圆点：状态一眼可辨（信息/标签类不加圆点） */
.badge.text-bg-success::before,
.badge.text-bg-warning::before,
.badge.text-bg-danger::before,
.badge.text-bg-secondary::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    margin-right: 5px;
    vertical-align: 1px;
}

/* 按钮：主/描边按钮对齐工业蓝色板 */
.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary-2);
    --bs-btn-hover-bg: var(--primary-2);
    --bs-btn-hover-border-color: var(--primary-2);
    --bs-btn-active-bg: var(--primary-2);
    --bs-btn-active-border-color: var(--primary-2);
    --bs-btn-disabled-bg: var(--primary);
    --bs-btn-disabled-border-color: var(--primary-2);
    --bs-btn-focus-shadow-rgb: 26, 92, 150;
}

.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-2);
    --bs-btn-hover-border-color: var(--primary-2);
    --bs-btn-active-bg: var(--primary-2);
    --bs-btn-active-border-color: var(--primary-2);
    --bs-btn-disabled-color: var(--primary);
    --bs-btn-disabled-border-color: var(--primary);
}

.btn-outline-secondary {
    --bs-btn-color: var(--ink-3);
    --bs-btn-border-color: var(--line-strong);
    --bs-btn-hover-color: var(--ink);
    --bs-btn-hover-bg: var(--panel-2);
    --bs-btn-hover-border-color: var(--line-strong);
    --bs-btn-active-bg: var(--panel-2);
    --bs-btn-active-border-color: var(--line-strong);
}

.btn-outline-danger {
    --bs-btn-color: var(--err);
    --bs-btn-border-color: #E0B4AF;
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--err);
    --bs-btn-hover-border-color: var(--err);
    --bs-btn-active-bg: var(--err);
    --bs-btn-active-border-color: var(--err);
}

.btn-outline-success {
    --bs-btn-color: var(--ok);
    --bs-btn-border-color: #9CCDB4;
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--ok);
    --bs-btn-hover-border-color: var(--ok);
    --bs-btn-active-bg: var(--ok);
    --bs-btn-active-border-color: var(--ok);
}

/* 提示条 / 复选框对齐基线 */
.alert {
    border-radius: var(--r);
}

.form-check-input:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* 首页看板统计图标 */
.stat-icon.text-primary {
    color: var(--primary) !important;
}

/* 抽屉底部：工业面板脚标（版本/版权） */
.app-drawer .offcanvas-body {
    display: flex;
    flex-direction: column;
}

.app-drawer .drawer-foot {
    margin-top: auto;
    padding: .75rem .875rem .25rem;
    border-top: 1px solid var(--steel-line);
    font-size: .6875rem;
    color: #6F7E8C;
    letter-spacing: .08em;
}

/* ============================================================
   11. 工业风页面布局（P2）：页头工具条 / KPI / 双栏工作台 / 手机底部操作条
   ============================================================ */

/* 页头工具条：左侧范围标识，右侧范围切换 */
.page-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem;
    margin-bottom: .75rem;
}

.page-bar .page-bar-sub {
    font-size: .8125rem;
    color: var(--muted);
}

/* 分段切换（时间范围 / 统计维度）：连体直角按钮，选中为钢色 */
.seg.btn-group > .btn {
    border-radius: 0;
    padding: .3125rem .75rem;
    font-size: .8125rem;
    font-weight: 600;
    white-space: nowrap;
}

.seg.btn-group > .btn:first-child {
    border-top-left-radius: var(--r);
    border-bottom-left-radius: var(--r);
}

.seg.btn-group > .btn:last-child {
    border-top-right-radius: var(--r);
    border-bottom-right-radius: var(--r);
}

.seg.btn-group > .btn.active,
.seg.btn-group > .btn.active:hover {
    background-color: var(--steel);
    border-color: var(--steel);
    color: #fff;
}

/* KPI 指标卡：左侧状态条 + 大号等宽数字 */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .5rem;
    margin-bottom: .75rem;
}

@media (min-width: 768px) {
    .kpi-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: .75rem;
    }
}

/* 卡片为奇数张时，最后一张跨两列补满末行（7 张：手机 2 列收成 4 行、桌面 4 列收成 4+3），
   避免最后一行只剩一张卡导致排布留白；不改变每张卡的可读宽度 */
.kpi-grid > .kpi-card:last-child:nth-child(odd) {
    grid-column: span 2;
}

.kpi-card {
    --kpi: var(--primary);
    position: relative;
    display: flex;
    align-items: center;
    gap: .625rem;
    min-width: 0;
    padding: .75rem .75rem .75rem .875rem;
    background-color: #fff;
    border: 1px solid var(--line);
    border-radius: var(--r);
    overflow: hidden;
}

.kpi-card::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background-color: var(--kpi);
}

.kpi-card .kpi-icon {
    flex-shrink: 0;
    font-size: 1.5rem;
    line-height: 1;
    color: var(--kpi);
}

.kpi-card .kpi-body {
    min-width: 0;
}

.kpi-card .kpi-label {
    font-size: .6875rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
}

.kpi-card .kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.15;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

/* 保留旧模板节点 class（测试依赖），字号由 KPI 卡统一控制 */
.kpi-card .kpi-value .fs-5 {
    font-size: inherit !important;
}

.kpi-card.kpi-ok { --kpi: var(--ok); }
.kpi-card.kpi-run { --kpi: var(--run); }
.kpi-card.kpi-steel { --kpi: var(--steel); }

/* 工作台双栏：左操作 / 右信息（≥992px） */
.work-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: .75rem;
}

@media (min-width: 992px) {
    .work-grid {
        grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
        align-items: start;
    }
}

.work-col {
    display: flex;
    flex-direction: column;
    gap: .75rem;
    min-width: 0;
}

/* 查询行：桌面输入框与按钮同排，手机上按钮通栏 */
.query-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: .5rem;
}

@media (min-width: 576px) {
    .query-row {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: end;
    }

    /* 查询按钮按内容自适应宽度，与大号扫码输入框底边对齐 */
    .query-row > .btn {
        height: 50px;          /* 与 .form-control-lg 同高，避免同排时按钮比输入框矮 */
        padding-left: 1.25rem;
        padding-right: 1.25rem;
        white-space: nowrap;
    }
}

/* 扫码步骤：编号 + 标签 + 输入框 */
.scan-step {
    margin-bottom: .75rem;
}

.scan-step:last-child {
    margin-bottom: 0;
}

.scan-step .scan-step-label {
    display: flex;
    align-items: center;
    gap: .375rem;
    margin-bottom: .375rem;
    font-size: .8125rem;
    font-weight: 700;
    color: var(--ink-2);
}

.scan-step .scan-step-no,
.form-label .scan-step-no {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: var(--r);
    background-color: var(--steel);
    color: #fff;
    font-size: .6875rem;
    font-weight: 700;
    vertical-align: -2px;
}

.form-label .scan-step-no {
    margin-right: .25rem;
}

/* 槽位看板：桌面端按行排列（序号 / 安装位置 / 部件），手机保持卡片 */
.slot-head {
    display: none;
}

@media (min-width: 992px) {
    .slot-head {
        display: grid;
        grid-template-columns: 1.75rem minmax(0, 1.1fr) minmax(0, 1fr);
        gap: .75rem;
        padding: .375rem .75rem;
        border-bottom: 1px solid var(--line-soft);
        font-size: .6875rem;
        font-weight: 700;
        letter-spacing: .06em;
        text-transform: uppercase;
        color: #5A6672;
    }

    .slot-head span:last-child {
        text-align: right;
    }

    .slot-board .slot-item {
        display: grid;
        grid-template-columns: 1.75rem minmax(0, 1.1fr) minmax(0, 1fr);
        align-items: center;
        gap: .75rem;
        min-height: 48px;
        padding: .5rem .75rem;
    }

    .slot-board .slot-item .slot-main {
        display: contents;
    }

    .slot-board .slot-item .slot-name {
        font-size: .875rem;
    }

    .slot-board .slot-item .slot-comp {
        overflow: hidden;
        text-align: right;
        font-size: .8125rem;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
}

/* 信息卡内的键值说明 */
.info-meta {
    font-size: .8125rem;
    line-height: 1.7;
    color: var(--muted);
}

/* 空态 */
.empty-state {
    padding: 1.5rem .75rem;
    text-align: center;
    font-size: .875rem;
    color: var(--muted);
}

/* 看板汇总表：数字列等宽右对齐 */
.dash-table td,
.dash-table th {
    padding: .5rem .625rem;
}

.dash-table .num {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* 手机底部固定操作条（扫码 / 换件） */
.mobile-actionbar {
    display: none;
}

@media (max-width: 991.98px) {
    .mobile-actionbar {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .5rem;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1030;
        padding: .5rem .75rem calc(.5rem + env(safe-area-inset-bottom));
        background-color: rgba(255, 255, 255, .97);
        border-top: 1px solid var(--line-strong);
    }

    .mobile-actionbar > .btn {
        min-height: 46px;
        font-size: .9375rem;
        font-weight: 700;
    }

    .mobile-actionbar.actionbar-single {
        grid-template-columns: minmax(0, 1fr);
    }

    body.has-actionbar .app-content {
        padding-bottom: calc(76px + env(safe-area-inset-bottom));
    }
}

/* 返修：尚未查询产品时，历史卡占满整行 */
@media (min-width: 992px) {
    .work-grid:has(#replaceCard.d-none) .repair-history {
        grid-column: 1 / -1;
    }
}

/* ============================================================
   12. 后台列表（P3）：桌面表格 + 手机卡片 + 页内 Tab
   ============================================================ */

/* 页内 Tab：角色 / 工位规则 / 产品条码规则 */
.page-tabs {
    display: flex;
    margin-bottom: .75rem;
    border-bottom: 1px solid var(--line-strong);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.page-tabs .page-tab {
    flex: 0 0 auto;
    padding: .625rem .875rem;
    border: 1px solid transparent;
    border-bottom: none;
    color: var(--ink-3);
    font-size: .8125rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.page-tabs .page-tab:hover {
    color: var(--ink);
}

.page-tabs .page-tab.active {
    background-color: #fff;
    border-color: var(--line-strong);
    color: var(--primary-2);
    box-shadow: inset 0 3px 0 var(--primary);
}

@media (max-width: 575.98px) {
    .page-tabs .page-tab {
        padding: .5rem .625rem;
        font-size: .75rem;
    }
}

/* 桌面表格：固定布局 + 单元格省略，保证不撑破内容区 */
.admin-table {
    width: 100%;
    table-layout: fixed;
}

.admin-table th,
.admin-table td {
    padding: .5rem .5rem;
    vertical-align: middle;
}

.admin-table th {
    white-space: nowrap;
}

.admin-table .cell-ellipsis {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.admin-table .cell-wrap {
    overflow-wrap: anywhere;
}

/* 表格内操作按钮：紧凑排列，必要时换行，不遮挡 */
.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
}

.admin-actions .btn {
    padding: .25rem .5rem;
    font-size: .75rem;
    line-height: 1.3;
}

.admin-actions form {
    display: flex;
}

/* 卡片列表按断点切换：桌面显示表格，手机显示卡片 */
@media (min-width: 992px) {
    .admin-mobile-list {
        display: none !important;
    }
}

@media (max-width: 991.98px) {
    .admin-desktop-table {
        display: none !important;
    }
}

/* ============================================================
   13. 登录 / PIN / 打印（P4）
   ============================================================ */

/* 登录页：桌面左右分栏（深色品牌 + 浅色表单），手机单列 */
.login-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    background-color: #fff;
    border: 1px solid var(--line);
    border-radius: var(--r);
    overflow: hidden;
}

@media (min-width: 768px) {
    .login-shell {
        grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr);
        min-height: 520px;
    }
}

.login-aside {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    padding: 2.25rem 1.75rem;
    color: #fff;
    background-color: var(--steel);
    background-image: linear-gradient(160deg, #1E2C38 0%, #101820 100%);
}

@media (min-width: 768px) {
    .login-aside {
        display: flex;
    }
}

.login-aside-logo {
    height: 52px;
    width: auto;
    max-width: 88px;
    object-fit: contain;
    background-color: #fff;
    border-radius: var(--r);
    padding: 3px;
}

.login-aside-name {
    margin-top: 1rem;
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: .06em;
}

.login-aside-sub {
    margin-top: .25rem;
    font-size: .6875rem;
    letter-spacing: .22em;
    color: var(--accent);
}

.login-aside-line {
    width: 36px;
    height: 3px;
    margin-bottom: .875rem;
    background-color: var(--accent);
}

.login-aside-foot {
    font-size: .75rem;
    line-height: 1.7;
    letter-spacing: .06em;
    color: #8FA0B0;
}

.login-main {
    padding: 1.75rem 1.5rem 2rem;
}

@media (min-width: 768px) {
    .login-main {
        padding: 2.5rem;
    }
}

.login-brand-row {
    display: flex;
    align-items: center;
    gap: .625rem;
    margin-bottom: 1.5rem;
}

.login-mini-logo {
    height: 38px;
    width: auto;
    max-width: 64px;
    object-fit: contain;
    background-color: #fff;
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 2px;
}

.login-mini-name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
}

.login-mini-sub {
    font-size: .625rem;
    letter-spacing: .16em;
    color: var(--muted);
}

.login-title {
    margin-bottom: .25rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--ink);
}

.login-desc {
    margin-bottom: 1.5rem;
    font-size: .8125rem;
    color: var(--muted);
}

.login-hint {
    margin-top: 1rem;
    padding-left: .625rem;
    border-left: 2px solid var(--line-strong);
    font-size: .75rem;
    line-height: 1.7;
    color: var(--muted);
}

/* 扫码 PIN 页 */
.auth-center {
    display: flex;
    justify-content: center;
    padding-top: 1rem;
}

.pin-card {
    width: 100%;
    max-width: 380px;
}

.pin-head {
    margin-bottom: 1rem;
    text-align: center;
}

.pin-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin: 0 auto .5rem;
    border: 1px solid var(--line);
    border-radius: var(--r);
    background-color: var(--primary-soft);
    color: var(--primary);
    font-size: 1.25rem;
}

.pin-title {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--ink);
}

.pin-account {
    margin-top: .25rem;
    font-size: .875rem;
    color: var(--ink-2);
}

.pin-sub {
    margin-top: .25rem;
    font-size: .8125rem;
    color: var(--muted);
}

.pin-boxes {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .5rem;
}

.pin-boxes .pin-box {
    height: 56px;
    padding: 0;
    text-align: center;
    font-family: var(--mono);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: .1em;
}

/* 二维码打印页 */
.print-page {
    max-width: 520px;
    margin: 0 auto;
}

.print-head {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .875rem 1rem;
    border-bottom: 1px solid var(--line);
}

.print-head .print-logo {
    height: 34px;
    width: auto;
    max-width: 60px;
    object-fit: contain;
}

.print-head .print-title {
    font-size: .875rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--ink);
}

.print-head .print-sub {
    font-size: .625rem;
    letter-spacing: .16em;
    color: var(--muted);
}

.print-body {
    padding: 1.25rem 1rem;
    text-align: center;
}

.print-qr {
    width: 100%;
    max-width: 240px;
    height: auto;
}

.print-user {
    margin-top: .75rem;
    font-size: .8125rem;
    color: var(--ink-2);
}

.print-tip {
    margin-top: .5rem;
    font-size: .8125rem;
    font-weight: 600;
    color: var(--ink);
}

.print-warn {
    margin-top: .25rem;
    font-size: .6875rem;
    color: var(--muted);
}

.print-url {
    margin-top: .75rem;
    font-size: .6875rem;
    color: var(--muted);
    word-break: break-all;
}

.print-pin {
    margin: 0 1rem 1.25rem;
    padding: .75rem;
    border: 1px dashed #D9B877;
    background-color: var(--run-soft);
    font-size: .8125rem;
    line-height: 1.7;
    color: #6B4A00;
}

.print-pin .pin-digits {
    font-family: var(--mono);
    font-size: 1.5rem;
    letter-spacing: .4rem;
    color: var(--ink);
}

/* 打印：仅保留工牌卡片，A4 不跨页 */
@media print {
    @page {
        size: A4 portrait;
        margin: 12mm;
    }

    .app-topbar,
    .app-drawer,
    .d-print-none,
    .alert,
    .btn {
        display: none !important;
    }

    .app-wrapper,
    .app-content {
        display: block !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    body {
        background-color: #fff !important;
    }

    .print-page {
        max-width: none;
        margin: 0;
    }

    .print-ticket {
        max-width: 100mm;
        margin: 0 auto;
        border: 1px solid #101820 !important;
        box-shadow: none !important;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .print-body {
        padding: 6mm;
    }

    .print-qr {
        max-width: 70mm;
    }
}
