/* The Terminal's header as a slim bar on the LEFT -- 2026-09-30.
 *
 * Asked for: the header's contents (Fund Intelligence, the apps button, READY,
 * BACKEND UP, language, Logout) in one vertical place on the left, Logout at
 * the bottom, next to the Assistant's own controls rail. The Terminal's source
 * is not in this repository (only its built bundle), so this RESTYLES the same
 * header element -- nothing is moved or re-created, every control keeps its
 * own behaviour, and deleting this file's <link> restores the top bar.
 *
 * Phones keep the top bar: a vertical bar would take too much of a small screen.
 */
@media (min-width: 761px) {
  :root { --purifi-left-rail: 78px; }

  .terminalRoot { padding-left: var(--purifi-left-rail); box-sizing: border-box; }

  .terminalRoot > header.topBar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--purifi-left-rail);
    box-sizing: border-box;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    gap: 10px;
    padding: 12px 6px;
    border-bottom: none;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: visible;
    scrollbar-width: none;
  }
  .terminalRoot > header.topBar::-webkit-scrollbar { display: none; }

  /* The build line was already hidden in practice; keep the bar quiet. */
  .terminalRoot > header.topBar > .brand { display: none; }

  /* "Fund Intelligence" / "Portfolio Intelligence" label: hidden in the bar
     (2026-09-30, asked for). Still shown in the phone top bar. */
  /* !important: the element carries an inline display:flex, which beats a normal rule. */
  .terminalRoot > header.topBar > div:not(.status) { display: none !important; }

  /* Everything else stacks; Logout (the last control) sits at the bottom. */
  .terminalRoot > header.topBar > .status {
    flex: 1 1 auto;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    min-height: 0;
  }
  .terminalRoot > header.topBar > .status > * {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin-right: 0 !important;
    text-align: center;
    justify-content: center;
  }
  .terminalRoot > header.topBar > .status .pill {
    font-size: 10px;
    padding: 4px 2px;
    white-space: normal;
    line-height: 1.2;
  }
  .terminalRoot > header.topBar > .status button,
  .terminalRoot > header.topBar > .status select {
    font-size: 11px;
    padding: 5px 2px;
    white-space: normal;
    line-height: 1.2;
  }
  .terminalRoot > header.topBar > .status > :last-child { margin-top: auto; }

  /* Language: globe on top, the language's name underneath, readable at the
     bar's width. Its inline min-width of 100px is what pushed it off the edge
     ("🌐 Englis…"); the ▼ is dropped -- the whole button opens the menu. */
  .terminalRoot > header.topBar .langSelector { display: block !important; width: 100%; }
  .terminalRoot > header.topBar .langToggle {
    width: 100% !important;
    min-width: 0 !important;
    flex-direction: column !important;
    justify-content: center !important;
    gap: 2px !important;
    padding: 6px 2px !important;
    font-size: 12px !important;
    font-weight: 600;
    line-height: 1.15;
  }
  .terminalRoot > header.topBar .langToggle > span:first-child { font-size: 18px !important; }
  .terminalRoot > header.topBar .langToggle > span:nth-child(2) {
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: center;
  }
  .terminalRoot > header.topBar .langToggle > span:last-child { display: none; }

  /* The ASI-Evolve button (round, brain icon): in the bar, just above Logout;
     its panel opens beside the bar. Its position is an inline style, hence
     !important. */
  .asiEvolveOverlayMinimized {
    left: calc((var(--purifi-left-rail) - 48px) / 2) !important;
    right: auto !important;
    bottom: 58px !important;
  }
  .asiEvolveOverlay {
    left: calc(var(--purifi-left-rail) + 10px) !important;
    right: auto !important;
    bottom: 16px !important;
  }
  /* Keep Logout clear of the button above it. */
  .terminalRoot > header.topBar { padding-bottom: 12px; }
}

/* 2026-09-30: phones. The top bar was wider than the screen -- language and
 * Logout were off the right edge with no way to reach them -- and took ~15% of
 * the height for the build line. Now one compact row that always fits (and
 * scrolls sideways on a very narrow phone rather than hiding anything). */
