:root {
    --erp-ink: #141c26;
    --erp-ink-soft: #1c2734;
    --erp-ink-mid: #243447;
    --erp-gold: #c6a048;
    --erp-gold-soft: #e8d5a3;
    --erp-gold-deep: #9a7a2f;
    --erp-teal: #0f6b5c;
    --erp-teal-hover: #0c574b;
    --erp-surface: #e9eef3;
    --erp-surface-soft: #f5f7fa;
    --erp-panel: #ffffff;
    --erp-text: #1a2330;
    --erp-muted: #5a6a7a;
    --erp-border: #cfd8e3;
    --erp-border-light: #e2e8ef;
    --erp-row-alt: #f7f9fb;
    --erp-total-bg: #f3efe3;
    --erp-sidebar-bg: var(--erp-ink);
    --erp-sidebar-active: var(--erp-ink-soft);
    --erp-header-blue: var(--erp-ink);
    --erp-grid-header: var(--erp-ink-soft);
    --erp-danger: #b42318;
    --erp-success: #067647;
    --erp-warning: #b54708;
    --erp-input-h: 28px;
    --erp-radius: 6px;
    --erp-radius-sm: 4px;
    --erp-shadow: 0 1px 2px rgba(20, 28, 38, 0.04), 0 4px 12px rgba(20, 28, 38, 0.05);
    --erp-shadow-sm: 0 1px 1px rgba(20, 28, 38, 0.04);
    --erp-font: "Outfit", "Segoe UI", sans-serif;
    --erp-display: "Cormorant Garamond", Georgia, serif;
    --erp-topbar-h: 40px;
    --erp-sidebar-w: 188px;
}

body.app-erp {
    font-family: var(--erp-font);
    font-size: 13px;
    color: var(--erp-text);
    background:
        radial-gradient(900px 320px at 8% -8%, rgba(198, 160, 72, 0.08), transparent 55%),
        var(--erp-surface);
    letter-spacing: 0;
    line-height: 1.35;
}

a {
    color: var(--erp-teal);
}

a:hover {
    color: var(--erp-teal-hover);
}

/* ----- Top bar ----- */
.erp-topbar {
    background: linear-gradient(90deg, #142b3a 0%, #1a3d52 55%, #142b3a 100%);
    min-height: var(--erp-topbar-h);
    border-bottom: 1px solid rgba(198, 160, 72, 0.35);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.14);
}

.erp-topbar .navbar-brand {
    font-family: var(--erp-display);
    font-size: 1.15rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: #fff !important;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.erp-brand-mark {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #f0e2b8, #c6a048 55%, #8d6b24);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
    flex: 0 0 auto;
}

.erp-topbar .btn-link,
.erp-topbar .text-white-50 {
    font-size: 12px;
}

.erp-user-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.12rem 0.5rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.82);
    font-size: 11px;
}

.erp-topbar .btn-outline-light {
    border-color: rgba(255, 255, 255, 0.35);
    color: #fff;
    border-radius: 999px;
    padding: 0.15rem 0.65rem;
}

.erp-topbar .btn-outline-light:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--erp-gold);
    color: #fff;
}

.content-wrap {
    min-height: calc(100vh - var(--erp-topbar-h));
}

main.erp-main {
    background: transparent;
    padding: 0.55rem 0.7rem 0.85rem !important;
}

/* Narrow sidebar — more room for grids */
@media (min-width: 768px) {
    .erp-sidebar.col-md-3,
    .erp-sidebar.col-lg-2 {
        flex: 0 0 var(--erp-sidebar-w);
        max-width: var(--erp-sidebar-w);
        width: var(--erp-sidebar-w);
    }
    main.erp-main.col-md-9,
    main.erp-main.col-lg-10 {
        flex: 1 1 auto;
        max-width: calc(100% - var(--erp-sidebar-w));
        width: auto;
    }
}

/* ----- Sidebar ----- */
.erp-sidebar {
    background: linear-gradient(180deg, #142b3a 0%, #0f2330 100%);
    min-height: calc(100vh - var(--erp-topbar-h));
    padding: 0.35rem 0.3rem 0.75rem;
    border-right: 1px solid rgba(255, 255, 255, 0.04);
}

.erp-sidebar .nav-link {
    color: rgba(240, 244, 248, 0.82);
    font-size: 12.5px;
    padding: 0.32rem 0.55rem;
    border-radius: 5px;
    border-left: 0;
    margin: 0.04rem 0.1rem;
    transition: background 0.12s ease, color 0.12s ease;
}

.erp-sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
}

.erp-sidebar .nav-link.active {
    background: linear-gradient(90deg, rgba(198, 160, 72, 0.22), rgba(255, 255, 255, 0.04));
    color: #fff;
    box-shadow: inset 2px 0 0 var(--erp-gold);
    font-weight: 600;
}

.erp-sidebar .nav-section-label {
    color: rgba(198, 160, 72, 0.78);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.45rem 0.55rem 0.1rem;
}

.erp-sidebar .nav-link-primary {
    font-weight: 600;
    background: rgba(8, 127, 112, 0.4);
    color: #fff;
}

.erp-sidebar .nav-link-primary:hover {
    background: rgba(8, 127, 112, 0.55);
}

.erp-sidebar .nav-link-with-icon {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.erp-sidebar .nav-ico {
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    opacity: 0.88;
}

.erp-sidebar .nav-link.active .nav-ico {
    opacity: 1;
}

.erp-sidebar details.nav-advanced {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: 0.5rem;
    padding-top: 0.35rem;
}

.erp-sidebar .nav-advanced-summary {
    cursor: pointer;
    list-style: none;
}

.erp-sidebar .nav-advanced-summary::-webkit-details-marker {
    display: none;
}

.erp-sidebar #sidebarToggle {
    border-radius: 8px;
    border-color: rgba(255, 255, 255, 0.25);
}

/* ----- Forms ----- */
body.app-erp .form-control,
body.app-erp .form-select,
body.app-erp textarea.form-control {
    border: 1px solid var(--erp-border);
    border-radius: var(--erp-radius-sm);
    box-shadow: none;
    font-size: 12.5px;
    padding: 0.2rem 0.45rem;
    min-height: var(--erp-input-h);
    line-height: 1.25;
    background: #fff;
    color: var(--erp-text);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

body.app-erp .form-control:focus,
body.app-erp .form-select:focus,
body.app-erp textarea.form-control:focus,
body.app-erp .erp-cell-input:focus {
    border-color: var(--erp-teal);
    box-shadow: 0 0 0 2px rgba(15, 107, 92, 0.14);
    outline: none;
}

body.app-erp .form-control:read-only,
body.app-erp .form-control[readonly] {
    background: var(--erp-surface-soft);
}

body.app-erp .form-label,
.erp-field > label {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 0.1rem;
    color: var(--erp-muted);
    letter-spacing: 0.01em;
}

.erp-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem 0.65rem;
    align-items: flex-end;
    background: var(--erp-panel);
    border: 1px solid var(--erp-border-light);
    border-radius: var(--erp-radius);
    padding: 0.45rem 0.55rem;
    margin-bottom: 0.45rem;
    box-shadow: var(--erp-shadow-sm);
}

.erp-field {
    display: flex;
    flex-direction: column;
    min-width: 100px;
}

.erp-field-sm { max-width: 88px; }
.erp-field-md { min-width: 132px; }
.erp-field-lg { min-width: 180px; flex: 1; }

.erp-radio-group {
    display: flex;
    gap: 0.55rem;
    align-items: center;
    min-height: var(--erp-input-h);
    padding-top: 0.85rem;
}

