:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2a7de1);
  --btn: var(--tg-theme-button-color, #2a7de1);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --buy: #1f9d55;
  --sell: #d64545;
  --warn: #c98a00;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg2);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid rgba(127, 127, 127, 0.15);
}

.title { font-weight: 700; font-size: 17px; }
.sub { color: var(--hint); font-size: 13px; }

.chip {
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  font-weight: 600;
  background: var(--bg2);
  color: var(--text);
}
.chip.paused { background: var(--warn); color: #fff; }
a.chip { text-decoration: none; font-size: 14px; }
.bar-actions { display: flex; gap: 6px; align-items: center; }
.howto { display: inline-block; margin: 2px 4px 8px; font-size: 13px; color: var(--link); text-decoration: none; }

.tabs {
  position: sticky;
  top: 61px;
  z-index: 2;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 6px 12px;
  background: var(--bg);
}
.tabs button {
  border: 0;
  border-radius: 8px;
  padding: 8px 2px;
  font-size: 13px;
  font-weight: 600;
  background: transparent;
  color: var(--hint);
}
.tabs button[aria-selected="true"] { background: var(--bg2); color: var(--text); }

h2.row { display: flex; align-items: center; justify-content: space-between; }
.toggle { font-size: 12px; text-transform: none; letter-spacing: 0; display: flex; gap: 6px; align-items: center; }
.muted { color: var(--hint); font-size: 13px; }
.hint { color: var(--hint); font-size: 12px; margin: 8px 4px; }

.modes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 8px; }
.modes button {
  border: 0;
  border-radius: 8px;
  padding: 9px 2px;
  font-size: 13px;
  font-weight: 600;
  background: var(--bg2);
  color: var(--text);
}
.modes button[aria-pressed="true"] { color: #fff; }
.modes button[aria-pressed="true"][data-mode="off"] { background: #6b7280; }
.modes button[aria-pressed="true"][data-mode="simulado"] { background: #7c5cc4; }
.modes button[aria-pressed="true"][data-mode="confirmacion"] { background: var(--warn); }
.modes button[aria-pressed="true"][data-mode="automatico"] { background: var(--buy); }

.rule-head { display: grid; grid-template-columns: 1fr 92px 36px; gap: 6px; }
input, select {
  min-width: 0;
  border: 1px solid rgba(127, 127, 127, 0.25);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  background: var(--bg);
  color: var(--text);
}
.remove { border: 0; border-radius: 8px; background: var(--bg2); color: var(--sell); font-weight: 700; }

button.wide { width: 100%; }
button.secondary { border: 0; border-radius: 10px; padding: 11px; font-weight: 600; background: var(--bg); color: var(--link); }
button.primary { border: 0; border-radius: 10px; padding: 11px 22px; font-weight: 700; background: var(--btn); color: var(--btn-text); }
button.primary:disabled { opacity: 0.4; }

.tester { display: grid; grid-template-columns: 1fr 92px; gap: 6px; }
.test-result { grid-column: 1 / -1; min-height: 20px; font-size: 14px; }

.savebar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 12px -12px -24px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid rgba(127, 127, 127, 0.15);
}

.badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--bg2); color: var(--hint); }

.chart { height: 230px; margin: 10px 0 4px; border-radius: 8px; overflow: hidden; }
.show-chart { margin-top: 10px; }

