/*
 * harry_chain.css — "the red thread": Harry's tool-chain tracker.
 *
 * A small window in the LEFT gutter (between the pink interface and the
 * browser edge) that appears while Harry works a tool chain mid-conversation
 * (stay-active follow-up passes, research sessions). Chrome matches his
 * avatar window (assets/harry_face.js): dark body, chunky pink border,
 * System 7 pinstriped title bar, beveled square controls. The expanded view
 * is a red thread with a heart knot at every step, unspooling down the side.
 *
 * Zero layout impact: everything is position:fixed. Animations are
 * transform/opacity/clip-path only (the mic pipeline shares the main thread —
 * see the 2026-07-06 note in harry_face.js).
 * Driven by assets/harry_chain.js; backend contract in chain_tracker.py.
 */

#harryChain {
    --hc-ink: #282426;
    --hc-ink-2: #332c30;
    --hc-ink-3: #3d3439;
    --hc-text: #f5e9ef;
    --hc-dim: #c9b2bf;
    --hc-faint: #9d8792;
    --hc-thread: #ff3f7f;
    --hc-thread-soft: rgba(255, 63, 127, 0.35);
    --hc-ok: #69db7c;
    --hc-warn: #ffd54f;
    --hc-fail: #ff6b6b;

    position: fixed;
    left: 16px;
    top: 96px;
    width: 280px;
    z-index: 1500;               /* under tool toasts (2000), modals, the avatar (9500) */
    display: none;
    flex-direction: column;
    max-height: calc(100vh - 96px - 44px);
    box-sizing: border-box;
    background: var(--hc-ink);
    border: 3px solid var(--primary, #ff69b4);
    outline: 1px solid rgba(20, 14, 16, 0.9);
    box-shadow:
        inset 0 0 0 1px rgba(255, 214, 231, 0.45),
        4px 4px 0 rgba(20, 14, 16, 0.45);
    border-radius: 4px;
    color: var(--hc-text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 12px;
    line-height: 1.35;
    user-select: none;
    transform-origin: 0 0;
}
#harryChain *, #harryChain *::before, #harryChain *::after { box-sizing: border-box; }
#harryChain.hc-visible { display: flex; }
#harryChain.hc-entering { animation: hc-enter 0.42s cubic-bezier(0.34, 1.4, 0.64, 1); }
#harryChain.hc-leaving { animation: hc-leave 0.32s ease-in forwards; pointer-events: none; }
@keyframes hc-enter {
    from { opacity: 0; transform: translateX(-26px) scale(0.96); }
    to   { opacity: 1; transform: none; }
}
@keyframes hc-leave {
    to { opacity: 0; transform: translateX(-26px) scale(0.97); }
}

/* ── Title bar (same pinstripes as the avatar window) ───────────────── */
#harryChain .hc-titlebar {
    flex: none;
    display: flex; align-items: center; gap: 7px;
    padding: 4px 7px;
    background: repeating-linear-gradient(
        to bottom,
        rgba(255, 182, 217, 0.55) 0px, rgba(255, 182, 217, 0.55) 1px,
        rgba(58, 44, 52, 0.2) 1px, rgba(58, 44, 52, 0.2) 3px);
    border-bottom: 1px solid var(--primary, #ff69b4);
    cursor: pointer;
}
#harryChain .hc-name {
    flex: 1; min-width: 0; text-align: center;
    font-family: ui-monospace, 'Cascadia Code', Menlo, monospace;
    font-size: 10px; font-weight: 700; letter-spacing: 0.24em;
    color: #fff; text-shadow: 0 1px 0 rgba(60, 20, 40, 0.8);
    background: rgba(40, 36, 38, 0.85);
    padding: 0 8px; border-radius: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#harryChain .hc-btn {
    width: 13px; height: 13px; flex: none; padding: 0;
    cursor: pointer;
    background: #efe0e8;
    border: 1px solid #241c20;
    box-shadow: inset 1px 1px 0 #fff, inset -1px -1px 0 #b391a2;
    position: relative;
}
#harryChain .hc-btn:hover { background: var(--primary-light, #ffb6d9); }
#harryChain .hc-btn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
#harryChain .hc-btn.hc-toggle::after {
    content: ''; position: absolute; left: 3px; top: 2px;
    border-left: 3px solid transparent; border-right: 3px solid transparent;
    border-top: 5px solid #241c20;
    transition: transform 0.25s ease;
}
#harryChain.hc-expanded .hc-btn.hc-toggle::after { transform: rotate(180deg); }

