/* ========================================================================
   Process Progress matrix — scoped styles.
   Uses --mud-palette-* variables so light + dark themes both work.
   Cell tints are color-mix blends of semantic palette colors with the
   current surface, so contrast stays correct in either mode.
   ======================================================================== */


/* ============================  HERO HEADER  ============================ */
.hero-card {
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--mud-palette-primary) 8%, var(--mud-palette-surface)),
        var(--mud-palette-surface));
    border-left: 4px solid var(--mud-palette-primary);
}
.hero-title { color: var(--mud-palette-text-primary); font-weight: 600; }
.hero-sub   { color: var(--mud-palette-text-secondary); }

.hero-right { gap: 0; }
.hero-export { white-space: nowrap; }
.hero-pct-wrap { position: relative; width: 100px; height: 100px; }
.hero-pct-text {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    pointer-events: none;
}
.hero-pct-num   { font-size: 1.4rem; font-weight: 700; color: var(--mud-palette-text-primary); line-height: 1; }
.hero-pct-label { font-size: 0.7rem; color: var(--mud-palette-text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }


/* ============================  KPI GRID  ============================ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    margin-top: 16px;
}
@media (max-width: 900px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 540px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }

.kpi-tile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: 8px;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-divider);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.kpi-tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--mud-palette-overlay-light);
}
.kpi-icon { color: var(--mud-palette-text-secondary); }
.kpi-text { display: flex; flex-direction: column; line-height: 1.1; }
.kpi-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--mud-palette-text-primary);
}
.kpi-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--mud-palette-text-secondary);
}

.kpi-primary  .kpi-icon  { color: var(--mud-palette-primary); }
.kpi-tertiary .kpi-icon  { color: var(--mud-palette-tertiary); }
.kpi-success  .kpi-icon  { color: var(--mud-palette-success); }
.kpi-warning  .kpi-icon  { color: var(--mud-palette-warning); }
.kpi-info     .kpi-icon  { color: var(--mud-palette-info); }
.kpi-error    .kpi-icon  { color: var(--mud-palette-error); }

/* Each color modifier sets --pp-accent so the active-state ring + value color
   follow the tile's own palette color, not a hardcoded primary. */
.kpi-primary  { --pp-accent: var(--mud-palette-primary);  border-top: 3px solid var(--pp-accent); }
.kpi-tertiary { --pp-accent: var(--mud-palette-tertiary); border-top: 3px solid var(--pp-accent); }
.kpi-success  { --pp-accent: var(--mud-palette-success);  border-top: 3px solid var(--pp-accent); }
.kpi-warning  { --pp-accent: var(--mud-palette-warning);  border-top: 3px solid var(--pp-accent); }
.kpi-info     { --pp-accent: var(--mud-palette-info);     border-top: 3px solid var(--pp-accent); }
.kpi-error    { --pp-accent: var(--mud-palette-error);    border-top: 3px solid var(--pp-accent); }

.kpi-clickable { cursor: pointer; }
.kpi-clickable:hover {
    background: color-mix(in srgb, var(--pp-accent) 6%, var(--mud-palette-surface));
}
.kpi-active {
    box-shadow: 0 0 0 2px var(--pp-accent), 0 4px 12px var(--mud-palette-overlay-light);
}
.kpi-active .kpi-value { color: var(--pp-accent); }

/* Banner uses --pp-accent so the color matches whichever KPI tile was clicked.
   Default is primary; the .filter-color-* modifiers below override it. */
.filter-active {
    --pp-accent: var(--mud-palette-primary);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 18px;
    background: color-mix(in srgb, var(--pp-accent) 18%, var(--mud-palette-surface));
    border: 1px solid var(--pp-accent);
    color: var(--mud-palette-text-primary);
    font-size: 0.85rem;
}
.filter-active strong       { color: var(--pp-accent); font-size: 1.05rem; }
.filter-active .filter-hint { color: var(--mud-palette-text-secondary); }

.filter-color-success { --pp-accent: var(--mud-palette-success); }
.filter-color-warning { --pp-accent: var(--mud-palette-warning); }
.filter-color-info    { --pp-accent: var(--mud-palette-info); }
.filter-color-error   { --pp-accent: var(--mud-palette-error); }


/* ============================  STATUS MIX BAR  ============================ */
.status-mix-bar {
    display: flex;
    width: 100%;
    height: 14px;
    border-radius: 7px;
    overflow: hidden;
    background: var(--mud-palette-action-disabled-background);
    box-shadow: inset 0 1px 3px var(--mud-palette-overlay-light);
}
.status-mix-seg {
    height: 100%;
    transition: filter 0.15s ease;
}
.status-mix-seg:hover { filter: brightness(1.15); }

.status-mix-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: center;
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}
.status-mix-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 2px;
    margin-right: 4px;
    vertical-align: middle;
}
.status-mix-legend-label  { margin-right: 6px; }
.status-mix-legend-count  { color: var(--mud-palette-text-primary); font-weight: 600; margin-left: 4px; }

