/* =========================================================
   主题变量：全站浅色
   ========================================================= */
:root {
    --app-topbar-h: 56px;
    --app-sidebar-w: 236px;
    --app-bg: #f4f6fa;
    --app-surface: #ffffff;
    --app-border: #e2e8f0;
    --app-text: #334155;
    --app-text-soft: #64748b;
    --app-primary: #2563eb;
    --app-primary-soft: #e8f0ff;
}

html {
    background: var(--app-bg);
}

body.app-body {
    background: var(--app-bg);
    color: var(--app-text);
}

/* ---------- 通用 ---------- */
.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex: 0 0 44px;
}

.table > :not(caption) > * > * {
    padding: 0.65rem 0.75rem;
}

/* 中文表头/单元格不折行：宁可容器内横向滚动，也避免被逐字挤成竖排 */
.app-content table.table th,
.app-content table.table td {
    white-space: nowrap;
}

/* 仪表盘卡片内的表格列多而窄：宽屏允许折行，避免右侧列被裁掉 */
.app-content .dashboard-grid table.table th,
.app-content .dashboard-grid table.table td {
    white-space: normal;
}

/* 笔记本宽度（<1366px）收紧表格密度，让「操作」列尽量不被挤出可视区 */
@media (max-width: 1365.98px) {
    .app-content table.table {
        font-size: 0.9rem;
    }

    .app-content table.table > :not(caption) > * > * {
        padding: 0.55rem 0.55rem;
    }
}

/* =========================================================
   应用外壳：固定首行 + 左侧导航 + 右侧主内容
   - 首行 fixed：内容滚动时不动
   - 侧栏 fixed 且 top 从首行底部开始（不含首行）
   - ≥992px 侧栏常驻，<992px 侧栏变抽屉（遮罩）
   ========================================================= */
.app-shell {
    min-height: 100vh;
}

/* ---------- 首行 ---------- */
.app-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1050;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    height: var(--app-topbar-h);
    padding: 0 0.9rem;
    background: #1e293b;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 1px 6px rgba(15, 23, 42, 0.2);
}

.app-topbar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 0.45rem;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 1.15rem;
    line-height: 1;
    flex: 0 0 auto;
}

.app-topbar-toggle:active {
    background: rgba(255, 255, 255, 0.2);
}

.app-topbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    color: #f8fafc;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    text-decoration: none;
    white-space: nowrap;
}

.app-topbar-brand i {
    font-size: 1.3rem;
    color: #60a5fa;
    flex: 0 0 auto;
}

.app-topbar-brand:hover {
    color: #cbd5e1;
}

.app-topbar-brand-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 首行右侧：登录时间 / 登录用户 / 退出 */
.app-topbar-right {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-left: auto;
    min-width: 0;
}

.app-topbar-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.32rem;
    max-width: 100%;
    padding: 0.26rem 0.6rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
    font-size: 0.78rem;
    line-height: 1.4;
    white-space: nowrap;
}

.app-topbar-chip > i {
    color: #93c5fd;
    font-size: 0.9rem;
    flex: 0 0 auto;
}

.app-chip-label {
    color: #94a3b8;
}

.app-chip-value {
    font-weight: 500;
    color: #f1f5f9;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-chip-value--short {
    display: none;
}

.app-topbar-logout {
    margin: 0;
    flex: 0 0 auto;
}

.app-logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.7rem;
    border: 1px solid rgba(248, 113, 113, 0.5);
    border-radius: 999px;
    background: rgba(248, 113, 113, 0.12);
    color: #fca5a5;
    font-size: 0.78rem;
    line-height: 1.4;
    white-space: nowrap;
}

.app-logout-btn i {
    font-size: 0.92rem;
}

.app-logout-btn:hover {
    background: rgba(248, 113, 113, 0.22);
    border-color: rgba(248, 113, 113, 0.7);
    color: #fecaca;
}

/* ---------- 左侧导航 ---------- */
.app-sidebar {
    position: fixed;
    top: var(--app-topbar-h);
    left: 0;
    bottom: 0;
    z-index: 1045;
    width: var(--app-sidebar-w);
    display: flex;
    flex-direction: column;
    background: var(--app-surface);
    border-right: 1px solid var(--app-border);
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    -webkit-overflow-scrolling: touch;
}

.app-sidebar.open {
    transform: translateX(0);
}

/* 导航项 */
.app-nav {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.35rem 0.6rem 1rem;
}

