<!-- SAGA-STAGING · part 99 -->
    headers: {'Content-Type': 'application/json', 'x-csrf-token': csrf},
            body: JSON.stringify({epoch: epoch}),
            credentials: 'same-origin'
          }).then(function(r2){ return r2.json(); });
        }
      }).catch(function(e){ sdLog('Revoke error: ' + e.message); });
    }
    SD._sessionEpoch = null;
    SD._agentName = null;
    if(typeof refreshCockpit === 'function') refreshCockpit();
  };

  sdWatchHuman();
  sdUpdateDiag();
  if(window.console) console.log("[SolidDrive] Stage 2 bridge installed (NOT commissioned)");
})();

/* ============================================================
   COCKPIT — Epistles Tactical Control Interface
   Built 2026-10-07. Replaces developer panels with designed UX.
   Underlying logic unchanged: V219, Safety, Drive, dead-man intact.
   ============================================================ */
(function(){
  if (window._cockpitInstalled) return;
  window._cockpitInstalled = true;

  var GOLD = '#c8a860';
  var WINE = '#8b1a1a';
  var CYAN = '#4ad0e0';
  var DARK = 'rgba(8,8,12,0.92)';
  var TEXT = '#f0e8d8';
  var DIM = '#8a8578';

  /* ---------- Authority Pill (persistent, top-center) ---------- */
  var pill = document.createElement('div');
  pill.id = 'cockpit-pill';
  pill.style.cssText =
    'position:fixed;top:170px;left:50%;transform:translateX(-50%);z-index:99990;' +
    'padding:8px 20px;border-radius:20px;cursor:pointer;user-select:none;' +
    'font-family:-apple-system,system-ui,sans-serif;font-size:13px;font-weight:600;letter-spacing:1px;' +
    'background:' + DARK + ';border:1px solid ' + GOLD + ';color:' + GOLD + ';' +
    'box-shadow:0 2px 12px rgba(0,0,0,0.5);white-space:nowrap;';
  pill.textContent = '◉ YOU DRIVE';
  document.body.appendChild(pill);

  /* ---------- Emergency Takeover (bottom-center, conditional) ---------- */
  var takeover = document.createElement('div');
  takeover.id = 'cockpit-takeover';
  takeover.style.cssText =
    'position:fixed;bottom:110px;left:20px;right:20px;z-index:99991;display:none;' +
    'padding:18px;border-radius:16px;cursor:pointer;user-select:none;text-align:center;' +
    'font-family:-apple-system,system-ui,sans-serif;font-size:17px;font-weight:700;letter-spacing:2px;' +
    'background:rgba(40,8,8,0.95);border:2px solid ' + WINE + ';color:#f0c0c0;' +
    'box-shadow:0 4px 24px rgba(139,26,26,0.4);';
  takeover.textContent = '✋ TAKE CONTROL';
  document.body.appendChild(takeover);

  /* ---------- Cockpit Sheet (slide-up) ---------- */
  var sheet = document.createElement('div');
  sheet.id = 'cockpit-sheet';
  sheet.style.cssText =
    'position:fixed;left:0;right:0;bottom:0;z-index:99992;display:none;' +
    'max-height:75vh;background:' + DARK + ';' +
    'border-top:2px solid ' + GOLD + ';border-radius:20px 20px 0 0;' +
    'box-shadow:0 -8px 32px rgba(0,0,0,0.6);' +
    'font-family:-apple-system,system-ui,sans-serif;color:' + TEXT + ';' +
    'overflow-y:auto;-webkit-overflow-scrolling:touch;';

  sheet.innerHTML =
    '<div style="padding:12px 20px 20px;">' +
    '<div style="width:40px;height:4px;background:#444;border-radius:2px;margin:0 auto 16px;"></div>' +

    '<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:16px;">' +
    '<div style="font-size:18px;font-weight:700;letter-spacing:2px;color:' + GOLD + ';">COCKPIT</div>' +
    '<div id="cockpit-close" style="font-size:24px;color:' + DIM + ';cursor:pointer;padding:8px;">✕</div>' +
    '</div>' +

    /* DRIVE section */
    '<div style="margin-bottom:20px;">' +
    '<div style="font-size:12px;font-weight:600;letter-spacing:2px;color:' + DIM + ';margin-bottom:8px;">DRIVE</div>' +
    '<div id="cockpit-drive-status" style="padding:12px;border-radius:12px;background:rgba(255,255,255,0.04);margin-bottom:8px;font-size:14px;">' +
    '<span style="color:' + DIM + ';">No AI connected</span></div>' +
    '<button id="cockpit-authorize" style="width:100%;padding:16px;border-radius:12px;border:1px solid ' + GOLD + ';' +
    'background:rgba(200,168,96,0.12);color:' + GOLD + ';font-size:16px;font-weight:600;cursor:pointer;margin-bottom:8px;">' +
    'Authorize Solid Drive</button>' +
    '<button id="cockpit-aidriver-toggle" style="width:100%;padding:14px;border-radius:12px;border:1px solid #555;' +
    'background:rgba(255,255,255,0.04);color:' + TEXT + ';font-size:15px;cursor:pointer;">' +
    'Connect Your AI ▸</button>' +
    '</div>' +

    /* AI DRIVER section (collapsible form) */
    '<div id="cockpit-aidriver" style="display:none;margin-bottom:20px;">' +
    '<div style="font-size:12px;font-weight:600;letter-spacing:2px;color:' + DIM + ';margin-bottom:8px;">CONNECT YOUR AI</div>' +

    '<div style="margin-bottom:10px;">' +
    '<div style="font-size:13px;color:' + DIM + ';margin-bottom:4px;">AI Name</div>' +
    '<input id="ai-name" placeholder="My Assistant" style="width:100%;padding:12px;border-radius:8px;' +
    'background:rgba(255,255,255