/* PDF editor — chat entry points and look & feel (js/custom/melp-pdf-chat.js).
   Kept in its own file so the chat stylesheets stay untouched: the whole feature is removed by
   deleting this file, the script and the melp.php hooks. */

/* ── Entry points ─────────────────────────────────────────────────────────── */

/* "Edit" on a PDF's file card. It is the app's Button component (secondary, small), so look, focus,
   tooltip, dark mode and its loading state all come from the design system; this only places it.
   The card is a flex row — icon, name and size — and the button takes the trailing edge, which keeps
   it apart from the "Summarize" link and the time in the row below. */
.files > .file-edit-pdf-btn {
  flex: none;
  margin: 0 0 0 auto;
}

/* Shown when the message is hovered or holds keyboard focus (opacity, not display, so the bubble
   keeps its width and nothing shifts), while it is loading, and while the "new" card points at it.
   Touch screens have no hover, so there it is always shown. */
@media (hover: hover) {
  .msgCell .files > .file-edit-pdf-btn:not([aria-busy="true"], .file-edit-pdf-btn--intro) {
    opacity: 0;
  }

  .msgCell:hover .files > .file-edit-pdf-btn,
  .msgCell:focus-within .files > .file-edit-pdf-btn {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .files > .file-edit-pdf-btn {
    transition: opacity var(--transition-fast);
  }
}

.files:has(> .file-edit-pdf-btn) .files-content {
  margin-right: var(--space-md);
}

.dashboard-file-edit-pdf {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 0.6rem;
  height: 3.2rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 1.2rem;
  background: var(--color-surface);
  color: var(--color-text-primary);
  font: inherit;
  font-size: var(--font-size-13);
  white-space: nowrap;
  cursor: pointer;
}

@media (hover: hover) {
  .recent-activity_msg-list:not(:hover, :focus-within) .dashboard-file-edit-pdf {
    opacity: 0;
  }
}

.dashboard-file-edit-pdf img {
  width: 1.6rem;
  height: 1.6rem;
}

.dashboard-file-edit-pdf:hover {
  background: var(--color-surface-hover, var(--color-background));
}

.dashboard-file-edit-pdf:focus-visible {
  outline: 0.2rem solid var(--color-focus-ring);
  outline-offset: 0.2rem;
}

/* Gallery header action (#previewEditPdfFile). The sizing comes from the shared
   `.previewDowlaodColum .previewDownloadFile img` rule and the cursor from main.css's per-id rule
   for its siblings, which this id is not in; so this adds the cursor, the keyboard focus ring and
   the in-flight state while the editor loads. */
#previewEditPdfFile {
  cursor: pointer;
}

#previewEditPdfFile:focus-visible {
  outline: 0.2rem solid var(--color-focus-ring);
  outline-offset: 0.2rem;
  border-radius: 0.4rem;
}

#previewEditPdfFile[aria-busy="true"] {
  opacity: 0.5;
  cursor: progress;
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  #previewEditPdfFile {
    transition: opacity var(--transition-fast);
  }
}

/* ── The editor dialog, brought in line with Melp's modal and button components ──────────────
   The vendored editor styles itself from its own `--ms-*` variables, which already fall back to
   Melp's `--color-*` tokens (so brand, surfaces, text and dark mode follow the app). What differed
   is corrected here by re-pointing those variables, not by restyling its internals. `body .mlsign`
   outranks the editor's own `.mlsign` rule, which is injected later, on first open. */
body .mlsign {
  /* Melp control radius (4px) rather than the editor's 6px, and the modal component's radius.
     The role aliases exist on newer branches; the fallbacks are today's tokens. */
  --ms-radius-btn: var(--radius-control, var(--radius-sm));
  --ms-radius-lg: var(--radius-panel, var(--radius-md));
  /* Type from the design-system scale, so it follows the app's root size. */
  --ms-fs-11: var(--font-size-11);
  --ms-fs-13: var(--font-size-13);
  --ms-fs-15: var(--font-size-15);
  --ms-fs-17: var(--font-size-17);
  --ms-fs-19: var(--font-size-19);
  /* .mui-modal's shadow: restrained, modals only. */
  --ms-shadow-3: 0 0.4rem 0.8rem rgb(from var(--color-text-primary) r g b / 15%);
}

