/* Department tree (desktop + mobile), level background colors, tree-view connectors, campaigns grid, dashboards, settings masonry. */

.activity-log-grid {
    --mud-palette-table-striped: var(--table-banding, color-mix(in srgb, var(--mud-palette-primary) 7%, transparent));
}

.activity-log-grid table {
    width: auto !important;
}


.activity-log-grid th {
    background: var(--table-header, color-mix(in srgb, var(--mud-palette-primary) 20%, var(--mud-palette-surface))) !important;
    border-bottom: 1.5px solid var(--mud-palette-primary) !important;
}

.activity-log-grid .mud-table-body tr {
    cursor: pointer;
}

.activity-log-grid .mud-table-body tr:nth-child(odd) {
    background-color: var(--mud-palette-table-striped);
}

.rule-grid {
    --mud-palette-table-striped: var(--table-banding, color-mix(in srgb, var(--mud-palette-primary) 7%, transparent));
    width: auto !important;
}

.rule-grid table {
    width: auto !important;
}

.rule-grid th {
    background: var(--table-header, color-mix(in srgb, var(--mud-palette-primary) 20%, var(--mud-palette-surface))) !important;
    border-bottom: 1.5px solid var(--mud-palette-primary) !important;
}

.rule-grid .mud-table-body tr:nth-child(odd) {
    background-color: var(--mud-palette-table-striped);
}

/* ── Campaigns grid ─────────────────────────────────────────────────── */
.campaigns-grid {
    --mud-palette-table-striped: var(--table-banding, color-mix(in srgb, var(--mud-palette-primary) 7%, transparent));
}

.campaigns-grid th {
    background: var(--table-header, color-mix(in srgb, var(--mud-palette-primary) 20%, var(--mud-palette-surface))) !important;
    border-bottom: 1.5px solid var(--mud-palette-primary) !important;
}

.campaigns-grid .mud-table-body tr:nth-child(odd) {
    background-color: var(--mud-palette-table-striped);
}

/* ── Department dashboard grid ─────────────────────────────────────── */
.dashboard-grid {
    --mud-palette-table-striped: var(--table-banding, color-mix(in srgb, var(--mud-palette-primary) 7%, transparent));
}

.dashboard-grid th {
    background: var(--table-header, color-mix(in srgb, var(--mud-palette-primary) 20%, var(--mud-palette-surface))) !important;
    border-bottom: 1.5px solid var(--mud-palette-primary) !important;
}

.dashboard-grid .mud-table-body tr:nth-child(odd) {
    background-color: var(--mud-palette-table-striped);
}

.dept-rule-chips {
    gap: 16px !important;
    align-items: center;
    padding: 8px 4px 4px 10px;
}

.dept-rule-chips > * {
    vertical-align: middle;
    margin: 4px 0;
}

.dept-rule-chips .mud-badge-top.mud-badge-left {
    top: 4px;
    left: 4px;
}

.dept-rule-chips .mud-badge-top.mud-badge-right {
    top: 4px;
    right: 4px;
}

.dept-rule-chips .mud-badge-bottom.mud-badge-right {
    bottom: 4px;
    right: 4px;
}

.rule-tooltip .mud-tooltip {
    background: color-mix(in srgb, var(--mud-palette-primary) 8%, var(--mud-palette-surface)) !important;
    color: var(--mud-palette-text-primary) !important;
    box-shadow: var(--mud-elevation-4);
    border: 1px solid var(--mud-palette-divider);
}

.rule-tooltip .mud-tooltip-arrow::before {
    background: color-mix(in srgb, var(--mud-palette-primary) 8%, var(--mud-palette-surface)) !important;
    border: 1px solid var(--mud-palette-divider);
}

/* ── Settings page masonry layout ───────────────────────────────────── */
.settings-masonry {
    column-count: 2;
    column-gap: 16px;
}
.settings-masonry-card {
    break-inside: avoid;
    margin-bottom: 16px;
}
@media (max-width: 960px) {
    .settings-masonry {
        column-count: 1;
    }
}

.sankey-settings-panel .mud-expand-panel-header {
    flex-direction: row-reverse;
    justify-content: flex-end;
}

.sankey-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    border-radius: 0 !important;
    background: var(--mud-palette-surface);
}

