/* Dashboards, widgets, the Client Overview tab and the staff preview. Owned by the dashboards work package.
   Builds on app.css (cards, .dash-grid, .kpi, .pacing, .funnel, .gallery, .score...). */

/* ── Page head ─────────────────────────────────────────────────────────── */
.dash-head { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.dash-head .page-title { margin-bottom: 0; }
.page-title__meta time { white-space: nowrap; }
.section-title { font-size: 15px; margin-bottom: 12px; }

/* Period picker: segmented links + a custom range form */
.period-picker { align-items: center; }
.period-custom { display: inline-flex; align-items: flex-end; gap: 6px; flex-wrap: wrap; padding: 3px 6px; border-radius: 8px; }
.period-custom.is-active { background: #eef0f3; }
.period-custom label { display: flex; flex-direction: column; gap: 2px; }
.period-custom__label { font-size: 11px; color: var(--text-3); font-weight: 500; }
.period-custom input[type="date"] { height: 30px; padding: 2px 6px; font-size: 13px; width: auto; }
.segmented a:focus-visible, .period-custom input:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 1px; }
.period-picker--compact .segmented a { padding: 4px 8px; font-size: 12px; }

/* ── Widget grid and cards ─────────────────────────────────────────────── */
/* Screen-reader-only text (.sr-only is position: absolute) must stay inside its scrolling table, or a
   wide table widens the whole page on phones. */
.widget, .table-wrap, .segmented { position: relative; }
.widget .card__title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.widget__flag { font-size: 11px; }
.widget--added { outline: 2px solid var(--good); outline-offset: 2px; }
.widget--changed { outline: 2px solid var(--info); outline-offset: 2px; }
.widget__error { margin: 0; color: var(--bad); font-size: 13px; }
.widget__empty { margin: 0; color: var(--text-3); font-size: 13px; padding: 12px 0; }
.widget--empty .card__body { display: flex; align-items: center; min-height: 64px; }
.widget__foot { display: flex; flex-direction: column; gap: 4px; }
.widget__notes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.widget__notes li { padding-left: 10px; position: relative; }
.widget__notes li::before { content: "*"; position: absolute; left: 0; }
.widget__updated { color: var(--text-3); }
.widget__updated--stale { color: var(--warn); }

/* ── Charts ─────────────────────────────────────────────────────────────── */
/* Until Chart.js draws, the data table is what people see; then it stays for screen readers only. */
.chart .chart-box, .chart .chart-legend { display: none; }
.chart.is-rendered .chart-box { display: block; }
.chart.is-rendered .chart-legend { display: flex; }
.chart.is-rendered .chart-fallback { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* Hidden, the table must not be a scroll container: browsers make those keyboard-focusable, so Tab would
   stop on an invisible box. Screen readers still read the table. */
.chart.is-rendered .chart-fallback .table-wrap { overflow: visible; }
.chart { position: relative; }
.chart-fallback { max-height: 320px; overflow: auto; }
.chart-data { font-size: 12px; }
.chart-data th[scope="row"] { font-weight: 400; color: var(--text-2); white-space: nowrap; }
.chart-legend { list-style: none; margin: 10px 0 0; padding: 0; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-2); }
.chart-legend li { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend__swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--swatch, var(--brand)); display: inline-block; flex-shrink: 0; }
.chart-legend .is-compare .chart-legend__swatch { background: transparent; border: 2px dashed var(--swatch, var(--brand)); }

/* Donut: chart next to its legend table when the card is wide enough for both, the legend under the chart
   otherwise (flex-wrap moves it down once its content doesn't fit beside the chart). The legend never runs
   past the card: long names truncate, amounts stay whole. */
