/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  /* Surfaces — dark charcoal, blue-tinted */
  --bg-base:       oklch(0.10 0.008 240);
  --bg-sidebar:    oklch(0.115 0.009 240);
  --bg-card:       oklch(0.135 0.011 240);
  --bg-card-alt:   oklch(0.148 0.011 240);
  --bg-hover:      oklch(0.19 0.014 240);

  /* Borders */
  --border:        oklch(0.24 0.016 240);
  --border-light:  oklch(0.30 0.019 240);

  /* Accent — amber */
  --accent:        oklch(0.82 0.16 75);
  --accent-dim:    oklch(0.55 0.12 75);
  --accent-bg:     oklch(0.82 0.16 75 / 0.13);

  /* Text */
  --text-primary:  oklch(0.95 0.005 240);
  --text-secondary:oklch(0.70 0.010 240);
  --text-muted:    oklch(0.58 0.008 240);

  /* Semantic */
  --positive:      oklch(0.74 0.19 145);
  --positive-bg:   oklch(0.74 0.19 145 / 0.13);
  --negative:      oklch(0.66 0.21 25);
  --negative-bg:   oklch(0.66 0.21 25 / 0.13);
  --warning:       oklch(0.80 0.17 65);
  --warning-bg:    oklch(0.80 0.17 65 / 0.13);
  --neutral-bg:    oklch(0.50 0.005 240 / 0.12);

  /* Typography */
  --font-display:  'Chakra Petch', system-ui, sans-serif;
  --font-body:     'Barlow', system-ui, sans-serif;
  --font-mono:     'JetBrains Mono', 'Fira Code', monospace;
  --font:          var(--font-body);

  /* Geometry */
  --radius-sm:     5px;
  --radius:        9px;
  --radius-lg:     13px;

  /* Layout */
  --sidebar-w:     220px;
  --header-h:      60px;
}

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