/* Same dimming as .mui-modal-backdrop: solid 80%, no blur. */
body .mlsign .mlsign__scrim {
  background: rgb(from var(--black) r g b / 80%);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* Title as in .mui-modal__title (17px / 600). The subtitle stays at the editor's 11px: at the
   modal's 13px it no longer fits the header and truncates ("Annotate & sign · client-side …"). */
body .mlsign .mlsign__title {
  font-size: var(--ms-fs-17);
}

/* Footer actions are the canonical .btn: 15px, 6px / 12px padding, an 8rem floor so short labels
   are not cramped chips. (The compact 13px buttons in the header and panel stay compact.) */
body .mlsign .mlsign__foot .mlsign__btn,
body .mlsign .mlsign__confirmactions .mlsign__btn {
  padding: 0.6rem 1.2rem;
  min-width: 8rem;
  line-height: 1.5;
}

/* Keyboard focus uses the app's focus-ring token instead of the editor's blue. */
body .mlsign :focus-visible {
  outline-color: var(--color-focus-ring);
}

/* Badges and chips are 4px-cornered in Melp (.badge), never full pills; the floating
   "place your signature" banner is a card, so it takes the card radius. */
body .mlsign .mlsign__badge,
body .mlsign .mlsign__badgenote,
body .mlsign .mlsign__tedit-loading {
  border-radius: var(--radius-sm);
}

/* A visible signature has been placed but the PDF has not yet been written and cryptographically
   finalized. Give that in-progress state the same compact, neutral treatment as the other badges. */
body .mlsign .mlsign__badge--placed {
  color: var(--ms-text);
  border-color: var(--ms-border);
  background: var(--ms-bg);
}

body .mlsign .mlsign__banner {
  border-radius: var(--radius-md);
}

/* View / Edit is a segmented control: the active segment is raised on the track in the neutral
   surface, as the editor's own Draw / Type / Upload tabs are — not filled with brand red, which
   competed with the one primary action in the footer. The same neutral selection marks the chosen
   tab, signature style and stroke width. */
body .mlsign .mlsign__seg[aria-pressed="true"] {
  color: var(--ms-text);
  background: var(--ms-surface);
  box-shadow: var(--ms-shadow-1);
}

body .mlsign .mlsign__tab[aria-selected="true"] {
  color: var(--ms-text);
}

body .mlsign .mlsign__style[aria-pressed="true"] {
  color: var(--ms-text);
  background: var(--ms-bg);
  border-color: var(--ms-text);
}

body .mlsign .mlsign__width[aria-pressed="true"] {
  border-color: var(--ms-text);
}

body .mlsign .mlsign__width[aria-pressed="true"] span {
  background: var(--ms-text);
}

/* Section labels ("Signature", "Saved signatures", "Comment", "Page 1") in sentence case, as all
   Melp headings are — not shouted in capitals. */
body .mlsign .mlsign__sectitle,
body .mlsign .mlsign__note-jump,
body .mlsign .mlsign__sticky-head {
  text-transform: none;
  letter-spacing: normal;
}

/* The editor sizes every child of the signature pad to fill it, which also stretched the absolutely
   placed "Draw your signature above" hint and the baseline, so the hint sat on the pad's top border. */
body .mlsign .mlsign__pad > .mlsign__padhint,
body .mlsign .mlsign__pad > .mlsign__padline {
  height: auto;
}

/* Ink and annotation swatches carry a hairline ring from the border token, so the near-black ink
   does not disappear on the dark surface. */
body .mlsign .mlsign__swatch {
  box-shadow: inset 0 0 0 0.1rem var(--ms-border);
}

/* The chosen colour is marked by a check inside its swatch: clear on every colour, black included,
   without the extra rings round it (the editor's 2px border vanished on black; a ring read as a
   second circle). */
body .mlsign .mlsign__swatches {
  gap: 0.8rem;
}

body .mlsign .mlsign__swatch {
  position: relative;
}

body .mlsign .mlsign__swatch[aria-pressed="true"] {
  border-color: transparent;
}

/* On the dark surface the black swatch (and black ink) disappeared: give every swatch a light edge. */
:root.dark body .mlsign .mlsign__swatch {
  box-shadow: inset 0 0 0 0.1rem rgb(255 255 255 / 35%);
}

body .mlsign .mlsign__swatch[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  top: 45%;
  left: 50%;
  width: 0.5rem;
  height: 0.9rem;
  border: solid var(--white);
  border-width: 0 0.2rem 0.2rem 0;
  filter: drop-shadow(0 0 0.1rem rgb(0 0 0 / 45%));
  transform: translate(-50%, -50%) rotate(45deg);
}

body .mlsign .mlsign__swatch:focus-visible {
  outline-offset: 0.2rem;
}

/* The tool row wraps onto a second line when the window is narrow, rather than scrolling sideways and
   hiding the controls at its end (alignment, Delete) out of sight. */
body .mlsign .mlsign__toolrow .mlsign__tools {
  flex-wrap: wrap;
  row-gap: 0.4rem;
  overflow-x: visible;
}

/* "Edit text": a run of a single character (a dot, a hyphen) is a few pixels across, and its field was
   as small — 6 x 3 px — so what was being changed or deleted could not be seen. The field gets a
   usable minimum size; the runs show their outline while the mode is on, so small ones can be found. */
body .mlsign .mlsign__tedit-input {
  min-width: 4.8rem;
  min-height: 2.4rem;
}

/* Delete for the open run, beside its field: the size and look of the toolbar's own icon buttons. */
body .mlsign .mlsign__tedit-delete {
  position: absolute;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border: 1px solid var(--ms-border);
  border-radius: var(--ms-radius-btn);
  background: var(--ms-surface);
  box-shadow: var(--ms-shadow-1);
  color: var(--ms-text-2);
  cursor: pointer;
}

body .mlsign .mlsign__tedit-delete:hover:not(:disabled) {
  border-color: var(--color-error);
  color: var(--color-error);
}

body .mlsign .mlsign__tedit-run {
  min-width: 0.8rem;
  min-height: 0.8rem;
  box-shadow: inset 0 0 0 1px rgb(from var(--ms-brand) r g b / 30%);
}

/* "Find text in image": a chip at the top-left of each image while "Edit text" is on, and the lines
   it finds, marked with a dashed outline so they read as "in the picture", not live text. */
body .mlsign .mlsign__tedit-imgchip {
  position: absolute;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 28rem;
  margin: 0.4rem 0 0 0.4rem;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--ms-border);
  border-radius: var(--ms-radius-btn);
  background: var(--ms-surface);
  box-shadow: var(--ms-shadow-1);
  color: var(--ms-text);
  font: inherit;
  font-size: var(--ms-fs-11);
  font-weight: 600;
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
}

