/* ── Reset & Base ──────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Backgrounds */
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d29;
  --bg-tertiary: #22263a;
  --bg-hover: #272b3d;

  /* Text */
  --text-primary: #e8eaf0;
  --text-secondary: #9ca3b8;
  --text-muted: #6b7280;

  /* Accent */
  --blue: #4f8df5;
  --blue-dim: rgba(79, 141, 245, 0.12);

  /* P&L */
  --green: #22c55e;
  --green-dim: rgba(34, 197, 94, 0.12);
  --red: #ef4444;
  --red-dim: rgba(239, 68, 68, 0.12);

  /* Borders */
  --border: #2a2e3f;
  --border-light: #353a4f;

  /* Misc */
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --transition: 150ms ease;
}

html {
  font-size: 16px;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  height: 64px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-text {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--green-dim);
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--green);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

.wallet-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wallet-address {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.95rem;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: default;
}

/* ── Main Content ──────────────────────────────────────────────────────── */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ── Stats Row ─────────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  transition: border-color var(--transition);
}

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

.stat-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: "JetBrains Mono", monospace;
  letter-spacing: -0.03em;
}

.stat-sub {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-top: 6px;
  font-weight: 500;
}

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

.stat-value.negative {
  color: var(--red);
}

.stat-sub.positive {
  color: var(--green);
}

.stat-sub.negative {
  color: var(--red);
}

/* ── Card ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.card-header h2 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-icon {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.btn-icon.spinning svg {
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.select-filter {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  outline: none;
}

.select-filter:hover {
  border-color: var(--border-light);
}

.select-filter option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* ── Table ──────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
}

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

thead th {
  text-align: left;
  padding: 14px 20px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

thead th.num {
  text-align: right;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

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

tbody tr:last-child {
  border-bottom: none;
}

tbody td {
  padding: 16px 20px;
  font-size: 1rem;
  white-space: nowrap;
}

tbody td.num {
  text-align: right;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.95rem;
}

tbody td .market-name {
  font-weight: 500;
  color: var(--text-primary);
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  font-size: 1rem;
}

tbody td .market-name a {
  color: var(--text-primary);
  text-decoration: none;
  transition: color var(--transition);
}

tbody td .market-name a:hover {
  color: var(--blue);
}

.side-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.side-badge.yes {
  background: var(--green-dim);
  color: var(--green);
}

.side-badge.no {
  background: var(--red-dim);
  color: var(--red);
}

.pnl-positive {
  color: var(--green);
  font-weight: 700;
}

.pnl-negative {
  color: var(--red);
  font-weight: 700;
}

/* ── Groups ────────────────────────────────────────────────────────────── */
.group-header-row td {
  padding: 0;
  border-bottom: none;
  background: transparent;
}

.group-header {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-tertiary);
  padding: 8px 12px;
  margin: 12px 0 4px 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  /* Use a lighter border or left accent to distinguish groups */
  border-left: 3px solid var(--blue);
}

.group-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.group-title a {
  color: var(--text-primary);
  text-decoration: none;
  transition: color var(--transition);
}

.group-title a:hover {
  color: var(--blue);
}

.timer-badge {
  background: var(--red);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
  0% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }

  100% {
    opacity: 1;
  }
}

/* ── Loading ───────────────────────────────────────────────────────────── */
.loading-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 20px;
  color: var(--text-muted);
  font-size: 1rem;
}

.loading-row td {
  text-align: center;
}

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  vertical-align: middle;
  margin-right: 8px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 20px;
  color: var(--text-muted);
  gap: 10px;
  font-size: 1rem;
}

.empty-state svg {
  opacity: 0.3;
  margin-bottom: 10px;
}

/* ── Footer ────────────────────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 24px;
  font-size: 0.9rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

.footer-sep {
  margin: 0 10px;
  opacity: 0.4;
}

/* ── Flash animation for updated values ────────────────────────────────── */
@keyframes flash-green {
  0% {
    color: var(--green);
    background: var(--green-dim);
  }

  100% {
    color: inherit;
    background: transparent;
  }
}

@keyframes flash-red {
  0% {
    color: var(--red);
    background: var(--red-dim);
  }

  100% {
    color: inherit;
    background: transparent;
  }
}

.flash-up {
  animation: flash-green 1s ease-out;
}

.flash-down {
  animation: flash-red 1s ease-out;
}

/* ── Financial Column Grouping ─────────────────────────────────────────── */
/* Mild background to group Current, Cost, Value */
th.col-group-financial,
td.col-group-financial {
  background: rgba(255, 255, 255, 0.03);
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .stats-row {
    grid-template-columns: repeat(3, 1fr);
  }
}

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

@media (max-width: 768px) {

  /* Force table to not be like tables anymore */
  table,
  thead,
  tbody,
  th,
  td,
  tr {
    display: block;
  }

  /* Hide table headers (but not display: none;, for accessibility) */
  thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }

  tbody tr {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    padding: 12px;
  }

  tbody td {
    border: none;
    border-bottom: 1px solid var(--border-light);
    position: relative;
    padding-left: 50%;
    text-align: right;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
  }

  tbody td:last-child {
    border-bottom: 0;
  }

  tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.85rem;
    text-align: left;
  }

  /* Special handling for Market Name to look like a card header */
  tbody td[data-label="Market"] {
    display: block;
    width: 100%;
    text-align: left;
    padding-left: 0;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
    margin-bottom: 8px;
  }

  tbody td[data-label="Market"]::before {
    display: none;
  }

  tbody td[data-label="Market"] .market-name {
    font-size: 1.1rem;
    font-weight: 600;
    white-space: normal;
    /* Allow wrapping */
    max-width: none;
  }

  /* Special handling for Group Header Row */
  .group-header-row {
    display: table-row;
    /* Keep it as a row if possible, or force block but handle content */
  }

  .group-header-row td {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0;
    border: none;
    background: transparent;
  }

  .group-header-row td::before {
    display: none;
  }

  .group-header {
    margin: 16px 0 8px 0;
  }
}

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

  .header {
    padding: 0 16px;
  }

  .main {
    padding: 16px;
  }

  .stat-value {
    font-size: 1.6rem;
  }
}