/* ========================================================================
   CWT Trading Bot — Design System v2
   Premium dark UI with indigo/emerald/rose accents
   ======================================================================== */

:root {
  /* Base surfaces */
  --bg:           #0a0e17;
  --bg-elevated:  #121826;
  --surface:      #161e2f;
  --surface-2:    #1d2740;
  --surface-hover:#223052;
  --border:       #263152;
  --border-subtle:#1c2540;

  /* Text */
  --text:        #e6ecf7;
  --text-muted:  #7d8aa0;
  --text-soft:   #a2acc0;

  /* Semantic colors */
  --indigo:      #6366f1;
  --indigo-glow: rgba(99, 102, 241, 0.18);
  --cyan:        #22d3ee;
  --green:       #22c55e;
  --green-bg:    rgba(34, 197, 94, 0.12);
  --green-border:rgba(34, 197, 94, 0.30);
  --red:         #ef4444;
  --red-bg:      rgba(239, 68, 68, 0.12);
  --red-border:  rgba(239, 68, 68, 0.30);
  --amber:       #f59e0b;
  --amber-bg:    rgba(245, 158, 11, 0.12);
  --purple:      #a855f7;

  /* Spacing scale */
  --s-1:  4px; --s-2:  8px; --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10:40px;

  /* Radius */
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px; --r-xl: 20px;

  /* Shadows */
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md:  0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg:  0 16px 40px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 0 1px var(--indigo-glow), 0 8px 24px rgba(99, 102, 241, 0.20);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(99, 102, 241, 0.08) 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--indigo); text-decoration: none; transition: color 0.15s; }
a:hover { color: #818cf8; }

/* ---------- Header / Navigation ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px;
  background: rgba(10, 14, 23, 0.80);
  backdrop-filter: saturate(150%) blur(10px);
  -webkit-backdrop-filter: saturate(150%) blur(10px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0; z-index: 10;
}
.brand a {
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.brand a::before {
  content: ""; width: 10px; height: 10px;
  background: linear-gradient(135deg, var(--indigo), var(--cyan));
  border-radius: 3px;
  box-shadow: 0 0 12px var(--indigo-glow);
}
.topbar nav { display: flex; align-items: center; gap: 4px; }
.navlink {
  color: var(--text-muted);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--r-sm);
  transition: all 0.15s;
}
.navlink:hover { color: var(--text); background: var(--surface); text-decoration: none; }
.navlink.active { color: var(--text); background: var(--surface-2); }

/* ---------- Buttons ---------- */
button, .btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.12s;
  letter-spacing: -0.005em;
}
button:hover, .btn:hover { background: var(--surface-hover); border-color: var(--indigo); }
button.primary {
  background: linear-gradient(135deg, var(--indigo) 0%, #8b5cf6 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--shadow-sm);
}
button.primary:hover {
  background: linear-gradient(135deg, #7c7ff8 0%, #9f75ff 100%);
  box-shadow: var(--shadow-glow);
}
button.link {
  background: transparent; border: none; color: var(--text-muted); padding: 6px 10px;
}
button.link:hover { color: var(--text); border: none; background: transparent; }

/* ---------- Layout ---------- */
main { padding: 28px; max-width: 1400px; margin: 0 auto; }
h1, h2, h3 { letter-spacing: -0.02em; font-weight: 700; }
h1 { font-size: 28px; margin: 0 0 8px; }
h2 { font-size: 18px; margin: 32px 0 16px; }
h3 { font-size: 15px; margin: 16px 0 8px; color: var(--text-soft); }
.muted { color: var(--text-muted); }
.muted.small { font-size: 12px; font-weight: 500; }

/* ---------- Cards & Summary ---------- */
.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.card {
  background: linear-gradient(180deg, var(--surface) 0%, rgba(19, 26, 42, 0.6) 100%);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s, border-color 0.15s;
}
.card::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--indigo), transparent);
  opacity: 0.4;
}
.card:hover { border-color: var(--surface-hover); }
.card .label {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.card .value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.card .value.win  { color: var(--green); }
.card .value.lost { color: var(--red); }
.card .hint {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 6px;
  font-weight: 500;
}
.card .hint.win  { color: var(--green); }
.card .hint.lost { color: var(--red); }
.card form + form { margin-left: 8px; margin-top: 4px; }
.card.hero {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12) 0%, rgba(34, 211, 238, 0.05) 100%);
  border-color: rgba(99, 102, 241, 0.25);
}