/* Status lamp: pink pulse while working; green told you; amber holding it;
   grey unfinished/stopped/quiet; red stumbled. */
#harryChain .hc-lamp {
    width: 9px; height: 9px; border-radius: 50%; flex: none; position: relative;
    background: #4a4046; border: 1px solid #241c20;
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.2);
}
#harryChain .hc-lamp::after {
    content: ''; position: absolute; inset: -4px; border-radius: 50%;
    opacity: 0;
}
#harryChain .hc-lamp.l-running { background: #ff5fa2; }
#harryChain .hc-lamp.l-running::after {
    background: radial-gradient(circle, rgba(255, 95, 162, 0.85) 0%, transparent 70%);
    animation: hc-glow 1.6s ease-in-out infinite;
}
#harryChain .hc-lamp.l-spoke { background: var(--hc-ok); box-shadow: 0 0 6px 1px rgba(105, 219, 124, 0.7); }
#harryChain .hc-lamp.l-done { background: var(--hc-ok); box-shadow: 0 0 6px 1px rgba(105, 219, 124, 0.5); }
#harryChain .hc-lamp.l-noted { background: var(--hc-warn); box-shadow: 0 0 6px 1px rgba(255, 213, 79, 0.6); }
#harryChain .hc-lamp.l-error { background: var(--hc-fail); box-shadow: 0 0 6px 1px rgba(255, 107, 107, 0.6); }
@keyframes hc-glow { 0%, 100% { opacity: 0.15; } 50% { opacity: 1; } }

/* ── Body ───────────────────────────────────────────────────────────── */
#harryChain .hc-body { flex: none; padding: 8px 10px 10px; }
#harryChain .hc-head {
    display: flex; align-items: baseline; gap: 6px; margin-bottom: 7px;
}
#harryChain .hc-kind {
    flex: none;
    font-family: ui-monospace, 'Cascadia Code', Menlo, monospace;
    font-size: 9px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
    color: var(--hc-ink); background: var(--primary-light, #ffb6d9);
    padding: 1px 5px; border-radius: 2px;
}
#harryChain .hc-title {
    flex: 1; min-width: 0;
    font-family: Georgia, serif; font-style: italic; font-size: 12px;
    color: var(--primary-light, #ffb6d9);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* The step happening right now */
#harryChain .hc-now {
    background: var(--hc-ink-2);
    border: 1px solid rgba(255, 182, 217, 0.22);
    border-left: 3px solid var(--hc-thread);
    border-radius: 3px;
    padding: 7px 8px 7px 9px;
}
#harryChain .hc-now.s-ok   { border-left-color: var(--hc-ok); }
#harryChain .hc-now.s-fail { border-left-color: var(--hc-fail); }
#harryChain .hc-now.s-info { border-left-color: var(--primary-light, #ffb6d9); }
#harryChain .hc-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
#harryChain .hc-ico {
    flex: none; width: 20px; height: 20px; font-size: 12px; line-height: 18px;
    text-align: center;
    background: #efe0e8; border: 1px solid #241c20;
    box-shadow: inset 1px 1px 0 #fff, inset -1px -1px 0 #b391a2;
    border-radius: 2px;
}
#harryChain .hc-label {
    flex: 1; min-width: 0; font-weight: 700; font-size: 12.5px; color: #fff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#harryChain .hc-who {
    flex: none; font-size: 9.5px; font-weight: 700; letter-spacing: 0.04em;
    color: var(--primary-light, #ffb6d9);
    border: 1px solid rgba(255, 182, 217, 0.45); border-radius: 8px;
    padding: 0 6px; white-space: nowrap;
}
#harryChain .hc-input {
    margin-top: 6px;
    font-family: ui-monospace, 'Cascadia Code', Menlo, monospace; font-size: 10.5px;
    color: #ffd9ea; background: rgba(0, 0, 0, 0.22);
    border-radius: 2px; padding: 4px 6px;
    overflow-wrap: anywhere;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
