/* ═══ Anchor HQ — Finance Section ("The Treasury") ═══ */
/* Phase 4: Gold vault, treasure counters, pixel charts */


/* ─── Keyframes ─── */

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

@keyframes vault-glow {
  0%, 100% { box-shadow: 0 0 8px rgba(218, 165, 32, 0.12), inset 0 0 4px rgba(218, 165, 32, 0.04); }
  50%      { box-shadow: 0 0 16px rgba(218, 165, 32, 0.25), inset 0 0 8px rgba(218, 165, 32, 0.08); }
}

@keyframes bar-grow {
  0%   { height: 0; opacity: 0; }
  100% { opacity: 1; }
}

@keyframes chest-bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

@keyframes treasure-sparkle {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 1; }
}

@keyframes kpi-appear {
  0%   { opacity: 0; transform: translateY(10px) scale(0.96); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}


/* ═══════════════════════════════════════════════════════════════════════════
   KPI GRID — Treasure Vault Counters
   ═══════════════════════════════════════════════════════════════════════════ */

.treasury-kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}


/* ─── Individual KPI Card ─── */

.treasury-kpi {
  background:
    /* Subtle vault texture overlay */
    radial-gradient(ellipse at 25% 75%, rgba(139, 111, 71, 0.05) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(218, 165, 32, 0.03) 0%, transparent 50%),
    var(--panel);
  border: 2px solid var(--wood);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  transition: all 250ms ease;
  animation: kpi-appear 350ms ease backwards;

  /* Wood grain accent at the top edge */
  border-top: 3px solid var(--wood);
  overflow: hidden;
}

/* Stagger the entrance animation */
.treasury-kpi:nth-child(1) { animation-delay: 0ms; }
.treasury-kpi:nth-child(2) { animation-delay: 60ms; }
.treasury-kpi:nth-child(3) { animation-delay: 120ms; }
.treasury-kpi:nth-child(4) { animation-delay: 180ms; }
.treasury-kpi:nth-child(5) { animation-delay: 240ms; }

/* Decorative gold accent line at top */
.treasury-kpi::before {
  content: "";
  position: absolute;
  top: 0;
  left: 12px;
  right: 12px;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--gold) 30%,
    var(--gold-bright, #f0c040) 50%,
    var(--gold) 70%,
    transparent 100%
  );
  opacity: 0.4;
  transition: opacity 250ms ease;
}

/* Subtle sparkle in top-right corner */
.treasury-kpi::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 10px;
  width: 4px;
  height: 4px;
  background: var(--gold);
  border-radius: 50%;
  opacity: 0;
  transition: opacity 250ms ease;
  box-shadow: 0 0 6px rgba(218, 165, 32, 0.4);
  animation: treasure-sparkle 2s ease infinite;
  animation-play-state: paused;
}

.treasury-kpi:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.3),
    0 0 10px rgba(218, 165, 32, 0.12),
    inset 0 0 12px rgba(218, 165, 32, 0.04);
}

.treasury-kpi:hover::before {
  opacity: 0.8;
}

.treasury-kpi:hover::after {
  opacity: 1;
  animation-play-state: running;
}


/* ─── KPI Icon ─── */

.treasury-kpi-icon {
  font-size: 1.5rem;
  margin-bottom: 10px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}


/* ─── KPI Label ─── */

.treasury-kpi-label {
  font-size: .7rem;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
  line-height: 1.3;
}


/* ─── KPI Value (Gold Pixel Font) ─── */

.treasury-kpi-value {
  font-family: var(--font-pixel);
  font-size: .65rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.04em;
  text-shadow: 0 0 8px rgba(218, 165, 32, 0.2);
  line-height: 1.4;
  margin-bottom: 4px;
}


/* ─── KPI Trend ─── */

.treasury-kpi-trend {
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.3;
  min-height: 1em;
}

/* Green for positive trends */
.treasury-kpi-trend.up,
.treasury-kpi-trend[data-trend="up"] {
  color: var(--green);
}

/* Red for negative trends */
.treasury-kpi-trend.down,
.treasury-kpi-trend[data-trend="down"] {
  color: var(--red);
}


/* ═══════════════════════════════════════════════════════════════════════════
   TREASURY GRID — Chart & Products Two-Column Layout
   ═══════════════════════════════════════════════════════════════════════════ */

.treasury-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}


/* ─── Chart Card (Revenue Bar Chart) ─── */