.donut { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; justify-content: center; }
.donut__chart { position: relative; flex: 0 0 180px; height: 180px; display: none; }
.donut.is-rendered .donut__chart { display: block; }
table.donut__legend { flex: 1 1 240px; width: auto; min-width: 0; max-width: 100%; }
.donut__total { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.donut__total span { font-weight: 600; font-size: 15px; }
.donut__legend { font-size: 12px; }
.donut__legend th[scope="row"] { font-weight: 400; }
.donut__legend .chart-legend__swatch { vertical-align: middle; margin-right: 8px; }
.donut__legend .entity { display: inline-block; vertical-align: middle; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── KPI cards ─────────────────────────────────────────────────────────── */
.kpi__label .badge { height: 18px; font-size: 10px; padding: 0 6px; }
.kpi__label span:first-child { overflow: hidden; text-overflow: ellipsis; }
.kpi__meta { align-items: center; }
.kpi__against { color: var(--text-3); }
.kpi__target { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); margin-top: 6px; flex-wrap: wrap; }
.kpi__progress { display: inline-block; width: 64px; height: 6px; border-radius: 3px; background: #eef0f3; overflow: hidden; vertical-align: middle; }
.kpi__progress span { display: block; height: 100%; background: var(--brand); border-radius: 3px; }
.kpi__progress--wide { width: 100%; max-width: 260px; }
.kpi__note { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.kpi__spark { display: none; }
.kpi__spark.is-rendered { display: block; }
.kpi__spark--big { height: 48px; }
.kpi--big { border: 0; padding: 0; }

/* ── Targets ────────────────────────────────────────────────────────────── */
.target-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.target-item__head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.target-item__label { font-weight: 500; }
.target-item__value { font-variant-numeric: tabular-nums; }
.target-item__bar { display: flex; align-items: center; gap: 8px; margin-top: 4px; }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.dash-table th[scope="row"] { font-weight: 400; text-align: left; }
/* Deltas sit under the value, which keeps half-width tables narrow. */
.dash-table td.num .delta, .funnel__value .delta { display: block; margin: 0; line-height: 1.3; }
.entity-cell { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 360px; }
.entity-cell .entity { display: block; min-width: 0; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: inherit; }
.entity-cell a.entity { color: var(--accent-ink); }
.thumb { width: 32px; height: 32px; object-fit: cover; border-radius: 4px; flex-shrink: 0; background: #f3f4f6; }
.platform-chip { display: inline-flex; align-items: center; gap: 4px; height: 18px; padding: 0 6px; border-radius: 999px; font-size: 11px; font-weight: 500; white-space: nowrap; color: var(--text-2); background: #f3f4f6; flex-shrink: 0; }
.platform-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--chip, var(--text-3)); }
.th-sort { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; border-radius: 4px; }
.th-sort:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }
.th-sort__icon::after { content: "↕"; opacity: 0.35; font-size: 10px; }
th[aria-sort="ascending"] .th-sort__icon::after { content: "↑"; opacity: 0.9; }
th[aria-sort="descending"] .th-sort__icon::after { content: "↓"; opacity: 0.9; }
.th-sub { display: block; font-weight: 400; font-size: 11px; color: var(--text-3); }
.comparison-table td.num, .comparison-table th.num { min-width: 92px; }

/* ── Funnel ─────────────────────────────────────────────────────────────── */
.funnel { list-style: none; margin: 0; padding: 0; }
.funnel__item { display: flex; flex-direction: column; gap: 2px; }
.funnel__step { grid-template-columns: minmax(90px, 150px) minmax(0, 1fr) auto; }
.funnel__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.funnel__track { display: block; background: #f3f4f6; border-radius: 4px; }
.funnel__bar { display: block; }
.funnel__value { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; font-weight: 500; }
.funnel__rate { padding-left: 0; margin-left: min(160px, 30%); }
.funnel__overall { margin: 12px 0 0; color: var(--text-2); }

/* ── Gallery ────────────────────────────────────────────────────────────── */
.gallery { list-style: none; margin: 0; padding: 0; }
img.gallery__img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #f3f4f6; }
.gallery__img--empty { width: 100%; }
.gallery__name a { color: inherit; }
.gallery__stats { margin: 4px 0 0; }
.gallery__stats dt { color: var(--text-3); }
.gallery__stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }

/* ── Pacing ─────────────────────────────────────────────────────────────── */
.pacing__item { display: flex; flex-direction: column; gap: 4px; }
.pacing__item--total { border-top: 1px solid var(--border); padding-top: 12px; }
.pacing__item--total .pacing__label { font-weight: 600; }
.pacing__row { grid-template-columns: minmax(80px, 120px) minmax(0, 1fr) auto; }
.pacing__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pacing__fill--under { background: #f59e0b; }
.pacing__fill--over { background: #ef4444; }
.pacing__fill--no_budget { background: var(--border-strong); }
.pacing__meta { white-space: normal; margin-left: min(132px, 30%); }

/* ── Health score ───────────────────────────────────────────────────────── */
.score__meta { margin-top: 4px; }
.score-parts { margin-top: 14px; font-size: 13px; }
.score-parts summary { cursor: pointer; color: var(--accent-ink); font-weight: 500; }
.score-parts summary:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }
.score-parts .table { margin-top: 8px; }

/* ── Alerts and observations ───────────────────────────────────────────── */
.insight__title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.insight__date { font-size: 11px; color: var(--text-3); margin-top: 4px; }
.insight--draft { border-left-style: dashed; background: #fffdf5; }
.all-clear { margin: 0; }

/* ── Client Overview ────────────────────────────────────────────────────── */
.overview > * + * { margin-top: 28px; }
.overview-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 24px; align-items: start; }
.overview-side { display: flex; flex-direction: column; gap: 24px; }
.link-cards { list-style: none; margin: 0; padding: 0; }
.link-cards > li { display: flex; }
.link-cards .link-card { flex: 1; align-items: center; }
.link-card__text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.link-card__desc { overflow: hidden; text-overflow: ellipsis; }
.link-card__go { color: var(--text-3); font-size: 14px; }
a.link-card:focus-visible, .glance__card:focus-visible, .service-card:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 2px; }
.icon { display: block; }
.overview-notes { display: grid; gap: 12px; margin-top: 16px; }
.overview-note { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.overview-note h3 { margin-bottom: 4px; }
.overview-note p { margin: 0; color: var(--text-2); }
.empty--inline { background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 18px 16px; }
.empty--inline .empty__title { margin-bottom: 8px; }

.glance__head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.glance__head .section-title { margin-bottom: 8px; }
.glance__note { margin: 0 0 10px; color: var(--text-2); }
.glance__list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.glance__list > li { display: flex; }
.glance__card { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--brand); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text); text-decoration: none !important; transition: border-color 0.12s, transform 0.12s; }
.glance__card:hover { transform: translateY(-1px); border-color: var(--brand); }
.glance__service { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); font-weight: 600; }
.glance__label { font-size: 13px; color: var(--text-2); }
.glance__value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; white-space: nowrap; }
.glance__card .pill-delta { align-self: flex-start; }
.glance__none { font-size: 12px; color: var(--text-3); }

