/* A session's side panel (session-panel.js): one narrow column of sections between hairlines.
   No cards, no shadows. A row is a 16px icon, words, and something at the right; a row that acts
   lights up whole. Linked after styles.css: everything here uses that file's tokens. */

/* What fills the context, one colour per part: the bar and its legend read the same ones. */
:root {
  --sp-part-messages: #4c8dff;
  --sp-part-tools: #e8973d;
  --sp-part-instructions: #a274e8;
  --sp-part-skills: #2fb391;
  --sp-part-workspace: #dc64a8;
  --sp-part-harness: #8b92a1;
}

/* The app's panel body gives up its own padding: the sections reach both edges. */
.panel-body:has(> .sp) { padding: 0 0 16px; }
.panel-body:has(> .sp) > .agent-head { padding-left: 14px; padding-right: 14px; padding-bottom: 6px; }

.sp { display: flex; flex-direction: column; min-width: 0; font-size: 14px; line-height: 20px; color: var(--text); text-align: left; }

/* --- Sections ----------------------------------------------------------------------------------- */

.sp-section { display: flex; flex-direction: column; min-width: 0; padding: 10px 14px; }
.sp-section:not([hidden]) ~ .sp-section, .sp-section:not([hidden]) ~ .sp-foot { border-top: 1px solid var(--border-3); }
.sp-head { display: flex; align-items: center; gap: 8px; min-height: 28px; }
.sp-title { flex: 1 1 0; min-width: 0; font-size: 13px; line-height: 18px; font-weight: 500; color: var(--text-2); }
.sp-head-right { flex: none; display: inline-flex; align-items: center; gap: 6px; }
.sp-count { font-size: 12px; line-height: 18px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.sp-rows { display: flex; flex-direction: column; min-width: 0; }
.sp-note { padding: 6px 0; font-size: 13px; line-height: 18px; color: var(--text-3); }

/* --- A row -------------------------------------------------------------------------------------- */

/* The hover reaches 8px past the words on both sides, so the words line up with the heading. */
.sp-row { display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 32px; margin: 0 -8px; padding: 0 8px; border-radius: 6px; text-align: left; text-decoration: none; }
.sp-act { cursor: pointer; }
.sp-act:hover { background: var(--fill); }
.sp-ico { flex: none; display: grid; place-items: center; width: 16px; height: 16px; color: var(--text-3); }
.sp-text { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-quiet { color: var(--text-3); }
.sp-quiet::before { content: " · "; white-space: pre; color: var(--text-4); }
.sp-owner { color: var(--text-3); }
.sp-right { flex: 0 1 auto; min-width: 0; max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; line-height: 18px; color: var(--text-3); text-align: right; }
.sp-right.sp-ctl { display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; max-width: 64%; overflow: visible; }
.sp-ctl .btn { flex: none; }

/* A row whose words act and that also carries a button: the words are the link, the button sits beside them. */
.sp-hit { flex: 1 1 0; align-self: stretch; display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; text-align: left; text-decoration: none; border-radius: 6px; }
.sp-hit:focus-visible { outline-offset: 2px; }
.sp-row.sp-two { align-items: center; min-height: 46px; }
.sp-stack { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; }
.sp-stack .sp-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-sub { display: flex; gap: 6px; min-width: 0; font-size: 12px; line-height: 17px; color: var(--text-3); white-space: nowrap; overflow: hidden; }
.sp-sub > span { overflow: hidden; text-overflow: ellipsis; }
.sp-sub > span:first-child { flex: none; font-variant-numeric: tabular-nums; }
.sp-stands::before { content: "· "; color: var(--text-4); }
.sp-more, .sp-stop { margin-right: -4px; }

/* What the app hands in for Project and Access: the same control, without its box. */
.sp .sp-ctl .select-btn { min-width: 0; max-width: 100%; height: 26px; margin-right: -6px; padding: 0 4px 0 8px; border: 0; background: none; font-size: 13px; color: var(--text-2); }
.sp .sp-ctl .select-btn span { overflow: hidden; text-overflow: ellipsis; }
.sp .sp-ctl .select-btn:hover, .sp .sp-ctl .select-btn[aria-expanded="true"] { background: var(--fill-hover); color: var(--text); }
.sp-link { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-radius: 4px; font-size: 13px; line-height: 18px; color: var(--text-3); }
.sp-link:hover { color: var(--text); text-decoration: underline; text-decoration-color: var(--border-1); text-underline-offset: 3px; }
.sp-ref { display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 12px/18px var(--mono); color: var(--text-3); }
.sp-state { display: inline-flex; align-items: center; gap: 6px; }
.sp-state[data-state="working"] { color: var(--text-2); }
.sp-state[data-state="working"]::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--blue); animation: pulse 1.4s ease-in-out infinite; }
.sp-go { display: inline-flex; align-items: center; gap: 2px; }

