/* People Intelligence tab - styled to match the rest of the dashboard. */
#people-panel {
  --pi-line: #dbe4dc;
  display: none;
}

#people-panel.active {
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* wide tables scroll inside, not the page */
  gap: 16px;
}

#people-panel > .panel h2 {
  margin: 4px 0 6px;
  font-size: 20px;
}

.pi-intro h2 {
  margin: 4px 0 6px;
  font-size: clamp(20px, 2.4vw, 26px);
}

.pi-intro > p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.pi-intro > p.section-label {
  font-size: 11px;
}

/* Colour per use case (used by tiles, card accents and tags) */
.pi-topic-ai { --pi-tone: #276b99; }
.pi-topic-efficiency { --pi-tone: #216b50; }
.pi-topic-workload { --pi-tone: #b97805; }
.pi-topic-patterns { --pi-tone: #0d7f83; }
.pi-topic-risk { --pi-tone: #b23b3b; }

.pi-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin: 16px 0 10px;
}

.pi-controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pi-controls input,
.pi-controls select {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(98, 112, 103, 0.26);
  border-radius: 10px;
  color: var(--ink);
  background: #ffffff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: normal;
  text-transform: none;
}

.pi-controls input[type=number] {
  width: 120px;
}

.pi-controls .secondary-action,
.pi-controls .primary-action {
  min-height: 40px;
}

.pi-question {
  flex: 1;
  min-width: 220px;
}

#pi-status {
  display: inline-block;
  margin: 4px 0 0;
  padding: 7px 12px;
  border: 1px solid rgba(13, 127, 131, 0.2);
  border-radius: 999px;
  color: var(--green);
  background: rgba(13, 127, 131, 0.07);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.4;
}

#pi-status:empty {
  display: none;
}

.pi-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
}

/* At-a-glance tiles */
.pi-overview {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.pi-tile {
  position: relative;
  display: grid;
  gap: 6px;
  min-height: 112px;
  padding: 14px 14px 14px 18px;
  overflow: hidden;
  border: 1px solid rgba(23, 77, 60, 0.12);
  border-radius: 12px;
  color: inherit;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(17, 26, 22, 0.04);
  text-decoration: none;
  transition: border-color 160ms ease;
}

.pi-tile::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--pi-tone);
}

.pi-tile:hover {
  border-color: #d2dad5;
}

