:root {
    --ink: #182033;
    --muted: #667085;
    --line: #d8dee9;
    --surface: #ffffff;
    --soft: #f5f7fb;
    --accent: #116a5c;
    --accent-strong: #0d554a;
    --danger: #b42318;
    --warning: #b54708;
    --shadow: 0 12px 28px rgba(27, 39, 67, 0.08);
    --mint-header: #a6e4ba;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: #eef2f7;
    font-family: "Segoe UI", Arial, sans-serif;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: #e6f4f1;
}

.login-card {
    width: min(380px, calc(100vw - 32px));
    display: grid;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    padding: 24px;
    box-shadow: var(--shadow);
}

.login-logo {
    max-width: 180px;
    margin: 0 auto 8px;
}

.staff-role .admin-only {
    display: none !important;
}

.staff-role.staff-purchase-mode .cost-column,
.staff-role.staff-purchase-mode .purchase-summary {
    display: none !important;
}

.admin-role.staff-purchase-mode .cost-column,
.admin-role.staff-purchase-mode .purchase-summary {
    display: none !important;
}

.user-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-form {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) 140px auto;
    gap: 10px;
    margin-bottom: 14px;
}

.password-cell {
    display: flex;
    align-items: center;
    gap: 6px;
}

.password-cell input {
    min-width: 0;
}

.password-cell button {
    width: 36px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: #e6f4f1;
    color: var(--accent);
    cursor: pointer;
}

.remember-line {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
}

.remember-line input {
    width: 18px;
    height: 18px;
}

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

.sidebar {
    background: var(--mint-header);
    color: var(--ink);
    padding: 8px 18px;
    display: flex;
    align-items: center;
    gap: 18px;
}

.brand-logo {
    width: 156px;
    height: 54px;
    object-fit: contain;
    object-position: left center;
    display: block;
}

nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-left: auto;
}

.nav-btn {
    border: 0;
    border-radius: 8px;
    padding: 12px 14px;
    color: #102033;
    background: transparent;
    text-align: center;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.nav-btn.active,
.nav-btn:hover {
    color: #075e54;
    background: rgba(255, 255, 255, 0.55);
}

.main {
    min-width: 0;
    padding: 14px 18px 22px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    margin-bottom: 18px;
}

.page-heading {
    display: none;
}

.topbar h2 {
    margin: 0;
    font-size: 28px;
}

.topbar p {
    margin: 6px 0 0;
    color: var(--muted);
}

.search-box input,
label input,
label select,
input[type="file"] {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    font: inherit;
    background: #fff;
}

.inline-search {
    width: min(320px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
}

.supplier-search {
    width: 100%;
    margin-bottom: 12px;
}

#salesProductSearch {
    min-height: 46px;
    font-size: 16px;
}

.divider {
    height: 1px;
    background: var(--line);
    margin: 16px 0;
}

.combo {
    position: relative;
    margin-bottom: 12px;
}

.combo-button {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}

.combo-button::after {
    content: "⌄";
    float: right;
}

.combo-menu {
    display: none;
    position: absolute;
    z-index: 20;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.combo.open .combo-menu {
    display: block;
}

.combo-menu input {
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    padding: 11px 12px;
    font: inherit;
    outline: none;
}

.combo-options {
    max-height: 260px;
    overflow-y: auto;
}

.bank-combo {
    margin-bottom: 12px;
}

.bank-options {
    max-height: 320px;
}

.combo-option {
    padding: 10px 12px;
    cursor: pointer;
}

.combo-option:hover,
.invoice-supplier-option:hover {
    background: #f1f7f6;
}

.invoice-supplier-option {
    padding: 10px 12px;
    cursor: pointer;
}

tr.clickable {
    cursor: pointer;
}

tr.clickable:hover td {
    background: #f1f7f6;
}

.search-box {
    width: min(380px, 100%);
}

.view {
    display: none;
}

.view.active {
    display: grid;
    gap: 18px;
}

#purchasesView.active {
    flex: 1;
    min-height: 0;
}

#productsView.active.receiving-setup-hidden {
    flex: 1;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 14px;
}

.metric,
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.metric {
    padding: 18px;
}

.metric span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.metric strong {
    display: block;
    margin-top: 10px;
    font-size: 30px;
}

.split,
.grid-layout,
.upload-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(360px, 0.75fr);
    gap: 18px;
}

.grid-layout {
    grid-template-columns: 360px minmax(0, 1fr);
}

.upload-layout {
    grid-template-columns: 380px minmax(0, 1fr);
}

.panel {
    padding: 16px;
    min-width: 0;
}

.settings-panel {
    margin-top: 18px;
}

.prefix-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 12px;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 7px;
    background: #94a3b8;
}

.status-dot.online {
    background: #10b981;
}

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

.panel-head h3 {
    margin: 0;
    font-size: 18px;
}

