/* FINANCE CSS */

/* --- PAGE LAYOUT (Match Dashboard) --- */
/* main {
  display: grid;
  grid-template-columns: 20.8rem 1fr;
  min-height: 100vh;
} */
/* Commented out main grid as it's handled by dashboard.css now */

/* --- LAYOUT GRID --- */
.finance-section {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  grid-gap: 2.4rem;
  padding: 3.2rem; /* Match dashboard padding */
  width: 100%;
  max-width: 100%;
}

/* --- HEADER STATS --- */
.finance-header-stats {
  grid-column: 1 / -1;
  display: flex;
  gap: 3.2rem;
  align-items: center;
  padding: 0 0.8rem;
  margin-bottom: 0.8rem;
  font-family: "Rajdhani", sans-serif;
}
.finance-stat-item {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  font-size: 1.6rem;
  color: #ccc;
}
.finance-stat-value {
  color: #fff;
  font-weight: 600;
}
.finance-stat-value.highlight {
  color: #40c057; /* Green highlight for net worth */
  font-size: 1.8rem;
}
.finance-stat-value.positive {
  color: #40c057;
}

/* --- CARDS COMMON --- */
.finance-card {
  background: rgba(18, 18, 24, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  /* Neon glow shadow subtle */
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
}

.finance-card-title {
  font-family: "Orbitron", sans-serif;
  font-size: 1.4rem;
  color: #ddd;
  margin-bottom: 2.4rem;
  font-weight: 500;
  letter-spacing: 1px;
}

/* --- MAIN CHART (Portfolio Value) --- */
.main-chart-card {
  grid-column: 1 / -1;
  min-height: 35rem;
  background: linear-gradient(
    180deg,
    rgba(20, 20, 30, 0.8) 0%,
    rgba(10, 10, 20, 0.95) 100%
  );
  /* Top neon border accent */
  border-top: 2px solid #a64dff;
  box-shadow: 0 0 15px rgba(166, 77, 255, 0.15);
}
.main-chart-card .finance-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}
.finance-time-selector {
  display: flex;
  gap: 1.6rem;
}
.finance-time-selector span {
  font-size: 1.2rem;
  color: #666;
  cursor: pointer;
  font-weight: 600;
}
.finance-time-selector span.active {
  color: #bbb;
}

.main-chart-placeholder {
  flex: 1;
  position: relative;
  width: 100%;
}
.chart-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 0 8px rgba(166, 77, 255, 0.4));
}

/* --- METRICS ROW (P&L, Roy, Fees) - LEFT SIDE --- */
.metrics-row {
  grid-column: 1 / 8; /* Left side roughly 60% */
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.6rem;
}

/* P&L Card Specifics */
.finance-metric-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1.6rem;
  padding: 1.6rem;
}
.finance-metric-card.accent-green {
  border-left: 4px solid #40c057;
}
.finance-metric-card.accent-yellow {
  border-left: 4px solid #fcc419;
}
.finance-metric-card.accent-red {
  border-left: 4px solid #fa5252;
}

