@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap");

:root {
  --bg: #ffffff;
  --card: #ffffff;
  --card-hover: #f3f4f7;
  --text: #0f172a;
  --text-secondary: #475569;
  --muted: #64748b;

  /* Brand colors */
  --brand: #1BAC5DFF;
  --brand-soft: rgba(27, 172, 93, 0.15);
  --brand-soft-2: rgba(27, 172, 93, 0.3);
  --sp-line: #1f2937;

  /* Accent colors for variety */
  --accent-blue: #3b82f6;
  --accent-purple: #8b5cf6;
  --accent-orange: #f59e0b;
  --accent-cyan: #06b6d4;
  --accent-pink: #ec4899;

  /* P/L colors */
  --profit: #1BAC5DFF;
  --profit-soft: rgba(27, 172, 93, 0.12);
  --loss: #ef4444;
  --loss-soft: rgba(239, 68, 68, 0.12);

  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.15);
  --surface: #f1f5f9;
  --radius: 16px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  color-scheme: light;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}

.wrap {
  display: flex;
  flex-direction: column;
  padding: 20px;
}

.widget {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* Header Section */
.top-row {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
  flex-shrink: 0;
}

@media (min-width: 768px) {
  .top-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.title-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.title {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--text) 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Year Tabs */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--card);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
  width: fit-content;
}

.tab {
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 8px;
  transition: all 0.2s ease;
  background: transparent;
  border: none;
  cursor: pointer;
}

.tab:hover:not(.is-active) {
  color: var(--text);
  background: var(--card-hover);
}

