/* =============================================================
 * Myra · Components — "Stripe Lumen" (Phase 2A · Step 2)
 *
 * All component classes are prefixed `ml-` (Myra Lumen) so they
 * never collide with legacy class names already used by templates
 * (.btn, .card, .badge, …). Migration screen-by-screen will swap
 * legacy classes for these.
 *
 * Strict rule: every value here resolves through a token from
 * design-tokens.css. No inline hex codes. No magic numbers.
 * ============================================================= */

/* ===== Hero gradient utility =============================== */
/* Use on hero bands, billing-success surfaces, and 1–2 empty
   states — never as a default page bg. Mobile (<600px) drops to
   a flat warm surface so content remains the focus. */
.ml-hero-gradient {
  background: var(--gradient-hero);
}
@media (max-width: 599px) {
  .ml-hero-gradient {
    background: var(--gradient-hero-fallback);
  }
}

/* ===== Buttons ============================================ */
.ml-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: 1;
  padding: var(--space-3) var(--space-5);
  min-height: 44px; /* mobile touch target */
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}
.ml-btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}
.ml-btn:disabled,
.ml-btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Variants */
.ml-btn--primary {
  background: var(--brand-primary);
  color: var(--text-inverse);
}
.ml-btn--primary:hover {
  background: var(--brand-primary-hover);
  color: var(--text-inverse);
  text-decoration: none;
}
.ml-btn--primary:active {
  background: var(--brand-primary-active);
}

.ml-btn--secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.ml-btn--secondary:hover {
  background: var(--bg-deeper);
  color: var(--text-primary);
  text-decoration: none;
}

.ml-btn--ghost {
  background: transparent;
  color: var(--text-primary);
}
.ml-btn--ghost:hover {
  background: var(--bg-deeper);
  color: var(--text-primary);
  text-decoration: none;
}

.ml-btn--destructive {
  background: var(--error);
  color: var(--text-inverse);
}
.ml-btn--destructive:hover {
  background: #B73E3E;
  color: var(--text-inverse);
  text-decoration: none;
}

/* Sizes */
.ml-btn--sm {
  font-size: var(--text-xs);
  padding: var(--space-2) var(--space-3);
  min-height: 32px;
  border-radius: var(--radius-sm);
}
.ml-btn--lg {
  font-size: var(--text-base);
  padding: var(--space-4) var(--space-8);
  min-height: 52px;
  border-radius: var(--radius-lg);
}

/* Loading state — keeps clickable area, swaps content for spinner */
.ml-btn--loading {
  pointer-events: none;
  position: relative;
  color: transparent !important;
}
.ml-btn--loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-bottom-color: transparent;
  border-radius: var(--radius-full);
  animation: ml-spin 600ms linear infinite;
  color: var(--text-inverse);
}
.ml-btn--secondary.ml-btn--loading::after,
.ml-btn--ghost.ml-btn--loading::after {
  color: var(--text-primary);
}
@keyframes ml-spin {
  to { transform: rotate(360deg); }
}

.ml-btn--full { width: 100%; }


/* ===== Card =============================================== */
.ml-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
}
.ml-card--elevated {
  box-shadow: var(--shadow-md);
  border-color: transparent;
}
.ml-card--bordered {
  border-color: var(--border-strong);
  box-shadow: none;
}
.ml-card__header {
  margin: calc(var(--space-6) * -1) calc(var(--space-6) * -1) var(--space-5);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}
.ml-card__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
  margin: 0;
}
.ml-card__subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--space-1);
}
.ml-card__body {
  /* default — padding handled by .ml-card */
}
.ml-card__footer {
  margin: var(--space-5) calc(var(--space-6) * -1) calc(var(--space-6) * -1);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}


/* ===== Form controls ===================================== */
.ml-field { margin-bottom: var(--space-5); }
.ml-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}
.ml-help {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: var(--space-2);
}
.ml-error-msg {
  font-size: var(--text-xs);
  color: var(--error);
  margin-top: var(--space-2);
}

