:root {
    --primary: #2f6df6;
    --primary-dark: #1f54d6;
    --bg: #f4f6fb;
    --card: #ffffff;
    --text: #1f2733;
    --muted: #8a94a6;
    --border: #e6e9f0;
    --success: #1aa86b;
    --error: #e0455a;
    --warn: #e08a1e;
    --radius: 12px;
    --shadow: 0 2px 12px rgba(31, 39, 51, .08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

/* 居中登录/安装页 */
.center-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: linear-gradient(135deg, #eef2ff 0%, #f4f6fb 100%);
}

/* 顶栏 */
.topbar {
    position: sticky;
    top: 0;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 20;
}
.topbar-inner {
    max-width: 1080px;
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.logo { font-weight: 700; font-size: 18px; color: var(--primary); letter-spacing: .5px; }
.user-box { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.username { color: var(--text); }
.link { color: var(--primary); text-decoration: none; cursor: pointer; }
.link.danger { color: var(--error); }
.link:hover { text-decoration: underline; }

/* 容器 */
.container { max-width: 1080px; margin: 0 auto; padding: 16px; }

/* 统计 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; box-shadow: var(--shadow); }
.stat-num { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat-num.warn { color: var(--warn); }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* 工具栏 */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search-form { display: flex; gap: 8px; flex: 1; min-width: 240px; }
.search-form input { flex: 1; }

/* 表单控件（所有输入框强制等高、去数字箭头，保证一致） */
input[type="text"], input[type="search"], input[type="password"], input[type="number"],
input:not([type]) {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    border: 1px solid #dfe4ec;
    border-radius: 10px;
    font-size: 15px;
    line-height: 1.4;
    color: var(--text);
    background: #f8f9fc;
    outline: none;
    box-sizing: border-box;
    vertical-align: middle;
    transition: border-color .15s, box-shadow .15s, background .15s;
    -webkit-appearance: none;
    -moz-appearance: textfield;
    appearance: none;
}
/* 去掉 number 原生上下箭头，避免高度/宽度不一致 */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input::placeholder { color: #b3bac6; }
input:hover { border-color: #c6cede; }
input:focus { background: #fff; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 109, 246, .13); }

/* 按钮 */
.btn {
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-size: 15px;
    cursor: pointer;
    font-weight: 600;
    transition: background .15s, transform .05s;
    white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #eef2ff; color: var(--primary); }
.btn-ghost:hover { background: #e2e9ff; }
.btn-danger { background: #e23b3b; color: #fff; }
.btn-danger:hover { background: #c92f2f; }
.btn-block { display: block; width: 100%; margin-top: 12px; }

/* 删除确认弹窗 */
.del-tip { margin: 2px 0 0; color: var(--text); font-size: 14px; line-height: 1.6; }
.del-name { color: var(--primary); font-weight: 600; }
.del-input {
    width: 100%; height: 44px; padding: 0 12px; margin-top: 12px;
    border: 1px solid var(--border); border-radius: 10px; font-size: 15px;
    box-sizing: border-box; -webkit-appearance: none; appearance: none;
}
.del-input:focus { outline: none; border-color: var(--primary); }
.del-error { display: none; margin: 8px 0 0; color: #e23b3b; font-size: 13px; }

/* 卡片（登录/安装） */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); }
.brand { text-align: center; color: var(--primary); margin: 0 0 4px; font-size: 22px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* 字段 */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; min-height: 19px; font-size: 13px; font-weight: 500; color: #5b6472; margin-bottom: 7px; letter-spacing: .3px; }
.field > span .req { color: var(--error); margin-left: 2px; }
/* 弹窗内两列表单：行间距统一，去掉字段自带的底部间距，保证整齐 */
.form-grid .field { margin-bottom: 0; }

/* 下拉选择框：与输入框同高同风格 */
select.select {
    width: 100%;
    height: 44px;
    padding: 0 38px 0 14px;
    border: 1px solid #dfe4ec;
    border-radius: 10px;
    font-size: 15px;
    line-height: 1.4;
    color: var(--text);
    background-color: #f8f9fc;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a94a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
    outline: none;
    box-sizing: border-box;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s, background-color .15s;
}
select.select:hover { border-color: #c6cede; }
select.select:focus { background-color: #fff; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(47, 109, 246, .13); }
/* 货架位置：三个下拉（架/层/箱）并排一行 */
.loc-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.loc-grid .loc-sel { width: 100%; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); margin: 6px 0 14px; }
.checkbox input { width: 16px; height: 16px; }

/* 提示 */
.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }
.alert-success { background: #e7f8ef; color: #0f7a4d; border: 1px solid #b6e8cf; }
.alert-error { background: #fdeaed; color: #b22a3c; border: 1px solid #f5c2cb; }

/* 表格 */
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
.goods-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.goods-table th, .goods-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
.goods-table thead th { background: #f7f9fc; color: var(--muted); font-weight: 600; position: sticky; top: 0; }
.goods-table tbody tr:hover { background: #f9fbff; }
.goods-table .loc { color: var(--primary); font-weight: 600; }
.goods-table .qty { font-weight: 700; }
.goods-table .ops { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.goods-table .ops .link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-width: 52px;
    height: 30px;
    padding: 0 12px;
    border: 1px solid currentColor;
    border-radius: 6px;
    font-size: 13px;
}
.goods-table .ops .link.takeout { color: #1a9d5a; }
.goods-table .ops .link.putin { color: #e8831a; }
.goods-table .ops .link:hover { text-decoration: none; opacity: .8; }
.inline-form { display: inline; vertical-align: middle; }
.inline-form .link { vertical-align: middle; }

/* 图片缩略图（列表） */
.goods-table .img-cell { width: 72px; }
.goods-table .thumb {
    width: 52px; height: 52px; object-fit: cover;
    border-radius: 8px; border: 1px solid var(--border);
    cursor: zoom-in; background: #f1f4f9;
    transition: transform .12s, box-shadow .12s;
}
.goods-table .thumb:hover { transform: scale(1.08); box-shadow: 0 2px 10px rgba(31,39,51,.18); }
.goods-table .no-img { color: var(--muted); font-size: 13px; }

/* 上传控件（弹窗内） */
.upload-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
/* 文件框：视觉隐藏但保留在 DOM 中，确保 iOS/安卓能用 JS 唤起选择框（hidden 会被移动端拒绝） */
.file-input-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.file-btn {
    display: inline-flex; align-items: center; gap: 6px;
    height: 44px; padding: 0 16px;
    background: #eef2ff; color: var(--primary);
    border: none; border-radius: 10px; font-size: 14px; font-weight: 600;
    font-family: inherit; line-height: 1;
    cursor: pointer; user-select: none;
    -webkit-appearance: none; appearance: none;
    transition: background .15s;
}
.file-btn:hover { background: #e2e9ff; }
.file-btn:active { transform: translateY(1px); }
.file-name { color: var(--muted); font-size: 13px; }
.img-preview {
    display: flex; align-items: center; gap: 12px;
    margin-top: 12px; padding: 10px;
    border: 1px dashed var(--border); border-radius: 10px;
    background: #fafbfe;
}
.img-preview img {
    width: 64px; height: 64px; object-fit: cover;
    border-radius: 8px; border: 1px solid var(--border); background: #fff;
    cursor: pointer;
}
.img-preview .link { color: var(--error); margin-left: auto; }
.hint { margin: 8px 0 0; }

.empty { background: var(--card); border: 1px dashed var(--border); border-radius: var(--radius); padding: 40px; text-align: center; color: var(--muted); }

/* 弹窗 */
.modal { display: none; position: fixed; inset: 0; z-index: 50; }
.modal.open { display: block; }
.modal-mask { position: absolute; inset: 0; background: rgba(15, 23, 42, .5); backdrop-filter: blur(2px); }
.modal-box {
    position: relative;
    max-width: 520px;
    width: calc(100% - 24px);
    margin: 4vh auto 0;
    background: var(--card);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
    padding: 0;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn .18s ease-out;
}
@keyframes modalIn {
    from { opacity: 0; transform: translateY(14px) scale(.98); }
    to   { opacity: 1; transform: none; }
}
.modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #f8faff, #ffffff);
    flex-shrink: 0;
}
.modal-head h3 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 9px; }
.modal-head h3::before { content: ''; width: 4px; height: 17px; border-radius: 2px; background: var(--primary); }
.modal-close {
    width: 32px; height: 32px; border-radius: 50%;
    border: none; background: #f1f4f9; font-size: 19px; line-height: 1;
    cursor: pointer; color: var(--muted);
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, color .15s;
}
.modal-close:hover { background: #e4e9f2; color: var(--text); }
.modal-box form { display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.modal-body { padding: 18px 20px 6px; overflow-y: auto; flex: 1; min-height: 0; }
.take-name, .take-cur { margin: 0 0 14px; font-size: 14px; color: var(--text); }
.take-cur { color: var(--muted); }
.take-cur b { color: #e23b3b; font-size: 16px; }
.take-name b { color: var(--primary); }
.modal-foot {
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 13px 20px;
    border-top: 1px solid var(--border);
    background: #fafbfe;
    flex-shrink: 0;
}
.modal-foot .btn { min-width: 104px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* 图片放大弹窗 */
#imgModal .img-lightbox {
    position: relative;
    max-width: min(92vw, 760px);
    max-height: 92vh;
    margin: 4vh auto 0;
    display: flex; align-items: center; justify-content: center;
}
#imgModal .img-lightbox img {
    max-width: 100%; max-height: 92vh;
    border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.45);
    background: #fff;
}
#imgModal .img-close { position: fixed; top: 18px; right: 18px; }
#imgModal .img-close:hover { background: #e4e9f2; color: var(--text); }
/* 图片放大弹窗始终居中（覆盖移动端底部弹出规则） */
#imgModal.modal.open { display: flex; align-items: center; justify-content: center; }

/* 手机端：表格变卡片 */
@media (max-width: 640px) {
    .stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .stat { padding: 12px 6px; }
    .stat-num { font-size: 20px; }
    .goods-table { min-width: 0; }
    .goods-table thead { display: none; }
    .goods-table, .goods-table tbody { display: block; width: 100%; }
    .goods-table tr { display: flex; flex-wrap: wrap; border-bottom: 8px solid var(--bg); background: var(--card); }
    .goods-table td { border: none; padding: 8px 14px; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; width: 100%; box-sizing: border-box; }
    .goods-table td::before { content: attr(data-label); color: var(--muted); font-size: 13px; flex-shrink: 0; }
    .goods-table td[data-label="分类"] { display: none; }   /* 手机端不显示分类 */
    /* 手机端卡片分行：① 名称 ② 单位+数量 ③ 位置 ④ 操作 */
    .goods-table td[data-label="图片"]   { order: 0; width: 100%; justify-content: flex-start; }
    .goods-table td[data-label="图片"]::before { display: none; }
    .goods-table td[data-label="图片"] .thumb { width: 64px; height: 64px; }
    /* 有图：左侧图片，右侧商品信息（2 列 grid） */
    .goods-table tr.has-img {
        display: grid;
        grid-template-columns: 88px 1fr 1fr;
        grid-template-rows: auto auto auto auto;   /* 显式 4 行：图片 grid-row:1/-1 才能跨满全部行 */
        column-gap: 10px;
        align-items: start;
    }
    .goods-table tr.has-img td { order: 0; }   /* 取消分行 order，恢复自然顺序 */
    .goods-table tr.has-img td[data-label="图片"] {
        grid-column: 1; grid-row: 1 / -1;
        width: auto; align-self: start;
        padding: 12px 0 12px 14px; justify-content: flex-start;
    }
    .goods-table tr.has-img td[data-label="图片"] .thumb { width: 72px; height: 72px; }
    .goods-table tr.has-img td[data-label="名称"] { grid-area: 1 / 2 / 2 / 4; }   /* 名称独占一整行 */
    .goods-table tr.has-img td[data-label="分类"] { display: none; }               /* 手机端不显示分类 */
    .goods-table tr.has-img td[data-label="单位"] { grid-area: 2 / 2 / 3 / 3; }
    .goods-table tr.has-img td[data-label="数量"] { grid-area: 2 / 3 / 3 / 4; }
    .goods-table tr.has-img td[data-label="位置"] { grid-area: 3 / 2 / 4 / 4; }   /* 位置独占一行 */
    .goods-table tr.has-img td[data-label="操作"] { grid-area: 4 / 2 / 5 / 4; }
    .goods-table tr.has-img td:not([data-label="图片"]) {
        width: 100%; padding-left: 0; padding-right: 14px;
    }
    .goods-table td[data-label="名称"]   { order: 1; width: 66.666%; justify-content: flex-start; }
    .goods-table td[data-label="分类"]   { order: 2; width: 33.333%; justify-content: flex-start; }
    .goods-table td[data-label="单位"]   { order: 3; width: 50%; justify-content: flex-start; }
    .goods-table td[data-label="数量"]   { order: 4; width: 50%; justify-content: flex-start; }
    .goods-table td[data-label="数量"]::before { color: var(--muted); }
    .goods-table td[data-label="数量"] .qval { color: #e23b3b; font-weight: 700; }
    .goods-table td[data-label="位置"]   { order: 5; justify-content: flex-start; }
    .goods-table td[data-label="操作"]   { order: 6; }
    .goods-table .ops { justify-content: flex-end; align-items: center; gap: 10px; border-top: 1px dashed var(--border); margin-top: 4px; }
    .goods-table .ops .link { vertical-align: middle; min-height: 32px; }
    .goods-table .ops .inline-form { display: inline-flex; align-items: center; margin: 0; }
    .form-grid { grid-template-columns: 1fr; gap: 2px; }
    .modal.open { display: flex; align-items: flex-end; justify-content: center; }
    .modal-box { width: 100%; max-width: 100%; margin: 0; border-radius: 16px 16px 0 0; max-height: 92vh; animation: sheetUp .22s ease-out; }
    @keyframes sheetUp {
        from { transform: translateY(40px); opacity: .6; }
        to   { transform: none; opacity: 1; }
    }
    .modal-body { padding: 16px 16px 4px; }
    .modal-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
    .modal-foot .btn { flex: 1; min-width: 0; }
    .toolbar { flex-direction: column; }
    .search-form { min-width: 0; }
}
