.workbench:has(> .note-reader) {
  --reading-height: max(410px, calc(100dvh - var(--header-h) - 44px));
  display: grid;
  grid-template-columns: minmax(160px, 21%) minmax(0, 1fr);
  gap: clamp(18px, 3vw, 42px);
  align-items: start;
  padding-block: 22px;
}
.workbench:has(> .note-reader) > :not(.task-header, .note-reader) { display: none; }
.workbench:has(> .note-reader) > .task-header {
  position: sticky;
  top: calc(var(--header-h) + 22px);
  display: block;
  max-height: var(--reading-height);
  margin: 0;
  padding: 7px var(--task-header-inline, 0px) 14px;
  border: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}
.workbench:has(> .note-reader) .task-progress-block {
  border: 0;
  padding-top: 0;
}
.note-reader {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-width: 0;
  height: var(--reading-height);
  container: note-reader / inline-size;
}
.note-reader [hidden] { display: none !important; }

.note-reader-bar {
  grid-row: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}
.note-reader-context, .note-reader-controls, .note-reader-tools {
  display: flex;
  align-items: center;
  min-width: 0;
}
.note-reader-context { gap: 9px; }
.note-reader-controls { gap: 7px; }
.note-reader-tools { gap: 1px; }
.note-reader .note-back, .note-reader .note-details-toggle {
  flex: none;
  gap: 6px;
  min-height: 34px;
  padding: 4px 8px;
  border-radius: 7px;
  color: var(--ink);
  font-size: 13px;
  white-space: nowrap;
}
.note-reader .note-back:hover, .note-reader .note-details-toggle:hover { background: var(--hover); }
.note-reader .note-details-toggle[aria-expanded="true"] { color: var(--accent-text); background: var(--accent-wash); }
.note-header-title {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-reader .note-tool {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 7px;
}
.note-tool[aria-expanded="true"] { color: var(--accent-text); background: var(--accent-wash); }
.note-mode-switch {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 8px;
  background: var(--hover);
}
.note-mode-switch button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 47px;
  min-height: 30px;
  padding: 4px 7px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 680;
  white-space: nowrap;
}
.note-mode-switch button:hover { color: var(--ink); }
.note-mode-switch button[aria-pressed="true"] {
  color: var(--accent-text);
  background: var(--accent-wash);
}

.note-reader-find {
  grid-row: 2;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 6px;
  color: var(--muted);
}
.note-reader-find input {
  min-width: 0;
  width: min(255px, 45vw);
  min-height: 34px;
  padding: 5px 9px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13px;
}
.note-match-count { min-width: 42px; font-size: 12px; font-variant-numeric: tabular-nums; }
[data-reader-action="find-prev"] svg { transform: rotate(180deg); }
.note-search-hit { border-radius: 3px; background: var(--warning-wash); color: var(--ink); }
.note-search-hit.current { background: var(--accent-wash); outline: 1px solid var(--accent-text); color: var(--accent-text); }

