/* Shared shell and form components (loaded last), rebuilt on the EMI business portal pattern with Daftar's teal:
   1 accessibility, 2 side menu, 3 control panel, 4 fields, 5 searchable select, 6 checkbox and switch,
   7 filter bar, 8 list tables, 9 line tables, 10 toasts and dialogs, 11 empty states, 12 phones and touch.
   Uses tokens.css only (no raw colours), logical properties for RTL, z-index and motion from tokens. */

/* ======================================================================
   1. Accessibility helpers
   ====================================================================== */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:where(a, button, input, select, textarea, [tabindex]):focus-visible { outline: none; box-shadow: var(--focus-ring); }
#view:focus { outline: none; }
button[aria-busy="true"] { cursor: progress; position: relative; }
button[aria-busy="true"]::after { content: ""; width: 12px; height: 12px; margin-inline-start: var(--space-2); display: inline-block; vertical-align: -2px;
  border: 2px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* "Skip to content" (M16): hidden until it gets keyboard focus, then the first thing on screen. */
.skip-link { position: fixed; inset-inline-start: var(--space-3); top: var(--space-2); z-index: var(--z-skip); transform: translateY(-200%);
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-md); background: var(--color-primary); color: var(--color-text-on-primary);
  font-weight: var(--weight-semibold); transition: transform var(--motion-fast) var(--ease); }
.skip-link:focus, .skip-link:focus-visible { transform: none; color: var(--color-text-on-primary); }

/* ======================================================================
   2. Side menu (shell/sidenav.js): frame, app header, sections, rows, children, edge toggle, rail, drawer
   ====================================================================== */
:root { --sb-w: var(--sidenav-width); }
@media (min-width: 901px) { :root[data-sidebar="collapsed"] { --sb-w: var(--sidenav-width-collapsed); } }

#sidebar { position: sticky; top: 0; z-index: var(--z-sidenav); flex: none; display: flex; flex-direction: column;
  width: var(--sb-w); min-width: var(--sb-w); height: 100vh; height: 100dvh;
  background: var(--sidebar); border-inline-end: 1px solid var(--color-border); transition: width var(--motion-base) var(--ease); }
#sidebar .sb-head { position: relative; flex: none; display: flex; align-items: center; height: var(--navbar-height); padding-inline: var(--space-4);
  border-bottom: 1px solid var(--color-border); overflow: hidden; }
#sidebar .brand .logo { width: 30px; height: 30px; }
#sb-backdrop { display: none; }
/* The menu column keeps its colour down the whole page (the menu itself is sticky, one screen high). */
@media (min-width: 901px) {
  #app { background-image: linear-gradient(to right, var(--sidebar) calc(var(--sb-w) - 1px), var(--color-border) calc(var(--sb-w) - 1px), var(--color-border) var(--sb-w), transparent var(--sb-w)); }
  :root[dir="rtl"] #app { background-image: linear-gradient(to left, var(--sidebar) calc(var(--sb-w) - 1px), var(--color-border) calc(var(--sb-w) - 1px), var(--color-border) var(--sb-w), transparent var(--sb-w)); }
}
/* Desktop: the edge toggle (#sb-collapse) is the only collapse control; the hamburger opens the phone drawer. */
@media (min-width: 901px) { #menu-toggle { display: none; } }

/* App header row: the current app, and "switch app" (opens the apps screen) */
#sidebar .sb-app { flex: none; display: flex; align-items: center; gap: 10px; height: 48px; margin: var(--space-2) var(--space-3) var(--space-1);
  padding-inline: 10px; border-radius: var(--sidenav-item-radius); color: var(--color-text); text-decoration: none;
  transition: background-color var(--motion-fast) var(--ease); }
#sidebar .sb-app:hover { background: var(--color-hover-wash); color: var(--color-text); }
#sidebar .sb-app:focus-visible { box-shadow: var(--focus-ring); }
#sidebar .sb-app-ic { flex: none; display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: var(--radius-md);
  background: var(--color-primary-subtle); color: var(--color-primary-text); }
#sidebar .sb-app-ic svg { width: var(--sidenav-icon-size); height: var(--sidenav-icon-size); fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }
#sidebar .sb-app-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
#sidebar .sb-app-kicker { font-size: var(--text-2xs); font-weight: var(--weight-medium); color: var(--color-text-muted); }
#sidebar .sb-app-name { font-size: var(--text-md); font-weight: var(--weight-bold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#sidebar .sb-app-switch { margin-inline-start: auto; flex: none; color: var(--color-text-muted); }
#sidebar .sb-app-switch svg { width: 16px; height: 16px; fill: currentColor; display: block; }
#sidebar .sb-app:hover .sb-app-switch { color: var(--color-text); }

/* The list. Rows never shrink, however many are open (H1). */
#nav { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 2px;
  padding: var(--space-1) var(--space-3) var(--space-3); scrollbar-width: thin; scrollbar-color: var(--color-border) transparent; }
#nav > *, #nav .sb-sec > *, #nav .dropdown > * { flex-shrink: 0; }
#nav .sb-sec { display: flex; flex-direction: column; gap: 2px; }
#nav .sb-section { padding: var(--space-4) 14px 6px; font-size: var(--text-2xs); line-height: 1; font-weight: var(--weight-bold);
  letter-spacing: .1em; text-transform: uppercase; color: var(--color-text-faint); user-select: none; }
#nav .sb-sec:first-child .sb-section { padding-top: var(--space-2); }

/* Level-1 row: a link (.nav-top) or a group button (.menu > button) */
#nav .nav-top, #nav .menu > button { position: relative; display: flex; align-items: center; gap: 11px; width: 100%;
  height: var(--sidenav-item-height); min-height: 0; padding: 0 var(--space-3); border: 0; border-radius: var(--sidenav-item-radius);
  background: transparent; color: var(--sidebar-text); font: inherit; font-size: var(--text-nav); font-weight: var(--weight-semibold); line-height: 1;
  text-align: start; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background-color var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease); }
#nav .sb-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; }
#nav .nav-ic { flex: 0 0 var(--sidenav-icon-box); width: var(--sidenav-icon-box); height: var(--sidenav-icon-box);
  display: inline-flex; align-items: center; justify-content: center; color: var(--color-text-muted); }
#nav .nav-ic svg, #menu-toggle svg, #sb-collapse svg { width: var(--sidenav-icon-size); height: var(--sidenav-icon-size);
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }
#nav .nav-top:hover, #nav .menu > button:hover { background: var(--color-hover-wash); color: var(--color-text); }
#nav .nav-top:hover .nav-ic, #nav .menu > button:hover .nav-ic { color: var(--sidebar-text); }
#nav .nav-top:focus-visible, #nav .menu > button:focus-visible { box-shadow: var(--focus-ring); border-radius: var(--sidenav-item-radius); }

/* Active: the page's own link, or the group that holds it. Pill + bar + brand text. */
#nav .nav-top.active, #nav .menu.active > button { background: var(--color-primary-subtle); color: var(--color-primary-text); font-weight: var(--weight-bold); }
#nav .nav-top.active .nav-ic, #nav .menu.active > button .nav-ic { color: var(--color-primary-text); }
#nav .nav-top.active::before, #nav .menu.active > button::before { content: ""; position: absolute; inset-inline-start: 0; top: 50%;
  width: var(--sidenav-indicator-width); height: var(--sidenav-indicator-height); transform: translateY(-50%); background: var(--color-primary);
  border-start-end-radius: 3px; border-end-end-radius: 3px; }

/* Group chevron: down when closed, up when open */
#nav .chev { flex: none; margin-inline-start: auto; margin-inline-end: var(--space-1); width: 7px; height: 7px; margin-top: -4px;
  border-inline-end: 1.8px solid currentColor; border-bottom: 1.8px solid currentColor; color: var(--color-text-faint);
  transform: rotate(45deg); transition: transform var(--motion-fast) var(--ease); }
:root[dir="rtl"] #nav .chev { transform: rotate(-45deg); }
#nav .menu.expanded > button .chev { transform: rotate(225deg); margin-top: 3px; }
#nav .menu.active > button .chev { color: var(--color-primary-text); }