/* 大项：纯文字标题，不可点击 */
.app-nav-heading {
    padding: 0.55rem 0.7rem 0.3rem;
    color: #94a3b8;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    line-height: 1.2;
    user-select: none;
}

/* 分组之间用细分隔线区隔 */
.app-nav-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-nav-group + .app-nav-group {
    margin-top: 0.35rem;
    padding-top: 0.35rem;
    border-top: 1px solid #eef2f7;
}

.app-nav-link {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 0.7rem;
    border-radius: 0.5rem;
    color: var(--app-text);
    font-size: 0.88rem;
    line-height: 1.4;
    text-decoration: none;
    cursor: pointer;
}

.app-nav-link > i:first-child {
    width: 1.15rem;
    text-align: center;
    font-size: 1rem;
    color: var(--app-text-soft);
    flex: 0 0 auto;
}

.app-nav-link > span {
    flex: 1 1 auto;
    white-space: nowrap;
}

.app-nav-link:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.app-nav-link:hover > i:first-child {
    color: var(--app-text);
}

.app-nav-link.active {
    background: var(--app-primary-soft);
    color: var(--app-primary);
    font-weight: 600;
}

.app-nav-link.active > i:first-child {
    color: var(--app-primary);
}

/* 抽屉遮罩 */
.app-backdrop {
    position: fixed;
    inset: var(--app-topbar-h) 0 0 0;
    z-index: 1040;
    background: rgba(15, 23, 42, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.app-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

body.sidebar-open {
    overflow: hidden;
}

/* ---------- 主内容区 ---------- */
.app-main {
    flex: 1 1 auto;
    min-width: 0; /* 关键：避免宽表格把整个布局撑破 */
    min-height: 100vh;
    margin-left: var(--app-sidebar-w);
    padding-top: var(--app-topbar-h);
    display: flex;
    flex-direction: column;
}

.app-shell.is-auth .app-main {
    margin-left: 0;
    padding-top: 0;
}

.app-content {
    flex: 1 1 auto;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.25rem 1.4rem 1.5rem;
}

.app-footer {
    padding: 0.8rem 1rem 1.2rem;
    text-align: center;
    color: #94a3b8;
}

/* ---------- 桌面端（≥992px）：侧栏常驻 ---------- */
@media (min-width: 992px) {
    .app-sidebar {
        transform: none;
        z-index: 1040;
    }

    .app-backdrop {
        display: none;
    }

    .app-topbar-toggle {
        display: none;
    }

    .app-content {
        padding: 1.5rem 1.75rem 2rem;
    }
}

/* ---------- 手机（<992px）：侧栏为抽屉 ---------- */
@media (max-width: 991.98px) {
    .app-main {
        margin-left: 0;
    }

    .app-content {
        padding: 0.9rem 0.75rem 1.2rem;
    }

    .app-footer {
        padding-bottom: 0.9rem;
    }

    /* 窄屏仪表盘卡片过窄，折行会把中文挤成竖排：改为不折行 + 卡内横向滚动 */
    .app-content .dashboard-grid table.table th,
    .app-content .dashboard-grid table.table td {
        white-space: nowrap;
    }

    /* 首行压缩：隐藏「登录时间 / 登录用户」字样，只留数值 */
    .app-chip-label {
        display: none;
    }
}

/* 直板手机（<576px）：进一步压缩首行，避免横向溢出 */
@media (max-width: 575.98px) {
    .app-topbar {
        gap: 0.45rem;
        padding: 0 0.55rem;
    }

    .app-topbar-brand-text {
        display: none;
    }

    .app-topbar-right {
        gap: 0.3rem;
    }

    .app-topbar-chip {
        padding: 0.24rem 0.45rem;
        font-size: 0.74rem;
    }

    .app-chip-value--full {
        display: none;
    }

    .app-chip-value--short {
        display: inline;
    }

    .app-logout-btn {
        padding: 0.28rem 0.5rem;
        font-size: 0.74rem;
    }

    .app-content {
        padding: 0.75rem 0.6rem 1rem;
    }

    .app-content h1 {
        font-size: 1.2rem;
    }

    .app-content .card-body {
        padding: 0.95rem 0.85rem;
    }

    .app-content .btn {
        white-space: nowrap;
    }
}

/* 窄屏页头（标题 + 操作按钮）：改为上下两行，避免标题被按钮挤掉 */
@media (max-width: 767.98px) {
    .app-content .d-flex.justify-content-between:has(h1) {
        flex-wrap: wrap;
        row-gap: 0.6rem;
    }

    .app-content .d-flex.justify-content-between:has(h1) > :first-child {
        flex: 1 1 100%;
    }

    .app-content .d-flex.justify-content-between:has(h1) > :last-child {
        margin-left: auto;
    }
}

/* ---------- 登录页（浅色） ---------- */
.auth-body {
    background: linear-gradient(160deg, #f7f9fc 0%, #eaf0f9 55%, #e3ebf6 100%);
    min-height: 100vh;
}

/* 登录页容器：交给 Bootstrap 栅格分列，这里只负责居中与留白 */
.auth-main {
    width: 100%;
    max-width: 1040px;
    margin: 0 auto;
    padding: 1.5rem 1rem 2.5rem;
}

.login-logo {
    width: 56px;
    height: 56px;
    margin: 0 auto;
    border-radius: 16px;
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.28);
}

.auth-body h1 {
    color: #0f172a;
}

.auth-body .card {
    border-radius: 14px;
    border: 1px solid var(--app-border);
}

.auth-body .text-muted.small {
    color: #64748b !important;
}

.auth-body .flash-area .alert {
    margin-bottom: 1rem;
}

/* ---------- 登录验证码 ---------- */
.captcha-img {
    height: 40px;
    width: 120px;
    flex: 0 0 120px;
    border: 1px solid #dee2e6;
    border-radius: .375rem;
    cursor: pointer;
    background: #f1f5f9;
    display: block;
}

/* ---------- 小屏横向溢出兜底 ----------
   .row 自带 -12px 左右外边距，内容区小屏内边距只有 9.6px 时会多顶出约 2px，
   表单页（新建 / 编辑）因此在手机上出现轻微横向滚动，这里统一收回。 */
@media (max-width: 575.98px) {
    .app-content > .row {
        margin-left: 0;
        margin-right: 0;
    }
}

/* ---------- 搜索式多选（picker）：存放位置的仓库 / 库位选择 ----------
   库位可能上千个，用「关键字 + 下拉候选 + 已选标签」代替成百上千个复选框。 */
.picker {
    position: relative;
}

.picker-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    min-height: 2.4rem;
    padding: .4rem .5rem;
    margin-bottom: .5rem;
    border: 1px solid var(--app-border, #dee2e6);
    border-radius: .5rem;
    background: #f8fafc;
}

.picker-chip {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    max-width: 100%;
    padding: .1rem .35rem .1rem .55rem;
    border: 1px solid #c7d7fe;
    border-radius: 1rem;
    background: #eef2ff;
    color: #1e3a8a;
    font-size: .8125rem;
    line-height: 1.5;
}

.picker-chip-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 22rem;
}

.picker-x {
    border: 0;
    background: transparent;
    color: #4c5fd5;
    font-size: 1rem;
    line-height: 1;
    padding: 0 .1rem;
    cursor: pointer;
}

.picker-x:hover {
    color: #b91c1c;
}

.picker-menu {
    display: none;
    position: absolute;
    z-index: 1050;
    left: 0;
    right: 0;
    margin-top: .25rem;
    border: 1px solid var(--app-border, #dee2e6);
    border-radius: .5rem;
    background: #fff;
    box-shadow: 0 .5rem 1.5rem rgba(15, 23, 42, .12);
    overflow: hidden;
}

.picker-menu.show {
    display: block;
}

.picker-options {
    max-height: 16rem;
    overflow-y: auto;
}

.picker-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    width: 100%;
    padding: .45rem .65rem;
    border: 0;
    border-bottom: 1px solid #f1f5f9;
    background: #fff;
    color: #1f2328;
    font-size: .875rem;
    text-align: left;
    cursor: pointer;
}

.picker-option:last-child {
    border-bottom: 0;
}

.picker-option:hover,
.picker-option:focus-visible {
    background: #eff6ff;
    outline: none;
}

.picker-option-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.picker-option-check {
    visibility: hidden;
    color: #0d6efd;
}

.picker-option.is-picked {
    background: #f1f5f9;
    color: #0f172a;
    font-weight: 600;
}

.picker-option.is-picked .picker-option-check {
    visibility: visible;
}

.picker-hint,
.picker-empty {
    padding: .4rem .65rem;
    color: #6b7682;
    font-size: .8125rem;
    background: #f8fafc;
}
