/* ============================================================
   ArbiMax Modern UI Layer v1.0
   Build: 20260325_MODERN_UI
   
   Binance-inspired density improvements on top of the existing
   design system. Preserves all existing tokens and classes.
   Load AFTER arbimax.components.css.
   ============================================================ */

/* ==========================================
   COMPACT KPI STRIP (Binance-style top bar)
   ========================================== */
.am-kpi-strip {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--am-surface-2);
  border: 1px solid var(--am-border-subtle);
  border-radius: var(--am-radius-lg);
  overflow: hidden;
  height: 48px;
}

.am-kpi-item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 var(--am-space-4);
  border-right: 1px solid var(--am-border-subtle);
  min-width: 100px;
  flex: 1;
}

.am-kpi-item:last-child {
  border-right: none;
}

.am-kpi-label {
  font-size: var(--am-text-xs);
  color: var(--am-text-muted);
  line-height: 1;
  margin-bottom: 2px;
  white-space: nowrap;
}

.am-kpi-value {
  font-size: var(--am-text-sm);
  font-weight: var(--am-font-weight-semibold);
  color: var(--am-text);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
}

.am-kpi-value.profit { color: var(--am-profit); }
.am-kpi-value.loss   { color: var(--am-loss); }
.am-kpi-value.accent { color: var(--am-accent); }

/* ==========================================
   TICKER ROW (pair + price + change)
   ========================================== */
.am-ticker {
  display: flex;
  align-items: center;
  gap: var(--am-space-3);
}

.am-ticker-pair {
  font-size: var(--am-text-base);
  font-weight: var(--am-font-weight-bold);
  color: var(--am-text);
  font-variant-numeric: tabular-nums;
}

.am-ticker-price {
  font-size: var(--am-text-xl);
  font-weight: var(--am-font-weight-bold);
  font-variant-numeric: tabular-nums;
  color: var(--am-text);
}

.am-ticker-change {
  font-size: var(--am-text-sm);
  font-weight: var(--am-font-weight-medium);
  padding: 2px 6px;
  border-radius: var(--am-radius-sm);
  font-variant-numeric: tabular-nums;
}

.am-ticker-change.positive {
  background: var(--am-profit-bg);
  color: var(--am-profit);
}

.am-ticker-change.negative {
  background: var(--am-loss-bg);
  color: var(--am-loss);
}

/* ==========================================
   STAT CARD (dense, centered KPI card)
   ========================================== */
.am-stat-card {
  background: var(--am-surface-1);
  border: 1px solid var(--am-border-subtle);
  border-radius: var(--am-radius-lg);
  padding: var(--am-space-4);
  display: flex;
  flex-direction: column;
  gap: var(--am-space-1);
  transition: border-color var(--am-duration-fast) var(--am-ease);
}

.am-stat-card:hover {
  border-color: var(--am-border);
}

.am-stat-label {
  font-size: var(--am-text-xs);
  color: var(--am-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1;
}

.am-stat-value {
  font-size: var(--am-text-2xl);
  font-weight: var(--am-font-weight-bold);
  color: var(--am-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.am-stat-value.profit { color: var(--am-profit); }
.am-stat-value.loss   { color: var(--am-loss); }
.am-stat-value.accent { color: var(--am-accent); }

.am-stat-sub {
  font-size: var(--am-text-xs);
  color: var(--am-text-dim);
  font-variant-numeric: tabular-nums;
}

/* Stats grid (4-col dense grid) */
.am-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--am-space-3);
}

@media (max-width: 1024px) {
  .am-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .am-stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--am-space-2);
  }
  .am-stat-value { font-size: var(--am-text-xl); }
}

/* ==========================================
   SECTION HEADER (clear hierarchy)
   ========================================== */
.am-section-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--am-space-3);
  padding-bottom: var(--am-space-2);
  border-bottom: 1px solid var(--am-border-subtle);
}

