/* mapa.css: this app's own CSS, beside estilo's theme.
 *
 * Everything here is something rastrillo's ui partials do not provide.
 * It is prefixed mapa-, never rst-, so the line between the framework's
 * vocabulary and this app's is visible in the markup. Only tokens.css
 * custom properties are used, so Calma and the light/dark switch apply.
 *
 * Calma's rules (estilo AGENTS.md, "Theme"): inside an app only the icons
 * carry colour; the accent is for the one primary action and the current
 * selection; white cards on a cool page, 12px shapes, one grey scale.
 */

[mapa-brand] {
  display: inline-flex;
  align-items: center;
  gap: var(--rst-sp-2);
  font-weight: 600;
}

/* ---- Quiet secondary text. */
[mapa-meta] {
  color: var(--rst-text-muted);
  font-size: var(--rst-fs-sm);
  margin: 0;
}

/* ---- A page: its title and actions on one row, the body on a card. */
[mapa-page-head] {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--rst-sp-3);
  margin-block-end: var(--rst-sp-4);
}
[mapa-page-head] h1 { margin: 0; }
[mapa-actions] {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--rst-sp-2);
}
[mapa-body] {
  line-height: 1.7;
  overflow-wrap: anywhere;
}
[mapa-body] > :first-child { margin-block-start: 0; }
[mapa-body] > :last-child { margin-block-end: 0; }
[mapa-body] blockquote,
[mapa-context] blockquote {
  margin-inline: 0;
  padding-inline-start: var(--rst-sp-3);
  border-inline-start: 3px solid var(--rst-line-strong);
  color: var(--rst-text-muted);
}
[mapa-body] pre,
[mapa-source-text] {
  background: var(--rst-surface-2);
  border-radius: var(--rst-radius-sm);
  padding: var(--rst-sp-3);
  overflow-x: auto;
  white-space: pre-wrap;
}
[mapa-body] code { font-size: 0.92em; }
[mapa-body] hr { border: 0; border-block-start: 1px solid var(--rst-line); }

/* ---- Links between pages. A pending link names no page yet: dashed,
 * and muted, so it never passes for one that leads somewhere. The text
 * label is its own; the style only repeats it. */
a[mapa-link] { text-decoration-thickness: 1px; }
a[mapa-link="pending"] {
  color: var(--rst-text-muted);
  text-decoration-style: dashed;
}
[mapa-link="broken"] { color: var(--rst-text-muted); }
[mapa-note], [mapa-embed] { color: var(--rst-text-muted); }

/* ---- Backlinks and mentions: each linking page with its blocks. */
[mapa-linked] { margin-block-start: var(--rst-sp-5); }
[mapa-linked] h2 { font-size: var(--rst-fs-lg); margin-block: 0 var(--rst-sp-2); }
[mapa-sources] {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--rst-sp-2);
}
[mapa-sources] > li {
  background: var(--rst-surface);
  border: 1px solid var(--rst-line);
  border-radius: var(--rst-radius);
  padding: var(--rst-sp-3) var(--rst-sp-4);
}
[mapa-source] { font-weight: 600; }
[mapa-context] {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--rst-sp-3);
  color: var(--rst-text-muted);
}
[mapa-context] > :first-child { margin-block: var(--rst-sp-1) 0; }
[mapa-context] ul, [mapa-context] ol { padding-inline-start: 1.25rem; }
[mapa-link-it] { flex: none; }

/* ---- A plain list of pages: a title over a muted line, no bullets. */
[mapa-list] {
  list-style: none;
  margin: 0 0 var(--rst-sp-4);
  padding: 0;
  background: var(--rst-surface);
  border: 1px solid var(--rst-line);
  border-radius: var(--rst-radius);
}
[mapa-list] > li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--rst-sp-2);
  padding: var(--rst-sp-3) var(--rst-sp-4);
  border-block-end: 1px solid var(--rst-line);
}
[mapa-list] > li:last-child { border-block-end: 0; }
[mapa-list] a { font-weight: 600; }