/* A dot that says how something stands: a subagent, or the tunnels. */
.sp-dot { flex: none; display: block; width: 8px; height: 8px; border-radius: 50%; box-shadow: inset 0 0 0 1px var(--border-1); }
.sp-dot[data-dot="working"] { background: var(--blue); box-shadow: none; animation: pulse 1.4s ease-in-out infinite; }
.sp-dot[data-dot="unread"] { background: #36b1fb; box-shadow: none; }
.sp-dot[data-dot="needs"] { background: var(--warn); box-shadow: none; }
.sp-dot[data-dot="failed"] { background: var(--danger); box-shadow: none; }
.sp-dot[data-dot="stopped"] { background: var(--text-4); box-shadow: none; }
.sp-dot[data-tone="open"] { background: var(--success); box-shadow: none; }
.sp-dot[data-tone="opening"] { background: var(--warn); box-shadow: none; animation: pulse 1.1s ease-in-out infinite; }
.sp-dot[data-tone="failed"] { background: var(--danger); box-shadow: none; }

/* "Show more", "3 finished", "2 earlier pull requests": a quiet line that unfolds what is under it. */
.sp-more-line { align-self: flex-start; min-height: 28px; margin: 0 -8px; padding: 0 8px; border-radius: 6px; font-size: 13px; line-height: 18px; color: var(--text-3); }
.sp-more-line:hover { background: var(--fill); color: var(--text); }
.sp-folded::after { content: ""; display: inline-block; width: 5px; height: 5px; margin: 0 0 2px 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform .15s var(--ease); }
.sp-folded[aria-expanded="true"]::after { transform: rotate(45deg); }

/* --- A one-row section that unfolds ------------------------------------------------------------- */

.sp-fold-label { flex: 1 1 0; min-width: 0; display: inline-flex; align-items: center; gap: 3px; }
.sp-chev { display: grid; place-items: center; color: var(--text-4); transition: transform .15s var(--ease); }
.sp-fold-row[aria-expanded="true"] .sp-chev { transform: rotate(90deg); }
.sp-summary { flex: none; display: inline-flex; align-items: center; gap: 8px; max-width: none; overflow: visible; font-variant-numeric: tabular-nums; }
.sp-summary[data-tone="open"] { color: var(--text-2); }
.sp-summary[data-tone="failed"] { color: var(--danger); }
/* Unfolded, the context screen says the same figure in full. */
.sp-fold[data-section="context"][data-open="true"] .sp-summary { display: none; }
.sp-meter { flex: none; display: block; width: 44px; height: 4px; border-radius: 2px; background: var(--fill-hover); overflow: hidden; }
.sp-meter-fill { display: block; height: 100%; border-radius: 2px; background: var(--text-2); }
.sp-meter[data-level="high"] .sp-meter-fill { background: var(--warn); }
.sp-meter[data-level="full"] .sp-meter-fill { background: var(--danger); }
.sp-detail { min-width: 0; padding: 6px 0 4px; }

/* --- The context screen ------------------------------------------------------------------------- */

.sp-ctx { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.sp-ctx-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.sp-ctx-used { font-size: 14px; line-height: 20px; font-weight: 500; }
.sp-ctx-of { font-size: 13px; line-height: 18px; color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sp-ctx-bar { display: flex; gap: 1px; height: 6px; border-radius: 3px; background: var(--fill-hover); overflow: hidden; }
.sp-ctx-seg { flex: none; min-width: 2px; height: 100%; background: var(--sp-part, var(--text-3)); }
:is(.sp-ctx-seg, .sp-ctx-line)[data-part="messages"] { --sp-part: var(--sp-part-messages); }
:is(.sp-ctx-seg, .sp-ctx-line)[data-part="tools"] { --sp-part: var(--sp-part-tools); }
:is(.sp-ctx-seg, .sp-ctx-line)[data-part="instructions"] { --sp-part: var(--sp-part-instructions); }
:is(.sp-ctx-seg, .sp-ctx-line)[data-part="skills"] { --sp-part: var(--sp-part-skills); }
:is(.sp-ctx-seg, .sp-ctx-line)[data-part="workspace"] { --sp-part: var(--sp-part-workspace); }
:is(.sp-ctx-seg, .sp-ctx-line)[data-part="harness"] { --sp-part: var(--sp-part-harness); }
.sp-ctx-legend { display: flex; flex-direction: column; }
.sp-ctx-line { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto 46px; align-items: center; column-gap: 8px; min-height: 24px; font-size: 13px; line-height: 18px; }
.sp-ctx[data-window="false"] .sp-ctx-line { grid-template-columns: 8px minmax(0, 1fr) auto; }
.sp-ctx[data-window="false"] .sp-ctx-pct { display: none; }
.sp-swatch { width: 8px; height: 8px; border-radius: 2px; background: var(--sp-part, var(--text-3)); }
.sp-ctx-free .sp-swatch { background: none; box-shadow: inset 0 0 0 1px var(--border-1); }
.sp-ctx-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.sp-ctx-free .sp-ctx-label { color: var(--text-3); }
.sp-ctx-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sp-ctx-pct { text-align: right; color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sp-ctx-totals { display: flex; flex-direction: column; padding-top: 8px; border-top: 1px solid var(--border-3); font-size: 12px; line-height: 20px; color: var(--text-3); }
.sp-ctx-caption { font-weight: 500; }
.sp-ctx-total { display: flex; justify-content: space-between; gap: 12px; }
.sp-ctx-total .sp-ctx-num { color: var(--text-2); }
.sp-ctx-foot { font-size: 12px; line-height: 17px; color: var(--text-3); }

/* --- The tunnels, unfolded: the same list without its box --------------------------------------- */

.sp-detail .tn-panel { border: 0; border-radius: 0; background: none; }
.sp-detail .tn-panel[data-compact="true"] .tn-row { padding: 8px 0; }
.sp-detail .tn-panel[data-compact="true"] :is(.tn-notice, .tn-foot, .tn-empty, .tn-note) { padding-left: 0; padding-right: 0; }
.sp-detail .tn-panel .tn-empty { padding-top: 4px; }
.sp-detail .tn-panel .tn-foot { padding-bottom: 2px; border-top: 0; }

/* --- Changes ------------------------------------------------------------------------------------ */

.sp-row[data-tone="success"] .sp-ico, .sp-row[data-tone="success"] .sp-stands { color: var(--success); }
.sp-row[data-tone="danger"] .sp-ico, .sp-row[data-tone="danger"] .sp-stands { color: var(--danger); }
.sp-row[data-tone="warn"] .sp-ico, .sp-row[data-tone="warn"] .sp-stands { color: var(--warn); }
.sp-row[data-tone="pending"] .sp-ico, .sp-row[data-tone="pending"] .sp-stands { color: var(--blue); }
.sp-row[data-tone="neutral"] .sp-ico { color: var(--text-2); }
.sp-row[data-tone="muted"] .sp-ico { color: var(--text-4); }
.sp-row[data-state="merged"] .sp-main, .sp-row[data-state="closed"] .sp-main { color: var(--text-2); }
.sp-plus { color: var(--success); font-variant-numeric: tabular-nums; }
.sp-minus { color: var(--danger); font-variant-numeric: tabular-nums; }

/* --- Tasks -------------------------------------------------------------------------------------- */

.sp-todos { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.sp-todo { display: flex; align-items: flex-start; gap: 10px; min-height: 28px; padding: 4px 0; }
.sp-todo-mark { flex: none; display: grid; place-items: center; width: 16px; height: 16px; margin-top: 2px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--border-1); color: var(--text-3); }
.sp-todo[data-status="in_progress"] .sp-todo-mark { box-shadow: inset 0 0 0 1.5px var(--blue); }
.sp-todo[data-status="in_progress"] .sp-todo-mark::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--blue); animation: pulse 1.4s ease-in-out infinite; }
.sp-todo[data-status="completed"] .sp-todo-mark { box-shadow: none; }
.sp-todo-text { flex: 1 1 0; min-width: 0; overflow-wrap: anywhere; }
.sp-todo[data-status="completed"] .sp-todo-text { color: var(--text-3); }
.sp-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 0 2px; }
.sp .sp-chips .chip { height: 26px; padding: 0 10px; border-radius: 13px; font-size: 12px; }

/* --- The foot ----------------------------------------------------------------------------------- */

.sp-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px 4px; font-size: 12px; line-height: 18px; color: var(--text-4); }
.sp-foot:empty { display: none; }
.sp-id { flex: none; margin: -3px -6px; padding: 3px 6px; border-radius: 6px; font: 12px/18px var(--mono); color: var(--text-4); }
.sp-id:hover { background: var(--fill); color: var(--text-2); }

