/*
 * Stella Ambient — drawer + bottom-sheet styling (A3 Phase 1).
 * Spec: docs/POST_RELEASE/roadmap/codex/codex_round16_audit_packet_A3_stella_ambient.md
 *
 * Desktop: right-side drawer (~420px wide), backdrop dim but app behind
 *          remains visible. Z-index above page chrome but below modals.
 * Mobile:  full-height bottom sheet, ≥85vh.
 */

.sa-overlay {
  position: fixed;
  inset: 0;
  /* Codex round-16 P1-3: raised above trade-detail drawer (z-index 10000)
     so users can review the selected trade with Stella open on top. The
     trade-detail drawer is still interactive behind the ambient backdrop
     dim if the user clicks through (backdrop click closes ambient). */
  z-index: 10020;
  pointer-events: none;
  font-family: inherit;
}
.sa-overlay .sa-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 4, 8, 0.42);
  pointer-events: auto;
  opacity: 0;
  animation: sa-fade-in 0.22s ease forwards;
}
.sa-overlay.sa-closing .sa-backdrop {
  animation: sa-fade-out 0.22s ease forwards;
}
@keyframes sa-fade-in  { to { opacity: 1; } }
@keyframes sa-fade-out { to { opacity: 0; } }

.sa-overlay .sa-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 100vw;
  pointer-events: auto;
  background: linear-gradient(180deg,
    rgba(20, 23, 30, 0.98) 0%,
    rgba(13, 15, 20, 0.98) 100%);
  border-left: 1px solid rgba(94, 173, 184, 0.22);
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  min-height: 0;
  color: var(--text-primary, #e2e8f0);
  transform: translateX(100%);
  animation: sa-slide-in 0.30s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.sa-overlay.sa-closing .sa-panel {
  animation: sa-slide-out 0.22s ease forwards;
}
@keyframes sa-slide-in  { to { transform: translateX(0); } }
@keyframes sa-slide-out { to { transform: translateX(100%); } }

.sa-panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    var(--brand, #5eadb8) 50%,
    transparent 100%);
  opacity: 0.65;
}

/* ── Header ─────────────────────────────────────────────────────────── */

.sa-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}
.sa-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.sa-title-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sa-eyebrow {
  font-family: 'JetBrains Mono', var(--font-mono, monospace);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brand, #5eadb8);
  opacity: 0.8;
}
.sa-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary, #f1f5f9);
  line-height: 1.2;
}
.sa-close-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  color: var(--text-tertiary, #64748b);
  cursor: pointer;
  padding: 0;
  transition: all 0.18s ease;
  flex-shrink: 0;
}
.sa-close-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary, #e2e8f0);
  border-color: rgba(255, 255, 255, 0.16);
}
.sa-context-row {
  margin-top: 10px;
  font-family: 'JetBrains Mono', var(--font-mono, monospace);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-tertiary, #64748b);
}

/* ── Body ───────────────────────────────────────────────────────────── */

.sa-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sa-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sa-summary-label,
.sa-ask-label {
  font-family: 'JetBrains Mono', var(--font-mono, monospace);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-tertiary, #64748b);
}
.sa-summary-body {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-secondary, #94a3b8);
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 8px;
}

/* Loading + empty states */

