/* ── Reset & Variables ────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-hover: #f0f1f4;
    --border: #e2e4e9;
    --text: #1a1d27;
    --text-dim: #8b8fa3;
    --accent: #4f7cff;
    --accent-hover: #3a66e0;
    --green: #16a34a;
    --orange: #d97706;
    --red: #dc2626;
    --radius: 8px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-hover: #222638;
    --border: #2a2e3a;
    --text: #e1e4eb;
    --text-dim: #8b8fa3;
    --green: #34d399;
    --orange: #f59e0b;
    --red: #ef4444;
}

html { font-size: 16px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    font-size: 1rem;
}

/* ── Header ───────────────────────────────────────── */
.header {
    display: none;
}

/* ── Main ─────────────────────────────────────────── */
main { max-width: 1400px; margin: 0 auto; padding: 12px 20px; }

/* ── Category Tabs ───────────────────────────────── */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.tabs__btn {
    background: var(--surface);
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 8px 18px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all .15s;
}
.tabs__btn:hover { background: var(--surface-hover); color: var(--text); }
.tabs__btn--active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.tabs__btn--active:hover { background: var(--accent-hover); }
.tabs__btn .count {
    color: var(--text-dim);
    font-size: .75rem;
    margin-left: 4px;
}
.tabs__btn--active .count { color: #fff; }
@media (min-width: 769px) {
    .name-short { display: none; }
}
@media (max-width: 768px) {
    /* ── Horizontal scrollable module nav ── */
    .module-nav {
        display: flex;
        overflow-x: auto;
        flex-wrap: nowrap;
        width: 100%;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .module-nav::-webkit-scrollbar { display: none; }
    .module-nav__btn { flex-shrink: 0; }
    .module-nav__item { flex: 0 0 auto; }
    .module-nav__menu { position: fixed; top: 56px; left: 12px; right: 12px; max-width: none; }
    .workspace-tabs { margin-top: -6px; }
    .workspace-detail__header { align-items: stretch; flex-direction: column; }

    .name-full { display: none; }
    .tabs__btn .count { display: none; }
    #recalc-weight-btn,
    #recalc-price-btn { display: none !important; }
    /* ── Mobile form row: stack vertically ── */
    .inv-form__row {
        flex-wrap: wrap;
        gap: 6px;
        margin-bottom: 6px;
    }
    .inv-form__row label {
        min-width: auto;
        font-size: .8rem;
        margin-left: 0 !important;
        flex: 0 0 auto;
    }
    .inv-form__row input,
    .inv-form__row select {
        flex: 1 1 auto;
        min-width: 60px;
        padding: 8px 8px;
        font-size: .9rem;
    }
    .inv-form__row .inv-search-wrap {
        flex: 1 1 100%;
        max-width: none;
    }
    .inv-form__row .inv-search-wrap input {
        width: 100%;
        font-size: .9rem;
        padding: 8px 10px;
    }
    /* ── Mobile batch table: bigger touch targets ── */
    .batch-table input, .batch-table select {
        padding: 6px 6px;
        font-size: .9rem;
    }
    .batch-table td {
        padding: 6px 4px;
    }
    .batch-table .bt-del {
        font-size: 1.2rem;
        padding: 6px 8px;
    }
    /* ── Mobile toolbar: wrap properly ── */
    .toolbar {
        flex-wrap: wrap;
        gap: 6px;
    }
    .toolbar .search-wrap {
        flex: 1 1 100%;
        max-width: none;
    }
    .toolbar .inv-form__select-sm,
    .toolbar input[type="date"] {
        flex: 1 1 auto;
        min-width: 0;
        font-size: .85rem;
    }
    /* ── Mobile modal: fill screen ── */
    .modal {
        min-width: auto !important;
        width: 92vw;
        max-height: 90vh;
        padding: 14px;
    }
    .modal__field {
        flex-wrap: wrap;
        gap: 4px;
    }
    .modal__field label {
        font-size: .85rem;
        flex: 0 0 auto;
    }
    .modal__field .edit-input,
    .modal__field select {
        flex: 1 1 auto;
        width: auto !important;
        min-width: 60px;
        padding: 8px;
        font-size: .9rem;
    }
    .modal .inv-table {
        font-size: .8rem;
    }
    .modal .inv-table input.edit-input {
        width: 40px !important;
        padding: 4px;
        font-size: .8rem;
    }
    .modal .settings-table-wrap {
        max-height: 180px;
    }
    /* 手机端出入库编辑弹窗：标题/内容/按钮分区，内容独立滚动 */
    #order-edit-modal {
        align-items: stretch;
        justify-content: center;
        padding: 10px;
    }
    #order-edit-modal .modal {
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 20px);
        max-height: calc(100vh - 20px);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        padding: 12px;
    }
    #order-edit-modal .modal__title,
    #order-edit-modal .modal__actions {
        flex: 0 0 auto;
    }
    #order-edit-modal .modal__body {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        padding-bottom: 12px;
    }
    #order-edit-modal .modal__body > div:first-child {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }
    #order-edit-modal .modal__field {
        display: grid;
        grid-template-columns: 72px minmax(0, 1fr);
        align-items: center;
        gap: 6px;
    }
    #order-edit-modal .modal__field[style*="grid-column"] {
        grid-column: auto !important;
    }
    #order-edit-modal .modal__field .edit-input,
    #order-edit-modal .modal__field select {
        width: 100% !important;
        min-width: 0;
    }
    #order-edit-modal .modal__field label[style*="margin-left"] {
        margin-left: 0 !important;
    }
    #order-edit-modal .settings-table-wrap {
        overflow-x: auto;
        overflow-y: auto;
        max-height: none;
        -webkit-overflow-scrolling: touch;
    }
    #order-edit-modal #order-edit-items-table {
        table-layout: auto;
        width: max-content;
        min-width: 100%;
    }
    #order-edit-modal .modal__actions {
        background: var(--surface);
        border-top: 1px solid var(--border);
        padding-top: 8px;
        margin-top: 0;
    }
    #order-edit-modal .doc-form__total-row {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        gap: 8px;
        align-items: start;
    }
    #order-edit-modal .doc-form__total-label {
        white-space: nowrap;
    }
    #order-edit-modal .doc-form__total-words {
        min-width: 0;
        word-break: keep-all;
        overflow-wrap: anywhere;
        line-height: 1.6;
    }
    #order-edit-modal .doc-form__total-number {
        grid-column: 1 / -1;
        text-align: right;
        white-space: nowrap;
    }
    /* ── Mobile batch table: keep all columns, horizontal scroll ── */
    .batch-table-wrap {
        max-width: 100%;
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        margin: 6px 0;
    }
    .inv-form.doc-form,
    .inv-form {
        max-width: 100%;
        min-width: 0;
        overflow-x: hidden;
    }
    .inv-table.batch-table {
        table-layout: auto;
        width: 100%;
        min-width: 820px;
    }
    .inv-table.batch-table th:nth-child(1),
    .inv-table.batch-table td:nth-child(1) {
        display: none;
    }
    .inv-table.batch-table th:nth-child(2),
    .inv-table.batch-table td:nth-child(2) {
        width: 145px;
        min-width: 145px;
    }
    .inv-table.batch-table th:nth-child(3),
    .inv-table.batch-table td:nth-child(3) {
        width: 76px;
        min-width: 76px;
    }
    .inv-table.batch-table th:nth-child(4),
    .inv-table.batch-table td:nth-child(4),
    .inv-table.batch-table th:nth-child(6),
    .inv-table.batch-table td:nth-child(6),
    .inv-table.batch-table th:nth-child(9),
    .inv-table.batch-table td:nth-child(9) {
        width: 95px;
        min-width: 95px;
    }
    .inv-table.batch-table th:nth-child(5),
    .inv-table.batch-table td:nth-child(5),
    .inv-table.batch-table th:nth-child(7),
    .inv-table.batch-table td:nth-child(7),
    .inv-table.batch-table th:nth-child(8),
    .inv-table.batch-table td:nth-child(8) {
        width: 120px;
        min-width: 120px;
    }
    .batch-table th,
    .batch-table td {
        padding: 6px 4px;
    }
    .batch-table td input,
    .batch-table td select {
        font-size: 16px;
        min-height: 36px;
    }
    .batch-table td:nth-child(2) input[type="text"] {
        padding: 8px 4px !important;
        font-size: 15px !important;
        min-height: 36px;
    }
    .batch-table td:nth-child(2) select {
        padding: 4px !important;
        font-size: 16px !important;
    }
    /* ── Mobile edit modal table ── */
    #order-edit-items-table th:nth-child(1),
    #order-edit-items-table td:nth-child(1),
    .batch-cat-filter { display: none !important; }
    #order-edit-items-table input.edit-input,
    #order-edit-items-table select {
        width: 100% !important;
        min-width: 0;
        box-sizing: border-box;
        font-size: 16px;
        padding: 6px 4px;
    }
    /* ── Mobile action buttons ── */
    .inv-table td .btn-sm {
        font-size: .75rem;
        padding: 4px 6px;
        margin-right: 2px !important;
        margin-bottom: 2px;
    }
    /* ── Mobile summary cards ── */
    .inv-summary__card {
        flex: 1 1 calc(50% - 8px);
        min-width: 0;
    }
}