/* segment / dot colors -- key is the lowercased status with whitespace -> '-'
   and parens -> '_' to keep CSS class names valid. */
.seg-completed,         .dot-completed         { background: var(--mud-palette-success); }
.seg-draft,             .dot-draft             { background: var(--mud-palette-warning); }
.seg-pending,           .dot-pending           { background: color-mix(in srgb, var(--mud-palette-info) 70%, var(--mud-palette-surface)); }
.seg-in-process,        .dot-in-process        { background: var(--mud-palette-info); }
.seg-skipped-_override_, .dot-skipped-_override_ { background: var(--mud-palette-action-disabled); }
.seg-form-skipped,      .dot-form-skipped      { background: var(--mud-palette-error); }


/* ============================  TAB CONTAINER  ============================ */
.pp-tab-panel {
    background: var(--mud-palette-surface);
    padding: 0;
}

/* The matrix's own scroll container -- guarantees position:sticky works
   regardless of any MudGrid/MudItem wrapping above. */
.matrix-scroll-wrap {
    overflow-x: auto;
    overflow-y: visible;
    width: 100%;
    background: var(--mud-palette-surface);
    padding: 8px;
}

/* Wrapper around MudTabs.  Hosts the filter banner as an absolutely-positioned
   overlay on the right side of the tab strip -- so activating the filter never
   shifts page layout, the banner just appears in the empty space next to the
   tab buttons. */
.tabs-banner-host {
    position: relative;
}

.filter-on-tab {
    position: absolute;
    top: 8px;
    right: 12px;
    z-index: 10;
}


/* ============================  MATRIX  ============================ */
.process-progress-matrix {
    /* IMPORTANT: do NOT set table-layout: fixed.  With fixed layout the
       browser ignores intrinsic content widths and tries to fit the table
       to its container width, which compresses Person+Location together
       when there are many form columns.  Use the default auto layout and
       enforce per-cell widths via min-width/max-width pairs on the actual
       cells -- that gets us predictable widths AND a table that grows
       beyond viewport so horizontal scroll triggers.

       border-collapse: separate (with border-spacing: 0) is required so
       sticky <th>/<td> can actually be on top of scrolling cells via
       z-index -- Chromium has a long-standing bug where collapse blocks
       sticky z-index. */
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12px;
    color: var(--mud-palette-text-primary);
}

.process-progress-matrix col.col-person   { width: 200px; }
.process-progress-matrix col.col-location { width: 160px; }
.process-progress-matrix col.col-form     { width: 150px; }
.process-progress-matrix col.col-rowtotal { width: 130px; }

.process-progress-matrix th,
.process-progress-matrix td {
    /* With border-collapse: separate, full borders would double up at cell joins.
       Use only right+bottom; top+left come from neighbors / the table edge. */
    border-right:  1px solid var(--mud-palette-table-lines);
    border-bottom: 1px solid var(--mud-palette-table-lines);
    padding: 4px 6px;
    text-align: center;
    white-space: nowrap;
}
/* Outer top + left borders on the table so the grid still appears closed. */
.process-progress-matrix {
    border-top:  1px solid var(--mud-palette-table-lines);
    border-left: 1px solid var(--mud-palette-table-lines);
}

/* ---- Header bands ---- */
.process-progress-matrix thead .obs-band {
    background: var(--mud-palette-background-grey);
    color: var(--mud-palette-text-primary);
    font-weight: 600;
}

.process-progress-matrix thead .form-headers th {
    background: var(--mud-palette-background-grey);
    color: var(--mud-palette-text-primary);
    vertical-align: top;
}

