/* Result document and charts (js/render/document.js, js/render/charts.js).
   Only .doc-* classes; colours, radii and the tap size come from the base.css tokens. */

/* ---- Layout ------------------------------------------------------------------------------- */

.doc {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* lets wide tables scroll inside their wrapper */
  gap: 14px;
  color: var(--text);
  overflow-wrap: anywhere;
}

.doc-section {
  min-width: 0;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.doc-section > :first-child,
.doc-details__body > :first-child {
  margin-top: 0;
}

.doc-section > :last-child,
.doc-details__body > :last-child {
  margin-bottom: 0;
}

/* ---- Headings --------------------------------------------------------------------------------
   .doc-heading--N is the document's own level (1..3) and decides the look. The tag level is relative to
   the page (js/render/document.js): the highest level present is an h2, the next an h3, and so on. */

.doc-heading {
  margin: 1.2em 0 .6em;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
}

.doc-heading--1 {
  font-size: 1.25rem;
  line-height: 1.35;
}

.doc-heading--2 {
  padding-left: .6em;
  border-left: 4px solid var(--primary);
  font-size: 1.0625rem;
}

.doc-heading--3 {
  font-size: 1rem;
}

/* ---- Text ---------------------------------------------------------------------------------- */

.doc-p {
  margin: 0 0 .8em;
  line-height: 1.75;
}

/* A short, all red and bold paragraph is a summary line (SCL-90, IQ, HADS): show it as a headline. */
.doc-emphasis {
  margin: .5em 0 .8em;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
}

.doc-link {
  color: var(--ok);
  text-decoration: underline;
  text-underline-offset: .18em;
}

.doc-link:hover {
  text-decoration-thickness: 2px;
}

/* No local focus styles on purpose: links, summaries and the table scroll regions use the app-wide
   :focus-visible ring of base.css (var(--focus), 6.2:1). A softer colour here would drop below the 3:1
   that WCAG 1.4.11 asks of a focus indicator. */

/* A paragraph that is only a link (the MMPI manual) looks like a button. */
.doc-linkonly {
  margin: 1em 0;
}

.doc-linkonly .doc-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: var(--radius-sm);
  background: var(--ok);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

.doc-list {
  margin: 0 0 .8em;
  padding-left: 1.4em;
  line-height: 1.7;
}

.doc-list li + li {
  margin-top: .3em;
}

.doc-divider {
  margin: 1.1em 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.doc-truncated {
  margin: 0;
  color: var(--muted);
  font-size: .875rem;
}

/* ---- Tables -------------------------------------------------------------------------------- */

/* Horizontally scrollable region. The white "covers" move with the content (local) and the soft
   shadows stay at the edges (scroll), so a shadow shows only on the side that has more content. */
.doc-table-wrap {
  margin: .8em 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background-color: var(--panel);
  background-image:
    linear-gradient(to right, var(--panel) 40%, rgba(255, 255, 255, 0)),
    linear-gradient(to left, var(--panel) 40%, rgba(255, 255, 255, 0)),
    radial-gradient(farthest-side at 0 50%, rgba(28, 39, 54, .22), rgba(28, 39, 54, 0)),
    radial-gradient(farthest-side at 100% 50%, rgba(28, 39, 54, .22), rgba(28, 39, 54, 0));
  background-repeat: no-repeat;
  background-position: 0 0, 100% 0, 0 0, 100% 0;
  background-size: 28px 100%, 28px 100%, 12px 100%, 12px 100%;
  background-attachment: local, local, scroll, scroll;
}

/* Cell backgrounds stay translucent so the scroll shadows underneath remain visible. */
.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9375rem;
  line-height: 1.55;
}

.doc-table th,
.doc-table td {
  min-width: 3.5em;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.doc-table tr:last-child > th,
.doc-table tr:last-child > td {
  border-bottom: 0;
}

.doc-table th {
  background: rgba(255, 138, 91, .1);
  color: var(--text);
  font-weight: 700;
}

.doc-table tbody tr:nth-child(even) > td {
  background: rgba(28, 39, 54, .03);
}

/* ---- Expandable content (MBTI "查看更多解读分析") --------------------------------------------- */

.doc-details {
  margin: .9em 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

.doc-details > summary {
  position: relative;
  display: block;
  min-height: var(--tap);
  padding: 11px 14px 11px 2.2em;
  border-radius: var(--radius-sm);
  font-weight: 600;
  line-height: 1.5;
  cursor: pointer;
  list-style: none;
}

.doc-details > summary::-webkit-details-marker {
  display: none;
}

/* Chevron: points right when closed, down when open. The open mark sits lower inside its box, so
   it is lifted a little to stay centred on the line. */
.doc-details > summary::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 1em;
  width: .5em;
  height: .5em;
  margin-top: calc(-.25em - 1px);
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .15s ease;
}

.doc-details[open] > summary::before {
  margin-top: calc(-.43em - 1px);
  transform: rotate(45deg);
}

.doc-details[open] > summary {
  border-bottom: 1px solid var(--line);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.doc-details__body {
  padding: 12px 14px 14px;
}

.doc-details__close {
  margin-top: .8em;
}

/* ---- Charts -------------------------------------------------------------------------------- */

.doc-chart {
  max-width: 640px;
  margin: 1rem auto;
}

/* The drawings are scaled by their viewBox (about 330-340 units wide), so the caps keep the text
   from growing far beyond phone size on wide screens. */
.doc-chart--mmpi {
  max-width: 480px;
}

.doc-chart--epq {
  max-width: 420px;
}

.doc-chart--mbti {
  max-width: 480px;
}

.doc-chart svg {
  display: block;
  width: 100%;
  max-width: 640px;
  height: auto;
  margin: 0 auto;
}

/* Unknown chart type or unusable data: plain text instead of the drawing. */
.doc-chart-fallback {
  margin: 0 0 .8em;
  line-height: 1.7;
}

/* Visually hidden but still readable by screen readers, search and copy. */
.doc-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---- Narrow screens and motion --------------------------------------------------------------- */

@media (max-width: 480px) {
  .doc {
    gap: 12px;
  }

  .doc-section {
    padding: 13px;
  }

  .doc-table {
    font-size: .875rem;
  }

  .doc-table th,
  .doc-table td {
    padding: 8px;
  }

  .doc-details > summary {
    padding-right: 10px;
  }

  .doc-details__body {
    padding: 10px 10px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .doc-details > summary::before {
    transition: none;
  }
}