.am-section-hd-title {
  font-size: var(--am-text-sm);
  font-weight: var(--am-font-weight-semibold);
  color: var(--am-text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.am-section-hd-action {
  font-size: var(--am-text-xs);
  color: var(--am-accent);
  cursor: pointer;
  text-decoration: none;
  transition: opacity var(--am-duration-fast);
}

.am-section-hd-action:hover { opacity: 0.7; }

/* ==========================================
   DENSE DATA TABLE (Binance-style)
   ========================================== */
.am-table-dense {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--am-text-sm);
  font-variant-numeric: tabular-nums;
}

.am-table-dense th {
  padding: var(--am-space-2) var(--am-space-3);
  text-align: left;
  font-size: var(--am-text-xs);
  font-weight: var(--am-font-weight-medium);
  color: var(--am-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--am-border-subtle);
  background: transparent;
  white-space: nowrap;
}

.am-table-dense td {
  padding: var(--am-space-2) var(--am-space-3);
  border-bottom: 1px solid var(--am-border-subtle);
  color: var(--am-text);
  vertical-align: middle;
  white-space: nowrap;
}

.am-table-dense tr:last-child td {
  border-bottom: none;
}

.am-table-dense tr:hover td {
  background: var(--am-hover-bg);
}

.am-table-dense .num-right {
  text-align: right;
}

.am-table-dense .col-profit { color: var(--am-profit); }
.am-table-dense .col-loss   { color: var(--am-loss); }
.am-table-dense .col-accent { color: var(--am-accent); }
.am-table-dense .col-muted  { color: var(--am-text-muted); }

/* ==========================================
   STATUS PILL (small inline status)
   ========================================== */
.am-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--am-radius-full);
  font-size: var(--am-text-xs);
  font-weight: var(--am-font-weight-medium);
  line-height: 1.4;
}

.am-pill-live {
  background: var(--am-profit-bg);
  color: var(--am-profit);
  border: 1px solid var(--am-profit-border);
}

.am-pill-live::before {
  content: '';
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--am-profit);
  animation: am-pulse-dot 1.5s ease-in-out infinite;
}

.am-pill-idle {
  background: var(--am-accent-bg);
  color: var(--am-accent);
  border: 1px solid var(--am-accent-border);
}

.am-pill-err {
  background: var(--am-loss-bg);
  color: var(--am-loss);
  border: 1px solid var(--am-loss-border);
}

.am-pill-dry {
  background: rgba(255, 165, 0, 0.1);
  color: #F59E0B;
  border: 1px solid rgba(255, 165, 0, 0.25);
}

@keyframes am-pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ==========================================
   LIVE FEED TICKER (scrolling events)
   ========================================== */
.am-livefeed {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 280px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.am-livefeed-row {
  display: grid;
  grid-template-columns: 80px 90px 1fr auto;
  align-items: center;
  gap: var(--am-space-2);
  padding: 5px var(--am-space-3);
  border-radius: var(--am-radius-sm);
  font-size: var(--am-text-xs);
  transition: background var(--am-duration-fast);
}

.am-livefeed-row:hover {
  background: var(--am-hover-bg);
}

.am-livefeed-time {
  color: var(--am-text-dim);
  font-variant-numeric: tabular-nums;
}

.am-livefeed-pair {
  color: var(--am-text);
  font-weight: var(--am-font-weight-medium);
}

.am-livefeed-event {
  color: var(--am-text-muted);
}

.am-livefeed-value {
  font-variant-numeric: tabular-nums;
  text-align: right;
  font-weight: var(--am-font-weight-medium);
}

/* ==========================================
   EMPTY STATE (consistent no-data display)
   ========================================== */
.am-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--am-space-8) var(--am-space-5);
  color: var(--am-text-dim);
  text-align: center;
  gap: var(--am-space-2);
}

.am-empty-icon {
  font-size: 2rem;
  opacity: 0.4;
}

.am-empty-text {
  font-size: var(--am-text-sm);
  color: var(--am-text-muted);
}

