* {
    box-sizing: border-box;
}

/* mis.html does not wrap content in .wf-main, so the fixed .wf-topbar
   overlays the first paint of .main-layout. Push direct-child layouts
   down by the topbar height. Scoped to direct children of body so this
   cannot affect .main-layout used inside .wf-main elsewhere. */
body.wf-page-shell > .main-layout {
    margin-top: var(--topbar-height);
}

/* VIEW SELECTOR */
.view-selector {
    display: flex;
    justify-content: center;
    gap: 15px;
    padding: 10px;
    background: var(--surface-container-lowest);
    border-bottom: 2px solid var(--outline-variant);
}
.view-btn {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--outline-variant);
    background: var(--surface-container-low);
    color: var(--on-surface-variant);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}
.view-btn i {
    font-size: 14px;
}
.view-btn:hover {
    background: var(--surface-container);
}
.view-btn.active {
    background: var(--primary);
    color: var(--on-primary);
    border-color: var(--primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* GRAPH SELECTION GRID */
.graph-selection-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    padding: 40px 20px;
    max-width: 1400px;
    margin: 0 auto;
}

/* ── MIS Landing — classy M3-tinted cards ──────────────────────
   Each card uses a soft container background from a small rotating
   palette (indigo / mint / amber / indigo-dim / mint). Icon squares
   use the darker family token. Cards lift on hover with a soft
   colored ring border. Uses color-mix for theme-aware tinting; falls
   back to container tokens on older browsers. */

.graph-box {
    --gb-bg:        var(--surface-container-low);
    --gb-icon-bg:   var(--surface-container);
    --gb-icon-fg:   var(--primary);
    --gb-ring:      var(--outline-variant);

    background: var(--gb-bg);
    border: 1px solid var(--gb-ring);
    border-radius: var(--radius-xl);
    padding: var(--space-6) var(--space-5);
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.graph-box:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--gb-icon-fg);
}

/* Per-card rotating tints. Tints blend 10-12% of the family color into
   the surface, producing a soft wash that flips automatically with
   light/dark theme (because --surface flips). */
.graph-box:nth-child(5n+1) {
    --gb-bg:      color-mix(in oklab, var(--primary)   12%, var(--surface));
    --gb-icon-bg: color-mix(in oklab, var(--primary)   22%, var(--surface));
    --gb-icon-fg: var(--primary);
}
.graph-box:nth-child(5n+2) {
    --gb-bg:      color-mix(in oklab, var(--secondary) 12%, var(--surface));
    --gb-icon-bg: color-mix(in oklab, var(--secondary) 22%, var(--surface));
    --gb-icon-fg: var(--secondary);
}
.graph-box:nth-child(5n+3) {
    --gb-bg:      color-mix(in oklab, var(--tertiary)  12%, var(--surface));
    --gb-icon-bg: color-mix(in oklab, var(--tertiary)  22%, var(--surface));
    --gb-icon-fg: var(--tertiary);
}
.graph-box:nth-child(5n+4) {
    --gb-bg:      color-mix(in oklab, var(--primary)   8%,  var(--surface));
    --gb-icon-bg: color-mix(in oklab, var(--primary)   18%, var(--surface));
    --gb-icon-fg: var(--primary-dim);
}
.graph-box:nth-child(5n+5) {
    --gb-bg:      color-mix(in oklab, var(--secondary) 8%,  var(--surface));
    --gb-icon-bg: color-mix(in oklab, var(--secondary) 18%, var(--surface));
    --gb-icon-fg: var(--secondary);
}

/* Fallback for older browsers (pre-2023 Safari) without color-mix. */
@supports not (background: color-mix(in oklab, red 10%, white)) {
    .graph-box:nth-child(5n+1),
    .graph-box:nth-child(5n+4) { --gb-bg: var(--primary-container); --gb-icon-bg: var(--surface-container-low); }
    .graph-box:nth-child(5n+2),
    .graph-box:nth-child(5n+5) { --gb-bg: var(--secondary-container, var(--surface-container-low)); --gb-icon-bg: var(--surface-container-low); }
    .graph-box:nth-child(5n+3) { --gb-bg: var(--tertiary-container, var(--surface-container-low));  --gb-icon-bg: var(--surface-container-low); }
}