/* ---------- Signals Table ---------- */
.signals h2 { display: flex; align-items: baseline; gap: 10px; }
.signals-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.signals table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.signals th, .signals td {
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}
.signals th {
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.signals td { font-variant-numeric: tabular-nums; }
.signals tbody tr { transition: background 0.1s; }
.signals tbody tr:hover { background: rgba(34, 42, 66, 0.4); }
.signals tr:last-child td { border-bottom: none; }
.signals tr.status-won_tp1 td, .signals tr.status-won_tp2 td, .signals tr.status-won_tp3 td {
  background: rgba(34, 197, 94, 0.04);
}
.signals tr.status-lost td { background: rgba(239, 68, 68, 0.04); }
.signals tr.status-skipped td { opacity: 0.5; }

.signals td.live  { color: var(--text); font-weight: 500; }
.signals td.pnl   { font-weight: 600; }
.signals td.pnl.win  { color: var(--green); }
.signals td.pnl.lost { color: var(--red); }
.signals td strong { font-weight: 600; }

.signals .actions { white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.signals .actions .btn, .signals .actions button { padding: 5px 10px; font-size: 12px; }

.ts {
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
}

/* ---------- Side Pills ---------- */
.side {
  display: inline-block;
  padding: 3px 8px;
  border-radius: var(--r-sm);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.side.buy  { color: var(--green); background: var(--green-bg); border: 1px solid var(--green-border); }
.side.sell { color: var(--red);   background: var(--red-bg);   border: 1px solid var(--red-border); }

/* ---------- Status Pills ---------- */
.status {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
}
.status.pending   { color: var(--amber); background: var(--amber-bg); border-color: rgba(245, 158, 11, 0.3); }
.status.taken     { color: var(--indigo); background: var(--indigo-glow); border-color: rgba(99, 102, 241, 0.35); }
.status.won_tp1, .status.won_tp2, .status.won_tp3 { color: var(--green); background: var(--green-bg); border-color: var(--green-border); }
.status.lost      { color: var(--red); background: var(--red-bg); border-color: var(--red-border); }
.status.skipped   { color: var(--text-muted); background: var(--surface); border-color: var(--border); }

/* ---------- Tags (outcomes/levels) ---------- */
.tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: var(--r-sm);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: var(--surface-2);
  color: var(--text-muted);
  text-transform: uppercase;
  margin-right: 3px;
}
.tag.tp1 { background: rgba(34, 197, 94, 0.14); color: var(--green); }
.tag.tp2 { background: rgba(34, 197, 94, 0.22); color: var(--green); }
.tag.tp3 { background: rgba(34, 197, 94, 0.30); color: var(--green); }
.tag.sl  { background: rgba(239, 68, 68, 0.16); color: var(--red); }
.tag.open { background: rgba(245, 158, 11, 0.18); color: var(--amber); }

/* ---------- Login ---------- */
.login {
  max-width: 380px;
  margin: 10vh auto;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-elevated) 100%);
  padding: 32px;
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}
.login h1 { margin: 0 0 24px; font-size: 24px; }
.login label { display: block; margin-bottom: 20px; color: var(--text-muted); font-size: 13px; font-weight: 500; }
.login input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  margin-top: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.login input:focus {
  outline: none;
  border-color: var(--indigo);
  box-shadow: 0 0 0 3px var(--indigo-glow);
}
.login button.primary { width: 100%; padding: 12px; font-size: 14px; }
.error {
  color: var(--red);
  background: var(--red-bg);
  border: 1px solid var(--red-border);
  padding: 10px 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  margin-bottom: 16px;
}

/* ---------- Signal Detail ---------- */
.signal-detail h1 { margin: 0 0 12px; font-size: 28px; }
.signal-detail h1 .side { font-size: 16px; padding: 5px 12px; vertical-align: middle; margin-left: 12px; }
.signal-detail .meta {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 24px;
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}
.signal-detail .meta > * {
  display: inline-flex; align-items: center; gap: 6px;
}

.levels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 20px 0;
}
.levels > div {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px 16px;
  border-radius: var(--r-md);
  position: relative;
}
.levels .label {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  display: block;
}
.levels .value {
  font-size: 18px;
  font-weight: 700;
  display: block;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.levels .value.sl { color: var(--red); }
.levels .value.tp { color: var(--green); }
.levels .value.win { color: var(--green); }
.levels .value.lost { color: var(--red); }
.levels .pnl { font-size: 13px; font-weight: 600; margin-left: 4px; }

.reasons {
  background: var(--surface);
  padding: 14px 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  list-style: none;
}
.reasons li {
  padding: 6px 0;
  border-bottom: 1px dashed var(--border-subtle);
  font-size: 13px;
  color: var(--text-soft);
}
.reasons li:before { content: "▸ "; color: var(--indigo); font-weight: 700; }
.reasons li:last-child { border-bottom: none; }

.signal-detail .actions { margin: 20px 0; display: flex; gap: 10px; }
.signal-detail .win  { color: var(--green); font-weight: 600; }
.signal-detail .lost { color: var(--red); font-weight: 600; }
.signal-detail .taken { color: var(--amber); font-weight: 600; }

/* ---------- Analysis ---------- */
.analysis h2 { margin-top: 32px; display: flex; align-items: baseline; gap: 10px; }
.slim-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
table.slim {
  width: 100%;
  border-collapse: collapse;
}
table.slim th, table.slim td {
  padding: 10px 14px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border-subtle);
}
table.slim th {
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
table.slim tbody tr:hover { background: rgba(34, 42, 66, 0.3); }
table.slim tr:last-child td { border-bottom: none; }
table.slim td { font-variant-numeric: tabular-nums; }
table.slim td.win  { color: var(--green); font-weight: 600; }
table.slim td.lost { color: var(--red); font-weight: 600; }
.last10 { display: flex; gap: 3px; flex-wrap: wrap; max-width: 240px; }
.last10 .tag { margin-right: 0; font-size: 9px; padding: 2px 6px; }

/* ---------- Equity curve sparkline ---------- */
.sparkline { height: 60px; width: 100%; display: block; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  main { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .navlink { padding: 4px 8px; }
  .summary { grid-template-columns: 1fr 1fr; }
  .card .value { font-size: 22px; }
  h1 { font-size: 22px; }
  .signals th, .signals td { padding: 8px 6px; font-size: 12px; }
}
@media (max-width: 520px) {
  .summary { grid-template-columns: 1fr; }
  .signals table { font-size: 11px; }
  .signals th:nth-child(n+8), .signals td:nth-child(n+8) { display: none; }
}