.erp-radio-group label {
    font-size: 13px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* ----- Suggest / loader ----- */
.item-suggest-box {
    position: fixed;
    z-index: 80;
    background: #fff;
    border: 1px solid var(--erp-border);
    border-radius: var(--erp-radius-sm);
    box-shadow: var(--erp-shadow);
    max-height: 240px;
    overflow: auto;
}

.item-suggest-option {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    background: #fff;
    padding: 0.5rem 0.75rem;
    font-size: 13px;
}

.item-suggest-option:hover,
.item-suggest-option:focus {
    background: #eef7f5;
}

#saveLoader {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(20, 28, 38, 0.35);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
}

#saveLoader[hidden] { display: none; }

.save-loader-card {
    background: #fff;
    border: 1px solid var(--erp-border-light);
    border-radius: 14px;
    padding: 1.4rem 1.9rem;
    text-align: center;
    font-weight: 600;
    color: var(--erp-ink);
    box-shadow: var(--erp-shadow);
}

.save-loader-spin {
    width: 36px;
    height: 36px;
    margin: 0 auto 0.65rem;
    border: 3px solid #d9e8e4;
    border-top-color: var(--erp-teal);
    border-radius: 50%;
    animation: save-spin 0.7s linear infinite;
}

@keyframes save-spin {
    to { transform: rotate(360deg); }
}

/* ----- Spreadsheet grid ----- */
.erp-grid-wrap {
    background: var(--erp-panel);
    border: 1px solid var(--erp-border-light);
    border-radius: var(--erp-radius);
    overflow-x: auto;
    box-shadow: var(--erp-shadow-sm);
}

table.erp-grid {
    width: 100%;
    margin: 0;
    border-collapse: collapse;
    font-size: 12px;
}

table.erp-grid thead th {
    background: var(--erp-grid-header);
    color: #f8fafc;
    font-weight: 600;
    text-align: center;
    padding: 0.28rem 0.25rem;
    border: 1px solid #2a394c;
    white-space: nowrap;
    vertical-align: middle;
    letter-spacing: 0.01em;
}

table.erp-grid tbody td {
    border: 1px solid var(--erp-border-light);
    padding: 0;
    vertical-align: middle;
    text-align: center;
    background: #fff;
}

table.erp-grid tbody tr:nth-child(even) td,
table.erp-grid tbody tr:nth-child(even) td .erp-cell-input {
    background: var(--erp-row-alt);
}

table.erp-grid tbody tr:hover td,
table.erp-grid tbody tr:hover td .erp-cell-input {
    background: #f3faf8;
}

table.erp-grid tfoot td {
    border: 1px solid var(--erp-border-light);
    padding: 0.2rem;
    font-weight: 700;
    background: var(--erp-surface-soft);
    text-align: center;
}

table.erp-grid td.col-total,
table.erp-grid th.col-total {
    background: var(--erp-total-bg) !important;
    color: var(--erp-gold-deep);
    font-weight: 600;
}

table.erp-grid .erp-cell-input {
    width: 100%;
    border: none;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    min-height: 24px;
    padding: 0.15rem 0.25rem;
    font-size: 12px;
    text-align: center;
}

table.erp-grid select.erp-cell-input {
    padding: 0.08rem 0.15rem;
    font-size: 11.5px;
    min-height: 24px;
}

table.erp-grid .erp-cell-input:focus {
    border: 1px solid var(--erp-teal);
    background: #fff !important;
    outline: none;
}

table.erp-grid .erp-cell-text {
    display: block;
    padding: 0.18rem 0.25rem;
    min-height: 24px;
    line-height: 1.3;
}

table.erp-grid .erp-cell-text.text-start { text-align: left; }

table.erp-grid .erp-link {
    color: var(--erp-teal);
    text-decoration: none;
    font-weight: 600;
    font-size: 12.5px;
    padding: 0.25rem;
}

table.erp-grid .erp-link:hover { text-decoration: underline; }

/* List tables */
.erp-main .table-responsive .table.erp-list,
.erp-main .table {
    font-size: 12px;
    margin: 0;
    border-collapse: collapse;
}

.erp-main .table.erp-list thead th,
.erp-main .table thead th {
    background: var(--erp-grid-header);
    color: #f8fafc;
    font-weight: 600;
    text-align: center;
    padding: 0.28rem 0.4rem;
    border: 1px solid #2a394c;
    white-space: nowrap;
    font-size: 11.5px;
    vertical-align: middle;
}

.erp-main .table.erp-list tbody td,
.erp-main .table tbody td {
    border: 1px solid var(--erp-border-light);
    padding: 0.25rem 0.4rem;
    vertical-align: middle;
    text-align: center;
    font-size: 12px;
}

.erp-main .table.erp-list tbody tr:nth-child(even),
.erp-main .table.table-striped > tbody > tr:nth-of-type(odd) > * {
    --bs-table-bg-type: var(--erp-row-alt);
    background-color: var(--erp-row-alt);
}

.erp-main .table.table-striped > tbody > tr:nth-of-type(even) > * {
    --bs-table-bg-type: #fff;
    background-color: #fff;
}

.erp-main .table-responsive {
    border-radius: var(--erp-radius);
    overflow: hidden;
    border: 1px solid var(--erp-border-light);
    background: #fff;
    box-shadow: var(--erp-shadow-sm);
}

/* ----- Panels / titles / buttons ----- */
.erp-panel {
    background: var(--erp-panel);
    border: 1px solid var(--erp-border-light);
    border-radius: var(--erp-radius);
    padding: 0.5rem 0.65rem;
    margin-bottom: 0.45rem;
    box-shadow: var(--erp-shadow-sm);
}

.erp-panel.h-100 { height: 100%; }

a.erp-panel {
    color: inherit;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

a.erp-panel:hover {
    border-color: rgba(198, 160, 72, 0.55);
    box-shadow: var(--erp-shadow);
    color: inherit;
}

a.erp-panel.border.border-primary,
a.erp-panel.border-primary {
    border: 1px solid rgba(198, 160, 72, 0.65) !important;
    background: linear-gradient(180deg, #fffdf8 0%, #fff 100%);
}

.erp-page-title {
    font-family: var(--erp-display);
    font-size: 1.35rem;
    font-weight: 600;
    margin-bottom: 0.15rem;
    color: var(--erp-ink);
    letter-spacing: 0.01em;
    line-height: 1.15;
}

.erp-page-lead {
    color: var(--erp-muted);
    margin-bottom: 0.5rem;
    max-width: 70ch;
    font-size: 12.5px;
}

body.app-erp .btn {
    font-size: 12.5px;
    font-weight: 600;
    border-radius: 5px;
    padding: 0.2rem 0.65rem;
    min-height: var(--erp-input-h);
    letter-spacing: 0;
}

body.app-erp .btn-primary {
    background: var(--erp-teal);
    border-color: var(--erp-teal);
}

body.app-erp .btn-primary:hover,
body.app-erp .btn-primary:focus {
    background: var(--erp-teal-hover);
    border-color: var(--erp-teal-hover);
}

body.app-erp .btn-success {
    background: #0f7a4c;
    border-color: #0f7a4c;
}

body.app-erp .btn-success:hover {
    background: #0b643e;
    border-color: #0b643e;
}

body.app-erp .btn-outline-primary {
    color: var(--erp-teal);
    border-color: rgba(15, 107, 92, 0.45);
    background: #fff;
}

body.app-erp .btn-outline-primary:hover {
    background: #eef7f5;
    border-color: var(--erp-teal);
    color: var(--erp-teal-hover);
}

body.app-erp .btn-outline-secondary {
    border-color: var(--erp-border);
    color: var(--erp-muted);
    background: #fff;
}

body.app-erp .btn-outline-secondary:hover {
    background: var(--erp-surface-soft);
    border-color: #b7c2cf;
    color: var(--erp-text);
}

.erp-home-hero .btn-outline-light {
    border-color: rgba(255, 255, 255, 0.45);
    color: #fff;
}

.erp-home-hero .btn-outline-light:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--erp-gold);
    color: #fff;
}

