/* ==========================================================================
   Components. Every value comes from tokens.css.
   ========================================================================== */

/* ---- Buttons --------------------------------------------------------------- */
.m-btn {
  --_bg: var(--surface); --_fg: var(--text); --_bd: var(--border-strong); --_bg-h: var(--surface-hover);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--ctl-h); padding-inline: var(--ctl-px);
  font: inherit; font-weight: var(--fw-medium); line-height: 1; white-space: nowrap;
  color: var(--_fg); background: var(--_bg); border: 1px solid var(--_bd); border-radius: var(--r-md);
  cursor: pointer; user-select: none; position: relative;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}
.m-btn:hover { background: var(--_bg-h); color: var(--_fg); text-decoration: none; }
.m-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }
.m-btn i { font-size: 1em; }
.m-btn--primary { --_bg: var(--accent); --_fg: var(--accent-contrast); --_bd: var(--accent); --_bg-h: var(--accent-hover); }
.m-btn--primary:hover { border-color: var(--accent-hover); }
.m-btn--danger { --_bg: var(--danger-solid); --_fg: #fff; --_bd: var(--danger-solid); --_bg-h: color-mix(in srgb, var(--danger-solid) 88%, #000); }   /* solid fill: white text keeps 4.5:1 in both themes (--danger itself is a text colour) */
.m-btn--ghost { --_bg: transparent; --_bd: transparent; --_fg: var(--text-muted); }
.m-btn--ghost:hover { --_fg: var(--text); }
.m-btn--subtle { --_bg: var(--accent-soft); --_bd: transparent; --_fg: var(--accent-text); --_bg-h: var(--accent-soft-strong); }
.m-btn--sm { height: var(--ctl-h-sm); padding-inline: 0.5rem; font-size: var(--fs-xs); }
.m-btn--lg { height: var(--ctl-h-lg); padding-inline: 1rem; font-size: var(--fs-md); }
.m-btn--block { width: 100%; }
.m-btn--icon { width: var(--ctl-h); padding: 0; }
.m-btn--icon.m-btn--sm { width: var(--ctl-h-sm); }
.m-btn:disabled, .m-btn.disabled, .m-btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; pointer-events: none; }
.m-btn.is-loading { pointer-events: none; color: transparent !important; }
.m-btn.is-loading > * { visibility: hidden; }
.m-btn.is-loading::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--_fg_spin, var(--text-muted)); border-inline-end-color: transparent;
  animation: m-spin .6s linear infinite;
}
.m-btn--primary.is-loading, .m-btn--danger.is-loading { --_fg_spin: #fff; }
.m-btn--primary.is-loading { --_fg_spin: var(--accent-contrast); }
@keyframes m-spin { to { transform: rotate(360deg); } }

/* ---- Fields & inputs ------------------------------------------------------- */
.m-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.m-field__label { font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--text); display: flex; gap: 4px; align-items: baseline; }
.m-field__req { color: var(--danger); }
.m-field__opt { color: var(--text-faint); font-weight: var(--fw-regular); }
.m-field__hint { font-size: var(--fs-xs); color: var(--text-faint); }
.m-field__error { font-size: var(--fs-xs); color: var(--danger); display: flex; gap: 4px; align-items: flex-start; }
.m-field__error:empty { display: none; }

.m-input, .m-select, .m-textarea {
  width: 100%; height: var(--ctl-h); padding-inline: var(--ctl-px);
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
  appearance: none; -webkit-appearance: none;
}
.m-input::placeholder, .m-textarea::placeholder { color: var(--text-faint); }
.m-input:hover:not(:disabled):not(:read-only), .m-select:hover:not(:disabled), .m-textarea:hover:not(:disabled):not(:read-only) { border-color: var(--text-faint); }
.m-input:focus, .m-select:focus, .m-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.m-textarea { height: auto; min-height: 72px; padding-block: 6px; resize: vertical; }
.m-select {
  padding-inline-end: 26px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none' stroke='%238a93a3' stroke-width='1.6'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center;
}
[dir="rtl"] .m-select { background-position: left 9px center; }
.m-input[type="date"], .m-input[type="time"] { min-width: 0; }
.m-input[type="color"] { padding: 2px; cursor: pointer; width: var(--ctl-h-lg); }
.m-input[type="file"] { padding-block: 0; line-height: calc(var(--ctl-h) - 2px); }
.m-input[type="file"]::file-selector-button { margin-inline-end: var(--sp-2); border: 0; background: var(--surface-hover); color: var(--text); height: calc(var(--ctl-h) - 4px); padding-inline: var(--sp-2); border-radius: var(--r-sm); font: inherit; cursor: pointer; }
.m-input:disabled, .m-select:disabled, .m-textarea:disabled { background: var(--surface-hover); color: var(--text-faint); cursor: not-allowed; }
.m-input:read-only:not(:disabled), .m-textarea:read-only:not(:disabled) { background: var(--surface-2); border-style: dashed; }
.is-invalid.m-input, .is-invalid.m-select, .is-invalid.m-textarea { border-color: var(--danger); }
.is-invalid.m-input:focus, .is-invalid.m-select:focus, .is-invalid.m-textarea:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 30%, transparent); }

