/* Shared UI alignment system. Loaded last on every page.
   Filter bars and toolbars were styled one by one (labels beside or above fields, controls 36-46px tall,
   different gaps), so the same row looked different on every screen. These rules give all of them one
   layout: label above the field, one control height, one gap, wrapping when a row is full.
   Colours, fonts and backgrounds stay with each page's own stylesheet. */
:root {
  --ui-control-h: 42px;
  --ui-radius: 8px;
  --ui-gap-x: 14px;
  --ui-gap-y: 12px;
  --ui-label-gap: 6px;
}

/* Same sizing model everywhere. Most pages already get this from admin.css, style.css or partner-ui.css;
   the standalone password pages did not, so padding was added on top of widths there (70px-tall fields,
   page wider than the phone). */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }

/* Filter bars: labelled fields + Search / Apply / Reset / Export buttons.
   :is() takes its most specific selector, so every container here outranks the per-page rules it replaces. */
body :is(.order-list-controls, .net-toolbar, .net-filters, .net-form-inline, .orders-filters, .dealer-filters, .commission-filters, .catalog-filters, .inv-toolbar, .pincode-toolbar, .dealer-report-filter, .dealer-page .dealer-report-filter) {
  align-items: end;
  gap: var(--ui-gap-y) var(--ui-gap-x);
  flex-wrap: wrap;
  min-width: 0;
}
body :is(.order-list-controls, .net-toolbar, .net-filters, .net-form-inline, .orders-filters, .dealer-filters, .commission-filters, .catalog-filters, .inv-toolbar, .pincode-toolbar, .dealer-report-filter, .dealer-page .dealer-report-filter) > label:not(:has(input[type=checkbox], input[type=radio])) {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--ui-label-gap);
  flex: 1 1 150px;
  min-width: 0;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--muted, #52647b);
}
body :is(.order-list-controls, .net-toolbar, .net-filters, .net-form-inline, .orders-filters, .dealer-filters, .commission-filters, .catalog-filters, .inv-toolbar, .pincode-toolbar, .dealer-report-filter, .dealer-page .dealer-report-filter) :is(input:not([type=checkbox], [type=radio], [type=file], [type=range], [type=color], [type=hidden]), select) {
  box-sizing: border-box;
  height: var(--ui-control-h);
  min-height: var(--ui-control-h);
  padding-block: 0;
  padding-inline: 12px;
  border-radius: var(--ui-radius);
  font-size: 14px;
  line-height: normal;
  min-width: 0;
  max-width: 100%;
}
/* Fields placed straight in a bar without a label (dropdowns, search boxes) share the row like labelled
   fields instead of being squeezed until their text is cut off. Grid bars ignore flex sizing. */
body :is(.order-list-controls, .net-toolbar, .net-filters, .net-form-inline, .orders-filters, .dealer-filters, .commission-filters, .inv-toolbar, .dealer-report-filter, .dealer-page .dealer-report-filter) > :is(select, input:not([type=checkbox], [type=radio], [type=file], [type=hidden])) {
  flex: 1 1 140px;
  min-width: 130px;
}

/* Flex bars only (grid bars size labels by their columns): stop one field stretching across a wide screen. */
body :is(.order-list-controls, .net-toolbar, .net-form-inline, .orders-filters, .dealer-filters, .commission-filters, .inv-toolbar, .dealer-report-filter, .dealer-page .dealer-report-filter) > label:not(:has(input[type=checkbox], input[type=radio])) {
  max-width: 320px;
}
body :is(.order-list-controls, .net-toolbar, .net-filters, .net-form-inline, .orders-filters, .dealer-filters, .commission-filters, .catalog-filters, .inv-toolbar, .pincode-toolbar, .dealer-report-filter, .dealer-page .dealer-report-filter) label :is(input, select) {
  width: 100%;
}

/* Toolbars beside page titles: search box + buttons on one centred line.
   Display is left alone: these toolbars are shown and hidden per screen by their own stylesheets. */
body :is(.catalog-toolbar, .orders-toolbar, .dealer-toolbar, .ledger-toolbar, .inv-toolbar-end, .portal-top-actions, .header-actions, .form-actions) {
  align-items: center;
  gap: 10px 12px;
  flex-wrap: wrap;
  min-width: 0;
}
body :is(.catalog-toolbar, .orders-toolbar, .dealer-toolbar, .ledger-toolbar) :is(input:not([type=checkbox], [type=radio], [type=file], [type=hidden]), select) {
  box-sizing: border-box;
  height: var(--ui-control-h);
  min-height: var(--ui-control-h);
  padding-block: 0;
  border-radius: var(--ui-radius);
  min-width: 0;
  max-width: 100%;
}

/* One button shape inside every filter bar and toolbar, whatever class the button carries
   (admin-button, quiet-button, table-action …). Colours stay with each button's own class. */
body :is(.order-list-controls, .net-toolbar, .net-filters, .net-form-inline, .orders-filters, .dealer-filters, .commission-filters, .catalog-filters, .inv-toolbar, .inv-toolbar-end, .pincode-toolbar, .dealer-report-filter, .dealer-page .dealer-report-filter, .catalog-toolbar, .orders-toolbar, .dealer-toolbar, .ledger-toolbar) :is(button, a.admin-button, a.quiet-button) {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--ui-control-h);
  min-height: var(--ui-control-h);
  padding-block: 0;
  padding-inline: 16px;
  border-radius: var(--ui-radius);
  line-height: 1;
  white-space: nowrap;
  flex: 0 0 auto;
}

