/*
 * SmartBriefer auth-overlay styles — externalized so the CSP can keep
 * `style-src 'self'` without `'unsafe-inline'`. This used to be a
 * runtime `<style>` injection by `smartbriefer-api.js#injectStyles()`,
 * which the post-v1.0.1 CSP-tightening pass moved here.
 *
 * Two responsibilities:
 *   1. FOUC guard — hide the intake form before its first paint when
 *      the user has no session token. `smartbriefer-api.js` toggles
 *      `html.smartbriefer-locked` synchronously before the parser yields.
 *   2. Auth chrome — login modal, top bar, brief picker, modals list.
 *      Mounted by `smartbriefer-api.js` at runtime; this stylesheet renders
 *      it whether or not the JS has finished setting up.
 */

/* ---------- FOUC guard ----------
   `smartbriefer-api.js` adds `html.smartbriefer-locked` synchronously at the top
   of its IIFE when no session token is present, and removes the class
   in `mountAuthenticatedShell()` once auth is resolved. Keeps every
   body child invisible during the brief window between HTML parsing
   and JS executing — except the login overlay itself. */
html.smartbriefer-locked body > *:not(#smartbriefer-login):not(.smartbriefer-overlay) {
  visibility: hidden !important;
}

/* ---------- Overlay scrim + modals ---------- */
/* ---------- MyFinAI-standard login (Tessera-first) ----------
   Dark card on the deep-blue app canvas · gradient primary button
   (gold → durazno, canonical palette · never amber #FFB547).
   Mirrors MyFinAI/api/app/web/index.html §.login-* classes so a
   Lopettia operator sees the same shape across products. */
#smartbriefer-login.smartbriefer-overlay {
  background: linear-gradient(180deg, #0A1628 0%, #142847 100%);
  backdrop-filter: none;
}
.sb-login {
  min-height: 100vh; width: 100%;
  display: grid; place-items: center; padding: 2rem;
}
.sb-login-card {
  width: min(430px, 92vw);
  background: rgba(24, 36, 64, .55);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 22px; padding: 2rem;
  text-align: center;
  color: #F2F0EB;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
.sb-login-brand {
  display: flex; align-items: center; justify-content: center;
  gap: .5rem;
  font-family: Quicksand, "SF Pro Display", sans-serif;
  font-weight: 700; font-size: 1.5rem; color: #F2F0EB;
}
.sb-login-brand img { width: 36px; height: 36px; }
.sb-login-brand .by {
  font-size: .8rem; color: rgba(242, 240, 235, .5); font-weight: 600;
  margin-left: .35rem;
}
.sb-login-sub {
  color: rgba(242, 240, 235, .65);
  font-size: .92rem; margin: .6rem 0 1.4rem;
}
.sb-tess-primary {
  width: 100%;
  background: linear-gradient(90deg, #FCE28A, #F7B285);
  color: #10203a;
  border: 0; border-radius: 12px; padding: .85rem;
  font: inherit; font-weight: 800; font-size: 1rem; cursor: pointer;
  transition: filter .12s;
}
.sb-tess-primary:hover { filter: brightness(1.05); }
.sb-login-or {
  display: flex; align-items: center; gap: .7rem;
  color: rgba(242, 240, 235, .4);
  font-size: .72rem; margin: 1.1rem 0;
}
.sb-login-or::before,
.sb-login-or::after {
  content: ""; flex: 1; height: 1px; background: rgba(255, 255, 255, .1);
}
#sb-lf { display: flex; flex-direction: column; gap: .7rem; }
#sb-lf input {
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 12px; padding: .75rem .9rem;
  color: #F2F0EB; font: inherit;
}
#sb-lf input::placeholder { color: rgba(242, 240, 235, .45); }
#sb-lf input:focus {
  outline: none;
  border-color: #5EEAD4;
  background: rgba(255, 255, 255, .09);
}
#sb-lf button {
  background: transparent;
  color: rgba(242, 240, 235, .85);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 12px; padding: .75rem;
  font: inherit; font-weight: 700; font-size: .95rem;
  cursor: pointer; margin-top: .2rem; transition: .12s;
}
#sb-lf button:hover { border-color: #F38281; color: #F38281; }
.sb-login-err {
  color: #F38281; font-size: .85rem; margin-top: .8rem;
}