.m-input-group { display: flex; align-items: stretch; }
.m-input-group > .m-input { flex: 1; min-width: 0; }
.m-input-group__addon { display: inline-flex; align-items: center; padding-inline: var(--sp-2); background: var(--surface-hover); border: 1px solid var(--border-strong); color: var(--text-muted); font-size: var(--fs-xs); }
.m-input-group__addon:first-child { border-start-start-radius: var(--r-md); border-end-start-radius: var(--r-md); border-inline-end: 0; }
.m-input-group__addon:last-child { border-start-end-radius: var(--r-md); border-end-end-radius: var(--r-md); border-inline-start: 0; }
.m-input-group > .m-input:not(:first-child) { border-start-start-radius: 0; border-end-start-radius: 0; }
.m-input-group > .m-input:not(:last-child) { border-start-end-radius: 0; border-end-end-radius: 0; }

/* checkbox / radio */
.m-check { display: inline-flex; align-items: flex-start; gap: var(--sp-2); cursor: pointer; line-height: 1.35; }
.m-check input { appearance: none; -webkit-appearance: none; flex: none; width: 16px; height: 16px; margin: 1px 0 0; background: var(--surface); border: 1px solid var(--border-strong); cursor: pointer; display: inline-grid; place-content: center; transition: background var(--t-fast), border-color var(--t-fast); }
.m-check input[type="checkbox"] { border-radius: var(--r-sm); }
.m-check input[type="radio"] { border-radius: 50%; }
.m-check input::after { content: ""; width: 8px; height: 8px; transform: scale(0); transition: transform var(--t-fast); }
.m-check input[type="checkbox"]::after { clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0, 43% 62%); background: var(--accent-contrast); }
.m-check input[type="radio"]::after { border-radius: 50%; background: var(--accent-contrast); width: 6px; height: 6px; }
.m-check input:checked { background: var(--accent); border-color: var(--accent); }
.m-check input:checked::after { transform: scale(1); }
.m-check input:focus-visible { box-shadow: 0 0 0 3px var(--focus-ring); outline: none; }
.m-check input:disabled { opacity: .5; cursor: not-allowed; }
.m-check input:disabled + span { color: var(--text-faint); }
.m-check__text small { display: block; color: var(--text-faint); font-size: var(--fs-xs); }
.m-choices { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); }

/* segmented / chip choices (theme, density) */
.m-segment { display: inline-flex; padding: 2px; gap: 2px; background: var(--surface-hover); border-radius: var(--r-md); }
.m-segment label { margin: 0; }
.m-segment input { position: absolute; opacity: 0; pointer-events: none; }
.m-segment span, .m-segment a, .m-segment button {
  display: inline-flex; align-items: center; gap: 6px; height: calc(var(--ctl-h) - 6px); padding-inline: var(--sp-3);
  border-radius: var(--r-sm); color: var(--text-muted); font-weight: var(--fw-medium); cursor: pointer; border: 0; background: transparent; font: inherit; font-weight: var(--fw-medium);
}
.m-segment a:hover { text-decoration: none; color: var(--text); }
.m-segment input:checked + span, .m-segment .active { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); }
.m-segment input:focus-visible + span { box-shadow: 0 0 0 3px var(--focus-ring); }

.swatches { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.swatch input { position: absolute; opacity: 0; }
.swatch span { display: block; width: 22px; height: 22px; border-radius: 50%; background: var(--c); cursor: pointer; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .12); }
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c); }
.swatch input:focus-visible + span { outline: 2px solid var(--text); outline-offset: 3px; }

/* ---- Search field ---------------------------------------------------------- */
.m-search { position: relative; min-width: 0; }
.m-search i { position: absolute; inset-inline-start: 9px; inset-block-start: 50%; transform: translateY(-50%); color: var(--text-faint); font-size: .8rem; pointer-events: none; }
.m-search .m-input { padding-inline-start: 28px; }

/* ---- Badges ---------------------------------------------------------------- */
.m-badge {
  --_c: var(--text-muted); --_bg: var(--neutral-soft);
  display: inline-flex; align-items: center; gap: 5px; height: 20px; padding-inline: 7px;
  border-radius: var(--r-pill); background: var(--_bg); color: var(--_c);
  font-size: var(--fs-xs); font-weight: var(--fw-medium); line-height: 1; white-space: nowrap;
}
.m-badge--success { --_c: var(--success); --_bg: var(--success-soft); }
.m-badge--warning { --_c: var(--warning); --_bg: var(--warning-soft); }
.m-badge--danger { --_c: var(--danger); --_bg: var(--danger-soft); }
.m-badge--info { --_c: var(--info); --_bg: var(--info-soft); }
.m-badge--accent { --_c: var(--accent-text); --_bg: var(--accent-soft); }
.m-badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.m-badge--sample { border: 1px dashed currentColor; background: transparent; }

