/* web/css/viewers.css
 *
 * Things that open over the app: the right-click menu and the diff viewer.
 * The diff viewer re-themes web/vendor/diff2html.css, which index.html links
 * before every file here so these rules win without !important.
 *
 * Linked from web/index.html in the order the sections had in the old
 * web/styles.css, and concatenated in that order they reproduce it exactly, so
 * the cascade is unchanged. A rule that moves between these files moves in the
 * cascade too: check what it now comes before and after.
 */

/* ── the right-click menu ────────────────────────────────────────────────────
   The turn tooltip's positioning with the recent-directories menu's rows. Not
   .turn-pop's `pointer-events: none`, which is right for a tooltip and would
   make this unclickable.

   z-index 70 is between two things: above .scrim (50) and every popover (60 —
   .bell-menu, .new-menu, .turn-pop, .slash-menu), because this can be opened
   over any of them; below .toasts (80), because "could not open that file" must
   not appear behind the menu that asked for it. */
.ctx-menu {
    position: fixed;
    z-index: var(--z-over);
    min-width: 168px;
    padding: var(--sp-3);
    background: var(--s3);
    border-radius: var(--r);
    box-shadow: var(--shadow-pop);
    transform-origin: top left;
    -webkit-app-region: no-drag;   /* opened over the bar, it is still a menu */
}
.ctx-menu[hidden] { display: none; }
.ctx-menu .picker-row { padding: var(--sp-3) var(--sp-5); gap: var(--sp-5); }
.ctx-menu .picker-row:hover:not([disabled]) { background: var(--s4); }
.ctx-menu .picker-row[disabled] { opacity: 0.4; cursor: default; }
.ctx-menu .picker-row.danger { color: var(--red); }
.ctx-menu .sep { height: 1px; margin: var(--sp-2) var(--sp-4); background: var(--outline-soft); }

/* ── the diff viewer ─────────────────────────────────────────────────────────
   diff2html 3.4.56, vendored in web/vendor/. Its stylesheet is loaded before
   this one so these override without !important, which works because every dark
   rule it ships is written `property: literal; property: var(--x)` — so
   redefining the variables is enough, and there is no !important anywhere in it
   to fight.

   The variables are scoped to #diff-body rather than :root deliberately: they
   are diff2html's names, and nothing else in the app should be tintable by
   them. */
