/*!
 * Stake Credit Builder widget styles — Stake Web SDK
 *
 * All rules are scoped to .stake-cb / .stake-cb-* so they don't collide with
 * host page CSS or with other Stake Web SDK widgets (which use their own
 * widget-specific class prefix). Theming is done via CSS custom properties;
 * clients can override them by passing `theme` to mount() (which applies them
 * as inline custom properties on the widget root) or by setting them on a
 * parent element in their own CSS.
 *
 * The .stake-cb class is the widget "namespace" — it carries variables, font,
 * color, and box-sizing only. Visual chrome (background, border, radius,
 * shadow, padding) lives on per-view classes (.stake-cb-card,
 * .stake-cb-history, .stake-cb-overlay-card) so the same .stake-cb class can
 * also be applied to the overlay backdrop without inheriting card chrome.
 */

.stake-cb {
  --stake-cb-accent: #0F8F4A;
  --stake-cb-accent-text: #ffffff;
  --stake-cb-bg: #ffffff;
  --stake-cb-surface: #ffffff;
  --stake-cb-text: #0F1219;
  --stake-cb-muted: #6B7180;
  --stake-cb-border: #E6E8EE;
  --stake-cb-danger: #C53434;
  --stake-cb-radius: 12px;
  --stake-cb-radius-sm: 8px;
  --stake-cb-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --stake-cb-shadow: 0 1px 2px rgba(15, 18, 25, 0.04), 0 4px 16px rgba(15, 18, 25, 0.06);
  --stake-cb-shadow-overlay: 0 12px 40px rgba(15, 18, 25, 0.22), 0 4px 12px rgba(15, 18, 25, 0.10);

  font-family: var(--stake-cb-font);
  color: var(--stake-cb-text);
  box-sizing: border-box;
}

.stake-cb *,
.stake-cb *::before,
.stake-cb *::after { box-sizing: border-box; }

.stake-cb p,
.stake-cb h2,
.stake-cb h3,
.stake-cb h4 { margin: 0; }

.stake-cb button {
  font: inherit;
}

/* ---------- Per-view chrome (card + history) ---------------------------- */

.stake-cb-card,
.stake-cb-history {
  background: var(--stake-cb-bg);
  border: 1px solid var(--stake-cb-border);
  border-radius: var(--stake-cb-radius);
  box-shadow: var(--stake-cb-shadow);
}

.stake-cb-card {
  padding: 24px;
}

.stake-cb-card-inner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

.stake-cb-eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--stake-cb-accent);
  margin-bottom: -4px;
}

.stake-cb-title {
  font-size: 20px;
  line-height: 1.3;
  font-weight: 600;
}

.stake-cb-description {
  font-size: 14px;
  line-height: 1.5;
  color: var(--stake-cb-muted);
}

.stake-cb-meta {
  font-size: 12px;
  color: var(--stake-cb-muted);
}

/* ---------- Icon circle ------------------------------------------------- */

.stake-cb-icon-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--stake-cb-accent) 12%, transparent);
  color: var(--stake-cb-accent);
}

.stake-cb-icon-circle svg {
  width: 22px;
  height: 22px;
}

.stake-cb-icon-circle--lg {
  width: 56px;
  height: 56px;
}

.stake-cb-icon-circle--lg svg {
  width: 30px;
  height: 30px;
}

.stake-cb-icon-circle--success {
  background: color-mix(in srgb, #1E9E5C 14%, transparent);
  color: #1E9E5C;
}

.stake-cb-icon-circle--muted {
  background: color-mix(in srgb, var(--stake-cb-muted) 14%, transparent);
  color: var(--stake-cb-muted);
}

/* ---------- Buttons ----------------------------------------------------- */

.stake-cb-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--stake-cb-radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease;
  min-height: 40px;
  background: transparent;
  color: inherit;
}

.stake-cb-button:focus-visible {
  outline: 2px solid var(--stake-cb-accent);
  outline-offset: 2px;
}

.stake-cb-button[disabled],
.stake-cb-button.is-disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

/* Busy state: hide the label, reveal a centered spinner. The button stays the
   same size so the dialog doesn't reflow. */
.stake-cb-button-spinner {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.stake-cb-button.is-busy {
  cursor: progress;
  pointer-events: none;
  opacity: 1;
}

.stake-cb-button.is-busy .stake-cb-button-label {
  visibility: hidden;
}

.stake-cb-button.is-busy .stake-cb-button-spinner {
  display: inline-flex;
}

.stake-cb-spinner {
  width: 18px;
  height: 18px;
  animation: stake-cb-spin 0.9s linear infinite;
}

@keyframes stake-cb-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .stake-cb-spinner { animation-duration: 1.8s; }
}