.process-progress-matrix .form-label {
    font-weight: 700;
    color: var(--mud-palette-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
}

.process-progress-matrix .form-name {
    font-size: 10px;
    color: var(--mud-palette-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Sticky leftmost columns ---- */
.process-progress-matrix .person-col,
.process-progress-matrix .location-col {
    text-align: left;
    font-weight: 500;
    color: var(--mud-palette-text-primary);
}

/* No sticky columns -- after extensive testing, position:sticky on <th>/<td>
   in tables has unreliable z-index/stacking behavior across Chromium versions
   when combined with border-collapse, table-layout, and rowspan.  The matrix
   uses standard horizontal scroll instead.  Person is the leftmost column
   and is always visible at scroll-x = 0; users scroll left/right naturally. */

.process-progress-matrix .person-col {
    width: 200px;
    min-width: 200px;
    max-width: 200px;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
}

.process-progress-matrix .location-col {
    width: 160px;
    min-width: 160px;
    max-width: 160px;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
}

.process-progress-matrix .form-col {
    width: 150px;
    min-width: 150px;
    max-width: 150px;
    box-sizing: border-box;
    overflow: hidden;
}

/* ---- At-risk row ---- */
.process-progress-matrix .row-at-risk .person-col {
    border-left: 3px solid var(--mud-palette-warning);
    padding-left: 10px;
}
.process-progress-matrix .row-at-risk { background: color-mix(in srgb, var(--mud-palette-warning) 6%, transparent); }
.process-progress-matrix .risk-icon  { vertical-align: middle; margin-right: 2px; }

/* ---- Row hover ---- */
.process-progress-matrix tbody tr:hover .sticky-col { background: var(--mud-palette-action-default-hover); }

/* ---- Row total / column total cells (now with mini progress bars) ---- */
.process-progress-matrix .row-total-col {
    background: var(--mud-palette-background-grey);
    color: var(--mud-palette-text-primary);
    font-weight: 600;
    text-align: center;
    width: 130px;
    min-width: 130px;
    max-width: 130px;
    padding: 4px 8px;
}
.process-progress-matrix .form-total {
    background: color-mix(in srgb, var(--mud-palette-info) 10%, var(--mud-palette-surface));
    color: var(--mud-palette-text-primary);
    min-width: 70px;
}
.mini-progress { padding: 2px 0; }
.mini-progress-bar { height: 6px; }
.mini-progress-meta {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    margin-top: 2px;
}
.mini-progress-meta .text-muted { color: var(--mud-palette-text-secondary); }

/* ---- Data cells ---- */
.process-progress-matrix .cell-completed {
    background: color-mix(in srgb, var(--mud-palette-success) 22%, var(--mud-palette-surface));
    color: var(--mud-palette-success);
    font-weight: 600;
}

.process-progress-matrix .cell-draft {
    background: color-mix(in srgb, var(--mud-palette-warning) 28%, var(--mud-palette-surface));
    color: var(--mud-palette-warning);
    font-weight: 700;
}

.process-progress-matrix .cell-status {
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-secondary);
    font-style: italic;
    font-size: 11px;
}

/* Sub-categories of the generic "status" cell.  Each picks its own foreground +
   subtle background tint so the matrix communicates state at a glance instead of
   making every non-completed cell look identical. */
.process-progress-matrix .cell-status-inflight {
    background: color-mix(in srgb, var(--mud-palette-info) 14%, var(--mud-palette-surface));
    color:      color-mix(in srgb, var(--mud-palette-info) 70%, var(--mud-palette-text-primary));
}
.process-progress-matrix .cell-status-pending {
    background: var(--mud-palette-surface);
    color:      var(--mud-palette-text-secondary);
}
.process-progress-matrix .cell-status-skipped {
    background: color-mix(in srgb, var(--mud-palette-error) 12%, var(--mud-palette-surface));
    color:      color-mix(in srgb, var(--mud-palette-error) 65%, var(--mud-palette-text-primary));
}
.process-progress-matrix .cell-status-incomplete {
    background: color-mix(in srgb, var(--mud-palette-warning) 18%, var(--mud-palette-surface));
    color:      var(--mud-palette-warning);
    font-weight: 600;
    font-style: normal;
}
.process-progress-matrix .cell-status-neutral {
    background: var(--mud-palette-surface);
    color:      var(--mud-palette-text-secondary);
}

.process-progress-matrix .cell-empty {
    background: var(--mud-palette-surface);
    color: var(--mud-palette-action-disabled);
}

/* Cell click-through to the form-response viewer */
.process-progress-matrix .cell-clickable {
    cursor: pointer;
    transition: filter 0.15s ease, box-shadow 0.15s ease;
}
.process-progress-matrix .cell-clickable:hover {
    filter: brightness(1.12);
    box-shadow: inset 0 0 0 2px var(--mud-palette-primary);
}
.process-progress-matrix .cell-link {
    display: block;
    color: inherit;
    text-decoration: none;
    width: 100%;
    height: 100%;
}
.process-progress-matrix .cell-link:hover { text-decoration: none; }

/* Status-filter dim mode: non-matching cells fade hard so matches pop */
.process-progress-matrix .cell-dim {
    opacity: 0.08;
    filter: grayscale(1);
    transition: opacity 0.25s ease, filter 0.25s ease;
}
.process-progress-matrix .cell-dim.cell-clickable:hover { opacity: 1; filter: none; }

/* Status-filter match mode: matching cells get an accent ring + gentle pulse
   so they're impossible to miss in a sea of dimmed peers.  Color comes from
   --pp-accent set on the matrix-scroll-wrap by its filter-color-* class. */
.process-progress-matrix .cell-match {
    box-shadow:
        inset 0 0 0 2px var(--pp-accent, var(--mud-palette-primary)),
        0 0 0 1px var(--pp-accent, var(--mud-palette-primary));
    position: relative;
    z-index: 1;
    animation: pp-cell-pulse 1.6s ease-in-out infinite;
}
@keyframes pp-cell-pulse {
    0%, 100% { box-shadow: inset 0 0 0 2px var(--pp-accent, var(--mud-palette-primary)),
                            0 0 0 1px var(--pp-accent, var(--mud-palette-primary)); }
    50%      { box-shadow: inset 0 0 0 2px var(--pp-accent, var(--mud-palette-primary)),
                            0 0 8px 2px var(--pp-accent, var(--mud-palette-primary)); }
}

/* ---- Footer column-totals row ---- */
.process-progress-matrix tfoot .column-totals {
    background: color-mix(in srgb, var(--mud-palette-info) 14%, var(--mud-palette-surface));
    font-weight: 600;
}
.process-progress-matrix .grand-total {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
    font-size: 14px;
    font-weight: 700;
}


/* ============================  INSIGHT SIDEBAR  ============================ */
.insight-panel {
    background: var(--mud-palette-surface);
}
.insight-title { color: var(--mud-palette-text-primary); font-weight: 600; }
.insight-section-title {
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--mud-palette-text-secondary);
    margin-top: 8px;
    margin-bottom: 4px;
}

.evaluator-row { margin-bottom: 8px; }
.evaluator-name  { font-size: 0.85rem; color: var(--mud-palette-text-primary); }
.evaluator-count {
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
    background: var(--mud-palette-action-disabled-background);
    padding: 2px 6px;
    border-radius: 10px;
}
.evaluator-bar { height: 4px; margin-top: 3px; }

.form-rank {
    display: grid;
    grid-template-columns: minmax(48px, max-content) 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 4px 0;
    font-size: 0.8rem;
    border-bottom: 1px dashed var(--mud-palette-divider);
}
.form-rank:last-child { border-bottom: none; }

.insight-sub { color: var(--mud-palette-text-secondary); }


/* ============================  EVALUATORS TAB  ============================ */
.evaluator-table, .hotspot-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--mud-palette-text-primary);
    font-size: 0.85rem;
}
.evaluator-table th, .hotspot-table th {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 2px solid var(--mud-palette-divider);
    color: var(--mud-palette-text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
}
.evaluator-table td, .hotspot-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--mud-palette-divider);
    vertical-align: middle;
}
.evaluator-table tbody tr:hover, .hotspot-table tbody tr:hover {
    background: var(--mud-palette-action-default-hover);
}

