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

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #22263a;
  --border:    #2e3450;
  --text:      #e2e8f0;
  --text-muted:#8892a4;
  --green:     #22c55e;
  --red:       #ef4444;
  --yellow:    #eab308;
  --blue:      #3b82f6;
  --accent:    #6366f1;
  --radius:    8px;
  --shadow:    0 2px 12px rgba(0,0,0,.4);
}

html { font-size: 15px; }
body { background: var(--bg); color: var(--text); font-family: "Inter", system-ui, sans-serif; line-height: 1.5; }

a { color: inherit; text-decoration: none; }
hr { border: none; border-top: 1px solid var(--border); }
strong { font-weight: 600; }

/* ── Navbar ──────────────────────────────────────────────────────────────── */
.navbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 2rem; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.nav-brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.1rem; color: var(--accent); }
.nav-logo { font-size: 1rem; }
.nav-links { display: flex; gap: 1.5rem; }
.nav-links a { color: var(--text-muted); font-size: .9rem; transition: color .15s; }
.nav-links a:hover { color: var(--text); }

/* ── Container ───────────────────────────────────────────────────────────── */
.container { max-width: 1400px; margin: 0 auto; padding: 2rem; }

/* ── Page Header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 2rem;
}
.page-header h1 { font-size: 1.6rem; font-weight: 700; }

.challenge-page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap;
}
.challenge-page-header h1 { font-size: 1.5rem; font-weight: 700; }
.phase-badge {
  display: inline-block; margin-top: .25rem;
  background: var(--surface2); color: var(--accent); border: 1px solid var(--accent);
  border-radius: 20px; padding: .15rem .75rem; font-size: .8rem; font-weight: 600;
}
.header-actions { display: flex; gap: .5rem; align-items: center; flex-shrink: 0; }

/* ── Challenge Cards (index) ─────────────────────────────────────────────── */
.challenge-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem;
}
.challenge-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; cursor: pointer; transition: border-color .15s, transform .1s;
}
.challenge-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.challenge-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.challenge-name { font-weight: 700; font-size: 1rem; }
.challenge-phase { font-size: .75rem; color: var(--text-muted); background: var(--surface2); padding: .15rem .5rem; border-radius: 4px; }
.challenge-card-body { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: 1rem; }
.card-stat { display: flex; flex-direction: column; }
.card-stat-label { font-size: .75rem; color: var(--text-muted); }
.card-stat-value { font-size: .95rem; font-weight: 600; }
.challenge-card-footer { font-size: .75rem; color: var(--text-muted); }

.empty-state {
  text-align: center; padding: 4rem 2rem; color: var(--text-muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 1rem; color: var(--accent); }
.empty-state h2 { color: var(--text); margin-bottom: .5rem; }
.empty-state p { margin-bottom: 1.5rem; }

/* ── Panel ───────────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem;
}
.panel.full-width { width: 100%; }
.panel-title { font-weight: 700; font-size: .9rem; margin-bottom: 1rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.panel-subtitle { font-weight: 600; font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin: 1rem 0 .5rem; }

/* ── Top Grid Layout ─────────────────────────────────────────────────────── */
.top-grid {
  display: grid; grid-template-columns: 360px 1fr; gap: 1rem; margin-bottom: 1rem; align-items: start;
}
.right-col { display: flex; flex-direction: column; }

/* ── Config Table ────────────────────────────────────────────────────────── */
.config-table { display: flex; flex-direction: column; gap: .1rem; }
.config-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: .4rem .6rem; border-radius: 4px; font-size: .88rem;
}
.config-row:nth-child(odd) { background: var(--surface2); }
.config-row .val { font-weight: 600; color: var(--text); }

/* ── Multipliers ─────────────────────────────────────────────────────────── */
.multipliers-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.mult-item {
  background: var(--surface2); border-radius: 6px; padding: .6rem .8rem;
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
}
.mult-label { font-size: .75rem; color: var(--text-muted); }
.mult-value { font-size: 1.1rem; font-weight: 700; }