.modal.diff-modal {
    /* Derived rather than picked: at 12.5px var(--mono) a character is about
       7.3px, so two 90-column panes plus their two 7.5em gutters is ~1310px.
       Narrower than that and side by side is two unreadable columns rather than
       a layout, which is what the media query at the foot of this block is for. */
    width: min(1400px, 100%);
    /* 92vh where every other dialog takes 88: a diff is the one where the
       vertical room is the product. */
    max-height: 92vh;
}
.diff-title { flex: 1; min-width: 0; display: flex; font: 400 var(--fs-lg)/var(--lh-snug) var(--mono); }
.diff-title .fpath { flex: 1; min-width: 0; display: flex; }
.diff-title .fdir { color: var(--text-4); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diff-title .fbase { color: var(--text); flex: none; }
.diff-stat { display: flex; align-items: center; gap: var(--sp-4); margin: 0 var(--sp-6); flex: none; }
.diff-stat .fstat { font: 400 var(--fs-xs)/var(--lh-snug) var(--mono); }
.diff-stat .ch-nums { font: 400 var(--fs-sm)/var(--lh-snug) var(--mono); }

.diff-bar {
    display: flex;
    align-items: center;
    gap: var(--sp-6);
    flex: none;
    padding: var(--sp-4) var(--sp-9) var(--sp-6);
}
.diff-bar .spacer { flex: 1; }
.diff-seg { display: flex; background: var(--s1); border-radius: var(--pill); padding: var(--sp-1); }
/* Both are hidden while a scratchpad file is up, and both set a display. */
.diff-seg[hidden], .diff-opt[hidden] { display: none; }
.diff-seg-btn {
    height: 26px;
    padding: 0 var(--sp-6);
    border: 0;
    border-radius: var(--pill);
    background: none;
    color: var(--text-3);
    font: 500 var(--fs-sm)/var(--lh-none) var(--sans);
    cursor: pointer;
}
.diff-seg-btn[aria-pressed="true"] { background: var(--blue-cont); color: var(--text); }
.diff-opt {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    font: 400 var(--fs-sm)/var(--lh-none) var(--sans);
    color: var(--text-3);
    cursor: pointer;
}
.diff-source {
    height: 26px;
    padding: 0 var(--sp-4);
    border: 1px solid var(--outline-soft);
    border-radius: var(--r-xs);
    background: var(--s1);
    color: var(--text-2);
    font: 400 var(--fs-sm)/var(--lh-none) var(--sans);
}
.diff-note { font: 400 var(--fs-sm)/var(--lh-snug) var(--sans); color: var(--text-4); text-align: right; }
/* The reload button earns a tint only when there is a reason to press it. */
.diff-bar .btn.accent { color: var(--yellow); }

.diff-body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 0 var(--sp-9) var(--sp-8);
    background: var(--bg);

    /* The additions and deletions are exactly .diff .dl.add / .dl.del above, so
       a diff in this dialog and a diff on a tool card are the same colour. Kept
       low-saturation for that block's reason: a long diff should not become a
       wall of colour. The word-level highlights are one step up from them,
       which is the only place a stronger tint is doing work. */
    --d2h-dark-ins-bg-color: var(--diff-add-bg);
    --d2h-dark-del-bg-color: var(--diff-del-bg);
    --d2h-dark-ins-highlight-bg-color: var(--diff-add-hl);
    --d2h-dark-del-highlight-bg-color: var(--diff-del-hl);
    --d2h-dark-ins-border-color: var(--diff-add-edge);
    --d2h-dark-del-border-color: var(--diff-del-edge);
    --d2h-dark-change-ins-color: var(--diff-add-bg);
    --d2h-dark-change-del-color: var(--diff-change-bg);

    --d2h-dark-bg-color: var(--bg);
    --d2h-dark-color: var(--text-2);
    --d2h-dark-border-color: var(--outline-soft);
    --d2h-dark-line-border-color: var(--outline-soft);
    --d2h-dark-dim-color: var(--text-4);
    --d2h-dark-file-header-bg-color: var(--s2);
    --d2h-dark-file-header-border-color: var(--outline-soft);
    --d2h-dark-empty-placeholder-bg-color: var(--s1);
    --d2h-dark-empty-placeholder-border-color: var(--outline-soft);
    --d2h-dark-selected-color: var(--blue-cont);
    --d2h-dark-info-bg-color: var(--s1);
    --d2h-dark-info-border-color: var(--outline-soft);

    /* The +N/−N labels, matching .ch-add and .ch-del in the drawer this opened from. */
    --d2h-dark-ins-label-color: var(--green);
    --d2h-dark-del-label-color: var(--red);
    --d2h-dark-change-label-color: var(--yellow);
    --d2h-dark-moved-label-color: var(--blue);
}
.diff-body .ch-note { margin: var(--sp-7) var(--sp-2); font-size: var(--fs-md); }

/* The rules diff2html does not put behind a variable. */
.diff-body .d2h-diff-table { font: 400 var(--fs-md)/var(--lh-prose) var(--mono); }
.diff-body .d2h-file-header {
    height: auto;
    padding: var(--sp-4) var(--sp-6);
    font: 400 var(--fs-md)/var(--lh-snug) var(--sans);
}
.diff-body .d2h-file-wrapper {
    border-radius: var(--r-sm);
    margin-bottom: var(--sp-6);
    /* Deliberately *not* `overflow: hidden`, which is what a border-radius here
       normally wants. Hiding overflow makes this a scroll container, and the
       sticky file header below then resolves against it rather than against
       .diff-body — so the header scrolled away with its own block instead of
       sticking, which for the transcript's answer is twelve headers all called
       the same thing and none of them telling you where you are. The radius is
       put on the header and the last row instead. */
    /* `position: relative` is not decoration either — without it the line numbers
       escape the dialog.
       diff2html gives every `.d2h-code-linenumber` `position: absolute` and ships
       no `position: relative` anywhere, which is fine on its own demo pages
       because the containing block ends up being the page and the page is what
       scrolls. Here the scroller is `.diff-body`, and an absolutely positioned
       box whose containing block sits *outside* a scroller is not clipped by it —
       so the gutter alone kept painting, measured at 7000px below the dialog and
       straight over the composer. This puts the containing block back inside the
       thing that clips. */
    position: relative;
}
/* Sticky is set here rather than left to diff2html's own `.d2h-sticky-header`,
   because that class is applied by Diff2HtmlUI.stickyFileHeaders() and the UI
   wrapper is the 90KB we did not vendor — so the rule that used to be here
   matched nothing and quietly did nothing. Offset 0 because .diff-body is the
   scroller, and above the rows so it covers them rather than the reverse.
   It earns its place on the transcript's answer, which is one block per edit:
   twelve headers all naming the same file, and this is what says which edit you
   are in. The tree's single block hides the header outright — see .one-file. */
