/* Sales Overview (/sales/overview/) — page-specific styling on top of the
   shared erp.dashboards framework (static/erp/{tokens,base,components}.css).

   Layout B (2026-09-25): the whole page fits one 1440×900 screen. One
   header row (title, filters, health, profile), the KPI band, one line of
   mini-KPI chips, then four section tabs whose panels take the remaining
   viewport height (--so-panel-h, set by the script in index.html). Cards
   scroll inside themselves; the page does not. Below 1100px the panels
   drop the fixed height, the cards stack, and the page scrolls normally. */

.erp-content:has(> .sales-overview) { padding-top: var(--space-5); padding-bottom: var(--space-5); }
.sales-overview { display: flex; flex-direction: column; gap: var(--space-3); }
.so-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Header row -------------------------------------------------------- */
.so-bar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.so-bar__title { display: flex; align-items: baseline; gap: var(--space-3); margin-inline-end: auto; min-width: 0; }
.so-bar__title h1 { margin: 0; font-family: var(--font-display); font-size: var(--text-xl); font-weight: 600; line-height: 1.2; }
.so-bar__title p { margin: 0; font-size: var(--text-xs); color: var(--text-subtle); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.so-bar__actions { display: flex; align-items: center; gap: var(--space-2); flex: none; }
/* a <select> sizes itself to its longest option (a rep or method name can
   be 400px+) — cap it here and let the row shrink on phones */
.so-bar__actions select { max-width: 220px; min-width: 0; text-overflow: ellipsis; }
@media (max-width: 720px) {
  .so-bar__actions { flex: 1 1 100%; min-width: 0; flex-wrap: wrap; }
  .so-bar__actions form { min-width: 0; max-width: 100%; }
  .so-bar__actions select { max-width: 100%; }
}

.so-filters { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin: 0; }
.so-filters__field { margin: 0; }
.so-filters select, .so-filters input[type="date"] {
  width: auto; height: 32px; padding: 0 var(--space-3); font-size: var(--text-sm);
  border: 1px solid var(--line); border-radius: var(--radius-sm); background-color: var(--surface); color: var(--text);
}
.so-filters select { padding-inline-end: var(--space-7); max-width: 200px; }
.so-filters__field[data-filter-field="date_from"],
.so-filters__field[data-filter-field="date_to"] { display: none; }
.so-filters__field[data-filter-field="date_from"].is-visible,
.so-filters__field[data-filter-field="date_to"].is-visible { display: block; }
.so-filters__submit { height: 32px; }
/* With JS the dropdowns submit on change, so Apply is only needed for
   the custom date range. */
.so-filters.is-enhanced:not(.is-custom) .so-filters__submit { display: none; }
.so-filters__reset { font-size: var(--text-xs); font-weight: 600; color: var(--brand); text-decoration: none; white-space: nowrap; }
.so-filters__reset:hover { text-decoration: underline; }

/* Profile chip — header-sized. */
.profile-chip { display: flex; align-items: center; gap: var(--space-2); padding-block: 3px 3px; padding-inline: 3px var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--surface); flex: none; }
.profile-chip__avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: var(--brand-tint); color: var(--brand-strong);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: var(--text-2xs);
}
.profile-chip__name { font-family: var(--font-display); font-weight: 600; font-size: var(--text-xs); color: var(--text); line-height: 1.2; }
.profile-chip__meta { display: flex; gap: var(--space-2); font-size: var(--text-2xs); color: var(--text-muted); line-height: 1.2; }
.profile-chip__meta span + span { display: none; }

/* Health pill + reasons popover (replaces the full-width banner). */
.so-health { position: relative; }
.so-health__pill {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; height: 32px;
  padding: 0 var(--space-3); border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.so-health__pill::-webkit-details-marker { display: none; }
.so-health__pill:focus-visible { outline: 2px solid var(--focus-color); outline-offset: 2px; }
.so-health__dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.so-health--good .so-health__pill { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok); }
.so-health--warning .so-health__pill { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn); }
.so-health--critical .so-health__pill { background: var(--crit-bg); color: var(--crit-fg); border-color: var(--crit); }
.so-health__pop {
  position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 30; width: 320px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--elev-2);
  padding: var(--space-3) var(--space-4); display: flex; flex-direction: column; gap: var(--space-2);
}
.so-health__title { font-family: var(--font-display); font-weight: 700; font-size: var(--text-sm); }
.so-health--critical .so-health__title { color: var(--crit-fg); }
.so-health--warning .so-health__title { color: var(--warn-fg); }
.so-health--good .so-health__title { color: var(--ok-fg); }
.so-health__reasons { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-sm); }
.so-health__reasons a { color: var(--text); text-decoration: underline; text-underline-offset: 2px; }
.so-health__more { font-size: var(--text-xs); font-weight: 600; color: var(--brand); text-decoration: none; }

