/* 仓库管理系统 - 移动端优先响应式样式（鲜彩浅色版） */
:root {
    --bg: #f5f6fb;
    --card: #ffffff;
    --text: #293041;
    --text-2: #5b6478;
    --muted: #8e99ad;
    --primary: #6d4aff;
    --primary-dark: #5333e0;
    --primary-soft: #f0edff;
    --danger: #f43f5e;
    --danger-soft: #ffeef1;
    --ok: #10b981;
    --ok-soft: #e7faf2;
    --warn: #f59e0b;
    --warn-soft: #fef4e2;
    --border: #e8eaf3;
    --border-strong: #d9deeb;
    --shadow-sm: 0 1px 2px rgba(80, 60, 180, .06);
    --shadow-md: 0 4px 16px rgba(80, 60, 180, .1);
    --radius: 12px;
    --radius-sm: 8px;
    --dark: #4338ca;
    --dark-2: #7c3aed;
    --grad: linear-gradient(120deg, #6d4aff, #9333ea);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background:
        radial-gradient(900px 280px at 8% -60px, rgba(109, 74, 255, .07), transparent 70%),
        radial-gradient(900px 280px at 92% -60px, rgba(236, 72, 153, .06), transparent 70%),
        radial-gradient(700px 240px at 50% 108%, rgba(16, 185, 129, .05), transparent 70%),
        var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.6;
    letter-spacing: .2px;
    -webkit-font-smoothing: antialiased;
}

/* ---------- 顶栏 ---------- */
.topbar {
    background: linear-gradient(120deg, #4338ca 0%, #7c3aed 55%, #c026d3 100%);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 14px rgba(93, 63, 211, .35);
}
.topbar-inner {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 10px 18px;
    max-width: 1200px;
    margin: 0 auto;
}
.brand {
    font-size: 16.5px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: 1px;
    white-space: nowrap;
}
.brand-ver {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .5px;
    background: rgba(255,255,255,.22);
    border: 1px solid rgba(255,255,255,.35);
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 2px;
}
.brand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px; height: 30px;
    background: rgba(255,255,255,.18);
    border-radius: 9px;
    font-size: 16px;
}
.user-area { display: flex; align-items: center; gap: 10px; }
.user-name { font-size: 13px; opacity: .88; }
a.user-name { color: inherit; text-decoration: none; border-bottom: 1px dashed rgba(255,255,255,.5); padding-bottom: 1px; transition: opacity .15s, border-color .15s; }
a.user-name:hover { opacity: 1; border-bottom-color: #fff; }

/* ---------- 修改密码 ---------- */
.profile-wrap { max-width: 420px; margin: 32px auto; }
.profile-card { padding: 28px; }
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.profile-avatar {
    width: 52px; height: 52px; border-radius: 50%;
    background: linear-gradient(135deg, #6d4aff, #c026d3);
    color: #fff; font-size: 22px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.profile-name { font-size: 17px; font-weight: 600; }
.profile-form .form-group { margin-bottom: 16px; }
.btn-block { width: 100%; margin-top: 6px; padding: 11px; font-size: 15px; }
.mainnav {
    display: flex;
    flex: 1 1 auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0;
    gap: 2px;
    scrollbar-width: none;
    min-width: 0;
}
.mainnav::-webkit-scrollbar { display: none; }
.mainnav a {
    color: rgba(255,255,255,.78);
    text-decoration: none;
    padding: 6px 11px;
    white-space: nowrap;
    font-size: 13.5px;
    border-radius: 18px;
    transition: all .18s ease;
    letter-spacing: .5px;
}
.mainnav a:hover { color: #fff; background: rgba(255,255,255,.14); }
.mainnav a.active {
    color: #5333e0;
    background: #fff;
    font-weight: 700;
    box-shadow: 0 2px 10px rgba(30, 15, 90, .3);
}

/* ---------- 布局 ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 20px 16px 10px; }
.page-title {
    font-size: 20px;
    font-weight: 700;
    margin: 6px 0 18px;
    letter-spacing: .5px;
    position: relative;
    padding-left: 14px;
}
.page-title::before {
    content: "";
    position: absolute;
    left: 0; top: 5px; bottom: 5px;
    width: 4px;
    border-radius: 2px;
    background: linear-gradient(180deg, #6d4aff, #e879f9);
}
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.page-head .page-title { margin-bottom: 0; }
.page-title .title-docno {
    margin-left: 10px;
    font-size: 14px;
    font-weight: 500;
    color: #6d4aff;
    letter-spacing: 0;
    background: var(--primary-soft);
    border-radius: 12px;
    padding: 3px 10px;
    vertical-align: 3px;
}
.ipt-readonly { background: #f6f7fb; color: var(--text-2); cursor: not-allowed; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 24px 0 34px; letter-spacing: 1px; }
.muted { color: var(--muted); font-size: 12.5px; margin: 10px 2px; }

/* ---------- 统计卡（四色循环，鲜彩点缀） ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 18px; }
.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 16px 13px;
    text-decoration: none;
    color: var(--text);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: transform .15s ease, box-shadow .15s ease;
}
.stat-card::after {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, #4f46e5, #818cf8);
    opacity: .9;
}
.stat-grid .stat-card:nth-child(4n+2)::after { background: linear-gradient(90deg, #10b981, #5eead4); }
.stat-grid .stat-card:nth-child(4n+3)::after { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.stat-grid .stat-card:nth-child(4n+4)::after { background: linear-gradient(90deg, #ec4899, #f9a8d4); }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-num {
    font-size: 25px;
    font-weight: 700;
    color: #4f46e5;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}
.stat-grid .stat-card:nth-child(4n+2) .stat-num { color: #0d9e77; }
.stat-grid .stat-card:nth-child(4n+3) .stat-num { color: #d97706; }
.stat-grid .stat-card:nth-child(4n+4) .stat-num { color: #db2777; }
.stat-label { font-size: 12.5px; color: var(--muted); margin-top: 2px; letter-spacing: .5px; }

.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }

/* ---------- 首页重设计 v2 ---------- */
.home-wrap { max-width: 1080px; margin: 0 auto; }
.home-wrap > h2.page-title:first-child { margin-top: 0; }
.home-wrap .page-title {
    font-size: 18.5px; letter-spacing: .3px;
    margin: 30px 0 16px;
    display: flex; align-items: center; gap: 10px;
}
/* 标题右侧带按钮：左右两端对齐 */
.sec-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap; margin: 30px 0 16px;
}
.sec-head .page-title { margin: 0; }
/* 危险色标题（库存预警 / 无销售记录）：左侧竖条同步变红 */
.page-title.t-danger { color: var(--danger); }
.page-title.t-danger::before { background: linear-gradient(180deg, #f43f5e, #fb7185); }
/* 标题计数胶囊 */
.count-pill {
    min-width: 24px; padding: 2px 10px;
    border-radius: 999px; color: #fff;
    background: linear-gradient(135deg, #f43f5e, #fb7185);
    font-size: 13px; font-weight: 700; line-height: 1.6;
    font-variant-numeric: tabular-nums;
}
.count-pill.pill-amber { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
/* 统计卡：图标盘 + 数字 + 标签，横排 */
.home-wrap .stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
    gap: 14px; margin-bottom: 20px;
}
.home-wrap .stat-card {
    display: flex; align-items: center; gap: 12px;
    padding: 15px 16px;
}
.stat-ico {
    width: 42px; height: 42px; flex: none;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
}
.stat-ico svg { width: 20px; height: 20px; }
.stat-txt { display: flex; flex-direction: column; min-width: 0; }
.home-wrap .stat-num { font-size: 24px; }
.home-wrap .stat-label { letter-spacing: .5px; white-space: nowrap; }
/* 图标盘配色：跟随卡片顶部色条循环 */
.stat-grid .stat-card:nth-child(4n+1) .stat-ico { background: #eef0ff; color: #4f46e5; }
.stat-grid .stat-card:nth-child(4n+2) .stat-ico { background: #e7f8f3; color: #0d9e77; }
.stat-grid .stat-card:nth-child(4n+3) .stat-ico { background: #fef4e6; color: #d97706; }
.stat-grid .stat-card:nth-child(4n+4) .stat-ico { background: #fdeef5; color: #db2777; }
/* 快捷操作：收纳成浅色操作条 */
.home-wrap .quick-actions {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 13px 16px;
    box-shadow: var(--shadow-sm); margin-bottom: 0; align-items: center;
}
/* 底部口径说明：浅色注释条 */
.note-bar {
    display: flex; align-items: flex-start; gap: 8px;
    margin-top: 12px; padding: 10px 14px;
    background: #f8f7fd; border-radius: 8px;
    color: var(--muted); font-size: 12.5px; line-height: 1.7;
    text-align: left;
}
.note-bar::before {
    content: "i"; flex: none;
    width: 15px; height: 15px; margin-top: 3px;
    border-radius: 50%; background: #e4e0fb; color: #6d4aff;
    font-size: 11px; font-weight: 700; font-style: italic;
    display: flex; align-items: center; justify-content: center;
    font-family: Georgia, serif;
}
/* 首页表格：轻量表头 + 行距收紧 + 等宽数字 */
.home-wrap .table th {
    background: transparent; color: #98a2b3;
    font-size: 12.5px; font-weight: 600; letter-spacing: .8px;
    border-bottom: 1px solid var(--border);
}
.home-wrap .table td, .home-wrap .table th { padding: 12px 14px; }
.home-wrap .table td.num { font-variant-numeric: tabular-nums; }

/* ---------- 卡片 ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-head h3, .card-title {
    margin: 0 0 12px;
    font-size: 15.5px;
    font-weight: 700;
    letter-spacing: .5px;
}
.card-head h3 { margin: 0; }
.help-card { background: linear-gradient(180deg, #fbfaff, #f5f3ff); }
.help-card ul { margin: 0; padding-left: 18px; color: var(--text-2); font-size: 13.5px; }
.help-card li { margin-bottom: 5px; }
.help-card code { background: var(--primary-soft); color: #6d28d9; padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }

/* ---------- 表单 ---------- */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-size: 12.5px;
    color: var(--text-2);
    margin-bottom: 5px;
    font-weight: 600;
    letter-spacing: .5px;
}
input[type=text], input[type=password], input[type=date], input[type=number], select, input[list] {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 14.5px;
    background: #fff;
    color: var(--text);
    min-height: 42px;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(109, 74, 255, .13);
}
.form-grid { display: grid; grid-template-columns: 1fr; gap: 2px; }
.form-actions { display: flex; gap: 10px; margin: 18px 0; }
.form-actions .btn { min-width: 104px; }
.check-label { display: flex; align-items: center; gap: 6px; font-size: 13.5px; white-space: nowrap; color: var(--text-2); }

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
    align-items: center;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow-sm);
}
.filter-bar input[type=text] { flex: 1 1 170px; min-width: 150px; }
.filter-bar input[type=date], .filter-bar select { flex: 0 1 150px; min-width: 132px; }
.filter-bar .btn { flex: 0 0 auto; }

/* ---------- 按钮 ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: .5px;
    cursor: pointer;
    text-decoration: none;
    min-height: 40px;
    transition: all .16s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(120deg, #6d4aff, #9333ea); color: #fff; box-shadow: 0 2px 8px rgba(109, 74, 255, .35); }
.btn-primary:hover { background: linear-gradient(120deg, #5d38f0, #7e22ce); box-shadow: 0 3px 12px rgba(109, 74, 255, .45); }
.btn-success { background: linear-gradient(120deg, #10b981, #34d399); color: #fff; box-shadow: 0 2px 6px rgba(16, 185, 129, .3); }
.btn-success:hover { background: linear-gradient(120deg, #0da271, #2bc48b); }
.btn-secondary { background: var(--primary-soft); color: #6d28d9; }
.btn-secondary:hover { background: #e6e0ff; }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #ffdde4; }
.btn-ghost { background: transparent; color: var(--primary); border: 1px solid var(--border-strong); }
.btn-ghost:hover { background: var(--primary-soft); border-color: var(--primary); }
.topbar .btn-ghost { color: rgba(255,255,255,.9); border-color: rgba(255,255,255,.35); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.14); }
.btn-sm { padding: 4px 11px; min-height: 30px; font-size: 12.5px; border-radius: 7px; }
.btn-block { width: 100%; }

/* ---------- 标签 ---------- */
.badge {
    display: inline-block;
    padding: 2.5px 9px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    background: #f1f2f8;
    color: var(--text-2);
    letter-spacing: .5px;
}
.badge-ok { background: var(--ok-soft); color: #0d9e77; }
.badge-warn { background: var(--warn-soft); color: #d97706; }
.badge-role { background: rgba(129, 140, 248, .18); color: #6366f1; }

/* ---------- 提示 ---------- */
.alert {
    padding: 11px 15px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    font-size: 13.5px;
    box-shadow: var(--shadow-sm);
}
.alert-success { background: var(--ok-soft); color: #0b7d5c; border: 1px solid #b5ecd6; }
.alert-error { background: var(--danger-soft); color: #be123c; border: 1px solid #fcd0da; }

/* ---------- 表格（大字号、宽松行高） ---------- */
.table-wrap {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
}
.table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 560px; }
.table th, .table td { padding: 14px 16px; text-align: left; border-bottom: 1px solid #d9dded; white-space: nowrap; }
.table th {
    background: #faf9ff;
    color: #8e99ad;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: .5px;
    position: sticky;
    top: 0;
    border-bottom: 1px solid var(--border);
}
.table th:first-child, .table td:first-child { padding-left: 20px; }
.table th:last-child, .table td:last-child { padding-right: 20px; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: #f7f5ff; }
.table tbody tr:last-child td { border-bottom: none; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.neg, .table td .neg, .neg { color: var(--danger); }
.in-num { color: var(--ok); }
.table td.strong, .table tfoot td { font-weight: 700; }
.table td.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.table tfoot td { background: #f6f4ff; }
.td-name { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
/* 纸箱尺寸：产品名称下方的灰色小字 */
.td-name.has-carton { overflow: visible; text-overflow: clip; white-space: normal; }
.carton-size {
    display: block; margin-top: 3px;
    color: #94a0b0; font-size: 11.5px; font-weight: 400; line-height: 1.35;
    letter-spacing: .2px;
}
.td-detail { white-space: normal !important; max-width: 320px; word-break: break-all; }
.table a { color: var(--primary); text-decoration: none; }
.table a:hover { text-decoration: underline; }
.ops { display: flex; gap: 6px; align-items: center; }
.inline-form { display: inline; }
.table-items input, .table-items select { min-width: 70px; min-height: 38px; padding: 6px 8px; font-size: 14.5px; }
.table-items .ipt-product { min-width: 170px; }
/* 明细列宽：规格/单位/备注收窄，仓库/数量保证完整显示 */
.table-items .ipt-spec { width: 100px; }
.table-items .ipt-unit { width: 64px; }
.table-items .ipt-wh { min-width: 96px; }
.table-items .ipt-qty { width: 80px; }
.table-items input[name="item_remark[]"] { width: 130px; }
/* 横向滚动条可见，避免窄屏下列被截断却看不出可滚动 */
.table-wrap { scrollbar-width: thin; scrollbar-color: #c9cee0 transparent; }
.table-wrap::-webkit-scrollbar { height: 9px; }
.table-wrap::-webkit-scrollbar-thumb { background: #c9cee0; border-radius: 5px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: #aeb5cd; }
/* 中窄屏：录单明细表紧凑化，尽量让全部列进入视野 */
@media (max-width: 1150px) {
    .table-items th, .table-items td { padding: 9px 6px; }
    .table-items input, .table-items select { min-height: 36px; padding: 5px 6px; font-size: 14px; }
    .table-items .ipt-product { min-width: 128px; }
    .table-items .ipt-spec { width: 88px; }
    .table-items .ipt-unit { width: 58px; }
    .table-items .ipt-wh { min-width: 92px; }
    .table-items .ipt-qty { width: 76px; }
    .table-items input[name="item_remark[]"] { width: 118px; }
    .table-items .pcell { gap: 4px; }
}
@media (max-width: 760px) {
    .table-items .ipt-product { min-width: 104px; }
    .table-items .ipt-spec { width: 76px; }
    .table-items input[name="item_remark[]"] { width: 100px; }
}
.table .badge { font-size: 12.5px; }
.table .btn-sm { font-size: 13px; }

/* ---------- 首页：超90天无出库商品 ---------- */
.stale-wrap { max-height: 480px; overflow-y: auto; padding: 0; }
.table-compact { font-size: 14px; min-width: 480px; }
.table-compact th, .table-compact td { padding: 8px 12px; }
/* 需要整表居中的表格（首页库存预警、无销售出库记录等）：覆盖 .num 的右对齐 */
.center-table th, .center-table td { text-align: center; }
.center-table td.num, .center-table th.num { text-align: center; }
.stale-never { color: var(--danger); font-weight: 600; }

/* ---------- 标签页 ---------- */
.tabs { display: flex; gap: 7px; margin-bottom: 14px; overflow-x: auto; padding-bottom: 2px; }
.tab {
    padding: 7px 18px;
    border-radius: 20px;
    background: var(--card);
    color: var(--text-2);
    text-decoration: none;
    font-size: 13.5px;
    white-space: nowrap;
    border: 1px solid var(--border-strong);
    transition: all .16s;
    letter-spacing: .5px;
}
.tab:hover { border-color: var(--primary); color: var(--primary); }
.tab.active {
    background: linear-gradient(120deg, #6d4aff, #9333ea);
    color: #fff;
    border-color: transparent;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(109, 74, 255, .35);
}

/* ---------- 单据详情 ---------- */
.doc-meta { display: grid; grid-template-columns: 1fr; gap: 9px; margin-bottom: 12px; }
.doc-meta > div { font-size: 14px; }
.meta-label {
    color: var(--muted);
    font-size: 12.5px;
    margin-right: 10px;
    letter-spacing: .5px;
}
.meta-wide { grid-column: 1 / -1; }

/* ---------- 报表柱状分布 ---------- */
.bar-row { display: flex; flex-direction: column; gap: 3px; min-width: 120px; }
.bar { display: block; height: 7px; border-radius: 4px; }
.bar-in { background: linear-gradient(90deg, #10b981, #5eead4); }
.bar-out { background: linear-gradient(90deg, #f43f5e, #fb7185); }

/* ---------- 分页 ---------- */
.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 18px 0; }

/* ---------- 登录 ---------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #4338ca 0%, #7c3aed 50%, #db2777 100%);
    padding: 16px;
}
.login-card {
    background: #fff;
    border-radius: 18px;
    padding: 32px 28px;
    width: 100%;
    max-width: 370px;
    box-shadow: 0 20px 60px rgba(40, 20, 100, .45);
}
.login-title {
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 24px;
    letter-spacing: 2px;
}
.login-hint {
    margin-top: 18px;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    line-height: 1.8;
}

/* ---------- 打印（保持白底，打印内容不受主题影响） ---------- */
@media print {
    .topbar, .footer, .page-actions, .form-actions, .btn, .inline-form { display: none !important; }
    body { background: #fff; }
    .card, .table-wrap { box-shadow: none; border: 1px solid #ccc; }
}

/* ---------- 平板/桌面 ---------- */
@media (min-width: 768px) {
    .container { padding: 26px 20px 12px; }
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
    .form-grid { grid-template-columns: repeat(2, 1fr); gap: 4px 24px; }
    .form-group-wide { grid-column: 1 / -1; }
    .doc-meta { grid-template-columns: repeat(3, 1fr); }
    .brand { font-size: 17.5px; }
    .mainnav a { padding: 7px 17px; }
}
@media (min-width: 1024px) {
    .form-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- 导航下拉分组（系统） ---------- */
.nav-drop { position: relative; display: flex; flex: 0 0 auto; }
.nav-drop-toggle {
    color: rgba(255,255,255,.75); text-decoration: none;
    padding: 6px 14px; border-radius: 7px; cursor: pointer;
    display: flex; align-items: center; gap: 4px; white-space: nowrap;
    font-size: 13.5px; font-family: inherit; line-height: inherit;
    background: none; border: 0; margin: 0;
    -webkit-appearance: none; appearance: none;   /* iOS 原生按钮外观重置 */
    transition: background .15s, color .15s;
    touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.nav-drop-toggle:hover,
.nav-drop.open .nav-drop-toggle { color: #fff; background: rgba(255,255,255,.14); }
.nav-drop.active .nav-drop-toggle { color: #5333e0; background: #fff; font-weight: 700; }
/* 下拉箭头：CSS 边框三角（iOS Safari 对 ▾ 字符渲染不可靠，改用纯 CSS 绘制） */
.nav-drop .caret {
    display: inline-block;
    width: 0; height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid currentColor;
    opacity: .85;
    margin-left: 2px;
}
.nav-drop-menu {
    display: none; position: fixed; z-index: 9999;
    flex-direction: column; min-width: 150px; padding: 6px;
    background: #fff; border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 8px 30px rgba(70, 40, 160, .18);
}
/* 菜单已被 JS 移到 body 直属层，用自身 .open 控制显示 */
.nav-drop-menu.open { display: flex; }
.nav-drop-menu a {
    color: #3b4256; text-decoration: none; padding: 9px 14px;
    border-radius: 8px; font-size: 14.5px; white-space: nowrap;
    font-weight: 400;
}
.nav-drop-menu a:hover { background: #f4f1ff; color: var(--primary); }
.nav-drop-menu a.active { background: linear-gradient(120deg, #6d4aff, #9333ea); color: #fff; font-weight: 600; }
@media (min-width: 768px) {
    .nav-drop-toggle { padding: 7px 17px; }
    .nav-drop-menu a { padding: 9px 14px; }
}

/* ---------- 商品搜索选择器 ---------- */
.pcell { display: flex; gap: 5px; align-items: center; }
.pcell input { flex: 1; min-width: 0; }
.pick-mask {
    position: fixed; inset: 0; background: rgba(50, 30, 110, .45);
    display: none; align-items: center; justify-content: center;
    padding: 16px; z-index: 60;
}
.pick-mask.show { display: flex; }
.pick-card {
    background: #fff; border-radius: 14px; width: 100%; max-width: 580px;
    max-height: 82vh; display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 12px 40px rgba(60, 30, 140, .3);
}
.pick-head { padding: 14px 16px 10px; }
.pick-head h3 { font-size: 16px; margin-bottom: 10px; }
.pick-search { display: flex; gap: 8px; }
.pick-search input {
    flex: 1; min-width: 0; padding: 10px 12px; font-size: 14.5px;
    border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.pick-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(109,74,255,.12); }
.pick-count { font-size: 12.5px; color: var(--muted); margin-top: 8px; min-height: 16px; }
.pick-list { overflow-y: auto; border-top: 1px solid var(--border); flex: 1; }
.pick-item {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    padding: 11px 16px; cursor: pointer; border-bottom: 1px solid #f2f3f9;
}
.pick-item:last-child { border-bottom: none; }
.pick-item:hover { background: #f6f4ff; }
.pick-item .pi-name { font-weight: 500; font-size: 14.5px; }
.pick-item .pi-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.pick-item .pi-unit { color: var(--muted); font-size: 13px; white-space: nowrap; }
.pick-empty { padding: 40px 16px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- 单据列表布局修正 ---------- */
/* 长单位名省略显示，防止表格被撑出横向滚动导致操作列截断 */
.table td.td-ellipsis {
    max-width: 200px; overflow: hidden; text-overflow: ellipsis;
}
/* 单据编号前的小类型标签（购货入库单/其他入库单等） */
.doc-type {
    display: inline-block; margin-right: 7px; padding: 2px 8px;
    border-radius: 6px; background: #eef1fb; color: #5b6b92;
    font-size: 11.5px; font-weight: 600; letter-spacing: .3px;
    vertical-align: middle; white-space: nowrap;
}
/* 未审核单据：编号下方的状态小字 */
.doc-status-sub {
    display: block; margin-top: 4px;
    color: var(--danger); font-size: 11.5px; font-weight: 600; line-height: 1.3;
}
/* 单据列表：编号下带状态小字时，各行统一顶部对齐，避免左右错位 */
.docs-table td { vertical-align: top; }
.docs-table .ops { white-space: nowrap; }
.docs-table .doc-type { vertical-align: baseline; }
/* 操作列固定在右侧：表格横向滚动时 查看/编辑/删除 始终完整可见（不画分隔线） */
.docs-table th:last-child, .docs-table td:last-child {
    position: sticky; right: 0;
    background: var(--card);
}
.docs-table th:last-child { background: #faf9ff; }
.docs-table tbody tr:hover td:last-child { background: #f7f5ff; }
/* 行分隔线画在 tr 上：sticky 单元格不撑满行高时线条也不会断开 */
.docs-table tr { border-bottom: 1px solid #d9dded; }
.docs-table th, .docs-table td { border-bottom: none; }
.docs-table tbody tr:last-child { border-bottom: none; }
/* 收窄省略列，减少横向滚动 */
.docs-table td.td-ellipsis { max-width: 150px; }
/* 表格文字层次（全站通用）：产品/名称深色中粗 · 辅助信息中灰 · 日期浅灰等宽 */
.td-prod { color: #2c3245 !important; font-weight: 500; }
.td-date {
    color: #6f7a90 !important; font-size: 13.5px;
    font-variant-numeric: tabular-nums; letter-spacing: .3px;
}
.td-sub { color: #5d6880 !important; }
/* 筛选栏：日期/下拉控件与按钮同高、字体收敛 */
.filter-bar input[type=date], .filter-bar select {
    flex: 0 1 150px; min-width: 132px;
    min-height: 40px; height: 40px; padding: 0 10px;
    font-size: 13px; color: #3d4354;
    letter-spacing: .2px; color-scheme: light;
}
/* 操作列按钮紧凑化，保证 查看/编辑/删除 完整显示 */
.table .ops .btn-sm { padding: 5px 11px; }
.table .ops .inline-form { display: inline-flex; }

/* ---------- 登录验证码 ---------- */
.captcha-row { display: flex; gap: 8px; align-items: center; }
.captcha-row input { flex: 1; min-width: 0; }
.captcha-row img {
    height: 42px; border-radius: 8px; border: 1px solid var(--border);
    cursor: pointer; flex: 0 0 auto; background: #eef1f8;
}

/* ---------- 库存预警设置：商品搜索 ---------- */
.sa-results {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30;
    background: var(--card); border: 1px solid var(--border-strong); border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .12); max-height: 320px; overflow-y: auto;
}
.sa-item {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 8px 12px; border: 0; border-bottom: 1px solid var(--border);
    background: transparent; text-align: left; cursor: pointer; font-size: 13.5px;
}
.sa-item:last-child { border-bottom: 0; }
.sa-item:hover { background: var(--primary-soft, #eef2ff); }
.sa-n { font-weight: 600; color: var(--text); white-space: nowrap; }
.sa-m { color: var(--muted); font-size: 12.5px; flex: 1; }
.sa-none { padding: 12px; color: var(--muted); font-size: 13px; text-align: center; }
.sa-picked {
    display: inline-flex; align-items: center; gap: 6px; align-self: center;
    padding: 5px 10px; border: 1px solid var(--primary); border-radius: 8px;
    color: var(--primary); font-size: 13px; background: var(--primary-soft, #eef2ff);
}
.sa-clear {
    border: 0; background: transparent; color: var(--muted); cursor: pointer;
    font-size: 15px; line-height: 1; padding: 0 2px;
}
.sa-clear:hover { color: var(--danger); }

/* ---------- 超90天无出库：查看全部 / 筛选工具条 ---------- */
.stale-more { float: right; margin-left: 12px; }
.stale-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 14px; }
.stale-toolbar input[type=text] { flex: 1 1 200px; min-width: 170px; }
.stale-toolbar select { flex: 0 1 150px; min-width: 120px; }


/* ---------- 顶栏单行布局：小屏时导航折到第二行横向滚动 ---------- */
@media (max-width: 950px) {
    .topbar-inner { flex-wrap: wrap; gap: 2px 14px; padding: 9px 14px; }
    .user-area { margin-left: auto; }
    .mainnav { order: 3; flex-basis: 100%; padding-bottom: 6px; }
    .brand { font-size: 15.5px; }
}
.login-ver { font-size: 13px; font-weight: 600; opacity: .65; letter-spacing: .5px; vertical-align: 2px; }

/* ==================================================================
   手机端适配补齐（仅窄屏生效，桌面视觉保持不变）
   ================================================================== */

/* 卡片内直接放表格：滚动条只出现在卡片内部，不把整页撑宽 */
.card-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* 卡片里的说明文字固定在可视区左侧，横向滑动表格时不会被一起带走 */
.card-scroll > .note-bar, .card-scroll > .muted { position: sticky; left: 0; }
/* 兜底：今后新增页面若把表格直接放进 .card，也自动获得横向滚动。
   :has 只在较新浏览器生效，上面的显式 class 负责兼容旧设备。 */
@supports selector(:has(*)) {
    .card:has(> table.table) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

@media (max-width: 767px) {
    /* 版面留白收紧 */
    .container { padding: 14px 12px 10px; }
    .card { padding: 14px; margin-bottom: 14px; }
    .card.stale-wrap { padding: 0; }   /* 查看全部页的表格原本贴边，保持原样 */
    .page-title { font-size: 18px; margin: 4px 0 14px; }
    .home-wrap > .page-title, .sec-head .page-title { font-size: 17px; }
    .home-wrap > .page-title, .sec-head { margin: 22px 0 12px; }
    .note-bar { font-size: 12px; line-height: 1.65; }

    /* 首页统计卡：保持两列，缩小图标与数字避免挤断 */
    .home-wrap .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .home-wrap .stat-card { padding: 12px; gap: 9px; }
    .stat-ico { width: 36px; height: 36px; flex: 0 0 36px; border-radius: 10px; }
    .stat-ico svg { width: 18px; height: 18px; }
    .home-wrap .stat-num { font-size: 20px; }
    .home-wrap .stat-label { font-size: 11.5px; letter-spacing: 0; }
    .stat-grid { gap: 10px; }

    /* 快捷操作：按钮两两等宽换行，触摸区加大 */
    .home-wrap .quick-actions { padding: 11px 12px; gap: 8px; }
    .home-wrap .quick-actions .btn { flex: 1 1 calc(50% - 4px); }
    .btn { min-height: 42px; }
    .btn-sm { min-height: 34px; padding: 6px 12px; }

    /* 表格紧凑化，减少手机上的横向滑动距离 */
    .table { font-size: 13.5px; }
    .table th, .table td { padding: 10px 12px; }
    .table th:first-child, .table td:first-child { padding-left: 12px; }
    .table th:last-child, .table td:last-child { padding-right: 12px; }
    .home-wrap .table td, .home-wrap .table th { padding: 9px 10px; }
    .table-wrap, .card-scroll {
        scrollbar-width: thin; scrollbar-color: #c9cee0 transparent;
        overscroll-behavior-x: contain;
    }
    .td-name { max-width: 180px; }
    .docs-table td.td-ellipsis { max-width: 130px; }
    .pick-card { max-height: 88vh; }
    .sa-results { max-height: 260px; }
}

@media (max-width: 600px) {
    /* 筛选栏 / 工具栏：控件各占一行，按钮并排，不再互相挤压 */
    .filter-bar, .stale-toolbar { padding: 10px; gap: 8px; }
    .filter-bar input[type=text], .filter-bar input[type=date], .filter-bar select,
    .stale-toolbar input[type=text], .stale-toolbar select {
        flex: 1 1 100%; min-width: 0; width: 100%;
    }
    .filter-bar .btn, .stale-toolbar .btn { flex: 1 1 auto; }
    .filter-bar input[type=date], .filter-bar select { height: 40px; }

    /* 表单按钮等宽 */
    .form-actions { flex-wrap: wrap; gap: 8px; }
    .form-actions .btn { flex: 1 1 auto; min-width: 0; }

    /* 库存预警设置：覆盖行内固定宽度，避免 320px 屏被 260px 输入框撑破 */
    #alert-add-form > div { flex: 1 1 100% !important; min-width: 0 !important; }
    #alert-add-form input[name="threshold"] {
        flex: 1 1 90px !important; width: auto !important; min-width: 90px !important;
    }
    #alert-add-form .btn { flex: 0 0 auto; }
}

@media (max-width: 400px) {
    .brand-ver { display: none; }
    .topbar-inner { gap: 2px 10px; padding: 8px 12px; }
    /* 极窄屏统计卡改单列，避免数字与标签折行 */
    .home-wrap .stat-grid { grid-template-columns: 1fr; }
    .count-pill { padding: 2px 8px; }
}