.ml-input,
.ml-select,
.ml-textarea {
  width: 100%;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  min-height: 44px;
  outline: none;
  transition:
    border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}
.ml-input::placeholder,
.ml-textarea::placeholder {
  color: var(--text-tertiary);
}
.ml-input:hover:not(:focus),
.ml-select:hover:not(:focus),
.ml-textarea:hover:not(:focus) {
  border-color: var(--brand-primary-hover);
}
.ml-input:focus,
.ml-select:focus,
.ml-textarea:focus {
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-focus);
}
.ml-input--error,
.ml-select--error,
.ml-textarea--error {
  border-color: var(--error);
}
.ml-input--error:focus,
.ml-select--error:focus,
.ml-textarea--error:focus {
  box-shadow: 0 0 0 4px rgba(210, 76, 76, 0.18);
}
.ml-textarea {
  resize: vertical;
  min-height: 96px;
  line-height: var(--leading-normal);
}
.ml-select {
  cursor: pointer;
  appearance: none;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23878598' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'></polyline></svg>");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-10);
}

/* Checkbox + radio (custom, accessible) */
.ml-checkbox,
.ml-radio {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-primary);
}
.ml-checkbox input,
.ml-radio input {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg-elevated);
  cursor: pointer;
  margin: 0;
  flex-shrink: 0;
  transition: all var(--duration-fast) var(--ease-out);
  position: relative;
}
.ml-checkbox input { border-radius: var(--radius-xs); }
.ml-radio input { border-radius: var(--radius-full); }
.ml-checkbox input:checked,
.ml-radio input:checked {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
}
.ml-checkbox input:checked::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>") center/12px no-repeat;
}
.ml-radio input:checked::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: var(--radius-full);
  background: var(--text-inverse);
}
.ml-checkbox input:focus-visible,
.ml-radio input:focus-visible {
  box-shadow: var(--shadow-focus);
  outline: none;
}

/* Switch */
.ml-switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-primary);
}
.ml-switch input {
  appearance: none;
  width: 36px;
  height: 22px;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  position: relative;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out);
  flex-shrink: 0;
  margin: 0;
}
.ml-switch input::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  background: #FFFFFF;
  border-radius: var(--radius-full);
  top: 3px;
  left: 3px;
  transition: left var(--duration-base) var(--ease-out);
  box-shadow: var(--shadow-xs);
}
.ml-switch input:checked {
  background: var(--brand-primary);
}
.ml-switch input:checked::after {
  left: 17px;
}
.ml-switch input:focus-visible {
  box-shadow: var(--shadow-focus);
  outline: none;
}


/* ===== Badges ============================================ */
.ml-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  line-height: 1;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  background: var(--bg-deeper);
  color: var(--text-secondary);
  white-space: nowrap;
}
.ml-badge--success { background: var(--success-bg); color: var(--success); }
.ml-badge--warning { background: var(--warning-bg); color: var(--warning); }
.ml-badge--error   { background: var(--error-bg);   color: var(--error); }
.ml-badge--info    { background: var(--info-bg);    color: var(--info); }
.ml-badge--soft    { background: var(--brand-soft); color: var(--brand-primary); }
.ml-badge--peach   { background: var(--brand-accent-2-soft); color: #A65A30; }


/* ===== Table ============================================ */
.ml-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}
.ml-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  color: var(--text-primary);
}
.ml-table thead th {
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-secondary);
  background: var(--bg-deeper);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.ml-table tbody td {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.ml-table tbody tr:last-child td { border-bottom: none; }
.ml-table--striped tbody tr:nth-child(even) td { background: var(--bg-primary); }
.ml-table--compact thead th { padding: var(--space-2) var(--space-3); }
.ml-table--compact tbody td { padding: var(--space-2) var(--space-3); }
.ml-table tbody tr:hover td { background: var(--bg-deeper); }


/* ===== Tabs + chips ===================================== */
.ml-tabs {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--bg-deeper);
  padding: var(--space-1);
  border-radius: var(--radius-md);
}
.ml-tab {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: none;
  background: transparent;
  transition: color var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-out);
}
.ml-tab:hover { color: var(--text-primary); }
.ml-tab--active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
}