.treasury-chart-card {
  position: relative;
  overflow: hidden;
}

/* Gold vault stripe at the top of chart card */
.treasury-chart-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    var(--wood-dark, #3d2b1a) 0%,
    var(--gold) 20%,
    var(--gold-bright, #f0c040) 50%,
    var(--gold) 80%,
    var(--wood-dark, #3d2b1a) 100%
  );
  opacity: 0.6;
  border-radius: var(--radius) var(--radius) 0 0;
}

.treasury-chart {
  min-height: 200px;
  position: relative;
  padding-top: 8px;
}


/* ─── Bar Chart Container ─── */

.treasury-chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 200px;
  padding: 0 4px;
  /* Ledger lines behind bars */
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 39px,
      rgba(107, 68, 35, 0.1) 39px,
      rgba(107, 68, 35, 0.1) 40px
    );
  border-bottom: 2px solid var(--border);
  position: relative;
}

/* Baseline label area */
.treasury-chart-bars::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(
    90deg,
    var(--wood-dark, #3d2b1a),
    var(--wood) 50%,
    var(--wood-dark, #3d2b1a)
  );
}


/* ─── Individual Bar Wrapper ─── */

.treasury-chart-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}


/* ─── The Actual Bar (Gold Gradient) ─── */

.treasury-chart-bar-fill {
  width: 100%;
  min-width: 30px;
  max-width: 48px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: linear-gradient(
    180deg,
    var(--gold-bright, #f0c040) 0%,
    var(--gold) 40%,
    #c99418 100%
  );
  position: relative;
  transition: height 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: bar-grow 600ms ease backwards;
  cursor: default;

  /* Pixel-style inset highlight */
  box-shadow:
    inset 2px 0 0 rgba(255, 255, 255, 0.2),
    inset -2px 0 0 rgba(0, 0, 0, 0.15),
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    0 -1px 4px rgba(218, 165, 32, 0.15);

  /* Pixel border via outline */
  border: 1px solid rgba(107, 68, 35, 0.5);
  border-bottom: none;
}

/* Stagger bar animation */
.treasury-chart-bar:nth-child(1) .treasury-chart-bar-fill  { animation-delay: 50ms; }
.treasury-chart-bar:nth-child(2) .treasury-chart-bar-fill  { animation-delay: 100ms; }
.treasury-chart-bar:nth-child(3) .treasury-chart-bar-fill  { animation-delay: 150ms; }
.treasury-chart-bar:nth-child(4) .treasury-chart-bar-fill  { animation-delay: 200ms; }
.treasury-chart-bar:nth-child(5) .treasury-chart-bar-fill  { animation-delay: 250ms; }
.treasury-chart-bar:nth-child(6) .treasury-chart-bar-fill  { animation-delay: 300ms; }
.treasury-chart-bar:nth-child(7) .treasury-chart-bar-fill  { animation-delay: 350ms; }
.treasury-chart-bar:nth-child(8) .treasury-chart-bar-fill  { animation-delay: 400ms; }
.treasury-chart-bar:nth-child(9) .treasury-chart-bar-fill  { animation-delay: 450ms; }
.treasury-chart-bar:nth-child(10) .treasury-chart-bar-fill { animation-delay: 500ms; }
.treasury-chart-bar:nth-child(11) .treasury-chart-bar-fill { animation-delay: 550ms; }
.treasury-chart-bar:nth-child(12) .treasury-chart-bar-fill { animation-delay: 600ms; }

/* Hover glow on bars */
.treasury-chart-bar-fill:hover {
  box-shadow:
    inset 2px 0 0 rgba(255, 255, 255, 0.25),
    inset -2px 0 0 rgba(0, 0, 0, 0.15),
    inset 0 2px 0 rgba(255, 255, 255, 0.3),
    0 0 12px rgba(218, 165, 32, 0.3),
    0 -2px 8px rgba(218, 165, 32, 0.2);
  filter: brightness(1.1);
}

/* Shine overlay on bar */
.treasury-chart-bar-fill::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40%;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.12) 0%,
    transparent 100%
  );
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  pointer-events: none;
}


/* ─── Bar Value Label (Above Bar) ─── */

.treasury-chart-bar-value {
  font-family: var(--font-pixel);
  font-size: .4rem;
  color: var(--gold);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  letter-spacing: 0.02em;
  line-height: 1;
  order: -1;
}


/* ─── Bar Month Label (Below Bar) ─── */

