/* Shared layout primitives. Theme colors and business components stay in their existing stylesheets. */
:root { --erp-control-height: 42px; --erp-label-height: 32px; --erp-field-gap: 16px; }

/* Equal-width cards, with an incomplete row centered instead of an empty trailing column. */
.erp-summary-grid { --summary-columns: 4; display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; margin-bottom: 24px; }
.erp-summary-five { --summary-columns: 3; }
.erp-summary-grid > :is(.kpi-card, .metric) { flex: 0 0 calc((100% - (var(--summary-columns) - 1) * 16px) / var(--summary-columns)); min-width: 0; min-height: 180px; padding: 18px; display: flex; flex-direction: column; justify-content: space-between; gap: 16px; }
.erp-summary-grid .kpi-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin: 0; }
.erp-summary-grid :is(.kpi-label, .metric-label) { min-width: 0; line-height: 1.5; }
.erp-summary-grid .kpi-icon { flex-shrink: 0; }
.erp-summary-grid :is(.kpi-value, .metric-value) { margin: 0; font-size: clamp(20px, 1.65vw, 26px); line-height: 1.25; overflow-wrap: anywhere; }
@media (min-width: 1600px) { .erp-summary-five { --summary-columns: 5; } }
@media (max-width: 991px) { .erp-summary-grid { --summary-columns: 2; } }
@media (max-width: 479px) { .erp-summary-grid { --summary-columns: 1; } }