.finance-icon-box {
  font-size: 2.4rem;
  width: 4.8rem;
  height: 4.8rem;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.finance-metric-card.accent-green .finance-icon-box {
  color: #40c057;
  background: rgba(64, 192, 87, 0.15);
}
.finance-metric-card.accent-yellow .finance-icon-box {
  color: #fcc419;
  background: rgba(252, 196, 25, 0.15);
}
.finance-metric-card.accent-red .finance-icon-box {
  color: #fa5252;
  background: rgba(250, 82, 82, 0.15);
}

.finance-metric-info {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.finance-metric-label {
  font-size: 1.2rem;
  color: #888;
}
.finance-metric-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: #eee;
  white-space: nowrap;
}
.finance-metric-value.positive {
  color: #40c057;
}
.finance-metric-value.color-blue {
  color: #4dabf7;
}
.finance-metric-value.color-red {
  color: #fa5252;
}

/* --- RIGHT SIDE DETAILS (Allocation, Liquidity) - FLATTENED --- */
/* .right-details-group removed */
.right-details-group {
  grid-column: 8 / -1; /* Remainder */
  display: grid;
  /* 3 columns: +10% / Normal / -10% -> 1.1fr 1fr 0.9fr */
  grid-template-columns: 1.1fr 1fr 0.9fr;
  gap: 1.6rem;
}

/* Allocation Card */
.allocation-card {
  grid-column: 1 / 2;
  padding: 1.2rem;
  flex-direction: row;
  align-items: center;
  gap: 1.2rem;
}
.pie-chart-icon {
  display: none;
}
.allocation-info {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}
.small-title {
  font-size: 1.1rem;
  color: #888;
  margin-bottom: 0.4rem;
}
.donut-mini {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.mini-chart {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: conic-gradient(#8a2be2 0% 40%, #00f2ff 40% 60%, #40c057 60% 100%);
  flex-shrink: 0;
}
.mini-legend {
  list-style: none;
  font-size: 1rem;
  color: #ccc;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.mini-legend li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: block;
}
.d1 {
  background: #8a2be2;
}
.d2 {
  background: #00f2ff;
}
.d3 {
  background: #40c057;
}

/* Liquidity Card */
.liquidity-card {
  /* Auto placement */
  padding: 1.2rem;
  flex-direction: row;
  align-items: center;
  gap: 1.2rem;
}
.liquidity-info {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.score-value {
  font-size: 1.3rem;
  font-weight: 700;
}
.color-yellow {
  color: #fcc419;
}

/* ROW 4 items */
.details-row {
  display: contents;
}

/* Trader Metrics (Left side below Metrics Row) */
.trader-metrics-card {
  grid-column: 1 / 8;
}
.trader-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2rem;
}
.ts-item {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.ts-label {
  font-size: 1.2rem;
  color: #888;
}
.ts-value {
  font-size: 1.8rem;
  font-weight: 600;
  color: #fff;
}

/* Best/Worst Trade (Right side) */
.trades-summary-card {
  /* Auto placement in Col 3, narrow */
  grid-column: auto; /* Force override of previous explicit settings */
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.8rem;
  padding: 1.2rem;
}
.trade-line {
  font-size: 1.05rem; /* Slight reduce fit */
  color: #ccc;
  display: flex;
  flex-direction: column; /* Stack for narrow column */
  gap: 0.2rem;
  align-items: flex-start;
}
.trade-label {
  color: #888;
  font-size: 1.1rem;
}
.trade-val {
  font-weight: 500;
  font-size: 1.2rem;
}
.positive {
  color: #40c057;
}
.negative {
  color: #fa5252;
}

/* --- CREATOR ROW --- */
.creator-card {
  height: 18rem;
  grid-column: 1 / -1;
}
.creator-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4rem;
}
.c-item {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.c-label {
  font-size: 1.2rem;
  color: #888;
}
.c-value {
  font-size: 2.4rem;
  font-weight: 700;
  color: #fff;
  font-family: "Rajdhani", sans-serif;
}
.mini-sparkline {
  height: 3rem;
  width: 100%;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* --- BOTTOM ROW (Assets + History) --- */
.grid-assets-history {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 8fr 4fr; /* 2/3 and 1/3 */
  gap: 2.4rem;
}

/* Assets Table */
.assets-table-card {
  padding: 0; /* Flush edges */
  background: rgba(18, 18, 24, 0.6);
}
.assets-table-card .finance-card-title {
  padding: 2rem 2rem 1rem 2rem;
  margin-bottom: 0;
}
.assets-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1.3rem;
}
.assets-table th {
  text-align: left;
  padding: 1.2rem 2rem;
  color: #666;
  font-weight: 400;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.assets-table td {
  padding: 1.6rem 2rem;
  color: #ddd;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  vertical-align: middle;
}
.assets-table tr:last-child td {
  border-bottom: none;
}
.asset-name {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-weight: 500;
}
.table-img {
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 6px;
  object-fit: cover;
}
.action-link {
  color: #a64dff;
  text-decoration: none;
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.action-link:hover {
  text-decoration: underline;
}

/* History List */
.history-card {
  grid-column: 2 / -1;
  /* height: fit-content; */
}
.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2.4rem;
}
.history-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 0.8rem;
  font-size: 1.4rem;
}
.history-list li:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.h-main {
  color: #ddd;
}
.h-type {
  color: #666;
  font-style: italic;
}

/* --- ICONS --- */
ion-icon {
  font-size: 2.4rem;
}
.card-icon ion-icon {
  color: #4dabf7;
}
.liquidity-card .card-icon ion-icon {
  color: #fcc419;
}

/* --- RESPONSIVENESS Tweaks --- */

/* 1. Smaller Desktops (max-width: 1344px / 84em) */
@media (max-width: 84em) {
  .finance-section {
    padding: 2.4rem;
  }
  .metrics-row {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, 1fr);
  }
  .trader-metrics-card,
  .right-details-group,
  .trades-summary-card {
    grid-column: 1 / -1;
  }
  .right-details-group {
    grid-template-columns: repeat(3, 1fr);
  }
  .trades-summary-card {
    grid-column: 3 / -1;
    /* flex-direction: row; */
    justify-content: space-around;
  }
}

/* 2. Landscape Tablets (max-width: 1200px / 75em) */
@media (max-width: 75em) {
  .finance-section {
    padding: 2rem;
    grid-gap: 1.6rem;
  }
  .grid-assets-history {
    grid-template-columns: 1fr;
  }
  .creator-grid {
    gap: 2rem;
  }
  .finance-header-stats {
    gap: 1.6rem;
  }
}

/* 3. Tablets (max-width: 944px / 59em) */
@media (max-width: 59em) {
  .finance-section {
    padding: 1.6rem;
  }
  .metrics-row,
  .trader-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .metrics-row > :last-child {
    grid-column: 1 / -1;
  }
  .right-details-group {
    grid-template-columns: 1fr 1fr;
  }
  .creator-grid {
    grid-template-columns: 1fr;
    gap: 1.6rem;
  }
  .creator-card {
    height: auto;
  }
  .assets-table-card {
    overflow-x: auto;
  }
  .history-card {
    grid-column: 1 / -1;
  }
  .mini-sparkline {
    height: 16rem;
  }
}

/* 4. Smaller Tablets (max-width: 704px / 44em) */
@media (max-width: 44em) {
  .finance-header-stats {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.8rem;
  }
  .main-chart-card {
    min-height: 28rem;
  }
  .main-chart-card .finance-card-header {
    margin-bottom: 1.2rem;
  }
  .finance-time-selector {
    gap: 2rem;
  }
  .finance-time-selector span {
    padding: 0.4rem;
  }
  .right-details-group {
    grid-template-columns: 1fr;
  }

  .allocation-card,
  .trades-summary-card,
  .liquidity-card {
    grid-column: 1 / -1;
  }

  .mini-sparkline {
    height: 12rem;
  }
}

/* 5. Phones (max-width: 544px / 34em) */
@media (max-width: 34em) {
  .finance-section {
    padding: 1.2rem;
    grid-gap: 1.2rem;
  }
  .metrics-row,
  .trader-stats-grid,
  .right-details-group {
    grid-template-columns: 1fr;
  }
  .trades-summary-card {
    flex-direction: column;
  }
  .main-chart-card {
    min-height: 22rem;
  }
  .main-chart-card .finance-card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  .finance-card {
    padding: 1.6rem;
  }
  .c-value {
    font-size: 2rem;
  }
  .history-list li {
    font-size: 1.2rem;
  }
  .mini-sparkline {
    height: 10rem;
  }
}

/* =========================================================
   LIVE MARKET SIMULATION (JS/finance.js)
   ========================================================= */
.finance-stat-value,
.finance-metric-value,
.ts-value,
.score-value,
.c-value,
.trade-val span,
.assets-table td,
.alloc-pct,
.chart-range-change,
.chart-tooltip {
  font-variant-numeric: tabular-nums;
}

/* Flash on value change */
.live-up,
.live-down {
  border-radius: 4px;
}
.live-up {
  animation: liveFlashUp 1.4s ease-out;
}
.live-down {
  animation: liveFlashDown 1.4s ease-out;
}
@keyframes liveFlashUp {
  0% {
    background-color: rgba(64, 192, 87, 0.28);
    box-shadow: 0 0 0 3px rgba(64, 192, 87, 0.28);
  }
  100% {
    background-color: transparent;
    box-shadow: 0 0 0 3px transparent;
  }
}
@keyframes liveFlashDown {
  0% {
    background-color: rgba(250, 82, 82, 0.28);
    box-shadow: 0 0 0 3px rgba(250, 82, 82, 0.28);
  }
  100% {
    background-color: transparent;
    box-shadow: 0 0 0 3px transparent;
  }
}

/* Table cells keep their tone colors */
.assets-table td.positive {
  color: #40c057;
}
.assets-table td.negative {
  color: #fa5252;
}

/* Range selector */
.finance-time-selector span {
  padding: 0.3rem 0.8rem;
  border-radius: 6px;
  transition:
    color 0.2s,
    background-color 0.2s;
  user-select: none;
}
.finance-time-selector span:hover {
  color: #ddd;
}
.finance-time-selector span.active {
  color: #fff;
  background-color: rgba(166, 77, 255, 0.22);
}
.finance-time-selector span:focus-visible {
  outline: 1px solid #a64dff;
}

/* Chart title extras */
.chart-range-change {
  margin-left: 1.2rem;
  font-family: "Rajdhani", sans-serif;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0;
}
.chart-live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: 1.2rem;
  padding: 0.2rem 0.7rem;
  border: 1px solid rgba(64, 192, 87, 0.35);
  border-radius: 999px;
  color: #40c057;
  font-size: 0.9rem;
  letter-spacing: 1.5px;
  vertical-align: middle;
}
.chart-live-badge::before {
  content: "";
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: #40c057;
  animation: livePulse 1.6s ease-in-out infinite;
}
@keyframes livePulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.25;
  }
}

