/* ================================================================
   CryptoSetype Shared UI Components
   ================================================================
   Depends on tokens.css custom properties.
   ================================================================ */


/* ── Keyframes ──────────────────────────────────────────────────── */

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

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

@keyframes fadeOut {
  to { opacity: 0; transform: translateX(20px); }
}


/* ================================================================
   Buttons
   ================================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  line-height: 1.4;
  text-decoration: none;
}

.btn svg {
  width: 16px;
  height: 16px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Variants */

.btn.btn-primary {
  background: #18181b;
  color: #fff;
  border-color: #18181b;
}
.btn.btn-primary:hover:not(:disabled) {
  background: #27272a;
}

.btn.btn-primary-inverse {
  background: #fff;
  color: #09090b;
  border-color: #fff;
  font-weight: 600;
}
.btn.btn-primary-inverse:hover:not(:disabled) {
  opacity: 0.9;
}

.btn.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-default);
}
.btn.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

.btn.btn-danger {
  background: var(--color-error);
  color: #fff;
}
.btn.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn.btn-success {
  background: var(--color-success);
  color: #fff;
}
.btn.btn-success:hover:not(:disabled) {
  background: #16a34a;
}

/* Sizes */

.btn-sm {
  padding: 6px 12px;
  font-size: var(--text-sm);
}

.btn-lg {
  padding: 14px 32px;
  font-size: var(--text-md);
}

/* Shape */

.btn-pill {
  border-radius: var(--radius-pill);
}


/* ================================================================
   Inputs
   ================================================================ */

.input {
  width: 100%;
  padding: 11px 14px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  outline: none;
  transition: border var(--transition-fast);
}

.input::placeholder {
  color: var(--text-muted);
}

.input:focus {
  border-color: var(--input-focus-border);
}

.select {
  width: 100%;
  padding: 9px 36px 9px 14px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  outline: none;
  transition: border var(--transition-fast);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.select::placeholder {
  color: var(--text-muted);
}

.select:focus {
  border-color: var(--input-focus-border);
}

/* Form groups */

.form-group {
  margin-bottom: var(--sp-4);
}

.form-group label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
}


/* ================================================================
   Cards
   ================================================================ */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
}

.card-padded {
  padding: var(--sp-6);
}


/* ================================================================
   Tables
   ================================================================ */

.table-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-wrap.overflow-x {
  overflow-x: auto;
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
}

.table-wrap thead th {
  background: var(--bg-elevated);
  padding: 10px var(--sp-4);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.table-wrap tbody td {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-base);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.table-wrap tbody tr:last-child td {
  border-bottom: none;
}

.table-wrap tbody tr:hover {
  background: var(--bg-hover);
}

.table-wrap td.mono {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.table-wrap td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table-wrap td.truncate {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


/* ================================================================
   Badges
   ================================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 3px 10px;
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.5;
}

.badge-success {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.badge-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.badge-error {
  background: var(--color-error-bg);
  color: var(--color-error);
}

.badge-info {
  background: var(--color-info-bg);
  color: var(--color-info);
}

.badge-neutral {
  background: var(--bg-elevated);
  color: var(--text-secondary);
}


/* ================================================================
   Status Dots
   ================================================================ */

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-success { background: var(--color-success); }
.dot-warning { background: var(--color-warning); }
.dot-error   { background: var(--color-error); }
.dot-info    { background: var(--color-info); }
.dot-neutral { background: var(--text-muted); }

.dot-pulse {
  animation: pulse 2s ease infinite;
}


/* ================================================================
   Spinner
   ================================================================ */

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-default);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-sm {
  width: 16px;
  height: 16px;
  border-width: 1.5px;
}

.spinner-lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}


/* ================================================================
   Error Message
   ================================================================ */

.error-msg {
  background: var(--color-error-bg);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: var(--color-error);
  font-size: var(--text-sm);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-5);
  display: none;
  line-height: 1.5;
}

.error-msg.visible {
  display: block;
  animation: fadeUp 0.25s;
}


/* ================================================================
   Notices
   ================================================================ */

.notice {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: 1.45;
  border: 1px solid transparent;
  display: none;
}

.notice.visible {
  display: block;
}

.notice.info {
  display: block;
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #334155;
}

.notice.warn {
  display: block;
  background: #fffbeb;
  border-color: #fcd34d;
  color: #92400e;
}

.notice.error {
  display: block;
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}

.notice.success {
  display: block;
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
}


/* ================================================================
   Toast Container
   ================================================================ */

