/* ==========================================================================
   库存管理系统 · 界面样式
   浅色主题，桌面侧边栏 + 移动端抽屉，表格与表单自适应
   ========================================================================== */

:root {
    --bg: #f4f6f9;
    --panel: #ffffff;
    --panel-2: #fafbfc;
    --line: #e5e8ee;
    --line-strong: #d6dae2;
    --text: #1c2330;
    --text-2: #4b5565;
    --muted: #8b93a3;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eef3ff;
    --success: #12855f;
    --success-soft: #e8f7f0;
    --danger: #d33c3c;
    --danger-soft: #fdeeee;
    --warn: #b7791f;
    --warn-soft: #fdf5e6;
    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 1px 3px rgba(24, 39, 75, .06), 0 8px 24px rgba(24, 39, 75, .05);
    --sidebar-w: 216px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
            "Microsoft YaHei", "Source Han Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
.ico { width: 17px; height: 17px; flex: none; vertical-align: -3px; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex: none;
    background: #101a2b;
    color: #c9d1e0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 18px 16px;
    color: #fff;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.brand-mark {
    width: 30px; height: 30px; border-radius: 8px;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px;
}
.brand-text { font-size: 14px; font-weight: 600; letter-spacing: .3px; }
.brand-text small { display: block; font-size: 11px; color: #7f8ca3; font-weight: 400; letter-spacing: 0; }

.nav { flex: 1; overflow-y: auto; padding: 10px 8px 20px; }
.nav::-webkit-scrollbar { width: 5px; }
.nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 3px; }

.nav-group-title {
    padding: 14px 12px 6px;
    font-size: 11px;
    color: #6b7891;
    letter-spacing: .6px;
}
.nav a {
    display: flex; align-items: center; gap: 9px;
    padding: 8px 12px;
    border-radius: 7px;
    color: #c2cbdb;
    font-size: 13.5px;
    margin-bottom: 1px;
    transition: background .15s, color .15s;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; font-weight: 500; }
.nav a.active .ico { color: #fff; }
.nav .ico { color: #8c99b0; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: 56px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar .menu-btn { display: none; }
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-spacer { flex: 1; }

.user-chip {
    display: flex; align-items: center; gap: 8px;
    padding: 5px 10px 5px 6px;
    border-radius: 20px;
    border: 1px solid var(--line);
    color: var(--text-2);
    font-size: 13px;
}
.user-chip:hover { background: var(--panel-2); }
.avatar {
    width: 26px; height: 26px; border-radius: 50%;
    background: var(--primary-soft); color: var(--primary);
    display: grid; place-items: center; font-size: 12px; font-weight: 600;
}

.content { padding: 18px 20px 40px; flex: 1; }

/* ---------- 通用组件 ---------- */
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card-head {
    display: flex; align-items: center; gap: 10px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--line);
}
.card-head h3 { font-size: 14.5px; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h2 { font-size: 18px; }
.page-head .sub { color: var(--muted); font-size: 12.5px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    height: 34px; padding: 0 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: #fff;
    color: var(--text-2);
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: all .15s;
    font-family: inherit;
}
.btn:hover { border-color: #c3c9d4; background: var(--panel-2); color: var(--text); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-danger { color: var(--danger); border-color: #f0cccc; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); border-color: #e8b4b4; color: var(--danger); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.94); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-icon { width: 32px; padding: 0; justify-content: center; }

.input, .select, textarea.input {
    width: 100%;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--text);
    font-size: 13.5px;
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.6; }
.input:focus, .select:focus, textarea.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b93a3' stroke-width='2.4'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; padding-right: 26px; }

.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 4px; }
.field .req { color: var(--danger); margin-left: 2px; }
.field .help { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.field-inline { display: flex; align-items: center; gap: 8px; }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cfd5df; border-radius: 20px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(18px); }

/* 筛选栏 */
.toolbar {
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-2);
    border-radius: var(--radius) var(--radius) 0 0;
}
.toolbar .input, .toolbar .select { width: auto; min-width: 130px; height: 32px; font-size: 13px; }
.toolbar .grow { flex: 1; min-width: 160px; }
.toolbar .spacer { flex: 1; }

/* 表格 */
.table-wrap { overflow: auto; max-height: calc(100vh - 260px); }
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.grid th {
    position: sticky; top: 0; z-index: 2;
    background: #f7f8fa;
    text-align: left;
    font-weight: 600;
    color: var(--text-2);
    padding: 9px 12px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
    font-size: 12.5px;
}
table.grid td {
    padding: 9px 12px;
    border-bottom: 1px solid #f0f2f5;
    color: var(--text);
    vertical-align: middle;
}
table.grid tbody tr:hover td { background: #fafbfd; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.actions { white-space: nowrap; text-align: right; }
table.grid tr.total td { background: #f7f8fa; font-weight: 600; }
table.grid .muted { color: var(--muted); font-size: 12px; }
table.grid .title-cell { font-weight: 500; }
table.grid .spec { display: block; color: var(--muted); font-size: 12px; }
table.grid.compact td, table.grid.compact th { padding: 6px 10px; }
table.grid tr.tree-lv1 td:first-child { padding-left: 34px; }
table.grid tr.tree-lv2 td:first-child { padding-left: 58px; }

.empty {
    padding: 48px 20px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}
.empty svg { width: 40px; height: 40px; opacity: .35; display: block; margin: 0 auto 8px; }

/* 标签 */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    height: 21px; padding: 0 8px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 500;
    background: #f0f2f5; color: var(--text-2);
    white-space: nowrap;
}
.badge-blue { background: var(--primary-soft); color: var(--primary); }
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-gray { background: #f0f2f5; color: var(--muted); }

/* 统计卡片 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 14px 16px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 24px; font-weight: 650; letter-spacing: -.4px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .unit { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 3px; }
.stat.accent .value { color: var(--primary); }
.stat.ok .value { color: var(--success); }
.stat.warn .value { color: var(--warn); }
.stat.bad .value { color: var(--danger); }

/* 快捷入口 */
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.quick a {
    display: flex; flex-direction: column; align-items: center; gap: 7px;
    padding: 16px 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 13px;
    background: var(--panel);
    transition: all .15s;
}
.quick a:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow); }
.quick .ico { width: 21px; height: 21px; }

/* 提示 */
.flashes { position: fixed; top: 66px; right: 18px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.flash {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: #fff;
    border: 1px solid var(--line);
    box-shadow: 0 6px 20px rgba(24,39,75,.12);
    font-size: 13px;
    animation: slidein .22s ease;
    max-width: 380px;
}
.flash.success { border-left: 3px solid var(--success); }
.flash.error { border-left: 3px solid var(--danger); }
.flash .ico { width: 16px; height: 16px; }
.flash.success .ico { color: var(--success); }
.flash.error .ico { color: var(--danger); }
@keyframes slidein { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* 弹窗 */
.modal-back {
    position: fixed; inset: 0; background: rgba(16, 26, 43, .45);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 40px 16px; z-index: 100; overflow-y: auto;
}
.modal {
    background: #fff; border-radius: 12px; width: 100%; max-width: 620px;
    box-shadow: 0 24px 60px rgba(16,26,43,.22); animation: pop .18s ease;
    margin: auto 0;
}
.modal.wide { max-width: 880px; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 15px; }
.modal-head .close { margin-left: auto; border: 0; background: none; cursor: pointer; color: var(--muted); padding: 4px; border-radius: 6px; }
.modal-head .close:hover { background: #f2f4f7; color: var(--text); }
.modal-body { padding: 18px; max-height: calc(100vh - 220px); overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 13px 18px; border-top: 1px solid var(--line); background: var(--panel-2); border-radius: 0 0 12px 12px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* 分页 */
.pager { display: flex; align-items: center; gap: 6px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.pager .info { color: var(--muted); font-size: 12.5px; margin-right: auto; }
.pager a, .pager span.cur {
    min-width: 30px; height: 30px; padding: 0 8px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--line-strong); border-radius: 6px;
    font-size: 12.5px; color: var(--text-2); background: #fff;
}
.pager span.cur { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager a:hover { border-color: var(--primary); color: var(--primary); }

/* 单据明细编辑 */
.items-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.items-table th {
    background: #f7f8fa; padding: 8px 6px; text-align: left; font-size: 12.5px;
    color: var(--text-2); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.items-table td { padding: 4px 6px; border-bottom: 1px solid #f2f4f7; }
.items-table td .input { height: 30px; font-size: 13px; padding: 0 7px; }
.items-table .col-no { width: 36px; text-align: center; color: var(--muted); }
.items-table .col-qty { width: 96px; }
.items-table .col-price { width: 96px; }
.items-table .col-amount { width: 100px; text-align: right; font-variant-numeric: tabular-nums; }
.items-table .col-unit { width: 62px; color: var(--text-2); }
.items-table .col-del { width: 40px; }
.items-table .mat-name { font-weight: 500; }
.items-table .mat-sub { color: var(--muted); font-size: 11.5px; }
.items-table tbody tr.dragging { opacity: .4; }

.mat-pick {
    display: flex; align-items: center; gap: 6px;
    border: 1px dashed var(--line-strong); border-radius: 6px;
    padding: 3px 8px; cursor: pointer; min-height: 30px; background: #fff;
}
.mat-pick:hover { border-color: var(--primary); }

/* 登录页 */
.login-wrap {
    min-height: 100vh; display: grid; place-items: center;
    background: radial-gradient(1200px 600px at 20% -10%, #dbe7ff 0%, transparent 55%),
                radial-gradient(900px 500px at 110% 20%, #e6f0ff 0%, transparent 50%), #f4f6f9;
    padding: 24px;
}
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 30px 26px; box-shadow: 0 20px 50px rgba(16,26,43,.13); border: 1px solid rgba(255,255,255,.6); }
.login-card .brand-mark { width: 42px; height: 42px; font-size: 18px; margin-bottom: 14px; }
.login-card h1 { font-size: 19px; margin-bottom: 4px; }
.login-card .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 20px; }
.login-card .btn { width: 100%; height: 40px; justify-content: center; font-size: 14px; margin-top: 6px; }
.login-foot { text-align: center; color: var(--muted); font-size: 11.5px; margin-top: 18px; }

/* 详情页 */
.detail-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 20px; padding: 16px; }
.detail-head .item .k { font-size: 11.5px; color: var(--muted); }
.detail-head .item .v { font-size: 13.5px; margin-top: 1px; word-break: break-all; }

/* 打印 */
@media print {
    .sidebar, .topbar, .flashes, .no-print { display: none !important; }
    .content { padding: 0; }
    body { background: #fff; }
}

/* 移动端 */
@media (max-width: 900px) {
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0;
        transform: translateX(-100%);
        transition: transform .22s ease;
        box-shadow: 8px 0 30px rgba(16,26,43,.2);
    }
    body.nav-open .sidebar { transform: none; }
    body.nav-open::after {
        content: ""; position: fixed; inset: 0; background: rgba(16,26,43,.35); z-index: 35;
    }
    .topbar .menu-btn { display: inline-flex; }
    .content { padding: 14px 12px 40px; }
    .form-grid { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat .value { font-size: 20px; }
    .table-wrap { max-height: none; }
    table.grid { min-width: 640px; }
    .modal-back { padding: 12px 8px; }
    .modal-body { max-height: calc(100vh - 180px); }
    .page-head h2 { font-size: 16px; }
    .toolbar .input, .toolbar .select { min-width: 0; flex: 1 1 120px; }
    .hide-sm { display: none !important; }
}

@media (max-width: 560px) {
    .stats { grid-template-columns: 1fr 1fr; }
    .login-card { padding: 24px 18px; }
}
