/* ===========================================================
   /diff — list & file compare
   Uses the palette variables from style.css, so every theme works.
   =========================================================== */

/* PIX-VIS-021: one tab component site-wide. /diff used to be the odd one
   out (solid dark fill for the active mode, wrapping onto a second row with
   "NET" stranded alone on mobile); it now matches /ssl's .tls-tab and
   /dns's .dns-tab exactly (grey fill, bordered active state) and, like
   them, scrolls horizontally as a single strip on narrow screens instead
   of wrapping. */
.diff-modes {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    margin-bottom: 1rem;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.diff-modes button {
    flex: 0 0 auto;
    white-space: nowrap;
    background: var(--surface-2);
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 14px;
    cursor: pointer;
    font: inherit;
}
.diff-modes button[aria-selected="true"] {
    color: var(--text-bright);
    border-color: var(--text);
    box-shadow: 0 0 6px var(--glow);
}
.diff-modes button[disabled] {
    opacity: .45;
    cursor: not-allowed;
}

/* ---------- input panes ---------- */
.diff-panes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.diff-pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.diff-pane-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}
.diff-pane-head h3 {
    margin: 0;
    font-size: 1rem;
}
.diff-pane-head .diff-file {
    color: var(--text-dim);
    font-size: .8rem;
    margin-left: auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 45%;
}
.diff-pane textarea {
    width: 100%;
    min-height: 260px;
    resize: vertical;
    white-space: pre;
    overflow-wrap: normal;
    overflow-x: auto;
}
.diff-pane textarea.dragging {
    border-color: var(--text-bright);
    box-shadow: 0 0 8px var(--glow);
}
.diff-stat {
    color: var(--text-dim);
    font-size: .8rem;
    min-height: 1.2em;
    margin-top: 3px;
}

/* Small inline buttons.
   style.css gives every <button> margin-top:14px and every <label>
   margin-bottom:8px. In a centred flex row it is the *margin* box that gets
   centred, so those stray margins push the buttons out of line with each
   other — hence the reset here. Same fix as .encode-actions button. */
.diff-mini {
    display: inline-flex;
    align-items: center;
    margin: 0;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font: inherit;
    font-size: .75rem;
    line-height: 1.4;
    padding: 1px 7px;
    cursor: pointer;
    border-radius: var(--radius);
    vertical-align: middle;
}
.diff-mini:hover { color: var(--text-bright); border-color: var(--text-dim); }

/* the file input is hidden behind a label styled as a button */
.diff-filelabel {
    display: inline-flex;
    align-items: center;
    position: relative;
    margin: 0;
}
.diff-filelabel input[type="file"] {
    position: absolute;
    width: 1px; height: 1px;
    opacity: 0;
    overflow: hidden;
}

/* ---------- action row ---------- */
.diff-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 14px 0 6px;
}
.diff-actions button { margin-top: 0; }   /* keep the whole row on one line */
.diff-actions .hint { margin: 0; }
/* PIX-VIS-022: "reload example" on its own row -- a mini button that used
   to sit in the full-size .diff-actions row above. */
.diff-actions-mini { margin: 0 0 6px; }
.diff-actions-mini button { margin-top: 0; }
.example-note { margin: 0 0 12px; opacity: .85; }

/* ---------- pipeline ---------- */
.diff-pipeline {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 8px 12px;
    margin-bottom: 18px;
}
.diff-pipeline > summary {
    cursor: pointer;
    color: var(--text-bright);
    list-style: none;
}
.diff-pipeline > summary::-webkit-details-marker { display: none; }
.diff-pipeline > summary::before { content: '▸ '; }
.diff-pipeline[open] > summary::before { content: '▾ '; }

/* Wide enough that the longest option text fits on one line — the labels are
   uppercased with letter-spacing, so they need more room than they look. */