body .mlsign .mlsign__tedit-imgchip:hover:not(:disabled) {
  border-color: var(--ms-brand);
  color: var(--ms-brand);
}

body .mlsign .mlsign__tedit-imgchip[aria-busy="true"] {
  cursor: progress;
  opacity: 0.85;
}

body .mlsign .mlsign__tedit-run--image {
  box-shadow: none;
  outline: 1px dashed rgb(from var(--ms-brand) r g b / 70%);
  outline-offset: 1px;
}

/* Text box formatting (font, size, bold, italic, alignment): the header's control size and style. */
body .mlsign .mlsign__textfmt {
  display: flex;
  flex: none;
  align-items: center;
  gap: 0.4rem;
  margin-left: 0.8rem;
}

body .mlsign .mlsign__select {
  box-sizing: border-box;
  height: 3.2rem;
  padding: 0 0.8rem;
  border: 1px solid var(--ms-border);
  border-radius: var(--ms-radius-btn);
  background: var(--ms-surface);
  color: var(--ms-text);
  font: inherit;
  font-size: var(--ms-fs-13);
  cursor: pointer;
}

body .mlsign .mlsign__fmt {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 3.2rem;
  height: 3.2rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--ms-radius-btn);
  background: transparent;
  color: var(--ms-text-2);
  font: inherit;
  font-size: var(--ms-fs-15);
  cursor: pointer;
}

body .mlsign .mlsign__fmt:hover {
  background: var(--ms-surface-alt);
  color: var(--ms-text);
}