/* ── Toolbar ──────────────────────────────────────── */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.search-wrap {
    position: relative;
    flex: 1;
    max-width: 360px;
}
.search-input {
    width: 100%;
    padding: 8px 32px 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    outline: none;
    transition: border-color .15s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-dim); }
.search-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}
.search-clear:hover { background: var(--surface-hover); color: var(--text); }
.toolbar__count { color: var(--text-dim); white-space: nowrap; }

/* ── Table ────────────────────────────────────────── */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.product-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 1rem;
    font-weight: 700;
    white-space: nowrap;
}
.product-table th {
    background: var(--surface);
    color: var(--text-dim);
    font-weight: 500;
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
}
.product-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.product-table tr:last-child td { border-bottom: none; }
.product-table tr:hover td { background: var(--surface-hover); }
.product-table tr:nth-child(even) td { background: #f8f9fb; }
[data-theme="dark"] .product-table tr:nth-child(even) td { background: #14161f; }

.product-table .cell-spec { font-weight: 500; }
.product-table .cell-category {
    color: var(--text-dim);
}
.cell-category.cell-editing { padding: 0; }
.thick-red { color: #dc2626; font-weight: 600; }

/* ── Base Price ──────────────────────────────────── */
.base-price-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.base-price-bar__label { color: var(--text-dim); }
.base-price-bar__value {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--accent);
}
.base-price-bar__edit { display: flex; align-items: center; gap: 6px; }
.base-price-input,
.edit-input {
    width: 120px;
    padding: 4px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    outline: none;
}
.base-price-input:focus,
.edit-input:focus { border-color: var(--accent); }

/* ── Small Buttons ───────────────────────────────── */
.btn-sm {
    padding: 4px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    cursor: pointer;
    transition: all .15s;
}
.btn-sm:hover { background: var(--surface-hover); }
.btn-sm--primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-sm--primary:hover { background: var(--accent-hover); }

.btn-sm--danger { color: var(--red); border-color: var(--red); }
.btn-sm--danger:hover { background: var(--red); color: #fff; }
.btn-sm--success { color: var(--green); border-color: var(--green); }
.btn-sm--success:hover { background: var(--green); color: #fff; }
.price-history-mini-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--accent);
    font-size: .78rem;
    line-height: 24px;
    text-align: center;
    cursor: pointer;
    z-index: 2;
}
.price-history-mini-btn:hover { background: var(--surface-hover); }

/* ── Editable Cells ──────────────────────────────── */
.cell-editable {
    cursor: pointer;
    border-radius: 4px;
    padding: 2px 4px;
    margin: -2px -4px;
    transition: background .1s;
}
.cell-editable:hover { background: rgba(79, 124, 255, .12); }
.cell-editable:focus {
    outline: 2px solid var(--accent);
    outline-offset: 0;
    background: transparent;
}
.cell-null { color: var(--text-dim); font-style: italic; }
.cell-editing { background: rgba(79, 124, 255, .15); }
.cell-computed { color: var(--text-dim); }
.cell-has-premium { color: var(--text); font-weight: 500; }
.cell-premium-pos { color: var(--red); }
.cell-premium-neg { color: var(--green); }

.category-select {
    width: 100%;
    padding: 2px 4px;
    background: var(--surface);
    border: 2px solid var(--accent);
    border-radius: 4px;
    color: var(--text);
    font-size: 1rem;
    outline: none;
    cursor: pointer;
}

/* ── States ───────────────────────────────────────── */
.loading {
    text-align: center;
    color: var(--text-dim);
    padding: 48px 0;
}

/* ── Toast ────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: var(--radius);
    color: var(--green);
    box-shadow: 0 4px 20px rgba(0,0,0,.4);
    transition: opacity .3s;
    z-index: 100;
}
.toast--hidden { opacity: 0; pointer-events: none; }
.toast--error { color: var(--red); }

/* ── Modal ─────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    min-width: 320px;
    box-shadow: 0 8px 32px rgba(0,0,0,.3);
}
/* 桌面端弹窗超高时可滚动：auto margin 在剩余空间充足时居中，不足时顶对齐并出现滚动条（滚动在 overlay 层，不影响 modal 内绝对定位下拉） */
@media (min-width: 769px) {
    .modal-overlay { align-items: flex-start; overflow-y: auto; padding: 20px 0; }
    .modal-overlay .modal { margin-top: auto; margin-bottom: auto; }
}
.modal__title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
}
.modal__body {
    margin-bottom: 16px;
}
.modal__info {
    color: var(--text-dim);
    margin-bottom: 12px;
    line-height: 1.6;
}
.modal__field {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.modal__field .edit-input { width: 160px; }
.modal__field label {
    font-size: 1rem;
    white-space: nowrap;
}
.modal__actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
#price-history-modal .modal {
    width: min(900px, calc(100vw - 24px));
    max-width: calc(100vw - 24px);
}
#price-history-modal {
    z-index: 201;
}
#price-history-modal .modal__body {
    overflow: auto;
}
.history-tabs {
    gap: 6px;
    padding: 8px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 2;
}
.history-tab {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-dim);
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: .9rem;
}
.history-tab--active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
#price-history-modal .settings-table {
    min-width: 680px;
    table-layout: auto;
}
#price-history-modal .settings-table th,
#price-history-modal .settings-table td {
    white-space: nowrap;
}
#price-history-modal .settings-table th:nth-child(2),
#price-history-modal .settings-table td:nth-child(2) {
    max-width: 220px;
    white-space: normal;
}