/* ---- Card ------------------------------------------------------------------ */
.m-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-card); min-width: 0; }
.m-card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-1) var(--sp-3); min-height: 36px; border-block-end: 1px solid var(--border); }
.m-card__title { font-size: var(--fs-sm); font-weight: var(--fw-semibold); margin: 0; display: flex; align-items: center; gap: var(--sp-2); }
.m-card__body { padding: var(--card-pad); }
.m-card__body--flush { padding: 0; }
.m-card__foot { padding: var(--sp-2) var(--sp-3); border-block-start: 1px solid var(--border); background: var(--surface-2); border-end-start-radius: inherit; border-end-end-radius: inherit; display: flex; gap: var(--sp-2); justify-content: flex-end; align-items: center; }
.m-card--sample { border-style: dashed; border-color: var(--border-strong); }

/* ---- Metric card ----------------------------------------------------------- */
.m-metric { padding: var(--sp-2) var(--sp-3); display: flex; flex-direction: column; gap: 1px; min-height: 0; }
.m-metric__label { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); color: var(--text-muted); font-size: var(--fs-xs); font-weight: var(--fw-medium); }
.m-metric__label i { color: var(--text-faint); }
.m-metric__value { font-size: var(--fs-xl); font-weight: var(--fw-semibold); line-height: 1.25; letter-spacing: var(--ls-title); font-variant-numeric: tabular-nums; }
.m-metric__amt { white-space: nowrap; }
.m-metric__value.is-empty { color: var(--text-faint); }
.m-metric__hint { font-size: var(--fs-2xs); color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-metric__hint:empty { display: none; }
.m-metric__trend--up { color: var(--success); } .m-metric__trend--down { color: var(--danger); }

/* ---- Alert ----------------------------------------------------------------- */
.m-alert { --_c: var(--info); --_bg: var(--info-soft); display: flex; gap: var(--sp-2); align-items: flex-start; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md); background: var(--_bg); border: 1px solid color-mix(in srgb, var(--_c) 25%, transparent); color: var(--text); }
.m-alert > i { color: var(--_c); margin-top: 2px; }
.m-alert--success { --_c: var(--success); --_bg: var(--success-soft); }
.m-alert--warning { --_c: var(--warning); --_bg: var(--warning-soft); }
.m-alert--danger { --_c: var(--danger); --_bg: var(--danger-soft); }
.m-alert__body { flex: 1; min-width: 0; }

/* ---- Tables ---------------------------------------------------------------- */
.m-table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; min-width: 0; }
.m-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.m-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.m-table th, .m-table td { padding: var(--cell-py) var(--cell-px); text-align: start; vertical-align: middle; border-block-end: 1px solid var(--border); }
.m-table td { height: var(--row-h); }
.m-table thead th { background: var(--surface-2); color: var(--text-muted); font-size: var(--fs-xs); font-weight: var(--fw-semibold); text-transform: none; white-space: nowrap; height: var(--th-h); position: sticky; inset-block-start: 0; }
.m-table tbody tr:last-child td { border-block-end: 0; }
.m-table tbody tr { transition: background var(--t-fast); }
.m-table tbody tr:hover { background: var(--surface-hover); }
.m-table-wrap[data-row-link] tbody tr:not(.m-table-empty) { cursor: pointer; }
.m-table tbody tr.is-selected { background: var(--accent-soft); }
.m-table .col-check { width: 36px; padding-inline-end: 0; }
.m-table .col-actions { width: 1%; white-space: nowrap; text-align: end; }
.m-table .col-num, .m-table th.col-num { text-align: end; font-variant-numeric: tabular-nums; }
.m-table .row-actions { opacity: 0; transition: opacity var(--t-fast); display: inline-flex; gap: 2px; }
.m-table tr:hover .row-actions, .m-table tr:focus-within .row-actions { opacity: 1; }
@media (hover: none) { .m-table .row-actions { opacity: 1; } }
.th-sort { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.th-sort:hover { color: var(--text); text-decoration: none; }
.th-sort i { font-size: .7rem; opacity: .35; } .th-sort.is-active i { opacity: 1; color: var(--accent-text); }

.m-bulkbar { display: none; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--cell-px); background: var(--accent-soft); border-block-end: 1px solid var(--border); font-weight: var(--fw-medium); }
.m-table-wrap.has-selection .m-bulkbar { display: flex; }
.m-table-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-1) var(--cell-px); min-height: 34px; border-block-start: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); font-size: var(--fs-xs); }
.m-table-wrap.is-loading { position: relative; }
.m-table-wrap.is-loading::after { content: ""; position: absolute; inset: 0; background: color-mix(in srgb, var(--surface) 70%, transparent); }

/* stacked (card) layout on small screens: <td data-label="…"> */
@media (max-width: 767.98px) {
  .m-table--stack { min-width: 0 !important; }
  .m-table--stack thead { display: none; }
  .m-table--stack, .m-table--stack tbody, .m-table--stack tr, .m-table--stack td { display: block; width: 100%; }
  .m-table--stack tr { padding: var(--sp-2) var(--cell-px); border-block-end: 1px solid var(--border); }
  .m-table--stack tbody tr:last-child { border-block-end: 0; }
  .m-table--stack td { display: flex; justify-content: space-between; gap: var(--sp-3); height: auto; border: 0; padding: 3px 0; text-align: end; }
  .m-table--stack td::before { content: attr(data-label); color: var(--text-faint); font-size: var(--fs-xs); text-align: start; flex: none; }
  .m-table--stack td:not([data-label])::before { content: none; }
  .m-table--stack td.col-check, .m-table--stack td.col-actions { width: auto; }
  .m-table--stack .row-actions { opacity: 1; }
}

