/* SENTRI chat widget — inherits the radar's CSS variables when present,
   falls back to its own values when loaded standalone. */
:root {
  --sentri-chat-bg:      var(--bg-card, #0c1424);
  --sentri-chat-border:  rgba(59,130,246,0.35);
  --sentri-chat-accent:  var(--accent, #3b82f6);
  --sentri-chat-ink:     var(--ink, #e6edf6);
  --sentri-chat-ink-dim: var(--ink-dim, #93a4bd);
  --sentri-chat-panel:   rgba(5, 9, 18, 0.96);
  /* User-message bubble + send button. Deliberately NOT --accent: the radar's
     accent is a near-white grey (#e5e5e5) that washes out white bubble text,
     so these two elements use a dark neutral grey instead. */
  --sentri-chat-user:    #3d3d3d;
}

#sentri-chat-btn {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 9999;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--sentri-chat-border);
  background: var(--sentri-chat-bg);
  color: var(--sentri-chat-accent);
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.55),
              0 0 0 1px var(--sentri-chat-border) inset;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
#sentri-chat-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.6),
              0 0 16px var(--sentri-chat-accent);
}

/* On phones the 36px page footer sits at the bottom edge; lift the launcher
   (and the panel anchored above it) clear of the footer text. */
@media (max-width: 480px) {
  #sentri-chat-btn   { bottom: 48px; }
  #sentri-chat-panel { bottom: 112px; }
}

#sentri-chat-panel {
  display: none;
  position: fixed;
  bottom: 92px;
  left: 24px;
  z-index: 9998;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 540px;
  max-height: calc(100vh - 120px);
  background: var(--sentri-chat-panel);
  border: 1px solid var(--sentri-chat-border);
  border-radius: 12px;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.65);
  font-family: var(--font-body, system-ui, sans-serif);
  color: var(--sentri-chat-ink);
  backdrop-filter: blur(10px);
}
#sentri-chat-panel.open { display: flex; }

#sentri-chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--sentri-chat-border);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sentri-chat-accent);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.sentri-header-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sentri-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
#sentri-chat-header button {
  background: none;
  border: none;
  color: var(--sentri-chat-ink-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
#sentri-chat-header button:hover { color: var(--sentri-chat-ink); }

.sentri-admin-badge {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #22c55e;
  background: rgba(34, 197, 94, 0.10);
  border: 1px solid rgba(34, 197, 94, 0.35);
  border-radius: 4px;
  padding: 2px 6px;
  white-space: nowrap;
}
.sentri-admin-badge.hidden { display: none; }

#sentri-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sentri-msg { max-width: 88%; }
.sentri-msg-user { align-self: flex-end; }
.sentri-msg-user .sentri-bubble {
  background: var(--sentri-chat-user);
  color: #fff;
  border-radius: 12px 12px 4px 12px;
}
.sentri-msg-bot { align-self: flex-start; }
.sentri-msg-bot .sentri-bubble {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--sentri-chat-ink);
  border-radius: 12px 12px 12px 4px;
  display: block;
  white-space: normal;
}
.sentri-bubble code {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.85em;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 3px;
  padding: 1px 4px;
}
.sentri-bubble pre {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  margin: 4px 0;
  font-size: 0.82em;
  white-space: pre;
}
.sentri-bubble pre code { background: none; padding: 0; }
.sentri-bubble ul, .sentri-bubble ol {
  margin: 4px 0;
  padding-left: 18px;
}
.sentri-bubble li { margin-bottom: 2px; }
.sentri-bubble hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin: 8px 0;
}

/* Markdown headings (rendered from #…###### so they no longer show raw) */
.sentri-md-h {
  font-weight: 700;
  line-height: 1.25;
  margin: 8px 0 4px;
  color: var(--sentri-chat-ink);
}
.sentri-md-h:first-child { margin-top: 0; }
.sentri-md-h1 { font-size: 1.25em; }
.sentri-md-h2 { font-size: 1.12em; }
.sentri-md-h3 { font-size: 1.02em; }
.sentri-md-h4, .sentri-md-h5, .sentri-md-h6 {
  font-size: 0.95em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--sentri-chat-ink-dim);
}

/* Markdown tables */
.sentri-md-table {
  border-collapse: collapse;
  margin: 6px 0;
  width: 100%;
  font-size: 0.92em;
  display: block;
  overflow-x: auto;
}
.sentri-md-table th,
.sentri-md-table td {
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 4px 8px;
  text-align: left;
  vertical-align: top;
}
.sentri-md-table th {
  background: rgba(255, 255, 255, 0.06);
  font-weight: 600;
  white-space: nowrap;
}
.sentri-md-table tbody tr:nth-child(even) td { background: rgba(255, 255, 255, 0.02); }

/* Rendered math (best-effort LaTeX → glyphs; no external engine) */
.sentri-math {
  font-family: "Cambria Math", "Latin Modern Math", Georgia, serif;
  white-space: nowrap;
}
.sentri-math-block {
  display: block;
  text-align: center;
  margin: 6px 0;
  font-size: 1.05em;
  white-space: normal;
}
.sentri-math sup, .sentri-math sub { font-size: 0.72em; }
.sentri-frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  text-align: center;
  font-size: 0.9em;
  line-height: 1.05;
  margin: 0 0.12em;
}
.sentri-frac-n { border-bottom: 1px solid currentColor; padding: 0 0.3em; }
.sentri-frac-d { padding: 0 0.3em; }
.sentri-sqrt {
  border-top: 1px solid currentColor;
  padding: 0 0.15em;
}
.sentri-bubble {
  padding: 8px 12px;
  display: inline-block;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.sentri-msg-meta {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  color: var(--sentri-chat-ink-dim);
  margin-top: 2px;
  letter-spacing: 0.05em;
}

#sentri-chat-typing {
  display: none;
  padding: 4px 14px 6px;
  opacity: 0.65;
}
#sentri-chat-typing.visible { display: block; }