/* Level-2 children: open in place, one group at a time, under a thin guide line */
#nav .dropdown { display: none; position: relative; flex-direction: column; gap: 2px; margin: 0; padding-block: 2px var(--space-1);
  padding-inline: var(--sidenav-children-indent) 0; border: 0; }
#nav .menu.expanded > .dropdown { display: flex; }
#nav .dropdown::before { content: ""; position: absolute; inset-inline-start: var(--sidenav-guide-inset); top: 6px; bottom: 6px;
  width: 1.5px; border-radius: var(--radius-pill); background: var(--color-border); }
#nav .dropdown .flyout-title { display: none; }
#nav .dropdown a { position: relative; display: flex; align-items: center; height: var(--sidenav-child-height); padding: 0 var(--space-3); margin: 0;
  border-radius: var(--sidenav-child-radius); color: var(--sidebar-text); font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: 1.4;
  white-space: nowrap; text-decoration: none; background: transparent;
  transition: background-color var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease); }
#nav .dropdown a .sb-child-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#nav .dropdown a:hover { background: var(--color-hover-wash); color: var(--color-text); }
#nav .dropdown a:focus-visible { box-shadow: var(--focus-ring); border-radius: var(--sidenav-child-radius); }
#nav .dropdown a.active { color: var(--color-primary-text); font-weight: var(--weight-semibold); }
#nav .dropdown a.active::before { content: ""; position: absolute; inset-inline-start: calc(var(--sidenav-guide-inset) - var(--sidenav-children-indent) - .25px);
  top: 8px; bottom: 8px; width: 2px; border-radius: var(--radius-pill); background: var(--color-primary); }

/* Edge toggle: a 32px circle half over the menu border, centred on the head's bottom line */
#sb-collapse { position: absolute; inset-inline-start: 100%; top: calc(var(--navbar-height) - var(--sidenav-toggle-size) / 2); transform: translateX(-50%);
  z-index: 1; display: inline-grid; place-items: center; width: var(--sidenav-toggle-size); height: var(--sidenav-toggle-size); min-height: 0;
  margin: 0; padding: 0; border: 1px solid var(--color-border); border-radius: var(--radius-pill); background: var(--color-surface); color: var(--color-text);
  box-shadow: var(--shadow-raised); transition: background-color var(--motion-fast) var(--ease); }
#sb-collapse .sb-label { display: none; }
#sb-collapse svg { width: 12px; height: 12px; stroke-width: 2.25; transition: transform var(--motion-base) var(--ease); }
#sb-collapse:hover { background: var(--color-surface-2); border-color: var(--color-border); color: var(--color-text); }
#sb-collapse:focus-visible { box-shadow: var(--focus-ring); border-radius: var(--radius-pill); }
:root[dir="rtl"] #sb-collapse { transform: translateX(50%); }
:root[dir="rtl"] #sb-collapse svg { transform: scaleX(-1); }

/* Collapsed rail (desktop): 42px icon squares, a tooltip, groups open a flyout beside the rail */
@media (min-width: 901px) {
  :root[data-sidebar="collapsed"] #sidebar .sb-label, :root[data-sidebar="collapsed"] #nav .chev,
  :root[data-sidebar="collapsed"] #sidebar .sb-app-text, :root[data-sidebar="collapsed"] #sidebar .sb-app-switch { display: none; }
  :root[data-sidebar="collapsed"] #sidebar .sb-head { justify-content: center; padding: 0; }
  :root[data-sidebar="collapsed"] #sb-collapse svg { transform: rotate(180deg); }
  :root[data-sidebar="collapsed"][dir="rtl"] #sb-collapse svg { transform: scaleX(-1) rotate(180deg); }
  :root[data-sidebar="collapsed"] #sidebar .sb-app { justify-content: center; width: var(--sidenav-item-height); margin-inline: auto; padding: 0; }
  :root[data-sidebar="collapsed"] #nav { padding: var(--space-1) 0 var(--space-3); align-items: center; }
  :root[data-sidebar="collapsed"] #nav .sb-sec { align-items: center; }
  :root[data-sidebar="collapsed"] #nav .sb-section { width: 24px; height: 1px; padding: 0; margin: 10px auto; font-size: 0; letter-spacing: 0;
    color: transparent; overflow: hidden; background: var(--color-border); }
  :root[data-sidebar="collapsed"] #nav .sb-sec:first-child .sb-section { display: none; }
  :root[data-sidebar="collapsed"] #nav .nav-top, :root[data-sidebar="collapsed"] #nav .menu > button { width: var(--sidenav-item-height); padding: 0; justify-content: center; }
  :root[data-sidebar="collapsed"] #nav .menu.open > button { background: var(--color-hover-wash-strong); }
  :root[data-sidebar="collapsed"] #nav .menu.active.open > button { background: var(--color-primary-subtle); }
  :root[data-sidebar="collapsed"] #nav .menu.expanded > .dropdown { display: none; }
  /* Tooltip with the row name, on hover AND keyboard focus (only the inline offset is set: a fixed child of a
     centred flex row keeps its static block position). */
  :root[data-sidebar="collapsed"] #nav :is(.nav-top, .menu > button):is(:hover, :focus-visible)::after,
  :root[data-sidebar="collapsed"] #sidebar .sb-app:is(:hover, :focus-visible)::after {
    content: attr(aria-label); position: fixed; inset-inline-start: calc(var(--sb-w) + var(--space-2)); margin: 0;
    padding: 6px 10px; border-radius: var(--radius-md); background: var(--color-tooltip-bg); color: var(--color-tooltip-text); box-shadow: var(--shadow-tooltip);
    font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: 1.4; letter-spacing: 0; white-space: nowrap; pointer-events: none; z-index: var(--z-flyout); }
  :root[data-sidebar="collapsed"] #nav .menu.open > button::after { display: none; }
  :root[data-sidebar="collapsed"] #nav .menu.open > .dropdown { display: flex; flex-direction: column; gap: 2px; position: fixed;
    inset-inline-start: calc(var(--sb-w) + var(--space-2)); margin: 0; min-width: var(--sidenav-flyout-width); max-width: 320px;
    max-height: calc(100vh - var(--space-4)); overflow-y: auto; padding: 6px; background: var(--color-surface); color: var(--color-text);
    border: 1px solid var(--color-border); border-radius: var(--radius-xl); box-shadow: var(--shadow-popover); z-index: var(--z-flyout); }
  :root[data-sidebar="collapsed"] #nav .menu.open > .dropdown::before { display: none; }
  :root[data-sidebar="collapsed"] #nav .menu.open > .dropdown .flyout-title { display: block; padding: var(--space-2) var(--space-3) 10px; margin: 0 0 var(--space-1);
    font-size: var(--text-2xs); font-weight: var(--weight-bold); letter-spacing: .1em; text-transform: uppercase; color: var(--color-text-faint);
    border-bottom: 1px solid var(--color-border); }
  :root[data-sidebar="collapsed"] #nav .menu.open > .dropdown a.active { background: var(--color-primary-subtle); }
  :root[data-sidebar="collapsed"] #nav .menu.open > .dropdown a.active::before { display: none; }
}

/* Phone drawer (<= 900px): always the expanded look, slides in from the inline start, blurred backdrop */
@media (max-width: 900px) {
  #sidebar { position: fixed; top: 0; bottom: 0; inset-inline-start: 0; width: var(--sidenav-drawer-width); min-width: 0; z-index: var(--z-drawer);
    transform: translateX(-100%); transition: transform var(--motion-base) var(--ease); }
  :root[dir="rtl"] #sidebar { transform: translateX(100%); }
  #sidebar[inert] { visibility: hidden; }
  #app.sb-open #sidebar { visibility: visible; transform: none; box-shadow: var(--shadow-dialog); }
  #app.sb-open #sb-backdrop { display: block; position: fixed; inset: 0; z-index: var(--z-backdrop); background: var(--color-backdrop);
    -webkit-backdrop-filter: blur(var(--backdrop-blur)); backdrop-filter: blur(var(--backdrop-blur)); }
  body:has(#app.sb-open) { overflow: hidden; }
  #sb-collapse { display: none; }
  #nav .nav-top, #nav .menu > button { height: var(--control-height-lg); }
  #nav .dropdown a { height: 40px; }
}