/* ── Departments page: responsive layout ── */
.dept-layout {
    display: flex;
    gap: 16px;
    align-items: stretch;
    height: calc(calc(var(--dvh, 1vh) * 100) - 200px);
}
.dept-tree-panel {
    width: fit-content;
    flex-shrink: 0;
    align-self: flex-start;
}
.dept-detail-panel {
    position: absolute;
    inset: 0;
    z-index: 10;
}

/* Mobile tabs */
.dept-mobile-tabs {
    display: flex;
    background: var(--mud-palette-surface);
    border-bottom: 2px solid var(--mud-palette-divider);
    margin-bottom: 8px;
}
.dept-mobile-tab {
    flex: 1;
    padding: 12px 0;
    min-height: 44px; /* WCAG 2.5.5 */
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--mud-palette-text-secondary);
    cursor: pointer;
    border: none;
    background: transparent;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}
.dept-mobile-tab.active {
    color: var(--mud-palette-primary);
    border-bottom-color: var(--mud-palette-primary);
}
.dept-mobile-tab:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: -2px;
}

@media (max-width: 600px) {
    .dept-layout {
        flex-direction: column;
        height: auto;
        gap: 0;
        overflow: visible;
    }
    .dept-tree-panel {
        width: 100%;
        flex-shrink: 1;
        overflow: visible !important;
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        background: transparent !important;
    }
    .dept-chart-panel {
        /* Inline style on <MudPaper> sets `min-width:300px`, which can force
           horizontal scroll on narrow phones (<360px usable after padding).
           CSS specificity (inline > class) means we need !important to win. */
        min-width: 0 !important;
        /* Parent .dept-layout goes `height: auto` on mobile, so inline
           `flex: 1` on this panel has nothing to grow into — the Sankey's
           Height="100%" then resolves against a 0-height parent and falls
           back to the inner container's min-height:200px (cramped). Force a
           readable height via dynamic-vh so landscape / standing vs sitting
           orientations all work; 65dvh is a Sankey-sized slice that leaves
           the Depts tab bar and PageHeader visible. */
        height: 65dvh !important;
        min-height: 400px;
    }
    .dept-mobile-hidden {
        display: none !important;
    }
    /* Detail panel: full-screen overlay on mobile */
    .dept-detail-panel {
        position: fixed;
        inset: 0;
        z-index: 200;
    }
    /* Condensed font for compact tree on mobile */
    .dept-tree-panel {
        font-family: 'Roboto Condensed', 'Arial Narrow', sans-serif;
    }
    .dept-tree-panel .mud-treeview {
        --app-tree-indent: var(--saved-tree-indent, 36px) !important; /* restored from localStorage or default */
    }
    /* Smooth indent animation — only after JS has set initial state.
       Honor prefers-reduced-motion (see @media block at end of file). */
    .dept-tree-panel.di-animated .mud-treeview-group {
        transition: margin-left 0.3s ease, margin-inline-start 0.3s ease;
    }
    @media (prefers-reduced-motion: reduce) {
        .dept-tree-panel.di-animated .mud-treeview-group { transition: none; }
        .dept-mobile-tab { transition: none; }
    }
    .dept-tree-panel .mud-treeview-item-content {
        padding-top: 2px !important;
        padding-bottom: 2px !important;
        min-height: 32px !important;
    }
    .dept-tree-panel .mud-treeview-item-body {
        font-size: 0.8rem;
    }
    .dept-tree-panel .mud-icon-size-small {
        font-size: 18px !important;
    }
    .dept-tree-panel .mud-chip-size-small {
        height: 20px !important;
        font-size: 0.65rem !important;
    }
    /* Mobile detail popup — visualViewport-aware height (handled via JS setting --dvh) */
    .dept-mobile-detail-overlay {
        position: fixed;
        inset: 0;
        z-index: 300;
        background: rgba(0,0,0,0.4);
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 24px 16px;
    }
    .dept-mobile-detail-card {
        background: var(--mud-palette-surface);
        border-radius: 12px;
        box-shadow: 0 8px 32px rgba(0,0,0,0.2);
        width: 100%;
        max-height: min(80vh, calc(var(--dvh, 1vh) * 80));
        display: flex;
        flex-direction: column;
        overflow: hidden;
        animation: dept-detail-slide-in 0.24s cubic-bezier(0.2, 0.9, 0.3, 1);
    }
    @keyframes dept-detail-slide-in {
        from { opacity: 0; transform: translateY(16px) scale(0.98); }
        to   { opacity: 1; transform: translateY(0) scale(1); }
    }
    .dept-mobile-detail-header {
        position: sticky;
        top: 0;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 12px 16px;
        border-bottom: 1px solid var(--mud-palette-divider);
        background: var(--mud-palette-surface);
        z-index: 1;
        min-height: 56px;
    }
    .dept-mobile-detail-body {
        overflow-y: auto;
        flex: 1;
        padding: 8px;
        -webkit-overflow-scrolling: touch;
    }
    /* Name-card per employee. Tinted with current dept colour; profile chips
       wrap underneath the avatar/name block. Desktop keeps the one-line layout. */
    .dept-emp-card {
        border: 1px solid var(--mud-palette-divider);
        border-radius: 10px;
        padding: 10px;
        margin-bottom: 8px;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    }
    .dept-emp-card-inactive {
        opacity: 0.55;
    }
    .dept-emp-card-top {
        display: flex;
        align-items: center;
        gap: 10px;
        margin-bottom: 8px;
        cursor: pointer;
    }
    /* Subdept row in the selected-dept detail panel — now a <button> for
       a11y, so override button defaults to fill the row and left-align. */
    .dept-subdept-row {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 4px 0;
        width: 100%;
        text-align: left;
    }
    .dept-subdept-row:hover {
        background: color-mix(in srgb, var(--mud-palette-primary) 4%, transparent);
    }
    .dept-emp-card-text {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        gap: 2px;
    }
    .dept-emp-card-name {
        display: flex;
        align-items: center;
        gap: 6px;
        min-width: 0;
    }
    .dept-emp-card-name-text {
        font-size: 0.9rem;
        font-weight: 700;
        color: var(--mud-palette-text-primary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        text-decoration: underline dotted;
        text-underline-offset: 2px;
        min-width: 0;
    }
    .dept-emp-card-job {
        font-size: 0.75rem;
        color: var(--mud-palette-text-secondary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .dept-emp-card-left-badge {
        font-size: 0.65rem;
        color: var(--mud-palette-error);
        border: 1px solid var(--mud-palette-error);
        border-radius: 3px;
        padding: 0 4px;
        line-height: 1.6;
        font-weight: 500;
        flex-shrink: 0;
    }
    .dept-emp-profiles {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
    }
    /* Compact employee rows in detail panel */
    .dept-detail-panel b[style*="min-width:10ch"] {
        min-width: 0 !important;
    }
    .dept-detail-panel span[style*="min-width:8ch"] {
        min-width: 0 !important;
    }
    /* Reduce subdepartment indentation */
    .dept-detail-panel div[style*="padding-left:32px"] {
        padding-left: 8px !important;
        margin-left: 0 !important;
    }
    /* Detail panel action buttons wrap on narrow screens */
    .dept-detail-panel .mud-stack-row {
        flex-wrap: wrap;
    }
}
@media (min-width: 601px) {
    .dept-mobile-tabs { display: none; }
    .dept-mobile-hidden { display: flex; }
}

/* Tree-view group indentation — overrides MudBlazor's hardcoded 17 px.
   Set --app-tree-indent on any ancestor element to control indentation. */
.mud-treeview-group {
    margin-left: var(--app-tree-indent, 17px) !important;
    margin-inline-start: var(--app-tree-indent, 17px) !important;
    margin-inline-end: unset !important;
}

/* All highlight animations (competency cards, profile requirement rows,
   profile-rule rows) are now applied inline via JS using user settings
   (HighlightColor + HighlightDuration). */

/* Competency names in profile requirement grids are double-click to edit. */
.comp-name-link {
    cursor: pointer;
}
.comp-name-link:hover {
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
}

/* ── Mobile dept-tree fine-tuning ────────────────────────────────────────
   With the row markup migrated to <DepartmentTree>'s .dt-* classes (see
   department-tree.css), most mobile-specific overrides moved with it. */
@media (max-width: 959.98px) {
    /* Hide kebab on mobile — long-press context menu is sufficient */
    .dept-tree-panel .row-kebab-btn-wrap {
        display: none !important;
    }
}
/* Honour prefers-reduced-motion globally — app.css's blanket neutraliser covers the
   0.24s slide-in for users who opted out. */