/* ── Confirm Modal ───────────────────────────── */
.confirm-modal__overlay {
    position: fixed; inset: 0; z-index: 10000;
    background: rgba(0,0,0,.45);
    display: flex; align-items: center; justify-content: center;
    animation: fadeIn .12s ease;
}
.confirm-modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    min-width: 300px;
    max-width: 420px;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
    animation: scaleIn .15s ease;
}
.confirm-modal__title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 8px;
}
.confirm-modal__message {
    font-size: .9rem;
    color: var(--text-dim);
    margin-bottom: 20px;
    line-height: 1.5;
    white-space: pre-line;
}
.confirm-modal__actions {
    display: flex; gap: 8px; justify-content: flex-end;
}
.confirm-modal__btn--cancel {
    padding: 6px 16px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: .9rem;
}
.confirm-modal__btn--cancel:hover { background: var(--surface-hover); }
.confirm-modal__btn--confirm {
    padding: 6px 16px;
    border: 1px solid var(--red);
    border-radius: 4px;
    background: var(--red);
    color: #fff;
    cursor: pointer;
    font-size: .9rem;
    font-weight: 500;
}
.confirm-modal__btn--confirm:hover { opacity: .85; }

/* ── Button loading state ─────────────────────── */
.btn-loading {
    opacity: .6;
    pointer-events: none;
    position: relative;
    color: transparent !important;
}
.btn-loading::after {
    content: '';
    position: absolute;
    left: 50%; top: 50%;
    width: 14px; height: 14px;
    margin: -7px 0 0 -7px;
    border: 2px solid var(--text);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}

