/* ==========================================================================
   EntegreSmart Management — Phase 2.2 refinements
   Shared list primitives (badges, sorting, selection, stackable tables),
   dashboard hierarchy, tabs and detail views. Tokens only.
   ========================================================================== */

/* ---------- Focus visibility ----------
   MudBlazor resets outlines on plain buttons; custom controls restate the shared focus ring. */
.es-chip-filter:focus-visible,
.es-option:focus-visible,
.es-collapse-btn:focus-visible,
.es-user-btn:focus-visible,
.es-nav-link:focus-visible,
.es-page-size select:focus-visible { outline: var(--es-focus-outline) !important; outline-offset: 2px; }
.es-nav-link:focus-visible { outline-offset: -2px; }

/* ---------- Layout width ---------- */
.es-content { max-width: 1600px; }

/* ---------- Badges & tags ---------- */
.es-badge-row { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.es-badge .es-badge-icon, .es-badge .mud-icon-root { font-size: 0.875rem; margin-left: -2px; }
.es-badge.is-unverified {
    background: transparent;
    border: 1px dashed var(--es-border-strong);
    color: var(--es-text-secondary);
}

.es-type-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 24px;
    padding: 0 8px;
    border-radius: var(--es-radius-sm);
    border: 1px solid var(--es-border);
    background: var(--es-surface-sunken);
    color: var(--es-text-secondary);
    font-size: var(--es-text-xs);
    font-weight: 500;
    white-space: nowrap;
}
.es-type-tag .mud-icon-root { font-size: 0.875rem; }

.es-demo-badge-scenario {
    margin-left: 2px;
    padding-left: 6px;
    border-left: 1px solid currentColor;
    font-weight: 700;
}
.es-topbar .es-demo-badge { flex-shrink: 0; }

/* ---------- Sorting & paging ---------- */
.es-sort-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: -4px -6px;
    padding: 4px 6px;
    border: 0;
    border-radius: var(--es-radius-sm);
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.es-sort-btn .mud-icon-root { font-size: 0.9375rem; opacity: 0.45; }
.es-sort-btn:hover { color: var(--es-text); background: var(--es-surface-hover); }
.es-sort-btn:hover .mud-icon-root, .es-sort-btn.is-active .mud-icon-root { opacity: 1; }
.es-sort-btn.is-active { color: var(--es-text); }
.es-sort-btn:focus-visible { outline: var(--es-focus-outline); outline-offset: 1px; }
th.is-num .es-sort-btn { flex-direction: row-reverse; }

.es-page-size { display: inline-flex; align-items: center; gap: var(--es-space-2); font-size: var(--es-text-sm); color: var(--es-text-secondary); }
.es-page-size select {
    height: 30px;
    padding: 0 26px 0 10px;
    border: 1px solid var(--es-border-strong);
    border-radius: var(--es-radius-sm);
    background: var(--es-surface);
    color: var(--es-text);
    font: inherit;
}
.es-page-size select:focus-visible { outline: var(--es-focus-outline); outline-offset: 1px; }
.es-table-footer { justify-content: flex-start; }
.es-table-footer .mud-pagination { margin-left: auto; }

/* ---------- Bulk selection (visual only) ---------- */
.es-table .is-select { width: 44px; padding-right: 0 !important; }
.es-table .is-select .mud-checkbox { margin: -8px 0 -8px -10px; }
.es-table tr.is-selected { background: color-mix(in srgb, var(--es-primary-soft) 55%, transparent); }

.es-selection-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--es-space-2) var(--es-space-3);
    padding: var(--es-space-2) var(--es-space-5);
    border-bottom: 1px solid var(--es-divider);
    background: var(--es-primary-soft);
    color: var(--es-primary-soft-text);
    font-size: var(--es-text-sm);
    font-weight: 600;
}
.es-selection-bar .es-field-hint { font-weight: 400; }
.es-selection-bar-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: var(--es-space-1); }

/* ---------- Not-yet-available state ---------- */
.es-state.is-unavailable {
    margin: var(--es-space-5);
    border: 1px dashed var(--es-border-strong);
    border-radius: var(--es-radius-lg);
    background: var(--es-surface-sunken);
}
.es-state.is-unavailable .es-badge { margin-bottom: var(--es-space-1); }