.ml-chips { display: inline-flex; flex-wrap: wrap; gap: var(--space-2); }
.ml-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
}
.ml-chip:hover {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}
.ml-chip--active {
  background: var(--brand-soft);
  border-color: var(--brand-soft-hover);
  color: var(--brand-primary);
}


/* ===== Skeleton ========================================= */
.ml-skeleton {
  display: block;
  background: linear-gradient(90deg,
    var(--bg-deeper) 0%,
    #EBE8DF 50%,
    var(--bg-deeper) 100%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: ml-shimmer 1.4s infinite;
  min-height: 12px;
}
.ml-skeleton--text { height: 14px; margin: 6px 0; }
.ml-skeleton--title { height: 24px; width: 60%; margin: 8px 0; }
.ml-skeleton--avatar { width: 40px; height: 40px; border-radius: var(--radius-full); }
.ml-skeleton--card {
  /* Placeholder for card-shaped blocks (stats tile, partner-card, etc.). */
  height: 96px;
  border-radius: var(--radius-xl);
  margin: var(--space-3) 0;
}
.ml-skeleton--bubble {
  /* Chat message placeholder for inbox/agent threads. Default left-aligned. */
  height: 38px;
  border-radius: var(--radius-lg);
  margin: var(--space-2) 0;
  max-width: 70%;
}
.ml-skeleton--bubble-right { margin-left: auto; }
@keyframes ml-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}


/* ===== Modal ============================================ */
.ml-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 12, 32, 0.45);
  backdrop-filter: blur(4px);
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: ml-fade-in var(--duration-base) var(--ease-out);
}
.ml-modal {
  background: var(--bg-elevated);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow: auto;
  z-index: var(--z-modal);
  animation: ml-modal-in var(--duration-slow) var(--ease-out);
}
.ml-modal__header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}
.ml-modal__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
}
.ml-modal__close {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  display: inline-flex;
}
.ml-modal__close:hover { background: var(--bg-deeper); color: var(--text-primary); }
.ml-modal__body { padding: var(--space-6); }
.ml-modal__footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}
@keyframes ml-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes ml-modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}


/* ===== Empty state ====================================== */
.ml-empty {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-secondary);
}
.ml-empty__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--brand-soft);
  color: var(--brand-primary);
  margin-bottom: var(--space-4);
}
.ml-empty__title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}
.ml-empty__desc {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  max-width: 36ch;
  margin: 0 auto var(--space-5);
  line-height: var(--leading-relaxed);
}


/* ===== Alerts =========================================== */
.ml-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}
.ml-alert__icon { flex-shrink: 0; display: inline-flex; }
.ml-alert__body { flex: 1; }
.ml-alert__title { font-weight: var(--weight-semibold); margin-bottom: var(--space-1); }
.ml-alert--info    { background: var(--info-bg);    border-color: var(--info-border);    color: var(--info); }
.ml-alert--success { background: var(--success-bg); border-color: var(--success-border); color: var(--success); }
.ml-alert--warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }
.ml-alert--error   { background: var(--error-bg);   border-color: var(--error-border);   color: var(--error); }

.ml-alert__sub { color: inherit; opacity: 0.85; font-size: var(--text-sm); }
.ml-alert--actionable { align-items: center; flex-wrap: wrap; }
.ml-alert--actionable .ml-btn { flex-shrink: 0; }
@media (max-width: 600px) {
  .ml-alert--actionable { align-items: flex-start; }
  .ml-alert--actionable .ml-btn { width: 100%; margin-top: var(--space-2); }
}


/* ===== Type utilities (used in styleguide and beyond) ===== */
.ml-eyebrow {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--text-tertiary);
}
.ml-display {
  font-family: var(--font-display);
  letter-spacing: var(--tracking-tighter);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  color: var(--text-primary);
}
.ml-mono {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
}