/* Grid forms: rows were stretched to their tallest item, so a field next to a two-line label grew taller
   and a button next to a labelled field filled the label's whole height. Aligning to the bottom keeps
   every field and button on one line whatever the label length. */
body .form-grid {
  align-items: end;
}
/* A checkbox label in a grid form ("Active on homepage"): box and text on one line, not stacked. */
body .form-grid > label:has(> input[type=checkbox]:first-child) {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  align-self: center;
}
body .form-grid > label:has(> input[type=checkbox]:first-child) > input[type=checkbox] {
  flex: none;
  width: 18px;
  height: 18px;
  min-height: 0;
  margin: 0;
}
body .form-grid > :is(button, .admin-button, .quiet-button) {
  align-self: end;
  min-height: var(--ui-control-h);
  height: auto;
}

/* Forms, button rows and table boxes stacked in one card had no margin, so a form's button touched the
   next form's first label and "Create …" buttons sat on the table header below. Vertical margins collapse
   with any margin already there, so this only adds space where there was none. */
:is(form, .form-grid, .table-scroll, .order-list-controls, .settings-note, label, button) + :is(form, .form-grid, .table-scroll),
:is(form, .form-grid, .table-scroll, .order-list-controls) + [hidden] + :is(form, .form-grid, .table-scroll) {
  margin-top: 18px;
}

/* Stand-alone card buttons (e.g. "Refresh credit notes", "Refresh refund ledger") placed between a form and
   a table touched both. Buttons without any class also showed as plain grey browser buttons. */
:is(.panel, section.panel) > button {
  margin: 16px 0 12px;
}
:is(.panel, section.panel) > button:not([class]) {
  min-height: var(--ui-control-h);
  padding: 0 16px;
  border: 1px solid var(--line, #dce5ef);
  border-radius: var(--ui-radius);
  background: #fff;
  color: var(--green, #164fc7);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

/* A single labelled field placed straight in a card or card header (outside any filter bar):
   label above the field, same field size as everywhere else. */
:is(.panel, .panel-heading, section) > label:not(:has(input[type=checkbox], input[type=radio])):has(> :is(select, input)) {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--ui-label-gap);
  max-width: 360px;
  margin: 8px 0 4px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--muted, #52647b);
}
:is(.panel, .panel-heading, section) > label:not(:has(input[type=checkbox], input[type=radio])) > :is(select, input:not([type=checkbox], [type=radio], [type=file], [type=hidden])) {
  box-sizing: border-box;
  width: 100%;
  height: var(--ui-control-h);
  min-height: var(--ui-control-h);
  padding: 0 12px;
  border: 1px solid var(--line, #dce5ef);
  border-radius: var(--ui-radius);
  background: #fff;
  color: var(--ink, #172c49);
  font: inherit;
  font-size: 14px;
  font-weight: 400;
}

/* Tables: scroll sideways inside their card instead of widening the page.
   position:relative keeps absolutely positioned helpers (screen-reader-only header text) inside the
   scroll box; without it they escaped it and pushed the whole page wider than the phone screen. */
.table-scroll {
  position: relative;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Long words, links and IDs wrap instead of pushing cards wider than the screen. */
:is(.panel, .panel-heading, .login-card, .portal-dashboard, .dealer-main) :is(h1, h2, h3, p) {
  overflow-wrap: anywhere;
}

/* Tablet: filter fields share the row two by two. */
@media (max-width: 900px) {
  body :is(.order-list-controls, .net-toolbar, .net-filters, .net-form-inline, .orders-filters, .dealer-filters, .commission-filters, .catalog-filters, .inv-toolbar, .pincode-toolbar, .dealer-report-filter, .dealer-page .dealer-report-filter) > label:not(:has(input[type=checkbox], input[type=radio])) {
    flex: 1 1 calc(50% - var(--ui-gap-x));
    max-width: none;
  }
}

/* Phone: fields stack one per row; buttons share the last row evenly. */
@media (max-width: 600px) {
  body :is(.order-list-controls, .net-toolbar, .net-filters, .net-form-inline, .orders-filters, .dealer-filters, .commission-filters, .catalog-filters, .inv-toolbar, .pincode-toolbar, .dealer-report-filter, .dealer-page .dealer-report-filter) > label:not(:has(input[type=checkbox], input[type=radio])) {
    flex: 1 1 100%;
  }
  body :is(.order-list-controls, .net-toolbar, .net-filters, .net-form-inline, .orders-filters, .dealer-filters, .commission-filters, .catalog-filters, .inv-toolbar, .inv-toolbar-end, .pincode-toolbar, .dealer-report-filter, .dealer-page .dealer-report-filter) > :is(button, a.admin-button, a.quiet-button) {
    flex: 1 1 auto;
  }
  body :is(.order-list-controls, .net-toolbar, .net-filters, .net-form-inline, .orders-filters, .dealer-filters, .commission-filters, .inv-toolbar, .dealer-report-filter, .dealer-page .dealer-report-filter) > :is(select, input:not([type=checkbox], [type=radio], [type=file], [type=hidden])) {
    flex: 1 1 100%;
    width: 100%;
  }
}

/* Dealer password setup page (dealer-invitation.html): label/field pairs are siblings, not nested. */
.signup-page [data-password-form] > label { margin-bottom: calc(var(--ui-label-gap) - 16px); font-weight: 600; }
.signup-page [data-password-form] > input { min-height: var(--ui-control-h); }