body .mlsign .mlsign__fmt[aria-pressed="true"] {
  border-color: var(--ms-border);
  background: var(--ms-bg);
  color: var(--ms-text);
}

body .mlsign .mlsign__fmt--bold {
  font-weight: 700;
}

body .mlsign .mlsign__fmt--italic {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
}

body .mlsign .mlsign__select:focus-visible,
body .mlsign .mlsign__fmt:focus-visible {
  outline: 0.2rem solid var(--color-focus-ring);
  outline-offset: 0.1rem;
}

/* While "Edit text" is on, its layer covers the page so the text runs can be clicked — and it also
   swallowed every press on signatures, text boxes and shapes, which could then not be selected,
   moved or resized. The layer now only takes presses on the runs themselves, and annotations sit
   above it (their own hit areas still take presses; the layer's container does not). */
body .mlsign .mlsign__tedit {
  pointer-events: none;
}

body .mlsign .mlsign__tedit > * {
  pointer-events: auto;
}

/* Placing a signature: a press on a line of text drops the signature there, not opens the text. */
body .mlsign .mlsign__stage[data-placing="true"] .mlsign__tedit > * {
  pointer-events: none;
}

body .mlsign .mlsign__page:has(> .mlsign__tedit) > div:not(.mlsign__tedit) {
  z-index: 61;
  pointer-events: none;
}

body .mlsign .mlsign__page:has(> .mlsign__tedit) > div:not(.mlsign__tedit) > div {
  pointer-events: none !important;
}

body .mlsign .mlsign__zoom-reset {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ms-text-2);
  font: inherit;
  font-size: var(--ms-fs-13);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

body .mlsign .mlsign__zoom-reset:hover {
  color: var(--ms-brand);
}

/* Links already in the PDF (a table of contents spans whole lines) are invisible boxes that took every
   click in Edit mode: a click meant for highlighting, a comment or a shape selected the link instead —
   a surprise box with resize handles — and nothing was created. In Edit mode clicks go through to the
   page; in View mode (no tool row) links still jump to their target. The hook is the link renderer's
   hit area: the first child rect at 0,0 with a transparent fill and no stroke (a drawn rectangle's hit
   area always carries stroke="transparent"); a drift test pins it. */
body .mlsign .mlsign__dialog:has(> .mlsign__toolrow) .mlsign__page svg > rect[x="0"][y="0"][fill="transparent"]:not([stroke]):first-child {
  pointer-events: none !important;
}

/* A new or selected comment opens both a popup on the page and its card in the Comments panel — two
   empty boxes for one note. While the panel is open it is the one place to write; the popup stays for
   reading comments with the panel closed. */
body .mlsign .mlsign__body:has(> .mlsign__side--comments) .mlsign__sticky {
  display: none;
}


/* While a signature is being placed, the panel's hint gets its own line above Clear / Cancel placing;
   squeezed between them it wrapped onto three lines and "Cancel placing" broke in two. */
body .mlsign .mlsign__side div:has(> .mlsign__hint[role="status"]) {
  flex-wrap: wrap;
}

body .mlsign .mlsign__side div > .mlsign__hint[role="status"] {
  flex: 1 0 100%;
  order: -1;
}

body .mlsign .mlsign__side div:has(> .mlsign__hint[role="status"]) > .mlsign__btn {
  white-space: nowrap;
}

/* The popup opens just below its comment icon instead of on top of it, so the icon stays visible
   and a second click on it closes the popup again. */
body .mlsign .mlsign__sticky {
  position: absolute;
  z-index: 100;
  top: calc(100% + 0.6rem);
  left: 0;
  pointer-events: auto;
}

body .mlsign .mlsign__sticky-head {
  position: relative;
  padding-right: 2.8rem;
}

body .mlsign .mlsign__sticky-close {
  position: absolute;
  z-index: 1;
  top: 50%;
  right: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ms-muted);
  cursor: pointer;
  transform: translateY(-50%);
}

body .mlsign .mlsign__sticky-close:hover {
  background: var(--ms-bg);
  color: var(--ms-text);
}

/* Header controls share one size: every button, group, toggle and badge is 3.2rem tall with the
   control radius and the same light border, and icons inside the page / zoom / undo groups are the
   same square. Before, the badge was 30px, the buttons 32px, View / Edit 36px and the groups 38px,
   and the zoom value was set larger than the page value beside it. */
