:root {
    --bg: #f4f6fb;
    --panel: #ffffff;
    --ink: #1b2431;
    --muted: #7a8699;
    --line: #e5e9f2;
    --sidebar: #111a2b;
    --sidebar-ink: #c8d1e0;
    --primary: #2563eb;
    --primary-ink: #ffffff;
    --danger: #e04343;
    --success: #1f9d64;
    --warn: #d98214;
    --radius: 12px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg);
    color: var(--ink);
    font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.app {
    display: flex;
    min-height: 100vh;
}

/* 侧边栏 */
.sidebar {
    width: 216px;
    flex: 0 0 216px;
    background: var(--sidebar);
    color: var(--sidebar-ink);
    display: flex;
    flex-direction: column;
    padding: 18px 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 18px;
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #22d3ee);
    color: #fff;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.brand-text strong {
    display: block;
    color: #fff;
    font-size: 15px;
    letter-spacing: 1px;
}

.brand-text small {
    color: #8593aa;
    font-size: 12px;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-group {
    margin: 16px 10px 6px;
    font-size: 11px;
    letter-spacing: 1px;
    color: #61708a;
}

.nav-item {
    display: block;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--sidebar-ink);
    text-decoration: none;
    font-size: 14px;
    transition: background .15s ease, color .15s ease;
}

.nav-item:hover {
    background: rgba(255, 255, 255, .06);
    color: #fff;
    text-decoration: none;
}

.nav-item.active {
    background: var(--primary);
    color: #fff;
}

.sidebar-foot {
    margin-top: auto;
    padding: 16px 8px 4px;
    font-size: 11px;
    color: #5b6880;
}

/* 主区域 */
.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 28px 8px;
}

.topbar h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.topbar-actions {
    display: flex;
    gap: 8px;
}

.content {
    padding: 12px 28px 36px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 卡片 */
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.card-head h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.card-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* 统计卡片 */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.stat-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    color: var(--muted);
    font-size: 13px;
}

.stat-value {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: .5px;
}

.stat-foot {
    color: var(--muted);
    font-size: 12px;
}

.split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

/* 表格 */
.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.table thead th {
    background: #f8fafd;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.table tbody tr:hover {
    background: #fafcff;
}

.table tfoot td {
    background: #f8fafd;
}

.table .num {
    text-align: right;
    white-space: nowrap;
}

.mono {
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
}

.muted {
    color: var(--muted);
}

.text-danger {
    color: var(--danger);
    font-weight: 600;
}

.text-success {
    color: var(--success);
    font-weight: 600;
}

.empty {
    padding: 36px 12px;
    text-align: center;
    color: var(--muted);
    background: #fafcff;
    border: 1px dashed var(--line);
    border-radius: 10px;
}

/* 标签 */
.tag {
    display: inline-block;
    padding: 1px 9px;
    border-radius: 999px;
    font-size: 12px;
    line-height: 20px;
    border: 1px solid transparent;
}

.tag-on {
    color: var(--success);
    background: #e9f8f0;
    border-color: #c6ecd8;
}

.tag-off {
    color: #7a8699;
    background: #f0f2f6;
    border-color: #e0e4ec;
}

.tag-warn {
    color: var(--warn);
    background: #fdf3e3;
    border-color: #f6e0bb;
}

.tag-in {
    color: var(--primary);
    background: #eaf1ff;
    border-color: #cddffd;
}

.tag-out {
    color: #b3552a;
    background: #fdefe6;
    border-color: #f6d8c6;
}

/* 金额、详情 */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px 20px;
}

.detail-grid > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.detail-label {
    color: var(--muted);
    font-size: 12px;
}

/* 表单 */
.form-card {
    max-width: 880px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px 20px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
}

.field > span {
    color: #46536a;
    font-weight: 600;
}

.field em {
    color: var(--danger);
    font-style: normal;
}

.field small,
.hint {
    color: var(--muted);
    font-size: 12px;
}

.field-wide {
    grid-column: 1 / -1;
}