/* ======================================================================
   3. Control panel: page title (crumbs) and the header search (H4, M1)
   ====================================================================== */
#crumbs { flex: 1 0 auto; max-width: 60%; min-width: 0; }
#crumbs .current { font-size: var(--text-xl); font-weight: var(--weight-semibold); line-height: 1.3; }
.cp-search { flex: 0 1 360px; margin-inline-start: auto; gap: var(--space-2); height: var(--field-height-compact); padding-inline: var(--space-3);
  background-color: var(--field-bg); border: 1px solid var(--field-border); border-radius: var(--field-radius);
  transition: background-color var(--motion-base) var(--ease), border-color var(--motion-base) var(--ease), box-shadow var(--motion-base) var(--ease); }
.cp-search[hidden] { display: none; }
.cp-search:hover { background-color: var(--field-bg-hover); border-color: var(--field-border-hover); }
.cp-search:focus-within { background-color: var(--field-bg-focus); border-color: var(--field-border-focus); box-shadow: 0 0 0 .5px var(--field-border-focus), var(--field-halo); }
.cp-search .search-icon { flex: none; width: 16px; height: 16px; fill: none; stroke: var(--color-text-muted); stroke-width: 2; stroke-linecap: round; }
#global-search, #global-search:hover, #global-search:focus { flex: 1; min-width: 0; height: auto; padding: 0; border: 0; background: transparent; box-shadow: none; }
@media (max-width: 1180px) { .cp-row { flex-wrap: wrap; } #crumbs { max-width: 100%; } }

/* ======================================================================
   4. Fields: label above a filled box (EMI). field() markup:
      <div class="field [full] [has-error]"> <label for> Label <span class="req">*</span></label>
        <div> CONTROL [<span class="field-suffix">JD</span>] [<span class="field-text">date</span>] [.field-hint] [.field-error] </div> </div>
   ====================================================================== */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: var(--space-4); column-gap: var(--space-8); }
.form-grid.one { grid-template-columns: minmax(0, 1fr); }
.field { display: flex; flex-direction: column; align-items: stretch; gap: var(--field-label-gap); min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > label { padding: 0; color: var(--field-label); font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: 1.3; }
.field > label .req { color: var(--color-danger); font-weight: var(--weight-bold); margin-inline-start: 2px; }
.field > div { position: relative; min-width: 0; }
/* dialogs stack their fields with 16px between them (fields inside a .form-grid use the grid gap) */
.modal .body :not(.form-grid) > .field:not(:last-child) { margin-bottom: var(--space-4); }
/* Opt-in: the old label-beside-control sheet, for very long settings pages. */
.form-grid.inline-labels .field { display: grid; grid-template-columns: 160px minmax(0, 1fr); align-items: center; gap: var(--space-2); }
.form-grid.inline-labels .field > label { font-size: var(--text-md); }
/* A checkbox or switch field: the control first, the label beside it, the hint or error under the label.
   The inner box melts into a two-column grid so the label is clickable and lines up with the box. */
.field:has(> div > input[type=checkbox]:first-child) { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: var(--space-3); row-gap: 2px;
  align-items: center; align-self: center; padding-block: var(--space-2); }
.field:has(> div > input[type=checkbox]:first-child) > div { display: contents; }
.field:has(> div > input[type=checkbox]:first-child) > div > input[type=checkbox] { grid-column: 1; grid-row: 1; }
.field:has(> div > input[type=checkbox]:first-child) > label { grid-column: 2; grid-row: 1; color: var(--color-text); font-size: var(--text-md); font-weight: var(--weight-medium); cursor: pointer; }
.field:has(> div > input[type=checkbox]:first-child) :is(.field-hint, .field-error) { grid-column: 2; margin-top: 0; }
/* A read-only value shown as text inside a field (a link, a hash, a date of a posted document). */
.field > div > :is(span, a):only-child { display: block; padding-block: var(--space-1); }

/* The control box: every text-like input, select and textarea. Bare controls get the compact 36px box; fields 44px. */
input:where(:not([type=checkbox], [type=radio], [type=range], [type=file], [type=color], [type=hidden])), select, textarea {
  height: var(--field-height-compact); padding-block: 0; padding-inline: var(--field-pad-start) var(--field-pad-end);
  background-color: var(--field-bg); border: 1px solid var(--field-border); border-radius: var(--field-radius); color: var(--color-text);
  font: inherit; font-size: var(--text-md); font-weight: var(--weight-medium); line-height: 1.4; min-width: 0; caret-color: var(--field-border-focus);
  transition: background-color var(--motion-base) var(--ease), border-color var(--motion-base) var(--ease), box-shadow var(--motion-base) var(--ease); }
.field :is(input:not([type=checkbox], [type=radio], [type=range], [type=file], [type=color], [type=hidden]), select, textarea):not(.chips *) { width: 100%; height: var(--field-height); }
input::placeholder, textarea::placeholder { color: var(--field-placeholder); font-weight: 400; opacity: 1; }
input:where(:not([type=checkbox], [type=radio], [type=range], [type=file], [type=color])):hover:not(:disabled):not([readonly]):not(:focus),
select:hover:not(:disabled):not(:focus), textarea:hover:not(:disabled):not([readonly]):not(:focus) {
  background-color: var(--field-bg-hover); border-color: var(--field-border-hover); }
input:where(:not([type=checkbox], [type=radio], [type=range], [type=file], [type=color])):is(:focus, :focus-visible), select:is(:focus, :focus-visible), textarea:is(:focus, :focus-visible) {
  outline: none; background-color: var(--field-bg-focus); border-color: var(--field-border-focus); border-radius: var(--field-radius);
  box-shadow: 0 0 0 .5px var(--field-border-focus), var(--field-halo); }
/* error: from field()/setFieldError() (.has-error) or any aria-invalid control */
.field.has-error :is(input:not([type=checkbox], [type=radio]), select, textarea, .ss-input):not(.chips *),
:is(input, select, textarea)[aria-invalid="true"]:not([type=checkbox]) { background-color: var(--field-bg-error); border-color: var(--field-border-error); }
.field.has-error :is(input:not([type=checkbox], [type=radio]), select, textarea, .ss-input):not(.chips *):focus,
:is(input, select, textarea)[aria-invalid="true"]:not([type=checkbox]):focus { background-color: var(--field-bg-focus); box-shadow: 0 0 0 .5px var(--field-border-error), var(--field-halo-error); }
/* disabled (a posted document): soft box, full-contrast text, no chevron */
input:where(:not([type=checkbox], [type=radio])):disabled, select:disabled, textarea:disabled {
  background-color: var(--field-bg-disabled); border-color: transparent; color: var(--color-text); -webkit-text-fill-color: var(--color-text);
  opacity: 1; cursor: default; box-shadow: none; }
select:not([multiple]):disabled { background-image: none; padding-inline-end: var(--field-pad-end); }
/* read-only: soft box, selectable */
:is(input, textarea)[readonly] { background-color: var(--field-bg-readonly); border-color: transparent; cursor: text; user-select: text; box-shadow: none; }
/* "Not set" placeholder of an empty locked field (M17) reads as a note, not as data */
:is(input, textarea).not-set::placeholder { font-style: italic; }
textarea, .field textarea:not(.chips *) { height: auto; min-height: var(--field-textarea-min); width: 100%; padding-block: 10px; line-height: 1.5; resize: vertical; }
/* select: one brand chevron drawn with two gradients (mirrored in RTL) */
select:not([multiple]) { appearance: none; -webkit-appearance: none; padding-inline-end: var(--field-select-pad-end); cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--field-chevron) 50%, var(--field-chevron) calc(50% + 2px), transparent calc(50% + 2px)),
    linear-gradient(-45deg, transparent 50%, var(--field-chevron) 50%, var(--field-chevron) calc(50% + 2px), transparent calc(50% + 2px));
  background-size: 6px 6px, 6px 6px; background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-repeat: no-repeat; }