/* ── Dashboard Grid ──────────────────────────────────────────────────────── */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .75rem; }
.dash-card {
  background: var(--surface2); border-radius: 6px; padding: .75rem;
  display: flex; flex-direction: column; gap: .25rem;
}
.dash-label { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.dash-value { font-size: 1.05rem; font-weight: 700; }

/* ── Risk Display ────────────────────────────────────────────────────────── */
.risk-display { display: flex; align-items: center; gap: 1.5rem; }
.risk-item { display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.risk-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.risk-value { font-size: 1.8rem; font-weight: 800; }
.risk-value.highlight { color: var(--accent); }
.risk-divider { width: 1px; height: 40px; background: var(--border); }

/* ── Status Panel ────────────────────────────────────────────────────────── */
.status-panel { text-align: center; padding: 1rem; }
.status-label { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .25rem; }
.status-value { font-size: 1.6rem; font-weight: 900; letter-spacing: .08em; }
.status-on-track { border-color: var(--green); }
.status-on-track .status-value { color: var(--green); }
.status-warning { border-color: var(--yellow); }
.status-warning .status-value { color: var(--yellow); }
.status-high-risk { border-color: #f97316; }
.status-high-risk .status-value { color: #f97316; }
.status-failing { border-color: var(--red); background: rgba(239,68,68,.07); }
.status-failing .status-value { color: var(--red); }

/* ── Performance Grid ────────────────────────────────────────────────────── */
.perf-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.perf-item {
  background: var(--surface2); border-radius: 6px; padding: .6rem;
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
}
.perf-label { font-size: .72rem; color: var(--text-muted); }
.perf-value { font-size: 1.05rem; font-weight: 700; }

/* ── Color utilities ─────────────────────────────────────────────────────── */
.green  { color: var(--green); }
.red    { color: var(--red); }
.yellow { color: var(--yellow); }
.muted  { color: var(--text-muted); }

/* ── Trade Log ───────────────────────────────────────────────────────────── */
.trade-log-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.table-wrapper { overflow-x: auto; }
.trade-table { width: 100%; border-collapse: collapse; font-size: .83rem; }
.trade-table th {
  text-align: left; padding: .5rem .75rem; font-size: .72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.trade-table td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.trade-table tbody tr:last-child td { border-bottom: none; }
.trade-table tbody tr:hover { background: var(--surface2); }
.notes-cell { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }
.empty-trades { color: var(--text-muted); text-align: center; padding: 2rem; }

/* outcome badges */
.outcome-badge {
  display: inline-block; padding: .15rem .55rem; border-radius: 20px;
  font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
}
.outcome-win     { background: rgba(34,197,94,.15); color: var(--green); }
.outcome-loss    { background: rgba(239,68,68,.15);  color: var(--red); }
.outcome-partial { background: rgba(234,179,8,.15);  color: var(--yellow); }
.outcome-breakeven { background: rgba(148,163,184,.1); color: var(--text-muted); }
.outcome-pending { background: rgba(99,102,241,.1);  color: var(--accent); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .5rem 1.1rem; border-radius: var(--radius); font-size: .88rem;
  font-weight: 600; cursor: pointer; border: none; transition: opacity .15s, background .15s;
}
.btn:hover { opacity: .87; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface2); opacity: 1; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--red); border: 1px solid var(--red); font-size: .88rem; font-weight: 600; padding: .5rem 1rem; border-radius: var(--radius); cursor: pointer; transition: background .15s; }
.btn-danger-ghost:hover { background: rgba(239,68,68,.1); }
.btn-sm { padding: .35rem .8rem; font-size: .8rem; }
.btn-icon-danger { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 1rem; padding: .2rem .4rem; border-radius: 4px; transition: color .15s, background .15s; }
.btn-icon-danger:hover { color: var(--red); background: rgba(239,68,68,.1); }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(2px); }
.modal-box {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 1.75rem; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); z-index: 1;
}
.modal-box-sm { max-width: 420px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; }
.modal-header h2 { font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.4rem; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }
.modal-warning { color: var(--text-muted); margin-bottom: 1.25rem; line-height: 1.6; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.modal-form { display: flex; flex-direction: column; gap: .75rem; }
.form-group { display: flex; flex-direction: column; gap: .35rem; flex: 1; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: .5rem .75rem; font-size: .9rem;
  width: 100%; transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--accent); }
.form-row { display: flex; gap: .75rem; }
.form-row.four-col { flex-wrap: wrap; }
.form-row.four-col .form-group { min-width: calc(50% - .375rem); }
.form-divider { margin: .5rem 0; }
.form-section-label { font-size: .78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.hint { font-weight: 400; font-size: .75rem; color: var(--text-muted); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .top-grid { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
  .perf-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
  .container { padding: 1rem; }
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
  .form-row { flex-direction: column; }
  .risk-value { font-size: 1.4rem; }
}