/* ---- Pagination ------------------------------------------------------------ */
.m-pagination { display: inline-flex; gap: 2px; list-style: none; margin: 0; padding: 0; align-items: center; }
.m-pagination a, .m-pagination span.m-page {
  min-width: var(--ctl-h-sm); height: var(--ctl-h-sm); padding-inline: 6px; display: inline-grid; place-items: center;
  border-radius: var(--r-md); color: var(--text-muted); font-size: var(--fs-xs); font-weight: var(--fw-medium);
}
.m-pagination a:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.m-pagination .active span.m-page { background: var(--accent); color: var(--accent-contrast); }
.m-pagination .disabled span.m-page { opacity: .4; }

/* ---- Tabs ------------------------------------------------------------------ */
.m-tabs { display: flex; gap: var(--sp-1); border-block-end: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; margin-block-end: var(--gap-section); }
.m-tabs::-webkit-scrollbar { display: none; }
.m-tab { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tab-h); padding: 0 var(--sp-3); color: var(--text-muted); font-weight: var(--fw-medium); background: none; border: 0; border-block-end: 2px solid transparent; margin-block-end: -1px; white-space: nowrap; cursor: pointer; font: inherit; font-weight: var(--fw-medium); }
.m-tab:hover { color: var(--text); text-decoration: none; }
.m-tab.active { color: var(--accent-text); border-block-end-color: var(--accent); }
.m-tab .m-badge { height: 17px; padding-inline: 5px; }

/* ---- Dropdown menus (Bootstrap dropdown, restyled) ------------------------- */
.dropdown-menu {
  --bs-dropdown-bg: var(--surface); --bs-dropdown-border-color: transparent; --bs-dropdown-border-radius: var(--r-lg);
  --bs-dropdown-color: var(--text); --bs-dropdown-link-color: var(--text);
  --bs-dropdown-link-hover-bg: var(--surface-hover); --bs-dropdown-link-hover-color: var(--text);
  --bs-dropdown-link-active-bg: var(--accent-soft); --bs-dropdown-link-active-color: var(--accent-text);
  --bs-dropdown-padding-y: 4px; --bs-dropdown-padding-x: 4px; --bs-dropdown-font-size: var(--fs-sm); --bs-dropdown-min-width: 11rem;
  --bs-dropdown-divider-bg: var(--border); --bs-dropdown-divider-margin-y: 4px;
  box-shadow: var(--sh-menu); border: 0;
}
.dropdown-item { display: flex; align-items: center; gap: var(--sp-2); padding: 6px var(--sp-2); border-radius: var(--r-md); font-weight: var(--fw-regular); width: 100%; background: none; border: 0; text-align: start; }
.dropdown-item i { color: var(--text-faint); width: 1em; text-align: center; }
.dropdown-item.active i, .dropdown-item.is-danger i { color: inherit; }
.dropdown-item.is-danger { color: var(--danger); }
.dropdown-item.disabled, .dropdown-item:disabled { color: var(--text-faint); opacity: .7; pointer-events: none; }
.dropdown-item .m-badge { margin-inline-start: auto; }
.dropdown-header { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint); padding: 6px var(--sp-2) 2px; }
.dropdown-divider { border-color: var(--border); opacity: 1; }
.dropdown-menu .check { margin-inline-start: auto; color: var(--accent-text); }
.menu-panel { width: 320px; max-width: calc(100vw - 16px); }

/* ---- Modal & drawer (Bootstrap, restyled) ---------------------------------- */
.modal { --bs-modal-bg: var(--surface); --bs-modal-border-width: 0; --bs-modal-border-radius: var(--r-lg); --bs-modal-padding: 0; --bs-modal-margin: 0.75rem; --bs-modal-box-shadow: var(--sh-modal); --bs-backdrop-bg: #000; --bs-backdrop-opacity: .5; --bs-modal-width: var(--modal-w); }
.modal-content { background: var(--surface); color: var(--text); border: 1px solid var(--border); max-height: calc(100vh - 1.5rem); }
.m-modal__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); min-height: 44px; border-block-end: 1px solid var(--border); }
.m-modal__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); margin: 0; }
.m-modal__body { padding: var(--card-pad-lg); overflow-y: auto; }
.m-modal__foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border-block-start: 1px solid var(--border); background: var(--surface-2); border-end-start-radius: inherit; border-end-end-radius: inherit; }
.modal-dialog-scrollable .modal-content { overflow: hidden; }
.modal-backdrop { --bs-backdrop-zindex: 1990; }
.modal { z-index: var(--z-modal); }
.confirm-icon { width: 34px; height: 34px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--danger-soft); color: var(--danger); flex: none; font-size: 1rem; }
.confirm-icon.is-primary { background: var(--accent-soft); color: var(--accent-text); }

