/*
 * Technting Manufacturing ERP theme for the admin panel (docs/UX_RULES.md, "Screen density").
 *
 * A plain stylesheet loaded after Filament's own (render hook in AdminPanelProvider), so it needs
 * no build step and reaches every installation through the normal system update. Copied to
 * public/css/app/erp-theme.css (keep both files identical; tests/Feature/ErpThemeTest checks it).
 *
 * Two densities, chosen per user in the user menu (users.dashboard_preferences "density"):
 *   compact      (default) ERP density: smaller text and spacing, 3 or 4 form columns on wide screens
 *   comfortable  Filament's own sizes (nothing below applies except the rules marked "always")
 *
 * Filament 5 sizes everything from Tailwind variables (--spacing, --text-*), declared in the
 * "theme" layer; the declarations here are not layered, so they win without !important.
 *
 * Accessibility (WCAG 2.2 AA) kept on purpose:
 *   - buttons, inputs and row actions stay at least 24 x 24 CSS px (2.5.8 target size);
 *   - checkboxes and radios keep 16 px;
 *   - colours stay Filament's, except the placeholder text, darkened to 4.5:1;
 *   - focus rings are not touched;
 *   - wide-screen columns only apply to wide containers, so the page still reflows at 320 px.
 * Only logical properties (inline-start / inline-end): Arabic right to left works the same.
 */

/* ---------------------------------------------------------------- compact density */

html:not([data-density="comfortable"]) {
    --spacing: 0.2rem;
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-sm--line-height: calc(1.15 / 0.8125);
    --text-base: 0.875rem;
    --text-base--line-height: calc(1.3 / 0.875);
    --text-lg: 1rem;
    --text-xl: 1.125rem;
    --text-2xl: 1.25rem;
    --text-3xl: 1.375rem;
    --sidebar-width: 16.5rem;
}

/* Page header: less air above and below the title. */
html:not([data-density="comfortable"]) .fi-page-header-main-ctn {
    row-gap: calc(var(--spacing) * 4);
    padding-block: calc(var(--spacing) * 4);
}

html:not([data-density="comfortable"]) .fi-page-main {
    gap: calc(var(--spacing) * 5);
}

/* Sections: smaller padding and gaps between fields. */
html:not([data-density="comfortable"]) .fi-section:not(.fi-section-not-contained):not(.fi-divided) > .fi-section-content-ctn > .fi-section-content,
html:not([data-density="comfortable"]) .fi-section:not(.fi-section-not-contained).fi-divided > .fi-section-content-ctn > .fi-section-content > * {
    padding: calc(var(--spacing) * 4);
}

html:not([data-density="comfortable"]) .fi-section-header {
    padding-block: calc(var(--spacing) * 3);
    padding-inline: calc(var(--spacing) * 4);
}

html:not([data-density="comfortable"]) .fi-sc-has-gap {
    gap: calc(var(--spacing) * 4);
}

html:not([data-density="comfortable"]) .fi-fo-field {
    row-gap: calc(var(--spacing) * 1.5);
}

/* Checkboxes and radios keep 16 px (they are sized from --spacing). */
html:not([data-density="comfortable"]) .fi-checkbox-input,
html:not([data-density="comfortable"]) .fi-radio-input {
    width: 1rem;
    height: 1rem;
}

/* Table header cells: less height. Row cells are sized by their content and the spacing above. */
html:not([data-density="comfortable"]) .fi-ta-header-cell {
    padding-block: calc(var(--spacing) * 2.5);
}

/*
 * Wide screens: a two-column form block becomes three, then four columns. Container queries, so
 * a modal or a narrow column keeps two columns and phones keep one; section contents are
 * containers already (Filament), tab panels and forms are made containers here. Fields that
 * asked for a full row (columnSpanFull) keep it. Blocks holding groups, sections, tabs, fieldsets
 * or repeaters are left alone (a :has() inside a :has() is not allowed, so they are listed).
 */