body.app-erp .btn-lg {
    font-size: 0.95rem;
    min-height: 34px;
    padding: 0.35rem 0.95rem;
    border-radius: 6px;
}

body.app-erp .input-group .form-control {
    border-radius: var(--erp-radius-sm) 0 0 var(--erp-radius-sm);
}

body.app-erp .badge {
    font-weight: 600;
    letter-spacing: 0.02em;
    border-radius: 999px;
    padding: 0.35em 0.7em;
}

.bell-badge {
    font-size: 0.65rem;
    top: 8px;
    right: 2px;
}

/* Sticky save bar */
.erp-sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 20;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(6px);
    border-top: 2px solid var(--erp-gold);
    border-radius: var(--erp-radius) var(--erp-radius) 0 0;
    padding: 0.4rem 0.55rem;
    margin: 0.45rem -0.15rem 0;
    box-shadow: 0 -3px 12px rgba(20, 28, 38, 0.08);
}

.erp-sticky-actions .btn-lg {
    font-size: 0.95rem;
    min-height: 34px;
    padding: 0.3rem 0.95rem;
}

/* Steps */
.erp-steps {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.erp-step {
    background: #e8eef4;
    color: var(--erp-muted);
    border-radius: 999px;
    padding: 0.3rem 0.8rem;
    font-size: 12px;
    font-weight: 600;
}

.erp-step.active {
    background: var(--erp-teal);
    color: #fff;
}

.erp-panel.border-success {
    border: 1px solid rgba(6, 118, 71, 0.35) !important;
    box-shadow: inset 0 0 0 1px rgba(6, 118, 71, 0.08);
}

.erp-panel.border-warning {
    border: 1px solid rgba(181, 71, 8, 0.35) !important;
    box-shadow: inset 0 0 0 1px rgba(181, 71, 8, 0.08);
}

/* Alerts */
body.app-erp .alert {
    border-radius: var(--erp-radius);
    border: 1px solid transparent;
    box-shadow: var(--erp-shadow-sm);
}

body.app-erp .alert-success {
    background: #ecfdf3;
    border-color: #abefc6;
    color: #067647;
}

body.app-erp .alert-danger {
    background: #fef3f2;
    border-color: #fecdca;
    color: #b42318;
}

/* Dashboard / home */
.erp-home-hero {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.55rem;
    align-items: center;
    margin-bottom: 0.5rem;
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    background:
        linear-gradient(135deg, rgba(20, 28, 38, 0.96), rgba(28, 39, 52, 0.92)),
        radial-gradient(420px 140px at 90% 10%, rgba(198, 160, 72, 0.22), transparent 60%);
    color: #fff;
    box-shadow: var(--erp-shadow-sm);
    border: 1px solid rgba(198, 160, 72, 0.28);
}

.erp-home-hero .erp-page-title {
    color: #fff;
    margin-bottom: 0.05rem;
    font-size: 1.25rem;
}

.erp-home-hero .erp-page-lead {
    color: rgba(255, 255, 255, 0.72);
    margin-bottom: 0;
    font-size: 12px;
}

.erp-setup-card .erp-setup-kicker {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--erp-gold-deep);
    font-weight: 700;
    margin-bottom: 0.1rem;
}

.erp-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.erp-metric-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.4rem;
}

.erp-metric {
    background: var(--erp-panel);
    border: 1px solid var(--erp-border-light);
    border-radius: var(--erp-radius);
    padding: 0.4rem 0.55rem;
    box-shadow: var(--erp-shadow-sm);
}

.erp-metric .label {
    font-size: 11px;
    color: var(--erp-muted);
    font-weight: 600;
}

.erp-metric .value {
    font-family: var(--erp-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--erp-ink);
    line-height: 1.15;
}

/* Report hub cards */
.erp-report-grid .erp-panel {
    padding: 0.45rem 0.55rem;
}

.erp-report-grid .erp-panel .fw-semibold {
    font-size: 0.92rem;
    color: var(--erp-ink);
}

.erp-report-grid .erp-panel .text-muted {
    line-height: 1.3;
    font-size: 11.5px;
}

/* Login */
body.app-login {
    min-height: 100vh;
    margin: 0;
    display: grid;
    place-items: center;
    font-family: var(--erp-font);
    background:
        radial-gradient(900px 420px at 15% 10%, rgba(198, 160, 72, 0.22), transparent 55%),
        radial-gradient(700px 380px at 90% 90%, rgba(15, 107, 92, 0.18), transparent 50%),
        linear-gradient(160deg, #101820, #1a2736 45%, #142029);
    color: var(--erp-text);
}

.login-shell {
    width: min(420px, calc(100vw - 2rem));
}

.login-card {
    background: rgba(255, 255, 255, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 12px;
    padding: 1.1rem 1.15rem 1rem;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin-bottom: 0.75rem;
}

.login-brand h1 {
    font-family: var(--erp-display);
    font-size: 1.45rem;
    margin: 0;
    line-height: 1.1;
    color: var(--erp-ink);
}

.login-brand p {
    margin: 0.15rem 0 0;
    color: var(--erp-muted);
    font-size: 13px;
}

.login-card .btn-primary {
    background: var(--erp-teal);
    border-color: var(--erp-teal);
    font-weight: 600;
    border-radius: 10px;
    min-height: 42px;
}

.login-card .btn-outline-secondary {
    border-radius: 10px;
    min-height: 42px;
}

/* Hide advanced sale / purchase columns until "More details" */
.erp-grid.simple-mode .col-adv,
body.sale-simple .sale-extra.d-none {
    display: none !important;
}

.erp-grid.simple-mode th.col-adv,
.erp-grid.simple-mode td.col-adv {
    display: none !important;
}

@media (max-width: 767px) {
    .erp-sidebar { min-height: auto; }
    main.erp-main { padding: 0.45rem 0.5rem 0.7rem !important; }
    .erp-page-title { font-size: 1.2rem; }
    .erp-home-hero { padding: 0.5rem 0.6rem; }
}

/* Compact Bootstrap spacing inside app pages */
.erp-main .mb-3 { margin-bottom: 0.45rem !important; }
.erp-main .mb-2 { margin-bottom: 0.3rem !important; }
.erp-main .mt-3 { margin-top: 0.45rem !important; }
.erp-main .mt-2 { margin-top: 0.3rem !important; }
.erp-main .my-3 { margin-top: 0.45rem !important; margin-bottom: 0.45rem !important; }
.erp-main .py-3 { padding-top: 0.4rem !important; padding-bottom: 0.4rem !important; }
.erp-main .py-2 { padding-top: 0.3rem !important; padding-bottom: 0.3rem !important; }
.erp-main .p-4 { padding: 0.7rem !important; }
.erp-main .p-3 { padding: 0.5rem !important; }
.erp-main .g-3,
.erp-main .row.g-3 {
    --bs-gutter-x: 0.45rem;
    --bs-gutter-y: 0.45rem;
}
.erp-main .g-2,
.erp-main .row.g-2 {
    --bs-gutter-x: 0.35rem;
    --bs-gutter-y: 0.35rem;
}
.erp-main .alert {
    padding: 0.35rem 0.55rem;
    margin-bottom: 0.45rem;
    font-size: 12.5px;
}
.erp-main h2.h6,
.erp-main .h6 {
    font-size: 0.85rem;
    margin-bottom: 0.25rem;
}
.erp-main .small,
.erp-main small {
    font-size: 11.5px;
}
.erp-main ol.ps-3,
.erp-main ul.ps-3 {
    padding-left: 1rem !important;
    margin-bottom: 0.45rem;
}
.erp-main ol li,
.erp-main ul li {
    margin-bottom: 0.15rem;
}
body.app-erp .btn-sm {
    min-height: 24px;
    padding: 0.12rem 0.45rem;
    font-size: 11.5px;
}

/* ----- Comfortable browse pages (payments / party history) ----- */
.erp-browse {
    --erp-input-h: 34px;
}

.erp-browse .erp-page-title {
    font-size: 1.5rem;
    margin-bottom: 0.2rem;
}

.erp-browse .erp-page-lead {
    font-size: 13px;
    margin-bottom: 0.75rem;
}

.erp-browse-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.erp-browse-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.erp-quick-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.65rem;
}

.erp-quick-filters .btn {
    border-radius: 999px;
    min-height: 30px;
    padding: 0.2rem 0.8rem;
    font-size: 12px;
}

.erp-browse .erp-toolbar {
    gap: 0.55rem 0.75rem;
    padding: 0.7rem 0.8rem;
    margin-bottom: 0.75rem;
    border-radius: 10px;
}

.erp-browse .erp-field > label {
    font-size: 11.5px;
    margin-bottom: 0.2rem;
}

.erp-browse .form-control,
.erp-browse .form-select {
    min-height: var(--erp-input-h);
    font-size: 13px;
    border-radius: 8px;
}

.erp-browse .btn:not(.btn-sm) {
    min-height: 34px;
    border-radius: 8px;
    padding: 0.35rem 0.9rem;
}

.erp-browse .btn-sm {
    min-height: 30px;
    padding: 0.25rem 0.7rem;
    font-size: 12px;
    border-radius: 8px;
}

.erp-stat-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.55rem;
    margin-bottom: 0.75rem;
}

