:root {
  --bg: #0b0b0d;
  --panel: #141417;
  --panel-2: #1b1b1f;
  --panel-3: #232328;
  --line: #2a2a30;
  --line-2: #383840;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --gold: #e0b54a;
  --gold-2: #f3d27a;
  --gold-dim: rgba(224, 181, 74, .14);
  --rose: #e8a0b4;
  --good: #2fbf71;
  --bad: #e5544f;
  --be: #9a9890;
  --time: #5b9be8;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, rgba(224, 181, 74, .07), transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  min-height: 100vh;
}
h1, h2, h3 { margin: 0 0 .4em; font-weight: 600; letter-spacing: -.01em; }
h1 { font-family: 'Playfair Display', Georgia, serif; font-size: 30px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
p { margin: 0 0 .8em; }
a { color: var(--gold-2); }
code { background: var(--panel-3); padding: 1px 6px; border-radius: 6px; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.gold { color: var(--gold-2); }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px;
  background: rgba(11, 11, 13, .86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 34px; height: 34px; color: var(--gold); }
.brand-name { font-family: 'Playfair Display', Georgia, serif; font-size: 22px; font-weight: 600; line-height: 1; }
.brand-name em { color: var(--gold); font-style: italic; font-weight: 500; }
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.brand-sub .heart { color: var(--rose); }
.tabs { display: flex; gap: 4px; margin-left: auto; background: var(--panel); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.tab {
  background: none; border: 0; color: var(--text-2); font: inherit; font-weight: 500;
  padding: 8px 16px; border-radius: 9px; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--gold-dim); color: var(--gold-2); }

/* ---------- Pages ---------- */
.page { display: none; }
.page.active { display: block; }
.layout { display: grid; grid-template-columns: 380px 1fr; gap: 20px; padding: 20px 24px; align-items: start; }
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }
.container.narrow { max-width: 860px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h3 { margin: 0; }

/* ---------- Builder ---------- */
.builder {
  position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0 0 12px;
  scrollbar-width: thin; scrollbar-color: var(--line-2) transparent;
}
.b-section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.b-section:last-child { border-bottom: 0; }
.b-title { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--gold); font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.b-title .count { background: var(--gold-dim); color: var(--gold-2); border-radius: 99px; padding: 0 7px; font-size: 11px; letter-spacing: 0; }
.field { margin-bottom: 10px; }
.field label, .label-inline { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.label-inline { display: inline; margin: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
input[type=text], input[type=number], input[type=date], input[type=time], select, textarea {
  width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--line-2);
  border-radius: 9px; padding: 8px 10px; font: inherit; outline: none;
}
textarea { resize: vertical; min-height: 54px; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-dim); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
input[type=checkbox] { accent-color: var(--gold); width: 15px; height: 15px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; padding: 3px 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text-2);
  padding: 5px 11px; border-radius: 99px; cursor: pointer; font: inherit; font-size: 12px; font-weight: 500;
}
.chip:hover { border-color: var(--muted); color: var(--text); }
.chip.on { background: var(--gold-dim); color: var(--gold-2); border-color: rgba(224, 181, 74, .5); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; color: var(--text-2); font: inherit; font-size: 12px; font-weight: 500; padding: 6px 4px; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--panel-3); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.05) inset; }
.seg button.on.buy { color: var(--good); }
.seg button.on.sell { color: var(--bad); }

.rule {
  border: 1px solid var(--line-2); border-radius: 12px; margin-bottom: 8px; background: var(--panel-2);
  overflow: hidden;
}
.rule.off { opacity: .55; }
.rule-head { display: flex; align-items: center; gap: 8px; padding: 9px 10px; cursor: pointer; }
.rule-head .name { font-weight: 600; font-size: 13px; flex: 1; }
.rule-head .grp { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.rule-body { padding: 2px 12px 10px; border-top: 1px solid var(--line); }
.rule-body .desc { font-size: 12px; color: var(--muted); margin: 8px 0; }
.rule.collapsed .rule-body { display: none; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; font-size: 15px; line-height: 1; }
.icon-btn:hover { color: var(--text); background: var(--panel-3); }
.switch { position: relative; width: 30px; height: 18px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line-2); border-radius: 99px; transition: .15s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; width: 12px; height: 12px; left: 3px; top: 3px; background: var(--text-2); border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--gold); }
.switch input:checked + span::after { transform: translateX(12px); background: #1a1406; }

.add-menu { position: relative; }
.add-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 30;
  background: var(--panel-3); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: var(--shadow);
  padding: 6px; max-height: 360px; overflow: auto;
}
.add-list .g { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--gold); padding: 8px 8px 4px; }
.add-list button { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); font: inherit; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.add-list button:hover { background: var(--panel-2); }
.add-list button small { display: block; color: var(--muted); font-size: 11px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel-3); color: var(--text); border: 1px solid var(--line-2);
  padding: 8px 14px; border-radius: 10px; font: inherit; font-weight: 600; font-size: 13px; cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #1a1406; border-color: transparent; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.buy { background: rgba(47, 191, 113, .15); color: var(--good); border-color: rgba(47, 191, 113, .4); }
