/* Thought Bubbles + Thread Headers + History Items.
 *
 * Extracted from styles.css 2026-05-20 (Phase 7 bucket 3 follow-up)
 * to bring styles.css under the 700-LoC hard cap. Cascade order is
 * preserved: this file loads immediately after styles.css in
 * index.html so design tokens + panel chrome resolve first.
 *
 * Shared design tokens (--surface, --border, --purple, --c-tech,
 * etc.) come from styles.css.
 */

    /* ── Thought Bubbles ── */
    .bubble {
      margin-bottom: 8px; border-radius: var(--radius-md);
      border: 1px solid var(--border-card); background: var(--surface-lo);
      overflow: hidden; box-shadow: var(--shadow-sm);
      transition: border-color var(--duration-fast), box-shadow var(--duration-normal), opacity 0.35s, transform 0.35s;
      animation: popIn 0.35s var(--ease-out);
    }
    @keyframes popIn {
      from { opacity: 0; transform: scale(0.96) translateY(-4px); }
      to   { opacity: 1; transform: scale(1) translateY(0); }
    }
    .bubble.dismissing { opacity: 0; transform: scale(0.96) translateY(-6px); pointer-events: none; }
    .bubble:hover { border-color: var(--purple-dim); box-shadow: var(--shadow-md); }
    .bubble.open  { border-color: var(--purple-dim); background: var(--surface-hi); box-shadow: var(--shadow-md); }

    .bubble-head {
      display: flex; align-items: center; gap: 8px;
      padding: 10px 12px; cursor: pointer; user-select: none;
    }
    .bubble-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
    .bubble-term { font-weight: 600; font-size: var(--fs-md); color: var(--text); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .bubble-badge {
      font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase;
      letter-spacing: 0.5px; padding: 2px 8px; border-radius: 10px; flex-shrink: 0;
    }
    .bubble-latency {
      font-size: 10px; color: var(--text-3); opacity: 0.6; flex-shrink: 0;
      font-variant-numeric: tabular-nums;
    }
    .bubble-chevron { font-size: var(--fs-xs); color: var(--text-3); flex-shrink: 0; transition: transform 0.2s; }
    .bubble.open .bubble-chevron { transform: rotate(180deg); }

    /* Draining timer bar */
    .bubble-timer { height: 3px; overflow: hidden; background: var(--border-sub); }
    .bubble-timer-bar {
      height: 100%; width: 100%; background: linear-gradient(90deg, var(--purple-dim), var(--purple));
      transform-origin: left; animation: drain 15s linear forwards;
    }
    @keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

    /* Expanded body */
    .bubble-body { display: none; padding: 0 12px 12px; border-top: 1px solid var(--border-sub); }
    .bubble.open .bubble-body { display: block; }
    .bubble-context { font-size: var(--fs-sm); color: var(--text-2); line-height: var(--lh-normal); padding-top: 8px; margin-bottom: 8px; }

    .bubble-actions { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; margin-top: 8px; }
    .dismiss-btn {
      width: 28px; height: 28px; border-radius: 50%;
      font-size: 17px; font-weight: 700; line-height: 1;
      display: flex; align-items: center; justify-content: center;
      border: 1px solid var(--border); background: var(--surface-hi);
      cursor: pointer; flex-shrink: 0;
      transition: background var(--duration-fast), border-color var(--duration-fast), transform var(--duration-fast), box-shadow var(--duration-fast);
      color: var(--red);
    }
    .dismiss-btn:hover { background: var(--hover-red); border-color: var(--red); transform: scale(1.1); box-shadow: 0 0 12px rgba(248,113,113,0.25); }
    .dismiss-btn:active { transform: scale(0.95); }

    .lookup-btn {
      display: inline-flex; align-items: center; gap: 5px;
      font-size: var(--fs-sm); font-weight: 500; padding: var(--btn-pad); border-radius: var(--radius-sm);
      border: 1px solid var(--border); background: var(--surface-hi);
      color: var(--purple); cursor: pointer;
      transition: background var(--duration-fast), border-color var(--duration-fast), transform var(--duration-fast);
    }
    .lookup-btn:hover { background: var(--active-bg); border-color: var(--purple-dim); }
    .lookup-btn:disabled { opacity: 0.45; cursor: default; }
    .lookup-btn .spinner {
      width: 10px; height: 10px;
      border: 2px solid #a78bfa55; border-top-color: var(--purple);
      border-radius: 50%; animation: spin 0.6s linear infinite; display: none;
    }
    .lookup-btn.loading .spinner { display: block; }
    .lookup-btn.loading .btn-label { display: none; }
    @keyframes spin { to { transform: rotate(360deg); } }

    .lookup-result {
      display: none; margin-top: 8px;
      font-size: var(--fs-base); line-height: 1.65; color: var(--text-2);
      padding: 10px 12px; background: var(--surface);
      border-radius: var(--radius-sm); border-left: 3px solid var(--purple-dim);
    }
    .lookup-result.visible { display: block; }
    .lookup-result strong { color: var(--text); display: block; margin-bottom: 3px; margin-top: 10px; }
    .lookup-result strong:first-child { margin-top: 0; }
    .retry-link { color: var(--purple); font-weight: 600; text-decoration: underline; cursor: pointer; margin-left: 4px; }
    .fallback-notice { font-size: 11px; color: var(--text-3); font-style: italic; margin-bottom: 6px; }

    /* Category theming */
    .bubble-technologies       .bubble-dot { background: var(--c-tech); }
    .bubble-technologies       .bubble-badge,
    .badge-technologies        { background: #1e3a5c; color: #7cb9ff; }
    .bubble-business_metrics   .bubble-dot { background: var(--c-metric); }
    .bubble-business_metrics   .bubble-badge,
    .badge-business_metrics    { background: #1a3d2e; color: #6ee7b7; }
    .bubble-compliance_risk    .bubble-dot { background: var(--c-compliance); }
    .bubble-compliance_risk    .bubble-badge,
    .badge-compliance_risk     { background: #3d1e1e; color: #fca5a5; }
    .bubble-companies_products .bubble-dot { background: var(--c-company); }
    .bubble-companies_products .bubble-badge,
    .badge-companies_products  { background: #3a2d14; color: #fcd34d; }
    .bubble-strategic_concepts .bubble-dot { background: var(--c-strategy); }
    .bubble-strategic_concepts .bubble-badge,
    .badge-strategic_concepts  { background: #2d1f45; color: #c4b5fd; }
    .bubble-concepts           .bubble-dot { background: var(--c-strategy); }
    .bubble-concepts           .bubble-badge,
    .badge-concepts            { background: #2d1f45; color: #c4b5fd; }
    .bubble-people_references  .bubble-dot { background: var(--c-metric); }
    .bubble-people_references  .bubble-badge,
    .badge-people_references   { background: #1a3d2e; color: #6ee7b7; }
    .bubble-key_numbers        .bubble-dot { background: var(--c-number); }
    .bubble-key_numbers        .bubble-badge,
    .badge-key_numbers         { background: #163040; color: #67e8f9; }

    /* Light mode badge overrides */
    html.light .bubble-technologies       .bubble-badge,
    html.light .badge-technologies        { background: #dbeafe; color: #1d4ed8; }
    html.light .bubble-business_metrics   .bubble-badge,
    html.light .badge-business_metrics    { background: #dcfce7; color: #15803d; }
    html.light .bubble-compliance_risk    .bubble-badge,
    html.light .badge-compliance_risk     { background: #fee2e2; color: #b91c1c; }
    html.light .bubble-companies_products .bubble-badge,
    html.light .badge-companies_products  { background: #fef3c7; color: #92400e; }
    html.light .bubble-strategic_concepts .bubble-badge,
    html.light .badge-strategic_concepts  { background: #ede9fe; color: #6d28d9; }
    html.light .bubble-concepts           .bubble-badge,
    html.light .badge-concepts            { background: #ede9fe; color: #6d28d9; }
    html.light .bubble-people_references  .bubble-badge,
    html.light .badge-people_references   { background: #dcfce7; color: #15803d; }
    html.light .bubble-key_numbers        .bubble-badge,
    html.light .badge-key_numbers         { background: #e0f2fe; color: #0369a1; }

    /* ── Thread Headers ── */
    .thread-header {
      font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase;
      letter-spacing: 0.6px; color: var(--text-3);
      padding: 10px 4px 4px; margin-top: 2px;
      border-top: 1px solid var(--border);
    }
    .thread-header:first-child { border-top: none; padding-top: 2px; }

    /* ── History Items ── */
    .history-item {
      display: flex; align-items: flex-start; gap: 8px;
      padding: 8px 12px; border-radius: var(--radius-sm);
      border: 1px solid var(--border-sub); background: var(--surface-lo);
      margin-bottom: 8px; animation: popIn 0.2s var(--ease-out);
    }
    .history-item.already-kept { opacity: 0.4; }
    .history-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-top: 3px; }
    .history-info { flex: 1; min-width: 0; }
    .history-term { font-size: var(--fs-base); font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .history-context { font-size: var(--fs-xs); color: var(--text-2); line-height: 1.4; margin-top: 2px; }
    .history-badge {
      font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase;
      letter-spacing: 0.5px; padding: 2px 8px; border-radius: var(--radius-sm);
      flex-shrink: 0; margin-top: 1px;
    }
    .history-keep-btn {
      width: 22px; height: 22px; border-radius: 50%;
      font-size: 15px; font-weight: 700; line-height: 1;
      display: flex; align-items: center; justify-content: center;
      border: 1px solid #1a6648; background: var(--surface-hi);
      color: var(--green); cursor: pointer; flex-shrink: 0;
      transition: background 0.15s;
    }
    .history-keep-btn:hover { background: var(--hover-green); }
    .history-keep-btn:disabled { opacity: 0.5; cursor: default; font-size: var(--fs-sm); }

