/* ============================================================================
   insight.css - Insight Engine "noticed" surfaces (S10-IE-FE-1)
   ============================================================================
   Two render targets, one shared card anatomy:
     1. .insight-band       per-page precision band (docked to a product page)
     2. .insight-boardroom  /today recall panel (everything noticed, one place)

   Authority: templates/mockups/sovereign_insight_band_mockup.html (canon,
   S14-REDESIGN-W2). Class names are carried verbatim from the mockup; the two
   root containers are namespaced (.insight-band / .insight-boardroom) and the
   generic internals (.live, .seg, .stream, .band-*, .br-*) are scoped under a
   root to avoid collision with the shipped .live rule in governance.css.

   Cascade: wrapped in @layer components to match sovereign.css / ui-kit.css.
   Tokens: reuses shipped tokens (--surface-*, --cream, --ink-ghost, --ink-muted,
   --ink-label, --terracotta*, --success/--warning/--danger/--info, --border,
   --divider, --radius-*, --ease-*). Adds four token families the mockup
   introduced (--telemetry, --border-strong, the semantic -muted tints, and the
   AA-lifted --signal-*-text tints), with [data-theme="light"] overrides so text
   clears AA over the pale light-mode fills.

   Charter invariants held: terracotta is action-only (act-on / promote / active
   filter / focus / quiet-link hover); signal type carries state via semantic
   spine + tag; unseen state rides the neutral cream/ghost family; Instrument
   Serif appears only on the observation sentence.

   NOTE (data contract, DECISION-FOR-CRITIC): the Wave A engine emits no
   structured evidence records on insight_events. The evidence trail therefore
   renders confidence-only (a single conf chip) when confidence is non-null, and
   is omitted entirely otherwise. No "Noticed in" record chips are fabricated.
   ============================================================================ */