.stake-cb-button--primary {
  background: var(--stake-cb-accent);
  color: var(--stake-cb-accent-text);
  width: 100%;
  margin-top: 4px;
}

.stake-cb-button--primary:hover:not([disabled]) {
  background: color-mix(in srgb, var(--stake-cb-accent) 88%, #000);
}

.stake-cb-button--ghost {
  background: transparent;
  color: var(--stake-cb-text);
  border-color: var(--stake-cb-border);
}

.stake-cb-button--ghost:hover:not([disabled]) {
  background: color-mix(in srgb, var(--stake-cb-text) 4%, transparent);
}

.stake-cb-button--danger {
  background: var(--stake-cb-danger);
  color: #ffffff;
}

.stake-cb-button--danger:hover:not([disabled]) {
  background: color-mix(in srgb, var(--stake-cb-danger) 88%, #000);
}

.stake-cb-button svg {
  width: 16px;
  height: 16px;
}

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

.stake-cb-skeleton {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 0;
}

.stake-cb-skeleton-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--stake-cb-text) 6%, transparent) 0%,
    color-mix(in srgb, var(--stake-cb-text) 12%, transparent) 50%,
    color-mix(in srgb, var(--stake-cb-text) 6%, transparent) 100%
  );
  background-size: 200% 100%;
  animation: stake-cb-skeleton 1.4s ease-in-out infinite;
}

.stake-cb-skeleton-line--lg { height: 22px; width: 70%; }
.stake-cb-skeleton-line--sm { height: 12px; width: 40%; }

@keyframes stake-cb-skeleton {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .stake-cb-skeleton-line { animation: none; }
}

/* ---------- Error state ------------------------------------------------ */

.stake-cb-error {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 0 4px;
}

.stake-cb-error-message {
  font-size: 14px;
  color: var(--stake-cb-muted);
}

/* ---------- Modal overlay (body-attached) ------------------------------ */

.stake-cb-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, #0F1219 55%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 2147483646;
  animation: stake-cb-fade 140ms ease-out;
}

.stake-cb-overlay-card {
  position: relative;
  background: var(--stake-cb-surface);
  border-radius: var(--stake-cb-radius);
  padding: 32px 24px 24px;
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  box-shadow: var(--stake-cb-shadow-overlay);
  animation: stake-cb-pop 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.stake-cb-overlay-card:focus { outline: none; }

.stake-cb-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

.stake-cb-overlay-title {
  font-size: 20px;
  line-height: 1.3;
  font-weight: 600;
}

.stake-cb-overlay-body {
  font-size: 14px;
  line-height: 1.5;
  color: var(--stake-cb-muted);
}

.stake-cb-overlay-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.stake-cb-overlay-actions--row {
  flex-direction: row;
}

.stake-cb-overlay-actions--row .stake-cb-button {
  flex: 1;
  min-width: 0;
  margin-top: 0;
}

.stake-cb-overlay-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: 0;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--stake-cb-muted);
  cursor: pointer;
  padding: 0;
  transition: background-color 120ms ease, color 120ms ease;
}

.stake-cb-overlay-close:hover {
  background: color-mix(in srgb, var(--stake-cb-text) 6%, transparent);
  color: var(--stake-cb-text);
}

.stake-cb-overlay-close:focus-visible {
  outline: 2px solid var(--stake-cb-accent);
  outline-offset: 2px;
}

.stake-cb-overlay-close svg {
  width: 16px;
  height: 16px;
}

.stake-cb-overlay-back {
  position: absolute;
  top: 12px;
  left: 12px;
  background: transparent;
  border: 0;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--stake-cb-muted);
  cursor: pointer;
  padding: 0;
  transition: background-color 120ms ease, color 120ms ease;
}

.stake-cb-overlay-back:hover {
  background: color-mix(in srgb, var(--stake-cb-text) 6%, transparent);
  color: var(--stake-cb-text);
}

.stake-cb-overlay-back:focus-visible {
  outline: 2px solid var(--stake-cb-accent);
  outline-offset: 2px;
}

.stake-cb-overlay-back svg {
  width: 18px;
  height: 18px;
}

@keyframes stake-cb-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes stake-cb-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .stake-cb-overlay,
  .stake-cb-overlay-card { animation: none; }
}

/* ---------- Intro modal content ---------------------------------------- */

.stake-cb-intro {
  align-items: center;
  text-align: center;
}

.stake-cb-intro .stake-cb-overlay-title {
  margin-top: 8px;
}

.stake-cb-divider {
  width: 100%;
  height: 1px;
  background: var(--stake-cb-border);
  margin: 12px 0 4px;
}

