/* Python code blocks (js/python-block.js). The header lies in the block's top padding and the
 * editor textarea over the code, so the block keeps one height whether its UI is built or not.
 * On paper the code and the output keep the screen's height limits: the page layout was made
 * with them. */
.py-block {
  position: relative;
  box-sizing: border-box;
  padding: 30px 0 0;
  border: 1px solid #d7dde5;
  border-radius: 6px;
  background: #fff;
  color: #1f2328;
  font-size: 14px;
  line-height: 1.6;
  text-align: left;
  text-indent: 0;
  overflow: hidden;
  break-inside: avoid;
}
.py-block.py-focus { border-color: #5b8fd6; box-shadow: 0 0 0 2px rgba(91, 143, 214, .18); }
.py-block.dyn-flash { box-shadow: 0 0 0 3px rgba(91, 143, 214, .35); }

/* ---- header (runtime UI) ---- */
.py-block > .py-head {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 30px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px 0 8px;
  border-bottom: 1px solid #e6eaef;
  background: #f6f8fa;
  color: #57606a;
  font: 12px/1 "Segoe UI", system-ui, sans-serif;
  white-space: nowrap;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
}
.py-head .py-tag { display: inline-flex; align-items: center; gap: 4px; flex: none; color: #3572a5; font-weight: 600; }
.py-head .py-tag svg { width: 15px; height: 15px; }
.py-head .py-tag::after { content: "Python"; }
.py-head .py-meta { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.py-head .py-meta::before { content: attr(data-text); }
.py-head .py-meta.py-meta-hint { color: #9a6700; }
.py-head .py-actions { display: inline-flex; align-items: center; gap: 4px; flex: none; margin-left: auto; }
.py-head button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #24292f;
  font: inherit;
  cursor: pointer;
}
.py-head button[hidden] { display: none; }
.py-head button svg { width: 14px; height: 14px; flex: none; }
.py-head button:hover:not(:disabled) { background: #e8ecf0; }
.py-head button:disabled { opacity: .45; cursor: default; }
.py-head button:focus-visible { outline: 2px solid #5b8fd6; outline-offset: 1px; }
.py-head .py-run::after,
.py-head .py-show-code::after,
.py-head .py-settings::after { content: attr(data-label); }
.py-head .py-settings { border-color: #d0d7de; background: #fff; }
.py-head .py-run { background: #1f883d; color: #fff; }
.py-head .py-run:hover:not(:disabled) { background: #1a7f37; }
.py-head .py-run:disabled { background: #8c959f; opacity: .55; }
.py-head .py-run.py-stop { background: #cf222e; }
.py-head .py-run.py-stop:hover { background: #a40e26; }
.py-head .py-more { padding: 0 4px; }

/* ---- code ---- */
.py-block > pre.py-code,
.page-content .py-block > pre.py-code {
  position: relative;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #f6f8fa;
  font: 13px/1.55 Consolas, "Cascadia Mono", "Courier New", monospace;
  white-space: pre-wrap;
  max-height: calc(var(--py-content-h, 930px) * .45);
  overflow: auto;
}
.page-content .py-block > pre.py-code::after,
.tbox-content .py-block > pre.py-code::after { content: none; }
.py-block > pre.py-code > code {
  display: block;
  box-sizing: border-box;
  padding: 8px 12px;
  font: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 4;
  color: #1f2328;
}
.py-block > pre.py-code > code::after { content: "\200B"; }
.py-block > pre.py-code > textarea.py-editor {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  outline: none;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: #1f2328;
  font: inherit;
  letter-spacing: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 4;
  -webkit-user-select: text;
  user-select: text;
  cursor: text;
}
.py-block > pre.py-code > textarea.py-editor[readonly] { cursor: default; }
.py-block[data-py-hide-code="1"] > pre.py-code { display: none; }
.py-code .py-k { color: #cf222e; }
.py-code .py-s { color: #0a3069; }
.py-code .py-c { color: #6e7781; }
.py-code .py-n { color: #0550ae; }
.py-code .py-b { color: #8250df; }
.py-code .py-d { color: #953800; }
.py-code .py-f { color: #6639ba; }

/* ---- output ---- */
.py-block > .py-output {
  box-sizing: border-box;
  padding: 8px 12px;
  border-top: 1px solid #e6eaef;
  max-height: calc(var(--py-content-h, 930px) * .45);
  overflow: auto;
  font-size: 14px;
  line-height: 1.6;
}
.py-block[data-py-hide-code="1"] > .py-output { border-top: 0; }
.py-block > .py-output:empty { display: none; }
.py-output > *, .py-output .py-result > * { margin: 0 0 .5em; }
.py-output > :last-child, .py-output .py-result > :last-child { margin-bottom: 0; }
.page-content .py-output pre,
.py-output pre {
  margin: 0 0 .5em;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  font: 12.5px/1.5 Consolas, "Cascadia Mono", "Courier New", monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.page-content .py-output pre::after { content: none; }
.py-output .py-stderr { color: #9a6700; }
.py-output table { border-collapse: collapse; font-size: 13px; }
.py-output td, .py-output th { border: 1px solid #d0d7de; padding: 3px 8px; vertical-align: top; }
.py-output th { background: #f6f8fa; font-weight: 600; }
.py-output .py-image img { display: block; max-width: 100%; height: auto; }
.py-output .py-note { color: #6e7781; font-size: 12px; }
.py-output .py-note-error { color: #cf222e; font-size: 13px; }
.py-output details.py-error { border: 1px solid #ffcecb; border-radius: 5px; background: #fff8f7; }
.py-output details.py-error > summary { padding: 5px 8px; color: #cf222e; font-weight: 600; cursor: pointer; }
.py-output details.py-error > pre { padding: 0 8px 8px; color: #82071e; }

/* The web layout and the exported flow view have no page to fit. */
body.flow-mode .py-block > pre.py-code,
body.flow-mode .py-block > .py-output,
#udoc-flow .py-block > pre.py-code,
#udoc-flow .py-block > .py-output { max-height: none; }

/* Reading view: what the block shows, without its commands. */
body[data-document-view="reading"] .py-head .py-actions { display: none; }

/* Exported pages and paper: code (unless hidden) and output only. */
body.udoc-export .py-block { padding-top: 0; }
@media print {
  .py-block { padding-top: 0 !important; box-shadow: none !important; border-color: #d7dde5 !important; }
  .py-block > .py-head,
  .py-block textarea.py-editor,
  .py-block [data-py-screen] { display: none !important; }
}

/* ---- block menu ---- */
.py-menu {
  position: fixed;
  z-index: 100000;
  min-width: 220px;
  padding: 4px;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(31, 35, 40, .16);
  color: #1f2328;
  font: 13px/1.4 "Segoe UI", system-ui, sans-serif;
}
.py-menu-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 10px 6px 4px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.py-menu-item:hover:not(:disabled),
.py-menu-item:focus-visible { background: #f0f3f6; outline: none; }
.py-menu-item:disabled { color: #8c959f; cursor: default; }
.py-menu-check { flex: none; width: 16px; color: #0969da; text-align: center; }
.py-menu-label { flex: 1 1 auto; }
.py-menu-detail { margin-left: 12px; color: #6e7781; font-size: 12px; }
.py-menu-heading { padding: 6px 10px 2px 26px; color: #6e7781; font-size: 12px; }
.py-menu-sep { height: 1px; margin: 4px 6px; background: #e6eaef; }