/* KPI band — the shared _kpis.html partial, tightened. */
.sales-overview .erp-kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--space-2); margin: 0; }
.sales-overview .erp-kpi { padding: var(--space-2) var(--space-3); }
.sales-overview .erp-kpi__label { font-size: var(--text-2xs); }
/* sized on the tile (cqi), not the window: the tile's width is what
   the number has to fit in, on a laptop and on a wide monitor alike */
.sales-overview .erp-kpi__value { font-size: clamp(var(--text-md), 10.5cqi, var(--text-xl)); white-space: nowrap; }
.sales-overview .erp-kpi__foot { font-size: var(--text-2xs); margin-top: var(--space-1); }
.sales-overview .erp-kpi__foot { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sales-overview .erp-kpi__label { margin-bottom: var(--space-1); line-height: 1.25; }

/* Mini-KPI chips — label + value on one line each. */
.so-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.so-chip {
  display: inline-flex; align-items: baseline; gap: 6px; padding: 3px var(--space-3);
  border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--surface);
  font-size: var(--text-xs); color: var(--text-muted); text-decoration: none; white-space: nowrap;
}
@media (max-width: 1400px) {
  .so-chips { gap: var(--space-1); }
  .so-chip { padding: 2px var(--space-2); font-size: var(--text-2xs); gap: var(--space-1); }
}
a.so-chip:hover { border-color: var(--brand); color: var(--text); }
.so-chip__value { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.so-chip--warning { background: var(--warn-bg); border-color: var(--warn); }
.so-chip--warning .so-chip__value { color: var(--warn-fg); }
.so-chip--negative { background: var(--crit-bg); border-color: var(--crit); }
.so-chip--negative .so-chip__value { color: var(--crit-fg); }

/* Section tabs ------------------------------------------------------ */
.so-tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.so-tab {
  display: inline-flex; align-items: center; gap: 6px; padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm); font-weight: 600; color: var(--text-muted); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.so-tab:hover { color: var(--text); }
.so-tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }
.so-tab:focus-visible { outline: 2px solid var(--focus-color); outline-offset: -2px; border-radius: var(--radius-xs); }
.so-count { font-size: var(--text-2xs); font-weight: 700; padding: 1px 7px; border-radius: var(--radius-pill); background: var(--surface-sunken); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.so-tab.is-active .so-count { background: var(--brand-tint); color: var(--brand-strong); }
.so-count--crit, .so-tab.is-active .so-count--crit { background: var(--crit-bg); color: var(--crit-fg); }
.so-count--warn, .so-tab.is-active .so-count--warn { background: var(--warn-bg); color: var(--warn-fg); }

/* Tab panels -------------------------------------------------------- */
.so-panel { display: grid; gap: var(--space-3); grid-template-columns: minmax(0, 1fr); }
.so-panel[hidden] { display: none; }
.so-area { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.so-area > .chart-panel, .so-area > .panel { flex: 1; min-height: 0; margin: 0; }
.so-stack { gap: var(--space-3); }
.so-stack > .chart-panel { flex: none; }
.so-stack > .chart-panel:last-child { flex: 1; }
.so-area--wide .erp-quick-actions { margin: 0; }

@media (min-width: 1101px) {
  .so-panel { height: var(--so-panel-h, auto); }
  .so-area > .chart-panel, .so-area > .panel { overflow: auto; }
  .so-panel--performance {
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "main side" "foot side";
  }
  .so-panel--performance .so-area--main { grid-area: main; }
  .so-panel--performance .so-area--side { grid-area: side; }
  .so-panel--performance .so-area--foot { grid-area: foot; }
  .so-panel--pipeline { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: minmax(0, 1fr); }
  .so-panel--team { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .so-panel--documents { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: minmax(0, 1fr) auto; }
  .so-panel--documents .so-area--wide { grid-column: 1 / -1; }
}
@media (min-width: 721px) and (max-width: 1100px) {
  .so-panel--pipeline, .so-panel--documents { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .so-panel--documents .so-area--wide { grid-column: 1 / -1; }
}

/* Pipeline tab: the donut gets the room the tab frees up. */
@media (min-width: 1101px) {
  .so-panel--pipeline .pipeline-widget { gap: var(--space-5); }
  .so-panel--pipeline .donut-chart--compact { gap: var(--space-7); padding-inline-start: var(--space-3); }
  .so-panel--pipeline .donut-chart--compact .donut-chart__svg { width: 200px; height: 200px; }
  .so-panel--pipeline .pipeline-widget__stages { font-size: var(--text-sm); gap: var(--space-3); }
  .so-panel--pipeline .pipeline-widget__swatch { width: 10px; height: 10px; }
}

/* Team tab: the week grid gets the height the tab frees up. */
@media (min-width: 1101px) {
  .so-panel--team .planning__day { min-height: 180px; }
}

/* Cockpit density for the cards inside the panels. */
.sales-overview .chart-panel { padding: var(--space-3) var(--space-4); }
.sales-overview .chart-panel__head { margin-bottom: var(--space-2); }
.sales-overview .line-chart__headline { margin-bottom: var(--space-2); }
.sales-overview .line-chart__headline-value { font-size: var(--text-2xl); }

/* Compact alerts card (Performance tab). */
.so-alerts:focus { outline: none; }
.so-alerts:focus-visible { outline: 2px solid var(--focus-color); outline-offset: 2px; }
.so-alerts__list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.so-alerts__item { display: flex; align-items: flex-start; gap: var(--space-2); padding: 7px 0; border-bottom: 1px solid var(--line); }
.so-alerts__item:last-child { border-bottom: none; }
.so-alerts__item .alert-card__severity { flex: none; margin-top: 1px; }
.so-alerts__msg {
  font-size: var(--text-sm); color: var(--text); text-decoration: none; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
a.so-alerts__msg:hover { color: var(--brand); }

/* My Sales — personal cockpit-within-the-cockpit. */
.my-sales__body { display: flex; flex-direction: column; gap: var(--space-4); }
.my-sales__id { display: flex; align-items: center; gap: var(--space-3); }
.my-sales__avatar {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  background: var(--brand-tint); color: var(--brand-strong);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: var(--text-md);
}
.my-sales__name { font-family: var(--font-display); font-weight: 600; font-size: var(--text-md); color: var(--text); }
.my-sales__meta { display: flex; gap: var(--space-3); font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }
.my-sales__stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.my-sales__stat-label { font-size: var(--text-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-subtle); margin-bottom: var(--space-1); }
.my-sales__stat-line { font-size: var(--text-sm); color: var(--text); }
.my-sales__stat-line--warning { color: var(--crit-fg); font-weight: 600; }
.my-sales__stat-value { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 600; color: var(--text); }
.my-sales__stat-value--warning { color: var(--crit-fg); }

/* Order-to-cash funnel — one document-flow stage per column. */
.sales-funnel { display: flex; align-items: stretch; gap: var(--space-2); }
.sales-funnel__stage {
  flex: 1; display: flex; flex-direction: column; align-items: center; text-decoration: none; color: inherit;
  padding: var(--space-2); border-radius: var(--radius-sm); min-width: 0;
}
.sales-funnel__stage:hover { background: var(--surface-sunken); }
.sales-funnel__stage:focus-visible { outline: 2px solid var(--focus-color); outline-offset: 2px; }
.sales-funnel__label { font-size: var(--text-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-subtle); margin-bottom: var(--space-2); }
.sales-funnel__track { width: 100%; height: 48px; display: flex; align-items: flex-end; background: var(--surface-sunken); border-radius: var(--radius-xs); overflow: hidden; }
.sales-funnel__fill { width: 100%; background: var(--brand); border-radius: var(--radius-xs); min-height: 3px; }
.sales-funnel__count { font-family: var(--font-display); font-weight: 600; font-size: var(--text-lg); margin-top: var(--space-2); color: var(--text); }
.sales-funnel__amount { font-size: var(--text-2xs); color: var(--text-muted); }
.sales-funnel__arrow { flex: none; display: flex; align-items: center; color: var(--text-subtle); font-size: var(--text-md); }

.empty-state--sm { font-size: var(--text-xs); padding: var(--space-2) 0; }

/* Pipeline-by-stage — compact donut + a stage/count/value list instead
   of a bare percentage legend, so "expected revenue" (§ row 3 widget
   1) is on the widget, not just implied by the slice size. */
.pipeline-widget { display: flex; flex-direction: column; gap: var(--space-3); }
.pipeline-widget__stat { display: flex; align-items: baseline; gap: var(--space-2); }
.pipeline-widget__stat-label { font-size: var(--text-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-subtle); }
.pipeline-widget__stat-value { font-family: var(--font-display); font-weight: 700; font-size: var(--text-md); color: var(--text); }
.donut-chart--compact { gap: var(--space-4); }
.donut-chart--compact .donut-chart__svg { width: 108px; height: 108px; }
.pipeline-widget__stages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-xs); flex: 1; min-width: 0; }
.pipeline-widget__stages li { display: flex; align-items: center; gap: var(--space-2); }
.pipeline-widget__swatch { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.pipeline-widget__swatch--1 { background: var(--chart-cat-1); }
.pipeline-widget__swatch--2 { background: var(--chart-cat-2); }
.pipeline-widget__swatch--3 { background: var(--chart-cat-3); }
.pipeline-widget__swatch--4 { background: var(--chart-cat-4); }
.pipeline-widget__swatch--5 { background: var(--chart-cat-5); }
.pipeline-widget__swatch--6 { background: var(--chart-cat-6); }
.pipeline-widget__stage-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }
.pipeline-widget__stage-count { color: var(--text-subtle); }
.pipeline-widget__stage-value { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

/* Sales performance ranking — erp-ranking rows plus a meta line
   (orders · target achievement) the generic ranking partial doesn't
   carry. */
.rep-performance__row { align-items: flex-start; }
.rep-performance__meta { font-size: var(--text-2xs); color: var(--text-subtle); margin-top: 2px; }
.rep-performance__meta--warn { color: var(--crit-fg); font-weight: 600; }

/* Top customers/products toggle — a GET-param tab pair, no JS. */
.top-toggle__tabs { display: flex; gap: var(--space-1); margin-bottom: var(--space-2); }
.top-toggle__tab { font-size: var(--text-xs); font-weight: 600; padding: 3px var(--space-3); border-radius: var(--radius-pill); color: var(--text-muted); text-decoration: none; background: var(--surface-sunken); }
.top-toggle__tab.is-active { background: var(--brand); color: #fff; }

/* Recent activity feed. */
.recent-feed { display: flex; flex-direction: column; }
.recent-feed__row { display: flex; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--line); font-size: var(--text-sm); }
.recent-feed__row:last-child { border-bottom: none; }
.recent-feed__text a { font-weight: 600; }
.recent-feed__meta { flex: none; color: var(--text-subtle); font-size: var(--text-xs); white-space: nowrap; }

/* Planning — day-list hybrid (Activity has no time-of-day, so this
   is a count/list view per day rather than an hour grid) + the
   manager-only team grid underneath. */
.planning__all { font-size: var(--text-xs); font-weight: 600; }
.planning__body { display: flex; flex-direction: column; gap: var(--space-4); }
.planning__week { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--space-2); }
.planning__day { background: var(--surface-sunken); border-radius: var(--radius-sm); padding: var(--space-2); min-height: 76px; }
.planning__day--today { background: var(--brand-tint); }
.planning__day-head { display: flex; justify-content: space-between; align-items: center; font-size: var(--text-2xs); font-weight: 600; color: var(--text-muted); margin-bottom: var(--space-1); }
.planning__items { display: flex; flex-direction: column; gap: 3px; }
.planning__item { display: block; text-decoration: none; color: inherit; font-size: var(--text-2xs); line-height: 1.3; padding: 2px 4px; border-radius: var(--radius-xs); background: var(--surface); }
.planning__item:hover { background: var(--surface-hover, var(--surface)); }
.planning__item--overdue { border-inline-start: 2px solid var(--crit-fg); }
.planning__item-type { font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; color: var(--text-subtle); margin-inline-end: 3px; }
.planning__item-subject { color: var(--text); }
.planning__item-target { color: var(--text-muted); display: block; }
.planning__day-empty { color: var(--text-subtle); font-size: var(--text-xs); text-align: center; padding-top: var(--space-2); }
.planning__team-title { font-size: var(--text-2xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-subtle); margin-bottom: var(--space-2); }
.planning__team-table { font-size: var(--text-xs); }


@media (max-width: 1100px) {
  .sales-overview .erp-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .planning__week { grid-template-columns: repeat(4, 1fr); }
  .my-sales__stats { grid-template-columns: 1fr; }
}

/* Mobile: the header stacks, filters take the full width, and the four
   widgets below reflow internally (§ mobile UX pass, phase 4) — the
   7-day planning grid becomes a day list, the funnel's stage row becomes
   a stage column, the donut+legend pair stacks, and a long activity
   line no longer fights its timestamp for space. */
@media (max-width: 720px) {
  .so-chips { display: none; } /* the .m-kpi-list cards take over */
  .so-bar__title { flex-basis: 100%; flex-direction: column; gap: 2px; }
  .so-bar__title p { white-space: normal; }
  .so-filters { flex: 1 1 100%; }
  .so-filters__field { flex: 1 1 140px; }
  .so-filters select { max-width: none; width: 100%; }
  .profile-chip__text { display: none; }
  .planning__week { grid-template-columns: 1fr; }
  .sales-funnel { flex-direction: column; }
  .sales-funnel__arrow { transform: rotate(90deg); align-self: center; }
  .donut-chart--compact { flex-direction: column; align-items: flex-start; }
  .recent-feed__row { flex-direction: column; align-items: flex-start; gap: 2px; }
}