.stake-cb-intro-bullets {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.stake-cb-intro-bullet {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--stake-cb-text);
}

.stake-cb-bullet-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--stake-cb-accent);
  margin-top: 7px;
}

/* ---------- Consent step (signature + checkbox) ----------------------- */

.stake-cb-consent.stake-cb-overlay-inner {
  align-items: stretch;
  text-align: left;
  gap: 16px;
}

.stake-cb-consent .stake-cb-overlay-title {
  margin-top: 12px;
}

.stake-cb-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.stake-cb-section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--stake-cb-text);
}

.stake-cb-input {
  width: 100%;
  padding: 12px 14px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  color: var(--stake-cb-text);
  background: var(--stake-cb-surface);
  border: 1px solid var(--stake-cb-border);
  border-radius: var(--stake-cb-radius-sm);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.stake-cb-input::placeholder {
  color: color-mix(in srgb, var(--stake-cb-muted) 70%, transparent);
}

.stake-cb-input:focus {
  border-color: var(--stake-cb-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--stake-cb-accent) 18%, transparent);
}

.stake-cb-input--error,
.stake-cb-input--error:focus {
  border-color: var(--stake-cb-danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--stake-cb-danger) 18%, transparent);
}

.stake-cb-input-hint {
  font-size: 12px;
  color: var(--stake-cb-muted);
}

.stake-cb-input-error {
  font-size: 12px;
  color: var(--stake-cb-danger);
}

.stake-cb-submit-error {
  font-size: 13px;
  line-height: 1.4;
  color: var(--stake-cb-danger);
  text-align: center;
  width: 100%;
}

.stake-cb-consent-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
}

.stake-cb-checkbox {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1.5px solid var(--stake-cb-border);
  background: var(--stake-cb-surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  margin-top: 1px;
  color: transparent;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.stake-cb-checkbox.is-checked {
  background: var(--stake-cb-accent);
  border-color: var(--stake-cb-accent);
  color: var(--stake-cb-accent-text);
}

.stake-cb-checkbox:focus-visible {
  outline: 2px solid var(--stake-cb-accent);
  outline-offset: 2px;
}

.stake-cb-checkbox svg {
  width: 12px;
  height: 12px;
}

.stake-cb-consent-text {
  font-size: 13px;
  line-height: 1.5;
  color: var(--stake-cb-text);
}

/* ---------- Confirm dialog content ------------------------------------- */

.stake-cb-confirm .stake-cb-overlay-title {
  margin-top: 4px;
}

/* ---------- History widget --------------------------------------------- */

.stake-cb-history {
  padding: 20px 24px 8px;
}

.stake-cb-history-header {
  margin-bottom: 12px;
}

.stake-cb-history-title {
  font-size: 16px;
  font-weight: 600;
}

.stake-cb-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.stake-cb-history-row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 0;
  border-top: 1px solid var(--stake-cb-border);
}

.stake-cb-history-row:first-child { border-top: 0; }

.stake-cb-history-row-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  background: color-mix(in srgb, var(--stake-cb-muted) 14%, transparent);
  color: var(--stake-cb-muted);
}

.stake-cb-history-row-icon svg {
  width: 18px;
  height: 18px;
}

.stake-cb-history-row--reported .stake-cb-history-row-icon {
  background: color-mix(in srgb, #1E9E5C 14%, transparent);
  color: #1E9E5C;
}

.stake-cb-history-row--late .stake-cb-history-row-icon {
  background: color-mix(in srgb, var(--stake-cb-danger) 14%, transparent);
  color: var(--stake-cb-danger);
}

.stake-cb-history-row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stake-cb-history-row-period {
  font-size: 14px;
  font-weight: 600;
}

.stake-cb-history-row-status {
  font-size: 13px;
  color: var(--stake-cb-muted);
}

.stake-cb-history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  padding: 24px 8px 32px;
}

.stake-cb-history-empty-text {
  font-size: 14px;
  color: var(--stake-cb-muted);
  max-width: 280px;
}

/* ---------- Dark-host fallback ----------------------------------------- */

@media (prefers-color-scheme: dark) {
  .stake-cb:not([data-stake-cb-theme]) {
    --stake-cb-bg: #0F1219;
    --stake-cb-surface: #161A24;
    --stake-cb-text: #F2F3F7;
    --stake-cb-muted: #9CA1B0;
    --stake-cb-border: #232838;
    --stake-cb-shadow: 0 1px 2px rgba(0,0,0,0.4), 0 4px 16px rgba(0,0,0,0.4);
    --stake-cb-shadow-overlay: 0 12px 40px rgba(0,0,0,0.6), 0 4px 12px rgba(0,0,0,0.4);
  }
}