.stale { margin: 8px 12px 0; padding: 10px 12px; border-radius: 10px; background: var(--warn); color: #fff; font-size: 14px; }
.account { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.account dt { font-size: 11px; color: var(--hint); }
.account dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }

.pos { cursor: pointer; }
.pos-head { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.pos-head .profit { margin-left: auto; font-variant-numeric: tabular-nums; }
.pos-line, .pos-extra { margin-top: 4px; font-variant-numeric: tabular-nums; }
.pos-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pos-actions button {
  border: 0;
  border-radius: 10px;
  padding: 11px 4px;
  font-weight: 700;
  background: var(--bg2);
  color: var(--text);
}
.pos-actions button.danger { background: var(--sell); color: #fff; }
.pos-actions button:disabled { opacity: 0.5; }
.pos.closed { opacity: 0.6; }
.pos-head .profit.pos-plus, .r.pos { color: var(--buy); }
.pos-head .profit.pos-minus { color: var(--sell); }

.summary { font-size: 14px; white-space: pre-wrap; margin-bottom: 8px; }

.periods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 8px 0; }
.periods button { border: 0; border-radius: 8px; padding: 9px; font-weight: 600; background: var(--bg); color: var(--text); }
.periods button[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); }
.stats-block h3 { font-size: 15px; margin: 0 0 6px; }
.stats-total { font-size: 14px; margin-bottom: 8px; }
table.stats { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; margin-bottom: 10px; }
table.stats th { text-align: left; color: var(--hint); font-weight: 600; padding: 4px 2px; }
table.stats td { padding: 5px 2px; border-top: 1px solid rgba(127, 127, 127, 0.15); }
table.stats td.num, table.stats th.num { text-align: right; }
.plus { color: var(--buy); }
.minus { color: var(--sell); }

.latency {
  padding: 6px 16px;
  font-size: 12px;
  color: var(--hint);
  background: var(--bg);
}

main { padding: 8px 12px 24px; }

h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--hint);
  margin: 16px 4px 8px;
}

.count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--btn);
  color: var(--btn-text);
  text-align: center;
}

.empty { color: var(--hint); margin: 4px; }

.card {
  background: var(--bg);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
}

.card-head { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.side { padding: 2px 8px; border-radius: 6px; color: #fff; font-size: 13px; }
.side.BUY { background: var(--buy); }
.side.SELL { background: var(--sell); }
.timer { margin-left: auto; font-weight: 600; color: var(--hint); font-variant-numeric: tabular-nums; }
.timer.urgent { color: var(--sell); }

.shots { display: grid; grid-template-columns: 2fr 1fr; gap: 6px; margin: 10px 0; }
.shots img {
  width: 100%;
  border-radius: 8px;
  background: var(--bg2);
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.plan {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 10px;
  margin: 0;
}
.plan div { min-width: 0; }
.plan dt { font-size: 11px; color: var(--hint); }
.plan dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.options { display: grid; gap: 6px; }
.option {
  text-align: left;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 9px 10px;
  background: var(--bg2);
  color: var(--text);
  font: inherit;
}
.option[aria-pressed="true"] { border-color: var(--btn); }
.option:disabled { opacity: 0.55; }
.option-head { display: flex; justify-content: space-between; font-weight: 700; }
.option-rr { font-variant-numeric: tabular-nums; }
.option-plan { font-size: 13px; font-variant-numeric: tabular-nums; margin-top: 2px; }

.ai { margin-top: 10px; font-size: 14px; }
.ai ul { margin: 4px 0 0; padding-left: 18px; }
.ai .muted { color: var(--hint); }

.actions { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; margin-top: 12px; }
.actions button {
  border: 0;
  border-radius: 10px;
  padding: 13px;
  font-size: 16px;
  font-weight: 700;
}
.actions .go { background: var(--btn); color: var(--btn-text); }
.actions .no { background: var(--bg2); color: var(--text); }
.actions button:disabled { opacity: 0.5; }

.progress { margin: 10px 0 0; padding-left: 20px; font-size: 14px; }
.progress li.ok { color: var(--buy); }
.progress li.bad { color: var(--sell); }

.today { list-style: none; margin: 0; padding: 0; }
.today li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  font-size: 14px;
}
.today .what { min-width: 0; }
.today .st { color: var(--hint); font-size: 12px; }
.today .r { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.r.pos { color: var(--buy); }
.r.neg { color: var(--sell); }

.viewer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.9);
}
.viewer img { max-width: 100%; max-height: 100%; }

.error {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 11;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--sell);
  color: #fff;
}

