/* =============================================================================
   SortedTrade — UI primitives
   Modal, toast, wizard, tabs, tier-gate overlay, demo-controls dropdown.
   Inherits design tokens from /style.css.
   ============================================================================= */

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

/* Skeleton loader — placeholder shimmer for content not yet hydrated.
   Mark any element with `data-skeleton` and (optionally) set width/height
   inline. Pages should reveal via `delete document.body.dataset.pageLoading`
   once JS finishes painting. */
[data-page-loading] [data-skeleton] {
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.10) 50%, rgba(255,255,255,0.04) 100%);
  background-size: 200% 100%;
  border-radius: 6px;
  color: transparent !important;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  min-height: 0.7rem;
  display: inline-block;
  min-width: 2rem;
}
[data-page-loading] [data-skeleton] * { visibility: hidden; }
[data-page-loading] .stat-tile-value[data-skeleton] { min-height: 1.8rem; width: 4rem; }
[data-page-loading] .stat-tile-label[data-skeleton] { min-height: 0.85rem; width: 60%; }
[data-page-loading] h1[data-skeleton] { min-height: 2rem; width: 18rem; }
[data-page-loading] .sub[data-skeleton] { min-height: 1rem; width: 24rem; }
[data-page-loading] .activity-icon[data-skeleton] { width: 36px !important; height: 36px !important; border-radius: 50% !important; }

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

/* Once the page hydrates, all skeleton styling vanishes */
body:not([data-page-loading]) [data-skeleton] {
  background: transparent !important;
  animation: none !important;
}

@media (prefers-reduced-motion: reduce) {
  [data-skeleton] { animation: none !important; }
}

/* Visually-hidden but still announced by screen readers */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Reduce motion for users who request it */
@media (prefers-reduced-motion: reduce) {
  .st-modal-overlay, .st-modal, .st-toast { animation-duration: 0.01ms !important; }
  .st-toast { transition: none !important; }
}

/* ----------------------------------------------------------------------------
   Modal
   ---------------------------------------------------------------------------- */

body.st-modal-open { overflow: hidden; }

.st-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(8, 10, 16, 0.6);
  backdrop-filter: blur(12px) saturate(160%);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  display: flex; align-items: center; justify-content: center;
  padding: 2rem 1rem;
  animation: stModalIn 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
.st-modal-overlay.closing { animation: stModalOut 0.15s ease forwards; }

@keyframes stModalIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes stModalOut { from { opacity: 1; } to { opacity: 0; } }

.st-modal {
  background: linear-gradient(180deg, rgba(30,35,48,0.95), rgba(20,25,35,0.95));
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  box-shadow: 0 24px 80px -16px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.08);
  width: 100%;
  max-width: 540px;
  max-height: calc(100vh - 4rem);
  display: flex; flex-direction: column;
  animation: stModalSlide 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.st-modal-sm  { max-width: 400px; }
.st-modal-md  { max-width: 540px; }
.st-modal-lg  { max-width: 720px; }
.st-modal-xl  { max-width: 960px; }

