/* The laboratory's panels. They borrow the book's palette (web/book.css): every colour here is
   one of its tokens, so light and dark themes both work. */

.lab { margin: 1.8rem 0; border: 1px solid var(--edge); border-radius: 8px; background: var(--bg);
       font: 14px/1.5 var(--chrome); box-shadow: 0 1px 2px var(--raise); overflow: hidden; }
.lab-fallback, .lab-status { margin: 0; color: var(--muted); }
.lab-fallback { padding: 1rem; }
.lab-error { color: var(--stop); }
.lab-head { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: baseline; padding: .6rem 1rem;
            border-bottom: 1px solid var(--edge); background: var(--panel); }
.lab-title { font-weight: 650; }
.lab-note { color: var(--faint); font-size: 12.5px; margin-left: auto; }
.lab code { font-size: 12.5px; }
.lab-foot { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; padding: .6rem 1rem;
            border-top: 1px solid var(--edge); background: var(--panel); }
.lab-foot .lab-status { font-size: 13px; flex: 1 1 16rem; }
.lab button { font: 13px var(--chrome); color: var(--ink); background: var(--bg); border: 1px solid var(--rule);
              border-radius: 4px; padding: .25rem .6rem; cursor: pointer; }
.lab button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.lab button:disabled { opacity: .6; cursor: progress; }

/* The plan: operators top down, as DuckDB draws them, rows flowing up the links between them. */
.plan-tree { padding: 1rem; overflow-x: auto; }
/* The tree is as wide as its widest row, and centred only when it fits: centring a row wider than
   the panel would push its left end past where the panel can scroll to. */
.plan-tree > .plan-node { width: max-content; min-width: 100%; }
.plan-node { display: flex; flex-direction: column; align-items: center; }
.plan-children { display: flex; gap: 1rem; justify-content: center; }
.plan-branch { display: flex; flex-direction: column; align-items: center; }
.plan-link { font-size: 12px; color: var(--faint); padding: .35rem 0; border-left: 2px solid var(--rule);
             padding-left: .5rem; margin: .2rem 0; font-variant-numeric: tabular-nums; }
/* One width for every operator, whatever its depth: a nested box has no container to size it by. */
.plan-op { width: 26rem; max-width: calc(100vw - 4rem); border: 1px solid var(--rule); border-radius: 6px; background: var(--bg);
           padding: .55rem .75rem; box-shadow: 0 1px 2px var(--raise); }
.plan-op-name { font: 600 12.5px var(--mono); letter-spacing: .02em; color: var(--accent); }
.plan-op-detail { margin: .3rem 0 .45rem; display: grid; grid-template-columns: max-content 1fr;
                  gap: .05rem .6rem; font-size: 12.5px; }