.erp-stat {
    background: var(--erp-panel);
    border: 1px solid var(--erp-border-light);
    border-radius: 10px;
    padding: 0.7rem 0.85rem;
    box-shadow: var(--erp-shadow-sm);
}

.erp-stat .erp-stat-label {
    color: var(--erp-muted);
    font-size: 11.5px;
    margin-bottom: 0.15rem;
}

.erp-stat .erp-stat-value {
    font-size: 1.05rem;
    font-weight: 650;
    color: var(--erp-ink);
    letter-spacing: 0.01em;
}

.erp-stat.is-in .erp-stat-value { color: var(--erp-success); }
.erp-stat.is-out .erp-stat-value { color: var(--erp-danger); }

.erp-browse .erp-panel {
    padding: 0.85rem 1rem;
    margin-bottom: 0.75rem;
    border-radius: 10px;
}

.erp-browse .erp-panel-title {
    font-weight: 650;
    margin-bottom: 0.55rem;
    color: var(--erp-ink);
}

.erp-browse .erp-grid-wrap {
    border-radius: 10px;
    margin-bottom: 0.85rem;
}

.erp-browse table.erp-grid {
    font-size: 13px;
}

.erp-browse table.erp-grid thead th {
    padding: 0.55rem 0.65rem;
    text-align: left;
    font-size: 11.5px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.erp-browse table.erp-grid tbody td {
    padding: 0.55rem 0.65rem;
    text-align: left;
    line-height: 1.35;
}

.erp-browse table.erp-grid tbody tr:hover td {
    background: #eef8f5;
}

.erp-browse table.erp-grid td.num,
.erp-browse table.erp-grid th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.erp-browse table.erp-grid td.actions {
    text-align: right;
    white-space: nowrap;
}

.erp-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.18rem 0.55rem;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.2;
    border: 1px solid transparent;
}

.erp-pill-in {
    color: #067647;
    background: #ecfdf3;
    border-color: #abefc6;
}

.erp-pill-out {
    color: #b42318;
    background: #fef3f2;
    border-color: #fecdca;
}

.erp-pill-muted {
    color: #475467;
    background: #f2f4f7;
    border-color: #e4e7ec;
}

.erp-party-hero {
    background: linear-gradient(180deg, #fffef9 0%, #ffffff 70%);
    border: 1px solid var(--erp-border-light);
    border-radius: 12px;
    padding: 0.95rem 1.05rem;
    margin-bottom: 0.85rem;
    box-shadow: var(--erp-shadow-sm);
}

.erp-party-hero .erp-balance {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.2;
}

.erp-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin: 0 0 0.85rem;
    padding: 0.3rem;
    background: #eef2f6;
    border-radius: 999px;
    border: 1px solid var(--erp-border-light);
}

.erp-tabs a {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    color: var(--erp-muted);
    text-decoration: none;
    font-weight: 600;
    font-size: 12.5px;
    min-height: 34px;
}

.erp-tabs a:hover {
    background: rgba(255, 255, 255, 0.7);
    color: var(--erp-ink);
}

.erp-tabs a.active {
    background: #fff;
    color: var(--erp-ink);
    box-shadow: var(--erp-shadow-sm);
}

.erp-tabs .count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 0.3rem;
    border-radius: 999px;
    background: #e4eaf1;
    color: var(--erp-ink-soft);
    font-size: 11px;
}

.erp-tabs a.active .count {
    background: #dff3ee;
    color: var(--erp-teal);
}

.erp-section-title {
    display: flex;
    align-items: baseline;
    gap: 0.45rem;
    margin: 0.15rem 0 0.45rem;
    font-size: 0.95rem;
    font-weight: 650;
}

.erp-section-title .muted {
    color: var(--erp-muted);
    font-weight: 500;
    font-size: 12.5px;
}

.erp-kv {
    width: 100%;
    margin: 0;
}

.erp-kv tr th,
.erp-kv tr td {
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--erp-border-light);
    vertical-align: top;
}

.erp-kv tr:last-child th,
.erp-kv tr:last-child td {
    border-bottom: 0;
}

.erp-kv tr th {
    width: 38%;
    color: var(--erp-muted);
    font-weight: 600;
    font-size: 12px;
}

.erp-kv tr td {
    font-weight: 550;
}

@media (max-width: 991px) {
    .erp-stat-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 767px) {
    .erp-stat-row {
        grid-template-columns: 1fr 1fr;
    }
    .erp-tabs {
        border-radius: 12px;
    }
    .erp-browse table.erp-grid thead th,
    .erp-browse table.erp-grid tbody td {
        padding: 0.5rem 0.45rem;
        font-size: 12.5px;
    }
}

/* ----- Sale desk (counter bill UX) ----- */
.sale-desk {
    --sale-gap: 0.6rem;
    --sale-ok: #067647;
    --sale-ok-bg: #ecfdf3;
    --sale-due: #8a4b00;
    --sale-due-bg: #fff4e0;
    --sale-bad: #b42318;
    --sale-bad-bg: #fef1ef;
}

/* Top line: what bill this is + the two always-needed tools */
.sale-top {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
}

.sale-top-title,
.sale-top-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.7rem;
}

.sale-top-btn,
.sale-quick-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0.25rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--erp-border);
    background: #fff;
    color: var(--erp-ink-soft);
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.sale-top-btn:hover,
.sale-quick-btn:hover {
    border-color: var(--erp-teal);
    color: var(--erp-teal);
    background: #f3faf8;
}

.sale-top-btn:focus-visible,
.sale-quick-btn:focus-visible,
.pay-chip:focus-visible,
.pay-remove:focus-visible,
.sale-row-del:focus-visible {
    outline: 2px solid var(--erp-teal);
    outline-offset: 1px;
}

.sale-desk-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 32px;
    padding: 0.25rem 0.7rem;
    border-radius: 8px;
    background: #fff;
    border: 1px solid var(--erp-border);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--erp-ink-soft);
    cursor: pointer;
}

.sale-desk-toggle input {
    margin: 0;
}

.sale-doc-switch {
    display: inline-flex;
    padding: 0.18rem;
    gap: 0.18rem;
    background: #dfe6ee;
    border-radius: 9px;
}

.sale-doc-btn {
    border: 0;
    background: transparent;
    color: var(--erp-muted);
    font-size: 12.5px;
    font-weight: 650;
    padding: 0.25rem 0.8rem;
    border-radius: 7px;
    min-height: 28px;
}