.tab.is-active {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

/* Controls */
.top-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

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

.count {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.count strong {
  color: var(--brand);
  font-weight: 800;
  font-size: 15px;
}

/* Search */
.search {
  width: 100%;
  max-width: 280px;
  position: relative;
}

.search input {
  width: 100%;
  padding: 12px 16px 12px 44px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  transition: all 0.2s ease;
}

.search input::placeholder {
  color: var(--muted);
}

.search input:focus {
  border-color: var(--brand);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.search .icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}

/* Algorithm Dropdown */
.algo-select {
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%231bac5d' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
  min-width: 180px;
}

.algo-select:hover {
  border-color: var(--brand);
}

.algo-select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.algo-select option {
  background: var(--card);
  color: var(--text);
  padding: 12px;
}

/* Card and Table Container */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.card-stack {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.table-card {
  flex: 0 0 auto;
  max-height: 550px;
  display: flex;
  flex-direction: column;
}

.chart-card {
  flex: 0 0 auto;
  min-height: 480px;
}

.table-scroll {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

/* Custom Scrollbar */
.table-scroll::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.table-scroll::-webkit-scrollbar-track {
  background: var(--card);
}

.table-scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

.table-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--brand);
}

.table-scroll::-webkit-scrollbar-corner {
  background: var(--card);
}

/* Table */
.trades-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.trades-table th,
.trades-table td {
  white-space: nowrap;
}

.trades-table th:first-child,
.trades-table td:first-child {
  white-space: normal;
}

/* Table Header */
thead th {
  position: sticky;
  top: 0;
  background: var(--brand);
  border-bottom: 2px solid rgba(0, 0, 0, 0.2);
  padding: 18px 20px;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #fff;
  text-align: left;
  z-index: 10;
}

.th-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: inherit;
  text-decoration: none;
  transition: color 0.2s;
}

.th-link:hover {
  color: var(--text);
}

.th-link .icon {
  width: 12px;
  height: 12px;
  opacity: 0.5;
}

.th-link.is-active {
  color: var(--text);
}

.th-link.is-active .icon {
  opacity: 1;
}

/* Table Body */
tbody td {
  border-bottom: 1px solid var(--border);
  padding: 16px 20px;
  font-size: 13px;
  color: var(--text);
  vertical-align: middle;
}

tbody tr {
  transition: background 0.15s ease;
}

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

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

/* Ticker Cell */
.ticker {
  display: flex;
  align-items: center;
  gap: 14px;
}

.ticker-bar {
  width: 4px;
  height: 36px;
  border-radius: 2px;
  flex-shrink: 0;
  transition: all 0.2s;
}

.ticker-bar.positive {
  background: var(--profit);
  box-shadow: 0 0 12px var(--profit-soft);
}

.ticker-bar.negative {
  background: linear-gradient(180deg, var(--loss) 0%, #dc2626 100%);
  box-shadow: 0 0 12px var(--loss-soft);
}

.ticker-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ticker-symbol {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.type-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 4px;
  width: fit-content;
}

.type-label.long {
  background: var(--brand-soft);
  color: var(--brand);
}

.type-label.short {
  background: rgba(139, 92, 246, 0.15);
  color: var(--accent-purple);
}

.ticker-note {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

/* Price/Date Details */
.detail {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.price {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.date {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

/* P/L Chip */
.pnl-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: all 0.2s;
}

.pnl-chip.positive {
  background: var(--profit-soft);
  color: var(--profit);
  border: 1px solid rgba(27, 172, 93, 0.25);
}

.pnl-chip.positive:hover {
  background: rgba(27, 172, 93, 0.2);
  box-shadow: 0 0 20px var(--profit-soft);
}

.pnl-chip.negative {
  background: var(--loss-soft);
  color: var(--loss);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.pnl-chip.negative:hover {
  background: rgba(239, 68, 68, 0.2);
  box-shadow: 0 0 20px var(--loss-soft);
}

.pnl-chip .icon {
  width: 14px;
  height: 14px;
}

/* Actions */
.actions {
  text-align: right;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  background: transparent;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.3);
  transform: translateY(-2px);
}

.icon-btn .icon {
  width: 16px;
  height: 16px;
}

/* Empty State */
.empty {
  padding: 60px 24px;
  text-align: center;
  color: var(--muted);
  font-weight: 500;
  font-size: 15px;
}

/* Generic Table (Raw View) */
.head {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

@media (min-width: 640px) {
  .head {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.meta {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.select {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
}

.btn {
  background: var(--brand);
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.body {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.body::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.body::-webkit-scrollbar-track {
  background: var(--card);
}

.body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

.body::-webkit-scrollbar-thumb:hover {
  background: var(--brand);
}

.body table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.body th,
.body td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  white-space: nowrap;
}

.body th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--brand);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.body td:last-child,
.body th:last-child {
  border-right: none;
}

.body tbody tr:hover td {
  background: var(--card-hover);
}

.pnl {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pnl.positive {
  color: var(--profit);
}

.pnl.negative {
  color: var(--loss);
}

/* Chart */
.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.chart-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.chart-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-secondary);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot.algo {
  background: var(--brand);
  box-shadow: 0 0 10px var(--brand-soft);
}

.legend-dot.sp500 {
  background: var(--sp-line);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.chart-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chart-area {
  position: relative;
  flex: 1;
  min-height: 340px;
  height: 340px;
}

.chart-container {
  width: 100%;
  height: 100%;
}

.chart-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.6), rgba(248, 250, 252, 0.95));
}

.chart-status.is-error {
  color: var(--loss);
}

.chart-stats {
  display: flex;
  gap: 16px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.chart-stat {
  min-width: 140px;
}

.chart-stat .label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
  font-weight: 700;
}

.chart-stat .value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.chart-stat .value.algo {
  color: var(--brand);
}

.chart-stat .return {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 700;
}

.chart-stat .return.positive {
  color: var(--profit);
}

.chart-stat .return.negative {
  color: var(--loss);
}

/* Responsive */
@media (max-width: 640px) {
  .wrap {
    padding: 12px;
  }

  .top-row {
    margin-bottom: 12px;
    gap: 12px;
  }

  .title {
    font-size: 22px;
  }

  .search {
    max-width: none;
  }

  thead th,
  tbody td {
    padding: 12px 14px;
  }

  .trades-table thead th:nth-child(5),
  .trades-table tbody td:nth-child(5) {
    display: none;
  }

  .ticker-symbol {
    font-size: 14px;
  }

  .price {
    font-size: 13px;
  }

  .pnl-chip {
    font-size: 12px;
    padding: 5px 10px;
  }

  .chart-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .chart-card {
    flex-basis: 300px;
    min-height: 240px;
  }
}

/* ========================================
   PERFORMANCE WIDGET - Exact /p/ replica
   ======================================== */
.perf-widget {
  background: transparent;
  padding: 20px 0;
}

.perf-title {
  text-align: center;
  font-size: 24px;
  font-weight: 400;
  color: var(--text);
  margin: 0 0 20px 0;
}

.perf-legend {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-bottom: 16px;
}

.perf-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}

.perf-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.perf-dot.algo {
  background: var(--brand);
}

.perf-dot.sp500 {
  background: var(--sp-line);
  border: 1px solid var(--border-strong);
}

.perf-chart {
  width: 100%;
  height: 500px;
  background: var(--card);
  border-radius: 8px;
}

.perf-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 500px;
  color: var(--muted);
  font-size: 14px;
}

.perf-loading:empty {
  display: none;
}

.perf-stats {
  display: flex;
  gap: 40px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

.perf-stat-card {
  background: var(--surface);
  border-radius: 8px;
  padding: 16px 24px;
  text-align: center;
  min-width: 180px;
  border: 1px solid var(--border);
}

.perf-stat-card .label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.perf-stat-card .value {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
}

.perf-stat-card .value.algo {
  color: var(--brand);
}

.perf-stat-card .value.sp500 {
  color: var(--text);
}

.perf-stat-card .return {
  font-size: 14px;
  margin-top: 4px;
}

.perf-stat-card .return.positive {
  color: var(--profit);
}

.perf-stat-card .return.negative {
  color: var(--loss);
}

/* Highcharts light theme overrides */
.perf-widget .highcharts-background {
  fill: transparent;
}

.perf-widget .highcharts-contextbutton {
  fill: var(--surface) !important;
  stroke: var(--border) !important;
}

.perf-widget .highcharts-contextbutton:hover {
  fill: var(--brand) !important;
}

.perf-widget .highcharts-menu {
  background: var(--card) !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow) !important;
  border-radius: 8px !important;
}

.perf-widget .highcharts-menu-item {
  color: var(--text) !important;
}

.perf-widget .highcharts-menu-item:hover {
  background: var(--brand) !important;
  color: #fff !important;
}