:root[dir="rtl"] select:not([multiple]) { background-position: 14px 50%, 20px 50%; }
select[multiple] { height: auto; padding-block: var(--space-1); }
/* the "+ add" select inside a chips (many2many) box stays small and borderless */
.chips select:not([multiple]) { height: 24px; width: auto; max-width: 140px; padding-inline: var(--space-1) 22px; border-color: transparent;
  background-color: transparent; background-position: calc(100% - 13px) 50%, calc(100% - 8px) 50%; font-size: var(--text-xs); color: var(--color-text-muted); }
/* ...and as the EMI dropdown: a small "+ add" pill, the same panel as every other list */
.chips .ss, .field .chips .ss.ss { display: inline-flex; flex: 0 0 auto; width: auto; min-width: 0; max-width: 100%; }
.chips .ss .ss-input, .chips .ss .ss-input:is(:hover, :focus) { height: 24px; min-height: 0; width: auto; padding-inline: var(--space-2) 22px; border-color: transparent; border-radius: var(--radius-pill);
  background-color: transparent; box-shadow: none; font-size: var(--text-xs); color: var(--color-text-muted); }
.chips .ss .ss-input:is(:hover, :focus-visible) { background-color: var(--field-option-active); color: var(--color-primary-text); }
.chips .ss .ss-input::placeholder { color: var(--color-primary-text); font-weight: var(--weight-medium); }
.chips .ss-chev { inset-inline-end: 9px; width: 5px; height: 5px; }
.chips .ss.ss .ss-input { width: calc(6ch + var(--space-2) + 22px); min-width: 0; text-overflow: clip; }
/* date and time: <input type=date> becomes the EMI date field (shared/date-field.js, section 5b);
   month and time boxes stay native with a muted picker button */
input:is([type=date], [type=datetime-local], [type=month], [type=time]) { padding-inline-end: var(--field-pad-end); font-variant-numeric: tabular-nums; }
input:is([type=date], [type=datetime-local], [type=month], [type=time])::-webkit-calendar-picker-indicator { opacity: .55; cursor: pointer; padding: 4px; border-radius: var(--radius-sm); transition: opacity var(--motion-fast) var(--ease); }
input:is([type=date], [type=datetime-local], [type=month], [type=time]):hover::-webkit-calendar-picker-indicator { opacity: 1; }
/* A locked date shows as text in the company format (H10); field() keeps .field-text in step with the value. */
.field-text { display: none; }
.field > div:has(> input[type=date]:disabled) > input[type=date], .field > div:has(> .dp.disabled) > .dp { display: none; }
.field > div:is(:has(> input[type=date]:disabled), :has(> .dp.disabled)) > .field-text { display: flex; align-items: center; min-height: var(--field-height); padding-inline: var(--field-pad-start);
  background: var(--field-bg-disabled); border-radius: var(--field-radius); font-weight: var(--weight-medium); font-variant-numeric: tabular-nums; }