.pill {
    border-radius: 999px;
    padding: 7px 10px;
    color: var(--accent);
    background: #e6f4f1;
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
}

.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.receiving-toolbar {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) auto auto;
    gap: 10px;
    align-items: center;
}

.receiving-file-order {
    gap: 5px;
    margin-top: 9px;
    max-width: 720px;
}

.receiving-file-order-row {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr) 32px 32px;
    gap: 5px;
    align-items: center;
    min-height: 34px;
    border: 1px solid var(--line);
    background: #f8fbfc;
    padding: 3px 5px;
}

.receiving-file-page {
    text-align: center;
    color: var(--accent);
    font-weight: 900;
}

.receiving-file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.receiving-file-move {
    width: 32px;
    height: 28px;
    border: 0;
    border-radius: 6px;
    background: #e3f5f2;
    color: var(--accent);
    font-size: 18px;
    font-weight: 900;
    cursor: pointer;
}

.receiving-file-move:disabled {
    opacity: 0.3;
    cursor: default;
}

.receiving-mapping-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.checkbox-row {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    align-items: center;
    margin-top: 14px;
}

.checkbox-row label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
}

.checkbox-row input {
    width: 18px;
    height: 18px;
}

.checkbox-row .vat-option {
    gap: 7px;
}

.checkbox-row .vat-option input[type="number"] {
    width: 82px;
    padding: 8px 10px;
}

.receiving-table-wrap {
    max-height: calc(100vh - 380px);
    max-width: 100%;
    overflow: auto;
    scrollbar-gutter: stable both-edges;
}

.receiving-table-wrap table {
    width: max-content;
    min-width: 100%;
}

.receiving-table-wrap th,
.receiving-table-wrap td {
    min-width: 120px;
    max-width: 360px;
    vertical-align: top;
}

.receiving-table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.receiving-preview-summary {
    display: flex;
    align-items: center;
    gap: 8px;
}

#productsView.receiving-setup-hidden #receivingUploadPanel,
#productsView.receiving-setup-hidden #receivingMappingPanel,
#productsView.receiving-setup-hidden #receivingPreviewPanel,
#productsView.receiving-setup-hidden .receiving-setup-panel {
    display: none !important;
}

.receiving-header-row td {
    background: #fff3c4;
    font-weight: 900;
}