.diff-body .d2h-file-header { position: sticky; top: 0; z-index: 2; }
/* The corners the wrapper can no longer clip for itself. The header carries the
   top pair, except in the single-file case where it is hidden and the first row
   inherits them. */
.diff-body .d2h-file-header { border-radius: var(--r-sm) var(--r-sm) 0 0; }
.diff-body.one-file .d2h-diff-tbody tr:first-child td:first-child { border-top-left-radius: var(--r-sm); }
.diff-body.one-file .d2h-diff-tbody tr:first-child td:last-child { border-top-right-radius: var(--r-sm); }
.diff-body .d2h-diff-tbody tr:last-child td:first-child { border-bottom-left-radius: var(--r-sm); }
.diff-body .d2h-diff-tbody tr:last-child td:last-child { border-bottom-right-radius: var(--r-sm); }
/* See paintDiff: for the tree's single block the header is the dialog title
   repeated, so it goes. */
.diff-body.one-file .d2h-file-header { display: none; }
/* A scratchpad file, drawn as one whole-file addition (see wholeFile in
   web/transcript/changes.js). Being all-new is how it got here, not something
   about the file, so the green, the `+` and the empty old-side gutter go. */
.diff-body.file-view .d2h-ins { background: var(--bg); border-color: transparent; }
.diff-body.file-view .d2h-code-line-prefix { display: none; }
.diff-body.file-view .line-num1 { display: none; }
.diff-body.file-view .d2h-info { display: none; }
.diff-body .d2h-file-side-diff { overflow-x: auto; }
.diff-body .d2h-file-list-wrapper { margin-bottom: var(--sp-6); }
.diff-body .d2h-file-list-title { font: 500 var(--fs-md)/var(--lh-snug) var(--sans); color: var(--text-3); }
.diff-body .d2h-file-name { font: 400 var(--fs-sm)/var(--lh-base) var(--mono); }

/* Wrap the content span, not the line box. .d2h-code-line is
   `width: calc(100% - 16em)` against an absolutely positioned 7.5em gutter, so
   wrapping the box itself pulls the line numbers out of alignment. */
.diff-body.wrap .d2h-code-line-ctn,
.diff-body.wrap .d2h-code-side-line .d2h-code-line-ctn {
    white-space: pre-wrap;
    word-break: break-word;
}

/* Below the width two panes need, side by side cannot be chosen at all — better
   than letting the remembered preference put someone into two 30-column columns
   they then have to work out how to leave. */
@media (max-width: 900px) {
    .diff-seg { display: none; }
    .diff-note { display: none; }
}


/* ── review comments ─────────────────────────────────────────────────────────
   web/transcript/diff-review.js. diff2html's markup is never edited, so all of
   this is either a hover rule on its gutter or a layer of our own laid over the
   body, measured off its rows. The layer is the body's positioned child: it
   scrolls with the rows it marks. */