/* ---------- Tabs ---------- */
.es-tabs .mud-tabs-tabbar { background: transparent !important; border-bottom: 1px solid var(--es-border); }
.es-tabs .mud-tabs-tabbar-inner { justify-content: flex-start; }
.es-tabs .mud-tab { flex: 0 0 auto; text-transform: none; font-weight: 600; letter-spacing: 0; min-width: 0; padding: 10px 16px; color: var(--es-text-secondary); }
.es-tabs .mud-tab.mud-tab-active { color: var(--es-primary); }
.es-tabs .mud-tab:focus-visible { outline: var(--es-focus-outline); outline-offset: -2px; }
.es-tabs .mud-tabs-panels { padding-top: var(--es-space-5); }
.es-tab-count {
    display: inline-grid;
    place-items: center;
    min-width: 20px;
    height: 18px;
    margin-left: 6px;
    padding: 0 6px;
    border-radius: var(--es-radius-pill);
    background: var(--es-neutral-soft);
    color: var(--es-text-secondary);
    font-size: 0.6875rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ---------- Summary strip (counts above lists / in detail headers) ---------- */
.es-summary-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--es-space-3); }
.es-summary-item { padding: var(--es-space-3) var(--es-space-4); border: 1px solid var(--es-border); border-radius: var(--es-radius-md); background: var(--es-surface); }
.es-summary-item dt { font-size: var(--es-text-xs); color: var(--es-text-muted); font-weight: 500; }
.es-summary-item dd { margin: 2px 0 0; font-size: var(--es-text-xl); font-weight: 650; letter-spacing: -0.015em; font-variant-numeric: tabular-nums; }

/* ---------- Dashboard ---------- */
.es-stat.is-emphasis { position: relative; border-color: color-mix(in srgb, var(--es-warning) 45%, var(--es-border)); }
.es-stat.is-emphasis::before {
    content: "";
    position: absolute;
    inset: 12px auto 12px 0;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--es-warning);
}
.es-stat-hint .es-days { font-size: inherit; }

.es-urgency { display: flex; flex-wrap: wrap; gap: var(--es-space-2); padding: var(--es-space-3) var(--es-space-5); border-bottom: 1px solid var(--es-divider); background: var(--es-surface-sunken); }
.es-urgency-item { display: inline-flex; align-items: center; gap: 6px; font-size: var(--es-text-xs); color: var(--es-text-secondary); }
.es-urgency-item strong { font-size: var(--es-text-md); color: var(--es-text); font-variant-numeric: tabular-nums; }
.es-urgency-dot { width: 8px; height: 8px; border-radius: 50%; }
.es-urgency-dot.is-critical { background: var(--es-danger); }
.es-urgency-dot.is-warning { background: var(--es-warning); }
.es-urgency-dot.is-normal { background: var(--es-border-strong); }
.es-table tr.is-critical td:first-child { box-shadow: inset 3px 0 0 var(--es-danger); }

.es-days-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 24px;
    padding: 0 8px;
    border-radius: var(--es-radius-pill);
    background: var(--es-neutral-soft);
    color: var(--es-text-secondary);
    font-size: var(--es-text-xs);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.es-days-pill.is-critical { background: var(--es-danger-soft); color: var(--es-danger); }
.es-days-pill.is-warning { background: var(--es-warning-soft); color: var(--es-warning); }
.es-days-pill .mud-icon-root { font-size: 0.875rem; }

.es-dist-bar { height: 14px; }
.es-dist-groups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--es-space-3); margin-top: var(--es-space-4); }
.es-dist-group { padding: var(--es-space-3) var(--es-space-4); border-radius: var(--es-radius-md); background: var(--es-surface-sunken); }
.es-dist-group dt { font-size: var(--es-text-xs); color: var(--es-text-muted); }
.es-dist-group dd { margin: 2px 0 0; font-weight: 650; font-size: var(--es-text-lg); font-variant-numeric: tabular-nums; }
.es-dist-group dd small { color: var(--es-text-muted); font-weight: 500; font-size: var(--es-text-xs); margin-left: 4px; }
.es-dist-row { grid-template-columns: 12px minmax(0, 1fr) minmax(60px, 120px) 32px 40px; }
.es-dist-track { height: 6px; border-radius: 3px; background: var(--es-divider); overflow: hidden; }
.es-dist-track span { display: block; height: 100%; border-radius: 3px; }
.es-dist-legend-title { margin: var(--es-space-5) 0 var(--es-space-1); font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--es-text-muted); }
.es-dist-legend-title + .es-dist-legend { margin-top: 0; }