body .mlsign .mlsign__head .mlsign__btn--sm,
body .mlsign .mlsign__head .mlsign__badge,
body .mlsign .mlsign__head .mlsign__segmented,
body .mlsign .mlsign__head .mlsign__pager,
body .mlsign .mlsign__toolrow .mlsign__btn--sm {
  box-sizing: border-box;
  height: 3.2rem;
  border: 1px solid var(--ms-border);
  border-radius: var(--ms-radius-btn);
  box-shadow: none;
}

body .mlsign .mlsign__head .mlsign__btn--sm,
body .mlsign .mlsign__toolrow .mlsign__btn--sm {
  padding: 0 1.2rem;
  font-size: var(--ms-fs-13);
  line-height: 1;
}

body .mlsign .mlsign__head .mlsign__badge {
  padding: 0 1rem;
  font-size: var(--ms-fs-13);
}

body .mlsign .mlsign__head .mlsign__segmented,
body .mlsign .mlsign__head .mlsign__pager {
  align-items: center;
  gap: 0;
  padding: 0.2rem;
  background: var(--ms-bg);
}

body .mlsign .mlsign__head .mlsign__seg {
  height: 100%;
  padding: 0 1.2rem;
  border-radius: var(--radius-xs, 0.2rem);
  font-size: var(--ms-fs-13);
}

body .mlsign .mlsign__head .mlsign__pager .mlsign__iconbtn {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: var(--radius-xs, 0.2rem);
}

body .mlsign .mlsign__head .mlsign__pagelabel {
  min-width: 5.6rem;
  font-size: var(--ms-fs-13);
}

/* The close button is the same 3.2rem square as the rest of the row. */
body .mlsign .mlsign__head > .mlsign__iconbtn {
  width: 3.2rem;
  height: 3.2rem;
}

/* Header: the file name gives way first. With its 140px floor a signed document's wider status
   badge pushed the close button onto a second row even on a 1440px screen. */
body .mlsign .mlsign__titles {
  flex-basis: 10rem;
}

/* Phone: the footer hint used to be crushed beside three buttons and the primary action wrapped
   onto three lines. Hint on its own line, the primary action full width on top, the other two
   sharing the row below. */
@media (max-width: 600px) {
  body .mlsign .mlsign__foot {
    flex-wrap: wrap;
    gap: var(--space-sm);
  }

  body .mlsign .mlsign__status {
    flex: 1 0 100%;
    order: -2;
  }

  body .mlsign .mlsign__foot .mlsign__btn {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
  }

  body .mlsign .mlsign__foot .mlsign__btn--primary {
    order: -1;
    flex: 1 0 100%;
  }

  /* Room for the header rows: the plain "Unsigned" badge and the subtitle go (a signed document's
     ok / warning / bad badge stays), and a narrower page label lets page, zoom and undo share a row. */
  body .mlsign .mlsign__head {
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
  }

  body .mlsign .mlsign__subtitle,
  body .mlsign .mlsign__head > .mlsign__badge:not(.mlsign__badge--ok):not(.mlsign__badge--warn):not(.mlsign__badge--bad) {
    display: none;
  }

  body .mlsign .mlsign__pagelabel {
    min-width: 5rem;
  }
}

/* Where the header cannot fit on one row, the file name and the close button take the first row —
   otherwise close wrapped to the start of a lower row (the third, on a phone) — and the actions and
   page / zoom controls follow below. */
@media (max-width: 1100px) {
  body .mlsign .mlsign__head > * {
    order: 3;
  }

  body .mlsign .mlsign__head > .mlsign__brand,
  body .mlsign .mlsign__head > .mlsign__titles {
    order: 0;
  }

  body .mlsign .mlsign__head > .mlsign__titles {
    flex: 1 1 0;
  }

  body .mlsign .mlsign__head > .mlsign__iconbtn {
    order: 1;
  }

  /* The spacer becomes the line break straight after the close button. */
  body .mlsign .mlsign__head > .mlsign__headspace {
    order: 2;
    flex: 1 0 100%;
    height: 0;
  }
}

/* ── "New: edit PDFs" introduction (js/custom/melp-pdf-chat.js showIntro) ──────────────── */