.diff-optgrid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(265px, 1fr));
    gap: 6px 18px;
    margin-top: 10px;
}
.diff-optgrid label {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 0;
    font-size: .88rem;
    color: var(--text);
}
.diff-optgrid input[type="checkbox"] { margin: 0; }
.diff-optgrid input[type="text"],
.diff-optgrid input[type="number"],
.diff-optgrid select {
    margin: 0;
    padding: 2px 6px;
    flex: 1 1 auto;
    min-width: 0;
}
.diff-optgrid input[type="number"] { max-width: 70px; flex: 0 0 auto; }
.diff-optgrid .opt-wide { grid-column: 1 / -1; }

/* labels that sit in front of a field: keep the wording on one line and let
   the field shrink instead — "split on" must never break in two */
.diff-optgrid .opt-inline { white-space: nowrap; }
.diff-optgrid .opt-inline input,
.diff-optgrid .opt-inline select { min-width: 0; }

.diff-warn {
    color: #ff6b6b;
    font-size: .82rem;
    margin-top: 8px;
}

/* ---------- results ---------- */
.diff-outs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-top: 20px;
}
.diff-out { min-width: 0; }
.diff-out-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}
.diff-out-head h3 { margin: 0; font-size: .95rem; }
.diff-out-head .diff-count {
    color: var(--text-bright);
    font-weight: bold;
}
.diff-out-head .diff-tools { margin-left: auto; display: flex; gap: 4px; }
.diff-out pre {
    max-height: 340px;
    overflow: auto;
    margin: 0;
    min-height: 120px;
}
.diff-capped {
    color: var(--text-dim);
    font-size: .75rem;
    margin-top: 4px;
}

/* ---------- summary table ---------- */
.diff-summary {
    margin-top: 22px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 12px 14px;
}
.diff-summary h3 { margin: 0 0 10px; font-size: .95rem; }
.diff-sumgrid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 6px 20px;
}
/* PIX-VIS-041: `justify-content: space-between` stretched the gap between
   label and value to fill whatever width auto-fit gave that particular
   item's column -- different label lengths in different auto-fit columns
   ended up with visibly different label-to-value gaps on the same grid. A
   fixed gap (label left, value right, no stretching) keeps every row's
   spacing the same regardless of how many columns auto-fit lands on. */
.diff-sumgrid div { display: grid; grid-template-columns: minmax(0, max-content) minmax(0, auto); justify-content: start; gap: 10px; align-items: baseline; }
.diff-sumgrid span:last-child { justify-self: end; }
.diff-sumgrid span:last-child { color: var(--text-bright); font-weight: bold; }

.diff-simwrap {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    height: 10px;
    overflow: hidden;
    background: var(--surface-2);
}
.diff-simbar {
    height: 100%;
    width: 0;
    background: var(--text);
    box-shadow: 0 0 6px var(--glow);
    transition: width .25s ease;
}

.diff-extra {
    margin-top: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    color: var(--text-dim);
    font-size: .85rem;
}

/* ==========================================================================
   lines mode — real diff
   ========================================================================== */
.dl-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    margin-top: 6px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}
.dl-toolbar label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: .85rem;
}
.dl-toolbar select,
.dl-toolbar input[type="number"] { margin: 0; padding: 2px 6px; }
.dl-toolbar input[type="number"] { width: 60px; }
.dl-toolbar .dl-tools { margin-left: auto; display: flex; gap: 5px; }
.dl-toolbar input:disabled,
.dl-toolbar select:disabled { opacity: .5; }

