/* v4 — bid editor (read + edit) + citation panel + 3-state underlines */

/* chapter-by-chapter view: ToC nav switches active chapter */
.bid-v4__toc-num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: .04em;
  flex: 0 0 auto;
  width: 22px;
}
.bid-v4__toc-title { flex: 1; min-width: 0; }
.bid-v4__toc-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
  border-left-color: var(--accent);
}
.bid-v4__toc-item.is-active .bid-v4__toc-num { color: var(--accent); }

.sec__eyebrow {
  font-size: 11px;
  letter-spacing: .08em;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  margin-bottom: 6px;
  text-transform: uppercase;
}

.sec__chapnav {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-top: var(--s-4);
  padding: var(--s-3) 0;
  border-top: 1px solid var(--line);
}
.sec__chapnav-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-2);
  padding: 10px 14px;
  cursor: pointer;
  font: inherit;
  text-align: left;
  color: var(--ink);
  transition: background .12s var(--ease), border-color .12s var(--ease);
}
.sec__chapnav-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.sec__chapnav-btn--next { justify-content: flex-end; text-align: right; }
.sec__chapnav-arrow {
  font-size: 22px;
  line-height: 1;
  color: var(--accent);
  flex: 0 0 auto;
}
.sec__chapnav-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sec__chapnav-label {
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--ink-3);
}
.sec__chapnav-title {
  font-size: 13.5px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 24em;
}
.sec__chapnav-progress {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-size: 12px;
  color: var(--ink-3);
  padding: 0 12px;
  flex: 0 0 auto;
}
.sec__chapnav-spacer { flex: 1; }

/* multi-profile picker bar (公司资料 page) */
.pf-bar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  margin-bottom: var(--s-4);
  flex-wrap: wrap;
}
.pf-bar__tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}
.pf-bar__tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-2);
  padding: 7px 14px;
  font: inherit;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s var(--ease), border-color .12s var(--ease);
}
.pf-bar__tab:hover { border-color: var(--ink-3); color: var(--ink); }
.pf-bar__tab.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.pf-bar__tab-empty {
  font-size: 10px;
  letter-spacing: .04em;
  color: var(--ink-3);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: 1px 6px;
  border-radius: 3px;
  font-weight: 400;
}
.pf-bar__actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.pf-bar__ic {
  display: inline-flex;
  align-items: center;
  margin-right: 4px;
  color: var(--ink-3);
}
.btn--danger {
  /* Solid destructive button — paired with the solid .btn--primary in modal
     confirms. The previous red-text-on-light-surface treatment failed
     contrast for the delete-confirm button (smoke fix 3). */
  background: var(--err);
  border-color: var(--err);
  color: #fff;
}
.btn--danger:hover:not(.is-disabled) {
  background: #6a1212;
  border-color: #6a1212;
}
.btn--danger.is-disabled,
.btn--danger:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* insert-panel: profile selector */
.bi-insert-panel__select {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}
.bi-insert-panel__sel-label {
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--ink-3);
}
.bi-insert-panel__sel {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: var(--r-1);
  padding: 4px 8px;
  font: inherit;
  font-size: 12.5px;
  background: var(--surface);
}

/* ============================================================
   bid-v4 layout: ToC | content | citation panel
   ============================================================ */
.bid-v4 { display: flex; flex-direction: column; gap: var(--s-4); }

.bid-v4__head {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  /* Sit below the topbar (--topbar-h) AND the sticky .js-tabs strip
     (--js-tabs-h) so the toolbar isn't visually obscured by the tabs. */
  position: sticky; top: calc(var(--topbar-h) + var(--js-tabs-h)); z-index: 5;
}
.bid-v4__head-left { display: flex; align-items: center; gap: 12px; }
.bid-v4__head-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.mode-seg {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-2);
  overflow: hidden;
  background: var(--bg-soft);
}
.mode-seg__btn {
  border: 0;
  background: transparent;
  padding: 7px 16px;
  font: inherit; font-size: 13px;
  cursor: pointer;
  color: var(--ink-2);
  white-space: nowrap;
}
.mode-seg__btn.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.cite-toggle__dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 6px;
  vertical-align: middle;
  opacity: .35;
}
.btn.is-active .cite-toggle__dot { opacity: 1; box-shadow: 0 0 0 2px var(--accent-soft); }

.bid-v4__layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 360px;
  gap: var(--s-4);
  align-items: start;
}
.bid-v4__layout.no-panel { grid-template-columns: 220px minmax(0, 1fr); }