.evaluator-table .rank-col,  .hotspot-table .rank-col      { width: 40px;  color: var(--mud-palette-text-secondary); font-weight: 700; }
.evaluator-table .name-col                                  { width: 35%;  font-weight: 500; }
.evaluator-table .count-col                                 { width: 80px; text-align: right; font-weight: 600; }
.evaluator-table .pct-col                                   { width: 100px; text-align: right; }
.evaluator-table .bar-col                                   { width: 30%; }
.evaluator-table .evaluator-tab-bar                         { height: 8px; }


/* ============================  HOTSPOTS TAB  ============================ */
.hotspot-table .label-col      { width: 130px; color: var(--mud-palette-primary); font-weight: 700; white-space: nowrap; }
.hotspot-table .obs-col        { width: 22%;   color: var(--mud-palette-text-secondary); }
.hotspot-table .form-name-col  { width: 30%;   overflow: hidden; text-overflow: ellipsis; max-width: 0; white-space: nowrap; }
.hotspot-table .completed-col  { width: 90px;  text-align: center; color: var(--mud-palette-text-secondary); font-size: 0.8rem; }
.hotspot-table .pct-col        { width: 90px;  text-align: center; }
.hotspot-table .bar-col        { width: 22%; }
.hotspot-table .hotspot-bar    { height: 8px; }
.form-rank-label {
    color: var(--mud-palette-primary);
    font-weight: 700;
    white-space: nowrap;
    font-size: 0.7rem;
}
.form-rank-name {
    color: var(--mud-palette-text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