.field > div:is(:has(> input[type=date]:disabled), :has(> .dp.disabled)) > .field-text:empty::before { content: "Not set"; color: var(--field-placeholder); font-style: italic; font-weight: 400; }
/* numbers and money: digits at the inline end, tabular, no spinners */
input.num, input[type=number] { text-align: end; font-variant-numeric: tabular-nums; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
/* currency chip at the inline end (field() renders it when the control has data-suffix) */
.field > div:has(> .field-suffix) > input { padding-inline-end: calc(var(--field-suffix-width) + var(--field-pad-end)); }
.field-suffix { position: absolute; inset-inline-end: 1px; top: 1px; display: inline-flex; align-items: center; justify-content: center;
  min-width: var(--field-suffix-width); height: calc(var(--field-height) - 2px); padding-inline: 10px; background: var(--color-surface-2);
  border-inline-start: 1px solid var(--field-border); border-start-end-radius: calc(var(--field-radius) - 1px); border-end-end-radius: calc(var(--field-radius) - 1px);
  color: var(--color-text-muted); font-size: var(--text-xs); font-weight: var(--weight-semibold); letter-spacing: .02em; pointer-events: none; }
.field > div:has(> input:is(:disabled, [readonly])) > .field-suffix { background: transparent; border-inline-start-color: transparent; }
/* hero amount (payment dialogs): 56px, currency chip at the start, mono digits */
.money-hero { position: relative; display: flex; align-items: stretch; height: 56px; background: var(--color-surface); border: 1px solid var(--field-border);
  border-radius: var(--radius-xl); overflow: hidden; transition: border-color var(--motion-fast) var(--ease), box-shadow var(--motion-fast) var(--ease); }
.money-hero:hover { border-color: var(--field-border-hover); }
.money-hero:focus-within { border-color: var(--field-border-focus); box-shadow: var(--field-halo); }
.money-hero .money-hero-cur { display: inline-flex; align-items: center; padding-inline: var(--space-4); background: var(--color-surface-2);
  border-inline-end: 1px solid var(--field-border); color: var(--sidebar-text); font-size: var(--text-md); font-weight: var(--weight-semibold); white-space: nowrap; }
.money-hero input { flex: 1; min-width: 0; height: 100%; padding-inline: var(--space-4); border: 0; border-radius: 0; background: transparent; box-shadow: none;
  font-family: var(--font-mono); font-size: var(--text-lg); font-weight: var(--weight-medium); font-variant-numeric: tabular-nums; text-align: end; }
.money-hero input:focus { box-shadow: none; background: transparent; }
/* a control plus a button */
.icon-field { display: flex; align-items: center; gap: var(--space-2); }
.field .icon-field > :is(button, .btn) { min-height: var(--field-height); min-width: var(--field-height); justify-content: center; border-radius: var(--field-radius); }

/* hint and error under the control (EMI form-error: icon, fade in) */
.field-hint { margin-top: var(--field-message-gap); color: var(--color-text-muted); font-size: var(--text-xs); line-height: 1.45; }
.field-error { margin-top: var(--field-message-gap); display: flex; align-items: flex-start; gap: 6px; color: var(--color-danger-strong);
  font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: 1.45; animation: field-error-in var(--motion-base) ease-out; }
.field-error[hidden] { display: none; }
.field-error::before { content: ""; flex: none; width: 14px; height: 14px; margin-top: 1px; background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12.86 3.4a1 1 0 0 0-1.72 0L1.7 19.7a1 1 0 0 0 .86 1.5h18.88a1 1 0 0 0 .86-1.5L12.86 3.4Zm-1.86 5.85a1 1 0 0 1 2 0v5a1 1 0 0 1-2 0v-5Zm1 9.75a1.15 1.15 0 1 1 0-2.3 1.15 1.15 0 0 1 0 2.3Z'/></svg>") center / contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12.86 3.4a1 1 0 0 0-1.72 0L1.7 19.7a1 1 0 0 0 .86 1.5h18.88a1 1 0 0 0 .86-1.5L12.86 3.4Zm-1.86 5.85a1 1 0 0 1 2 0v5a1 1 0 0 1-2 0v-5Zm1 9.75a1.15 1.15 0 1 1 0-2.3 1.15 1.15 0 0 1 0 2.3Z'/></svg>") center / contain no-repeat; }
.field.has-error .field-hint { display: none; }
@keyframes field-error-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

/* ======================================================================
   5. Dropdowns (shared/search-select.js): every <select> is the EMI field + the EMI panel. "pick" = a short
      list (button-like, type-ahead); "search" = more than 10 options (the field is the search box).
   ====================================================================== */
.ss { position: relative; display: flex; align-items: center; width: 100%; min-width: 120px; }
/* a short list outside a form field is as wide as its longest option, like the native select was */
.ss.pick { display: inline-flex; width: auto; min-width: 0; vertical-align: middle; }
:is(.field, td, .emp-dep-select, .form-grid) .ss.pick { display: flex; width: 100%; }
.ss .ss-native { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
/* the hidden native select must not draw a second chevron */
.ss select.ss-native { background-image: none; }
.ss .ss-input { width: 100%; padding-inline-end: var(--field-select-pad-end); text-overflow: ellipsis; cursor: pointer; }
.ss.search .ss-input:focus { cursor: text; }
.ss.pick .ss-input { caret-color: transparent; user-select: none; -webkit-user-select: none; }
.ss.pick .ss-input::selection { background: transparent; }
.ss-chev { position: absolute; inset-inline-end: 14px; top: 50%; width: 6px; height: 6px; margin-top: -4px; cursor: pointer;
  border-inline-end: 2px solid var(--field-chevron); border-bottom: 2px solid var(--field-chevron); transform: rotate(45deg); transition: transform var(--motion-base) var(--ease); }
:root[dir="rtl"] .ss-chev { transform: rotate(-45deg); }
.ss.open .ss-chev { transform: rotate(225deg); margin-top: -1px; }
.ss.disabled .ss-chev { display: none; }
.ss.disabled .ss-input { padding-inline-end: var(--field-pad-end); cursor: default; }
/* The panel: at least as wide as the field, 14px radius, popover shadow, above dialogs, scrolls inside. */
.ss-list, .dp-pop { position: fixed; z-index: var(--z-dropdown); margin: 0; background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border); border-radius: var(--radius-xl); box-shadow: var(--shadow-popover); }
.ss-list { max-height: 320px; max-width: min(520px, calc(100vw - 16px)); overflow-y: auto; overscroll-behavior: contain; padding: 6px;
  font-size: var(--text-md); scrollbar-width: thin; scrollbar-color: var(--color-border-strong) transparent; animation: panel-in var(--motion-fast) var(--ease); }
.ss-list[hidden], .dp-pop[hidden] { display: none; }
.ss-list.up, .dp-pop.up { animation-name: panel-in-up; }
@keyframes panel-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes panel-in-up { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.ss-opt { position: relative; display: flex; align-items: center; min-height: 40px; padding-block: 6px; padding-inline: var(--space-3) 34px;
  border-radius: var(--radius-md); color: var(--color-text); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ss-opt:hover:not([aria-disabled="true"]), .ss-opt.active { background-color: var(--field-option-active); }
.ss-opt.selected { background-color: color-mix(in srgb, var(--color-primary) 8%, transparent); color: var(--color-primary-text); font-weight: var(--weight-semibold); }
.ss-opt.selected.active, .ss-opt.selected:hover { background-color: color-mix(in srgb, var(--color-primary) 16%, transparent); }
.ss-opt.selected::after { content: ""; position: absolute; inset-inline-end: var(--space-3); top: 50%; width: 14px; height: 14px; margin-top: -7px; background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'><path d='M5 12.5l4.5 4.5L19 7.5'/></svg>") center / contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'><path d='M5 12.5l4.5 4.5L19 7.5'/></svg>") center / contain no-repeat; }
/* the empty choice ("None", "Any status") reads as a choice, not as data */
.ss-opt.ss-none:not(.selected) { color: var(--color-text-muted); }
/* "Create ..." option at the end of the list (selectEl create option, L9) */
.ss-opt.ss-create { margin-top: var(--space-1); border-top: 1px solid var(--color-border); border-start-start-radius: 0; border-start-end-radius: 0;
  color: var(--color-primary-text); font-weight: var(--weight-semibold); }
.ss-opt.ss-create::before { content: "+"; margin-inline-end: var(--space-2); font-weight: var(--weight-bold); }
.ss-opt[aria-disabled="true"] { color: var(--color-text-muted); opacity: .6; cursor: not-allowed; }
.ss-opt mark { background: var(--color-warning-subtle); color: inherit; padding: 0; border-radius: 2px; }
/* <optgroup> label, and a line between groups */
.ss-group { padding: var(--space-2) var(--space-3) var(--space-1); color: var(--color-text-muted); font-size: var(--text-xs); font-weight: var(--weight-semibold);
  letter-spacing: .03em; text-transform: uppercase; }
:is(.ss-grp, .ss-opt) + .ss-grp { margin-top: var(--space-1); border-top: 1px solid var(--color-border); }
.ss-empty { padding: 10px var(--space-3); color: var(--color-text-muted); font-size: var(--text-sm); }
/* compact panel for table cells, filters, toolbars and tag pickers */
.ss-list.compact { font-size: var(--text-sm); }
.ss-list.compact .ss-opt { min-height: 34px; padding-block: 4px; }

/* ======================================================================
   5b. Date field (shared/date-field.js): the box shows the company format with a calendar button at the end;
       the calendar popover uses the same panel. The hidden <input type=date> keeps the ISO value.
   ====================================================================== */
.dp { position: relative; display: inline-flex; align-items: center; min-width: 0; vertical-align: middle; }
:is(.field, td, .form-grid) .dp { display: flex; width: 100%; }
.dp input.dp-native[type] { position: absolute; inset-inline-start: 0; top: 0; width: 1px; height: 1px; min-height: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.dp .dp-input { width: 100%; padding-inline-end: 40px; font-variant-numeric: tabular-nums; }
.dp:not(:is(.field, td, .form-grid) .dp) .dp-input { width: 15ch; }
.dp .dp-btn { position: absolute; inset-inline-end: 6px; top: 50%; display: inline-grid; place-items: center; width: 28px; height: 28px; min-height: 0; min-width: 0; margin-top: -14px;
  padding: 0; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--field-chevron); cursor: pointer; opacity: .8; }
.dp .dp-btn:hover, .dp.open .dp-btn { opacity: 1; background: var(--field-option-active); }
.dp-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dp:is(.disabled, .readonly) .dp-btn { display: none; }
.dp:is(.disabled, .readonly) .dp-input { padding-inline-end: var(--field-pad-end); }
/* a typed date that is not a real date (or is outside min/max) */
.dp.bad .dp-input, .dp.bad .dp-input:hover { background-color: var(--field-bg-error); border-color: var(--field-border-error); }
.dp.bad .dp-input:focus { box-shadow: 0 0 0 .5px var(--field-border-error), var(--field-halo-error); }
.dp-pop { width: 296px; max-width: calc(100vw - 16px); padding: var(--space-3); font-size: var(--text-sm); animation: panel-in var(--motion-fast) var(--ease); }
.dp-head { display: flex; align-items: center; gap: 2px; margin-bottom: var(--space-2); }
.dp-title { flex: 1; text-align: center; font-weight: var(--weight-semibold); font-size: var(--text-md); color: var(--color-text); }
.dp-pop .dp-nav { position: relative; flex: none; width: 32px; height: 32px; min-height: 0; min-width: 0; padding: 0; border: 0; border-radius: var(--radius-md);
  background: transparent; color: var(--color-text); cursor: pointer; }
.dp-pop .dp-nav:hover { background: var(--field-option-active); }
/* chevrons drawn with borders (mirrored in RTL); the year buttons get two */
.dp-nav::before, .dp-nav::after { content: ""; position: absolute; top: 50%; inset-inline-start: 50%; width: 6px; height: 6px; margin-top: -3px; margin-inline-start: -2px;
  border-inline-start: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); }
.dp-nav::after { display: none; }
:is(.dp-prev2, .dp-next2)::after { display: block; }
:is(.dp-next, .dp-next2)::before, :is(.dp-next, .dp-next2)::after { transform: rotate(-135deg); margin-inline-start: -5px; }
:root[dir="rtl"] :is(.dp-prev, .dp-prev2)::before, :root[dir="rtl"] :is(.dp-prev, .dp-prev2)::after { transform: rotate(-45deg); }
:root[dir="rtl"] :is(.dp-next, .dp-next2)::before, :root[dir="rtl"] :is(.dp-next, .dp-next2)::after { transform: rotate(135deg); }
.dp-prev2::before { margin-inline-start: -5px; } .dp-prev2::after { margin-inline-start: 1px; }
.dp-next2::before { margin-inline-start: -8px; } .dp-next2::after { margin-inline-start: -2px; }
.dp-grid { width: 100%; border-collapse: separate; border-spacing: 2px; table-layout: fixed; }
.dp-grid th { position: static; padding: var(--space-1) 0; background: none; border: 0; color: var(--color-text-muted); font-size: var(--text-xs); font-weight: var(--weight-semibold); text-align: center; }
.dp-grid td.dp-day { height: 34px; padding: 0; border: 0; border-radius: var(--radius-md); text-align: center; font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums;
  color: var(--color-text); cursor: pointer; }
.dp-grid td.dp-day.other { color: var(--color-text-muted); font-weight: var(--weight-medium); }
.dp-grid td.dp-day:hover:not([aria-disabled="true"]), .dp-grid td.dp-day.active { background: var(--field-option-active); }
.dp-grid td.dp-day.today { box-shadow: inset 0 0 0 1px var(--color-border-strong); }
.dp-grid td.dp-day.active { box-shadow: inset 0 0 0 1.5px var(--color-primary); }
.dp-grid td.dp-day.selected, .dp-grid td.dp-day.selected:hover { background: var(--color-primary); color: var(--color-text-on-primary); }
:root[data-theme="dark"] .dp-grid td.dp-day.selected { background: color-mix(in srgb, var(--primary) 78%, var(--color-shade)); }
.dp-grid td.dp-day[aria-disabled="true"] { color: var(--field-placeholder); font-weight: 400; text-decoration: line-through; cursor: not-allowed; }
.dp-foot { display: flex; gap: var(--space-2); margin-top: var(--space-2); padding-top: var(--space-2); border-top: 1px solid var(--color-border); }
.dp-pop .dp-foot-btn { height: 30px; min-height: 0; padding: 0 var(--space-3); border: 0; border-radius: var(--radius-md); background: transparent;
  color: var(--color-primary-text); font-weight: var(--weight-semibold); cursor: pointer; }
.dp-pop .dp-foot-btn:hover { background: var(--field-option-active); }
.dp-pop .dp-foot-btn:disabled { color: var(--color-text-muted); cursor: not-allowed; background: transparent; }
.dp-foot-btn[hidden] { display: none; }
.dp-foot-btn:last-child { margin-inline-start: auto; }
/* line tables: the date cell keeps the compact cell box */
table.lines .dp .dp-input { padding-inline-end: 30px; }
table.lines .dp .dp-btn { inset-inline-end: 3px; width: 24px; height: 24px; margin-top: -12px; opacity: .6; }

/* ======================================================================
   6. Checkbox, radio, switch
   ====================================================================== */
input[type=checkbox]:not(.switch):not([role=switch]) { appearance: none; -webkit-appearance: none; flex: none; display: inline-grid; place-items: center;
  width: var(--check-size); height: var(--check-size); margin: 0; padding: 0; border: 1.5px solid var(--color-border-strong); border-radius: var(--check-radius);
  background: var(--color-surface); vertical-align: middle; cursor: pointer;
  transition: background-color var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease); }
input[type=checkbox]:not(.switch):not([role=switch])::before { content: ""; width: 12px; height: 12px; background-color: var(--color-text-on-primary);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'><path d='M5 12.5l4.5 4.5L19 7.5'/></svg>") center / contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'><path d='M5 12.5l4.5 4.5L19 7.5'/></svg>") center / contain no-repeat;
  transform: scale(0); transition: transform var(--motion-fast) var(--ease); }
input[type=checkbox]:not(.switch):not([role=switch]):hover:not(:disabled) { border-color: var(--color-primary); }
input[type=checkbox]:not(.switch):not([role=switch]):is(:checked, :indeterminate) { background: var(--color-primary); border-color: var(--color-primary); }
input[type=checkbox]:not(.switch):not([role=switch]):checked::before { transform: scale(1); }
input[type=checkbox]:not(.switch):not([role=switch]):indeterminate::before { -webkit-mask: none; mask: none; width: 10px; height: 2px; border-radius: 1px; transform: scale(1); }
input[type=checkbox]:focus-visible { box-shadow: var(--focus-ring); border-radius: var(--check-radius); }
input[type=checkbox]:disabled { opacity: .5; cursor: not-allowed; }
input[type=radio] { width: var(--check-size); height: var(--check-size); margin: 0; accent-color: var(--color-primary); cursor: pointer; vertical-align: middle; }
/* Switch: <input type="checkbox" class="switch" role="switch"> */
input[type=checkbox]:is(.switch, [role=switch]) { appearance: none; -webkit-appearance: none; position: relative; flex: none;
  width: var(--switch-width); height: var(--switch-height); margin: 0; padding: 0; border: 0; border-radius: var(--radius-pill);
  background: var(--color-switch-off); vertical-align: middle; cursor: pointer; transition: background-color var(--motion-switch) ease-in-out; }
input[type=checkbox]:is(.switch, [role=switch])::before { content: ""; position: absolute; inset-inline-start: var(--switch-gap); top: var(--switch-gap);
  width: var(--switch-knob); height: var(--switch-knob); border-radius: var(--radius-pill); background: var(--color-knob); box-shadow: var(--shadow-knob);
  transition: transform var(--motion-switch) var(--ease-standard); }
input[type=checkbox]:is(.switch, [role=switch]):checked { background: var(--color-primary); }
input[type=checkbox]:is(.switch, [role=switch]):checked::before { transform: translateX(calc(var(--switch-width) - var(--switch-knob) - 2 * var(--switch-gap))); }
:root[dir="rtl"] input[type=checkbox]:is(.switch, [role=switch]):checked::before { transform: translateX(calc(-1 * (var(--switch-width) - var(--switch-knob) - 2 * var(--switch-gap)))); }
input[type=checkbox]:is(.switch, [role=switch]):focus-visible { box-shadow: var(--focus-ring); border-radius: var(--radius-pill); }
input[type=checkbox]:is(.switch, [role=switch]):disabled { opacity: .5; cursor: not-allowed; }

/* ======================================================================
   7. Filters: the old inline .filters row (other screens) and the shared filterBar (shared/filter-bar.js, M3, M15)
   ====================================================================== */
.filters, .filter-controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); min-width: 0; }
:is(.filters, .filter-bar) :is(input:not([type=checkbox], [type=radio]), select, .ss-input) { height: var(--field-height-compact); font-size: var(--text-sm); }
:is(.filters, .filter-controls) select:not([multiple]) { width: auto; min-width: 128px; }
.filters > label:not(:has(input)) { color: var(--color-text-muted); font-size: var(--text-xs); font-weight: var(--weight-medium); }
/* A filter that is not on its default (empty) choice looks "on" (EMI active chip). */
:is(.filters, .filter-bar) select:has(option[value=""]):not(:has(option[value=""]:checked)) { background-color: var(--field-bg-on); border-color: var(--field-border-on); color: var(--color-primary-text); }
/* A checkbox filter ("Overdue") is a toggle chip */
:is(.filters, .filter-controls, .doc-filters) label:has(> input[type=checkbox]) { display: inline-flex; align-items: center; gap: var(--space-2); height: var(--field-height-compact);
  padding-inline: var(--space-3); border: 1px solid var(--field-border); border-radius: var(--field-radius); background-color: var(--field-bg);
  color: var(--color-text); font-size: var(--text-sm); font-weight: var(--weight-medium); cursor: pointer; white-space: nowrap;
  transition: background-color var(--motion-fast) var(--ease), border-color var(--motion-fast) var(--ease); }
:is(.filters, .filter-controls, .doc-filters) label:has(> input[type=checkbox]):hover { background-color: var(--field-bg-hover); border-color: var(--field-border-hover); }
:is(.filters, .filter-controls, .doc-filters) label:has(> input[type=checkbox]:checked) { background: var(--field-bg-on); border-color: var(--field-border-on); color: var(--color-primary-text); }
/* A date range is one group, so From and To never split across rows (M15) */
.date-range { display: inline-flex; align-items: center; gap: var(--space-1); height: var(--field-height-compact); padding-inline: var(--space-3) var(--space-1);
  border: 1px solid var(--field-border); border-radius: var(--field-radius); background: var(--field-bg); white-space: nowrap; }
.date-range:focus-within { border-color: var(--field-border-focus); box-shadow: 0 0 0 .5px var(--field-border-focus), var(--field-halo); background: var(--field-bg-focus); }
.date-range.on { background: var(--field-bg-on); border-color: var(--field-border-on); }
.date-range > .date-range-label { color: var(--color-text-muted); font-size: var(--text-xs); font-weight: var(--weight-medium); }
.date-range > .date-range-sep { color: var(--color-text-muted); font-size: var(--text-xs); }
.date-range input[type=date], .date-range input[type=date]:is(:hover, :focus), .date-range .dp .dp-input, .date-range .dp .dp-input:is(:hover, :focus) { height: calc(var(--field-height-compact) - 2px); width: auto; min-width: 0; padding-inline: var(--space-1);
  border: 0; background: transparent; box-shadow: none; font-size: var(--text-sm); }
.date-range .dp.dp .dp-input { width: 12.5ch; padding-inline-end: 26px; }
.date-range .dp-btn { inset-inline-end: 0; width: 24px; height: 24px; margin-top: -12px; }
.date-range .dp-btn svg { width: 15px; height: 15px; }
/* the filter look "on" for a dropdown that is not on its empty choice */
:is(.filters, .filter-bar) .ss:has(> select option[value=""]):not(:has(> select option[value=""]:checked)) .ss-input { background-color: var(--field-bg-on); border-color: var(--field-border-on); color: var(--color-primary-text); }
:is(.filters, .filter-controls) .ss { width: auto; min-width: 128px; }
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--space-2); flex: 1 1 auto; min-width: 0; }
.filter-bar-search { position: relative; flex: 0 1 280px; min-width: 160px; }
/* Inside a toolbar the bar melts into it: buttons and search on the first row, the filters on the next, then the chips. */
.toolbar > .filter-bar { display: contents; }
.toolbar > .filter-bar > .filter-bar-search { margin-inline-start: auto; }
.toolbar > .filter-bar > .filter-controls { flex: 1 1 100%; }
.filter-bar-search > svg { position: absolute; inset-inline-start: var(--space-3); top: 50%; width: 15px; height: 15px; margin-top: -7.5px; fill: none;
  stroke: var(--color-text-muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.filter-bar-search > input { width: 100%; padding-inline-start: 34px; }
.filter-toggle { display: none; }
.filter-toggle .filter-count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--radius-pill);
  background: var(--color-primary); color: var(--color-text-on-primary); font-size: var(--text-2xs); font-weight: var(--weight-bold); }