.pi-tile span {
  color: var(--pi-tone);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pi-tile strong {
  color: var(--ink);
  font-size: 24px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.pi-tile em {
  color: var(--muted);
  font-size: 11.5px;
  font-style: normal;
  font-weight: 700;
  line-height: 1.35;
}

/* Opportunity cards */
.pi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 16px;
}

.pi-card {
  min-width: 0;
  padding: 18px 20px;
  border: 1px solid var(--pi-line);
  border-top: 4px solid var(--pi-tone, var(--teal));
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(17, 26, 22, 0.04);
  scroll-margin-top: calc(var(--sticky-top, 0px) + 90px);
}

.pi-card h3 {
  margin: 14px 0 8px;
  font-size: 16px;
  font-weight: 700;
}

.pi-card p,
.pi-card li {
  margin: 6px 0;
  font-size: 13.5px;
  line-height: 1.55;
}

.pi-card ol {
  margin: 6px 0;
  padding-left: 20px;
}

.pi-tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--pi-tone, #174d3c);
  background: color-mix(in srgb, var(--pi-tone, #174d3c) 12%, #ffffff);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.pi-number {
  display: block;
  margin: 12px 0 2px;
  color: var(--pi-tone, #174d3c);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}

.pi-measure {
  margin: 12px 0;
  padding: 12px 14px;
  border-left: 3px solid var(--pi-tone, var(--teal));
  border-radius: 0 10px 10px 0;
  background: #f4f7f2;
  font-size: 13px;
  line-height: 1.6;
}

.pi-card .pi-note {
  font-size: 12px;
}

.pi-card .secondary-action {
  margin-top: 6px;
}

/* Tables */
.pi-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.pi-table th,
.pi-table td {
  padding: 10px 12px;
  text-align: left;
}

.pi-table td.numeric,
.pi-table th.numeric {
  white-space: nowrap;
}

/* Chat and saved reports */
.pi-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 4px;
}

.pi-answer {
  margin: 14px 0;
  padding: 14px 16px;
  border-left: 4px solid var(--teal);
  border-radius: 0 12px 12px 0;
  background: #f4f7f2;
}

.pi-answer h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.pi-answer p {
  margin: 6px 0;
  font-size: 13.5px;
  line-height: 1.6;
  white-space: pre-line;
}

.pi-empty {
  margin: 0;
  padding: 24px;
  border: 1px dashed var(--pi-line);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  text-align: center;
}

@media (max-width: 1060px) {
  .pi-overview {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  .pi-overview {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pi-controls > * {
    flex: 1 1 140px;
  }

  .pi-controls input[type=number] {
    width: 100%;
  }
}

/* ---- Layout: every block in the tab lines up on one grid ---- */
#pi-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

#pi-content > .pi-overview,
#pi-content > .pi-grid {
  margin: 0;
}

#people-panel .panel-heading {
  margin-bottom: 12px;
}

#people-panel .panel-heading h2 {
  margin: 4px 0 0;
}

/* Field-work notice */
.pi-field-note {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 12px 0 0;
  padding: 10px 14px;
  border: 1px solid rgba(185, 120, 5, 0.25);
  border-radius: 10px;
  color: #6b4a10;
  background: #fdf8ee;
  font-size: 13px;
  line-height: 1.5;
}

.pi-field-note::before {
  content: "i";
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  border-radius: 50%;
  color: #ffffff;
  background: #b97805;
  font-size: 11px;
  font-style: italic;
  font-weight: 700;
}

.panel .pi-field-note {
  margin: 0 0 12px;
}

/* Workload & productivity table */
.pi-table th,
.pi-table td {
  vertical-align: middle;
}

.pi-table .numeric {
  text-align: right;
}

.pi-person-cell {
  font-weight: 600;
  white-space: normal;
}

.pi-pct-col {
  width: 34%;
  min-width: 220px;
}

.pi-pct {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) 64px;
  gap: 12px;
  align-items: center;
}

.pi-pct-track {
  display: block;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1ee;
}

.pi-pct-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.pi-pct strong {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Saved live reports */
.pi-count {
  color: var(--muted);
  font-size: 0.8em;
  font-weight: 500;
}

#pi-saved {
  display: grid;
  gap: 14px;
}

.pi-report {
  padding: 16px 18px;
  border: 1px solid var(--pi-line);
  border-left: 4px solid var(--pi-tone, var(--teal));
  border-radius: 12px;
  background: #ffffff;
  transition: box-shadow 300ms ease, border-color 300ms ease;
}

.pi-report.is-new {
  border-color: var(--pi-tone, var(--teal));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pi-tone, #0d7f83) 22%, transparent);
}

.pi-report-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
}

.pi-report-head h3 {
  margin: 8px 0 2px;
  font-size: 16px;
}

.pi-report-meta {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.pi-report-figures {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 6px;
}

.pi-report-figures div {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--pi-line);
  border-radius: 10px;
  background: #fbfcfb;
}

.pi-report-figures span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pi-report-figures strong {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

/* Structured answers (chat and saved reports) */
.pi-answer-body p,
.pi-answer-body li {
  margin: 6px 0;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: normal;
}

.pi-answer-body ol {
  margin: 4px 0 8px;
  padding-left: 20px;
}

.pi-answer-label {
  font-weight: 600;
}

.pi-answer .pi-report-meta {
  margin: -4px 0 6px;
}

.pi-answer .secondary-action {
  margin-top: 6px;
}

@media (max-width: 780px) {
  .pi-report-head {
    flex-direction: column;
  }

  .pi-report-figures {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Phones: keep Person, hours and % on screen without sideways scrolling */
  .pi-workload {
    min-width: 0;
  }

  .pi-workload th:nth-child(2),
  .pi-workload td:nth-child(2),
  .pi-workload .pi-pct-track {
    display: none;
  }

  .pi-workload th,
  .pi-workload td {
    padding: 9px 8px;
  }

  .pi-workload th,
  .pi-workload th.numeric {
    white-space: normal;
    line-height: 1.25;
  }

  .pi-pct-col {
    width: auto;
    min-width: 0;
  }

  .pi-pct {
    grid-template-columns: minmax(0, 1fr);
  }
}