.diff-body { position: relative; }
.diff-body.commentable td.d2h-code-linenumber:hover,
.diff-body.commentable td.d2h-code-side-linenumber:hover {
    color: var(--blue);
    box-shadow: inset 3px 0 var(--blue);
}
.dc-layer {
    position: absolute;
    inset: 0 0 auto 0;
    height: 0;
    z-index: 3;
    pointer-events: none;
}
.dc-sel, .dc-mark {
    position: absolute;
    left: var(--sp-9);
    right: var(--sp-9);
    border-left: 3px solid var(--blue);
    background: color-mix(in srgb, var(--blue) 14%, transparent);
}
.dc-mark {
    border-left-color: var(--yellow);
    background: color-mix(in srgb, var(--yellow) 8%, transparent);
}
.dc-mark.on { background: color-mix(in srgb, var(--yellow) 16%, transparent); }
.dc-badge {
    position: absolute;
    right: calc(var(--sp-9) + var(--sp-3));
    min-width: 20px;
    height: 18px;
    margin-top: 1px;
    padding: 0 var(--sp-3);
    border: 0;
    border-radius: var(--pill);
    background: var(--yellow);
    color: var(--bg);
    font: 600 var(--fs-xs)/18px var(--sans);
    cursor: pointer;
    pointer-events: auto;
}
.dc-offer {
    position: absolute;
    left: calc(var(--sp-9) + 8em);
    pointer-events: auto;
    box-shadow: var(--shadow-float);
}
.dc-editor {
    position: absolute;
    left: calc(var(--sp-9) + 4em);
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    padding: var(--sp-5);
    border-radius: var(--r-sm);
    background: var(--s2);
    box-shadow: var(--shadow-float);
    pointer-events: auto;
}
.dc-editor-head { font: 400 var(--fs-sm)/var(--lh-snug) var(--mono); color: var(--text-3); }
.dc-editor textarea {
    resize: vertical;
    min-height: 64px;
    padding: var(--sp-4);
    border: 1px solid var(--outline-soft);
    border-radius: var(--r-xs);
    background: var(--bg);
    color: var(--text);
    font: 400 var(--fs-md)/var(--lh-base) var(--sans);
}
.dc-editor textarea:focus { outline: none; border-color: var(--blue); }
.dc-editor-foot { display: flex; align-items: center; gap: var(--sp-4); }
.dc-hint { flex: 1; font: 400 var(--fs-xs)/var(--lh-snug) var(--sans); color: var(--text-4); }

/* ── Restore files to before a turn (web/transcript/restore.js) ───────────
   The row button is drawn hidden until the turn is known to have a checkpoint;
   .ev-copy's display: grid would otherwise beat the attribute. */
.ev-copy.ev-restore[hidden] { display: none; }
/* The dialog: the list and buttons above, the diff below, one scroll each so a long file
   list never pushes the Restore button off the dialog. */
.modal.restore-modal {
    width: min(1100px, 100%);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
}
.restore-main { display: flex; flex-direction: column; flex: none; }
.restore-main .rs-body { overflow: auto; max-height: 38vh; }
.restore-main .rs-files { padding-bottom: 6px; }
.restore-modal > .modal-foot { flex: none; }
.restore-diff { flex: 1 1 auto; min-height: 0; overflow: auto; border-top: 1px solid var(--outline-soft); }
.rs-what { margin: 0 0 10px; color: var(--text-2); line-height: var(--lh-snug, 1.4); }
.rs-what code { font-family: var(--mono); color: var(--text); }
.rs-note { color: var(--text-3); margin: 6px 0; }
.rs-error { color: var(--red); margin: 6px 0; }
.rs-listhead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 6px; }
.rs-all { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.rs-warn { color: var(--yellow); font-size: var(--fs-sm, 12px); }
.rs-files { display: flex; flex-direction: column; gap: 1px; }
.rs-file {
    display: grid;
    grid-template-columns: auto 5.5em minmax(0, 1fr) auto auto;
    align-items: center; gap: 8px;
    padding: 3px 6px; border-radius: 6px; cursor: pointer;
}
.rs-file:hover { background: var(--s3); }
.rs-change {
    font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3);
}
.rs-file[data-change="delete"] .rs-change { color: var(--red); }
.rs-file[data-change="create"] .rs-change { color: var(--green); }
.rs-path { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
.rs-outside {
    font-size: 11px; color: var(--yellow); border: 1px solid currentColor;
    border-radius: 999px; padding: 0 6px; white-space: nowrap;
}
.rs-counts { font-family: var(--mono); font-size: 12px; display: flex; gap: 6px; justify-content: flex-end; min-width: 6em; }
.rs-add { color: var(--green); }
.rs-del { color: var(--red); }
.rs-bin { color: var(--text-3); }