.bid-v4__toc {
  position: sticky; top: calc(var(--topbar-h) + var(--js-tabs-h) + 24px);
  max-height: calc(100vh - 160px);
  overflow: auto;
  padding-right: 4px;
}
.bid-v4__toc-head {
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 600;
  padding: 6px 8px;
}
.bid-v4__toc-list { display: flex; flex-direction: column; gap: 1px; }
.bid-v4__toc-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--ink-2);
  text-decoration: none;
  border-radius: var(--r-2);
  border-left: 2px solid transparent;
}
.bid-v4__toc-item:hover {
  background: var(--bg-soft);
  color: var(--ink);
}
.bid-v4__toc-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--line-strong);
  flex: 0 0 auto;
}

.bid-v4__stack {
  min-width: 0;
  display: flex; flex-direction: column; gap: var(--s-5);
}

/* ============================================================
   Section (per chapter)
   ============================================================ */
.sec {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  padding: var(--s-5) var(--s-5);
  scroll-margin-top: 132px;
}
.sec__title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--ink);
  margin: 0 0 var(--s-3);
}
.sec__meta {
  display: flex; flex-wrap: wrap; gap: 0 var(--s-5);
  padding: 10px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  margin-bottom: var(--s-4);
}
.sec__meta-item {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 12.5px;
  padding: 4px 0;
}
.sec__meta-label {
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--ink-3);
}
.sec__meta-val {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* read-mode body styling */
.sec__body--read,
.wys-editor {
  font-size: 14.5px;
  line-height: 1.85;
  color: var(--ink);
  text-wrap: pretty;
}
.sec__body--read p,
.wys-editor p { margin: 0 0 14px; }
.sec__body--read h1, .wys-editor h1,
.sec__body--read h2, .wys-editor h2,
.sec__body--read h3, .wys-editor h3,
.sec__body--read h4, .wys-editor h4 {
  margin: 18px 0 10px;
  letter-spacing: -.005em;
}
.sec__body--read h2, .wys-editor h2 { font-size: 17px; font-weight: 600; }
.sec__body--read h3, .wys-editor h3 { font-size: 15px; font-weight: 600; }
.sec__body--read ul, .wys-editor ul,
.sec__body--read ol, .wys-editor ol {
  margin: 0 0 14px; padding-left: 24px;
}
.sec__body--read li, .wys-editor li { margin: 4px 0; }
.sec__body--read blockquote, .wys-editor blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 14px;
  color: var(--ink-2);
  background: var(--accent-soft);
  margin: 0 0 14px;
  border-radius: 0 var(--r-2) var(--r-2) 0;
}
.sec__body--read table, .wys-editor table {
  border-collapse: collapse;
  width: 100%; margin: 0 0 14px;
  font-size: 13.5px;
}
.sec__body--read th, .wys-editor th,
.sec__body--read td, .wys-editor td {
  border: 1px solid var(--line-strong);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}
.sec__body--read th, .wys-editor th {
  background: var(--bg-soft);
  font-weight: 600;
}

