/*
 * Portal home dashboard shell — the KPI strip, panel chrome, "Needs you"
 * worklist, activity feed and triaged action-items rail that a portal's landing
 * page is built from (ISH-715).
 *
 * Hosts: index.html (Broker Portal home) and, from ISH-717, sales-pipeline-home.html.
 * Built here rather than inline because the two home pages had already drifted
 * apart while sharing a layout skeleton — same grid, different greys, different
 * radii (ISH-714 records the table). A component used by more than one page
 * belongs in css/, per AGENTS.md; this file is the same move css/sales-process-tab.css
 * (ISH-514) and css/mdat-boa-card.css (ISH-660 → ISH-682) made before it.
 *
 * ── Scoping ─────────────────────────────────────────────────────────────────
 *
 * Every selector below is prefixed `.dh-` and there is not one bare element
 * selector in the file. That is deliberate: ISH-572 is the case where a
 * component stylesheet's bare selectors restyled all 22 pages, and a home page
 * links this alongside ~6 other css/ files plus a long inline <style>.
 *
 * ── Tokens this file reads ──────────────────────────────────────────────────
 *
 * From css/tokens.css (present on every page, never redeclared here):
 *   --card-bg  --page-bg  --red  --red-hover  --text-secondary
 *
 * From the HOST PAGE's own :root — these have not been unified yet (see the
 * drift table in css/tokens.css), so a host must declare all of them:
 *   --text  --text-label  --border  --border-light  --radius  --radius-lg
 *   --green  --orange
 *
 * Both current hosts carry the slate scale (--text #0f172a, --border #e2e8f0,
 * 8px/12px radii). ISH-717 moves sales-pipeline-home.html onto it. If a third
 * host arrives on the warm scale the components still resolve — they just
 * inherit that page's greys, which is the intended behaviour, not a bug.
 *
 * Stage colours come from css/stage-colors.css via [data-stage]; never restate
 * one here (ISH-353).
 */

/* ── KPI strip ──────────────────────────────────────────────────────────────
   Four slim cards reporting the state of the book. Deliberately not the page's
   centrepiece — the worklist below it is. Each card pairs a value with
   something to read it against; a card with a bare number belongs somewhere
   else. */

.dh-kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.dh-kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.125rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.dh-kpi-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-label);
  margin-bottom: 0.5rem;
}

.dh-kpi-headline {
  display: flex;
  align-items: baseline;
  gap: 0.625rem;
  margin-bottom: 0.625rem;
}

.dh-kpi-value {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--text);
}

.dh-kpi-unit {
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.dh-kpi-delta {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.dh-kpi-delta.is-good {
  font-weight: 600;
  color: var(--green);
}

.dh-kpi-delta.is-bad {
  font-weight: 600;
  color: var(--red);
}

.dh-kpi-note {
  font-size: 0.6875rem;
  color: var(--text-label);
}

.dh-kpi-pills {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
}

/* Progress meter with a target tick. The tick is the point of the component:
   a measured average means nothing without the number it is measured against. */
.dh-kpi-meter {
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: var(--border-light);
  overflow: hidden;
}

.dh-kpi-meter-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: 3px;
  background: var(--green);
}

.dh-kpi-meter-fill.is-over {
  background: var(--red);
}

.dh-kpi-meter-target {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--text);
}

.dh-kpi-meter-note {
  font-size: 0.65625rem;
  color: var(--text-label);
  margin-top: 0.3125rem;
}

/* ── Pills ─────────────────────────────────────────────────────────────────
   The neutral count pill. A stage-coloured one is the same markup carrying
   data-stage, which css/stage-colors.css paints. */

.dh-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3125rem;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.1875rem 0.5rem;
  border-radius: 50px;
  background: var(--border-light);
  color: var(--text);
  white-space: nowrap;
}

.dh-pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.dh-pill[data-stage] {
  background: var(--stage-tint);
  color: var(--stage-text);
}

.dh-pill[data-stage] .dh-pill-dot {
  background: var(--stage-color);
}

.dh-pill.is-critical {
  background: rgba(166, 38, 38, 0.1);
  color: var(--red);
}

.dh-pill.is-warning {
  background: rgba(253, 126, 20, 0.1);
  color: #b45309;
}

/* ── Panel ─────────────────────────────────────────────────────────────────
   Card chrome shared by every panel on a home page. The header is a flex row
   so a title, a count and a link-out can sit on one line without per-panel
   inline styles. */

.dh-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  overflow: hidden;
}

.dh-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9375rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
}

.dh-panel-titlewrap {
  display: flex;
  align-items: center;
  gap: 0.5625rem;
}