.graph-box-icon {
    color: var(--gb-icon-fg);
    background: var(--gb-icon-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    margin: 0 auto var(--space-4);
    border-radius: var(--radius-lg);
    box-shadow: 0 0 0 1px var(--gb-ring);
}
.graph-box-icon .material-symbols-outlined {
    font-size: 30px;
}

.graph-box-title {
    color: var(--on-surface);
    font-family: var(--font-headline);
    font-size: 1.0625rem;
    font-weight: 700;
    margin: 0 0 var(--space-2) 0;
    letter-spacing: -0.01em;
}

.graph-box-description {
    color: var(--on-surface-variant);
    font-size: 0.8125rem;
    line-height: 1.5;
    margin: 0;
    font-weight: 400;
}

/* When the MIS tab is active, we need to handle the parent's overflow */
#MIS.tab-content {
    padding: 20px !important;
    overflow-y: auto !important;
    background: var(--surface);
    height: calc(100vh - 130px);
}

.main-layout {
    width: 100%;
    margin: 0 auto;
    max-width: 1400px;
}

.section-fullscreen {
    width: 100%;
    margin-bottom: 20px;
    display: block;
    min-height: calc(100vh - 250px);
}

.card-full {
    background: var(--surface-container-lowest);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    padding: 30px;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 500px;
    border: 1px solid var(--outline-variant);
}

h2 {
    margin: 0;
    font-size: 20px;
    color: var(--on-surface);
    font-weight: 800;
}
.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--surface-container-high);
    padding-bottom: 12px;
    flex-shrink: 0;
}
.legend-sla {
    font-size: 11px !important;
    gap: 10px !important;
}

.chart-container,
.pie-container {
    flex-grow: 1;
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.pie-container {
    max-height: 500px;
    margin: 0 auto;
}

canvas {
    display: block !important;
    max-width: 100%;
    max-height: 100%;
}

/* CHART EMPTY-STATE
   Shown by renderSLAChart() when no breaches are present in the data —
   either everything is within SLA, or no SLA is configured on workflow nodes. */
.mis-chart-empty {
    display: none;          /* renderSLAChart toggles to block when needed */
    padding: 32px 24px;
    text-align: center;
    background: var(--surface-container-low);
    border: 1px dashed var(--outline-variant);
    border-radius: 8px;
    margin: 24px 16px;
    max-width: 600px;
    align-self: center;     /* center within .chart-container's flex column */
}
.mis-chart-empty.is-visible {
    display: block;
}
.mis-chart-empty p {
    margin: 0;
}
.mis-chart-empty p + p {
    margin-top: 8px;
}
.mis-chart-empty .mis-chart-empty-title {
    font-weight: 600;
    color: var(--on-surface);
    font-size: 14px;
}
.mis-chart-empty .mis-chart-empty-body {
    font-size: 13px;
    color: var(--on-surface-variant);
    line-height: 1.5;
}

/* PAGINATION */
.pagination {
    display: flex;
    gap: 8px;
    align-items: center;
    user-select: none;
}
.page-info {
    font-weight: normal;
    color: var(--on-surface-variant);
    font-size: 13px;
    margin: 0 4px;
}
.btn-pagination {
    background: transparent;
    color: var(--on-surface-variant);
    border: none;
    padding: 6px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.btn-pagination:hover:not(:disabled) {
    background: var(--surface-container);
    color: var(--on-surface);
}
.btn-pagination:disabled {
    color: var(--outline-variant);
    cursor: default;
}
.btn-pagination span {
    font-size: 14px;
    line-height: 1;
}

/* DRILL DOWN OVERLAY */
#drillDownContainer {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    padding: 40px;
    box-sizing: border-box;
}
#drillDownCard {
    height: 85vh;
    width: 85%;
    margin: 6vh auto;
    background: var(--surface-container-lowest);
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}
#drillDownCard h2 {
    font-size: 20px;
    color: var(--on-surface);
    margin-right: 20px;
}