/* ---- The editor: Markdown in a monospace box as tall as the screen. */
[mapa-editor] {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--rst-fs-base);
  line-height: 1.6;
  min-block-size: 50vh;
}

/* ---- Make team page: each block a choice, drawn as it reads. */
[mapa-choose] {
  border: 0;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--rst-sp-2);
}
[mapa-choose] legend { font-weight: 600; margin-block-end: var(--rst-sp-2); }
[mapa-choice] {
  display: flex;
  gap: var(--rst-sp-3);
  align-items: baseline;
  background: var(--rst-surface);
  border: 1px solid var(--rst-line);
  border-radius: var(--rst-radius);
  padding: var(--rst-sp-2) var(--rst-sp-3);
  cursor: pointer;
}
[mapa-choice]:has(input:checked) {
  border-color: var(--rst-accent);
  background: var(--rst-accent-soft);
}
[mapa-choice-body] > :first-child { margin-block: 0; }

/* ---- Search: the box and its button on one row. */
[mapa-search] { margin-block-end: var(--rst-sp-4); }
[mapa-search-row] {
  display: flex;
  gap: var(--rst-sp-2);
  align-items: center;
}
[mapa-search-row] input { flex: 1; min-inline-size: 0; }
[mapa-create] { margin-block: 0 var(--rst-sp-3); }
[mapa-results] > li { display: block; }
[mapa-result] p { margin-block-start: var(--rst-sp-1); }

/* ---- Unsaved changes, and who else is editing: a quiet band. */
[mapa-unsaved] {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--rst-sp-2) var(--rst-sp-3);
  background: var(--rst-surface);
  border: 1px solid var(--rst-line-strong);
  border-radius: var(--rst-radius);
  padding: var(--rst-sp-2) var(--rst-sp-4);
  margin-block: var(--rst-sp-3);
}
[mapa-unsaved] p { margin: 0; flex: 1 1 16rem; }
[mapa-editing] { margin-block: var(--rst-sp-2); }

/* ---- The conflict view: each disputed block a choice between sides. */
[mapa-hunk] {
  border: 1px dashed var(--rst-line-strong);
  border-radius: var(--rst-radius);
  padding: var(--rst-sp-3);
  margin-block: var(--rst-sp-3);
  display: grid;
  gap: var(--rst-sp-2);
}
[mapa-hunk] legend { font-weight: 600; padding-inline: var(--rst-sp-1); }
[mapa-sides] {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: var(--rst-sp-3);
}
[mapa-sides] h2 { font-size: var(--rst-fs-lg); }
[mapa-copy] code { user-select: all; }

