/* AuthMantra UI system, forms. Loaded after ui.css and ui-motion.css.
   One layout for every form on every page, whether it uses the ui_* macros or hand-written markup:
   labels above controls, controls of one height on one grid, checkboxes and toggles that line up with the inputs beside them,
   buttons side by side, and a quiet teal-to-blue accent so a card you can act on looks different from one you can only read. */

/* ── Checkboxes and radios: one look, whatever the markup ───────────────────────────────────────── */
html input[type="checkbox"], html input[type="radio"] {
  appearance: none; -webkit-appearance: none; flex: none; box-sizing: border-box; width: 18px !important; height: 18px !important; min-width: 18px !important; max-width: 18px !important; min-height: 18px !important; padding: 0 !important; margin: 0; cursor: pointer;
  border: 1.5px solid var(--ui-control-border); background-color: var(--ui-surface); background-position: center; background-repeat: no-repeat; background-size: 12px 12px;
  transition: background-color var(--ui-dur) var(--ui-ease), border-color var(--ui-dur) var(--ui-ease), box-shadow var(--ui-dur) var(--ui-ease);
}
html input[type="checkbox"] { border-radius: 5px; }
html input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]:hover, input[type="radio"]:hover { border-color: var(--ui-accent-ink); }
input[type="checkbox"]:checked {
  background-color: var(--ui-accent); border-color: var(--ui-accent-ink);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231A2332' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}
input[type="radio"]:checked { background-color: var(--ui-surface); border: 5px solid var(--ui-accent); }
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { outline: none; box-shadow: var(--ui-focus); }
input[type="checkbox"]:disabled, input[type="radio"]:disabled { opacity: 0.5; cursor: not-allowed; }
/* The macro draws its own box and hides the real input; hand-written .ui-check labels have no box, so their input stays visible. */
.ui-check > input:not(:has(+ .ui-check__box)) { position: static; opacity: 1; margin: 1px 0 0; }
.ui-check:has(> input:not(:has(+ .ui-check__box))), .checkbox-row { align-items: center; gap: 10px; }

/* A lone on/off field (label and one checkbox) is a switch: "Switched on", "Send the digest". */
.ui-field:has(> input[type="checkbox"]) { display: flex; flex-direction: row-reverse; justify-content: flex-end; align-items: center; gap: 12px; min-height: 40px; align-self: end; }
.ui-field:has(> input[type="checkbox"]) > .ui-label { cursor: pointer; font-size: 0.94rem; color: var(--ui-text); }
.ui-field > input[type="checkbox"], html .ui-field > input[type="checkbox"] {
  width: 40px !important; min-width: 40px !important; max-width: 40px !important; height: 22px !important; min-height: 22px !important; border-radius: 999px; border-width: 0; background-color: var(--ui-control-border); background-size: 22px 22px; background-position: 0 center;
  background-image: radial-gradient(circle at center, #fff 0 8px, transparent 8.5px);
  transition: background-color 200ms var(--ui-ease), background-position 200ms var(--ui-ease);
}
.ui-field > input[type="checkbox"]:checked { background-color: var(--ui-accent-ink); background-position: 100% center; background-image: radial-gradient(circle at center, #fff 0 8px, transparent 8.5px); border: 0; }

/* ── The form grid ──────────────────────────────────────────────────────────────────────────────── */
.ui-form-row { grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); align-items: end; gap: 18px 20px; }
.ui-form-row > .ui-field { min-width: 0; }
.ui-form-row > .ui-check, .ui-form-row > .checkbox-row, .ui-form-row > .ui-switch { min-height: 40px; align-self: end; }
.ui-form-row > .ui-form-wide, .ui-form-row > p, .ui-form-row > .ui-muted { grid-column: 1 / -1; }
.ui-form-row > .ui-btn { align-self: end; min-height: 40px; }
.ui-form-row .ui-select { text-overflow: ellipsis; }

/* A stack is a column of rows. Fields take the full width, buttons sit side by side underneath. */
.ui-card .ui-form-stack { max-width: none; }
.ui-form-stack { display: flex; flex-wrap: wrap; align-items: center; gap: 18px 12px; }
.ui-form-stack > * { flex: 1 1 100%; min-width: 0; }
.ui-form-stack > .ui-btn, .ui-form-stack > button, .ui-form-stack > .ui-form-actions { flex: 0 0 auto; }
.ui-form-stack > .ui-form-row, .ui-form-stack > .ui-field, .ui-form-stack > .ui-check, .ui-form-stack > .ui-muted, .ui-form-stack > p, .ui-form-stack > details { flex-basis: 100%; }
.ui-form-stack:not(:has(.ui-form-row)) { max-width: 640px; }
.ui-form-stack > p { margin: 0; }
.ui-form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* Field labels: one size, one colour, always directly above the control. */
.ui-form-row .ui-label, .ui-form-stack .ui-label, .ui-field .ui-label { display: block; margin: 0; font-size: 0.84rem; font-weight: 590; color: var(--ui-text-2); letter-spacing: 0.005em; }
.ui-field .ui-field__help, .ui-field > small { color: var(--ui-text-3); font-size: 0.8rem; }

/* Controls respond: a soft tint on hover, the brand ring on focus. */
.ui-input, .ui-select, .ui-textarea { background-color: var(--ui-surface); }
.ui-input:hover, .ui-select:hover, .ui-textarea:hover { background-color: var(--ui-accent-soft); border-color: var(--ui-accent-ink); }
.ui-input:focus, .ui-select:focus, .ui-textarea:focus { background-color: var(--ui-surface); }

/* ── Colour and depth ───────────────────────────────────────────────────────────────────────────── */
/* A card with a form in it is a place to act: a thin teal-to-blue line along its top edge says so. */
.ui-card:has(form) { position: relative; overflow: clip; }
.ui-card:has(form)::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: linear-gradient(90deg, #0ABFBC 0%, #1F8FBF 55%, #2F5FC4 100%); opacity: 0.9; }
.ui-card:has(table)::before, .ui-card--flush::before { opacity: 0.55; }
.ui-card__title { font-size: 1.04rem; }
.ui-btn--secondary { transition: background-color var(--ui-dur) var(--ui-ease), border-color var(--ui-dur) var(--ui-ease), transform var(--ui-dur) var(--ui-ease); }
.ui-btn--secondary:hover { background: var(--ui-accent-soft); border-color: var(--ui-accent-ink); color: var(--ui-accent-ink); }
.ui-btn:active { transform: translateY(1px); }
/* Stat tiles share one row when there are five. */
.ui-pam-hero { grid-template-columns: repeat(auto-fit, minmax(min(100%, 196px), 1fr)); }

@media (max-width: 640px) {
  .ui-form-row { grid-template-columns: 1fr; }
  .ui-form-stack > .ui-btn, .ui-form-stack > button { flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) {
  input[type="checkbox"], input[type="radio"], .ui-field > input[type="checkbox"], .ui-btn--secondary { transition: none; }
}

/* ── Forms inside tables: a price or a note next to its Save, on one line, centred in the row ───── */
.ui-table th, .ui-table td { vertical-align: middle; }
.ui-table .ui-inline-form { flex-wrap: nowrap; gap: 6px; }
.ui-table .ui-inline-form .ui-input, .ui-table .ui-inline-form .ui-select { min-width: 92px; max-width: 132px; flex: 0 1 112px; min-height: 34px; padding-top: 4px; padding-bottom: 4px; }
.ui-table .ui-inline-form .ui-btn, .ui-table td > form > .ui-btn { min-height: 34px; padding-top: 0; padding-bottom: 0; }

/* Hand-built rows of fields (.ui-row) share the width evenly and sit on one baseline; a button in a stack is as wide as its label. */
.ui-row:has(> .ui-field) { align-items: flex-end; gap: 18px 20px; }
.ui-row > .ui-field { flex: 1 1 200px; min-width: 0; }
.ui-stack > .ui-btn, .ui-stack > button.ui-btn, .ui-stack > .ui-row > .ui-btn { justify-self: start; }
.ui-stack > .ui-row:has(> .ui-btn:only-child) { justify-content: flex-start; }
.ui-row > .ui-select, .ui-row > .ui-input { flex: 1 1 170px; width: auto; min-width: 0; }
.ui-row > .ui-input[name="value"], .ui-row > .ui-input[type="text"]:last-of-type { flex-grow: 1.6; }
:where(.ui-content, .ui-main) > .ui-card + .ui-card { margin-top: 20px; }

/* ── Older pages: bare <label>, <select>, <input>, <fieldset> with no classes get the same look as everything else ── */
.ui-content form select:not([class]), .ui-content form input:not([class]):not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="file"]), .ui-content form textarea:not([class]) {
  width: 100%; min-height: 40px; padding: 8px 12px; font: inherit; font-size: 0.94rem; color: var(--ui-text); background-color: var(--ui-surface);
  border: 1px solid var(--ui-control-border); border-radius: var(--ui-r); transition: border-color var(--ui-dur), box-shadow var(--ui-dur), background-color var(--ui-dur);
}
.ui-content form select:not([class]) { appearance: none; padding-right: 36px; background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23788799' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
.ui-content form textarea:not([class]) { min-height: 96px; resize: vertical; }
.ui-content form select:not([class]):hover, .ui-content form input:not([class]):hover, .ui-content form textarea:not([class]):hover { border-color: var(--ui-accent-ink); background-color: var(--ui-accent-soft); }
.ui-content form select:not([class]):focus, .ui-content form input:not([class]):focus, .ui-content form textarea:not([class]):focus { outline: none; border-color: var(--ui-accent); box-shadow: var(--ui-focus); background-color: var(--ui-surface); }
.ui-content form label[for]:not([class]) { display: block; margin: 16px 0 6px; font-size: 0.84rem; font-weight: 590; color: var(--ui-text-2); }
.ui-content form label[for]:not([class]):first-child { margin-top: 0; }
.ui-content form label:not([class]):not([for]):not(:has(input[type="checkbox"], input[type="radio"])) { display: grid; gap: 6px; margin: 0 0 16px; font-size: 0.84rem; font-weight: 590; color: var(--ui-text-2); }
.ui-content form label:not([class]):has(input[type="checkbox"], input[type="radio"]) { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; font-size: 0.94rem; cursor: pointer; }
.ui-content fieldset { margin: 18px 0; padding: 18px 20px 6px; border: 1px solid var(--ui-border); border-radius: var(--ui-r); background: var(--ui-surface-2); min-width: 0; }
.ui-content fieldset > legend { padding: 0 8px; font-size: 0.9rem; font-weight: 590; color: var(--ui-text); }
.ui-content fieldset > p { margin: 0 0 14px; color: var(--ui-text-2); font-size: 0.88rem; }
.ui-content form div:has(> label[for]:not([class]):first-child + :is(select, input, textarea)) { margin-bottom: 16px; }
.ui-content form .two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 20px; }

/* Cards that sit side by side are one height, so the row reads as one band. */
.ui-grid-2:has(> .ui-card), .ui-grid-stats:has(> .ui-card) { align-items: stretch; }
.ui-grid-2 > .ui-card, .ui-grid-stats > .ui-card { height: 100%; }
/* A filter above a row of tiles keeps a gap from them. */
form + .ui-pam-hero, form + .ui-grid-stats, .ui-field + .ui-pam-hero { margin-top: 20px; }

/* The search box is one box: the wrapper draws the border, the input inside it draws nothing. (The rules for bare inputs above must not reach it.) */
.ui-content form .ui-search input, .ui-search input, .ui-content form .ui-search input:hover, .ui-content form .ui-search input:focus {
  width: 100% !important; min-height: 0 !important; padding: 0 !important; border: 0 !important; border-radius: 0 !important; background: none !important; box-shadow: none !important; outline: none !important; }
.ui-search:focus-within { border-color: var(--ui-accent); box-shadow: var(--ui-focus); }

/* Side-by-side cards are one height wherever they sit (the setting is ignored when they are stacked). */
:has(> .ui-card ~ .ui-card), .integration-grid:has(> .conn) { align-items: stretch; }
.integration-grid { align-items: stretch; }
.integration-grid > .conn { display: flex; flex-direction: column; gap: var(--ui-sp-2); }
.integration-grid > .conn > .conn-card:last-child { flex: 1; }
/* A filter above a card or a row of tiles keeps a gap from it. */
.ui-content > form:has(+ .ui-card), .ui-content > form:has(+ .ui-pam-hero), .ui-content > form:has(+ .ui-grid-stats), .ui-content > .ui-field:has(+ .ui-card) { margin-bottom: 20px; }

/* ── One set of buttons: the older .btn matches .ui-btn, so no page has a button in a different colour ── */
.ui-body .btn:not(.primary):not(.saffron):not(.ghost):not(.subtle):not(.danger) {
  min-height: 36px; padding: 0 14px; border-radius: var(--ui-r); font: 590 0.9rem/1 var(--ui-font); background: var(--ui-surface); color: var(--ui-text);
  border: 1px solid var(--ui-border-strong); box-shadow: none; transition: background-color var(--ui-dur), border-color var(--ui-dur), color var(--ui-dur); }
.ui-body .btn:not(.primary):not(.saffron):not(.ghost):not(.subtle):not(.danger):hover { background: var(--ui-accent-soft); border-color: var(--ui-accent-ink); color: var(--ui-accent-ink); }
.ui-body .btn.primary, .ui-body .btn.saffron {
  min-height: 36px; padding: 0 16px; border-radius: var(--ui-r); font: 590 0.9rem/1 var(--ui-font); color: #14202E; border: 1px solid var(--ui-accent);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0) 60%), linear-gradient(100deg, #0ABFBC 0%, #22D0CD 50%, #0ABFBC 100%); background-size: 100% 100%, 220% 100%; background-position: 0 0, 0% 0;
  box-shadow: 0 1px 2px rgba(10, 191, 188, 0.35); transition: background-position 420ms var(--ui-ease), box-shadow 240ms, transform 160ms; }
.ui-body .btn.primary:hover, .ui-body .btn.saffron:hover { background-position: 0 0, 100% 0; box-shadow: 0 8px 18px -8px rgba(10, 191, 188, 0.75); transform: none; }

/* A card that sticks keeps sticking (the action-line rule above sets position: relative, which would push a sticky card down by its offset). */
.ui-card.pp-gl:has(form) { position: sticky; }
@media (max-width: 960px) { .ui-card.pp-gl:has(form) { position: static; } }
/* Audit-style tables: every row has the same separator all the way across. */
.ui-table tbody tr > td { border-bottom: 1px solid var(--ui-border); }
.ui-table tbody tr:last-child > td { border-bottom: 0; }

/* Tiles in a grid are one height and their buttons sit on one line along the bottom. */
.integration-grid { grid-auto-rows: 1fr; }
.integration-grid:has(> form.card) > form.card { display: flex; flex-direction: column; justify-content: flex-start; gap: 12px; height: 100%; margin: 0; }
.integration-grid:has(> form.card.inset) > form.card.inset > :is(div, p):last-of-type:has(> button, > .ui-btn) { margin-top: auto; }
.integration-grid:has(> .conn) { grid-auto-rows: auto; }

/* Extra height from a taller neighbour is never spread between the parts of a card: parts stay together at the top. */
.card.stack, .ui-card.stack, form.card.stack, section.card.stack { align-content: start; }
.ui-form-row > .checkbox-row, .ui-form-row > .ui-check, .ui-form-row > .ui-switch { min-height: 42px; align-items: center; }

/* A card title always has room below it, whatever follows (a label, a paragraph, a form). */
.card > h3:first-child, form.card > h3:first-child, section.card > h3:first-child, .ui-card__title + * { margin-top: 0; }
.card > h3:first-child, form.card > h3:first-child, section.card > h3:first-child, .card.inset > h3:first-child { margin-bottom: 14px; font-size: 1.04rem; }
.card.stack > h3:first-child { margin-bottom: 4px; }
/* Details/summary lists look like one list. */
.ui-content details > summary { cursor: pointer; padding: 6px 0; font-weight: 590; color: var(--ui-text-2); transition: color var(--ui-dur); }
.ui-content details > summary:hover { color: var(--ui-accent-ink); }
.ui-content details[open] > summary { color: var(--ui-text); margin-bottom: 8px; }
.checkbox-row, .ui-check { margin-bottom: 0; }
.ui-form-row > .checkbox-row, .ui-form-row > .ui-check { margin: 0; }

/* ── File pickers: a real control, with a clear gap before the button that follows it ─────────────── */
input[type="file"] { width: 100%; min-height: 44px; padding: 6px; font: inherit; font-size: 0.92rem; color: var(--ui-text-2); background: var(--ui-surface); border: 1px dashed var(--ui-control-border); border-radius: var(--ui-r); cursor: pointer; margin-bottom: 14px; transition: border-color var(--ui-dur), background-color var(--ui-dur); }
input[type="file"]:hover { border-color: var(--ui-accent-ink); background: var(--ui-accent-soft); }
input[type="file"]::file-selector-button { margin-right: 12px; padding: 7px 14px; font: 590 0.88rem var(--ui-font); color: var(--ui-text); background: var(--ui-surface); border: 1px solid var(--ui-border-strong); border-radius: var(--ui-r-sm); cursor: pointer; transition: background-color var(--ui-dur), border-color var(--ui-dur); }
input[type="file"]::file-selector-button:hover { background: var(--ui-accent-soft); border-color: var(--ui-accent-ink); }

/* ── Choice cards: a group of radios reads as a list of options, the chosen one highlighted ───────── */
.ui-fieldset { display: grid; gap: 10px; border: 0; padding: 0; margin: 0; min-width: 0; }
.ui-fieldset > br { display: none; }
label.ui-radio { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 1px solid var(--ui-border); border-radius: var(--ui-r); cursor: pointer; background: var(--ui-surface);
  transition: border-color var(--ui-dur), background-color var(--ui-dur), box-shadow var(--ui-dur); }
label.ui-radio:hover { border-color: var(--ui-accent-ink); background: var(--ui-accent-soft); }
label.ui-radio:has(input:checked) { border-color: var(--ui-accent); background: var(--ui-accent-soft); box-shadow: 0 0 0 1px var(--ui-accent) inset; }
label.ui-radio > input { margin-top: 2px; }
label.ui-radio > b { white-space: nowrap; }
label.ui-radio > .ui-muted { flex: 1; }

/* Rows that start with a coloured dot keep the dot beside the first line of text, never on a line of its own. */
div:has(> .dot:first-child) { align-items: flex-start !important; }
div > .dot:first-child { flex: none; margin-top: 7px; }
div:has(> .dot:first-child) { flex-wrap: nowrap !important; }
div:has(> .dot:first-child) > span:not(.dot) { flex: 1 1 0; min-width: 0; }

/* Cards without padding are for tables. Anything else put in one (a form, a note, a list of options) gets the same side margin as a padded card. */
.ui-card--flush > .ui-card__body > :is(form, details, pre, fieldset, .ui-field, .ui-form-stack, .ui-form-row, h3, .ui-alert, .ui-muted, p:not([style*="padding"])) { margin-inline: 24px; }
.ui-card--flush > .ui-card__body > :is(form, details, fieldset, .ui-form-stack, .ui-form-row):first-child { margin-top: 4px; }
.ui-card--flush > .ui-card__body > :is(form, details, fieldset, .ui-form-stack, .ui-form-row):last-child { margin-bottom: 24px; }
.ui-card--flush > .ui-card__body > p:not([style*="padding"]):last-child { margin-bottom: 18px; }
.ui-card--flush > .ui-card__body > form > input[type="file"] { width: 100%; }

/* Hand-written cards put their content straight inside the card (no body wrapper): it gets the card's own side margin and room at the bottom. */
.ui-card > :is(form, details, pre, fieldset, .ui-field, .ui-form-stack, .ui-form-row, .ui-alert, .ui-list, ul:not(.ui-list), p) { margin-inline: 24px; }
.ui-card > :is(form, details, fieldset, .ui-form-stack, .ui-form-row, .ui-list, ul, p):last-child { margin-bottom: 24px; }
.ui-card > .ui-card__head + :is(form, details, fieldset, .ui-form-stack, .ui-form-row, .ui-list, ul, p) { margin-top: 14px; }
.ui-card > .ui-card__head { flex-wrap: wrap; align-items: baseline; gap: 2px 20px; }
.ui-card > .ui-card__head > :is(h2, h3) { margin: 0; font-size: 1.04rem; font-weight: 590; letter-spacing: -0.01em; }
.ui-card > .ui-card__head > p { margin: 0; font-size: 0.86rem; color: var(--ui-text-2); }
.ui-card > form.pi-upload { display: grid; gap: 14px; justify-items: start; }
.ui-card > form.pi-upload > input[type="file"] { justify-self: stretch; margin: 0; }

/* Pagers, toolbars and grids inside a card without padding keep a side margin. */
.ui-card--flush > .ui-card__body > :is(nav.ui-pager, .ui-pager, .pp-pager, .ui-toolbar, .apps-grid) { padding-inline: 20px; }
.ui-card--flush > .ui-card__body > .apps-grid { padding-block: 16px; }
.ui-card--flush > .ui-card__body > :is(.ui-pager, .pp-pager, nav.ui-pager) { padding-block: 12px; }
/* Stacked blocks of a field (label, control, hint) keep a steady gap between one field and the next. */
.ui-card__body > .ui-field + .ui-field, .ui-card > form > .ui-field + .ui-field, form > .ui-field + .ui-field { margin-top: 16px; }
.apps-kv > * + * { margin-top: 2px; }

[data-kind-panel] > .ui-field + .ui-field, .ui-field + [data-kind-panel], [data-kind-panel] + .ui-field, [data-kind-panel] + [data-kind-panel] { margin-top: 16px; }
.ui-card__body > .ui-field + .ui-field, .ui-card__body > .ui-field + [data-kind-panel] { margin-top: 16px; }