.btn.sell { background: rgba(229, 84, 79, .15); color: var(--bad); border-color: rgba(229, 84, 79, .4); }
.btn.dashed { border-style: dashed; background: transparent; color: var(--gold-2); }
.small-btn { padding: 5px 10px; font-size: 12px; margin-top: 10px; }
.run-bar { position: sticky; bottom: -12px; background: linear-gradient(180deg, transparent, var(--panel) 30%); padding: 14px 16px 2px; display: grid; grid-template-columns: 1fr auto; gap: 8px; }

/* ---------- Results ---------- */
.results { min-width: 0; }
.empty-state { text-align: center; padding: 80px 30px; border: 1px dashed var(--line-2); border-radius: var(--radius); }
.empty-state h2 { font-family: 'Playfair Display', Georgia, serif; font-size: 26px; }
.empty-state p { color: var(--muted); max-width: 520px; margin: 0 auto; }
.empty-mark { font-size: 34px; color: var(--gold); margin-bottom: 10px; }
.notice { background: rgba(250, 178, 25, .08); border: 1px solid rgba(250, 178, 25, .3); color: #f3cf7a; border-radius: 10px; padding: 9px 12px; margin-bottom: 12px; font-size: 13px; }
.notice.err { background: rgba(229, 84, 79, .08); border-color: rgba(229, 84, 79, .35); color: #f0908c; }
.run-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.run-meta b { color: var(--text-2); font-weight: 600; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--text-2); }
.kpi.hero { background: linear-gradient(160deg, rgba(224,181,74,.12), var(--panel) 60%); border-color: rgba(224,181,74,.35); }
.pos { color: var(--good); }
.neg { color: var(--bad); }

.outcome-bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; gap: 2px; margin: 8px 0 4px; }
.outcome-bar span { display: block; height: 100%; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.chart { width: 100%; height: 440px; position: relative; }
.chart.short { height: 240px; }
.chart-card { padding-bottom: 10px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
td.num, th.num { text-align: right; }
tbody tr:hover { background: var(--panel-2); }
tr.sel { background: var(--gold-dim) !important; }
tr.click { cursor: pointer; }
.table-wrap { overflow: auto; max-height: 520px; }
.mini-bar { display: inline-block; height: 8px; border-radius: 2px; vertical-align: middle; }
.bar-cell { width: 140px; }
.bar-track { position: relative; height: 10px; }
.bar-track .mid { position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--line-2); }
.bar-track .fill { position: absolute; top: 0; height: 10px; border-radius: 3px; }

.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 99px; letter-spacing: .02em; }
.pill.tp { background: rgba(47, 191, 113, .15); color: var(--good); }
.pill.sl { background: rgba(229, 84, 79, .15); color: var(--bad); }
.pill.be { background: rgba(154, 152, 144, .18); color: #cfcdc4; }
.pill.time { background: rgba(91, 155, 232, .15); color: var(--time); }
.pill.open { background: var(--panel-3); color: var(--muted); }
.dir-buy { color: var(--good); font-weight: 600; }
.dir-sell { color: var(--bad); font-weight: 600; }

.filter-chips { display: flex; gap: 6px; }

/* ---------- Strategies page ---------- */
.compare-bar { padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.strat-row { display: grid; grid-template-columns: 24px 1fr auto; gap: 12px; align-items: center; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.strat-row:last-child { border-bottom: 0; }
.strat-row .nm { font-weight: 600; }
.strat-row .meta { font-size: 12px; color: var(--muted); }
.tagline { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag { font-size: 11px; background: var(--panel-3); color: var(--text-2); padding: 1px 8px; border-radius: 99px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }

/* ---------- Data page ---------- */
.drop { display: flex; flex-direction: column; gap: 2px; align-items: center; justify-content: center; text-align: center; border: 1px dashed var(--line-2); border-radius: 12px; padding: 22px; cursor: pointer; background: var(--panel-2); }
.drop:hover { border-color: var(--gold); }
.help summary { cursor: pointer; color: var(--gold-2); margin-top: 12px; }
.help-card ol { padding-left: 20px; }
.help-card li { margin-bottom: 8px; color: var(--text-2); }
.src-row { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.src-row:last-child { border-bottom: 0; }

/* ---------- Replay ---------- */
.replay-layout .chart { height: 520px; }
.open-trade { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 10px; font-size: 13px; }
.open-trade .big { font-size: 20px; font-weight: 700; }
.tag-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-3); border: 1px solid var(--line-2); color: var(--text); padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s; z-index: 50; font-size: 13px;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 40px; justify-content: center; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line-2); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Drawing tools ---------- */
.chart.has-tools { display: flex; height: 540px; position: relative; }
.replay-layout .chart.has-tools { height: 600px; }
.draw-tb {
  width: 42px; flex: none; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 4px 0; border-right: 1px solid var(--line); overflow-y: auto; overflow-x: hidden; scrollbar-width: none;
}
.draw-tb::-webkit-scrollbar { display: none; }
.dt-grp { position: relative; display: flex; }
.dt-btn {
  width: 34px; height: 32px; flex: none; display: grid; place-items: center;
  background: none; border: 0; border-radius: 7px; color: var(--text-2); cursor: pointer; padding: 0;
}
.dt-btn svg { width: 21px; height: 21px; }
.dt-btn:hover { background: var(--panel-3); color: var(--text); }
.dt-btn.on { background: var(--gold-dim); color: var(--gold-2); }
.dt-emoji { font-size: 17px; line-height: 1; }
.dt-more {
  position: absolute; right: -5px; top: 0; bottom: 0; width: 10px; border: 0; background: none; padding: 0;
  color: var(--muted); font-size: 12px; cursor: pointer; opacity: 0; border-radius: 4px;
}
.dt-grp:hover .dt-more, .dt-more:focus { opacity: 1; }
.dt-more:hover { color: var(--gold-2); background: var(--panel-3); }
.dt-sep { width: 24px; height: 1px; background: var(--line); margin: 4px 0; flex: none; }
.draw-plot { position: relative; flex: 1; min-width: 0; }
.draw-layer { position: absolute; left: 0; top: 0; z-index: 3; pointer-events: none; touch-action: none; }
.draw-fly {
  display: none; position: absolute; z-index: 30; min-width: 230px;
  background: var(--panel-3); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: var(--shadow); padding: 5px;
}
.df-item {
  display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; color: var(--text);
  font: inherit; font-size: 13px; padding: 6px 8px; border-radius: 7px; cursor: pointer; text-align: left;
}
.df-item svg { width: 20px; height: 20px; flex: none; color: var(--text-2); }
.df-item span { flex: 1; }
.df-item kbd { font: 11px Inter, sans-serif; color: var(--muted); }
.df-item:hover { background: var(--panel-2); }
.df-item.on { color: var(--gold-2); }
.df-title { font-size: 11px; color: var(--gold); text-transform: uppercase; letter-spacing: .08em; padding: 4px 6px 6px; }
.df-emojis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; }
.df-emojis button { background: none; border: 0; font-size: 22px; padding: 6px; border-radius: 7px; cursor: pointer; }
.df-emojis button:hover { background: var(--panel-2); }
.draw-props {
  display: none; position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 5;
  align-items: center; gap: 4px; padding: 5px 7px; max-width: calc(100% - 16px); flex-wrap: wrap; justify-content: center;
  background: var(--panel-3); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: var(--shadow);
}
.draw-props .sw { width: 18px; height: 18px; border-radius: 5px; border: 2px solid transparent; cursor: pointer; padding: 0; }
.draw-props .sw.on { border-color: var(--text); }
.draw-props .lw { width: 24px; height: 22px; background: none; border: 1px solid transparent; border-radius: 6px; cursor: pointer; display: grid; place-items: center; padding: 0; }
.draw-props .lw i { display: block; width: 14px; background: var(--text-2); border-radius: 2px; }
.draw-props .lw.on { border-color: var(--line-2); background: var(--panel-2); }
.draw-props .sep { width: 1px; height: 18px; background: var(--line-2); margin: 0 3px; }
.draw-props .pb { background: none; border: 1px solid transparent; color: var(--text-2); font: inherit; font-size: 12px; font-weight: 500; padding: 3px 7px; border-radius: 6px; cursor: pointer; display: grid; place-items: center; }
.draw-props .pb:hover { background: var(--panel-2); color: var(--text); }
.draw-props .pb.on { color: var(--gold-2); }
.draw-props .pb svg { width: 16px; height: 16px; }
.draw-props .pb.del:hover { color: var(--bad); }

/* ---------- Live chart (TradingView widget) ---------- */
.live-wrap { height: calc(100vh - 190px); min-height: 480px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--panel); }
.live-wrap > div { height: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .builder { position: static; max-height: none; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .tabs { margin-left: 0; width: 100%; overflow-x: auto; }
  .tab { padding: 7px 11px; flex: 1; }
  .grid2 { grid-template-columns: 1fr; }
  .container { padding: 16px; }
  .chart { height: 340px; }
  .replay-layout .chart { height: 380px; }
  .chart.has-tools, .replay-layout .chart.has-tools { height: 460px; }
  .dt-more { opacity: 1; }
  .live-wrap { height: 70vh; }
}