@media (max-width: 760px) {
  .terminalRoot > header.topBar {
    flex-wrap: nowrap;
    gap: 6px;
    padding: 6px 8px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .terminalRoot > header.topBar::-webkit-scrollbar { display: none; }
  .terminalRoot > header.topBar > .brand,
  .terminalRoot > header.topBar > div:not(.status) { display: none !important; }
  .terminalRoot > header.topBar > .status {
    flex: 1 1 auto;
    flex-wrap: nowrap;
    gap: 6px;
    min-width: 0;
  }
  .terminalRoot > header.topBar > .status .pill { font-size: 10px; padding: 3px 7px; white-space: nowrap; }
  .terminalRoot > header.topBar > .status button { font-size: 12px; padding: 4px 8px; white-space: nowrap; margin-right: 0 !important; }
  /* Language: the globe only; the list still opens on tap. */
  .terminalRoot > header.topBar .langToggle { min-width: 0 !important; padding: 4px 8px !important; gap: 0 !important; }
  .terminalRoot > header.topBar .langToggle > span:nth-child(2),
  .terminalRoot > header.topBar .langToggle > span:last-child { display: none; }
  /* Logout at the far right. */
  .terminalRoot > header.topBar > .status > :last-child { margin-left: auto; }

  /* Less chrome around the tab content, so the Assistant gets the width. */
  .terminalRoot > .grid { padding: 0 !important; gap: 0 !important; }
  .terminalRoot > .grid .panel { padding: 2px !important; border-radius: 0 !important; border-left: none !important; border-right: none !important; }

  /* Command bar: the input takes the width; the "PURIFI>" label and the voice
     picker (cut off at the right) are dropped; mic and voice toggle stay. */
  .terminalRoot footer.cmdBar { gap: 6px; padding: 6px 8px; }
  .terminalRoot footer.cmdBar > .prompt,
  .terminalRoot footer.cmdBar > select { display: none; }
  .terminalRoot footer.cmdBar > .cmdInput { min-width: 0; font-size: 16px; padding: 8px 10px; }
  .terminalRoot footer.cmdBar > button { flex: 0 0 auto; padding: 6px 8px; }

  /* iOS zooms in on any input under 16px; that made the page jump on tap. */
  .terminalRoot input,
  .terminalRoot textarea,
  .terminalRoot select { font-size: 16px; }

  /* The ASI-Evolve button: in the top bar, centred between the globe and
     Logout -- send-to-assistant.js measures the gap and sets these two
     variables (fallback until it runs: top right, clear of everything). Its
     panel opens as a sheet under the bar. */
  .asiEvolveOverlayMinimized {
    width: 34px !important;
    height: 34px !important;
    left: var(--asi-phone-left, calc(100% - 44px)) !important;
    top: var(--asi-phone-top, 8px) !important;
    right: auto !important;
    bottom: auto !important;
  }
  .asiEvolveOverlay {
    left: 8px !important;
    right: 8px !important;
    width: auto !important;
    top: calc(var(--asi-phone-top, 8px) + 44px) !important;
    bottom: auto !important;
    max-height: 70vh;
    overflow-y: auto;
  }
}

/* SSO Form and Login Recovery classes (CSP compliant, no inline styles) */
#purifi-sso-form {
  display: none;
  gap: 6px;
  margin-top: 6px;
  flex-direction: column;
}
#purifi-sso-form.open {
  display: flex !important;
}
#purifi-sso-btn.hidden {
  display: none !important;
}
.purifi-sso-input {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.04);
  color: inherit;
  font: inherit;
}
.purifi-sso-submit {
  justify-content: center !important;
}
.purifi-sso-note {
  font-size: 12px;
  opacity: .8;
}

.purifi-recovery-root {
  font-family: system-ui, sans-serif;
  padding: 24px;
  color: #d7e3ff;
  background: #0a0e1a;
  min-height: 100vh;
}
.purifi-recovery-title {
  margin: 0 0 12px;
}
.purifi-recovery-msg {
  opacity: .85;
  line-height: 1.5;
}
.purifi-recovery-actions {
  margin-top: 16px;
}
.purifi-recovery-btn {
  padding: 8px 14px;
  cursor: pointer;
}
.purifi-recovery-btn-secondary {
  margin-left: 8px;
}


/* 2026-10-19: Upgrade Button next to Logout & In-app Pricing Modal */
.terminalRoot > header.topBar > .status > .purifi-upgrade-btn {
  margin-top: auto !important;
  margin-bottom: 6px !important;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
  color: #ffffff !important;
  border: 1px solid rgba(16, 185, 129, 0.45) !important;
  border-radius: 6px !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  padding: 6px 4px !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 4px !important;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
  box-shadow: 0 1px 4px rgba(16, 185, 129, 0.28) !important;
  letter-spacing: 0.02em !important;
  line-height: 1.2 !important;
}
.terminalRoot > header.topBar > .status > .purifi-upgrade-btn:hover {
  filter: brightness(1.12) !important;
  box-shadow: 0 3px 10px rgba(16, 185, 129, 0.45) !important;
  transform: translateY(-1px) !important;
}
.terminalRoot > header.topBar > .status > .purifi-upgrade-btn:active {
  transform: translateY(0) !important;
  filter: brightness(0.95) !important;
}
.terminalRoot > header.topBar > .status > .purifi-upgrade-btn.is-trial {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%) !important;
  border-color: rgba(56, 189, 248, 0.45) !important;
  box-shadow: 0 1px 4px rgba(2, 132, 199, 0.28) !important;
}
.terminalRoot > header.topBar > .status > .purifi-upgrade-btn.is-trial:hover {
  box-shadow: 0 3px 10px rgba(2, 132, 199, 0.45) !important;
}
.terminalRoot > header.topBar > .status > .purifi-upgrade-btn.is-active-plan {
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%) !important;
  border-color: rgba(99, 102, 241, 0.45) !important;
}
.terminalRoot > header.topBar > .status > .purifi-upgrade-btn .upgrade-trial-badge {
  background: rgba(255, 255, 255, 0.25) !important;
  border-radius: 10px !important;
  padding: 1px 5px !important;
  font-size: 9px !important;
  font-weight: 700 !important;
  line-height: 1 !important;
  color: #ffffff !important;
}
.terminalRoot > header.topBar > .status > .purifi-upgrade-btn + :last-child {
  margin-top: 0 !important;
}