.sale-doc-btn.active,
.sale-doc-btn.text-bg-primary {
    background: #fff !important;
    color: var(--erp-ink) !important;
    box-shadow: var(--erp-shadow-sm);
}

.sale-doc-btn.text-bg-secondary {
    background: transparent !important;
    color: var(--erp-muted) !important;
}

.sale-desk-order-note {
    margin-bottom: 0.6rem;
}

/* The three parts of a bill, top to bottom */
.sale-desk-main {
    display: flex;
    flex-direction: column;
    gap: var(--sale-gap);
    min-width: 0;
}

.sale-card {
    background: #fff;
    border: 1px solid var(--erp-border-light);
    border-radius: 10px;
    box-shadow: var(--erp-shadow-sm);
}

.sale-card-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.4rem 0.75rem;
    padding: 0.5rem 0.8rem;
    border-bottom: 1px solid var(--erp-border-light);
}

.sale-card-heading,
.sale-card-head-side {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.6rem;
    min-width: 0;
}

.sale-step-no {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    border-radius: 50%;
    background: var(--erp-ink-soft);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
}

.sale-step-no.is-done {
    background: var(--sale-ok);
}

.sale-card-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 650;
    color: var(--erp-ink);
    line-height: 1.2;
}

.sale-card-sub {
    font-size: 12.5px;
    color: var(--erp-muted);
}

.sale-lookup-status {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--erp-teal);
}

.sale-count-chip {
    font-size: 12px;
    font-weight: 650;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    background: #eef2f6;
    color: var(--erp-muted);
}

.sale-count-chip.has-items {
    background: var(--sale-ok-bg);
    color: var(--sale-ok);
}

.sale-card-body {
    padding: 0.65rem 0.8rem 0.75rem;
}

/* Fields */
.sale-field {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sale-field > label {
    font-size: 12px;
    font-weight: 600;
    color: var(--erp-muted);
    margin-bottom: 0.15rem;
}

body.app-erp .sale-desk .sale-field .form-control,
body.app-erp .sale-desk .sale-field .form-select {
    min-height: 36px;
    border-radius: 8px;
    font-size: 14px;
    padding: 0.25rem 0.6rem;
}

body.app-erp .sale-desk .sale-field .input-group .form-control {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

body.app-erp .sale-desk .sale-field .input-group .btn {
    min-height: 36px;
    padding: 0.25rem 0.8rem;
    font-size: 13px;
    font-weight: 600;
    border-radius: 0 8px 8px 0;
}

.sale-field-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1.35fr) minmax(0, 1fr) minmax(0, 0.9fr);
    gap: 0.5rem 0.7rem;
}

.sale-field-wide { grid-column: span 2; }
.sale-field-grow { flex: 1 1 200px; }
.sale-field-tag { flex: 1.3 1 260px; }

body.app-erp .sale-desk #partyMobile,
body.app-erp .sale-desk #partyName {
    font-weight: 600;
}

body.app-erp .sale-desk #partyBalance {
    background: #f5f7fa;
    font-weight: 650;
    color: var(--erp-muted);
}

body.app-erp .sale-desk #partyBalance.is-due {
    background: var(--sale-bad-bg);
    border-color: #f3c6bf;
    color: var(--sale-bad);
}

body.app-erp .sale-desk #partyBalance.is-adv {
    background: var(--sale-ok-bg);
    border-color: #b7e4c7;
    color: var(--sale-ok);
}

/* Scan / find — the main way to add an item */
.sale-scan-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem 0.7rem;
    padding: 0.6rem 0.8rem;
    background: #f3faf8;
    border-bottom: 1px solid #d7ebe6;
}

body.app-erp .sale-desk .sale-scan-bar .form-control-lg {
    min-height: 42px;
    font-size: 15.5px;
    font-weight: 600;
    border-color: #9fcabf;
}

body.app-erp .sale-desk .sale-scan-bar .btn-lg {
    min-height: 42px;
    padding: 0.3rem 1.1rem;
    font-size: 15px;
    font-weight: 650;
}

.sale-scan-or {
    align-self: flex-end;
    padding: 0 0.1rem 0.65rem;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--erp-muted);
}

/* Item grid */
.sale-desk-grid {
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.sale-desk .erp-grid thead th {
    padding: 0.4rem 0.3rem;
    font-size: 11.5px;
}

.sale-desk .erp-grid tbody td {
    padding: 0.1rem;
}

.sale-desk .erp-grid .erp-cell-input {
    min-height: 32px;
    font-size: 13px;
}

.sale-desk .erp-grid select.erp-cell-input {
    font-size: 12.5px;
    min-height: 32px;
}

.sale-desk .erp-grid .erp-cell-text {
    font-size: 13px;
    min-height: 0;
}

/* Every column wide enough to read its number (a rate like 10795.24 must not be cut). */
#cartTable thead th:nth-child(3) { min-width: 64px; }   /* Tag no. */
#cartTable thead th:nth-child(4) { min-width: 62px; }   /* HUID */
#cartTable thead th:nth-child(5) { min-width: 72px; }   /* Remark */
#cartTable thead th:nth-child(6) { min-width: 58px; }   /* Purity */
#cartTable thead th:nth-child(7) { min-width: 40px; }   /* Piece */
#cartTable thead th:nth-child(8) { min-width: 56px; }   /* Gr. wt. */
#cartTable thead th:nth-child(9) { min-width: 54px; }   /* Less wt. */
#cartTable thead th:nth-child(10) { min-width: 56px; }  /* Net wt. */
#cartTable thead th:nth-child(11) { min-width: 46px; }  /* Tunch */
#cartTable thead th:nth-child(12) { min-width: 42px; }  /* Wstg */
#cartTable thead th:nth-child(13) { min-width: 52px; }  /* St. ch. */
#cartTable thead th:nth-child(14) { min-width: 48px; }  /* Pol wt. */
#cartTable thead th:nth-child(15) { min-width: 62px; }  /* Pol rate */
#cartTable thead th:nth-child(16) { min-width: 48px; }  /* Dia wt. */
#cartTable thead th:nth-child(17) { min-width: 62px; }  /* Dia rate */
#cartTable thead th:nth-child(18) { min-width: 74px; }  /* Rate */
#cartTable thead th:nth-child(19) { min-width: 56px; }  /* Labour */
#cartTable thead th:nth-child(20) { min-width: 66px; }  /* On */
#cartTable thead th:nth-child(21) { min-width: 54px; }  /* Fine */
#cartTable thead th:nth-child(22) { min-width: 52px; }  /* Other */
#cartTable thead th:nth-child(23) { min-width: 62px; }  /* MRP */
#cartTable thead th:nth-child(24) { min-width: 52px; }  /* Disc. */
#cartTable thead th:nth-child(25) { min-width: 60px; }  /* Disc. on */
#cartTable thead th:nth-child(26) { min-width: 58px; }  /* Design */

/*
 * When all the detail columns do not fit, the grid scrolls sideways — but the item
 * (left) and its amount (right) stay in view so the seller never loses the row.
 */
#cartTable {
    --col-type: 84px;
    --col-item: 150px;
    --col-total: 98px;
    --col-del: 76px;
}

#cartTable tr > :nth-child(1),
#cartTable tbody tr > :nth-child(2),
#cartTable thead tr > :nth-child(2),
#cartTable tbody tr > :nth-last-child(1),
#cartTable thead tr > :nth-last-child(1),
#cartTable tfoot tr > :nth-last-child(1),
#cartTable tbody tr > :nth-last-child(2),
#cartTable thead tr > :nth-last-child(2),
#cartTable tfoot tr > :nth-last-child(2) {
    position: sticky;
    z-index: 2;
}

#cartTable thead tr > :nth-child(1),
#cartTable tbody tr > :nth-child(1) {
    left: 0;
    width: var(--col-type);
    min-width: var(--col-type);
    max-width: var(--col-type);
}