.sentri-thinking-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  color: var(--sentri-chat-ink-dim);
  letter-spacing: 0.04em;
}
#sentri-thinking-latest {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#sentri-thinking-toggle {
  background: none;
  border: none;
  color: var(--sentri-chat-ink-dim);
  font-size: 14px;  /* F0.1 — 1.5× the prior 9px so the disclosure caret is easy to hit */
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  opacity: 0.6;
  flex-shrink: 0;
}
#sentri-thinking-toggle:hover { opacity: 1; }

#sentri-thinking-steps {
  display: none;
  margin-top: 4px;
  max-height: 110px;
  overflow-y: auto;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 10px;
  color: var(--sentri-chat-ink-dim);
  line-height: 1.5;
}
#sentri-thinking-steps.open { display: block; }

.sentri-step {
  display: flex;
  gap: 4px;
}
.sentri-step-ts {
  color: rgba(147, 164, 189, 0.45);
  flex-shrink: 0;
  min-width: 30px;
}
.sentri-step-icon { flex-shrink: 0; width: 12px; }
.sentri-step-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sentri-step-error .sentri-step-icon,
.sentri-step-error .sentri-step-text { color: rgba(239, 68, 68, 0.6); }

#sentri-chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--sentri-chat-border);
}
#sentri-chat-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--sentri-chat-ink);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  outline: none;
}
#sentri-chat-input:focus { border-color: var(--sentri-chat-accent); }

#sentri-chat-send {
  background: var(--sentri-chat-user);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
#sentri-chat-send:hover { filter: brightness(1.15); }
#sentri-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* System / status messages (admin auth ok, admin expired, etc.) */
.sentri-msg-system { align-self: stretch; max-width: 100%; }
.sentri-msg-system .sentri-bubble {
  display: block;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-align: center;
  color: var(--sentri-chat-ink-dim);
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 6px 10px;
}
.sentri-msg-system.sentri-msg-ok .sentri-bubble {
  color: #22c55e;
  background: rgba(34, 197, 94, 0.06);
  border-color: rgba(34, 197, 94, 0.25);
}
.sentri-msg-system.sentri-msg-warn .sentri-bubble {
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.06);
  border-color: rgba(245, 158, 11, 0.25);
}

/* Slash command autocomplete — appended to body, positioned dynamically */
#sentri-slash-menu {
  display: none;
  position: fixed;
  z-index: 9999;
  background: rgba(5, 9, 18, 0.98);
  border: 1px solid var(--sentri-chat-border);
  border-radius: 8px 8px 0 0;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.4);
}
#sentri-slash-menu.open { display: block; }

/* Ghost completion text overlay */
#sentri-input-ghost {
  display: none;
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: transparent;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  box-sizing: border-box;
  overflow: hidden;
  line-height: 1.5;
}
.sentri-ghost-text { color: rgba(147, 164, 189, 0.45); }
.sentri-slash-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 14px;
  cursor: pointer;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  transition: background 0.1s;
}
.sentri-slash-item:hover,
.sentri-slash-item.active { background: rgba(59, 130, 246, 0.12); }
.sentri-slash-cmd { color: var(--sentri-chat-accent); font-weight: 600; flex-shrink: 0; }
.sentri-slash-args { color: rgba(147, 164, 189, 0.55); flex-shrink: 0; }
.sentri-slash-desc { color: var(--sentri-chat-ink-dim); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Admin token modal */
#sentri-admin-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#sentri-admin-modal.open { display: flex; }

.sentri-modal-card {
  width: min(380px, 100%);
  background: var(--sentri-chat-panel);
  border: 1px solid var(--sentri-chat-border);
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
  color: var(--sentri-chat-ink);
  font-family: var(--font-body, system-ui, sans-serif);
}
.sentri-modal-title {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sentri-chat-accent);
  margin-bottom: 8px;
}
.sentri-modal-sub {
  font-size: 12px;
  color: var(--sentri-chat-ink-dim);
  line-height: 1.5;
  margin-bottom: 14px;
}
#sentri-admin-token-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: var(--sentri-chat-ink);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  font-family: var(--font-mono, ui-monospace, monospace);
  outline: none;
  box-sizing: border-box;
}
#sentri-admin-token-input:focus { border-color: var(--sentri-chat-accent); }

.sentri-modal-error {
  margin-top: 8px;
  font-size: 11px;
  color: #ef4444;
  font-family: var(--font-mono, ui-monospace, monospace);
}
.sentri-modal-error.hidden { display: none; }

.sentri-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.sentri-modal-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: var(--sentri-chat-ink);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.sentri-modal-btn:hover { filter: brightness(1.2); }
.sentri-modal-submit {
  background: var(--sentri-chat-user);
  color: #fff;
  border-color: var(--sentri-chat-user);
}
.sentri-modal-cancel { color: var(--sentri-chat-ink-dim); }
