/* The Docs page and its open card (public/docs.js): one calm card per topic. The open card is the canvas panel
   (canvas.css) with a tool row, its sections as a list that opens one at a time, a comment thread and a comment box.
   Only transform, opacity and colours animate. */
.docs-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.docs-search { display: flex; align-items: center; gap: 10px; max-width: 520px; min-height: 44px; padding: 0 16px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--card); color: var(--ink-3); transition: border-color .2s var(--ease), box-shadow .2s var(--ease); }
.docs-search:focus-within { border-color: var(--ink-3); box-shadow: 0 0 0 3px rgba(43, 79, 214, .12); }
.docs-search input { flex: 1; min-width: 0; border: 0; outline: none; background: none; font: inherit; font-size: 15px; color: var(--ink); }
.docs-search input::-webkit-search-cancel-button { cursor: pointer; }
.docs-search { flex: 1 1 280px; }
.docs-project select { font: inherit; font-size: 15px; min-height: 44px; border: 1px solid var(--line-2); border-radius: 999px; padding: 0 14px; background: var(--card); color: var(--ink); max-width: 100%; }
.docs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 18px; align-items: stretch; }

.doc-card { min-width: 0; display: flex; flex-direction: column; gap: 12px; padding: 22px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; color: var(--ink); text-decoration: none; transition: box-shadow .3s var(--ease), border-color .3s var(--ease), transform .3s var(--ease); }
.doc-card:hover { border-color: var(--line-2); box-shadow: var(--lift); transform: translateY(-2px); }
.doc-card:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }
.doc-card h3 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.25; overflow-wrap: anywhere; }
.doc-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; font-weight: 600; color: var(--ink-3); }
.doc-proj { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.doc-proj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-proj .dot-sq { flex: none; width: 9px; height: 9px; }
.doc-status { flex: none; padding: 3px 10px; font-size: 12px; }
.doc-excerpt { font-size: 15px; line-height: 1.5; color: var(--ink-2); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.doc-card-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--rule); display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--ink-3); }
.doc-counts { display: inline-flex; gap: 10px; flex: none; }
.doc-counts span { display: inline-flex; align-items: center; gap: 4px; }

.docs-form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.docs-new select, .doc-edit select { font: inherit; font-size: 15px; min-height: 44px; border: 1px solid var(--line-2); border-radius: 12px; padding: 0 10px; background: var(--card); }
.docs-new input[type="text"] { width: 100%; min-width: 0; font-size: 15px; border: 1px solid var(--line-2); border-radius: 12px; padding: 10px 12px; min-height: 44px; background: var(--card); }
.docs-new textarea { font-size: 15px; line-height: 1.5; }