.offcanvas { --bs-offcanvas-bg: var(--surface); --bs-offcanvas-color: var(--text); --bs-offcanvas-width: 420px; --bs-offcanvas-border-width: 1px; --bs-offcanvas-border-color: var(--border); --bs-offcanvas-padding-x: 0; --bs-offcanvas-padding-y: 0; --bs-offcanvas-box-shadow: var(--sh-modal); --bs-offcanvas-zindex: 2000; max-width: 100vw; }
.offcanvas-backdrop { --bs-backdrop-zindex: 1990; }
.offcanvas-body { padding: var(--sp-4); }
.offcanvas.m-drawer { display: flex; flex-direction: column; }

/* ---- Document header (contacts, projects, invoices, bills, expenses, payments, accounts…): avatar, title and its facts on one line, actions at the end ---- */
.ct-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-1) var(--sp-3); margin-block-end: var(--gap-section); }
.ct-header__id { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; flex: 1 1 auto; }
.ct-header__id > .min-w-0 { display: flex; flex-wrap: wrap; align-items: center; gap: 2px var(--sp-3); }
.ct-header__id h1 { overflow-wrap: anywhere; letter-spacing: var(--ls-title); }
.ct-header__id .m-avatar { width: 32px; height: 32px; font-size: var(--fs-sm); border-radius: var(--r-md); }
.ct-header__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px var(--sp-2); color: var(--text-muted); font-size: var(--fs-sm); }

/* ---- Empty / loading ------------------------------------------------------- */
.m-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; padding: var(--sp-5) var(--sp-4); color: var(--text-muted); }
.m-empty--compact { padding: var(--sp-4) var(--sp-3); }
.m-empty__icon { width: 28px; height: 28px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--neutral-soft); color: var(--text-faint); font-size: .95rem; margin-block-end: 2px; }
.m-empty__title { font-weight: var(--fw-semibold); color: var(--text); font-size: var(--fs-sm); }
.m-empty__text { max-width: 36ch; font-size: var(--fs-xs); color: var(--text-muted); margin: 0; }
.m-empty__action { margin-block-start: var(--sp-2); }

.m-spinner { display: inline-block; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-inline-end-color: var(--accent); animation: m-spin .7s linear infinite; vertical-align: -3px; }
.m-loading { display: flex; align-items: center; justify-content: center; gap: var(--sp-2); padding: var(--sp-5); color: var(--text-muted); }
.m-skeleton { display: block; height: 10px; border-radius: var(--r-sm); background: linear-gradient(90deg, var(--surface-hover) 25%, var(--surface-active) 37%, var(--surface-hover) 63%); background-size: 400% 100%; animation: m-shimmer 1.4s ease infinite; margin-block: 8px; }
@keyframes m-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---- Toasts ---------------------------------------------------------------- */
.m-toasts { position: fixed; inset-block-end: var(--sp-4); inset-inline-end: var(--sp-4); z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--sp-2); width: 340px; max-width: calc(100vw - 2 * var(--sp-3)); pointer-events: none; }
.m-toast { --_c: var(--info); pointer-events: auto; display: flex; gap: var(--sp-2); align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-inline-start: 3px solid var(--_c); border-radius: var(--r-md); box-shadow: var(--sh-menu); padding: var(--sp-2) var(--sp-3); animation: m-toast-in var(--t-base); }
.m-toast > i { color: var(--_c); margin-top: 2px; }
.m-toast--success { --_c: var(--success); } .m-toast--danger { --_c: var(--danger); } .m-toast--warning { --_c: var(--warning); }
.m-toast__body { flex: 1; min-width: 0; word-break: break-word; }
.m-toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity var(--t-base), transform var(--t-base); }
@keyframes m-toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (max-width: 575.98px) { .m-toasts { inset-inline: var(--sp-3); width: auto; inset-block-end: var(--sp-3); } }

/* ---- Filters & view switcher ---------------------------------------------- */
.m-filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.m-filters .m-search { flex: 1 1 200px; max-width: 320px; }
.m-filters .m-select { width: auto; min-width: 120px; }
.m-chips { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.m-chip { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding-inline: 8px 4px; border-radius: var(--r-pill); background: var(--accent-soft); color: var(--accent-text); font-size: var(--fs-xs); font-weight: var(--fw-medium); }
.m-chip a, .m-chip button { color: inherit; display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; border: 0; background: transparent; font-size: .65rem; }
.m-chip a:hover { background: var(--accent-soft-strong); text-decoration: none; }

/* ---- Lists ----------------------------------------------------------------- */
.m-list { list-style: none; margin: 0; padding: 0; }
.m-list__item { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); border-block-end: 1px solid var(--border); min-height: var(--row-h); }
.m-list__item:last-child { border-block-end: 0; }
.m-list__icon { width: 26px; height: 26px; border-radius: var(--r-md); background: var(--neutral-soft); color: var(--text-muted); display: grid; place-items: center; flex: none; }
.m-list__main { flex: 1; min-width: 0; }
.m-list__main small { display: block; color: var(--text-faint); font-size: var(--fs-xs); }

/* quick actions */
.m-actions-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); }
.m-action { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md); color: var(--text); background: var(--surface); font-weight: var(--fw-medium); min-height: var(--ctl-h-lg); }
.m-action i { color: var(--accent-text); }
a.m-action:hover { background: var(--surface-hover); text-decoration: none; color: var(--text); }
.m-action.is-disabled { color: var(--text-faint); background: var(--surface-2); cursor: not-allowed; }
.m-action.is-disabled i { color: var(--text-faint); }

