/* ============================================================
   ui.css — shared admin page/list contracts (UI_SCREEN_FIX_PLAN Package A)
   Loaded AFTER Bootstrap by base.html and base_embed.html, so these rules do
   not lose to Bootstrap the way components.css rules can (it loads before
   Bootstrap). Standalone calculator pages do not load this file.
   Live examples: /styleguide → "Lists" tab.
   ============================================================ */

/* ── Button size scale ──
   Bootstrap has no .btn-xs and its .btn rule (same specificity, loaded later)
   overrode components.css, so XS rendered larger than Small. The doubled class
   wins regardless of load order. Order: standard > .btn-sm (dense) > .btn-xs. */
.btn.btn-xs {
  padding: 2px 8px;
  font-size: 11px;
  line-height: 1.4;
  border-radius: var(--r-sm);
}

/* ── Page header: title + count, actions at the end ── */
.ui-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-3);
}
.ui-header-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.ui-header-count { font-size: 12px; color: var(--text-tertiary); }
.ui-header-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.ui-header-actions .btn { min-height: var(--control-h); }

/* ── List card: toolbar, table or cards, pager ── */
.ui-list {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  overflow: hidden;
}
/* Positioned, so absolutely positioned descendants (e.g. .visually-hidden
   header labels) are clipped by the scroll box instead of widening the page. */
.ui-list,
.ui-table-wrap { position: relative; }
.ui-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--gray-25);
}
.ui-toolbar .ui-search { flex: 1 1 200px; max-width: 320px; min-width: 0; }
/* components.css `input[type=text]` padding outranks Bootstrap .form-control-sm,
   which made the search box taller than the selects beside it. */
.ui-toolbar .form-control-sm { padding: .25rem .5rem; font-size: .875rem; }
.ui-toolbar .form-select { width: auto; max-width: 220px; }
.ui-toolbar-meta {
  margin-inline-start: auto;
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
}

/* Sortable headers (docs/12 §3.1a) */
th.ui-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.ui-sortable:hover { color: var(--brand-700); }
th.ui-sortable .sort-icon { opacity: .35; font-size: .75em; margin-inline-start: 3px; }
th.ui-sortable.asc .sort-icon,
th.ui-sortable.desc .sort-icon { opacity: 1; color: var(--brand-700); }

/* Loading / empty / error row and card message */
.ui-empty { text-align: center; padding: var(--sp-8) var(--sp-4); color: var(--text-tertiary); }
.ui-empty .bi { display: block; font-size: 2rem; opacity: .35; margin-bottom: var(--sp-2); }

/* ── Pager (renderPager() in admin-core.js) ── */
.ui-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding: var(--sp-2) var(--sp-3);
  border-top: 1px solid var(--border-subtle);
}
.ui-pager[hidden] { display: none; }
.ui-pager-pages { display: flex; gap: 4px; flex-wrap: wrap; }
.ui-pager-btn {
  min-width: var(--control-h-dense);
  height: var(--control-h-dense);
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  background: var(--surface-card);
  color: var(--text-primary);
  font-size: 12px;
}
.ui-pager-btn:hover:not(:disabled) { background: var(--brand-50); border-color: var(--brand-200); }
.ui-pager-btn.active {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: var(--text-inverse);
  font-weight: 600;
}
.ui-pager-btn:disabled { opacity: .4; cursor: default; }
.ui-pager-gap { padding: 0 4px; color: var(--text-tertiary); align-self: center; }
.ui-pager-info { font-size: 12px; color: var(--text-tertiary); }

/* ── Mobile cards: the desktop table is replaced, not squeezed ──
   Mark the list container .ui-has-cards; render rows into .ui-table-wrap and
   the same data into .ui-cards. Every action of the row must exist on its card. */
.ui-cards { display: none; }
.ui-card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-width: 0;
}
.ui-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-2); }
.ui-card-head > :first-child { flex: 1; min-width: 0; }
/* Status chip/select keeps its natural width (components.css gives every
   select width:100%) and never shrinks into an ellipsis. */
.ui-card-head > :not(:first-child) { flex: none; width: auto; max-width: 50%; }
.ui-card-head .pill { max-width: none; }
.ui-card-title { font-weight: 600; color: var(--text-primary); overflow-wrap: anywhere; min-width: 0; }
.ui-card-sub { font-size: 12px; color: var(--text-tertiary); overflow-wrap: anywhere; }
.ui-card-fields {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px var(--sp-3);
  margin: 0;
  font-size: 13px;
}
.ui-card-fields dt { font-weight: 400; color: var(--text-tertiary); }
.ui-card-fields dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.ui-card-actions {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  align-items: center;
  padding-top: var(--sp-2);
  border-top: 1px solid var(--border-subtle);
}

/* Cards are touch layouts, including the dense-list tablet variant. */
.ui-card-actions .act-btn { width: var(--touch-target); height: var(--touch-target); font-size: 1rem; }
.ui-card .status-select { min-height: var(--touch-target); font-size: .875rem; }
/* Keep the switch compact while its enclosing label supplies the hit area. */
.ui-card .ui-switch-target {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  padding: 0;
  cursor: pointer;
}
.ui-card .ui-switch-target .form-check-input { float: none; margin: 0; width: 32px; height: 16px; }

/* Dense lists opt into cards through tablet widths instead of squeezing columns. */
@media (max-width: 1199.98px) {
  .ui-has-cards-tablet .ui-table-wrap { display: none; }
  .ui-has-cards-tablet .ui-cards { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-2); }
  .ui-header-actions .btn { min-height: var(--touch-target); }
  .ui-has-cards-tablet .ui-toolbar .btn,
  .ui-has-cards-tablet .ui-toolbar .form-select,
  .ui-has-cards-tablet .ui-toolbar .form-control { min-height: var(--touch-target); }
  .ui-has-cards-tablet .ui-toolbar .btn { min-width: var(--touch-target); }
  .ui-has-cards-tablet .ui-pager-btn { min-width: var(--touch-target); height: var(--touch-target); }
}

@media (max-width: 767.98px) {
  .ui-has-cards .ui-table-wrap { display: none; }
  .ui-has-cards .ui-cards { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-2); }
  .ui-toolbar .ui-search { flex-basis: 100%; max-width: none; }
  .ui-toolbar .form-select { flex: 1 1 140px; max-width: none; }
  .ui-toolbar-meta { flex-basis: 100%; margin-inline-start: 0; }
  .ui-toolbar .btn,
  .ui-toolbar .form-select,
  .ui-toolbar .form-control { min-height: var(--touch-target); }
  .ui-toolbar .btn { min-width: var(--touch-target); justify-content: center; }
  .ui-pager { justify-content: center; }
  .ui-pager-btn { min-width: var(--touch-target); height: var(--touch-target); }
}