/* The open card. */
.doc-panel { width: min(680px, calc(100vw - 24px)); }
.doc-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 14px 10px 22px; border-bottom: 1px solid var(--line); background: var(--card); }
.doc-tools .canvas-btn { height: 34px; padding: 0 12px; }
.doc-tools .doc-save { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.doc-tools .doc-pin .pin-btn { height: 34px; }
.doc-body > * + * { margin-top: 16px; }
.doc-lede { display: flex; flex-direction: column; gap: 10px; }
.doc-summary { margin: 0; font-size: 17px; line-height: 1.5; color: var(--ink); overflow-wrap: anywhere; }
.doc-summary.muted { font-size: 14px; color: var(--ink-3); }
.doc-head-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-3); }
.doc-head-tags .pill { padding: 3px 9px; font-size: 11px; }
.doc-author { margin-left: auto; font-size: 12px; }
.doc-files, .doc-links { display: flex; flex-direction: column; gap: 8px; }
.doc-links { flex-direction: row; flex-wrap: wrap; align-items: center; }
.doc-links .chip { text-decoration: none; color: var(--ink); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Sections: a plain list; each opens in place to its text. */
.doc-sections { display: flex; flex-direction: column; gap: 8px; }
.doc-sections .doc-sections-title { margin: 0 0 2px; font-size: 12px; font-weight: 600; letter-spacing: 0; color: var(--ink-3); }
.doc-sections-empty { margin: 0; }
.doc-section { border: 1px solid var(--line); border-radius: 16px; background: var(--card); transition: border-color .2s var(--ease); }
.doc-section.open { border-color: var(--line-2); }
.doc-section-head { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 12px 16px; border: 0; background: none; font: inherit; text-align: left; color: var(--ink); cursor: pointer; border-radius: 16px; }
.doc-section-head:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }
.doc-section-head svg { flex: none; color: var(--ink-3); transition: transform .2s var(--ease); }
.doc-section.open .doc-section-head svg { transform: rotate(90deg); }
.doc-section-title { flex: 1; min-width: 0; font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.doc-section-when { flex: none; font-size: 12px; color: var(--ink-3); }
.doc-section-body { padding: 0 16px 14px 42px; }
.doc-section-body[hidden] { display: none; }
.doc-sections.single { display: block; }
.doc-section-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--rule); font-size: 12px; color: var(--ink-3); }
.doc-section-foot .canvas-btn { height: 34px; padding: 0 12px; }
.doc-edit-what { margin: 0; font-size: 14px; color: var(--ink-3); }
.doc-remove { align-self: flex-start; }
/* Undo after removing a card: a full-size target on any screen. */
.toast-undo.doc-toast-undo { min-height: 44px; padding: 0 18px; }

/* The body uses the canvas's formatting (canvas.css), one level down. */
.doc-md > * { margin: 0; }
.doc-md > * + * { margin-top: 12px; }
.doc-md h3, .doc-md h4, .doc-md h5 { font-weight: 700; letter-spacing: -0.015em; line-height: 1.3; }
.doc-md h3 { font-size: 20px; }
.doc-md h4 { font-size: 17px; }
.doc-md h5 { font-size: 15px; }
.doc-md > h3, .doc-md > h4 { margin-top: 22px; }
.doc-md > :first-child { margin-top: 0; }
.doc-md ul, .doc-md ol { padding-left: 22px; }

.doc-comments { padding-top: 18px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.doc-comments .doc-comments-title { font-size: 16px; font-weight: 700; margin: 0; }
.doc-comments .empty { margin: 0; font-size: 14px; }
.doc-foot { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--paper); }
.doc-foot:empty { display: none; }
.doc-comment-box { margin: 0; }
.doc-comment-box textarea { min-height: 44px; }

.doc-edit { display: flex; flex-direction: column; gap: 12px; min-height: 100%; }
.doc-edit select { width: 100%; }
.doc-edit .rtn-field input[type="text"] { width: 100%; min-width: 0; font-size: 15px; border: 1px solid var(--line-2); border-radius: 12px; padding: 10px 12px; min-height: 44px; background: var(--card); }
.doc-editor-field { flex: 1; }
.doc-edit .doc-editor { width: 100%; min-height: 46vh; resize: vertical; font-size: 15px; line-height: 1.55; border: 1px solid var(--line-2); border-radius: 12px; padding: 12px 14px; background: var(--card); color: var(--ink); }
.doc-edit input:focus, .doc-editor:focus { outline: none; border-color: var(--ink-3); box-shadow: 0 0 0 3px rgba(43, 79, 214, .12); }
.doc-notice { margin: 0; font-size: 13px; line-height: 1.45; color: var(--butter-ink); background: var(--butter-soft); border: 1px solid var(--butter-edge); border-radius: 12px; padding: 8px 12px; }
.doc-notice[hidden] { display: none; }

