/* ==========================================================================
   BoostaMe — component primitives
   Every value here comes from boostame-tokens.css. No literal colours, sizes,
   radii or durations. If a component needs a value that does not exist as a
   token, the token is missing -- add it there, not here.

   Namespaced `.bm-` so these coexist with Bootstrap 4 in the admin without a
   specificity war during the migration.
   ========================================================================== */

/* ---------------------------------------------------------------- button */

.bm-btn {
  --btn-bg: transparent;
  --btn-fg: var(--text-primary);
  --btn-border: var(--border-default);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);

  padding: 0.5625rem var(--space-4);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);

  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: var(--weight-medium);
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;

  transition:
    background var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    transform var(--dur-instant) var(--ease-out);
}

.bm-btn:active:not(:disabled) { transform: scale(0.985); }

.bm-btn:disabled,
.bm-btn[aria-disabled='true'] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Indigo. The only colour permitted on a primary affordance. */
.bm-btn--primary {
  --btn-bg: var(--color-action);
  --btn-fg: var(--color-action-text);
  --btn-border: var(--color-action);
}
.bm-btn--primary:hover:not(:disabled) {
  --btn-bg: var(--color-action-hover);
  --btn-border: var(--color-action-hover);
}

.bm-btn--secondary { --btn-bg: var(--surface-raised); }
.bm-btn--secondary:hover:not(:disabled) {
  --btn-bg: var(--surface-overlay);
  --btn-border: var(--border-strong);
}

.bm-btn--ghost { --btn-border: transparent; --btn-fg: var(--text-secondary); }
.bm-btn--ghost:hover:not(:disabled) {
  --btn-bg: var(--surface-hover);
  --btn-fg: var(--text-primary);
}

.bm-btn--danger {
  --btn-bg: var(--color-error);
  --btn-fg: var(--raw-white);
  --btn-border: var(--color-error);
}

.bm-btn--sm { padding: 0.375rem var(--space-3); font-size: var(--fs-sm); }
.bm-btn--lg { padding: 0.75rem var(--space-6); font-size: var(--fs-lg); }
.bm-btn--block { width: 100%; }

/* Loading state. The label stays in the DOM so the button does not resize and
   shift the layout under the user's cursor mid-click. */
.bm-btn[data-loading='true'] {
  color: transparent !important;
  pointer-events: none;
  position: relative;
}
.bm-btn[data-loading='true']::after {
  content: '';
  position: absolute;
  width: 1rem;
  height: 1rem;
  border: 2px solid currentColor;
  border-top-color: var(--btn-fg);
  border-radius: var(--radius-full);
  color: var(--btn-fg);
  opacity: 0.9;
  animation: bm-spin 0.6s linear infinite;
}
@keyframes bm-spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- input */

.bm-field { display: flex; flex-direction: column; gap: var(--space-2); }

.bm-label {
  font-size: var(--fs-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}
.bm-label[data-required]::after {
  content: '*';
  color: var(--color-error);
  margin-inline-start: 2px;
}

.bm-input,
.bm-select,
.bm-textarea {
  width: 100%;
  padding: 0.5625rem var(--space-3);
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--fs-base);
  line-height: 1.4;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}

.bm-input::placeholder,
.bm-textarea::placeholder { color: var(--text-disabled); }

.bm-input:hover:not(:disabled),
.bm-select:hover:not(:disabled) { border-color: var(--border-default); }

.bm-input:focus,
.bm-select:focus,
.bm-textarea:focus {
  outline: none;
  border-color: var(--color-action);
  box-shadow: var(--shadow-focus);
}

.bm-input[aria-invalid='true'] {
  border-color: var(--color-error);
}
.bm-input[aria-invalid='true']:focus {
  box-shadow: 0 0 0 3px var(--color-error-subtle);
}

/* Money inputs and any field holding a number get tabular figures. */
.bm-input[inputmode='decimal'],
.bm-input[inputmode='numeric'],
.bm-input[type='number'] {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
}

.bm-hint { font-size: var(--fs-sm); color: var(--text-muted); }
.bm-error {
  font-size: var(--fs-sm);
  color: var(--color-error);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* Password field with reveal toggle */
.bm-password { position: relative; }
.bm-password .bm-input { padding-inline-end: 2.75rem; }
.bm-password__toggle {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-end: var(--space-2);
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: var(--space-2);
  color: var(--text-muted);
  cursor: pointer;
  line-height: 0;
}
.bm-password__toggle:hover { color: var(--text-primary); }

/* Strength meter. Four segments rather than a percentage bar -- a discrete
   scale is easier to read at a glance than a continuous one. */
.bm-strength { display: flex; gap: var(--space-1); margin-top: var(--space-2); }
.bm-strength__seg {
  height: 3px;
  flex: 1;
  background: var(--border-subtle);
  border-radius: var(--radius-full);
  transition: background var(--dur-normal) var(--ease-out);
}
.bm-strength[data-score='1'] .bm-strength__seg:nth-child(-n+1),
.bm-strength[data-score='2'] .bm-strength__seg:nth-child(-n+2) { background: var(--color-error); }
.bm-strength[data-score='3'] .bm-strength__seg:nth-child(-n+3) { background: var(--color-pending); }
.bm-strength[data-score='4'] .bm-strength__seg { background: var(--color-delivered); }

/* ---------------------------------------------------------------- card */

.bm-card {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-5);
}

.bm-card--interactive {
  transition: transform var(--dur-normal) var(--ease-out),
              border-color var(--dur-normal) var(--ease-out);
}
.bm-card--interactive:hover {
  transform: translateY(-3px);
  border-color: var(--border-default);
}