.input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d8dee9;
    border-radius: 8px;
    background: #fff;
    font-size: 14px;
    font-family: inherit;
    color: var(--ink);
    transition: border-color .15s ease, box-shadow .15s ease;
}

.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

textarea.input {
    resize: vertical;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.filters .input {
    width: auto;
    min-width: 150px;
}

.checkbox {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #46536a;
    font-size: 13px;
    white-space: nowrap;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid #d8dee9;
    background: #fff;
    color: var(--ink);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
    white-space: nowrap;
}

.btn:hover {
    background: #f4f6fb;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-ink);
}

.btn-primary:hover {
    background: #1d4fd7;
    border-color: #1d4fd7;
    color: #fff;
}

.btn-ghost {
    background: #fff;
    color: #46536a;
}

.btn-danger {
    color: var(--danger);
    border-color: #f0c9c9;
    background: #fff;
}

.btn-danger:hover {
    background: #fdeeee;
}

.btn-sm {
    padding: 3px 10px;
    font-size: 13px;
    border-radius: 6px;
}

.inline {
    display: inline;
    margin: 0;
}

/* 提示条 */
.alert {
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-size: 14px;
}

.alert-success {
    color: #146c46;
    background: #e9f8f0;
    border-color: #c6ecd8;
}

.alert-error {
    color: #9b2c2c;
    background: #fdeeee;
    border-color: #f3cccc;
}

/* 分页 */
.pager {
    margin-top: 16px;
}

.pager .pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    list-style: none;
    padding: 0;
    margin: 0;
}

.pager .pagination li {
    display: inline-flex;
}

.pager .pagination li a,
.pager .pagination li span {
    display: inline-block;
    min-width: 32px;
    padding: 5px 10px;
    text-align: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: #46536a;
    background: #fff;
    text-decoration: none;
    font-size: 13px;
}

.pager .pagination li.active span {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.pager .pagination li.disabled span {
    color: #b7c0cf;
    background: #f8fafd;
}

/* 明细录入 */
#bill-items .input {
    padding: 6px 8px;
    font-size: 13px;
}

#bill-items .num .input {
    text-align: right;
}

/* 响应式 */
@media (max-width: 1100px) {
    .stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .split,
    .detail-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 860px) {
    .app {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex: none;
        padding: 12px;
    }

    .nav {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .nav-group {
        display: none;
    }

    .nav-item {
        padding: 7px 10px;
    }

    .sidebar-foot {
        display: none;
    }

    .topbar,
    .content {
        padding-left: 14px;
        padding-right: 14px;
    }

    .form-grid,
    .stat-grid,
    .split,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .card {
        overflow-x: auto;
    }
}

/* ===== 标签打印 ===== */
.label-body {
    background: #fff;
}

.label-toolbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 18px;
    background: #fff;
    border-bottom: 1px solid var(--line);
}

.label-copies {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #46536a;
    font-size: 13px;
}

.label-copies .input {
    width: 72px;
    padding: 5px 8px;
}

.label-sheet {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 18px;
}

.label-size-form {
    display: inline-flex;
    margin: 0;
}

.label-warn {
    padding: 6px 10px;
    border-radius: 8px;
    background: #fff6e5;
    color: #8a5a00;
    font-size: 12px;
}

.label-copies .input {
    width: auto;
    min-width: 72px;
    padding: 5px 8px;
}

.label-sheet.sheet-40x30 .label {
    width: 40mm;
    height: 30mm;
}

.label-sheet.sheet-40x30 .label-name {
    font-size: 10px;
}

.label-sheet.sheet-60x40 .label {
    width: 60mm;
    height: 40mm;
}

.label-sheet.sheet-60x40 .label-name {
    font-size: 12px;
}

.label-sheet.sheet-60x40 .label-barcode {
    height: 16mm;
}

.barcode-preview {
    margin: 16px 0 4px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fbfcfe;
}

.barcode-preview-img {
    height: 56px;
    max-width: 320px;
    margin: 8px 0 4px;
}

