/* ═══════════════════════════════════════════════════════════
   Role Management - Permission Matrix & Sidebar Config
   ═══════════════════════════════════════════════════════════ */

/* ─── Tabs ─── */
.role-tabs {
    border-bottom: 2px solid var(--bs-border-color);
    gap: 0;
}
.role-tabs .nav-link {
    color: var(--bs-secondary-color);
    font-weight: 500;
    padding: 0.75rem 1.25rem;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    border-radius: 0.375rem 0.375rem 0 0;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
    font-size: 0.9rem;
}
.role-tabs .nav-link:hover {
    color: var(--bs-body-color);
    background: rgba(0,0,0,0.03);
}
.role-tabs .nav-link.active {
    color: var(--bs-primary);
    border-bottom-color: var(--bs-primary);
    background: transparent;
}
.role-tabs .nav-link .badge {
    font-size: 0.7rem;
    vertical-align: middle;
}
[data-bs-theme="dark"] .role-tabs .nav-link:hover {
    background: rgba(255,255,255,0.05);
}

/* ─── Permission Matrix ─── */
.perm-matrix {
    border-collapse: separate;
    border-spacing: 0;
}
.perm-matrix thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bs-body-bg);
    border-bottom: 2px solid var(--bs-border-color);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--bs-secondary-color);
    padding: 0.75rem 0.5rem;
    white-space: nowrap;
    text-align: center;
}
.perm-matrix thead th:first-child {
    text-align: left;
    position: sticky;
    left: 0;
    z-index: 11;
}
.perm-matrix thead th.col-action {
    min-width: 70px;
}
.perm-matrix tbody tr {
    transition: background-color 0.1s;
}
.perm-matrix tbody tr:hover {
    background-color: rgba(13, 110, 253, 0.04);
}
.perm-matrix tbody td {
    padding: 0.5rem;
    border-bottom: 1px solid var(--bs-border-color);
    text-align: center;
    vertical-align: middle;
}
.perm-matrix tbody td:first-child {
    text-align: left;
    font-weight: 500;
    position: sticky;
    left: 0;
    background: var(--bs-body-bg);
    z-index: 5;
    white-space: nowrap;
}
.perm-matrix tbody tr:hover td:first-child {
    background-color: rgba(13, 110, 253, 0.04);
}
.perm-matrix .perm-check {
    width: 1.15rem;
    height: 1.15rem;
    cursor: pointer;
    accent-color: var(--bs-primary);
}
.perm-matrix .perm-unavailable {
    color: var(--bs-secondary-color);
    opacity: 0.3;
}
.perm-matrix tfoot td {
    padding: 0.6rem 0.5rem;
    border-top: 2px solid var(--bs-border-color);
    font-weight: 600;
    font-size: 0.8rem;
    background: var(--bs-body-bg);
    position: sticky;
    bottom: 0;
    z-index: 10;
    text-align: center;
}
.perm-matrix tfoot td:first-child {
    text-align: left;
    position: sticky;
    left: 0;
    z-index: 11;
}
.perm-count-badge {
    font-size: 0.75rem;
    font-weight: 600;
}

/* ─── Sidebar Config Tree ─── */
.sidebar-config-tree {
    max-width: 560px;
}
.sidebar-config-group {
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    overflow: hidden;
    transition: border-color 0.15s;
}
.sidebar-config-group:hover {
    border-color: var(--bs-primary);
}
.sidebar-config-group-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--bs-tertiary-bg);
    cursor: pointer;
    user-select: none;
    transition: background-color 0.1s;
}
.sidebar-config-group-header:hover {
    background: rgba(13, 110, 253, 0.04);
}
.sidebar-config-group-header .group-icon {
    color: var(--bs-primary);
    font-size: 1.1rem;
    flex-shrink: 0;
    width: 1.25rem;
    text-align: center;
}
.sidebar-config-group-header .group-label {
    font-weight: 600;
    flex-grow: 1;
}
.sidebar-config-group-header .group-toggle-icon {
    color: var(--bs-secondary-color);
    transition: transform 0.2s;
    font-size: 0.75rem;
}
.sidebar-config-group.open .group-toggle-icon {
    transform: rotate(180deg);
}
.sidebar-config-children {
    padding: 0.5rem 0.5rem 0.5rem 2.5rem;
    display: none;
}
.sidebar-config-group.open .sidebar-config-children {
    display: block;
}
.sidebar-config-child {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    transition: background-color 0.1s;
}
.sidebar-config-child:hover {
    background: rgba(13, 110, 253, 0.04);
}
.sidebar-config-child .perm-check {
    width: 1rem;
    height: 1rem;
}

/* ─── Toggle Switch ─── */
.form-switch .perm-check {
    width: 2rem;
    height: 1rem;
    cursor: pointer;
    accent-color: var(--bs-primary);
}