.bm-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.bm-card__title {
  margin: 0;
  font-size: var(--fs-h3);
  font-weight: var(--weight-semi);
  letter-spacing: var(--tracking-snug);
}

/* ---------------------------------------------------------------- stat */

.bm-stat__label {
  font-size: var(--fs-xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
}
.bm-stat__value {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 1.75rem;
  font-weight: var(--weight-semi);
  line-height: var(--leading-tight);
  margin-top: var(--space-2);
}
.bm-stat__value--money { color: var(--color-money); }
.bm-stat__delta { font-size: var(--fs-sm); margin-top: var(--space-1); }
.bm-stat__delta--up   { color: var(--color-delivered); }
.bm-stat__delta--down { color: var(--color-error); }

/* ---------------------------------------------------------------- badge */

.bm-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.1875rem var(--space-2);
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  font-size: var(--fs-xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  white-space: nowrap;
}
.bm-badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: var(--radius-full);
  background: currentColor;
}

.bm-badge--completed { color: var(--color-delivered); background: var(--color-delivered-subtle); border-color: var(--color-delivered-border); }
.bm-badge--pending   { color: var(--color-pending);   background: var(--color-pending-subtle); }
.bm-badge--failed    { color: var(--color-error);     background: var(--color-error-subtle);   border-color: var(--color-error-border); }
.bm-badge--info      { color: var(--color-info);      background: var(--color-info-subtle);    border-color: var(--color-info-border); }
.bm-badge--neutral   { color: var(--text-muted);      background: var(--surface-overlay); }

/* ---------------------------------------------------------------- table */

.bm-table-wrap {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: auto;
}
.bm-table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }

.bm-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-overlay);
  padding: var(--space-3) var(--space-4);
  text-align: start;
  font-size: var(--fs-xs);
  font-weight: var(--weight-semi);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.bm-table tbody td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.bm-table tbody tr:last-child td { border-bottom: none; }
.bm-table tbody tr { transition: background var(--dur-fast) var(--ease-out); }
.bm-table tbody tr:hover { background: var(--surface-hover); }

/* Numeric columns right-align with tabular figures, so magnitudes are
   comparable by eye down the column. */
.bm-table [data-col='num'],
.bm-table [data-col='money'] {
  text-align: end;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}
.bm-table [data-col='money'] { color: var(--color-money); }

/* ---------------------------------------------------------------- progress
   Progress always runs left-to-right, even in RTL: it represents elapsed
   time, not reading order. Mirroring it makes it read as depletion. */

.bm-progress {
  height: 6px;
  background: var(--border-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
  direction: ltr;
}
.bm-progress__fill {
  height: 100%;
  width: 0;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--raw-emerald-600), var(--color-delivered));
  transition: width var(--dur-slow) var(--ease-out);
}

/* ---------------------------------------------------------------- skeleton */

.bm-skeleton {
  background: linear-gradient(90deg,
    var(--surface-overlay) 25%,
    var(--border-subtle) 37%,
    var(--surface-overlay) 63%);
  background-size: 400% 100%;
  border-radius: var(--radius-sm);
  animation: bm-shimmer 1.2s ease-in-out infinite;
}
@keyframes bm-shimmer { to { background-position: -135% 0; } }

/* ---------------------------------------------------------------- empty state
   An empty table is not an error. It is a moment to tell someone what to do
   next, which is the highest-leverage UX surface in the product. */

.bm-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-14) var(--space-6);
  gap: var(--space-3);
}
.bm-empty__icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: var(--color-action-subtle);
  color: var(--color-action);
  margin-bottom: var(--space-1);
}
.bm-empty__title {
  margin: 0;
  font-size: var(--fs-h3);
  font-weight: var(--weight-semi);
}
.bm-empty__body {
  margin: 0;
  max-width: 34ch;
  color: var(--text-muted);
  font-size: var(--fs-base);
}

/* ---------------------------------------------------------------- toast */

.bm-toasts {
  position: fixed;
  inset-block-start: var(--space-4);
  inset-inline-end: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.bm-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-width: 18rem;
  max-width: 24rem;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-overlay);
  border: 1px solid var(--border-default);
  border-inline-start: 3px solid var(--color-info);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: bm-toast-in var(--dur-normal) var(--ease-out);
}
.bm-toast--success { border-inline-start-color: var(--color-delivered); }
.bm-toast--error   { border-inline-start-color: var(--color-error); }
.bm-toast--warning { border-inline-start-color: var(--color-pending); }

@keyframes bm-toast-in {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: none; }
}
[dir='rtl'] @keyframes bm-toast-in {
  from { opacity: 0; transform: translateX(-12px); }
}

/* ---------------------------------------------------------------- modal */

.bm-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background: rgba(7, 8, 13, 0.7);
  backdrop-filter: blur(3px);
  animation: bm-fade var(--dur-fast) var(--ease-out);
}
.bm-modal {
  position: fixed;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  transform: translate(-50%, -50%);
  z-index: var(--z-modal);
  width: min(32rem, calc(100vw - 2rem));
  max-height: calc(100vh - 4rem);
  overflow: auto;
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: bm-modal-in var(--dur-normal) var(--ease-out);
}
@keyframes bm-fade { from { opacity: 0; } }
@keyframes bm-modal-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.97); }
}

/* ---------------------------------------------------------------- reveal */

.bm-reveal {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity var(--dur-reveal) var(--ease-out),
              transform var(--dur-reveal) var(--ease-out);
}
.bm-reveal.is-visible { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .bm-reveal { opacity: 1 !important; transform: none !important; }
}