.receiving-duplicate-1 { background: #ffe2e2; font-weight: 900; }
.receiving-duplicate-2 { background: #fff0bf; font-weight: 900; }
.receiving-duplicate-3 { background: #d9fbe6; font-weight: 900; }
.receiving-duplicate-4 { background: #dbeafe; font-weight: 900; }
.receiving-duplicate-5 { background: #f3e8ff; font-weight: 900; }
.receiving-duplicate-6 { background: #cffafe; font-weight: 900; }
.receiving-duplicate-7 { background: #fde68a; font-weight: 900; }
.receiving-duplicate-8 { background: #fecdd3; font-weight: 900; }

.receiving-workbook-head {
    align-items: flex-start;
}

.receiving-workbook-head > .receiving-preview-summary {
    display: none;
}

.receiving-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.receiving-bulk-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    justify-content: space-between;
    margin: 0 0 12px;
}

.receiving-bulk-left,
.receiving-bulk-right {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.receiving-bulk-right {
    margin-left: auto;
    justify-content: flex-end;
}

.receiving-bulk-tools label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
}

.receiving-bulk-tools input[type="number"] {
    width: 96px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    font: inherit;
}

.receiving-filter-input {
    width: 220px;
    max-width: 24vw;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    font: inherit;
}

.receiving-tab {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #eef6f3;
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    max-width: 96px;
    min-width: 72px;
    height: 34px;
    white-space: nowrap;
    overflow: hidden;
}

.receiving-tab span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.receiving-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.receiving-tab i {
    font-style: normal;
    font-size: 16px;
    line-height: 1;
}

.receiving-match-wrap {
    overflow: auto;
}

.receiving-workbook-panel {
    min-height: 0;
}

#productsView.receiving-setup-hidden .receiving-workbook-panel {
    display: flex;
    flex-direction: column;
}

#productsView.receiving-setup-hidden .receiving-match-wrap {
    flex: 1;
    min-height: 220px;
}

.receiving-match-table {
    width: max-content;
    min-width: 100%;
}

.receiving-match-table th {
    position: sticky;
    top: 0;
    z-index: 3;
}

.receiving-match-table th,
.receiving-match-table td {
    min-width: 130px;
    vertical-align: top;
    border-left: 0;
    border-right: 0;
}

.receiving-match-table tbody tr.receiving-row-odd > td {
    background: #ffffff;
    box-shadow: inset 0 9999px #ffffff;
}

.receiving-match-table tbody tr.receiving-row-even > td {
    background: #dceaf8;
    box-shadow: inset 0 9999px #dceaf8;
}

.receiving-match-table tbody tr:hover > td {
    background: #caebdd;
    box-shadow: inset 0 9999px #caebdd;
}

.receiving-ref-cell {
    cursor: cell;
}

.receiving-selectable-cell {
    user-select: none;
}

.receiving-match-table td.receiving-cell-selected {
    background: #b7f0d4 !important;
    box-shadow: inset 0 0 0 2px #00866f, inset 0 9999px #b7f0d4 !important;
}

.receiving-match-table td.receiving-cell-selected .table-input {
    font-weight: 900;
}

.receiving-match-table td.receiving-duplicate-1 { background: #ffe2e2; font-weight: 900; }
.receiving-match-table td.receiving-duplicate-2 { background: #fff0bf; font-weight: 900; }
.receiving-match-table td.receiving-duplicate-3 { background: #d9fbe6; font-weight: 900; }
.receiving-match-table td.receiving-duplicate-4 { background: #dbeafe; font-weight: 900; }
.receiving-match-table td.receiving-duplicate-5 { background: #f3e8ff; font-weight: 900; }
.receiving-match-table td.receiving-duplicate-6 { background: #cffafe; font-weight: 900; }
.receiving-match-table td.receiving-duplicate-7 { background: #fde68a; font-weight: 900; }
.receiving-match-table td.receiving-duplicate-8 { background: #fecdd3; font-weight: 900; }

.receiving-match-table td.receiving-haru-duplicate {
    background: #ffe4e6 !important;
    box-shadow: inset 0 0 0 2px #f43f5e, inset 0 9999px #ffe4e6 !important;
    font-weight: 900;
}

.receiving-match-table th:nth-child(1),
.receiving-match-table td:nth-child(1),
.receiving-match-table th:nth-child(2),
.receiving-match-table td:nth-child(2),
.receiving-match-table th:nth-child(11),
.receiving-match-table td:nth-child(11) {
    min-width: 56px;
    width: 56px;
}

.receiving-match-table th:nth-child(3),
.receiving-match-table td:nth-child(3),
.receiving-match-table th:nth-child(7),
.receiving-match-table td:nth-child(7) {
    min-width: 150px;
    width: 150px;
}

.receiving-match-table th:nth-child(4),
.receiving-match-table td:nth-child(4),
.receiving-match-table th:nth-child(8),
.receiving-match-table td:nth-child(8) {
    min-width: 300px;
    width: 300px;
}

.receiving-match-table th:nth-child(5),
.receiving-match-table td:nth-child(5),
.receiving-match-table th:nth-child(6),
.receiving-match-table td:nth-child(6),
.receiving-match-table th:nth-child(9),
.receiving-match-table td:nth-child(9),
.receiving-match-table th:nth-child(10),
.receiving-match-table td:nth-child(10) {
    min-width: 104px;
    width: 104px;
}

.receiving-qty-cell {
    font-weight: 800;
    white-space: nowrap;
    vertical-align: middle !important;
}

.receiving-qty-inner {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    min-height: 34px;
}

.receiving-qty-cell input {
    display: inline-block;
    width: 58px;
    min-width: 48px;
    flex: 1 1 auto;
}

.receiving-qty-diff {
    display: inline-block;
    min-width: 22px;
    white-space: nowrap;
    font-size: 12px;
    font-weight: 900;
}

.receiving-qty-stepper {
    display: inline-flex;
    flex-direction: column;
    gap: 1px;
}

.receiving-qty-stepper button {
    width: 18px;
    height: 15px;
    border: 1px solid #b9c7d8;
    border-radius: 3px;
    background: #f8fbfc;
    color: #0f766e;
    font-size: 11px;
    font-weight: 900;
    line-height: 1;
    padding: 0;
    cursor: pointer;
}

.receiving-qty-stepper button:hover {
    background: #dff3ef;
}

.receiving-qty-less input,
.receiving-qty-less .receiving-qty-diff {
    color: #c00000;
}

.receiving-qty-more input,
.receiving-qty-more .receiving-qty-diff {
    color: #2494d3;
}

.receiving-name-input {
    min-height: 34px;
    max-height: 96px;
    resize: vertical;
    white-space: normal;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.receiving-missing-product {
    color: #c00000 !important;
    font-weight: 900;
}

.receiving-match-table .table-input,
.receiving-match-table .table-input:focus {
    background: transparent;
}

.receiving-product-cell {
    position: relative;
    overflow: visible;
}

.receiving-sku-editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 34px;
    align-items: center;
    gap: 3px;
}

.receiving-barcode-camera {
    width: 34px;
    height: 32px;
    border: 0;
    border-radius: 7px;
    background: #e3f5f2;
    color: var(--accent);
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
}

.receiving-barcode-camera:hover {
    background: #cdeee8;
}

.barcode-scanner-backdrop {
    position: fixed;
    inset: 0;
    z-index: 300;
    align-items: center;
    justify-content: center;
    padding: 14px;
    background: rgba(12, 27, 51, 0.72);
}

.barcode-scanner-modal {
    width: min(620px, 100%);
    max-height: calc(100vh - 28px);
    overflow: auto;
    border-radius: 8px;
    background: #fff;
    padding: 14px;
    box-shadow: 0 20px 55px rgba(0, 0, 0, 0.34);
}

.barcode-scanner-modal .panel-head > div {
    display: flex;
    align-items: center;
    gap: 10px;
}

.barcode-scanner-viewport {
    position: relative;
    width: 100%;
    min-height: 280px;
    margin-top: 12px;
    overflow: hidden;
    background: #0d1726;
}

#receivingBarcodeVideo,
#receivingBarcodeFallbackReader {
    width: 100%;
    min-height: 280px;
}

#receivingBarcodeVideo {
    display: block;
    max-height: 65vh;
    object-fit: cover;
}

#receivingBarcodeFallbackReader video {
    object-fit: cover;
}

.barcode-scan-guide {
    position: absolute;
    left: 12%;
    right: 12%;
    top: 50%;
    height: 120px;
    transform: translateY(-50%);
    border: 3px solid #a7f3d0;
    box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

body.scanner-open {
    overflow: hidden;
}

.receiving-product-results {
    position: fixed;
    z-index: 80;
    left: 0;
    top: 0;
    width: min(680px, calc(100vw - 28px));
    max-height: 260px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}

.receiving-product-option {
    display: grid;
    grid-template-columns: 150px minmax(320px, 1fr);
    gap: 8px;
    align-items: start;
    white-space: normal;
}

.receiving-row-tools {
    display: flex;
    gap: 6px;
    align-items: center;
}

.top-sales-table-wrap {
    max-height: 640px;
    overflow-y: auto;
}

.top-sales-table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.table-input {
    width: 100%;
    border: 0;
    background: transparent;
    font: inherit;
    padding: 4px 6px;
}

.table-input:focus {
    outline: 2px solid var(--accent);
    background: #fff;
}

.money-input {
    text-align: right;
    font-weight: 800;
}

.debt-panel {
    min-height: calc(100vh - 100px);
}

.debt-table {
    min-width: 1280px;
    table-layout: fixed;
}

.debt-table th {
    text-align: center;
}

.debt-table td,
.debt-table th {
    border-right: 1px solid #ccd4e0;
    padding: 7px 8px;
}

.debt-table tbody tr:nth-child(even) td {
    background: #dfeaf6;
}

.debt-table tbody tr:nth-child(odd) td {
    background: #ffffff;
}

.debt-table tfoot th {
    background: #8de6bd;
    text-align: right;
    font-size: 16px;
    font-weight: 800;
}

.debt-table th:first-child,
.debt-table td:first-child {
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    padding-left: 6px;
    padding-right: 6px;
    text-align: center;
}

.debt-table th:last-child,
.debt-table td:last-child {
    width: 64px;
    min-width: 64px;
    max-width: 64px;
    padding-left: 6px;
    padding-right: 6px;
    text-align: center;
}

.debt-supplier-cell {
    width: 250px;
    min-width: 250px;
    position: relative;
}

.debt-supplier-combo {
    margin-bottom: 0;
}

.debt-supplier-combo .combo-button {
    padding: 8px 10px;
    font-weight: 700;
}

.debt-supplier-combo .combo-menu {
    z-index: 80;
    min-width: 300px;
}

.debt-supplier-options {
    max-height: 320px;
}

.debt-bank-cell {
    min-width: 170px;
}

.debt-account-name-cell {
    width: 350px;
    min-width: 350px;
}

.debt-account-name {
    white-space: normal;
    overflow: visible;
    line-height: 1.35;
}

.debt-bank-combo {
    margin-bottom: 0;
}

.debt-bank-combo .combo-button {
    padding: 8px 10px;
    font-weight: 700;
}

.debt-bank-combo .combo-menu {
    z-index: 80;
    min-width: 320px;
}

.debt-bank-options {
    max-height: 300px;
}

.debt-info-input[readonly] {
    color: var(--ink);
    cursor: default;
}

.debt-create-supplier-btn {
    white-space: nowrap;
    padding-left: 8px;
    padding-right: 8px;
}

.debt-amount {
    cursor: pointer;
}

.debt-amount-inner {
    display: flex;
    align-items: center;
    gap: 6px;
}

.debt-amount-inner .money-input {
    flex: 1 1 auto;
    min-width: 94px;
}

.debt-qr-btn {
    flex: 0 0 auto;
    border: 0;
    border-radius: 6px;
    background: #e3f5f2;
    color: #007062;
    cursor: pointer;
    font-size: 11px;
    font-weight: 900;
    line-height: 1;
    padding: 7px 6px;
}

.debt-qr-btn:hover {
    background: #cdeee8;
}

.debt-total-value {
    flex: 1 1 auto;
    text-align: right;
}

.debt-total {
    background: #f5caca !important;
    font-weight: 800;
    font-size: 16px;
}

.debt-table-wrap {
    max-height: calc(100vh - 142px);
    padding-bottom: 260px;
}

.debt-trash-btn {
    width: 30px;
    height: 30px;
}

.debt-color-btn {
    width: 28px;
    height: 28px;
    border: 1px solid #aeb8c6;
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
    background: transparent;
}

.debt-color-palette {
    display: none;
    position: fixed;
    z-index: 120;
    width: 244px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}

.debt-color-palette.open {
    display: block;
}

.debt-palette-reset {
    border: 0;
    background: transparent;
    padding: 4px 2px 8px;
    font: inherit;
    cursor: pointer;
}

.debt-palette-grid {
    display: grid;
    grid-template-columns: repeat(8, 22px);
    gap: 5px;
}

.debt-palette-grid button {
    width: 22px;
    height: 22px;
    border: 1px solid #cbd5e1;
    border-radius: 50%;
    cursor: pointer;
}

.debt-title-tools {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.debt-title-tools h3 {
    margin-right: 4px;
}

.strike-btn {
    width: 32px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: line-through;
    font-weight: 900;
    line-height: 1;
}

.debt-strike {
    text-decoration: line-through;
}

.debt-color-orange,
.debt-highlight-orange {
    background: #ffd8a8 !important;
}

.debt-color-green,
.debt-highlight-green {
    background: #c8f7c5 !important;
}

.debt-color-yellow,
.debt-highlight-yellow {
    background: #fff200 !important;
}

.qr-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.42);
}

.qr-modal {
    width: min(420px, calc(100vw - 32px));
    border-radius: 8px;
    background: #fff;
    padding: 16px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.3);
}

.bank-modal {
    width: min(620px, calc(100vw - 32px));
    border-radius: 8px;
    background: #eaf4ff;
    padding: 18px;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.3);
}

.bank-modal label {
    display: grid;
    gap: 7px;
    margin-bottom: 12px;
    font-weight: 800;
}

.bank-modal input,
.bank-modal select {
    width: 100%;
    border: 1px solid #b9c7d8;
    border-radius: 6px;
    padding: 12px 14px;
    font: inherit;
    background: #fff;
}

.bank-modal label.toggle-line {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bank-modal label.toggle-line input {
    width: 18px;
    height: 18px;
    padding: 0;
    flex: 0 0 auto;
}

.full-btn {
    width: 100%;
}

.mini-btn {
    padding: 6px 9px;
    margin-bottom: 5px;
}

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

.qr-modal img {
    display: block;
    width: 280px;
    height: 280px;
    object-fit: contain;
    margin: 0 auto 12px;
}

.qr-detail {
    display: grid;
    gap: 5px;
    text-align: center;
}

.qr-detail strong {
    color: var(--accent);
    font-size: 22px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

th,
td {
    padding: 11px 12px;
    border-bottom: 1px solid #edf0f5;
    text-align: left;
    vertical-align: top;
}

th {
    background: var(--soft);
    color: #4c596d;
    font-size: 12px;
    text-transform: uppercase;
}

tr.low td {
    background: #fff8eb;
}

.form-panel {
    align-self: start;
}

form label,
.upload-panel label {
    display: grid;
    gap: 6px;
    margin-bottom: 12px;
    color: #344054;
    font-size: 13px;
    font-weight: 700;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.toggle-line {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
}

.toggle-line input {
    width: 18px;
    height: 18px;
}

.button-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.primary-btn,
.secondary-btn,
.small-btn {
    border: 0;
    border-radius: 8px;
    padding: 11px 14px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.primary-btn {
    color: #fff;
    background: var(--accent);
}

.primary-btn:hover {
    background: var(--accent-strong);
}

.secondary-btn,
.small-btn {
    color: var(--accent);
    background: #e6f4f1;
}

.small-btn {
    padding: 7px 10px;
}

.status-line {
    min-height: 20px;
    margin-top: 12px;
    color: var(--muted);
    font-size: 14px;
}

.status-line.error {
    color: var(--danger);
}

.danger-btn {
    background: #fee4e2;
    color: var(--danger);
}

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

.progress-shell {
    position: relative;
    height: 22px;
    margin-top: 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #eef6f3;
    overflow: hidden;
}

.progress-bar {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #0f766e, #2dd4bf);
    transition: width 0.25s ease;
}

.progress-shell.error .progress-bar {
    background: linear-gradient(90deg, #b91c1c, #f87171);
}

.progress-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #073b36;
    font-size: 12px;
    font-weight: 900;
}

.muted {
    color: var(--muted);
    margin: 0 0 14px;
    line-height: 1.45;
}

.muted.compact {
    margin: 5px 0 0;
}

.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.health-grid > div {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fbfc;
    padding: 10px;
}

.health-grid strong,
.health-grid span {
    display: block;
}

.health-grid strong {
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 4px;
}

.health-grid span {
    font-weight: 900;
}

.audit-log-wrap {
    max-height: 340px;
    overflow: auto;
}

.audit-log-wrap th,
.audit-log-wrap td {
    white-space: nowrap;
}

.audit-log-wrap td:last-child {
    min-width: 220px;
    white-space: normal;
}

.history-actions,
.button-row.tight {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.history-actions {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
}

.history-actions .primary-btn {
    order: -1;
    white-space: nowrap;
}

.history-actions .inline-search {
    width: 320px;
}

#purchaseHistoryPanel .table-wrap {
    max-height: 482px;
    overflow-y: auto;
}

#purchaseHistoryPanel thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.button-row.tight {
    margin-top: 0;
}

.editor-action-bar {
    display: flex;
    align-items: end;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.invoice-supplier-field {
    position: relative;
    display: grid;
    gap: 5px;
    min-width: 320px;
}

.invoice-supplier-field label {
    font-size: 12px;
    font-weight: 800;
    color: #344054;
}

.invoice-supplier-field input {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
    background: #fff;
}

.icon-btn,
.branch-toggle-btn {
    border: 0;
    border-radius: 8px;
    color: var(--accent);
    background: #e6f4f1;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.icon-btn {
    width: 34px;
    height: 30px;
    font-size: 18px;
}

.header-icon-btn {
    width: 34px;
    height: 30px;
}

.excel-export-btn {
    background: #0b7a4b;
    color: #fff;
}

.excel-export-btn:hover {
    background: #075e3a;
}

.excel-export-btn svg {
    width: 19px;
    height: 19px;
    display: block;
    margin: 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.branch-toggle-btn {
    min-width: 56px;
    height: 30px;
    padding: 4px 9px;
    font-size: 17px;
    line-height: 1;
}

.branch-toggle-btn.muted-toggle {
    color: #667085;
    background: #eef2f7;
}

.invoice-supplier-options {
    display: none;
    position: absolute;
    z-index: 40;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}

.activity-list {
    display: grid;
    gap: 10px;
}

.activity-item {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--soft);
}

.activity-item strong {
    display: block;
}

.activity-item span {
    color: var(--muted);
    font-size: 13px;
}

.purchase-search-panel {
    overflow: visible;
}

.purchase-search {
    position: relative;
}

.purchase-search-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
}

.purchase-search input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    font: inherit;
}

.purchase-results {
    display: none;
    position: absolute;
    z-index: 30;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 360px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}

.manual-product-panel {
    grid-template-columns: minmax(120px, 0.7fr) minmax(260px, 2fr) repeat(4, minmax(96px, 0.55fr)) auto;
    gap: 8px;
    margin-top: 10px;
    padding: 10px;
    border: 1px solid #c6d7ef;
    border-radius: 8px;
    background: #f7fbff;
}

.manual-product-panel input {
    min-width: 0;
}

.purchase-result {
    display: grid;
    grid-template-columns: 150px minmax(240px, 1fr) 220px;
    gap: 12px;
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #edf0f5;
}

.purchase-result:hover {
    background: #f1f7f6;
}

.purchase-result strong {
    display: block;
}

.purchase-result span {
    color: var(--muted);
    font-size: 13px;
}

.purchase-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    color: var(--accent);
    font-weight: 800;
    font-size: 13px;
}

.purchase-table-toolbar {
    position: relative;
    display: flex;
    align-items: center;
    min-width: 1320px;
    min-height: 34px;
    margin-bottom: 6px;
}

.purchase-line-count {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.purchase-table-toolbar .purchase-summary {
    margin-left: auto;
    justify-content: flex-end;
}

.order-column-tools {
    position: absolute;
    left: calc(68px + 58px + 150px + ((100% - 1320px) + 220px) + 177px);
    transform: translateX(-50%);
    top: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.purchase-meta {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr) minmax(220px, 0.8fr);
    gap: 12px;
    align-items: end;
}

#purchaseHistoryWorkspace {
    display: grid;
    gap: 18px;
}

.purchase-editor {
    min-height: calc(100vh - 118px);
    display: flex;
    flex-direction: column;
}

.purchase-editor-layout {
    display: block;
    flex: 1;
    min-height: 0;
}

.purchase-filter-panel {
    border: 1px solid #bdd7ff;
    border-left: 5px solid #1f6feb;
    border-radius: 8px;
    background: #fff;
    padding: 14px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.filter-popup-backdrop {
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(15, 23, 42, 0.28);
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 36px 28px 28px;
}

.filter-popup {
    width: min(430px, calc(100vw - 56px));
    min-height: calc(100vh - 72px);
    max-height: calc(100vh - 72px);
    overflow: visible;
}

.purchase-filter-panel h3 {
    margin: 0 0 14px;
    color: #164f9c;
}

.purchase-filter-panel label {
    display: grid;
    gap: 6px;
    margin-bottom: 12px;
    color: #344054;
    font-size: 13px;
    font-weight: 700;
}

.purchase-filter-panel input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
}

.purchase-work-panel {
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.category-checks {
    min-height: 360px;
    max-height: calc(100vh - 340px);
    overflow-y: auto;
    border: 0;
    border-radius: 0;
    background: #fff;
}

.category-picker {
    position: relative;
    margin-bottom: 12px;
}

.category-picker > input {
    cursor: pointer;
    background: #fff;
}

.category-picker-menu {
    display: none;
    position: absolute;
    z-index: 35;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
    overflow: hidden;
    max-height: calc(100vh - 260px);
}

.category-picker.open .category-picker-menu {
    display: block;
}

.category-picker-menu > input {
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
}

.category-checks label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0;
    padding: 9px 10px;
    border-bottom: 1px solid #edf0f5;
    font-weight: 600;
    line-height: 1.3;
}

.category-checks label:hover {
    background: #f4f8ff;
}

.category-checks input {
    width: auto;
    margin-top: 2px;
}

.purchase-meta label {
    display: grid;
    gap: 6px;
    color: #344054;
    font-size: 13px;
    font-weight: 700;
}

.purchase-meta select,
.purchase-meta input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 11px 12px;
    font: inherit;
    background: #fff;
}

.purchase-table {
    min-width: 1320px;
}

.purchase-table-wrap {
    height: calc(100vh - 286px);
    max-height: none;
}

.purchase-table {
    margin-bottom: 150px;
}

.purchase-table thead th {
    position: sticky;
    top: 0;
    z-index: 4;
}

.purchase-table thead tr:nth-child(2) th {
    top: 39px;
    z-index: 5;
}

.purchase-table tbody tr:nth-child(even) > td {
    background-color: #dfeaf6 !important;
}

.purchase-table tbody tr:nth-child(odd) > td {
    background-color: #ffffff !important;
}

.purchase-table tbody tr:nth-child(odd) > td.order-bl {
    background-color: #fff4f4 !important;
}

.purchase-table tbody tr:nth-child(odd) > td.order-dl {
    background-color: #f4f8ff !important;
}

.purchase-table tbody tr:nth-child(odd) > td.order-dtr {
    background-color: #fff1df !important;
}

.purchase-table tbody tr:nth-child(even) > td.order-bl {
    background-color: #f2cdcd !important;
}

.purchase-table tbody tr:nth-child(even) > td.order-dl {
    background-color: #d5e6fb !important;
}

.purchase-table tbody tr:nth-child(even) > td.order-dtr {
    background-color: #ffd79e !important;
}

.trash-btn {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: #e6f4f1;
    color: var(--accent);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}

.trash-btn:hover {
    background: #d5eee9;
}

.row-action-cell {
    vertical-align: middle;
    white-space: nowrap;
}

.row-action-cell > button + button {
    margin-left: 6px;
}

.capture-eye-btn {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: #ffe4ec;
    color: #be185d;
    font-size: 16px;
    font-weight: 900;
    line-height: 1;
    cursor: pointer;
}

.capture-eye-btn:hover {
    background: #ffd1df;
}

.capture-eye-btn.muted-eye {
    color: #9f1239;
    background: #fecdd3;
    opacity: 0.58;
}

.purchase-name-color-btn {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: #e3f5f2;
    cursor: pointer;
    font-weight: 900;
    font-size: 16px;
    line-height: 1;
}

.purchase-name-color-btn:hover {
    background: #cdeee8;
}

.purchase-row-add-btn {
    width: 38px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: #e3f5f2;
    color: #007062;
    cursor: pointer;
    font-size: 13px;
    font-weight: 900;
    line-height: 1;
}

.purchase-row-add-btn:hover {
    background: #cdeee8;
}

.global-eye-btn {
    width: 38px;
    height: 32px;
}

.positive-capture-btn {
    width: 42px;
    height: 32px;
    font-size: 14px;
    font-weight: 900;
}

.purchase-table tbody tr.capture-row-hidden > td {
    opacity: 0.5;
}

.purchase-table th {
    text-align: center;
    border-right: 1px solid #ccd4e0;
}

.purchase-table td {
    padding: 7px 8px;
    border-right: 1px solid #e2e7ef;
}

.purchase-table .num {
    text-align: right;
}

.purchase-table .order-bl {
    background: #fff4f4;
}

.purchase-table .order-dl {
    background: #f4f8ff;
}

.purchase-table .order-dtr {
    background: #fff1df;
}

.purchase-table .hidden-order-branch {
    display: none;
}

.purchase-table .stock {
    color: #c1121f;
    font-weight: 700;
    text-align: right;
}

.purchase-table .sales-average {
    color: #075e54;
    font-weight: 800;
    position: relative;
    text-align: right;
}

.sales-value {
    display: inline-flex;
    min-width: 44px;
    justify-content: flex-end;
    border-bottom: 1px dotted #075e54;
    cursor: help;
}

.sales-tooltip {
    display: none;
    position: absolute;
    z-index: 30;
    left: 50%;
    top: calc(100% + 8px);
    min-width: 190px;
    transform: translateX(-50%);
    border: 1px solid #bfd5df;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.18);
    color: #102033;
    padding: 10px 12px;
    text-align: left;
}

.sales-tooltip strong {
    display: block;
    margin-bottom: 7px;
    color: #075e54;
    font-size: 12px;
}

.sales-tooltip div {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 3px 0;
    font-size: 12px;
}

.sales-tooltip span {
    color: var(--muted);
}

.sales-average:hover .sales-tooltip {
    display: block;
}

.sales-product-matches {
    display: none;
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    margin: -8px 0 12px;
}

.sales-product-matches button {
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    padding: 10px 12px;
    display: grid;
    grid-template-columns: auto minmax(160px, 1fr) auto;
    gap: 8px;
    align-items: center;
    max-width: 100%;
    cursor: pointer;
    font: inherit;
}

.sales-product-matches button:hover {
    background: #e6f4f1;
}

.sales-product-matches span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sales-product-matches em {
    color: var(--accent);
    font-style: normal;
    font-weight: 800;
}

.sales-chart {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    min-height: 360px;
    padding: 12px;
    position: relative;
}

.sales-dot {
    cursor: pointer;
}

.sales-chart-tooltip {
    position: fixed;
    z-index: 140;
    display: none;
    border-radius: 6px;
    background: #102033;
    color: #fff;
    padding: 7px 9px;
    font-weight: 800;
    pointer-events: none;
    box-shadow: var(--shadow);
}

.compact-select {
    width: 150px;
}

.sales-chart-scroll {
    overflow-x: auto;
}

.sales-chart svg {
    display: block;
    font: 12px system-ui, sans-serif;
    color: #334155;
}

.sales-grid {
    stroke: #d9e2ef;
    stroke-width: 1;
}

.sales-chart-title {
    font-weight: 800;
    color: var(--accent);
    margin: 2px 0 10px;
}

.sales-chart-legend {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    margin-top: 10px;
    font-weight: 700;
}

.sales-chart-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.sales-chart-legend i {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.empty-state {
    min-height: 320px;
    display: grid;
    place-items: center;
    color: var(--muted);
    text-align: center;
}

.purchase-qty {
    width: 82px;
    border: 0;
    background: transparent;
    text-align: right;
    font: inherit;
    font-weight: 900;
    outline: none;
}

.purchase-qty:focus {
    background: #fff;
    box-shadow: inset 0 0 0 2px var(--accent);
}

.purchase-name-input {
    width: 100%;
    min-width: 320px;
    min-height: 32px;
    height: auto;
    border: 0;
    background: transparent;
    font: inherit;
    line-height: 1.35;
    outline: none;
    padding: 6px 8px;
    resize: none;
    overflow: hidden;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    display: block;
    box-sizing: border-box;
}

.purchase-name-cell {
    min-width: 336px;
    white-space: normal;
    overflow-wrap: anywhere;
}

.purchase-name-input:focus {
    background: #fff;
    box-shadow: inset 0 0 0 2px var(--accent);
}

.purchase-table td.remote-editing {
    outline: 3px solid #1f6feb;
    outline-offset: -3px;
    position: relative;
}

.purchase-table td.remote-editing::after {
    content: attr(data-editor);
    position: absolute;
    top: 2px;
    right: 3px;
    border-radius: 999px;
    padding: 2px 6px;
    background: #1f6feb;
    color: #fff;
    font-size: 10px;
    font-weight: 800;
}

@media (max-width: 980px) {
    .sidebar {
        align-items: flex-start;
        flex-direction: column;
    }

    nav {
        margin-left: 0;
    }

    .metric-grid,
    .split,
    .grid-layout,
    .upload-layout,
    .purchase-editor-layout {
        grid-template-columns: 1fr;
    }

    .purchase-filter-panel {
        margin-top: 0;
        width: auto;
        max-height: none;
    }
}

@media (max-width: 640px) {
    .main {
        padding: 14px;
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    nav {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
    }

    .metric-grid,
    .form-row {
        grid-template-columns: 1fr;
    }

    .receiving-barcode-camera {
        width: 40px;
        height: 38px;
        font-size: 20px;
    }

    .receiving-sku-editor {
        grid-template-columns: minmax(120px, 1fr) 40px;
    }

    .barcode-scanner-backdrop {
        padding: 0;
    }

    .barcode-scanner-modal {
        width: 100%;
        max-height: 100vh;
        min-height: 100vh;
        border-radius: 0;
    }
}
