/* Employee Surveys → Reports (employee-surveys-reports.js). Prefix esr-.
   Series colors come in a fixed order and passed the dataviz palette check
   (lightness band, chroma floor, colorblind separation, contrast). The first
   is a brighter cyan than --teal, which reads gray as a chart fill. */

:root {
  --esr-s1: #0891B2;
  --esr-s2: #C4492A;
  --esr-s3: #5B6BD6;
  --esr-s4: #A16207;
  --esr-s5: #7E3AF2;
  --esr-label-w: 200px;
}

.esr { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 20px; align-items: start; }

/* Report picker */
.esr-picker { display: flex; flex-direction: column; gap: 2px; position: sticky; top: calc(var(--topbar-h) + 12px); }
.es-page .esr-picker { padding: 8px; border: 1px solid var(--line-soft); border-radius: var(--es-r); background: var(--card); box-shadow: var(--es-shadow); }
.esr-pick-item {
  display: block; width: 100%; padding: 10px 14px; border: 0; border-radius: var(--r-pill); background: none;
  color: var(--fg-soft); font: inherit; font-size: var(--fs-base); font-weight: 600; text-align: left; cursor: pointer;
}
.esr-pick-item:hover { background: var(--surface-hover); color: var(--fg); }
.esr-pick-item.is-active { background: var(--teal-soft); color: var(--brand-ink); }
.es-page .esr-pick-item.is-active { background: var(--teal); color: var(--on-solid); }

.esr-main { min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.esr-content { display: flex; flex-direction: column; gap: 14px; }
.esr-questions { display: flex; flex-direction: column; gap: 14px; }

/* Display Options: sticky under the top bar */
.esr-options {
  position: sticky; top: var(--topbar-h); z-index: 20;
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; padding: 12px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow-sm);
}
.es-page .esr-options { border-color: var(--line-soft); border-radius: var(--es-r); box-shadow: var(--es-shadow); padding: 14px 18px; }
.es-page .esr-field input, .es-page .esr-select { border-radius: var(--r-pill); padding: 0 14px; }
.esr-options-title { flex-basis: 100%; font-size: var(--fs-xs); font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.esr-field { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-xs); font-weight: 650; color: var(--muted); }
.esr-field input, .esr-select {
  height: var(--ctl-h); padding: 0 10px; box-sizing: border-box; border: 1px solid var(--input-line); border-radius: var(--r-sm);
  background: var(--card); color: var(--fg); font: inherit; font-size: var(--fs-base);
}
.esr-checkline { display: inline-flex; align-items: center; gap: 8px; height: var(--ctl-h); font-size: var(--fs-base); color: var(--fg); }
.esr-graph { align-self: flex-end; }

.esr-pick { position: relative; align-self: flex-end; }
.esr-pick > summary { list-style: none; }
.esr-pick > summary::-webkit-details-marker { display: none; }
.esr-pick-pop {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; min-width: 220px; padding: 8px;
  display: flex; flex-direction: column; gap: 2px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-field); box-shadow: var(--shadow-pop);
}

/* Tools row */
.esr-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.esr-count { margin-right: auto; font-size: var(--fs-base); font-weight: 650; color: var(--fg); }
.esr-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.esr-actions .esr-count { margin: 0 0 0 4px; }

/* Question cards */
.esr-qcard { padding: 0; }
.esr-qhead { padding: 14px 18px 0; }
.esr-qtitle { display: flex; align-items: center; gap: 6px; margin: 0; font-family: var(--font-display); font-size: var(--fs-lead); font-weight: 700; color: var(--fg); line-height: 1.35; }
.esr-qsub { margin: 4px 0 0; font-size: var(--fs-sm); color: var(--muted); }
.esr-qstat b { color: var(--fg); }
.esr-qbody { padding: 12px 18px 16px; display: flex; flex-direction: column; gap: 10px; }
.esr-grid-head { margin: 6px 0 -4px; font-size: var(--fs-md); font-weight: 650; color: var(--fg-soft); }
.esr-note { margin: 0; font-size: var(--fs-sm); color: var(--muted); }
.esr-none { margin: 0; font-size: var(--fs-base); color: var(--muted); }
.esr-sub { font-size: var(--fs-sm); color: var(--muted); }

