/**
 * @source-master Market Movers Widget & Price Chart Modal — MTG Engine
 * Compact card strip + modale con grafico storico prezzi stile TradingView.
 * @version 2.0.0
 */

/* ==========================================================================
   COMPACT MARKET STRIP
   ========================================================================== */
.tsb-market-strip { width: 100%; margin: 0; }

.tsb-market-strip-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.tsb-ms-live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
  flex-shrink: 0;
  animation: tsbMsPulse 2s ease-in-out infinite;
}

@keyframes tsbMsPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

.tsb-ms-title {
  font-size: .98rem;
  font-weight: 700;
  color: var(--tsb-text-title, #f1f5f9);
  margin: 0;
}

.tsb-ms-period-tag {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(212,175,55,.14);
  color: #d4af37;
  border: 1px solid rgba(212,175,55,.28);
}

/* Grid: 5 colonne desktop, scroll su mobile */
.tsb-market-strip-scroller {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px;
}

/* Card singola */
.tsb-ms-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--tsb-surface-card, rgba(19,23,34,.95));
  border: 1px solid var(--tsb-surface-card-border, rgba(255,255,255,.07));
  border-radius: 10px;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-width: 0;
}

.tsb-ms-card:hover,
.tsb-ms-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(255,255,255,.18);
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  outline: none;
}

.tsb-ms-card:focus-visible {
  box-shadow: 0 0 0 2px #d4af37, 0 6px 18px rgba(0,0,0,.35);
}

/* Thumbnail */
.tsb-ms-thumb {
  width: 38px;
  height: 53px;
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
  background: #000;
  border: 1px solid rgba(255,255,255,.1);
}

.tsb-ms-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .3s ease;
}

.tsb-ms-card:hover .tsb-ms-thumb img {
  transform: scale(1.07);
}

/* Testo info */
.tsb-ms-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.tsb-ms-name {
  font-size: .78rem;
  font-weight: 700;
  color: var(--tsb-text-title, #f1f5f9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.tsb-ms-set {
  font-size: .62rem;
  color: var(--tsb-text-muted, #64748b);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
  margin-bottom: 4px;
}

/* Prezzo + badge */
.tsb-ms-finance {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
  gap: 2px;
}

.tsb-ms-price {
  font-size: .84rem;
  font-weight: 800;
  font-family: var(--tsb-font-mono, monospace);
  color: var(--tsb-mana-gold, #d4af37);
  letter-spacing: -.02em;
  white-space: nowrap;
}

.tsb-ms-delta {
  display: inline-flex;
  align-items: center;
  font-size: .67rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
}

.tsb-ms-delta.is-up   { background: rgba(16,185,129,.15); color: #10b981; border: 1px solid rgba(16,185,129,.25); }
.tsb-ms-delta.is-down { background: rgba(239,68,68,.15);  color: #ef4444; border: 1px solid rgba(239,68,68,.25);  }
.tsb-ms-delta.is-nd   { background: rgba(100,116,139,.1); color: #94a3b8; border: 1px solid rgba(100,116,139,.2); }

/* ==========================================================================
   MODAL
   ========================================================================== */
.tsb-price-modal {
  position: fixed;
  inset: 0;
  z-index: 99998;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s ease;
}

.tsb-price-modal.is-open {
  pointer-events: all;
  opacity: 1;
}

.tsb-pm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4,6,12,.82);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: -1;
  cursor: pointer;
}

.tsb-pm-dialog {
  background: var(--tsb-surface-card, #0d1119);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 14px;
  box-shadow: 0 28px 70px rgba(0,0,0,.75);
  width: 100%;
  max-width: 820px;
  max-height: 88vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  transform: translateY(14px) scale(.98);
  transition: transform .22s cubic-bezier(.34,1.4,.64,1);
}

.tsb-price-modal.is-open .tsb-pm-dialog {
  transform: translateY(0) scale(1);
}

/* Accento superiore */
.tsb-pm-dialog::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, #10b981, #d4af37, #ef4444);
  border-radius: 14px 14px 0 0;
  z-index: 1;
}

/* Chiudi */
.tsb-pm-close {
  position: absolute;
  top: 12px; right: 14px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 6px;
  cursor: pointer;
  color: #94a3b8;
  font-size: 1.1rem;
  line-height: 1;
  transition: background .15s, color .15s;
  z-index: 3;
}

.tsb-pm-close:hover { background: rgba(255,255,255,.14); color: #f1f5f9; }

/* Layout 2 colonne */
.tsb-pm-layout {
  display: flex;
  flex-direction: row;
  overflow-y: auto;
  max-height: 88vh;
}

/* Colonna sinistra: carta */
.tsb-pm-card-col {
  width: 188px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 14px 20px;
  background: rgba(0,0,0,.22);
  border-right: 1px solid rgba(255,255,255,.06);
  gap: 16px;
}

#tsb-pm-img {
  width: 158px;
  height: 220px;
  object-fit: cover;
  border-radius: 8px;
  box-shadow: 0 10px 32px rgba(0,0,0,.6);
  border: 1px solid rgba(255,255,255,.12);
  display: block;
}

.tsb-pm-prices {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.tsb-pm-currency-label {
  font-size: .62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: #64748b;
}

#tsb-pm-price-val {
  font-size: 1.3rem;
  font-weight: 800;
  font-family: var(--tsb-font-mono, monospace);
  color: #d4af37;
  letter-spacing: -.03em;
}

#tsb-pm-delta-badge {
  font-size: .72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
}

#tsb-pm-delta-badge.is-up   { background: rgba(16,185,129,.15); color: #10b981; border: 1px solid rgba(16,185,129,.3); }
#tsb-pm-delta-badge.is-down { background: rgba(239,68,68,.15);  color: #ef4444; border: 1px solid rgba(239,68,68,.3);  }
#tsb-pm-delta-badge.is-nd   { background: rgba(100,116,139,.1); color: #94a3b8; }

/* Colonna destra */
.tsb-pm-info-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 22px 22px 20px 18px;
  gap: 0;
}

.tsb-pm-header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 14px;
  padding-right: 40px;
  flex-wrap: wrap;
}

#tsb-pm-name {
  margin: 0 0 4px 0;
  font-size: 1.12rem;
  font-weight: 800;
  color: var(--tsb-text-title, #f1f5f9);
  line-height: 1.25;
  flex: 1 1 100%;
}

#tsb-pm-set {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #94a3b8;
  padding: 2px 7px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(255,255,255,.04);
}