/* mini bar chart (SVG-free, token-coloured) */
.m-bars { display: flex; align-items: flex-end; gap: var(--sp-2); height: 96px; padding: var(--sp-2) 0 0; }
.m-bars__col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; }
.m-bars__pair { display: flex; align-items: flex-end; gap: 2px; width: 100%; height: calc(100% - 16px); justify-content: center; }
.m-bars__bar { width: 38%; max-width: 14px; border-radius: 2px 2px 0 0; background: var(--accent); min-height: 2px; }
.m-bars__bar--b { background: var(--border-strong); }
.m-bars__lbl { font-size: var(--fs-2xs); color: var(--text-faint); line-height: 1; }
.m-hbar { display: grid; grid-template-columns: 84px 1fr auto; gap: var(--sp-2); align-items: center; padding-block: 3px; }
.m-hbar__track { height: 6px; background: var(--neutral-soft); border-radius: var(--r-pill); overflow: hidden; }
.m-hbar__fill { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.m-legend { display: flex; gap: var(--sp-3); font-size: var(--fs-xs); color: var(--text-muted); }
.m-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--accent); margin-inline-end: 4px; }
.m-legend i.b { background: var(--border-strong); }

.sample-banner { display: flex; gap: var(--sp-2); align-items: center; justify-content: space-between; flex-wrap: wrap; }

/* UI kit helpers */
.kit-section { margin-block-end: var(--sp-6); }
.kit-section > h2 { margin-block-end: var(--sp-3); }
.kit-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.token-swatch { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); }
.token-swatch i { width: 22px; height: 22px; border-radius: var(--r-sm); background: var(--c); box-shadow: inset 0 0 0 1px rgb(0 0 0 / .12); flex: none; }

/* ---- Avatar, definition list, collapsible section, lookup (shared) ---------- */
.m-avatar { display: inline-grid; place-items: center; flex: none; border-radius: 50%; background: var(--accent-soft-strong); color: var(--accent-text); font-weight: var(--fw-semibold); text-transform: uppercase; }
.m-avatar--sm { width: 24px; height: 24px; font-size: var(--fs-2xs); }
.m-avatar--md { width: 30px; height: 30px; font-size: var(--fs-xs); }
.m-avatar--lg { width: 44px; height: 44px; font-size: var(--fs-lg); }
.m-avatar--square { border-radius: var(--r-lg); }

.m-dl { display: grid; grid-template-columns: minmax(96px, 150px) 1fr; gap: 6px var(--sp-3); margin: 0; }
.m-dl dt { color: var(--text-muted); font-weight: var(--fw-regular); font-size: var(--fs-xs); padding-block-start: 1px; }
.m-dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 575.98px) { .m-dl { grid-template-columns: 1fr; gap: 0; } .m-dl dt { margin-block-start: 6px; } }

.m-details { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); }
.m-details > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-4); font-weight: var(--fw-semibold); border-radius: inherit; }
.m-details > summary::-webkit-details-marker { display: none; }
.m-details > summary:hover { background: var(--surface-hover); }
.m-details > summary small { color: var(--text-faint); font-weight: var(--fw-regular); margin-inline-start: var(--sp-1); }
.m-details__chev { font-size: .7rem; color: var(--text-faint); transition: transform var(--t-fast); }
.m-details[open] > summary { border-end-start-radius: 0; border-end-end-radius: 0; border-block-end: 1px solid var(--border); }
.m-details[open] > summary .m-details__chev { transform: rotate(90deg); }
[dir="rtl"] .m-details[open] > summary .m-details__chev { transform: scaleX(-1) rotate(90deg); }
.m-details__body { padding: var(--sp-3) var(--sp-4) var(--sp-4); }

.m-lookup { position: relative; }
.m-lookup__icon { position: absolute; inset-inline-start: 9px; inset-block-start: 50%; transform: translateY(-50%); color: var(--text-faint); font-size: .8rem; pointer-events: none; }
.m-lookup .m-input { padding-inline: 28px 30px; }
.m-lookup__clear { position: absolute; inset-inline-end: 2px; inset-block-start: 2px; width: calc(var(--ctl-h) - 4px); height: calc(var(--ctl-h) - 4px); font-size: .7rem; }
.m-lookup.is-linked .m-input { background: var(--accent-soft); border-color: var(--accent); }
.m-lookup-wrap { display: flex; align-items: center; gap: var(--sp-1); }
.m-lookup-wrap > .m-lookup { flex: 1 1 auto; min-width: 0; }
.m-lookup__open { flex: none; width: var(--ctl-h); height: var(--ctl-h); border: 1px solid var(--border); border-radius: var(--r-md); color: var(--accent-text); text-decoration: none; }
.m-lookup__open:hover { background: var(--accent-soft); }
[dir="rtl"] .m-lookup__open .bi { transform: scaleX(-1); }
/* The menu is one shared element attached to <body> (position: fixed by JS) so no overflow:hidden parent, modal or drawer clips it. */
.m-lookup__menu { position: fixed; z-index: var(--z-lookup); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-menu); max-height: 300px; overflow-y: auto; padding: var(--sp-1); }
.m-lookup__menu[hidden] { display: none; }
.m-lookup__item { display: flex; align-items: center; gap: var(--sp-2); width: 100%; padding: 6px var(--sp-2); border: 0; background: none; border-radius: var(--r-md); text-align: start; color: var(--text); font: inherit; cursor: pointer; }
.m-lookup__item:hover, .m-lookup__item.is-active { background: var(--surface-hover); }
.m-lookup__item small { color: var(--text-faint); margin-inline-start: auto; max-width: 45%; }
.m-lookup__item--create { color: var(--accent-text); font-weight: var(--fw-medium); }
.m-lookup__item--create .bi { flex: none; }
.m-lookup__sep { height: 1px; background: var(--border); margin: var(--sp-1) 0; }
.m-lookup__empty { padding: var(--sp-2) var(--sp-3); color: var(--text-muted); font-size: var(--fs-xs); }
.m-lookup__empty .spinner-border { width: .8rem; height: .8rem; border-width: .15em; margin-inline-end: var(--sp-2); }

