html, body.ops-body {
  margin: 0; padding: 0; height: 100%; background: var(--bg); overflow: hidden;
}
.ops-body { display: flex; flex-direction: column; height: 100vh; }

/* --- Barra superior --- */
.ops-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 18px; border-bottom: 1px solid var(--border);
  background: var(--panel); flex-shrink: 0; flex-wrap: wrap;
}
.topbar-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; }
.topbar-controls { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.topbar-links { display: flex; align-items: center; gap: 12px; }
.topbar-links .back-link { color: var(--accent); text-decoration: none; font-size: 13px; }
.topbar-links .back-link:hover { text-decoration: underline; }
.last-updated { color: var(--muted); font-size: 11.5px; }

.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--green);
  animation: opspulse 2s infinite;
}
@keyframes opspulse {
  0% { box-shadow: 0 0 0 0 rgba(46,204,113,0.55); }
  70% { box-shadow: 0 0 0 6px rgba(46,204,113,0); }
  100% { box-shadow: 0 0 0 0 rgba(46,204,113,0); }
}
.live-dot.stale { background: var(--red); animation: none; }

.ctrl-group {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 10px 5px 12px;
}
.ctrl-group-label { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; margin-right: 2px; }
.ctrl-status-pill { font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: rgba(255,255,255,0.06); }
.ctrl-btn {
  padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  cursor: pointer; border: 1px solid; background: transparent; line-height: 1.4;
}
.ctrl-btn.ctrl-on { border-color: var(--green); color: var(--green); }
.ctrl-btn.ctrl-off { border-color: var(--red); color: var(--red); }
.ctrl-btn.ctrl-pause { border-color: var(--amber); color: var(--amber); }
.ctrl-btn.ctrl-resume { border-color: var(--green); color: var(--green); }
.ctrl-btn.ctrl-demo { border-color: var(--accent); color: var(--accent); }
.ctrl-btn.ctrl-live { border-color: var(--red); color: var(--red); }
.ctrl-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* --- Gráfico a pantalla completa --- */
.ops-chart-wrap {
  flex: 1 1 55%; display: flex; flex-direction: column; min-height: 200px;
  border-bottom: 1px solid var(--border);
}
.ops-chart-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px; font-size: 12.5px; color: var(--muted); flex-shrink: 0;
}
.ig-chart-status.err { color: var(--red); }
.ops-fullchart { flex: 1 1 auto; width: 100%; min-height: 150px; }

/* --- Tabla de operaciones --- */
.ops-table-wrap {
  flex: 1 1 45%; display: flex; flex-direction: column; overflow: hidden; min-height: 160px;
}
.ops-table-header-row {
  padding: 8px 16px 4px; flex-shrink: 0;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px;
}
.ops-count { font-size: 11px; color: var(--muted); }
.export-btn {
  padding: 4px 12px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
  cursor: pointer; border: 1px solid var(--green); color: var(--green); background: transparent;
}
.export-btn:hover { background: rgba(46,204,113,0.1); }
.export-btn:disabled { opacity: 0.4; cursor: wait; }
.ops-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 11px; color: var(--muted); }