.es-activity-summary { display: flex; flex-wrap: wrap; gap: var(--es-space-4); padding: var(--es-space-3) var(--es-space-5); border-bottom: 1px solid var(--es-divider); background: var(--es-surface-sunken); font-size: var(--es-text-xs); color: var(--es-text-secondary); }
.es-activity-summary strong { color: var(--es-text); font-size: var(--es-text-md); font-variant-numeric: tabular-nums; margin-right: 4px; }
.es-activity-day { padding: var(--es-space-3) var(--es-space-5) var(--es-space-1); font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--es-text-muted); }
.es-activity-code { font-family: var(--es-font-mono); font-size: 0.6875rem; color: var(--es-text-muted); }

.es-server-summary { display: flex; flex-wrap: wrap; gap: var(--es-space-2); }

/* ---------- Detail panels (license validity, endpoint detail) ---------- */
.es-timeline { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; margin: var(--es-space-2) 0 0; padding: 0; list-style: none; }
.es-timeline li { position: relative; padding: var(--es-space-6) var(--es-space-3) 0 0; }
.es-timeline li::before { content: ""; position: absolute; top: 7px; left: 0; right: 0; height: 2px; background: var(--es-border); }
.es-timeline li::after { content: ""; position: absolute; top: 2px; left: 0; width: 12px; height: 12px; border-radius: 50%; background: var(--es-surface); border: 2px solid var(--es-border-strong); }
.es-timeline li.is-reached::before { background: var(--es-primary); }
.es-timeline li.is-reached::after { border-color: var(--es-primary); background: var(--es-primary); }
.es-timeline li.is-muted { opacity: 0.6; }
.es-timeline-label { display: block; font-size: var(--es-text-xs); color: var(--es-text-muted); }
.es-timeline-value { display: block; margin-top: 2px; font-weight: 600; font-variant-numeric: tabular-nums; }