.fi-sc-tabs-tab,
.fi-sc-form {
    container-type: inline-size;
}

@container (min-width: 46rem) {
    html:not([data-density="comfortable"]) .fi-grid.lg\:fi-grid-cols[style*="--cols-lg: repeat(2, minmax(0, 1fr))"]:not(:has(> .fi-grid-col > .fi-sc-component.fi-grid-ctn, > .fi-grid-col > .fi-sc-component > :is(.fi-section, .fi-sc-section, .fi-sc-tabs, .fi-fieldset, .fi-fo-repeater, .fi-fo-table-repeater, .fi-fo-builder))) {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@container (min-width: 64rem) {
    html:not([data-density="comfortable"]) .fi-grid.lg\:fi-grid-cols[style*="--cols-lg: repeat(2, minmax(0, 1fr))"]:not(:has(> .fi-grid-col > .fi-sc-component.fi-grid-ctn, > .fi-grid-col > .fi-sc-component > :is(.fi-section, .fi-sc-section, .fi-sc-tabs, .fi-fieldset, .fi-fo-repeater, .fi-fo-table-repeater, .fi-fo-builder))),
    html:not([data-density="comfortable"]) .fi-grid.lg\:fi-grid-cols[style*="--cols-lg: repeat(3, minmax(0, 1fr))"]:not(:has(> .fi-grid-col > .fi-sc-component.fi-grid-ctn, > .fi-grid-col > .fi-sc-component > :is(.fi-section, .fi-sc-section, .fi-sc-tabs, .fi-fieldset, .fi-fo-repeater, .fi-fo-table-repeater, .fi-fo-builder))) {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

/* ---------------------------------------------------------------- always (both densities) */

/* Tabs never hide behind a horizontal scrollbar: they wrap onto a second line. */
.fi-tabs {
    flex-wrap: wrap;
    overflow-x: visible;
    row-gap: calc(var(--spacing) * 1);
}

/*
 * Lists: on wide screens the row actions (Edit, Confirm, Convert, Cancel...) stay in view at the
 * inline end of the row, even when the other columns need a horizontal scroll. The column is
 * capped and its actions wrap onto a second line, so it never grows over the record (audit F-386).
 * Phones and tablets keep the actions as a normal last column: a pinned column there covered the
 * name and the amounts (audit F-391).
 */
@media (min-width: 64rem) {
    .fi-ta-table th.fi-ta-actions-header-cell:last-child,
    .fi-ta-table td.fi-ta-cell:last-child:has(> .fi-ta-actions) {
        position: sticky;
        inset-inline-end: 0;
        z-index: 1;
        background-color: var(--color-white);
        box-shadow: -1px 0 0 0 var(--gray-200);
    }

    [dir="rtl"] .fi-ta-table th.fi-ta-actions-header-cell:last-child,
    [dir="rtl"] .fi-ta-table td.fi-ta-cell:last-child:has(> .fi-ta-actions) {
        box-shadow: 1px 0 0 0 var(--gray-200);
    }

    .fi-ta-table td.fi-ta-cell:last-child > .fi-ta-actions {
        flex-wrap: wrap;
        row-gap: calc(var(--spacing) * 1);
        max-width: 15rem;
        margin-inline-start: auto;
    }

    .fi-ta-table thead th.fi-ta-actions-header-cell:last-child {
        background-color: var(--gray-50);
    }

    .fi-ta-table tr:hover > td.fi-ta-cell:last-child:has(> .fi-ta-actions) {
        background-color: var(--gray-50);
    }
}

/* Money and quantity columns line up: western digits of the same width. */
.fi-ta-text-item,
.fi-fo-table-repeater input,
.fi-ta-summary-row,
.erp-totals {
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- document lines as a table */

/*
 * Line tables never squeeze their columns: each input keeps a minimum width and the table
 * scrolls sideways inside its own box when the lines are wider than the page.
 */
.fi-fo-table-repeater {
    overflow-x: auto;
    /*
     * Keeps the visually hidden texts of the table (screen-reader labels, position: absolute)
     * inside the scroll box. Without it they are placed against the page and, in Arabic, push
     * the whole page sideways (the table scrolled, but the page did too).
     */
    position: relative;
}

/*
 * Dropdown lists in a line table open in full above the page. The repeater is a Filament fixed
 * positioning context (AppServiceProvider), so a Select places its list with position: fixed. But
 * Filament also makes the table box a CSS container, and a container is the containing block of
 * fixed elements: the list stayed inside the scroll box and was cut. The container moves one level
 * up, to the field column that holds the table (same width, no scrolling), so the list escapes the
 * box and the responsive table layout still reads the same width.
 */
.fi-fo-table-repeater.fi-fixed-positioning-context {
    container-type: normal;
}

.fi-fo-field-content-col:has(> .fi-fo-table-repeater.fi-fixed-positioning-context) {
    container-type: inline-size;
}

/*
 * The calendar of a date picker in a line (ERP audit F-393) follows the same rule: Filament
 * places it with position: absolute, inside the scroll box, where it was cut. Fixed, its
 * containing block is the field column above (see just before), so it opens in full.
 */
.fi-fo-table-repeater.fi-fixed-positioning-context .fi-fo-date-time-picker-panel {
    position: fixed;
}

.fi-fo-table-repeater > table th {
    white-space: nowrap;
}

@container (min-width: 36rem) {
    .fi-fo-table-repeater > table {
        width: max-content;
        min-width: 100%;
    }

    /* Minimum widths: selects (product, account, tax...) and text inputs never shrink to a sliver. */
    .fi-fo-table-repeater > table > tbody > tr > td .fi-select-input,
    .fi-fo-table-repeater > table > tbody > tr > td .fi-select-input-btn {
        min-width: 7.5rem;
    }

    .fi-fo-table-repeater > table > tbody > tr > td .fi-input-wrp {
        min-width: 5.5rem;
    }

    /*
     * A date cell is as wide as a date in words ("20 سبتمبر 2026", "Sep 20, 2026"): the picker's
     * text box is short (size 12, DatePickers) and grows to this minimum.
     */
    .fi-fo-table-repeater > table > tbody > tr > td .fi-fo-date-time-picker .fi-input-wrp {
        min-width: 8.5rem;
    }

    .fi-fo-table-repeater > table > tbody > tr > td .fi-fo-date-time-picker-display-text-input {
        width: 100%;
        min-width: 0;
    }

    /* The chosen option stays on one line (full text in the dropdown and on hover). */
    .fi-fo-table-repeater > table > tbody > tr > td .fi-select-input-value-ctn {
        flex-wrap: nowrap;
        white-space: nowrap;
        word-break: normal;
        overflow: hidden;
    }

    .fi-fo-table-repeater > table > tbody > tr > td .fi-select-input-value-ctn > * {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /*
     * In a table row the column header is the label: the field's own label row (with its "?" hint
     * and "open" icons) and its helper text are hidden visually, still read by screen readers.
     */
    .fi-fo-table-repeater > table > tbody > tr > td .fi-fo-field-label-col,
    .fi-fo-table-repeater > table > tbody > tr > td .fi-fo-field-content-col > .fi-sc {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
}

/* Inputs in a compact line table keep a visible border (Filament removes it in compact mode). */
.fi-fo-table-repeater.fi-compact .fi-input-wrp,
.fi-fo-table-repeater.fi-compact .fi-select-input-btn {
    box-shadow: 0 0 0 1px var(--gray-300);
    background-color: var(--color-white);
}

.fi-fo-table-repeater.fi-compact .fi-input-wrp:focus-within,
.fi-fo-table-repeater.fi-compact .fi-select-input-btn:focus {
    box-shadow: 0 0 0 2px var(--primary-600);
}

/* Read-only amounts (sub total, tax, total): grey background, no border, so they read as results. */
.fi-fo-table-repeater.fi-compact .fi-input-wrp:has(input[readonly]),
.fi-fo-table-repeater.fi-compact .fi-input-wrp.fi-disabled {
    box-shadow: none;
    background-color: var(--gray-50);
}

.fi-fo-table-repeater input[readonly] {
    text-align: end;
}

html:not([data-density="comfortable"]) .fi-fo-table-repeater > table td {
    padding: calc(var(--spacing) * 1);
}

html:not([data-density="comfortable"]) .fi-fo-table-repeater > table th {
    padding: calc(var(--spacing) * 2) calc(var(--spacing) * 1.5);
}

/* Totals under a line table: sticky at the bottom of the screen while the lines scroll. */
.erp-totals {
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: calc(var(--spacing) * 2) calc(var(--spacing) * 6);
    padding: calc(var(--spacing) * 2.5) calc(var(--spacing) * 4);
    border-top: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    background-color: var(--color-white);
    box-shadow: 0 -4px 8px -6px rgb(0 0 0 / 0.15);
    font-size: var(--text-sm);
}

.erp-totals-item {
    display: flex;
    gap: calc(var(--spacing) * 2);
    align-items: baseline;
}

.erp-totals-label {
    color: var(--gray-600);
}

.erp-totals-value {
    font-weight: var(--font-weight-semibold);
    color: var(--gray-950);
    direction: ltr;
    unicode-bidi: isolate;
}

.erp-totals-item.erp-totals-grand .erp-totals-value {
    font-size: var(--text-base);
    font-weight: var(--font-weight-bold);
}

.erp-totals-item.erp-totals-warning .erp-totals-value {
    color: var(--danger-700);
}

/* ---------------------------------------------------------------- dashboard: modules as icons */

.erp-modules {
    /*
     * Equal tiles in a grid: at most --erp-modules-cols per row (5 by default; 4, 6 or 8 chosen per
     * browser in the "Module icons" panel, html[data-erp-modules-cols]), fewer when a tile would get
     * narrower than --erp-modules-min (tablets), so no row ever has odd widths. Phones: one row that
     * scrolls sideways (below). Grid columns follow the writing direction, so Arabic starts at the right.
     */
    --erp-modules-cols: 5;
    --erp-modules-min: 7.5rem;
    --erp-modules-gap: calc(var(--spacing) * 2.5);
    display: grid;
    grid-template-columns: repeat(
        auto-fill,
        minmax(max(var(--erp-modules-min), calc((100% - (var(--erp-modules-cols) - 1) * var(--erp-modules-gap)) / var(--erp-modules-cols))), 1fr)
    );
    gap: var(--erp-modules-gap);
}

html[data-erp-modules-cols="4"] .erp-modules { --erp-modules-cols: 4; }
html[data-erp-modules-cols="6"] .erp-modules { --erp-modules-cols: 6; }
html[data-erp-modules-cols="8"] .erp-modules { --erp-modules-cols: 8; --erp-modules-min: 6.5rem; }

.erp-module {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: calc(var(--spacing) * 1.5);
    min-width: 0;
    min-height: 5rem;
    padding: calc(var(--spacing) * 2.5) calc(var(--spacing) * 2);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    background-color: var(--color-white);
    color: var(--gray-700);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.erp-module:hover {
    border-color: var(--primary-300);
    box-shadow: 0 4px 12px -6px rgb(0 0 0 / 0.18);
    transform: translateY(-1px);
}

.erp-module:focus-visible {
    outline: 2px solid var(--primary-600);
    outline-offset: 2px;
}

.erp-module-active {
    border-color: var(--primary-600);
    background-color: var(--primary-50);
    color: var(--primary-800);
    box-shadow: inset 0 0 0 1px var(--primary-600);
}

.erp-module-icon {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius-lg);
    background-color: var(--primary-50);
    color: var(--primary-700);
}

.erp-module-active .erp-module-icon {
    background-color: var(--primary-600);
    color: var(--color-white);
}

.erp-module-icon svg {
    width: 1.25rem;
    height: 1.25rem;
}

/* Small icons: icon and name side by side in a low tile. */
html[data-erp-modules-size="compact"] .erp-modules { --erp-modules-min: 9rem; --erp-modules-gap: calc(var(--spacing) * 2); }
html[data-erp-modules-size="compact"] .erp-module {
    flex-direction: row;
    justify-content: flex-start;
    gap: calc(var(--spacing) * 2);
    min-height: 2.75rem;
    padding: calc(var(--spacing) * 1.5) calc(var(--spacing) * 2.5);
    text-align: start;
}
html[data-erp-modules-size="compact"] .erp-module-icon { width: 1.75rem; height: 1.75rem; }
html[data-erp-modules-size="compact"] .erp-module-icon svg { width: 1rem; height: 1rem; }

/* Large icons: taller tiles, bigger icon and name. */
html[data-erp-modules-size="large"] .erp-modules { --erp-modules-min: 9rem; --erp-modules-gap: calc(var(--spacing) * 3.5); }
html[data-erp-modules-size="large"] .erp-module {
    gap: calc(var(--spacing) * 2.5);
    min-height: 7rem;
    padding: calc(var(--spacing) * 4) calc(var(--spacing) * 3);
}
html[data-erp-modules-size="large"] .erp-module-icon { width: 3rem; height: 3rem; border-radius: var(--radius-xl); }
html[data-erp-modules-size="large"] .erp-module-icon svg { width: 1.625rem; height: 1.625rem; }
html[data-erp-modules-size="large"] .erp-module-label { font-size: var(--text-sm); }

/* Dark mode. */
.dark .erp-module {
    border-color: rgb(255 255 255 / 0.1);
    background-color: var(--gray-900);
    color: var(--gray-200);
}
.dark .erp-module:hover { border-color: var(--primary-500); }
.dark .erp-module-icon { background-color: rgb(255 255 255 / 0.06); color: var(--primary-400); }
.dark .erp-module-active {
    border-color: var(--primary-500);
    background-color: rgb(255 255 255 / 0.05);
    color: var(--primary-300);
    box-shadow: inset 0 0 0 1px var(--primary-500);
}
.dark .erp-module-active .erp-module-icon { background-color: var(--primary-500); color: var(--gray-950); }

/* Phones: one row that scrolls sideways, so the cards stay near the top (any column choice). */
@media (max-width: 40rem) {
    .erp-modules {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: calc(var(--spacing) * 1);
        scroll-snap-type: x proximity;
        scrollbar-width: thin;
    }

    .erp-module {
        flex: 0 0 5.75rem;
        scroll-snap-align: start;
    }

    html[data-erp-modules-size="compact"] .erp-module { flex-basis: auto; }
    html[data-erp-modules-size="compact"] .erp-module-label { white-space: nowrap; }
    html[data-erp-modules-size="large"] .erp-module { flex-basis: 7.5rem; }
}

/* The "Module icons" panel: icons per row and icon size, kept in this browser only. */
.erp-modules-wrap {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing) * 3);
}

.erp-modules-layout {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: calc(var(--spacing) * 3) calc(var(--spacing) * 6);
    padding: calc(var(--spacing) * 3) calc(var(--spacing) * 4);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-xl);
    background-color: var(--gray-50);
    font-size: var(--text-sm);
    color: var(--gray-700);
}

.erp-modules-layout-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: calc(var(--spacing) * 2);
}

.erp-modules-layout-title {
    font-weight: var(--font-weight-semibold);
}

.erp-modules-layout-choices {
    display: inline-flex;
    flex-wrap: wrap;
    gap: calc(var(--spacing) * 1);
    padding: calc(var(--spacing) * 0.75);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    background-color: var(--color-white);
}

.erp-modules-layout-choice {
    min-width: 2rem;
    min-height: 1.75rem;
    padding: 0 calc(var(--spacing) * 2.5);
    border-radius: var(--radius-md);
    color: var(--gray-700);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
}

.erp-modules-layout-choice:hover {
    background-color: var(--gray-100);
}

.erp-modules-layout-choice[aria-pressed="true"] {
    background-color: var(--primary-600);
    color: var(--color-white);
}

.erp-modules-layout-choice:focus-visible,
.erp-modules-layout-link:focus-visible {
    outline: 2px solid var(--primary-600);
    outline-offset: 2px;
}

.erp-modules-layout-end {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: calc(var(--spacing) * 3);
    margin-inline-start: auto;
}

.erp-modules-layout-note {
    color: var(--gray-500);
    font-size: var(--text-xs);
}

.erp-modules-layout-link {
    min-height: 1.75rem;
    color: var(--primary-700);
    font-weight: var(--font-weight-semibold);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}

.dark .erp-modules-layout {
    border-color: rgb(255 255 255 / 0.1);
    background-color: rgb(255 255 255 / 0.03);
    color: var(--gray-200);
}
.dark .erp-modules-layout-choices { border-color: rgb(255 255 255 / 0.1); background-color: var(--gray-900); }
.dark .erp-modules-layout-choice { color: var(--gray-200); }
.dark .erp-modules-layout-choice:hover { background-color: rgb(255 255 255 / 0.06); }
.dark .erp-modules-layout-choice[aria-pressed="true"] { background-color: var(--primary-500); color: var(--gray-950); }
.dark .erp-modules-layout-note { color: var(--gray-400); }
.dark .erp-modules-layout-link { color: var(--primary-400); }

.erp-module-label {
    font-size: var(--text-xs);
    font-weight: var(--font-weight-semibold);
    line-height: 1.25;
}

.erp-module-details {
    padding: calc(var(--spacing) * 5);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-xl);
    background-color: var(--color-white);
}

.erp-module-details-header {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 3);
    margin-bottom: calc(var(--spacing) * 4);
}

.erp-module-details-title {
    font-size: var(--text-xl);
    font-weight: var(--font-weight-bold);
    color: var(--gray-950);
}

.erp-module-part {
    margin: calc(var(--spacing) * 5) 0 calc(var(--spacing) * 2);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-semibold);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--gray-600);
}

