/* =========================================================
   Notebook: the table and diagram blocks on the page, the blocks
   button in the top bar, and the line where a dragged block will land.
   (The palette itself is palette.css; the diagram editor diagram.css.
   Both load the first time they open.)
   ========================================================= */

/* ── Table block ─────────────────────────────────────── */
.nb-block.table { margin: 10px 0; }
.nb-table { flex: 1; min-width: 0; }
/* Wide tables scroll inside the block, never the page (position: relative
   keeps anything positioned inside, like KaTeX, from escaping the clip). */
.nb-table-scroll {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  scrollbar-width: thin;
  overscroll-behavior-x: contain;
}
/* The table fills the line and its words wrap; it scrolls sideways only
   when its columns cannot shrink further. */
.nb-table-grid {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 0.92rem;
}
.nb-table-grid th,
.nb-table-grid td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  min-width: 7.5em;
  max-width: 24em;
  vertical-align: top;
  text-align: left;
  line-height: 1.55;
  color: var(--text);
  outline: none;
  overflow-wrap: anywhere;
}
.nb-table-grid tr > :last-child { border-right: none; }
.nb-table-grid tr:last-child > * { border-bottom: none; }
.nb-table-grid th {
  font-family: var(--font-heading);
  font-weight: 600;
  background: color-mix(in srgb, var(--purple) 8%, var(--bg-elevated));
}
.nb-table-cell { cursor: text; transition: background-color 120ms; }
.nb-table-cell:focus {
  background: color-mix(in srgb, var(--purple) 6%, transparent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--purple) 55%, transparent);
}
.nb-table-cell:empty::before {
  content: attr(data-ph);
  color: var(--text-muted);
  pointer-events: none;
}
th.nb-table-cell:empty::before { font-weight: 500; }
.nb-table-bar {
  position: relative;
  display: flex;
  gap: 4px;
  margin-top: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  opacity: 0;
  transition: opacity 150ms;
}
.nb-table-bar::-webkit-scrollbar { display: none; }
.nb-block.table:hover .nb-table-bar,
.nb-table.is-on .nb-table-bar,
.nb-table:focus-within .nb-table-bar { opacity: 1; }
.nb-table-bar button {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font: 500 0.76rem/1 var(--font-heading);
  white-space: nowrap;
  cursor: pointer;
}
.nb-table-bar button svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nb-table-bar button:hover:not(:disabled) { color: var(--text); border-color: var(--border-hover); background: var(--bg-elevated); }
.nb-table-bar button.on { color: var(--text); border-color: color-mix(in srgb, var(--purple) 50%, var(--border)); background: color-mix(in srgb, var(--purple) 10%, transparent); }
.nb-table-bar button:disabled { opacity: 0.4; cursor: default; }
.nb-table-bar button:focus-visible { outline: 2px solid var(--purple); outline-offset: 1px; }
/* Phones: the bar shows while you are in the table, with thumb-sized buttons. */
@media (pointer: coarse) {
  .nb-table-bar { display: none; opacity: 1; }
  .nb-table.is-on .nb-table-bar, .nb-table:focus-within .nb-table-bar { display: flex; }
  .nb-table-bar button { height: 44px; padding: 0 12px; font-size: 0.82rem; }
  .nb-table-grid th, .nb-table-grid td { font-size: max(16px, 0.92rem); padding: 10px 12px; }
}

/* ── Diagram block ───────────────────────────────────── */
.nb-block.diagram { margin: 12px 0; }
.nb-diagram {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 150ms, box-shadow 150ms;
}
.nb-diagram-view {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 14px 10px 10px;
  scrollbar-width: thin;
  overscroll-behavior-x: contain;
}
.nb-diagram-view svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.nb-diagram-view.is-wide:not(.at-end) { -webkit-mask-image: linear-gradient(90deg, #000 84%, transparent); mask-image: linear-gradient(90deg, #000 84%, transparent); }
.nb-diagram-view.is-wide.at-end:not(.at-start) { -webkit-mask-image: linear-gradient(270deg, #000 84%, transparent); mask-image: linear-gradient(270deg, #000 84%, transparent); }
.nb-diagram-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 6px 14px;
  border-top: 1px solid var(--border);
}
.nb-diagram-count { font: 400 0.72rem/1.2 var(--font-mono); color: var(--text-muted); }
.nb-diagram-edit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font: 600 0.78rem/1 var(--font-heading);
  cursor: pointer;
  transition: var(--nb-easing);
}
.nb-diagram-edit svg { width: 14px; height: 14px; }
.nb-diagram-edit:hover, .nb-diagram-edit:focus-visible { color: var(--text); border-color: var(--purple); background: color-mix(in srgb, var(--purple) 8%, transparent); outline: none; }
.nb-diagram-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 26px 16px 22px;
  background-image: radial-gradient(color-mix(in srgb, var(--text-muted) 40%, transparent) 1px, transparent 1.3px);
  background-size: 20px 20px;
}
.nb-diagram-empty-ic { display: inline-flex; width: 44px; height: 44px; align-items: center; justify-content: center; border-radius: 12px; background: var(--bg-elevated); border: 1px solid var(--border); color: var(--purple); }
.nb-diagram-empty-ic svg { width: 24px; height: 24px; }
.nb-diagram-empty p { margin: 0; color: var(--text-dim); font-size: 0.88rem; line-height: 1.5; max-width: 32ch; }
.nb-diagram-acts { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.nb-diagram-acts .nb-btn-ghost { padding: 8px 14px; background: var(--bg); }
@media (pointer: coarse) {
  .nb-diagram-edit { height: 44px; padding: 0 16px; }
  .nb-diagram-acts .nb-btn-ghost { min-height: 44px; }
}
/* A shape held over a diagram: it will join it. */
.nb-block.diagram.nb-drop-into .nb-diagram {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--purple) 22%, transparent);
}

/* In embeds and the review: the same table and picture, read-only. */
.nb-static-table .nb-table-grid th, .nb-static-table .nb-table-grid td { cursor: default; }
.nb-static-diagram .nb-diagram-view { border: 1px solid var(--border); border-radius: 12px; }

/* ── The blocks button and where a dragged block lands ── */
.nb-blocks-btn[aria-pressed="true"] { color: var(--purple); background: color-mix(in srgb, var(--purple) 10%, transparent); }
.nb-chapter { position: relative; }
.nb-drop-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  pointer-events: none;
  z-index: 6;
}
.nb-drop-line::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -1.5px;
  height: 3px;
  border-radius: 3px;
  background: var(--purple);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--purple) 18%, transparent);
}
.nb-drop-line::after {
  content: '';
  position: absolute;
  left: -5px;
  top: -5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--purple);
}
/* The name of what will land, in the margin to the left of the line. */
.nb-drop-line span {
  position: absolute;
  right: calc(100% + 12px);
  top: -10px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--purple);
  color: #fff;
  font: 600 0.72rem/1.3 var(--font-heading);
  white-space: nowrap;
}
[data-theme="light"] .nb-drop-line span { color: #fff; }
/* A callout block also matches the site's article .callout rule (style.css),
   which drew a second, padded border around it. The block's own box is the
   inner one. */
.nb-block.callout { border: 0; border-radius: 0; padding: 3px 0; font-size: inherit; line-height: inherit; }

/* The ＋ sheet's way into the palette */
.nb-sheet-more .nb-sheet-ic { color: var(--purple); }
@media print { .nb-table-bar, .nb-diagram-bar, .nb-drop-line { display: none !important; } }