/* "Create and Edit": the module's own create form in a dialog (lightweight so it also works over Bootstrap modals/drawers). */
.m-lkdlg { position: fixed; inset: 0; z-index: var(--z-toast); display: flex; align-items: flex-start; justify-content: center; padding: var(--sp-5) var(--sp-3); overflow-y: auto; background: rgba(0, 0, 0, .45); }
.m-lkdlg__panel { background: var(--surface); color: var(--text); border-radius: var(--r-lg); box-shadow: var(--sh-menu); width: min(720px, 100%); margin-block: auto; }
.m-lkdlg__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-block-end: 1px solid var(--border); }
.m-lkdlg__head h2 { margin: 0; font-size: var(--fs-md, 1rem); font-weight: var(--fw-semi, 600); }
.m-lkdlg__body { padding: var(--sp-4); }
.m-lkdlg__body .form-narrow { max-width: none; }
.m-lkdlg__loading { padding: var(--sp-5); text-align: center; color: var(--text-muted); }

/* ---- Shared overlays (drawer / modal loaded by AJAX) and region refresh states ---------------------------------------- */
.m-overlay .breadcrumbs, .m-overlay nav[aria-label] > .breadcrumbs, .m-overlay .page-header, .m-overlay > .offcanvas-body > .breadcrumbs { display: none; }
.m-overlay [data-overlay-body] form { max-width: none; }
.m-overlay [data-overlay-body] .m-card { border: 0; box-shadow: none; background: transparent; }
.m-overlay [data-overlay-body] .m-card__head { padding-inline: 0; }
.m-overlay [data-overlay-body] .m-card__body { padding-inline: 0; }
.m-overlay [data-overlay-body] .form-actions { position: sticky; inset-block-end: 0; background: var(--surface); padding-block: var(--sp-2); margin-block-start: var(--sp-2); border-block-start: 1px solid var(--border); }
[data-region] { transition: opacity var(--t-fast); }
[data-region].is-loading { opacity: .55; pointer-events: none; }

/* Settings: launcher background preview (shares .has-bg rules with the real page, see layout.css) */
.lb-stage { border: 1px solid var(--border); border-radius: var(--r-lg); min-height: 190px; display: grid; place-items: center; padding: var(--sp-4); overflow: hidden; background: var(--bg); }
.lb-stage__grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--sp-2); width: 100%; max-width: 520px; }
.lb-stage__tile { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: var(--fs-2xs); text-align: center; }
.lb-stage__tile .app-tile__icon { width: 34px; height: 34px; font-size: 1rem; border-radius: 10px; }
.lb-stage__empty { position: absolute; inset-block-end: 6px; inset-inline-start: 10px; font-size: var(--fs-xs); color: var(--text-faint); }
.lb-stage.has-bg .lb-stage__tile { text-shadow: 0 0 6px var(--bg); }
@media (max-width: 575.98px) { .lb-stage__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } .lb-stage { min-height: 220px; } }