.dh-panel-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.dh-panel-count {
  background: var(--red);
  color: #ffffff;
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.125rem 0.4375rem;
  border-radius: 50px;
}

.dh-panel-count.is-quiet {
  background: var(--border-light);
  color: var(--text-secondary);
}

.dh-panel-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.dh-panel-link {
  font-size: 0.78125rem;
  font-weight: 500;
  color: var(--red);
  text-decoration: none;
  white-space: nowrap;
}

.dh-panel-link:hover {
  color: var(--red-hover);
  text-decoration: underline;
}

.dh-panel-actions {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

/* ── Tab strip inside a panel header ───────────────────────────────────── */

.dh-tabs {
  display: flex;
  gap: 0.25rem;
}

.dh-tab {
  border: none;
  background: none;
  font: inherit;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.71875rem;
  font-weight: 500;
  padding: 0.25rem 0.625rem;
  border-radius: 50px;
}

.dh-tab:hover {
  background: var(--border-light);
}

.dh-tab.is-active {
  background: var(--text);
  color: var(--card-bg);
}

.dh-tab:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

/* ── Worklist ("Needs you") ────────────────────────────────────────────────
   One row per thing waiting on the viewer. The kind chip carries the severity
   so the row reads before it is read: what it is, which broker, what is needed,
   how long it has sat, and the action. */

.dh-worklist {
  display: flex;
  flex-direction: column;
}

.dh-wl-row {
  display: grid;
  grid-template-columns: 7.25rem 1fr 6rem 6.625rem;
  gap: 1rem;
  align-items: center;
  padding: 0.8125rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
}

.dh-wl-row:last-child {
  border-bottom: none;
}

.dh-wl-row:hover {
  background: var(--page-bg);
}

.dh-wl-kind {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  text-align: center;
  background: var(--border-light);
  color: var(--text);
}

.dh-wl-kind.is-critical {
  background: rgba(166, 38, 38, 0.1);
  color: var(--red);
}

.dh-wl-kind.is-warning {
  background: rgba(253, 126, 20, 0.1);
  color: #b45309;
}

.dh-wl-broker {
  display: block;
  font-size: 0.84375rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  margin-bottom: 0.125rem;
}

.dh-wl-broker:hover {
  color: var(--red);
}

.dh-wl-detail {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.dh-wl-age {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.dh-wl-action {
  font-size: 0.78125rem;
  font-weight: 500;
  color: var(--red);
  text-align: right;
  text-decoration: none;
}

.dh-wl-action:hover {
  color: var(--red-hover);
  text-decoration: underline;
}

/* The one row type that gets a solid button: something is blocked on the
   viewer personally, rather than merely assigned to them. */
.dh-wl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--red);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  text-decoration: none;
}

.dh-wl-btn:hover {
  background: var(--red-hover);
  color: #ffffff;
}

/* ── Activity feed ─────────────────────────────────────────────────────────
   One line per event, with the event's REAL status — a signature, a waiver and
   a plain completion are three different things and used to render identically
   (ISH-517). */

.dh-activity {
  display: flex;
  flex-direction: column;
}

.dh-act-row {
  display: grid;
  grid-template-columns: 1.625rem 1fr 5.25rem 6.25rem;
  gap: 0.875rem;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
}

.dh-act-row:last-child {
  border-bottom: none;
}

.dh-act-row:hover {
  background: var(--page-bg);
}

.dh-act-main {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
}

.dh-act-broker {
  font-size: 0.84375rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.dh-act-broker:hover {
  color: var(--red);
}

.dh-act-task {
  font-size: 0.78125rem;
  color: var(--text-secondary);
}

.dh-act-when {
  font-size: 0.71875rem;
  color: var(--text-label);
  text-align: right;
}

.dh-act-status {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.1875rem 0.5rem;
  border-radius: var(--radius);
  text-align: center;
  background: var(--border-light);
  color: var(--text);
}

.dh-act-status.is-complete,
.dh-act-status.is-signed {
  background: rgba(4, 120, 87, 0.12);
  color: #064e3b;
}

.dh-act-status.is-waived {
  background: rgba(253, 126, 20, 0.1);
  color: #b45309;
}

/* ── Action items rail ─────────────────────────────────────────────────────
   Replaces the uncapped one-card-per-flag list. Nineteen flag types exist and
   a rep can carry dozens of rows; grouped by type with a count, the age of the
   oldest and the rule's stage gate, the rail states the SHAPE of the backlog
   rather than enumerating it. */

.dh-rail-summary {
  padding: 0.875rem 1.125rem;
  border-bottom: 1px solid var(--border-light);
}

.dh-sev-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5625rem;
  background: var(--border-light);
}

.dh-sev-seg.is-critical {
  background: var(--red);
}

.dh-sev-seg.is-warning {
  background: var(--orange);
}

.dh-sev-legend {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.71875rem;
  color: var(--text-secondary);
}

.dh-sev-key {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.dh-sev-swatch {
  width: 7px;
  height: 7px;
  border-radius: 2px;
}

.dh-sev-swatch.is-critical {
  background: var(--red);
}

.dh-sev-swatch.is-warning {
  background: var(--orange);
}

.dh-sev-spacer {
  margin-left: auto;
  color: var(--text-label);
}

.dh-group {
  border-bottom: 1px solid var(--border-light);
}

.dh-group:last-child {
  border-bottom: none;
}

.dh-group.is-open {
  background: var(--page-bg);
}

.dh-group-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 1.125rem;
  border: none;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.dh-group-head:hover {
  background: var(--page-bg);
}

.dh-group-head:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: -2px;
}

.dh-group-bar {
  width: 3px;
  height: 30px;
  border-radius: 2px;
  background: var(--orange);
  flex-shrink: 0;
}

.dh-group-bar.is-critical {
  background: var(--red);
}

.dh-group-main {
  flex-grow: 1;
  min-width: 0;
}

.dh-group-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.125rem;
}