.pdf-edit-intro {
  --pdf-edit-intro-arrow: 50%;
  position: fixed;
  z-index: var(--z-popover, 1060);
  box-sizing: border-box;
  width: 34rem;
  max-width: calc(100vw - 2.4rem);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: 0 0.8rem 2.4rem var(--shadow-color-strong);
  color: var(--color-text-primary);
  font-size: var(--font-size-13);
}

/* The pointer towards the button: under the card, or above it when the card opens below. */
.pdf-edit-intro::after {
  content: "";
  position: absolute;
  top: 100%;
  left: var(--pdf-edit-intro-arrow);
  width: 1.2rem;
  height: 1.2rem;
  border: solid var(--color-border);
  border-width: 0 1px 1px 0;
  background: var(--color-surface);
  transform: translate(-50%, -50%) rotate(45deg);
}

.pdf-edit-intro--below::after {
  top: 0;
  border-width: 1px 0 0 1px;
}

/* Beside the button: the pointer is on the card's right edge, at the button's height. */
.pdf-edit-intro--left::after {
  top: var(--pdf-edit-intro-arrow);
  left: 100%;
  border-width: 1px 1px 0 0;
}

/* The demo: a miniature editor inset on the app's ground colour, its steps underneath. The card's
   edge stays white all round, so the pointer to the button always matches it. */
.pdf-edit-intro__stage {
  padding: var(--space-sm) var(--space-sm) 0;
}

.pdf-edit-intro__art {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 280 / 150;
  border-radius: var(--radius-md);
  background: var(--color-background);
}

.pdf-edit-intro__window {
  fill: rgb(from var(--color-surface-alt) r g b / 55%);
  stroke: var(--color-border);
  stroke-width: 0.6;
}

.pdf-edit-intro__bar {
  fill: var(--color-surface);
}

.pdf-edit-intro__tool rect {
  fill: transparent;
}