.plan-op-detail dt { color: var(--faint); }
.plan-op-detail dd { margin: 0; font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
.plan-bars { display: grid; gap: .2rem; }
.plan-bar { display: grid; grid-template-columns: 6.6rem 1fr 4.2rem; gap: .5rem; align-items: center;
            font-size: 12.5px; }
.plan-bar-label { color: var(--muted); }
.plan-bar-track { height: .55rem; background: var(--panel); border-radius: 3px; overflow: hidden; }
.plan-bar-fill { display: block; height: 100%; border-radius: 3px; }
.plan-bar.estimated .plan-bar-fill { background: var(--rule); }
.plan-bar.measured .plan-bar-fill { background: var(--accent); }
.plan-bar-value { text-align: right; font-variant-numeric: tabular-nums; }
.plan-op-flow { margin-top: .4rem; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.plan-op-flow b { color: var(--ink); font-weight: 600; margin-right: .6rem; }

/* Changes to the query the book computed ahead: one press redraws the plan from that report. */
.plan-variants-ask { margin: 0; padding: .7rem 1rem 0; font-size: 13px; color: var(--ink); }
.plan-variants { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; padding: .7rem 1rem 0; }
.plan-variants-label { font-size: 12.5px; color: var(--muted); margin-right: .2rem; }
.lab .plan-variant { font-size: 12.5px; border-radius: 999px; padding: .2rem .7rem; }
.lab .plan-variant[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--wash); font-weight: 600; }
.plan-sql { margin: .6rem 1rem 0; padding: .5rem .7rem; font: 12.5px/1.45 var(--mono); background: var(--code);
            border-radius: 4px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* The first rows of the result. */
/* Under the tree and as wide as an operator, so the eye goes from the top operator to its rows. */
.plan-preview { width: 26rem; max-width: calc(100vw - 4rem); margin: 0 auto; padding: 0 0 1rem; }
.plan-preview h4 { margin: 0 0 .4rem; font-size: 11.5px; font-weight: 600; letter-spacing: .05em;
                   text-transform: uppercase; color: var(--faint); }
.plan-preview-wrap { overflow-x: auto; }
.plan-preview table { border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.plan-preview th, .plan-preview td { padding: .2rem .7rem .2rem 0; text-align: left; border-bottom: 1px solid var(--edge);
                                     white-space: nowrap; }
.plan-preview th { font-family: var(--mono); font-weight: 600; color: var(--muted); }
.plan-preview td.num { text-align: right; }

/* The query editor: the reader's copy of the query, run by the button below it. */
.lab-editor { border-top: 1px solid var(--edge); }
.lab-editor summary { padding: .5rem 1rem; cursor: pointer; font-size: 13px; color: var(--accent); }
.lab-editor[open] summary { border-bottom: 1px solid var(--edge); }
.lab-editor textarea { display: block; box-sizing: border-box; width: 100%; margin: 0; border: 0; resize: vertical;
                       padding: .7rem 1rem; font: 13px/1.5 var(--mono); color: var(--ink); background: var(--code);
                       tab-size: 2; }
.lab-editor textarea:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.lab-editor-bar { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center; padding: .5rem 1rem; }
.lab-hint { font-size: 12px; color: var(--faint); }
.lab[data-edited="true"] .lab-run { border-color: var(--accent); color: var(--accent); }

/* Predict, then reveal. The reader's guess is its own colour, beside the estimate and the
   measurement, and a hidden measurement is an empty track. */
.plan-bar.predicted .plan-bar-fill { background: var(--warn); }
.plan-predict input { font: 13px var(--chrome); color: var(--ink); background: var(--bg); width: 100%;
                      box-sizing: border-box; border: 1px solid var(--rule); border-radius: 4px; padding: .1rem .35rem;
                      font-variant-numeric: tabular-nums; grid-column: 2 / 4; }
.plan-predict input:focus { outline: 2px solid var(--warn); outline-offset: 0; border-color: var(--warn); }
.plan-bar.hidden .plan-bar-track { background: repeating-linear-gradient(135deg, var(--panel) 0 6px, var(--edge) 6px 8px); }
.plan-bar.hidden .plan-bar-value { color: var(--faint); font-style: italic; }
.plan-ask { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: center;
            padding: 0 1rem 1rem; }
.lab .plan-reveal { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.lab .plan-again { margin-left: .5rem; font-size: 12px; padding: .1rem .5rem; }

/* The problems workbench: the reader's answers, the graders' verdicts under them. */
.workbench { margin: 1.8rem 0; border: 1px solid var(--edge); border-radius: 8px; background: var(--bg);
             font: 14px/1.5 var(--chrome); box-shadow: 0 1px 2px var(--raise); overflow: hidden; }
.workbench .lab-fallback { padding: 1rem; margin: 0; color: var(--muted); }
.workbench textarea { display: block; box-sizing: border-box; width: 100%; margin: 0; border: 0; resize: vertical;
                      padding: .7rem 1rem; font: 13px/1.5 var(--mono); color: var(--ink); background: var(--code);
                      tab-size: 4; }
.workbench textarea:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.workbench button { font: 13px var(--chrome); color: var(--ink); background: var(--bg); border: 1px solid var(--rule);
                    border-radius: 4px; padding: .25rem .6rem; cursor: pointer; }
.workbench button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.workbench .lab-run { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.wb-results:empty { display: none; }
.wb-results { padding: .6rem 1rem 1rem; border-top: 1px solid var(--edge); }
.wb-problem { margin: .3rem 0; }
.wb-problem summary { cursor: pointer; font-weight: 600; }
.wb-problem.pass summary { color: var(--go); }
.wb-problem.fail summary { color: var(--stop); }
.wb-problem ul { margin: .3rem 0 .6rem; padding-left: 1.2rem; font-size: 13px; }
.wb-problem li { margin: .15rem 0; }
.wb-problem li.passed code { color: var(--go); }
.wb-problem li.failed code { color: var(--stop); }
.wb-message { display: block; color: var(--muted); font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.wb-output { font: 12px/1.45 var(--mono); white-space: pre-wrap; margin: 0; }

/* The gather: the two files' gathers side by side where there is room, each with the pattern of
   its first reads above its bars. */
.gather-facts { margin: 0; padding: .7rem 1rem 0; font-size: 13px; color: var(--muted); }
.gather-facts b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.gather-runs { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; padding: 1rem; }
.gather-run { width: 22rem; }
.gather-figure { margin: .4rem 0 .6rem; }
.gather-pattern { display: block; width: 100%; height: auto; background: var(--panel); border-radius: 4px; }
.gather-pattern circle { fill: var(--accent); }
.gather-figure figcaption { font-size: 11.5px; color: var(--faint); margin-top: .25rem; }

/* Pruning: each row group as the range its statistics record, on one scale per file, with the
   filters' band across it. A skipped row group is faint; a read one is solid. */
.pruning-file { width: 22rem; }
.pruning-groups { list-style: none; margin: .5rem 0 .3rem; padding: 0; display: grid; gap: .22rem; }
.pruning-group { display: grid; grid-template-columns: 1fr 4.2rem; gap: .5rem; align-items: center; font-size: 12px; }
.pruning-track { position: relative; display: block; height: .7rem; background: var(--panel); border-radius: 3px; overflow: hidden; }
.pruning-track-alone { height: 1.1rem; margin: .5rem 0 .2rem; }
.pruning-window { position: absolute; top: 0; bottom: 0; background: var(--warn); opacity: .35; }
.pruning-range { position: absolute; top: 25%; bottom: 25%; border-radius: 2px; background: var(--rule); }
.pruning-group.read .pruning-range { background: var(--accent); }
.pruning-verdict { color: var(--faint); text-align: right; }
.pruning-group.read .pruning-verdict { color: var(--ink); font-weight: 600; }
.pruning-caption { margin: 0 0 .5rem; font-size: 11.5px; color: var(--faint); }
/* Under the tracks only: a row group's list has a verdict column the axis must not run under. */
.pruning-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint);
                font-variant-numeric: tabular-nums; margin: 0 0 .3rem; }
.pruning-groups + .pruning-axis { margin-right: 4.7rem; }

/* The branches panel (ch06): cases as the gather panel's, then the sweep. */
.branch-facts { margin: 0; padding: .7rem 1rem 0; font-size: 13px; color: var(--muted); }
.branch-facts b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.branch-case { width: 22rem; }
.branch-figure { margin: 0 1rem 1rem; }
.branch-sweep { display: block; width: 100%; max-width: 36rem; height: auto; margin: 0 auto; background: var(--panel); border-radius: 4px; }
.branch-axis { stroke: var(--rule); stroke-width: 1; }
.branch-line { fill: none; stroke-width: 1.6; }
.branch-line.with, .branch-dot.with { stroke: var(--warn); fill: var(--warn); }
.branch-line.without, .branch-dot.without { stroke: var(--accent); fill: var(--accent); }
.branch-line.with, .branch-line.without { fill: none; }
.branch-label { font: 10px var(--chrome); fill: var(--faint); }
.branch-label.end { text-anchor: end; }
.branch-figure figcaption { font-size: 11.5px; color: var(--faint); margin-top: .35rem; text-align: center; }
.branch-figure figcaption b { color: var(--ink); font-weight: 600; }
.branch-key { font-weight: 600; }
.branch-key.with { color: var(--warn); }
.branch-key.without { color: var(--accent); }

/* Edit and run: a quoted listing turned into an editor, with the result of running it below. */
.edit-open { flex: none; align-self: center; margin: -.15rem 0; font: 12px/1 var(--chrome); color: var(--accent);
             background: var(--bg); border: 1px solid var(--accent); border-radius: 5px; padding: .3rem .5rem;
             cursor: pointer; }
.edit-open:hover { background: var(--wash); }
figure.quoted textarea.code-area { display: block; box-sizing: border-box; width: 100%; margin: 0; resize: vertical;
                                   padding: .8rem 1rem; font: 13px/1.5 var(--mono); color: var(--ink);
                                   background: var(--code); border: 1px solid var(--edge); border-top: 0;
                                   tab-size: 4; white-space: pre; overflow-x: auto; }
figure.quoted textarea.code-area:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.edit-bar { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center; padding: .5rem 0 0; font: 13px var(--chrome); }
.edit-bar button { font: 13px var(--chrome); color: var(--ink); background: var(--bg); border: 1px solid var(--rule);
                   border-radius: 4px; padding: .25rem .6rem; cursor: pointer; }
.edit-bar button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.edit-bar .lab-run { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.run-result { margin: .8rem 0 1.6rem; }
/* Nothing run yet, nothing to show: no empty box below the editor. */
.run-result:has(> .lab-status:empty) { display: none; }
.run-result > .lab-status { padding: .6rem 1rem; margin: 0; border-bottom: 1px solid var(--edge); }
.run-result > .lab-body:empty { display: none; }
.edit-tests { margin: .6rem 0; padding: 0 1rem 0 2.2rem; font-size: 13px; }
.edit-tests li { margin: .15rem 0; }
/* What a script printed, shown as a notebook shows a cell's output. */
.run-result pre.cell-output { margin: 0; padding: .7rem 1rem; font: 12.5px/1.45 var(--mono);
  white-space: pre; overflow-x: auto; background: none; border: 0; }
.run-result .cell-error { margin: 0 1rem .8rem; font: 13px/1.4 var(--mono); }
.edit-tests li.passed code { color: var(--go); }
.edit-tests li.failed code { color: var(--stop); }

/* The measure panel (from ch07): the book's general predict-then-reveal panel. */
.measure-facts { margin: 0; padding: .7rem 1rem 0; font-size: 13px; color: var(--muted); }
.measure-case { width: 22rem; }
.measure-detail { display: block; margin: .15rem 0 .45rem; font-size: 12px; color: var(--muted); white-space: pre-wrap; }
.measure-figure { margin: 0 1rem 1rem; }
.measure-chart { display: block; width: 100%; max-width: 36rem; height: auto; margin: 0 auto; background: var(--panel); border-radius: 4px; }
.measure-axis { stroke: var(--rule); stroke-width: 1; }
.measure-line { fill: none; stroke-width: 1.6; }
.measure-line.s0, .measure-dot.s0 { stroke: var(--warn); }
.measure-dot.s0 { fill: var(--warn); }
.measure-line.s1, .measure-dot.s1 { stroke: var(--accent); }
.measure-dot.s1 { fill: var(--accent); }
.measure-line.s2, .measure-dot.s2 { stroke: var(--go); }
.measure-dot.s2 { fill: var(--go); }
.measure-line.s3, .measure-dot.s3 { stroke: var(--stop); }
.measure-dot.s3 { fill: var(--stop); }
.measure-label { font: 10px var(--chrome); fill: var(--faint); }
.measure-label.end { text-anchor: end; }
.measure-figure figcaption { font-size: 11.5px; color: var(--faint); margin-top: .35rem; text-align: center; }
.measure-figure figcaption b { color: var(--ink); font-weight: 600; }
.measure-key { font-weight: 600; }
.measure-key.s0 { color: var(--warn); }
.measure-key.s1 { color: var(--accent); }
.measure-key.s2 { color: var(--go); }
.measure-key.s3 { color: var(--stop); }

/* A figure or panel computed for the book's query, while the reader's edit of it ran last. */
.stale-note { margin: 0 0 .4rem; padding: .35rem .7rem; font: 12.5px/1.4 var(--chrome); color: var(--ink);
              background: var(--wash); border-left: 3px solid var(--warn); border-radius: 0 4px 4px 0; }
.lab > .stale-note { margin: 0; border-radius: 0; }
[data-stale="true"] > :not(.stale-note) { opacity: .6; }

/* A long listing shows its first lines and a button for the rest; editing it shows all of it. */
figure.quoted[data-folded="true"] > pre {
  max-height: calc(30 * 1.5em + 1.6rem); overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 80%, transparent);
  mask-image: linear-gradient(to bottom, #000 80%, transparent); }
.fold-toggle { display: block; margin: .3rem 0 0 auto; font: 12px/1 var(--chrome); color: var(--accent);
               background: var(--bg); border: 1px solid var(--edge); border-radius: 5px; padding: .3rem .6rem;
               cursor: pointer; }
.fold-toggle:hover { border-color: var(--accent); }
figure.quoted[data-editing="true"] > .fold-toggle { display: none; }

/* An editor in colour: the colours drawn in a layer behind a textarea whose own text is
   transparent, laid out alike (web/lab/highlight.js copies the textarea's font and padding). */
.code-edit { position: relative; background: var(--code); }
.code-edit > pre.code-layer { position: absolute; inset: 0; margin: 0; box-sizing: border-box; overflow: hidden;
                              white-space: pre; pointer-events: none; color: var(--ink); background: none;
                              border-radius: 0; }
/* Important, as each editor's own rule sets its text's colour and background more specifically. */
.code-edit > textarea { position: relative; background: transparent !important; color: transparent !important;
                        caret-color: var(--ink); }
.code-edit > textarea::selection { color: transparent; background: color-mix(in srgb, var(--accent) 25%, transparent); }

/* A timed block: the cases, each with a bar of its time on one scale, the slowest the full width.
   Nothing is drawn as a time until the reader times it: the page holds no times. */
.timed-cases { list-style: none; margin: 0; padding: .4rem 1rem .8rem; display: grid; gap: .8rem; }
.timed-case { display: grid; gap: .25rem; }
.timed-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .2rem 1rem; }
.timed-label { font-weight: 600; }
.timed-value { color: var(--muted); font-variant-numeric: tabular-nums; }
.timed-case.timing .timed-value { color: var(--accent); }
.timed-detail { display: block; color: var(--muted); overflow-wrap: anywhere; }
.timed-track { display: block; height: .55rem; background: var(--panel); border-radius: 3px; overflow: hidden; }
.timed-fill { display: block; height: 100%; width: 0; border-radius: 3px; background: var(--accent); transition: width .3s; }
.timed-track.share { height: .45rem; }
.timed-track.share .timed-fill { background: var(--warn); }
.timed-profile { margin-top: .3rem; display: grid; gap: .15rem; font-size: 12.5px; }
.timed-profile-head { color: var(--faint); }
.timed-op { display: grid; grid-template-columns: minmax(7rem, 12rem) 1fr 3rem; gap: .5rem; align-items: center; }
.timed-op-name { font-family: var(--mono); font-size: 12px; }
.timed-op-share { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.timed-caveat { margin: 0; padding: .5rem 1rem .7rem; font-size: 12.5px; color: var(--faint); background: var(--panel); }
