/*
 * UI System — badges, bulk-table chrome, and undo toasts.
 * Loaded globally after styles.css / responsive.css (see components/header.php).
 * Behaviour lives in assets/js/ui-system.js.
 */

:root {
  /* Semantic badge tokens */
  --badge-urgent: #dc2626;   /* action / decision required */
  --badge-status: #16a34a;   /* presence / active state */
  --surface-bg: #ffffff;
}

/* ── Phase 1: Notification badges ─────────────────────────── */

.icon-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/*
 * Pinned to the host's top-right corner. min-width + padding-inline let the pill
 * grow from "1" to "99+" outward without shifting the icon underneath.
 */
.badge-count {
  position: absolute;
  top: -6px;
  right: -8px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  box-sizing: border-box;
  border-radius: 999px;
  background-color: var(--badge-urgent, #dc2626);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 18px;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  transform-origin: left center;
  /* Ring drawn with box-shadow so it never affects layout. */
  box-shadow: 0 0 0 2px var(--surface-bg, #ffffff);
  z-index: 1;
}

.badge-dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--badge-status, #16a34a);
  box-shadow: 0 0 0 2px var(--surface-bg, #ffffff);
  pointer-events: none;
}

.badge-count.is-hidden,
.badge-dot.is-hidden {
  display: none !important;
}

/* ── Phase 2: Bulk table chrome ───────────────────────────── */

tr.is-paged-out,
tr.is-bulk-pending {
  display: none !important;
}

.admin-table tr.is-selected > td {
  background-color: rgba(37, 99, 235, 0.06);
}

.bulk-btn-count {
  font-variant-numeric: tabular-nums;
  white-space: pre;
}

.bulk-scope-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 6px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--color-border, #e5e7eb);
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 0.82rem;
  text-align: center;
}

.bulk-scope-banner[hidden] {
  display: none;
}

.bulk-scope-link {
  position: relative;
  border: 0;
  padding: 2px 4px;
  background: none;
  color: #1d4ed8;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.bulk-scope-link::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  min-width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
}

.bulk-scope-link:focus-visible,
.bulk-page-btn:focus-visible,
.ui-toast-action:focus-visible,
.ui-toast-close:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.bulk-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 10px 14px;
  border-top: 1px solid var(--color-border, #e5e7eb);
  font-size: 0.82rem;
  color: var(--color-text-muted, #64748b);
}

.bulk-pagination[hidden] {
  display: none;
}

.bulk-pagination-summary,
.bulk-pagination-page {
  font-variant-numeric: tabular-nums;
}

.bulk-pagination-controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.bulk-page-btn {
  min-width: 44px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--color-border, #d1d5db);
  border-radius: 8px;
  background: #ffffff;
  color: var(--color-text, #1f2937);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.bulk-page-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── Toasts (undo queue) ──────────────────────────────────── */

.ui-toast-stack {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 10050;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(480px, calc(100vw - 24px));
  transform: translateX(-50%);
  pointer-events: none;
}

.ui-toast {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 10px 14px 16px;
  overflow: hidden;
  border-radius: 12px;
  background: #111827;
  color: #f9fafb;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.28);
  font-size: 0.9rem;
  pointer-events: auto;
  animation: ui-toast-in 160ms ease-out;
}

.ui-toast--danger {
  background: #7f1d1d;
}

.ui-toast.is-leaving {
  opacity: 0;
  transition: opacity 160ms ease;
}

.ui-toast-message {
  flex: 1 1 auto;
  min-width: 0;
}

.ui-toast-action {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: transparent;
  color: #93c5fd;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.ui-toast-close {
  position: relative;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: rgba(249, 250, 251, 0.75);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.ui-toast-close::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
}

.ui-toast-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.15);
}

.ui-toast-progress > span {
  display: block;
  height: 100%;
  background: #60a5fa;
  transform-origin: left center;
  animation-name: ui-toast-countdown;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes ui-toast-countdown {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

@keyframes ui-toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .ui-toast {
    animation: none;
  }
}

/* Keep toasts clear of the fixed mobile bottom navigation. */
@media (max-width: 768px) {
  .ui-toast-stack {
    bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  }
}

@media (hover: hover) and (pointer: fine) {
  .bulk-page-btn:not(:disabled):hover {
    background: #f3f4f6;
  }

  .ui-toast-action:hover {
    background: rgba(255, 255, 255, 0.1);
  }

  .ui-toast-close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
  }

  .bulk-scope-link:hover {
    color: #1e40af;
  }
}