.erp-module-pages {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
    gap: calc(var(--spacing) * 2);
    margin: 0;
    padding: 0;
    list-style: none;
}

.erp-module-page {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 2.5);
    min-height: 2.75rem;
    padding: calc(var(--spacing) * 2) calc(var(--spacing) * 3);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    color: var(--gray-800);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    text-decoration: none;
    transition: border-color 0.15s, background-color 0.15s;
}

.erp-module-page:hover {
    border-color: var(--primary-300);
    background-color: var(--primary-50);
    color: var(--primary-800);
}

.erp-module-page:focus-visible {
    outline: 2px solid var(--primary-600);
    outline-offset: 2px;
}

.erp-module-page-icon {
    display: inline-flex;
    flex-shrink: 0;
    color: var(--primary-600);
}

.erp-module-page-icon svg {
    width: 1.25rem;
    height: 1.25rem;
}

.erp-module-page-label {
    flex: 1;
}

.erp-module-page-badge {
    padding: 0 calc(var(--spacing) * 2);
    border-radius: 9999px;
    background-color: var(--primary-100);
    color: var(--primary-800);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-semibold);
}

/* ---------------------------------------------------------------- chart of accounts as a tree */

.erp-tree-cell {
    padding-inline-start: calc(var(--erp-tree-depth, 0) * 1.5rem);
}