/* Every grid row includes its helpers and errors, so the next row starts after the tallest group. */
.erp-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--erp-field-gap); margin: 0; }
.erp-form-grid > * { width: auto; min-width: 0; margin: 0; padding: 0; }
.erp-form-grid > .col-12:not(.col-lg-6), .erp-form-grid > .erp-field-wide { grid-column: 1 / -1; }
.erp-field { min-width: 0; }
.erp-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: var(--erp-label-height); margin-bottom: 6px; }
.erp-label-row .form-label { margin: 0; min-width: 0; line-height: 1.4; }
.erp-label-row .btn { flex-shrink: 0; min-height: 28px; padding-block: 3px; font-size: 12px; }
.erp-field :is(.form-control, .form-select) { min-height: var(--erp-control-height); }
.erp-field :is(.form-text, .invalid-feedback) { margin: 6px 0 0; line-height: 1.45; overflow-wrap: anywhere; }
.erp-field :is(.form-text, .invalid-feedback):empty { display: none; }
.erp-switch-control { display: flex; align-items: center; gap: 10px; min-height: var(--erp-control-height); padding: 8px 12px; margin: 0; border: 1px solid var(--erp-border); border-radius: 10px; }
.erp-switch-control .form-check-input { float: none; flex-shrink: 0; margin: 0; }
.erp-switch-control .form-check-label { margin: 0; }
.erp-money-control { display: grid; grid-template-columns: minmax(0, 1fr) 7rem; gap: 8px; }
.erp-money-control > * { min-width: 0; }
.erp-money-single { grid-template-columns: minmax(0, 1fr); }
.supplier-benefit-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 20px; margin-block: 16px 0; }
.supplier-benefit-summary > div { display: grid; align-content: start; gap: 5px; min-width: 0; }
.supplier-benefit-summary .benefit-label { font-size: 12px; }
.supplier-benefit-summary .benefit-value { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.erp-form-grid ~ .form-actions, .supplier-benefit-summary + .form-actions { margin-top: 18px; padding-top: 18px; }
@media (max-width: 767px) {
    .erp-form-grid, .supplier-benefit-summary { grid-template-columns: minmax(0, 1fr); }
    .erp-switch-heading { display: none; }
}

/* Fields wrap as complete groups; actions align with controls without an empty label row. */
.erp-filter-grid { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.erp-filter-grid > div { flex: 1 1 14rem; min-width: 0; }
.erp-filter-grid > div > .form-label, .erp-filter-grid > .erp-field > .erp-label-row { display: flex; align-items: center; min-height: var(--erp-label-height); margin: 0 0 6px; }
.erp-filter-grid :is(.form-control, .form-select, .btn) { min-height: var(--erp-control-height); }
.erp-filter-grid > .erp-filter-actions { flex: 1 1 auto; }
.erp-filter-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.erp-filter-actions .btn { flex: 1 1 auto; white-space: nowrap; }
@media (max-width: 575px) { .erp-filter-grid > div, .erp-filter-grid > .erp-filter-actions { flex-basis: 100%; } }

/* Keep header/body edges identical; wide data scrolls within its existing responsive wrapper. */
.data-table :is(th, td) { padding-inline: 14px; vertical-align: middle; }
.data-table :is(th.text-right, th.numeric, td.amount-cell, td.numeric) { text-align: right; font-variant-numeric: tabular-nums; }
.data-table :is(td.amount-cell, td.numeric) { white-space: nowrap; }
.data-table :is(th.action-cell, td.action-cell) { text-align: right; white-space: nowrap; }
.data-table td.action-cell .btn { vertical-align: middle; }
.table-responsive { min-width: 0; overscroll-behavior-inline: contain; }

/* Notification bell in the top bar */
.notification-button { position: relative; }
.notification-button.is-warning { color: var(--erp-warning); }
.notification-button.is-danger { color: var(--erp-danger); }
.notification-badge { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--erp-warning); color: #fff; font-size: 11px; font-weight: 800; line-height: 18px; text-align: center; box-shadow: 0 0 0 2px var(--erp-card-bg, #fff); }
.notification-button.is-danger .notification-badge { background: var(--erp-danger); }
.notification-dropdown { width: min(380px, calc(100vw - 28px)); max-height: min(70vh, 520px); overflow-y: auto; padding: 0; }
.notification-dropdown-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--erp-border); }
.notification-dropdown-header span { font-size: 12px; font-weight: 700; color: var(--erp-muted); }
.notification-group { padding: 10px 16px 12px; }
.notification-group + .notification-group { border-top: 1px solid var(--erp-border); }
.notification-group h3 { margin: 0 0 8px; font-size: 11px; font-weight: 750; letter-spacing: .04em; text-transform: uppercase; color: var(--erp-muted); }
.notification-group ul { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.notification-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-left: 10px; border-left: 3px solid var(--erp-warning); }
.notification-item.is-danger { border-left-color: var(--erp-danger); }
.notification-item > a:first-child { display: flex; flex-direction: column; min-width: 0; color: var(--erp-text); font-size: 13px; line-height: 1.3; text-decoration: none; }
.notification-item > a:first-child:hover strong { text-decoration: underline; }
.notification-item span { font-size: 12px; font-weight: 700; color: var(--erp-warning); }
.notification-item.is-danger span { color: var(--erp-danger); }
.notification-item .btn { flex: 0 0 auto; }
.notification-empty { margin: 0; padding: 18px 16px; color: var(--erp-muted); font-size: 13px; }
.notification-button.is-warning .bi { color: var(--erp-warning); }
.notification-button.is-danger .bi { color: var(--erp-danger); }
/* The search toggle and close button exist only for the phone layout below. */
.topbar-search-toggle, .topbar-search-close { display: none; }
/* Phones: one row (menu, search, then quick create, bell and user on the right); the search opens over the bar. */
@media (max-width: 767.98px) {
    /* Clip sideways only, so the bell and user menus can open below the bar. */
    .topbar { position: sticky; flex-direction: row; align-items: center; gap: 8px; padding: 10px 14px; overflow: visible; overflow-x: clip; }
    .topbar-left { display: flex; align-items: center; gap: 8px; width: auto; max-width: none; }
    .topbar-search-toggle { display: inline-grid; place-items: center; }
    .topbar-search { display: none; }
    .topbar.is-searching .topbar-search { position: absolute; inset: 8px 14px; z-index: 20; display: flex; align-items: center; width: auto; }
    .topbar.is-searching .topbar-actions, .topbar.is-searching .topbar-left > .icon-button { visibility: hidden; }
    .topbar.is-searching .topbar-search-input { flex: 1 1 auto; padding-right: 44px; }
    .topbar.is-searching .topbar-search-close { position: absolute; right: 4px; display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--erp-muted); }
    .topbar-actions { width: auto; max-width: none; margin-left: auto; gap: 8px; justify-content: flex-end; }
    .topbar-actions .dropdown:last-child, .topbar-actions .notification-menu { position: relative; top: auto; right: auto; }
}

