/* The PRD visual editor (app/prd/editor.js): a sticky formatting toolbar over one contenteditable surface that reads
   like the public page (css/prd.css), plus the Markdown Source textarea. Colours come from tokens.css, so light and
   dark follow the theme; every toolbar target is 44 px. */
:root { --pe-code-bg: rgb(120 120 128 / 0.12); --pe-quote: rgb(109 74 255 / 0.5); --pe-done: #1c7a3a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --pe-code-bg: rgb(255 255 255 / 0.08); --pe-quote: rgb(167 148 255 / 0.6); --pe-done: #6fdc8f; } }
:root[data-theme="dark"] { --pe-code-bg: rgb(255 255 255 / 0.08); --pe-quote: rgb(167 148 255 / 0.6); --pe-done: #6fdc8f; }

.pe { position: relative; min-width: 0; color: var(--label); }

/* Toolbar: one scrollable row on phones, sticky at the top of the host's scroller (so it stays above the iOS keyboard) */
/* Under the app's sticky top bar by default; a host with its own scroller sets --pe-sticky-top (e.g. 0). */
.pe-bar { position: sticky; top: var(--pe-sticky-top, calc(var(--topbar-h, 0px) + var(--safe-top, 0px))); z-index: 15; display: flex; align-items: center; gap: 2px; overflow-x: auto; overscroll-behavior-x: contain;
  padding: 2px max(var(--s-2), env(safe-area-inset-right)) 2px max(var(--s-2), env(safe-area-inset-left));
  background: var(--chat-bg, var(--bg)); border-bottom: var(--hairline) solid var(--separator); scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.pe-bar::-webkit-scrollbar { display: none; }
/* more buttons than fit (phones, 320 px): a fade at the right edge says the row scrolls; it rides along (sticky) and
   sits over empty space once the row is scrolled to its end */
.pe-bar::after { content: ""; position: sticky; right: 0; flex: none; align-self: stretch; width: 28px; margin-left: -6px; pointer-events: none;
  background: linear-gradient(to right, transparent, var(--chat-bg, var(--bg)) 85%); }
.pe-btn { flex: none; display: inline-grid; place-items: center; min-width: var(--tap); height: var(--tap); padding: 0; border: 0; border-radius: var(--r-sm);
  background: none; color: var(--label-2); font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
@media (hover: hover) { .pe-btn:hover { background: var(--fill-2); color: var(--label); } }
.pe-btn[aria-pressed="true"] { background: var(--accent-tint); color: var(--accent); }
.pe-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.pe-btn:disabled { opacity: 0.35; cursor: default; background: none; }
.pe-btn-hr { margin-left: 6px; }
.pe-btn-source { margin-left: auto; }
.pe-h-label { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; min-width: 22px; text-align: center; }

/* The surface */
.pe-surface { min-height: 40vh; padding: var(--s-4) max(var(--s-4), env(safe-area-inset-right)) var(--s-8) max(var(--s-4), env(safe-area-inset-left));
  outline: none; font-size: 16px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; caret-color: var(--accent);
  -webkit-user-select: text; user-select: text; }
.pe-readonly .pe-surface { min-height: 0; }
.pe-surface > :first-child { margin-top: 0; }
.pe-surface .prd-h { letter-spacing: -0.02em; line-height: 1.25; font-weight: 700; overflow-wrap: anywhere; }
.pe-surface h1.prd-h { margin: 8px 0 12px; font-size: 26px; letter-spacing: -0.03em; }
.pe-surface h2.prd-h { margin: 28px 0 8px; font-size: 21px; }
.pe-surface h3.prd-h { margin: 22px 0 6px; font-size: 17px; }
.pe-surface .prd-p { margin: 0 0 12px; }
.pe-surface code { padding: 0.12em 0.36em; border-radius: 6px; background: var(--pe-code-bg); font: 0.88em/1.4 var(--font-mono); }
.pe-surface a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.pe-surface .prd-list { margin: 0 0 12px; padding-left: 28px; }
.pe-surface .prd-list .prd-list { margin: 2px 0 0; }
.pe-surface .prd-list > li { margin: 3px 0; padding-left: 2px; }
.pe-surface .prd-list > li.prd-task { list-style: none; position: relative; }
.pe-surface .prd-check { position: absolute; left: -25px; top: 3px; width: 19px; height: 19px; border: 1.75px solid var(--label-3); border-radius: 6px;
  font-size: 0; color: transparent; cursor: pointer; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
.pe-surface .prd-check::before { content: ""; position: absolute; inset: -12.5px; } /* a 44 px target around the 19 px box */
.pe-surface .prd-check[aria-checked="true"] { border-color: var(--pe-done); background: var(--pe-done); }
.pe-surface .prd-check[aria-checked="true"]::after { content: ""; position: absolute; left: 32%; top: 12%; width: 28%; height: 52%;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.pe-surface .prd-done > .prd-item { color: var(--label-2); text-decoration: line-through; text-decoration-color: var(--label-3); }
.pe-readonly .pe-surface .prd-check { cursor: default; }
.pe-surface .prd-quote { margin: 0 0 12px; padding: 2px 0 2px 14px; border-left: 3px solid var(--pe-quote); color: var(--label-2); }
.pe-surface .prd-quote > :last-child { margin-bottom: 0; }
.pe-surface .prd-code { margin: 0 0 12px; padding: 12px 14px; border-radius: 12px; background: var(--pe-code-bg); overflow-x: auto;
  font: 13.5px/1.5 var(--font-mono); white-space: pre; tab-size: 2; }
.pe-surface .prd-code code { padding: 0; background: none; font: inherit; }
.pe-surface .prd-hr { height: 0; margin: 20px 0; border: 0; border-top: 1.5px solid var(--separator); }
.pe-surface .prd-fig { margin: 4px 0 14px; -webkit-user-select: none; user-select: none; }
.pe-surface .prd-img { display: block; max-width: 100%; height: auto; max-height: 70vh; border-radius: 12px; background: var(--fill-2); }
.pe-surface .prd-img-missing { display: block; margin: 0 0 12px; padding: 18px; border-radius: 12px; background: var(--fill-2); color: var(--label-2); font-size: 14px; }

/* Markdown source */
.pe-source { display: block; width: 100%; min-height: 60vh; margin: 0; padding: var(--s-4) max(var(--s-4), env(safe-area-inset-right)) var(--s-8) max(var(--s-4), env(safe-area-inset-left));
  border: 0; outline: none; resize: none; overflow: hidden; background: transparent; color: var(--label); font: 14px/1.6 var(--font-mono); tab-size: 2; }
@media (pointer: coarse) { .pe-source { font-size: 16px; } } /* iOS zooms into fields under 16 px */
.pe-source[hidden], .pe-surface[hidden] { display: none; }

@media (prefers-reduced-motion: no-preference) {
  .pe-btn { transition: background var(--t-fast), color var(--t-fast); }
}

/* Tables in the editing surface: one object (edited in Source), scrolling sideways when wide */
.pe-surface .prd-table-wrap { margin: 0 0 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; border: var(--hairline) solid var(--separator); border-radius: 12px; -webkit-user-select: none; user-select: none; }
.pe-surface .prd-table { width: 100%; min-width: max-content; border-collapse: collapse; font-size: 0.95em; line-height: 1.4; }
.pe-surface .prd-table th, .pe-surface .prd-table td { padding: 8px 12px; text-align: left; vertical-align: top; border-top: var(--hairline) solid var(--separator); }
.pe-surface .prd-table thead th { border-top: 0; background: var(--fill-2); font-weight: 650; white-space: nowrap; }
.pe-surface .prd-table tbody tr:first-child td { border-top: 0; }
.pe-surface .prd-table .prd-al-r { text-align: right; font-variant-numeric: tabular-nums; }
.pe-surface .prd-table .prd-al-c { text-align: center; }