/* Selettore periodo */
.tsb-pm-periods {
  display: inline-flex;
  gap: 3px;
  background: rgba(0,0,0,.3);
  padding: 3px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,.06);
  align-self: flex-start;
  margin-bottom: 12px;
}

.tsb-pm-period {
  padding: 4px 11px;
  font-size: .7rem;
  font-weight: 700;
  color: #64748b;
  background: transparent;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all .15s;
  letter-spacing: .02em;
}

.tsb-pm-period:hover { color: #cbd5e1; }

.tsb-pm-period.is-active {
  background: rgba(212,175,55,.15);
  color: #d4af37;
}

/* Area grafico */
.tsb-pm-chart-wrap {
  position: relative;
  flex: 1;
  min-height: 190px;
  max-height: 250px;
}

#tsb-pm-chart {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.tsb-pm-chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #64748b;
  font-size: .82rem;
  text-align: center;
  padding: 16px;
  line-height: 1.55;
}

.tsb-pm-loading-spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,.08);
  border-top-color: #d4af37;
  border-radius: 50%;
  animation: tsbSpin .7s linear infinite;
}

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

body.tsb-no-scroll { overflow: hidden; }

/* ==========================================================================
   RESPONSIVE MOBILE
   ========================================================================== */
@media (max-width: 600px) {
  .tsb-price-modal { padding: 0; align-items: flex-end; }

  .tsb-pm-dialog {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }

  .tsb-price-modal.is-open .tsb-pm-dialog { transform: translateY(0); }

  .tsb-pm-layout { flex-direction: column; max-height: 92vh; }

  .tsb-pm-card-col {
    width: 100%;
    flex-direction: row;
    padding: 14px 16px;
    gap: 14px;
    border-right: none;
    border-bottom: 1px solid rgba(255,255,255,.06);
    justify-content: flex-start;
  }

  #tsb-pm-img { width: 58px; height: 81px; }

  .tsb-pm-prices { flex-direction: row; gap: 12px; align-items: flex-end; }

  #tsb-pm-price-val { font-size: 1rem; }

  .tsb-pm-info-col { padding: 14px 16px; }

  .tsb-pm-header { padding-right: 0; }

  .tsb-pm-chart-wrap { min-height: 155px; max-height: 195px; }
}

/* ==========================================================================
   LIGHT MODE
   ========================================================================== */
[data-theme="light"] .tsb-ms-card {
  background: #fff;
  border-color: #e2e8f0;
}

[data-theme="light"] .tsb-ms-card:hover,
[data-theme="light"] .tsb-ms-card:focus-visible {
  background: #f8fafc;
  border-color: #cbd5e1;
  box-shadow: 0 4px 12px rgba(0,0,0,.08);
}

[data-theme="light"] .tsb-ms-name  { color: #0f172a; }
[data-theme="light"] .tsb-ms-set   { color: #94a3b8; }
[data-theme="light"] .tsb-ms-price { color: #b45309; }
[data-theme="light"] .tsb-ms-title { color: #0f172a; }

[data-theme="light"] .tsb-pm-dialog {
  background: #fff;
  border-color: #e2e8f0;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
}

[data-theme="light"] .tsb-pm-card-col {
  background: #f8fafc;
  border-right-color: #e2e8f0;
}

[data-theme="light"] #tsb-pm-name      { color: #0f172a; }
[data-theme="light"] #tsb-pm-price-val { color: #b45309; }

[data-theme="light"] .tsb-pm-close {
  background: rgba(0,0,0,.05);
  border-color: #e2e8f0;
  color: #64748b;
}

[data-theme="light"] .tsb-pm-close:hover {
  background: rgba(0,0,0,.1);
  color: #0f172a;
}

[data-theme="light"] .tsb-pm-periods {
  background: #f1f5f9;
  border-color: #e2e8f0;
}

[data-theme="light"] .tsb-pm-period { color: #64748b; }
[data-theme="light"] .tsb-pm-period:hover { color: #0f172a; }
[data-theme="light"] .tsb-pm-period.is-active { background: rgba(180,83,9,.1); color: #b45309; }

[data-theme="light"] #tsb-pm-set { color: #64748b; border-color: #e2e8f0; background: #f8fafc; }