/* paragraph hover affordance */
[data-paragraph-id] {
  position: relative;
  border-radius: 4px;
  transition: background .12s var(--ease);
}
[data-paragraph-id]:hover {
  background: linear-gradient(to right, transparent, rgba(0,0,0,.015) 8%, rgba(0,0,0,.015) 92%, transparent);
}
[data-paragraph-id].is-pinned {
  background: var(--accent-soft) !important;
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

/* 3-state cite underlines */
.cite-state-1 {
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 4px;
}
.cite-state-2 {
  text-decoration: underline;
  text-decoration-color: #c4791b;
  text-decoration-thickness: 1.5px;
  text-decoration-style: dotted;
  text-underline-offset: 4px;
}
.cite-state-2::before {
  content: "已修改";
  display: inline-block;
  font-size: 10px;
  letter-spacing: .04em;
  color: #c4791b;
  background: #fcf2dd;
  border: 1px solid #e6c887;
  padding: 1px 6px;
  border-radius: 3px;
  margin-right: 8px;
  vertical-align: 2px;
  text-decoration: none;
  font-weight: 500;
}

/* ============================================================
   WYSIWYG editor
   ============================================================ */
.wys {
  border: 1px solid var(--line-strong);
  border-radius: var(--r-2);
  background: var(--surface);
  overflow: visible;
}
.wys-tb {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 8px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  position: sticky; top: 132px; z-index: 4;
}
.wys-tb__group { display: inline-flex; gap: 2px; }
.wys-tb__sep {
  width: 1px; height: 20px;
  background: var(--line);
  margin: 0 4px;
}
.wys-tb__btn {
  border: 0;
  background: transparent;
  width: 30px; height: 28px;
  border-radius: var(--r-1);
  font: inherit;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.wys-tb__btn:hover { background: var(--surface-2); color: var(--ink); }
.wys-tb__btn--bold { font-weight: 700; font-family: serif; }
.wys-tb__btn--italic { font-style: italic; font-family: serif; }
.wys-tb__select {
  border: 1px solid var(--line);
  border-radius: var(--r-1);
  padding: 4px 8px;
  font: inherit; font-size: 12.5px;
  background: var(--surface);
  height: 28px;
  cursor: pointer;
}
.wys-tb__right { margin-left: auto; }

.wys-editor {
  padding: var(--s-4) var(--s-5);
  min-height: 240px;
  outline: none;
  caret-color: var(--accent);
}
.wys-editor:focus { outline: none; }

.sec__edit-footer {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
  /* Keep "保存修改" + save-state indicator reachable while scrolling a long
     chapter in edit mode. z-index below .bid-v4__head (5) and topbar (18). */
  position: sticky; bottom: 0; z-index: 4;
}
.sec__edit-spacer { flex: 1; }

/* Save-state indicator (B-6). Pill base + dirty/saving/saved come from
   v3.css; here we hide the clean (empty) state and add the two states
   v3.css lacks: 已保存 N 秒前 (gray) and 保存失败 (red). */
.save-state:empty { display: none; }
.save-state.is-saved-ago { background: var(--bg-soft); color: var(--ink-3); }
.save-state.is-failed    { background: var(--err-soft); color: var(--err); }

/* ============================================================
   Citation panel
   ============================================================ */
.cite-panel {
  position: sticky; top: calc(var(--topbar-h) + var(--js-tabs-h) + 24px);
  max-height: calc(100vh - 160px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  padding: 0;
  display: flex; flex-direction: column;
}
.cite-panel.is-hidden { display: none; }

.cite-panel__head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: var(--r-3) var(--r-3) 0 0;
}
.cite-panel__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -.005em;
}
.cite-panel__collapse {
  margin-left: auto;
  border: 0; background: transparent;
  font-size: 18px; line-height: 1;
  color: var(--ink-3); cursor: pointer;
  width: 22px; height: 22px;
  border-radius: 50%;
}
.cite-panel__collapse:hover { background: var(--bg-soft); color: var(--ink); }

.cite-panel__body {
  padding: 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.cite-panel__hint {
  font-size: 13px;
  color: var(--ink-3);
  text-align: center;
  padding: 24px 8px;
  line-height: 1.7;
}
.cite-panel__nocite {
  font-size: 13px;
  color: var(--ink-3);
  padding: 16px 12px;
  background: var(--bg-soft);
  border-radius: var(--r-2);
  text-align: center;
}

.cite-panel__pinned-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--r-2);
}
.cite-panel__pin-tag {
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--accent-ink);
  font-weight: 600;
}
.cite-panel__unpin {
  margin-left: auto;
  border: 0; background: transparent;
  font: inherit; font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.cite-panel__edited {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 12px;
  background: #fcf2dd;
  border: 1px solid #e6c887;
  border-radius: var(--r-2);
  font-size: 12.5px;
  line-height: 1.6;
}
.cite-panel__edited-tag {
  flex: 0 0 auto;
  font-size: 10px;
  letter-spacing: .04em;
  background: #c4791b;
  color: #fff;
  padding: 2px 7px;
  border-radius: 3px;
  font-weight: 600;
}
.cite-panel__edited-text { color: #804f0c; }

.req-card {
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  padding: 12px 14px;
  background: var(--surface);
}
.req-card__id {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .04em;
  margin-bottom: 8px;
}
.req-card__row {
  display: flex; gap: 6px; align-items: baseline;
  margin-bottom: 8px;
  font-size: 12px;
  flex-wrap: wrap;
}
.req-card__row-label {
  color: var(--ink-3);
  font-size: 11px;
  letter-spacing: .04em;
}
.req-card__row-val {
  color: var(--ink-2);
}
.req-card__quote {
  margin: 0;
  padding: 8px 12px;
  border-left: 3px solid var(--accent);
  background: var(--bg-soft);
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink);
  border-radius: 0 var(--r-1) var(--r-1) 0;
  text-wrap: pretty;
}
.req-card__missing {
  font-size: 12px;
  color: var(--ink-4);
  font-style: italic;
}

/* responsive: collapse panel + ToC under 1100px */
@media (max-width: 1100px) {
  .bid-v4__layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .bid-v4__layout.no-panel { grid-template-columns: minmax(0, 1fr); }
  .bid-v4__toc, .cite-panel {
    position: static; max-height: none;
  }
  .bid-v4__toc { order: -1; }
  .cite-panel { order: 99; }
}