/* ---------- Legacy overlay + modal (kept for other dialogs) ---------- */
.smartbriefer-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(15,23,42,0.55); display: flex;
  align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
  font-family: var(--font-body, ui-sans-serif, system-ui);
}
.smartbriefer-modal {
  background: #fff;
  /* The page sets `color: var(--lop-text-primary, #fff)` on body for the
     dark intake form. Without an explicit override here, every text
     element inside the modal — picker rows, history rows, the login
     subtitle — would inherit white-on-white and be invisible until
     hover (when `:hover` repaints the background). Lock to slate-900. */
  color: #0f172a;
  border-radius: 14px;
  padding: 28px 32px; width: min(420px, 92vw);
  box-shadow: 0 30px 80px rgba(0,0,0,0.25);
}
/* Wide-modal variant — used by the brief picker and revision history. */
.smartbriefer-modal--wide { width: min(560px, 92vw); }

/* Logomark inside a modal — sits above the title in the login form. */
.smartbriefer-modal-brand {
  display: flex; justify-content: center;
  margin-bottom: 14px;
}
.smartbriefer-modal-brand img {
  height: 64px; width: auto;
  display: block;
}
.smartbriefer-modal h2 { margin: 0 0 6px; font-size: 22px; text-align: center; }
.smartbriefer-modal p.sub { text-align: center; }
.smartbriefer-modal p.sub { color: #475569; margin: 0 0 18px; font-size: 14px; }
.smartbriefer-modal label { display: block; font-size: 13px; color: #334155; margin-top: 14px; }
.smartbriefer-modal input[type="email"],
.smartbriefer-modal input[type="password"],
.smartbriefer-modal input[type="text"],
.smartbriefer-modal input[type="search"] {
  width: 100%; box-sizing: border-box; padding: 10px 12px;
  border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14px; margin-top: 4px;
}
.smartbriefer-modal .btn-row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

.smartbriefer-btn {
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; font-size: 14px; font-weight: 500;
}
.smartbriefer-btn.primary { background: #0D9488; color: #fff; }
.smartbriefer-btn.primary:hover { background: #1e40af; }
.smartbriefer-btn.ghost { background: #fff; color: #334155; border-color: #cbd5e1; }
.smartbriefer-btn.ghost:hover { background: #f1f5f9; }
.smartbriefer-error {
  background: #fee2e2; color: #991b1b;
  padding: 9px 12px; border-radius: 8px;
  font-size: 13px; margin-top: 10px;
}

/* ---------- Top bar (mounted post-auth) ---------- */
.smartbriefer-topbar {
  position: sticky; top: 0; z-index: 500;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 24px;
  background: #0f172a; color: #f1f5f9;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
  border-bottom: 1px solid #1e293b;
}
.smartbriefer-topbar .brand {
  display: inline-flex; align-items: center; gap: 8px;
  text-decoration: none; color: inherit;
  font-weight: 600; letter-spacing: 0.02em;
}
.smartbriefer-topbar .brand img {
  height: 22px; width: auto;
  display: block;
}
.smartbriefer-topbar .brand:hover { color: #fff; }
.smartbriefer-topbar .ctx { color: #94a3b8; }
.smartbriefer-topbar .ctx strong { color: #e2e8f0; font-weight: 600; }
.smartbriefer-topbar .spacer { flex: 1; }
.smartbriefer-topbar button {
  padding: 6px 12px; border-radius: 6px; font-size: 13px;
  background: #1e293b; color: #e2e8f0; border: 1px solid #334155; cursor: pointer;
}
.smartbriefer-topbar button:hover { background: #334155; }
.smartbriefer-topbar button.primary { background: #0D9488; border-color: #0D9488; color: #fff; }
.smartbriefer-topbar button.primary:hover { background: #1e40af; }
.smartbriefer-topbar button.danger { background: transparent; color: #fca5a5; border-color: transparent; }

/* ---------- Brief picker / history modal lists ---------- */
.smartbriefer-list { max-height: 420px; overflow: auto; margin-top: 10px; }
.smartbriefer-list .row { padding: 10px; border-bottom: 1px solid #e2e8f0; cursor: pointer; }
.smartbriefer-list .row:hover { background: #f1f5f9; }
.smartbriefer-list .row .meta { color: #64748b; font-size: 12px; }

/* Result counter — sits between the search input and the list. */
.smartbriefer-list-meta {
  margin-top: 12px;
  font-size: 11px;
  color: #64748b;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.smartbriefer-list-empty {
  padding: 20px 10px;
  color: #64748b;
  font-style: italic;
  text-align: center;
}

/* ---------- JS-injected widget styling ---------- */
/* These four classes back inline style="…" attributes that used to live
   inside smartbriefer-api.js innerHTML strings. Externalized so the CSP can
   keep `style-src 'self'` without `'unsafe-inline'`. */
.smartbriefer-brief-meta { color: #64748b; }
.smartbriefer-readiness-pill { color: #0D9488; }
.smartbriefer-btn-restore { margin-top: 6px; }

/* ============ Contextus floating helper ============
   Lives in `smartbriefer-contextus.js`. The panel is anchored bottom-right
   and follows the user as they edit fields. The dock chip is what the
   user sees when the panel is minimized. */

.smartbriefer-contextus {
  position: fixed;
  right: 20px; bottom: 20px;
  width: 360px; max-width: calc(100vw - 40px);
  max-height: 60vh;
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #1e293b;
  border-radius: 14px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.45);
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 13px;
  z-index: 9000;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.smartbriefer-contextus.ctxs-open { display: flex; }

.ctxs-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #111c33 0%, #0f172a 100%);
  border-bottom: 1px solid #1e293b;
}
.ctxs-brand {
  display: inline-flex; align-items: center; gap: 8px;
  flex: 1;
  font-weight: 700; letter-spacing: 0.02em;
  color: #f1f5f9;
}
.ctxs-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%;
  background: #0D9488;
  box-shadow: 0 0 8px rgba(13, 148, 136, 0.6);
}
.ctxs-iconbtn {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
  background: transparent;
  color: #94a3b8;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 14px; line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.ctxs-iconbtn:hover {
  background: #1e293b; color: #f1f5f9; border-color: #334155;
}

.ctxs-fieldlabel {
  padding: 10px 14px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em;
  color: #94a3b8;
  border-bottom: 1px solid #1e293b;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
}

.ctxs-body {
  flex: 1;
  padding: 10px;
  overflow: auto;
  display: flex; flex-direction: column; gap: 10px;
  min-height: 80px;
}
.ctxs-loading {
  padding: 20px 0;
  text-align: center;
  color: #94a3b8;
  font-size: 12px;
}
.ctxs-empty {
  padding: 20px 0;
  text-align: center;
  color: #64748b;
  font-size: 12px;
}
.ctxs-item {
  background: #1a2540;
  border: 1px solid #2a3855;
  border-radius: 10px;
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.ctxs-suggestion {
  color: #f1f5f9;
  line-height: 1.5;
  white-space: pre-wrap;
  font-size: 13px;
}
.ctxs-rationale {
  color: #94a3b8;
  font-size: 11px;
  font-style: italic;
  border-top: 1px dashed #2a3855;
  padding-top: 6px;
}
.ctxs-actions {
  display: flex; gap: 6px; justify-content: flex-end;
  padding-top: 4px;
}
.ctxs-applybtn {
  padding: 4px 10px;
  background: transparent;
  color: #cbd5e1;
  border: 1px solid #334155;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.ctxs-applybtn:hover { background: #1e293b; border-color: #475569; color: #fff; }
.ctxs-applybtn--primary {
  background: #0D9488; color: #0a1628;
  border-color: #0D9488;
  font-weight: 600;
}
.ctxs-applybtn--primary:hover { background: #0D9488; border-color: #0D9488; color: #0a1628; }

.ctxs-refresh-bar {
  padding: 8px 12px;
  border-top: 1px solid #1e293b;
  display: flex; justify-content: flex-end; gap: 6px;
}
.ctxs-runbtn {
  padding: 4px 10px;
  background: #1e293b;
  color: #cbd5e1;
  border: 1px solid #334155;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
}
.ctxs-runbtn:hover { background: #334155; color: #fff; }
/* The ✨ Enrich variant — visually distinct so the user knows enrichment
   is the higher-effort, higher-quality path. */
.ctxs-runbtn--primary {
  background: #0D9488; color: #0a1628;
  border-color: #0D9488;
  font-weight: 600;
}
.ctxs-runbtn--primary:hover { background: #0D9488; border-color: #0D9488; color: #0a1628; }

/* Dock — collapsed-mode chip. Always present after init; visible only
   while the panel is closed. */
.smartbriefer-contextus-dock {
  position: fixed;
  right: 20px; bottom: 20px;
  display: none;
  align-items: center; gap: 8px;
  padding: 8px 14px;
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #1e293b;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em;
  cursor: pointer;
  z-index: 9000;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.smartbriefer-contextus-dock.ctxs-dock-visible { display: inline-flex; }
.smartbriefer-contextus-dock:hover {
  background: #1e293b; border-color: #334155; transform: translateY(-1px);
}

/* Settings dialog reuses .smartbriefer-overlay + .smartbriefer-modal but wants the
   selects/inputs to span the full width. */
.ctxs-settings-overlay .smartbriefer-modal select,
.ctxs-settings-overlay .smartbriefer-modal input[type="password"] {
  width: 100%; box-sizing: border-box;
  margin-top: 4px;
  padding: 9px 12px;
  font-size: 13px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
}
.ctxs-settings-overlay .smartbriefer-modal label.ctxs-toggle {
  display: flex; align-items: center; gap: 8px;
  margin-top: 16px;
  font-size: 13px; color: #334155;
}
.ctxs-settings-overlay .smartbriefer-modal label.ctxs-toggle input { width: auto; margin: 0; }
.ctxs-settings-overlay .smartbriefer-modal a {
  color: #0D9488; text-decoration: none;
}
.ctxs-settings-overlay .smartbriefer-modal a:hover { text-decoration: underline; }
.ctxs-settings-overlay .smartbriefer-modal code {
  background: #f1f5f9; padding: 1px 5px; border-radius: 3px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11px;
}

/* Per-provider links — get-key + buy-credits side-by-side, one row per
   provider. Surfaces both 'configure' and 'top up' paths so the user can
   resolve a provider error (rate limit, exhausted credit) without leaving
   SmartBriefer. */
.ctxs-provider-links {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: 14px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 12px;
}
.ctxs-provider-row {
  display: flex; align-items: center; gap: 12px;
  flex-wrap: wrap;
}
.ctxs-provider-name {
  flex: 0 0 110px;
  font-weight: 600;
  color: #334155;
}
.ctxs-provider-row a {
  flex: 0 0 auto;
  color: #0D9488;
}

/* ---------- Section §13 inline-style replacements ---------- */
/* These four classes replace inline `style="..."` attributes in
   smartbriefer.html — necessary because dropping `'unsafe-inline'` from
   the CSP `style-src` directive forbids inline styles. */
.readiness-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--ink-faint);
  margin-top: 8px;
}
.recompute-btn { margin-top: 16px; }
.preview-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.preview-hidden { display: none; margin-top: 16px; }