.dl-statline {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin: 10px 0;
    font-size: .85rem;
    color: var(--text-dim);
}
.dl-bar { letter-spacing: -1px; }
.dl-plus  { color: #3ddc84; }
.dl-minus { color: #ff6b6b; }
.dl-pos { margin-left: auto; color: var(--text-bright); }

/* ---------- the diff surface ---------- */
.dl-wrap {
    display: flex;
    gap: 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
}
.dl-area {
    flex: 1 1 auto;
    min-width: 0;
    max-height: 65vh;
    overflow: auto;
    font-size: .82rem;
    line-height: 1.45;
    padding: 6px 0;
}
.dl-row {
    display: grid;
    align-items: start;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.dl-side .dl-row { grid-template-columns: 3.5em 1fr 3.5em 1fr; }
.dl-inline .dl-row { grid-template-columns: 3.5em 1.4em 1fr; }
.dl-group { display: block; }

.dl-no {
    color: var(--text-dim);
    opacity: .6;
    text-align: right;
    padding-right: 8px;
    user-select: none;
    font-size: .75rem;
    /* PIX-VIS-041: a fixed-em grid track does not shrink for overflowing
       content, but a grid item's default min-width is `auto` (its own
       content's intrinsic width), which can still force the row a few
       pixels wider than the track on a narrow phone (e.g. 3-digit line
       numbers at 2.4em). min-width: 0 lets the track's own fixed size win
       instead. */
    min-width: 0;
    overflow: hidden;
}
.dl-txt { padding: 0 8px; min-width: 0; }
.dl-sign { user-select: none; opacity: .7; text-align: center; min-width: 0; }

.dl-del { background: rgba(255, 107, 107, .12); }
.dl-ins { background: rgba(61, 220, 132, .12); }
.dl-chg { background: rgba(255, 200, 0, .10); }
.dl-moved { background: rgba(90, 160, 255, .14); }

.dl-row mark {
    background: var(--text);
    color: var(--bg);
    border-radius: 2px;
    padding: 0 1px;
}
.dl-del mark { background: #ff6b6b; color: #1a0000; }
.dl-ins mark { background: #3ddc84; color: #00190a; }

.dl-fold {
    display: block;
    text-align: center;
    color: var(--text-dim);
    background: var(--surface);
    border-top: 1px dashed var(--border);
    border-bottom: 1px dashed var(--border);
    font-size: .78rem;
    padding: 2px 0;
    user-select: none;
}
.dl-focus { outline: 1px solid var(--text-bright); outline-offset: -1px; }

.dl-patch { margin: 0; border: 0; background: transparent; padding: 8px 12px; }

/* ---------- minimap ---------- */
.dl-map {
    position: relative;
    flex: 0 0 12px;
    border-left: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
}
.dl-seg { position: absolute; left: 1px; right: 1px; }
.dl-seg-del { background: #ff6b6b; }
.dl-seg-ins { background: #3ddc84; }
.dl-seg-chg { background: #ffc800; }

/* ---------- help panel ---------- */
.dl-help {
    margin-top: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 10px 14px;
}
.dl-help h3 { margin: 0 0 6px; font-size: .9rem; }
.dl-help pre { margin: 0; border: 0; background: transparent; padding: 0; font-size: .8rem; }

/* ==========================================================================
   struct mode — compare by meaning
   ========================================================================== */
.ds-detected { color: var(--text-dim); }

.ds-out {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    max-height: 60vh;
    overflow: auto;
    font-size: .82rem;
    line-height: 1.5;
}
.ds-out:empty { display: none; }

.ds-row {
    display: grid;
    grid-template-columns: 1.6em minmax(8em, 22em) 1fr;
    gap: 8px;
    padding: 2px 8px;
    align-items: start;
    overflow-wrap: anywhere;
}
.ds-row + .ds-row { border-top: 1px solid rgba(128, 128, 128, .12); }
.ds-sign { text-align: center; user-select: none; }
.ds-path { color: var(--text-bright); }
.ds-val  { white-space: pre-wrap; }

.ds-add { background: rgba(61, 220, 132, .10); }
.ds-del { background: rgba(255, 107, 107, .10); }
.ds-chg { background: rgba(255, 200, 0, .08); }
.ds-add .ds-sign { color: #3ddc84; }
.ds-del .ds-sign { color: #ff6b6b; }
.ds-chg .ds-sign { color: #ffc800; }

.ds-old { color: #ff9d9d; }
.ds-new { color: #7ef2b0; }
body.theme-notepad .ds-old { color: #a11212; }
body.theme-notepad .ds-new { color: #0a6b31; }

/* ==========================================================================
   binary mode — hex dump
   ========================================================================== */
.db-area {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    max-height: 60vh;
    overflow: auto;
    font-size: .78rem;
    line-height: 1.5;
    padding: 6px 0;
    white-space: nowrap;
}
/*
    max-content instead of 1fr 1fr: a 1fr track forces the hex/ASCII columns
    to shrink to fit the row, but .db-hex/.db-asc are white-space: pre (they
    do not wrap), so the squeezed column just painted its unbreakable text
    past its own box and into the next column -- side A's ASCII glyphs printed
    over side B's first hex bytes. Sizing each column to its natural content
    width means a row is only ever as wide as it needs to be, and .db-area's
    existing overflow: auto scrolls the rest (PIX-VIS-008).
*/
.db-row {
    display: grid;
    grid-template-columns: 9ch max-content max-content;
    gap: 10px;
    padding: 0 8px;
    width: max-content;
}
.db-off  { color: var(--text-dim); opacity: .7; user-select: none; }
.db-side { display: flex; gap: 10px; min-width: max-content; }
.db-hex  { white-space: pre; }
.db-asc  { opacity: .75; white-space: pre; }
.db-side-b { border-left: 1px solid var(--border); padding-left: 10px; }
.db-x {
    background: rgba(255, 107, 107, .30);
    color: var(--text-bright);
    border-radius: 2px;
}
.db-fold {
    display: block;
    text-align: center;
    color: var(--text-dim);
    border-top: 1px dashed var(--border);
    border-bottom: 1px dashed var(--border);
    user-select: none;
}

.db-hashtable {
    display: grid;
    grid-template-columns: 5em 1fr 1fr;
    gap: 4px 14px;
    margin-top: 16px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: .78rem;
    overflow-wrap: anywhere;
}
.db-hlabel { color: var(--text-dim); }
.db-hhead  { color: var(--text-bright); font-weight: bold; }
/* Ground rule: colours only from palette tokens. #3ddc84/#ff6b6b were a
   literal green/red pair that ignored every theme (e.g. read as an
   off-palette green in amber/notepad/c64). --text and --text-err already
   are the "good"/"bad" tokens the rest of the page uses. */
.db-same   { color: var(--text); }
.db-diff   { color: var(--text-err); }
/* PIX-VIS-023: overall checksum status line, text plus marker (the literal
   text already carries "[+] "/"[!] "), one colour from the same tokens. */
#db-hash-status.db-hash-ok  { color: var(--text); }
#db-hash-status.db-hash-bad { color: var(--text-err); text-shadow: 0 0 4px var(--glow-err); }

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
    .ds-row { grid-template-columns: 1.4em 1fr; }
    .ds-row .ds-val { grid-column: 2; }
    /* A and B stack vertically (both sides share column 2, B placed on its
       own row below A) instead of squeezing side by side on a phone. */
    .db-row { grid-template-columns: 8ch max-content; }
    .db-side-b { grid-column: 2; border-left: 0; padding-left: 0; border-top: 1px dashed var(--border); margin-top: 3px; padding-top: 3px; }
    /* Keep the 3-column label/A/B grid on mobile too (label, A, B): collapsing
       to 2 columns broke the row-per-3-children layout -- the B column landed
       under the next row's label. Columns just get narrower and the hash
       values wrap (.db-hashtable already has overflow-wrap: anywhere). */
    .db-hashtable { grid-template-columns: 4em minmax(0, 1fr) minmax(0, 1fr); }
    .diff-panes { grid-template-columns: 1fr; }
    .diff-outs  { grid-template-columns: 1fr; }
    .diff-pane textarea { min-height: 180px; }
    .dl-side .dl-row { grid-template-columns: 2.4em 1fr 2.4em 1fr; }
    .dl-area { font-size: .75rem; }
    .dl-txt  { padding: 0 4px; }
}

/* At ~20px tall the mini buttons (load file / clear / copy / save / reload
   example) were easy to mis-tap on a phone, including CLEAR, which throws
   away typed input. Desktop keeps the smaller size. */
@media (max-width: 720px) {
    .diff-mini {
        min-height: 32px;
        padding: 6px 10px;
        font-size: .8rem;
    }
    .diff-filelabel {
        min-height: 32px;
    }
}