#harryChain .hc-input::before { content: '\201C'; color: var(--hc-thread); font-weight: 700; }
#harryChain .hc-input::after  { content: '\201D'; color: var(--hc-thread); font-weight: 700; }
#harryChain .hc-preview {
    margin-top: 5px; font-size: 10.5px; font-style: italic; color: var(--hc-dim);
    overflow-wrap: anywhere;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
#harryChain .hc-meta {
    margin-top: 6px; display: flex; align-items: center; gap: 6px;
    font-family: ui-monospace, 'Cascadia Code', Menlo, monospace; font-size: 10.5px;
    color: var(--hc-dim);
}
#harryChain .hc-meta .hc-grow { flex: 1; }
#harryChain .hc-par {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 9.5px; color: var(--hc-faint);
}

/* The heart: beats while a step runs */
#harryChain .hc-heart {
    display: inline-block; color: var(--hc-thread); font-size: 12px; line-height: 1;
    transform-origin: 50% 60%;
}
#harryChain .hc-heart.beating { animation: hc-beat 1.1s ease-in-out infinite; }
@keyframes hc-beat {
    0%, 40%, 100% { transform: scale(1); }
    15% { transform: scale(1.32); }
    28% { transform: scale(0.94); }
    34% { transform: scale(1.18); }
}
#harryChain .hc-okmark { color: var(--hc-ok); font-weight: 700; }
#harryChain .hc-failmark { color: var(--hc-fail); font-weight: 700; }

/* How it ended */
#harryChain .hc-outcome {
    margin-top: 8px; display: flex; gap: 7px; align-items: flex-start;
    padding: 6px 8px; border-radius: 3px;
    background: rgba(255, 182, 217, 0.1);
    border: 1px dashed rgba(255, 182, 217, 0.45);
    font-size: 11.5px; color: var(--hc-text);
}
#harryChain .hc-outcome b { color: #fff; }
#harryChain .hc-outcome .hc-otext { display: block; color: var(--hc-dim); font-size: 10.5px; margin-top: 1px; overflow-wrap: anywhere; }
#harryChain .hc-outcome.o-spoke { border-color: rgba(105, 219, 124, 0.6); background: rgba(105, 219, 124, 0.08); }
#harryChain .hc-outcome.o-noted { border-color: rgba(255, 213, 79, 0.6); background: rgba(255, 213, 79, 0.07); }
#harryChain .hc-outcome.o-error { border-color: rgba(255, 107, 107, 0.6); background: rgba(255, 107, 107, 0.08); }

#harryChain .hc-counts {
    margin-top: 8px; font-size: 10px; color: var(--hc-faint);
    font-family: ui-monospace, 'Cascadia Code', Menlo, monospace;
    display: flex; gap: 8px; justify-content: space-between;
}
#harryChain .hc-others {
    margin-top: 6px; font-size: 10px; color: var(--hc-faint); font-style: italic;
}

/* ── The trail: a red thread with heart knots ───────────────────────── */
#harryChain .hc-trail {
    display: none;
    flex: 1 1 auto; min-height: 0;
    overflow-y: auto; overscroll-behavior: contain;
    border-top: 1px solid rgba(255, 182, 217, 0.25);
    padding: 6px 10px 12px 8px;
    scrollbar-width: thin; scrollbar-color: var(--primary, #ff69b4) transparent;
}
#harryChain.hc-expanded .hc-trail { display: block; }
#harryChain .hc-trail.hc-unfurl { animation: hc-unfurl 0.55s cubic-bezier(0.22, 0.8, 0.3, 1); }
#harryChain .hc-trail.hc-rollup { animation: hc-rollup 0.24s ease-in forwards; }
@keyframes hc-unfurl { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes hc-rollup { from { clip-path: inset(0 0 0 0); } to { clip-path: inset(0 0 100% 0); } }

#harryChain .hc-group + .hc-group { margin-top: 10px; }
#harryChain .hc-ghead.hc-solo { display: none; }
#harryChain .hc-ghead {
    display: flex; gap: 6px; align-items: baseline;
    margin: 4px 0 4px 2px; font-size: 10.5px; color: var(--hc-dim);
}
#harryChain .hc-ghead .hc-gtitle {
    flex: 1; min-width: 0; font-family: Georgia, serif; font-style: italic;
    color: var(--primary-light, #ffb6d9);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#harryChain .hc-ghead .hc-gtime { flex: none; font-family: ui-monospace, Menlo, monospace; font-size: 10px; }

#harryChain ol.hc-steps {
    list-style: none; margin: 4px 0 0; padding: 0 0 0 22px; position: relative;
}
/* the thread itself — stitched, like embroidery floss */
#harryChain ol.hc-steps::before {
    content: ''; position: absolute; left: 8px; top: 6px; bottom: 8px; width: 2px;
    background: repeating-linear-gradient(to bottom,
        var(--hc-thread) 0px, var(--hc-thread) 7px, transparent 7px, transparent 10px);
    border-radius: 1px;
    transform-origin: 50% 0;
}
#harryChain .hc-trail.hc-unfurl ol.hc-steps::before { animation: hc-draw 0.7s cubic-bezier(0.22, 0.8, 0.3, 1); }
@keyframes hc-draw { from { transform: scaleY(0); } to { transform: scaleY(1); } }