/* ─── User Assign ─── */
.user-assign-panel {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
}
.user-assign-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--bs-border-color);
    font-size: 0.875rem;
    transition: background-color 0.1s;
}
.user-assign-item:last-child {
    border-bottom: none;
}
.user-assign-item:hover {
    background: rgba(13, 110, 253, 0.04);
}
.user-assign-item .perm-check {
    width: 1rem;
    height: 1rem;
}
.user-assign-item .user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bs-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    flex-shrink: 0;
}

/* ─── Role List Enhanced ─── */
.role-stat-card {
    border: none;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    border-radius: 0.5rem;
    transition: transform 0.15s, box-shadow 0.15s;
}
.role-stat-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
}
.role-stat-card .stat-icon {
    width: 42px;
    height: 42px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}
.role-name-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.role-name-cell .role-icon {
    width: 32px;
    height: 32px;
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* ─── Role Type Colors ─── */
.role-color-super_admin { background: #dc3545; color: #fff; }
.role-color-org_admin { background: #0d6efd; color: #fff; }
.role-color-hr_manager { background: #6f42c1; color: #fff; }
.role-color-hr_director { background: #6f42c1; color: #fff; }
.role-color-hr_executive { background: #0dcaf0; color: #000; }
.role-color-dept_head { background: #198754; color: #fff; }
.role-color-it_admin { background: #fd7e14; color: #fff; }
.role-color-recruiter { background: #20c997; color: #fff; }
.role-color-payroll_manager { background: #ffc107; color: #000; }
.role-color-finance_manager { background: #ffc107; color: #000; }
.role-color-team_lead { background: #198754; color: #fff; }
.role-color-project_manager { background: #0dcaf0; color: #000; }
.role-color-employee { background: #6c757d; color: #fff; }
.role-color-default { background: var(--bs-secondary); color: #fff; }

/* ─── Responsive ─── */
@media (max-width: 767.98px) {
    .perm-matrix {
        font-size: 0.8rem;
    }
    .perm-matrix thead th,
    .perm-matrix tbody td {
        padding: 0.35rem;
    }
    .role-tabs .nav-link {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }
    .user-assign-panel {
        max-height: 300px;
    }
}

/* ─── Stepper / Guide ─── */
.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.4rem;
    height: 1.4rem;
    border-radius: 50%;
    background: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
    font-size: 0.72rem;
    font-weight: 700;
    margin-right: 0.35rem;
    border: 1px solid var(--bs-border-color);
}
.step-num.step-active {
    background: var(--bs-primary);
    color: #fff;
    border-color: var(--bs-primary);
}
.role-guide {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 1rem;
    border-radius: 0.5rem;
    background: rgba(13, 110, 253, 0.06);
    color: var(--bs-body-color);
    font-size: 0.85rem;
    border-left: 3px solid var(--bs-primary);
    max-width: 640px;
}

/* ─── Permission cards ─── */
.perm-category-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.85rem;
    font-size: 0.9rem;
}
.perm-category-header i {
    color: var(--bs-primary);
}
.perm-category-header strong {
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-size: 0.8rem;
}
.perm-module-card {
    height: 100%;
    border: 1px solid var(--bs-border-color);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.perm-module-card:hover {
    border-color: var(--bs-primary);
    box-shadow: 0 0.125rem 0.35rem rgba(13, 110, 253, 0.12);
}
.perm-module-card .card-header {
    padding: 0.6rem 0.9rem;
    background: var(--bs-tertiary-bg);
    border-bottom: 1px solid var(--bs-border-color);
}
.perm-module-card .card-body {
    padding: 0.75rem 0.9rem;
}
.module-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.action-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 500;
    background: var(--bs-body-bg);
    transition: all 0.12s;
    user-select: none;
}
.action-chip:hover {
    border-color: var(--bs-primary);
    background: rgba(13, 110, 253, 0.05);
}
.action-chip:has(input:checked) {
    background: rgba(13, 110, 253, 0.1);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}
.action-chip input.perm-check {
    width: 0.95rem;
    height: 0.95rem;
    margin: 0;
}
.action-chip-label {
    line-height: 1;
}
/* Fallback for browsers without :has() support */
.action-chip.chip-checked {
    background: rgba(13, 110, 253, 0.1);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}
.module-presets {
    display: flex;
    gap: 0.3rem;
    margin-bottom: 0.6rem;
}
.btn-xs {
    padding: 0.15rem 0.5rem;
    font-size: 0.72rem;
    border-radius: 0.3rem;
}
/* Initial chip state: reflect server-rendered checked state */
.action-chip:has(input:checked) {
    background: rgba(13, 110, 253, 0.1);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}

/* ─── Sticky actions / save bar ─── */
.sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 20;
    background: var(--bs-body-bg);
    border-top: 1px solid var(--bs-border-color);
    padding: 0.8rem 1.25rem;
    margin: 1rem -1.25rem -1rem;
    box-shadow: 0 -0.25rem 0.75rem rgba(0, 0, 0, 0.05);
}
.sticky-actions .d-flex {
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}
[data-bs-theme="dark"] .sticky-actions {
    box-shadow: 0 -0.25rem 0.75rem rgba(0, 0, 0, 0.35);
}