/* ---- The script layer: status, preview, [[ suggestions, ⌘K. */
[mapa-status] {
  color: var(--rst-text-muted);
  font-size: var(--rst-fs-sm);
  min-block-size: 1.5em;
  margin: var(--rst-sp-1) 0 0;
}
[mapa-preview]:empty { display: none; }
[mapa-preview]::before {
  content: "Preview";
  display: block;
  color: var(--rst-text-muted);
  font-size: var(--rst-fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-block-end: var(--rst-sp-2);
}
[mapa-suggest],
[mapa-palette-results] {
  list-style: none;
  margin: var(--rst-sp-1) 0 0;
  padding: var(--rst-sp-1);
  background: var(--rst-surface);
  border: 1px solid var(--rst-line);
  border-radius: var(--rst-radius-sm);
  box-shadow: var(--rst-shadow-pop);
  max-block-size: 18rem;
  overflow-y: auto;
}
[mapa-suggest][hidden] { display: none; }
[mapa-suggest] li,
[mapa-palette-results] li {
  padding: var(--rst-sp-1) var(--rst-sp-2);
  border-radius: var(--rst-radius-sm);
  cursor: pointer;
}
[mapa-palette-results] li { display: grid; }
[mapa-suggest] li[aria-selected="true"],
[mapa-palette-results] li[aria-selected="true"] {
  background: var(--rst-accent-soft);
}
[mapa-palette-results]:empty { display: none; }
[mapa-palette] {
  inline-size: min(36rem, calc(100vw - 2rem));
  margin-block-start: 12vh;
  padding: var(--rst-sp-3);
  border: 1px solid var(--rst-line);
  border-radius: var(--rst-radius);
  background: var(--rst-surface);
  color: var(--rst-text);
  box-shadow: var(--rst-shadow-pop);
}
[mapa-palette]::backdrop { background: var(--rst-overlay); }
[mapa-palette] input { inline-size: 100%; box-sizing: border-box; }

/* ---- The page editor (level-up §6). Here, never injected (§6.9).
 * ProseMirror's own rules, only those that change nothing the server
 * drew: the article holds no text between blocks once mounted, so
 * pre-wrap there moves nothing, and ligatures are left as they are. */
[mapa-body].ProseMirror {
  position: relative;
  white-space: pre-wrap;
  word-wrap: break-word;
  outline: none;
}
[mapa-body].ProseMirror [contenteditable="false"] { white-space: normal; }
.ProseMirror-hideselection *::selection { background: transparent; }
.ProseMirror-hideselection { caret-color: transparent; }
.ProseMirror-selectednode { outline: 2px solid var(--rst-accent); outline-offset: 1px; }
li.ProseMirror-selectednode { outline: none; }
img.ProseMirror-separator {
  display: inline !important;
  border: none !important;
  margin: 0 !important;
}
.ProseMirror-gapcursor { display: none; pointer-events: none; position: absolute; }
.ProseMirror-gapcursor::after {
  content: "";
  display: block;
  position: absolute;
  inset-block-start: -2px;
  inline-size: 20px;
  border-block-start: 1px solid var(--rst-text);
  animation: mapa-gap-blink 1.1s steps(2, start) infinite;
}
@keyframes mapa-gap-blink { to { visibility: hidden; } }
.ProseMirror-focused .ProseMirror-gapcursor { display: block; }
@media (prefers-reduced-motion: reduce) {
  .ProseMirror-gapcursor::after { animation: none; }
}

/* The inline choice (§6.5): the blocks both of you changed are marked
 * and read-only until you choose; theirs is drawn beside them. */
[mapa-body] [mapa-hunk] {
  background: color-mix(in oklab, var(--rst-accent-soft) 60%, transparent);
  border-radius: 4px;
  box-shadow: -10px 0 0 color-mix(in oklab, var(--rst-accent-soft) 60%, transparent);
}
[mapa-hunk-choice] {
  margin: 0 0 var(--rst-sp-2);
  padding: var(--rst-sp-3);
  border: 1px solid var(--rst-line);
  border-radius: var(--rst-radius-sm);
  background: var(--rst-surface);
  white-space: normal;
  user-select: none;
}
[mapa-hunk-choice] > p { margin: 0 0 var(--rst-sp-2); }
[mapa-hunk-theirs] {
  padding-inline-start: var(--rst-sp-3);
  border-inline-start: 3px solid var(--rst-line-strong);
  margin-block-end: var(--rst-sp-2);
  user-select: text;
}
[mapa-hunk-buttons] { display: flex; flex-wrap: wrap; gap: var(--rst-sp-2); }

/* [[ and / (§6.6): a list under the caret, placed by script. */
[mapa-combo] {
  position: fixed;
  z-index: 40;
  min-inline-size: 14rem;
  max-inline-size: min(24rem, calc(100vw - 8px));
  max-block-size: 16rem;
  overflow-y: auto;
  margin: 0;
  padding: var(--rst-sp-1);
  list-style: none;
  background: var(--rst-surface);
  border: 1px solid var(--rst-line);
  border-radius: var(--rst-radius-sm);
  box-shadow: var(--rst-shadow-pop);
  font-size: var(--rst-fs-sm);
}
[mapa-combo][hidden] { display: none; }
[mapa-combo] li {
  display: flex;
  justify-content: space-between;
  gap: var(--rst-sp-3);
  min-block-size: 24px;
  padding: var(--rst-sp-1) var(--rst-sp-2);
  border-radius: var(--rst-radius-sm);
  cursor: pointer;
}
[mapa-combo] li small { color: var(--rst-text-muted); }
[mapa-combo] li[aria-selected="true"] { background: var(--rst-accent-soft); }
@media (pointer: coarse) { [mapa-combo] li { min-block-size: 32px; align-items: center; } }

/* The selection bubble (§6.6): above the selection, below on touch. */
[mapa-bubble] {
  position: fixed;
  z-index: 40;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--rst-surface);
  border: 1px solid var(--rst-line);
  border-radius: var(--rst-radius-sm);
  box-shadow: var(--rst-shadow-pop);
  transition: opacity 120ms ease;
}
[mapa-bubble][hidden] { display: none; }
[mapa-bubble] button {
  min-inline-size: 28px;
  min-block-size: 28px;
  padding: 0 var(--rst-sp-2);
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--rst-text);
  font: inherit;
  font-size: var(--rst-fs-sm);
  cursor: pointer;
}
[mapa-bubble] button[aria-pressed="true"],
[mapa-bubble] button:hover { background: var(--rst-surface-2); }
[mapa-bubble] button:focus-visible { outline: 2px solid var(--rst-accent); }
[mapa-bubble] button[aria-label="Bold"] { font-weight: 700; }
[mapa-bubble] button[aria-label="Italic"] { font-style: italic; }
[mapa-bubble] button[aria-label="Code"] { font-family: ui-monospace, monospace; }
[mapa-bubble] { flex-wrap: wrap; max-inline-size: calc(100vw - 8px); }
[mapa-bubble-field],
[mapa-bubble-page] { inline-size: 14rem; max-inline-size: 100%; font-size: 16px; }
[mapa-bubble-page][hidden] { display: none; }
/* Why a selection cannot be a page link (build note 81): a line of its
   own under the buttons; empty, it takes no room but stays a live
   region, so what it says next is announced. */