.barcode-preview-img svg {
    display: block;
    width: 100%;
    height: 100%;
}

.barcode-preview-text {
    font-size: 12px;
    color: #46536a;
    letter-spacing: .5px;
}

.inline-form {
    display: inline-flex;
    margin: 0;
}

.check-inline {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 4px 0 16px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #f8fafd;
    color: #46536a;
    font-size: 13px;
    line-height: 1.5;
}

.check-inline input {
    margin-top: 3px;
    accent-color: var(--primary);
}

.label {
    width: 50mm;
    height: 30mm;
    padding: 2mm;
    border: 1px dashed #d0d7e2;
    border-radius: 3px;
    background: #fff;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
}

.label-name {
    font-size: 11px;
    font-weight: 600;
    line-height: 1.25;
    max-height: 2.6em;
    overflow: hidden;
}

.label-title {
    font-size: 10px;
    color: #46536a;
}

.label-order-no {
    font-size: 8px;
    color: #666;
    letter-spacing: .3px;
}

.label-barcode {
    height: 12mm;
    margin: 1mm 0;
}

.label-barcode svg {
    display: block;
    width: 100%;
    height: 100%;
}

.label-sku {
    font-size: 9px;
    text-align: center;
    letter-spacing: .5px;
}

.label-meta {
    display: flex;
    justify-content: space-between;
    gap: 4px;
    font-size: 9px;
    color: #333;
}

@media print {
    .no-print {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .label-sheet {
        padding: 0;
        gap: 0;
    }

    .label {
        border: none;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    @page {
        margin: 4mm;
    }
}

/* ===== 扫码出入库 ===== */
.scan-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.scan-switch {
    display: inline-flex;
    gap: 8px;
}

.scan-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: 1px solid #d8dee9;
    border-radius: 8px;
    cursor: pointer;
    color: #46536a;
    font-size: 14px;
    user-select: none;
}

.scan-option:has(input:checked) {
    border-color: var(--primary);
    color: var(--primary);
    background: #eef4ff;
    font-weight: 600;
}

.scan-option input {
    accent-color: var(--primary);
}

.scan-message {
    flex: 1;
    min-width: 240px;
    padding: 8px 12px;
    border-radius: 8px;
    background: #f4f6fb;
    color: #46536a;
    font-size: 13px;
}

.scan-message.scan-ok {
    background: #e9f8f0;
    color: #146c46;
}

.scan-message.scan-error {
    background: #fdeeee;
    color: #9b2c2c;
}

.scan-input {
    height: 46px;
    font-size: 17px;
    letter-spacing: 1px;
    font-family: Consolas, "Courier New", monospace;
}

#scan-items .scan-qty,
#scan-items .scan-price {
    width: 100%;
    text-align: right;
    padding: 5px 8px;
    font-size: 13px;
}

.scan-flash {
    animation: scanFlash .8s ease;
}

@keyframes scanFlash {
    from {
        background: #e8f2ff;
    }
    to {
        background: transparent;
    }
}

/* ===== 极速扫码 ===== */
.quick-fields {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.quick-fields .input {
    width: 180px;
}

.quick-hint {
    margin: 10px 0 0;
}

.quick-summary {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: #f8fafd;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: #46536a;
    font-size: 13px;
}

.quick-summary strong {
    color: var(--ink);
    font-size: 15px;
}

.quick-log {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 320px;
    overflow-y: auto;
    font-size: 13px;
}

.quick-log li {
    display: flex;
    gap: 10px;
    align-items: baseline;
    padding: 7px 10px;
    border-bottom: 1px dashed var(--line);
}

.quick-log li:last-child {
    border-bottom: none;
}

.quick-log .log-time {
    color: var(--muted);
    font-family: Consolas, "Courier New", monospace;
    font-size: 12px;
    flex: 0 0 auto;
}

.quick-log .log-ok {
    color: #146c46;
}

.quick-log .log-error {
    color: #9b2c2c;
    background: #fdf3f3;
}