.sa-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  color: var(--text-tertiary, #64748b);
  font-size: 13px;
}
.sa-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(94, 173, 184, 0.20);
  border-top-color: var(--brand, #5eadb8);
  animation: sa-spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes sa-spin { to { transform: rotate(360deg); } }

.sa-empty {
  padding: 24px 16px;
  text-align: center;
  border: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-secondary, #94a3b8);
}
.sa-empty-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #e2e8f0);
  margin-bottom: 4px;
}
.sa-empty-body {
  font-size: 12.5px;
  color: var(--text-tertiary, #64748b);
}

/* ── Cards ──────────────────────────────────────────────────────────── */

.sa-cards {
  gap: 10px;
}
.sa-card {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: background 0.18s, border-color 0.18s;
}
.sa-card:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.10);
}
.sa-card-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}
.sa-sev {
  flex-shrink: 0;
  font-family: 'JetBrains Mono', var(--font-mono, monospace);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-tertiary, #64748b);
  align-self: center;
}
.sa-sev-risk    { background: rgba(244, 63, 94, 0.14);  color: #fb7185; }
.sa-sev-watch   { background: rgba(245, 158, 11, 0.14); color: #fbbf24; }
.sa-sev-info    { background: rgba(94, 173, 184, 0.14); color: var(--brand, #5eadb8); }
.sa-sev-success { background: rgba(34, 197, 94, 0.14);  color: #4ade80; }

.sa-card-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary, #f1f5f9);
  line-height: 1.35;
  flex: 1 1 auto;
  min-width: 0;
}
.sa-card-body {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-secondary, #94a3b8);
}
.sa-card-action {
  display: inline-flex;
  align-self: flex-start;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 500;
  color: var(--brand, #5eadb8);
  background: rgba(94, 173, 184, 0.08);
  border: 1px solid rgba(94, 173, 184, 0.22);
  border-radius: 6px;
  text-decoration: none;
  transition: all 0.18s ease;
}
.sa-card-action:hover {
  background: rgba(94, 173, 184, 0.16);
  border-color: rgba(94, 173, 184, 0.40);
}

/* ── Ask Stella surface ─────────────────────────────────────────────── */

.sa-ask {
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  padding-top: 12px;
}

/* Round-18 canary fix #1: Q/A conversation history. Appends below cards,
   above the input, scrolls with the drawer body. */
.sa-conversation {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}
.sa-conversation:empty {
  display: none;
}
.sa-qa {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 10px;
}
.sa-qa-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.sa-qa-row + .sa-qa-row {
  margin-top: 4px;
}
.sa-qa-tag {
  font-family: 'JetBrains Mono', var(--font-mono, monospace);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--text-tertiary, #64748b);
}
.sa-qa-stella .sa-qa-tag {
  color: var(--brand, #5eadb8);
}
.sa-qa-body {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary, #e2e8f0);
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Round 22B: per-answer action strip rendered below each Stella body.
   Buttons are click-to-act (navigate / click whitelisted selector /
   copy validated text / reveal_inline). Same subtle bordered tint as
   the nav-rail Ask Stella pill. */
.sa-qa-actions-slot {
  margin-top: 8px;
}
.sa-qa-actions-slot:empty {
  display: none;
}
.sa-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.sa-action-btn {
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  background: rgba(94, 173, 184, 0.06);
  border: 1px solid rgba(94, 173, 184, 0.20);
  color: var(--text-primary, #e2e8f0);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.sa-action-btn:hover {
  background: rgba(94, 173, 184, 0.14);
  border-color: rgba(94, 173, 184, 0.40);
}
.sa-action-btn:active {
  transform: translateY(1px);
}
.sa-action-btn:disabled {
  cursor: progress;
  opacity: 0.8;
}
.sa-action-btn[data-stella-action-state="success"] {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.36);
  color: #b7f7d8;
}
.sa-action-btn[data-stella-action-state="error"] {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.36);
  color: #fecaca;
}
.sa-action-btn[data-stella-action-state="pending"] {
  background: rgba(94, 173, 184, 0.14);
  border-color: rgba(94, 173, 184, 0.36);
}

/* Round-18 canary fix #2: route-aware suggestion chips. */
.sa-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.sa-suggestion {
  font-family: inherit;
  font-size: 11.5px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(94, 173, 184, 0.06);
  border: 1px solid rgba(94, 173, 184, 0.18);
  color: var(--text-primary, #e2e8f0);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.sa-suggestion:hover {
  background: rgba(94, 173, 184, 0.12);
  border-color: rgba(94, 173, 184, 0.32);
}

.sa-ask-form {
  display: flex;
  gap: 8px;
}
.sa-ask-input {
  flex: 1 1 auto;
  min-width: 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary, #e2e8f0);
  font-family: inherit;
  font-size: 13px;
  padding: 9px 12px;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.18s, background 0.18s;
}
.sa-ask-input:focus {
  border-color: rgba(94, 173, 184, 0.45);
  background: rgba(94, 173, 184, 0.06);
}
.sa-ask-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.sa-ask-submit {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg,
    var(--brand, #5eadb8) 0%,
    color-mix(in srgb, var(--brand, #5eadb8) 80%, #000) 100%);
  color: var(--brand-text, #001216);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
  transition: filter 0.18s, transform 0.12s;
}
.sa-ask-submit:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}
.sa-ask-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.sa-ask-hint {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-tertiary, #64748b);
  min-height: 1.2em;
}

/* Stabilization patch (browser QA round): explicit disabled-Ask panel.
   When LLM is disabled or tier doesn't allow Ask, we render this
   panel instead of a fake input field. No text cursor, no placeholder,
   no send icon — reads as intentional disabled state. */
.sa-ask-disabled-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
}
.sa-ask-disabled-body {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-secondary, #94a3b8);
}
.sa-ask-disabled-pill {
  align-self: flex-start;
  font-family: 'JetBrains Mono', var(--font-mono, monospace);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-tertiary, #64748b);
  cursor: not-allowed;
  opacity: 0.85;
}

/* ── Footer ─────────────────────────────────────────────────────────── */

.sa-footer {
  flex-shrink: 0;
  padding: 12px 20px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.sa-footer-link {
  font-size: 12.5px;
  color: var(--brand, #5eadb8);
  text-decoration: none;
  font-weight: 500;
}
.sa-footer-link:hover { text-decoration: underline; }

/* ── Mobile bottom sheet ───────────────────────────────────────────── */

@media (max-width: 768px) {
  .sa-overlay .sa-panel {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: min(92dvh, calc(100dvh - env(safe-area-inset-top, 0px) - 12px));
    max-height: min(92dvh, calc(100dvh - env(safe-area-inset-top, 0px) - 12px));
    border-left: none;
    border-top: 1px solid rgba(94, 173, 184, 0.22);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -24px 60px rgba(0, 0, 0, 0.55);
    transform: translateY(100%);
    animation: sa-slide-up 0.30s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .sa-overlay.sa-closing .sa-panel {
    animation: sa-slide-down 0.22s ease forwards;
  }
  @keyframes sa-slide-up   { to { transform: translateY(0); } }
  @keyframes sa-slide-down { to { transform: translateY(100%); } }

  .sa-header {
    position: relative;
    padding: 22px 16px 12px;
  }
  /* Pull handle visual cue */
  .sa-header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.10);
  }
  .sa-body {
    padding: 14px 16px;
  }
  .sa-footer {
    padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .sa-title {
    font-size: 16px;
  }
  .sa-card,
  .sa-qa,
  .sa-ask-disabled-panel {
    border-radius: 8px;
  }
}

@media (max-width: 480px) {
  .sa-overlay .sa-panel {
    height: min(94dvh, calc(100dvh - env(safe-area-inset-top, 0px) - 8px));
    max-height: min(94dvh, calc(100dvh - env(safe-area-inset-top, 0px) - 8px));
  }
  .sa-actions,
  .sa-suggestions {
    display: grid;
    grid-template-columns: 1fr;
  }
  .sa-action-btn,
  .sa-suggestion {
    width: 100%;
    min-height: 34px;
    text-align: left;
  }
  .sa-ask-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
  }
  .sa-ask-input,
  .sa-ask-submit {
    min-height: 44px;
  }
  .sa-ask-submit {
    width: 44px;
    height: 44px;
  }
}