.group-by { display: inline-flex; align-items: center; gap: var(--space-1); }
.filter-chips { flex: 1 1 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; }
.filter-chips:empty { display: none; }
.filter-chip { display: inline-flex; align-items: center; gap: 2px; height: 28px; padding-inline: 10px 2px; border-radius: var(--radius-pill);
  background: var(--color-primary-subtle); color: var(--color-primary-text); font-size: var(--text-sm); font-weight: var(--weight-medium); white-space: nowrap; }
.filter-chip > b { font-weight: var(--weight-semibold); margin-inline-end: 3px; }
.filter-chip > button { min-height: 0; width: 24px; height: 24px; padding: 0; justify-content: center; border: 0; border-radius: var(--radius-pill);
  background: transparent; color: inherit; font-size: var(--text-lg); line-height: 1; }
.filter-chip > button:hover { background: var(--color-hover-wash-strong); color: inherit; }
.filter-chips > button.link { font-size: var(--text-sm); }
@media (max-width: 640px) {
  .filter-bar { justify-content: stretch; }
  .filter-bar-search { flex: 1 1 auto; }
  .filter-toggle { display: inline-flex; }
  .filter-bar > .filter-controls { display: none; flex: 1 1 100%; }
  .filter-bar.open > .filter-controls { display: grid; grid-template-columns: minmax(0, 1fr); }
  .filter-bar.open > .filter-controls > * { width: 100%; }
  .filter-bar.open > .filter-controls select:not([multiple]) { width: 100%; }
  .filter-chips { justify-content: flex-start; }
  .date-range { justify-content: space-between; }
}
/* Filter drawer for phones (optional; EMI filter-drawer) */
.filter-panel { position: fixed; inset-block: 0; inset-inline-end: 0; width: 380px; max-width: 92vw; display: flex; flex-direction: column;
  background: var(--color-surface); border-inline-start: 1px solid var(--color-border); box-shadow: var(--shadow-dialog);
  transform: translateX(100%); transition: transform var(--motion-base) var(--ease); z-index: var(--z-drawer); pointer-events: none; }
