/* viewer-extra.css — piece-specific layout overrides beyond viewer-chrome.css. */
:root {
  --cv-canvas-min-width: 320px;
  --cv-ages-table-min-height: 260px;
  --cv-canvas-min-height: 520px;
  --cv-canvas-max-height: 880px;
  --cv-canvas-min-height-stacked: 680px;
  --cv-canvas-max-height-stacked: 1600px;
  --cv-plot-pad-left: 54px;
  --cv-plot-pad-right: 16px;
  --cv-plot-pad-top: 32px;
  --cv-plot-pad-bottom: 82px;
  --cv-plot-gap: 36px;
  --cv-cause-label-width: 148px;
  --cv-years-col-width: 64px;
  --cv-bar-min-width: 240px;
  --cv-bar-max-width: 340px;
  --cv-bar-width-share: 0.28;
  --cv-heat-min-cell: 18px;
  --cv-stacked-bar-min-height: 220px;
  --cv-stacked-bar-share: 1.5;
  /* Axis tick at 12px and caption at 32px sit under the bars; BY AGE sits
     10px above the heatmap. 62px leaves ~20px between caption and title. */
  --cv-stacked-plot-gap: 62px;
  --cv-bar-axis-tick-y: 12px;
  --cv-bar-axis-caption-y: 32px;
  --cv-bar-grid-alpha: 0.22;
  --cv-bar-grid-mid-alpha: 0.12;
  --cv-bar-zero-alpha: 0.35;
}

body {
  min-height: auto;
}

.container {
  width: 100%;
  max-width: 100%;
}

.sidebar {
  max-height: none;
}

.canvas-area {
  flex: 1 1 auto;
  min-width: 0;
  overflow: visible;
}

.canvas-area > div {
  width: 100%;
  min-width: 0;
}

.front-readout {
  font-family: "Spline Sans Mono", monospace;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  background: var(--cv-bg);
  color: var(--cv-secondary);
  border: 1px solid var(--cv-border);
  padding: 6px 10px;
  border-radius: 4px;
  margin-bottom: 10px;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
}

.front-readout .age-value {
  color: var(--cv-ink);
  font-weight: 600;
}

.stat-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: max-content;
  padding: 12px;
  background: color-mix(in srgb, var(--cv-border) 22%, var(--cv-bg));
  border: 1px solid var(--cv-border);
  border-radius: 6px;
}

.stat-badge {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: var(--cv-surface);
  border-radius: 5px;
  padding: 10px 12px;
  border: 1px solid var(--cv-border);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--cv-ink) 4%, transparent);
}

.stat-badge .stat-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--cv-secondary);
  line-height: 1.35;
}

.stat-badge .stat-value {
  margin-top: 4px;
  line-height: 1.3;
}

.headline-num {
  font-family: "Literata", Georgia, serif;
  font-size: 19px;
  font-weight: 600;
  color: var(--cv-answer);
  font-variant-numeric: tabular-nums;
}

.stat-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  margin-bottom: 6px;
}

.stat-label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--cv-secondary);
}

.swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex: none;
}

.rule {
  width: 12px;
  height: 0;
  border-top: 2px dashed var(--cv-answer);
  flex: none;
}

.stat-value {
  font-family: "Spline Sans Mono", monospace;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stat-unit {
  font-family: "Fira Sans", sans-serif;
  font-size: 12px;
  font-weight: 400;
  color: var(--cv-secondary);
  margin-left: 4px;
}

#viewer-canvas-holder {
  width: 100%;
  max-width: 100%;
}

#viewer-canvas-holder canvas {
  display: block;
  width: 100%;
  height: auto;
}

.identity {
  margin-top: 11px;
  padding: 8px 11px;
  border: 1px solid var(--cv-border);
  border-radius: 3px;
  font-family: "Spline Sans Mono", monospace;
  font-size: 11.5px;
  color: var(--cv-secondary);
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-wrap: wrap;
  gap: 3px 15px;
}

.identity b {
  color: var(--cv-ink);
  font-weight: 500;
}

.pair-label { display: block; margin-bottom: 6px; }

.pair-selects {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.pair-selects .profile-select { min-width: 0; }

#snap-note:empty { display: none; }

.ages-table { margin-top: 10px; font-size: 12px; }
.ages-table summary { cursor: pointer; color: var(--cv-secondary); }

.ages-table-wrap {
  max-height: 260px;
  overflow: auto;
  margin-top: 8px;
  border: 1px solid var(--cv-border);
  border-radius: 3px;
}

.ages-table table {
  border-collapse: collapse;
  width: 100%;
  font-family: "Spline Sans Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.ages-table th,
.ages-table td {
  padding: 3px 8px;
  text-align: right;
  border-bottom: 1px solid var(--cv-border);
}

.ages-table th:first-child,
.ages-table td:first-child {
  text-align: left;
  white-space: nowrap;
}

.ages-table th {
  position: sticky;
  top: 0;
  background: var(--cv-bg);
  color: var(--cv-secondary);
  font-weight: 500;
}

.ages-table th:last-child,
.ages-table td:last-child { border-left: 1px solid var(--cv-border); }

.ages-table tr.all-causes td { font-weight: 500; }
.ages-table tr.direction td:first-child { color: var(--cv-secondary); }
.ages-table td.grand-total { color: var(--cv-answer); font-weight: 600; }

@media (min-width: 769px) {
  .canvas-area { align-items: stretch; }

  .canvas-area > div {
    display: flex;
    flex-direction: column;
  }

  .canvas-area > div > #viewer-canvas-holder,
  .canvas-area > div > .identity { flex: none; }

  .ages-table[open] {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .ages-table[open] > summary { flex: none; }

  .ages-table[open]::details-content {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .ages-table[open] > .ages-table-wrap {
    flex: 1 1 0;
    min-height: var(--cv-ages-table-min-height);
    max-height: none;
  }
}