/* Rows under a folded parent (tree-toggle-script). */
.erp-tree-folded {
    display: none;
}

/* The fold arrow of a parent row: 24 px target; points sideways when folded. */
.erp-tree-toggle,
.erp-tree-spacer {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    margin-inline-end: calc(var(--spacing) * 1);
    vertical-align: middle;
}

.erp-tree-toggle {
    border-radius: var(--radius-md);
    color: var(--gray-500);
    cursor: pointer;
    transition: transform 0.15s, background-color 0.15s;
}

.erp-tree-toggle:hover {
    background-color: var(--gray-100);
    color: var(--primary-700);
}

.erp-tree-toggle:focus-visible {
    outline: 2px solid var(--primary-600);
    outline-offset: 1px;
}

.erp-tree-toggle svg {
    width: 1rem;
    height: 1rem;
}

.erp-tree-toggle[aria-expanded="false"] {
    transform: rotate(-90deg);
}

[dir="rtl"] .erp-tree-toggle[aria-expanded="false"] {
    transform: rotate(90deg);
}

/* ---------------------------------------------------------------- module menu (topbar) and sidebar title */

.erp-module-switcher-btn {
    display: inline-flex;
    align-items: center;
    gap: calc(var(--spacing) * 2);
    min-height: 2.25rem;
    margin-inline-start: calc(var(--spacing) * 3);
    padding: calc(var(--spacing) * 1) calc(var(--spacing) * 3);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    background-color: var(--color-white);
    color: var(--gray-800);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
    cursor: pointer;
}