/* Horizontal bars */
.esr-bars { display: flex; flex-direction: column; gap: 8px; }
.esr-bar-row { display: grid; grid-template-columns: var(--esr-label-w) minmax(0, 1fr); gap: 12px; align-items: center; }
.esr-bar-label { font-size: var(--fs-base); color: var(--fg); overflow-wrap: anywhere; }
.esr-bar-stack { display: flex; flex-direction: column; gap: 3px; }
.esr-bar-line { display: grid; grid-template-columns: minmax(0, 1fr) 104px; gap: 8px; align-items: center; }
.esr-bar-track { position: relative; height: 16px; border-radius: var(--r-pill); background: var(--surface-sunk); }
.esr-bar-fill { height: 100%; min-width: 4px; border-radius: var(--r-pill); background: var(--esr-s1); }
.esr-bar-fill[data-s="1"] { background: var(--esr-s2); }
.esr-bar-fill[data-s="2"] { background: var(--esr-s3); }
.esr-bar-fill[data-s="3"] { background: var(--esr-s4); }
.esr-bar-fill[data-s="4"] { background: var(--esr-s5); }
.esr-bar-target { position: absolute; top: -4px; bottom: -4px; width: 3px; margin-left: -1.5px; border-radius: var(--r-pill); background: var(--fg); }
.esr-bar-value { font-size: var(--fs-sm); color: var(--fg-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
.esr-bar-axis { display: grid; grid-template-columns: var(--esr-label-w) minmax(0, 1fr) 104px; gap: 12px 8px; }
.esr-bar-ends { display: flex; justify-content: space-between; gap: 8px; font-size: var(--fs-xs); color: var(--muted); }
.esr-tkey { display: inline-block; width: 2px; height: 14px; background: var(--fg); }

.esr-help {
  display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; margin-left: 4px; vertical-align: 1px;
  border-radius: var(--r-pill); background: var(--surface-sunk); color: var(--fg-soft); font-size: var(--fs-2xs); font-weight: 700; cursor: help;
}

/* Legend: a colored key beside text-colored words */
.esr-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: var(--fs-sm); color: var(--fg-soft); }
.esr-legend span { display: inline-flex; align-items: center; gap: 6px; }
.esr-key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--esr-s1); }
.esr-key[data-s="1"] { background: var(--esr-s2); }
.esr-key[data-s="2"] { background: var(--esr-s3); }
.esr-key[data-s="3"] { background: var(--esr-s4); }
.esr-key[data-s="4"] { background: var(--esr-s5); }