#harryChain li.hc-step {
    position: relative; padding: 4px 4px 5px 6px; margin: 0 0 3px;
    border-radius: 3px; cursor: pointer;
}
#harryChain li.hc-step:hover { background: rgba(255, 255, 255, 0.045); }
#harryChain li.hc-step.is-new { animation: hc-stepin 0.4s ease-out; }
@keyframes hc-stepin { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
/* heart knots on the thread */
#harryChain li.hc-step > .hc-knot {
    position: absolute; left: -20px; top: 3px; width: 18px; height: 18px;
    text-align: center; font-size: 13px; line-height: 18px; color: var(--hc-thread);
    background: var(--hc-ink); border-radius: 50%;     /* a bead the thread runs through */
    transform-origin: 50% 55%;
}
#harryChain li.hc-step.s-running > .hc-knot { animation: hc-beat 1.1s ease-in-out infinite; }
#harryChain li.hc-step.s-info > .hc-knot { color: var(--primary-light, #ffb6d9); font-size: 11px; }
#harryChain li.hc-step.s-fail > .hc-knot { color: var(--hc-fail); }
#harryChain li.hc-step.s-ok > .hc-knot { color: var(--hc-thread); }
#harryChain .hc-sline { display: flex; align-items: center; gap: 5px; min-width: 0; }
#harryChain .hc-sico { flex: none; font-size: 11px; width: 15px; text-align: center; }
#harryChain .hc-slabel {
    flex: 1; min-width: 0; font-weight: 600; font-size: 11.5px; color: #fff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#harryChain li.hc-step.s-info .hc-slabel { font-weight: 500; color: var(--hc-dim); }
#harryChain .hc-swho { flex: none; font-size: 9px; color: var(--primary-light, #ffb6d9); }
#harryChain .hc-sdur {
    flex: none; font-family: ui-monospace, Menlo, monospace; font-size: 10px; color: var(--hc-faint);
}
#harryChain li.hc-step.s-running .hc-sdur { color: #ff9cc5; }
#harryChain li.hc-step.s-fail .hc-sdur { color: var(--hc-fail); }
#harryChain .hc-sinput {
    margin: 2px 0 0 20px; font-family: ui-monospace, Menlo, monospace; font-size: 10px;
    color: #ffcfe3; overflow-wrap: anywhere;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#harryChain .hc-spreview {
    display: none; margin: 3px 0 0 20px; font-size: 10.5px; font-style: italic;
    color: var(--hc-dim); overflow-wrap: anywhere; white-space: pre-wrap;
}
#harryChain li.hc-step.open .hc-sinput { white-space: normal; }
#harryChain li.hc-step.open .hc-spreview { display: block; }
#harryChain .hc-soff {
    font-family: ui-monospace, Menlo, monospace; font-size: 9px; color: var(--hc-faint);
    margin-left: 20px;
}
/* the needle at the tail while he's still stitching */
#harryChain li.hc-needle {
    position: relative; height: 20px; margin: 0; padding: 0; cursor: default;
}
#harryChain li.hc-needle > span {
    position: absolute; left: -21px; top: -2px; font-size: 13px;
    animation: hc-stitch 1.4s ease-in-out infinite;
}
@keyframes hc-stitch {
    0%, 100% { transform: translateY(0) rotate(-8deg); }
    50% { transform: translateY(4px) rotate(10deg); }
}
#harryChain li.hc-needle > em {
    position: absolute; left: 2px; top: 1px; font-size: 10px; color: var(--hc-faint);
}
#harryChain li.hc-more { margin: 0 0 4px 6px; font-size: 10px; color: var(--hc-faint); font-style: italic; cursor: default; }