.erp-module-switcher-btn:hover {
    border-color: var(--primary-300);
    background-color: var(--primary-50);
}

.erp-module-switcher-btn:focus-visible {
    outline: 2px solid var(--primary-600);
    outline-offset: 2px;
}

.erp-module-switcher-icon,
.erp-module-switcher-chevron {
    display: inline-flex;
    color: var(--primary-600);
}

.erp-module-switcher-icon svg {
    width: 1.25rem;
    height: 1.25rem;
}

.erp-module-switcher-chevron svg {
    width: 1rem;
    height: 1rem;
    color: var(--gray-500);
}

/*
 * Two copies of the module menu: beside the logo from 64rem (where Filament shows the logo area),
 * in the topbar end below it. Phones show the icon and the arrow only (the name is in the menu).
 */
@media (min-width: 64rem) {
    .erp-module-switcher-phone {
        display: none;
    }
}

@media (max-width: 63.99rem) {
    .erp-module-switcher-wide {
        display: none;
    }

    .erp-module-switcher-phone .erp-module-switcher-btn {
        margin-inline-start: 0;
    }
}

@media (max-width: 40rem) {
    .erp-module-switcher-label {
        display: none;
    }
}

.erp-sidebar-module {
    display: grid;
    gap: calc(var(--spacing) * 1.5);
    margin-bottom: calc(var(--spacing) * 3);
    padding-bottom: calc(var(--spacing) * 3);
    border-bottom: 1px solid var(--gray-200);
}