.note-reader-body {
  --note-details-width: clamp(222px, 28cqw, 280px);
  grid-row: 3;
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}
.note-reader-scroll, .note-reader-panel {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--strong-line) transparent;
}
.note-reader-scroll { overflow: hidden; }
.note-editor-frame { display: block; width: 100%; height: 100%; border: 0; }
.note-reader-scroll.links-media { width: 100%; overflow: auto; }
.links-media [data-links-file-preview] { height: 100%; color: var(--muted); }
.links-media [data-links-file-preview]:has(.links-image) { display: flex; }
.links-image { display: block; flex: none; max-width: 100%; max-height: 100%; object-fit: contain; margin: auto; }
.links-image-actual .links-image { max-width: none; max-height: none; }
.links-pdf { display: block; width: 100%; height: 100%; border: 1px solid var(--line); border-radius: 6px; }
.links-media-controls { flex-wrap: wrap; }
.links-media-controls .text-button { min-height: 34px; padding-inline: 6px; }
.links-reader-source { overflow-wrap: anywhere; color: var(--muted); font-size: 13px; }
.note-reader-panel {
  position: absolute;
  z-index: 2;
  inset: 8px 0 auto auto;
  width: min(var(--note-details-width), 100%);
  max-height: calc(100% - 14px);
  padding: 15px 16px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 10px 34px color-mix(in srgb, var(--ink) 11%, transparent);
}
.note-details-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.note-details-heading h2 { font-size: 15px; font-weight: 740; }
.note-details-heading .text-button { min-height: 28px; padding-inline: 4px; font-size: 12px; }
.note-source-label {
  flex: none;
  display: inline-block;
  margin-inline-start: 2px;
  padding: 2px 5px;
  border-radius: 5px;
  color: var(--accent-text);
  background: var(--accent-wash);
  font-size: 10px;
  line-height: 1.4;
  font-weight: 750;
}
.note-info-section { margin-top: 16px; }
.note-info-section h3 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  font-weight: 720;
}
.note-sidebar-count { color: var(--muted); opacity: .72; font-variant-numeric: tabular-nums; }
.note-sidebar-empty { color: var(--muted); font-size: 12px; line-height: 1.55; }
.note-update-section + .note-update-section { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.note-update-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.note-update-heading h3 { display: flex; align-items: center; gap: 6px; margin: 0; }
.note-update-heading h3 svg { color: var(--accent-text); }
.note-update-check { min-height: 30px; padding: 3px 8px; font-size: 12px; }
.note-update-list { display: grid; gap: 8px; padding: 0; margin: 0; list-style: none; }
.note-update-list li { padding: 11px 12px; border: 1px solid var(--line); border-radius: 8px; }
.note-update-list h4 { margin: 0; color: var(--ink); font-size: 15px; font-weight: 720; overflow-wrap: anywhere; }
.note-update-list p { margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.note-update-source { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 10px; margin-top: 7px; }
.note-update-source small { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.note-update-source :is(a, button) { display: inline-flex; align-items: center; gap: 4px; min-height: 26px; color: var(--accent-text); font-size: 12px; font-weight: 650; }
.note-update-section :is(.note-update-muted, .note-update-status) { color: var(--muted); font-size: 12px; }
.note-update-status { margin-top: 8px; }
.note-update-status:empty { display: none; }
.note-update-search { margin-top: 10px; color: var(--muted); font-size: 12px; }
.note-update-search summary { width: fit-content; cursor: pointer; }
.note-update-search form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.note-update-search input {
  flex: 1 1 160px; min-width: 0; min-height: 34px; padding: 5px 8px; border: 1px solid var(--line);
  border-radius: 7px; background: var(--surface); color: var(--ink); font: inherit;
}
.note-update-search .button { min-height: 34px; padding: 5px 8px; font-size: 12px; }

.note-detail-relations > section {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 8px;
}
.note-detail-relations h3 { margin: 0; font-weight: 600; }
.note-detail-relations .note-sidebar-empty { padding: 4px 4px 4px 0; text-align: end; }
.note-detail-relations .note-side-row { min-height: 24px; padding: 2px 4px; text-align: end; }
.note-detail-relations .note-side-row span { color: var(--ink); }

.note-outline { display: grid; gap: 2px; }
.note-outline-link, .note-side-row {
  min-width: 0;
  min-height: 29px;
  width: 100%;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: start;
}
.note-outline-link {
  --heading-depth: 0;
  padding: 5px 7px 5px calc(7px + var(--heading-depth) * 12px);
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-outline-start { color: var(--ink); font-weight: 670; }
.note-outline-link:hover, .note-side-row:hover { color: var(--ink); background: var(--hover); }
.note-outline-link[aria-current] { color: var(--accent-text); background: var(--accent-wash); font-weight: 680; }
.note-side-row { display: flex; align-items: center; gap: 8px; padding: 5px 7px; }
.note-side-row span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.note-side-row svg { flex: none; }
.note-add-link { color: var(--accent-text); margin-top: 6px; padding-inline: 0; }
.note-sidebar-meta, .note-sidebar-meta dd, .note-syntax-list, .note-syntax-list dd { margin: 0; }
.note-sidebar-meta > div, .note-syntax-list > div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.note-sidebar-meta > div + div, .note-syntax-list > div + div { margin-top: 7px; }
.note-sidebar-meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.note-sidebar-meta dd { color: var(--ink); text-align: end; }
.note-syntax-list { padding-block: 4px 9px; font-size: 13px; }
.note-syntax-list code { padding: 3px 5px; border-radius: 4px; background: var(--hover); overflow-wrap: anywhere; }

.note-reader-footer {
  grid-row: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px 12px;
  min-height: 40px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
}
.note-reader-meta, .note-reader-state, .note-reader-confirm { display: flex; align-items: center; gap: 10px; }
.note-reader-meta { font-variant-numeric: tabular-nums; }
.note-reader-state, .note-reader-confirm { margin-inline-start: auto; }
.note-reader-state .button, .note-reader-confirm .button { min-height: 31px; }
.note-reader-message { display: inline-flex; align-items: center; gap: 4px; color: var(--positive); }
.note-reader-message[data-state="draft"] { color: var(--muted); }
.note-reader-message[data-state="error"], .note-discard { color: var(--negative); }

.note-heading-button {
  display: inline;
  max-width: 100%;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
.note-heading-button:hover { color: var(--accent-text); text-decoration: underline; text-underline-offset: .22em; }

@container note-reader (min-width: 660px) {
  .note-reader-scroll {
    width: min(760px, calc(100% - var(--note-details-width) - 22px));
  }
}
@container note-reader (max-width: 460px) {
  .note-reader-bar { grid-template-columns: minmax(0, 1fr); gap: 4px; padding-bottom: 3px; }
  .note-reader-controls { justify-content: space-between; gap: 5px; }
  .note-mode-switch button { min-width: 42px; }
  .note-reader .note-tool { width: 28px; }
  .note-reader-find { gap: 4px; padding-inline: 0; }
  .note-reader-find input { width: auto; flex: 1; }
}
@media (max-width: 760px) {
  .workbench:has(> .note-reader) {
    --reading-height: max(400px, calc(100dvh - var(--header-h) - 24px));
    grid-template-columns: minmax(0, 1fr);
    padding-block: 12px;
  }
  .workbench:has(> .note-reader) > .task-header {
    position: static;
    order: 1;
    max-height: none;
  }
}