#cartTable thead tr > :nth-child(2),
#cartTable tbody tr > :nth-child(2) {
    left: var(--col-type);
    width: var(--col-item);
    min-width: var(--col-item);
    box-shadow: 1px 0 0 var(--erp-border), 6px 0 8px -6px rgba(20, 28, 38, 0.18);
}

#cartTable tfoot tr > :nth-child(1) {
    position: static;
}

#cartTable tr > :nth-last-child(1) {
    right: 0;
    width: var(--col-del);
    min-width: var(--col-del);
}

#cartTable tr > :nth-last-child(2) {
    right: var(--col-del);
    width: var(--col-total);
    min-width: var(--col-total);
    box-shadow: -1px 0 0 var(--erp-border), -6px 0 8px -6px rgba(20, 28, 38, 0.18);
}

#cartTable thead tr > :nth-last-child(1),
#cartTable thead tr > :nth-last-child(2),
#cartTable thead tr > :nth-child(1),
#cartTable thead tr > :nth-child(2) {
    z-index: 3;
}

/* Small screens: pinned columns would leave no room for the rest — let everything scroll. */
@media (max-width: 991px) {
    #cartTable tr > * {
        position: static !important;
        box-shadow: none !important;
    }
}

.sale-desk .erp-grid .line-edit[data-field="itemName"] {
    text-align: left;
    font-weight: 600;
    padding-left: 0.45rem;
}

.sale-desk .erp-grid td.col-total .erp-cell-text {
    font-size: 13.5px;
    font-weight: 700;
    white-space: nowrap;
}

.sale-desk .erp-grid tfoot td {
    padding: 0.35rem 0.25rem;
    font-size: 12.5px;
}

.sale-desk .erp-grid tr.sale-row-new td,
.sale-desk .erp-grid tr.sale-row-new td .erp-cell-input {
    background: #fbfcfd;
}

.sale-desk .erp-grid tr.sale-row-new .line-edit[data-field="itemName"] {
    font-weight: 500;
}

.sale-desk .erp-grid tr.sale-row-new .line-edit[data-field="itemName"]::placeholder {
    color: var(--erp-teal);
    opacity: 0.85;
}

.sale-row-del {
    border: 1px solid #f3c6bf;
    background: #fff;
    color: var(--sale-bad);
    border-radius: 6px;
    min-height: 26px;
    padding: 0.1rem 0.5rem;
    margin: 0 0.15rem;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

.sale-row-del:hover {
    background: var(--sale-bad);
    border-color: var(--sale-bad);
    color: #fff;
}

.sale-empty {
    margin: 0;
    padding: 0.6rem 0.8rem;
    font-size: 13px;
    color: var(--erp-muted);
    border-top: 1px dashed var(--erp-border);
}

.sale-tool-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

/* Payment */
.sale-pay-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 0.9rem;
    align-items: start;
}

.sale-pay-main {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    min-width: 0;
}

.sale-pay-rows {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-bottom: 0.55rem;
}

.pay-split {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem 0.6rem;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--erp-border-light);
    border-radius: 10px;
    background: #f8fafc;
}

.pay-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.pay-chip {
    min-height: 38px;
    padding: 0.3rem 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--erp-border);
    background: #fff;
    color: var(--erp-ink-soft);
    font-size: 13.5px;
    font-weight: 650;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.pay-chip:hover {
    border-color: var(--erp-teal);
    color: var(--erp-teal);
}

.pay-chip.active {
    background: var(--erp-teal);
    border-color: var(--erp-teal);
    color: #fff;
}

.pay-amt-wrap {
    display: flex;
    align-items: center;
    flex: 0 0 170px;
    border: 1px solid #9fcabf;
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}

.pay-amt-wrap:focus-within {
    border-color: var(--erp-teal);
    box-shadow: 0 0 0 2px rgba(15, 107, 92, 0.14);
}

.pay-amt-cur {
    padding: 0 0.1rem 0 0.6rem;
    font-size: 15px;
    font-weight: 650;
    color: var(--erp-muted);
}

body.app-erp .sale-desk .pay-amt {
    border: 0;
    box-shadow: none;
    min-height: 38px;
    padding: 0.2rem 0.5rem 0.2rem 0.25rem;
    font-size: 17px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: right;
    background: transparent;
}

body.app-erp .sale-desk .pay-ref {
    flex: 1 1 170px;
    min-height: 38px;
    border-radius: 8px;
    font-size: 13.5px;
    padding: 0.25rem 0.6rem;
}

.pay-remove {
    border: 0;
    background: transparent;
    color: var(--sale-bad);
    font-size: 12.5px;
    font-weight: 600;
    padding: 0.25rem 0.4rem;
    border-radius: 6px;
    cursor: pointer;
}

.pay-remove:hover {
    background: var(--sale-bad-bg);
}

.pay-split:only-child .pay-remove {
    display: none;
}

.sale-pay-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.55rem;
}

.sale-pay-status {
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 650;
    line-height: 1.35;
}

.sale-pay-status.is-idle {
    background: #f1f4f8;
    color: var(--erp-muted);
    font-weight: 500;
}

.sale-pay-status.is-ok {
    background: var(--sale-ok-bg);
    border-color: #b7e4c7;
    color: var(--sale-ok);
}

.sale-pay-status.is-due {
    background: var(--sale-due-bg);
    border-color: #f2d19b;
    color: var(--sale-due);
}

.sale-pay-status.is-bad {
    background: var(--sale-bad-bg);
    border-color: #f3c6bf;
    color: var(--sale-bad);
}

.sale-due-box {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.6rem;
    margin-top: 0.45rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    background: #fffaf1;
    border: 1px solid #f2d19b;
}

.sale-due-box > label {
    font-size: 13px;
    font-weight: 650;
    color: var(--sale-due);
    margin: 0;
}

body.app-erp .sale-desk .sale-due-box .form-control {
    width: 165px;
    min-height: 34px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 600;
}

.sale-due-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.sale-pay-extras {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem 0.9rem;
}

.sale-print-opts {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.2rem 0.6rem;
    min-height: 36px;
    font-size: 13px;
}

/* Bill summary beside the payment */
.sale-sum {
    border: 1px solid var(--erp-border-light);
    border-radius: 10px;
    background: #fafbfc;
    padding: 0.6rem 0.8rem;
}

.sale-sum-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
    padding: 0.2rem 0;
    font-size: 13px;
    color: var(--erp-muted);
}

.sale-sum-row > label {
    margin: 0;
}

.sale-sum-row strong {
    color: var(--erp-ink);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

body.app-erp .sale-desk .sale-sum-input {
    width: 110px;
    min-height: 30px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    text-align: right;
}

body.app-erp .sale-desk .sale-sum-input[readonly] {
    background: #f1f4f8;
    color: var(--erp-muted);
}

.sale-sum-total {
    margin-top: 0.3rem;
    padding-top: 0.45rem;
    border-top: 2px solid var(--erp-ink-soft);
    font-size: 14px;
    font-weight: 650;
    color: var(--erp-ink);
}

.sale-sum-total strong {
    font-size: 1.3rem;
    font-weight: 700;
}

.sale-sum-old {
    margin-top: 0.3rem;
    padding-top: 0.4rem;
    border-top: 1px dashed var(--erp-border);
}

.sale-sum-old strong.is-due { color: var(--sale-bad); }
.sale-sum-old strong.is-adv { color: var(--sale-ok); }

.sale-sum-note {
    margin: 0;
    font-size: 11.5px;
    color: var(--erp-muted);
}

.sale-sum-detail {
    width: 100%;
    margin-top: 0.5rem;
    font-size: 12px;
}

.sale-sum-detail td {
    padding: 0.22rem 0;
    border-top: 1px solid var(--erp-border-light);
    color: var(--erp-muted);
    font-variant-numeric: tabular-nums;
}

.sale-sum-detail td + td {
    text-align: right;
    padding-left: 0.5rem;
}

.sale-sum-detail td:last-child {
    color: var(--erp-ink);
    font-weight: 600;
}

/* Bottom bar: the three numbers that matter + Save */
.erp-sticky-actions.sale-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem 1rem;
    margin: 0.6rem 0 0;
    padding: 0.5rem 0.8rem;
    background: #13202c;
    border-top: 2px solid var(--erp-gold);
    border-radius: 10px 10px 0 0;
    color: #fff;
    box-shadow: 0 -4px 14px rgba(20, 28, 38, 0.18);
}