/* ── The ribbon: a bookmark tab hanging below the window ────────────── */
#harryChain .hc-ribbon {
    position: absolute; left: 50%; bottom: -26px; margin-left: -46px;
    width: 92px; height: 24px; padding: 0 0 5px;
    border: none; cursor: pointer;
    background: var(--primary, #ff69b4);
    color: #fff; font-size: 10px; font-weight: 700; letter-spacing: 0.05em;
    font-family: ui-monospace, 'Cascadia Code', Menlo, monospace;
    text-shadow: 0 1px 0 rgba(60, 20, 40, 0.6);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 72%, 0 100%);
    transition: transform 0.2s ease;
    transform-origin: 50% 0;
}
#harryChain .hc-ribbon:hover { transform: scaleY(1.12); }
#harryChain .hc-ribbon:focus-visible { outline: 2px solid #fff; }

/* ── Narrow screens: an orb bottom-left that opens as an overlay ───── */
#harryChainOrb {
    position: fixed; left: 14px; bottom: 16px; z-index: 1500;
    width: 50px; height: 50px; border-radius: 50%;
    display: none; align-items: center; justify-content: center;
    background: #282426; border: 3px solid var(--primary, #ff69b4);
    outline: 1px solid rgba(20, 14, 16, 0.9);
    box-shadow: inset 0 0 0 1px rgba(255, 214, 231, 0.45), 3px 3px 0 rgba(20, 14, 16, 0.45);
    cursor: pointer; padding: 0;
    color: #ff3f7f; font-size: 20px; line-height: 1;
}
#harryChainOrb.hc-visible { display: flex; }
#harryChainOrb .hc-heart { color: #ff3f7f; font-size: 20px; }
#harryChainOrb .hc-heart.beating { animation: hc-beat 1.1s ease-in-out infinite; }
#harryChainOrb .hc-badge {
    position: absolute; right: -6px; top: -6px; min-width: 18px; height: 18px;
    padding: 0 4px; border-radius: 9px;
    background: var(--primary-light, #ffb6d9); color: #282426;
    font: 700 10px/18px ui-monospace, Menlo, monospace; text-align: center;
    border: 1px solid #241c20;
}
#harryChain.hc-pill {
    top: auto !important; bottom: 76px; left: 14px !important;
    width: min(330px, calc(100vw - 28px)) !important;
    max-height: min(70vh, calc(100vh - 110px));
    z-index: 9460;
}
#harryChain.hc-pill .hc-ribbon { display: none; }
#harryChain.hc-pill.hc-expanded .hc-trail { display: block; }
#harryChain.hc-pill .hc-pillfoot { display: block; }
#harryChain .hc-pillfoot {
    display: none; flex: none; text-align: center; padding: 5px 0 7px;
    border-top: 1px solid rgba(255, 182, 217, 0.25);
}
#harryChain .hc-pillfoot button {
    background: none; border: 1px solid rgba(255, 182, 217, 0.5); border-radius: 10px;
    color: var(--primary-light, #ffb6d9); font-size: 10.5px; padding: 2px 10px; cursor: pointer;
}

/* Presence mode covers the page with its own overlay — ride above it. */
body.presence-active #harryChain { z-index: 9460; }
body.presence-active #harryChainOrb { z-index: 9460; }

@media (prefers-reduced-motion: reduce) {
    #harryChain.hc-entering, #harryChain.hc-leaving,
    #harryChain .hc-trail.hc-unfurl, #harryChain .hc-trail.hc-rollup,
    #harryChain .hc-trail.hc-unfurl ol.hc-steps::before,
    #harryChain li.hc-step.is-new,
    #harryChain .hc-lamp.l-running::after { animation: none !important; }
    #harryChain .hc-heart.beating, #harryChainOrb .hc-heart.beating,
    #harryChain li.hc-step.s-running > .hc-knot,
    #harryChain li.hc-needle > span { animation: none !important; }
    #harryChain .hc-lamp.l-running::after { opacity: 0.8; }
}