:root[dir="rtl"] .filter-panel { transform: translateX(-100%); }
.filter-panel.open { transform: none; pointer-events: auto; }

/* ======================================================================
   8. List tables (table() in core.js): date cells, late badge, column priority, edge fade, phone cards, groups
   ====================================================================== */
td.date, th.date { white-space: nowrap; font-variant-numeric: tabular-nums; }
.filter-toggle .filter-count[hidden] { display: none; }
.due-late { white-space: nowrap; }
.badge.late { margin-inline-start: var(--space-1); padding: 0 6px; font-size: var(--text-2xs); line-height: 16px; }
.cell-badges { display: inline-flex; flex-wrap: wrap; gap: var(--space-1); align-items: center; }
/* Column priority (H3): low-value columns hide when the table's own box gets narrow. */
.table-wrap.cq { container-type: inline-size; }
@container (max-width: 900px) { .col-p3 { display: none; } }
@container (max-width: 760px) { .col-p2 { display: none; } }
/* Edge fade: a soft end edge tells that the table scrolls sideways (set by JS when it does). */
.table-wrap.fade-end { -webkit-mask-image: linear-gradient(to right, black calc(100% - var(--table-fade)), transparent); mask-image: linear-gradient(to right, black calc(100% - var(--table-fade)), transparent); }
.table-wrap.fade-start { -webkit-mask-image: linear-gradient(to left, black calc(100% - var(--table-fade)), transparent); mask-image: linear-gradient(to left, black calc(100% - var(--table-fade)), transparent); }
.table-wrap.fade-start.fade-end { -webkit-mask-image: linear-gradient(to right, transparent, black var(--table-fade), black calc(100% - var(--table-fade)), transparent);
  mask-image: linear-gradient(to right, transparent, black var(--table-fade), black calc(100% - var(--table-fade)), transparent); }
:root[dir="rtl"] .table-wrap.fade-end:not(.fade-start) { -webkit-mask-image: linear-gradient(to left, black calc(100% - var(--table-fade)), transparent); mask-image: linear-gradient(to left, black calc(100% - var(--table-fade)), transparent); }
:root[dir="rtl"] .table-wrap.fade-start:not(.fade-end) { -webkit-mask-image: linear-gradient(to right, black calc(100% - var(--table-fade)), transparent); mask-image: linear-gradient(to right, black calc(100% - var(--table-fade)), transparent); }
/* Group rows (table(..., { group })) */
table.list tr.group-row > * { position: static; text-align: start; font-size: var(--text-sm); color: var(--color-text); background: var(--color-surface-2); font-weight: var(--weight-semibold); padding-block: var(--space-2); }
table.list tr.group-row .group-count { margin-inline-start: var(--space-2); color: var(--color-text-muted); font-weight: var(--weight-medium); font-size: var(--text-xs); }
/* Phone card rows (H7): each row becomes a small card, label beside each value, no sideways scroll. */
@media (max-width: 640px) {
  table.list.cards, table.list.cards > tbody, table.list.cards > tfoot { display: block; }
  table.list.cards > thead { display: none; }
  table.list.cards > tbody > tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px var(--space-3); padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border); }
  table.list.cards > tbody > tr > td { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3);
    min-width: 0; padding: 0; border: 0; text-align: end; white-space: normal; background: none; }
  table.list.cards > tbody > tr:hover > td { background: none; }
  table.list.cards > tbody > tr > td::before { content: attr(data-label); flex: none; color: var(--color-text-muted); font-size: var(--text-xs); font-weight: var(--weight-medium); text-align: start; }
  table.list.cards > tbody > tr > td:empty, table.list.cards .col-p3 { display: none; }
  table.list.cards > tbody > tr > td.card-title { grid-column: 1; justify-content: flex-start; text-align: start; font-size: var(--text-md); font-weight: var(--weight-semibold); }
  table.list.cards > tbody > tr > td.card-title::before, table.list.cards > tbody > tr > td.card-check::before { content: none; }
  table.list.cards > tbody > tr > td.card-check { grid-column: 2; grid-row: 1; justify-content: flex-end; }
  table.list.cards > tbody > tr.group-row { display: block; padding: 0; }
  table.list.cards > tbody > tr.group-row > * { display: block; padding: var(--space-2) var(--space-4); background: var(--color-surface-2); text-align: start; }
  table.list.cards > tbody > tr.group-row > *::before { content: none; }
  table.list.cards > tfoot > tr { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2); padding: var(--space-3) var(--space-4); }
  table.list.cards > tfoot > tr > td { padding: 0; border: 0; }
  table.list.cards > tfoot > tr > td:empty { display: none; }
}