.pdf-edit-intro__tool path {
  fill: none;
  stroke: var(--color-text-secondary);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pdf-edit-intro__page {
  fill: var(--color-surface);
  stroke: var(--color-border);
  stroke-width: 0.6;
}

.pdf-edit-intro__heading {
  fill: var(--color-text-primary);
}

.pdf-edit-intro__line {
  fill: var(--color-border);
}

.pdf-edit-intro__old,
.pdf-edit-intro__new {
  transform-box: fill-box;
  transform-origin: left center;
}

/* Finished frame (also the reduced-motion still): the old line is gone, the new one in place. */
.pdf-edit-intro__old {
  opacity: 0;
}

.pdf-edit-intro__new {
  fill: var(--color-brand);
}

.pdf-edit-intro__select {
  fill: none;
  stroke: var(--color-brand);
  stroke-width: 0.8;
  stroke-dasharray: 2 1.5;
  opacity: 0;
}

.pdf-edit-intro__caret {
  fill: var(--color-text-primary);
  opacity: 0;
}

.pdf-edit-intro__mark {
  fill: rgb(from var(--color-warning) r g b / 30%);
}

.pdf-edit-intro__note {
  transform-box: fill-box;
  transform-origin: left center;
}

.pdf-edit-intro__note > rect:first-child {
  fill: var(--color-surface);
  stroke: var(--color-border);
  stroke-width: 0.6;
}

.pdf-edit-intro__avatar {
  fill: var(--color-info);
}

.pdf-edit-intro__notetext {
  fill: var(--color-text-secondary);
}

.pdf-edit-intro__signline {
  stroke: var(--color-border);
  stroke-width: 0.8;
}

.pdf-edit-intro__sign {
  fill: none;
  stroke: var(--color-text-primary);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pdf-edit-intro__sent > rect:first-child {
  fill: var(--color-success);
}

.pdf-edit-intro__senticon {
  fill: none;
  stroke: var(--color-text-inverse);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pdf-edit-intro__senttext {
  fill: rgb(from var(--color-text-inverse) r g b / 85%);
}

.pdf-edit-intro__cursor {
  opacity: 0;
}

.pdf-edit-intro__cursor path {
  fill: var(--color-text-primary);
  stroke: var(--color-surface);
  stroke-width: 0.8;
  stroke-linejoin: round;
}

/* The three steps the demo walks through, each with a bar that fills while it is shown. */
.pdf-edit-intro__steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  margin: 0;
  padding: var(--space-sm) 0.4rem 0;
  list-style: none;
}

.pdf-edit-intro__step {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 0.4rem;
  row-gap: 0.6rem;
  min-width: 0;
  color: var(--color-text-primary);
  font-size: var(--font-size-11);
  font-weight: var(--font-weight-semibold, 600);
}

.pdf-edit-intro__step svg {
  width: 1.4rem;
  height: 1.4rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pdf-edit-intro__steplabel {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-edit-intro__progress {
  grid-column: 1 / -1;
  height: 0.3rem;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--color-border-light);
}

.pdf-edit-intro__progress > span {
  display: block;
  height: 100%;
  background: var(--color-text-primary);
  transform-origin: left center;
}

.pdf-edit-intro__body {
  padding: var(--space-md);
}

.pdf-edit-intro__badge {
  display: inline-block;
  margin-bottom: var(--space-sm);
  padding: 0.2rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--color-brand-light);
  color: var(--color-brand);
  font-size: var(--font-size-11);
  font-weight: var(--font-weight-semibold, 600);
}

.pdf-edit-intro__title {
  display: block;
  font-size: var(--font-size-17);
  font-weight: var(--font-weight-semibold, 600);
  line-height: 1.3;
}

.pdf-edit-intro__text {
  margin: 0.4rem 0 var(--space-md);
  color: var(--color-text-secondary);
  line-height: 1.5;
}

.pdf-edit-intro__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}

/* The button the card introduces stays visible and gets a soft ring. */
.file-edit-pdf-btn--intro {
  box-shadow: 0 0 0 0.3rem var(--color-brand-light);
}

/* One 9 s loop in three acts with the pointer: a line is retyped, a comment is added, the page is
   signed and the copy goes back to the chat. The tool and the step for each act light up with it.
   Without motion, the finished page is shown and every step bar is full. */
@media (prefers-reduced-motion: no-preference) {
  .pdf-edit-intro {
    animation: pdf-edit-intro-enter 220ms ease-out;
  }

  .pdf-edit-intro--left {
    animation-name: pdf-edit-intro-enter-left;
  }

  .file-edit-pdf-btn--intro {
    animation: pdf-edit-intro-pulse 1.6s ease-out infinite;
  }

  .pdf-edit-intro__cursor { animation: pdf-edit-intro-cursor 9s ease-in-out infinite; }
  .pdf-edit-intro__select { animation: pdf-edit-intro-select 9s infinite; }
  .pdf-edit-intro__old { animation: pdf-edit-intro-old 9s ease-in-out infinite; }
  .pdf-edit-intro__new { animation: pdf-edit-intro-new 9s ease-out infinite; }
  .pdf-edit-intro__caret { animation: pdf-edit-intro-caret 9s steps(1) infinite; }
  .pdf-edit-intro__mark { animation: pdf-edit-intro-mark 9s ease-out infinite; }
  .pdf-edit-intro__note { animation: pdf-edit-intro-note 9s ease-out infinite; }
  .pdf-edit-intro__sign { stroke-dasharray: 120; animation: pdf-edit-intro-sign 9s linear infinite; }
  .pdf-edit-intro__sent { animation: pdf-edit-intro-sent 9s ease-out infinite; }

  .pdf-edit-intro__tool rect { animation: pdf-edit-intro-tool 9s infinite; }
  .pdf-edit-intro__tool path { animation: pdf-edit-intro-toolicon 9s infinite; }
  .pdf-edit-intro__step { animation: pdf-edit-intro-step 9s infinite; }

  .pdf-edit-intro__tool:nth-of-type(2) :is(rect, path),
  .pdf-edit-intro__step:nth-child(2) {
    animation-delay: -6s;
  }

  .pdf-edit-intro__tool:nth-of-type(3) :is(rect, path),
  .pdf-edit-intro__step:nth-child(3) {
    animation-delay: -3s;
  }

  .pdf-edit-intro__step:nth-child(1) .pdf-edit-intro__progress > span { animation: pdf-edit-intro-fill-1 9s linear infinite; }
  .pdf-edit-intro__step:nth-child(2) .pdf-edit-intro__progress > span { animation: pdf-edit-intro-fill-2 9s linear infinite; }
  .pdf-edit-intro__step:nth-child(3) .pdf-edit-intro__progress > span { animation: pdf-edit-intro-fill-3 9s linear infinite; }
}

@keyframes pdf-edit-intro-enter {
  from { opacity: 0; transform: translateY(0.6rem); }
  to { opacity: 1; transform: none; }
}

@keyframes pdf-edit-intro-enter-left {
  from { opacity: 0; transform: translateX(0.6rem); }
  to { opacity: 1; transform: none; }
}

@keyframes pdf-edit-intro-pulse {
  0% { box-shadow: 0 0 0 0 rgb(from var(--color-brand) r g b / 35%); }
  100% { box-shadow: 0 0 0 0.8rem rgb(from var(--color-brand) r g b / 0%); }
}

/* Pointer: to the line (act 1), the next line (act 2), along the signature (act 3), then away. */
@keyframes pdf-edit-intro-cursor {
  0% { transform: translate(250px, 146px); opacity: 0; }
  3% { opacity: 1; }
  9%, 31% { transform: translate(184px, 74px); }
  40%, 64% { transform: translate(150px, 86px); }
  70% { transform: translate(86px, 124px); }
  86% { transform: translate(140px, 124px); opacity: 1; }
  92% { transform: translate(200px, 128px); opacity: 0; }
  100% { transform: translate(250px, 146px); opacity: 0; }
}

@keyframes pdf-edit-intro-select {
  0%, 9% { opacity: 0; }
  10%, 31% { opacity: 1; }
  33%, 100% { opacity: 0; }
}

@keyframes pdf-edit-intro-old {
  0%, 12% { opacity: 1; transform: scaleX(1); }
  16% { opacity: 1; transform: scaleX(0); }
  17%, 98% { opacity: 0; transform: scaleX(0); }
  100% { opacity: 1; transform: scaleX(1); }
}

@keyframes pdf-edit-intro-new {
  0%, 16% { transform: scaleX(0); }
  28%, 97% { transform: scaleX(1); }
  100% { transform: scaleX(0); }
}

@keyframes pdf-edit-intro-caret {
  0%, 15% { opacity: 0; }
  16%, 20%, 24%, 28% { opacity: 1; }
  18%, 22%, 26% { opacity: 0; }
  31%, 100% { opacity: 0; }
}

@keyframes pdf-edit-intro-mark {
  0%, 40% { opacity: 0; }
  43%, 97% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes pdf-edit-intro-note {
  0%, 42% { opacity: 0; transform: scale(0.85); }
  46%, 97% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: none; }
}

@keyframes pdf-edit-intro-sign {
  0%, 70% { stroke-dashoffset: 120; opacity: 1; }
  86%, 97% { stroke-dashoffset: 0; opacity: 1; }
  100% { stroke-dashoffset: 0; opacity: 0; }
}

@keyframes pdf-edit-intro-sent {
  0%, 87% { opacity: 0; transform: translateY(4px); }
  91%, 97% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: none; }
}

@keyframes pdf-edit-intro-tool {
  0%, 31% { fill: var(--color-brand-light); }
  33%, 100% { fill: transparent; }
}

@keyframes pdf-edit-intro-toolicon {
  0%, 31% { stroke: var(--color-brand); }
  33%, 100% { stroke: var(--color-text-secondary); }
}

@keyframes pdf-edit-intro-step {
  0%, 31% { color: var(--color-text-primary); }
  33%, 100% { color: var(--color-text-secondary); }
}

@keyframes pdf-edit-intro-fill-1 {
  0% { transform: scaleX(0); }
  31%, 97% { transform: scaleX(1); }
  100% { transform: scaleX(0); }
}

@keyframes pdf-edit-intro-fill-2 {
  0%, 33% { transform: scaleX(0); }
  64%, 97% { transform: scaleX(1); }
  100% { transform: scaleX(0); }
}

@keyframes pdf-edit-intro-fill-3 {
  0%, 66% { transform: scaleX(0); }
  97% { transform: scaleX(1); }
  100% { transform: scaleX(0); }
}