.ops-filters {
  display: flex; flex-wrap: wrap; gap: 14px; padding: 4px 16px 10px; flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.filter-group { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.filter-group-label { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; margin-right: 2px; }
.filter-btn {
  padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--border); background: transparent; color: var(--muted);
}
.filter-btn:hover { border-color: var(--accent); color: var(--text); }
.filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.legend-item { display: flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-live { background: var(--accent); }
.dot-shadow { background: var(--muted); }
.dot-open { background: var(--amber); }
.dot-win { background: var(--green); }
.dot-loss { background: var(--red); }

.ops-empty { text-align: center; color: var(--muted); padding: 30px 20px; font-size: 13px; }

.ops-pagination {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 10px; flex-shrink: 0; border-top: 1px solid var(--border);
}

.ops-table { flex: 1 1 auto; overflow-y: auto; padding: 0 8px 8px; }
.ops-row {
  display: grid;
  grid-template-columns: 14px 90px 70px 66px 78px 74px 60px 70px 130px 90px;
  gap: 8px; align-items: center; padding: 6px 8px; font-size: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.ops-row-head {
  font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px;
  position: sticky; top: 0; background: var(--bg); z-index: 1; border-bottom: 1px solid var(--border);
}
.ops-row-data { cursor: pointer; }
.ops-row-data:hover { background: rgba(255,255,255,0.03); }
.col-dot .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.col-pips, .col-usd { text-align: right; font-weight: 600; }
.col-pips.positive, .col-usd.positive { color: var(--green); }
.col-pips.negative, .col-usd.negative { color: var(--red); }
.col-prob { font-size: 11px; color: var(--muted); }
.col-broker { font-size: 11px; }
.col-broker.sent { color: var(--green); }
.col-broker.rejected { color: var(--red); }

/* --- Modal --- */
.op-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.op-modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  max-width: 520px; width: 100%; max-height: 85vh; overflow-y: auto; padding: 22px;
  position: relative;
}
.op-modal-close {
  position: absolute; top: 12px; right: 14px; background: none; border: none;
  color: var(--muted); font-size: 18px; cursor: pointer;
}
.op-modal-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.op-modal-meta { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.op-modal-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; font-size: 13px; margin-bottom: 14px;
}
.op-modal-grid .label { font-size: 11px; color: var(--muted); }
.op-modal-grid .value { font-weight: 600; }
.op-modal-reasons ul { margin: 4px 0 0; padding-left: 18px; font-size: 12.5px; }
.op-modal-error { margin-top: 10px; font-size: 12.5px; color: var(--red); }

/* --- Tarjeta flotante de operación abierta (arrastrable) --- */
.open-pos-card {
  position: fixed; top: 80px; right: 20px; width: 240px; z-index: 90;
  background: var(--panel); border: 1px solid var(--amber); border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.4); user-select: none;
}
.open-pos-handle {
  padding: 8px 12px; font-size: 11.5px; font-weight: 700; color: var(--amber);
  cursor: grab; border-bottom: 1px solid var(--border); touch-action: none;
}
.open-pos-handle:active { cursor: grabbing; }
.open-pos-body { padding: 10px 12px; font-size: 12px; }
.open-pos-body .row { display: flex; justify-content: space-between; margin-bottom: 4px; }
.open-pos-body .label { color: var(--muted); }
.open-pos-body .value { font-weight: 700; }

/* Responsive: en pantallas angostas, la tabla se vuelve scroll horizontal */
@media (max-width: 800px) {
  .ops-row { grid-template-columns: 14px 80px 60px 56px 66px 64px 50px 60px 110px 76px; font-size: 11px; }
  .topbar-controls { gap: 10px; }
}

/* --- Vista móvil: filtros y tabla se reorganizan por completo --- */
@media (max-width: 600px) {
  /* En PC usamos scroll interno fijo (100vh partido en secciones) --
     en móvil eso se "paralizaba" en varios navegadores porque el 100vh
     real varía con la barra de direcciones. Se cambia a scroll normal
     de página completa, mucho más confiable en celulares. */
  html, body.ops-body { height: auto; overflow: visible; }
  .ops-body { display: block; }
  .ops-chart-wrap { height: 260px; flex: none; }
  .ops-table-wrap { flex: none; overflow: visible; }
  .ops-table { overflow: visible; max-height: none; }
  .ops-row-head { position: static; }

  .ops-topbar { padding: 8px 10px; }
  .topbar-controls { gap: 6px; width: 100%; order: 3; justify-content: flex-start; }
  .ctrl-group { padding: 3px 6px 3px 8px; }
  .ctrl-group-label { display: none; }
  .topbar-links { order: 2; }

  .ops-chart-wrap { flex: 1 1 42%; }
  .ops-table-wrap { flex: 1 1 58%; }

  /* Filtros: cada grupo en su propia fila, con scroll horizontal si hace falta */
  .ops-filters { flex-direction: column; gap: 8px; padding: 6px 10px 10px; }
  .filter-group {
    flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }
  .filter-group-label { flex-shrink: 0; }
  .filter-btn { flex-shrink: 0; }

  /* Tabla -> tarjetas apiladas, una por operación, sin scroll horizontal */
  .ops-row-head { display: none; }
  .ops-row {
    display: grid;
    grid-template-columns: 14px 1fr 1fr;
    grid-template-areas:
      "dot action status"
      "dot time time"
      "dot pips usd"
      "dot prob prob"
      "dot broker broker";
    gap: 3px 8px; padding: 10px 8px; font-size: 12px;
    border: 1px solid var(--border); border-radius: 10px; margin-bottom: 6px;
  }
  .ops-row .col-dot { grid-area: dot; align-self: start; }
  .ops-row .col-action { grid-area: action; font-weight: 700; }
  .ops-row .col-source { display: none; } /* el color del punto ya indica el origen */
  .ops-row .col-price { display: none; } /* visible en el modal */
  .ops-row .col-status { grid-area: status; text-align: right; color: var(--muted); }
  .ops-row .col-time { grid-area: time; color: var(--muted); font-size: 11px; }
  .ops-row .col-pips { grid-area: pips; text-align: left; }
  .ops-row .col-usd { grid-area: usd; text-align: right; }
  .ops-row .col-prob { grid-area: prob; }
  .ops-row .col-broker { grid-area: broker; }

  .open-pos-card { width: 200px; top: 70px; right: 10px; }
}