/* PREMIUM BUTTONS */
.btn-download {
    background: var(--success);
    color: var(--on-primary);
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-download:hover {
    background: var(--success-dim);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

.btn-download:active {
    transform: translateY(0);
}

.dd-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--surface-container-high);
    padding-bottom: 15px;
    flex-shrink: 0;
}

/* Chart wrapper inside drill-down */
#drillDownCard > div:last-child {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
    padding: 20px 10px;
}

#drillDownCard canvas {
    position: absolute !important;
    top: 20px !important;
    left: 10px !important;
    right: 10px !important;
    bottom: 20px !important;
    width: calc(100% - 20px) !important;
    height: calc(100% - 40px) !important;
}

/* Drill Down Pagination */
#drillPagination {
    display: none;
    gap: 10px;
    align-items: center;
}

/* OU DASHBOARD STYLES */
.breadcrumb {
    font-size: 14px;
    color: var(--on-surface-variant);
    font-weight: 500;
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 5px;
}
.crumb {
    cursor: pointer;
    color: var(--primary);
    text-decoration: none;
    transition: color 0.2s;
}
.crumb:hover {
    color: var(--primary-dim);
    text-decoration: underline;
}
.crumb-sep {
    color: var(--outline);
}
.current-crumb {
    color: var(--on-surface);
    font-weight: 700;
    cursor: default;
}

.status-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    color: var(--on-primary);
    display: inline-block;
    width: 90px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mis-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}
.mis-table th {
    background: var(--surface-container-low);
    padding: 12px 15px;
    text-align: left;
    border-bottom: 2px solid var(--outline-variant);
    position: sticky;
    top: 0;
    z-index: 10;
    color: var(--on-surface);
    font-weight: 600;
}
.mis-table td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--outline-variant);
    color: var(--on-surface-variant);
}
.mis-table tr:hover td {
    background: var(--surface-container-low);
}

#ouTableContainer {
    animation: fadeIn 0.3s ease-in-out;
}

/* STICKY TABLE HEADER */
.mis-table thead th {
    position: sticky !important;
    top: 0;
    background-color: var(--surface-container-low) !important;
    z-index: 100;
}

/* COLUMN CUSTOMIZER MODAL */
.col-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}
.col-modal-content {
    background: var(--surface-container-lowest);
    padding: 25px;
    border-radius: 12px;
    width: 400px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}
.col-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--outline-variant);
    border-radius: 8px;
    padding: 5px;
}
.col-item {
    display: flex;
    align-items: center;
    padding: 10px;
    background: var(--surface-container-lowest);
    border-bottom: 1px solid var(--surface-container-high);
    gap: 12px;
}
.col-item:last-child {
    border-bottom: none;
}
.col-item:hover {
    background: var(--surface-container-low);
}
.col-handle {
    cursor: grab;
    color: var(--outline);
    font-size: 18px;
    user-select: none;
}
.col-item label {
    flex-grow: 1;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* RESPONSIVE DESIGN */
@media (max-width: 1200px) {
    .graph-selection-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .graph-selection-container {
        grid-template-columns: 1fr;
        gap: 20px;
        padding: 20px;
    }

    .graph-box {
        padding: 30px 20px;
    }

    .graph-box-icon {
        font-size: 48px;
    }

    .graph-box-title {
        font-size: 20px;
    }
}

/* FILTER DROPDOWNS */
.mis-filter {
    padding: 6px 10px;
    border: 1px solid var(--outline-variant);
    border-radius: 6px;
    font-size: 13px;
    color: var(--on-surface);
    background-color: var(--surface-container-lowest);
    outline: none;
    cursor: pointer;
    min-width: 120px;
}

.mis-filter:hover {
    border-color: var(--outline);
}

.mis-filter:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0, 96, 173, 0.15);
}

/* REPORTS VIEW */
#reportsView {
    padding: 20px;
    background-color: var(--surface-container-low);
    color: var(--on-surface-variant);
    font-size: 16px;
}