.toast-container {
  position: fixed;
  top: var(--sp-5);
  right: var(--sp-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: var(--font-sans);
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.3s;
  cursor: pointer;
  max-width: 380px;
  background: #18181b;
  color: #fff;
  border: 1px solid #27272a;
}

.toast.removing {
  animation: fadeOut 0.2s forwards;
}

.toast-success { background: #18181b; color: #fff; border-color: #27272a; }
.toast-error   { background: #18181b; color: #fff; border-color: #27272a; }
.toast-warning { background: #18181b; color: #fff; border-color: #27272a; }
.toast-info    { background: #18181b; color: #fff; border-color: #27272a; }

.toast-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.toast-success .toast-dot { background: var(--color-success); }
.toast-error   .toast-dot { background: var(--color-error); }
.toast-warning .toast-dot { background: var(--color-warning); }
.toast-info    .toast-dot { background: var(--color-info); }


/* ================================================================
   Modal
   ================================================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-modal-backdrop);
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  animation: fadeIn 0.15s;
}

.modal-backdrop.active {
  display: flex;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: scaleIn 0.2s;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-6) var(--sp-6) 0;
}

.modal-header h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--sp-1);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
  font-size: 20px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: var(--sp-5) var(--sp-6);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
  padding: 0 var(--sp-6) var(--sp-6);
}


/* ================================================================
   Stats Grid
   ================================================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-8);
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--sp-5) var(--sp-6);
}

.stat-label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
}

.stat-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}


/* ================================================================
   Filter Bar
   ================================================================ */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}

.filter-bar label {
  font-size: var(--text-base);
  color: var(--text-secondary);
  font-weight: 500;
}


/* ================================================================
   Page Header
   ================================================================ */

.page-header {
  margin-bottom: var(--sp-8);
}

.page-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  margin-bottom: var(--sp-1);
}

.page-subtitle {
  font-size: var(--text-base);
  color: var(--text-secondary);
  font-weight: 400;
}


/* ================================================================
   Section Headers (Landing)
   ================================================================ */

.section-eyebrow {
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: var(--sp-4);
}

.section-heading {
  font-size: clamp(30px, 4vw, 44px);
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--text-primary);
  margin-bottom: 14px;
}

.section-subtext {
  font-size: 17px;
  max-width: 500px;
  line-height: 1.65;
  font-weight: 300;
  color: var(--text-secondary);
  margin-bottom: var(--sp-16);
}


/* ================================================================
   Responsive
   ================================================================ */

@media (max-width: 768px) {
  .hide-mobile {
    display: none !important;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 769px) {
  .show-mobile-only {
    display: none !important;
  }
}

/* ---- Shared data-list (wh-*/dl-*) — used by dashboard + admin (Spec F) ---- */
.wh-list { background: #fff; border: 1px solid var(--border-default); border-radius: 12px; overflow: hidden; }
.wh-row { display: flex; align-items: flex-start; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--border-subtle); transition: background .12s; }
.wh-row.dl-clickable:hover { background: #fafafa; }
.wh-row:last-child { border-bottom: none; }
.wh-row:hover { background: #fafafa; }
.wh-dot { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; }
.wh-dot-delivered { background: #16a34a; }
.wh-dot-pending { background: #d97706; }
.wh-dot-failed { background: #dc2626; }
.wh-main { flex: 1 1 auto; min-width: 0; }
.wh-line1 { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.wh-event { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 13px; font-weight: 600; color: var(--text-heading); word-break: break-all; }
.wh-meta { margin-top: 4px; font-size: 12px; color: var(--text-secondary); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.wh-meta-dot { color: var(--text-muted); }
.wh-http-ok { color: #166534; font-weight: 500; }
.wh-http-bad { color: #991b1b; font-weight: 500; }
.wh-http-none { color: var(--text-muted); }
.wh-actions { flex: 0 0 auto; display: flex; align-items: center; gap: 6px; }
.wh-detail { margin-top: 12px; border-top: 1px dashed var(--border-default); padding-top: 12px; display: none; }
.wh-detail.open { display: block; }
.wh-detail-grid { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 12px; margin-bottom: 10px; }
.wh-detail-key { color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-size: 11px; align-self: center; }
.wh-detail-val { color: var(--text-body); word-break: break-all; }
.wh-detail-val .copy-inline { margin-left: 6px; cursor: pointer; color: var(--text-secondary); font-size: 11px; text-decoration: underline; }
.wh-body-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.wh-body { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 12px; color: #3f3f46; white-space: pre-wrap; word-break: break-all; margin: 0; max-height: 200px; overflow: auto; background: #fafafa; border: 1px solid var(--border-default); border-radius: 8px; padding: 10px 12px; }
.wh-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-weight: 400; }
.wh-empty { padding: 40px 24px; text-align: center; }
.wh-empty-icon { color: var(--text-muted); margin-bottom: 10px; }
.wh-empty-title { font-size: 14px; font-weight: 600; color: var(--text-heading); }
.wh-empty-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; max-width: 380px; margin-left: auto; margin-right: auto; }
.wh-skeleton { padding: 14px 16px; }
.wh-skeleton-row { height: 14px; border-radius: 6px; background: linear-gradient(90deg, #f1f1f3 25%, #e7e7ea 37%, #f1f1f3 63%); background-size: 400% 100%; animation: wh-shimmer 1.3s ease infinite; margin-bottom: 10px; }
@keyframes wh-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
@media (max-width: 600px) {
  .wh-row { flex-wrap: wrap; }
  .wh-actions { width: 100%; margin-top: 8px; padding-left: 23px; }
}
