/* ================================================================
   style.css  –  Strategy Rotation Simulator
   ================================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  color: #222;
  background: #f7f8fa;
  padding: 16px;
}

/* ── Controls panel ─────────────────────────────────────────── */

.panel {
  background: #fff;
  border: 1px solid #dde1e7;
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 16px;
}

.panel h2 {
  font-size: 15px;
  font-weight: 600;
  color: #1a1a2e;
  margin-bottom: 14px;
  border-bottom: 2px solid #2563eb;
  padding-bottom: 6px;
  display: inline-block;
}

/* ── Strategy grid ───────────────────────────────────────────── */

.strategy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px 16px;
  margin-bottom: 12px;
}

.family-group {
  background: #f9fafc;
  border: 1px solid #e4e8f0;
  border-radius: 5px;
  padding: 8px 10px;
}

.family-name {
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #1e3a5f;
  margin-bottom: 6px;
}

.family-items {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}

.family-items label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #333;
  cursor: pointer;
  white-space: nowrap;
}

.family-items input[type="checkbox"] {
  width: 13px;
  height: 13px;
  cursor: pointer;
  accent-color: #2563eb;
}

/* Select-all toolbar */
.sel-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.btn-sm {
  font-size: 11px;
  padding: 3px 10px;
  border: 1px solid #b0bad0;
  border-radius: 3px;
  background: #f0f4ff;
  color: #1e3a5f;
  cursor: pointer;
}
.btn-sm:hover { background: #dce8ff; }

/* ── Run-controls row ─────────────────────────────────────────── */

.run-row {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ctrl-group label {
  font-size: 11px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ctrl-group select,
.ctrl-group input[type="number"] {
  border: 1px solid #c8d0dc;
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 13px;
  color: #222;
  background: #fff;
  outline: none;
}
.ctrl-group select:focus,
.ctrl-group input:focus { border-color: #2563eb; }

.ctrl-group input[type="number"] { width: 80px; }

.radio-opt {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: normal;
  font-size: 12px;
  color: #333;
  cursor: pointer;
}

.period-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
}

.period-row input[type="number"] {
  width: 54px;
  border: 1px solid #c8d0dc;
  border-radius: 4px;
  padding: 3px 5px;
  font-size: 12px;
  outline: none;
}

.period-row input[readonly] {
  background: #f0f2f5;
  color: #777;
}

.period-row span {
  font-size: 11px;
  color: #555;
}

.btn-run {
  padding: 7px 24px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: background 0.15s;
}
.btn-run:hover  { background: #1d4ed8; }
.btn-run:active { background: #1e40af; }
.btn-run:disabled { background: #93a8d4; cursor: not-allowed; }

/* ── Error / validation messages ─────────────────────────────── */

.error-msg {
  color: #b91c1c;
  font-size: 12px;
  margin-top: 6px;
  min-height: 16px;
}

/* ── Loading overlay ─────────────────────────────────────────── */

.loading {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  color: #555;
  font-size: 13px;
}
.loading.active { display: flex; }

.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid #dde1e7;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Results panel ────────────────────────────────────────────── */

#results { display: none; }
#results.visible { display: block; }

/* ── Warnings ─────────────────────────────────────────────────── */

.warnings {
  background: #fffbeb;
  border: 1px solid #fbbf24;
  border-radius: 4px;
  padding: 8px 12px;
  margin-bottom: 12px;
}

.warning-item {
  font-size: 12px;
  color: #92400e;
  line-height: 1.6;
}

/* ── Monthly returns table ────────────────────────────────────── */

.table-wrap {
  overflow-x: auto;
  margin-bottom: 10px;
}

.rt-table {
  border-collapse: collapse;
  font-size: 12px;
  white-space: nowrap;
  width: 100%;
}

.rt-table thead tr {
  background: #1a1a2e;
  color: #fff;
}

.rt-table th {
  padding: 6px 8px;
  text-align: right;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.03em;
}

.rt-table th:first-child { text-align: left; }

.rt-table td {
  padding: 3px 7px;
  text-align: right;
  border-bottom: 1px solid #eef0f4;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.rt-table tbody tr:nth-child(even):not(.spy-row):not(.spy-detail-row) {
  background: #f9fafb;
}

.rt-table tbody tr:hover:not(.spy-row) { background: #eef4ff; }

.row-label {
  text-align: left !important;
  font-weight: 600;
  color: #1a1a2e;
  padding-left: 8px !important;
}

.year-col {
  font-weight: 700;
  border-left: 2px solid #dde1e7;
}

.pos { color: #166534; }
.neg { color: #991b1b; }

.cell-empty {
  color: #ccc;
  text-align: right;
}

/* SPY benchmark rows */
.spy-row {
  background: #f0f4ff !important;
  border-top: 2px solid #93afd4;
}

.spy-row .spy-label {
  color: #1e3a5f;
  font-style: italic;
}

.spy-row .spy-year-col {
  font-size: 11px;
  font-style: italic;
}

.spy-detail-row { background: #f8faff !important; }
.spy-detail-row .spy-detail-label {
  font-weight: 400;
  font-size: 11px;
  color: #4a5568;
}
.spy-cell { opacity: 0.85; }

/* ── Stats bar ────────────────────────────────────────────────── */

.stats-row {
  display: flex;
  gap: 40px;
  flex-wrap: wrap;
  margin: 8px 0 20px;
}

.stat {
  font-size: 14px;
  font-weight: 700;
}

/* ── Equity curve chart ───────────────────────────────────────── */

.chart-container {
  position: relative;
  height: 340px;
  background: #fff;
  border: 1px solid #dde1e7;
  border-radius: 5px;
  padding: 12px;
}

/* ── Trades table ─────────────────────────────────────────────── */

#trades-container {
  margin-top: 20px;
}

.trades-table {
  border-collapse: collapse;
  font-size: 12px;
  width: 100%;
}

.trades-table thead tr {
  background: #1a1a2e;
  color: #fff;
}

.trades-table th {
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.trades-table td {
  padding: 5px 10px;
  border-bottom: 1px solid #eef0f4;
  vertical-align: top;
}

.trades-table tbody tr:nth-child(even) { background: #f9fafb; }
.trades-table tbody tr:hover            { background: #eef4ff; }

.trade-quarter {
  font-weight: 700;
  white-space: nowrap;
  color: #1a1a2e;
}

.trade-date {
  white-space: nowrap;
  color: #555;
  font-variant-numeric: tabular-nums;
}

.trade-holdings {
  line-height: 1.7;
}

.trade-cash { color: #888; font-style: italic; }

/* ── Current rankings table ──────────────────────────────────── */

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a2e;
  margin: 18px 0 8px;
  border-bottom: 1px solid #dde1e7;
  padding-bottom: 5px;
}

.rankings-table {
  border-collapse: collapse;
  font-size: 12px;
  width: auto;
  min-width: 320px;
}

.rankings-table thead tr { background: #1a1a2e; color: #fff; }

.rankings-table th {
  padding: 6px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.rankings-table td {
  padding: 5px 12px;
  border-bottom: 1px solid #eef0f4;
  white-space: nowrap;
}

.rankings-table tbody tr:nth-child(even) { background: #f9fafb; }
.rankings-table tbody tr:hover           { background: #eef4ff; }

.rank-num   { text-align: center; color: #555; width: 44px; }
.rank-score { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.rankings-pair {
  display: flex;
  gap: 32px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.rankings-col { flex: 0 0 auto; }

.trade-ret {
  font-weight: 700;
  white-space: nowrap;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Family-level substitute (ShadowVega & VTT) ─────────────── */

.family-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.family-header .family-name {
  margin-bottom: 0;
}
.family-fallback-sel {
  font-size: 10px;
  padding: 1px 2px;
  max-width: 100px;
  border: 1px solid #b0bad0;
  border-radius: 3px;
  background: #f0f4ff;
  color: #1e3a5f;
  cursor: pointer;
}
.sub-label {
  font-size: 0.85em;
  color: #777;
  font-style: italic;
}

/* ── Custom strategy upload ──────────────────────────────────── */

.custom-section {
  margin: 8px 0 12px;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fafafa;
}
.custom-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.custom-section-title {
  font-weight: 600;
  font-size: 0.85rem;
}
.custom-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  font-size: 0.85rem;
}
.btn-delete {
  color: #c00;
  padding: 1px 5px;
}
.custom-empty {
  font-size: 0.8rem;
  color: #888;
}

/* ── Responsive tweaks ───────────────────────────────────────── */

@media (max-width: 600px) {
  body { padding: 8px; }
  .run-row { gap: 12px; }
  .stats-row { gap: 20px; }
  .rt-table { font-size: 11px; }
}