/* --- The file viewer ---------------------------------------------------------------------------- */

.modal.sp-viewer { width: min(880px, 100%); height: min(760px, 100%); }
.sp-viewer-box { flex: 1 1 auto; display: flex; flex-direction: column; width: 100%; min-width: 0; min-height: 0; }
.sp-viewer-head { flex: none; display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 0 12px 0 18px; border-bottom: 1px solid var(--border-3); }
.sp-viewer-name { flex: 1 1 0; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.sp-viewer-title { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; line-height: 20px; font-weight: 500; }
.sp-viewer-path { flex: 0 10 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 12px/18px var(--mono); color: var(--text-3); }
.sp-viewer-body { flex: 1 1 0; min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; padding: 18px; }
.sp-viewer-doc { max-width: 720px; margin: 0 auto; font-size: 14px; line-height: 22px; overflow-wrap: anywhere; }
/* Code fills the viewer: the box and its own Copy are the viewer's already. */
.sp-viewer-body > .md-code { margin: -18px; border: 0; border-radius: 0; background: none; overflow: visible; }
.sp-viewer-body > .md-code > .md-code-head { display: none; }
.sp-viewer-body > .md-code > pre { padding: 14px 18px; overflow: visible; }
.sp-viewer-error { display: flex; flex-direction: column; gap: 4px; padding: 24px 0; font-size: 13px; line-height: 19px; color: var(--text-2); text-align: center; }
.sp-viewer-error strong { font-size: 14px; font-weight: 500; color: var(--danger); }

/* --- A phone: the panel is a sheet, and everything is 44px to touch ------------------------------ */

@media (max-width: 767px) {
  .sp-section { padding: 8px 16px; }
  .sp-foot { padding: 14px 16px 4px; }
  .sp-row { min-height: 44px; font-size: 15px; }
  .sp-row.sp-two { min-height: 54px; }
  .sp-right { font-size: 14px; }
  .sp-more-line { min-height: 44px; font-size: 14px; }
  .sp-todo { min-height: 36px; padding: 8px 0; }
  .sp-ctx-line { min-height: 30px; font-size: 14px; }
  .sp-id { padding: 12px 8px; margin: -12px -8px; }
  .sp .sp-ctl .select-btn { height: 36px; font-size: 14px; }
  .sp :is(.sp-more, .sp-stop) { width: 40px; height: 40px; }
  /* The app's 44px buttons are for the bottom of a sheet; inside a row they stay a row's height. */
  .sp .sp-row .btn, .sp .sp-head .btn { height: 32px; padding: 0 12px; border-radius: 16px; font-size: 13px; }
  .sp .sp-chips .chip { height: 36px; padding: 0 14px; border-radius: 18px; font-size: 13px; }
  .sp-viewer-head { min-height: 56px; padding: 0 8px 0 16px; }
  .sp-viewer-head .btn { height: 36px; padding: 0 14px; border-radius: 18px; }
  .sp-viewer-path { display: none; }
  .sp-viewer-body { padding: 16px; }
  .sp-viewer-body > .md-code { margin: -16px; }
  .sp-viewer-body > .md-code > pre { padding: 12px 16px; }
}

@media (hover: none) {
  .sp-act:hover, .sp-more-line:hover, .sp-id:hover { background: none; }
  .sp-act:active, .sp-more-line:active { background: var(--fill); }
}

@media (prefers-reduced-motion: reduce) {
  .sp-dot, .sp-state::before, .sp-todo-mark::after { animation: none !important; }
  .sp-chev, .sp-folded::after { transition: none; }
}

/* A control at the right of a row keeps its words: the label gives way, not the control. */
.sp-right.sp-ctl { flex: 0 0 auto; }
.sp .sp-ctl .select-btn span { max-width: 190px; }
/* (Its own width is its limit: a share of a box sized by it would clip it by its negative margin.) */
.sp .sp-ctl .select-btn { max-width: none; margin-right: -4px; }