/* Sidebar groups that fold on their title. */
.sidebar-home { margin-top: 12px; }
.sidebar-group > summary.sidebar-section { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 2px; border-radius: 6px; cursor: pointer; list-style: none; user-select: none; }
.sidebar-group > summary.sidebar-section::-webkit-details-marker { display: none; }
.sidebar-group > summary.sidebar-section::after { content: ""; width: 7px; height: 7px; margin-right: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform 0.15s ease; opacity: 0.7; }
.sidebar-group:not([open]) > summary.sidebar-section::after { transform: rotate(-45deg); }
.sidebar-group > summary.sidebar-section:hover { color: var(--erp-text); }
.sidebar-group > summary.sidebar-section:focus-visible { outline: 2px solid var(--erp-primary, #3B82F6); outline-offset: 2px; }

/* The menu folds to an icon strip with the round arrow on its edge; the choice is remembered per browser. */
.sidebar-toggle { position: absolute; top: 26px; right: -12px; z-index: 2; display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 1px solid var(--erp-border); border-radius: 50%; background: var(--erp-card-bg); color: var(--erp-muted); box-shadow: var(--erp-shadow-sm); cursor: pointer; transition: color 0.15s ease, border-color 0.15s ease, transform 0.18s ease; }
.sidebar-toggle:hover { border-color: var(--erp-primary); color: var(--erp-primary); }
.sidebar-toggle:focus-visible { outline: 2px solid var(--erp-primary); outline-offset: 2px; }
.sidebar-toggle i { font-size: 12px; line-height: 1; }
/* Only the click animates; a window resize or page load moves nothing. */
html.sidebar-animating :is(.app-main, .app-sidebar) { transition: margin-left 0.18s ease, width 0.18s ease; }
@media (min-width: 992px) {
    html.sidebar-collapsed { --erp-sidebar-width: 72px; }
    html.sidebar-collapsed .sidebar-toggle { transform: rotate(180deg); }
    html.sidebar-collapsed .app-sidebar .sidebar-inner { padding-inline: 14px; }
    html.sidebar-collapsed .app-sidebar .sidebar-brand { justify-content: center; padding-inline: 0; }
    html.sidebar-collapsed .app-sidebar :is(.brand-text, .sidebar-link span) { display: none; }
    html.sidebar-collapsed .app-sidebar .sidebar-link { justify-content: center; padding-inline: 0; }
    html.sidebar-collapsed .app-sidebar .sidebar-link.active::before { left: -14px; }
    /* A group title becomes a short line; it still folds the group. */
    html.sidebar-collapsed .app-sidebar .sidebar-group > summary.sidebar-section { justify-content: center; height: 17px; margin: 8px 0 4px; padding: 0; font-size: 0; }
    html.sidebar-collapsed .app-sidebar .sidebar-group > summary.sidebar-section::after { width: 20px; height: 0; margin: 0; border: 0; border-top: 1px solid var(--erp-border); transform: none; opacity: 1; }
}

/* Date fields: a text field for ДД.ММ.ГГГГ with a calendar button; the native date input sits invisibly under the button. */
.date-field { position: relative; display: block; min-width: 0; }
.date-field > input[type="text"] { padding-right: 42px; font-variant-numeric: tabular-nums; }
.date-field-button { position: absolute; top: 50%; right: 4px; z-index: 2; display: grid; place-items: center; width: 34px; height: 30px; padding: 0; border: 0; border-radius: 6px; background: transparent; color: var(--erp-muted); transform: translateY(-50%); cursor: pointer; }
.date-field-button:hover:not(:disabled) { background: color-mix(in srgb, var(--erp-primary) 12%, transparent); color: var(--erp-primary); }
.date-field-button:disabled { cursor: default; opacity: 0.5; }
.date-field > .date-field-native { position: absolute; top: 50%; right: 4px; z-index: 1; width: 34px !important; min-width: 0 !important; height: 30px; padding: 0 !important; border: 0 !important; opacity: 0; pointer-events: none; transform: translateY(-50%); }
.input-group > .date-field { flex: 1 1 auto; width: 1%; }
.input-group > .date-field > input[type="text"] { border-top-right-radius: 0; border-bottom-right-radius: 0; }
/* The calendar: Bulgarian, Monday first, in the ERP's colours. */
.date-calendar { position: absolute; top: calc(100% + 4px); right: 0; z-index: 1060; width: 284px; padding: 12px; border: 1px solid var(--erp-border); border-radius: var(--erp-radius); background: var(--erp-card-bg); box-shadow: var(--erp-shadow); color: var(--erp-text); }
.date-field.opens-up > .date-calendar { top: auto; bottom: calc(100% + 4px); }
.date-field.opens-left > .date-calendar { right: auto; left: 0; }
.date-calendar-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 8px; }
.date-calendar-head strong { font-size: 14px; font-weight: 700; text-transform: capitalize; }
.date-calendar button { border: 0; background: transparent; color: inherit; font: inherit; cursor: pointer; }
.date-calendar-nav { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; color: var(--erp-muted) !important; }
.date-calendar-nav:hover { background: var(--erp-surface-subtle, #F3F4F6); color: var(--erp-text) !important; }
.date-calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.date-calendar-grid > span { padding: 4px 0; color: var(--erp-muted); font-size: 11.5px; font-weight: 700; text-align: center; }
.date-calendar-day { height: 34px; border-radius: 8px; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.date-calendar-day:hover:not(:disabled) { background: color-mix(in srgb, var(--erp-primary) 12%, transparent); }
.date-calendar-day.is-other { color: var(--erp-muted) !important; opacity: .55; }
.date-calendar-day.is-today { box-shadow: inset 0 0 0 1px var(--erp-primary); color: var(--erp-primary) !important; font-weight: 700; }
.date-calendar-day.is-selected { background: var(--erp-primary) !important; color: #FFFFFF !important; font-weight: 700; }
.date-calendar-day:disabled { opacity: .3; cursor: default; }
.date-calendar-day:focus-visible, .date-calendar-nav:focus-visible { outline: 2px solid var(--erp-primary); outline-offset: 1px; }
.date-calendar-foot { display: flex; justify-content: space-between; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--erp-soft-border); }
.date-calendar-foot button { padding: 4px 8px; border-radius: 6px; color: var(--erp-primary) !important; font-size: 13px; font-weight: 600; }
.date-calendar-foot button:hover { background: color-mix(in srgb, var(--erp-primary) 10%, transparent); }
.searchable-select { position: relative; display: block; min-width: 0; }
.searchable-select > .searchable-input { cursor: pointer; text-overflow: ellipsis; }
.searchable-select.is-open > .searchable-input { cursor: text; }
/* The native select keeps its box (so forms, tests and labels still find it) but paints nothing over the field. */
.searchable-select > .searchable-native { position: absolute; inset: 0; z-index: 0; width: 100% !important; height: 100%; opacity: 0; pointer-events: none; clip-path: inset(50%); }
.searchable-list { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 1060; max-height: min(340px, 60vh); overflow-y: auto; padding: 6px; border: 1px solid var(--erp-border); border-radius: var(--erp-radius); background: var(--erp-card-bg); box-shadow: var(--erp-shadow); overscroll-behavior: contain; }
.searchable-select.opens-up > .searchable-list { top: auto; bottom: calc(100% + 4px); }
.searchable-group { position: sticky; top: -6px; z-index: 1; margin: 4px -6px 0; padding: 6px 12px 4px; background: var(--erp-card-bg); color: var(--erp-muted); font-size: 11px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.searchable-group:first-child { margin-top: -6px; padding-top: 10px; }
.searchable-option { padding: 8px 10px; border-radius: 8px; color: var(--erp-text); cursor: pointer; overflow-wrap: anywhere; }
.searchable-option.is-empty { color: var(--erp-muted); }
.searchable-option.is-create { color: var(--erp-primary); font-weight: 700; }
.searchable-option[aria-selected="true"] { font-weight: 700; }
.searchable-option.is-active, .searchable-option:hover { background: color-mix(in srgb, var(--erp-primary) 12%, transparent); }
.searchable-none { padding: 10px; color: var(--erp-muted); }
/* A short list opens on a click and is not typed into. */
.searchable-select > .searchable-input { transition: none; }
.searchable-select.is-plain > .searchable-input { caret-color: transparent; user-select: none; cursor: pointer; }
/* An inline select keeps sizing itself by its options: it stays in the flow under the visible field. */
.searchable-select.is-inline { display: inline-grid; vertical-align: middle; }
.searchable-select.is-inline > .searchable-native { position: static; grid-area: 1 / 1; width: auto !important; height: auto; }
.searchable-select.is-inline > .searchable-input { grid-area: 1 / 1; width: 100%; }
@media (max-width: 575.98px) { .searchable-option { padding: 11px 10px; } }

/* Compact forms: twelve columns where each field says how wide it is, and a fold for the rarely needed fields. */
.erp-form-grid.erp-grid-12 { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.erp-grid-12 > [hidden] { display: none !important; }
.erp-grid-12 > .span-2 { grid-column: span 2; } .erp-grid-12 > .span-3 { grid-column: span 3; } .erp-grid-12 > .span-4 { grid-column: span 4; }
.erp-grid-12 > .span-5 { grid-column: span 5; } .erp-grid-12 > .span-6 { grid-column: span 6; } .erp-grid-12 > .span-7 { grid-column: span 7; }
.erp-grid-12 > .span-8 { grid-column: span 8; } .erp-grid-12 > .span-9 { grid-column: span 9; }
.erp-grid-12 > .span-12 { grid-column: 1 / -1; }
.erp-grid-12 textarea.form-control { min-height: 0; }
.erp-form-hint { margin: 8px 0 0; font-size: 13px; color: var(--erp-muted); }
.erp-form-part { margin: 22px 0 10px; font-size: 14px; font-weight: 700; }
.erp-more { margin-top: 20px; padding: 10px 14px; border: 1px dashed var(--erp-border); border-radius: var(--erp-radius); }
.erp-more > summary { cursor: pointer; font-weight: 600; color: var(--erp-muted); }
.erp-more[open] > summary { margin-bottom: 8px; }
@media (max-width: 991px) {
    .erp-grid-12 > :is(.span-2, .span-3, .span-4, .span-5) { grid-column: span 6; }
    .erp-grid-12 > :is(.span-6, .span-7, .span-8, .span-9) { grid-column: 1 / -1; }
}
@media (max-width: 767px) {
    .erp-form-grid.erp-grid-12 { grid-template-columns: minmax(0, 1fr); }
    .erp-grid-12 > [class*="span-"] { grid-column: 1 / -1; }
}