.erp-sidebar-module-title {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing) * 2.5);
    color: var(--gray-950);
    font-size: var(--text-base);
    font-weight: var(--font-weight-bold);
    text-decoration: none;
}

.erp-sidebar-module-back {
    display: inline-flex;
    align-items: center;
    gap: calc(var(--spacing) * 1.5);
    min-height: 1.5rem;
    color: var(--primary-700);
    font-size: var(--text-xs);
    font-weight: var(--font-weight-semibold);
    text-decoration: none;
}

.erp-sidebar-module-back svg {
    width: 1rem;
    height: 1rem;
}

.erp-sidebar-module-back:hover,
.erp-sidebar-module-title:hover {
    text-decoration: underline;
}

/* ---------------------------------------------------------------- BOM multi-level structure */

.erp-bom-structure-note {
    margin-bottom: calc(var(--spacing) * 3);
    color: var(--gray-600);
    font-size: var(--text-sm);
}

.erp-bom-structure-scroll {
    overflow-x: auto;
}

.erp-bom-structure table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.erp-bom-structure th,
.erp-bom-structure td {
    padding: calc(var(--spacing) * 2) calc(var(--spacing) * 3);
    border-bottom: 1px solid var(--gray-200);
    text-align: start;
}

.erp-bom-structure thead th {
    background-color: var(--gray-50);
    font-weight: var(--font-weight-semibold);
    white-space: nowrap;
}