[mapa-bubble-note] {
  flex-basis: 100%;
  max-inline-size: 22rem;
  margin: 0;
  padding: 2px var(--rst-sp-2) 4px;
  color: var(--rst-text-muted);
  font-size: var(--rst-fs-sm);
}
[mapa-bubble-note]:empty {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
}
@media (pointer: coarse) { [mapa-bubble] button { min-inline-size: 36px; min-block-size: 36px; } }
@media (prefers-reduced-motion: reduce) { [mapa-bubble] { transition: none; } }

/* A block's ¶ (§6.3): out of the text's flow, so it moves nothing. */
[mapa-anchor] {
  position: absolute;
  margin-inline-start: -28px;
  inline-size: 24px;
  block-size: 24px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--rst-text-faint);
  font: inherit;
  line-height: 24px;
  cursor: pointer;
  opacity: 0;
}
:is(p, h2, h3, h4, h5, h6, li, blockquote):hover > [mapa-anchor],
[mapa-anchor]:focus-visible,
[mapa-anchor][data-copied] { opacity: 1; }
[mapa-anchor][data-copied] { color: var(--rst-accent); }
@media (pointer: coarse) { [mapa-anchor] { display: none; } }

/* Make team page (§6.7): the blocks that will move are tinted first. */
[mapa-body] [mapa-moving] {
  background: var(--rst-accent-soft);
  border-radius: 4px;
  box-shadow: -8px 0 0 var(--rst-accent-soft), 8px 0 0 var(--rst-accent-soft);
}
[mapa-make-team] {
  inline-size: min(28rem, calc(100vw - 2rem));
  padding: var(--rst-sp-4);
  border: 1px solid var(--rst-line);
  border-radius: var(--rst-radius);
  background: var(--rst-surface);
  color: var(--rst-text);
  box-shadow: var(--rst-shadow-pop);
}
[mapa-make-team]::backdrop { background: var(--rst-overlay); }
[mapa-make-team] h2 { margin: 0 0 var(--rst-sp-3); font-size: var(--rst-fs-lg); }
[mapa-make-team] label { display: block; margin-block-end: var(--rst-sp-1); }
[mapa-make-team] input { inline-size: 100%; box-sizing: border-box; font-size: 16px; }
[mapa-make-team] p { color: var(--rst-text-muted); font-size: var(--rst-fs-sm); }
[mapa-make-team-error]:empty { display: none; }
[mapa-make-team-error] { color: var(--rst-danger, var(--rst-text)); }
[mapa-make-team-foot] { display: flex; justify-content: flex-end; gap: var(--rst-sp-2); }