.doc-versions { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.doc-version { display: flex; flex-direction: column; }
.doc-version.current { padding: 12px 14px; border-radius: 14px; background: var(--mint); color: var(--mint-ink); gap: 2px; font-size: 14px; }
.doc-version-open { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: left; font: inherit; font-size: 14px; padding: 12px 14px; border: 1px solid var(--line-2); border-radius: 14px; background: var(--card); color: var(--ink); cursor: pointer; transition: border-color .2s var(--ease); }
.doc-version-open:hover { border-color: var(--pen); }
.doc-version-open span, .doc-version.current span { font-size: 12px; color: var(--ink-3); }
.doc-version.current span { color: inherit; opacity: .8; }

/* The doc popup (openDocPopup): one section of a card over the page he is on, with the card's sections in a list and
   an arrow either side to step through them. A full-screen sheet on a phone. */
.doc-pop { width: min(680px, calc(100vw - 32px)); max-width: none; max-height: min(86vh, 900px); padding: 0; border: 0; border-radius: var(--radius); background: var(--card); color: var(--ink); box-shadow: 0 28px 56px -28px rgba(0, 0, 0, .55); overflow: hidden; }
.doc-pop[open] { display: flex; animation: rise .3s var(--ease) both; }
.doc-pop::backdrop { background: rgba(29, 26, 22, .55); }
html:has(.doc-pop[open]) { overflow: hidden; scrollbar-gutter: stable; }
.doc-pop-panel { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.doc-pop-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px 10px 24px; }
.doc-pop-title { flex: 1; min-width: 0; margin: 0; font-size: 15px; font-weight: 600; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-pop-close, .doc-pop-step { flex: none; width: 44px; height: 44px; }
.doc-pop-step:disabled { opacity: .35; cursor: default; }
.doc-pop-prev svg { transform: rotate(180deg); }
.doc-pop-nav { display: flex; align-items: center; gap: 8px; padding: 0 16px 12px; border-bottom: 1px solid var(--line); }
.doc-pop-nav[hidden] { display: none; }
.doc-pop-picker { flex: 1; min-width: 0; min-height: 44px; padding: 0 14px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--card); color: var(--ink); font: inherit; font-size: 15px; font-weight: 600; text-overflow: ellipsis; }
.doc-pop-picker:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; }
.doc-pop-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 18px 24px 22px; outline: none; }
.doc-pop-head:has(+ .doc-pop-nav[hidden]) { border-bottom: 1px solid var(--line); }
.doc-pop-section { margin: 0; font-size: 21px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.3; overflow-wrap: anywhere; }
.doc-pop-meta { margin: 4px 0 16px; font-size: 12.5px; color: var(--ink-3); }
.doc-pop-body .doc-md { font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; }
.doc-pop-foot { display: flex; flex-direction: column; gap: 8px; padding: 10px 16px 12px; border-top: 1px solid var(--line); background: var(--paper); }
.doc-pop-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.doc-pop-actions .canvas-btn { height: 44px; padding: 0 16px; text-decoration: none; }
.doc-pop-full { margin-left: auto; }

@media (max-width: 860px) {
  .doc-panel { width: auto; }
  .doc-pop { width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  .doc-pop-head { padding-top: calc(10px + env(safe-area-inset-top)); padding-left: 18px; padding-right: 12px; }
  .doc-pop-nav { padding: 0 12px 10px; }
  .doc-pop-body { padding: 16px 18px 20px; }
  .doc-pop-foot { padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); }
  .doc-tools { padding: 8px 12px; }
  .doc-tools .canvas-btn, .doc-tools .doc-pin .pin-btn { height: 44px; }
  .doc-author { margin-left: 0; width: 100%; }
  .doc-card { padding: 18px; }
  .doc-section-body { padding: 0 14px 14px; }
  .doc-section-when { display: none; }
  .doc-card:hover { transform: none; }
  .doc-edit .doc-editor { min-height: 50vh; }
  .doc-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .doc-card, .doc-card:hover { transition: none; transform: none; }
  .doc-section-head svg { transition: none; }
  .doc-pop[open] { animation: none; }
}

/* A wide screen shows the doc beside the page, and the doc has its own message box, so the page's one steps aside. */
@media (min-width: 861px) {
  .doc-open .main > .composer-wrap { display: none; }
}