/* ── Pagination ───────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 0;
    font-size: .85rem;
    color: var(--text-dim);
}
.pagination__btn {
    padding: 4px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    cursor: pointer;
    font-size: .85rem;
}
.pagination__btn:hover:not(:disabled) { background: var(--surface-hover); }
.pagination__btn:disabled { opacity: .4; cursor: default; }
.pagination__btn--active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.pagination__info { margin: 0 8px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Module Navigation ───────────────────────────── */
.module-nav {
    display: flex;
    gap: 2px;
    margin-bottom: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3px;
    width: 100%;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    position: sticky;
    top: 0;
    z-index: 40;
}
.module-nav__item {
    position: relative;
    display: flex;
    flex: 1;
    min-width: 0;
}
.module-nav__btn {
    padding: 12px 20px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-dim);
    cursor: pointer;
    font-size: .9rem;
    transition: all .15s;
    white-space: nowrap;
    flex: 1;
    text-align: center;
}
.module-nav__item .module-nav__btn { min-width: 0; }
.module-nav__menu-trigger {
    width: 26px;
    flex: 0 0 26px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    font-size: .9rem;
}
.module-nav__menu-trigger:hover,
.module-nav__item--menu-open .module-nav__menu-trigger { color: var(--text); background: var(--surface-hover); }
.module-nav__menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 60;
    min-width: 172px;
    max-height: min(420px, 60vh);
    overflow: auto;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 28px rgba(0,0,0,.16);
}
@media (hover: hover) and (pointer: fine) {
    .module-nav__item:hover .module-nav__menu { display: block; }
}
.module-nav__item--menu-open .module-nav__menu { display: block; }
.module-nav__menu-group + .module-nav__menu-group { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
.module-nav__menu-label { display: block; padding: 4px 8px; color: var(--text-dim); font-size: .75rem; }
.module-nav__menu-item {
    display: block;
    width: 100%;
    padding: 7px 8px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-size: .85rem;
    text-align: left;
    white-space: nowrap;
}
.module-nav__menu-item:hover { background: var(--surface-hover); }
.workspace-tabs {
    display: flex;
    gap: 4px;
    min-height: 38px;
    margin: -8px 0 12px;
    padding: 3px 0;
    overflow-x: auto;
    scrollbar-width: thin;
}
.workspace-tabs:empty { display: none; }
.workspace-tab {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    max-width: 220px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text-dim);
}
.workspace-tab--active { border-color: var(--accent); color: var(--accent); }
.workspace-tab--dirty .workspace-tab__title::after { content: ' *'; color: var(--orange); }
.workspace-tab__activate,
.workspace-tab__close { border: none; background: transparent; color: inherit; cursor: pointer; }
.workspace-tab__activate { overflow: hidden; padding: 7px 6px 7px 10px; text-overflow: ellipsis; white-space: nowrap; }
.workspace-tab__close { padding: 5px 8px; font-size: 1rem; line-height: 1; }
.workspace-tab__close:hover { color: var(--red); }
.workspace-detail__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.workspace-detail__header h2 { font-size: 1.05rem; }
.workspace-detail__header p { margin-top: 3px; color: var(--text-dim); font-size: .85rem; }
.workspace-detail__table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.stock-flow-mini-btn {
    position: absolute;
    right: 6px;
    bottom: 4px;
    z-index: 2;
    padding: 1px 5px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--surface);
    color: var(--accent);
    cursor: pointer;
    font-size: .7rem;
}
.stock-flow-mini-btn:hover { background: var(--surface-hover); }
.module-nav__btn:hover { color: var(--text); background: var(--surface-hover); }
.module-nav__btn--active {
    background: var(--accent);
    color: #fff;
}
.module-nav__btn--active:hover { background: var(--accent-hover); color: #fff; }
.module-nav span[style*="flex:1"] { display: none; }

/* ── Inventory Forms ────────────────────────────── */
.inv-section { display: none; }
.inv-section--active { display: block; }
#section-inbound[data-workspace-view="new"] > .toolbar,
#section-inbound[data-workspace-view="new"] > .inv-table-wrap,
#section-outbound[data-workspace-view="new"] > .toolbar,
#section-outbound[data-workspace-view="new"] > .inv-table-wrap { display: none; }
#section-inbound[data-workspace-view="history"] > .doc-form,
#section-outbound[data-workspace-view="history"] > .doc-form { display: none; }

.inv-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.inv-form__row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.inv-form__row label {
    min-width: 60px;
    font-weight: 500;
    color: var(--text-dim);
    font-size: .9rem;
    white-space: nowrap;
}
.inv-form__row input,
.inv-form__row select {
    flex: 1;
    padding: 6px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    outline: none;
    font-size: .9rem;
}
.inv-form__row input:focus,
.inv-form__row select:focus { border-color: var(--accent); }
.inv-form__actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

/* ── Inventory Tables ───────────────────────────── */
.inv-table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.inv-table {
    border-collapse: collapse;
    font-size: .9rem;
    width: 100%;
    white-space: nowrap;
}
.inv-table th {
    background: var(--surface);
    color: var(--text-dim);
    font-weight: 500;
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
.inv-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.inv-table tr:last-child td { border-bottom: none; }
.inv-table tr:hover td { background: var(--surface-hover); }
.inv-table tr:nth-child(even) td { background: #f8f9fb; }
[data-theme="dark"] .inv-table tr:nth-child(even) td { background: #14161f; }

.inv-stock-qty { font-weight: 600; }
.inv-stock-positive { color: var(--green); }
.inv-stock-low { color: var(--orange); }
.inv-stock-zero { color: var(--text-dim); }
.inv-stock-warning { color: var(--red); font-weight: 700; }
.stock-row--warning { background: #fff5f5; }
[data-theme="dark"] .stock-row--warning { background: #2a1515; }

.inv-type-in { color: var(--green); font-weight: 600; }
.inv-type-out { color: var(--red); font-weight: 600; }

/* ── Category filter for inbound/outbound ───────── */
.inv-cat-filter {
    flex: 0 0 140px;
    padding: 6px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    outline: none;
    font-size: .9rem;
    cursor: pointer;
}
.inv-cat-filter:focus { border-color: var(--accent); }
.inv-cat-filter option { background: var(--surface); color: var(--text); }

/* ── Inventory summary ──────────────────────────── */
.inv-summary {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.inv-summary__card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 18px;
    min-width: 120px;
}
.inv-summary__card-label {
    font-size: .8rem;
    color: var(--text-dim);
    margin-bottom: 4px;
}
.inv-summary__card-value {
    font-size: 1.3rem;
    font-weight: 700;
}

/* ── Product Search Dropdown ─────────────────────── */
.inv-search-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
}
.inv-search-input {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    outline: none;
    font-size: .9rem;
}
.inv-search-input:focus { border-color: var(--accent); }
.inv-search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 240px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-top: 2px;
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
    z-index: 50;
    display: none;
}
.inv-search-dropdown-item {
    padding: 6px 10px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: .85rem;
    display: flex;
    gap: 8px;
    align-items: center;
}
.inv-search-dropdown-item:last-child { border-bottom: none; }
.inv-search-dropdown-item:hover { background: var(--surface-hover); }
.inv-search-dropdown-item__cat {
    color: var(--text-dim);
    font-size: .8rem;
    min-width: 60px;
}
.inv-search-dropdown-item__spec { font-weight: 600; }
.inv-search-dropdown-item__thick { color: var(--text-dim); }
.inv-search-dropdown-item__stock { margin-left: auto; font-weight: 600; }
.inv-search-dropdown-item--active { background: var(--accent); color: #fff; }
.inv-selected-info {
    font-size: .9rem;
    color: var(--text);
    font-weight: 500;
}

/* ── Inbound Enhanced Form ──────────────────────── */
.inv-form__current {
    font-size: .85rem;
    color: var(--text-dim);
    background: var(--bg);
    padding: 8px 12px;
    border-radius: 4px;
    margin: -4px 0 10px 0;
    line-height: 1.6;
}
.inv-form__current strong { color: var(--text); font-weight: 600; }

.inv-form__calc {
    font-size: .85rem;
    background: var(--bg);
    padding: 8px 12px;
    border-radius: 4px;
    margin: 4px 0 10px 0;
    display: none;
    line-height: 1.6;
}
.inv-form__calc--visible { display: block; }
.inv-form__calc strong { color: var(--accent); font-weight: 700; font-size: .95rem; }

.inv-form__sep {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0;
}
.inv-form__sep--label {
    position: relative;
    text-align: center;
    font-size: .8rem;
    color: var(--text-dim);
    margin: 14px 0 10px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

.inv-form__input-sm {
    max-width: 100px;
    padding: 4px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    outline: none;
    font-size: .9rem;
}
.inv-form__input-sm:focus { border-color: var(--accent); }

.inv-form__select-sm {
    flex: 0 0 90px;
    padding: 3px 5px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    outline: none;
    font-size: .9rem;
    cursor: pointer;
}
.inv-form__select-sm:focus { border-color: var(--accent); }

/* ── Batch Table ─────────────────────────────── */
.batch-table-wrap {
    overflow: visible;
    margin: 8px 0;
}
.batch-table { font-size: .85rem; width: 100%; table-layout: fixed; }
.batch-table th {
    background: var(--surface);
    color: var(--text-dim);
    font-weight: 500;
    text-align: left;
    padding: 6px 6px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    font-size: .8rem;
}
.batch-table td {
    padding: 4px 6px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.batch-table tr:last-child td { border-bottom: none; }
.batch-table .bt-select {
    cursor: pointer;
    color: var(--accent);
    font-weight: 500;
    white-space: nowrap;
}
.batch-table .bt-select:hover { text-decoration: underline; }
.batch-table .bt-select__empty { color: var(--text-dim); font-style: italic; font-weight: 400; }
.batch-table input, .batch-table select {
    width: 100%;
    padding: 3px 5px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    outline: none;
    font-size: .85rem;
    box-sizing: border-box;
}
.batch-table input:focus, .batch-table select:focus { border-color: var(--accent); }
.batch-table input[type="number"] { text-align: right; }
.batch-table .bt-del {
    background: none;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 6px;
    border-radius: 3px;
}
.batch-table .bt-del:hover { background: rgba(220,38,38,.1); }
.batch-table .bt-tax { font-size: .8rem; color: var(--text-dim); }
.batch-table .bt-cell-fixed {
    padding: 3px 5px;
    min-height: 22px;
    font-size: .85rem;
    color: var(--text);
}
.batch-table .bt-cell-dim { color: var(--text-dim); }

.batch-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
}
.batch-footer__total {
    margin-left: auto;
    font-weight: 600;
    color: var(--accent);
}

.batch-dd {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
    z-index: 9999;
    display: none;
}
.batch-dd-item {
    padding: 5px 8px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: .8rem;
}
.batch-dd-item:last-child { border-bottom: none; }
.batch-dd-item:hover { background: var(--surface-hover); }
.batch-dd-item--active { background: var(--accent); color: #fff; }
.batch-dd-item--active span { color: inherit !important; }

/* ── Column Resize Handle ───────────────────────── */
.batch-table .bt-resize-handle {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 5px;
    cursor: col-resize;
    z-index: 10;
    user-select: none;
}
.batch-table .bt-resize-handle:hover,
.batch-table .bt-resize-handle--active {
    background: var(--accent);
}
.batch-table th {
    position: relative;
}

/* ── Settings Layout ──────────────────────────── */
.settings-layout {
    display: flex;
    gap: 20px;
    min-height: 500px;
}
.settings-nav {
    flex: 0 0 140px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.settings-nav__btn {
    padding: 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-dim);
    cursor: pointer;
    text-align: left;
    transition: all .15s;
}
.settings-nav__btn:hover { color: var(--text); background: var(--surface-hover); }
.settings-nav__btn--active { background: var(--accent); color: #fff; border-color: var(--accent); }
.settings-nav__btn--active:hover { background: var(--accent-hover); color: #fff; }

.settings-content {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    min-width: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.settings-panel { display: none; }
.settings-panel--active { display: block; }
.settings-panel__title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.settings-panel__section {
    margin-bottom: 20px;
}
.settings-panel__section h4 {
    font-size: .9rem;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 8px;
}
.settings-table-wrap {
    overflow-x: auto;
    margin-bottom: 8px;
}
.settings-add-row {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}
.settings-add-row .edit-input {
    width: 130px;
    padding: 4px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    outline: none;
    font-size: .9rem;
}
.settings-add-row .edit-input:focus { border-color: var(--accent); }
.settings-field {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.settings-field > label {
    font-size: .9rem;
    color: var(--text-dim);
    white-space: nowrap;
    min-width: 60px;
}
.settings-field .edit-input,
.settings-field .inv-form__select-sm {
    padding: 4px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    outline: none;
    font-size: .9rem;
}
.settings-field .edit-input:focus,
.settings-field .inv-form__select-sm:focus { border-color: var(--accent); }
.settings-panel__actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* 产品管理：品类分类栏 */
#section-products #category-tabs {
    background: var(--bg);
    padding-bottom: 8px;
}

@media (max-width: 767px) {
    #section-products #category-tabs {
        overflow: visible;
    }

    #section-products .tabs__more-wrap #tabs-more-dd {
        right: 0;
        left: auto !important;
        max-height: calc(100dvh - 180px) !important;
    }
}

/* 库存查询：摘要+工具栏固定，表格滚动 */
#section-stock.inv-section--active {
    height: calc(100vh - 84px);
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
#section-stock .inv-summary {
    flex: 0 0 auto;
}
#section-stock .toolbar {
    flex: 0 0 auto;
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
}
#section-stock .inv-table-wrap {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
}

/* 财务页与设置页：左侧分类固定，右侧内容独立滚动 */
#section-finance.inv-section--active,
#section-settings.inv-section--active {
    height: calc(100vh - 84px);
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
#section-finance .inv-summary {
    flex: 0 0 auto;
}
#section-finance .settings-layout,
#section-settings .settings-layout {
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    align-items: stretch;
    overflow: hidden;
}
#section-finance .settings-nav,
#section-settings .settings-nav {
    width: max-content;
    min-width: 120px;
    max-height: 100%;
    overflow-y: auto;
    align-self: start;
}
#section-finance .settings-content,
#section-settings .settings-content {
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: auto;
}

@media (max-width: 768px) {
    #section-stock.inv-section--active,
    #section-finance.inv-section--active,
    #section-settings.inv-section--active {
        height: auto;
        overflow: visible;
    }
    #section-stock .inv-table-wrap {
        flex: none;
        overflow: visible;
    }
    #section-finance .settings-layout,
    #section-settings .settings-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
    #section-finance .settings-content,
    #section-settings .settings-content {
        height: auto;
        overflow: visible;
    }
    #section-finance .settings-nav,
    #section-settings .settings-nav {
        width: auto;
        max-height: none;
    }
    #section-stock .inv-table-wrap {
        flex: none;
        overflow: visible;
    }
}