.treasury-chart-bar-label {
  font-size: .6rem;
  color: var(--muted);
  white-space: nowrap;
  padding-top: 6px;
  letter-spacing: 0.01em;
  line-height: 1;
}


/* ─── Chart Empty State ─── */

.treasury-chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: .75rem;
  font-style: italic;
  opacity: 0.7;
}


/* ═══════════════════════════════════════════════════════════════════════════
   PRODUCTS CARD — Revenue Ledger
   ═══════════════════════════════════════════════════════════════════════════ */

.treasury-products-card {
  position: relative;
  overflow: hidden;
}

/* Matching vault stripe */
.treasury-products-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    var(--wood-dark, #3d2b1a) 0%,
    var(--wood) 30%,
    var(--gold) 50%,
    var(--wood) 70%,
    var(--wood-dark, #3d2b1a) 100%
  );
  opacity: 0.5;
  border-radius: var(--radius) var(--radius) 0 0;
}

.treasury-products {
  display: flex;
  flex-direction: column;
}


/* ─── Individual Product Row (Ledger Line) ─── */

.treasury-product {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  transition: all 200ms ease;
  position: relative;
}

.treasury-product:last-child {
  border-bottom: none;
}

/* Ledger hover effect */
.treasury-product:hover {
  background:
    linear-gradient(
      90deg,
      rgba(218, 165, 32, 0.04) 0%,
      rgba(218, 165, 32, 0.08) 50%,
      rgba(218, 165, 32, 0.04) 100%
    );
}

/* Left accent dash on hover */
.treasury-product::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: var(--gold);
  border-radius: 2px;
  transition: height 200ms ease;
}

.treasury-product:hover::before {
  height: 60%;
}


/* ─── Product Icon ─── */

.treasury-product-icon {
  font-size: 1.2rem;
  line-height: 1;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}


/* ─── Product Name ─── */