@layer components {

  /* New component tokens (dark defaults). Semantic hues are theme-invariant in
     this design, so the -muted tints derive from fixed hues and hold in both
     themes; the text tints and neutral telemetry/border get a light override. */
  :root {
    --telemetry: #C6BEB2;                     /* lifted ghost, mono telemetry on surface-2/3 */
    --border-strong: rgba(255,255,255,0.12);

    --success-muted: rgba(122,143,114,0.14);
    --warning-muted: rgba(212,169,75,0.14);
    --danger-muted:  rgba(199,93,74,0.14);
    --info-muted:    rgba(107,141,174,0.14);

    --signal-observation-text: #839FBB;       /* info,    ~5.18:1 on info-muted (dark) */
    --signal-opportunity-text: #92A38B;       /* success, ~5.3:1  on success-muted (dark) */
    --signal-attention-text:   #D4A94B;       /* warning, ~6.0:1 (dark) */
    --signal-risk-text:        #D48475;       /* danger,  ~5.14:1 on danger-muted (dark) */

    /* Seen-state narrative recede ink (CEO ruling (a), 2026-07-28). Dims the
       observation on a seen card while still clearing WCAG AA: ~5.59:1 on
       surface-1 (dark). Signal tags and labels keep their own full AA tokens. */
    --insight-seen-ink: #9A928A;
  }

  [data-theme="light"] {
    --telemetry: #4A443D;                     /* dark telemetry ink for pale surfaces */
    --border-strong: rgba(0,0,0,0.14);

    /* deepened so 12px text clears AA over the pale muted fills on white */
    --signal-observation-text: #3A5C7E;
    --signal-opportunity-text: #4C5D44;
    --signal-attention-text:   #866619;
    --signal-risk-text:        #A63D2A;

    /* Seen-state recede ink, light context (CEO ruling (a), 2026-07-28):
       ~5.11:1 on surface-1 (white), a clear recede that still clears AA. */
    --insight-seen-ink: #736D66;
  }

  /* ==========================================================================
     SHARED INSIGHT CARD ANATOMY (both targets)
     ========================================================================== */

  .insight {
    position: relative;
    display: grid;
    grid-template-columns: 3px 1fr;
    gap: 0;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
  }
  /* Explicit hide rule: an author `display: grid` above outranks the UA
     [hidden] default, so signal-filter hiding needs this to take effect. */
  .insight[hidden] { display: none; }
  /* the spine encodes signal type (state = meaning) */
  .insight-spine { width: 3px; }
  .insight.observation .insight-spine { background: var(--info); }
  .insight.opportunity .insight-spine { background: var(--success); }
  .insight.attention   .insight-spine { background: var(--warning); }
  .insight.risk        .insight-spine { background: var(--danger); }

  .insight-body { padding: 14px 16px 13px; display: flex; flex-direction: column; gap: 10px; }

  /* Chrome row: signal type + category + freshness. All mono. */
  .insight-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

  .signal-tag {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
  }
  .insight.observation .signal-tag { color: var(--signal-observation-text); background: var(--info-muted);    border-color: rgba(107,141,174,0.30); }
  .insight.opportunity .signal-tag { color: var(--signal-opportunity-text); background: var(--success-muted); border-color: rgba(122,143,114,0.30); }
  .insight.attention   .signal-tag { color: var(--signal-attention-text);   background: var(--warning-muted); border-color: rgba(212,169,75,0.30); }
  .insight.risk        .signal-tag { color: var(--signal-risk-text);        background: var(--danger-muted);  border-color: rgba(199,93,74,0.32); }

  .insight-category {
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-label);
  }

  .insight-fresh {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-family: var(--mono);
    font-size: 12px;
    color: var(--ink-label);
  }
  /* freshness dot: unseen pings on the neutral cream/ghost family, never
     terracotta (charter: terracotta is action-only). Seen recedes to muted. */
  .fresh-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-muted); position: relative; flex-shrink: 0; }
  .insight.is-new .fresh-dot { background: var(--cream); }
  .insight.is-new .fresh-dot::after {
    content: '';
    position: absolute; inset: -4px;
    border-radius: 50%;
    border: 1px solid var(--ink-ghost);
    opacity: 0.5;
    animation: insight-ping 1.8s cubic-bezier(0,0,0.2,1) infinite;
  }
  @keyframes insight-ping {
    0%   { transform: scale(0.5); opacity: 0.7; }
    80%, 100% { transform: scale(1.9); opacity: 0; }
  }

  /* THE VESSEL: the observation sentence. Instrument Serif, the one voice. */
  .observation {
    font-family: var(--font-display);
    font-size: 20px;
    line-height: 1.34;
    color: var(--cream);
    letter-spacing: 0.005em;
  }

  /* Evidence trail: confidence-only in Wave A (see file header note). */
  .evidence {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 2px;
  }
  .ev-chip {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--telemetry);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px 8px;
    white-space: nowrap;
  }
  .ev-chip.conf { color: var(--ink-label); }

  /* Reaction row: ONE terracotta action, the rest quiet feedback primitives */
  .reactions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 2px; }

  .act-on {
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--cream);
    background: var(--terracotta-button);
    border: 1px solid var(--terracotta-button);
    border-radius: var(--radius-sm);
    padding: 6px 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    transition: background var(--ease-fast), border-color var(--ease-fast);
  }
  .act-on:hover { background: var(--terracotta-deep); border-color: var(--terracotta-deep); }
  .act-on svg { width: 14px; height: 14px; }
  .act-on[disabled] { opacity: 0.65; cursor: default; }
  /* promoted pin: filled terracotta reads as the active/on state (reversible) */
  .act-on.is-on { background: var(--terracotta-deep); border-color: var(--terracotta-deep); }

  .react {
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-ghost);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 11px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: color var(--ease-fast), border-color var(--ease-fast), background var(--ease-fast);
  }
  .react:hover { color: var(--cream); border-color: var(--border-strong); background: var(--surface-2); }
  .react svg { width: 14px; height: 14px; stroke: currentColor; }
  .react[aria-pressed="true"] { color: var(--cream); border-color: var(--border-strong); background: var(--surface-2); }
  .react-group { display: inline-flex; align-items: center; gap: 4px; margin-left: auto; }
  .react.icon-only { padding: 6px 9px; }

  /* boardroom source back-reference */
  .insight-source {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--ink-label);
    text-decoration: none;
  }
  .insight-source:hover, .insight-source:focus-visible { color: var(--terracotta); }

  /* Seen-state recede, chrome-preserving (CEO ruling (a), 2026-07-28). Replaces
     the former group opacity, which dimmed the whole card (tags and labels
     included) below AA. Now only the observation narrative and the card border
     recede; the signal tag, category label, telemetry, and freshness keep their
     own full AA tokens. The dimmed narrative still clears WCAG AA on surface-1
     in both themes (dark ~5.59:1, light ~5.11:1 via --insight-seen-ink). */
  .insight.seen { border-color: var(--divider); }
  .insight.seen .observation { color: var(--insight-seen-ink); }

  /* ==========================================================================
     TARGET 1 chrome: PER-PAGE BAND (.insight-band)
     ========================================================================== */
  .insight-band {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-top: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-top: 24px;
  }
  .insight-band[hidden] { display: none; }

  .insight-band .band-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--divider);
    flex-wrap: wrap;
  }
  .insight-band .band-title {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--cream);
  }
  .insight-band .band-context { font-family: var(--mono); font-size: 12px; color: var(--ink-label); letter-spacing: 0.02em; }
  /* new-count pill: neutral, not terracotta (state never rides the action accent) */
  .insight-band .band-count {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 500;
    color: var(--cream);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    padding: 2px 9px;
  }
  .insight-band .band-count[hidden] { display: none; }
  .insight-band .band-spacer { flex: 1 1 20px; }
  .insight-band .band-link {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--ink-label);
    text-decoration: none;
    letter-spacing: 0.02em;
    transition: color var(--ease-fast);
  }
  .insight-band .band-link:hover, .insight-band .band-link:focus-visible { color: var(--terracotta); }

  .insight-band .band-body { padding: 14px 18px 16px; display: flex; flex-direction: column; gap: 12px; }

  /* ==========================================================================
     TARGET 2 chrome: BOARDROOM PANEL (.insight-boardroom)
     ========================================================================== */
  .insight-boardroom {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin: 24px 0 8px;
  }
  .insight-boardroom[hidden] { display: none; }

  .insight-boardroom .br-head { padding: 16px 20px 14px; border-bottom: 1px solid var(--border); }
  .insight-boardroom .br-top { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
  .insight-boardroom .br-titles { display: flex; flex-direction: column; gap: 3px; }
  .insight-boardroom .br-title {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--cream);
  }
  .insight-boardroom .br-sub { font-family: var(--font-body); font-size: 13px; color: var(--ink-ghost); }

  /* watching pill: neutral state cue, no fabricated sweep timestamp (Wave A
     band API returns no sweep state). Non-pinging idle dot. */
  .insight-boardroom .live {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.1em;
    color: var(--ink-ghost);
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
  }
  .insight-boardroom .live .pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-muted); }

  /* filter segments: filtering by signal type. Active is an ACTION -> terracotta. */
  .insight-boardroom .br-filters { display: flex; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
  .insight-boardroom .flabel {
    font-family: var(--font-body);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-label);
    margin-right: 2px;
  }
  .insight-boardroom .seg {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--ink-label);
    padding: 5px 11px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    min-height: 30px;
    transition: color var(--ease-fast), border-color var(--ease-fast), background var(--ease-fast);
  }
  .insight-boardroom .seg:hover { color: var(--cream); border-color: var(--border-strong); }
  .insight-boardroom .seg.on { color: var(--terracotta); border-color: var(--terracotta); background: var(--terracotta-muted); }
  .insight-boardroom .seg .n { color: var(--ink-muted); }
  .insight-boardroom .seg.on .n { color: var(--terracotta-light); }
  .insight-boardroom .seg[hidden] { display: none; }

  /* the stream: temporally grouped, scrollable, overflow folds into a drawer */
  .insight-boardroom .stream { max-height: 560px; overflow-y: auto; padding: 6px 20px 18px; }
  .insight-boardroom .time-group { margin-top: 14px; }
  .insight-boardroom .time-label {
    position: sticky;
    top: 0;
    z-index: 2;
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-label);
    background: var(--surface-1);
    padding: 8px 2px 8px;
    border-bottom: 1px solid var(--divider);
  }
  .insight-boardroom .time-label .cnt { color: var(--ink-muted); }
  .insight-boardroom .time-group .insight { margin-top: 12px; }

  /* in-panel overflow drawer (NOT a history page): older insights fold behind a
     toggle inside the panel. */
  .insight-boardroom .stream-drawer { margin-top: 12px; }
  .insight-boardroom .stream-drawer[hidden] { display: none; }
  .insight-boardroom .drawer-toggle {
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.06em;
    color: var(--ink-label);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    margin-top: 14px;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: color var(--ease-fast), border-color var(--ease-fast);
  }
  .insight-boardroom .drawer-toggle:hover { color: var(--cream); border-color: var(--border-strong); }
  .insight-boardroom .drawer-toggle[hidden] { display: none; }

  /* ==========================================================================
     RESPONSIVE (375px target)
     ========================================================================== */
  @media (max-width: 680px) {
    .observation { font-size: 18px; }
    .insight-fresh { margin-left: 0; }
    .insight-meta { gap: 8px; }
    .reactions { gap: 6px; }
    .react-group { margin-left: 0; width: 100%; justify-content: flex-start; }
    .act-on { flex: 1 1 auto; justify-content: center; }
    .insight-band .band-head { gap: 8px; }
    .insight-band .band-spacer { flex-basis: 100%; height: 0; }
    .insight-band .band-link { order: 5; }
    .insight-boardroom .stream { max-height: none; }
    .insight-boardroom .time-label { position: static; }
  }
  @media (max-width: 420px) {
    .observation { font-size: 17px; }
    .react .rlabel { display: none; }   /* thumbs collapse to icon-only at phone width */
    .react.thumb { padding: 6px 9px; }
  }

  /* Reduced-motion: still the ping (philosophy 3.1) */
  @media (prefers-reduced-motion: reduce) {
    .insight.is-new .fresh-dot::after { animation: none; }
  }
}