/* ==========================================
   LOADING PULSE (skeleton loader)
   ========================================== */
.am-skeleton {
  background: linear-gradient(
    90deg,
    var(--am-surface-2) 25%,
    var(--am-border) 50%,
    var(--am-surface-2) 75%
  );
  background-size: 200% 100%;
  animation: am-shimmer 1.5s infinite;
  border-radius: var(--am-radius-sm);
  color: transparent !important;
  user-select: none;
}

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

/* ==========================================
   DATA FRESHNESS INDICATOR
   ========================================== */
.am-freshness {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--am-text-xs);
  color: var(--am-text-dim);
}

.am-freshness-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--am-profit);
}

.am-freshness-dot.stale {
  background: var(--am-loss);
}

/* ==========================================
   CARD UPGRADE: better header section
   ========================================== */
.am-card > .am-section-hd:first-child {
  margin: calc(-1 * var(--am-space-lg)) calc(-1 * var(--am-space-lg)) var(--am-space-3);
  padding: var(--am-space-3) var(--am-space-lg);
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--am-border-subtle);
  border-radius: var(--am-radius-xl) var(--am-radius-xl) 0 0;
}

/* ==========================================
   SCROLLBAR for dense panels
   ========================================== */
.am-livefeed::-webkit-scrollbar,
.am-table-dense-wrap::-webkit-scrollbar {
  width: 4px;
}

.am-livefeed::-webkit-scrollbar-track,
.am-table-dense-wrap::-webkit-scrollbar-track {
  background: transparent;
}

.am-livefeed::-webkit-scrollbar-thumb,
.am-table-dense-wrap::-webkit-scrollbar-thumb {
  background: var(--am-border);
  border-radius: 2px;
}

/* Horizontal overflow wrapper */
.am-table-dense-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

/* ==========================================
   CONTENT MAX-WIDTH CENTERING
   Desktop: cap content at 1440px, center it
   ========================================== */
.am-content-frame {
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

/* ==========================================
   DIVIDER
   ========================================== */
.am-divider {
  height: 1px;
  background: var(--am-border-subtle);
  border: none;
  margin: var(--am-space-4) 0;
}

/* ==========================================
   PAGE HEADER (page title + actions)
   ========================================== */
.am-page-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--am-space-6);
  flex-wrap: wrap;
  gap: var(--am-space-3);
}

.am-page-title {
  font-size: var(--am-text-xl);
  font-weight: var(--am-font-weight-bold);
  color: var(--am-text);
  line-height: 1.2;
}

.am-page-subtitle {
  font-size: var(--am-text-sm);
  color: var(--am-text-muted);
  margin-top: 2px;
}

.am-page-actions {
  display: flex;
  align-items: center;
  gap: var(--am-space-2);
  flex-wrap: wrap;
}

/* ==========================================
   NUMERIC DELTA (change from reference)
   ========================================== */
.am-delta {
  font-size: var(--am-text-xs);
  font-weight: var(--am-font-weight-medium);
  font-variant-numeric: tabular-nums;
}

.am-delta.up   { color: var(--am-profit); }
.am-delta.down { color: var(--am-loss); }
.am-delta.flat { color: var(--am-text-dim); }

/* ==========================================
   RESPONSIVE ADJUSTMENTS
   ========================================== */
@media (max-width: 768px) {
  .am-kpi-strip {
    flex-wrap: wrap;
    height: auto;
    gap: 1px;
  }

  .am-kpi-item {
    flex: 0 0 calc(50% - 1px);
    border-right: none;
    border-bottom: 1px solid var(--am-border-subtle);
    padding: var(--am-space-2) var(--am-space-3);
  }

  .am-kpi-item:nth-child(odd) {
    border-right: 1px solid var(--am-border-subtle);
  }

  .am-page-hd {
    margin-bottom: var(--am-space-4);
  }

  .am-livefeed-row {
    grid-template-columns: 65px 72px 1fr auto;
    font-size: 11px;
  }
}