.erp-bom-structure .erp-num {
    text-align: end;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.erp-bom-structure td.erp-tree-cell {
    padding-inline-start: calc(var(--spacing) * 3 + var(--erp-tree-depth, 0) * 1.5rem);
}

.erp-bom-level-1 .erp-bom-name {
    font-weight: var(--font-weight-semibold);
}

.erp-bom-code {
    margin-inline-start: calc(var(--spacing) * 2);
    color: var(--gray-500);
    font-size: var(--text-xs);
}

.erp-bom-tag {
    display: inline-block;
    margin-inline-start: calc(var(--spacing) * 2);
    padding: 0 calc(var(--spacing) * 2);
    border-radius: 9999px;
    background-color: var(--primary-50);
    color: var(--primary-800);
    font-size: var(--text-xs);
}

.erp-bom-tag-warning {
    background-color: var(--warning-50);
    color: var(--warning-800);
}

.erp-bom-structure tfoot th {
    text-align: end;
}

/* Sidebar links: a visible keyboard focus ring (ERP audit F-516; Filament only tints the background, 1.05:1). */
.fi-sidebar-item-btn:focus-visible,
.fi-sidebar-group-btn:focus-visible {
    outline: 2px solid var(--primary-700);
    outline-offset: -2px;
}
.dark .fi-sidebar-item-btn:focus-visible,
.dark .fi-sidebar-group-btn:focus-visible {
    outline-color: var(--primary-400);
}

/* ---------------------------------------------------------------- accessibility (always) */

/* Placeholder text at least 4.5:1 on a white field (Filament's gray-400 gives 2.6:1, ERP audit F-390). */
.fi-input::placeholder,
.fi-select-input-placeholder,
.fi-ta-search-field input::placeholder {
    color: var(--gray-500);
}
.dark .fi-input::placeholder,
.dark .fi-select-input-placeholder,
.dark .fi-ta-search-field input::placeholder {
    color: var(--gray-400);
}

/* 24 x 24 px targets (2.5.8): the clear button of a select keeps its 16 px cross inside a 24 px
   target, and small icon buttons beside fields (Create, Balance line...) are never below 24 px (ERP audit F-520). */
.fi-select-input .fi-select-input-value-remove-btn {
    width: 1.5rem;
    height: 1.5rem;
    mask-size: 1rem 1rem;
    -webkit-mask-size: 1rem 1rem;
}
.fi-fo-field-label-ctn .fi-icon-btn,
.fi-fo-field-wrp-hint .fi-icon-btn,
.fi-input-wrp-actions .fi-icon-btn,
.fi-input-wrp-prefix .fi-icon-btn,
.fi-input-wrp-suffix .fi-icon-btn {
    min-width: 1.5rem;
    min-height: 1.5rem;
}

/* The language switch in the topbar (.fi-ls-trigger, checked on demo-jo: it was 20 px): its trigger asks for w-9 h-9, classes the panel stylesheet
   does not build, so it shrank to the 20 px letter. A 36 px target like the user menu (ERP audit F-401). */
.language-switch-trigger,
.fi-ls-trigger {
    min-width: 2.25rem;
    min-height: 2.25rem;
    justify-content: center;
}

/*
 * Journal entry lines: the Foreign debit / credit columns of an entry in the base currency.
 * Filament marks their header and cells fi-hidden, which this theme does not otherwise hide;
 * only this table, where header and cells are always hidden together, so columns stay aligned.
 */
.fi-fo-table-repeater.erp-journal-lines th.fi-hidden,
.fi-fo-table-repeater.erp-journal-lines td.fi-hidden {
    display: none;
}