.dh-group-meta {
  font-size: 0.71875rem;
  color: var(--text-label);
}

.dh-group-count {
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.dh-group-chevron {
  color: var(--text-label);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.dh-group.is-open .dh-group-chevron {
  transform: rotate(90deg);
}

.dh-group-items {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0 1.125rem 0.75rem 2.0625rem;
}

.dh-group-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.625rem;
  font-size: 0.78125rem;
  color: var(--text);
  text-decoration: none;
}

.dh-group-item:hover {
  color: var(--red);
}

.dh-group-item-age {
  font-size: 0.6875rem;
  color: var(--text-label);
  flex-shrink: 0;
}

/* ── Compact person rows (team overview, by-rep breakdowns) ─────────────── */

.dh-person-row {
  display: flex;
  align-items: center;
  gap: 0.6875rem;
  padding: 0.6875rem 1.125rem;
  border-bottom: 1px solid var(--border-light);
}

.dh-person-row:last-child {
  border-bottom: none;
}

.dh-person-name {
  flex-grow: 1;
  min-width: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dh-person-name:hover {
  color: var(--red);
}

.dh-person-stat {
  text-align: right;
  flex-shrink: 0;
}

.dh-person-stat-value {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
}

.dh-person-stat-value.is-flagged {
  color: var(--red);
}

.dh-person-stat-label {
  font-size: 0.625rem;
  color: var(--text-label);
}

/* ── Avatar ────────────────────────────────────────────────────────────────
   Own class rather than the host pages' `.avatar`, so this file stands up on a
   page that does not happen to define one. */

.dh-avatar {
  width: 1.625rem;
  height: 1.625rem;
  border-radius: 50%;
  background: var(--border-light);
  color: var(--text);
  font-size: 0.625rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-decoration: none;
}

a.dh-avatar:hover {
  background: var(--red);
  color: #ffffff;
}

/* ── Empty states ──────────────────────────────────────────────────────────
   Two of them, because "nothing in your scope" and "nothing to do" look
   identical and mean opposite things. A new rep lands on a home page with no
   brokers at all; that is the app's first impression, not an edge case. */

.dh-empty {
  padding: 1.75rem 1.25rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.dh-empty-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.dh-empty-hint {
  font-size: 0.75rem;
  color: var(--text-label);
}

/* ── Responsive ────────────────────────────────────────────────────────────
   The strip breaks 4 → 2 before the page's own layout drops its right rail at
   1024px, so four cards never squeeze to unreadable widths in between. */

@media (max-width: 1150px) {
  .dh-kpi-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .dh-wl-row {
    grid-template-columns: 6.5rem 1fr 5.5rem;
  }

  .dh-wl-action,
  .dh-wl-btn {
    grid-column: 2 / -1;
    justify-self: start;
    text-align: left;
  }

  .dh-act-row {
    grid-template-columns: 1.625rem 1fr 5.25rem;
  }

  .dh-act-when {
    grid-column: 2 / -1;
    text-align: left;
  }
}

@media (max-width: 700px) {
  .dh-kpi-strip {
    grid-template-columns: minmax(0, 1fr);
  }

  .dh-wl-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.5rem;
  }

  .dh-wl-kind {
    justify-self: start;
  }

  .dh-wl-action,
  .dh-wl-btn {
    grid-column: auto;
  }
}