/* A task's box in the editor (§6.11): a named button laid over the box
 * the server draws, out of the flow. The box's own alternative text
 * gives way to the button's name, so it is read once. */
[mapa-body].ProseMirror li[mapa-task] > p::before { content: ""; content: "" / ""; }
[mapa-task-box] {
  position: absolute;
  inline-size: 24px;
  block-size: 24px;
  margin-inline-start: calc(-1.35em - 4.5px);
  margin-block-start: -1px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  cursor: pointer;
}
[mapa-task-box]:focus-visible { outline: 2px solid var(--rst-accent); }
@media (pointer: coarse) {
  [mapa-task-box] {
    inline-size: 32px;
    block-size: 32px;
    margin-inline-start: calc(-1.35em - 8.5px);
    margin-block-start: -5px;
  }
}

/* The phone's row over the keyboard (§6.11, D6). */
[mapa-accessory] {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 45;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 4px max(4px, env(safe-area-inset-left));
  background: var(--rst-surface);
  border-block-start: 1px solid var(--rst-line);
}
[mapa-accessory][hidden] { display: none; }
[mapa-accessory] button {
  flex: none;
  min-inline-size: 44px;
  min-block-size: 36px;
  padding: 0 var(--rst-sp-2);
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--rst-text);
  font: inherit;
  font-size: 16px;
}
[mapa-accessory] button:active { background: var(--rst-surface-2); }
[mapa-accessory] button[aria-label="Bold"] { font-weight: 700; }
[mapa-accessory] button[aria-label="Italic"] { font-style: italic; }
/* The Links sheet hides while the keyboard is up (§4.3). */
html[data-mapa-keyboard] aside[mapa-links] [mapa-peek] { display: none; }

/* The in-page title, renamed in place (level-up §4.1, build note 78).
   Its look does not change when it is edited: the text keeps its face,
   size and wrap, and the ring is an outline, which takes no room. The
   note under it is empty, and so takes no room, until a rename says
   something. */
h1[mapa-rename] { cursor: text; border-radius: 6px; }
/* Engines give editable text their own white space (Chromium: pre-wrap,
   so a line's end space is kept and measured); the title keeps the
   heading's, so nothing moves when it becomes editable. Spaces typed
   into it are still kept: the engine writes them as no-break spaces,
   which the title's whitespace rule reads as spaces. */
h1[mapa-rename] [mapa-title-text][contenteditable] {
  outline: none;
  white-space: inherit;
  overflow-wrap: inherit;
  line-break: inherit;
}
h1[mapa-rename]:focus-within { outline: 2px solid var(--rst-accent); outline-offset: 4px; }
h1[mapa-rename] [mapa-title-text][aria-busy="true"] { cursor: progress; }
[mapa-title-note]:not(:empty) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-block-start: 14px;
  font-size: 14px;
}
[mapa-title-note] p { margin: 0; flex: 1 1 16rem; }
[mapa-title-note] p:has(> [rst-spin]) { display: inline-flex; align-items: center; gap: 8px; color: var(--rst-text-muted); }
[mapa-title-note] [role="alert"] { color: var(--rst-danger, var(--rst-text)); }