.call-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.call-card + .call-card { margin-top: 12px; }
.call-card__head { display: flex; gap: 12px; align-items: flex-start; }
.call-card__title { font-weight: 600; }
.call-card__when { font-size: 15px; }
.call-card__meta { font-size: 12px; color: var(--text-3); }
.call-card__desc { margin: 0; color: var(--text-2); font-size: 13px; }
.call-card__next { font-size: 13px; color: var(--text-2); margin-top: 4px; }

.team-list { list-style: none; margin: 0; padding: 0; }
.team-list--stack { grid-template-columns: 1fr; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; gap: 14px; }
.team-member { align-items: flex-start; }
.team-member__avatar img { width: 100%; height: 100%; object-fit: cover; }
.team-member__text { min-width: 0; }
.team-member__contact { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; font-size: 13px; }
.team-member__contact a { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.team-member__contact a span { overflow: hidden; text-overflow: ellipsis; }
.team-member__contact .icon { width: 14px; height: 14px; flex-shrink: 0; }

.service-cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.service-cards > li { display: flex; }
.service-card { flex: 1; display: flex; flex-direction: column; gap: 6px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text); text-decoration: none !important; transition: border-color 0.12s; }
.service-card:hover { border-color: var(--brand); }
.service-card__title { font-weight: 600; font-size: 15px; }
.service-card__desc { font-size: 13px; color: var(--text-3); }
.service-card__go { margin-top: auto; padding-top: 6px; font-size: 13px; color: var(--accent-ink); font-weight: 500; }