.treasury-product-name {
  flex: 1;
  font-size: .8rem;
  color: var(--text);
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


/* ─── Product Revenue ─── */

.treasury-product-revenue {
  font-family: var(--font-pixel);
  font-size: .5rem;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-shadow: 0 0 6px rgba(218, 165, 32, 0.15);
  white-space: nowrap;
  flex-shrink: 0;
}


/* ─── Product Subscribers Badge ─── */

.treasury-product-subs {
  font-size: .6rem;
  color: var(--muted);
  background: rgba(107, 68, 35, 0.12);
  padding: 3px 8px;
  border-radius: 0;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: 0.02em;

  /* Pixel border */
  box-shadow:
    -1px  0   0 0 var(--border),
     1px  0   0 0 var(--border),
     0   -1px 0 0 var(--border),
     0    1px 0 0 var(--border);
}


/* ═══════════════════════════════════════════════════════════════════════════
   TRANSACTIONS CARD — Treasury Ledger
   ═══════════════════════════════════════════════════════════════════════════ */

.treasury-transactions-card {
  position: relative;
  overflow: hidden;
}

/* Vault stripe top accent */
.treasury-transactions-card::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(
    90deg,
    var(--wood-dark, #3d2b1a) 0%,
    var(--wood) 20%,
    var(--gold) 50%,
    var(--wood) 80%,
    var(--wood-dark, #3d2b1a) 100%
  );
  opacity: 0.5;
  border-radius: var(--radius) var(--radius) 0 0;
}

.treasury-transactions {
  display: flex;
  flex-direction: column;
}


/* ─── Individual Transaction Row ─── */

.treasury-transaction {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 8px;
  transition: background 200ms ease;
  border-radius: var(--radius-sm);
}

/* Alternating row tinting for ledger feel */
.treasury-transaction:nth-child(odd) {
  background: rgba(26, 21, 16, 0.3);
}

.treasury-transaction:nth-child(even) {
  background: rgba(31, 26, 20, 0.5);
}

.treasury-transaction:hover {
  background: rgba(218, 165, 32, 0.06);
}

/* Subtle left border on hover */
.treasury-transaction:hover {
  box-shadow: inset 3px 0 0 rgba(218, 165, 32, 0.3);
}


/* ─── Transaction Icon ─── */

.treasury-transaction-icon {
  font-size: 1.1rem;
  line-height: 1;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
}


/* ─── Transaction Description ─── */

.treasury-transaction-desc {
  flex: 1;
  font-size: .78rem;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}


/* ─── Transaction Amount ─── */

.treasury-transaction-amount {
  font-family: var(--font-pixel);
  font-size: .48rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
  flex-shrink: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* Positive amount — gold/green, the vault grows */
.treasury-transaction-amount.positive {
  color: var(--green);
}

/* Negative amount — red, a withdrawal */
.treasury-transaction-amount.negative {
  color: var(--red);
}


/* ─── Transaction Date ─── */

.treasury-transaction-date {
  font-size: .65rem;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
  opacity: 0.8;
  min-width: 65px;
  text-align: right;
}


/* ═══════════════════════════════════════════════════════════════════════════
   EMPTY STATES — Dormant Treasury
   ═══════════════════════════════════════════════════════════════════════════ */

/* Inline hint for empty product/transaction lists */
.treasury-empty-hint {
  text-align: center;
  color: var(--muted);
  font-size: .75rem;
  font-style: italic;
  padding: 24px 16px;
  opacity: 0.7;
}


/* ─── Full Empty State (No Finance Data) ─── */

.treasury-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 24px;
  position: relative;
}

/* Subtle vault door outline behind the empty state */
.treasury-empty-state::before {
  content: "";
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 120px;
  border: 2px dashed rgba(107, 68, 35, 0.2);
  border-radius: 50%;
  pointer-events: none;
}

.treasury-empty-chest {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: 16px;
  animation: chest-bob 3s ease-in-out infinite;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
  position: relative;
  z-index: 1;
}

.treasury-empty-title {
  font-family: var(--font-pixel);
  font-size: .6rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 10px;
  text-shadow: 0 0 10px rgba(218, 165, 32, 0.2);
}

.treasury-empty-desc {
  font-size: .78rem;
  color: var(--muted);
  line-height: 1.5;
  max-width: 340px;
}

.treasury-empty-desc code {
  font-family: 'Press Start 2P', monospace;
  font-size: .45rem;
  color: var(--gold);
  background: rgba(218, 165, 32, 0.08);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(218, 165, 32, 0.2);
}


/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Adapting the Treasury
   ═══════════════════════════════════════════════════════════════════════════ */

/* Large tablets and small desktops */
@media (max-width: 1200px) {
  .treasury-kpis {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Tablets */
@media (max-width: 900px) {
  .treasury-kpis {
    grid-template-columns: repeat(2, 1fr);
  }

  .treasury-grid {
    grid-template-columns: 1fr;
  }

  .treasury-chart-bars {
    height: 160px;
  }
}

/* Mobile */
@media (max-width: 640px) {
  .treasury-kpis {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .treasury-kpi {
    padding: 16px;
  }

  .treasury-grid {
    gap: 12px;
  }

  .treasury-chart-bars {
    height: 140px;
    gap: 4px;
  }

  .treasury-chart-bar-fill {
    min-width: 22px;
  }

  .treasury-chart-bar-value {
    font-size: .35rem;
  }

  .treasury-transaction {
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 6px;
  }

  .treasury-transaction-desc {
    flex-basis: 100%;
    order: 2;
    white-space: normal;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    padding-left: 30px;
  }

  .treasury-transaction-amount {
    order: 3;
    margin-left: auto;
  }

  .treasury-transaction-date {
    order: 4;
  }

  .treasury-product {
    gap: 8px;
    padding: 10px 2px;
  }

  .treasury-product-name {
    font-size: .72rem;
  }

  .treasury-product-revenue {
    font-size: .45rem;
  }

  .treasury-empty-state {
    padding: 40px 16px;
  }

  .treasury-empty-chest {
    font-size: 2.4rem;
  }

  .treasury-empty-title {
    font-size: .5rem;
  }

  .treasury-kpi-label {
    font-size: .65rem;
  }

  .treasury-kpi-value {
    font-size: .58rem;
  }

  .treasury-product-subs {
    font-size: .55rem;
    padding: 2px 6px;
  }
}

/* ═══ Growth Deltas Card ═══ */
.treasury-deltas-card {
  margin-top: 16px;
}

.treasury-trend-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.treasury-trend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex: 1 1 140px;
  min-width: 140px;
}

.trend-label {
  font-size: .78rem;
  color: var(--text-muted);
}

.trend-value {
  font-size: .85rem;
  font-weight: 700;
  font-family: 'Press Start 2P', monospace;
  font-size: .55rem;
}

.trend-value.positive {
  color: var(--green);
}

.trend-value.negative {
  color: var(--red, #e74c3c);
}

.trend-value.neutral {
  color: var(--text-muted);
}