/* ======================================================================
   9. Line tables (table.lines: invoice lines, statements, payslips): compact cells, no box until touched
   ====================================================================== */
table.lines :is(input:not([type=checkbox], [type=radio]), select, .ss-input) { width: 100%; height: var(--field-height-cell); padding-block: 0; padding-inline: var(--space-2);
  background-color: transparent; border: 1px solid transparent; border-radius: var(--field-radius-cell); font-size: var(--text-md); font-weight: 400; box-shadow: none; }
table.lines select:not([multiple]) { padding-inline-end: 26px; background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; }
:root[dir="rtl"] table.lines select:not([multiple]) { background-position: 11px 50%, 16px 50%; }
table.lines .ss .ss-input { padding-inline-end: 26px; }
table.lines .ss-chev { inset-inline-end: 10px; opacity: .6; }
table.lines .ss { min-width: 140px; }
table.lines :is(input:not([type=checkbox], [type=radio]), select, .ss-input):hover:not(:disabled):not([readonly]):not(:focus),
table.lines tr:hover :is(input:not([type=checkbox], [type=radio]), select, .ss-input):not(:disabled):not([readonly]):not(:focus) { background-color: var(--field-bg-hover); border-color: var(--field-border); }
table.lines :is(input:not([type=checkbox], [type=radio]), select, .ss-input):is(:focus, :focus-visible) { outline: none; background-color: var(--field-bg-focus);
  border-color: var(--field-border-focus); border-radius: var(--field-radius-cell); box-shadow: 0 0 0 .5px var(--field-border-focus), 0 0 0 2px color-mix(in srgb, var(--color-primary) 16%, transparent); }
table.lines :is(input, select, .ss-input)[aria-invalid="true"], table.lines .ss:has(.ss-input[aria-invalid="true"]) .ss-input {
  background-color: var(--color-danger-subtle); border-color: var(--field-border-error); }
table.lines :is(input:not([type=checkbox], [type=radio]), select):disabled, table.lines .ss.disabled .ss-input, table.lines input[readonly] {
  background-color: transparent; border-color: transparent; color: var(--color-text); -webkit-text-fill-color: var(--color-text); background-image: none; cursor: default; }

/* ======================================================================
   10. Toasts and dialogs
   ====================================================================== */
#toasts { z-index: var(--z-toast); }
.toast { display: flex; align-items: flex-start; gap: var(--space-3); }
.toast > span { flex: 1; }
.toast-close { border: none; background: none; padding: 0 var(--space-1); color: var(--color-text-muted); font-size: var(--text-lg); line-height: 1; }
.toast-close:hover { background: none; color: var(--color-text); }
.modal-backdrop { z-index: var(--z-dialog); background: var(--color-backdrop); }
.modal { box-shadow: var(--shadow-dialog); border-radius: var(--radius-xl); }
/* A tall dialog (a payslip) scrolls its body; the title and the buttons stay in view. */
.modal-backdrop > .modal { display: flex; flex-direction: column; overflow: hidden; }
.modal-backdrop > .modal > header, .modal-backdrop > .modal > footer { flex: none; }
.modal-backdrop > .modal > .body { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.modal header .modal-title { margin: 0; font-size: var(--text-lg); font-weight: var(--weight-semibold); }

/* ======================================================================
   11. Empty and not-found states, link buttons, dark-mode solid buttons
   ====================================================================== */
.empty-state { padding: var(--space-12) var(--space-6); text-align: center; display: grid; justify-items: center; gap: var(--space-2); }
.empty-state h2 { margin: 0; font-size: var(--text-xl); }
.empty-state p { margin: 0 0 var(--space-3); max-width: 46ch; }
a.button { display: inline-flex; align-items: center; height: var(--control-height-md); padding: 0 var(--space-4); border-radius: var(--radius-md);
  background: var(--color-surface-2); color: var(--color-text); font-weight: var(--weight-medium); text-decoration: none; }
a.button.primary { background: var(--color-primary); color: var(--color-text-on-primary); }
a.button.primary:hover { background: var(--color-primary-hover); text-decoration: none; }
/* Dark mode: solid buttons darkened so white text keeps 4.5:1. */
:root[data-theme="dark"] :is(button.primary, .btn.primary, a.button.primary) { background: color-mix(in srgb, var(--primary) 78%, var(--color-shade)); border-color: transparent; }
:root[data-theme="dark"] :is(button.primary, .btn.primary, a.button.primary):hover { background: color-mix(in srgb, var(--primary) 66%, var(--color-shade)); }
:root[data-theme="dark"] .modal footer button.danger { background: color-mix(in srgb, var(--danger) 62%, var(--color-shade)); color: var(--color-text-on-primary); border-color: transparent; }
:root[data-theme="dark"] .modal footer button.danger:hover { background: color-mix(in srgb, var(--danger) 52%, var(--color-shade)); }

/* ======================================================================
   12. Phones (<= 640px: 16px text so iOS does not zoom, 44px controls) and touch screens (H8)
   ====================================================================== */
@media (max-width: 640px) {
  .form-grid { grid-template-columns: minmax(0, 1fr); row-gap: var(--space-3); }
  .field :is(input:not([type=checkbox], [type=radio]), select, textarea):not(.chips *), :is(.filters, .filter-bar) :is(input:not([type=checkbox], [type=radio]), select, .ss-input) { font-size: var(--text-lg); }
  input:where(:not([type=checkbox], [type=radio], [type=range], [type=file], [type=color], [type=hidden])), select, textarea { font-size: var(--text-lg); }
  :is(.filters, .filter-bar) :is(input:not([type=checkbox], [type=radio]), select, .ss-input), :is(.filters, .filter-controls, .doc-filters) label:has(> input[type=checkbox]),
  .date-range { height: var(--field-height); }
}
/* Fingers, not a mouse: every control and small "x" gets a 44px target; checkboxes grow to 22px. */
@media (pointer: coarse) {
  :where(button, .btn, a.button, select, input:not([type=checkbox], [type=radio], [type=hidden]), .ss-input) { min-height: var(--touch-target); }
  table.lines :is(input:not([type=checkbox], [type=radio]), select, .ss-input) { height: var(--touch-target); }
  input[type=checkbox]:not(.switch):not([role=switch]) { --check-size: 22px; }
  :is(.toast-close, .chip button, .filter-chip > button, button.link) { min-width: var(--touch-target); min-height: var(--touch-target); justify-content: center; }
  .chip button, .filter-chip > button { margin-block: -10px; }
  td:has(> input[type=checkbox]:only-child) { padding-block: var(--space-2); }
  #nav .dropdown a { height: var(--touch-target); }
}

/* Arrows that point along the text flip in right-to-left pages (Phase 8). */
:root[dir="rtl"] .icon-dir { transform: scaleX(-1); }