.es-module-scope { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--es-space-2); list-style: none; margin: 0; padding: 0; }
.es-module-scope li { display: flex; align-items: center; gap: var(--es-space-3); padding: var(--es-space-3); border: 1px solid var(--es-border); border-radius: var(--es-radius-md); }
.es-module-scope li.is-off { border-style: dashed; background: var(--es-surface-sunken); color: var(--es-text-muted); }
.es-module-scope .es-module-code { width: 36px; height: 28px; font-size: 0.6875rem; }
.es-module-scope-name { flex: 1; min-width: 0; font-weight: 600; font-size: var(--es-text-sm); }
.es-module-scope li.is-off .es-module-scope-name { font-weight: 500; }
.es-module-scope-limit { font-size: var(--es-text-xs); color: var(--es-text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Audience separation (Management vs ERP users) ---------- */
.es-audience { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--es-space-4); margin-bottom: var(--es-space-6); }

/* ---------- Event detail ---------- */
.es-event-head { display: flex; align-items: center; gap: var(--es-space-3); }
.es-hash-note { font-size: var(--es-text-xs); color: var(--es-text-muted); }

/* ---------- Toolbar additions ---------- */
.es-toolbar-select { min-width: 220px; }
.es-toolbar-select .mud-input-control { margin: 0 !important; }
.es-toolbar-chips { padding-top: var(--es-space-3); padding-bottom: var(--es-space-3); gap: var(--es-space-2); }
.es-chip-count { font-variant-numeric: tabular-nums; color: var(--es-text-muted); font-weight: 500; }
.es-chip-filter[aria-pressed="true"] .es-chip-count { color: inherit; }
.es-chip-filter .es-dist-swatch { width: 8px; height: 8px; border-radius: 50%; }
.es-toolbar-sep { width: 1px; height: 20px; background: var(--es-border); margin: 0 var(--es-space-1); }

.es-link-btn {
    padding: 0;
    border: 0;
    background: none;
    color: var(--es-primary);
    font: inherit;
    font-weight: inherit;
    text-align: left;
    cursor: pointer;
}
.es-link-btn:hover { text-decoration: underline; }
.es-link-btn:focus-visible { outline: var(--es-focus-outline); outline-offset: 2px; border-radius: 2px; }
.es-cell-title .es-link-btn { color: inherit; font-weight: 600; }
.es-cell-title .es-link-btn:hover { color: var(--es-primary); text-decoration: none; }

/* ---------- Error summary (forms) ---------- */
.es-error-summary {
    display: flex;
    gap: var(--es-space-3);
    margin-bottom: var(--es-space-5);
    padding: var(--es-space-3) var(--es-space-4);
    border: 1px solid var(--es-danger);
    border-left-width: 4px;
    border-radius: var(--es-radius-md);
    background: var(--es-danger-soft);
    color: var(--es-text);
}
.es-error-summary > .mud-icon-root { color: var(--es-danger); flex-shrink: 0; }
.es-error-summary-title { margin: 0 0 4px; font-weight: 600; }
.es-error-summary ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 2px; font-size: var(--es-text-sm); }
.es-error-summary .es-link-btn { color: var(--es-danger); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Wizard refinements ---------- */
@container (min-width: 900px) {
    .es-review { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
    .es-review > .es-review-block:nth-child(4) { grid-column: 1 / -1; } /* modules list is wide */
}
.es-review-block .es-dl dd { font-size: var(--es-text-md); }

@media (max-width: 767.98px) {
    /* Phones: the progress header replaces the step list and the page intro, saving a screen of scrolling. */
    .es-wizard-rail .es-steps-list { display: none; }
    .es-wizard-page .es-page-description { display: none; }
    .es-wizard-page .es-page-header { margin-bottom: var(--es-space-3); }
    .es-wizard-body .es-form-section { padding: var(--es-space-4) 0; }
    .es-wizard-body .es-form-section-text { font-size: var(--es-text-xs); }
    .es-option-group { gap: var(--es-space-2); margin-bottom: var(--es-space-4); }
    .es-option { padding: var(--es-space-3); }
    .es-identity-card ul { font-size: var(--es-text-xs); }
}

/* ---------- Stackable tables: rows become cards on phones ---------- */
@media (max-width: 639.98px) {
    .es-table-wrap.is-stackable { overflow-x: visible; }
    .es-table-wrap.is-stackable .es-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
    .es-table-wrap.is-stackable .es-table,
    .es-table-wrap.is-stackable .es-table tbody,
    .es-table-wrap.is-stackable .es-table tr,
    .es-table-wrap.is-stackable .es-table td { display: block; width: 100%; }
    .es-table-wrap.is-stackable .es-table tr {
        position: relative;
        padding: var(--es-space-3) var(--es-space-4);
        border-bottom: 1px solid var(--es-divider);
    }
    .es-table-wrap.is-stackable .es-table td {
        display: grid;
        grid-template-columns: 112px minmax(0, 1fr);
        align-items: center;
        gap: var(--es-space-3);
        padding: 5px 0 !important;
        border: 0;
        text-align: left !important;
        white-space: normal;
    }
    .es-table-wrap.is-stackable .es-table td > * { justify-self: start; max-width: 100%; }
    .es-table-wrap.is-stackable .es-table td::before {
        content: attr(data-label);
        font-size: var(--es-text-xs);
        font-weight: 500;
        color: var(--es-text-muted);
    }
    .es-table-wrap.is-stackable .es-table td.is-primary { display: block; padding-right: 48px !important; }
    .es-table-wrap.is-stackable .es-table td.is-primary::before { content: none; }
    .es-table-wrap.is-stackable .es-table td.is-action,
    .es-table-wrap.is-stackable .es-table td.is-select { position: absolute; top: var(--es-space-2); right: var(--es-space-2); width: auto; display: block; }
    .es-table-wrap.is-stackable .es-table td.is-action::before,
    .es-table-wrap.is-stackable .es-table td.is-select::before { content: none; }
    .es-table-wrap.is-stackable .es-table td.is-select { right: auto; left: var(--es-space-1); }
    .es-table-wrap.is-stackable .es-table tr:has(td.is-select) { padding-left: 44px; }
    .es-table-wrap.is-stackable .es-cell-primary { max-width: none; min-width: 0; }
    .es-table-wrap.is-stackable .es-cell-title { white-space: normal; }
    .es-table-wrap.is-stackable .es-table tr.is-critical td:first-child { box-shadow: none; }
    .es-table-wrap.is-stackable .es-table tr.is-critical { box-shadow: inset 3px 0 0 var(--es-danger); }

    .es-topbar .es-demo-badge > span:not(.es-demo-badge-scenario) { display: none; }
    .es-topbar .es-notify { display: none; } /* passive placeholder; frees room for the page title */
    .es-audience, .es-dist-groups { grid-template-columns: minmax(0, 1fr); }
    .es-timeline { grid-template-columns: minmax(0, 1fr); }
    .es-timeline li { padding: 0 0 var(--es-space-4) var(--es-space-6); }
    .es-timeline li::before { top: 0; bottom: 0; left: 5px; right: auto; width: 2px; height: auto; }
    .es-timeline li::after { top: 2px; }
    .es-selection-bar { padding: var(--es-space-2) var(--es-space-4); }
    .es-selection-bar-actions { margin-left: 0; }
    .es-dist-row { grid-template-columns: 12px minmax(0, 1fr) 32px 40px; }
    .es-dist-track { display: none; }
}
