/**
 * Compact enterprise ERP forms (Stripe/Linear density)
 * Does not alter field names/IDs.
 */

:root {
    --erp-form-max: 1440px;
    --erp-page-pad: 24px;
    --erp-card-pad: 24px;
    --erp-card-radius: 14px;
    --erp-gap-x: 20px;
    --erp-gap-y: 16px;
    --erp-input-h: 42px;
}

/* —— Soften oversized shells from prior redesign —— */
.erp-form-page {
    max-width: var(--erp-form-max);
    margin: 0 auto;
    padding: 0 0 48px;
}

.erp-form-page__body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.erp-form-section {
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--erp-card-radius);
    box-shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
    overflow: visible;
}

.erp-form-section__header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px var(--erp-card-pad) 0;
}

.erp-form-section__icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 0.875rem;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--primary, #6d28d9) 10%, var(--surface, #fff));
    color: var(--primary, #6d28d9);
}

.erp-form-section__title {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--text-primary, #111827);
    letter-spacing: -0.01em;
}

.erp-form-section__desc {
    margin: 2px 0 0;
    font-size: 0.75rem;
    color: var(--text-secondary, #6b7280);
    line-height: 1.35;
}

.erp-form-section__body {
    padding: 12px var(--erp-card-pad) var(--erp-card-pad);
}

.erp-form-sticky-footer {
    position: sticky;
    bottom: 0;
    z-index: 40;
    margin-top: 16px;
    padding: 12px 0;
    background: color-mix(in srgb, var(--background, #f6f7fb) 92%, transparent);
    border-top: 1px solid var(--border, #e5e7eb);
    backdrop-filter: blur(6px);
}

.erp-form-sticky-footer__inner {
    max-width: var(--erp-form-max);
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.erp-form-tabs {
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--erp-card-radius);
    box-shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
    overflow: hidden;
    margin-top: 8px;
}

.erp-form-tabs__nav {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 10px 12px 0;
    border-bottom: 1px solid var(--border, #e5e7eb);
    background: var(--surface-secondary, #f8fafc);
}

.erp-form-tabs__item {
    margin: 0;
}

.erp-form-tabs__btn {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--text-secondary, #6b7280);
    font-size: 0.8125rem;
    font-weight: 600;
    padding: 0.55rem 0.85rem;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    line-height: 1.3;
}

.erp-form-tabs__btn:hover {
    color: var(--text-primary, #111827);
    background: color-mix(in srgb, var(--primary, #6d28d9) 6%, var(--surface, #fff));
}

.erp-form-tabs__item.is-active .erp-form-tabs__btn {
    color: var(--primary, #6d28d9);
    background: var(--surface, #fff);
    box-shadow: 0 -1px 0 var(--surface, #fff), 0 1px 0 var(--border, #e5e7eb) inset;
}

.erp-form-tabs__panels {
    padding: 16px var(--erp-card-pad, 24px) var(--erp-card-pad, 24px);
}

.erp-form-tabs__panel.hide,
.erp-form-tabs__panel[hidden],
.erp-form-tabs__panel:not(.is-active) {
    display: none !important;
}

.erp-form-tabs__panel.is-active {
    display: block !important;
}

.erp-pricing-card {
    background: transparent;
    border: 0;
    padding: 0;
    overflow-x: auto;
}

/* —— Compact card used by Purchase / Sale —— */
.erp-card {
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    border-radius: var(--erp-card-radius);
    box-shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
    padding: var(--erp-card-pad);
    margin-bottom: 16px;
}

.erp-card__title {
    margin: 0 0 16px;
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--text-primary, #111827);
    letter-spacing: -0.01em;
}

/* Use Bootstrap float grid (flex collapses column widths) */
.erp-card .row {
    margin-left: -10px;
    margin-right: -10px;
}

.erp-card .row:before,
.erp-card .row:after {
    content: " ";
    display: table;
}

.erp-card .row:after {
    clear: both;
}

.erp-card .row > [class*="col-"] {
    padding-left: 10px;
    padding-right: 10px;
}

.erp-card .form-group {
    margin-bottom: var(--erp-gap-y);
}

.erp-card .form-group > label,
.erp-card .control-label {
    display: block !important;
    width: 100%;
    margin-bottom: 6px;
    margin-right: 0;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--label-color, #6b7280);
    line-height: 1.3;
}

.erp-card .form-group > label + i.fa-info-circle,
.erp-card .form-group > label + i.hover-q {
    float: right;
    margin-top: -1.55rem;
    position: relative;
    z-index: 2;
}

.erp-card .form-control,
.erp-card .input-group,
.erp-card .select2-container {
    width: 100% !important;
    max-width: 100%;
}

.erp-card .help-block {
    margin-top: 4px;
    margin-bottom: 0;
    font-size: 0.75rem;
}

.erp-field-stack {
    display: flex;
    flex-direction: column;
}

.erp-addr-compact {
    margin-top: 6px;
    max-height: 40px;
    overflow: hidden;
    font-size: 0.75rem;
    line-height: 1.35;
    color: var(--text-secondary, #6b7280);
}

.erp-addr-compact strong {
    font-weight: 600;
    color: var(--text-primary, #111827);
}

.erp-addr-box {
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 10px;
    background: var(--surface-secondary, #f8fafc);
    padding: 8px 10px;
    max-height: 70px;
    overflow: hidden;
    font-size: 0.75rem;
    line-height: 1.35;
    color: var(--text-secondary, #6b7280);
    margin-bottom: var(--erp-gap-y);
}

.erp-addr-box strong {
    display: block;
    margin-bottom: 2px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary, #111827);
}

.erp-switch-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    min-height: var(--erp-input-h);
}

/* Pay term is a compound number + unit control, not a Bootstrap addon group. */
.erp-pay-term-group {
    display: flex;
    align-items: stretch;
    width: 100%;
    min-width: 0;
}

.erp-pay-term-group > input.form-control {
    flex: 0 0 40%;
    width: 40% !important;
    min-width: 0;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.erp-pay-term-group > select.form-control,
.erp-pay-term-group > .select2-container {
    flex: 1 1 60%;
    width: 60% !important;
    min-width: 0;
}

.erp-pay-term-group > select.form-control {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.erp-pay-term-group > .select2-container .select2-selection--single {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
}

/* Products toolbar */
.erp-toolbar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.erp-toolbar__search {
    flex: 1 1 auto;
    min-width: 0;
}

.erp-toolbar__actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.erp-toolbar .form-group {
    margin-bottom: 0;
}

.erp-toolbar .btn,
.erp-toolbar .tw-dw-btn {
    min-height: var(--erp-input-h);
    height: var(--erp-input-h);
    border-radius: 8px;
    font-weight: 600;
    box-shadow: none !important;
    white-space: nowrap;
}

.erp-toolbar .btn-default,
.erp-toolbar .btn-link,
.erp-toolbar .tw-dw-btn:not(.tw-dw-btn-primary) {
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e5e7eb);
    color: var(--text-secondary, #6b7280);
    text-decoration: none;
    box-shadow: none !important;
}

@media (max-width: 767px) {
    .erp-toolbar {
        flex-wrap: wrap;
    }

    .erp-toolbar__search {
        flex-basis: 100%;
    }

    .erp-card {
        padding: 16px;
    }

    section.content:has(#add_purchase_form),
    section.content:has(#add_sell_form) {
        padding-left: 12px;
        padding-right: 12px;
    }
}

.erp-txn-summary {
    display: flex;
    justify-content: flex-end;
    margin-top: 10px;
}

.erp-txn-summary table {
    width: auto;
    min-width: 240px;
    margin: 0;
}

.erp-txn-summary th {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text-secondary, #6b7280);
    padding: 4px 12px 4px 0 !important;
    border: 0 !important;
}

.erp-txn-summary td {
    font-weight: 700;
    font-size: 0.875rem;
    color: var(--text-primary, #111827);
    padding: 4px 0 !important;
    border: 0 !important;
    font-variant-numeric: tabular-nums;
}

section.content:has(#add_purchase_form),
section.content:has(#add_sell_form) {
    max-width: var(--erp-form-max);
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--erp-page-pad);
    padding-right: var(--erp-page-pad);
}

form.erp-txn-form .erp-txn-table-wrap,
form.erp-txn-form .table-responsive.erp-txn-table-wrap {
    background: transparent;
    border: 0;
    box-shadow: none;
    padding: 0;
    border-radius: 0;
}

@media (min-width: 1100px) {
    form#add_purchase_form .pull-right.col-md-5 {
        position: static;
        background: transparent;
        border: 0;
        box-shadow: none;
        padding: 0 !important;
    }
}

.erp-contact-modal.modal-dialog {
    width: min(960px, 96vw);
}

.erp-contact-page {
    max-width: 1100px;
}

.erp-contact-page__body {
    padding: 0;
}

.erp-contact-page__footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border, #e5e7eb);
}

.erp-contact-type-toggle {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    min-height: var(--erp-input-h, 42px);
}

.erp-contact-type-toggle .radio-inline {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    padding: 0.45rem 0.75rem;
    padding-left: 0.75rem; /* kill Bootstrap .radio-inline absolute offset */
    border: 1px solid var(--border, #e5e7eb);
    border-radius: 8px;
    background: var(--surface, #fff);
    font-weight: 500;
    color: var(--text-secondary, #6b7280);
    cursor: pointer;
    line-height: 1.2;
}

.erp-contact-type-toggle .radio-inline:hover {
    border-color: color-mix(in srgb, var(--primary, #6d28d9) 40%, var(--border, #e5e7eb));
    color: var(--text-primary, #111827);
}

.erp-contact-type-toggle .radio-inline input[type="radio"] {
    position: static !important;
    margin: 0 !important;
    float: none !important;
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary, #6d28d9);
}

.erp-contact-type-toggle .radio-inline span {
    line-height: 1.2;
    white-space: nowrap;
}

.erp-contact-type-toggle .radio-inline:has(input:checked) {
    border-color: color-mix(in srgb, var(--primary, #6d28d9) 55%, var(--border, #e5e7eb));
    background: color-mix(in srgb, var(--primary, #6d28d9) 12%, var(--surface, #fff));
    color: var(--primary, #6d28d9);
    font-weight: 600;
}

[data-theme="dark"] .erp-contact-type-toggle .radio-inline {
    background: var(--surface-secondary, #1f2937);
    border-color: var(--border, #334155);
    color: var(--text-secondary, #cbd5e1);
}

[data-theme="dark"] .erp-contact-type-toggle .radio-inline:hover {
    border-color: color-mix(in srgb, var(--primary, #8b5cf6) 45%, var(--border, #334155));
    color: var(--text-primary, #f9fafb);
}

[data-theme="dark"] .erp-contact-type-toggle .radio-inline:has(input:checked) {
    background: color-mix(in srgb, var(--primary, #8b5cf6) 18%, var(--surface, #111827));
    border-color: color-mix(in srgb, var(--primary, #8b5cf6) 50%, var(--border, #334155));
    color: var(--primary, #a78bfa);
}

.erp-assigned-wrap .select2-container {
    width: 100% !important;
}

form.erp-txn-form .tw-mb-4.tw-bg-white,
form.erp-txn-form [class*="tw-rounded-xl"] {
    margin-bottom: 12px !important;
}

form.erp-txn-form .box-header {
    padding: 10px 16px 4px;
}

form.erp-txn-form .box-title {
    font-size: 0.875rem;
}

form.erp-txn-form .form-group {
    margin-bottom: 14px;
}

form.erp-txn-form .well {
    padding: 10px 12px;
    margin-bottom: 12px;
}

/* —— Sale location (circled #1) —— */
.erp-sale-location {
    margin-bottom: 8px;
}

.erp-sale-location > [class*="col-"] {
    max-width: 420px;
    width: 33.333333%;
}

@media (max-width: 991px) {
    .erp-sale-location > [class*="col-"] {
        width: 50%;
        max-width: none;
    }
}

@media (max-width: 767px) {
    .erp-sale-location > [class*="col-"] {
        width: 100%;
    }
}

.erp-sale-location .form-group {
    margin-bottom: 12px;
}

.erp-sale-location .input-group {
    width: 100% !important;
    display: table !important;
    table-layout: auto !important;
}

.erp-sale-location .input-group-addon {
    width: 42px !important;
}

.erp-sale-location .input-group > .form-control,
.erp-sale-location .input-group > select,
.erp-sale-location .input-group .select2-container {
    width: 100% !important;
}

/* —— Restaurant table / staff (circled #2 & #3) ——
   AJAX injects .col-sm-4 into #restaurant_module_span — must be full-width, not nested in a narrow col. */
span#restaurant_module_span,
.erp-restaurant-module {
    display: block !important;
    width: 100% !important;
    float: none !important;
}

span#restaurant_module_span:before,
span#restaurant_module_span:after,
.erp-restaurant-module:before,
.erp-restaurant-module:after {
    content: " ";
    display: table;
}

span#restaurant_module_span:after,
.erp-restaurant-module:after {
    clear: both;
}

#restaurant_module_span > [class*="col-"] {
    min-width: 240px;
}

#restaurant_module_span .form-group {
    margin-bottom: var(--erp-gap-y);
}

#restaurant_module_span .input-group {
    width: 100% !important;
    display: table !important;
    table-layout: auto !important;
}

#restaurant_module_span .input-group-addon,
#restaurant_module_span .input-group-btn {
    width: 42px !important;
}

#restaurant_module_span .input-group > .form-control,
#restaurant_module_span .input-group > select,
#restaurant_module_span .input-group .select2-container {
    width: 100% !important;
}

/* Collapsible form sections */
.erp-form-section--collapsible .erp-form-section__header.erp-form-section__toggle {
    cursor: pointer;
    user-select: none;
    padding-bottom: 12px;
    transition: background var(--transition-fast, 0.15s ease);
    border-radius: var(--erp-card-radius) var(--erp-card-radius) 0 0;
}

.erp-form-section--collapsible .erp-form-section__header.erp-form-section__toggle:hover {
    background: color-mix(in srgb, var(--primary, #6d28d9) 4%, var(--surface, #fff));
}

.erp-form-section__chevron {
    margin-left: auto;
    color: var(--text-muted, #9ca3af);
    font-size: 0.75rem;
    transition: transform var(--transition-fast, 0.15s ease);
}

.erp-form-section--collapsible.is-collapsed .erp-form-section__chevron {
    transform: rotate(-90deg);
}

.erp-form-section--collapsible .erp-form-section__body.hide {
    display: none !important;
}

.erp-form-section.erp-form-section--nested {
    margin-bottom: 12px;
    border: 1px dashed var(--border, #e5e7eb);
    box-shadow: none;
}