/* ── Document-style Form (inbound/outbound) ──────── */
.doc-form {
    font-family: 'SimSun', 'STSong', serif;
    padding: 20px 24px 16px;
}

.doc-form__header {
    text-align: center;
    margin-bottom: 10px;
}

.doc-form__company {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 6px;
    color: var(--text);
}

.doc-form__title {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: 8px;
    margin-top: 2px;
}

.doc-form__info {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
}

.doc-form__info-row {
    display: flex;
    justify-content: space-between;
    line-height: 1.8;
}

.doc-form__info-col {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.doc-form__info-col .inv-search-wrap {
    flex: 0 1 auto;
    min-width: 140px;
}

.doc-form__info-col .inv-search-wrap input {
    font-family: 'SimSun', 'STSong', serif;
    font-weight: 600;
    font-size: 15px;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    padding: 2px 4px;
    outline: none;
    color: var(--text);
    width: 100%;
}

.doc-form__info-col .inv-search-wrap input:focus {
    border-bottom-color: var(--accent);
}

.doc-form__label {
    white-space: nowrap;
    font-weight: 700;
}

.doc-form__value {
    color: var(--text-dim);
}

.df-input,
.df-select {
    font-family: 'SimSun', 'STSong', serif;
    font-weight: 600;
    font-size: 15px;
    padding: 2px 4px;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    outline: none;
    color: var(--text);
}
.df-input:focus,
.df-select:focus {
    border-bottom-color: var(--accent);
}
.df-btn-fullpay {
    font-family: 'SimSun','STSong',serif;
    font-size: 13px;
    font-weight: 600;
    padding: 2px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.df-btn-fullpay:hover { border-color: var(--accent); color: var(--accent); }
.df-btn-fullpay--active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.df-btn-fullpay--active:hover { background: var(--accent-hover); }
.df-btn-fullpay--changed {
    border-color: var(--text-dim);
    color: var(--text-dim);
    background: var(--bg);
}

/* Table styling within doc-form */
.doc-form .batch-table {
    font-family: 'SimSun', 'STSong', serif;
    font-size: 14px;
}
.doc-form .batch-table th {
    font-weight: 700;
    text-align: center;
    background: var(--surface);
    padding: 6px 8px;
    border: 1px solid var(--border);
}
.doc-form .batch-table td {
    padding: 3px 5px;
    border: 1px solid var(--border);
    vertical-align: middle;
}
.doc-form .batch-table tr:last-child td {
    border-bottom: 1px solid var(--border);
}
.doc-form .batch-table input,
.doc-form .batch-table select {
    font-size: 13px;
}

/* Total row in doc-form */
.doc-form__total-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    font-size: 15px;
    font-weight: 700;
    padding: 8px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin: 4px 0 8px;
}
.doc-form__total-label {
    white-space: nowrap;
}
.doc-form__total-words {
    flex: 1;
    margin-left: 12px;
    letter-spacing: 2px;
    color: var(--text);
}
.doc-form__total-number {
    white-space: nowrap;
    color: var(--accent);
}

/* Signature row */
.doc-form__signature {
    display: flex;
    gap: 24px;
    font-size: 15px;
    font-weight: 600;
    margin-top: 10px;
    padding-top: 4px;
    justify-content: flex-end;
}
.doc-form__sig-item {
    display: flex;
    align-items: center;
    gap: 4px;
}
.doc-form__sig-line {
    display: inline-block;
    width: 80px;
    border-bottom: 1px solid var(--text);
}

/* Mobile adjustments for doc-form */
@media (max-width: 768px) {
    .doc-form {
        padding: 12px 8px 10px;
    }
    .doc-form__title {
        font-size: 20px;
        letter-spacing: 4px;
    }
    .doc-form__info-row {
        flex-wrap: wrap;
        gap: 2px;
    }
    .doc-form__info-col {
        flex: 1 1 100%;
    }
    .doc-form__info-col .inv-search-wrap {
        flex: 1;
    }
    .doc-form__signature {
        display: none;
    }
    .doc-form__total-row {
        flex-wrap: wrap;
        gap: 4px;
    }
    .doc-form__total-words {
        font-size: 13px;
    }
    /* ── Mobile: full-width layout override ── */
    main { padding: 0; }
    .module-nav { display: flex; border-radius: 0; border-left: none; border-right: none; border-top: none; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
    .inv-form { border-radius: 0; border-left: none; border-right: none; padding: 12px 10px; max-width: 100%; min-width: 0; overflow-x: hidden; }
    /* 高特异性压过 base .batch-table-wrap{overflow:visible}(974行)：wrap 成为横滑容器 */
    .doc-form .batch-table-wrap {
        max-width: 100%;
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        margin: 6px 0;
    }
    .inv-table-wrap { border-radius: 0; border-left: none; border-right: none; }
    .table-wrap { border-radius: 0; border-left: none; border-right: none; }
    /* 手机端：保留全部列，表格横向滑动 */
    .batch-cat-filter { display: none !important; }
    .inv-table.batch-table { table-layout: auto; width: 100%; min-width: 820px; }
    .inv-table.batch-table th:nth-child(1),
    .inv-table.batch-table td:nth-child(1) { display: none; }
    .inv-table.batch-table th:nth-child(2),
    .inv-table.batch-table td:nth-child(2) { width: 145px; min-width: 145px; }
    .inv-table.batch-table th:nth-child(3),
    .inv-table.batch-table td:nth-child(3) { width: 76px; min-width: 76px; }
    .inv-table.batch-table th:nth-child(4),
    .inv-table.batch-table td:nth-child(4),
    .inv-table.batch-table th:nth-child(6),
    .inv-table.batch-table td:nth-child(6),
    .inv-table.batch-table th:nth-child(9),
    .inv-table.batch-table td:nth-child(9) { width: 95px; min-width: 95px; }
    .inv-table.batch-table th:nth-child(5),
    .inv-table.batch-table td:nth-child(5),
    .inv-table.batch-table th:nth-child(7),
    .inv-table.batch-table td:nth-child(7),
    .inv-table.batch-table th:nth-child(8),
    .inv-table.batch-table td:nth-child(8) { width: 120px; min-width: 120px; }
    .batch-table th, .batch-table td { padding: 6px 4px; }
    .batch-table td:nth-child(2) input[type="text"] {
        flex: 1 1 auto !important;
        min-width: 50px !important;
        font-size: 15px !important;
        padding: 8px 5px !important;
        min-height: 36px !important;
    }
    .batch-dd { width: max-content; min-width: 100%; max-width: 90vw; right: auto; }
    .batch-dd-item { white-space: nowrap; }
    .base-price-bar { border-radius: 0; border-left: none; border-right: none; }
    .settings-content { border-radius: 0; border-left: none; border-right: none; padding: 12px 10px; }
}
.price-hint:hover {
    opacity: .8;
}

/* ── Workspace tab actions ───────────────────────── */
.workspace-tab { min-width: 88px; }
.workspace-tab__activate { flex: 1 1 auto; min-width: 0; max-width: 164px; }
.workspace-tab__tools { display: flex; align-items: center; flex: 0 0 auto; }

/* This block follows the desktop rules so mobile labels cannot be compressed by them. */
@media (max-width: 768px) {
    .module-nav { overflow-x: auto; flex-wrap: nowrap; }
    .module-nav__item { flex: 0 0 auto; min-width: max-content; }
    .module-nav__item .module-nav__btn { flex: 0 0 auto; min-width: max-content; }
    .module-nav__menu {
        position: fixed;
        top: 56px;
        left: 12px;
        right: 12px;
        max-width: none;
        max-height: calc(100dvh - 72px);
    }
    .workspace-tabs { flex-wrap: nowrap; margin: -6px 0 10px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .workspace-tabs::-webkit-scrollbar { display: none; }
    .workspace-tab { flex: 0 0 auto; min-width: 88px; max-width: 72vw; }
    .workspace-tab__activate { max-width: calc(72vw - 58px); }
}

/* ── Operations UI refresh ───────────────────────── */
:root {
    --ui-control-height: 32px;
    --ui-control-radius: 6px;
    --ui-focus: 0 0 0 3px rgba(79,124,255,.2);
}
.btn-sm {
    min-height: var(--ui-control-height);
    padding: 0 11px;
    border-radius: var(--ui-control-radius);
    border-color: var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: .82rem;
    font-weight: 500;
    box-shadow: none;
}
.btn-sm:hover { border-color: #b9c1d1; background: var(--surface-hover); }
.btn-sm:focus-visible,
.module-nav__btn:focus-visible,
.workspace-tab button:focus-visible { outline: none; box-shadow: var(--ui-focus); }
.btn-sm--primary {
    min-height: 36px;
    padding: 0 16px;
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 5px rgba(79,124,255,.22);
}
.btn-sm--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-sm--danger { color: var(--red); border-color: rgba(220,38,38,.35); }
.btn-sm--success { color: var(--green); border-color: rgba(22,163,74,.35); }
.module-nav {
    gap: 0;
    margin-bottom: 10px;
    padding: 0 4px;
    border-radius: 6px;
    box-shadow: none;
}
.module-nav__btn {
    min-height: 42px;
    padding: 0 14px;
    border-radius: 0;
    color: var(--text-dim);
    font-weight: 500;
}
.module-nav__btn--active,
.module-nav__btn--active:hover {
    background: transparent;
    color: var(--accent);
    box-shadow: inset 0 -2px 0 var(--accent);
}
.module-nav__menu-trigger { border-radius: 4px; }
.workspace-tabs { gap: 0; margin: 0 0 12px; padding: 0; border-bottom: 1px solid var(--border); }
.workspace-tab { margin-bottom: -1px; border: none; border-radius: 0; background: transparent; }
.workspace-tab--active { color: var(--accent); background: var(--surface); box-shadow: inset 0 -2px 0 var(--accent); }
.workspace-tab__activate { padding: 8px 7px 8px 10px; font-size: .84rem; }
.workspace-tab__tools { opacity: .55; }
.workspace-tab:hover .workspace-tab__tools,
.workspace-tab--active .workspace-tab__tools { opacity: 1; }
.tabs { gap: 6px; margin-bottom: 10px; }
.tabs__btn { padding: 6px 10px; border-radius: 5px; font-size: .82rem; }
.tabs__btn--active { box-shadow: none; }
.toolbar { gap: 8px; padding: 8px 0; }
.toolbar__count { margin-left: 2px; font-size: .8rem; }
.doc-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.doc-actions__tools { display: flex; flex-wrap: wrap; gap: 6px; }
.doc-form .batch-table th { font-size: .76rem; color: var(--text-dim); font-weight: 600; }
.inv-table tbody tr:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); }
.inv-table td .btn-sm { min-height: 28px; padding: 0 8px; font-size: .76rem; }
.order-actions { position: relative; white-space: nowrap; }
.order-actions > .btn-sm { margin-right: 4px; }
.order-actions__more { display: inline-block; position: relative; }
.order-actions__more summary { list-style: none; cursor: pointer; }
.order-actions__more summary::-webkit-details-marker { display: none; }
.order-actions__more[open] > div {
    position: absolute;
    right: 0;
    z-index: 30;
    display: flex;
    min-width: 160px;
    padding: 6px;
    gap: 4px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    box-shadow: 0 8px 20px rgba(0,0,0,.14);
}
.inv-summary__card { transition: border-color .15s, background .15s, transform .15s; }
.inv-summary__card[role="button"] { cursor: pointer; }
.inv-summary__card[role="button"]:hover { border-color: var(--accent); background: var(--surface-hover); transform: translateY(-1px); }
.inv-summary__card--active { border-color: var(--accent) !important; background: color-mix(in srgb, var(--accent) 7%, var(--surface)); }
.settings-nav { padding: 6px; border-radius: 6px; background: var(--surface); }
.settings-nav__btn { border-radius: 4px; font-size: .84rem; font-weight: 500; }
.settings-nav__btn--active,
.settings-nav__btn--active:hover { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); border-color: transparent; color: var(--accent); box-shadow: inset 2px 0 0 var(--accent); }
.settings-panel__title { font-size: 1rem; letter-spacing: 0; }
.settings-panel__section { border-radius: 6px; }
.settings-add-row { gap: 6px; }
@media (max-width: 768px) {
    .module-nav { margin-bottom: 8px; }
    .workspace-tabs { margin-bottom: 8px; }
    .doc-actions { align-items: stretch; flex-direction: column; }
    .doc-actions__tools { width: 100%; }
    .doc-actions > .btn-sm--primary { width: 100%; }
}