.sim-head { font-size: 14px; }
.sim-head .clock { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.analyzing { display: flex; gap: 12px; align-items: center; border: 2px solid var(--warn); }
.spinner {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid var(--bg2);
  border-top-color: var(--warn);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.verdict.ok { background: var(--buy); color: #fff; }
.verdict.no { background: var(--bg2); color: var(--hint); }
.verdict.err { background: var(--warn); color: #fff; }
.sim .zone { margin-top: 4px; }
.sim .options { margin-top: 8px; }
.sim .card-head { flex-wrap: wrap; }

/* --- Estrategia --- */
.strat-head .field { margin-bottom: 6px; }
.strat-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.strat-tools button { padding: 9px 6px; font-size: 13px; background: var(--bg2); }
.strat-section { background: var(--bg); border-radius: 14px; margin: 10px 0; padding: 0 12px 2px; }
.strat-section[open] { padding-bottom: 12px; }
.strat-section > summary { padding: 12px 0; font-weight: 700; cursor: pointer; list-style: none; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.strat-section > summary::-webkit-details-marker { display: none; }
.strat-section > summary::after { content: "›"; margin-left: auto; color: var(--hint); transform: rotate(90deg); }
.strat-section[open] > summary::after { transform: rotate(-90deg); }
.strat-section > summary .muted { font-weight: 400; }
.strat-section .card { background: var(--bg2); }
.strat-section h2 { margin-top: 12px; }
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 12px; color: var(--hint); margin-bottom: 3px; }
.field .hint-inline { font-size: 12px; color: var(--hint); margin-top: 2px; }
.field input:not([type="checkbox"]):not([type="range"]), .field select, .field textarea { width: 100%; }
.field textarea { border: 1px solid rgba(127, 127, 127, 0.25); border-radius: 8px; padding: 9px 10px; font: inherit; font-size: 14px; background: var(--bg); color: var(--text); resize: vertical; min-height: 64px; }
.field input:invalid, .field textarea:invalid { border-color: var(--sell); }
.field.bool { display: flex; align-items: center; gap: 8px; }
.field.bool > span { display: inline; margin: 0; font-size: 14px; color: var(--text); }
.field.num { display: grid; grid-template-columns: 1fr 96px; gap: 6px; align-items: center; }
.field.num > span { grid-column: 1 / -1; }
.field.num input[type="range"] { width: 100%; margin: 0; }
.field.num input[type="number"] { padding: 7px 8px; text-align: right; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { display: flex; gap: 5px; align-items: center; padding: 6px 10px; border-radius: 999px; background: var(--bg); font-size: 13px; }
.chips label.on { background: var(--btn); color: var(--btn-text); }
.pattern-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.pattern-head .toggle { font-size: 14px; }
.pattern textarea { width: 100%; border: 1px solid rgba(127, 127, 127, 0.25); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 13px; background: var(--bg); color: var(--text); resize: vertical; }
.pattern.off textarea { opacity: 0.55; }
.sheet { position: fixed; inset: 0; z-index: 12; background: rgba(0, 0, 0, 0.5); display: flex; align-items: flex-end; }
.sheet-body { width: 100%; max-height: 88vh; overflow: auto; background: var(--bg); border-radius: 16px 16px 0 0; padding: 12px 14px calc(16px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sheet pre { white-space: pre-wrap; font-size: 12px; line-height: 1.35; background: var(--bg2); border-radius: 10px; padding: 10px; margin: 0 0 10px; }
.sheet .today li { background: var(--bg2); }
.sheet .today .what button { margin-left: 0; }
.row-actions { display: flex; gap: 6px; }
.row-actions button { border: 0; border-radius: 8px; padding: 7px 10px; font-weight: 600; background: var(--bg); color: var(--link); }
.row-actions button.danger { color: var(--sell); }
.new-profile { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-top: 10px; }
.preview-plans th, .preview-plans td { font-size: 12px; }
.strat-section .tester { margin-top: 8px; }

/* --- Reglas del gatillo --- */
.trule.off { opacity: 0.6; }
.trule-head { display: grid; grid-template-columns: 28px 1fr 36px; gap: 6px; align-items: center; margin-bottom: 8px; }
.trule-head .toggle { justify-content: center; }
.cond { border: 1px solid rgba(127, 127, 127, 0.25); border-radius: 10px; padding: 8px 10px; margin: 8px 0; background: var(--bg); }
.cond-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.cond .field:last-child { margin-bottom: 0; }
.trule .add-cond { width: 100%; margin-top: 4px; }
.trule .rhint { margin: -4px 0 8px; }