.sale-bar-figs {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.3rem 1.6rem;
}

.sale-bar-fig {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.sale-bar-fig > span {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.66);
}

.sale-bar-fig > strong {
    font-size: 1.15rem;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.sale-bar-total > strong {
    font-size: 1.6rem;
    font-weight: 700;
    color: #f3e7c4;
}

.sale-bar-fig.is-due > strong { color: #ffc46b; }
.sale-bar-fig.is-ok > strong { color: #7fe0a7; }
.sale-bar-fig.is-bad > strong { color: #ff9c8f; }

.sale-bar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem 0.7rem;
    margin-left: auto;
}

.sale-bar-hint {
    font-size: 12.5px;
    color: rgba(255, 255, 255, 0.75);
    max-width: 34ch;
    text-align: right;
}

body.app-erp .sale-bar .btn {
    min-height: 36px;
    padding: 0.3rem 0.9rem;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
}

body.app-erp .sale-bar .btn-lg {
    min-height: 46px;
    padding: 0.4rem 1.5rem;
    font-size: 1.05rem;
    font-weight: 700;
    border-radius: 10px;
}

@media (max-width: 1100px) {
    .sale-pay-layout {
        grid-template-columns: 1fr;
    }
    .sale-field-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .sale-bar-hint {
        display: none;
    }
}

@media (max-width: 767px) {
    .sale-field-grid {
        grid-template-columns: 1fr;
    }
    .sale-field-wide {
        grid-column: span 1;
    }
    .sale-scan-or {
        display: none;
    }
    .sale-card-sub {
        display: none;
    }
    .pay-chip {
        flex: 1 1 30%;
    }
    .pay-amt-wrap {
        flex: 1 1 100%;
    }
    .sale-bar-figs {
        gap: 0.3rem 1rem;
    }
    .sale-bar-total > strong {
        font-size: 1.35rem;
    }
    .sale-bar-actions {
        width: 100%;
    }
    body.app-erp .sale-bar .btn-lg {
        flex: 1 1 auto;
    }
}

/* ----- Sell-first counter layout ----- */
.sale-sell {
    --sale-gap: 0.55rem;
    padding-bottom: 0.25rem;
}

.sale-sell-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.55rem 1rem;
    margin-bottom: 0.55rem;
}

.sale-sell-head-left,
.sale-sell-head-right {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem 0.65rem;
}

.sale-sell-lead {
    width: 100%;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--erp-muted);
    letter-spacing: 0.01em;
}

.sale-card-head-slim {
    padding: 0.4rem 0.75rem;
}

.sale-customer-strip {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.35fr) minmax(0, 1fr) minmax(140px, 0.85fr);
    gap: 0.45rem 0.65rem;
    padding-top: 0.55rem;
    padding-bottom: 0.65rem;
}

.sale-customer-strip .sale-field-wide {
    grid-column: span 2;
}

.sale-scan-hero {
    background: linear-gradient(180deg, #e8f6f2 0%, #f7fcfa 55%, #fff 100%);
    border-bottom: 1px solid #cfe8e0;
}

.sale-scan-hero-top {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.4rem 0.7rem;
    padding: 0.55rem 0.8rem 0.15rem;
}

.sale-scan-bar-hero {
    background: transparent;
    border-bottom: 0;
    padding: 0.45rem 0.8rem 0.75rem;
}

body.app-erp .sale-sell .sale-scan-bar-hero .form-control-lg {
    min-height: 48px;
    font-size: 17px;
    border-width: 2px;
    border-color: #6fb5a5;
    border-radius: 10px 0 0 10px;
}

body.app-erp .sale-sell .sale-scan-bar-hero .input-group .btn-lg {
    min-height: 48px;
    padding: 0.35rem 1.25rem;
    font-size: 16px;
    border-radius: 0 10px 10px 0;
}

body.app-erp .sale-sell .sale-scan-bar-hero .sale-field-grow .form-control-lg {
    border-radius: 10px;
}

.sale-sum-collect {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    margin-bottom: 0.65rem;
    padding: 0.7rem 0.8rem;
    border-radius: 10px;
    background: linear-gradient(135deg, #13202c 0%, #1c2f3f 75%);
    border: 1px solid rgba(198, 160, 72, 0.4);
    color: #fff;
}

.sale-sum-collect > span {
    font-size: 11px;
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.75;
}

.sale-sum-collect > strong {
    font-family: var(--erp-display);
    font-size: 1.75rem;
    font-weight: 600;
    line-height: 1.1;
    color: #f3e7c4;
    font-variant-numeric: tabular-nums;
}

.sale-quick-primary {
    background: var(--erp-teal) !important;
    border-color: var(--erp-teal) !important;
    color: #fff !important;
}

.sale-quick-primary:hover {
    background: var(--erp-teal-hover) !important;
    border-color: var(--erp-teal-hover) !important;
    color: #fff !important;
}

body.app-erp .sale-sell .sale-bar .btn-lg {
    min-height: 50px;
    padding: 0.45rem 1.7rem;
    font-size: 1.1rem;
}

@media (max-width: 991px) {
    .sale-customer-strip {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 767px) {
    .sale-customer-strip {
        grid-template-columns: 1fr;
    }
    .sale-customer-strip .sale-field-wide {
        grid-column: span 1;
    }
    .sale-sum-collect > strong {
        font-size: 1.45rem;
    }
}

/* ----- Purchase desk (mirrors sell counter) ----- */
.purchase-desk .purchase-scan-hero {
    background: linear-gradient(180deg, #eef4fa 0%, #f7fafc 55%, #fff 100%);
    border-bottom: 1px solid #d5e0ea;
}

.purchase-hint {
    padding: 0 0.85rem 0.65rem;
    font-size: 12.5px;
    color: var(--erp-muted);
}

.purchase-hint a {
    font-weight: 650;
}

.purchase-desk .sale-pay-extras {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem 0.75rem;
    margin-top: 0.35rem;
}

.purchase-desk .sale-sum-total-row strong {
    font-size: 1.05rem;
}

.purchase-desk #sellerBalance.is-due {
    color: #b42318;
    font-weight: 650;
}

.purchase-desk #sellerBalance.is-adv {
    color: #0f6b5c;
    font-weight: 650;
}

body.app-erp .purchase-desk .sale-scan-bar-hero .form-control-lg {
    border-color: #7aa0c4;
}

/* Purchase grid: core money columns first; Rate/Total always wide + sticky */
.purchase-grid-wrap {
    position: relative;
}

.purchase-grid-scroll-hint {
    display: none;
    font-size: 0.72rem;
    color: var(--erp-muted, #6b7280);
    padding: 0.15rem 0.35rem 0.35rem;
    text-align: right;
}

@media (max-width: 1200px) {
    .purchase-grid-scroll-hint {
        display: block;
    }
}

#purchaseGrid {
    --pg-type: 72px;
    --pg-cat: 86px;
    --pg-name: 148px;
    --pg-purity: 58px;
    --pg-pcs: 46px;
    --pg-wt: 68px;
    --pg-rate: 90px;
    --pg-labour: 74px;
    --pg-total: 100px;
    --pg-del: 58px;
    table-layout: fixed;
    width: max-content;
    min-width: 100%;
}

#purchaseGrid.simple-mode {
    /* Core shop columns only — keep Rate on screen without huge scroll */
    width: 100%;
    min-width: 820px;
}

#purchaseGrid thead th,
#purchaseGrid tbody td,
#purchaseGrid tfoot td {
    white-space: nowrap;
}