@media (max-width: 760px) {
  .terminalRoot > header.topBar > .status > .purifi-upgrade-btn {
    margin-left: auto !important;
    margin-right: 6px !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    width: auto !important;
    padding: 4px 8px !important;
  }
  .terminalRoot > header.topBar > .status > .purifi-upgrade-btn + :last-child {
    margin-left: 0 !important;
  }
}

/* Pricing & Subscription Modal Overlay */
#purifi-pricing-overlay {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: none;
}
#purifi-pricing-overlay .purifi-pricing-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 14, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
}
#purifi-pricing-overlay .purifi-pricing-container {
  width: 100%;
  max-width: 1040px;
  height: 94vh;
  max-height: 900px;
  background: #0d1117;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.7);
  animation: purifiFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes purifiFadeIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}
#purifi-pricing-overlay .purifi-pricing-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #161b22;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
#purifi-pricing-overlay .purifi-pricing-brand {
  font-size: 13px;
  font-weight: 600;
  color: #38bdf8;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 8px;
}
#purifi-pricing-overlay .purifi-pricing-sparkle {
  color: #fbbf24;
  font-size: 16px;
}
#purifi-pricing-overlay .purifi-pricing-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
#purifi-pricing-overlay .purifi-pricing-back {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #38bdf8;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  align-items: center;
  gap: 4px;
}
#purifi-pricing-overlay .purifi-pricing-back:hover {
  background: rgba(56, 189, 248, 0.25);
  border-color: #38bdf8;
  color: #ffffff;
}
#purifi-pricing-overlay .purifi-pricing-popout {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #94a3b8;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
}
#purifi-pricing-overlay .purifi-pricing-popout:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.3);
}
#purifi-pricing-overlay .purifi-pricing-close {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #94a3b8;
  font-size: 16px;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}
#purifi-pricing-overlay .purifi-pricing-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.3);
}
#purifi-pricing-overlay .purifi-pricing-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: transparent;
}

/* In-System Checkout Status View */
#purifi-pricing-overlay .purifi-checkout-status-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: radial-gradient(circle at 50% 30%, rgba(56, 189, 248, 0.08) 0%, rgba(13, 17, 23, 0.98) 70%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #f1f5f9;
}
#purifi-pricing-overlay .purifi-checkout-status-card {
  max-width: 560px;
  width: 100%;
  background: #161b22;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 36px 32px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
#purifi-pricing-overlay .purifi-checkout-status-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 20px;
  padding: 4px 14px;
  margin-bottom: 18px;
}
#purifi-pricing-overlay .purifi-checkout-status-title {
  font-size: 22px;
  font-weight: 700;
  color: #ffffff;
  margin: 0 0 12px 0;
}
#purifi-pricing-overlay .purifi-checkout-status-desc {
  font-size: 14px;
  line-height: 1.5;
  color: #94a3b8;
  margin: 0 0 28px 0;
}
#purifi-pricing-overlay .purifi-checkout-status-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 380px;
  margin: 0 auto;
}
#purifi-pricing-overlay .purifi-checkout-btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
}
#purifi-pricing-overlay .purifi-checkout-btn-primary {
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}
#purifi-pricing-overlay .purifi-checkout-btn-primary:hover:not(:disabled) {
  opacity: 0.95;
  transform: translateY(-1px);
}
#purifi-pricing-overlay .purifi-checkout-btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #f1f5f9;
}
#purifi-pricing-overlay .purifi-checkout-btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
}
#purifi-pricing-overlay .purifi-checkout-btn-ghost {
  background: transparent;
  color: #94a3b8;
  font-size: 13px;
  padding: 8px;
}
#purifi-pricing-overlay .purifi-checkout-btn-ghost:hover {
  color: #ffffff;
}
#purifi-pricing-overlay .purifi-checkout-status-feedback {
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 6px;
  margin-top: 14px;
  text-align: center;
}
#purifi-pricing-overlay .purifi-checkout-status-feedback.success {
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.4);
  color: #4ade80;
}
#purifi-pricing-overlay .purifi-checkout-status-feedback.pending {
  background: rgba(234, 179, 8, 0.12);
  border: 1px solid rgba(234, 179, 8, 0.3);
  color: #fde047;
}