/* ---- State ribbon: a diagonal tag across the top corner of the card it belongs to (Web only; PDFs print a stamp instead) ---------------------------- */
.m-ribbon-host { position: relative; border-radius: var(--r-lg); overflow: hidden; }
.m-ribbon { --_rb: #6b7280; --_rf: #fff; position: absolute; top: 0; inset-inline-end: 0; width: 76px; height: 76px; overflow: hidden; pointer-events: none; z-index: 3; }
.m-ribbon__tag { position: absolute; top: 15px; inset-inline-end: -33px; width: 112px; padding: 2px 0; text-align: center; transform: rotate(45deg); background: var(--_rb); color: var(--_rf);
  font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; line-height: 1.5; white-space: nowrap; box-shadow: 0 1px 3px rgba(0, 0, 0, .28); }
[dir="rtl"] .m-ribbon__tag { transform: rotate(-45deg); }
.m-ribbon-host .m-table th:last-child, .m-ribbon-host .m-table td:last-child { padding-inline-end: 2rem; }   /* the corner mark never sits on a figure */
.m-ribbon--paid { --_rb: #15803d; }
.m-ribbon--partial { --_rb: #b45309; }
.m-ribbon--overdue { --_rb: #b91c1c; }
.m-ribbon--draft { --_rb: #6b7280; }
.m-ribbon--voided { --_rb: #374151; }
:root[data-theme="dark"] .m-ribbon--draft { --_rb: #6b7280; }
:root[data-theme="dark"] .m-ribbon--voided { --_rb: #4b5563; }
:root[data-theme="dark"] .m-ribbon__tag { box-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
@media print { .m-ribbon { display: none; } }   /* the printed copy is the PDF, with its own stamp */

/* Picker: "Add “typed text”" row at the end of a select's search results */
.m-cs__create { color: var(--accent); font-weight: var(--fw-semibold); }
.m-cs__create .bi { margin-inline-end: 6px; }

/* Selectable lists (checkbox per row, "select all", bulk bar) and compact one-line rows */
.sel-check { width: 18px; height: 18px; margin: 0; cursor: pointer; flex: none; }
.sel-bar { display: inline-flex; align-items: center; gap: var(--sp-2); margin: 0; }
.sel-bar[hidden] { display: none; }
.sel-bar__count { font-size: var(--fs-sm); color: var(--text-muted); }
.sel-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); border-block-end: 1px solid var(--border); min-height: 40px; }
.m-list--compact .m-list__item { min-height: 44px; padding-block: 4px; }

/* Empty states: centred in the free space with a round icon, title and hint (compact ones stay small) */
.m-empty:not(.m-empty--compact) { min-height: 300px; justify-content: center; gap: 6px; padding: var(--sp-6) var(--sp-4); }
.m-empty:not(.m-empty--compact) .m-empty__icon { width: 64px; height: 64px; border-radius: 50%; font-size: 1.6rem; margin-block-end: 8px; color: var(--text-muted); }
.m-empty:not(.m-empty--compact) .m-empty__title { font-size: var(--fs-md, 1rem); }
.m-empty:not(.m-empty--compact) .m-empty__text { font-size: var(--fs-sm); max-width: 42ch; }
.m-empty:not(.m-empty--compact) .m-empty__action { margin-block-start: var(--sp-3); }

/* ---- Records: bulk bar, selection, report, import wizard (shared by every manageable list) ---- */
.m-bulkbar { flex-wrap: wrap; }
.m-bulkbar .d-flex { flex-wrap: wrap; }
.rec-banner { flex-basis: 100%; font-weight: var(--fw-regular, 400); font-size: var(--fs-xs); color: var(--text-muted); order: 9; }
.rec-link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: var(--fw-medium); cursor: pointer; text-decoration: underline; }
.m-table .col-check { width: 36px; padding-inline-end: 0; }
.m-table tr.is-selected > td { background: var(--accent-soft); }
.m-table td.col-actions, .m-table th.col-actions { width: 1%; white-space: nowrap; text-align: end; }
.row-actions { display: inline-flex; gap: 2px; align-items: center; justify-content: flex-end; }
.row-actions form { display: inline; margin: 0; }
.row-actions .icon-btn { width: 28px; height: 28px; }
.rec-cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: var(--sp-1) var(--sp-3); }
.rec-report { border: 1px solid var(--border); border-inline-start: 3px solid var(--success); background: var(--surface); border-radius: var(--r-md); padding: var(--sp-2) var(--sp-3); margin-block-end: var(--sp-3); display: grid; gap: var(--sp-1); }
.rec-report.has-failed { border-inline-start-color: var(--warning); }
.rec-report__head { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-2); }
.rec-report__list { margin: 0; padding-inline-start: 1.1rem; font-size: var(--fs-sm); max-height: 12rem; overflow: auto; }
.rec-steps { display: flex; flex-wrap: wrap; gap: var(--sp-2); list-style: none; padding: 0; margin: 0 0 var(--sp-3); font-size: var(--fs-sm); color: var(--text-muted); }
.rec-steps li { display: inline-flex; align-items: center; gap: 6px; }
.rec-steps li > span { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border-strong); font-size: 11px; }
.rec-steps li.is-on { color: var(--text); font-weight: var(--fw-medium); }
.rec-steps li.is-on > span { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.rec-steps li.is-done > span { background: var(--success); border-color: var(--success); color: #fff; }
.rec-fields { columns: 2 14rem; margin: 0; padding-inline-start: 1.1rem; font-size: var(--fs-sm); }
.m-modal__body legend, [data-overlay-body] legend, .rec-form legend { float: none; width: auto; padding: 0; margin: 0 0 var(--sp-1); font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); }
[data-overlay-body] fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
/* Phones: the stacked list keeps a "select all on this page" row (the header's checkbox) so a whole page can be ticked without a table header */
@media (max-width: 767.98px) {
  .m-table--stack thead:has([data-select-all]) { display: block; }
  .m-table--stack thead:has([data-select-all]) tr { display: flex; padding: var(--sp-2) var(--cell-px); border-block-end: 1px solid var(--border); background: var(--surface-2); }
  .m-table--stack thead:has([data-select-all]) th { display: none; }
  .m-table--stack thead:has([data-select-all]) th.col-check { display: block; width: auto; padding: 0; }
  .m-table--stack thead:has([data-select-all]) th.col-check::after { content: attr(data-all-label); margin-inline-start: var(--sp-2); color: var(--text-muted); font-size: var(--fs-xs); }
}