#purchaseGrid .col-type {
    width: var(--pg-type);
    min-width: var(--pg-type);
    max-width: var(--pg-type);
}

#purchaseGrid .col-cat {
    width: var(--pg-cat);
    min-width: var(--pg-cat);
    max-width: var(--pg-cat);
}

#purchaseGrid .col-name {
    width: var(--pg-name);
    min-width: var(--pg-name);
    max-width: var(--pg-name);
}

#purchaseGrid .col-name .erp-cell-input {
    text-align: left;
}

#purchaseGrid .col-purity {
    width: var(--pg-purity);
    min-width: var(--pg-purity);
    max-width: var(--pg-purity);
}

#purchaseGrid .col-pcs {
    width: var(--pg-pcs);
    min-width: var(--pg-pcs);
    max-width: var(--pg-pcs);
}

#purchaseGrid .col-wt {
    width: var(--pg-wt);
    min-width: var(--pg-wt);
    max-width: var(--pg-wt);
}

#purchaseGrid .col-rate {
    width: var(--pg-rate);
    min-width: var(--pg-rate);
    max-width: var(--pg-rate);
}

#purchaseGrid .col-labour {
    width: var(--pg-labour);
    min-width: var(--pg-labour);
    max-width: var(--pg-labour);
}

#purchaseGrid .col-total {
    width: var(--pg-total);
    min-width: var(--pg-total);
    max-width: var(--pg-total);
}

#purchaseGrid .col-del {
    width: var(--pg-del);
    min-width: var(--pg-del);
    max-width: var(--pg-del);
}

#purchaseGrid .col-rate .erp-cell-input,
#purchaseGrid .col-labour .erp-cell-input,
#purchaseGrid .col-total .erp-cell-text {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
}

#purchaseGrid .col-del .sale-row-del {
    font-size: 11px;
    padding: 0.15rem 0.25rem;
}

/* Sticky: Type + Category + Name (left), Rate + Labour + Total + Del (right) */
#purchaseGrid thead th.col-type,
#purchaseGrid tbody td.col-type,
#purchaseGrid thead th.col-cat,
#purchaseGrid tbody td.col-cat,
#purchaseGrid thead th.col-name,
#purchaseGrid tbody td.col-name,
#purchaseGrid thead th.col-rate,
#purchaseGrid tbody td.col-rate,
#purchaseGrid tfoot td.col-rate,
#purchaseGrid thead th.col-labour,
#purchaseGrid tbody td.col-labour,
#purchaseGrid thead th.col-total,
#purchaseGrid tbody td.col-total,
#purchaseGrid tfoot td.col-total,
#purchaseGrid thead th.col-del,
#purchaseGrid tbody td.col-del,
#purchaseGrid tfoot td.col-del {
    position: sticky;
    z-index: 2;
    background: #fff;
}

#purchaseGrid thead th.col-type,
#purchaseGrid thead th.col-cat,
#purchaseGrid thead th.col-name,
#purchaseGrid thead th.col-rate,
#purchaseGrid thead th.col-labour,
#purchaseGrid thead th.col-total,
#purchaseGrid thead th.col-del {
    z-index: 4;
    background: var(--erp-surface-soft, #f5f7f9);
}

#purchaseGrid tfoot td.col-total,
#purchaseGrid tfoot td.col-del {
    z-index: 3;
    background: var(--erp-surface-soft, #f5f7f9);
}

#purchaseGrid tbody tr:nth-child(even) td.col-type,
#purchaseGrid tbody tr:nth-child(even) td.col-cat,
#purchaseGrid tbody tr:nth-child(even) td.col-name,
#purchaseGrid tbody tr:nth-child(even) td.col-rate,
#purchaseGrid tbody tr:nth-child(even) td.col-labour,
#purchaseGrid tbody tr:nth-child(even) td.col-total,
#purchaseGrid tbody tr:nth-child(even) td.col-del {
    background: var(--erp-row-alt);
}

#purchaseGrid td.col-total,
#purchaseGrid th.col-total {
    background: var(--erp-total-bg) !important;
}

#purchaseGrid thead th.col-type,
#purchaseGrid tbody td.col-type {
    left: 0;
}

#purchaseGrid thead th.col-cat,
#purchaseGrid tbody td.col-cat {
    left: var(--pg-type);
}

#purchaseGrid thead th.col-name,
#purchaseGrid tbody td.col-name {
    left: calc(var(--pg-type) + var(--pg-cat));
    box-shadow: 1px 0 0 var(--erp-border), 6px 0 8px -6px rgba(20, 28, 38, 0.16);
}

#purchaseGrid thead th.col-del,
#purchaseGrid tbody td.col-del,
#purchaseGrid tfoot td.col-del {
    right: 0;
}

#purchaseGrid thead th.col-total,
#purchaseGrid tbody td.col-total,
#purchaseGrid tfoot td.col-total {
    right: var(--pg-del);
}

#purchaseGrid thead th.col-labour,
#purchaseGrid tbody td.col-labour {
    right: calc(var(--pg-del) + var(--pg-total));
}

#purchaseGrid thead th.col-rate,
#purchaseGrid tbody td.col-rate {
    right: calc(var(--pg-del) + var(--pg-total) + var(--pg-labour));
    box-shadow: -1px 0 0 var(--erp-border), -6px 0 8px -6px rgba(20, 28, 38, 0.16);
}

.purchase-desk .purchase-hint {
    font-size: 0.82rem;
    line-height: 1.35;
    color: var(--erp-muted, #5b6570);
    max-width: 52rem;
}

.purchase-desk .sale-card-items .sale-scan-hero {
    padding-bottom: 0.35rem;
}

.purchase-view-grid .col-name {
    min-width: 140px;
    text-align: left;
}

.purchase-view-grid .col-rate,
.purchase-view-grid .col-labour,
.purchase-view-grid .col-total {
    min-width: 88px;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.purchase-view-grid.simple-mode .col-adv {
    display: none !important;
}

/* Narrow screens: keep Rate + Total pinned; drop Type/Cat/Labour from sticky to free space */
@media (max-width: 991px) {
    #purchaseGrid {
        --pg-type: 64px;
        --pg-cat: 78px;
        --pg-name: 120px;
        --pg-purity: 52px;
        --pg-pcs: 42px;
        --pg-wt: 60px;
        --pg-rate: 84px;
        --pg-labour: 68px;
        --pg-total: 92px;
        --pg-del: 52px;
    }

    #purchaseGrid.simple-mode {
        min-width: 740px;
    }

    #purchaseGrid thead th.col-type,
    #purchaseGrid tbody td.col-type,
    #purchaseGrid thead th.col-cat,
    #purchaseGrid tbody td.col-cat,
    #purchaseGrid thead th.col-labour,
    #purchaseGrid tbody td.col-labour {
        position: static;
        left: auto;
        right: auto;
        box-shadow: none;
    }

    #purchaseGrid thead th.col-name,
    #purchaseGrid tbody td.col-name {
        left: 0;
    }

    #purchaseGrid thead th.col-rate,
    #purchaseGrid tbody td.col-rate {
        right: calc(var(--pg-del) + var(--pg-total));
    }

    .purchase-desk {
        padding-bottom: 4.5rem;
    }

    .purchase-grid-scroll-hint {
        display: block;
    }
}

@media (max-width: 575px) {
    #purchaseGrid .col-del .sale-row-del {
        font-size: 0;
        width: 28px;
        height: 28px;
        padding: 0;
        position: relative;
    }

    #purchaseGrid .col-del .sale-row-del::after {
        content: "x";
        font-size: 14px;
        font-weight: 700;
        position: absolute;
        inset: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}