/* Chart area + overlay */
.main-chart-placeholder {
  min-height: 16rem;
  cursor: crosshair;
}
.main-chart-placeholder .chart-svg {
  position: absolute;
  inset: 0;
  display: block;
  overflow: visible;
}
.chart-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.chart-crosshair {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: linear-gradient(
    transparent,
    rgba(166, 77, 255, 0.7),
    transparent
  );
}
.chart-hover-dot,
.chart-live-dot {
  position: absolute;
  width: 1rem;
  height: 1rem;
  margin: -0.5rem 0 0 -0.5rem;
  border-radius: 50%;
  background: #a64dff;
  box-shadow: 0 0 10px #a64dff;
  transition: top 0.3s ease-out;
}
.chart-hover-dot {
  background: #fff;
  border: 2px solid #a64dff;
  transition: none;
}
.chart-live-dot::after {
  content: "";
  position: absolute;
  inset: -0.6rem;
  border-radius: 50%;
  border: 2px solid #a64dff;
  animation: liveRing 1.8s ease-out infinite;
}
@keyframes liveRing {
  0% {
    transform: scale(0.4);
    opacity: 1;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}
.chart-tooltip {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.6rem 1rem;
  background: rgba(12, 12, 20, 0.92);
  border: 1px solid rgba(166, 77, 255, 0.45);
  border-radius: 8px;
  white-space: nowrap;
  font-family: "Rajdhani", sans-serif;
  z-index: 2;
}
.chart-tooltip-value {
  color: #fff;
  font-size: 1.6rem;
  font-weight: 700;
}
.chart-tooltip-value small {
  margin-left: 0.4rem;
  font-size: 1.2rem;
}
.chart-tooltip-date {
  color: #999;
  font-size: 1.1rem;
}
.chart-crosshair,
.chart-hover-dot,
.chart-tooltip {
  opacity: 0;
  transition: opacity 0.15s;
}
.is-hovering .chart-crosshair,
.is-hovering .chart-hover-dot,
.is-hovering .chart-tooltip {
  opacity: 1;
}

/* New history entry */
.history-list li.history-new {
  animation: historyIn 0.7s ease-out;
}
@keyframes historyIn {
  from {
    opacity: 0;
    transform: translateY(-0.8rem);
    background-color: rgba(166, 77, 255, 0.15);
  }
  to {
    opacity: 1;
    transform: none;
    background-color: transparent;
  }
}

@media (prefers-reduced-motion: reduce) {
  .live-up,
  .live-down,
  .history-list li.history-new,
  .chart-live-dot::after,
  .chart-live-badge::before {
    animation: none;
  }
}

/* =========================================================
   REAL FINANCES (JS/finance.js + JS/wallet.js)
   ========================================================= */
.wallet-topup-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: 0.4rem;
  padding: 0.3rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(64, 192, 87, 0.5);
  background: rgba(64, 192, 87, 0.1);
  color: #40c057;
  cursor: pointer;
  font-family: "Rajdhani", sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  transition: all 0.2s;
}
.wallet-topup-btn ion-icon {
  font-size: 1.4rem;
}
.wallet-topup-btn:hover {
  background: #40c057;
  color: #000;
}