/* ── Staff preview (AI studio iframe) ──────────────────────────────────── */
body.preview-page { background: var(--bg); }
.preview-main { padding: 0 20px 32px; max-width: 1360px; margin: 0 auto; }
.preview-bar { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border); margin: 0 -20px 16px; padding: 8px 20px 0; }
.preview-bar__row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-bottom: 8px; }
.preview-bar__summary { font-size: 13px; color: var(--text-2); flex: 1; min-width: 160px; }
.preview-bar__views { margin-left: auto; }
.preview-bar__tabs { margin-top: 2px; }
.preview-report { padding-top: 4px; }
.preview-clients { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.preview-clients .link-card { align-items: center; flex-wrap: wrap; }
/* A proposal from Claude through MCP: who proposed it, text checks, Apply and Discard. */
.preview-proposal { display: grid; gap: 8px; margin: 0 0 16px; }
.preview-proposal p { margin: 0; }
.preview-proposal ul { margin: 6px 0 0; padding-left: 18px; }
.preview-proposal__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.preview-proposal__actions .api-form { margin: 0; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .w-quarter { grid-column: span 6; }
  .w-third { grid-column: span 6; }
  .w-two_thirds { grid-column: span 12; }
}
@media (max-width: 860px) {
  .overview-grid { grid-template-columns: minmax(0, 1fr); }
  .dash-grid { gap: 12px; }
  .w-quarter, .w-third, .w-half, .w-two_thirds, .w-full { grid-column: span 12; }
  .report-widgets > .card { grid-column: span 12; }
}
@media (max-width: 560px) {
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 10px 12px; }
  /* Two cards a row: long labels ("Lead-to-admission rate", "Cost per result" with its badge) wrap instead of clipping. */
  .kpi__label { white-space: normal; flex-wrap: wrap; row-gap: 2px; }
  .kpi__label span:first-child { overflow: visible; }
  .kpi__value { font-size: 20px; }
  .kpi--big .kpi__value { font-size: 28px; }
  .donut__chart { flex-basis: 160px; height: 160px; }
  table.donut__legend { flex-basis: 100%; }
  .pacing__row { grid-template-columns: minmax(0, 1fr) auto; }
  .pacing__row .pacing__bar { grid-column: 1 / -1; grid-row: 2; }
  .pacing__meta { margin-left: 0; }
  .funnel__step { grid-template-columns: minmax(0, 1fr) auto; }
  .funnel__step .funnel__track { grid-column: 1 / -1; grid-row: 2; }
  .funnel__rate { margin-left: 0; }
  /* Names wrap to two lines instead of truncating until rows look alike ("FM | Prospecting | Broad | …"). */
  .dash-table th[scope="row"] { white-space: normal; }
  .entity-cell { flex-direction: column; align-items: flex-start; gap: 3px; max-width: 220px; min-width: 170px; }
  .entity-cell .entity { max-width: none; white-space: normal; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; line-height: 1.35; }
  .glance__value { font-size: 22px; }
  .period-custom { width: 100%; }
}

/* ── Motion and print ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .glance__card, .link-card, .service-card { transition: none; }
  .glance__card:hover, a.link-card:hover { transform: none; }
}
@media print {
  .period-picker, .period-custom, .preview-bar, .th-sort__icon { display: none !important; }
  .th-sort { cursor: default; }
  .widget--added, .widget--changed { outline: 0; }
  .dash-grid { gap: 10px; }
  .kpi-row { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
}
body.print-mode .th-sort__icon { display: none; }
