/* ============================================================
 * Dashboard engine — KPI cards, HTML/CSS charts, feeds.
 * ============================================================ */

.dash-filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
  padding: 12px 14px; margin-bottom: 16px;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e2e6ee); border-radius: 10px;
}
.dash-filter { display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
.dash-filter label {
  font-size: calc(9.5px * var(--ui-font-scale, 1)); text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted, #6b7280); font-weight: 700;
}
.dash-filter select, .dash-filter input {
  padding: 7px 9px; border: 1px solid var(--border, #d5d9e0);
  border-radius: 6px; font: inherit; background: #fff;
}
.dash-live { display: inline-flex; align-items: center; gap: 6px;
  font-size: calc(11px * var(--ui-font-scale, 1)); color: var(--muted, #6b7280); margin-left: auto; }
.dash-updated { font-size: calc(11px * var(--ui-font-scale, 1)); color: var(--muted, #6b7280); margin-right: 4px; }
.dash-loading, .dash-empty {
  padding: 24px; text-align: center; color: var(--muted, #9ca3af);
  font-size: calc(12px * var(--ui-font-scale, 1));
}
.dash-empty { padding: 16px; }

/* --- KPI row ---------------------------------------------------------- */
.dash-kpis {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.dash-kpi {
  background: var(--surface, #fff); border: 1px solid var(--border, #e2e6ee);
  border-radius: 12px; padding: 14px 16px;
}
.dash-kpi-value { font-size: calc(22px * var(--ui-font-scale, 1)); font-weight: 800; line-height: 1.1; }
.dash-kpi-label { font-size: calc(11px * var(--ui-font-scale, 1)); font-weight: 600; color: var(--text, #334155); margin-top: 4px; }
.dash-kpi-sub { font-size: calc(10.5px * var(--ui-font-scale, 1)); color: var(--muted, #9ca3af); margin-top: 2px; }

/* --- Card grid -------------------------------------------------------- */
.dash-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.dash-card {
  background: var(--surface, #fff); border: 1px solid var(--border, #e2e6ee);
  border-radius: 12px; padding: 14px; display: flex; flex-direction: column;
}
.dash-card-wide { grid-column: span 2; }
@media (max-width: 700px) { .dash-card-wide { grid-column: span 1; } }
.dash-card-title {
  font-size: calc(11px * var(--ui-font-scale, 1)); font-weight: 700; text-transform: uppercase;
  letter-spacing: .4px; color: #475569; margin-bottom: 12px;
}
.dash-card-body { flex: 1; min-height: 60px; }

/* --- Vertical bars ---------------------------------------------------- */
.dash-vbars {
  display: flex; align-items: flex-end; gap: 8px; height: 150px;
  padding-top: 16px; overflow-x: auto;
}
.dash-vbar {
  flex: 1; min-width: 26px; display: flex; flex-direction: column;
  align-items: center; height: 100%; justify-content: flex-end; gap: 4px;
}
.dash-vbar-fill { width: 70%; min-height: 2px; border-radius: 4px 4px 0 0;
  transition: height .3s ease; }
.dash-vbar-val { font-size: calc(9.5px * var(--ui-font-scale, 1)); font-weight: 700; color: #475569; }
.dash-vbar-lbl { font-size: calc(9.5px * var(--ui-font-scale, 1)); color: var(--muted, #9ca3af); white-space: nowrap; }

/* --- Horizontal bars -------------------------------------------------- */
.dash-hbars { display: flex; flex-direction: column; gap: 8px; }
.dash-hbar { display: grid; grid-template-columns: 90px 1fr 44px; align-items: center; gap: 8px; }
.dash-hbar-lbl {
  font-size: calc(11px * var(--ui-font-scale, 1)); color: #334155; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dash-hbar-track { background: #eef2f7; border-radius: 999px; height: 12px; overflow: hidden; }
.dash-hbar-fill { height: 100%; border-radius: 999px; min-width: 2px; transition: width .3s ease; }
.dash-hbar-val { font-size: calc(11px * var(--ui-font-scale, 1)); font-weight: 700; color: #475569; text-align: right; }

/* --- Donut ------------------------------------------------------------ */
.dash-donut-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.dash-donut {
  width: 120px; height: 120px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center;
}
.dash-donut-hole {
  width: 74px; height: 74px; border-radius: 50%;
  background: var(--surface, #fff); display: grid; place-items: center;
}
.dash-donut-hole span { font-size: calc(16px * var(--ui-font-scale, 1)); font-weight: 800; color: #334155; }
.dash-legend { display: flex; flex-direction: column; gap: 5px; min-width: 120px; flex: 1; }
.dash-legend-row { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 8px; font-size: calc(11px * var(--ui-font-scale, 1)); }
.dash-legend-dot { width: 12px; height: 12px; border-radius: 3px; }
.dash-legend-lbl { color: #475569; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-legend-val { font-weight: 700; color: #334155; }

/* --- Tables ----------------------------------------------------------- */
.dash-table { width: 100%; border-collapse: collapse; font-size: calc(11.5px * var(--ui-font-scale, 1)); }
.dash-table th, .dash-table td {
  text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border-soft, #eef0f3);
}
.dash-table th { color: var(--muted, #6b7280); font-weight: 700; font-size: calc(10.5px * var(--ui-font-scale, 1)); text-transform: uppercase; }
.dash-table td.num, .dash-table th.num { text-align: right; }
.dash-table td:first-child { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Activity feed + mini lists --------------------------------------- */
.dash-feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 320px; overflow-y: auto; }
.dash-feed li { display: grid; grid-template-columns: 22px 1fr auto; align-items: baseline; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--border-soft, #f1f3f6); }
.dash-feed-icon { font-size: calc(12px * var(--ui-font-scale, 1)); }
.dash-feed-text { font-size: calc(11.5px * var(--ui-font-scale, 1)); color: #334155; }
.dash-feed-actor { color: var(--muted, #9ca3af); font-size: calc(10.5px * var(--ui-font-scale, 1)); }
.dash-feed-time { font-size: calc(10.5px * var(--ui-font-scale, 1)); color: var(--muted, #9ca3af); white-space: nowrap; }

.dash-mini-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.dash-mini-list li { display: flex; flex-direction: column; }
.dash-mini-main { font-size: calc(11.5px * var(--ui-font-scale, 1)); font-weight: 600; color: #334155; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-mini-sub { font-size: calc(10.5px * var(--ui-font-scale, 1)); color: var(--muted, #9ca3af); }

/* =====================================================================
 * Part B DMS upgrade — sections, executive tiles, lifecycle funnel,
 * trend, org roll-up, team, clearinghouse/payments, needs-attention.
 * StayCloud Pro idiom: white borderless cards, soft shadow, 8px radius.
 * ===================================================================== */

/* Section bar: sticky under the navbar + info bar. */
.dash-sections {
  position: sticky; top: calc(var(--sc-navbar-h, 56px) + var(--sc-infobar-h, 32px));
  z-index: 20; display: flex; gap: 4px; flex-wrap: wrap;
  margin: -4px 0 16px; padding: 6px;
  background: rgba(243, 244, 246, .92); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--divider, #e5e7eb);
}
.dash-sections a {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  font-size: 13px; font-weight: 500; color: #374151; text-decoration: none;
  border-radius: 999px; transition: background .12s, color .12s;
}
.dash-sections a:hover { background: #fff; color: var(--sc-primary, #1a5c3a); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.dash-sections a i { color: var(--sc-primary, #1a5c3a); }
.dash-sec-badge {
  min-width: 20px; padding: 1px 7px; font-size: 11px; font-weight: 700; color: #fff;
  background: var(--sc-accent, #e8722a); border-radius: 999px; text-align: center;
}

.dash-section { margin-bottom: 26px; scroll-margin-top: 150px; }
.dash-section-head {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px;
  flex-wrap: wrap; margin-bottom: 12px;
}
.dash-section-head h3 {
  display: flex; align-items: center; gap: 8px;
  font-size: 1.15rem; font-weight: 600; color: #212529;
}
.dash-section-head h3 i { color: var(--sc-primary, #1a5c3a); }
.dash-section-head p { margin-top: 3px; font-size: 13px; color: var(--text-muted, #6b7280); max-width: 920px; }
.dash-section-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dash-muted { font-size: 12px; color: var(--text-muted, #6b7280); }

/* Cards in the new sections follow StayCloud (borderless + shadow). */
.dash-section .dash-card, .dash-stat, .dash-step {
  border: none; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); border-radius: 8px; background: #fff;
}
.dash-section .dash-card-title { color: #374151; letter-spacing: .3px; }
.dash-title-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dash-grid-2 { grid-template-columns: 1fr; }
.dash-grid-2 .dash-card-wide { grid-column: auto; }

.dash-linkbtn {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px;
  font-size: 12.5px; font-weight: 500; color: var(--sc-primary, #1a5c3a);
  text-transform: none; letter-spacing: normal;
}
.dash-linkbtn:hover { text-decoration: underline; }

/* --- Executive tiles (StayCloud summary-card) ------------------------ */
.dash-stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.dash-stat { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 18px; }
.dash-stat-label { font-size: 13px; color: var(--text-muted, #6b7280); margin-bottom: 4px; }
.dash-stat-value { font-size: 1.75rem; font-weight: 500; line-height: 1.15; }
.dash-stat-sub { margin-top: 4px; font-size: 12px; color: var(--text-muted, #6b7280); }
.dash-stat-sub b { color: #374151; font-weight: 600; }
.dash-stat-icon {
  flex-shrink: 0; width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.35rem;
}
.tone-green  { color: #1a5c3a; } .dash-stat-icon.tone-green  { background: rgba(26, 92, 58, .1); }
.tone-orange { color: #c2410c; } .dash-stat-icon.tone-orange { background: rgba(232, 114, 42, .12); }
.tone-blue   { color: #2f5fc4; } .dash-stat-icon.tone-blue   { background: rgba(59, 111, 216, .1); }
.tone-red    { color: #dc3545; } .dash-stat-icon.tone-red    { background: rgba(220, 53, 69, .1); }
.tone-dark   { color: #0f2b1a; } .dash-stat-icon.tone-dark   { background: rgba(15, 43, 26, .08); }
.tone-muted  { color: #6c757d; } .dash-stat-icon.tone-muted  { background: rgba(108, 117, 125, .1); }

/* --- Lifecycle funnel -------------------------------------------------- */
.dash-funnel { display: flex; align-items: stretch; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.dash-step { flex: 1 1 0; min-width: 150px; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.dash-step-head { display: flex; align-items: center; justify-content: space-between; color: var(--sc-primary, #1a5c3a); }
.dash-step-no {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 11.5px; font-weight: 700; color: #fff; background: var(--sc-primary, #1a5c3a);
}
.dash-step-head i { font-size: 1.1rem; }
.dash-step-label { font-size: 12.5px; font-weight: 600; color: #374151; min-height: 2.5em; }
.dash-step-count { font-size: 1.6rem; font-weight: 600; color: #212529; line-height: 1.1; }
.dash-step-bar { height: 8px; background: #edf1ee; border-radius: 999px; overflow: hidden; }
.dash-step-bar span { display: block; height: 100%; min-width: 2px; background: #2d9960; border-radius: 999px; }
.dash-step-conv { font-size: 11.5px; color: var(--text-muted, #6b7280); }
.dash-step-conv b { color: #212529; }
.dash-step-arrow { display: flex; align-items: center; color: #c3cbc6; font-size: 1.1rem; }
.dash-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.dash-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px;
  font-size: 12.5px; color: #374151; background: #fff; border: 1px solid #e5e7eb; border-radius: 999px;
}
.dash-chip i { color: var(--text-muted, #6b7280); }
.dash-chip b { color: #212529; }

/* --- Trend line chart -------------------------------------------------- */
.dash-trend { position: relative; }
.dash-trend-svg { width: 100%; height: auto; display: block; overflow: visible; }
.dash-grid-line { stroke: #e5e7eb; stroke-width: 1; vector-effect: non-scaling-stroke; }
.dash-axis { font-size: 11px; fill: #6b7280; }
.dash-endlabel { font-size: 11.5px; font-weight: 600; fill: #374151; }
.dash-trend-svg polyline { vector-effect: non-scaling-stroke; }
.dash-crosshair { stroke: #9ca3af; stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.dash-hit { cursor: crosshair; }
.dash-tip {
  position: absolute; top: 8px; z-index: 5; min-width: 220px; padding: 8px 10px;
  font-size: 12px; background: #fff; border-radius: 8px; pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
}
.dash-tip-h { font-weight: 600; margin-bottom: 4px; color: #212529; }
.dash-tip-row { display: grid; grid-template-columns: 16px 1fr auto; align-items: center; gap: 6px; color: #374151; }
.dash-legend-inline { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 8px; }
.dash-lg { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #374151; }
.dash-lg-line { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.dash-lg-sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }

/* --- Org roll-up table -------------------------------------------------- */
.dash-org-card { padding: 0; overflow: hidden; }
.dash-table-wrap { overflow-x: auto; }
.dash-org-table, .dash-team-table { font-size: 13px; }
.dash-org-table td:first-child, .dash-team-table td:first-child { max-width: none; overflow: visible; }
.dash-org-table th, .dash-team-table th { background: #f9fafb; white-space: nowrap; }
.dash-org-table td { white-space: nowrap; }
.dash-org-name { display: flex; align-items: center; gap: 6px; min-width: 300px; }
.dash-org-label { overflow: hidden; text-overflow: ellipsis; max-width: 280px; }
.dash-caret, .dash-caret-sp { width: 20px; height: 20px; flex-shrink: 0; display: grid; place-items: center; border-radius: 4px; color: #6b7280; }
.dash-caret:hover { background: #f3f4f6; color: #212529; }
.dash-kind { color: var(--sc-primary, #1a5c3a); }
.kind-group { background: #f0faf4; }
.kind-group td { font-weight: 700; color: #0f3d26; }
.kind-org td { font-weight: 600; }
.kind-sub .dash-kind { color: #9ca3af; }
.dash-focus {
  margin-left: auto; width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center;
  color: #9ca3af; opacity: 0; transition: opacity .12s;
}
.dash-org-row:hover .dash-focus, .dash-focus:focus-visible { opacity: 1; }
.dash-focus:hover { background: var(--primary-soft, #e8f5ee); color: var(--sc-primary, #1a5c3a); }
.dash-zero { color: #c0c4cc; }
.dash-tag { padding: 0 6px; font-size: 10.5px; color: #6b7280; border: 1px solid #e5e7eb; border-radius: 6px; }
.dash-complete { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.dash-pbar { flex: 1; height: 8px; background: #edf1ee; border-radius: 999px; overflow: hidden; }
.dash-pbar span { display: block; height: 100%; background: #2d9960; border-radius: 999px; }
.dash-complete > span { font-size: 12px; font-weight: 600; color: #374151; min-width: 46px; text-align: right; }
.dash-org-search {
  width: 280px; padding: 6px 10px; border: 1px solid #dee2e6; border-radius: 6px; font: inherit; background: #fff;
}

/* --- Team tables -------------------------------------------------------- */
.dash-who { display: flex; align-items: center; gap: 8px; }
.dash-who small { display: block; font-size: 11px; color: #9ca3af; }
.dash-avatar {
  width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff; background: var(--sc-primary, #1a5c3a);
}
.dash-team-table td { white-space: nowrap; }
.dash-inline-bar { display: inline-block; width: 80px; height: 6px; margin-right: 8px; vertical-align: middle; background: #edf1ee; border-radius: 999px; overflow: hidden; }
.dash-inline-bar span { display: block; height: 100%; border-radius: 999px; }
.dash-pill-open { padding: 1px 8px; font-weight: 600; color: #7a4510; background: #fff3cd; border-radius: 999px; }

/* --- Clearinghouse & payments ----------------------------------------- */
.dash-mini-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.dash-mini-kpis div { font-size: 11.5px; color: #6b7280; line-height: 1.3; }
.dash-mini-kpis span { display: block; font-size: 1.1rem; font-weight: 600; color: #212529; }
.dash-hbar-money, .dash-section .dash-hbar { grid-template-columns: 120px 1fr auto; }
.dash-hbar-val small { font-weight: 500; color: #9ca3af; }
.dash-track-stack { position: relative; }
.dash-track-stack .dash-hbar-fill { position: absolute; left: 0; top: 0; }
.dash-fill-over { box-shadow: 2px 0 0 #fff; }

/* --- Needs attention ---------------------------------------------------- */
.dash-attn { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
.dash-attn-row {
  display: grid; grid-template-columns: 20px 1fr auto 64px; align-items: center; gap: 10px;
  padding: 10px 14px; background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.1);
  border-left: 4px solid #d1d5db;
}
.dash-attn-label { font-size: 13px; color: #374151; }
.dash-attn-count { font-size: 1.1rem; font-weight: 600; color: #212529; }
.sev-danger  { border-left-color: #dc3545; } .sev-danger  > i { color: #dc3545; }
.sev-warning { border-left-color: #e8722a; } .sev-warning > i { color: #e8722a; }
.sev-info    { border-left-color: #3b6fd8; } .sev-info    > i { color: #3b6fd8; }
.sev-ok      { border-left-color: #2d9960; opacity: .75; } .sev-ok > i { color: #2d9960; }
.sev-ok .dash-attn-count { color: #9ca3af; }

@media (max-width: 860px) {
  .dash-mini-kpis { grid-template-columns: 1fr 1fr; }
  .dash-org-search { width: 100%; }
  .dash-attn { grid-template-columns: 1fr; }
}