/* Buy / mint / sale markers on the chart */
.chart-events {
  position: absolute;
  inset: 0;
}
.chart-event {
  position: absolute;
  width: 1rem;
  height: 1rem;
  margin: -0.5rem 0 0 -0.5rem;
  border-radius: 50%;
  border: 2px solid #121218;
  background: #ffd900;
  box-shadow: 0 0 8px rgba(255, 217, 0, 0.6);
  transition: top 0.3s ease-out;
}
.chart-event.ev-sell {
  background: #40c057;
  box-shadow: 0 0 8px rgba(64, 192, 87, 0.6);
}
.chart-event.ev-mint {
  background: #be2edd;
  box-shadow: 0 0 8px rgba(190, 46, 221, 0.6);
}
.chart-tooltip-events {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 1.2rem;
}
.chart-tooltip-events:empty {
  display: none;
}
.chart-tooltip-events .ev-buy {
  color: #ffd900;
}
.chart-tooltip-events .ev-sell {
  color: #40c057;
}
.chart-tooltip-events .ev-mint {
  color: #be2edd;
}

/* Assets table with every owned NFT */
.assets-table td.nft-class-pai {
  color: #6a58dc;
}
.assets-table td.nft-class-fig {
  color: #22a6b3;
}
.assets-table td.nft-class-sc {
  color: #be2edd;
}
.asset-mint {
  margin-left: 0.4rem;
  font-size: 1rem;
  color: #be2edd;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.asset-device {
  font-size: 1.2rem;
  color: #666;
}
.asset-device.on {
  color: #40c057;
}
.asset-actions {
  white-space: nowrap;
}
button.action-link {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}
.assets-empty {
  text-align: center;
  color: #888;
}
.assets-empty a {
  color: #ffd900;
}
.h-fee {
  margin-left: 0.4rem;
  font-size: 1.1rem;
  color: #777;
}

@media (max-width: 75em) {
  .assets-table-card {
    overflow-x: auto;
  }
  .assets-table {
    min-width: 72rem;
  }
}
.assets-table th,
.assets-table td {
  padding: 1.2rem 1.2rem;
}
.assets-table th:first-child,
.assets-table td:first-child {
  padding-left: 2rem;
}
.assets-table td:not(.asset-name),
.assets-table th {
  white-space: nowrap;
}
.assets-table .asset-device.on {
  display: inline-block;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.asset-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}
.asset-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 16rem;
}
.asset-cat {
  font-size: 1.1rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.assets-table .asset-device.on {
  max-width: 12rem;
}
@media (max-width: 75em) {
  .assets-table {
    min-width: 64rem;
  }
}