@keyframes stModalSlide { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.st-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.st-modal-header h2 {
  margin: 0;
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.st-modal-close {
  background: none; border: none;
  color: var(--text-mute);
  font-size: 1.5rem;
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.st-modal-close:hover { background: rgba(255,255,255,0.08); color: #fff; }

.st-modal-body {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  color: var(--text-dim);
  flex: 1;
}
.st-modal-body p { margin: 0 0 0.75rem; line-height: 1.5; }
.st-modal-body p:last-child { margin-bottom: 0; }

.st-modal-actions {
  display: flex; gap: 0.5rem; justify-content: flex-end;
  padding: 1rem 1.5rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* ----------------------------------------------------------------------------
   Toast
   ---------------------------------------------------------------------------- */

#st-toast-container {
  position: fixed;
  top: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column;
  gap: 0.6rem;
  z-index: 5000;
  pointer-events: none;
  max-width: 380px;
}

.st-toast {
  display: flex; align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  background: linear-gradient(180deg, rgba(40,45,60,0.95), rgba(28,32,44,0.95));
  border: 1px solid rgba(255,255,255,0.10);
  border-left: 3px solid var(--primary);
  border-radius: 12px;
  box-shadow: 0 12px 32px -8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.05);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 500;
  pointer-events: auto;
  transform: translateX(40px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}
.st-toast.visible { transform: translateX(0); opacity: 1; }

.st-toast-icon  { font-size: 1.1rem; line-height: 1; flex-shrink: 0; }
.st-toast-body  { flex: 1; line-height: 1.35; }
.st-toast-close {
  background: none; border: none; color: var(--text-mute);
  font-size: 1.1rem; cursor: pointer;
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px;
}
.st-toast-close:hover { background: rgba(255,255,255,0.08); color: #fff; }
.st-toast-action {
  background: var(--primary-tint);
  border: 1px solid rgba(255,107,0,0.3);
  color: var(--primary-soft);
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  font-size: 0.78rem; font-weight: 600;
  cursor: pointer;
}

.st-toast-success { border-left-color: var(--status-success); }
.st-toast-warn    { border-left-color: var(--status-warn); }
.st-toast-error   { border-left-color: var(--status-error); }
.st-toast-info    { border-left-color: var(--status-info); }

/* ----------------------------------------------------------------------------
   Wizard
   ---------------------------------------------------------------------------- */

.st-wizard {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 16px;
  padding: 1.5rem;
}

.st-wizard-progress {
  display: flex; align-items: center;
  gap: 0;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.st-wizard-step {
  display: flex; flex-direction: column;
  align-items: center; gap: 0.4rem;
  flex-shrink: 0;
}
.st-wizard-step-bullet {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text-mute);
  font-size: 0.85rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.st-wizard-step-label { font-size: 0.75rem; color: var(--text-mute); }
.st-wizard-step.active .st-wizard-step-bullet  { background: var(--primary-tint); border-color: var(--primary); color: var(--primary-soft); }
.st-wizard-step.active .st-wizard-step-label   { color: #fff; font-weight: 600; }
.st-wizard-step.done   .st-wizard-step-bullet  { background: rgba(34,197,94,0.18); border-color: rgba(34,197,94,0.3); color: #4ade80; }

.st-wizard-step-bar {
  flex: 1; height: 1px;
  background: rgba(255,255,255,0.10);
  margin: 0 0.6rem;
  align-self: center;
  margin-top: -1.2rem;
}

.st-wizard-body { min-height: 200px; }
.st-wizard-body.shake { animation: stShake 0.4s; }
@keyframes stShake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}

.st-wizard-body label {
  display: block;
  color: #fff; font-size: 0.85rem; font-weight: 600;
  margin: 1rem 0 0.35rem;
}
.st-wizard-body input[type="text"],
.st-wizard-body input[type="email"],
.st-wizard-body input[type="tel"],
.st-wizard-body input[type="number"],
.st-wizard-body input[type="url"],
.st-wizard-body select,
.st-wizard-body textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  color: #fff;
  font-size: 0.92rem;
  font-family: inherit;
  transition: all 0.15s;
}
.st-wizard-body input:focus,
.st-wizard-body select:focus,
.st-wizard-body textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: rgba(255,255,255,0.06);
}
.st-wizard-body .hint {
  color: var(--text-mute); font-size: 0.78rem;
  margin: 0.35rem 0 0;
}

.st-wizard-actions {
  display: flex; gap: 0.5rem; justify-content: space-between;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.st-wizard-actions button[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ----------------------------------------------------------------------------
   Tabs
   ---------------------------------------------------------------------------- */

.st-tabs {}
.st-tabs-strip {
  display: flex;
  gap: 0.2rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 1.5rem;
  overflow-x: auto;
}
.st-tab {
  background: none; border: none;
  padding: 0.7rem 1rem;
  color: var(--text-mute);
  font-size: 0.88rem; font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: inline-flex; align-items: center; gap: 0.4rem;
  white-space: nowrap;
  transition: all 0.15s;
}
.st-tab:hover { color: #fff; }
.st-tab.active {
  color: #fff;
  border-bottom-color: var(--primary);
}
.st-tab .badge {
  background: var(--primary-tint);
  color: var(--primary-soft);
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}
.st-tab-panel {}

/* ----------------------------------------------------------------------------
   Tier gate overlay
   ---------------------------------------------------------------------------- */

[data-pro-gate] { min-height: 200px; }

.st-pro-overlay {
  position: absolute; inset: 0;
  background: rgba(8, 10, 16, 0.75);
  backdrop-filter: blur(8px) saturate(140%);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
  border-radius: inherit;
}
.st-pro-overlay-card {
  background: linear-gradient(180deg, rgba(30,35,48,0.95), rgba(20,25,35,0.95));
  border: 1px solid rgba(255,107,0,0.3);
  border-radius: 14px;
  padding: 1.5rem 2rem;
  text-align: center;
  max-width: 380px;
}
.st-pro-overlay-badge {
  display: inline-block;
  background: var(--primary-tint);
  color: var(--primary-soft);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}
.st-pro-overlay-card h3 {
  color: #fff;
  font-size: 1.15rem;
  margin: 0 0 0.4rem;
}
.st-pro-overlay-card p {
  color: var(--text-dim);
  font-size: 0.88rem;
  line-height: 1.45;
  margin: 0 0 1rem;
}

/* ----------------------------------------------------------------------------
   Demo controls dropdown
   ---------------------------------------------------------------------------- */

.st-demo-trigger {
  position: fixed;
  bottom: 1.25rem; right: 1.25rem;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #fff;
  border: none;
  width: 48px; height: 48px;
  border-radius: 50%;
  font-size: 1.2rem; font-weight: 800;
  cursor: pointer;
  box-shadow: 0 12px 32px -8px rgba(0,0,0,0.4);
  z-index: 4000;
  transition: transform 0.15s;
}
.st-demo-trigger:hover { transform: scale(1.08); }

.st-demo-panel {
  position: fixed;
  bottom: 5rem; right: 1.25rem;
  width: 320px;
  background: linear-gradient(180deg, rgba(30,35,48,0.97), rgba(20,25,35,0.97));
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  box-shadow: 0 24px 60px -12px rgba(0,0,0,0.6);
  z-index: 4000;
  padding: 1rem;
  max-height: 70vh;
  overflow-y: auto;
}

.st-demo-panel h4 {
  color: #fff;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 1rem 0 0.5rem;
  font-weight: 700;
  color: var(--text-mute);
}
.st-demo-panel h4:first-child { margin-top: 0; }

.st-demo-panel select,
.st-demo-panel button {
  width: 100%;
  padding: 0.55rem 0.7rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 8px;
  color: #fff;
  font-size: 0.83rem;
  font-family: inherit;
  cursor: pointer;
  margin-bottom: 0.4rem;
  transition: all 0.15s;
  text-align: left;
}
.st-demo-panel button:hover { background: rgba(255,255,255,0.08); }
.st-demo-panel select { background-image: none; }

.st-demo-panel .hint {
  color: var(--text-mute);
  font-size: 0.75rem;
  line-height: 1.4;
  margin: 0.25rem 0 0.6rem;
}

.st-demo-panel-footer {
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 0.75rem;
  margin-top: 0.75rem;
  color: var(--text-mute);
  font-size: 0.72rem;
  line-height: 1.4;
}