/* Line charts */
.esr-linewrap { position: relative; }
.esr-linechart { display: block; width: 100%; height: auto; max-height: 260px; overflow: visible; }
.esr-grid { stroke: var(--line); stroke-width: 1; }
.esr-tick { fill: var(--muted); font-size: var(--fs-2xs); }
.esr-line { --esr-c: var(--esr-s1); }
.esr-line[data-s="1"] { --esr-c: var(--esr-s2); }
.esr-line[data-s="2"] { --esr-c: var(--esr-s3); }
.esr-line[data-s="3"] { --esr-c: var(--esr-s4); }
.esr-line[data-s="4"] { --esr-c: var(--esr-s5); }
.esr-line-path { fill: none; stroke: var(--esr-c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.esr-line-dot { fill: var(--esr-c); stroke: var(--card); stroke-width: 2; }
.esr-line-end { fill: var(--fg-soft); font-size: var(--fs-2xs); font-weight: 650; }
.esr-hit { fill: transparent; cursor: crosshair; }
.esr-hit.is-on { fill: var(--surface-hover); fill-opacity: 0.5; }
.esr-tip {
  position: absolute; z-index: 5; width: 180px; padding: 8px 10px; white-space: pre-line; pointer-events: none;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-sm); box-shadow: var(--shadow-pop);
  font-size: var(--fs-xs); color: var(--fg); line-height: 1.45;
}

/* Table view */
.esr-table-view > summary { cursor: pointer; font-size: var(--fs-sm); font-weight: 600; color: var(--teal); }
.esr-table-scroll { overflow-x: auto; margin-top: 8px; }

/* Participation */
.esr-part-total { font-family: var(--font-display); font-size: var(--fs-2xl); font-weight: 750; color: var(--fg); }
.esr-part-total span { margin-left: 6px; font-family: var(--font-sans); font-size: var(--fs-sm); font-weight: 500; color: var(--muted); }

/* Comments */
.esr-comments { display: flex; flex-direction: column; gap: 6px; padding-top: 6px; border-top: 1px solid var(--line-soft); }
.esr-comments-title { font-size: var(--fs-xs); font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.esr-cgroup { border: 1px solid var(--line-soft); border-radius: var(--es-r-md, var(--r-sm)); background: var(--surface-2); transition: background-color 0.15s; }
.esr-cgroup:hover { background: var(--surface-hover); }
.esr-cgroup > summary { display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer; font-size: var(--fs-base); }
.esr-cgroup-label { font-weight: 650; color: var(--fg); }
.esr-cgroup-n { color: var(--muted); }
.esr-cgroup-n::before { content: "· "; }
.esr-clist { margin: 0; padding: 0 12px 10px; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.esr-clist li { padding: 8px 10px; background: var(--card); border-radius: var(--r-xs); border: 1px solid var(--line-soft); }
.esr-ctext { font-size: var(--fs-md); color: var(--fg); white-space: pre-line; }
.esr-cmeta { margin-top: 4px; font-size: var(--fs-xs); color: var(--muted); }
.esr-link { padding: 0; border: 0; background: none; color: var(--teal); font: inherit; font-weight: 650; cursor: pointer; text-decoration: underline; }

/* Comment summary */
.esr-summary { border-color: var(--teal-line); }
.esr-summary-text { margin: 0; font-size: var(--fs-md); color: var(--fg); white-space: pre-line; line-height: 1.55; }

/* Turnover */
.esr-turn-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }

/* Contact Information */
.esr-opts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.esr-opt {
  position: relative; display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card);
}
.esr-opt input { position: absolute; opacity: 0; pointer-events: none; }
.esr-opt:focus-within { outline: 2px solid var(--teal); outline-offset: 2px; }
.esr-opt.is-on { border-color: var(--teal); background: var(--teal-soft); }
.esr-opt-label { font-size: var(--fs-base); font-weight: 600; color: var(--fg); }
.esr-opt-n { font-family: var(--font-display); font-size: var(--fs-kpi); font-weight: 750; color: var(--fg); }
.esr-ok { display: inline-flex; color: var(--ok); vertical-align: -2px; }
.esr-contact-table td, .esr-imports-table td { vertical-align: top; }

@media (max-width: 1100px) {
  .esr { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .esr-picker { position: static; flex-direction: row; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
  .esr-picker::-webkit-scrollbar { display: none; }
  .esr-pick-item { width: auto; flex: none; white-space: nowrap; }
  .esr-turn-grid { grid-template-columns: minmax(0, 1fr); }
  .esr-opts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  :root { --esr-label-w: 100%; }
  .esr-options { position: static; }
  .esr-bar-row { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .esr-bar-axis { grid-template-columns: minmax(0, 1fr) 104px; }
  .esr-bar-axis > span:first-child { display: none; }
  .esr-graph { flex-wrap: wrap; }
  .esr-tools .ivy-btn { flex: 1 1 auto; }
  .esr-count { flex-basis: 100%; }
}
@media print {
  .esr { display: block; }
  .esr-picker, .esr-options, .esr-tools, .esr-actions, .esr-table-view, .esr-link, .esr-hit { display: none; }
  .esr-qcard { break-inside: avoid; box-shadow: none; margin-bottom: 12px; }
  .esr-bar-fill, .esr-key { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