html, body {
  height: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
ul { list-style: none; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 18px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
}

.logo-text {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.logo-sub {
  font-family: var(--font-body);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.sidebar-nav {
  padding: 14px 10px;
  flex: 1;
}

.nav-section {
  margin-bottom: 22px;
}

.nav-label {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  padding: 0 8px;
  margin-bottom: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  margin-bottom: 2px;
  letter-spacing: 0.01em;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent);
}

.nav-icon {
  width: 17px;
  height: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

/* ── Main content ────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.header {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  background: var(--bg-base);
}

.header-title {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.header-subtitle {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

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

.badge {
  padding: 3px 10px;
  border-radius: 100px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.badge-paper {
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid oklch(0.82 0.16 75 / 0.28);
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ── Stat cards ──────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s;
}

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

.stat-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.2s;
}
.stat-card:hover::after { opacity: 1; }

.stat-label {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

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

.stat-sub {
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

.stat-icon {
  position: absolute;
  top: 16px; right: 16px;
  font-size: 18px;
  opacity: 0.2;
}

/* ── Section heading ─────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.section-link {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  transition: opacity 0.15s;
}

.section-link:hover { opacity: 0.75; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin-bottom: 20px;
}

.card-title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 16px;
  color: var(--text-primary);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 9px 12px;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

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

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

tbody td {
  padding: 9px 12px;
  color: var(--text-secondary);
  vertical-align: middle;
}

.td-primary {
  color: var(--text-primary);
  font-weight: 500;
}

.td-mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

/* ── Status badges ───────────────────────────────────────────────────────── */
.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 100px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.status::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-open    { background: var(--warning-bg);  color: var(--warning);  }
.status-open::before    { background: var(--warning);  }
.status-won     { background: var(--positive-bg); color: var(--positive); }
.status-won::before     { background: var(--positive); }
.status-lost    { background: var(--negative-bg); color: var(--negative); }
.status-lost::before    { background: var(--negative); }
.status-void    { background: var(--neutral-bg);  color: var(--text-muted); }
.status-void::before    { background: var(--text-muted); }

/* ── P&L values ──────────────────────────────────────────────────────────── */
.pnl-pos {
  color: var(--positive);
  font-weight: 600;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.pnl-neg {
  color: var(--negative);
  font-weight: 600;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.pnl-nil {
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Filters ─────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.filter-label {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.filter-select, .filter-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 14px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  letter-spacing: 0.02em;
}

.filter-select:focus, .filter-btn:hover {
  border-color: var(--border-light);
  color: var(--text-primary);
  outline: none;
}

.filter-btn-active {
  background: var(--accent-bg);
  border-color: oklch(0.82 0.16 75 / 0.35);
  color: var(--accent);
}

/* ── Sport mini-cards (overview) ─────────────────────────────────────────── */
.sport-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.sport-card {
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}

.sport-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sport-name {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-primary);
}

.sport-emoji { font-size: 18px; }

.sport-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sport-stat-label {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.sport-stat-value {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ── Chart ───────────────────────────────────────────────────────────────── */
.chart-wrap {
  position: relative;
  height: 240px;
}

/* ── Performance breakdown tables ────────────────────────────────────────── */
.breakdown-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 24px;
  color: var(--text-muted);
}

.empty-state-icon { font-size: 32px; margin-bottom: 10px; }
.empty-state-text { font-family: var(--font-body); font-size: 13px; }

/* ── Confidence bar ──────────────────────────────────────────────────────── */
.conf-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.conf-bar {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  max-width: 72px;
}

.conf-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

.conf-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ── Run / action buttons ────────────────────────────────────────────────── */
.run-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 15px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: oklch(0.12 0.010 240);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}

.run-btn:hover  { opacity: 0.85; transform: translateY(-1px); }
.run-btn:active { transform: translateY(0); }
.run-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.run-btn-secondary {
  background: var(--bg-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.run-btn-secondary:hover { opacity: 1; background: var(--bg-hover); border-color: var(--border-light); color: var(--text-primary); }

/* ── Mobile nav & FAB (hidden on desktop) ────────────────────────────────── */
.mobile-nav   { display: none; }
.mobile-fab   { display: none; }
.mobile-sheet { display: none; }

/* ── Large desktop ────────────────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ── Tablet: icon-only sidebar (768–900px) ────────────────────────────────── */
@media (min-width: 768px) and (max-width: 900px) {
  .sidebar { width: 56px; }
  .logo-text, .logo-sub, .nav-label, .nav-item span:last-child { display: none; }
  .sidebar-logo { justify-content: center; padding: 16px 0; }
  .nav-item { justify-content: center; padding: 10px; }
  .breakdown-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Mobile (≤767px) ──────────────────────────────────────────────────────── */
@media (max-width: 767px) {

  html, body { height: auto; }
  .layout { flex-direction: column; height: auto; min-height: 100vh; overflow: visible; }
  .main { overflow: visible; height: auto; }
  .content {
    flex: none;
    overflow-y: visible;
    padding: 12px 12px calc(60px + 18px);
  }

  .sidebar { display: none; }

  .header { height: auto; min-height: 52px; padding: 10px 14px; gap: 8px; flex-wrap: wrap; }
  .header-title { font-size: 15px; }
  .header-subtitle { display: none; }
  .badge-paper { display: none; }
  #runBtn, #settleBtn, #retrainBtn { display: none; }

  .stat-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; margin-bottom: 14px; }
  .stat-value { font-size: 20px; }
  .stat-card { padding: 13px 14px; }

  .card { padding: 13px 14px; margin-bottom: 12px; }

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

  .table-wrap { -webkit-overflow-scrolling: touch; }

  .filter-bar { gap: 5px; margin-bottom: 12px; }
  .filter-btn, .filter-select { font-size: 11px; padding: 5px 11px; }

  /* ── Bottom navigation bar ──────────────────────────────────────────── */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 60px;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    z-index: 100;
    align-items: stretch;
  }

  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-muted);
    font-family: var(--font-display);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 6px 2px 4px;
    text-decoration: none;
    transition: color 0.15s;
    text-transform: uppercase;
  }

  .mobile-nav-item.active { color: var(--accent); }
  .mobile-nav-item:hover  { color: var(--text-secondary); }
  .mobile-nav-icon { font-size: 19px; line-height: 1; }

  /* ── Floating action button ─────────────────────────────────────────── */
  .mobile-fab {
    display: flex;
    position: fixed;
    bottom: 72px; right: 16px;
    z-index: 150;
    width: 50px; height: 50px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: oklch(0.12 0.010 240);
    font-size: 20px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px oklch(0.82 0.16 75 / 0.35);
    transition: transform 0.2s;
  }
  .mobile-fab:active { transform: scale(0.92); }

  /* ── Action sheet ───────────────────────────────────────────────────── */
  .mobile-sheet { display: none; position: fixed; inset: 0; z-index: 200; }
  .mobile-sheet.open { display: block; }

  .mobile-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: oklch(0.05 0.005 240 / 0.7);
  }

  .mobile-sheet-panel {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: calc(60px + 8px);
    overflow: hidden;
  }

  .mobile-sheet-title {
    font-family: var(--font-display);
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    padding: 14px 20px 10px;
  }

  .mobile-sheet-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 16px 20px;
    background: none;
    border: none;
    border-top: 1px solid var(--border);
    color: var(--text-primary);
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
  }
  .mobile-sheet-btn:active { background: var(--bg-hover); }
  .mobile-sheet-icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; color: var(--accent); }
}

/* ── Reduced motion ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
